unbreak grab-backtrace frame skipping logic
When building with -O0 -fno-inlines, +[] () {} (lambda) syntax for
function pointers actually creates "wrapper function" so we see extra
frame (due to disabled inlinings). Fix is to create explicit function
and pass it, instead of lambda thingy.
diff --git a/src/malloc_backtrace.cc b/src/malloc_backtrace.cc
index 20127b9..05f69a5 100644
--- a/src/malloc_backtrace.cc
+++ b/src/malloc_backtrace.cc
@@ -61,20 +61,25 @@
args.skip_count = skip_count;
args.result_depth = 0;
- ThreadCachePtr::WithStacktraceScope(+[] (bool stacktrace_allowed, void* _args) {
- Args* args = static_cast<Args*>(_args);
- if (!stacktrace_allowed) {
- return;
- }
+ struct Body {
+ static ATTRIBUTE_NOINLINE
+ void Run(bool stacktrace_allowed, void* _args) {
+ Args* args = static_cast<Args*>(_args);
+ if (!stacktrace_allowed) {
+ return;
+ }
#if (!defined(NDEBUG) || defined(TCMALLOC_FORCE_BAD_TLS)) && defined(ENABLE_EMERGENCY_MALLOC)
- // Lets ensure test coverage of emergency malloc even in
- // configurations that otherwise don't exercise it.
- (tc_delete)(tc_new(32));
+ // Lets ensure test coverage of emergency malloc even in
+ // configurations that otherwise don't exercise it.
+ (tc_delete)(tc_new(32));
#endif
- args->result_depth = GetStackTrace(args->result, args->max_depth, args->skip_count + 3);
- }, &args);
+ args->result_depth = GetStackTrace(args->result, args->max_depth, args->skip_count + 3);
+ }
+ };
+
+ ThreadCachePtr::WithStacktraceScope(Body::Run, &args);
// Prevent tail calling WithStacktraceScope above
return *const_cast<volatile int*>(&args.result_depth);