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

Structure with information about a single call, parsed. More...

#include "DebugUtils.h"

Public Member Functions

 CallInfo_t (std::string const &s)
 
 CallInfo_t (const char *s)
 
 operator bool () const
 Returns whether there is some information parsed. More...
 
bool operator! () const
 Returns whether no information was parsed out of the original. More...
 
bool ParseString (std::string const &s)
 Returns whether the translation was complete (offset is optional!). More...
 
std::string const & function () const
 Returns the function name (mangled if nothing better). More...
 
std::string shortLibrary () const
 Returns only the library name (with suffix). More...
 

Public Attributes

std::string original
 String from the backtrace, unparsed. More...
 
std::string libraryName
 Parsed library name. More...
 
std::string functionName
 Parsed function name, demangled. More...
 
std::string mangledFunctionName
 Parsed function name, unprocessed. More...
 
void * address = nullptr
 Function address. More...
 
std::ptrdiff_t offset = 0
 Instruction pointer offset. More...
 

Private Types

using range_t = std::pair< size_t, size_t >
 

Private Member Functions

void demangleFunction ()
 Runs the demangler and stores the result. More...
 
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. More...
 

Static Private Member Functions

static bool emptyRange (range_t const &r)
 Returns whether the range is empty or invalid. More...
 
static std::string extract (std::string const &s, range_t const &r)
 Translates a range into a string. More...
 

Detailed Description

Structure with information about a single call, parsed.

Definition at line 60 of file DebugUtils.h.

Member Typedef Documentation

using lar::debug::CallInfo_t::range_t = std::pair<size_t, size_t>
private

Definition at line 62 of file DebugUtils.h.

Constructor & Destructor Documentation

lar::debug::CallInfo_t::CallInfo_t ( std::string const &  s)
inline

Definition at line 65 of file DebugUtils.h.

References ParseString().

65 { ParseString(s); }
bool ParseString(std::string const &s)
Returns whether the translation was complete (offset is optional!).
Definition: DebugUtils.cxx:10
lar::debug::CallInfo_t::CallInfo_t ( const char *  s)
inline

Definition at line 66 of file DebugUtils.h.

References ParseString().

66 { ParseString(std::string(s)); }
bool ParseString(std::string const &s)
Returns whether the translation was complete (offset is optional!).
Definition: DebugUtils.cxx:10

Member Function Documentation

void lar::debug::CallInfo_t::demangleFunction ( )
inlineprivate

Runs the demangler and stores the result.

Definition at line 108 of file DebugUtils.h.

References setAll().

Referenced by ParseString(), and setAll().

108 { functionName = cet::demangle_symbol(mangledFunctionName); }
std::string functionName
Parsed function name, demangled.
Definition: DebugUtils.h:92
std::string mangledFunctionName
Parsed function name, unprocessed.
Definition: DebugUtils.h:93
static bool lar::debug::CallInfo_t::emptyRange ( range_t const &  r)
inlinestaticprivate

Returns whether the range is empty or invalid.

Definition at line 99 of file DebugUtils.h.

Referenced by extract(), and setAll().

99 { return r.first >= r.second; }
TRandom r
Definition: spectrum.C:23
static std::string lar::debug::CallInfo_t::extract ( std::string const &  s,
range_t const &  r 
)
inlinestaticprivate

Translates a range into a string.

Definition at line 102 of file DebugUtils.h.

References emptyRange().

Referenced by setAll().

103  {
104  return emptyRange(r) ? "" : s.substr(r.first, r.second - r.first);
105  }
TRandom r
Definition: spectrum.C:23
static bool emptyRange(range_t const &r)
Returns whether the range is empty or invalid.
Definition: DebugUtils.h:99
std::string const& lar::debug::CallInfo_t::function ( ) const
inline

Returns the function name (mangled if nothing better).

Definition at line 77 of file DebugUtils.h.

References functionName, and mangledFunctionName.

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

78  {
80  }
std::string functionName
Parsed function name, demangled.
Definition: DebugUtils.h:92
std::string mangledFunctionName
Parsed function name, unprocessed.
Definition: DebugUtils.h:93
lar::debug::CallInfo_t::operator bool ( ) const
inline

Returns whether there is some information parsed.

Definition at line 69 of file DebugUtils.h.

References libraryName, and mangledFunctionName.

69 { return !libraryName.empty() || !mangledFunctionName.empty(); }
std::string libraryName
Parsed library name.
Definition: DebugUtils.h:91
std::string mangledFunctionName
Parsed function name, unprocessed.
Definition: DebugUtils.h:93
bool lar::debug::CallInfo_t::operator! ( ) const
inline

Returns whether no information was parsed out of the original.

Definition at line 71 of file DebugUtils.h.

References libraryName, mangledFunctionName, and ParseString().

71 { return libraryName.empty() && mangledFunctionName.empty(); }
std::string libraryName
Parsed library name.
Definition: DebugUtils.h:91
std::string mangledFunctionName
Parsed function name, unprocessed.
Definition: DebugUtils.h:93
bool lar::debug::CallInfo_t::ParseString ( std::string const &  s)

Returns whether the translation was complete (offset is optional!).

Definition at line 10 of file DebugUtils.cxx.

References address, demangleFunction(), functionName, libraryName, mangledFunctionName, n, offset, original, and setAll().

Referenced by CallInfo_t(), and operator!().

11 {
12 
13  //----------------------------------------------------------------------------
14 #if (__linux__)
15  constexpr auto boo = std::string::npos;
16  range_t libraryStr{boo, boo};
17  range_t addressStr{boo, boo};
18  range_t functionStr{boo, boo};
19  range_t offsetStr{boo, boo};
20  setAll(s, addressStr, libraryStr, functionStr, offsetStr);
21 
22  // expected format:
23  // libraryName(mangledSymbol+offset) [hexAddress]
24  // (+offset optional)
25 
26  size_t i = s.find('(');
27  if (i == boo) return false;
28  libraryStr.first = 0;
29  while (true) {
30  // at all time, if we find a '(', we start over
31  // since a '(' can only be after the library name
32 
33  libraryStr = {0U, i};
34  addressStr = {boo, boo};
35  functionStr = {boo, boo};
36  offsetStr = {boo, boo};
37 
38  functionStr.first = ++i;
39 
40  i = s.find_first_of("(+-)", i);
41  if (i == boo) return false;
42  switch (s[i]) {
43  case '(': continue;
44  case '+':
45  case '-':
46  functionStr.second = i;
47  if (s[i] == '+') ++i;
48  offsetStr.first = i;
49  i = s.find_first_of("()", ++i);
50  if (i == boo) return false;
51  switch (s[i]) {
52  case '(': continue;
53  case ')': offsetStr.second = i; break;
54  } // switch (inner)
55  break;
56  case ')': functionStr.second = i; break;
57  } // switch (outer)
58 
59  // finish with the address
60  i = s.find_first_of("([", ++i);
61  if (i == boo) break;
62  if (s[i] == '(') continue;
63  addressStr.first = ++i;
64 
65  i = s.find_first_of("(]", i);
66  if (s[i] == '(') continue;
67  addressStr.second = i;
68 
69  break;
70  } // while (for ever)
71 
72  setAll(s, addressStr, libraryStr, functionStr, offsetStr);
73  return true;
74 
75  //----------------------------------------------------------------------------
76 #elif (__APPLE__)
77  // expected format:
78  // N libraryName address mangledFunction + offset
79  // "+ offset" is considered optional
80  original = s;
81  while (true) {
82  std::istringstream sstr(s);
83  int n;
84  char plus;
85  sstr >> n >> libraryName >> std::hex >> address >> std::dec >> mangledFunctionName;
86 
87  // optional offset
88  if (sstr.fail()) break; // an error somewhere: bail out
89  sstr >> plus;
90  if (sstr.fail())
91  offset = 0;
92  else {
93  if (plus != '+') break;
94  sstr >> offset;
95  if (sstr.fail()) break;
96  }
97 
99  return true;
100  } // while
101  address = nullptr;
102  libraryName.clear();
103  mangledFunctionName.clear();
104  functionName.clear();
105  offset = 0;
106  return false;
107  //----------------------------------------------------------------------------
108 #else
109 #error("I am not on Linux nor on OSX. Hard to believe.")
110 #endif
111 } // lar::debug::CallInfo_t::ParseString()
std::string original
String from the backtrace, unparsed.
Definition: DebugUtils.h:90
std::string functionName
Parsed function name, demangled.
Definition: DebugUtils.h:92
std::string libraryName
Parsed library name.
Definition: DebugUtils.h:91
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.
Definition: DebugUtils.cxx:113
void * address
Function address.
Definition: DebugUtils.h:94
void demangleFunction()
Runs the demangler and stores the result.
Definition: DebugUtils.h:108
std::pair< size_t, size_t > range_t
Definition: DebugUtils.h:62
std::string mangledFunctionName
Parsed function name, unprocessed.
Definition: DebugUtils.h:93
Char_t n[5]
std::ptrdiff_t offset
Instruction pointer offset.
Definition: DebugUtils.h:95
void lar::debug::CallInfo_t::setAll ( std::string const &  s,
range_t  addressStr,
range_t  libraryStr,
range_t  functionStr,
range_t  offsetStr 
)
private

Fills the information from an original string and parsed ranges.

Definition at line 113 of file DebugUtils.cxx.

References address, demangleFunction(), emptyRange(), extract(), if(), libraryName, mangledFunctionName, offset, and original.

Referenced by demangleFunction(), and ParseString().

118 {
119  original = s;
120 
121  libraryName = extract(s, libraryStr);
122 
123  mangledFunctionName = extract(s, functionStr);
125 
126  if (!emptyRange(addressStr)) {
127  std::istringstream sstr(extract(s, addressStr));
128  sstr >> address;
129  }
130 
131  if (emptyRange(offsetStr))
132  offset = 0;
133  else {
134  auto offsetRange = offsetStr;
135  if (!emptyRange(offsetRange)) {
136  bool neg = (s[offsetRange.first] == '-');
137  std::istringstream sstr;
138  if (neg || (s[offsetRange.first] == '+')) ++offsetRange.first;
139  if (s.substr(offsetRange.first, 2) == "0x") {
140  offsetRange.first += 2;
141  sstr.setf(std::ios::hex);
142  }
143  sstr.str(extract(s, offsetRange));
144  sstr >> offset;
145  if (neg) offset = -offset;
146  }
147  } // if offset ... else
148 
149 } // lar::debug::CallInfo_t::setAll()
std::string original
String from the backtrace, unparsed.
Definition: DebugUtils.h:90
static std::string extract(std::string const &s, range_t const &r)
Translates a range into a string.
Definition: DebugUtils.h:102
std::string libraryName
Parsed library name.
Definition: DebugUtils.h:91
void * address
Function address.
Definition: DebugUtils.h:94
void demangleFunction()
Runs the demangler and stores the result.
Definition: DebugUtils.h:108
if(nlines<=0)
static bool emptyRange(range_t const &r)
Returns whether the range is empty or invalid.
Definition: DebugUtils.h:99
std::string mangledFunctionName
Parsed function name, unprocessed.
Definition: DebugUtils.h:93
std::ptrdiff_t offset
Instruction pointer offset.
Definition: DebugUtils.h:95
std::string lar::debug::CallInfo_t::shortLibrary ( ) const
inline

Returns only the library name (with suffix).

Definition at line 83 of file DebugUtils.h.

References libraryName.

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

84  {
85  size_t sep = libraryName.rfind('/');
86  return (sep == std::string::npos) ? libraryName : libraryName.substr(sep + 1);
87  // return std::experimental::filesystem::path(libraryName).filename();
88  }
std::string libraryName
Parsed library name.
Definition: DebugUtils.h:91

Member Data Documentation

void* lar::debug::CallInfo_t::address = nullptr

Function address.

Definition at line 94 of file DebugUtils.h.

Referenced by ParseString(), lar::debug::CallInfoPrinter::print(), and setAll().

std::string lar::debug::CallInfo_t::functionName

Parsed function name, demangled.

Definition at line 92 of file DebugUtils.h.

Referenced by function(), and ParseString().

std::string lar::debug::CallInfo_t::libraryName

Parsed library name.

Definition at line 91 of file DebugUtils.h.

Referenced by operator bool(), operator!(), ParseString(), lar::debug::CallInfoPrinter::print(), setAll(), and shortLibrary().

std::string lar::debug::CallInfo_t::mangledFunctionName

Parsed function name, unprocessed.

Definition at line 93 of file DebugUtils.h.

Referenced by function(), operator bool(), operator!(), ParseString(), lar::debug::CallInfoPrinter::print(), and setAll().

std::ptrdiff_t lar::debug::CallInfo_t::offset = 0

Instruction pointer offset.

Definition at line 95 of file DebugUtils.h.

Referenced by ParseString(), lar::debug::CallInfoPrinter::print(), and setAll().

std::string lar::debug::CallInfo_t::original

String from the backtrace, unparsed.

Definition at line 90 of file DebugUtils.h.

Referenced by ParseString(), lar::debug::CallInfoPrinter::print(), and setAll().


The documentation for this struct was generated from the following files: