Skip to content

Commit

Permalink
Port remaining debug commands to RzShell (#4753)
Browse files Browse the repository at this point in the history
* Port `dmhb` to RzShell
* Port `dmhf` to RzShell
* Remove 'to' argument from rz_core_debug_continue_until(). It was never used in the whole function. Hence, whatever it was supposed to do, it didn't
* Port `dcu` to RzShell
* Fix tests of `dmh[bf]` commands
* Port `dmi` commands to RzShell
* Port `dmx` to RzShell
* Remove `dta` command.

Originally it limited the addresses to trace.
But it was not used in any test, and the implementation was not optimal.
It allowed only specific addresses (no range).
Also worked on strings (not ut64 values).
Also, the usefulness is limited, considering the alternative
to just not tracing a certain address.

* Add quiet and quietest mode to `dmi` commands.

This also removes the test for `dmias`.
The command was not documented and it doesn't seem to
do anything special `dmia` can't do.
  • Loading branch information
Rot127 authored Dec 6, 2024
1 parent 7637377 commit 87b7591
Show file tree
Hide file tree
Showing 21 changed files with 419 additions and 471 deletions.
45 changes: 31 additions & 14 deletions librz/core/cdebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,24 @@ RZ_IPI void rz_core_debug_continue(RzCore *core) {
}
}

RZ_API bool rz_core_debug_continue_until(RzCore *core, ut64 addr, ut64 to) {
/**
* \brief Continue the execution of the debugged binary until \p addr.
*
* \param core The current core.
* \param addr The address to execute to.
*
* \return true On success.
* \return false Otherwise.
*/
RZ_API bool rz_core_debug_continue_until(RzCore *core, ut64 addr) {
#if RZ_BUILD_DEBUG
long level = 0;
ut64 prev_pc = UT64_MAX;
unsigned long steps = 0;
#endif
ut64 pc;
if (!strcmp(core->dbg->btalgo, "trace") && core->dbg->arch && !strcmp(core->dbg->arch, "x86") && core->dbg->bits == 4) {
unsigned long steps = 0;
long level = 0;
const char *pc_name = core->dbg->reg->name[RZ_REG_NAME_PC];
ut64 prev_pc = UT64_MAX;
bool prev_call = false;
bool prev_ret = false;
const char *sp_name = core->dbg->reg->name[RZ_REG_NAME_SP];
Expand All @@ -127,45 +138,51 @@ RZ_API bool rz_core_debug_continue_until(RzCore *core, ut64 addr, ut64 to) {
frame->sp = cur_sp;
frame->bp = old_sp;
rz_list_prepend(core->dbg->call_frames, frame);
eprintf("%ld Call from 0x%08" PFMT64x " to 0x%08" PFMT64x " ret 0x%08" PFMT32x "\n",
level, prev_pc, pc, ret_addr);
level++;
RZ_LOG_DEBUG("%ld Call from 0x%08" PFMT64x " to 0x%08" PFMT64x " ret 0x%08" PFMT32x "\n",
level++, prev_pc, pc, ret_addr);
old_sp = cur_sp;
prev_call = false;
} else if (prev_ret) {
RzDebugFrame *head = rz_list_first(core->dbg->call_frames);
if (head && head->addr != pc) {
eprintf("*");
RZ_LOG_DEBUG("*");
} else {
rz_list_pop_head(core->dbg->call_frames);
eprintf("%ld", level);
level--;
RZ_LOG_DEBUG("%ld", level--);
}
eprintf(" Ret from 0x%08" PFMT64x " to 0x%08" PFMT64x "\n",
RZ_LOG_DEBUG(" Ret from 0x%08" PFMT64x " to 0x%08" PFMT64x "\n",
prev_pc, pc);
prev_ret = false;
}
#if RZ_BUILD_DEBUG
if (steps % 500 == 0 || pc == addr) {
eprintf("At 0x%08" PFMT64x " after %lu steps\n", pc, steps);
RZ_LOG_DEBUG("At 0x%08" PFMT64x " after %lu steps\n", pc, steps);
}
#endif
if (rz_cons_is_breaked() || rz_debug_is_dead(core->dbg) || pc == addr) {
break;
}
if (is_x86_call(core->dbg, pc)) {
#if RZ_BUILD_DEBUG
prev_pc = pc;
#endif
prev_call = true;
} else if (is_x86_ret(core->dbg, pc)) {
#if RZ_BUILD_DEBUG
prev_pc = pc;
#endif
prev_ret = true;
}
rz_debug_step(core->dbg, 1);
#if RZ_BUILD_DEBUG
steps++;
#endif
}
rz_core_reg_update_flags(core);
rz_cons_break_pop();
return true;
}
eprintf("Continue until 0x%08" PFMT64x "\n", addr);
RZ_LOG_DEBUG("Continue until 0x%08" PFMT64x "\n", addr);
rz_reg_arena_swap(core->dbg->reg, true);
if (rz_bp_add_sw(core->dbg->bp, addr, 0, RZ_PERM_X)) {
if (rz_debug_is_dead(core->dbg)) {
Expand All @@ -185,7 +202,7 @@ RZ_API bool rz_core_debug_continue_until(RzCore *core, ut64 addr, ut64 to) {
RZ_IPI void rz_core_debug_single_step_in(RzCore *core) {
if (rz_core_is_debug(core)) {
if (core->print->cur_enabled) {
rz_core_debug_continue_until(core, core->offset, core->offset + core->print->cur);
rz_core_debug_continue_until(core, core->offset);
core->print->cur_enabled = 0;
} else {
rz_core_debug_step_one(core, 1);
Expand Down
4 changes: 2 additions & 2 deletions librz/core/cio.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ RZ_API int rz_core_setup_debugger(RzCore *r, const char *debugbackend, bool atta
/* do nothing here */
} else if (!strcmp(bep, "entry")) {
address = rz_num_math(r->num, "entry0");
rz_core_debug_continue_until(r, address, address);
rz_core_debug_continue_until(r, address);
} else {
address = rz_num_math(r->num, bep);
rz_core_debug_continue_until(r, address, address);
rz_core_debug_continue_until(r, address);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions librz/core/cmd/cmd_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ static const struct argv_modes_t {
{ "l", " (verbose mode)", RZ_OUTPUT_MODE_LONG },
{ "J", " (verbose JSON mode)", RZ_OUTPUT_MODE_LONG_JSON },
{ "t", " (table mode)", RZ_OUTPUT_MODE_TABLE },
{ "g", " (graph mode)", RZ_OUTPUT_MODE_GRAPH },
};

RZ_IPI int rz_output_mode_to_char(RzOutputMode mode) {
Expand Down
Loading

0 comments on commit 87b7591

Please sign in to comment.