Include debug symbols in Release build, rework exception stack trace.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#if !WINDOWS
|
||||
#define BACKWARD_HAS_BFD 1
|
||||
#define BACKWARD_HAS_DW 1
|
||||
#include "../extern/backward.hpp"
|
||||
#endif
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace ArbUt {
|
||||
public:
|
||||
explicit Exception(const std::string& msg) : std::logic_error(msg) {
|
||||
#if !WINDOWS
|
||||
_stack.load_here(9);
|
||||
_stack.load_here(32);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -43,33 +43,20 @@ namespace ArbUt {
|
||||
backward::TraceResolver tr;
|
||||
tr.load_stacktrace(_stack);
|
||||
std::stringstream ss;
|
||||
for (size_t i = 3; i < _stack.size() && i < depth + 3; ++i) {
|
||||
ss << "Stacktrace with depth " << depth << ": " << std::endl;
|
||||
bool foundExceptionClass = false;
|
||||
size_t framesAppended = -1;
|
||||
for (size_t i = 0; i < _stack.size(); ++i) {
|
||||
backward::ResolvedTrace trace = tr.resolve(_stack[i]);
|
||||
if (trace.source.filename.empty()) {
|
||||
auto objectName =
|
||||
(strrchr(trace.object_filename.c_str(), '/') ? strrchr(trace.object_filename.c_str(), '/') + 1
|
||||
: trace.object_filename.c_str());
|
||||
auto function = trace.object_function;
|
||||
if (function.length() > 70) {
|
||||
function = function.substr(0, 67);
|
||||
function += "...";
|
||||
}
|
||||
ss << objectName;
|
||||
if (include_addr) {
|
||||
ss << "[" << trace.addr << "]";
|
||||
}
|
||||
ss << " " << function << std::endl;
|
||||
|
||||
AppendNoSourceStack(ss, trace, include_addr);
|
||||
} else {
|
||||
auto fileName =
|
||||
(strrchr(trace.source.filename.c_str(), '/') ? strrchr(trace.source.filename.c_str(), '/') + 1
|
||||
: trace.source.filename.c_str());
|
||||
auto function = trace.object_function;
|
||||
if (function.length() > 70) {
|
||||
function = function.substr(0, 67);
|
||||
function += "...";
|
||||
AppendSourceStack(ss, trace, foundExceptionClass);
|
||||
if (foundExceptionClass){
|
||||
framesAppended++;
|
||||
if (framesAppended >= depth)
|
||||
break;
|
||||
}
|
||||
ss << fileName << "[" << trace.source.line << "] " << function << std::endl;
|
||||
}
|
||||
}
|
||||
return ss.str();
|
||||
@@ -77,6 +64,42 @@ namespace ArbUt {
|
||||
return "Stack trace not available on Windows.";
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
static void AppendNoSourceStack(std::stringstream& ss, const backward::ResolvedTrace& trace,
|
||||
bool include_addr) {
|
||||
auto objectName =
|
||||
(strrchr(trace.object_filename.c_str(), '/') ? strrchr(trace.object_filename.c_str(), '/') + 1
|
||||
: trace.object_filename.c_str());
|
||||
auto function = trace.object_function;
|
||||
if (function.length() > 70) {
|
||||
function = function.substr(0, 67);
|
||||
function += "...";
|
||||
}
|
||||
ss << objectName;
|
||||
if (include_addr) {
|
||||
ss << "[" << trace.addr << "]";
|
||||
}
|
||||
ss << " " << function << std::endl;
|
||||
}
|
||||
static void AppendSourceStack(std::stringstream& ss, const backward::ResolvedTrace& trace, bool& foundExceptionClass) {
|
||||
auto fileName =
|
||||
(strrchr(trace.source.filename.c_str(), '/') ? strrchr(trace.source.filename.c_str(), '/') + 1
|
||||
: trace.source.filename.c_str());
|
||||
if (strcmp(fileName, "Exception.hpp") == 0) {
|
||||
foundExceptionClass = true;
|
||||
return;
|
||||
} else if (!foundExceptionClass) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto function = trace.object_function;
|
||||
if (function.length() > 70) {
|
||||
function = function.substr(0, 67);
|
||||
function += "...";
|
||||
}
|
||||
ss << fileName << "[" << trace.source.line << "] " << function << std::endl;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user