Fix four WebSocket debugger bugs found while stress testing

memory.readString could kill the connection: it copied raw emulated memory
straight into a JSON string, so any address not holding valid UTF-8 produced an
invalid WebSocket text frame.

hle.data.remove wiped the name of a function sharing the address. Labels are
shared between data and function symbols, so removing the data label left the
function showing up in hle.func.list with an empty name.

hle.data.add silently did nothing outside a loaded module. GetModuleIndex()
returns -1 for e.g. a heap or stack address, and symbols under that index never
reach the active maps - so the add reported success while the symbol was
invisible to list, and rename/remove then failed with "No data symbol found".
Falls back to module index 0 ("no module, absolute address"), which is the right
answer for a label the user put somewhere after a memory.search.

hle.thread.list reported the thread's stack base address in a field called
initialStackSize. Renamed to initialStack, matching the SceKernelThreadInfo
field it comes from.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GZq8ZtJmFY7bkX5FVkr3P9
This commit is contained in:
Henrik RydgårdandClaude Opus 5 committed 2026-08-17 00:25:39 +02:00
1 parent 0e15445b54
commit 6a05ef290d
5 files changed
+146 -7

No files matched your search

+8 -2
View File
@@ -19,6 +19,7 @@
#include <cstring>
#include <mutex>
#include "Common/Data/Encoding/Base64.h"
#include "Common/Data/Encoding/Utf8.h"
#include "Common/StringUtils.h"
#include "Core/Core.h"
#include "Core/Debugger/WebSocket/MemorySubscriber.h"
@@ -249,7 +250,9 @@ void WebSocketMemoryRead(DebuggerRequest &req) {
// - type: optional, 'utf-8' (default) or 'base64'.
//
// Response (same event name) for 'utf8':
// - value: string value read.
// - value: string value read. Since this reads arbitrary emulated memory, which is under no
// obligation to hold text at all, any byte sequence that isn't valid UTF-8 is replaced with
// U+FFFD. Use 'base64' if you need the bytes exactly as they are.
//
// Response (same event name) for 'base64':
// - base64: base64 encode of binary data, not including NUL.
@@ -287,7 +290,10 @@ void WebSocketMemoryReadString(DebuggerRequest &req) {
JsonWriter &json = req.Respond();
if (type == "utf-8") {
json.writeString("value", raw);
// Must not go out raw: WebSocket text frames are required to be valid UTF-8, so a stray
// byte from some non-text address would make a conforming client (browsers included) drop
// the connection - taking down the whole debugger session over one bad read.
json.writeString("value", ReplaceInvalidUTF8(raw));
} else if (type == "base64") {
json.writeString("base64", Base64Encode((const uint8_t *)raw.data(), raw.size()));
}