Skip to content

Commit aa628f0

Browse files
author
Mike McLaughlin
committed
Simplified the thread stack unwind; removed some (probably) unnecessary fallback code
1 parent 725fc40 commit aa628f0

File tree

4 files changed

+15
-126
lines changed

4 files changed

+15
-126
lines changed

documentation/clrma.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ ISOSDacInterface::GetMethodDescName()
5454
ISOSDacInterface::GetModuleData()
5555
ISOSDacInterface::GetPEFileBase()
5656
ISOSDacInterface::GetPEFileName()
57-
ISOSDacInterface::GetMethodDescPtrFromIP
58-
ISOSDacInterface::GetMethodDescPtrFromFrame()
57+
ISOSDacInterface::GetMethodDescPtrFromIP()
5958
6059
// Module name fallback if debugger and GetPEFileName() can't get the name.
6160
ISOSDacInterface::GetModule()
@@ -67,14 +66,6 @@ IXCLRDataTask::CreateStackWalk()
6766
IXCLRDataStackWalk::Request(DACSTACKPRIV_REQUEST_FRAME_DATA, ...)
6867
IXCLRDataStackWalk::GetContext()
6968
IXCLRDataStackWalk::Next()
70-
71-
// Fallback if GetMethodDescPtrFromFrame() fails when getting the stack frame method name. Not sure how important this fallback path is.
72-
IXCLRDataStackWalk::GetFrame()
73-
IXCLRDataFrame::GetMethodInstance()
74-
IXCLRDataMethodInstance::GetRepresentativeEntryAddress()
75-
IXCLRDataMethodInstance::GetTokenAndScope()
76-
IXCLRDataMethodInstance::GetName()
77-
IXCLRDataModule::GetFileName
7869
```
7970

8071
### References

src/SOS/Strike/clrma/thread.cpp

Lines changed: 14 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -199,50 +199,28 @@ ClrmaThread::get_FrameCount(
199199
frame.Frame = index;
200200
if (FAILED(hr = GetFrameLocation(pStackWalk, &frame.IP, &frame.SP)))
201201
{
202+
TraceError("Unwind: GetFrameLocation() FAILED %08x\n", hr);
202203
break;
203204
}
205+
// Only include normal frames, skipping any special frames
204206
DacpFrameData frameData;
205207
if (SUCCEEDED(hr = frameData.Request(pStackWalk)) && frameData.frameAddr != 0)
206208
{
207-
frame.SP = frameData.frameAddr;
208-
209-
// Get special stack frame name
210-
CLRDATA_ADDRESS methodDesc = 0;
211-
if (SUCCEEDED(hr = m_managedAnalysis->SosDacInterface()->GetMethodDescPtrFromFrame(frame.SP, &methodDesc)))
212-
{
213-
if (FAILED(hr = m_managedAnalysis->GetMethodDescInfo(methodDesc, frame, /* stripFunctionParameters */ false)))
214-
{
215-
continue;
216-
}
217-
}
218-
else
219-
{
220-
if (FAILED(hr = GetFrameFromStackWalk(pStackWalk, frame)))
221-
{
222-
continue;
223-
}
224-
}
209+
TraceInformation("Unwind: skipping special frame SP %016llx IP %016llx\n", frame.SP, frame.IP);
210+
continue;
225211
}
226-
else
212+
CLRDATA_ADDRESS methodDesc = 0;
213+
if (FAILED(hr = m_managedAnalysis->SosDacInterface()->GetMethodDescPtrFromIP(frame.IP, &methodDesc)))
227214
{
228-
// Get normal module and method names like MethodNameFromIP() does for !clrstack
229-
CLRDATA_ADDRESS methodDesc = 0;
230-
if (SUCCEEDED(hr = m_managedAnalysis->SosDacInterface()->GetMethodDescPtrFromIP(frame.IP, &methodDesc)))
231-
{
232-
if (FAILED(hr = m_managedAnalysis->GetMethodDescInfo(methodDesc, frame, /* stripFunctionParameters */ false)))
233-
{
234-
continue;
235-
}
236-
}
237-
else
238-
{
239-
if (FAILED(hr = GetFrameFromStackWalk(pStackWalk, frame)))
240-
{
241-
continue;
242-
}
243-
}
215+
TraceInformation("Unwind: skipping frame GetMethodDescPtrFromIP(%016llx) FAILED %08x\n", frame.IP, hr);
216+
continue;
217+
}
218+
// Get normal module and method names like MethodNameFromIP() does for !clrstack
219+
if (FAILED(hr = m_managedAnalysis->GetMethodDescInfo(methodDesc, frame, /* stripFunctionParameters */ false)))
220+
{
221+
TraceInformation("Unwind: skipping frame GetMethodDescInfo(%016llx) FAILED %08x\n", methodDesc, hr);
222+
continue;
244223
}
245-
246224
m_stackFrames.push_back(frame);
247225
index++;
248226

@@ -534,81 +512,3 @@ ClrmaThread::GetFrameLocation(
534512
}
535513
return S_OK;
536514
}
537-
538-
HRESULT
539-
ClrmaThread::GetFrameFromStackWalk(
540-
IXCLRDataStackWalk* pStackWalk,
541-
StackFrame& frame
542-
)
543-
{
544-
HRESULT hr;
545-
ReleaseHolder<IXCLRDataFrame> clrDataFrame;
546-
if (SUCCEEDED(hr = pStackWalk->GetFrame((IXCLRDataFrame**)&clrDataFrame)))
547-
{
548-
ReleaseHolder<IXCLRDataMethodInstance> methodInstance;
549-
if (SUCCEEDED(hr = clrDataFrame->GetMethodInstance((IXCLRDataMethodInstance**)&methodInstance)))
550-
{
551-
// Don't compute the method displacement if IP is 0
552-
if (frame.IP > 0)
553-
{
554-
CLRDATA_ADDRESS startAddr;
555-
if (SUCCEEDED(hr = methodInstance->GetRepresentativeEntryAddress(&startAddr)))
556-
{
557-
frame.Displacement = (frame.IP - startAddr);
558-
}
559-
else
560-
{
561-
TraceError("GetFrameFromStackWalk: IXCLRDataMethodInstance::GetRepresentativeEntryAddress FAILED %08x\n", hr);
562-
}
563-
}
564-
565-
ArrayHolder<WCHAR> wszNameBuffer = new WCHAR[MAX_LONGPATH + 1];
566-
if (SUCCEEDED(hr = methodInstance->GetName(0, MAX_LONGPATH, nullptr, wszNameBuffer)))
567-
{
568-
frame.Function = wszNameBuffer;
569-
}
570-
else
571-
{
572-
TraceError("GetFrameFromStackWalk: IXCLRDataMethodInstance::GetName FAILED %08x\n", hr);
573-
}
574-
575-
mdMethodDef token;
576-
IXCLRDataModule* pModule;
577-
if (SUCCEEDED(hr = methodInstance->GetTokenAndScope(&token, &pModule)))
578-
{
579-
wszNameBuffer[0] = L'\0';
580-
581-
ULONG32 nameLen = 0;
582-
if (SUCCEEDED(hr = pModule->GetFileName(MAX_LONGPATH, &nameLen, wszNameBuffer)))
583-
{
584-
frame.Module = wszNameBuffer;
585-
}
586-
else
587-
{
588-
TraceError("GetFrameFromStackWalk: IXCLRDataModule::GetFileName FAILED %08x\n", hr);
589-
}
590-
}
591-
else
592-
{
593-
TraceError("GetFrameFromStackWalk: IXCLRDataMethodInstance::GetTokenAndScope FAILED %08x\n", hr);
594-
}
595-
}
596-
else
597-
{
598-
TraceError("GetFrameFromStackWalk: IXCLRDataFrame::GetMethodInstance FAILED %08x\n", hr);
599-
}
600-
}
601-
else
602-
{
603-
TraceError("GetFrameFromStackWalk: IXCLRDataStackWalk::GetFrame FAILED %08x\n", hr);
604-
}
605-
if (frame.Module.empty())
606-
{
607-
frame.Module = L"UNKNOWN";
608-
}
609-
if (frame.Function.empty())
610-
{
611-
frame.Function = L"UNKNOWN";
612-
}
613-
return hr;
614-
}

src/SOS/Strike/clrma/thread.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,4 @@ class ClrmaThread : public ICLRMAClrThread
4949
bool m_nestedExceptionsInitialized;
5050

5151
HRESULT GetFrameLocation(IXCLRDataStackWalk* pStackWalk, CLRDATA_ADDRESS* ip, CLRDATA_ADDRESS* sp);
52-
HRESULT GetFrameFromStackWalk(IXCLRDataStackWalk* pStackWalk, StackFrame& frame);
5352
};

src/SOS/Strike/strike.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12656,7 +12656,6 @@ HRESULT ImplementEFNGetManagedExcepStack(
1265612656
DECLARE_API(VerifyStackTrace)
1265712657
{
1265812658
INIT_API();
12659-
ONLY_SUPPORTED_ON_WINDOWS_TARGET();
1266012659

1266112660
BOOL bVerifyManagedExcepStack = FALSE;
1266212661
CMDOption option[] =

0 commit comments

Comments
 (0)