libdwarf
Loading...
Searching...
No Matches
Examining Section Group data

Example accessing Section Group data.

With split dwarf your libdwarf calls after than the initial open are done against the base Dwarf_Dbg and libdwarf automatically looks in the open tied dbg when and as appropriate. the tied-dbg can be detached too, see example3 link, though you must call dwarf_finish() on the detached dw_tied_dbg, the library will not do that for you..

Section groups apply to Elf COMDAT groups too.

*/
void examplesecgroup(Dwarf_Debug dbg)
{
int res = 0;
Dwarf_Unsigned section_count = 0;
Dwarf_Unsigned group_count;
Dwarf_Unsigned selected_group = 0;
Dwarf_Unsigned group_map_entry_count = 0;
Dwarf_Unsigned *sec_nums = 0;
Dwarf_Unsigned *group_nums = 0;
const char ** sec_names = 0;
Dwarf_Error error = 0;
res = dwarf_sec_group_sizes(dbg,&section_count,
&group_count,&selected_group, &group_map_entry_count,
&error);
if (res != DW_DLV_OK) {
/* Something is badly wrong*/
return;
}
/* In an object without split-dwarf sections
or COMDAT sections we now have
selected_group == 1. */
sec_nums = calloc(group_map_entry_count,sizeof(Dwarf_Unsigned));
if (!sec_nums) {
/* FAIL. out of memory */
return;
}
group_nums = calloc(group_map_entry_count,sizeof(Dwarf_Unsigned));
if (!group_nums) {
free(group_nums);
/* FAIL. out of memory */
return;
}
sec_names = calloc(group_map_entry_count,sizeof(char*));
if (!sec_names) {
free(group_nums);
free(sec_nums);
/* FAIL. out of memory */
return;
}
res = dwarf_sec_group_map(dbg,group_map_entry_count,
group_nums,sec_nums,sec_names,&error);
if (res != DW_DLV_OK) {
/* FAIL. Something badly wrong. */
free(sec_names);
free(group_nums);
free(sec_nums);
}
for ( i = 0; i < group_map_entry_count; ++i) {
/* Now do something with
group_nums[i],sec_nums[i],sec_names[i] */
}
/* The strings are in Elf data.
Do not free() the strings themselves.*/
free(sec_names);
free(group_nums);
free(sec_nums);
}
struct Dwarf_Debug_s * Dwarf_Debug
Definition libdwarf.h:603
struct Dwarf_Error_s * Dwarf_Error
Definition libdwarf.h:597
unsigned long long Dwarf_Unsigned
Definition libdwarf.h:196
int dwarf_sec_group_sizes(Dwarf_Debug dw_dbg, Dwarf_Unsigned *dw_section_count_out, Dwarf_Unsigned *dw_group_count_out, Dwarf_Unsigned *dw_selected_group_out, Dwarf_Unsigned *dw_map_entry_count_out, Dwarf_Error *dw_error)
Get Section Groups data counts.
int dwarf_sec_group_map(Dwarf_Debug dw_dbg, Dwarf_Unsigned dw_map_entry_count, Dwarf_Unsigned *dw_group_numbers_array, Dwarf_Unsigned *dw_sec_numbers_array, const char **dw_sec_names_array, Dwarf_Error *dw_error)
Return a map between group numbers and section numbers.