Implement simple command-based debugger interface

Add a new debugger interface using a simple command language. This is
less powerful than the scheme interface (which still exists) but more
ergonomic for interactive debugging.

This debugger has no external dependencies (it will however use readline
if available) and is included in builds by default.

A sample interaction might look like:

    xsystem4 --debug /path/to/game
    dbg(cmd)> breakpoint bar
    Set breakpoint at function 'bar' (0x00001234)
    dbg(cmd)> continue
    Hit breakpoint at function 'bar' (0x00001234)
    dbg(cmd)> backtrace
    #0 0x00001234 in bar
    #1 0x00002222 in foo
    #2 0x00004444 in main
    dbg(cmd)> locals
    [0] i: 2
    [1] s: "baz"
    dbg(cmd)> locals 1
    [0] j: 3
    [1] obj: { m_i = 0; m_s = "" }
    dbg(cmd)> quit
This commit is contained in:
Nunuhara Cabbage
2022-04-01 19:38:55 -07:00
parent 0780442e13
commit 9fbc9ec5b7
11 changed files with 762 additions and 170 deletions
+23
View File
@@ -20,6 +20,17 @@
#include <stdbool.h>
#include "system4/instructions.h"
#include "xsystem4.h"
#define DBG_ERROR(fmt, ...) sys_warning("ERROR: " fmt "\n", ##__VA_ARGS__)
struct breakpoint {
enum opcode restore_op;
void *data;
void (*cb)(struct breakpoint*);
char *message;
int count;
};
extern bool dbg_enabled;
@@ -27,7 +38,19 @@ void dbg_init(void);
void dbg_fini(void);
void dbg_repl(void);
void dbg_continue(void);
void dbg_quit(void);
void dbg_start(void(*fun)(void*), void *data);
void dbg_cmd_repl(void);
enum opcode dbg_handle_breakpoint(unsigned bp_no);
bool dbg_set_function_breakpoint(const char *_name, void(*cb)(struct breakpoint*), void *data);
bool dbg_set_address_breakpoint(uint32_t address, void(*cb)(struct breakpoint*), void *data);
void dbg_print_stack_trace(void);
#ifdef HAVE_SCHEME
void dbg_scm_init(void);
void dbg_scm_fini(void);
void dbg_scm_repl(void);
#endif /* HAVE_SCHEME */
#endif /* DEBUGGER_ENABLED */
#endif /* SYSTEM4_DEBUGGER_H */