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