Move ProcessInfo and Minidump to HleProcessDebugger

This allows developers to call them in the code for debugging.
This commit is contained in:
Coxxs 2025-10-22 16:20:13 -05:00 committed by KeatonTheBot
parent 52b6fcf1a4
commit afa1ab95c2
2 changed files with 120 additions and 54 deletions

View file

@ -61,38 +61,16 @@ namespace Ryujinx.HLE.Debugger
public string GetMinidump() public string GetMinidump()
{ {
var response = new StringBuilder(); if (Process is not { } kProcess)
response.AppendLine("=== Begin Minidump ===\n"); return "No application process found\n";
response.AppendLine(GetProcessInfo());
foreach (var thread in GetThreads()) if (kProcess.Debugger is not { } debugger)
{ return $"Error getting minidump: debugger is null\n";
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}]");
}
try var response = debugger.GetMinidump();
{
string registers = Process.Debugger.GetCpuRegisterPrintout(thread);
response.AppendLine(registers);
}
catch (Exception e)
{
response.AppendLine($"[Error getting registers: {e.Message}]");
}
}
response.AppendLine("=== End Minidump ==="); Logger.Info?.Print(LogClass.GdbStub, response);
return response;
Logger.Info?.Print(LogClass.GdbStub, response.ToString());
return response.ToString();
} }
public string GetProcessInfo() public string GetProcessInfo()
@ -102,32 +80,10 @@ namespace Ryujinx.HLE.Debugger
if (Process is not { } kProcess) if (Process is not { } kProcess)
return "No application process found\n"; return "No application process found\n";
var sb = new StringBuilder(); if (kProcess.Debugger is not { } debugger)
return $"Error getting process info: debugger is null\n";
sb.AppendLine($"Program Id: 0x{kProcess.TitleId:x16}"); return debugger.GetProcessInfoPrintout();
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:");
var 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();
} }
catch (Exception e) catch (Exception e)
{ {

View file

@ -159,6 +159,116 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
return sb.ToString(); 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) private static bool TryGetSubName(Image image, ulong address, out ElfSymbol symbol)
{ {
address -= image.BaseAddress; address -= image.BaseAddress;