]> git.siccegge.de Git - frida/frida.git/blob - src/disassembler/llvm/LLVMDisassembler.hxx
Create ObjectFile only once and store it with full type
[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 #include "disassembler/BasicBlock.hxx"
12 #include "disassembler/Function.hxx"
13 #include "disassembler/llvm/LLVMBasicBlock.hxx"
14 #include "disassembler/llvm/LLVMFunction.hxx"
15
16
17 Disassembler * createLLVMDisassembler(const std::string& filename, InformationManager* manager);
18
19 template <typename ELFT>
20 class LLVMDisassembler
21 : public Disassembler {
22 public:
23 LLVMDisassembler(const std::string& filename, InformationManager* manager,
24 llvm::object::ELFObjectFile<ELFT>* file = NULL);
25 virtual ~LLVMDisassembler();
26
27 void start();
28 void getSymbols() {}
29 uint64_t entryAddress() {return _entryAddress;}
30
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);
35
36 BasicBlock * getBasicBlock(uint64_t address) {
37 return blocks[address];
38 }
39
40 Function * disassembleFunctionAt(uint64_t address, const std::string& name = "");
41
42 protected:
43 bool isFunctionCall(uint64_t address) {return false;}
44 bool isJump(uint64_t address) {return false;}
45
46 private:
47 // http://llvm.org/docs/doxygen/html/MCObjectDisassembler_8cpp_source.html +197
48 void disassembleFunction(LLVMFunction* function);
49 void splitBlocks(LLVMFunction* fun);
50 void disassemble();
51
52 void readSymbols();
53 void readSections();
54
55 log4cxx::LoggerPtr logger;
56 std::map<uint64_t, LLVMBasicBlock*> blocks;
57 std::map<uint64_t, LLVMFunction*> functions;
58
59 llvm::Triple triple;
60 std::shared_ptr<llvm::object::Binary> binary;
61
62 const llvm::Target * target;
63 llvm::object::ELFObjectFile<ELFT> * o;
64
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;
77
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;
82 };
83
84 #endif