13 #ifndef LARCOREALG_COREUTILS_DEBUGUTILS_H
14 #define LARCOREALG_COREUTILS_DEBUGUTILS_H
20 #include "cetlib_except/demangle.h"
57 inline std::string
demangle(T
const* =
nullptr);
64 using range_t = std::pair<size_t, size_t>;
81 std::string
const&
function()
const
88 return (sep == std::string::npos)
107 {
return emptyRange(r)?
"": s.substr(r.first, r.second - r.first); }
115 std::string
const&
s,
169 template <
typename Stream>
173 template <
typename Stream>
175 {
print(std::forward<Stream>(out), info); }
196 template <
typename Stream>
227 template <
typename Stream>
235 template <
typename Stream>
251 template <
typename Stream>
254 unsigned int maxLines, std::string indent =
" ",
331 template <
typename T,
bool Enable >
347 template <
typename T>
349 {
return cet::demangle_symbol(
typeid(std::decay_t<T>).
name()); }
353 template <
typename Stream>
365 else out <<
"unknown";
373 if (
offset > 0) out <<
'+';
378 out << std::showbase << std::hex <<
offset <<
"]";
387 out <<
" at " << ((
void*) info.
address);
393 template <
typename Stream>
396 print(std::forward<Stream>(out), info);
402 template <
typename Stream>
404 unsigned int nSkip = std::max(options.
skipLines, 0U);
405 std::vector<void*> buffer
406 (nSkip + std::max(options.
maxLines, 200U),
nullptr);
408 unsigned int const nItems
409 = (
unsigned int) backtrace(buffer.data(), buffer.size());
412 char**
symbols = backtrace_symbols(buffer.data(), buffer.size());
414 out << options.
firstIndent <<
"<failed to get the call stack>\n"
418 std::vector<CallInfo_t> callStack;
419 for (
size_t i = 0; i < buffer.size(); ++i)
420 callStack.push_back((
const char*) symbols[i]);
423 size_t lastItem = nSkip + options.
maxLines;
424 if (lastItem > nItems) lastItem = nItems;
425 if (lastItem >= buffer.size()) --lastItem;
428 for (
size_t i = nSkip; i < lastItem; ++i) {
430 print(std::forward<Stream>(out), callStack[i]);
434 out << options.
indent <<
" ... and other " << (nItems - lastItem);
435 if (nItems == buffer.size()) out <<
" (or more)";
444 template <
typename Stream>
447 unsigned int maxLines, std::string indent ,
462 template <
typename T>
466 static_assert(::util::always_false_v<T>,
467 "static_assert_on<T>: check the error message (\"THE_TYPE_IS<>\") for expansion of type `T`."
473 template <
typename T,
bool Enable = true>
480 template <
typename T>
489 #endif // LARCOREALG_COREUTILS_DEBUGUTILS_H
std::string original
String from the backtrace, unparsed.
std::string demangle(T const *=nullptr)
Outputs a demangled name for type T.
then echo echo For and will not be changed by echo further linking echo echo B echo The symbol is in the uninitialized data multiple common symbols may appear with the echo same name If the symbol is defined the common echo symbols are treated as undefined references For more echo details on common symbols
std::string firstIndent
Special indentation for the first line.
static std::string extract(std::string const &s, range_t const &r)
Translates a range into a string.
unsigned int maxLines
Total number of lines to print.
BEGIN_PROLOG TPC Trig offset(g4 rise time) ProjectToHeight
std::string functionName
Parsed function name, demangled.
Print the library name the function lives in.
static opt defaultOptions()
Returns a set of default options.
void setDefaultOptions()
Sets this object to use a set of default options.
std::string libraryName
Parsed library name.
void setAll(std::string const &s, range_t addressStr, range_t libraryStr, range_t functionStr, range_t offsetStr)
Fills the information from an original string and parsed ranges.
static_assert_on()=default
do one_file $F done echo for F in find $TOP name CMakeLists txt print
CallInfo_t(const char *s)
CallInfoPrinter(opt opts)
Constructor: use specified options.
Print the instruction pointer memory address.
bool has(option_t o) const
Returns whether the specified option is set.
void * address
Function address.
void demangleFunction()
Runs the demangler and stores the result.
Backtrace printing options.
bool countOthers
Whether to print number of omitted lines.
CallInfoPrinter()
Default constructor: use default options.
Class handling the output of information in a CallInfo_t object.
bool operator!() const
Returns whether no information was parsed out of the original.
A range (interval) of integers.
Use demangled function names when possible.
Number of available options.
Print a shorter library name (base name only).
std::bitset< NOptions > options
Value of current options.
bool ParseString(std::string const &s)
Returns whether the translation was complete (offset is optional!).
std::pair< size_t, size_t > range_t
opt options
Set of current options.
Structure with information about a single call, parsed.
option_t
List of available options.
static bool emptyRange(range_t const &r)
Returns whether the range is empty or invalid.
void setUniformIndent(std::string uniformIndent)
Sets all indentation to the same specified uniformIndent string.
CallInfoPrinter::opt callInfoOptions
Options for each single backtrace call information line.
std::string indent
Indentation string for all lines.
void operator()(Stream &&out, CallInfo_t const &info) const
Print the content of info into the stream out, using the current options.
opt & set(option_t o, bool set=true)
Set one option o to the specified set value (true by default).
Stream & operator<<(Stream &&out, CallInfo_t const &info)
Helper operator to insert a call information in a stream with default options.
unsigned int skipLines
Number of lines to skip.
std::string shortLibrary() const
Returns only the library name (with suffix).
then echo File list $list not found else cat $list while read file do echo $file sed s
then echo echo For and will not be changed by echo further linking echo echo B echo The symbol is in the uninitialized data multiple common symbols may appear with the echo same name If the symbol is defined the common echo symbols are treated as undefined references For more echo details on common see the discussion of warn common echo in *Note Linker options
std::string mangledFunctionName
Parsed function name, unprocessed.
details::THE_TYPE_IS< T > _
std::string const & function() const
Returns the function name (mangled if nothing better).
void print(Stream &&out, CallInfo_t const &info) const
Print the content of info into the stream out, using the current options.
void printBacktrace(Stream &&out, BacktracePrintOptions options)
Prints the full backtrace into a stream.
void setOptions(opt opts)
Override all the options.
CallInfo_t(std::string const &s)
std::ptrdiff_t offset
Instruction pointer offset.
Set of options for printing.
Print the offset from the beginning of function.