mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-27 07:00:30 +00:00
Bring back asm.trace and dbg.trace to life
This commit is contained in:
parent
211688f537
commit
6fcd870a5c
@ -1114,6 +1114,8 @@ static void r_core_debug_trace_calls (RCore *core) {
|
||||
RAnalOp aop;
|
||||
if (r_cons_singleton ()->breaked)
|
||||
break;
|
||||
if (r_debug_is_dead (core->dbg))
|
||||
break;
|
||||
r_debug_step (core->dbg, 1);
|
||||
r_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, R_FALSE);
|
||||
addr = r_debug_reg_get (core->dbg, "pc");
|
||||
@ -1251,10 +1253,13 @@ static int cmd_debug(void *data, const char *input) {
|
||||
|
||||
switch (input[0]) {
|
||||
case 't':
|
||||
// TODO: define ranges? to display only some traces, allow to scroll on this disasm? ~.. ?
|
||||
switch (input[1]) {
|
||||
case '?': {
|
||||
const char * help_message[] = {
|
||||
"Usage: dt", "", "Trace commands",
|
||||
"dt", "", "List all traces ",
|
||||
"dtd", "", "List all traced disassembled",
|
||||
"dtc", "", "Trace call/ret",
|
||||
"dtg", "", "Graph call/ret trace",
|
||||
"dtr", "", "Reset traces (instruction//cals)",
|
||||
@ -1263,12 +1268,16 @@ static int cmd_debug(void *data, const char *input) {
|
||||
r_core_cmd_help (core, help_message);
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
case 'c': // "dtc"
|
||||
if (r_debug_is_dead (core->dbg))
|
||||
eprintf ("No process to debug.");
|
||||
else r_core_debug_trace_calls (core);
|
||||
break;
|
||||
case 'g':
|
||||
case 'd':
|
||||
// TODO: reimplement using the api
|
||||
r_core_cmd0 (core, "pd 1 @@= `dt~[0]`");
|
||||
break;
|
||||
case 'g': // "dtg"
|
||||
dot_r_graph_traverse (core, core->dbg->graph);
|
||||
break;
|
||||
case 'r':
|
||||
|
@ -930,7 +930,7 @@ R_API int r_core_config_init(RCore *core) {
|
||||
SETICB("dbg.bpsize", 1, &cb_dbgbpsize, "Specify size of software breakpoints");
|
||||
#endif
|
||||
SETCB("dbg.trace", "false", &cb_trace, "Trace program execution (see asm.trace)");
|
||||
SETCB("dbg.trace.tag", "0xff", &cb_tracetag, "Set trace tag");
|
||||
SETICB("dbg.trace.tag", 0, &cb_tracetag, "Set trace tag");
|
||||
|
||||
/* cmd */
|
||||
if (r_file_exists ("/usr/bin/xdot"))
|
||||
|
@ -318,7 +318,6 @@ static void handle_reflines_fcn_init (RCore *core, RDisasmState *ds, RAnalFunct
|
||||
core->reflines2 = r_anal_reflines_fcn_get (core->anal,
|
||||
fcn, -1, ds->linesout, 1);
|
||||
} else core->reflines = core->reflines2 = NULL;
|
||||
|
||||
}
|
||||
|
||||
static void handle_deinit_ds (RCore *core, RDisasmState *ds) {
|
||||
@ -468,7 +467,6 @@ R_API RAnalHint *r_core_hint_begin (RCore *core, RAnalHint* hint, ut64 at) {
|
||||
if (hint->arch) {
|
||||
if (!hint_arch) hint_arch = strdup (
|
||||
r_config_get (core->config, "asm.arch"));
|
||||
//eprintf ("ST ARCH\n");
|
||||
r_config_set (core->config, "asm.arch", hint->arch);
|
||||
}
|
||||
/* bits */
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include <r_debug.h>
|
||||
|
||||
// DO IT WITH SDB
|
||||
|
||||
R_API RDebugTrace *r_debug_trace_new () {
|
||||
RDebugTrace *t = R_NEW (RDebugTrace);
|
||||
t->tag = 1; // UT32_MAX;
|
||||
@ -36,7 +38,9 @@ R_API int r_debug_trace_pc (RDebug *dbg) {
|
||||
r_debug_reg_sync (dbg, R_REG_TYPE_GPR, R_FALSE);
|
||||
if ((ri = r_reg_get (dbg->reg, dbg->reg->name[R_REG_NAME_PC], -1))) {
|
||||
ut64 addr = r_reg_get_value (dbg->reg, ri);
|
||||
if (addr)
|
||||
if (!addr) {
|
||||
return R_FALSE;
|
||||
}
|
||||
if (dbg->iob.read_at (dbg->iob.io, addr, buf, sizeof (buf))>0) {
|
||||
if (r_anal_op (dbg->anal, &op, addr, buf, sizeof (buf))>0) {
|
||||
if (oldpc!=0LL)
|
||||
@ -56,7 +60,6 @@ R_API void r_debug_trace_at(RDebug *dbg, const char *str) {
|
||||
}
|
||||
|
||||
R_API RDebugTracepoint *r_debug_trace_get (RDebug *dbg, ut64 addr) {
|
||||
/* TODO: handle opcode size .. warn when jumping in the middle of instructions */
|
||||
int tag = dbg->trace->tag;
|
||||
RListIter *iter;
|
||||
RDebugTracepoint *trace;
|
||||
@ -95,8 +98,6 @@ static int r_debug_trace_is_traceable(RDebug *dbg, ut64 addr) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* sort insert, or separated sort function ? */
|
||||
/* TODO: detect if inner opcode */
|
||||
R_API RDebugTracepoint *r_debug_trace_add (RDebug *dbg, ut64 addr, int size) {
|
||||
RDebugTracepoint *tp;
|
||||
int tag = dbg->trace->tag;
|
||||
@ -105,13 +106,12 @@ R_API RDebugTracepoint *r_debug_trace_add (RDebug *dbg, ut64 addr, int size) {
|
||||
r_anal_trace_bb (dbg->anal, addr);
|
||||
tp = r_debug_trace_get (dbg, addr);
|
||||
if (!tp) {
|
||||
tp = R_NEW (RDebugTracepoint);
|
||||
memset (tp, 0, sizeof (RDebugTracepoint));
|
||||
tp = R_NEW0 (RDebugTracepoint);
|
||||
tp->stamp = r_sys_now ();
|
||||
tp->addr = addr;
|
||||
tp->tags = tag;
|
||||
tp->size = size;
|
||||
tp->count = dbg->trace->count++;
|
||||
tp->count = ++dbg->trace->count;
|
||||
tp->times = 1;
|
||||
r_list_append (dbg->trace->traces, tp);
|
||||
} else tp->times++;
|
||||
|
Loading…
Reference in New Issue
Block a user