]> git.cworth.org Git - apitrace/commitdiff
common: carve out RawStackFrame::dump
authorAlexander Monakov <amonakov@ispras.ru>
Fri, 12 Jul 2013 20:17:12 +0000 (00:17 +0400)
committerJosé Fonseca <jfonseca@vmware.com>
Fri, 20 Sep 2013 13:52:03 +0000 (14:52 +0100)
common/trace_dump.cpp
common/trace_model.hpp

index 6e67e08ab53e0f2585d5a1e952b9d00bae220b02..8732d1e56aeeb580a046f0b64b99d7ac8bb0de15 100644 (file)
@@ -229,23 +229,7 @@ public:
     }
 
     void visit(StackFrame *frame) {
-        if (frame->module != NULL) {
-            os << frame->module << " ";
-        }
-        if (frame->function != NULL) {
-            os << "at " << frame->function << "() ";
-        }
-        if (frame->filename != NULL) {
-            os << "at " << frame->filename;
-            if (frame->linenumber >= 0) {
-                os << ":" << frame->linenumber << " ";
-            }
-        }
-        else {
-            if (frame->offset >= 0) {
-                os << "[" << "0x" << std::hex << frame->offset << std::dec << "]";
-            }
-        }
+        frame->dump(os);
     }
 
     void visit(Backtrace & backtrace) {
index 36f0a03eff83cb15d5919fb86b661eb0cd271513..ba7c845362e55fdc5aae14fe42a4597fada84e49 100644 (file)
@@ -36,6 +36,7 @@
 
 #include <map>
 #include <vector>
+#include <ostream>
 
 
 namespace trace {
@@ -388,6 +389,22 @@ struct RawStackFrame {
         offset(-1)
     {
     }
+
+    void dump(std::ostream &os) {
+        os << (this->module ? this->module : "?");
+        if (this->function != NULL) {
+            os << ": " << this->function;
+        }
+        if (this->offset >= 0) {
+            os << "+0x" << std::hex << this->offset << std::dec;
+        }
+        if (this->filename != NULL) {
+            os << ": " << this->filename;
+            if (this->linenumber >= 0) {
+                os << ":" << this->linenumber;
+            }
+        }
+    }
 };
 
 class StackFrame : public RawStackFrame {