45std::string pipeOpen(
const std::string& cmd,
const int lineNum = 0)
49 FILE *handle = popen(cmd.c_str(),
"r");
50 if (!handle)
return str;
60 cnt <= lineNum && (nread = ::getline(&buf, &len, handle)) >= 0;
82inline std::string addressToWord(
const uintptr_t addr)
84 std::ostringstream buf;
85 buf.setf(std::ios_base::hex, std::ios_base::basefield);
90 buf << uint64_t(addr);
100inline std::string demangleSymbol(
const char* sn)
104 char* cxx_sname = abi::__cxa_demangle(sn,
nullptr,
nullptr, &st);
106 if (st == 0 && cxx_sname)
108 std::string demangled(cxx_sname);
126void printSourceFileAndLine
134 uintptr_t address = uintptr_t(addr);
135 std::string myAddress = addressToWord(address);
146 uintptr_t offset = uintptr_t(info.dli_fbase);
147 intptr_t relativeAddress = address - offset;
148 myAddress = addressToWord(relativeAddress);
151 if (filename[0] ==
'/')
155 "addr2line -f --demangle=auto --exe "
164 os <<
" addr2line failed";
166 else if (line ==
"??:0" || line ==
"??:?" )
169 os <<
" in " << shorterPath(line).c_str();
173 os <<
" at " << shorterPath(line).c_str();
185 if (!fname.empty() && fname[0] !=
'/' && fname[0] !=
'~')
187 std::string
s = pipeOpen(
"which " + fname);
189 if (
s[0] ==
'/' ||
s[0] ==
'~')
206 void *callstack[100];
207 size = backtrace(callstack, (size > 0 && size < 100) ? size + 1 : 100);
209 char **strings = backtrace_symbols(callstack, size);
213 os <<
"[stack trace]" << std::endl
214 <<
"=============" << std::endl;
216 for (
int i = 1; i < size; ++i)
218 std::string str(strings[i]);
220 os <<
'#' << i <<
'\t';
228 auto ldelim = str.find(
'(');
229 auto beg = str.find(
"/platforms/");
231 if (beg == std::string::npos || !beg || beg > ldelim)
242 (ldelim != std::string::npos)
243 && (rdelim = str.find(
'+', ldelim+1)) != std::string::npos
244 && (rdelim > ldelim+1)
251 os << str.substr(beg, ldelim-beg)
255 str.substr(ldelim+1, rdelim-ldelim-1).c_str()
258 if ((rdelim = str.find(
'[', rdelim)) != std::string::npos)
260 os <<
' ' << str.substr(rdelim);
266 os << str.substr(beg);
276 os <<
"=============" << std::endl;
285 void *callstack[100];
286 size = backtrace(callstack, (size > 0 && size < 100) ? size + 1 : 100);
292 os <<
"[stack trace]" <<
nl
293 <<
"=============" <<
nl;
295 for (
int i = 1; i < size; ++i)
297 int st = dladdr(callstack[i], &info);
299 os <<
'#' << i <<
" ";
300 if (st != 0 && info.dli_fname !=
nullptr && *(info.dli_fname))
302 fname = whichPath(info.dli_fname);
306 os << demangleSymbol(info.dli_sname).c_str();
319 printSourceFileAndLine(
os, fname, info, callstack[i]);
323 os <<
"=============" <<
nl;
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
static void safePrintStack(std::ostream &os, int size=-1)
Helper function to print a stack, with optional upper limit. Used when OpenFOAM IO not yet initialise...
static void printStack(Ostream &os, int size=-1)
Helper function to print a stack, with optional upper limit.
A class for handling file names.
bool has_ext() const
Various checks for extensions.
A class for handling character strings derived from std::string.
OBJstream os(runTime.globalPath()/outputName)
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
fileName cwd()
The physical or logical current working directory path name.
fileName home()
Return home directory path name for the current user.
constexpr char nl
The newline '\n' character (0x0a).