Skip to content

Commit

Permalink
Use HtUP for storing trace nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
pelijah authored and ret2libc committed Mar 1, 2021
1 parent ea879f7 commit 8a69088
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
18 changes: 8 additions & 10 deletions librz/core/cmd_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -3620,17 +3620,15 @@ static void rz_core_cmd_bp(RzCore *core, const char *input) {
free(str);
}

static RTreeNode *add_trace_tree_child(Sdb *db, RTree *t, RTreeNode *cur, ut64 addr) {
struct trace_node *t_node;
char dbkey[TN_KEY_LEN];

snprintf(dbkey, TN_KEY_LEN, TN_KEY_FMT, addr);
t_node = (struct trace_node *)(size_t)sdb_num_get(db, dbkey, NULL);
static RTreeNode *add_trace_tree_child(HtUP *ht, RTree *t, RTreeNode *cur, ut64 addr) {
struct trace_node *t_node = ht_up_find(ht, addr, NULL);
if (!t_node) {
t_node = RZ_NEW0(struct trace_node);
t_node->addr = addr;
t_node->refs = 1;
sdb_num_set(db, dbkey, (ut64)(size_t)t_node, 0);
if (t_node) {
t_node->addr = addr;
t_node->refs = 1;
ht_up_insert(ht, addr, t_node);
}
} else {
t_node->refs++;
}
Expand Down Expand Up @@ -3670,7 +3668,7 @@ static void trace_traverse(RTree *t) {
static void do_debug_trace_calls(RzCore *core, ut64 from, ut64 to, ut64 final_addr) {
bool trace_libs = rz_config_get_i(core->config, "dbg.trace.libs");
bool shallow_trace = rz_config_get_i(core->config, "dbg.trace.inrange");
Sdb *tracenodes = core->dbg->tracenodes;
HtUP *tracenodes = core->dbg->tracenodes;
RTree *tr = core->dbg->tree;
RzDebug *dbg = core->dbg;
ut64 debug_to = UT64_MAX;
Expand Down
19 changes: 8 additions & 11 deletions librz/debug/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ static const char *rz_debug_str_callback(RNum *userptr, ut64 off, int *ok) {
return NULL;
}

void free_tracenodes_kv(HtUPKv *kv) {
free(kv->value);
}

RZ_API RzDebug *rz_debug_new(int hard) {
RzDebug *dbg = RZ_NEW0(RzDebug);
if (!dbg) {
Expand All @@ -368,7 +372,7 @@ RZ_API RzDebug *rz_debug_new(int hard) {
dbg->bpsize = 1;
dbg->tid = -1;
dbg->tree = rz_tree_new();
dbg->tracenodes = sdb_new0();
dbg->tracenodes = ht_up_new(NULL, free_tracenodes_kv, NULL);
dbg->swstep = 0;
dbg->stop_all_threads = false;
dbg->trace = rz_debug_trace_new();
Expand All @@ -395,15 +399,9 @@ RZ_API RzDebug *rz_debug_new(int hard) {
return dbg;
}

static int free_tracenodes_entry(RzDebug *dbg, const char *k, const char *v) {
ut64 v_num = rz_num_get(NULL, v);
free((void *)(size_t)v_num);
return true;
}

RZ_API void rz_debug_tracenodes_reset(RzDebug *dbg) {
sdb_foreach(dbg->tracenodes, (SdbForeachCallback)free_tracenodes_entry, dbg);
sdb_reset(dbg->tracenodes);
ht_up_free(dbg->tracenodes);
dbg->tracenodes = ht_up_new(NULL, free_tracenodes_kv, NULL);
}

RZ_API RzDebug *rz_debug_free(RzDebug *dbg) {
Expand All @@ -418,8 +416,7 @@ RZ_API RzDebug *rz_debug_free(RzDebug *dbg) {
rz_num_free(dbg->num);
sdb_free(dbg->sgnls);
rz_tree_free(dbg->tree);
sdb_foreach(dbg->tracenodes, (SdbForeachCallback)free_tracenodes_entry, dbg);
sdb_free(dbg->tracenodes);
ht_up_free(dbg->tracenodes);
rz_list_free(dbg->plugins);
rz_list_free(dbg->call_frames);
free(dbg->btalgo);
Expand Down
2 changes: 1 addition & 1 deletion librz/include/rz_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ typedef struct rz_debug_t {

/* tracing vars */
RzDebugTrace *trace;
Sdb *tracenodes;
HtUP *tracenodes;
RTree *tree;
RzList *call_frames;

Expand Down

0 comments on commit 8a69088

Please sign in to comment.