MCPcopy Create free account
hub / github.com/defold/defold / DumpBacktrace

Function DumpBacktrace

engine/dlib/src/dlib/memprofile.cpp:343–378  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

341 }
342
343 void DumpBacktrace(char type, void* ptr, uint32_t size)
344 {
345 static int32_atomic_t call_depth = 0;
346
347 if (!dmMemProfile::g_Mutex)
348 return;
349
350 int ret = pthread_mutex_lock(dmMemProfile::g_Mutex);
351 assert(ret == 0);
352
353 if (g_TraceFile == -1)
354 {
355 ret = pthread_mutex_unlock(dmMemProfile::g_Mutex);
356 assert(ret == 0);
357 return;
358 }
359
360 // Avoid recursive calls to DumpBacktrace. backtrace can allocate memory...
361 if (dmAtomicIncrement32(&call_depth) > 0)
362 {
363 dmAtomicDecrement32(&call_depth);
364 return;
365 }
366
367 char buf[256];
368 snprintf(buf, sizeof(buf), "%c %p 0x%x ", type, ptr, (int32_t) size);
369 Log(g_TraceFile, buf);
370
371 DumpBacktracePlatform(g_TraceFile);
372
373 Log(g_TraceFile, "\n");
374
375 dmAtomicDecrement32(&call_depth);
376 ret = pthread_mutex_unlock(dmMemProfile::g_Mutex);
377 assert(ret == 0);
378 }
379}
380
381extern "C"

Callers 6

mallocFunction · 0.85
memalignFunction · 0.85
posix_memalignFunction · 0.85
callocFunction · 0.85
reallocFunction · 0.85
freeFunction · 0.85

Calls 5

dmAtomicIncrement32Function · 0.85
dmAtomicDecrement32Function · 0.85
DumpBacktracePlatformFunction · 0.85
LogFunction · 0.70
assertFunction · 0.50

Tested by

no test coverage detected