Public Member Functions | Public Attributes | Private Types | Private Member Functions | Static Private Member Functions | List of all members
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 62 of file DebugUtils.h.

Member Typedef Documentation

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

Definition at line 64 of file DebugUtils.h.

Constructor & Destructor Documentation

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

Definition at line 67 of file DebugUtils.h.

67 { ParseString(s); }
bool ParseString(std::string const &s)
Returns whether the translation was complete (offset is optional!).
Definition: DebugUtils.cxx:11
static QCString * s
Definition: config.cpp:1042
lar::debug::CallInfo_t::CallInfo_t ( const char *  s)
inline

Definition at line 68 of file DebugUtils.h.

std::string string
Definition: nybbler.cc:12
bool ParseString(std::string const &s)
Returns whether the translation was complete (offset is optional!).
Definition: DebugUtils.cxx:11
static QCString * s
Definition: config.cpp:1042

Member Function Documentation

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

Runs the demangler and stores the result.

Definition at line 110 of file DebugUtils.h.

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

Returns whether the range is empty or invalid.

Definition at line 103 of file DebugUtils.h.

103 { 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 106 of file DebugUtils.h.

107  { return emptyRange(r)? "": s.substr(r.first, r.second - r.first); }
static bool emptyRange(range_t const &r)
Returns whether the range is empty or invalid.
Definition: DebugUtils.h:103
static QCString * s
Definition: config.cpp:1042
std::string const& lar::debug::CallInfo_t::function ( ) const
inline

Returns the function name (mangled if nothing better).

Definition at line 81 of file DebugUtils.h.

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

Returns whether there is some information parsed.

Definition at line 71 of file DebugUtils.h.

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

Returns whether no information was parsed out of the original.

Definition at line 74 of file DebugUtils.h.

75  { return libraryName.empty() && mangledFunctionName.empty(); }
std::string libraryName
Parsed library name.
Definition: DebugUtils.h:94
std::string mangledFunctionName
Parsed function name, unprocessed.
Definition: DebugUtils.h:96
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.

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:93
std::string functionName
Parsed function name, demangled.
Definition: DebugUtils.h:95
std::string libraryName
Parsed library name.
Definition: DebugUtils.h:94
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
QTextStream & hex(QTextStream &s)
int find(char c, int index=0, bool cs=TRUE) const
Definition: qcstring.cpp:41
void demangleFunction()
Runs the demangler and stores the result.
Definition: DebugUtils.h:110
std::pair< size_t, size_t > range_t
Definition: DebugUtils.h:64
std::void_t< T > n
QTextStream & dec(QTextStream &s)
std::string mangledFunctionName
Parsed function name, unprocessed.
Definition: DebugUtils.h:96
static QCString * s
Definition: config.cpp:1042
std::ptrdiff_t offset
Instruction pointer offset.
Definition: DebugUtils.h:98
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.

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:93
static std::string extract(std::string const &s, range_t const &r)
Translates a range into a string.
Definition: DebugUtils.h:106
std::string libraryName
Parsed library name.
Definition: DebugUtils.h:94
QTextStream & hex(QTextStream &s)
void * address
Function address.
Definition: DebugUtils.h:97
void demangleFunction()
Runs the demangler and stores the result.
Definition: DebugUtils.h:110
static bool emptyRange(range_t const &r)
Returns whether the range is empty or invalid.
Definition: DebugUtils.h:103
std::string mangledFunctionName
Parsed function name, unprocessed.
Definition: DebugUtils.h:96
if(!yymsg) yymsg
static QCString * s
Definition: config.cpp:1042
std::ptrdiff_t offset
Instruction pointer offset.
Definition: DebugUtils.h:98
std::string lar::debug::CallInfo_t::shortLibrary ( ) const
inline

Returns only the library name (with suffix).

Definition at line 85 of file DebugUtils.h.

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

Member Data Documentation

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

Function address.

Definition at line 97 of file DebugUtils.h.

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

Parsed function name, demangled.

Definition at line 95 of file DebugUtils.h.

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

Parsed library name.

Definition at line 94 of file DebugUtils.h.

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

Parsed function name, unprocessed.

Definition at line 96 of file DebugUtils.h.

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

Instruction pointer offset.

Definition at line 98 of file DebugUtils.h.

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

String from the backtrace, unparsed.

Definition at line 93 of file DebugUtils.h.


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