user1942828
user1942828

Reputation: 1

reading type,address,size of variables from symbol table. Which is built using gnu tools (like gmake or gcc)

We are trying to implement the customized gdb tool for specific environment. We have Linux- Centos operating systems.

Trying to implement the gdb functionality with some customization. Our tool will be attached to the PID (already running process), which will start debugging session. we would like to read the symbols information (symbol table) and print as much as possible information of symbols (mainly the data type, address and size).

We are able to read the symbol table using the readelf, file commands in gdb, and able to print some information related to local/global variables. But we are not able to find the exact command to print the addresses and sizes of the variables.

Upvotes: 0

Views: 273

Answers (1)

scottt
scottt

Reputation: 7228

You can use the ptype command and sizeof in expressions in gdb:

(gdb) ptype exit
type = int ()
(gdb) print sizeof(argc)
$1 = 4

This of course requires that debuginfo and not just the symbol table to be available, e.g. for ELF, this requires the .debug_{aranges,info,abbrev,...} sections and not just .shstrtab, .symtab, and .strtab.

Upvotes: 1

Related Questions