Get breakpoint filename and line number from DWARF
This commit is contained in:
@@ -152,6 +152,7 @@ typedef struct {
|
||||
HashTable brks;
|
||||
uintptr_t program_load_offset;
|
||||
HashTable js_descs;
|
||||
PLibelfinBinding plibelfin;
|
||||
} Dbg;
|
||||
|
||||
siginfo_t dbg_get_siginfo(Dbg *dbg)
|
||||
@@ -178,10 +179,9 @@ void dbg_handle_sigtrap(Dbg *dbg, siginfo_t info)
|
||||
case SI_KERNEL:
|
||||
case TRAP_BRKPT:
|
||||
dbg_set_rip(dbg, dbg_get_rip(dbg) - 1);
|
||||
ai = libelfin_wrap_info_from_rip(dbg_get_rip(dbg));
|
||||
ai = libelfin_wrap_info_from_rip(dbg->plibelfin, dbg_get_rip(dbg) - (uint64_t)dbg->program_load_offset);
|
||||
if (ai != NULL) {
|
||||
LOG_INF("Hit breakpoint at 0x%"PRIxPTR", %s:%zu\n", dbg_get_rip(dbg),
|
||||
ai->file, (size_t)ai->line);
|
||||
LOG_INF("Hit breakpoint at 0x%"PRIxPTR", %s:%zu\n", dbg_get_rip(dbg), ai->file, (size_t)ai->line);
|
||||
libelfin_wrap_free_info(ai);
|
||||
} else {
|
||||
LOG_INF("Hit breakpoint at 0x%"PRIxPTR"\n", dbg_get_rip(dbg));
|
||||
@@ -538,7 +538,7 @@ void dbg_libelfin_wrap_init(Dbg *dbg)
|
||||
return;
|
||||
}
|
||||
|
||||
libelfin_wrap_init(fileno(bin));
|
||||
dbg->plibelfin = libelfin_wrap_get_binding(fileno(bin));
|
||||
|
||||
fclose(bin);
|
||||
}
|
||||
@@ -561,6 +561,7 @@ void dbg_deinit(Dbg *dbg)
|
||||
js_freestate(dbg->js);
|
||||
hashtable_deinit(&dbg->brks);
|
||||
hashtable_deinit(&dbg->js_descs);
|
||||
libelfin_wrap_free_binding(dbg->plibelfin);
|
||||
}
|
||||
|
||||
void dbg_loop(Dbg *dbg)
|
||||
|
||||
@@ -1,25 +1,40 @@
|
||||
#include <inttypes.h>
|
||||
#include <libelfin/dwarf/dwarf++.hh>
|
||||
#include <libelfin/elf/elf++.hh>
|
||||
|
||||
#include "libelfin_wrap.h"
|
||||
|
||||
static elf::elf gelf;
|
||||
static dwarf::dwarf gdwarf;
|
||||
|
||||
DEBUGUS_EXTERNC void libelfin_wrap_init(int fd)
|
||||
class LibelfinBinding
|
||||
{
|
||||
public:
|
||||
LibelfinBinding(int fd)
|
||||
: elf(elf::create_mmap_loader(fd)),
|
||||
dwarf(dwarf::elf::create_loader(this->elf))
|
||||
{
|
||||
gelf = elf::elf{elf::create_mmap_loader(fd)};
|
||||
gdwarf = dwarf::dwarf{dwarf::elf::create_loader(gelf)};
|
||||
}
|
||||
|
||||
DEBUGUS_EXTERNC AddrInfo *libelfin_wrap_info_from_rip(uint64_t rip)
|
||||
elf::elf elf;
|
||||
dwarf::dwarf dwarf;
|
||||
};
|
||||
|
||||
DEBUGUS_EXTERNC PLibelfinBinding libelfin_wrap_get_binding(int fd)
|
||||
{
|
||||
for (auto &cu : gdwarf.compilation_units()) {
|
||||
return (PLibelfinBinding)new LibelfinBinding(fd);
|
||||
}
|
||||
|
||||
DEBUGUS_EXTERNC void libelfin_wrap_free_binding(PLibelfinBinding pbind)
|
||||
{
|
||||
delete (LibelfinBinding *)pbind;
|
||||
}
|
||||
|
||||
DEBUGUS_EXTERNC AddrInfo *libelfin_wrap_info_from_rip(PLibelfinBinding pbind, uint64_t rip)
|
||||
{
|
||||
LibelfinBinding *bind = (LibelfinBinding *)pbind;
|
||||
for (auto &cu : bind->dwarf.compilation_units()) {
|
||||
if (die_pc_range(cu.root()).contains(rip)) {
|
||||
auto < = cu.get_line_table();
|
||||
auto it = lt.find_address(rip);
|
||||
if (it == lt.end()) {
|
||||
printf("ADDR NOT FOUND\n");
|
||||
return NULL;
|
||||
} else {
|
||||
AddrInfo *ai = (AddrInfo *)malloc(sizeof(*ai));
|
||||
@@ -31,7 +46,6 @@ DEBUGUS_EXTERNC AddrInfo *libelfin_wrap_info_from_rip(uint64_t rip)
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("NO CUS\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,11 @@ typedef struct {
|
||||
uint64_t addr;
|
||||
} AddrInfo;
|
||||
|
||||
DEBUGUS_EXTERNC void libelfin_wrap_init(int fd);
|
||||
DEBUGUS_EXTERNC AddrInfo *libelfin_wrap_info_from_rip(uint64_t rip);
|
||||
typedef void * PLibelfinBinding;
|
||||
|
||||
DEBUGUS_EXTERNC PLibelfinBinding libelfin_wrap_get_binding(int fd);
|
||||
DEBUGUS_EXTERNC void libelfin_wrap_free_binding(PLibelfinBinding pbind);
|
||||
DEBUGUS_EXTERNC AddrInfo *libelfin_wrap_info_from_rip(PLibelfinBinding pbind, uint64_t rip);
|
||||
DEBUGUS_EXTERNC void libelfin_wrap_free_info(AddrInfo *ai);
|
||||
|
||||
#endif // LIBELFIN_WRAP_H_
|
||||
|
||||
Reference in New Issue
Block a user