40 lines
1.1 KiB
C++
40 lines
1.1 KiB
C++
#include <DwarfInterpret.hpp>
|
|
|
|
#include <fstream>
|
|
|
|
#include <fileno.hpp>
|
|
#include <dwarfpp/lib.hpp>
|
|
#include <dwarfpp/regs.hpp>
|
|
#include <dwarfpp/frame.hpp>
|
|
#include <dwarfpp/attr.hpp>
|
|
#include <dwarfpp/frame.hpp>
|
|
#include <dwarfpp/root.hpp>
|
|
#include <gelf.h>
|
|
|
|
DwarfInterpret::DwarfInterpret(const std::string& elf_path)
|
|
: root_die(fileno(std::ifstream(elf_path)))
|
|
{
|
|
//std::ifstream file_in(elf_path);
|
|
//root_die = dwarf::core::root_die(fileno(file_in));
|
|
// FIXME this ^ deserves some checks. But this looks tedious.
|
|
|
|
GElf_Ehdr ehdr;
|
|
GElf_Ehdr *ret = gelf_getehdr(root_die.get_elf(), &ehdr);
|
|
assert(ret != 0);
|
|
elf_machine = ehdr.e_machine;
|
|
}
|
|
|
|
DwarfInterpret& DwarfInterpret::acquire() {
|
|
if(DwarfInterpret::instance == nullptr)
|
|
throw NotInstanciated();
|
|
return *(DwarfInterpret::instance);
|
|
}
|
|
|
|
DwarfInterpret& DwarfInterpret::instanciate(const std::string& elf_path) {
|
|
if(DwarfInterpret::instance != nullptr)
|
|
throw AlreadyInstanciated();
|
|
DwarfInterpret::instance = std::unique_ptr<DwarfInterpret>(
|
|
new DwarfInterpret(elf_path));
|
|
return *(DwarfInterpret::instance);
|
|
}
|