Avoid memory leak
[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
28 BasicBlock * generateControlFlowGraph(const std::string& name);
29 BasicBlock * generateControlFlowGraph(uint64_t address);
30
31 protected:
32 bool isFunctionCall(uint64_t address) {return false;}
33 bool isJump(uint64_t address) {return false;}
34
35 private:
36 void disassemble();
37
38 void readSymbols();
39 void readSections();
40
41 log4cxx::LoggerPtr logger;
42 std::map<uint64_t, LLVMBasicBlock*> blocks;
43 std::map<uint64_t, LLVMFunction*> functions;
44
45 llvm::Triple triple;
46 std::shared_ptr<llvm::object::Binary> binary;
47
48
49 const llvm::Target * target;
50 llvm::object::ObjectFile * o;
51
52 std::unique_ptr<const llvm::MCRegisterInfo> MRI;
53 std::unique_ptr<const llvm::MCAsmInfo> AsmInfo;
54 std::unique_ptr<llvm::MCModule> Mod;
55 std::unique_ptr<llvm::MCInstPrinter> IP;
56 std::unique_ptr<llvm::MCDisassembler> DisAsm;
57 std::unique_ptr<const llvm::MCObjectFileInfo> MOFI;
58 std::unique_ptr<llvm::MCContext> Ctx;
59 std::unique_ptr<const llvm::MCInstrAnalysis> MIA;
60 std::unique_ptr<const llvm::MCSubtargetInfo> STI;
61 std::unique_ptr<const llvm::MCInstrInfo> MII;
62 llvm::OwningPtr<llvm::MCRelocationInfo> RelInfo;
63 llvm::OwningPtr<llvm::MCSymbolizer> Symzer;
64
65 std::map<std::string, llvm::object::SectionRef> sections;
66 std::map<std::string, llvm::object::SymbolRef> symbols;
67 };
68
69 #endif