summaryrefslogtreecommitdiffstats
path: root/src/core/debugger
diff options
context:
space:
mode:
authorMorph <39850852+Morph1984@users.noreply.github.com>2022-06-13 20:38:37 +0200
committerGitHub <noreply@github.com>2022-06-13 20:38:37 +0200
commita0407a8e646172392514dd996d62464db64aee83 (patch)
treeb13a559bcb4a9f9641730d58285a56bde6d5cc80 /src/core/debugger
parentMerge pull request #8454 from liamwhite/inaddr-any (diff)
parentyuzu-cmd: ignore bogus timeous from SDL (diff)
downloadyuzu-a0407a8e646172392514dd996d62464db64aee83.tar
yuzu-a0407a8e646172392514dd996d62464db64aee83.tar.gz
yuzu-a0407a8e646172392514dd996d62464db64aee83.tar.bz2
yuzu-a0407a8e646172392514dd996d62464db64aee83.tar.lz
yuzu-a0407a8e646172392514dd996d62464db64aee83.tar.xz
yuzu-a0407a8e646172392514dd996d62464db64aee83.tar.zst
yuzu-a0407a8e646172392514dd996d62464db64aee83.zip
Diffstat (limited to '')
-rw-r--r--src/core/debugger/debugger.cpp55
-rw-r--r--src/core/debugger/debugger.h5
-rw-r--r--src/core/debugger/debugger_interface.h5
-rw-r--r--src/core/debugger/gdbstub.cpp2
-rw-r--r--src/core/debugger/gdbstub.h1
5 files changed, 61 insertions, 7 deletions
diff --git a/src/core/debugger/debugger.cpp b/src/core/debugger/debugger.cpp
index 7774ffdef..edf991d71 100644
--- a/src/core/debugger/debugger.cpp
+++ b/src/core/debugger/debugger.cpp
@@ -42,6 +42,16 @@ static std::span<const u8> ReceiveInto(Readable& r, Buffer& buffer) {
return received_data;
}
+enum class SignalType {
+ Stopped,
+ ShuttingDown,
+};
+
+struct SignalInfo {
+ SignalType type;
+ Kernel::KThread* thread;
+};
+
namespace Core {
class DebuggerImpl : public DebuggerBackend {
@@ -56,7 +66,7 @@ public:
ShutdownServer();
}
- bool NotifyThreadStopped(Kernel::KThread* thread) {
+ bool SignalDebugger(SignalInfo signal_info) {
std::scoped_lock lk{connection_lock};
if (stopped) {
@@ -64,9 +74,13 @@ public:
// It should be ignored.
return false;
}
+
+ // Set up the state.
stopped = true;
+ info = signal_info;
- boost::asio::write(signal_pipe, boost::asio::buffer(&thread, sizeof(thread)));
+ // Write a single byte into the pipe to wake up the debug interface.
+ boost::asio::write(signal_pipe, boost::asio::buffer(&stopped, sizeof(stopped)));
return true;
}
@@ -124,7 +138,7 @@ private:
Common::SetCurrentThreadName("yuzu:Debugger");
// Set up the client signals for new data.
- AsyncReceiveInto(signal_pipe, active_thread, [&](auto d) { PipeData(d); });
+ AsyncReceiveInto(signal_pipe, pipe_data, [&](auto d) { PipeData(d); });
AsyncReceiveInto(client_socket, client_data, [&](auto d) { ClientData(d); });
// Stop the emulated CPU.
@@ -142,9 +156,28 @@ private:
}
void PipeData(std::span<const u8> data) {
- AllCoreStop();
- UpdateActiveThread();
- frontend->Stopped(active_thread);
+ switch (info.type) {
+ case SignalType::Stopped:
+ // Stop emulation.
+ AllCoreStop();
+
+ // Notify the client.
+ active_thread = info.thread;
+ UpdateActiveThread();
+ frontend->Stopped(active_thread);
+
+ break;
+ case SignalType::ShuttingDown:
+ frontend->ShuttingDown();
+
+ // Wait for emulation to shut down gracefully now.
+ suspend.reset();
+ signal_pipe.close();
+ client_socket.shutdown(boost::asio::socket_base::shutdown_both);
+ LOG_INFO(Debug_GDBStub, "Shut down server");
+
+ break;
+ }
}
void ClientData(std::span<const u8> data) {
@@ -246,7 +279,9 @@ private:
boost::asio::ip::tcp::socket client_socket;
std::optional<std::unique_lock<std::mutex>> suspend;
+ SignalInfo info;
Kernel::KThread* active_thread;
+ bool pipe_data;
bool stopped;
std::array<u8, 4096> client_data;
@@ -263,7 +298,13 @@ Debugger::Debugger(Core::System& system, u16 port) {
Debugger::~Debugger() = default;
bool Debugger::NotifyThreadStopped(Kernel::KThread* thread) {
- return impl && impl->NotifyThreadStopped(thread);
+ return impl && impl->SignalDebugger(SignalInfo{SignalType::Stopped, thread});
+}
+
+void Debugger::NotifyShutdown() {
+ if (impl) {
+ impl->SignalDebugger(SignalInfo{SignalType::ShuttingDown, nullptr});
+ }
}
} // namespace Core
diff --git a/src/core/debugger/debugger.h b/src/core/debugger/debugger.h
index ea36c6ab2..f9738ca3d 100644
--- a/src/core/debugger/debugger.h
+++ b/src/core/debugger/debugger.h
@@ -35,6 +35,11 @@ public:
*/
bool NotifyThreadStopped(Kernel::KThread* thread);
+ /**
+ * Notify the debugger that a shutdown is being performed now and disconnect.
+ */
+ void NotifyShutdown();
+
private:
std::unique_ptr<DebuggerImpl> impl;
};
diff --git a/src/core/debugger/debugger_interface.h b/src/core/debugger/debugger_interface.h
index 35ba0bc61..c0bb4ecaf 100644
--- a/src/core/debugger/debugger_interface.h
+++ b/src/core/debugger/debugger_interface.h
@@ -67,6 +67,11 @@ public:
virtual void Stopped(Kernel::KThread* thread) = 0;
/**
+ * Called when emulation is shutting down.
+ */
+ virtual void ShuttingDown() = 0;
+
+ /**
* Called when new data is asynchronously received on the client socket.
* A list of actions to perform is returned.
*/
diff --git a/src/core/debugger/gdbstub.cpp b/src/core/debugger/gdbstub.cpp
index f52d78829..52e76f659 100644
--- a/src/core/debugger/gdbstub.cpp
+++ b/src/core/debugger/gdbstub.cpp
@@ -106,6 +106,8 @@ GDBStub::~GDBStub() = default;
void GDBStub::Connected() {}
+void GDBStub::ShuttingDown() {}
+
void GDBStub::Stopped(Kernel::KThread* thread) {
SendReply(arch->ThreadStatus(thread, GDB_STUB_SIGTRAP));
}
diff --git a/src/core/debugger/gdbstub.h b/src/core/debugger/gdbstub.h
index 1bb638187..ec934c77e 100644
--- a/src/core/debugger/gdbstub.h
+++ b/src/core/debugger/gdbstub.h
@@ -23,6 +23,7 @@ public:
void Connected() override;
void Stopped(Kernel::KThread* thread) override;
+ void ShuttingDown() override;
std::vector<DebuggerAction> ClientData(std::span<const u8> data) override;
private: