Reoganize Function/BasicBlock creation
[frida/frida.git] / src / disassembler / llvm / LLVMDisassembler.hxx
1 #ifndef INCLUDE__LLVMDisassembler_hxx
2 #define INCLUDE__LLVMDisassembler_hxx
3
4 #include <memory>
5 #include <map>
6 #include <log4cxx/logger.h>
7
8 #include "include_llvm.hxx"
9
10 #include "disassembler/Disassembler.hxx"
11
12 class Function;
13 class BasicBlock;
14
15 Disassembler * createLLVMDisassembler(const std::string& filename, InformationManager* manager);
16
17 template <typename ELFT>
18 class LLVMDisassembler
19 : public Disassembler {
20 public:
21 LLVMDisassembler(const std::string& filename, InformationManager* manager,
22 llvm::object::ELFObjectFile<ELFT>* file = NULL);
23 virtual ~LLVMDisassembler();
24
25 void start();
26 void getSymbols() {}
27 uint64_t entryAddress() {return _entryAddress;}
28
29 void printEachInstruction(uint64_t start, uint64_t end,
30 std::function<void (uint8_t*, size_t, const std::string&,
31 const std::string&)> fun);
32
33 Function * disassembleFunctionAt(uint64_t address, const std::string& name = "");
34
35 protected:
36 bool isFunctionCall(uint64_t address) {return false;}
37 bool isJump(uint64_t address) {return false;}
38
39 private:
40 typedef llvm::object::ELFFile<ELFT> ELFO;
41
42 // http://llvm.org/docs/doxygen/html/MCObjectDisassembler_8cpp_source.html +197
43 void disassembleFunction(Function* function);
44 void splitBlocks(Function* fun);
45 void disassemble();
46
47 void readSymbols();
48 void readSections();
49 void readDynamicSymbols();
50
51 log4cxx::LoggerPtr logger;
52
53 llvm::Triple triple;
54 std::shared_ptr<llvm::object::Binary> binary;
55
56 const llvm::Target * target;
57 llvm::object::ELFObjectFile<ELFT> * o;
58
59 std::unique_ptr<const llvm::MCRegisterInfo> MRI;
60 std::unique_ptr<const llvm::MCAsmInfo> AsmInfo;
61 std::unique_ptr<llvm::MCModule> Mod;
62 std::unique_ptr<llvm::MCInstPrinter> IP;
63 std::unique_ptr<llvm::MCDisassembler> DisAsm;
64 std::unique_ptr<const llvm::MCObjectFileInfo> MOFI;
65 std::unique_ptr<llvm::MCContext> Ctx;
66 std::unique_ptr<const llvm::MCInstrAnalysis> MIA;
67 std::unique_ptr<const llvm::MCSubtargetInfo> STI;
68 std::unique_ptr<const llvm::MCInstrInfo> MII;
69 std::unique_ptr<llvm::MCRelocationInfo> RelInfo;
70 std::unique_ptr<llvm::MCSymbolizer> Symzer;
71
72 std::map<std::string, llvm::object::SectionRef> sections;
73 std::map<std::string, llvm::object::SymbolRef> symbols;
74 InformationManager * manager;
75 uint64_t _entryAddress;
76 };
77
78 #endif