Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 548 Vote(s) - 3.53 Average
  • 1
  • 2
  • 3
  • 4
  • 5
gdb - get variable name of register

#1
In GDB, `info registers` or `info all-registers` will show you all of the register symbol names and their values.

**Question:**

How do I get the *variable* name (i.e. from the source code) that is stored in that register? (or a line number in source code, or anything)

For example:

int my_reg = /* something */;
float another_reg = /* something else */;
...

Then perhaps, `info all-registers` will return:

R0 0x0 0
R1 0xfffbf0 16776176
R2 0x0 0
R3 0x0 0
R4 0x6 6

How do I determine which register (R0? R2? R4?) is "associated" with `my_reg`?
Reply

#2
There might be one register, multiple registers, or even no registers associated with any given C variable at any given point in time. You'll have to inspect the disassembly to see what's going on.

Why not just `print my_reg` to see the value?

`l *$pc` will list the source code around the current instruction being executed.
Reply

#3
If you have access to the debug symbols (and understand how to read them - that is, you have some code that parses the debug symbols), it is possible to trace exactly which register corresponds to which register. However, this is quite possibly changing from one line to the next, as the compiler decides to move things around for one reason or another (e.g. some calculation starts with R1, and ends up with the result in R2, because that's better than trying to retain the value in R1 [or we need the original value in R1 too - think `array[x++]` - now we have the new value of `x`, hopefully in a register, and the value of the old `x` that we need to use for indexing, also needed to be in a register to add to the base-address of `array`.

Not all variables end up in registers (depending on processor, and "what registers are available").

The debugger _WILL_ know where each variable is at any given time - but sometimes it can be a big confused, e.g:

int array[10000];
...
for(int i = 0; i < 10000; i++)
{
array[i] = rand();
}

may translate to something like this during optimization:

int array[10000];
int *ptr = array;
int *ptr2 = &array[10000];
while(ptr < ptr2)
{
*ptr++ = rand();
}

Now try printing `i`... ;)
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through