Skip to content

Commit aac3faf

Browse files
committed
refactor ExecutionManager
1 parent ebb4a67 commit aac3faf

4 files changed

Lines changed: 194 additions & 159 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Diagnostics;
7+
using System.Diagnostics.CodeAnalysis;
8+
9+
namespace Microsoft.Diagnostics.DataContractReader.Contracts;
10+
11+
internal readonly partial struct ExecutionManager_1 : IExecutionManager
12+
{
13+
private class EEJitManager : JitManager
14+
{
15+
private readonly NibbleMap _nibbleMap;
16+
public EEJitManager(Target target, NibbleMap nibbleMap) : base(target)
17+
{
18+
_nibbleMap = nibbleMap;
19+
}
20+
21+
public override bool GetMethodInfo(RangeSection rangeSection, TargetCodePointer jittedCodeAddress, [NotNullWhen(true)] out EECodeInfo? info)
22+
{
23+
info = null;
24+
// EEJitManager::JitCodeToMethodInfo
25+
if (rangeSection.IsRangeList)
26+
{
27+
return false;
28+
}
29+
TargetPointer start = FindMethodCode(rangeSection, jittedCodeAddress);
30+
if (start == TargetPointer.Null)
31+
{
32+
return false;
33+
}
34+
Debug.Assert(start.Value <= jittedCodeAddress.Value);
35+
TargetNUInt relativeOffset = new TargetNUInt(jittedCodeAddress.Value - start.Value);
36+
int codeHeaderOffset = Target.PointerSize;
37+
TargetPointer codeHeaderIndirect = new TargetPointer(start - (ulong)codeHeaderOffset);
38+
if (RangeSection.IsStubCodeBlock(Target, codeHeaderIndirect))
39+
{
40+
return false;
41+
}
42+
TargetPointer codeHeaderAddress = Target.ReadPointer(codeHeaderIndirect);
43+
Data.RealCodeHeader realCodeHeader = Target.ProcessedData.GetOrAdd<Data.RealCodeHeader>(codeHeaderAddress);
44+
info = new EECodeInfo(jittedCodeAddress, codeHeaderOffset, relativeOffset, realCodeHeader, rangeSection.Data!.JitManager);
45+
return true;
46+
}
47+
48+
private TargetPointer FindMethodCode(RangeSection rangeSection, TargetCodePointer jittedCodeAddress)
49+
{
50+
// EEJitManager::FindMethodCode
51+
if (rangeSection.Data == null)
52+
{
53+
throw new InvalidOperationException();
54+
}
55+
if (!rangeSection.IsCodeHeap)
56+
{
57+
throw new InvalidOperationException("RangeSection is not a code heap");
58+
}
59+
TargetPointer heapListAddress = rangeSection.Data.HeapList;
60+
Data.HeapList heapList = Target.ProcessedData.GetOrAdd<Data.HeapList>(heapListAddress);
61+
if (jittedCodeAddress < heapList.StartAddress || jittedCodeAddress > heapList.EndAddress)
62+
{
63+
return TargetPointer.Null;
64+
}
65+
TargetPointer mapBase = heapList.MapBase;
66+
TargetPointer mapStart = heapList.HeaderMap;
67+
return _nibbleMap.FindMethodCode(mapBase, mapStart, jittedCodeAddress);
68+
}
69+
70+
}
71+
}

src/native/managed/cdacreader/src/Contracts/ExecutionManager_1.NibbleMap.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ namespace Microsoft.Diagnostics.DataContractReader.Contracts;
2828
internal sealed class NibbleMap
2929
{
3030

31-
public static NibbleMap Create(Target target, uint codeHeaderSize)
31+
public static NibbleMap Create(Target target)
3232
{
33+
uint codeHeaderSize = (uint)target.PointerSize;
3334
return new NibbleMap(target, codeHeaderSize);
3435
}
3536

0 commit comments

Comments
 (0)