Example reading DWARF5 macro data.
This builds an list or some other data structure (not defined) to give an import somewhere to list the import offset and then later to enquire if the list has unexamined offsets. The code compiles but is not yet tested.
This example does not actually do the import at the correct time as this is just checking import offsets, not creating a proper full list (in the proper order) of the macros with the imports inserted. Here we find the macro context for a DIE, report those macro entries, noting any macro_import in a list loop extracting unchecked macro offsets from the list note any import in a list Of course some functions are not implemented here...
*/
int has_unchecked_import_in_list(void)
{
return DW_DLV_OK;
}
{
return 22;
}
void mark_this_offset_as_examined(
{
(void)macro_unit_offset;
}
{
(void)offset;;
}
{
int lres = 0;
for ( ; ; ) {
if (is_primary) {
&version,¯o_context,
¯o_unit_offset,
&number_of_ops,
&ops_total_byte_len,
error);
is_primary = FALSE;
} else {
if (has_unchecked_import_in_list()) {
macro_unit_offset = get_next_import_from_list();
} else {
break;
}
macro_unit_offset,
&version,
¯o_context,
&number_of_ops,
&ops_total_byte_len,
error);
mark_this_offset_as_examined(macro_unit_offset);
}
if (lres == DW_DLV_ERROR) {
return lres;
}
if (lres == DW_DLV_NO_ENTRY) {
break;
}
for (k = 0; k < number_of_ops; ++k) {
const char * macro_string =0;
int lres2 = 0;
k, §ion_offset,¯o_operator,
&forms_count, &formcode_array,error);
if (lres2 != DW_DLV_OK) {
return lres2;
}
switch(macro_operator) {
case 0:
break;
case DW_MACRO_end_file:
break;
case DW_MACRO_define:
case DW_MACRO_undef:
case DW_MACRO_define_strp:
case DW_MACRO_undef_strp:
case DW_MACRO_define_strx:
case DW_MACRO_undef_strx:
case DW_MACRO_define_sup:
case DW_MACRO_undef_sup: {
k,
&line_number,
&index,
&offset,
&forms_count,
¯o_string,
error);
if (lres2 != DW_DLV_OK) {
return lres2;
}
}
break;
case DW_MACRO_start_file: {
k,&line_number,
&index,
¯o_string,error);
if (lres2 != DW_DLV_OK) {
return lres2;
}
}
break;
case DW_MACRO_import: {
k,&offset,error);
if (lres2 != DW_DLV_OK) {
return lres2;
}
add_offset_to_list(offset);
}
break;
case DW_MACRO_import_sup: {
k,&offset,error);
if (lres2 != DW_DLV_OK) {
return lres2;
}
}
break;
default:
break;
}
}
macro_context = 0;
}
return DW_DLV_OK;
}
struct Dwarf_Die_s * Dwarf_Die
Definition: libdwarf.h:608
struct Dwarf_Error_s * Dwarf_Error
Definition: libdwarf.h:597
struct Dwarf_Macro_Context_s * Dwarf_Macro_Context
Definition: libdwarf.h:702
unsigned char Dwarf_Small
Definition: libdwarf.h:204
unsigned short Dwarf_Half
Definition: libdwarf.h:203
unsigned long long Dwarf_Unsigned
Definition: libdwarf.h:196
int Dwarf_Bool
Definition: libdwarf.h:202
int dwarf_get_macro_context(Dwarf_Die dw_die, Dwarf_Unsigned *dw_version_out, Dwarf_Macro_Context *dw_macro_context, Dwarf_Unsigned *dw_macro_unit_offset_out, Dwarf_Unsigned *dw_macro_ops_count_out, Dwarf_Unsigned *dw_macro_ops_data_length_out, Dwarf_Error *dw_error)
DWARF5 .debug_macro access via Dwarf_Die.
int dwarf_get_macro_import(Dwarf_Macro_Context dw_macro_context, Dwarf_Unsigned dw_op_number, Dwarf_Unsigned *dw_target_offset, Dwarf_Error *dw_error)
Get Macro import.
int dwarf_get_macro_op(Dwarf_Macro_Context dw_macro_context, Dwarf_Unsigned dw_op_number, Dwarf_Unsigned *dw_op_start_section_offset, Dwarf_Half *dw_macro_operator, Dwarf_Half *dw_forms_count, const Dwarf_Small **dw_formcode_array, Dwarf_Error *dw_error)
Access macro operation details of a single operation.
int dwarf_get_macro_context_by_offset(Dwarf_Die dw_die, Dwarf_Unsigned dw_offset, Dwarf_Unsigned *dw_version_out, Dwarf_Macro_Context *dw_macro_context, Dwarf_Unsigned *dw_macro_ops_count_out, Dwarf_Unsigned *dw_macro_ops_data_length, Dwarf_Error *dw_error)
DWARF5 .debug_macro access via Dwarf_Die and an offset.
void dwarf_dealloc_macro_context(Dwarf_Macro_Context dw_mc)
Dealloc a macro context.
int dwarf_get_macro_startend_file(Dwarf_Macro_Context dw_macro_context, Dwarf_Unsigned dw_op_number, Dwarf_Unsigned *dw_line_number, Dwarf_Unsigned *dw_name_index_to_line_tab, const char **dw_src_file_name, Dwarf_Error *dw_error)
Get Macro start end.
int dwarf_get_macro_defundef(Dwarf_Macro_Context dw_macro_context, Dwarf_Unsigned dw_op_number, Dwarf_Unsigned *dw_line_number, Dwarf_Unsigned *dw_index, Dwarf_Unsigned *dw_offset, Dwarf_Half *dw_forms_count, const char **dw_macro_string, Dwarf_Error *dw_error)
Get Macro defundef.