LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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 61 of file DebugUtils.h.

Member Typedef Documentation

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

Definition at line 63 of file DebugUtils.h.

Constructor & Destructor Documentation

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

Definition at line 66 of file DebugUtils.h.

References ParseString().

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

Definition at line 67 of file DebugUtils.h.

References ParseString().

67 { ParseString(std::string(s)); }
Float_t s
Definition: plot.C:23
bool ParseString(std::string const &s)
Returns whether the translation was complete (offset is optional!).
Definition: DebugUtils.cxx:11

Member Function Documentation

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

Runs the demangler and stores the result.

Definition at line 109 of file DebugUtils.h.

References setAll().

Referenced by ParseString(), and setAll().

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

Returns whether the range is empty or invalid.

Definition at line 102 of file DebugUtils.h.

Referenced by extract(), and setAll().

102 { return r.first >= r.second; }
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 105 of file DebugUtils.h.

References emptyRange().

Referenced by setAll().

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

Returns the function name (mangled if nothing better).

Definition at line 80 of file DebugUtils.h.

References functionName, and mangledFunctionName.

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

81  { return functionName.empty()? mangledFunctionName: functionName; }
std::string functionName
Parsed function name, demangled.
Definition: DebugUtils.h:94
std::string mangledFunctionName
Parsed function name, unprocessed.
Definition: DebugUtils.h:95
lar::debug::CallInfo_t::operator bool ( ) const
inline

Returns whether there is some information parsed.

Definition at line 70 of file DebugUtils.h.

References libraryName, and mangledFunctionName.

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

Returns whether no information was parsed out of the original.

Definition at line 73 of file DebugUtils.h.

References libraryName, mangledFunctionName, ParseString(), and s.

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

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

Definition at line 11 of file DebugUtils.cxx.

References address, demangleFunction(), functionName, libraryName, mangledFunctionName, n, offset, original, s, 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 '+': case '-':
45  functionStr.second = i;
46  if (s[i] == '+') ++i;
47  offsetStr.first = i;
48  i = s.find_first_of("()", ++i);
49  if (i == boo) return false;
50  switch (s[i]) {
51  case '(': continue;
52  case ')':
53  offsetStr.second = i;
54  break;
55  } // switch (inner)
56  break;
57  case ')':
58  functionStr.second = i;
59  break;
60  } // switch (outer)
61 
62  // finish with the address
63  i = s.find_first_of("([", ++i);
64  if (i == boo) break;
65  if (s[i] == '(') continue;
66  addressStr.first = ++i;
67 
68  i = s.find_first_of("(]", i);
69  if (s[i] == '(') continue;
70  addressStr.second = i;
71 
72  break;
73  } // while (for ever)
74 
75  setAll(s, addressStr, libraryStr, functionStr, offsetStr);
76  return true;
77 
78  //----------------------------------------------------------------------------
79 #elif (__APPLE__)
80  // expected format:
81  // N libraryName address mangledFunction + offset
82  // "+ offset" is considered optional
83  original = s;
84  while (true) {
85  std::istringstream sstr(s);
86  int n;
87  char plus;
88  sstr
89  >> n
90  >> libraryName
91  >> std::hex >> address >> std::dec
93 
94  // optional offset
95  if (sstr.fail()) break; // an error somewhere: bail out
96  sstr >> plus;
97  if (sstr.fail()) offset = 0;
98  else {
99  if (plus != '+') break;
100  sstr >> offset;
101  if (sstr.fail()) break;
102  }
103 
105  return true;
106  } // while
107  address = nullptr;
108  libraryName.clear();
109  mangledFunctionName.clear();
110  functionName.clear();
111  offset = 0;
112  return false;
113  //----------------------------------------------------------------------------
114 #else
115 # error("I am not on Linux nor on OSX. Hard to believe.")
116 #endif
117 } // lar::debug::CallInfo_t::ParseString()
std::string original
String from the backtrace, unparsed.
Definition: DebugUtils.h:92
Float_t s
Definition: plot.C:23
std::string functionName
Parsed function name, demangled.
Definition: DebugUtils.h:94
std::string libraryName
Parsed library name.
Definition: DebugUtils.h:93
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:121
void * address
Function address.
Definition: DebugUtils.h:96
void demangleFunction()
Runs the demangler and stores the result.
Definition: DebugUtils.h:109
std::pair< size_t, size_t > range_t
Definition: DebugUtils.h:63
std::string mangledFunctionName
Parsed function name, unprocessed.
Definition: DebugUtils.h:95
Char_t n[5]
std::ptrdiff_t offset
Instruction pointer offset.
Definition: DebugUtils.h:97
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 121 of file DebugUtils.cxx.

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

Referenced by demangleFunction(), and ParseString().

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

Returns only the library name (with suffix).

Definition at line 84 of file DebugUtils.h.

References libraryName.

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

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

Member Data Documentation

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

Function address.

Definition at line 96 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 94 of file DebugUtils.h.

Referenced by function(), and ParseString().

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

Parsed library name.

Definition at line 93 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 95 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 97 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 92 of file DebugUtils.h.

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


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