Remove the SLD command, reorder debugger commands

This commit is contained in:
Lior Halphon 2022-07-01 16:14:52 +03:00
parent 1b38e8c932
commit 96d127e160
2 changed files with 25 additions and 73 deletions

View File

@ -794,22 +794,6 @@ static bool finish(GB_gameboy_t *gb, char *arguments, char *modifiers, const deb
return false;
}
static bool stack_leak_detection(GB_gameboy_t *gb, char *arguments, char *modifiers, const debugger_command_t *command)
{
NO_MODIFIERS
STOPPED_ONLY
if (strlen(lstrip(arguments))) {
print_usage(gb, command);
return true;
}
gb->debug_stopped = false;
gb->stack_leak_detection = true;
gb->debug_call_depth = 0;
return false;
}
static bool registers(GB_gameboy_t *gb, char *arguments, char *modifiers, const debugger_command_t *command)
{
NO_MODIFIERS
@ -1986,22 +1970,17 @@ static const debugger_command_t commands[] = {
{"step", 1, step, "Run the next instruction, stepping into function calls"},
{"finish", 1, finish, "Run until the current function returns"},
{"undo", 1, undo, "Revert the last command"},
{"registers", 1, registers, "Print values of processor registers and other important registers"},
{"backtrace", 2, backtrace, "Display the current call stack"},
{"bt", 2, }, /* Alias */
{"sld", 3, stack_leak_detection, "Like finish, but stops if a stack leak is detected"},
{"ticks", 2, ticks, "Display the number of CPU ticks since the last time 'ticks' was" HELP_NEWLINE
"used"},
{"registers", 1, registers, "Print values of processor registers and other important registers"},
{"cartridge", 2, mbc, "Display information about the MBC and cartridge"},
{"mbc", 3, }, /* Alias */
{"apu", 3, apu, "Display information about the current state of the audio processing unit", "[channel (1-4, 5 for NR5x)]"},
{"wave", 3, wave, "Print a visual representation of the wave RAM." HELP_NEWLINE
"Modifiers can be used for a (f)ull print (the default)," HELP_NEWLINE
"a more (c)ompact one, or a one-(l)iner", "", "(f|c|l)", .modifiers_completer = wave_completer},
{"lcd", 3, lcd, "Display information about the current state of the LCD controller"},
{"palettes", 3, palettes, "Display the current CGB palettes"},
{"dma", 3, dma, "Display the current OAM DMA status"},
{"softbreak", 2, softbreak, "Enable or disable software breakpoints", "(on|off)", .argument_completer = on_off_completer},
{"print", 1, print, "Evaluate and print an expression" HELP_NEWLINE
"Use modifier to format as an address (a, default) or as a number in" HELP_NEWLINE
"decimal (d), hexadecimal (x), octal (o) or binary (b).",
"<expression>", "format", .argument_completer = symbol_completer, .modifiers_completer = format_completer},
{"eval", 2, }, /* Alias */
{"examine", 2, examine, "Examine values at address", "<expression>", "count", .argument_completer = symbol_completer},
{"x", 1, }, /* Alias */
{"disassemble", 1, disassemble, "Disassemble instructions at address", "<expression>", "count", .argument_completer = symbol_completer},
{"breakpoint", 1, breakpoint, "Add a new breakpoint at the specified address/expression" HELP_NEWLINE
"Can also modify the condition of existing breakpoints." HELP_NEWLINE
"If the j modifier is used, the breakpoint will occur just before" HELP_NEWLINE
@ -2016,16 +1995,19 @@ static const debugger_command_t commands[] = {
.argument_completer = symbol_completer, .modifiers_completer = rw_completer
},
{"unwatch", 3, unwatch, "Delete a watchpoint by its address, or all watchpoints", "[<expression>]", .argument_completer = symbol_completer},
{"softbreak", 2, softbreak, "Enable or disable software breakpoints", "(on|off)", .argument_completer = on_off_completer},
{"list", 1, list, "List all set breakpoints and watchpoints"},
{"print", 1, print, "Evaluate and print an expression" HELP_NEWLINE
"Use modifier to format as an address (a, default) or as a number in" HELP_NEWLINE
"decimal (d), hexadecimal (x), octal (o) or binary (b).",
"<expression>", "format", .argument_completer = symbol_completer, .modifiers_completer = format_completer},
{"eval", 2, }, /* Alias */
{"examine", 2, examine, "Examine values at address", "<expression>", "count", .argument_completer = symbol_completer},
{"x", 1, }, /* Alias */
{"disassemble", 1, disassemble, "Disassemble instructions at address", "<expression>", "count", .argument_completer = symbol_completer},
{"ticks", 2, ticks, "Display the number of CPU ticks since the last time 'ticks' was" HELP_NEWLINE
"used"},
{"cartridge", 2, mbc, "Display information about the MBC and cartridge"},
{"mbc", 3, }, /* Alias */
{"apu", 3, apu, "Display information about the current state of the audio processing unit", "[channel (1-4, 5 for NR5x)]"},
{"wave", 3, wave, "Print a visual representation of the wave RAM." HELP_NEWLINE
"Modifiers can be used for a (f)ull print (the default)," HELP_NEWLINE
"a more (c)ompact one, or a one-(l)iner", "", "(f|c|l)", .modifiers_completer = wave_completer},
{"lcd", 3, lcd, "Display information about the current state of the LCD controller"},
{"palettes", 3, palettes, "Display the current CGB palettes"},
{"dma", 3, dma, "Display the current OAM DMA status"},
{"help", 1, help, "List available commands or show help for the specified command", "[<command>]"},
{NULL,}, /* Null terminator */
@ -2093,19 +2075,7 @@ void GB_debugger_call_hook(GB_gameboy_t *gb, uint16_t call_addr)
{
/* Called just after the CPU calls a function/enters an interrupt/etc... */
if (gb->stack_leak_detection) {
if (gb->debug_call_depth >= sizeof(gb->sp_for_call_depth) / sizeof(gb->sp_for_call_depth[0])) {
GB_log(gb, "Potential stack overflow detected (Functions nest too much). \n");
gb->debug_stopped = true;
}
else {
gb->sp_for_call_depth[gb->debug_call_depth] = gb->sp;
gb->addr_for_call_depth[gb->debug_call_depth] = gb->pc;
}
}
if (gb->backtrace_size < sizeof(gb->backtrace_sps) / sizeof(gb->backtrace_sps[0])) {
while (gb->backtrace_size) {
if (gb->backtrace_sps[gb->backtrace_size - 1] < gb->sp) {
gb->backtrace_size--;
@ -2130,21 +2100,6 @@ void GB_debugger_ret_hook(GB_gameboy_t *gb)
gb->debug_call_depth--;
if (gb->stack_leak_detection) {
if (gb->debug_call_depth < 0) {
GB_log(gb, "Function finished without a stack leak.\n");
gb->debug_stopped = true;
}
else {
if (gb->sp != gb->sp_for_call_depth[gb->debug_call_depth]) {
GB_log(gb, "Stack leak detected for function %s!\n", value_to_string(gb, gb->addr_for_call_depth[gb->debug_call_depth], true));
GB_log(gb, "SP is $%04x, should be $%04x.\n", gb->sp,
gb->sp_for_call_depth[gb->debug_call_depth]);
gb->debug_stopped = true;
}
}
}
while (gb->backtrace_size) {
if (gb->backtrace_sps[gb->backtrace_size - 1] <= gb->sp) {
gb->backtrace_size--;
@ -2445,7 +2400,6 @@ next_command:
if (gb->debug_stopped && !gb->debug_disable) {
gb->debug_next_command = false;
gb->debug_fin_command = false;
gb->stack_leak_detection = false;
input = gb->input_callback(gb);
if (input == NULL) {

View File

@ -733,8 +733,6 @@ struct GB_gameboy_internal_s {
void *nontrivial_jump_state;
bool non_trivial_jump_breakpoint_occured;
/* SLD (Todo: merge with backtrace) */
bool stack_leak_detection;
signed debug_call_depth;
uint16_t sp_for_call_depth[0x200]; /* Should be much more than enough */
uint16_t addr_for_call_depth[0x200];