#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 Function;
+class BasicBlock;
+class LLVMFunction;
+class LLVMBasicBlock;
+Disassembler * createLLVMDisassembler(const std::string& filename, InformationManager* manager);
+
+template <typename ELFT>
class LLVMDisassembler
- : public Disassembler {
+ : public Disassembler {
public:
- LLVMDisassembler(const std::string& filename);
- virtual ~LLVMDisassembler();
+ LLVMDisassembler(const std::string& filename, InformationManager* manager,
+ llvm::object::ELFObjectFile<ELFT>* file = NULL);
+ virtual ~LLVMDisassembler();
- void getSymbols();
- uint64_t entryAddress();
+ void start();
+ void getSymbols() {}
+ uint64_t entryAddress() {return _entryAddress;}
void forEachFunction(std::function<void (uint64_t, Function*)> callback);
- void printEachInstruction(uint64_t start, uint64_t end, std::function<void (const std::string&)> fun);
+ void printEachInstruction(uint64_t start, uint64_t end,
+ std::function<void (uint8_t*, size_t, const std::string&,
+ const std::string&)> fun);
BasicBlock * getBasicBlock(uint64_t address) {
return blocks[address];
}
+ Function * disassembleFunctionAt(uint64_t address, const std::string& name = "");
+
protected:
- bool isFunctionCall(uint64_t address) {return false;}
- bool isJump(uint64_t address) {return false;}
+ 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
+ typedef llvm::object::ELFFile<ELFT> ELFO;
+
+ // http://llvm.org/docs/doxygen/html/MCObjectDisassembler_8cpp_source.html +197
+ void disassembleFunction(LLVMFunction* function);
+ void splitBlocks(LLVMFunction* fun);
void disassemble();
void readSymbols();
void readSections();
+ void readDynamicSymbols();
- log4cxx::LoggerPtr logger;
+ 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;
-
-
- const llvm::Target * target;
- llvm::object::ObjectFile * o;
-
- std::unique_ptr<const llvm::MCRegisterInfo> MRI;
- std::unique_ptr<const llvm::MCAsmInfo> AsmInfo;
- std::unique_ptr<llvm::MCModule> Mod;
- std::unique_ptr<llvm::MCInstPrinter> IP;
- std::unique_ptr<llvm::MCDisassembler> DisAsm;
- std::unique_ptr<const llvm::MCObjectFileInfo> MOFI;
- std::unique_ptr<llvm::MCContext> Ctx;
- 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::map<std::string, llvm::object::SectionRef> sections;
- std::map<std::string, llvm::object::SymbolRef> symbols;
+ llvm::Triple triple;
+ std::shared_ptr<llvm::object::Binary> binary;
+
+ const llvm::Target * target;
+ llvm::object::ELFObjectFile<ELFT> * o;
+
+ std::unique_ptr<const llvm::MCRegisterInfo> MRI;
+ std::unique_ptr<const llvm::MCAsmInfo> AsmInfo;
+ std::unique_ptr<llvm::MCModule> Mod;
+ std::unique_ptr<llvm::MCInstPrinter> IP;
+ std::unique_ptr<llvm::MCDisassembler> DisAsm;
+ std::unique_ptr<const llvm::MCObjectFileInfo> MOFI;
+ std::unique_ptr<llvm::MCContext> Ctx;
+ std::unique_ptr<const llvm::MCInstrAnalysis> MIA;
+ std::unique_ptr<const llvm::MCSubtargetInfo> STI;
+ std::unique_ptr<const llvm::MCInstrInfo> MII;
+ 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;
+ InformationManager * manager;
+ uint64_t _entryAddress;
};
#endif