bl()/rmbl() commands for setting/removing breakpoints at source line
This commit is contained in:
39
debugus.c
39
debugus.c
@@ -188,7 +188,6 @@ static RegisterDescriptor reg_descriptors[MAX_REGISTERS] = {
|
||||
|
||||
typedef struct {
|
||||
pid_t pid;
|
||||
pid_t proc_pid;
|
||||
uintptr_t addr;
|
||||
bool enabled;
|
||||
uint8_t data;
|
||||
@@ -712,6 +711,42 @@ done:
|
||||
js_pushundefined(js);
|
||||
}
|
||||
|
||||
void dbg_js_bl(js_State *js)
|
||||
{
|
||||
Dbg *dbg = getdbg();
|
||||
const char *filepath = js_tostring(js, 1);
|
||||
size_t line = (size_t)js_tonumber(js, 2);
|
||||
AddrInfo *ai = libelfin_wrap_info_from_line(dbg->plibelfin, filepath, line);
|
||||
if (ai != NULL) {
|
||||
char addr_str[20];
|
||||
snprintf(addr_str, sizeof(addr_str), "0x%"PRIxPTR, ai->addr);
|
||||
Brk brk = { .pid = dbg->pid, .addr = ai->addr };
|
||||
brk_enable(&brk);
|
||||
hashtable_set(&dbg->brks, addr_str, &brk, sizeof(brk));
|
||||
libelfin_wrap_free_info(ai);
|
||||
}
|
||||
js_pushundefined(js);
|
||||
}
|
||||
|
||||
void dbg_js_rmbl(js_State *js)
|
||||
{
|
||||
Dbg *dbg = getdbg();
|
||||
const char *filepath = js_tostring(js, 1);
|
||||
size_t line = (size_t)js_tonumber(js, 2);
|
||||
AddrInfo *ai = libelfin_wrap_info_from_line(dbg->plibelfin, filepath, line);
|
||||
if (ai != NULL) {
|
||||
char addr_str[20];
|
||||
snprintf(addr_str, sizeof(addr_str), "0x%"PRIxPTR, ai->addr);
|
||||
Brk *brk = (Brk *)hashtable_get(&dbg->brks, addr_str);
|
||||
if (brk != NULL) {
|
||||
brk_disable(brk);
|
||||
hashtable_delete(&dbg->brks, addr_str);
|
||||
}
|
||||
libelfin_wrap_free_info(ai);
|
||||
}
|
||||
js_pushundefined(js);
|
||||
}
|
||||
|
||||
void dbg_init_js(Dbg *dbg)
|
||||
{
|
||||
dbg->js = js_newstate(NULL, NULL, JS_STRICT);
|
||||
@@ -746,6 +781,8 @@ void dbg_init_js(Dbg *dbg)
|
||||
make_js_func(dbaddr, 1, "Disable breakpoint at address, ARGS=Address:hex string");
|
||||
make_js_func(ebfn, 1, "Enable breakpoint at function, ARGS=Function name:string");
|
||||
make_js_func(dbfn, 1, "Disable breakpoint at function, ARGS=Function name:string");
|
||||
make_js_func(bl, 2, "Set breakpoint at line in file, ARGS=File:string,Line:int");
|
||||
make_js_func(rmbl, 2, "Remove breakpoint at line in file, ARGS=File:string,Line:int");
|
||||
|
||||
#undef make_js_func
|
||||
}
|
||||
|
||||
@@ -39,6 +39,25 @@ DEBUGUS_EXTERNC void libelfin_wrap_get_funcs(PLibelfinBinding pbind, Funcs *func
|
||||
}
|
||||
}
|
||||
|
||||
DEBUGUS_EXTERNC AddrInfo *libelfin_wrap_info_from_line(PLibelfinBinding pbind, const char *file, size_t line)
|
||||
{
|
||||
LibelfinBinding *bind = (LibelfinBinding *)pbind;
|
||||
for (auto &cu : bind->dwarf.compilation_units()) {
|
||||
auto < = cu.get_line_table();
|
||||
for (auto &ent : lt) {
|
||||
if (ent.is_stmt && ent.line == line) {
|
||||
AddrInfo *ai = (AddrInfo *)malloc(sizeof(*ai));
|
||||
ai->addr = bind->loadoffset + (uintptr_t)ent.address;
|
||||
ai->line = (ssize_t)line;
|
||||
ai->file = (const char*)malloc(strlen(file)+1);
|
||||
strcpy((char*)ai->file, file);
|
||||
return ai;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DEBUGUS_EXTERNC uintptr_t libelfin_wrap_func_addr(PLibelfinBinding pbind, Func *f)
|
||||
{
|
||||
LibelfinBinding *bind = (LibelfinBinding *)pbind;
|
||||
|
||||
@@ -38,5 +38,6 @@ DEBUGUS_EXTERNC AddrInfo *libelfin_wrap_info_from_rip(PLibelfinBinding pbind, ui
|
||||
DEBUGUS_EXTERNC void libelfin_wrap_free_info(AddrInfo *ai);
|
||||
DEBUGUS_EXTERNC void libelfin_wrap_get_funcs(PLibelfinBinding pbind, Funcs *funcs);
|
||||
DEBUGUS_EXTERNC uintptr_t libelfin_wrap_func_addr(PLibelfinBinding pbind, Func *f);
|
||||
DEBUGUS_EXTERNC AddrInfo *libelfin_wrap_info_from_line(PLibelfinBinding pbind, const char *file, size_t line);
|
||||
|
||||
#endif // LIBELFIN_WRAP_H_
|
||||
|
||||
Reference in New Issue
Block a user