Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions librz/core/cmd/cmd_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -768,11 +768,17 @@ static ut64 addroflib(RzCore *core, const char *libname) {
rz_debug_map_sync(core->dbg);
// RzList *list = rz_debug_native_modules_get (core->dbg);
RzList *list = rz_debug_modules_list(core->dbg);
ut64 addr = UT64_MAX;
rz_list_foreach (list, iter, map) {
if (strstr(rz_file_basename(map->name), libname)) {
return map->addr;
addr = map->addr;
break;
}
}
rz_list_free(list);
if (addr != UT64_MAX) {
return addr;
}
rz_list_foreach (core->dbg->maps, iter, map) {
if (strstr(rz_file_basename(map->name), libname)) {
return map->addr;
Expand All @@ -781,20 +787,36 @@ static ut64 addroflib(RzCore *core, const char *libname) {
return UT64_MAX;
}

static RzDebugMap *debug_map_clone(RzDebugMap *m) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make it an API function.

RzDebugMap *c = rz_debug_map_new(m->name, m->addr, m->addr_end, m->perm, m->user);
if (c) {
c->offset = m->offset;
c->shared = m->shared;
c->file = rz_str_dup(m->file);
}
return c;
}

static RzDebugMap *get_closest_map(RzCore *core, ut64 addr) {
RzListIter *iter;
RzDebugMap *map;

rz_debug_map_sync(core->dbg);
RzList *list = rz_debug_modules_list(core->dbg);
RzDebugMap *found = NULL;
rz_list_foreach (list, iter, map) {
if (addr != UT64_MAX && (addr >= map->addr && addr < map->addr_end)) {
return map;
found = debug_map_clone(map);
break;
}
}
rz_list_free(list);
if (found) {
return found;
}
rz_list_foreach (core->dbg->maps, iter, map) {
if (addr != UT64_MAX && (addr >= map->addr && addr < map->addr_end)) {
return map;
return debug_map_clone(map);
}
}
return NULL;
Expand Down Expand Up @@ -1076,11 +1098,12 @@ RZ_IPI RzCmdStatus rz_cmd_debug_dmi_handler(RzCore *core, int argc, const char *
return RZ_CMD_STATUS_ERROR;
}
const char *file = map->file ? map->file : map->name;
if (!get_bin_info(core, file, map->addr, state, action, &filter)) {
bool ok = get_bin_info(core, file, map->addr, state, action, &filter);
if (!ok) {
RZ_LOG_ERROR("Failed to get binary information for map: '%s' in file: '%s'\n", map->name, file);
return RZ_CMD_STATUS_ERROR;
}
return RZ_CMD_STATUS_OK;
rz_debug_map_free(map);
return ok ? RZ_CMD_STATUS_OK : RZ_CMD_STATUS_ERROR;
}

RZ_IPI RzCmdStatus rz_cmd_debug_dmi_all_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state) {
Expand Down Expand Up @@ -1126,11 +1149,12 @@ RZ_IPI RzCmdStatus rz_cmd_debug_dmi_all_handler(RzCore *core, int argc, const ch
return RZ_CMD_STATUS_ERROR;
}
const char *file = map->file ? map->file : map->name;
if (!get_bin_info(core, file, map->addr, state, action, &filter)) {
bool ok = get_bin_info(core, file, map->addr, state, action, &filter);
if (!ok) {
RZ_LOG_ERROR("Failed to get binary information for map: '%s' in file: '%s'\n", map->name, file);
return RZ_CMD_STATUS_ERROR;
}
return RZ_CMD_STATUS_OK;
rz_debug_map_free(map);
return ok ? RZ_CMD_STATUS_OK : RZ_CMD_STATUS_ERROR;
}

RZ_IPI RzCmdStatus rz_cmd_debug_dmi_closest_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state) {
Expand Down
Loading