diff --git a/src/OSspecific/POSIX/printStack.C b/src/OSspecific/POSIX/printStack.C index df31b35f7b..4a3859dcae 100644 --- a/src/OSspecific/POSIX/printStack.C +++ b/src/OSspecific/POSIX/printStack.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -167,6 +167,26 @@ void getSymbolForRaw } +void error::safePrintStack(std::ostream& os) +{ + // Get raw stack symbols + void *array[100]; + size_t size = backtrace(array, 100); + char **strings = backtrace_symbols(array, size); + + // See if they contain function between () e.g. "(__libc_start_main+0xd0)" + // and see if cplus_demangle can make sense of part before + + for (size_t i = 0; i < size; i++) + { + string msg(strings[i]); + fileName programFile; + word address; + + os << '#' << label(i) << '\t' << msg << std::endl; + } +} + + void error::printStack(Ostream& os) { // Reads the starting addresses for the dynamically linked libraries diff --git a/src/OpenFOAM/db/error/error.H b/src/OpenFOAM/db/error/error.H index ea599b6550..8216f5f71f 100644 --- a/src/OpenFOAM/db/error/error.H +++ b/src/OpenFOAM/db/error/error.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -162,6 +162,10 @@ public: operator dictionary() const; + //- Helper function to print a stack (if OpenFOAM IO not yet + // initialised) + static void safePrintStack(std::ostream&); + //- Helper function to print a stack static void printStack(Ostream&);