summaryrefslogtreecommitdiff
path: root/src/core/gdbstub
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/gdbstub')
-rw-r--r--src/core/gdbstub/gdbstub.cpp20
-rw-r--r--src/core/gdbstub/gdbstub.h11
2 files changed, 19 insertions, 12 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() {
diff --git a/src/core/gdbstub/gdbstub.h b/src/core/gdbstub/gdbstub.h
index a7483bb10..38177e32c 100644
--- a/src/core/gdbstub/gdbstub.h
+++ b/src/core/gdbstub/gdbstub.h
@@ -5,7 +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#pragma once 7#pragma once
8#include <atomic> 8
9#include "common/common_types.h" 9#include "common/common_types.h"
10 10
11namespace GDBStub { 11namespace GDBStub {
@@ -24,10 +24,6 @@ struct BreakpointAddress {
24 BreakpointType type; 24 BreakpointType type;
25}; 25};
26 26
27/// If set to false, the server will never be started and no gdbstub-related functions will be
28/// executed.
29extern std::atomic<bool> g_server_enabled;
30
31/** 27/**
32 * Set the port the gdbstub should use to listen for connections. 28 * Set the port the gdbstub should use to listen for connections.
33 * 29 *
@@ -36,7 +32,7 @@ extern std::atomic<bool> g_server_enabled;
36void SetServerPort(u16 port); 32void SetServerPort(u16 port);
37 33
38/** 34/**
39 * Set the g_server_enabled flag and start or stop the server if possible. 35 * Starts or stops the server if possible.
40 * 36 *
41 * @param status Set the server to enabled or disabled. 37 * @param status Set the server to enabled or disabled.
42 */ 38 */
@@ -48,6 +44,9 @@ void Init();
48/// Stop gdbstub server. 44/// Stop gdbstub server.
49void Shutdown(); 45void Shutdown();
50 46
47/// Checks if the gdbstub server is enabled.
48bool IsServerEnabled();
49
51/// Returns true if there is an active socket connection. 50/// Returns true if there is an active socket connection.
52bool IsConnected(); 51bool IsConnected();
53 52