Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added optional parsable exception reports #11

Merged
merged 1 commit into from
Dec 18, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions arch/exception_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
*/

#include <sys/syscall.h>
#include <fstream>
#include "exception.h"
#include "exception_hook.h"
#include "demangle.h"
#include <cxxabi.h>
#include "backtrace.h"
#include "jml/arch/format.h"
#include "jml/compiler/compiler.h"
#include "jml/utils/environment.h"

Expand Down Expand Up @@ -107,15 +109,43 @@ void trace_exception(void * object, const std::type_info * tinfo)
// We don't want these exceptions to be printed out.
if (dynamic_cast<const ML::SilentException *>(exc)) return;

time_t now;
time(&now);

char datetime[128];
strftime(datetime, sizeof(datetime), "%F-%H%M%S", localtime(&now));

auto pid = getpid();
auto tid = (long) syscall(SYS_gettid);


cerr << endl;
cerr << "----------------- Exception thrown ------------------------"
cerr << "--------------------------[Exception thrown]---------------------------"
<< endl;
cerr << "time: " << datetime << endl;
cerr << "type: " << demangle(tinfo->name()) << endl
<< "pid: " << getpid() << "; tid: " << (long) syscall(SYS_gettid) << endl;
<< "pid: " << pid << "; tid: " << tid << endl;
if (exc) cerr << "what: " << exc->what() << endl;

cerr << "stack:" << endl;
backtrace(cerr, 3);

char const * reports = getenv("ENABLE_EXCEPTION_REPORTS");
if(reports) {
std::string path = ML::format("%s/exception-report-%s-%d-%d.log",
reports,
datetime,
pid,
tid);

std::ofstream file(path, std::ios_base::app);
if(file) {
file << getenv("_") << endl;
backtrace(file, 3);
file.close();
}
}

cerr << endl;
}

Expand Down