libdwarf
Reading string offsets section data

Example accessing the string offsets section.

An example accessing the string offsets section

Parameters
dbgThe Dwarf_Debug of interest.
dw_errorOn error dw_error is set to point to the error details.
Returns
DW_DLV_OK etc.
*/
int examplestrngoffsets(Dwarf_Debug dbg,Dwarf_Error *error)
{
int res = 0;
Dwarf_Unsigned wasted_byte_count = 0;
Dwarf_Unsigned table_count = 0;
Dwarf_Error closeerror = 0;
res = dwarf_open_str_offsets_table_access(dbg, &sot,error);
if (res == DW_DLV_NO_ENTRY) {
/* No such table */
return res;
}
if (res == DW_DLV_ERROR) {
/* Something is very wrong. Print the error? */
return res;
}
for (;;) {
Dwarf_Unsigned unit_length =0;
Dwarf_Unsigned unit_length_offset =0;
Dwarf_Unsigned table_start_offset =0;
Dwarf_Half entry_size = 0;
Dwarf_Half version =0;
Dwarf_Half padding =0;
Dwarf_Unsigned table_value_count =0;
Dwarf_Unsigned table_entry_value = 0;
&unit_length, &unit_length_offset,
&table_start_offset,
&entry_size,&version,&padding,
&table_value_count,error);
if (res == DW_DLV_NO_ENTRY) {
/* We have dealt with all tables */
break;
}
if (res == DW_DLV_ERROR) {
/* Something badly wrong. Do something. */
dwarf_dealloc_error(dbg,closeerror);
return res;
}
/* One could call dwarf_str_offsets_statistics to
get the wasted bytes so far, but we do not do that
in this example. */
/* Possibly print the various table-related values
returned just above. */
for (i=0; i < table_value_count; ++i) {
&table_entry_value,error);
if (res != DW_DLV_OK) {
/* Something is badly wrong. Do something. */
dwarf_dealloc_error(dbg,closeerror);
return res;
}
/* Do something with the table_entry_value
at this index. Maybe just print it.
It is an offset in .debug_str. */
}
}
res = dwarf_str_offsets_statistics(sot,&wasted_byte_count,
&table_count,error);
if (res != DW_DLV_OK) {
dwarf_dealloc_error(dbg,closeerror);
return res;
}
/* little can be done about any error. */
sot = 0;
return res;
}
/*
struct Dwarf_Debug_s * Dwarf_Debug
Definition: libdwarf.h:603
struct Dwarf_Str_Offsets_Table_s * Dwarf_Str_Offsets_Table
Definition: libdwarf.h:455
struct Dwarf_Error_s * Dwarf_Error
Definition: libdwarf.h:597
unsigned short Dwarf_Half
Definition: libdwarf.h:203
unsigned long long Dwarf_Unsigned
Definition: libdwarf.h:196
void dwarf_dealloc_error(Dwarf_Debug dw_dbg, Dwarf_Error dw_error)
Free (dealloc) an Dwarf_Error something created.
int dwarf_str_offsets_statistics(Dwarf_Str_Offsets_Table dw_table_data, Dwarf_Unsigned *dw_wasted_byte_count, Dwarf_Unsigned *dw_table_count, Dwarf_Error *dw_error)
Reports final wasted-bytes count.
int dwarf_open_str_offsets_table_access(Dwarf_Debug dw_dbg, Dwarf_Str_Offsets_Table *dw_table_data, Dwarf_Error *dw_error)
Creates access to a .debug_str_offsets table.
int dwarf_next_str_offsets_table(Dwarf_Str_Offsets_Table dw_table_data, Dwarf_Unsigned *dw_unit_length, Dwarf_Unsigned *dw_unit_length_offset, Dwarf_Unsigned *dw_table_start_offset, Dwarf_Half *dw_entry_size, Dwarf_Half *dw_version, Dwarf_Half *dw_padding, Dwarf_Unsigned *dw_table_value_count, Dwarf_Error *dw_error)
Iterate through the offsets tables.
int dwarf_close_str_offsets_table_access(Dwarf_Str_Offsets_Table dw_table_data, Dwarf_Error *dw_error)
Close str_offsets access, free table_data.
int dwarf_str_offsets_value_by_index(Dwarf_Str_Offsets_Table dw_table_data, Dwarf_Unsigned dw_index_to_entry, Dwarf_Unsigned *dw_entry_value, Dwarf_Error *dw_error)
Access to an individual str offsets table entry.