I'm writing a tool to add variables to a2l file, the input is elf file. For searching which compile unit (CU) has the variable, I have to search through all CUs (till meet the variable). Because the SW is very big, it takes time to find a variable. I would like to know if there's any faster way to know which CU the variable is defined ?
The DWARF standard includes an optional section, .debug_pubnames
, that provides name-to-offset translation for global objects and functions.
Another approach is to use the symbol table. If it has an entry for the variable then you can use its address with the optional .debug_aranges
section or, failing that, read every DW_TAG_compile_unit
looking for the one with the enclosing address range.