Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SOS message context #3375

Merged
merged 2 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/SOS/SOS.Extensions/HostServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ private void Uninitialize(

if (DebuggerServices != null)
{
// This turns off any logging to console now that debugger services will be released and the console service will no longer work.
DiagnosticLoggingService.Instance.SetConsole(consoleService: null, fileLoggingService: null);
DebuggerServices.Release();
DebuggerServices = null;
}
Expand Down
8 changes: 4 additions & 4 deletions src/SOS/SOS.UnitTests/Scripts/NestedExceptionTest.script
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ SOSCOMMAND:PrintException
VERIFY:Exception object:\s+<HEXVAL>\s+
VERIFY:Exception type:\s+System\.InvalidOperationException\s+
VERIFY:Message:\s+(<Invalid Object>|Invalid operation exception, outer)\s+
VERIFY:InnerException:\s+System\.FormatException, Use !PrintException <HEXVAL> to see more.\s+
VERIFY:InnerException:\s+System\.FormatException, Use !?printexception <HEXVAL> to see more.\s+
VERIFY:StackTrace \(generated\):\s+
VERIFY:\s+SP\s+IP\s+\s+Function\s+
VERIFY:\s+<HEXVAL>\s+<HEXVAL>\s+[Nn]ested[Ee]xception[Tt]est.*!NestedExceptionTest\.Program\.Main(\(.*\))?\+0x<HEXVAL>\s+
Expand All @@ -54,7 +54,7 @@ SOSCOMMAND:PrintException -nested
VERIFY:Exception object:\s+<HEXVAL>\s+
VERIFY:Exception type:\s+System\.InvalidOperationException\s+
VERIFY:Message:\s+(<Invalid Object>|Invalid operation exception, outer)\s+
VERIFY:InnerException:\s+System\.FormatException, Use !PrintException <HEXVAL> to see more.\s+
VERIFY:InnerException:\s+System\.FormatException, Use !?printexception <HEXVAL> to see more.\s+
VERIFY:StackTrace \(generated\):\s+
VERIFY:\s+SP\s+IP\s+Function\s+
VERIFY:\s+<HEXVAL>\s+<HEXVAL>\s+[Nn]ested[Ee]xception[Tt]est.*!NestedExceptionTest\.Program\.Main(\(.*\))?\+0x<HEXVAL>\s+
Expand All @@ -72,7 +72,7 @@ VERIFY:(StackTraceString: <none>\s+)?
VERIFY:HResult:\s+80131537

# 6) Verifying that the Exception Object/ID gives us the same output about the reflected exception.
SOSCOMMAND:PrintException <POUT>InnerException:\s+System\.FormatException, Use !PrintException (<HEXVAL>) to see more<POUT>
SOSCOMMAND:PrintException <POUT>InnerException:\s+System\.FormatException, Use !?printexception (<HEXVAL>) to see more<POUT>
VERIFY:Exception object:\s+<HEXVAL>\s+
VERIFY:Exception type:\s+System\.FormatException\s+
VERIFY:Message:\s+(<Invalid Object>|Bad format exception, inner)\s+
Expand All @@ -89,7 +89,7 @@ SOSCOMMAND:PrintException -lines
VERIFY:Exception object:\s+<HEXVAL>\s+
VERIFY:Exception type:\s+System\.InvalidOperationException\s+
VERIFY:Message:\s+(<Invalid Object>|Invalid operation exception, outer)\s+
VERIFY:InnerException:\s+System\.FormatException, Use !PrintException <HEXVAL> to see more.\s+
VERIFY:InnerException:\s+System\.FormatException, Use !?printexception <HEXVAL> to see more.\s+
VERIFY:StackTrace \(generated\):
VERIFY:\s+SP\s+IP\s+Function\s+
VERIFY:\s+<HEXVAL>\s+<HEXVAL>\s+[Nn]ested[Ee]xception[Tt]est.*!NestedExceptionTest\.Program\.Main(\(.*\))?\+0x<HEXVAL>\s*
Expand Down
6 changes: 3 additions & 3 deletions src/SOS/SOS.UnitTests/Scripts/Reflection.script
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ SOSCOMMAND:PrintException
VERIFY:Exception object:\s+<HEXVAL>\s+
VERIFY:Exception type:\s+System\.Reflection\.TargetInvocationException\s+
VERIFY:Message:\s+(<Invalid Object>|Exception has been thrown by the target of an invocation\.)\s+
VERIFY:InnerException:\s+System\.Exception, Use !PrintException <HEXVAL> to see more.\s+
VERIFY:InnerException:\s+System\.Exception, Use !?printexception <HEXVAL> to see more.\s+
VERIFY:StackTrace \(generated\):\s+
VERIFY:<HEXVAL>\s+<HEXVAL>\s+[Rr]eflection[Tt]est.*!(\$0_)?RefLoader(\.|::)Loader\.Main(\(\))?\+0x<HEXVAL>
VERIFY:(StackTraceString: <none>\s+)?
VERIFY:HResult:\s+80131604

# 6) Verifying that the Exception Object/ID gives us the same output about the reflected exception.
SOSCOMMAND:PrintException <POUT>InnerException:\s+System\.Exception, Use !PrintException (<HEXVAL>) to see more<POUT>
SOSCOMMAND:PrintException <POUT>InnerException:\s+System\.Exception, Use !?printexception (<HEXVAL>) to see more<POUT>
VERIFY:Exception object:\s+<HEXVAL>\s+
VERIFY:Exception type:\s+System\.Exception\s+
VERIFY:Message:\s+(<Invalid Object>|Exception from InvokedCode\.Invoked\.ExceptionNoHandler(\(\))?)\s+
Expand All @@ -35,7 +35,7 @@ VERIFY:HResult:\s+80131500
SOSCOMMAND:PrintException -lines
VERIFY:Exception type:\s+System\.Reflection\.TargetInvocationException\s+
VERIFY:Message:\s+(<Invalid Object>|Exception has been thrown by the target of an invocation\.)\s+
VERIFY:InnerException:\s+System\.Exception, Use !PrintException <HEXVAL> to see more\.\s+
VERIFY:InnerException:\s+System\.Exception, Use !?printexception <HEXVAL> to see more\.\s+
VERIFY:StackTrace \(generated\):\s+
VERIFY:\s+<HEXVAL>\s+<HEXVAL>\s+[Rr]eflection[Tt]est.*!(\$0_)?RefLoader\.Loader\.Main(\(\))?\+0x<HEXVAL>\s*
VERIFY:[.*[\\|/]Debuggees[\\|/].*[Rr]eflection[Tt]est[\\|/][Rr]eflection[Tt]est\.cs @ 32\s*\]
Expand Down
8 changes: 4 additions & 4 deletions src/SOS/SOS.UnitTests/Scripts/TaskNestedException.script
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ SOSCOMMAND:PrintException
VERIFY:Exception object:\s+<HEXVAL>\s+
VERIFY:Exception type:\s+System\.AggregateException\s+
VERIFY:Message:\s+(<Invalid Object>|One or more errors occurred\.)\s+
VERIFY:InnerException:\s+System\.FormatException, Use !PrintException <HEXVAL> to see more\.\s+
VERIFY:InnerException:\s+System\.FormatException, Use !?printexception <HEXVAL> to see more\.\s+
VERIFY:StackTrace \(generated\):\s+
VERIFY:\s+SP\s+IP\s+Function\s+
VERIFY:\s+<HEXVAL>\s+<HEXVAL>.+System(::|\.)Threading(::|\.)Tasks(::|\.)Task\.Wait(\(\))?\+0x<HEXVAL>\s+
VERIFY:\s+<HEXVAL>\s+<HEXVAL>\s+.*RandomUserTask\.WaitTask(\(\))?\+0x<HEXVAL>\s+
VERIFY:\s+<HEXVAL>\s+<HEXVAL>\s+.*SosTests(::|\.)TaskException\.Main(\(\))?\+0x<HEXVAL>\s+

SOSCOMMAND:PrintException -lines <POUT>InnerException:\s+System\.FormatException, Use !PrintException (<HEXVAL>) to see more<POUT>
SOSCOMMAND:PrintException -lines <POUT>InnerException:\s+System\.FormatException, Use !?printexception (<HEXVAL>) to see more<POUT>
VERIFY:Exception object:\s+<HEXVAL>\s+
VERIFY:Exception type:\s+System\.FormatException\s+
VERIFY:Message:\s+(<Invalid Object>|Bad format exception, outer\.)\s+
VERIFY:InnerException:\s+System\.InvalidOperationException, Use !PrintException <HEXVAL> to see more\.\s+
VERIFY:InnerException:\s+System\.InvalidOperationException, Use !?printexception <HEXVAL> to see more\.\s+
VERIFY:StackTrace \(generated\):\s+
VERIFY:\s+SP\s+IP\s+Function\s+
VERIFY:\s+<HEXVAL>\s+<HEXVAL>.+RandomTest(::|\.)RandomUserTask\.<\.ctor>.+\+0x<HEXVAL>\s*
Expand All @@ -34,7 +34,7 @@ VERIFY:[.+[\\|/]Debuggees[\\|/].*[Tt]ask[Nn]ested[Ee]xception[\\|/][Rr]andom[Uu]
ENDIF:TRIAGE_DUMP
ENDIF:DESKTOP

SOSCOMMAND:PrintException -lines <POUT>InnerException:\s+System\.InvalidOperationException, Use !PrintException (<HEXVAL>) to see more<POUT>
SOSCOMMAND:PrintException -lines <POUT>InnerException:\s+System\.InvalidOperationException, Use !?printexception (<HEXVAL>) to see more<POUT>
VERIFY:Exception object:\s+<HEXVAL>\s+
VERIFY:Exception type:\s+System\.InvalidOperationException\s+
VERIFY:Message:\s+(<Invalid Object>|This is an Inner InvalidOperationException\.)\s+
Expand Down
2 changes: 2 additions & 0 deletions src/SOS/Strike/exts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ void __cdecl _SOS_invalid_parameter(
}

bool g_Initialized = false;
const char* g_sosPrefix = "";

bool IsInitializedByDbgEng()
{
Expand All @@ -238,6 +239,7 @@ DebugExtensionInitialize(PULONG Version, PULONG Flags)
return S_OK;
}
g_Initialized = true;
g_sosPrefix = "!";

ReleaseHolder<IDebugClient> debugClient;
if ((hr = DebugCreate(__uuidof(IDebugClient), (void **)&debugClient)) != S_OK)
Expand Down
32 changes: 16 additions & 16 deletions src/SOS/Strike/sosdocsunix.txt
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ memory in that range, you'll see the object pointers that are registered:

You could run dumpobj on any of those pointers to learn more. In this example,
there are no objects ready for finalization, presumably because they still have
roots (You can use !GCRoot to find out). The statistics section provides a
roots (You can use gcroot to find out). The statistics section provides a
higher-level summary of the objects registered for finalization. Note that
objects ready for finalization are also included in the statistics (if any).

Expand Down Expand Up @@ -1326,14 +1326,14 @@ It means that Thread e04 owns object 00a7a194, and Thread ab8 owns object
0404ea04 77f5c524 SharedUserData!SystemCallStub+0x4
0404ea08 77e75ee0 ntdll!NtWaitForMultipleObjects+0xc
0404eaa4 5d9de9d6 KERNEL32!WaitForMultipleObjectsEx+0x12c
0404eb38 5d9def80 clr!Thread::DoAppropriateAptStateWait+0x156
0404ecc4 5d9dd8bb clr!Thread::DoAppropriateWaitWorker+0x360
0404ed20 5da628dd clr!Thread::DoAppropriateWait+0xbb
0404ede4 5da4e2e2 clr!CLREvent::Wait+0x29d
0404ee70 5da4dd41 clr!AwareLock::EnterEpilog+0x132
0404ef34 5da4efa3 clr!AwareLock::Enter+0x2c1
0404f09c 5d767880 clr!AwareLock::Contention+0x483
0404f1c4 03f00229 clr!JITutil_MonContention+0x2c0
0404eb38 5d9def80 coreclr!Thread::DoAppropriateAptStateWait+0x156
0404ecc4 5d9dd8bb coreclr!Thread::DoAppropriateWaitWorker+0x360
0404ed20 5da628dd coreclr!Thread::DoAppropriateWait+0xbb
0404ede4 5da4e2e2 coreclr!CLREvent::Wait+0x29d
0404ee70 5da4dd41 coreclr!AwareLock::EnterEpilog+0x132
0404ef34 5da4efa3 coreclr!AwareLock::Enter+0x2c1
0404f09c 5d767880 coreclr!AwareLock::Contention+0x483
0404f1c4 03f00229 coreclr!JITutil_MonContention+0x2c0
0404f1f4 5b6ef077 image00400000!Worker.Work()+0x79
...

Expand Down Expand Up @@ -1706,10 +1706,10 @@ VerifyObj <object address>
VerifyObj is a diagnostic tool that checks the object that is passed as an
argument for signs of corruption.

0:002> !verifyobj 028000ec
0:002> verifyobj 028000ec
object 0x28000ec does not have valid method table

0:002> !verifyobj 0680017c
0:002> verifyobj 0680017c
object 0x680017c: bad member 00000001 at 06800184

\\
Expand Down Expand Up @@ -1763,14 +1763,14 @@ generations too, and report those roots.
\\

COMMAND: analyzeoom.
AnalyzeOOM
analyzeoom

AnalyzeOOM displays the info of the last OOM occurred on an allocation request to
the GC heap (in Server GC it displays OOM, if any, on each GC heap).

To see the managed exception(s) use the clrthreads command which will show you
managed exception(s), if any, on each managed thread. If you do see an
OutOfMemoryException exception you can use the !PrintException command on it.
OutOfMemoryException exception you can use the printexception command on it.
To get the full callstack use the "kb" command in the debugger for that thread.
For example, to display thread 3's stack use ~3kb.

Expand All @@ -1785,7 +1785,7 @@ OOM exceptions could be because of the following reasons:
for example, some .NET framework code converts a native OOM exception to managed
and throws it.

The !AnalyzeOOM command aims to help you with investigating 1) which is the most
The analyzeoom command aims to help you with investigating 1) which is the most
difficult because it requires some internal info from GC. The only exception is
we don't support allocating objects larger than 2GB on CLR v2.0 or prior. And this
command will not display any managed OOM because we will throw OOM right away
Expand All @@ -1807,7 +1807,7 @@ The other cases should be fairly obvious from the callstack.

Sample output:

0:011> !analyzeoom
0:011> analyzeoom
---------Heap 2 ---------
Managed OOM occurred after GC #28 (Requested to allocate 1234 bytes)
Reason: Didn't have enough memory to commit
Expand Down Expand Up @@ -2026,7 +2026,7 @@ Here is sample output from a very simple program. Note that the "RefCount"
field only applies to RefCount Handles, and this field will contain the
reference count:

0:000> !GCHandles
0:000> gchandles
Handle Type Object Size RefCount Type
001611c0 Strong 01d00b58 84 System.IndexOutOfRangeException
001611c4 Strong 01d00b58 84 System.IndexOutOfRangeException
Expand Down
Loading