Added dump methods to stacktrace

This commit is contained in:
sale 2016-12-19 10:02:24 +00:00
parent fcc1642cad
commit 18612a3063
3 changed files with 8 additions and 12 deletions

View File

@ -58,17 +58,18 @@ public:
return lines.size();
}
void dump(std::ostream& stream) {
std::string message;
dump(message);
stream << message;
template <class Stream>
void dump(Stream& stream) {
stream << dump();
}
void dump(std::string& message) {
std::string dump() {
std::string message;
for (int i = 0; i < size(); i++) {
message.append(fmt::format("at {} ({}) \n", lines[i].function,
lines[i].location));
}
return message;
}
private:

View File

@ -22,8 +22,7 @@ static constexpr const char* port = "7687";
void throw_and_stacktace(std::string message) {
Stacktrace stacktrace;
stacktrace.dump(message);
logger.info(message);
logger.info(stacktrace.dump());
}
int main(void) {

View File

@ -12,11 +12,7 @@ TEST_CASE("SignalHandler Segmentation Fault Test") {
SignalHandler::register_handler(Signal::SegmentationFault, []() {
std::cout << "Segmentation Fault" << std::endl;
Stacktrace stacktrace;
std::string message;
stacktrace.dump(message);
std::cout << message << std::endl;
std::cout << stacktrace.dump() << std::endl;
});
std::raise(SIGSEGV);