Commit e2a5259e authored by pugmire's avatar pugmire
Browse files

Add PrintCallStack function. linux only



git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@11796 18c085ea-50e0-402c-830e-de6fd14e8384
parent dab65d0d
......@@ -42,7 +42,6 @@
#include <Utility.h>
#include <visitstream.h>
#include <visit-config.h>
#include <stdio.h>
#include <string.h>
......@@ -63,6 +62,11 @@ using std::vector;
#include <pwd.h>
#endif
#if !defined(_WIN32) && !defined(__APPLE__)
#include <execinfo.h>
#include <cxxabi.h>
#endif
// ****************************************************************************
// Function: LongestCommonPrefixLength
//
......@@ -247,6 +251,63 @@ GetMemorySize(unsigned int &size, unsigned int &rss)
#endif
}
// ****************************************************************************
// Function: PrintCallStack
//
// Purpose:
// Prints the call stack.
//
// Programmer: Dave Pugmire
// Creation: Tue Jun 29 15:58:52 EDT 2010
//
// Modifications:
//
// ****************************************************************************
void
PrintCallStack(ostream &out, const char *file, int line)
{
#if !defined(_WIN32) && !defined(__APPLE__)
const int N = 100;
void *stackAddrs[N];
size_t stackDepth = backtrace(stackAddrs, N);
int nfuncs = backtrace(stackAddrs, N);
char **stackStrings = backtrace_symbols(stackAddrs, nfuncs);
out<<"Call stack from "<<file<<" "<<line<<endl;
for (int i = 1; i < nfuncs; i++)
{
std::string symbol = stackStrings[i];
size_t i0 = symbol.find("(");
size_t i1 = symbol.rfind("+");
std::string outStr;
if (i0 == std::string::npos || i1 == std::string::npos)
outStr = symbol;
else
{
i0 = i0+1;
std::string funcSymbol = symbol.substr(i0, i1-i0);
int stat = 0;
char *demangle = abi::__cxa_demangle(funcSymbol.c_str(), 0,0, &stat);
if (demangle)
{
outStr = demangle;
free(demangle);
}
else
outStr = funcSymbol;
}
out<<i<<": "<<outStr<<endl;
}
free(stackStrings);
#endif
}
// ****************************************************************************
// Function: WaitUntilFile
......
......@@ -43,6 +43,7 @@
#ifndef UTILITY_H
#define UTILITY_H
#include <utility_exports.h>
#include <visitstream.h>
#include <visit-config.h>
#include <vectortypes.h>
#include <map>
......@@ -59,6 +60,7 @@ int UTILITY_API LongestCommonSuffixLength(const char * const *, int);
// LINUX ONLY
void UTILITY_API GetMemorySize(unsigned int &, unsigned int &);
void UTILITY_API PrintCallStack(ostream &out, const char *file, int line);
void UTILITY_API WaitUntilFile(const char *);
bool UTILITY_API WildcardStringMatch(const char *p, const char *s);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment