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

Add simple stack trace on unhandled exception #78

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Source/Core/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ set(SRCS ActionReplay.cpp
Debugger/Debugger_SymbolMap.cpp
Debugger/Dump.cpp
Debugger/PPCDebugInterface.cpp
Debugger/StackWalker.cpp
DSP/DSPAssembler.cpp
DSP/DSPDisassembler.cpp
DSP/DSPAccelerator.cpp
Expand Down
68 changes: 68 additions & 0 deletions Source/Core/Core/Debugger/StackWalker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2008 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include <cstdio>
#include <string>
#include <ctime>

#include "Common/CommonPaths.h"
#include "Common/FileUtil.h"
#include "Common/StringUtil.h"
#include "Core/Debugger/StackWalker.h"


StackWalker::StackWalker(bool log)
: _log(log)
{
#if defined(__APPLE__)
std::string path = File::GetBundleDirectory() + "/Contents/Resources";
#elif defined(_WIN32)
std::string path = File::GetExeDirectory();
#else
std::string path = File::GetSysDirectory();
#endif

// This conversion is necessary for *reasons*
char sep = DIR_SEP_CHR;
if (path.back() != sep) {
path.push_back(sep);
}

int timestamp = std::time(0);

path = StringFromFormat("%s%d.txt", path.c_str(), timestamp);

if (_log)
{
printf("%s\n", path.c_str());
File::CreateEmptyFile(path);
log_file = File::IOFile(path, "wb");
}
}


void StackWalker::OnStackFrame(const wxStackFrame& frame)
{
const std::string head = StringFromFormat(
"Frame@ %p\n",
frame.GetAddress()
);

const std::string body = StringFromFormat(
"%lu %lu %s %s %s\n",
frame.GetLine(),
frame.GetLevel(),
frame.GetFileName().c_str().AsChar(),
frame.GetModule().c_str().AsChar(),
frame.GetName().c_str().AsChar()
);

if (_log) {
log_file.WriteBytes(head.data(), head.length());
log_file.WriteBytes(body.data(), body.length());
}

// To stdout as well
printf("%s%s", head.c_str(), body.c_str());
}
25 changes: 25 additions & 0 deletions Source/Core/Core/Debugger/StackWalker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2008 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include <wx/string.h>
#include <wx/stackwalk.h>

#include "Common/FileUtil.h"

class StackWalker : public wxStackWalker
{
public:
StackWalker(bool);
~StackWalker() { log_file.Close(); };

const File::IOFile& get_log_file() { return log_file; };
bool will_write() {return _log; };

protected:
void OnStackFrame(const wxStackFrame&);

private:
File::IOFile log_file;
bool _log;
};
3 changes: 3 additions & 0 deletions Source/Core/DolphinWX/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "Core/HW/Wiimote.h"
#include "Core/Host.h"
#include "Core/Movie.h"
#include "Core/Debugger/StackWalker.h"

#include "DolphinWX/Debugger/CodeWindow.h"
#include "DolphinWX/Debugger/JitWindow.h"
Expand Down Expand Up @@ -473,6 +474,8 @@ int DolphinApp::OnExit()

void DolphinApp::OnFatalException()
{
StackWalker walker (true);
walker.WalkFromException();
WiimoteReal::Shutdown();
}

Expand Down