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"
11 #include "disassembler/BasicBlock.hxx"
12 #include "disassembler/Function.hxx"
13 #include "disassembler/llvm/LLVMBasicBlock.hxx"
14 #include "disassembler/llvm/LLVMFunction.hxx"
17 Disassembler * createLLVMDisassembler(const std::string& filename, InformationManager* manager);
19 template <typename ELFT>
20 class LLVMDisassembler
21 : public Disassembler {
23 LLVMDisassembler(const std::string& filename, InformationManager* manager,
24 llvm::object::ELFObjectFile<ELFT>* file = NULL);
25 virtual ~LLVMDisassembler();
29 uint64_t entryAddress() {return _entryAddress;}
31 void forEachFunction(std::function<void (uint64_t, Function*)> callback);
32 void printEachInstruction(uint64_t start, uint64_t end,
33 std::function<void (uint8_t*, size_t, const std::string&,
34 const std::string&)> fun);
36 BasicBlock * getBasicBlock(uint64_t address) {
37 return blocks[address];
40 Function * disassembleFunctionAt(uint64_t address, const std::string& name = "");
43 bool isFunctionCall(uint64_t address) {return false;}
44 bool isJump(uint64_t address) {return false;}
47 // http://llvm.org/docs/doxygen/html/MCObjectDisassembler_8cpp_source.html +197
48 void disassembleFunction(LLVMFunction* function);
49 void splitBlocks(LLVMFunction* fun);
55 log4cxx::LoggerPtr logger;
56 std::map<uint64_t, LLVMBasicBlock*> blocks;
57 std::map<uint64_t, LLVMFunction*> functions;
60 std::shared_ptr<llvm::object::Binary> binary;
62 const llvm::Target * target;
63 llvm::object::ELFObjectFile<ELFT> * o;
65 std::unique_ptr<const llvm::MCRegisterInfo> MRI;
66 std::unique_ptr<const llvm::MCAsmInfo> AsmInfo;
67 std::unique_ptr<llvm::MCModule> Mod;
68 std::unique_ptr<llvm::MCInstPrinter> IP;
69 std::unique_ptr<llvm::MCDisassembler> DisAsm;
70 std::unique_ptr<const llvm::MCObjectFileInfo> MOFI;
71 std::unique_ptr<llvm::MCContext> Ctx;
72 std::unique_ptr<const llvm::MCInstrAnalysis> MIA;
73 std::unique_ptr<const llvm::MCSubtargetInfo> STI;
74 std::unique_ptr<const llvm::MCInstrInfo> MII;
75 std::unique_ptr<llvm::MCRelocationInfo> RelInfo;
76 std::unique_ptr<llvm::MCSymbolizer> Symzer;
78 std::map<std::string, llvm::object::SectionRef> sections;
79 std::map<std::string, llvm::object::SymbolRef> symbols;
80 InformationManager * manager;
81 uint64_t _entryAddress;