]> git.siccegge.de Git - frida/frida.git/blobdiff - src/disassembler/llvm/LLVMDisassembler.hxx
Forward-port to LLVM 3.5 release
[frida/frida.git] / src / disassembler / llvm / LLVMDisassembler.hxx
index ff81be55385890a7ca642d9fa7d50a469ea001ac..6ed3c8c86936b75c383097e3ff841fd0db8ad027 100644 (file)
@@ -2,33 +2,49 @@
 #define INCLUDE__LLVMDisassembler_hxx
 
 #include <memory>
+#include <map>
 #include <log4cxx/logger.h>
 
 #include "include_llvm.hxx"
 
 #include "disassembler/Disassembler.hxx"
+#include "disassembler/BasicBlock.hxx"
+#include "disassembler/Function.hxx"
+#include "disassembler/llvm/LLVMBasicBlock.hxx"
+#include "disassembler/llvm/LLVMFunction.hxx"
 
 
 class LLVMDisassembler
     : public Disassembler {
 public:
     LLVMDisassembler(const std::string& filename);
-    virtual ~LLVMDisassembler() {};
+    virtual ~LLVMDisassembler();
 
        void getSymbols();
        uint64_t entryAddress();
 
-    void forEachInstruction(const std::string& name, std::function<void (long, std::string, std::string)> callback) {}
+       void forEachFunction(std::function<void (uint64_t, Function*)> callback);
+       void printEachInstruction(uint64_t start, uint64_t end,
+                                                         std::function<void (uint8_t*, size_t, const std::string&)> fun);
 
-       BasicBlock * generateControlFlowGraph(const std::string& name);
-       BasicBlock * generateControlFlowGraph(uint64_t address);
+       BasicBlock * getBasicBlock(uint64_t address) {
+               return blocks[address];
+       }
 
 protected:
     bool isFunctionCall(uint64_t address) {return false;}
     bool isJump(uint64_t address) {return false;}
 
 private:
+    // http://llvm.org/docs/doxygen/html/MCObjectDisassembler_8cpp_source.html +197
+       void disassemble();
+
+       void readSymbols();
+       void readSections();
+
     log4cxx::LoggerPtr logger;
+       std::map<uint64_t, LLVMBasicBlock*> blocks;
+       std::map<uint64_t, LLVMFunction*> functions;
 
     llvm::Triple triple;
     std::shared_ptr<llvm::object::Binary> binary;
@@ -47,8 +63,8 @@ private:
     std::unique_ptr<const llvm::MCInstrAnalysis> MIA;
     std::unique_ptr<const llvm::MCSubtargetInfo> STI;
     std::unique_ptr<const llvm::MCInstrInfo> MII;
-       llvm::OwningPtr<llvm::MCRelocationInfo> RelInfo;
-       llvm::OwningPtr<llvm::MCSymbolizer> Symzer;
+    std::unique_ptr<llvm::MCRelocationInfo> RelInfo;
+    std::unique_ptr<llvm::MCSymbolizer> Symzer;
 
     std::map<std::string, llvm::object::SectionRef> sections;
     std::map<std::string, llvm::object::SymbolRef> symbols;