Go to the documentation of this file.
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;
132 string cwdLine(
line.replaceAll(
cwd() +
'/',
""));
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 != NULL && info->dli_fname[0] !=
'\0')
236 (info->dli_sname != NULL)
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
string & replaceAll(const string &oldStr, const string &newStr, size_type start=0)
Replace all occurences of sub-string oldStr with newStr.
A class for handling words, derived from string.
A class for handling file names.
A class for managing temporary objects.
word demangleSymbol(const char *sn)
Ostream & endl(Ostream &os)
Add newline and flush stream.
A class for handling character strings derived from std::string.
word addressToWord(const uintptr_t addr)
string str() const
Return the string.
static void printStack(Ostream &)
Helper function to print a stack.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
word ext() const
Return file name extension (part after last .)
static void safePrintStack(std::ostream &)
Helper function to print a stack (if OpenFOAM IO not yet.
IOstream & hex(IOstream &io)
fileName home()
Return home directory path name for the current user.
Output to memory buffer stream.
string pOpen(const string &cmd, label line=0)
fileName cwd()
Return current working directory path name.
void printSourceFileAndLine(Ostream &os, const fileName &filename, Dl_info *info, void *addr)
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
fileName absolutePath(const char *fn)