diff --git a/include/ehp.hpp b/include/ehp.hpp index bbdb80a84fba36a4cd815c08589e13b6c2994b41..e5c5d979b7920822c714409e6c7b4d6b37a82741 100644 --- a/include/ehp.hpp +++ b/include/ehp.hpp @@ -26,6 +26,8 @@ class EHProgramInstruction_t virtual bool isRestoreState() const =0; virtual bool isRememberState() const =0; virtual const EHProgramInstructionByteVector_t& getBytes() const =0; + virtual bool advance(uint64_t &cur_addr, uint64_t CAF) const =0; + }; using EHProgramInstructionVector_t = vector<shared_ptr<EHProgramInstruction_t> >; @@ -98,7 +100,9 @@ class LSDACallSite_t virtual void print() const=0; }; -using CallSiteVector_t = vector<shared_ptr<LSDACallSite_t> > ; +using CallSiteVector_t = vector<shared_ptr<LSDACallSite_t> >; +using TypeTableVector_t = vector<shared_ptr<LSDATypeTableEntry_t> >; + class LSDA_t { protected: @@ -109,6 +113,7 @@ class LSDA_t virtual uint8_t getTTEncoding() const =0; virtual void print() const=0; virtual shared_ptr<CallSiteVector_t> getCallSites() const =0; + virtual shared_ptr<TypeTableVector_t> getTypeTable() const =0; }; class FDEContents_t @@ -123,6 +128,7 @@ class FDEContents_t virtual const CIEContents_t& getCIE() const =0; virtual const EHProgram_t& getProgram() const =0; virtual shared_ptr<LSDA_t> getLSDA() const =0; + virtual uint64_t getLSDAAddress() const =0; virtual void print() const=0; // move to ostream? toString? }; diff --git a/src/ehp.cpp b/src/ehp.cpp index 5e1e054fa37d2357a4b1fa0752ddedfea67f0a6f..1f1250b862a29c0f7bcca752475539b1bd1450a0 100644 --- a/src/ehp.cpp +++ b/src/ehp.cpp @@ -732,7 +732,7 @@ bool eh_program_insn_t<ptrsize>::isRememberState() const } template <int ptrsize> -bool eh_program_insn_t<ptrsize>::Advance(uint64_t &cur_addr, uint64_t CAF) const +bool eh_program_insn_t<ptrsize>::advance(uint64_t &cur_addr, uint64_t CAF) const { // make sure uint8_t is an unsigned char. static_assert(std::is_same<unsigned char, uint8_t>::value, "uint8_t is not unsigned char"); @@ -1617,6 +1617,27 @@ void split_eh_frame_impl_t<ptrsize>::print() const } +template <int ptrsize> +shared_ptr<EHProgramInstructionVector_t> eh_program_t<ptrsize>::getInstructions() const +{ + auto ret=shared_ptr<EHProgramInstructionVector_t>(new EHProgramInstructionVector_t()); + transform(ALLOF(getInstructionsInternal()), back_inserter(*ret), + [](const eh_program_insn_t<ptrsize> &a) { return shared_ptr<EHProgramInstruction_t>(new eh_program_insn_t<ptrsize>(a));}); + return shared_ptr<EHProgramInstructionVector_t>(ret); + +} + + +template <int ptrsize> +shared_ptr<TypeTableVector_t> lsda_t<ptrsize>::getTypeTable() const +{ + auto ret=shared_ptr<TypeTableVector_t>(new TypeTableVector_t()); + transform(ALLOF(type_table), back_inserter(*ret), + [](const lsda_type_table_entry_t<ptrsize> &a) { return shared_ptr<LSDATypeTableEntry_t>(new lsda_type_table_entry_t<ptrsize>(a));}); + return shared_ptr<TypeTableVector_t>(ret); +} + + template <int ptrsize> shared_ptr<CallSiteVector_t> lsda_t<ptrsize>::getCallSites() const { diff --git a/src/ehp_priv.hpp b/src/ehp_priv.hpp index 4864b3b08f1e9ee87dc9eada16118a9596f8fa13..af7b7a765cf97846d51173807f866f7147afa082 100644 --- a/src/ehp_priv.hpp +++ b/src/ehp_priv.hpp @@ -97,7 +97,7 @@ class eh_program_insn_t : public EHProgramInstruction_t bool isRestoreState() const ; bool isRememberState() const ; - bool Advance(uint64_t &cur_addr, uint64_t CAF) const ; + bool advance(uint64_t &cur_addr, uint64_t CAF) const ; const std::vector<uint8_t>& getBytes() const ; std::vector<uint8_t>& getBytes() ; @@ -122,7 +122,7 @@ class eh_program_t : public EHProgram_t const uint32_t& program_start_position, const uint8_t* const data, const uint32_t &max_program_pos); - virtual shared_ptr<EHProgramInstructionVector_t> getInstructions() const { assert(0); } + virtual shared_ptr<EHProgramInstructionVector_t> getInstructions() const ; std::vector<eh_program_insn_t <ptrsize> >& getInstructionsInternal() ; const std::vector<eh_program_insn_t <ptrsize> >& getInstructionsInternal() const ; @@ -266,6 +266,7 @@ class lsda_call_site_t : public LSDACallSite_t, private eh_frame_util_t<ptrsize> // short hand for a vector of call sites template <int ptrsize> using call_site_table_t = std::vector<lsda_call_site_t <ptrsize> > ; +template <int ptrsize> using lsda_type_table_t = std::vector<lsda_type_table_entry_t <ptrsize> > ; template <int ptrsize> class lsda_t : public LSDA_t, private eh_frame_util_t<ptrsize> @@ -282,8 +283,8 @@ class lsda_t : public LSDA_t, private eh_frame_util_t<ptrsize> uint64_t cs_table_length; uint64_t cs_table_end_addr; uint64_t action_table_start_addr; - call_site_table_t <ptrsize> call_site_table; - std::vector<lsda_type_table_entry_t <ptrsize> > type_table; + call_site_table_t<ptrsize> call_site_table; + lsda_type_table_t<ptrsize> type_table; public: @@ -300,6 +301,8 @@ class lsda_t : public LSDA_t, private eh_frame_util_t<ptrsize> shared_ptr<CallSiteVector_t> getCallSites() const ; const call_site_table_t<ptrsize> getCallSitesInternal() const { return call_site_table;} + shared_ptr<TypeTableVector_t> getTypeTable() const ; + }; @@ -346,6 +349,8 @@ class fde_contents_t : public FDEContents_t, eh_frame_util_t<ptrsize> shared_ptr<LSDA_t> getLSDA() const { return shared_ptr<LSDA_t>(new lsda_t<ptrsize>(lsda)) ; } const lsda_t<ptrsize>& getLSDAInternal() const { return lsda; } + uint64_t getLSDAAddress() const { return lsda_addr; } + bool parse_fde( const uint32_t &fde_position, const uint32_t &cie_position,