Skip to content

Commit

Permalink
crossplatform LazyMachState fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Charlamb committed Jan 23, 2025
1 parent 22a3c9a commit 5d9317a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
6 changes: 2 additions & 4 deletions src/coreclr/debug/runtimeinfo/datadescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -602,16 +602,14 @@ DEFINE_FRAME_TYPE(HelperMethodFrame_3OBJ)
DEFINE_FRAME_TYPE(HelperMethodFrame_PROTECTOBJ)
#undef DEFINE_FRAME_TYPE

#ifdef TARGET_AMD64
CDAC_TYPE_BEGIN(LazyMachState)
CDAC_TYPE_SIZE(sizeof(LazyMachState))
CDAC_TYPE_FIELD(LazyMachState, /*pointer*/, InstructionPointer, cdac_data<LazyMachState>::InstructionPointer)
CDAC_TYPE_FIELD(LazyMachState, /*pointer*/, StackPointer, cdac_data<LazyMachState>::StackPointer)
CDAC_TYPE_FIELD(LazyMachState, /*pointer*/, ReturnAddress, cdac_data<LazyMachState>::ReturnAddress)
CDAC_TYPE_FIELD(LazyMachState, /*pointer*/, CapturedInstructionPointer, offsetof(LazyMachState, m_CaptureRip))
CDAC_TYPE_FIELD(LazyMachState, /*pointer*/, CapturedStackPointer, offsetof(LazyMachState, m_CaptureRsp))
CDAC_TYPE_FIELD(LazyMachState, /*CalleeSavedRegisters*/, CalleeSavedRegisters, cdac_data<LazyMachState>::CalleeSavedRegisters)
CDAC_TYPE_FIELD(LazyMachState, /*CalleeSavedRegistersPointers*/, CalleeSavedRegistersPointers, cdac_data<LazyMachState>::CalleeSavedRegistersPointers)
CDAC_TYPE_END(LazyMachState)
#endif // TARGET_AMD64

CDAC_TYPES_END()

Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/vm/amd64/gmscpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ struct cdac_data<LazyMachState>
static constexpr size_t InstructionPointer = offsetof(LazyMachState, m_Rip);
static constexpr size_t StackPointer = offsetof(LazyMachState, m_Rsp);
static constexpr size_t ReturnAddress = offsetof(LazyMachState, _pRetAddr);
static constexpr size_t CalleeSavedRegisters = offsetof(LazyMachState, m_Capture);
static constexpr size_t CalleeSavedRegistersPointers = offsetof(LazyMachState, m_Ptrs);
};

inline void LazyMachState::setLazyStateFromUnwind(MachState* copy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public static bool TryGetContext(Target target, Data.Frame frame, [NotNullWhen(t
case DataType.HelperMethodFrame_3OBJ:
case DataType.HelperMethodFrame_PROTECTOBJ:
Data.HelperMethodFrame helperMethodFrame = target.ProcessedData.GetOrAdd<Data.HelperMethodFrame>(frame.Address);
if (helperMethodFrame.LazyMachState.StackPointer is null || helperMethodFrame.LazyMachState.InstructionPointer is null)
{
IP = null;
SP = null;
return false;
}
IP = helperMethodFrame.LazyMachState.InstructionPointer;
SP = helperMethodFrame.LazyMachState.StackPointer;
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@ static LazyMachState IData<LazyMachState>.Create(Target target, TargetPointer ad
public LazyMachState(Target target, TargetPointer address)
{
Target.TypeInfo type = target.GetTypeInfo(DataType.LazyMachState);
InstructionPointer = target.ReadPointer(address + (ulong)type.Fields[nameof(InstructionPointer)].Offset);
StackPointer = target.ReadPointer(address + (ulong)type.Fields[nameof(StackPointer)].Offset);
ReturnAddress = target.ReadPointer(address + (ulong)type.Fields[nameof(ReturnAddress)].Offset);
if (type.Fields.ContainsKey(nameof(InstructionPointer)))
{
InstructionPointer = target.ReadPointer(address + (ulong)type.Fields[nameof(InstructionPointer)].Offset);
}
if (type.Fields.ContainsKey(nameof(StackPointer)))
{
StackPointer = target.ReadPointer(address + (ulong)type.Fields[nameof(StackPointer)].Offset);
}
if (type.Fields.ContainsKey(nameof(ReturnAddress)))
{
ReturnAddress = target.ReadPointer(address + (ulong)type.Fields[nameof(ReturnAddress)].Offset);
}
}

public TargetPointer InstructionPointer { get; }
public TargetPointer StackPointer { get; }
public TargetPointer ReturnAddress { get; }
public TargetPointer? InstructionPointer { get; }
public TargetPointer? StackPointer { get; }
public TargetPointer? ReturnAddress { get; }
}

0 comments on commit 5d9317a

Please sign in to comment.