Skip to content

Commit

Permalink
Fix line number issues in SOS
Browse files Browse the repository at this point in the history
Reported issues https://github.com/dotnet/coreclr/issues/27765 and https://github.com/dotnet/coreclr/issues/25740 for the runtime's unhandled exception message

Gracefully fail with runtime module size == 0

Add some more PrintException -lines testing
  • Loading branch information
mikem8361 committed Jan 7, 2020
1 parent 900436c commit 8253e52
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
14 changes: 13 additions & 1 deletion src/SOS/SOS.UnitTests/Scripts/SimpleThrow.script
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ VERIFY:\s+<HEXVAL>\s+<HEXVAL>\s+[Ss]imple[Tt]hrow.*!(\$0_)?UserObject\.UseObject
VERIFY:\s+<HEXVAL>\s+<HEXVAL>\s+[Ss]imple[Tt]hrow.*!(\$0_)?Simple\.Main.*\+0x<HEXVAL>\s+
VERIFY:HResult:\s+80131509

SOSCOMMAND:PrintException -lines
VERIFY:Exception object:\s+<HEXVAL>\s+
VERIFY:Exception type:\s+System\.InvalidOperationException\s+
VERIFY:Message:\s+(<Invalid Object>|Throwing an invalid operation\.\.\.\.)\s+
VERIFY:InnerException:\s+<none>\s+
VERIFY:StackTrace\s+\(generated\):\s+
VERIFY:\s+SP\s+IP\s+Function\s+
VERIFY:\s+<HEXVAL>\s+<HEXVAL>\s+[Ss]imple[Tt]hrow.*!(\$0_)?UserObject\.UseObject.*\+0x<HEXVAL>\s*
VERIFY:\[.*[\\|/]Debuggees[\\|/](dotnet.+[\\|/])?SimpleThrow[\\|/]UserObject\.cs @ 16\s*\]\s*
VERIFY:\s+<HEXVAL>\s+<HEXVAL>\s+[Ss]imple[Tt]hrow.*!(\$0_)?Simple\.Main.*\+0x<HEXVAL>\s+
VERIFY:\[.*[\\|/]Debuggees[\\|/](dotnet.+[\\|/])?SimpleThrow[\\|/]SimpleThrow\.cs @ 9\s*\]\s*

# Verify that Threads (clrthreads) works
IFDEF:DOTNETDUMP
SOSCOMMAND:clrthreads
Expand All @@ -54,6 +66,6 @@ SOSCOMMAND:ClrStack
VERIFY:.*OS Thread Id:\s+0x<HEXVAL>\s+.*
VERIFY:\s+Child\s+SP\s+IP\s+Call Site\s+
VERIFY:\s+<HEXVAL>\s+<HEXVAL>\s+(\*\*\* WARNING: Unable to verify checksum for SimpleThrow.exe\s*)?UserObject\.UseObject.*\s+
VERIFY:[.*[\\|/]Debuggees[\\|/](dotnet.+[\\|/])?SimpleThrow[\\|/]UserObject\.cs @ 18\s*\]
VERIFY:[.*[\\|/]Debuggees[\\|/](dotnet.+[\\|/])?SimpleThrow[\\|/]UserObject\.cs @ 16\s*\]
VERIFY:\s+<HEXVAL>\s+<HEXVAL>\s+Simple\.Main\(\)\s+
VERIFY:[.*[\\|/]Debuggees[\\|/](dotnet.+[\\|/])?SimpleThrow[\\|/]SimpleThrow\.cs @ 9\s*\]
12 changes: 10 additions & 2 deletions src/SOS/Strike/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,16 @@ HRESULT Runtime::CreateInstance(bool isDesktop, Runtime **ppRuntime)
}
if (SUCCEEDED(hr))
{
*ppRuntime = new Runtime(isDesktop, moduleIndex, moduleAddress, moduleSize);
OnUnloadTask::Register(CleanupRuntimes);
if (moduleSize > 0)
{
*ppRuntime = new Runtime(isDesktop, moduleIndex, moduleAddress, moduleSize);
OnUnloadTask::Register(CleanupRuntimes);
}
else
{
ExtOut("Runtime (%s) module size == 0\n", runtimeModuleName);
hr = E_INVALIDARG;
}
}
}
return hr;
Expand Down
14 changes: 11 additions & 3 deletions src/SOS/Strike/strike.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2464,7 +2464,8 @@ size_t FormatGeneratedException (DWORD_PTR dataPtr,
WCHAR filename[MAX_LONGPATH] = W("");
ULONG linenum = 0;
if (bLineNumbers &&
SUCCEEDED(GetLineByOffset(TO_CDADDR(ste.ip), &linenum, filename, _countof(filename))))
// Adjust the ip for leaf node frames
SUCCEEDED(GetLineByOffset(TO_CDADDR(i == 0 ? ste.ip - 1 : ste.ip), &linenum, filename, _countof(filename))))
{
swprintf_s(wszLineBuffer, _countof(wszLineBuffer), W(" %s [%s @ %d]\n"), so.String(), filename, linenum);
}
Expand Down Expand Up @@ -13481,7 +13482,9 @@ class ClrStackImpl

TableOutput out(3, POINTERSIZE_HEX, AlignRight);
out.WriteRow("Child SP", "IP", "Call Site");


int frameNumber = 0;
int internalFrames = 0;
do
{
if (IsInterrupt())
Expand Down Expand Up @@ -13516,6 +13519,8 @@ class ClrStackImpl
// Print the method/Frame info
if (SUCCEEDED(frameDataResult) && FrameData.frameAddr)
{
internalFrames++;

// Skip the instruction pointer because it doesn't really mean anything for method frames
out.WriteColumn(1, bFull ? String("") : NativePtr(ip));

Expand All @@ -13534,8 +13539,11 @@ class ClrStackImpl
}
else
{
frameNumber++;

out.WriteColumn(1, InstructionPtr(ip));
out.WriteColumn(2, MethodNameFromIP(ip, bSuppressLines, bFull, bFull));
// To get the correct line number, the ip needs to be adjusted for leaf frames.
out.WriteColumn(2, MethodNameFromIP(frameNumber == 1 && internalFrames > 0 ? ip - 1 : ip, bSuppressLines, bFull, bFull));

// Print out gc references. refCount will be zero if bGC is false (or if we
// failed to fetch gc reference information).
Expand Down

0 comments on commit 8253e52

Please sign in to comment.