mardi 30 juin 2015

How can my C code find the symbol corresponding to an address at run-time (in Linux)?


Given a function or variable run-time address, my code needs to find out the name and, if it's a variable, type information of the symbol. Or at least provide enough information for later, off-line extraction of the name (and type info).

It is Linux code and it is assumed debug information is available.

I tried to look into the ELF file format, binutils and all but the subject is huge, so I was hoping somebody can help me narrow the scope.

I can see the following types of solutions:

  • find the range of the code/data segments of the modules currently loaded in memory - HOW TO DO THAT ?. Save the address's module and segment name and offset in it's segment. Off-line then use binutils to find the symbol in the module's debug info - again, HOW TO DO THAT?

  • use some API/system services I do not know of to find the symbol and info at run-time - HOW?

Thank you in advance.


Aucun commentaire:

Enregistrer un commentaire