Add lsf() command to list all functions

This commit is contained in:
2025-03-12 14:31:40 +01:00
parent 3b938a06dd
commit 673b7800a7
3 changed files with 16 additions and 5 deletions

View File

@@ -11,6 +11,7 @@ var offset = "0x0000000000001169"; // dupa(), objdump -d ./test
// pplo(); // pplo();
baddr(offset); baddr(offset);
lsbrk(); lsbrk();
lsf();
// lif("1 --------------------------------------------"); // lif("1 --------------------------------------------");
// dr(); // dr();

View File

@@ -11,6 +11,7 @@ var offset = "@DUPA_ADDR"; // dupa(), objdump -d ./test
// pplo(); // pplo();
baddr(offset); baddr(offset);
lsbrk(); lsbrk();
lsf();
// lif("1 --------------------------------------------"); // lif("1 --------------------------------------------");
// dr(); // dr();

View File

@@ -401,6 +401,19 @@ void dbg_js_lsbrk(js_State *js)
js_pushundefined(js); js_pushundefined(js);
} }
void dbg_js_lsf(js_State *js)
{
Dbg *dbg = getdbg();
for (int i = 0; i < dbg->symbols.count; i++) {
Symbol *s = &dbg->symbols.items[i];
AddrInfo *ai = libelfin_wrap_info_from_rip(dbg->plibelfin, (uint64_t)(s->addr - dbg->program_load_offset));
if (ai != NULL) {
LOG_INF("Sym %s 0x%"PRIxPTR" %s:%zu\n", s->name, s->addr, ai->file, (size_t)ai->line);
libelfin_wrap_free_info(ai);
}
}
}
void dbg_js_lif(js_State *js) void dbg_js_lif(js_State *js)
{ {
const char *str = js_tostring(js, 1); const char *str = js_tostring(js, 1);
@@ -524,6 +537,7 @@ void dbg_init_js(Dbg *dbg)
make_js_func(mrd, 1, "Read memory at address, ARGS=Address: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(mwr, 2, "Write memory at address, ARGS=Address:hex string,Value:hex string");
make_js_func(help, 0, "Print help information, ARGS=None"); make_js_func(help, 0, "Print help information, ARGS=None");
make_js_func(lsf, 0, "List functions in executable, ARGS=None");
#undef make_js_func #undef make_js_func
} }
@@ -585,11 +599,6 @@ void dbg_libelfin_wrap_init(Dbg *dbg)
void dbg_load_symbols(Dbg *dbg) void dbg_load_symbols(Dbg *dbg)
{ {
libelfin_wrap_get_syms(dbg->plibelfin, &dbg->symbols); libelfin_wrap_get_syms(dbg->plibelfin, &dbg->symbols);
for (int i = 0; i < dbg->symbols.count; i++) {
Symbol *s = &dbg->symbols.items[i];
LOG_INF("Found symbol %s 0x%"PRIxPTR"\n", s->name, s->addr);
}
} }
void dbg_init(Dbg *dbg, const char *file, pid_t pid) void dbg_init(Dbg *dbg, const char *file, pid_t pid)