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"
15 Disassembler * createLLVMDisassembler(const std::string& filename, InformationManager* manager);
17 template <typename ELFT>
18 class LLVMDisassembler
19 : public Disassembler {
21 LLVMDisassembler(const std::string& filename, InformationManager* manager,
22 llvm::object::ELFObjectFile<ELFT>* file = NULL);
23 virtual ~LLVMDisassembler();
27 uint64_t entryAddress() {return _entryAddress;}
29 void forEachFunction(std::function<void (uint64_t, Function*)> callback);
30 void printEachInstruction(uint64_t start, uint64_t end,
31 std::function<void (uint8_t*, size_t, const std::string&,
32 const std::string&)> fun);
34 BasicBlock * getBasicBlock(uint64_t address) {
35 return blocks[address];
38 Function * disassembleFunctionAt(uint64_t address, const std::string& name = "");
41 bool isFunctionCall(uint64_t address) {return false;}
42 bool isJump(uint64_t address) {return false;}
45 typedef llvm::object::ELFFile<ELFT> ELFO;
47 // http://llvm.org/docs/doxygen/html/MCObjectDisassembler_8cpp_source.html +197
48 void disassembleFunction(Function* function);
49 void splitBlocks(Function* fun);
54 void readDynamicSymbols();
56 log4cxx::LoggerPtr logger;
57 std::map<uint64_t, BasicBlock*> blocks;
58 std::map<uint64_t, Function*> functions;
61 std::shared_ptr<llvm::object::Binary> binary;
63 const llvm::Target * target;
64 llvm::object::ELFObjectFile<ELFT> * o;
66 std::unique_ptr<const llvm::MCRegisterInfo> MRI;
67 std::unique_ptr<const llvm::MCAsmInfo> AsmInfo;
68 std::unique_ptr<llvm::MCModule> Mod;
69 std::unique_ptr<llvm::MCInstPrinter> IP;
70 std::unique_ptr<llvm::MCDisassembler> DisAsm;
71 std::unique_ptr<const llvm::MCObjectFileInfo> MOFI;
72 std::unique_ptr<llvm::MCContext> Ctx;
73 std::unique_ptr<const llvm::MCInstrAnalysis> MIA;
74 std::unique_ptr<const llvm::MCSubtargetInfo> STI;
75 std::unique_ptr<const llvm::MCInstrInfo> MII;
76 std::unique_ptr<llvm::MCRelocationInfo> RelInfo;
77 std::unique_ptr<llvm::MCSymbolizer> Symzer;
79 std::map<std::string, llvm::object::SectionRef> sections;
80 std::map<std::string, llvm::object::SymbolRef> symbols;
81 InformationManager * manager;
82 uint64_t _entryAddress;