Print function name and file location when caught a SIGSEGV

This commit is contained in:
2025-03-12 14:25:55 +01:00
parent 6a5b07fa93
commit 3b938a06dd
7 changed files with 131 additions and 46 deletions

View File

@@ -7,19 +7,41 @@
class LibelfinBinding
{
public:
LibelfinBinding(int fd)
LibelfinBinding(int fd, uintptr_t _loadoffset)
: elf(elf::create_mmap_loader(fd)),
dwarf(dwarf::elf::create_loader(this->elf))
dwarf(dwarf::elf::create_loader(this->elf)),
loadoffset(_loadoffset)
{
}
elf::elf elf;
dwarf::dwarf dwarf;
uintptr_t loadoffset;
};
DEBUGUS_EXTERNC PLibelfinBinding libelfin_wrap_get_binding(int fd)
DEBUGUS_EXTERNC void libelfin_wrap_get_syms(PLibelfinBinding *pbind, Symbols *syms)
{
return (PLibelfinBinding)new LibelfinBinding(fd);
LibelfinBinding *bind = (LibelfinBinding *)pbind;
for (auto &section : bind->elf.sections()) {
if (section.get_hdr().type == elf::sht::symtab) {
for (auto sym : section.as_symtab()) {
auto &d = sym.get_data();
if (d.type() == elf::stt::func) {
Symbol s = {
.name = (const char *)malloc(strlen(sym.get_name().c_str())+1),
.addr = bind->loadoffset + (uintptr_t)d.value,
};
strcpy((char*)s.name, sym.get_name().c_str());
da_append(syms, s);
}
}
}
}
}
DEBUGUS_EXTERNC PLibelfinBinding libelfin_wrap_get_binding(int fd, uintptr_t loadoffset)
{
return (PLibelfinBinding)new LibelfinBinding(fd, loadoffset);
}
DEBUGUS_EXTERNC void libelfin_wrap_free_binding(PLibelfinBinding pbind)