Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port debug commands to RzShell #4753

Draft
wants to merge 12 commits into
base: dev
Choose a base branch
from
39 changes: 26 additions & 13 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;
#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,35 +138,37 @@ 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 (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);
}
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);
Expand All @@ -165,7 +178,7 @@ RZ_API bool rz_core_debug_continue_until(RzCore *core, ut64 addr, ut64 to) {
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 +198,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
Loading