libdwarf
Reading .debug_macinfo (DWARF2-4)

Example reading .debug_macinfo, DWARF2-4.

*/
void functionusingsigned(Dwarf_Signed s);
int examplep2(Dwarf_Debug dbg, Dwarf_Off cur_off,
Dwarf_Error*error)
{
Dwarf_Signed count = 0;
Dwarf_Macro_Details *maclist = 0;
Dwarf_Signed i = 0;
Dwarf_Unsigned max = 500000; /* sanity limit */
int errv = 0;
/* This is for DWARF2,DWARF3, and DWARF4
.debug_macinfo section only.*/
/* Given an offset from a compilation unit,
start at that offset (from DW_AT_macroinfo)
and get its macro details. */
errv = dwarf_get_macro_details(dbg, cur_off,max,
&count,&maclist,error);
if (errv == DW_DLV_OK) {
for (i = 0; i < count; ++i) {
Dwarf_Macro_Details * mentry = maclist +i;
/* example of use */
Dwarf_Signed lineno = mentry->dmd_lineno;
functionusingsigned(lineno);
}
dwarf_dealloc(dbg, maclist, DW_DLA_STRING);
}
/* Loop through all the compilation units macro info from zero.
This is not guaranteed to work because DWARF does not
guarantee every byte in the section is meaningful:
there can be garbage between the macro info
for CUs. But this loop will sometimes work.
*/
cur_off = 0;
while((errv = dwarf_get_macro_details(dbg, cur_off,max,
&count,&maclist,error))== DW_DLV_OK) {
for (i = 0; i < count; ++i) {
Dwarf_Macro_Details * mentry = maclist +i;
/* example of use */
Dwarf_Signed lineno = mentry->dmd_lineno;
functionusingsigned(lineno);
}
cur_off = maclist[count-1].dmd_offset + 1;
dwarf_dealloc(dbg, maclist, DW_DLA_STRING);
}
return DW_DLV_OK;
}
struct Dwarf_Debug_s * Dwarf_Debug
Definition: libdwarf.h:586
struct Dwarf_Error_s * Dwarf_Error
Definition: libdwarf.h:580
signed long long Dwarf_Signed
Definition: libdwarf.h:197
unsigned long long Dwarf_Unsigned
Definition: libdwarf.h:196
unsigned long long Dwarf_Off
Definition: libdwarf.h:198
void dwarf_dealloc(Dwarf_Debug dw_dbg, void *dw_space, Dwarf_Unsigned dw_type)
The generic dealloc (free) function. It requires you know the correct DW_DLA value to pass in,...
int dwarf_get_macro_details(Dwarf_Debug dw_dbg, Dwarf_Off dw_macro_offset, Dwarf_Unsigned dw_maximum_count, Dwarf_Signed *dw_entry_count, Dwarf_Macro_Details **dw_details, Dwarf_Error *dw_error)
Getting .debug_macinfo macro details.
Definition: libdwarf.h:711