CPN
Computational Process Networks
StackTrace.cc
Go to the documentation of this file.
1 //=============================================================================
2 // Computational Process Networks class library
3 // Copyright (C) 1997-2006 Gregory E. Allen and The University of Texas
4 //
5 // This library is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU Library General Public License as published
7 // by the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Library General Public License for more details.
14 //
15 // The GNU Public License is available in the file LICENSE, or you
16 // can write to the Free Software Foundation, Inc., 59 Temple Place -
17 // Suite 330, Boston, MA 02111-1307, USA, or you can find it on the
18 // World Wide Web at http://www.fsf.org.
19 //=============================================================================
25 #include "common_priv.h"
26 #include <cpn/utils/StackTrace.h>
27 #include <execinfo.h>
28 #include <cstdlib>
29 #include <cstdio>
30 #include <sstream>
31 #include <cstdio>
32 
33 void PrintStack() {
34  void* stack[STACKTRACE_MAXTRACE];
35  size_t size = backtrace(stack, STACKTRACE_MAXTRACE);
36  backtrace_symbols_fd(stack, size, 2);
37 }
38 
39 std::string GetStack(unsigned ignore) {
40  void* stack[STACKTRACE_MAXTRACE];
41  size_t size = backtrace(stack, STACKTRACE_MAXTRACE);
42  char **bt = backtrace_symbols(stack, size);
43  if (!bt) {
44  perror("backtrace_symbols");
45  return "";
46  }
47  std::ostringstream oss;
48  for (unsigned i = ignore; i < size; ++i) {
49  oss << bt[i] << '\n';
50  }
51  free(bt);
52  return oss.str();
53 }
54 
55 
std::string GetStack(unsigned ignore=0)
Definition: StackTrace.cc:39
function for printing out a stack trace Note that we need to pass -rdynamic to the linker to be able ...
#define STACKTRACE_MAXTRACE
Definition: StackTrace.h:33
void PrintStack()
Definition: StackTrace.cc:33