mirror of
https://git.ryujinx.app/kenji-nx/ryujinx.git
synced 2025-12-17 07:37:06 +00:00
feat: resolve real module names in HLE debugger
This commit is contained in:
parent
2699bcf03e
commit
5a9bc0d703
1 changed files with 70 additions and 27 deletions
|
|
@ -3,6 +3,7 @@ using Ryujinx.HLE.HOS.Kernel.Memory;
|
||||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||||
using Ryujinx.HLE.Loaders.Elf;
|
using Ryujinx.HLE.Loaders.Elf;
|
||||||
using Ryujinx.Memory;
|
using Ryujinx.Memory;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
@ -18,6 +19,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
||||||
|
|
||||||
private class Image
|
private class Image
|
||||||
{
|
{
|
||||||
|
public string Name { get; internal set; }
|
||||||
public ulong BaseAddress { get; }
|
public ulong BaseAddress { get; }
|
||||||
public ulong Size { get; }
|
public ulong Size { get; }
|
||||||
public ulong EndAddress => BaseAddress + Size;
|
public ulong EndAddress => BaseAddress + Size;
|
||||||
|
|
@ -29,6 +31,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
||||||
BaseAddress = baseAddress;
|
BaseAddress = baseAddress;
|
||||||
Size = size;
|
Size = size;
|
||||||
Symbols = symbols;
|
Symbols = symbols;
|
||||||
|
Name = "(unknown)";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -241,11 +244,66 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
||||||
info.SubName = "";
|
info.SubName = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
info.ImageName = GetGuessedNsoNameFromIndex(imageIndex);
|
info.ImageName = image.Name;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool GetModuleName(out string moduleName, Image image)
|
||||||
|
{
|
||||||
|
moduleName = string.Empty;
|
||||||
|
|
||||||
|
var rodataStart = image.BaseAddress + image.Size;
|
||||||
|
|
||||||
|
KMemoryInfo roInfo = _owner.MemoryManager.QueryMemory(rodataStart);
|
||||||
|
if (roInfo.Permission != KMemoryPermission.Read)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var rwdataStart = roInfo.Address + roInfo.Size;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Span<byte> rodataBuf = stackalloc byte[0x208];
|
||||||
|
_owner.CpuMemory.Read(rodataStart, rodataBuf);
|
||||||
|
|
||||||
|
ulong deprecatedRwDataOffset = BitConverter.ToUInt64(rodataBuf);
|
||||||
|
// no name if using old format
|
||||||
|
if (image.BaseAddress + deprecatedRwDataOffset == rwdataStart)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint zero = BitConverter.ToUInt32(rodataBuf);
|
||||||
|
int pathLength = BitConverter.ToInt32(rodataBuf.Slice(4));
|
||||||
|
if (zero != 0 || pathLength <= 0)
|
||||||
|
{
|
||||||
|
// try again with 12 byte offset, 20.0.0+
|
||||||
|
_owner.CpuMemory.Read(rodataStart + 12, rodataBuf);
|
||||||
|
zero = BitConverter.ToUInt32(rodataBuf);
|
||||||
|
pathLength = BitConverter.ToInt32(rodataBuf.Slice(4));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (zero != 0 || pathLength <= 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
pathLength = Math.Min(pathLength, rodataBuf.Length - 8);
|
||||||
|
var pathBuf = rodataBuf.Slice(8, pathLength);
|
||||||
|
int lastSlash = pathBuf.LastIndexOfAny(new byte[] { (byte)'\\', (byte)'/' });
|
||||||
|
|
||||||
|
moduleName = Encoding.ASCII.GetString(pathBuf.Slice(lastSlash + 1).TrimEnd((byte)0));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (InvalidMemoryRegionException)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private bool AnalyzePointerFromStack(out PointerInfo info, ulong address, KThread thread)
|
private bool AnalyzePointerFromStack(out PointerInfo info, ulong address, KThread thread)
|
||||||
{
|
{
|
||||||
info = default;
|
info = default;
|
||||||
|
|
@ -280,31 +338,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetGuessedNsoNameFromIndex(int index)
|
|
||||||
{
|
|
||||||
if ((uint)index > 11)
|
|
||||||
{
|
|
||||||
return "???";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (index == 0)
|
|
||||||
{
|
|
||||||
return "rtld";
|
|
||||||
}
|
|
||||||
else if (index == 1)
|
|
||||||
{
|
|
||||||
return "main";
|
|
||||||
}
|
|
||||||
else if (index == GetImagesCount() - 1)
|
|
||||||
{
|
|
||||||
return "sdk";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return "subsdk" + (index - 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int GetImagesCount()
|
private int GetImagesCount()
|
||||||
{
|
{
|
||||||
lock (_images)
|
lock (_images)
|
||||||
|
|
@ -426,7 +459,17 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
||||||
|
|
||||||
lock (_images)
|
lock (_images)
|
||||||
{
|
{
|
||||||
_images.Add(new Image(textOffset, textSize, symbols.OrderBy(x => x.Value).ToArray()));
|
var image = new Image(textOffset, textSize, symbols.OrderBy(x => x.Value).ToArray());
|
||||||
|
|
||||||
|
string moduleName;
|
||||||
|
if (!GetModuleName(out moduleName, image))
|
||||||
|
{
|
||||||
|
var newIndex = _images.Count;
|
||||||
|
moduleName = $"(unknown{newIndex})";
|
||||||
|
}
|
||||||
|
image.Name = moduleName;
|
||||||
|
|
||||||
|
_images.Add(image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue