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 ...
It's quite common for compiler to produce a mixed assembler/source code listing. It will show the source code it compiled and underneath it will show the generated assembler code. A quick Google gives
http://www.delorie.com/djgpp/v2faq/faq8_20.html