47 FILE *cmdPipe = popen(cmd.c_str(),
"r");
58 linelen = getline(&buf, &linecap, cmdPipe);
80 return res.substr(0, res.size() - 1);
87 nStream <<
"0x" <<
hex << addr;
100 uintptr_t address = uintptr_t(addr);
103 if (filename.
ext() ==
"so")
106 uintptr_t offset = uintptr_t(info->dli_fbase);
107 intptr_t relativeAddress = address - offset;
111 if (filename[0] ==
'/')
115 "addr2line -f --demangle=auto --exe " 124 os <<
" addr2line failed";
126 else if (line ==
"??:0")
128 os <<
" in " << filename;
133 string homeLine(cwdLine.replaceAll(
home(),
'~'));
135 os <<
" at " << homeLine.c_str();
145 if (fname[0] !=
'/' && fname[0] !=
'~')
147 string tmp =
pOpen(
"which " + fname);
149 if (tmp[0] ==
'/' || tmp[0] ==
'~')
163 char* cxx_sname = abi::__cxa_demangle
171 if (st == 0 && cxx_sname)
173 res =
word(cxx_sname);
196 size_t size = backtrace(array, 100);
197 char **strings = backtrace_symbols(array, size);
201 for (
size_t i = 0; i < size; i++)
203 string msg(strings[i]);
215 const size_t CALLSTACK_SIZE = 128;
217 void *callstack[CALLSTACK_SIZE];
218 size_t size = backtrace(callstack, CALLSTACK_SIZE);
220 Dl_info *info =
new Dl_info;
225 for(
size_t i=0; i<size; i++)
227 int st = dladdr(callstack[i], info);
229 os <<
'#' <<
label(i) <<
" ";
230 if (st != 0 && info->dli_fname !=
nullptr && info->dli_fname[0] !=
'\0')
236 (info->dli_sname !=
nullptr)
static void printStack(Ostream &)
Helper function to print a stack.
string & replaceAll(const string &oldStr, const string &newStr, size_type start=0)
Replace all occurrences of sub-string oldStr with newStr.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
A class for handling file names.
IOstream & hex(IOstream &io)
static void safePrintStack(std::ostream &)
Helper function to print a stack (if OpenFOAM IO not yet.
string pOpen(const string &cmd, label line=0)
Ostream & endl(Ostream &os)
Add newline and flush stream.
fileName home()
Return home directory path name for the current user.
word ext() const
Return file name extension (part after last .)
fileName absolutePath(const char *fn)
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
void printSourceFileAndLine(Ostream &os, const fileName &filename, Dl_info *info, void *addr)
A class for handling words, derived from string.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
string str() const
Return the string.
fileName cwd()
Return current working directory path name.
word addressToWord(const uintptr_t addr)
A class for managing temporary objects.
word demangleSymbol(const char *sn)
A class for handling character strings derived from std::string.
Output to memory buffer stream.