Blame src/stacktrace_generic-inl.h

Packit Service 9def5d
// Copyright (c) 2000 - 2007, Google Inc.
Packit Service 9def5d
// All rights reserved.
Packit Service 9def5d
//
Packit Service 9def5d
// Redistribution and use in source and binary forms, with or without
Packit Service 9def5d
// modification, are permitted provided that the following conditions are
Packit Service 9def5d
// met:
Packit Service 9def5d
//
Packit Service 9def5d
//     * Redistributions of source code must retain the above copyright
Packit Service 9def5d
// notice, this list of conditions and the following disclaimer.
Packit Service 9def5d
//     * Redistributions in binary form must reproduce the above
Packit Service 9def5d
// copyright notice, this list of conditions and the following disclaimer
Packit Service 9def5d
// in the documentation and/or other materials provided with the
Packit Service 9def5d
// distribution.
Packit Service 9def5d
//     * Neither the name of Google Inc. nor the names of its
Packit Service 9def5d
// contributors may be used to endorse or promote products derived from
Packit Service 9def5d
// this software without specific prior written permission.
Packit Service 9def5d
//
Packit Service 9def5d
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit Service 9def5d
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit Service 9def5d
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Packit Service 9def5d
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Packit Service 9def5d
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Packit Service 9def5d
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Packit Service 9def5d
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit Service 9def5d
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit Service 9def5d
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit Service 9def5d
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit Service 9def5d
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit Service 9def5d
//
Packit Service 9def5d
// Portable implementation - just use glibc
Packit Service 9def5d
//
Packit Service 9def5d
// Note:  The glibc implementation may cause a call to malloc.
Packit Service 9def5d
// This can cause a deadlock in HeapProfiler.
Packit Service 9def5d
#include <execinfo.h>
Packit Service 9def5d
#include <string.h>
Packit Service 9def5d
#include "stacktrace.h"
Packit Service 9def5d
Packit Service 9def5d
_START_GOOGLE_NAMESPACE_
Packit Service 9def5d
Packit Service 9def5d
// If you change this function, also change GetStackFrames below.
Packit Service 9def5d
int GetStackTrace(void** result, int max_depth, int skip_count) {
Packit Service 9def5d
  static const int kStackLength = 64;
Packit Service 9def5d
  void * stack[kStackLength];
Packit Service 9def5d
  int size;
Packit Service 9def5d
Packit Service 9def5d
  size = backtrace(stack, kStackLength);
Packit Service 9def5d
  skip_count++;  // we want to skip the current frame as well
Packit Service 9def5d
  int result_count = size - skip_count;
Packit Service 9def5d
  if (result_count < 0)
Packit Service 9def5d
    result_count = 0;
Packit Service 9def5d
  if (result_count > max_depth)
Packit Service 9def5d
    result_count = max_depth;
Packit Service 9def5d
  for (int i = 0; i < result_count; i++)
Packit Service 9def5d
    result[i] = stack[i + skip_count];
Packit Service 9def5d
Packit Service 9def5d
  return result_count;
Packit Service 9def5d
}
Packit Service 9def5d
Packit Service 9def5d
_END_GOOGLE_NAMESPACE_