From 0992a6848830ac973a2b0e586e7b617603be5c18 Mon Sep 17 00:00:00 2001 From: Amar Takhar Date: Wed, 9 Sep 2009 07:04:10 +0000 Subject: [PATCH] Rewrite how wxStackWalker works: * Change from fstream to wxFile. * Create both text-based and xml based reports (for the reporter) Originally committed to SVN as r3499. --- aegisub/src/main.cpp | 85 ++++++++++++++++++++++++++++---------------- aegisub/src/main.h | 9 ++--- 2 files changed, 58 insertions(+), 36 deletions(-) diff --git a/aegisub/src/main.cpp b/aegisub/src/main.cpp index ae5f41567..9e877ebe0 100644 --- a/aegisub/src/main.cpp +++ b/aegisub/src/main.cpp @@ -300,6 +300,7 @@ void AegisubApp::OnUnhandledException() { wxMessageBox(wxString::Format(exception_message, filename.c_str()), _("Program error"), wxOK | wxICON_ERROR, NULL); } + /// @brief Called during a fatal exception. void AegisubApp::OnFatalException() { // Current filename if any. @@ -327,54 +328,78 @@ void AegisubApp::OnFatalException() { #if wxUSE_STACKWALKER == 1 +/// @brief Called at the start of walking the stack. +/// @param cause cause of the crash. +/// +StackWalker::StackWalker(wxString cause) { + + wxFileName report_dir(""); + report_dir.SetPath(StandardPaths::DecodePath(_T("?user/reporter"))); + if (!report_dir.DirExists()) report_dir.Mkdir(); + + crash_text = new wxFile(StandardPaths::DecodePath("?user/crashlog.txt"), wxFile::write_append); + crash_xml = new wxFile(StandardPaths::DecodePath("?user/reporter/crash.xml"), wxFile::write); + + if ((crash_text->IsOpened()) && (crash_xml->IsOpened())) { + wxDateTime time = wxDateTime::Now(); + + crash_text->Write(wxString::Format("--- %s ------------------\n", time.FormatISOCombined())); + crash_text->Write(wxString::Format("VER - %s\n", GetAegisubLongVersionString())); + crash_text->Write(wxString::Format("FTL - Begining stack dump for \"%s\":\n", cause)); + + crash_xml->Write( "\n"); + crash_xml->Write( " \n"); + crash_xml->Write(wxString::Format(" %s\n", cause)); + crash_xml->Write(wxString::Format(" \n", time.FormatISOCombined())); + crash_xml->Write(wxString::Format(" %s\n", GetAegisubLongVersionString())); + crash_xml->Write( " \n"); + crash_xml->Write( " \n"); + } +} + /// @brief Callback to format a single frame /// @param frame frame to parse. /// void StackWalker::OnStackFrame(const wxStackFrame &frame) { - wxString dst = wxString::Format(_T("%03i - 0x%08X: "),frame.GetLevel(),frame.GetAddress()) + frame.GetName(); - if (frame.HasSourceLocation()) dst += _T(" on ") + frame.GetFileName() + wxString::Format(_T(":%i"),frame.GetLine()); - if (file.is_open()) { - file << dst.mb_str() << std::endl; - } - else wxLogMessage(dst); -} + if ((crash_text->IsOpened()) && (crash_xml->IsOpened())) { -/// @brief Called at the start of walking the stack. -/// @param cause cause of the crash. -/// -StackWalker::StackWalker(wxString cause) { - file.open(wxString(StandardPaths::DecodePath(_T("?user/crashlog.txt"))).mb_str(),std::ios::out | std::ios::app); - if (file.is_open()) { - wxDateTime time = wxDateTime::Now(); - wxString timeStr = _T("---") + time.FormatISODate() + _T(" ") + time.FormatISOTime() + _T("------------------"); - formatLen = timeStr.Length(); - file << std::endl << timeStr.mb_str(csConvLocal); - file << "\nVER - " << GetAegisubLongVersionString().mb_str(wxConvUTF8); - file << "\nFTL - Begining stack dump for \"" << cause.mb_str(wxConvUTF8) <<"\":\n"; + wxString dst = wxString::Format("%03i - 0x%08X: ",frame.GetLevel(),frame.GetAddress()) + frame.GetName(); + if (frame.HasSourceLocation()) + dst = wxString::Format("%s on %s:%d", dst, frame.GetFileName(), frame.GetLine()); + + crash_text->Write(wxString::Format("%s\n", dst)); + + crash_xml->Write(wxString::Format(" \n", frame.GetLevel(), frame.GetAddress())); + crash_xml->Write(wxString::Format(" %s\n", frame.GetName())); + if (frame.HasSourceLocation()) + crash_xml->Write(wxString::Format(" %s>%s\n", frame.GetLine(), frame.GetFileName())); + crash_xml->Write(wxString::Format(" \n", frame.GetModule())); + crash_xml->Write( " \n"); } } /// @brief Called at the end of walking the stack. StackWalker::~StackWalker() { - if (file.is_open()) { - char dashes[1024]; - int i = 0; - for (i=0;iIsOpened()) && (crash_xml->IsOpened())) { + + crash_text->Write("End of stack dump.\n"); + crash_text->Write("----------------------------------------\n\n"); + + crash_text->Close(); + + crash_xml->Write(" \n"); + crash_xml->Write("\n"); + + crash_xml->Close(); } } #endif - - /// @brief Call main loop /// @return /// diff --git a/aegisub/src/main.h b/aegisub/src/main.h index f724d56b3..68d3e1cb5 100644 --- a/aegisub/src/main.h +++ b/aegisub/src/main.h @@ -46,7 +46,7 @@ #include #include #include -#include +#include #include "aegisublocale.h" @@ -131,11 +131,8 @@ DECLARE_APP(AegisubApp) class StackWalker: public wxStackWalker { private: - /// DOCME - std::ofstream file; - - /// DOCME - int formatLen; + wxFile *crash_text; // FP to the crash text file. + wxFile *crash_xml; // FP to the crash xml file. public: StackWalker(wxString cause);