From 9fe5caf6408d1b7d5eb86dacdb211bd22335398a Mon Sep 17 00:00:00 2001 From: Christoph Egger Date: Fri, 20 Feb 2015 17:34:23 +0100 Subject: [PATCH] Pass the InformationManager inside the BasicBlock and Function classes All models should know the InformationManager so we can forward changes to any kind of information to the manager, who then is responsible to update all stakeholders of this information --- src/core/BasicBlock.hxx | 11 +++++++++-- src/core/Function.hxx | 14 +++++++++++--- src/disassembler/llvm/LLVMDisassembler.cxx | 12 ++++++------ 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/core/BasicBlock.hxx b/src/core/BasicBlock.hxx index 0a759bf..9018b5b 100644 --- a/src/core/BasicBlock.hxx +++ b/src/core/BasicBlock.hxx @@ -6,12 +6,15 @@ #include class Disassembler; +class InformationManager; class BasicBlock { public: - BasicBlock(uint64_t start_address, Disassembler * disassembler) + BasicBlock(uint64_t start_address, Disassembler * disassembler, + InformationManager* manager) : start_address(start_address) - , disassembler(disassembler) { + , disassembler(disassembler) + , manager(manager) { next_blocks[0] = 0; next_blocks[1] = 0; } @@ -52,10 +55,14 @@ public: return disassembler; } + InformationManager* getManager() const { + return manager; + } private: uint64_t start_address; uint64_t end_address; Disassembler* disassembler; + InformationManager* manager; uint64_t next_blocks[2]; }; diff --git a/src/core/Function.hxx b/src/core/Function.hxx index 3c8f799..f4fa90e 100644 --- a/src/core/Function.hxx +++ b/src/core/Function.hxx @@ -4,12 +4,15 @@ #include #include "BasicBlock.hxx" +class InformationManager; + class Function { public: - Function(const std::string& name, uint64_t start_address) + Function(const std::string& name, uint64_t start_address, + InformationManager* manager) : name(name) - , start_address(start_address) { - } + , start_address(start_address) + ,manager(manager) {} uint64_t getStartAddress() const { return start_address; @@ -19,6 +22,10 @@ public: return name; } + InformationManager* getManager() const { + return manager; + } + void addBasicBlock(BasicBlock* block) { _blocks.insert(std::make_pair(block->getStartAddress(), block)); } @@ -29,6 +36,7 @@ public: private: std::string name; uint64_t start_address; + InformationManager * manager; std::map _blocks; }; diff --git a/src/disassembler/llvm/LLVMDisassembler.cxx b/src/disassembler/llvm/LLVMDisassembler.cxx index 1d4f2df..b6f8dae 100644 --- a/src/disassembler/llvm/LLVMDisassembler.cxx +++ b/src/disassembler/llvm/LLVMDisassembler.cxx @@ -192,9 +192,9 @@ Function* LLVMDisassembler::disassembleFunctionAt(uint64_t address, const if (name == "") { std::stringstream s; s << ""; - function = new Function(s.str(), address); + function = new Function(s.str(), address, manager); } else { - function = new Function(name, address); + function = new Function(name, address, manager); } functions.insert(std::make_pair(address, function)); @@ -213,7 +213,7 @@ void LLVMDisassembler::disassembleFunction(Function* function) { LOG4CXX_DEBUG(logger, "Handling function " << function->getName()); - BasicBlock * block = new BasicBlock(function->getStartAddress(), this); + BasicBlock * block = new BasicBlock(function->getStartAddress(), this, manager); remaining_blocks.push(block); blocks.insert(std::make_pair(block->getStartAddress(), block)); function->addBasicBlock(block); @@ -247,7 +247,7 @@ void LLVMDisassembler::disassembleFunction(Function* function) { } else { current_block->setNextBlock(0, jmptarget); if (blocks.find(jmptarget) == blocks.end()) { - BasicBlock * block = new BasicBlock(jmptarget, this); + BasicBlock * block = new BasicBlock(jmptarget, this, manager); blocks.insert(std::make_pair(block->getStartAddress(), block)); function->addBasicBlock(block); remaining_blocks.push(block); @@ -259,7 +259,7 @@ void LLVMDisassembler::disassembleFunction(Function* function) { jmptarget = base_address + current_address + inst_size; current_block->setNextBlock(1, jmptarget); if (blocks.find(jmptarget) == blocks.end()) { - BasicBlock * block = new BasicBlock(jmptarget, this); + BasicBlock * block = new BasicBlock(jmptarget, this, manager); blocks.insert(std::make_pair(block->getStartAddress(), block)); function->addBasicBlock(block); remaining_blocks.push(block); @@ -310,7 +310,7 @@ void LLVMDisassembler::disassemble() { continue; if (!x->second.getAddress(result)) { - Function * fun = new Function(x->first, result); + Function * fun = new Function(x->first, result, manager); remaining_functions.push_back(fun); functions.insert(std::make_pair(result, fun)); LOG4CXX_DEBUG(logger, "Disasembling " << x->first); -- 2.39.5