libdwarf
Using dwarf_get_globals()

Example using global symbol names.

For 0.4.2 and earlier this returned .debug_pubnames content. As of version 0.5.0 (October 2022) this returns .debug_pubnames (if it exists) and the relevant portion of .debug_names (if .debug_names exists) data.

*/
int examplef(Dwarf_Debug dbg,Dwarf_Error *error)
{
Dwarf_Signed count = 0;
Dwarf_Global *globs = 0;
Dwarf_Signed i = 0;
int res = 0;
res = dwarf_get_globals(dbg, &globs,&count, error);
if (res != DW_DLV_OK) {
return res;
}
for (i = 0; i < count; ++i) {
/* use globs[i] */
char *name = 0;
res = dwarf_globname(globs[i],&name,error);
if (res != DW_DLV_OK) {
dwarf_globals_dealloc(dbg,globs,count);
return res;
}
}
dwarf_globals_dealloc(dbg, globs, count);
return DW_DLV_OK;
}
struct Dwarf_Debug_s * Dwarf_Debug
Definition: libdwarf.h:603
struct Dwarf_Global_s * Dwarf_Global
Definition: libdwarf.h:625
struct Dwarf_Error_s * Dwarf_Error
Definition: libdwarf.h:597
signed long long Dwarf_Signed
Definition: libdwarf.h:197
int dwarf_globname(Dwarf_Global dw_global, char **dw_returned_name, Dwarf_Error *dw_error)
Return the name of a global-like data item.
void dwarf_globals_dealloc(Dwarf_Debug dw_dbg, Dwarf_Global *dw_global_like, Dwarf_Signed dw_count)
Dealloc the Dwarf_Global data.
int dwarf_get_globals(Dwarf_Debug dw_dbg, Dwarf_Global **dw_globals, Dwarf_Signed *dw_number_of_globals, Dwarf_Error *dw_error)
Global name space operations, .debug_pubnames access.