help() command and comand descriptions
This commit is contained in:
53
debugus.c
53
debugus.c
@@ -29,6 +29,7 @@
|
||||
#define shift(argc, argv, msg, ...) (argc <= 0 ? (LOG_ERR(msg, ##__VA_ARGS__), exit(EXIT_FAILURE)) : (void)0, argc--, *argv++)
|
||||
|
||||
#define INIT_SCRIPT ".debugusrc.js"
|
||||
#define MAX_JS_FUNCS 100
|
||||
|
||||
// Registers
|
||||
// Taken from da goat https://source.winehq.org/source/dlls/dbghelp/cpu_x86_64.c
|
||||
@@ -160,6 +161,7 @@ typedef struct {
|
||||
HashTable brks;
|
||||
uintptr_t program_load_offset;
|
||||
Symbols symbols;
|
||||
HashTable js_descs;
|
||||
} Dbg;
|
||||
|
||||
void dbg_wait(Dbg *dbg)
|
||||
@@ -420,32 +422,47 @@ void dbg_js_lsm(js_State *js)
|
||||
js_pushundefined(js);
|
||||
}
|
||||
|
||||
void dbg_js_help(js_State *js)
|
||||
{
|
||||
Dbg *dbg = getdbg();
|
||||
for (int i = 0; i < dbg->js_descs.capacity; i++) {
|
||||
if (dbg->js_descs.buckets[i] != NULL) {
|
||||
const char *key = dbg->js_descs.buckets[i]->key;
|
||||
char *val = dbg->js_descs.buckets[i]->value;
|
||||
LOG_INF("%s: %s\n", key, val);
|
||||
}
|
||||
}
|
||||
js_pushundefined(js);
|
||||
}
|
||||
|
||||
void dbg_init_js(Dbg *dbg)
|
||||
{
|
||||
dbg->js = js_newstate(NULL, NULL, JS_STRICT);
|
||||
|
||||
#define make_js_func(name, n) \
|
||||
#define make_js_func(name, n, desc) \
|
||||
do { \
|
||||
js_newcfunctionx(dbg->js, &dbg_js_##name, #name, n, dbg, NULL); \
|
||||
js_setglobal(dbg->js, #name); \
|
||||
hashtable_set(&dbg->js_descs, #name, desc, strlen((desc))+1); \
|
||||
} while(0)
|
||||
|
||||
make_js_func(cont, 0);
|
||||
make_js_func(baddr, 1 /*addr*/);
|
||||
make_js_func(rmbaddr, 1 /*addr*/);
|
||||
make_js_func(lsbrk, 0);
|
||||
make_js_func(splo, 1 /*offset*/);
|
||||
make_js_func(lif, 1 /*string*/);
|
||||
make_js_func(ler, 1 /*string*/);
|
||||
make_js_func(ldscr, 1 /*path*/);
|
||||
make_js_func(gf, 0);
|
||||
make_js_func(pid, 0);
|
||||
make_js_func(plo, 0);
|
||||
make_js_func(gr, 1 /*reg name*/);
|
||||
make_js_func(sr, 2 /* reg name, value*/);
|
||||
make_js_func(mrd, 1 /*addr*/);
|
||||
make_js_func(mwr, 2 /*addr, value*/);
|
||||
make_js_func(lsm, 0);
|
||||
make_js_func(cont, 0, "Continue execution, ARGS=None");
|
||||
make_js_func(baddr, 1, "Place breakpoint at address, ARGS=Address:hex string");
|
||||
make_js_func(rmbaddr, 1, "Remove breakpoint at address, ARGS=Address:hex string");
|
||||
make_js_func(lsbrk, 0, "List all breakpoints");
|
||||
make_js_func(splo, 1, "Set program load offset, ARGS=Offset:hex string");
|
||||
make_js_func(lif, 1, "Log information, ARGS=Text:string");
|
||||
make_js_func(ler, 1, "Log error, ARGS=Text:string");
|
||||
make_js_func(ldscr, 1, "Load script, ARGS=Path:string");
|
||||
make_js_func(gf, 0, "Get current executable file path, ARGS=None");
|
||||
make_js_func(pid, 0, "Get executable process ID, ARGS=None");
|
||||
make_js_func(plo, 0, "Get program load offset, ARGS=None");
|
||||
make_js_func(gr, 1, "Get value of a register, ARGS=Register name:string");
|
||||
make_js_func(sr, 2, "Set register value, ARGS=Register name:string,Register value:hex string");
|
||||
make_js_func(mrd, 1, "Read memory at address, ARGS=Address:hex string");
|
||||
make_js_func(mwr, 2, "Write memory at address, ARGS=Address:hex string,Value:hex string");
|
||||
make_js_func(lsm, 0, "List all symbols, ARGS=None");
|
||||
make_js_func(help, 0, "Print help information, ARGS=None");
|
||||
|
||||
#undef make_js_func
|
||||
}
|
||||
@@ -549,6 +566,7 @@ void dbg_init(Dbg *dbg, const char *file, pid_t pid)
|
||||
memset(dbg, 0, sizeof(*dbg));
|
||||
dbg->file = file;
|
||||
dbg->pid = pid;
|
||||
hashtable_init(&dbg->js_descs, MAX_JS_FUNCS);
|
||||
dbg_init_js(dbg);
|
||||
dbg_init_load_offset(dbg);
|
||||
hashtable_init(&dbg->brks, MAX_BRKS);
|
||||
@@ -560,6 +578,7 @@ void dbg_deinit(Dbg *dbg)
|
||||
{
|
||||
js_freestate(dbg->js);
|
||||
hashtable_deinit(&dbg->brks);
|
||||
hashtable_deinit(&dbg->js_descs);
|
||||
da_deinit(&dbg->symbols);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user