diff --git a/Source/Common/DeferredStackTracingImpl.cs b/Source/Common/DeferredStackTracingImpl.cs index 373a9258..2f71d756 100644 --- a/Source/Common/DeferredStackTracingImpl.cs +++ b/Source/Common/DeferredStackTracingImpl.cs @@ -141,8 +141,12 @@ static long UpdateNewElement(ref AddrInfo info, long ret) info.addr = ret; info.stackUsage = stackUsage; - var rawName = Native.MethodNameFromAddr(ret, true); // Use the original instead of replacement for hashing - info.nameHash = rawName != null ? Native.GetMethodAggressiveInlining(ret) ? 0 : StableStringHash(rawName) : 1; + var normalizedMethodNameBetweenOS = Native.MethodNameNormalizedFromAddr(ret, true); + + info.nameHash = + normalizedMethodNameBetweenOS == null ? 1 : + Native.GetMethodAggressiveInlining(ret) ? 0 : + StableStringHash(normalizedMethodNameBetweenOS); hashtableEntries++; if (hashtableEntries > hashtableSize * LoadFactor) diff --git a/Source/Common/Native.cs b/Source/Common/Native.cs index e2c4959c..b6e7f0fc 100644 --- a/Source/Common/Native.cs +++ b/Source/Common/Native.cs @@ -96,6 +96,24 @@ public static unsafe void InitLmfPtr(NativeOS os) return string.IsNullOrEmpty(name) ? null : name; } + public static string? MethodNameNormalizedFromAddr(long addr, bool harmonyOriginals) + { + var name = MethodNameFromAddr(addr, harmonyOriginals); + + if (name == null) return null; + if (name.Length == 0) return name; + + int ilOffsetIndex = name.IndexOf(" [0x", StringComparison.Ordinal); + if (ilOffsetIndex >= 0) + name = name.Substring(0, ilOffsetIndex); + + int mvidIndex = name.IndexOf(" in <", StringComparison.Ordinal); + if (mvidIndex >= 0) + name = name.Substring(0, mvidIndex); + + return name.TrimEnd(); + } + private static ConstructorInfo runtimeMethodHandleCtor = AccessTools.Constructor(typeof(RuntimeMethodHandle), new[]{typeof(IntPtr)}); public static bool GetMethodAggressiveInlining(long addr)