1 #ifndef INCLUDE__LLVMDisassembler_hxx
2 #define INCLUDE__LLVMDisassembler_hxx
6 #include <log4cxx/logger.h>
8 #include "include_llvm.hxx"
10 #include "disassembler/Disassembler.hxx"
16 Disassembler * createLLVMDisassembler(const std::string& filename, InformationManager* manager);
18 template <typename ELFT>
19 class LLVMDisassembler
20 : public Disassembler {
22 LLVMDisassembler(const std::string& filename, InformationManager* manager,
23 llvm::object::ELFObjectFile<ELFT>* file = NULL);
24 virtual ~LLVMDisassembler();
28 uint64_t entryAddress() {return _entryAddress;}
30 void forEachFunction(std::function<void (uint64_t, Function*)> callback);
31 void printEachInstruction(uint64_t start, uint64_t end,
32 std::function<void (uint8_t*, size_t, const std::string&,
33 const std::string&)> fun);
35 BasicBlock * getBasicBlock(uint64_t address) {
36 return blocks[address];
39 Function * disassembleFunctionAt(uint64_t address, const std::string& name = "");
42 bool isFunctionCall(uint64_t address) {return false;}
43 bool isJump(uint64_t address) {return false;}
46 typedef llvm::object::ELFFile<ELFT> ELFO;
48 // http://llvm.org/docs/doxygen/html/MCObjectDisassembler_8cpp_source.html +197
49 void disassembleFunction(Function* function);
50 void splitBlocks(Function* fun);
55 void readDynamicSymbols();
57 log4cxx::LoggerPtr logger;
58 std::map<uint64_t, LLVMBasicBlock*> blocks;
59 std::map<uint64_t, Function*> functions;
62 std::shared_ptr<llvm::object::Binary> binary;
64 const llvm::Target * target;
65 llvm::object::ELFObjectFile<ELFT> * o;
67 std::unique_ptr<const llvm::MCRegisterInfo> MRI;
68 std::unique_ptr<const llvm::MCAsmInfo> AsmInfo;
69 std::unique_ptr<llvm::MCModule> Mod;
70 std::unique_ptr<llvm::MCInstPrinter> IP;
71 std::unique_ptr<llvm::MCDisassembler> DisAsm;
72 std::unique_ptr<const llvm::MCObjectFileInfo> MOFI;
73 std::unique_ptr<llvm::MCContext> Ctx;
74 std::unique_ptr<const llvm::MCInstrAnalysis> MIA;
75 std::unique_ptr<const llvm::MCSubtargetInfo> STI;
76 std::unique_ptr<const llvm::MCInstrInfo> MII;
77 std::unique_ptr<llvm::MCRelocationInfo> RelInfo;
78 std::unique_ptr<llvm::MCSymbolizer> Symzer;
80 std::map<std::string, llvm::object::SectionRef> sections;
81 std::map<std::string, llvm::object::SymbolRef> symbols;
82 InformationManager * manager;
83 uint64_t _entryAddress;