Get breakpoint filename and line number from DWARF

This commit is contained in:
2025-03-12 11:37:23 +01:00
parent dc66bc84ae
commit d4fdd69c48
3 changed files with 34 additions and 16 deletions

View File

@@ -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
{
gelf = elf::elf{elf::create_mmap_loader(fd)};
gdwarf = dwarf::dwarf{dwarf::elf::create_loader(gelf)};
public:
LibelfinBinding(int fd)
: elf(elf::create_mmap_loader(fd)),
dwarf(dwarf::elf::create_loader(this->elf))
{
}
elf::elf elf;
dwarf::dwarf dwarf;
};
DEBUGUS_EXTERNC PLibelfinBinding libelfin_wrap_get_binding(int fd)
{
return (PLibelfinBinding)new LibelfinBinding(fd);
}
DEBUGUS_EXTERNC AddrInfo *libelfin_wrap_info_from_rip(uint64_t rip)
DEBUGUS_EXTERNC void libelfin_wrap_free_binding(PLibelfinBinding pbind)
{
for (auto &cu : gdwarf.compilation_units()) {
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 &lt = 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;
}