Varför fixar examplet att fa en bra stackdump MEN INTE g3log examplet????

This commit is contained in:
Kjell Hedstrom 2015-01-11 17:02:32 -07:00
parent 05fd4632c7
commit bd2b89f9de
2 changed files with 11 additions and 14 deletions

View File

@ -32,41 +32,32 @@ void ToLower(std::string &str)
}
}
void sleep_for(size_t seconds) {
std::this_thread::sleep_for(std::chrono::seconds(seconds));
}
void RaiseSIGABRT() {
std::cout << "Calling :" << __FUNCTION__ << " Line: " << __LINE__ << std::endl << std::flush;
sleep_for(2);
raise(SIGABRT);
LOG(WARNING) << "Expected to have died by now...";
}
void RaiseSIGFPE() {
std::cout << "Calling :" << __FUNCTION__ << " Line: " << __LINE__ << std::endl << std::flush;
sleep_for(2);
raise(SIGFPE);
LOG(WARNING) << "Expected to have died by now...";
}
void RaiseSIGSEGV() {
std::cout << "Calling :" << __FUNCTION__ << " Line: " << __LINE__ << std::endl << std::flush;
sleep_for(2);
raise(SIGSEGV);
LOG(WARNING) << "Expected to have died by now...";
}
void RaiseSIGILL() {
std::cout << "Calling :" << __FUNCTION__ << " Line: " << __LINE__ << std::endl << std::flush;
sleep_for(2);
raise(SIGILL);
LOG(WARNING) << "Expected to have died by now...";
}
void RAiseSIGTERM() {
std::cout << "Calling :" << __FUNCTION__ << " Line: " << __LINE__ << std::endl << std::flush;
sleep_for(2);
raise(SIGTERM);
LOG(WARNING) << "Expected to have died by now...";
}
@ -75,7 +66,6 @@ int gShouldBeZero = 1;
void DivisionByZero() {
std::cout << "Calling :" << __FUNCTION__ << " Line: " << __LINE__ << std::endl << std::flush;
std::cout << "Executing DivisionByZero: gShouldBeZero: " << gShouldBeZero << std::endl;
sleep_for(2);
int value = 3;
auto test = value / gShouldBeZero;
LOG(WARNING) << "Expected to have died by now...";
@ -83,7 +73,7 @@ void DivisionByZero() {
void IllegalPrintf() {
std::cout << "Calling :" << __FUNCTION__ << " Line: " << __LINE__ << std::endl << std::flush;
sleep_for(2);
printf("ILLEGAL PRINTF_SYNTAX %d EXAMPLE. %s %s", "hello", 1);
LOGF(INFO, "2nd attempt at ILLEGAL PRINTF_SYNTAX %d EXAMPLE. %s %s", "hello", 1);
LOG(WARNING) << "Expected to have died by now...";
@ -91,7 +81,6 @@ void IllegalPrintf() {
void OutOfBoundsArrayIndexing() {
std::cout << "Calling :" << __FUNCTION__ << " Line: " << __LINE__ << std::endl << std::flush;
sleep_for(2);
std::vector<int> v;
v[0] = 5;
LOG(WARNING) << "Expected to have died by now...";
@ -100,7 +89,6 @@ void OutOfBoundsArrayIndexing() {
void AccessViolation() {
std::cout << "Calling :" << __FUNCTION__ << " Line: " << __LINE__ << std::endl << std::flush;
sleep_for(2);
char *ptr = 0;
*ptr = 0;
LOG(WARNING) << "Expected to have died by now...";

View File

@ -22,6 +22,8 @@
#include <cstdlib>
#include <iostream> // to remove TODO
#include <sstream> // TODO REMOVE
#include <working_trace.hpp>
#pragma once
#if !(defined(WIN32) || defined(_WIN32) || defined(__WIN32__))
#error "stacktrace_win.cpp used but not on a windows system"
@ -149,6 +151,7 @@ std::string exceptionIdToText(size_t id) {
}
/// helper function: retrieve stackdump from no excisting exception pointer
std::string stackdump() {
CONTEXT current_context;
@ -166,7 +169,12 @@ std::string stackdump(EXCEPTION_POINTERS *info) {
/// main stackdump function. retrieve stackdump, from the given context
std::string stackdump(CONTEXT *context) {
{
stack_trace sttrace(context); // if there is a windows exception then call it like THIS
auto crashreport = sttrace.to_string();
return crashreport;
/* {
static std::atomic<size_t> recursiveCounter = 0;
++recursiveCounter;
assert(recursiveCounter.load() == 1 && "Never allow recursive crashes");
@ -185,6 +193,7 @@ std::string stackdump(CONTEXT *context) {
std::vector<uint64_t> frame_pointers(kmax_frame_dump_size); // C++11: size set and values are zeroed
captureStackTrace(context, frame_pointers);
return convertFramesToText(frame_pointers);
*/
}