Skip to content

Commit 14fd98f

Browse files
committed
When debugging 64-bit processes VS can not lookup the mono_pmip symbol in the
JIT frame's context. This patch enumerates all loaded modules and tries DkmNativeModuleInstance.FindExportName("mono_pmip") to find the address of the mono_pmip() function rather than using expression evaluation. This method has been validated to work with 32-bit and 64-bit processes.
1 parent 8723561 commit 14fd98f

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

PmipRunner.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
using Microsoft.VisualStudio.Debugger;
33
using Microsoft.VisualStudio.Debugger.CallStack;
44
using Microsoft.VisualStudio.Debugger.Evaluation;
5+
using Microsoft.VisualStudio.Debugger.Native;
56

67
namespace PmipMyCallStack
78
{
89
class PmipRunner
910
{
1011
private static readonly DkmLanguage CppLanguage = DkmLanguage.Create("C++", new DkmCompilerId(DkmVendorId.Microsoft, DkmLanguageId.Cpp));
11-
private static readonly string[] Modules = { "mono", "monosgen-2.0" };
1212

1313
private readonly DkmStackContext _stackContext;
1414
private readonly DkmStackWalkFrame _frame;
@@ -59,17 +59,19 @@ private bool TryGetPmipFunction(out PmipFunctionDataItem pmipFunction)
5959
if (pmipFunction != null)
6060
return true;
6161

62-
foreach (var module in Modules)
62+
foreach (var module in this._frame.RuntimeInstance.GetModuleInstances())
6363
{
64-
var definition = $"{{,,{module}}}mono_pmip";
65-
66-
PmipFunctionDataItem item = null;
67-
if (!EvaluateExpression(definition, r => item = new PmipFunctionDataItem {PmipFunction = definition}))
68-
continue;
69-
70-
pmipFunction = item;
71-
_stackContext.SetDataItem(DkmDataCreationDisposition.CreateAlways, item);
72-
return true;
64+
if (module is DkmNativeModuleInstance)
65+
{
66+
DkmNativeInstructionAddress address = ((DkmNativeModuleInstance) module).FindExportName("mono_pmip", true);
67+
if (address != null)
68+
{
69+
PmipFunctionDataItem item = new PmipFunctionDataItem { PmipFunction = "0x" + address.CPUInstructionPart.InstructionPointer.ToString("X") };
70+
pmipFunction = item;
71+
_stackContext.SetDataItem(DkmDataCreationDisposition.CreateAlways, item);
72+
return true;
73+
}
74+
}
7375
}
7476

7577
return false;
@@ -116,4 +118,4 @@ private bool EvaluateExpression(string expression, Action<DkmSuccessEvaluationRe
116118
return success;
117119
}
118120
}
119-
}
121+
}

0 commit comments

Comments
 (0)