mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-27 08:12:44 +00:00
Bring back the DWARF
This commit is contained in:
parent
bdc1ec0a06
commit
952469afed
@ -1497,13 +1497,28 @@ R_API int r_bin_dwarf_parse_info(RBinDwarfDebugAbbrev *da, RBin *a, int mode) {
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
static RBinDwarfRow *r_bin_dwarf_row_new (ut64 addr, const char *file, int line, int col) {
|
||||
RBinDwarfRow *row = R_NEW0 (RBinDwarfRow);
|
||||
row->file = strdup (file);
|
||||
row->address = addr;
|
||||
row->line = line;
|
||||
row->column = 0;
|
||||
return row;
|
||||
}
|
||||
|
||||
static void r_bin_dwarf_row_free (void *p) {
|
||||
RBinDwarfRow *row = (RBinDwarfRow*)p;
|
||||
free (row->file);
|
||||
free (row);
|
||||
}
|
||||
|
||||
R_API RList *r_bin_dwarf_parse_line(RBin *a, int mode) {
|
||||
ut8 *buf;
|
||||
RList *list = NULL;
|
||||
int len, ret;
|
||||
RBinSection *section = getsection (a, "debug_line");
|
||||
RBinFile *binfile = a ? a->cur: NULL;
|
||||
if (binfile && section) {
|
||||
RList *list;
|
||||
len = section->size;
|
||||
if (len<1) {
|
||||
return NULL;
|
||||
@ -1515,12 +1530,31 @@ R_API RList *r_bin_dwarf_parse_line(RBin *a, int mode) {
|
||||
return NULL;
|
||||
}
|
||||
list = r_list_new (); // always return empty list wtf
|
||||
list->free = r_bin_dwarf_row_free;
|
||||
r_bin_dwarf_parse_line_raw2 (a, buf, len, mode);
|
||||
//sdb_query (binfile->sdb_addrinfo, "*");
|
||||
// k bin/cur/addrinfo/*
|
||||
SdbListIter *iter;
|
||||
SdbKv *kv;
|
||||
ls_foreach (binfile->sdb_addrinfo->ht->list, iter, kv) {
|
||||
if (!strncmp (kv->key, "0x", 2)) {
|
||||
ut64 addr;
|
||||
RBinDwarfRow *row;
|
||||
int line;
|
||||
char *file = strdup (kv->value);
|
||||
char *tok = strchr (file, '|');
|
||||
if (tok) {
|
||||
*tok++ = 0;
|
||||
line = atoi (tok);
|
||||
addr = r_num_math (NULL, kv->key);
|
||||
row = r_bin_dwarf_row_new (addr, file, line, 0);
|
||||
r_list_append (list, row);
|
||||
}
|
||||
free (file);
|
||||
}
|
||||
}
|
||||
free (buf);
|
||||
return list;
|
||||
}
|
||||
return NULL;
|
||||
return list;
|
||||
}
|
||||
|
||||
R_API RList *r_bin_dwarf_parse_aranges(RBin *a, int mode) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2011-2014 - earada, pancake */
|
||||
/* radare - LGPL - Copyright 2011-2015 - earada, pancake */
|
||||
|
||||
#include <r_core.h>
|
||||
|
||||
@ -435,6 +435,7 @@ static int bin_dwarf (RCore *core, int mode) {
|
||||
r_bin_dwarf_parse_info (da, core->bin, mode);
|
||||
r_bin_dwarf_parse_aranges (core->bin, mode);
|
||||
list = r_bin_dwarf_parse_line (core->bin, mode);
|
||||
eprintf ("LIST %d\n", r_list_length (list));
|
||||
r_bin_dwarf_free_debug_abbrev (da);
|
||||
free (da);
|
||||
}
|
||||
@ -446,8 +447,7 @@ static int bin_dwarf (RCore *core, int mode) {
|
||||
if (mode) {
|
||||
// TODO: use 'Cl' instead of CC
|
||||
const char *path = row->file;
|
||||
char *line = r_file_slurp_line (
|
||||
path, row->line-1, 0);
|
||||
char *line = r_file_slurp_line (path, row->line-1, 0);
|
||||
if (line) {
|
||||
r_str_filter (line, strlen (line));
|
||||
line = r_str_replace (line, "\"", "\\\"", 1);
|
||||
@ -455,8 +455,10 @@ static int bin_dwarf (RCore *core, int mode) {
|
||||
}
|
||||
// TODO: implement internal : if ((mode & R_CORE_BIN_SET)) {
|
||||
if ((mode & R_CORE_BIN_SET)) {
|
||||
r_core_cmdf (core, "\"CC %s:%d %s\"@0x%"PFMT64x"\n",
|
||||
row->file, row->line, line?line:"", row->address);
|
||||
char *cmt = r_str_newf ("%s:%d %s", row->file, row->line, line?line:"");
|
||||
r_meta_set_string (core->anal, R_META_TYPE_COMMENT,
|
||||
row->address, cmt);
|
||||
free (cmt);
|
||||
} else r_cons_printf ("\"CC %s:%d %s\"@0x%"PFMT64x"\n",
|
||||
row->file, row->line, line?line:"", row->address);
|
||||
free (line);
|
||||
@ -465,8 +467,8 @@ static int bin_dwarf (RCore *core, int mode) {
|
||||
}
|
||||
}
|
||||
r_cons_break_end ();
|
||||
r_list_purge (list);
|
||||
free (list);
|
||||
//r_list_purge (list);
|
||||
r_list_free (list);
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
|
@ -544,7 +544,6 @@ R_API RCoreFile *r_core_file_open_many(RCore *r, const char *file, int flags, ut
|
||||
const char *suppress_warning = r_config_get (r->config, "file.nowarn");
|
||||
int openmany = r_config_get_i (r->config, "file.openmany"), opened_count = 0;
|
||||
|
||||
|
||||
list_fds = r_io_open_many (r->io, file, flags, 0644);
|
||||
|
||||
if (!list_fds || r_list_length (list_fds) == 0 ) {
|
||||
|
@ -555,7 +555,7 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
ut64 address;
|
||||
const char *file;
|
||||
char *file;
|
||||
unsigned int line;
|
||||
unsigned int column;
|
||||
} RBinDwarfRow;
|
||||
|
Loading…
x
Reference in New Issue
Block a user