58 lines
1.5 KiB
C++
58 lines
1.5 KiB
C++
#include <inttypes.h>
|
|
#include <libelfin/dwarf/dwarf++.hh>
|
|
#include <libelfin/elf/elf++.hh>
|
|
|
|
#include "libelfin_wrap.h"
|
|
|
|
class LibelfinBinding
|
|
{
|
|
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 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()) {
|
|
return NULL;
|
|
} else {
|
|
AddrInfo *ai = (AddrInfo *)malloc(sizeof(*ai));
|
|
ai->addr = rip;
|
|
ai->line = it->line;
|
|
ai->file = (const char*)malloc(strlen(it->file->path.c_str())+1);
|
|
strcpy((char*)ai->file, it->file->path.c_str());
|
|
return ai;
|
|
}
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
DEBUGUS_EXTERNC void libelfin_wrap_free_info(AddrInfo *ai)
|
|
{
|
|
free((void*)ai->file);
|
|
free((void*)ai);
|
|
}
|
|
|