From 0c165c3f627d06fd6908444935204776fe07dd8c Mon Sep 17 00:00:00 2001 From: Coxxs <58-coxxs@users.noreply.git.ryujinx.app> Date: Wed, 22 Oct 2025 16:20:13 -0500 Subject: [PATCH] Move ProcessInfo and Minidump to HleProcessDebugger (ryubing/ryujinx!187) See merge request ryubing/ryujinx!187 --- src/Ryujinx.HLE/Debugger/Debugger.Rcmd.cs | 64 ++-------- .../HOS/Kernel/Process/HleProcessDebugger.cs | 110 ++++++++++++++++++ 2 files changed, 120 insertions(+), 54 deletions(-) diff --git a/src/Ryujinx.HLE/Debugger/Debugger.Rcmd.cs b/src/Ryujinx.HLE/Debugger/Debugger.Rcmd.cs index f63817ef3..1cf86b153 100644 --- a/src/Ryujinx.HLE/Debugger/Debugger.Rcmd.cs +++ b/src/Ryujinx.HLE/Debugger/Debugger.Rcmd.cs @@ -62,38 +62,16 @@ namespace Ryujinx.HLE.Debugger public string GetMinidump() { - StringBuilder response = new(); - response.AppendLine("=== Begin Minidump ===\n"); - response.AppendLine(GetProcessInfo()); + if (Process is not { } kProcess) + return "No application process found\n"; - foreach (KThread thread in GetThreads()) - { - response.AppendLine($"=== Thread {thread.ThreadUid} ==="); - try - { - string stackTrace = Process.Debugger.GetGuestStackTrace(thread); - response.AppendLine(stackTrace); - } - catch (Exception e) - { - response.AppendLine($"[Error getting stack trace: {e.Message}]"); - } + if (kProcess.Debugger is not { } debugger) + return $"Error getting minidump: debugger is null\n"; - try - { - string registers = Process.Debugger.GetCpuRegisterPrintout(thread); - response.AppendLine(registers); - } - catch (Exception e) - { - response.AppendLine($"[Error getting registers: {e.Message}]"); - } - } + var response = debugger.GetMinidump(); - response.AppendLine("=== End Minidump ==="); - - Logger.Info?.Print(LogClass.GdbStub, response.ToString()); - return response.ToString(); + Logger.Info?.Print(LogClass.GdbStub, response); + return response; } public string GetProcessInfo() @@ -103,32 +81,10 @@ namespace Ryujinx.HLE.Debugger if (Process is not { } kProcess) return "No application process found\n"; - StringBuilder sb = new(); + if (kProcess.Debugger is not { } debugger) + return $"Error getting process info: debugger is null\n"; - sb.AppendLine($"Program Id: 0x{kProcess.TitleId:x16}"); - sb.AppendLine($"Application: {(kProcess.IsApplication ? 1 : 0)}"); - sb.AppendLine("Layout:"); - sb.AppendLine( - $" Alias: 0x{kProcess.MemoryManager.AliasRegionStart:x10} - 0x{kProcess.MemoryManager.AliasRegionEnd - 1:x10}"); - sb.AppendLine( - $" Heap: 0x{kProcess.MemoryManager.HeapRegionStart:x10} - 0x{kProcess.MemoryManager.HeapRegionEnd - 1:x10}"); - sb.AppendLine( - $" Aslr: 0x{kProcess.MemoryManager.AslrRegionStart:x10} - 0x{kProcess.MemoryManager.AslrRegionEnd - 1:x10}"); - sb.AppendLine( - $" Stack: 0x{kProcess.MemoryManager.StackRegionStart:x10} - 0x{kProcess.MemoryManager.StackRegionEnd - 1:x10}"); - - sb.AppendLine("Modules:"); - HleProcessDebugger debugger = kProcess.Debugger; - if (debugger != null) - { - foreach (HleProcessDebugger.Image image in debugger.GetLoadedImages()) - { - ulong endAddress = image.BaseAddress + image.Size - 1; - sb.AppendLine($" 0x{image.BaseAddress:x10} - 0x{endAddress:x10} {image.Name}"); - } - } - - return sb.ToString(); + return debugger.GetProcessInfoPrintout(); } catch (Exception e) { diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/HleProcessDebugger.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/HleProcessDebugger.cs index 2e14f2a40..71ee7a086 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/HleProcessDebugger.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/HleProcessDebugger.cs @@ -161,6 +161,116 @@ namespace Ryujinx.HLE.HOS.Kernel.Process return sb.ToString(); } + public string GetProcessInfoPrintout() + { + StringBuilder sb = new(); + + sb.AppendLine($"Process: {_owner.Name}, PID: {_owner.Pid}"); + sb.AppendLine($"Program Id: 0x{_owner.TitleId:x16}"); + sb.AppendLine($"Application: {(_owner.IsApplication ? 1 : 0)}"); + + sb.AppendLine("Layout:"); + sb.AppendLine( + $" Alias: 0x{_owner.MemoryManager.AliasRegionStart:x10} - 0x{_owner.MemoryManager.AliasRegionEnd - 1:x10}"); + sb.AppendLine( + $" Heap: 0x{_owner.MemoryManager.HeapRegionStart:x10} - 0x{_owner.MemoryManager.HeapRegionEnd - 1:x10}"); + sb.AppendLine( + $" Aslr: 0x{_owner.MemoryManager.AslrRegionStart:x10} - 0x{_owner.MemoryManager.AslrRegionEnd - 1:x10}"); + sb.AppendLine( + $" Stack: 0x{_owner.MemoryManager.StackRegionStart:x10} - 0x{_owner.MemoryManager.StackRegionEnd - 1:x10}"); + + sb.AppendLine("Modules:"); + + foreach (Image image in GetLoadedImages()) + { + ulong endAddress = image.BaseAddress + image.Size - 1; + sb.AppendLine($" 0x{image.BaseAddress:x10} - 0x{endAddress:x10} {image.Name}"); + } + + return sb.ToString(); + } + + public string GetMinidump() + { + var result = new StringBuilder(); + + result.AppendLine("=== Begin Minidump ===\n"); + try + { + result.AppendLine(GetProcessInfoPrintout()); + } + catch (Exception e) + { + result.AppendLine($"[Error getting process info: {e.Message}]"); + } + + var debugInterface = _owner?.DebugInterface; + + if (debugInterface != null) + { + ulong[] threadUids; + + try + { + threadUids = debugInterface.ThreadUids ?? []; + } + catch (Exception e) + { + result.AppendLine($"[Error getting thread uids: {e.Message}]"); + threadUids = []; + } + + foreach (ulong threadUid in threadUids) + { + result.AppendLine($"=== Thread {threadUid} ==="); + + KThread thread; + + try + { + thread = debugInterface.GetThread(threadUid); + } + catch (Exception e) + { + result.AppendLine($"[Error getting thread: {e.Message}]"); + continue; + } + + if (thread == null) + { + result.AppendLine("[Thread not found]"); + continue; + } + + try + { + result.AppendLine(GetGuestStackTrace(thread)); + } + catch (Exception e) + { + result.AppendLine($"[Error getting stack trace: {e.Message}]"); + } + + try + { + result.AppendLine(GetCpuRegisterPrintout(thread)); + } + catch (Exception e) + { + result.AppendLine($"[Error getting registers: {e.Message}]"); + } + } + } + else + { + result.AppendLine("[Error generating minidump: debugInterface is null]"); + } + + result.AppendLine("=== End Minidump ==="); + + return result.ToString(); + } + private static bool TryGetSubName(Image image, ulong address, out ElfSymbol symbol) { address -= image.BaseAddress;