From acdaaae7a4b0af0efe93eb6f3760b2cd85fe6a5f Mon Sep 17 00:00:00 2001 From: Nemoumbra Date: Wed, 12 Oct 2022 11:55:01 +0300 Subject: [PATCH 1/4] Added optional parameter to hle.func.scan, improved code of hle.func.removeRange --- Core/Debugger/WebSocket/HLESubscriber.cpp | 92 ++++++++++++++++------- 1 file changed, 66 insertions(+), 26 deletions(-) diff --git a/Core/Debugger/WebSocket/HLESubscriber.cpp b/Core/Debugger/WebSocket/HLESubscriber.cpp index 2a90ca619d..50ef77163d 100644 --- a/Core/Debugger/WebSocket/HLESubscriber.cpp +++ b/Core/Debugger/WebSocket/HLESubscriber.cpp @@ -362,6 +362,41 @@ void WebSocketHLEFuncRemove(DebuggerRequest &req) { json.writeUint("size", funcSize); } +static u32 RemoveFuncSymbolsInRange(u32 addr, u32 size) { + // Note: this makes no checks whether the range is valid + + u32 func_address = g_symbolMap->GetFunctionStart(addr); + if (func_address == SymbolMap::INVALID_ADDRESS) { + func_address = g_symbolMap->GetNextSymbolAddress(addr, SymbolType::ST_FUNCTION); + } + + u32 counter = 0; + while (func_address < addr + size && func_address != SymbolMap::INVALID_ADDRESS) { + g_symbolMap->RemoveFunction(func_address, true); + ++counter; + func_address = g_symbolMap->GetNextSymbolAddress(addr, SymbolType::ST_FUNCTION); + } + + if (counter) { + MIPSAnalyst::ForgetFunctions(addr, addr + size - 1); + + // The following was copied from hle.func.remove: + g_symbolMap->SortSymbols(); + + MIPSAnalyst::UpdateHashMap(); + MIPSAnalyst::ApplyHashMap(); + + if (g_Config.bFuncReplacements) { + MIPSAnalyst::ReplaceFunctions(); + } + + // Clear cache for branch lines and such. + DisassemblyManager manager; + manager.clear(); + } + return counter; +} + // Remove function symbols in range (hle.func.removeRange) // // Parameters: @@ -386,34 +421,10 @@ void WebSocketHLEFuncRemoveRange(DebuggerRequest &req) { if (!Memory::IsValidRange(addr, size)) return req.Fail("Address or size outside valid memory"); - u32 first_address = g_symbolMap->GetFunctionStart(addr); - if (first_address == SymbolMap::INVALID_ADDRESS) { - first_address = g_symbolMap->GetNextSymbolAddress(addr, SymbolType::ST_FUNCTION); - } - - u32 counter = 0; - for (u32 current_addr = first_address; (current_addr < addr + size) && current_addr != SymbolMap::INVALID_ADDRESS; current_addr = g_symbolMap->GetNextSymbolAddress(addr, SymbolType::ST_FUNCTION)) { - g_symbolMap->RemoveFunction(current_addr, true); - ++counter; - } - MIPSAnalyst::ForgetFunctions(addr, addr + size - 1); - - // The following was copied from hle.func.remove: - g_symbolMap->SortSymbols(); - - MIPSAnalyst::UpdateHashMap(); - MIPSAnalyst::ApplyHashMap(); - - if (g_Config.bFuncReplacements) { - MIPSAnalyst::ReplaceFunctions(); - } - - // Clear cache for branch lines and such. - DisassemblyManager manager; - manager.clear(); + u32 count = RemoveFuncSymbolsInRange(addr, size); JsonWriter &json = req.Respond(); - json.writeUint("count", counter); + json.writeUint("count", count); } // Rename a function symbol (hle.func.rename) @@ -480,9 +491,38 @@ void WebSocketHLEFuncScan(DebuggerRequest &req) { if (!req.ParamU32("size", &size)) return; + bool has_recreate = req.HasParam("recreate"); + bool recreate; + if (has_recreate) { + if (!req.ParamBool("recreate", &recreate)) { + return; + } + } + if (!Memory::IsValidRange(addr, size)) return req.Fail("Address or size outside valid memory"); + if (recreate) { + // let's see if the last function is partially inside our range + + u32 last_func_start = g_symbolMap->GetFunctionStart(addr + size - 1); + if (last_func_start != SymbolMap::INVALID_ADDRESS) { + // there is a function + // u32 end = last_func_start + g_symbolMap->GetFunctionSize(last_func_start); + if (last_func_start + g_symbolMap->GetFunctionSize(last_func_start) != addr + size) { + size = last_func_start - addr; + } + } + // let's see if the first function is partially inside our range + u32 start = g_symbolMap->GetFunctionStart(addr); + + if (start != SymbolMap::INVALID_ADDRESS && start != addr) { + // skip to a byte after end + addr = start + g_symbolMap->GetFunctionSize(start); + } + RemoveFuncSymbolsInRange(addr, size); + } + bool insertSymbols = MIPSAnalyst::ScanForFunctions(addr, addr + size - 1, true); MIPSAnalyst::FinalizeScan(insertSymbols); From a772e87072731376340c841120090b1f619be642 Mon Sep 17 00:00:00 2001 From: Nemoumbra Date: Wed, 12 Oct 2022 12:09:05 +0300 Subject: [PATCH 2/4] Comments updated, default value for parameter "recreate" set to false --- Core/Debugger/WebSocket/HLESubscriber.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Core/Debugger/WebSocket/HLESubscriber.cpp b/Core/Debugger/WebSocket/HLESubscriber.cpp index 50ef77163d..8c8bfe50dd 100644 --- a/Core/Debugger/WebSocket/HLESubscriber.cpp +++ b/Core/Debugger/WebSocket/HLESubscriber.cpp @@ -476,6 +476,7 @@ void WebSocketHLEFuncRename(DebuggerRequest &req) { // Parameters: // - address: unsigned integer address for the start of the range. // - size: unsigned integer size in bytes for scan. +// - recreate: optional bool indicating whether functions that lie inside the range must be removed before scanning // // Response (same event name) with no extra data. void WebSocketHLEFuncScan(DebuggerRequest &req) { @@ -492,7 +493,7 @@ void WebSocketHLEFuncScan(DebuggerRequest &req) { return; bool has_recreate = req.HasParam("recreate"); - bool recreate; + bool recreate = false; if (has_recreate) { if (!req.ParamBool("recreate", &recreate)) { return; @@ -510,7 +511,7 @@ void WebSocketHLEFuncScan(DebuggerRequest &req) { // there is a function // u32 end = last_func_start + g_symbolMap->GetFunctionSize(last_func_start); if (last_func_start + g_symbolMap->GetFunctionSize(last_func_start) != addr + size) { - size = last_func_start - addr; + size = last_func_start - addr; // decrease the size parameter } } // let's see if the first function is partially inside our range From 4a967966ef6f09b4d1e9fb3c74c06d919d7f08fd Mon Sep 17 00:00:00 2001 From: Nemoumbra Date: Sat, 15 Oct 2022 16:01:12 +0300 Subject: [PATCH 3/4] Removed the bugged part of hle.func.scan + new comments --- Core/Debugger/WebSocket/HLESubscriber.cpp | 41 +++++++++++++---------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/Core/Debugger/WebSocket/HLESubscriber.cpp b/Core/Debugger/WebSocket/HLESubscriber.cpp index 8c8bfe50dd..09b67624d1 100644 --- a/Core/Debugger/WebSocket/HLESubscriber.cpp +++ b/Core/Debugger/WebSocket/HLESubscriber.cpp @@ -362,9 +362,10 @@ void WebSocketHLEFuncRemove(DebuggerRequest &req) { json.writeUint("size", funcSize); } +// This function removes function symbols that intersect or lie inside the range +// (Note: this makes no checks whether the range is valid) +// Returns the number of removed functions static u32 RemoveFuncSymbolsInRange(u32 addr, u32 size) { - // Note: this makes no checks whether the range is valid - u32 func_address = g_symbolMap->GetFunctionStart(addr); if (func_address == SymbolMap::INVALID_ADDRESS) { func_address = g_symbolMap->GetNextSymbolAddress(addr, SymbolType::ST_FUNCTION); @@ -476,7 +477,7 @@ void WebSocketHLEFuncRename(DebuggerRequest &req) { // Parameters: // - address: unsigned integer address for the start of the range. // - size: unsigned integer size in bytes for scan. -// - recreate: optional bool indicating whether functions that lie inside the range must be removed before scanning +// - recreate: optional bool indicating whether functions that intersect or inside lie inside the range must be removed before scanning // // Response (same event name) with no extra data. void WebSocketHLEFuncScan(DebuggerRequest &req) { @@ -504,23 +505,27 @@ void WebSocketHLEFuncScan(DebuggerRequest &req) { return req.Fail("Address or size outside valid memory"); if (recreate) { - // let's see if the last function is partially inside our range + // The following code doesn't do what I wanted it to do AND it's debatable whether it's needed at all + // In short, I wanted to shift the start and the end of the range before removal - u32 last_func_start = g_symbolMap->GetFunctionStart(addr + size - 1); - if (last_func_start != SymbolMap::INVALID_ADDRESS) { - // there is a function - // u32 end = last_func_start + g_symbolMap->GetFunctionSize(last_func_start); - if (last_func_start + g_symbolMap->GetFunctionSize(last_func_start) != addr + size) { - size = last_func_start - addr; // decrease the size parameter - } - } - // let's see if the first function is partially inside our range - u32 start = g_symbolMap->GetFunctionStart(addr); + //// let's see if the last function is partially inside our range + + //u32 last_func_start = g_symbolMap->GetFunctionStart(addr + size - 1); + //if (last_func_start != SymbolMap::INVALID_ADDRESS) { + // // there is a function + // // u32 end = last_func_start + g_symbolMap->GetFunctionSize(last_func_start); + // if (last_func_start + g_symbolMap->GetFunctionSize(last_func_start) != addr + size) { + // size = last_func_start - addr; // decrease the size parameter + // } + //} + //// let's see if the first function is partially inside our range + //u32 start = g_symbolMap->GetFunctionStart(addr); + + //if (start != SymbolMap::INVALID_ADDRESS && start != addr) { + // // skip to a byte after end + // addr = start + g_symbolMap->GetFunctionSize(start); + //} - if (start != SymbolMap::INVALID_ADDRESS && start != addr) { - // skip to a byte after end - addr = start + g_symbolMap->GetFunctionSize(start); - } RemoveFuncSymbolsInRange(addr, size); } From 73e5791b08723780fa38991a53027152b4871453 Mon Sep 17 00:00:00 2001 From: Nemoumbra Date: Sun, 16 Oct 2022 14:43:56 +0300 Subject: [PATCH 4/4] Code cleanup, optional param renamed: "recreate" -> "remove" --- Core/Debugger/WebSocket/HLESubscriber.cpp | 35 ++++------------------- 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/Core/Debugger/WebSocket/HLESubscriber.cpp b/Core/Debugger/WebSocket/HLESubscriber.cpp index 09b67624d1..0efe01b222 100644 --- a/Core/Debugger/WebSocket/HLESubscriber.cpp +++ b/Core/Debugger/WebSocket/HLESubscriber.cpp @@ -477,7 +477,7 @@ void WebSocketHLEFuncRename(DebuggerRequest &req) { // Parameters: // - address: unsigned integer address for the start of the range. // - size: unsigned integer size in bytes for scan. -// - recreate: optional bool indicating whether functions that intersect or inside lie inside the range must be removed before scanning +// - remove: optional bool indicating whether functions that intersect or inside lie inside the range must be removed before scanning // // Response (same event name) with no extra data. void WebSocketHLEFuncScan(DebuggerRequest &req) { @@ -493,39 +493,14 @@ void WebSocketHLEFuncScan(DebuggerRequest &req) { if (!req.ParamU32("size", &size)) return; - bool has_recreate = req.HasParam("recreate"); - bool recreate = false; - if (has_recreate) { - if (!req.ParamBool("recreate", &recreate)) { - return; - } - } + bool remove = false; + if (!req.ParamBool("remove", &remove, DebuggerParamType::OPTIONAL)) + return; if (!Memory::IsValidRange(addr, size)) return req.Fail("Address or size outside valid memory"); - if (recreate) { - // The following code doesn't do what I wanted it to do AND it's debatable whether it's needed at all - // In short, I wanted to shift the start and the end of the range before removal - - //// let's see if the last function is partially inside our range - - //u32 last_func_start = g_symbolMap->GetFunctionStart(addr + size - 1); - //if (last_func_start != SymbolMap::INVALID_ADDRESS) { - // // there is a function - // // u32 end = last_func_start + g_symbolMap->GetFunctionSize(last_func_start); - // if (last_func_start + g_symbolMap->GetFunctionSize(last_func_start) != addr + size) { - // size = last_func_start - addr; // decrease the size parameter - // } - //} - //// let's see if the first function is partially inside our range - //u32 start = g_symbolMap->GetFunctionStart(addr); - - //if (start != SymbolMap::INVALID_ADDRESS && start != addr) { - // // skip to a byte after end - // addr = start + g_symbolMap->GetFunctionSize(start); - //} - + if (remove) { RemoveFuncSymbolsInRange(addr, size); }