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 };
20 setAll(s, addressStr, libraryStr, functionStr, offsetStr);
26 size_t i = s.find(
'(');
27 if (i == boo)
return false;
33 libraryStr = { 0U, i };
34 addressStr = { boo, boo };
35 functionStr = { boo, boo };
36 offsetStr = { boo, boo };
38 functionStr.first = ++i;
40 i = s.find_first_of(
"(+-)", i);
41 if (i == boo)
return false;
45 functionStr.second = i;
48 i = s.find_first_of(
"()", ++i);
49 if (i == boo)
return false;
58 functionStr.second = i;
63 i = s.find_first_of(
"([", ++i);
65 if (s[i] ==
'(')
continue;
66 addressStr.first = ++i;
68 i = s.find_first_of(
"(]", i);
69 if (s[i] ==
'(')
continue;
70 addressStr.second = i;
75 setAll(s, addressStr, libraryStr, functionStr, offsetStr);
85 std::istringstream sstr(s);
91 >> std::hex >>
address >> std::dec
95 if (sstr.fail())
break;
97 if (sstr.fail())
offset = 0;
99 if (plus !=
'+')
break;
101 if (sstr.fail())
break;
115 # error("I am not on Linux nor on OSX. Hard to believe.") 122 std::string
const&
s,
135 std::istringstream sstr(
extract(s, addressStr));
141 auto offsetRange = offsetStr;
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);
150 sstr.str(
extract(s, offsetRange));
152 if (neg) offset = -
offset;
std::string original
String from the backtrace, unparsed.
static std::string extract(std::string const &s, range_t const &r)
Translates a range into a string.
std::string functionName
Parsed function name, demangled.
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.
void * address
Function address.
void demangleFunction()
Runs the demangler and stores the result.
bool ParseString(std::string const &s)
Returns whether the translation was complete (offset is optional!).
std::pair< size_t, size_t > range_t
static bool emptyRange(range_t const &r)
Returns whether the range is empty or invalid.
Functions to help debugging by instrumenting code.
std::string mangledFunctionName
Parsed function name, unprocessed.
std::ptrdiff_t offset
Instruction pointer offset.