diff --git a/librz/core/cconfig.c b/librz/core/cconfig.c index 98290f44fec..63e07becd4f 100644 --- a/librz/core/cconfig.c +++ b/librz/core/cconfig.c @@ -3032,6 +3032,7 @@ RZ_API int rz_core_config_init(RzCore *core) { SETBPREF("asm.dwarf", "false", "Show dwarf comment at disassembly"); SETBPREF("asm.dwarf.abspath", "false", "Show absolute path in asm.dwarf"); SETBPREF("asm.dwarf.file", "true", "Show filename of asm.dwarf in pd"); + SETBPREF("asm.dwarf.lines", "false", "Show DWARF source line information at disassembly"); SETBPREF("asm.esil", "false", "Show ESIL instead of mnemonic"); SETBPREF("asm.nodup", "false", "Do not show dupped instructions (collapse disasm)"); SETBPREF("asm.emu", "false", "Run ESIL emulation analysis on disasm"); diff --git a/librz/core/disasm.c b/librz/core/disasm.c index 5dcb3f0daac..9008b09b51f 100644 --- a/librz/core/disasm.c +++ b/librz/core/disasm.c @@ -292,6 +292,7 @@ typedef struct { int _tabsoff; bool dwarfFile; bool dwarfAbspath; + bool dwarfShowLines; bool showpayloads; bool showrelocs; int cmtcount; @@ -349,7 +350,7 @@ static void ds_print_sysregs(RzDisasmState *ds); static void ds_print_fcn_name(RzDisasmState *ds); static void ds_print_as_string(RzDisasmState *ds); static bool ds_print_core_vmode(RzDisasmState *ds, int pos); -static void ds_print_dwarf(RzDisasmState *ds); +static void ds_print_dwarf(RzCore *core, RzCmdStateOutput *state, RzDisasmState *ds); static void ds_print_asmop_payload(RzDisasmState *ds, const ut8 *buf); static char *ds_esc_str(RzDisasmState *ds, const char *str, int len, const char **prefix_out, bool is_comment); static void ds_print_ptr(RzDisasmState *ds, int len, int idx); @@ -721,6 +722,7 @@ static RzDisasmState *ds_init(RzCore *core) { ds->show_dwarf = rz_config_get_b(core->config, "asm.dwarf"); ds->dwarfFile = rz_config_get_b(ds->core->config, "asm.dwarf.file"); ds->dwarfAbspath = rz_config_get_b(ds->core->config, "asm.dwarf.abspath"); + ds->dwarfShowLines = rz_config_get_b(ds->core->config, "asm.dwarf.lines"); ds->show_lines_call = ds->show_lines ? rz_config_get_b(core->config, "asm.lines.call") : false; ds->show_lines_ret = ds->show_lines ? rz_config_get_b(core->config, "asm.lines.ret") : false; ds->show_size = rz_config_get_b(core->config, "asm.size"); @@ -3811,7 +3813,40 @@ static void ds_align_comment(RzDisasmState *ds) { rz_cons_print(" "); } -static void ds_print_dwarf(RzDisasmState *ds) { +static void ds_print_dwarf(RzCore *core, RzCmdStateOutput *state, RzDisasmState *ds) { + + bool binFileExists = true; + bool SourceLineInfoExists = true; + RzBinFile *binfile = core->bin->cur; + RzBinSourceLineInfo *li = binfile->o->lines; + + if (ds->dwarfShowLines && ds->show_dwarf/* && SourceLineInfoExists && binFileExists*/) { + rz_cmd_state_output_array_start(state); + rz_cons_break_push(NULL, NULL); + RzBinSourceLineSample *linesampleinfo = NULL; + char *path = strdup(rz_config_get(core->config,"file.path")); + char *filename = strrchr(path,'/'); + + for (size_t i = 0; i < li->samples_count; i++) { + if (rz_cons_is_breaked()) { + break; + } + linesampleinfo = &li->samples[i]; + ds_align_comment(ds); + if (ds->vat == linesampleinfo->address) { + // rz_cons_printf("\tLine number%s", temps->file ? temps->file : "-"); + rz_cons_printf("\t ; %s:%s",filename,linesampleinfo->file ? linesampleinfo->file:""); + if (linesampleinfo->line) { + rz_cons_printf("%" PFMT32u "\n", linesampleinfo->line); + } else { + rz_cons_print("-\n"); + } + } + } + rz_cons_break_pop(); + rz_cmd_state_output_array_end(state); + } + if (ds->show_dwarf) { // TODO: cache value in ds int dwarfFile = (int)ds->dwarfFile + (int)ds->dwarfAbspath; @@ -5534,7 +5569,6 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u ds_adistrick_comments(ds); /* XXX: This is really cpu consuming.. need to be fixed */ ds_show_functions(ds); - if (ds->show_comments && !ds->show_comment_right) { ds_show_refs(ds); ds_build_op_str(ds, false); @@ -5556,7 +5590,6 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u } ds_show_comments_describe(ds); } - f = fcnIn(ds, ds->addr, 0); ds_begin_line(ds); ds_print_labels(ds, f); @@ -5576,7 +5609,6 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u } } } - //// int mi_type; bool mi_found = ds_print_meta_infos(ds, buf, len, idx, &mi_type); if (ds->asm_hint_pos == 0) { @@ -5592,7 +5624,7 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u ds_print_family(ds); ds_print_stackptr(ds); if (mi_found) { - ds_print_dwarf(ds); + ds_print_dwarf(core, state, ds); ret = ds_print_middle(ds, ret); ds_print_asmop_payload(ds, buf + addrbytes * idx); @@ -5632,7 +5664,7 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u ds_build_op_str(ds, true); ds_print_opstr(ds); ds_end_line_highlight(ds); - ds_print_dwarf(ds); + ds_print_dwarf(core, state, ds); ret = ds_print_middle(ds, ret); ds_print_asmop_payload(ds, buf + addrbytes * idx);