I need to know from which variable is a register of a binary instruction in the obj file is compiled from.
In short: the mapping from the register to variable for each instruction
Example: suppose objdump gives a snippet of obj file as:
MOV R1 5 # move 5 to register R1
SW R2 SP[-20] # store the value of R2 to address SP-20
How could we know that R1 stores variable, say, var1 from the source code? And R2 stores var2?
I searched in the documentation of readelf, unfortunately in vain.
(Though it can give me the line mapping between source and binary, it helps me no further)
Then I searched for some debugging options of gcc and the linker. Found some useful info, but they still dont solve my problem.
The info i found is:
- Option -fdump-rtl-vartrack can track all the variables and seems to be useful. But I didnt find the expected *.vartrack dump file when compiling with this option.
- Option *fdump-rtl-vartrack-uid shows the unique ID (DECL_UID) for each variable. But I received this error when using it: cc1: error: unrecognized command line option "-fdump-tree-uid"
- Option fdump-rtl-lreg dumps local register allocation, but I dont see how it can tell me the mapping from a reg to variable.
Does anyone have some experience or idea?
Thank you all!
hack on ...
GCC's "-fverbose-asm" option may help a little. It annotates the compiler's output with variable names. Unfortunately, the names are often temporaries invented by the compiler, such as "D.1234". It can still help to give you an idea of what's going on.
Try compiling something simple and take a look:
The way a debugger like GDB figures out where variables are stored at a given point in your program is (for most systems) using DWARF debug information generated by the compiler and stored in the object file. If your system is using DWARF, then readelf will do some very basic interpretation of this information for you. Try this:
It's clearly not trivial to decode. If you want to have a go, then check out the DWARF standard(s) at http://dwarfstd.org/.