summaryrefslogtreecommitdiff
path: root/src/core/gdbstub/gdbstub.cpp
diff options
context:
space:
mode:
authorGravatar Lioncash2016-12-15 16:19:30 -0500
committerGravatar Lioncash2016-12-15 16:37:22 -0500
commitba20dd9b6125551ecf2016ed7dbd61dc618fc876 (patch)
tree339289e4a87660df3edf1d3263ecb0e22ca2b573 /src/core/gdbstub/gdbstub.cpp
parentMerge pull request #2330 from lioncash/pragma (diff)
downloadyuzu-ba20dd9b6125551ecf2016ed7dbd61dc618fc876.tar.gz
yuzu-ba20dd9b6125551ecf2016ed7dbd61dc618fc876.tar.xz
yuzu-ba20dd9b6125551ecf2016ed7dbd61dc618fc876.zip
gdbstub: Remove global variable from public interface
Currently, this is only ever queried, so adding a function to check if the server is enabled is more sensible. If directly modifying this externally is ever desirable, it should be done by adding a function to the interface, rather than exposing implementation details directly.
Diffstat (limited to 'src/core/gdbstub/gdbstub.cpp')
-rw-r--r--src/core/gdbstub/gdbstub.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp
index 21d941363..1303bafc1 100644
--- a/src/core/gdbstub/gdbstub.cpp
+++ b/src/core/gdbstub/gdbstub.cpp
@@ -5,6 +5,7 @@
5// Originally written by Sven Peter <sven@fail0verflow.com> for anergistic. 5// Originally written by Sven Peter <sven@fail0verflow.com> for anergistic.
6 6
7#include <algorithm> 7#include <algorithm>
8#include <atomic>
8#include <climits> 9#include <climits>
9#include <csignal> 10#include <csignal>
10#include <cstdarg> 11#include <cstdarg>
@@ -130,7 +131,10 @@ static u16 gdbstub_port = 24689;
130 131
131static bool halt_loop = true; 132static bool halt_loop = true;
132static bool step_loop = false; 133static bool step_loop = false;
133std::atomic<bool> g_server_enabled(false); 134
135// If set to false, the server will never be started and no
136// gdbstub-related functions will be executed.
137static std::atomic<bool> server_enabled(false);
134 138
135#ifdef _WIN32 139#ifdef _WIN32
136WSADATA InitData; 140WSADATA InitData;
@@ -902,7 +906,7 @@ void SetServerPort(u16 port) {
902 906
903void ToggleServer(bool status) { 907void ToggleServer(bool status) {
904 if (status) { 908 if (status) {
905 g_server_enabled = status; 909 server_enabled = status;
906 910
907 // Start server 911 // Start server
908 if (!IsConnected() && Core::g_sys_core != nullptr) { 912 if (!IsConnected() && Core::g_sys_core != nullptr) {
@@ -914,12 +918,12 @@ void ToggleServer(bool status) {
914 Shutdown(); 918 Shutdown();
915 } 919 }
916 920
917 g_server_enabled = status; 921 server_enabled = status;
918 } 922 }
919} 923}
920 924
921static void Init(u16 port) { 925static void Init(u16 port) {
922 if (!g_server_enabled) { 926 if (!server_enabled) {
923 // Set the halt loop to false in case the user enabled the gdbstub mid-execution. 927 // Set the halt loop to false in case the user enabled the gdbstub mid-execution.
924 // This way the CPU can still execute normally. 928 // This way the CPU can still execute normally.
925 halt_loop = false; 929 halt_loop = false;
@@ -998,7 +1002,7 @@ void Init() {
998} 1002}
999 1003
1000void Shutdown() { 1004void Shutdown() {
1001 if (!g_server_enabled) { 1005 if (!server_enabled) {
1002 return; 1006 return;
1003 } 1007 }
1004 1008
@@ -1015,8 +1019,12 @@ void Shutdown() {
1015 LOG_INFO(Debug_GDBStub, "GDB stopped."); 1019 LOG_INFO(Debug_GDBStub, "GDB stopped.");
1016} 1020}
1017 1021
1022bool IsServerEnabled() {
1023 return server_enabled;
1024}
1025
1018bool IsConnected() { 1026bool IsConnected() {
1019 return g_server_enabled && gdbserver_socket != -1; 1027 return IsServerEnabled() && gdbserver_socket != -1;
1020} 1028}
1021 1029
1022bool GetCpuHaltFlag() { 1030bool GetCpuHaltFlag() {