LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
lar::debug Namespace Reference

Namespaces

 details
 

Classes

struct  BacktracePrintOptions
 Backtrace printing options. More...
 
struct  CallInfo_t
 Structure with information about a single call, parsed. More...
 
class  CallInfoPrinter
 Class handling the output of information in a CallInfo_t object. More...
 
struct  static_assert_on
 
struct  static_assert_on< T, false >
 

Functions

template<typename T >
std::string demangle (T const *=nullptr)
 Outputs a demangled name for type T. More...
 
template<typename Stream >
Stream & operator<< (Stream &&out, CallInfo_t const &info)
 Helper operator to insert a call information in a stream with default options. More...
 
template<typename Stream >
void printBacktrace (Stream &&out, BacktracePrintOptions options)
 Prints the full backtrace into a stream. More...
 
template<typename Stream >
void printBacktrace (Stream &&out)
 Prints the full backtrace into a stream with default options. More...
 
template<typename Stream >
void printBacktrace (Stream &&out, unsigned int maxLines, std::string indent=" ", CallInfoPrinter::opt const *callInfoOptions=nullptr)
 Prints the full backtrace into a stream. More...
 

Function Documentation

template<typename T >
std::string lar::debug::demangle ( T const *  = nullptr)
inline

Outputs a demangled name for type T.


Template Parameters
Ttype whose name must be demangled (optional)
Returns
a string with demangled name

It relies on cetlib. The type to be demangled can be specified either as template argument:

auto name = lar::debug::demangle<std::string>();

or via a argument pointer:

auto name = lar::debug::demangle(this);

Definition at line 343 of file DebugUtils.h.

344  {
345  return cet::demangle_symbol(typeid(std::decay_t<T>).name());
346  }
template<typename Stream >
Stream & lar::debug::operator<< ( Stream &&  out,
CallInfo_t const &  info 
)
inline

Helper operator to insert a call information in a stream with default options.

Definition at line 389 of file DebugUtils.h.

Referenced by lar::debug::CallInfoPrinter::defaultOptions().

390  {
391  CallInfoPrinter print;
392  print(std::forward<Stream>(out), info);
393  return out;
394  }
template<typename Stream >
void lar::debug::printBacktrace ( Stream &&  out,
BacktracePrintOptions  options 
)

Prints the full backtrace into a stream.

Template Parameters
Streamtype of output stream
Parameters
outthe output stream to insert output into
optionsprinting options (see BacktracePrintOptions)

Definition at line 398 of file DebugUtils.h.

References lar::debug::BacktracePrintOptions::callInfoOptions, lar::debug::BacktracePrintOptions::countOthers, lar::debug::BacktracePrintOptions::firstIndent, lar::debug::BacktracePrintOptions::indent, lar::debug::BacktracePrintOptions::maxLines, and lar::debug::BacktracePrintOptions::skipLines.

Referenced by printBacktrace(), and lar::debug::BacktracePrintOptions::setUniformIndent().

399  {
400  unsigned int nSkip = std::max(options.skipLines, 0U);
401  std::vector<void*> buffer(nSkip + std::max(options.maxLines, 200U), nullptr);
402 
403  unsigned int const nItems = (unsigned int)backtrace(buffer.data(), buffer.size());
404 
405  // convert the calls in the buffer into a vector of strings
406  char** symbols = backtrace_symbols(buffer.data(), buffer.size());
407  if (!symbols) {
408  out << options.firstIndent << "<failed to get the call stack>\n" << std::flush;
409  return;
410  }
411  std::vector<CallInfo_t> callStack;
412  for (size_t i = 0; i < buffer.size(); ++i)
413  callStack.push_back((const char*)symbols[i]);
414  std::free(symbols);
415 
416  size_t lastItem = nSkip + options.maxLines;
417  if (lastItem > nItems) lastItem = nItems;
418  if (lastItem >= buffer.size()) --lastItem;
419 
420  CallInfoPrinter print(options.callInfoOptions);
421  for (size_t i = nSkip; i < lastItem; ++i) {
422  out << (i == 0 ? options.firstIndent : options.indent);
423  print(std::forward<Stream>(out), callStack[i]);
424  out << "\n";
425  }
426  if ((lastItem < nItems) && options.countOthers) {
427  out << options.indent << " ... and other " << (nItems - lastItem);
428  if (nItems == buffer.size()) out << " (or more)";
429  out << " levels\n";
430  }
431  out << std::flush;
432 
433  } // printBacktrace()
template<typename Stream >
void lar::debug::printBacktrace ( Stream &&  out)

Prints the full backtrace into a stream with default options.

Template Parameters
Streamtype of output stream
Parameters
outthe output stream to insert output into

Definition at line 233 of file DebugUtils.h.

References art::detail::indent(), and printBacktrace().

234  {
235  printBacktrace(std::forward<Stream>(out), BacktracePrintOptions());
236  }
void printBacktrace(Stream &&out, unsigned int maxLines, std::string indent=" ", CallInfoPrinter::opt const *callInfoOptions=nullptr)
Prints the full backtrace into a stream.
Definition: DebugUtils.h:437
template<typename Stream >
void lar::debug::printBacktrace ( Stream &&  out,
unsigned int  maxLines,
std::string  indent = "  ",
CallInfoPrinter::opt const *  callInfoOptions = nullptr 
)

Prints the full backtrace into a stream.

Template Parameters
Streamtype of output stream
Parameters
outthe output stream to insert output into
maxLinesprint at most this many lines in the output (default: 5)
indentprepend a string in front of any new line (default: " ")
callInfoOptionsuse these output options (default ones if null)

The call information output options are described in CallInfoPrinter::opt structure.

Definition at line 437 of file DebugUtils.h.

References lar::debug::BacktracePrintOptions::callInfoOptions, lar::debug::BacktracePrintOptions::firstIndent, art::detail::indent(), lar::debug::BacktracePrintOptions::indent, lar::debug::BacktracePrintOptions::maxLines, and printBacktrace().

442  {
443  BacktracePrintOptions options;
444  options.maxLines = maxLines;
445  options.indent = options.firstIndent = indent;
446  if (callInfoOptions) options.callInfoOptions = *callInfoOptions;
447  printBacktrace(std::forward<Stream>(out), options);
448  }
std::string indent(std::size_t const i)
void printBacktrace(Stream &&out, unsigned int maxLines, std::string indent=" ", CallInfoPrinter::opt const *callInfoOptions=nullptr)
Prints the full backtrace into a stream.
Definition: DebugUtils.h:437