1 // Copyright 2000 - 2007 Google Inc.
2 // All rights reserved.
4 // Portable implementation - just use glibc
6 // Note: The glibc implementation may cause a call to malloc.
7 // This can cause a deadlock in HeapProfiler.
10 #include "stacktrace.h"
12 _START_GOOGLE_NAMESPACE_
14 // If you change this function, also change GetStackFrames below.
15 int GetStackTrace(void** result, int max_depth, int skip_count) {
16 static const int kStackLength = 64;
17 void * stack[kStackLength];
20 size = backtrace(stack, kStackLength);
21 skip_count++; // we want to skip the current frame as well
22 int result_count = size - skip_count;
25 if (result_count > max_depth)
26 result_count = max_depth;
27 for (int i = 0; i < result_count; i++)
28 result[i] = stack[i + skip_count];
33 _END_GOOGLE_NAMESPACE_