Rizin
unix-like reverse engineering framework and cli tools
cdwarf.c File Reference
#include <rz_core.h>

Go to the source code of this file.

Functions

RZ_API void rz_core_bin_dwarf_print_abbrev_section (const RzBinDwarfDebugAbbrev *da)
 
RZ_API void rz_core_bin_dwarf_print_attr_value (const RzBinDwarfAttrValue *val)
 
RZ_API void rz_core_bin_dwarf_print_debug_info (const RzBinDwarfDebugInfo *inf)
 
static int offset_comp (const void *a, const void *b)
 
static bool sort_loclists (void *user, const ut64 key, const void *value)
 
RZ_API void rz_core_bin_dwarf_print_loc (HtUP *loc_table, int addr_size)
 
RZ_API void rz_core_bin_dwarf_print_aranges (RzList *aranges)
 
static void print_line_op (RzBinDwarfLineOp *op, RzBinDwarfLineHeader *hdr, RZ_NULLABLE RzBinDwarfSMRegisters *regs)
 
RZ_API void rz_core_bin_dwarf_print_line_units (RzList *lines)
 

Function Documentation

◆ offset_comp()

static int offset_comp ( const void *  a,
const void *  b 
)
static

Definition at line 175 of file cdwarf.c.

175  {
176  const RzBinDwarfLocList *f = a;
177  const RzBinDwarfLocList *s = b;
178  ut64 first = f->offset;
179  ut64 second = s->offset;
180  if (first < second) {
181  return -1;
182  }
183  if (first > second) {
184  return 1;
185  }
186  return 0;
187 }
static RzSocket * s
Definition: rtr.c:28
#define b(i)
Definition: sha256.c:42
#define f(i)
Definition: sha256.c:46
#define a(i)
Definition: sha256.c:41
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References a, b, f, s, and ut64().

Referenced by sort_loclists().

◆ print_line_op()

static void print_line_op ( RzBinDwarfLineOp op,
RzBinDwarfLineHeader hdr,
RZ_NULLABLE RzBinDwarfSMRegisters regs 
)
static
Parameters
regsoptional, the state after op has been executed. If not null, some meaningful results from this context will be shown.

Definition at line 247 of file cdwarf.c.

247  {
248  switch (op->type) {
250  switch (op->opcode) {
251  case DW_LNS_copy:
252  rz_cons_print("Copy");
253  break;
254  case DW_LNS_advance_pc:
255  rz_cons_printf("Advance PC by %" PFMT64u, op->args.advance_pc * hdr->min_inst_len);
256  if (regs) {
257  rz_cons_printf(" to 0x%" PFMT64x, regs->address);
258  }
259  break;
260  case DW_LNS_advance_line:
261  rz_cons_printf("Advance line by %" PFMT64d, op->args.advance_line);
262  if (regs) {
263  rz_cons_printf(", to %" PFMT64d, regs->line);
264  }
265  break;
266  case DW_LNS_set_file:
267  rz_cons_printf("Set file to %" PFMT64d, op->args.set_file);
268  break;
269  case DW_LNS_set_column:
270  rz_cons_printf("Set column to %" PFMT64d, op->args.set_column);
271  break;
272  case DW_LNS_negate_stmt:
273  if (regs) {
274  rz_cons_printf("Set is_stmt to %u", (unsigned int)regs->is_stmt);
275  } else {
276  rz_cons_print("Negate is_stmt");
277  }
278  break;
280  rz_cons_print("set_basic_block");
281  break;
282  case DW_LNS_const_add_pc:
283  rz_cons_printf("Advance PC by constant %" PFMT64u, rz_bin_dwarf_line_header_get_spec_op_advance_pc(hdr, 255));
284  if (regs) {
285  rz_cons_printf(" to 0x%" PFMT64x, regs->address);
286  }
287  break;
289  rz_cons_printf("Fixed advance pc by %" PFMT64u, op->args.fixed_advance_pc);
290  rz_cons_printf(" to %" PFMT64d, regs->address);
291  break;
293  rz_cons_print("set_prologue_end");
294  break;
296  rz_cons_print("set_epilogue_begin");
297  break;
298  case DW_LNS_set_isa:
299  rz_cons_printf("set_isa to %" PFMT64u, op->args.set_isa);
300  break;
301  default:
302  rz_cons_printf("Unknown Standard Opcode %u", (unsigned int)op->opcode);
303  break;
304  }
305  break;
307  rz_cons_printf("Extended opcode %u: ", (unsigned int)op->opcode);
308  switch (op->opcode) {
309  case DW_LNE_end_sequence:
310  rz_cons_print("End of Sequence");
311  break;
312  case DW_LNE_set_address:
313  rz_cons_printf("set Address to 0x%" PFMT64x, op->args.set_address);
314  break;
315  case DW_LNE_define_file:
316  rz_cons_printf("define_file \"%s\", dir_index %" PFMT64u ", ",
317  op->args.define_file.filename,
318  op->args.define_file.dir_index);
319  break;
321  rz_cons_printf("set Discriminator to %" PFMT64u "\n", op->args.set_discriminator);
322  break;
323  default:
324  rz_cons_printf("Unknown");
325  break;
326  }
327  break;
329  rz_cons_printf("Special opcode %u: ", (unsigned int)rz_bin_dwarf_line_header_get_adj_opcode(hdr, op->opcode));
330  rz_cons_printf("advance Address by %" PFMT64u, rz_bin_dwarf_line_header_get_spec_op_advance_pc(hdr, op->opcode));
331  if (regs) {
332  rz_cons_printf(" to 0x%" PFMT64x, regs->address);
333  }
335  if (regs) {
336  rz_cons_printf(" to %" PFMT64u, regs->line);
337  }
338  break;
339  }
340  rz_cons_print("\n");
341 }
static char * regs[]
Definition: analysis_sh.c:203
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
RZ_API st64 rz_bin_dwarf_line_header_get_spec_op_advance_line(const RzBinDwarfLineHeader *header, ut8 opcode)
Definition: dwarf.c:628
RZ_API ut64 rz_bin_dwarf_line_header_get_spec_op_advance_pc(const RzBinDwarfLineHeader *header, ut8 opcode)
Definition: dwarf.c:618
RZ_API ut64 rz_bin_dwarf_line_header_get_adj_opcode(const RzBinDwarfLineHeader *header, ut8 opcode)
Definition: dwarf.c:613
#define DW_LNE_set_address
Definition: rz_bin_dwarf.h:33
#define DW_LNS_set_column
Definition: rz_bin_dwarf.h:23
#define DW_LNS_advance_pc
Definition: rz_bin_dwarf.h:20
#define DW_LNS_advance_line
Definition: rz_bin_dwarf.h:21
#define DW_LNS_set_file
Definition: rz_bin_dwarf.h:22
#define DW_LNS_copy
Definition: rz_bin_dwarf.h:19
#define DW_LNS_set_isa
Definition: rz_bin_dwarf.h:30
#define DW_LNS_negate_stmt
Definition: rz_bin_dwarf.h:24
#define DW_LNE_set_discriminator
Definition: rz_bin_dwarf.h:35
#define DW_LNS_set_epilogue_begin
Definition: rz_bin_dwarf.h:29
@ RZ_BIN_DWARF_LINE_OP_TYPE_SPEC
Definition: rz_bin_dwarf.h:859
@ RZ_BIN_DWARF_LINE_OP_TYPE_EXT
Definition: rz_bin_dwarf.h:861
@ RZ_BIN_DWARF_LINE_OP_TYPE_STD
Definition: rz_bin_dwarf.h:860
#define DW_LNS_fixed_advance_pc
Definition: rz_bin_dwarf.h:27
#define DW_LNE_define_file
Definition: rz_bin_dwarf.h:34
#define DW_LNS_set_basic_block
Definition: rz_bin_dwarf.h:25
#define DW_LNS_set_prologue_end
Definition: rz_bin_dwarf.h:28
#define DW_LNE_end_sequence
Definition: rz_bin_dwarf.h:32
#define DW_LNS_const_add_pc
Definition: rz_bin_dwarf.h:26
#define PFMT64d
Definition: rz_types.h:394
#define PFMT64u
Definition: rz_types.h:395
#define PFMT64x
Definition: rz_types.h:393
Definition: dis.c:32

References DW_LNE_define_file, DW_LNE_end_sequence, DW_LNE_set_address, DW_LNE_set_discriminator, DW_LNS_advance_line, DW_LNS_advance_pc, DW_LNS_const_add_pc, DW_LNS_copy, DW_LNS_fixed_advance_pc, DW_LNS_negate_stmt, DW_LNS_set_basic_block, DW_LNS_set_column, DW_LNS_set_epilogue_begin, DW_LNS_set_file, DW_LNS_set_isa, DW_LNS_set_prologue_end, RzBinDwarfLineHeader::min_inst_len, PFMT64d, PFMT64u, PFMT64x, regs, rz_bin_dwarf_line_header_get_adj_opcode(), rz_bin_dwarf_line_header_get_spec_op_advance_line(), rz_bin_dwarf_line_header_get_spec_op_advance_pc(), RZ_BIN_DWARF_LINE_OP_TYPE_EXT, RZ_BIN_DWARF_LINE_OP_TYPE_SPEC, RZ_BIN_DWARF_LINE_OP_TYPE_STD, and rz_cons_printf().

Referenced by rz_core_bin_dwarf_print_line_units().

◆ rz_core_bin_dwarf_print_abbrev_section()

RZ_API void rz_core_bin_dwarf_print_abbrev_section ( const RzBinDwarfDebugAbbrev da)

Definition at line 6 of file cdwarf.c.

6  {
7  size_t i, j;
8  if (!da) {
9  return;
10  }
11  for (i = 0; i < da->count; i++) {
12  rz_cons_printf(" %-4" PFMT64d " ", da->decls[i].code);
13  const char *tagname = rz_bin_dwarf_get_tag_name(da->decls[i].tag);
14  if (tagname) {
15  rz_cons_printf(" %-25s ", tagname);
16  }
17  rz_cons_printf("[%s]", da->decls[i].has_children ? "has children" : "no children");
18  rz_cons_printf(" (0x%" PFMT64x ")\n", da->decls[i].offset);
19 
20  if (da->decls[i].defs) {
21  for (j = 0; j < da->decls[i].count; j++) {
22  const char *attr_name = rz_bin_dwarf_get_attr_name(da->decls[i].defs[j].attr_name);
23  const char *attr_form_name = rz_bin_dwarf_get_attr_form_name(da->decls[i].defs[j].attr_form);
24  if (attr_name && attr_form_name) {
25  rz_cons_printf(" %-30s %-30s\n", attr_name, attr_form_name);
26  }
27  }
28  }
29  }
30 }
lzma_index ** i
Definition: index.h:629
RZ_API const char * rz_bin_dwarf_get_attr_name(ut64 attr_code)
Definition: dwarf.c:323
RZ_API const char * rz_bin_dwarf_get_attr_form_name(ut64 form_code)
Definition: dwarf.c:373
RZ_API const char * rz_bin_dwarf_get_tag_name(ut64 tag)
Definition: dwarf.c:316
RzBinDwarfAttrDef * defs
Definition: rz_bin_dwarf.h:793
RzBinDwarfAbbrevDecl * decls
Definition: rz_bin_dwarf.h:801

References RzBinDwarfAttrDef::attr_form, RzBinDwarfAttrDef::attr_name, RzBinDwarfAbbrevDecl::code, RzBinDwarfAbbrevDecl::count, RzBinDwarfDebugAbbrev::count, RzBinDwarfDebugAbbrev::decls, RzBinDwarfAbbrevDecl::defs, RzBinDwarfAbbrevDecl::has_children, i, RzBinDwarfAbbrevDecl::offset, PFMT64d, PFMT64x, rz_bin_dwarf_get_attr_form_name(), rz_bin_dwarf_get_attr_name(), rz_bin_dwarf_get_tag_name(), rz_cons_printf(), and RzBinDwarfAbbrevDecl::tag.

Referenced by bin_dwarf().

◆ rz_core_bin_dwarf_print_aranges()

RZ_API void rz_core_bin_dwarf_print_aranges ( RzList aranges)

Definition at line 222 of file cdwarf.c.

222  {
223  rz_return_if_fail(aranges);
224  rz_cons_print("\nContents of the .debug_aranges section:\n");
225  RzListIter *it;
226  RzBinDwarfARangeSet *set;
227  rz_list_foreach (aranges, it, set) {
228  rz_cons_print(" Address Range Set\n");
229  rz_cons_printf(" Unit Length: 0x%" PFMT64x "\n", set->unit_length);
230  rz_cons_printf(" 64bit: %s\n", rz_str_bool(set->is_64bit));
231  rz_cons_printf(" Version: %u\n", (unsigned int)set->version);
232  rz_cons_printf(" Offset in .debug_info: 0x%" PFMT64x "\n", set->debug_info_offset);
233  rz_cons_printf(" Address Size: %u\n", (unsigned int)set->address_size);
234  rz_cons_printf(" Segment Size: %u\n", (unsigned int)set->segment_size);
235  rz_cons_print(" Ranges:\n");
236  rz_cons_print(" address length\n");
237  for (size_t i = 0; i < set->aranges_count; i++) {
238  rz_cons_printf(" 0x%016" PFMT64x " 0x%016" PFMT64x "\n", set->aranges[i].addr, set->aranges[i].length);
239  }
240  }
241  rz_cons_print("\n");
242 }
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100
RZ_API const char * rz_str_bool(int b)
Definition: str.c:3896
DWARF 3 Standard Section 6.1.2 Lookup by Address.
Definition: rz_bin_dwarf.h:931
RzBinDwarfARange * aranges
Definition: rz_bin_dwarf.h:939

References rz_bin_dwarf_arange_t::addr, rz_bin_dwarf_arange_set_t::address_size, rz_bin_dwarf_arange_set_t::aranges, rz_bin_dwarf_arange_set_t::aranges_count, rz_bin_dwarf_arange_set_t::debug_info_offset, i, rz_bin_dwarf_arange_set_t::is_64bit, rz_bin_dwarf_arange_t::length, PFMT64x, rz_cons_printf(), rz_return_if_fail, rz_str_bool(), rz_bin_dwarf_arange_set_t::segment_size, rz_bin_dwarf_arange_set_t::unit_length, and rz_bin_dwarf_arange_set_t::version.

Referenced by bin_dwarf().

◆ rz_core_bin_dwarf_print_attr_value()

RZ_API void rz_core_bin_dwarf_print_attr_value ( const RzBinDwarfAttrValue val)

Definition at line 32 of file cdwarf.c.

32  {
33  size_t i;
35 
36  switch (val->attr_form) {
37  case DW_FORM_block:
38  case DW_FORM_block1:
39  case DW_FORM_block2:
40  case DW_FORM_block4:
41  case DW_FORM_exprloc:
42  rz_cons_printf("%" PFMT64u " byte block:", val->block.length);
43  for (i = 0; i < val->block.length; i++) {
44  rz_cons_printf(" 0x%02x", val->block.data[i]);
45  }
46  break;
47  case DW_FORM_data1:
48  case DW_FORM_data2:
49  case DW_FORM_data4:
50  case DW_FORM_data8:
51  case DW_FORM_data16:
52  rz_cons_printf("%" PFMT64u "", val->uconstant);
53  if (val->attr_name == DW_AT_language) {
54  const char *lang_name = rz_bin_dwarf_get_lang_name(val->uconstant);
55  if (lang_name) {
56  rz_cons_printf(" (%s)", lang_name);
57  }
58  }
59  break;
60  case DW_FORM_string:
61  if (val->string.content) {
62  rz_cons_printf("%s", val->string.content);
63  } else {
64  rz_cons_print("No string found");
65  }
66  break;
67  case DW_FORM_flag:
68  rz_cons_printf("%u", val->flag);
69  break;
70  case DW_FORM_sdata:
71  rz_cons_printf("%" PFMT64d "", val->sconstant);
72  break;
73  case DW_FORM_udata:
74  rz_cons_printf("%" PFMT64u "", val->uconstant);
75  break;
76  case DW_FORM_ref_addr:
77  case DW_FORM_ref1:
78  case DW_FORM_ref2:
79  case DW_FORM_ref4:
80  case DW_FORM_ref8:
81  case DW_FORM_ref_sig8:
82  case DW_FORM_ref_udata:
83  case DW_FORM_ref_sup4:
84  case DW_FORM_ref_sup8:
85  case DW_FORM_sec_offset:
86  rz_cons_printf("<0x%" PFMT64x ">", val->reference);
87  break;
89  rz_cons_print("1");
90  break;
91  case DW_FORM_strx:
92  case DW_FORM_strx1:
93  case DW_FORM_strx2:
94  case DW_FORM_strx3:
95  case DW_FORM_strx4:
96  case DW_FORM_line_ptr:
97  case DW_FORM_strp_sup:
98  case DW_FORM_strp:
99  rz_cons_printf("(indirect string, offset: 0x%" PFMT64x "): %s",
100  val->string.offset, val->string.content);
101  break;
102  case DW_FORM_addr:
103  case DW_FORM_addrx:
104  case DW_FORM_addrx1:
105  case DW_FORM_addrx2:
106  case DW_FORM_addrx3:
107  case DW_FORM_addrx4:
108  case DW_FORM_loclistx:
109  case DW_FORM_rnglistx:
110  rz_cons_printf("0x%" PFMT64x "", val->address);
111  break;
113  rz_cons_printf("0x%" PFMT64d "", val->uconstant);
114  break;
115  default:
116  rz_cons_printf("Unknown attr value form %" PFMT64d "\n", val->attr_form);
117  break;
118  };
119 }
ut16 val
Definition: armass64_const.h:6
RZ_API const char * rz_bin_dwarf_get_lang_name(ut64 lang)
Definition: dwarf.c:387
#define DW_FORM_strx4
Definition: rz_bin_dwarf.h:317
#define DW_FORM_strx3
Definition: rz_bin_dwarf.h:316
#define DW_FORM_exprloc
Definition: rz_bin_dwarf.h:301
#define DW_FORM_sdata
Definition: rz_bin_dwarf.h:290
#define DW_FORM_addrx4
Definition: rz_bin_dwarf.h:321
#define DW_FORM_udata
Definition: rz_bin_dwarf.h:292
#define DW_FORM_ref_sup8
Definition: rz_bin_dwarf.h:313
#define DW_FORM_strx
Definition: rz_bin_dwarf.h:303
#define DW_FORM_addrx3
Definition: rz_bin_dwarf.h:320
#define DW_AT_language
Definition: rz_bin_dwarf.h:143
#define DW_FORM_ref_udata
Definition: rz_bin_dwarf.h:298
#define DW_FORM_block2
Definition: rz_bin_dwarf.h:280
#define DW_FORM_addr
Definition: rz_bin_dwarf.h:279
#define DW_FORM_data16
Definition: rz_bin_dwarf.h:307
#define DW_FORM_line_ptr
Definition: rz_bin_dwarf.h:308
#define DW_FORM_ref_sup4
Definition: rz_bin_dwarf.h:305
#define DW_FORM_ref_sig8
Definition: rz_bin_dwarf.h:309
#define DW_FORM_implicit_const
Definition: rz_bin_dwarf.h:310
#define DW_FORM_block1
Definition: rz_bin_dwarf.h:287
#define DW_FORM_block
Definition: rz_bin_dwarf.h:286
#define DW_FORM_strx1
Definition: rz_bin_dwarf.h:314
#define DW_FORM_ref_addr
Definition: rz_bin_dwarf.h:293
#define DW_FORM_strx2
Definition: rz_bin_dwarf.h:315
#define DW_FORM_string
Definition: rz_bin_dwarf.h:285
#define DW_FORM_block4
Definition: rz_bin_dwarf.h:281
#define DW_FORM_addrx2
Definition: rz_bin_dwarf.h:319
#define DW_FORM_addrx1
Definition: rz_bin_dwarf.h:318
#define DW_FORM_data2
Definition: rz_bin_dwarf.h:282
#define DW_FORM_flag_present
Definition: rz_bin_dwarf.h:302
#define DW_FORM_flag
Definition: rz_bin_dwarf.h:289
#define DW_FORM_data4
Definition: rz_bin_dwarf.h:283
#define DW_FORM_data1
Definition: rz_bin_dwarf.h:288
#define DW_FORM_strp_sup
Definition: rz_bin_dwarf.h:306
#define DW_FORM_data8
Definition: rz_bin_dwarf.h:284
#define DW_FORM_ref2
Definition: rz_bin_dwarf.h:295
#define DW_FORM_ref8
Definition: rz_bin_dwarf.h:297
#define DW_FORM_addrx
Definition: rz_bin_dwarf.h:304
#define DW_FORM_rnglistx
Definition: rz_bin_dwarf.h:312
#define DW_FORM_strp
Definition: rz_bin_dwarf.h:291
#define DW_FORM_ref1
Definition: rz_bin_dwarf.h:294
#define DW_FORM_loclistx
Definition: rz_bin_dwarf.h:311
#define DW_FORM_ref4
Definition: rz_bin_dwarf.h:296
#define DW_FORM_sec_offset
Definition: rz_bin_dwarf.h:300

References DW_AT_language, DW_FORM_addr, DW_FORM_addrx, DW_FORM_addrx1, DW_FORM_addrx2, DW_FORM_addrx3, DW_FORM_addrx4, DW_FORM_block, DW_FORM_block1, DW_FORM_block2, DW_FORM_block4, DW_FORM_data1, DW_FORM_data16, DW_FORM_data2, DW_FORM_data4, DW_FORM_data8, DW_FORM_exprloc, DW_FORM_flag, DW_FORM_flag_present, DW_FORM_implicit_const, DW_FORM_line_ptr, DW_FORM_loclistx, DW_FORM_ref1, DW_FORM_ref2, DW_FORM_ref4, DW_FORM_ref8, DW_FORM_ref_addr, DW_FORM_ref_sig8, DW_FORM_ref_sup4, DW_FORM_ref_sup8, DW_FORM_ref_udata, DW_FORM_rnglistx, DW_FORM_sdata, DW_FORM_sec_offset, DW_FORM_string, DW_FORM_strp, DW_FORM_strp_sup, DW_FORM_strx, DW_FORM_strx1, DW_FORM_strx2, DW_FORM_strx3, DW_FORM_strx4, DW_FORM_udata, i, PFMT64d, PFMT64u, PFMT64x, rz_bin_dwarf_get_lang_name(), rz_cons_printf(), rz_return_if_fail, and val.

Referenced by rz_core_bin_dwarf_print_debug_info().

◆ rz_core_bin_dwarf_print_debug_info()

RZ_API void rz_core_bin_dwarf_print_debug_info ( const RzBinDwarfDebugInfo inf)

Definition at line 121 of file cdwarf.c.

121  {
122  size_t i, j, k;
123  RzBinDwarfDie *dies;
124  RzBinDwarfAttrValue *values;
125 
127 
128  for (i = 0; i < inf->count; i++) {
129  rz_cons_print("\n");
130  rz_cons_printf(" Compilation Unit @ offset 0x%" PFMT64x ":\n", inf->comp_units[i].offset);
131  rz_cons_printf(" Length: 0x%" PFMT64x "\n", inf->comp_units[i].hdr.length);
132  rz_cons_printf(" Version: %d\n", inf->comp_units[i].hdr.version);
133  rz_cons_printf(" Abbrev Offset: 0x%" PFMT64x "\n", inf->comp_units[i].hdr.abbrev_offset);
134  rz_cons_printf(" Pointer Size: %d\n", inf->comp_units[i].hdr.address_size);
135  const char *unit_type_name = rz_bin_dwarf_get_unit_type_name(inf->comp_units[i].hdr.unit_type);
136  if (unit_type_name) {
137  rz_cons_printf(" Unit Type: %s\n", unit_type_name);
138  }
139  rz_cons_print("\n");
140 
141  dies = inf->comp_units[i].dies;
142 
143  for (j = 0; j < inf->comp_units[i].count; j++) {
144  rz_cons_printf("<0x%" PFMT64x ">: Abbrev Number: %-4" PFMT64u " ", dies[j].offset, dies[j].abbrev_code);
145 
146  const char *tag_name = rz_bin_dwarf_get_tag_name(dies[j].tag);
147  if (tag_name) {
148  rz_cons_printf("(%s)\n", tag_name);
149  } else {
150  rz_cons_print("(Unknown abbrev tag)\n");
151  }
152 
153  if (!dies[j].abbrev_code) {
154  continue;
155  }
156  values = dies[j].attr_values;
157 
158  for (k = 0; k < dies[j].count; k++) {
159  if (!values[k].attr_name) {
160  continue;
161  }
162  const char *attr_name = rz_bin_dwarf_get_attr_name(values[k].attr_name);
163  if (attr_name) {
164  rz_cons_printf(" %-25s : ", attr_name);
165  } else {
166  rz_cons_printf(" AT_UNKWN [0x%-3" PFMT64x "]\t : ", values[k].attr_name);
167  }
169  rz_cons_printf("\n");
170  }
171  }
172  }
173 }
RZ_API void rz_core_bin_dwarf_print_attr_value(const RzBinDwarfAttrValue *val)
Definition: cdwarf.c:32
const char * k
Definition: dsignal.c:11
RZ_API const char * rz_bin_dwarf_get_unit_type_name(ut64 unit_type)
Definition: dwarf.c:380
voidpf uLong offset
Definition: ioapi.h:144
RzBinDwarfAttrValue * attr_values
Definition: rz_bin_dwarf.h:756
int inf(FILE *source, FILE *dest)
Definition: zpipe.c:92

References RzBinDwarfDie::attr_values, RzBinDwarfDie::count, i, inf(), k, PFMT64u, PFMT64x, rz_bin_dwarf_get_attr_name(), rz_bin_dwarf_get_tag_name(), rz_bin_dwarf_get_unit_type_name(), rz_cons_printf(), rz_core_bin_dwarf_print_attr_value(), rz_return_if_fail, and test-lz4-versions::tag.

Referenced by bin_dwarf().

◆ rz_core_bin_dwarf_print_line_units()

RZ_API void rz_core_bin_dwarf_print_line_units ( RzList lines)

Definition at line 343 of file cdwarf.c.

343  {
345  rz_cons_print("Raw dump of debug contents of section .debug_line:\n\n");
346  RzListIter *it;
347  RzBinDwarfLineUnit *unit;
348  bool first = true;
349  rz_list_foreach (lines, it, unit) {
350  if (first) {
351  first = false;
352  } else {
353  rz_cons_print("\n");
354  }
355  rz_cons_print(" Header information:\n");
356  rz_cons_printf(" Length: %" PFMT64u "\n", unit->header.unit_length);
357  rz_cons_printf(" DWARF Version: %d\n", unit->header.version);
358  rz_cons_printf(" Header Length: %" PFMT64d "\n", unit->header.header_length);
359  rz_cons_printf(" Minimum Instruction Length: %d\n", unit->header.min_inst_len);
360  rz_cons_printf(" Maximum Operations per Instruction: %d\n", unit->header.max_ops_per_inst);
361  rz_cons_printf(" Initial value of 'is_stmt': %d\n", unit->header.default_is_stmt);
362  rz_cons_printf(" Line Base: %d\n", unit->header.line_base);
363  rz_cons_printf(" Line Range: %d\n", unit->header.line_range);
364  rz_cons_printf(" Opcode Base: %d\n\n", unit->header.opcode_base);
365  rz_cons_print(" Opcodes:\n");
366  for (size_t i = 1; i < unit->header.opcode_base; i++) {
367  rz_cons_printf(" Opcode %zu has %d arg\n", i, unit->header.std_opcode_lengths[i - 1]);
368  }
369  rz_cons_print("\n");
370  if (unit->header.include_dirs_count && unit->header.include_dirs) {
371  rz_cons_printf(" The Directory Table:\n");
372  for (size_t i = 0; i < unit->header.include_dirs_count; i++) {
373  rz_cons_printf(" %u %s\n", (unsigned int)i + 1, unit->header.include_dirs[i]);
374  }
375  }
376  if (unit->header.file_names_count && unit->header.file_names) {
377  rz_cons_print("\n");
378  rz_cons_print(" The File Name Table:\n");
379  rz_cons_print(" Entry Dir Time Size Name\n");
380  for (size_t i = 0; i < unit->header.file_names_count; i++) {
382  rz_cons_printf(" %u %" PFMT32u " %" PFMT32u " %" PFMT32u " %s\n",
383  (unsigned int)i + 1, f->id_idx, f->mod_time, f->file_len, f->name);
384  }
385  rz_cons_print("\n");
386  }
387  if (unit->ops_count && unit->ops) {
388  // also execute all ops simultaneously which gives us nice intermediate value printing
391  rz_cons_print(" Line Number Statements:\n");
392  for (size_t i = 0; i < unit->ops_count; i++) {
393  rz_bin_dwarf_line_op_run(&unit->header, &regs, &unit->ops[i], NULL, NULL, NULL);
394  rz_cons_print(" ");
395  RzBinDwarfLineOp *op = &unit->ops[i];
396  print_line_op(op, &unit->header, &regs);
397  if (op->type == RZ_BIN_DWARF_LINE_OP_TYPE_EXT && op->opcode == DW_LNE_end_sequence && i + 1 < unit->ops_count) {
398  // extra newline for nice sequence separation
399  rz_cons_print("\n");
400  }
401  }
402  }
403  }
404  rz_cons_print("\n");
405 }
static RzBinSourceLineInfo * lines(RzBinFile *bf)
Definition: bin_symbols.c:427
static void print_line_op(RzBinDwarfLineOp *op, RzBinDwarfLineHeader *hdr, RZ_NULLABLE RzBinDwarfSMRegisters *regs)
Definition: cdwarf.c:247
#define NULL
Definition: cris-opc.c:27
RZ_API bool rz_bin_dwarf_line_op_run(const RzBinDwarfLineHeader *hdr, RzBinDwarfSMRegisters *regs, RzBinDwarfLineOp *op, RZ_NULLABLE RzBinSourceLineInfoBuilder *bob, RZ_NULLABLE RzBinDwarfDebugInfo *info, RZ_NULLABLE RzBinDwarfLineFileCache fnc)
Execute a single line op on regs and optionally store the resulting line info in bob.
Definition: dwarf.c:851
RZ_API void rz_bin_dwarf_line_header_reset_regs(const RzBinDwarfLineHeader *hdr, RzBinDwarfSMRegisters *regs)
Definition: dwarf.c:824
#define PFMT32u
Definition: rz_types.h:409
ut8 * std_opcode_lengths
The number of LEB128 operands for each of the standard opcodes From standard_opcode_lengths in DWARF ...
Definition: rz_bin_dwarf.h:850
RzBinDwarfLineFileEntry * file_names
Definition: rz_bin_dwarf.h:854
DWARF 3 Standard Section 6.2 Line Number Information This contains the entire raw line info for one c...
Definition: rz_bin_dwarf.h:891
RzBinDwarfLineHeader header
Definition: rz_bin_dwarf.h:892
RzBinDwarfLineOp * ops
Definition: rz_bin_dwarf.h:895
Definition: rz_bin_dwarf.h:822

References RzBinDwarfLineHeader::default_is_stmt, DW_LNE_end_sequence, f, RzBinDwarfLineHeader::file_names, RzBinDwarfLineHeader::file_names_count, RzBinDwarfLineUnit::header, RzBinDwarfLineHeader::header_length, i, RzBinDwarfLineHeader::include_dirs, RzBinDwarfLineHeader::include_dirs_count, RzBinDwarfLineHeader::line_base, RzBinDwarfLineHeader::line_range, lines(), RzBinDwarfLineHeader::max_ops_per_inst, RzBinDwarfLineHeader::min_inst_len, NULL, RzBinDwarfLineHeader::opcode_base, RzBinDwarfLineUnit::ops, RzBinDwarfLineUnit::ops_count, PFMT32u, PFMT64d, PFMT64u, print_line_op(), regs, rz_bin_dwarf_line_header_reset_regs(), rz_bin_dwarf_line_op_run(), RZ_BIN_DWARF_LINE_OP_TYPE_EXT, rz_cons_printf(), rz_return_if_fail, RzBinDwarfLineHeader::std_opcode_lengths, RzBinDwarfLineHeader::unit_length, and RzBinDwarfLineHeader::version.

Referenced by bin_dwarf().

◆ rz_core_bin_dwarf_print_loc()

RZ_API void rz_core_bin_dwarf_print_loc ( HtUP *  loc_table,
int  addr_size 
)

Definition at line 196 of file cdwarf.c.

196  {
197  rz_return_if_fail(loc_table);
198  rz_cons_print("\nContents of the .debug_loc section:\n");
199  RzList /*<RzBinDwarfLocList *>*/ *sort_list = rz_list_new();
200  /* sort the table contents by offset and print sorted
201  a bit ugly, but I wanted to decouple the parsing and printing */
202  ht_up_foreach(loc_table, sort_loclists, sort_list);
203  RzListIter *i;
204  RzBinDwarfLocList *loc_list;
205  rz_list_foreach (sort_list, i, loc_list) {
206  RzListIter *j;
208  ut64 base_offset = loc_list->offset;
209  rz_list_foreach (loc_list->list, j, range) {
210  rz_cons_printf("0x%" PFMT64x " 0x%" PFMT64x " 0x%" PFMT64x "\n", base_offset, range->start, range->end);
211  base_offset += addr_size * 2;
212  if (range->expression) {
213  base_offset += 2 + range->expression->length; /* 2 bytes for expr length */
214  }
215  }
216  rz_cons_printf("0x%" PFMT64x " <End of list>\n", base_offset);
217  }
218  rz_cons_print("\n");
219  rz_list_free(sort_list);
220 }
static bool sort_loclists(void *user, const ut64 key, const void *value)
Definition: cdwarf.c:189
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
Definition: list.c:235
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
Definition: rz_bin_dwarf.h:912

References i, rz_bin_dwarf_loc_list_t::list, rz_bin_dwarf_loc_list_t::offset, PFMT64x, capstone::range, rz_cons_printf(), rz_list_free(), rz_list_new(), rz_return_if_fail, sort_loclists(), and ut64().

Referenced by bin_dwarf().

◆ sort_loclists()

static bool sort_loclists ( void *  user,
const ut64  key,
const void *  value 
)
static

Definition at line 189 of file cdwarf.c.

189  {
191  RzList *sort_list = user;
192  rz_list_add_sorted(sort_list, loc_list, offset_comp);
193  return true;
194 }
static int offset_comp(const void *a, const void *b)
Definition: cdwarf.c:175
static int value
Definition: cmd_api.c:93
RZ_API RZ_BORROW RzListIter * rz_list_add_sorted(RZ_NONNULL RzList *list, void *data, RZ_NONNULL RzListComparator cmp)
Adds an element to a sorted list via the RzListComparator.
Definition: list.c:518

References offset_comp(), rz_list_add_sorted(), and value.

Referenced by rz_core_bin_dwarf_print_loc().