diff --git a/src/OSspecific/POSIX/printStack.C b/src/OSspecific/POSIX/printStack.C index 19db2c63034c498a4f2d9d1f62dc5cf187e0619e..e9310dfb7ee1e36947293eb336e8b6077a20d39e 100644 --- a/src/OSspecific/POSIX/printStack.C +++ b/src/OSspecific/POSIX/printStack.C @@ -50,7 +50,7 @@ string pOpen(const string& cmd, label line=0) char *buf = nullptr; // Read line number of lines - for (label cnt = 0; cnt <= line; cnt++) + for (label cnt = 0; cnt <= line; ++cnt) { size_t linecap = 0; ssize_t linelen = ::getline(&buf, &linecap, cmdPipe); @@ -96,6 +96,14 @@ inline word addressToWord(const uintptr_t addr) } +inline string& shorterPath(string& s) +{ + s.replace(cwd() + '/', ""); + s.replace(home(), "~"); + return s; +} + + void printSourceFileAndLine ( Ostream& os, @@ -132,14 +140,12 @@ void printSourceFileAndLine } else if (line == "??:0") { - os << " in " << filename; + line = filename; + os << " in " << shorterPath(line).c_str(); } else { - string cwdLine(line.replaceAll(cwd() + '/', "")); - string homeLine(cwdLine.replaceAll(home(), "~")); - - os << " at " << homeLine.c_str(); + os << " at " << shorterPath(line).c_str(); } } } @@ -202,7 +208,7 @@ void Foam::error::safePrintStack(std::ostream& os) // 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++) + for (size_t i = 0; i < size; ++i) { string msg(strings[i]); fileName programFile; @@ -226,7 +232,7 @@ void Foam::error::printStack(Ostream& os) fileName fname = "???"; word address; - for(size_t i=0; i<size; i++) + for (size_t i=0; i<size; ++i) { int st = dladdr(callstack[i], info);