If you have access to debug symbols (and understand how to read them, that is, you have code that analyzes debug symbols), you can precisely determine which register corresponds to that register. However, this, quite possibly, changes from one line to another, because the compiler decides to move things for one reason or another (for example, some calculations start with R1 and end with the result in R2, because it's better than trying to store the value in R1 [or we need the original value in R1 too - think array[x++] - now we have a new value x , I hope, in the register, and the value of the old x , which we need to use for indexing, should also be in the register to add to base address of array .
Not all variables fall into registers (depending on the processor and "which registers are available").
The WILL debugger knows where each variable is at any given time, but sometimes it can be a big embarrassment, for example:
int array[10000]; ... for(int i = 0; i < 10000; i++) { array[i] = rand(); }
might translate something like this during optimization:
int array[10000]; int *ptr = array; int *ptr2 = &array[10000]; while(ptr < ptr2) { *ptr++ = rand(); }
Now try to print i ...;)
source share