]> git.siccegge.de Git - frida/frida.git/commitdiff
Make pieces of information serialize themselves
authorChristoph Egger <Christoph.Egger@fau.de>
Tue, 3 Mar 2015 13:26:10 +0000 (14:26 +0100)
committerChristoph Egger <Christoph.Egger@fau.de>
Tue, 3 Mar 2015 14:34:34 +0000 (15:34 +0100)
Moving responsibility of serialization to the individual pieces of
Information.

CMakeLists.txt
src/core/BasicBlock.cxx [new file with mode: 0644]
src/core/BasicBlock.hxx
src/core/Function.cxx
src/core/Function.hxx
src/core/InformationManager.cxx

index 0fe40fbae181dfdfbb05378dcb92b847ae77c4e6..e9ff46b72a838b4a8ad2c4d8f36f5bc36f874958 100644 (file)
@@ -45,6 +45,7 @@ separate_arguments(LLVM_LIBS)
 SET(frida_SOURCES
   src/main.cxx
   src/core/InformationManager.cxx
+  src/core/BasicBlock.cxx
   src/core/Function.cxx
   src/gui/Mainwindow.cxx
   src/gui/widgets/BasicBlockWidget.cxx
diff --git a/src/core/BasicBlock.cxx b/src/core/BasicBlock.cxx
new file mode 100644 (file)
index 0000000..0dec430
--- /dev/null
@@ -0,0 +1,14 @@
+#include "BasicBlock.hxx"
+#include "gui/qt.hxx"
+
+void BasicBlock::serialize(QXmlStreamWriter& stream) {
+       stream.writeStartElement("block");
+       stream.writeAttribute("id", getName().c_str());
+       stream.writeTextElement("start", QString::number(getStartAddress(), 16));
+       stream.writeTextElement("end", QString::number(getEndAddress(), 16));
+       if (0 != getNextBlock(0))
+               stream.writeTextElement("next", QString::number(getNextBlock(0), 16));
+       if (0 != getNextBlock(1))
+               stream.writeTextElement("next", QString::number(getNextBlock(1), 16));
+       stream.writeEndElement(); // "block"
+}
index 69d4f37d9c85cb8643bccdd713bb40f9c9adf102..c7ae26eb0a3c03d7650b47653a77a888f456239d 100644 (file)
@@ -7,6 +7,7 @@
 
 class Disassembler;
 class InformationManager;
+class QXmlStreamWriter;
 
 class BasicBlock {
 public:
@@ -45,6 +46,8 @@ public:
        InformationManager* getManager() const {
                return manager;
        }
+
+       void serialize(QXmlStreamWriter& stream);
 private:
        BasicBlock(uint64_t start_address, InformationManager* manager)
                : start_address(start_address)
index 539192c5fd6f2fb2cb90e914c39acf17749d1042..1df4d1dba3b6a154c337c6d06f63bedcb3a2e6cd 100644 (file)
@@ -1,8 +1,7 @@
 #include "Function.hxx"
 #include "core/events/RenameFunctionEvent.hxx"
 #include "InformationManager.hxx"
-
-#include <iostream>
+#include "gui/qt.hxx"
 
 Function::Function(uint64_t start_address, InformationManager* manager)
        : start_address(start_address)
@@ -15,3 +14,14 @@ void Function::setName(const std::string& new_name) {
        manager->dispatch(&event);
 }
 
+void Function::serialize(QXmlStreamWriter& stream) {
+       stream.writeStartElement("function");
+       stream.writeAttribute("name", getName().c_str());
+       stream.writeAttribute("entry", QString::number(getStartAddress(), 16));
+
+       for (auto& blockentry : blocks()) {
+               blockentry.second->serialize(stream);
+       }
+
+       stream.writeEndElement(); // "function"
+}
index 5497800969e57b8f12a2a2c8e24bdaf20688c675..d567c28c4828b4763378fd0cbed5b5adb3a42795 100644 (file)
@@ -5,10 +5,10 @@
 #include "BasicBlock.hxx"
 
 class InformationManager;
+class QXmlStreamWriter;
 
 class Function {
 public:
-
        uint64_t getStartAddress() const {
                return start_address;
        }
@@ -28,6 +28,8 @@ public:
        const std::map<uint64_t, BasicBlock*>& blocks() {
                return _blocks;
        }
+
+       void serialize(QXmlStreamWriter& stream);
 private:
        Function(uint64_t start_address, InformationManager* manager);
 
index 294dc2f53583b7e3a9c5ce6b8f33fd49427bf058..3eebc3422300cfde2f68323192d7f20b2a46f203 100644 (file)
@@ -37,23 +37,9 @@ void InformationManager::save(const QString& filename) {
                stream.setAutoFormatting(true);
                stream.setAutoFormattingIndent(-1);
                stream.writeStartDocument();
-               stream.writeStartElement("function");
-               stream.writeAttribute("name", fun->getName().c_str());
-               stream.writeAttribute("entry", QString::number(fun->getStartAddress(), 16));
-
-               for (auto& blockentry : fun->blocks()) {
-                       stream.writeStartElement("block");
-                       stream.writeAttribute("id", blockentry.second->getName().c_str());
-                       stream.writeTextElement("start", QString::number(blockentry.second->getStartAddress(), 16));
-                       stream.writeTextElement("end", QString::number(blockentry.second->getEndAddress(), 16));
-                       if (0 != blockentry.second->getNextBlock(0))
-                               stream.writeTextElement("next", QString::number(blockentry.second->getNextBlock(0), 16));
-                       if (0 != blockentry.second->getNextBlock(1))
-                               stream.writeTextElement("next", QString::number(blockentry.second->getNextBlock(1), 16));
-                       stream.writeEndElement(); // "block"
-               }
-
-               stream.writeEndElement(); // "function"
+
+               fun->serialize(stream);
+
                stream.writeEndDocument();
                outZipFile.close();
        }