简体   繁体   中英

How do you get the initialized value of a global variable out of an object file?

If you have an object file, how do you get the initialized value of a global variable in that object file's data segment? For example, say I've done the following:

# I'm interested in the variable foo inside bar.o in libbar.a:
$ ar -x libbar.a bar.o
$ nm --print-size bar.o | grep foo
00000048 00000004 D foo

This tells me that foo is at offset 0x48 in the data segment with size 4, but how do I obtain the actual initialized value it obtains upon load?

Figured it out:

objdump -j.data -s bar.o

This gives a hexdump of the data segment, making it easy to look up values. I've used objdump -d before to disassemble code, but the -s option is new to me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM