debugger: add finish command

Add finish (fin) command which resumes execution until returning from
the current function.
This commit is contained in:
Nunuhara Cabbage
2023-01-07 13:44:08 -08:00
parent 31930c5e97
commit 9fd0415ec6
3 changed files with 47 additions and 6 deletions
+27
View File
@@ -341,6 +341,9 @@ static int32_t dbg_next_address(bool into, int *call_index)
bool dbg_set_step_over_breakpoint(void)
{
if (instr_ptr <= 0)
return false;
int call_index;
int32_t address = dbg_next_address(false, &call_index);
if (address < 0)
@@ -351,6 +354,9 @@ bool dbg_set_step_over_breakpoint(void)
bool dbg_set_step_into_breakpoint(void)
{
if (instr_ptr <= 0)
return false;
int call_index;
int32_t address = dbg_next_address(true, &call_index);
if (address < 0)
@@ -359,6 +365,19 @@ bool dbg_set_step_into_breakpoint(void)
return true;
}
bool dbg_set_finish_breakpoint(void)
{
if (call_stack_ptr < 2)
return false;
int32_t address = call_stack[call_stack_ptr-1].return_address;
// XXX: VM_RETURN
if (address < 0)
return false;
dbg_set_step_breakpoint(address, call_stack_ptr - 1);
return true;
}
static void _dbg_handle_breakpoint(void *data)
{
struct breakpoint *bp = data;
@@ -549,6 +568,9 @@ struct string *dbg_value_to_string(struct ain_type *type, union vm_value value,
// Rewind to DASM_REWIND instructions before the current instruction pointer.
static bool dbg_init_dasm(struct dasm *dasm)
{
if (call_stack_ptr < 1)
goto error;
unsigned addr_i = 0;
size_t addr[DASM_REWIND] = {0};
int fno = call_stack[call_stack_ptr-1].fno;
@@ -759,6 +781,11 @@ static bool dasm_print_finished(struct dasm *dasm, int dasm_i)
void dbg_print_vm_state(void)
{
if (call_stack_ptr < 1) {
DBG_ERROR("VM not running");
return;
}
puts("");
puts(" Stack Disassembly");
puts("----------------- -----------");