dwarfinterpret/include/DwarfInterpret.hpp

70 lines
2 KiB
C++
Raw Normal View History

#pragma once
#include <string>
#include <memory>
#include <cstdint>
#include <dwarfpp/lib.hpp>
#include <dwarfpp/regs.hpp>
#include <dwarfpp/frame.hpp>
#include <dwarfpp/attr.hpp>
#include <dwarfpp/frame.hpp>
#include <dwarfpp/root.hpp>
class DwarfInterpret {
/** Singleton class holding a Dwarf interpret.
* Must be first instanciated with the path to the binary being run, with a
* call to `instanciate`, and can afterwards be accessed with calls to
* `acquire`.
*/
public:
class NotInstanciated: public std::exception {};
class AlreadyInstanciated: public std::exception {};
class ValuelessRegister: public std::exception {};
class NotImplemented: public std::exception {};
class FailedGetContext: public std::exception {};
typedef dwarf::core::FrameSection::register_def DwarfRegister;
typedef std::set<std::pair<int, DwarfRegister> > DwarfRow; // FIXME
typedef uintptr_t reg_content_t;
private:
//typedef std::set<std::pair<int, DwarfRegister> > DwarfRow;
public:
DwarfInterpret(DwarfInterpret const&) = delete;
void operator=(DwarfInterpret const&) = delete;
static DwarfInterpret& acquire();
static DwarfInterpret& instanciate(const std::string& elf_path);
2018-03-28 16:03:43 +02:00
int get_elf_machine() const { return elf_machine; }
reg_content_t interpret_dw_register(
const DwarfRow& row,
const DwarfRegister& reg
) const;
reg_content_t interpret_dw_register(
const DwarfRow& row,
int reg_id
) const;
2018-03-28 16:03:43 +02:00
private:
DwarfInterpret(const std::string& elf_path);
DwarfRegister get_column(const DwarfRow& row, int column) const;
reg_content_t get_cpu_register(int reg_id) const;
private: // members
static std::unique_ptr<DwarfInterpret> instance;
dwarf::core::root_die root_die;
int elf_machine;
friend class std::unique_ptr<DwarfInterpret>;
};