]> git.siccegge.de Git - frida/frida.git/blob - src/disassembler/llvm/LLVMDisassembler.hxx
Properly create and export BasicBlock linking
[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 class LLVMDisassembler
18 : public Disassembler {
19 public:
20 LLVMDisassembler(const std::string& filename);
21 virtual ~LLVMDisassembler();
22
23 void getSymbols();
24 uint64_t entryAddress();
25
26 void forEachFunction(std::function<void (uint64_t, Function*)> callback);
27 BasicBlock * getBasicBlock(uint64_t address) {
28 return blocks[address];
29 }
30
31 protected:
32 bool isFunctionCall(uint64_t address) {return false;}
33 bool isJump(uint64_t address) {return false;}
34
35 private:
36 // http://llvm.org/docs/doxygen/html/MCObjectDisassembler_8cpp_source.html +197
37 void disassemble();
38
39 void readSymbols();
40 void readSections();
41
42 log4cxx::LoggerPtr logger;
43 std::map<uint64_t, LLVMBasicBlock*> blocks;
44 std::map<uint64_t, LLVMFunction*> functions;
45
46 llvm::Triple triple;
47 std::shared_ptr<llvm::object::Binary> binary;
48
49
50 const llvm::Target * target;
51 llvm::object::ObjectFile * o;
52
53 std::unique_ptr<const llvm::MCRegisterInfo> MRI;
54 std::unique_ptr<const llvm::MCAsmInfo> AsmInfo;
55 std::unique_ptr<llvm::MCModule> Mod;
56 std::unique_ptr<llvm::MCInstPrinter> IP;
57 std::unique_ptr<llvm::MCDisassembler> DisAsm;
58 std::unique_ptr<const llvm::MCObjectFileInfo> MOFI;
59 std::unique_ptr<llvm::MCContext> Ctx;
60 std::unique_ptr<const llvm::MCInstrAnalysis> MIA;
61 std::unique_ptr<const llvm::MCSubtargetInfo> STI;
62 std::unique_ptr<const llvm::MCInstrInfo> MII;
63 llvm::OwningPtr<llvm::MCRelocationInfo> RelInfo;
64 llvm::OwningPtr<llvm::MCSymbolizer> Symzer;
65
66 std::map<std::string, llvm::object::SectionRef> sections;
67 std::map<std::string, llvm::object::SymbolRef> symbols;
68 };
69
70 #endif