Fix #9612 - Skip dummy nodes in graph navigation (#9622)

- This reverts commit 747de793c369f29238abaf8138202a4894d4c8c1.
- And skip dummy nodes for VVtf
This commit is contained in:
Riccardo Schirone 2018-03-07 22:14:12 +01:00 committed by radare
parent a4de64b169
commit a5811d1a2b
6 changed files with 25 additions and 57 deletions

View File

@ -1699,19 +1699,6 @@ static int cb_scrstrconv(void *user, void *data) {
return true;
}
static int cb_graphdummy(void *user, void *data) {
RCore *core = (RCore*) user;
RConfigNode *node = (RConfigNode *) data;
if (!strcmp (node->value, "?")) {
r_cons_printf ("dot\ngml\ngmlfcn\n");
return false;
}
if (core->graph) {
core->graph->use_dummynodes = node->i_value;
}
return true;
}
static int cb_graphformat(void *user, void *data) {
RConfigNode *node = (RConfigNode *) data;
if (!strcmp (node->value, "?")) {
@ -2735,7 +2722,6 @@ R_API int r_core_config_init(RCore *core) {
SETPREF ("tcp.islocal", "false", "Bind a loopback for tcp command server");
/* graph */
SETCB ("graph.dummy", "true", &cb_graphdummy, "Add dummy nodes to improve edge");
SETPREF ("graph.comments", "true", "Show disasm comments in graph");
SETPREF ("graph.cmtright", "false", "Show comments at right");
SETCB ("graph.format", "dot", &cb_graphformat, "Specify output format for graphs (dot, gml, gmlfcn)");

View File

@ -5670,19 +5670,11 @@ static void cmd_agraph_print(RCore *core, const char *input) {
r_core_cmd_help (core, help_msg_agg);
break;
default:
if (!core->graph) {
core->graph = r_agraph_new (NULL, r_config_get_i (core->config, "graph.dummy"));
}
if (core->graph) {
if (!core->graph->can) {
core->graph->can = r_cons_canvas_new (1, 1);
}
core->graph->can->linemode = r_config_get_i (core->config, "graph.linemode");
core->graph->can->color = r_config_get_i (core->config, "scr.color");
r_agraph_set_title (core->graph,
r_config_get (core->config, "graph.title"));
r_agraph_print (core->graph);
}
core->graph->can->linemode = r_config_get_i (core->config, "graph.linemode");
core->graph->can->color = r_config_get_i (core->config, "scr.color");
r_agraph_set_title (core->graph,
r_config_get (core->config, "graph.title"));
r_agraph_print (core->graph);
break;
}
}

View File

@ -1840,6 +1840,8 @@ R_API bool r_core_init(RCore *core) {
core->fs = r_fs_new ();
core->flags = r_flag_new ();
core->flags->cb_printf = r_cons_printf;
core->graph = r_agraph_new (r_cons_canvas_new (1, 1));
core->graph->need_reload_nodes = false;
core->asmqjmps_size = R_CORE_ASMQJMPS_NUM;
if (sizeof (ut64) * core->asmqjmps_size < core->asmqjmps_size) {
core->asmqjmps_size = 0;
@ -1899,8 +1901,6 @@ R_API bool r_core_init(RCore *core) {
r_config_set (core->config, "asm.arch", R_SYS_ARCH);
r_bp_use (core->dbg->bp, R_SYS_ARCH, core->anal->bits);
update_sdb (core);
core->graph = r_agraph_new (NULL, r_config_get_i (core->config, "graph.dummy"));
core->graph->need_reload_nodes = false;
return 0;
}

View File

@ -1648,9 +1648,11 @@ void backedge_info (RAGraph *g) {
arr[i][0] = tc;
arr[i][1] = tc + tl;
}
if (arr[i][0] > tc) {
arr[i][0] = tc;
}
if (arr[i][1] < tc + tl) {
arr[i][1] = tc + tl;
}
@ -1797,14 +1799,7 @@ static void set_layout(RAGraph *g) {
remove_cycles (g);
assign_layers (g);
if (g->use_dummynodes) {
// running this makes the graph look better, but 't' and 'f' keys
// dont work well because there are dummy nodes still in the graph
// which are not valid and should be fixed. The graph.dummy config
// var is the one used to choose this behaviour until the fix is done.
// also, layout times are improved without graph.dummy
create_dummy_nodes (g);
}
create_dummy_nodes (g);
create_layers (g);
minimize_crossings (g);
@ -2884,16 +2879,14 @@ static int agraph_reload_nodes(RAGraph *g, RCore *core, RAnalFunction *fcn) {
static void follow_nth(RAGraph *g, int nth) {
const RGraphNode *cn = r_graph_nth_neighbour (g->graph, g->curnode, nth);
RGraphNode *node;
RListIter *iter;
r_list_foreach (g->curnode->out_nodes, iter, node) {
RANode *an = node->data;
if (an->is_dummy) {
eprintf ("if there's a dummy node it means the graph hasnt been generated properly\n");
}
RANode *a = get_anode (cn);
while (a && a->is_dummy) {
cn = r_graph_nth_neighbour (g->graph, a->gnode, 0);
a = get_anode (cn);
}
if (cn) {
r_agraph_set_curnode (g, get_anode (cn));
if (a) {
r_agraph_set_curnode (g, a);
}
}
@ -3184,13 +3177,12 @@ static void agraph_toggle_speed(RAGraph *g, RCore *core) {
g->movspeed = g->movspeed == DEFAULT_SPEED? alt: DEFAULT_SPEED;
}
static void agraph_init(RAGraph *g, bool usedummy) {
static void agraph_init(RAGraph *g) {
g->is_callgraph = false;
g->is_instep = false;
g->need_reload_nodes = true;
g->force_update_seek = true;
g->graph = r_graph_new ();
g->use_dummynodes = usedummy;
g->nodes = sdb_new0 (); // XXX leak
g->edgemode = 2;
g->zoom = ZOOM_DEFAULT;
@ -3435,13 +3427,13 @@ R_API void r_agraph_free(RAGraph *g) {
}
}
R_API RAGraph *r_agraph_new(RConsCanvas *can, bool usedummy) {
R_API RAGraph *r_agraph_new(RConsCanvas *can) {
RAGraph *g = R_NEW0 (RAGraph);
if (!g) {
return NULL;
}
g->can = can;
agraph_init (g, usedummy);
agraph_init (g);
agraph_sdb_init (g);
return g;
}
@ -3555,7 +3547,6 @@ static void graph_breakpoint(RCore *core) {
static void graph_continue(RCore *core) {
r_core_cmd (core, "dc", 0);
}
static void applyDisMode(RCore *core) {
switch (disMode) {
case 0:
@ -3627,7 +3618,7 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int
r_cons_canvas_free (can);
return false;
}
g = r_agraph_new (can, r_config_get_i (core->config, "graph.dummy"));
g = r_agraph_new (can);
if (!g) {
r_cons_canvas_free (can);
r_config_restore (hc);

View File

@ -439,7 +439,7 @@ static int GH(print_double_linked_list_bin_simple)(RCore *core, GHT bin, GH(RHea
}
static int GH(print_double_linked_list_bin_graph)(RCore *core, GHT bin, GH(RHeap_MallocState) *main_arena, GHT brk_start) {
RAGraph *g = r_agraph_new (r_cons_canvas_new (1, 1), r_config_get_i (core->config, "graph.dummy"));
RAGraph *g = r_agraph_new (r_cons_canvas_new (1, 1));
GHT next = GHT_MAX;
char title[256], chunk[256];
RANode *bin_node = NULL, *prev_node = NULL, *next_node = NULL;
@ -699,7 +699,7 @@ static void GH(print_mmap_graph)(RCore *core, GH(RHeap_MallocState) *malloc_stat
can->linemode = r_config_get_i (core->config, "graph.linemode");
can->color = r_config_get_i (core->config, "scr.color");
core->cons->use_utf8 = r_config_get_i (core->config, "scr.utf8");
RAGraph *g = r_agraph_new (NULL, r_config_get_i (core->config, "graph.dummy"));
RAGraph *g = r_agraph_new (can);
if (!g) {
r_cons_canvas_free (can);
r_config_restore (hc);
@ -800,7 +800,7 @@ static void GH(print_heap_graph)(RCore *core, GH(RHeap_MallocState) *main_arena,
can->linemode = r_config_get_i (core->config, "graph.linemode");
can->color = r_config_get_i (core->config, "scr.color");
core->cons->use_utf8 = r_config_get_i (core->config, "scr.utf8");
RAGraph *g = r_agraph_new (can, r_config_get_i (core->config, "graph.dummy"));
RAGraph *g = r_agraph_new (can);
if (!g) {
r_cons_canvas_free (can);
r_config_restore (hc);

View File

@ -873,7 +873,6 @@ typedef struct r_ascii_graph_t {
bool is_callgraph;
int zoom;
int movspeed;
bool use_dummynodes;
RANode *update_seek_on;
bool need_reload_nodes;
@ -898,7 +897,7 @@ typedef struct r_ascii_graph_t {
} RAGraph;
#ifdef R_API
R_API RAGraph *r_agraph_new(RConsCanvas *can, bool usedummy);
R_API RAGraph *r_agraph_new(RConsCanvas *can);
R_API void r_agraph_free(RAGraph *g);
R_API void r_agraph_reset(RAGraph *g);
R_API void r_agraph_set_title(RAGraph *g, const char *title);