]> git.cworth.org Git - apitrace/blobdiff - retrace.hpp
Merge branch 'master' into d3dretrace
[apitrace] / retrace.hpp
index b697adb6b2c7fa7495be034f831c1f47d23b025f..1b5fdd23cdff7ba01ee17d3164d8697e332f2229 100644 (file)
@@ -1,6 +1,6 @@
 /**************************************************************************
  *
- * Copyright 2011 Jose Fonseca
+ * Copyright 2011-2012 Jose Fonseca
  * All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
 
 #include <string.h>
 
+#include <list>
 #include <map>
+#include <ostream>
 
 #include "trace_model.hpp"
+#include "trace_parser.hpp"
 
 
 namespace retrace {
 
 
+extern trace::Parser parser;
+
+
 /**
  * Handle map.
  *
@@ -78,17 +84,82 @@ public:
 };
 
 
+/**
+ * Similar to alloca(), but implemented with malloc.
+ */
+class ScopedAllocator
+{
+private:
+    void *next;
+
+public:
+    ScopedAllocator() :
+        next(NULL) {
+    }
+
+    inline void *
+    alloc(size_t size) {
+        if (!size) {
+            return NULL;
+        }
+
+        void * * buf = static_cast<void **>(malloc(sizeof(void *) + size));
+        if (!buf) {
+            return NULL;
+        }
+
+        *buf = next;
+        next = buf;
+
+        return &buf[1];
+    }
+
+    template< class T >
+    inline T *
+    alloc(size_t n = 1) {
+        return static_cast<T *>(alloc(sizeof(T) * n));
+    }
+
+    inline
+    ~ScopedAllocator() {
+        while (next) {
+            void *temp = *static_cast<void **>(next);
+            free(next);
+            next = temp;
+        }
+    }
+};
+
+
+void
+addRegion(unsigned long long address, void *buffer, unsigned long long size);
+
+void
+delRegionByPointer(void *ptr);
+
+void *
+toPointer(trace::Value &value, bool bind = false);
+
+
 /**
  * Output verbosity when retracing files.
  */
 extern int verbosity;
 
+/**
+ * Add profiling data to the dump when retracing.
+ */
+extern bool profiling;
+
+
+std::ostream &warning(trace::Call &call);
 
-void ignore(Trace::Call &call);
-void retrace_unknown(Trace::Call &call);
 
+void ignore(trace::Call &call);
+void unsupported(trace::Call &call);
 
-typedef void (*Callback)(Trace::Call &call);
+
+typedef void (*Callback)(trace::Call &call);
 
 struct Entry {
     const char *name;
@@ -103,6 +174,9 @@ struct stringComparer {
 };
 
 
+extern const Entry stdc_callbacks[];
+
+
 class Retracer
 {
     typedef std::map<const char *, Callback, stringComparer> Map;
@@ -111,14 +185,16 @@ class Retracer
     std::vector<Callback> callbacks;
 
 public:
-    Retracer() {}
+    Retracer() {
+        addCallbacks(stdc_callbacks);
+    }
 
     virtual ~Retracer() {}
 
     void addCallback(const Entry *entry);
     void addCallbacks(const Entry *entries);
 
-    void retrace(Trace::Call &call);
+    void retrace(trace::Call &call);
 };