From: José Fonseca <jose.r.fonseca@gmail.com>
Date: Sat, 4 May 2013 10:10:33 +0000 (+0100)
Subject: Remove FunctionSig::backtrace member.
X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=69909e3853c23d0ce062b6c9f232191970da9aee;p=apitrace

Remove FunctionSig::backtrace member.

Backtraces are really disjoint from signature.

This puts back const keyword in most FunctionSig usages.
---

diff --git a/common/trace_model.hpp b/common/trace_model.hpp
index 7c4cdc7..fbfa1fb 100644
--- a/common/trace_model.hpp
+++ b/common/trace_model.hpp
@@ -49,7 +49,6 @@ struct FunctionSig {
     const char *name;
     unsigned num_args;
     const char **arg_names;
-    bool backtrace;
 };
 
 
@@ -488,14 +487,14 @@ class Call
 public:
     unsigned thread_id;
     unsigned no;
-    FunctionSig *sig;
+    const FunctionSig *sig;
     std::vector<Arg> args;
     Value *ret;
 
     CallFlags flags;
     Backtrace* backtrace;
 
-    Call(FunctionSig *_sig, const CallFlags &_flags, unsigned _thread_id) :
+    Call(const FunctionSig *_sig, const CallFlags &_flags, unsigned _thread_id) :
         thread_id(_thread_id), 
         sig(_sig), 
         args(_sig->num_args), 
diff --git a/common/trace_parser.cpp b/common/trace_parser.cpp
index 8ba9bdc..6ccc68d 100644
--- a/common/trace_parser.cpp
+++ b/common/trace_parser.cpp
@@ -463,7 +463,7 @@ Call *Parser::parse_leave(Mode mode) {
          * between two frames.  We won't return this call, but we still need to skip 
          * over its data.
          */
-        FunctionSig sig = {0, NULL, 0, NULL};
+        const FunctionSig sig = {0, NULL, 0, NULL};
         call = new Call(&sig, 0, 0);
         parse_call_details(call, SCAN);
         delete call;
diff --git a/common/trace_writer.cpp b/common/trace_writer.cpp
index 2dc7a00..be01376 100644
--- a/common/trace_writer.cpp
+++ b/common/trace_writer.cpp
@@ -200,12 +200,11 @@ void Writer::beginStackFrameOffset(void ) {
     _writeByte(trace::CALL_BACKTRACE_OFFSET);
 }
 
-unsigned Writer::beginEnter(FunctionSig *sig, unsigned thread_id) {
+unsigned Writer::beginEnter(const FunctionSig *sig, unsigned thread_id) {
     _writeByte(trace::EVENT_ENTER);
     _writeUInt(thread_id);
     _writeUInt(sig->id);
     if (!lookup(functions, sig->id)) {
-        sig->backtrace = backtrace_is_needed(sig->name);
         _writeString(sig->name);
         _writeUInt(sig->num_args);
         for (unsigned i = 0; i < sig->num_args; ++i) {
diff --git a/common/trace_writer.hpp b/common/trace_writer.hpp
index 6440ab9..f8d0afb 100644
--- a/common/trace_writer.hpp
+++ b/common/trace_writer.hpp
@@ -74,7 +74,7 @@ namespace trace {
         void beginStackFrameOffset(void);
         inline void endStackFrameOffset(void) {}
 
-        unsigned beginEnter(FunctionSig *sig, unsigned thread_id);
+        unsigned beginEnter(const FunctionSig *sig, unsigned thread_id);
         void endEnter(void);
 
         void beginLeave(unsigned call);
diff --git a/common/trace_writer_local.cpp b/common/trace_writer_local.cpp
index b894bf9..8661701 100644
--- a/common/trace_writer_local.cpp
+++ b/common/trace_writer_local.cpp
@@ -43,16 +43,16 @@ namespace trace {
 
 
 static const char *memcpy_args[3] = {"dest", "src", "n"};
-FunctionSig memcpy_sig = {0, "memcpy", 3, memcpy_args, false};
+const FunctionSig memcpy_sig = {0, "memcpy", 3, memcpy_args};
 
 static const char *malloc_args[1] = {"size"};
-FunctionSig malloc_sig = {1, "malloc", 1, malloc_args, false};
+const FunctionSig malloc_sig = {1, "malloc", 1, malloc_args};
 
 static const char *free_args[1] = {"ptr"};
-FunctionSig free_sig = {2, "free", 1, free_args, false};
+const FunctionSig free_sig = {2, "free", 1, free_args};
 
 static const char *realloc_args[2] = {"ptr", "size"};
-FunctionSig realloc_sig = {3, "realloc", 2, realloc_args, false};
+const FunctionSig realloc_sig = {3, "realloc", 2, realloc_args};
 
 
 static void exceptionCallback(void)
@@ -134,7 +134,7 @@ static uintptr_t next_thread_num = 1;
 static OS_THREAD_SPECIFIC_PTR(void)
 thread_num;
 
-unsigned LocalWriter::beginEnter(FunctionSig *sig) {
+unsigned LocalWriter::beginEnter(const FunctionSig *sig, bool fake) {
     mutex.lock();
     ++acquired;
 
@@ -153,7 +153,7 @@ unsigned LocalWriter::beginEnter(FunctionSig *sig) {
     assert(this_thread_num);
     unsigned thread_id = this_thread_num - 1;
     unsigned call_no = Writer::beginEnter(sig, thread_id);
-    if (sig->backtrace) {
+    if (!fake) {
         std::vector<RawStackFrame> backtrace = get_backtrace();
         beginBacktrace();
         writeBacktrace(backtrace);
diff --git a/common/trace_writer_local.hpp b/common/trace_writer_local.hpp
index 1da2250..1859354 100644
--- a/common/trace_writer_local.hpp
+++ b/common/trace_writer_local.hpp
@@ -39,10 +39,10 @@
 
 namespace trace {
 
-    extern FunctionSig memcpy_sig;
-    extern FunctionSig malloc_sig;
-    extern FunctionSig free_sig;
-    extern FunctionSig realloc_sig;
+    extern const FunctionSig memcpy_sig;
+    extern const FunctionSig malloc_sig;
+    extern const FunctionSig free_sig;
+    extern const FunctionSig realloc_sig;
 
     /**
      * A specialized Writer class, mean to trace the current process.
@@ -83,7 +83,7 @@ namespace trace {
         /**
          * It will acquire the mutex.
          */
-        unsigned beginEnter(FunctionSig *sig);
+        unsigned beginEnter(const FunctionSig *sig, bool fake = false);
 
         /**
          * It will release the mutex.
diff --git a/wrappers/gltrace.py b/wrappers/gltrace.py
index fcb48bb..c40fbb3 100644
--- a/wrappers/gltrace.py
+++ b/wrappers/gltrace.py
@@ -520,7 +520,7 @@ class GlTracer(Tracer):
 
                     # Emit a fake function
                     print '        {'
-                    print '            static trace::FunctionSig &_sig = %s ? _glEnableClientState_sig : _glDisableClientState_sig;' % flag_name
+                    print '            static const trace::FunctionSig &_sig = %s ? _glEnableClientState_sig : _glDisableClientState_sig;' % flag_name
                     print '            unsigned _call = trace::localWriter.beginEnter(&_sig);'
                     print '            trace::localWriter.beginArg(0);'
                     self.serializeValue(glapi.GLenum, enable_name)
diff --git a/wrappers/trace.py b/wrappers/trace.py
index 9ff5410..252db49 100644
--- a/wrappers/trace.py
+++ b/wrappers/trace.py
@@ -452,7 +452,7 @@ class Tracer:
                 print 'static const char * _%s_args[%u] = {%s};' % (function.name, len(function.args), ', '.join(['"%s"' % arg.name for arg in function.args]))
             else:
                 print 'static const char ** _%s_args = NULL;' % (function.name,)
-            print 'static trace::FunctionSig _%s_sig = {%u, "%s", %u, _%s_args};' % (function.name, self.getFunctionSigId(), function.name, len(function.args), function.name)
+            print 'static const trace::FunctionSig _%s_sig = {%u, "%s", %u, _%s_args};' % (function.name, self.getFunctionSigId(), function.name, len(function.args), function.name)
             print
 
     def getFunctionSigId(self):
@@ -685,7 +685,7 @@ class Tracer:
         assert not method.internal
 
         print '    static const char * _args[%u] = {%s};' % (len(method.args) + 1, ', '.join(['"this"'] + ['"%s"' % arg.name for arg in method.args]))
-        print '    static trace::FunctionSig _sig = {%u, "%s", %u, _args};' % (self.getFunctionSigId(), interface.name + '::' + method.name, len(method.args) + 1)
+        print '    static const trace::FunctionSig _sig = {%u, "%s", %u, _args};' % (self.getFunctionSigId(), interface.name + '::' + method.name, len(method.args) + 1)
 
         print '    %s *_this = static_cast<%s *>(m_pInstance);' % (base, base)
 
@@ -782,7 +782,7 @@ class Tracer:
         print '    %s_this->%s(%s);' % (result, method.name, ', '.join([str(arg.name) for arg in method.args]))
     
     def emit_memcpy(self, dest, src, length):
-        print '        unsigned _call = trace::localWriter.beginEnter(&trace::memcpy_sig);'
+        print '        unsigned _call = trace::localWriter.beginEnter(&trace::memcpy_sig, true);'
         print '        trace::localWriter.beginArg(0);'
         print '        trace::localWriter.writePointer((uintptr_t)%s);' % dest
         print '        trace::localWriter.endArg();'