summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/arm/dyncom/arm_dyncom_interpreter.cpp4
-rw-r--r--src/core/arm/skyeye_common/armstate.cpp2
-rw-r--r--src/core/core.cpp2
-rw-r--r--src/core/gdbstub/gdbstub.cpp20
-rw-r--r--src/core/gdbstub/gdbstub.h11
5 files changed, 23 insertions, 16 deletions
diff --git a/src/core/arm/dyncom/arm_dyncom_interpreter.cpp b/src/core/arm/dyncom/arm_dyncom_interpreter.cpp
index 7b8616702..67c45640a 100644
--- a/src/core/arm/dyncom/arm_dyncom_interpreter.cpp
+++ b/src/core/arm/dyncom/arm_dyncom_interpreter.cpp
@@ -953,7 +953,7 @@ unsigned InterpreterMainLoop(ARMul_State* cpu) {
953#define GDB_BP_CHECK \ 953#define GDB_BP_CHECK \
954 cpu->Cpsr &= ~(1 << 5); \ 954 cpu->Cpsr &= ~(1 << 5); \
955 cpu->Cpsr |= cpu->TFlag << 5; \ 955 cpu->Cpsr |= cpu->TFlag << 5; \
956 if (GDBStub::g_server_enabled) { \ 956 if (GDBStub::IsServerEnabled()) { \
957 if (GDBStub::IsMemoryBreak() || (breakpoint_data.type != GDBStub::BreakpointType::None && \ 957 if (GDBStub::IsMemoryBreak() || (breakpoint_data.type != GDBStub::BreakpointType::None && \
958 PC == breakpoint_data.address)) { \ 958 PC == breakpoint_data.address)) { \
959 GDBStub::Break(); \ 959 GDBStub::Break(); \
@@ -1649,7 +1649,7 @@ DISPATCH : {
1649 } 1649 }
1650 1650
1651 // Find breakpoint if one exists within the block 1651 // Find breakpoint if one exists within the block
1652 if (GDBStub::g_server_enabled && GDBStub::IsConnected()) { 1652 if (GDBStub::IsConnected()) {
1653 breakpoint_data = 1653 breakpoint_data =
1654 GDBStub::GetNextBreakpointFromAddress(cpu->Reg[15], GDBStub::BreakpointType::Execute); 1654 GDBStub::GetNextBreakpointFromAddress(cpu->Reg[15], GDBStub::BreakpointType::Execute);
1655 } 1655 }
diff --git a/src/core/arm/skyeye_common/armstate.cpp b/src/core/arm/skyeye_common/armstate.cpp
index 1465b074e..c36b0208f 100644
--- a/src/core/arm/skyeye_common/armstate.cpp
+++ b/src/core/arm/skyeye_common/armstate.cpp
@@ -182,7 +182,7 @@ void ARMul_State::ResetMPCoreCP15Registers() {
182} 182}
183 183
184static void CheckMemoryBreakpoint(u32 address, GDBStub::BreakpointType type) { 184static void CheckMemoryBreakpoint(u32 address, GDBStub::BreakpointType type) {
185 if (GDBStub::g_server_enabled && GDBStub::CheckBreakpoint(address, type)) { 185 if (GDBStub::IsServerEnabled() && GDBStub::CheckBreakpoint(address, type)) {
186 LOG_DEBUG(Debug, "Found memory breakpoint @ %08x", address); 186 LOG_DEBUG(Debug, "Found memory breakpoint @ %08x", address);
187 GDBStub::Break(true); 187 GDBStub::Break(true);
188 } 188 }
diff --git a/src/core/core.cpp b/src/core/core.cpp
index 49ac8be6e..6efa18159 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -22,7 +22,7 @@ std::unique_ptr<ARM_Interface> g_sys_core; ///< ARM11 system (OS) core
22 22
23/// Run the core CPU loop 23/// Run the core CPU loop
24void RunLoop(int tight_loop) { 24void RunLoop(int tight_loop) {
25 if (GDBStub::g_server_enabled) { 25 if (GDBStub::IsServerEnabled()) {
26 GDBStub::HandlePacket(); 26 GDBStub::HandlePacket();
27 27
28 // If the loop is halted and we want to step, use a tiny (1) number of instructions to 28 // If the loop is halted and we want to step, use a tiny (1) number of instructions to
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