This is an interesting problem to solve. I have often wondered through school how to perform this (on a linux machine). But as others have pointed out, it's kinda tricky.
Well, consider a small program which is like this :
/* smallprogram.c */
/* Assume suitable headers for system calls */
/* getpid() gets the caller's Process ID */
int my_pid = getpid(); /* Line 1 */
printf("My PID is : \n%x" , my_pid); /* Line 2 */
/* my_pid variable is at an address 0x000000F0 */
/* printf function definition (libc) is loaded at an address 0x00AA0000 */
Now say, you run this program on MACHINE-1 and want to break after Line 1.
my_pid has been set to the current process ID on MACHINE-1 . Assume my_pid = 120.
Your registers and assembly of the program are set up according to current state of MACHINE-1.
Shifting this to MACHINE2 (Say you are able to perform a 1:1 copy somehow of the memory space):
libc loaded at 0x00BB0000.
130 processes running. So the next available pid will be 131.
Assuming everything else is the same as MACHINE1. (Very difficult in reality, but let's assume)
Some issues (There may be more) :
*As soon as your program tries to continue execution on MACHINE2, it will crash (as some other memory address is CALLED instead of print() )
*EVEN IF you were able to run without the issues you faced with libc, the value of my_pid is 120 (migrated from MACHINE-1). But the actual PID on MACHINE2 is 131. So all code that follows Line2 and uses the value of my_pid will behave in an irresponsible/unexpected manner.
A valid approach here might be to have some sort of a "CONTAINER" (jail, chroot, virtual memory space, or something along these lines) which is able to run a program inside it. But you write the container in such a way, that it automatically *fixes* all the addresses of the program running inside this container (or the approach is universal, and does not require address fixing in any manner).
Hope this helps.
Check out the Netsurf
Web Browser for KolibriOS.
Read the wiki and happy hacking with KolibriOS!