Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9431 from shuffle2/msvc-gdbstub
msbuild: enable USE_GDBSTUB
  • Loading branch information
lioncash committed Jan 10, 2021
2 parents 75e19a0 + f0a6244 commit 59fa613
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 70 deletions.
2 changes: 2 additions & 0 deletions Source/Core/Core/Core.vcxproj
Expand Up @@ -242,6 +242,7 @@
<ClCompile Include="PowerPC\CachedInterpreter\CachedInterpreter.cpp" />
<ClCompile Include="PowerPC\CachedInterpreter\InterpreterBlockCache.cpp" />
<ClCompile Include="PowerPC\ConditionRegister.cpp" />
<ClCompile Include="PowerPC\GDBStub.cpp" />
<ClCompile Include="PowerPC\Interpreter\Interpreter.cpp" />
<ClCompile Include="PowerPC\Interpreter\Interpreter_Branch.cpp" />
<ClCompile Include="PowerPC\Interpreter\Interpreter_FloatingPoint.cpp" />
Expand Down Expand Up @@ -600,6 +601,7 @@
<ClInclude Include="PowerPC\CachedInterpreter\CachedInterpreter.h" />
<ClInclude Include="PowerPC\CachedInterpreter\InterpreterBlockCache.h" />
<ClInclude Include="PowerPC\ConditionRegister.h" />
<ClInclude Include="PowerPC\GDBStub.h" />
<ClInclude Include="PowerPC\Interpreter\ExceptionUtils.h" />
<ClInclude Include="PowerPC\Interpreter\Interpreter.h" />
<ClInclude Include="PowerPC\Interpreter\Interpreter_FPUtils.h" />
Expand Down
6 changes: 6 additions & 0 deletions Source/Core/Core/Core.vcxproj.filters
Expand Up @@ -326,6 +326,9 @@
<ClCompile Include="PowerPC\BreakPoints.cpp">
<Filter>PowerPC</Filter>
</ClCompile>
<ClCompile Include="PowerPC\GDBStub.cpp">
<Filter>PowerPC</Filter>
</ClCompile>
<ClCompile Include="PowerPC\CachedInterpreter\CachedInterpreter.cpp">
<Filter>PowerPC\Cached Interpreter</Filter>
</ClCompile>
Expand Down Expand Up @@ -1390,6 +1393,9 @@
<ClInclude Include="PowerPC\CPUCoreBase.h">
<Filter>PowerPC</Filter>
</ClInclude>
<ClInclude Include="PowerPC\GDBStub.h">
<Filter>PowerPC</Filter>
</ClInclude>
<ClInclude Include="PowerPC\Gekko.h">
<Filter>PowerPC</Filter>
</ClInclude>
Expand Down
156 changes: 87 additions & 69 deletions Source/Core/Core/PowerPC/GDBStub.cpp
Expand Up @@ -5,17 +5,21 @@
// Originally written by Sven Peter <sven@fail0verflow.com> for anergistic.

#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#ifdef _WIN32
#include <WinSock2.h>
#include <iphlpapi.h>
#include <ws2tcpip.h>
typedef SSIZE_T ssize_t;
#define SHUT_RDWR SD_BOTH
#else
#include <netinet/in.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#endif

#include "Common/Logging/Log.h"
Expand Down Expand Up @@ -108,7 +112,7 @@ static u8 gdb_read_byte()
{
u8 c = '+';

const ssize_t res = recv(sock, &c, 1, MSG_WAITALL);
const ssize_t res = recv(sock, (char*)&c, 1, MSG_WAITALL);
if (res != 1)
{
ERROR_LOG_FMT(GDB_STUB, "recv failed : {}", res);
Expand Down Expand Up @@ -319,7 +323,7 @@ static void gdb_reply(const char* reply)

memset(cmd_bfr, 0, sizeof cmd_bfr);

cmd_len = strlen(reply);
cmd_len = (u32)strlen(reply);
if (cmd_len + 4 > sizeof cmd_bfr)
ERROR_LOG_FMT(GDB_STUB, "cmd_bfr overflow in gdb_reply");

Expand All @@ -335,7 +339,7 @@ static void gdb_reply(const char* reply)

DEBUG_LOG_FMT(GDB_STUB, "gdb: reply (len: {}): {}", cmd_len, CommandBufferAsString());

u8* ptr = cmd_bfr;
const char* ptr = (const char*)cmd_bfr;
u32 left = cmd_len + 4;
while (left > 0)
{
Expand Down Expand Up @@ -427,41 +431,46 @@ static void gdb_read_register()
id |= hex2char(cmd_bfr[2]);
}

switch (id)
if (id < 32)
{
case 0 ... 31:
wbe32hex(reply, GPR(id));
break;
case 32 ... 63:
}
else if (id >= 32 && id < 64)
{
wbe64hex(reply, rPS(id - 32).PS0AsU64());
break;
case 64:
wbe32hex(reply, PC);
break;
case 65:
wbe32hex(reply, MSR.Hex);
break;
case 66:
wbe32hex(reply, PowerPC::ppcState.cr.Get());
break;
case 67:
wbe32hex(reply, LR);
break;
case 68:
wbe32hex(reply, CTR);
break;
case 69:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_XER]);
break;
case 70:
wbe32hex(reply, 0x0BADC0DE);
break;
case 71:
wbe32hex(reply, FPSCR.Hex);
break;
default:
return gdb_reply("E01");
break;
}
else
{
switch (id)
{
case 64:
wbe32hex(reply, PC);
break;
case 65:
wbe32hex(reply, MSR.Hex);
break;
case 66:
wbe32hex(reply, PowerPC::ppcState.cr.Get());
break;
case 67:
wbe32hex(reply, LR);
break;
case 68:
wbe32hex(reply, CTR);
break;
case 69:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_XER]);
break;
case 70:
wbe32hex(reply, 0x0BADC0DE);
break;
case 71:
wbe32hex(reply, FPSCR.Hex);
break;
default:
return gdb_reply("E01");
break;
}
}

gdb_reply((char*)reply);
Expand Down Expand Up @@ -512,41 +521,46 @@ static void gdb_write_register()
id |= hex2char(cmd_bfr[2]);
}

switch (id)
if (id < 32)
{
case 0 ... 31:
GPR(id) = re32hex(bufptr);
break;
case 32 ... 63:
}
else if (id >= 32 && id < 64)
{
rPS(id - 32).SetPS0(re64hex(bufptr));
break;
case 64:
PC = re32hex(bufptr);
break;
case 65:
MSR.Hex = re32hex(bufptr);
break;
case 66:
PowerPC::ppcState.cr.Set(re32hex(bufptr));
break;
case 67:
LR = re32hex(bufptr);
break;
case 68:
CTR = re32hex(bufptr);
break;
case 69:
PowerPC::ppcState.spr[SPR_XER] = re32hex(bufptr);
break;
case 70:
// do nothing, we dont have MQ
break;
case 71:
FPSCR.Hex = re32hex(bufptr);
break;
default:
return gdb_reply("E01");
break;
}
else
{
switch (id)
{
case 64:
PC = re32hex(bufptr);
break;
case 65:
MSR.Hex = re32hex(bufptr);
break;
case 66:
PowerPC::ppcState.cr.Set(re32hex(bufptr));
break;
case 67:
LR = re32hex(bufptr);
break;
case 68:
CTR = re32hex(bufptr);
break;
case 69:
PowerPC::ppcState.spr[SPR_XER] = re32hex(bufptr);
break;
case 70:
// do nothing, we dont have MQ
break;
case 71:
FPSCR.Hex = re32hex(bufptr);
break;
default:
return gdb_reply("E01");
break;
}
}

gdb_reply("OK");
Expand Down Expand Up @@ -833,7 +847,7 @@ static void gdb_init_generic(int domain, const sockaddr* server_addr, socklen_t
ERROR_LOG_FMT(GDB_STUB, "Failed to create gdb socket");

int on = 1;
if (setsockopt(tmpsock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof on) < 0)
if (setsockopt(tmpsock, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof on) < 0)
ERROR_LOG_FMT(GDB_STUB, "Failed to setsockopt");

if (bind(tmpsock, server_addr, server_addrlen) < 0)
Expand All @@ -849,7 +863,11 @@ static void gdb_init_generic(int domain, const sockaddr* server_addr, socklen_t
ERROR_LOG_FMT(GDB_STUB, "Failed to accept gdb client");
INFO_LOG_FMT(GDB_STUB, "Client connected.");

#ifdef _WIN32
closesocket(tmpsock);
#else
close(tmpsock);
#endif
tmpsock = -1;
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/PowerPC/GDBStub.h
Expand Up @@ -8,7 +8,7 @@

#include "Common/CommonTypes.h"

#if defined(_WIN32) || !defined(MSG_WAITALL)
#ifndef MSG_WAITALL
#define MSG_WAITALL (8)
#endif

Expand Down
1 change: 1 addition & 0 deletions Source/VSProps/Base.props
Expand Up @@ -69,6 +69,7 @@
<PreprocessorDefinitions Condition="'$(Platform)'=='x64'">_ARCH_64=1;_M_X86=1;_M_X86_64=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Platform)'=='ARM64'">_ARCH_64=1;_M_ARM_64=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Platform)'=='x64'">HAVE_FFMPEG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>USE_GDBSTUB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<!--
Make sure we include a clean version of windows.h.
-->
Expand Down

0 comments on commit 59fa613

Please sign in to comment.