forked from suyu/suyu
Merge pull request #2332 from lioncash/gdb
gdbstub: Remove global variable from public interface
This commit is contained in:
commit
7524a55133
5 changed files with 23 additions and 16 deletions
|
@ -953,7 +953,7 @@ unsigned InterpreterMainLoop(ARMul_State* cpu) {
|
||||||
#define GDB_BP_CHECK \
|
#define GDB_BP_CHECK \
|
||||||
cpu->Cpsr &= ~(1 << 5); \
|
cpu->Cpsr &= ~(1 << 5); \
|
||||||
cpu->Cpsr |= cpu->TFlag << 5; \
|
cpu->Cpsr |= cpu->TFlag << 5; \
|
||||||
if (GDBStub::g_server_enabled) { \
|
if (GDBStub::IsServerEnabled()) { \
|
||||||
if (GDBStub::IsMemoryBreak() || (breakpoint_data.type != GDBStub::BreakpointType::None && \
|
if (GDBStub::IsMemoryBreak() || (breakpoint_data.type != GDBStub::BreakpointType::None && \
|
||||||
PC == breakpoint_data.address)) { \
|
PC == breakpoint_data.address)) { \
|
||||||
GDBStub::Break(); \
|
GDBStub::Break(); \
|
||||||
|
@ -1649,7 +1649,7 @@ DISPATCH : {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find breakpoint if one exists within the block
|
// Find breakpoint if one exists within the block
|
||||||
if (GDBStub::g_server_enabled && GDBStub::IsConnected()) {
|
if (GDBStub::IsConnected()) {
|
||||||
breakpoint_data =
|
breakpoint_data =
|
||||||
GDBStub::GetNextBreakpointFromAddress(cpu->Reg[15], GDBStub::BreakpointType::Execute);
|
GDBStub::GetNextBreakpointFromAddress(cpu->Reg[15], GDBStub::BreakpointType::Execute);
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,7 +182,7 @@ void ARMul_State::ResetMPCoreCP15Registers() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CheckMemoryBreakpoint(u32 address, GDBStub::BreakpointType type) {
|
static void CheckMemoryBreakpoint(u32 address, GDBStub::BreakpointType type) {
|
||||||
if (GDBStub::g_server_enabled && GDBStub::CheckBreakpoint(address, type)) {
|
if (GDBStub::IsServerEnabled() && GDBStub::CheckBreakpoint(address, type)) {
|
||||||
LOG_DEBUG(Debug, "Found memory breakpoint @ %08x", address);
|
LOG_DEBUG(Debug, "Found memory breakpoint @ %08x", address);
|
||||||
GDBStub::Break(true);
|
GDBStub::Break(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ std::unique_ptr<ARM_Interface> g_sys_core; ///< ARM11 system (OS) core
|
||||||
|
|
||||||
/// Run the core CPU loop
|
/// Run the core CPU loop
|
||||||
void RunLoop(int tight_loop) {
|
void RunLoop(int tight_loop) {
|
||||||
if (GDBStub::g_server_enabled) {
|
if (GDBStub::IsServerEnabled()) {
|
||||||
GDBStub::HandlePacket();
|
GDBStub::HandlePacket();
|
||||||
|
|
||||||
// If the loop is halted and we want to step, use a tiny (1) number of instructions to
|
// If the loop is halted and we want to step, use a tiny (1) number of instructions to
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
// Originally written by Sven Peter <sven@fail0verflow.com> for anergistic.
|
// Originally written by Sven Peter <sven@fail0verflow.com> for anergistic.
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <atomic>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <cstdarg>
|
#include <cstdarg>
|
||||||
|
@ -130,7 +131,10 @@ static u16 gdbstub_port = 24689;
|
||||||
|
|
||||||
static bool halt_loop = true;
|
static bool halt_loop = true;
|
||||||
static bool step_loop = false;
|
static bool step_loop = false;
|
||||||
std::atomic<bool> g_server_enabled(false);
|
|
||||||
|
// If set to false, the server will never be started and no
|
||||||
|
// gdbstub-related functions will be executed.
|
||||||
|
static std::atomic<bool> server_enabled(false);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WSADATA InitData;
|
WSADATA InitData;
|
||||||
|
@ -902,7 +906,7 @@ void SetServerPort(u16 port) {
|
||||||
|
|
||||||
void ToggleServer(bool status) {
|
void ToggleServer(bool status) {
|
||||||
if (status) {
|
if (status) {
|
||||||
g_server_enabled = status;
|
server_enabled = status;
|
||||||
|
|
||||||
// Start server
|
// Start server
|
||||||
if (!IsConnected() && Core::g_sys_core != nullptr) {
|
if (!IsConnected() && Core::g_sys_core != nullptr) {
|
||||||
|
@ -914,12 +918,12 @@ void ToggleServer(bool status) {
|
||||||
Shutdown();
|
Shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
g_server_enabled = status;
|
server_enabled = status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Init(u16 port) {
|
static void Init(u16 port) {
|
||||||
if (!g_server_enabled) {
|
if (!server_enabled) {
|
||||||
// Set the halt loop to false in case the user enabled the gdbstub mid-execution.
|
// Set the halt loop to false in case the user enabled the gdbstub mid-execution.
|
||||||
// This way the CPU can still execute normally.
|
// This way the CPU can still execute normally.
|
||||||
halt_loop = false;
|
halt_loop = false;
|
||||||
|
@ -998,7 +1002,7 @@ void Init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shutdown() {
|
void Shutdown() {
|
||||||
if (!g_server_enabled) {
|
if (!server_enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1015,8 +1019,12 @@ void Shutdown() {
|
||||||
LOG_INFO(Debug_GDBStub, "GDB stopped.");
|
LOG_INFO(Debug_GDBStub, "GDB stopped.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsServerEnabled() {
|
||||||
|
return server_enabled;
|
||||||
|
}
|
||||||
|
|
||||||
bool IsConnected() {
|
bool IsConnected() {
|
||||||
return g_server_enabled && gdbserver_socket != -1;
|
return IsServerEnabled() && gdbserver_socket != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetCpuHaltFlag() {
|
bool GetCpuHaltFlag() {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
// Originally written by Sven Peter <sven@fail0verflow.com> for anergistic.
|
// Originally written by Sven Peter <sven@fail0verflow.com> for anergistic.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <atomic>
|
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
|
|
||||||
namespace GDBStub {
|
namespace GDBStub {
|
||||||
|
@ -24,10 +24,6 @@ struct BreakpointAddress {
|
||||||
BreakpointType type;
|
BreakpointType type;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// If set to false, the server will never be started and no gdbstub-related functions will be
|
|
||||||
/// executed.
|
|
||||||
extern std::atomic<bool> g_server_enabled;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the port the gdbstub should use to listen for connections.
|
* Set the port the gdbstub should use to listen for connections.
|
||||||
*
|
*
|
||||||
|
@ -36,7 +32,7 @@ extern std::atomic<bool> g_server_enabled;
|
||||||
void SetServerPort(u16 port);
|
void SetServerPort(u16 port);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the g_server_enabled flag and start or stop the server if possible.
|
* Starts or stops the server if possible.
|
||||||
*
|
*
|
||||||
* @param status Set the server to enabled or disabled.
|
* @param status Set the server to enabled or disabled.
|
||||||
*/
|
*/
|
||||||
|
@ -48,6 +44,9 @@ void Init();
|
||||||
/// Stop gdbstub server.
|
/// Stop gdbstub server.
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
||||||
|
/// Checks if the gdbstub server is enabled.
|
||||||
|
bool IsServerEnabled();
|
||||||
|
|
||||||
/// Returns true if there is an active socket connection.
|
/// Returns true if there is an active socket connection.
|
||||||
bool IsConnected();
|
bool IsConnected();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue