]> git.siccegge.de Git - frida/frida.git/blob - src/disassembler/llvm/LLVMDisassembler.hxx
Make function/jump targets clickable
[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 virtual ~LLVMDisassembler();
25
26 void start();
27 void getSymbols() {}
28 uint64_t entryAddress() {return _entryAddress;}
29
30 void forEachFunction(std::function<void (uint64_t, Function*)> callback);
31 void printEachInstruction(uint64_t start, uint64_t end,
32 std::function<void (uint8_t*, size_t, const std::string&,
33 const std::string&)> fun);
34
35 BasicBlock * getBasicBlock(uint64_t address) {
36 return blocks[address];
37 }
38
39 Function * disassembleFunctionAt(uint64_t address, const std::string& name = "");
40
41 protected:
42 bool isFunctionCall(uint64_t address) {return false;}
43 bool isJump(uint64_t address) {return false;}
44
45 private:
46 // http://llvm.org/docs/doxygen/html/MCObjectDisassembler_8cpp_source.html +197
47 void disassembleFunction(LLVMFunction* function);
48 void splitBlocks(LLVMFunction* fun);
49 void disassemble();
50
51 void readSymbols();
52 void readSections();
53
54 log4cxx::LoggerPtr logger;
55 std::map<uint64_t, LLVMBasicBlock*> blocks;
56 std::map<uint64_t, LLVMFunction*> functions;
57
58 llvm::Triple triple;
59 std::shared_ptr<llvm::object::Binary> binary;
60
61 const llvm::Target * target;
62 llvm::object::ObjectFile * o;
63
64 std::unique_ptr<const llvm::MCRegisterInfo> MRI;
65 std::unique_ptr<const llvm::MCAsmInfo> AsmInfo;
66 std::unique_ptr<llvm::MCModule> Mod;
67 std::unique_ptr<llvm::MCInstPrinter> IP;
68 std::unique_ptr<llvm::MCDisassembler> DisAsm;
69 std::unique_ptr<const llvm::MCObjectFileInfo> MOFI;
70 std::unique_ptr<llvm::MCContext> Ctx;
71 std::unique_ptr<const llvm::MCInstrAnalysis> MIA;
72 std::unique_ptr<const llvm::MCSubtargetInfo> STI;
73 std::unique_ptr<const llvm::MCInstrInfo> MII;
74 std::unique_ptr<llvm::MCRelocationInfo> RelInfo;
75 std::unique_ptr<llvm::MCSymbolizer> Symzer;
76
77 std::map<std::string, llvm::object::SectionRef> sections;
78 std::map<std::string, llvm::object::SymbolRef> symbols;
79 InformationManager * manager;
80 uint64_t _entryAddress;
81 };
82
83 #endif