Backtraces are really disjoint from signature.
This puts back const keyword in most FunctionSig usages.
const char *name;
unsigned num_args;
const char **arg_names;
- bool backtrace;
};
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),
* 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;
_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) {
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);
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)
static OS_THREAD_SPECIFIC_PTR(void)
thread_num;
-unsigned LocalWriter::beginEnter(FunctionSig *sig) {
+unsigned LocalWriter::beginEnter(const FunctionSig *sig, bool fake) {
mutex.lock();
++acquired;
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);
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.
/**
* It will acquire the mutex.
*/
- unsigned beginEnter(FunctionSig *sig);
+ unsigned beginEnter(const FunctionSig *sig, bool fake = false);
/**
* It will release the mutex.
# 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)
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):
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)
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();'