Add CLRMA diagnostic command runnable under dotnet-dump - #5865

Merged
steveisok merged 5 commits into
dotnet:mainfrom
steveisok:add-clrma-cmd
Jun 10, 2026
Merged

Add CLRMA diagnostic command runnable under dotnet-dump#5865
steveisok merged 5 commits into
dotnet:mainfrom
steveisok:add-clrma-cmd

Conversation

@steveisok

Copy link
Copy Markdown
Member

Adds a native SOS 'clrma' command that drives the CLRMA contract (CLRMACreateInstance -> ICLRManagedAnalysis: AssociateClient/GetThread/GetException) and prints the managed thread stack and current/nested exceptions. This lets the Watson/!analyze code path be exercised locally in any SOS host (notably dotnet-dump) without windbg/lldb, as a proxy for Watson bucketing. Registered as a top-level command for DbgEng !clrma parity and framed as a CLRMA-provider diagnostic.

Fixes two latent blockers that only surface in the dotnet-dump host (where Extensions debugger services are null):

  • AssociateClient gated the whole CLRMA path on GetDebuggerServices() != null; now uses the target obtained from the host.

  • InternalOutputVaList/TraceHostingError dereferenced a null GetDebuggerServices() when CLRMA logging was enabled; now null-guarded.

Adds a dotnet-dump-scoped clrma verification to NestedExceptionTest.script and documents the local workflow in documentation/clrma.md.

Adds a native SOS 'clrma' command that drives the CLRMA contract (CLRMACreateInstance -> ICLRManagedAnalysis: AssociateClient/GetThread/GetException) and prints the managed thread stack and current/nested exceptions. This lets the Watson/!analyze code path be exercised locally in any SOS host (notably dotnet-dump) without windbg/lldb, as a proxy for Watson bucketing. Registered as a top-level command for DbgEng !clrma parity and framed as a CLRMA-provider diagnostic.
Fixes two latent blockers that only surface in the dotnet-dump host (where Extensions debugger services are null):
- AssociateClient gated the whole CLRMA path on GetDebuggerServices() != null; now uses the target obtained from the host.
- InternalOutputVaList/TraceHostingError dereferenced a null GetDebuggerServices() when CLRMA logging was enabled; now null-guarded.
Adds a dotnet-dump-scoped clrma verification to NestedExceptionTest.script and documents the local workflow in documentation/clrma.md.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@steveisok
steveisok requested a review from a team as a code ownerJune 6, 2026 00:10
CopilotAI review requested due to automatic review settings June 6, 2026 00:10

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new SOS diagnostic command (clrma) to exercise the CLRMA contract end-to-end in any SOS host (notably dotnet-dump), enabling local validation of the Watson/!analyze managed-analysis path and addressing dotnet-dump-specific null debugger-services scenarios.

Changes:

  • Introduces a new native SOS clrma command that prints managed stack and exception (current/nested) details via ICLRManagedAnalysis.
  • Removes an AssociateClient gate that prevented CLRMA from running when debugger services are unavailable (dotnet-dump host scenario).
  • Adds dotnet-dump-scoped script verification and documents the local workflow in documentation/clrma.md.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
FileDescription
src/tests/SOS.UnitTests/Scripts/NestedExceptionTest.scriptAdds DOTNETDUMP-only validation of clrma output structure (provider + exception type/HResult).
src/SOS/Strike/sos.defExports the new clrma command from the SOS module.
src/SOS/Strike/clrma/managedanalysis.cppAllows CLRMA to proceed even when debugger services are null (dotnet-dump), relying on host target/runtime.
src/SOS/Strike/clrma/clrma.cppImplements the new clrma command and its printing helpers.
src/SOS/SOS.Hosting/Commands/SOSCommand.csRegisters clrma as a top-level hosted command.
src/SOS/extensions/extensions.cppAdds null-guards for missing debugger services to avoid crashes in dotnet-dump scenarios.
documentation/clrma.mdDocuments how to run clrma under dotnet-dump and provides sample output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadsrc/SOS/extensions/extensions.cpp Outdated
Comment threaddocumentation/clrma.md Outdated
steveisokand others added 3 commits June 7, 2026 09:29
The clrma SOS command was only compiled and exported on Windows, so under
dotnet-dump on Linux/macOS it failed with 'Unrecognized SOS command clrma',
breaking the NestedExceptionTest CLRMA verification on every non-Windows leg.
Compile the clrma sources into the Unix SOS build and export clrma in
sos_unixexports.src. Port the native code to the cross-platform debugger
services: source the debug interfaces from the ExtQuery globals (no COM
IDebugClient on Unix), map IDebugControl/IDebugSymbols3 to the available
IDebugControl2/IDebugSymbols compat interfaces, widen ASCII module names from
GetModuleNames (no GetModuleNameStringWide), and guard the last-event-thread
path (no GetThreadIdsByIndex). Use W() literals and basic_string<WCHAR> so
UTF-16 strings match WCHAR/BSTR where wchar_t differs from WCHAR on Unix.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
In _DEBUG builds, debugreturn.h (pulled in via exts.h -> contract.h)
defines 'return' as a macro. The Alpine/musl rootfs uses libstdc++
10.2.1 whose <vector> has constexpr relocate helpers containing
return statements, which break when the macro is active. Including
managedanalysis.h (which pulls in <vector>) before exts.h matches the
sibling files and resolves the compile error.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@noahfalknoahfalk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd only suggest we keep this if we can cut it down to an unseen Windows-only command. I don't think we want to create any customer expectations that this is publicly supported or xplat.

Comment threadsrc/SOS/Strike/clrma/exception.cpp
Comment threadsrc/SOS/Strike/clrma/exception.cpp
m_debugControl = debugControl.Detach();
m_debugSymbols = debugSymbols.Detach();
#else
// On Unix there is no COM IDebugClient. The cross-platform debugger services (ILLDBServices,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to support CLRMA on non-Windows systems? Until we have a scenario that requires it I'd suggest we don't create expand our feature support.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For testing purposes I think having something that works on linux and mac makes sense. I hid the command from the actual help list.

Comment threadsrc/SOS/SOS.Hosting/Commands/SOSCommand.cs Outdated
Make clrma a hidden command and apply review feedback from PR dotnet#5865:
- Add a reusable Hidden flag to CommandAttribute and filter hidden
commands out of the help/soshelp command list (CommandService.
GetAllCommandHelp). The command stays registered and invocable on all
hosts/platforms; it just isn't advertised. clrma is marked Hidden.
- Document why exception.cpp uses W()/manual-copy instead of L"" with
wcslen/wcscpy (wchar_t != WCHAR on Unix; W() yields UTF-16).
- Harden InternalOutputVaList: use int length, guard negative vsnprintf
returns, and always va_end(argsCopy) before returning.
- clrma.md: grammar fix and an internal-validation note clarifying clrma
is not a supported public command.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@steveisok
steveisok merged commit 7a1c84f into dotnet:mainJun 10, 2026
19 checks passed
@steveisok
steveisok deleted the add-clrma-cmd branch June 10, 2026 12:54
@leculver

Copy link
Copy Markdown
Contributor

Hey Steve, this is causing dotnet/runtime cDac tests to fail. The cDac stress is choking on a quirk from how a particular API in the dac returns E_INVALIDPOINTER on a particular valid input. This "fix" resolves the problem by matching the regular dac's odd behavior and fixes the break: dotnet/runtime#129297.

leculver added a commit to dotnet/runtime that referenced this pull request Jun 11, 2026
…ior (#129297)
The legacy DAC (ClrDataAccess::GetObjectStringData) returns E_INVALIDARG
when called on a valid string with no output buffer (stringData == null
or count == 0), while still populating *pNeeded. The cDAC implementation
returned S_OK in that case, which trips the cDAC-vs-DAC HResult parity
assert (SOSDacImpl.cs ValidateHResult) when clrma sizes an exception
string. Mirror the DAC: populate *pNeeded via CopyStringToBuffer, then
return E_INVALIDARG for the no-buffer case.
This fixes the build/test-break in the cDac introduced by
dotnet/diagnostics#5865.
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Jul 12, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@steveisok@leculver@noahfalk
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Add CLRMA diagnostic command runnable under dotnet-dump - #5865

Merged
steveisok merged 5 commits into
dotnet:mainfrom
steveisok:add-clrma-cmd
Jun 10, 2026
Merged

Add CLRMA diagnostic command runnable under dotnet-dump#5865
steveisok merged 5 commits into
dotnet:mainfrom
steveisok:add-clrma-cmd

Conversation

@steveisok

Copy link
Copy Markdown
Member

Adds a native SOS 'clrma' command that drives the CLRMA contract (CLRMACreateInstance -> ICLRManagedAnalysis: AssociateClient/GetThread/GetException) and prints the managed thread stack and current/nested exceptions. This lets the Watson/!analyze code path be exercised locally in any SOS host (notably dotnet-dump) without windbg/lldb, as a proxy for Watson bucketing. Registered as a top-level command for DbgEng !clrma parity and framed as a CLRMA-provider diagnostic.

Fixes two latent blockers that only surface in the dotnet-dump host (where Extensions debugger services are null):

  • AssociateClient gated the whole CLRMA path on GetDebuggerServices() != null; now uses the target obtained from the host.

  • InternalOutputVaList/TraceHostingError dereferenced a null GetDebuggerServices() when CLRMA logging was enabled; now null-guarded.

Adds a dotnet-dump-scoped clrma verification to NestedExceptionTest.script and documents the local workflow in documentation/clrma.md.

Adds a native SOS 'clrma' command that drives the CLRMA contract (CLRMACreateInstance -> ICLRManagedAnalysis: AssociateClient/GetThread/GetException) and prints the managed thread stack and current/nested exceptions. This lets the Watson/!analyze code path be exercised locally in any SOS host (notably dotnet-dump) without windbg/lldb, as a proxy for Watson bucketing. Registered as a top-level command for DbgEng !clrma parity and framed as a CLRMA-provider diagnostic.
Fixes two latent blockers that only surface in the dotnet-dump host (where Extensions debugger services are null):
- AssociateClient gated the whole CLRMA path on GetDebuggerServices() != null; now uses the target obtained from the host.
- InternalOutputVaList/TraceHostingError dereferenced a null GetDebuggerServices() when CLRMA logging was enabled; now null-guarded.
Adds a dotnet-dump-scoped clrma verification to NestedExceptionTest.script and documents the local workflow in documentation/clrma.md.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@steveisok
steveisok requested a review from a team as a code ownerJune 6, 2026 00:10
CopilotAI review requested due to automatic review settings June 6, 2026 00:10

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new SOS diagnostic command (clrma) to exercise the CLRMA contract end-to-end in any SOS host (notably dotnet-dump), enabling local validation of the Watson/!analyze managed-analysis path and addressing dotnet-dump-specific null debugger-services scenarios.

Changes:

  • Introduces a new native SOS clrma command that prints managed stack and exception (current/nested) details via ICLRManagedAnalysis.
  • Removes an AssociateClient gate that prevented CLRMA from running when debugger services are unavailable (dotnet-dump host scenario).
  • Adds dotnet-dump-scoped script verification and documents the local workflow in documentation/clrma.md.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
FileDescription
src/tests/SOS.UnitTests/Scripts/NestedExceptionTest.scriptAdds DOTNETDUMP-only validation of clrma output structure (provider + exception type/HResult).
src/SOS/Strike/sos.defExports the new clrma command from the SOS module.
src/SOS/Strike/clrma/managedanalysis.cppAllows CLRMA to proceed even when debugger services are null (dotnet-dump), relying on host target/runtime.
src/SOS/Strike/clrma/clrma.cppImplements the new clrma command and its printing helpers.
src/SOS/SOS.Hosting/Commands/SOSCommand.csRegisters clrma as a top-level hosted command.
src/SOS/extensions/extensions.cppAdds null-guards for missing debugger services to avoid crashes in dotnet-dump scenarios.
documentation/clrma.mdDocuments how to run clrma under dotnet-dump and provides sample output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadsrc/SOS/extensions/extensions.cpp Outdated
Comment threaddocumentation/clrma.md Outdated
steveisokand others added 3 commits June 7, 2026 09:29
The clrma SOS command was only compiled and exported on Windows, so under
dotnet-dump on Linux/macOS it failed with 'Unrecognized SOS command clrma',
breaking the NestedExceptionTest CLRMA verification on every non-Windows leg.
Compile the clrma sources into the Unix SOS build and export clrma in
sos_unixexports.src. Port the native code to the cross-platform debugger
services: source the debug interfaces from the ExtQuery globals (no COM
IDebugClient on Unix), map IDebugControl/IDebugSymbols3 to the available
IDebugControl2/IDebugSymbols compat interfaces, widen ASCII module names from
GetModuleNames (no GetModuleNameStringWide), and guard the last-event-thread
path (no GetThreadIdsByIndex). Use W() literals and basic_string<WCHAR> so
UTF-16 strings match WCHAR/BSTR where wchar_t differs from WCHAR on Unix.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
In _DEBUG builds, debugreturn.h (pulled in via exts.h -> contract.h)
defines 'return' as a macro. The Alpine/musl rootfs uses libstdc++
10.2.1 whose <vector> has constexpr relocate helpers containing
return statements, which break when the macro is active. Including
managedanalysis.h (which pulls in <vector>) before exts.h matches the
sibling files and resolves the compile error.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@noahfalknoahfalk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd only suggest we keep this if we can cut it down to an unseen Windows-only command. I don't think we want to create any customer expectations that this is publicly supported or xplat.

Comment threadsrc/SOS/Strike/clrma/exception.cpp
Comment threadsrc/SOS/Strike/clrma/exception.cpp
m_debugControl = debugControl.Detach();
m_debugSymbols = debugSymbols.Detach();
#else
// On Unix there is no COM IDebugClient. The cross-platform debugger services (ILLDBServices,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to support CLRMA on non-Windows systems? Until we have a scenario that requires it I'd suggest we don't create expand our feature support.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For testing purposes I think having something that works on linux and mac makes sense. I hid the command from the actual help list.

Comment threadsrc/SOS/SOS.Hosting/Commands/SOSCommand.cs Outdated
Make clrma a hidden command and apply review feedback from PR dotnet#5865:
- Add a reusable Hidden flag to CommandAttribute and filter hidden
commands out of the help/soshelp command list (CommandService.
GetAllCommandHelp). The command stays registered and invocable on all
hosts/platforms; it just isn't advertised. clrma is marked Hidden.
- Document why exception.cpp uses W()/manual-copy instead of L"" with
wcslen/wcscpy (wchar_t != WCHAR on Unix; W() yields UTF-16).
- Harden InternalOutputVaList: use int length, guard negative vsnprintf
returns, and always va_end(argsCopy) before returning.
- clrma.md: grammar fix and an internal-validation note clarifying clrma
is not a supported public command.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@steveisok
steveisok merged commit 7a1c84f into dotnet:mainJun 10, 2026
19 checks passed
@steveisok
steveisok deleted the add-clrma-cmd branch June 10, 2026 12:54
@leculver

Copy link
Copy Markdown
Contributor

Hey Steve, this is causing dotnet/runtime cDac tests to fail. The cDac stress is choking on a quirk from how a particular API in the dac returns E_INVALIDPOINTER on a particular valid input. This "fix" resolves the problem by matching the regular dac's odd behavior and fixes the break: dotnet/runtime#129297.

leculver added a commit to dotnet/runtime that referenced this pull request Jun 11, 2026
…ior (#129297)
The legacy DAC (ClrDataAccess::GetObjectStringData) returns E_INVALIDARG
when called on a valid string with no output buffer (stringData == null
or count == 0), while still populating *pNeeded. The cDAC implementation
returned S_OK in that case, which trips the cDAC-vs-DAC HResult parity
assert (SOSDacImpl.cs ValidateHResult) when clrma sizes an exception
string. Mirror the DAC: populate *pNeeded via CopyStringToBuffer, then
return E_INVALIDARG for the no-buffer case.
This fixes the build/test-break in the cDac introduced by
dotnet/diagnostics#5865.
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Jul 12, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@steveisok@leculver@noahfalk
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Add CLRMA diagnostic command runnable under dotnet-dump - #5865

Merged
steveisok merged 5 commits into
dotnet:mainfrom
steveisok:add-clrma-cmd
Jun 10, 2026
Merged

Add CLRMA diagnostic command runnable under dotnet-dump#5865
steveisok merged 5 commits into
dotnet:mainfrom
steveisok:add-clrma-cmd

Conversation

@steveisok

Copy link
Copy Markdown
Member

Adds a native SOS 'clrma' command that drives the CLRMA contract (CLRMACreateInstance -> ICLRManagedAnalysis: AssociateClient/GetThread/GetException) and prints the managed thread stack and current/nested exceptions. This lets the Watson/!analyze code path be exercised locally in any SOS host (notably dotnet-dump) without windbg/lldb, as a proxy for Watson bucketing. Registered as a top-level command for DbgEng !clrma parity and framed as a CLRMA-provider diagnostic.

Fixes two latent blockers that only surface in the dotnet-dump host (where Extensions debugger services are null):

  • AssociateClient gated the whole CLRMA path on GetDebuggerServices() != null; now uses the target obtained from the host.

  • InternalOutputVaList/TraceHostingError dereferenced a null GetDebuggerServices() when CLRMA logging was enabled; now null-guarded.

Adds a dotnet-dump-scoped clrma verification to NestedExceptionTest.script and documents the local workflow in documentation/clrma.md.

Adds a native SOS 'clrma' command that drives the CLRMA contract (CLRMACreateInstance -> ICLRManagedAnalysis: AssociateClient/GetThread/GetException) and prints the managed thread stack and current/nested exceptions. This lets the Watson/!analyze code path be exercised locally in any SOS host (notably dotnet-dump) without windbg/lldb, as a proxy for Watson bucketing. Registered as a top-level command for DbgEng !clrma parity and framed as a CLRMA-provider diagnostic.
Fixes two latent blockers that only surface in the dotnet-dump host (where Extensions debugger services are null):
- AssociateClient gated the whole CLRMA path on GetDebuggerServices() != null; now uses the target obtained from the host.
- InternalOutputVaList/TraceHostingError dereferenced a null GetDebuggerServices() when CLRMA logging was enabled; now null-guarded.
Adds a dotnet-dump-scoped clrma verification to NestedExceptionTest.script and documents the local workflow in documentation/clrma.md.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@steveisok
steveisok requested a review from a team as a code ownerJune 6, 2026 00:10
CopilotAI review requested due to automatic review settings June 6, 2026 00:10

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new SOS diagnostic command (clrma) to exercise the CLRMA contract end-to-end in any SOS host (notably dotnet-dump), enabling local validation of the Watson/!analyze managed-analysis path and addressing dotnet-dump-specific null debugger-services scenarios.

Changes:

  • Introduces a new native SOS clrma command that prints managed stack and exception (current/nested) details via ICLRManagedAnalysis.
  • Removes an AssociateClient gate that prevented CLRMA from running when debugger services are unavailable (dotnet-dump host scenario).
  • Adds dotnet-dump-scoped script verification and documents the local workflow in documentation/clrma.md.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
FileDescription
src/tests/SOS.UnitTests/Scripts/NestedExceptionTest.scriptAdds DOTNETDUMP-only validation of clrma output structure (provider + exception type/HResult).
src/SOS/Strike/sos.defExports the new clrma command from the SOS module.
src/SOS/Strike/clrma/managedanalysis.cppAllows CLRMA to proceed even when debugger services are null (dotnet-dump), relying on host target/runtime.
src/SOS/Strike/clrma/clrma.cppImplements the new clrma command and its printing helpers.
src/SOS/SOS.Hosting/Commands/SOSCommand.csRegisters clrma as a top-level hosted command.
src/SOS/extensions/extensions.cppAdds null-guards for missing debugger services to avoid crashes in dotnet-dump scenarios.
documentation/clrma.mdDocuments how to run clrma under dotnet-dump and provides sample output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadsrc/SOS/extensions/extensions.cpp Outdated
Comment threaddocumentation/clrma.md Outdated
steveisokand others added 3 commits June 7, 2026 09:29
The clrma SOS command was only compiled and exported on Windows, so under
dotnet-dump on Linux/macOS it failed with 'Unrecognized SOS command clrma',
breaking the NestedExceptionTest CLRMA verification on every non-Windows leg.
Compile the clrma sources into the Unix SOS build and export clrma in
sos_unixexports.src. Port the native code to the cross-platform debugger
services: source the debug interfaces from the ExtQuery globals (no COM
IDebugClient on Unix), map IDebugControl/IDebugSymbols3 to the available
IDebugControl2/IDebugSymbols compat interfaces, widen ASCII module names from
GetModuleNames (no GetModuleNameStringWide), and guard the last-event-thread
path (no GetThreadIdsByIndex). Use W() literals and basic_string<WCHAR> so
UTF-16 strings match WCHAR/BSTR where wchar_t differs from WCHAR on Unix.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
In _DEBUG builds, debugreturn.h (pulled in via exts.h -> contract.h)
defines 'return' as a macro. The Alpine/musl rootfs uses libstdc++
10.2.1 whose <vector> has constexpr relocate helpers containing
return statements, which break when the macro is active. Including
managedanalysis.h (which pulls in <vector>) before exts.h matches the
sibling files and resolves the compile error.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@noahfalknoahfalk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd only suggest we keep this if we can cut it down to an unseen Windows-only command. I don't think we want to create any customer expectations that this is publicly supported or xplat.

Comment threadsrc/SOS/Strike/clrma/exception.cpp
Comment threadsrc/SOS/Strike/clrma/exception.cpp
m_debugControl = debugControl.Detach();
m_debugSymbols = debugSymbols.Detach();
#else
// On Unix there is no COM IDebugClient. The cross-platform debugger services (ILLDBServices,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to support CLRMA on non-Windows systems? Until we have a scenario that requires it I'd suggest we don't create expand our feature support.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For testing purposes I think having something that works on linux and mac makes sense. I hid the command from the actual help list.

Comment threadsrc/SOS/SOS.Hosting/Commands/SOSCommand.cs Outdated
Make clrma a hidden command and apply review feedback from PR dotnet#5865:
- Add a reusable Hidden flag to CommandAttribute and filter hidden
commands out of the help/soshelp command list (CommandService.
GetAllCommandHelp). The command stays registered and invocable on all
hosts/platforms; it just isn't advertised. clrma is marked Hidden.
- Document why exception.cpp uses W()/manual-copy instead of L"" with
wcslen/wcscpy (wchar_t != WCHAR on Unix; W() yields UTF-16).
- Harden InternalOutputVaList: use int length, guard negative vsnprintf
returns, and always va_end(argsCopy) before returning.
- clrma.md: grammar fix and an internal-validation note clarifying clrma
is not a supported public command.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@steveisok
steveisok merged commit 7a1c84f into dotnet:mainJun 10, 2026
19 checks passed
@steveisok
steveisok deleted the add-clrma-cmd branch June 10, 2026 12:54
@leculver

Copy link
Copy Markdown
Contributor

Hey Steve, this is causing dotnet/runtime cDac tests to fail. The cDac stress is choking on a quirk from how a particular API in the dac returns E_INVALIDPOINTER on a particular valid input. This "fix" resolves the problem by matching the regular dac's odd behavior and fixes the break: dotnet/runtime#129297.

leculver added a commit to dotnet/runtime that referenced this pull request Jun 11, 2026
…ior (#129297)
The legacy DAC (ClrDataAccess::GetObjectStringData) returns E_INVALIDARG
when called on a valid string with no output buffer (stringData == null
or count == 0), while still populating *pNeeded. The cDAC implementation
returned S_OK in that case, which trips the cDAC-vs-DAC HResult parity
assert (SOSDacImpl.cs ValidateHResult) when clrma sizes an exception
string. Mirror the DAC: populate *pNeeded via CopyStringToBuffer, then
return E_INVALIDARG for the no-buffer case.
This fixes the build/test-break in the cDac introduced by
dotnet/diagnostics#5865.
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Jul 12, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@steveisok@leculver@noahfalk
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Add CLRMA diagnostic command runnable under dotnet-dump - #5865

Merged
steveisok merged 5 commits into
dotnet:mainfrom
steveisok:add-clrma-cmd
Jun 10, 2026
Merged

Add CLRMA diagnostic command runnable under dotnet-dump#5865
steveisok merged 5 commits into
dotnet:mainfrom
steveisok:add-clrma-cmd

Conversation

@steveisok

Copy link
Copy Markdown
Member

Adds a native SOS 'clrma' command that drives the CLRMA contract (CLRMACreateInstance -> ICLRManagedAnalysis: AssociateClient/GetThread/GetException) and prints the managed thread stack and current/nested exceptions. This lets the Watson/!analyze code path be exercised locally in any SOS host (notably dotnet-dump) without windbg/lldb, as a proxy for Watson bucketing. Registered as a top-level command for DbgEng !clrma parity and framed as a CLRMA-provider diagnostic.

Fixes two latent blockers that only surface in the dotnet-dump host (where Extensions debugger services are null):

  • AssociateClient gated the whole CLRMA path on GetDebuggerServices() != null; now uses the target obtained from the host.

  • InternalOutputVaList/TraceHostingError dereferenced a null GetDebuggerServices() when CLRMA logging was enabled; now null-guarded.

Adds a dotnet-dump-scoped clrma verification to NestedExceptionTest.script and documents the local workflow in documentation/clrma.md.

Adds a native SOS 'clrma' command that drives the CLRMA contract (CLRMACreateInstance -> ICLRManagedAnalysis: AssociateClient/GetThread/GetException) and prints the managed thread stack and current/nested exceptions. This lets the Watson/!analyze code path be exercised locally in any SOS host (notably dotnet-dump) without windbg/lldb, as a proxy for Watson bucketing. Registered as a top-level command for DbgEng !clrma parity and framed as a CLRMA-provider diagnostic.
Fixes two latent blockers that only surface in the dotnet-dump host (where Extensions debugger services are null):
- AssociateClient gated the whole CLRMA path on GetDebuggerServices() != null; now uses the target obtained from the host.
- InternalOutputVaList/TraceHostingError dereferenced a null GetDebuggerServices() when CLRMA logging was enabled; now null-guarded.
Adds a dotnet-dump-scoped clrma verification to NestedExceptionTest.script and documents the local workflow in documentation/clrma.md.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@steveisok
steveisok requested a review from a team as a code ownerJune 6, 2026 00:10
CopilotAI review requested due to automatic review settings June 6, 2026 00:10

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new SOS diagnostic command (clrma) to exercise the CLRMA contract end-to-end in any SOS host (notably dotnet-dump), enabling local validation of the Watson/!analyze managed-analysis path and addressing dotnet-dump-specific null debugger-services scenarios.

Changes:

  • Introduces a new native SOS clrma command that prints managed stack and exception (current/nested) details via ICLRManagedAnalysis.
  • Removes an AssociateClient gate that prevented CLRMA from running when debugger services are unavailable (dotnet-dump host scenario).
  • Adds dotnet-dump-scoped script verification and documents the local workflow in documentation/clrma.md.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
FileDescription
src/tests/SOS.UnitTests/Scripts/NestedExceptionTest.scriptAdds DOTNETDUMP-only validation of clrma output structure (provider + exception type/HResult).
src/SOS/Strike/sos.defExports the new clrma command from the SOS module.
src/SOS/Strike/clrma/managedanalysis.cppAllows CLRMA to proceed even when debugger services are null (dotnet-dump), relying on host target/runtime.
src/SOS/Strike/clrma/clrma.cppImplements the new clrma command and its printing helpers.
src/SOS/SOS.Hosting/Commands/SOSCommand.csRegisters clrma as a top-level hosted command.
src/SOS/extensions/extensions.cppAdds null-guards for missing debugger services to avoid crashes in dotnet-dump scenarios.
documentation/clrma.mdDocuments how to run clrma under dotnet-dump and provides sample output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadsrc/SOS/extensions/extensions.cpp Outdated
Comment threaddocumentation/clrma.md Outdated
steveisokand others added 3 commits June 7, 2026 09:29
The clrma SOS command was only compiled and exported on Windows, so under
dotnet-dump on Linux/macOS it failed with 'Unrecognized SOS command clrma',
breaking the NestedExceptionTest CLRMA verification on every non-Windows leg.
Compile the clrma sources into the Unix SOS build and export clrma in
sos_unixexports.src. Port the native code to the cross-platform debugger
services: source the debug interfaces from the ExtQuery globals (no COM
IDebugClient on Unix), map IDebugControl/IDebugSymbols3 to the available
IDebugControl2/IDebugSymbols compat interfaces, widen ASCII module names from
GetModuleNames (no GetModuleNameStringWide), and guard the last-event-thread
path (no GetThreadIdsByIndex). Use W() literals and basic_string<WCHAR> so
UTF-16 strings match WCHAR/BSTR where wchar_t differs from WCHAR on Unix.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
In _DEBUG builds, debugreturn.h (pulled in via exts.h -> contract.h)
defines 'return' as a macro. The Alpine/musl rootfs uses libstdc++
10.2.1 whose <vector> has constexpr relocate helpers containing
return statements, which break when the macro is active. Including
managedanalysis.h (which pulls in <vector>) before exts.h matches the
sibling files and resolves the compile error.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@noahfalknoahfalk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd only suggest we keep this if we can cut it down to an unseen Windows-only command. I don't think we want to create any customer expectations that this is publicly supported or xplat.

Comment threadsrc/SOS/Strike/clrma/exception.cpp
Comment threadsrc/SOS/Strike/clrma/exception.cpp
m_debugControl = debugControl.Detach();
m_debugSymbols = debugSymbols.Detach();
#else
// On Unix there is no COM IDebugClient. The cross-platform debugger services (ILLDBServices,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to support CLRMA on non-Windows systems? Until we have a scenario that requires it I'd suggest we don't create expand our feature support.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For testing purposes I think having something that works on linux and mac makes sense. I hid the command from the actual help list.

Comment threadsrc/SOS/SOS.Hosting/Commands/SOSCommand.cs Outdated
Make clrma a hidden command and apply review feedback from PR dotnet#5865:
- Add a reusable Hidden flag to CommandAttribute and filter hidden
commands out of the help/soshelp command list (CommandService.
GetAllCommandHelp). The command stays registered and invocable on all
hosts/platforms; it just isn't advertised. clrma is marked Hidden.
- Document why exception.cpp uses W()/manual-copy instead of L"" with
wcslen/wcscpy (wchar_t != WCHAR on Unix; W() yields UTF-16).
- Harden InternalOutputVaList: use int length, guard negative vsnprintf
returns, and always va_end(argsCopy) before returning.
- clrma.md: grammar fix and an internal-validation note clarifying clrma
is not a supported public command.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@steveisok
steveisok merged commit 7a1c84f into dotnet:mainJun 10, 2026
19 checks passed
@steveisok
steveisok deleted the add-clrma-cmd branch June 10, 2026 12:54
@leculver

Copy link
Copy Markdown
Contributor

Hey Steve, this is causing dotnet/runtime cDac tests to fail. The cDac stress is choking on a quirk from how a particular API in the dac returns E_INVALIDPOINTER on a particular valid input. This "fix" resolves the problem by matching the regular dac's odd behavior and fixes the break: dotnet/runtime#129297.

leculver added a commit to dotnet/runtime that referenced this pull request Jun 11, 2026
…ior (#129297)
The legacy DAC (ClrDataAccess::GetObjectStringData) returns E_INVALIDARG
when called on a valid string with no output buffer (stringData == null
or count == 0), while still populating *pNeeded. The cDAC implementation
returned S_OK in that case, which trips the cDAC-vs-DAC HResult parity
assert (SOSDacImpl.cs ValidateHResult) when clrma sizes an exception
string. Mirror the DAC: populate *pNeeded via CopyStringToBuffer, then
return E_INVALIDARG for the no-buffer case.
This fixes the build/test-break in the cDac introduced by
dotnet/diagnostics#5865.
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Jul 12, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@steveisok@leculver@noahfalk
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Add CLRMA diagnostic command runnable under dotnet-dump - #5865

Merged
steveisok merged 5 commits into
dotnet:mainfrom
steveisok:add-clrma-cmd
Jun 10, 2026
Merged

Add CLRMA diagnostic command runnable under dotnet-dump#5865
steveisok merged 5 commits into
dotnet:mainfrom
steveisok:add-clrma-cmd

Conversation

@steveisok

Copy link
Copy Markdown
Member

Adds a native SOS 'clrma' command that drives the CLRMA contract (CLRMACreateInstance -> ICLRManagedAnalysis: AssociateClient/GetThread/GetException) and prints the managed thread stack and current/nested exceptions. This lets the Watson/!analyze code path be exercised locally in any SOS host (notably dotnet-dump) without windbg/lldb, as a proxy for Watson bucketing. Registered as a top-level command for DbgEng !clrma parity and framed as a CLRMA-provider diagnostic.

Fixes two latent blockers that only surface in the dotnet-dump host (where Extensions debugger services are null):

  • AssociateClient gated the whole CLRMA path on GetDebuggerServices() != null; now uses the target obtained from the host.

  • InternalOutputVaList/TraceHostingError dereferenced a null GetDebuggerServices() when CLRMA logging was enabled; now null-guarded.

Adds a dotnet-dump-scoped clrma verification to NestedExceptionTest.script and documents the local workflow in documentation/clrma.md.

Adds a native SOS 'clrma' command that drives the CLRMA contract (CLRMACreateInstance -> ICLRManagedAnalysis: AssociateClient/GetThread/GetException) and prints the managed thread stack and current/nested exceptions. This lets the Watson/!analyze code path be exercised locally in any SOS host (notably dotnet-dump) without windbg/lldb, as a proxy for Watson bucketing. Registered as a top-level command for DbgEng !clrma parity and framed as a CLRMA-provider diagnostic.
Fixes two latent blockers that only surface in the dotnet-dump host (where Extensions debugger services are null):
- AssociateClient gated the whole CLRMA path on GetDebuggerServices() != null; now uses the target obtained from the host.
- InternalOutputVaList/TraceHostingError dereferenced a null GetDebuggerServices() when CLRMA logging was enabled; now null-guarded.
Adds a dotnet-dump-scoped clrma verification to NestedExceptionTest.script and documents the local workflow in documentation/clrma.md.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@steveisok
steveisok requested a review from a team as a code ownerJune 6, 2026 00:10
CopilotAI review requested due to automatic review settings June 6, 2026 00:10

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new SOS diagnostic command (clrma) to exercise the CLRMA contract end-to-end in any SOS host (notably dotnet-dump), enabling local validation of the Watson/!analyze managed-analysis path and addressing dotnet-dump-specific null debugger-services scenarios.

Changes:

  • Introduces a new native SOS clrma command that prints managed stack and exception (current/nested) details via ICLRManagedAnalysis.
  • Removes an AssociateClient gate that prevented CLRMA from running when debugger services are unavailable (dotnet-dump host scenario).
  • Adds dotnet-dump-scoped script verification and documents the local workflow in documentation/clrma.md.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
FileDescription
src/tests/SOS.UnitTests/Scripts/NestedExceptionTest.scriptAdds DOTNETDUMP-only validation of clrma output structure (provider + exception type/HResult).
src/SOS/Strike/sos.defExports the new clrma command from the SOS module.
src/SOS/Strike/clrma/managedanalysis.cppAllows CLRMA to proceed even when debugger services are null (dotnet-dump), relying on host target/runtime.
src/SOS/Strike/clrma/clrma.cppImplements the new clrma command and its printing helpers.
src/SOS/SOS.Hosting/Commands/SOSCommand.csRegisters clrma as a top-level hosted command.
src/SOS/extensions/extensions.cppAdds null-guards for missing debugger services to avoid crashes in dotnet-dump scenarios.
documentation/clrma.mdDocuments how to run clrma under dotnet-dump and provides sample output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadsrc/SOS/extensions/extensions.cpp Outdated
Comment threaddocumentation/clrma.md Outdated
steveisokand others added 3 commits June 7, 2026 09:29
The clrma SOS command was only compiled and exported on Windows, so under
dotnet-dump on Linux/macOS it failed with 'Unrecognized SOS command clrma',
breaking the NestedExceptionTest CLRMA verification on every non-Windows leg.
Compile the clrma sources into the Unix SOS build and export clrma in
sos_unixexports.src. Port the native code to the cross-platform debugger
services: source the debug interfaces from the ExtQuery globals (no COM
IDebugClient on Unix), map IDebugControl/IDebugSymbols3 to the available
IDebugControl2/IDebugSymbols compat interfaces, widen ASCII module names from
GetModuleNames (no GetModuleNameStringWide), and guard the last-event-thread
path (no GetThreadIdsByIndex). Use W() literals and basic_string<WCHAR> so
UTF-16 strings match WCHAR/BSTR where wchar_t differs from WCHAR on Unix.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
In _DEBUG builds, debugreturn.h (pulled in via exts.h -> contract.h)
defines 'return' as a macro. The Alpine/musl rootfs uses libstdc++
10.2.1 whose <vector> has constexpr relocate helpers containing
return statements, which break when the macro is active. Including
managedanalysis.h (which pulls in <vector>) before exts.h matches the
sibling files and resolves the compile error.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@noahfalknoahfalk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd only suggest we keep this if we can cut it down to an unseen Windows-only command. I don't think we want to create any customer expectations that this is publicly supported or xplat.

Comment threadsrc/SOS/Strike/clrma/exception.cpp
Comment threadsrc/SOS/Strike/clrma/exception.cpp
m_debugControl = debugControl.Detach();
m_debugSymbols = debugSymbols.Detach();
#else
// On Unix there is no COM IDebugClient. The cross-platform debugger services (ILLDBServices,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to support CLRMA on non-Windows systems? Until we have a scenario that requires it I'd suggest we don't create expand our feature support.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For testing purposes I think having something that works on linux and mac makes sense. I hid the command from the actual help list.

Comment threadsrc/SOS/SOS.Hosting/Commands/SOSCommand.cs Outdated
Make clrma a hidden command and apply review feedback from PR dotnet#5865:
- Add a reusable Hidden flag to CommandAttribute and filter hidden
commands out of the help/soshelp command list (CommandService.
GetAllCommandHelp). The command stays registered and invocable on all
hosts/platforms; it just isn't advertised. clrma is marked Hidden.
- Document why exception.cpp uses W()/manual-copy instead of L"" with
wcslen/wcscpy (wchar_t != WCHAR on Unix; W() yields UTF-16).
- Harden InternalOutputVaList: use int length, guard negative vsnprintf
returns, and always va_end(argsCopy) before returning.
- clrma.md: grammar fix and an internal-validation note clarifying clrma
is not a supported public command.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@steveisok
steveisok merged commit 7a1c84f into dotnet:mainJun 10, 2026
19 checks passed
@steveisok
steveisok deleted the add-clrma-cmd branch June 10, 2026 12:54
@leculver

Copy link
Copy Markdown
Contributor

Hey Steve, this is causing dotnet/runtime cDac tests to fail. The cDac stress is choking on a quirk from how a particular API in the dac returns E_INVALIDPOINTER on a particular valid input. This "fix" resolves the problem by matching the regular dac's odd behavior and fixes the break: dotnet/runtime#129297.

leculver added a commit to dotnet/runtime that referenced this pull request Jun 11, 2026
…ior (#129297)
The legacy DAC (ClrDataAccess::GetObjectStringData) returns E_INVALIDARG
when called on a valid string with no output buffer (stringData == null
or count == 0), while still populating *pNeeded. The cDAC implementation
returned S_OK in that case, which trips the cDAC-vs-DAC HResult parity
assert (SOSDacImpl.cs ValidateHResult) when clrma sizes an exception
string. Mirror the DAC: populate *pNeeded via CopyStringToBuffer, then
return E_INVALIDARG for the no-buffer case.
This fixes the build/test-break in the cDac introduced by
dotnet/diagnostics#5865.
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Jul 12, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@steveisok@leculver@noahfalk
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Add CLRMA diagnostic command runnable under dotnet-dump - #5865

Merged
steveisok merged 5 commits into
dotnet:mainfrom
steveisok:add-clrma-cmd
Jun 10, 2026
Merged

Add CLRMA diagnostic command runnable under dotnet-dump#5865
steveisok merged 5 commits into
dotnet:mainfrom
steveisok:add-clrma-cmd

Conversation

@steveisok

Copy link
Copy Markdown
Member

Adds a native SOS 'clrma' command that drives the CLRMA contract (CLRMACreateInstance -> ICLRManagedAnalysis: AssociateClient/GetThread/GetException) and prints the managed thread stack and current/nested exceptions. This lets the Watson/!analyze code path be exercised locally in any SOS host (notably dotnet-dump) without windbg/lldb, as a proxy for Watson bucketing. Registered as a top-level command for DbgEng !clrma parity and framed as a CLRMA-provider diagnostic.

Fixes two latent blockers that only surface in the dotnet-dump host (where Extensions debugger services are null):

  • AssociateClient gated the whole CLRMA path on GetDebuggerServices() != null; now uses the target obtained from the host.

  • InternalOutputVaList/TraceHostingError dereferenced a null GetDebuggerServices() when CLRMA logging was enabled; now null-guarded.

Adds a dotnet-dump-scoped clrma verification to NestedExceptionTest.script and documents the local workflow in documentation/clrma.md.

Adds a native SOS 'clrma' command that drives the CLRMA contract (CLRMACreateInstance -> ICLRManagedAnalysis: AssociateClient/GetThread/GetException) and prints the managed thread stack and current/nested exceptions. This lets the Watson/!analyze code path be exercised locally in any SOS host (notably dotnet-dump) without windbg/lldb, as a proxy for Watson bucketing. Registered as a top-level command for DbgEng !clrma parity and framed as a CLRMA-provider diagnostic.
Fixes two latent blockers that only surface in the dotnet-dump host (where Extensions debugger services are null):
- AssociateClient gated the whole CLRMA path on GetDebuggerServices() != null; now uses the target obtained from the host.
- InternalOutputVaList/TraceHostingError dereferenced a null GetDebuggerServices() when CLRMA logging was enabled; now null-guarded.
Adds a dotnet-dump-scoped clrma verification to NestedExceptionTest.script and documents the local workflow in documentation/clrma.md.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@steveisok
steveisok requested a review from a team as a code ownerJune 6, 2026 00:10
CopilotAI review requested due to automatic review settings June 6, 2026 00:10

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new SOS diagnostic command (clrma) to exercise the CLRMA contract end-to-end in any SOS host (notably dotnet-dump), enabling local validation of the Watson/!analyze managed-analysis path and addressing dotnet-dump-specific null debugger-services scenarios.

Changes:

  • Introduces a new native SOS clrma command that prints managed stack and exception (current/nested) details via ICLRManagedAnalysis.
  • Removes an AssociateClient gate that prevented CLRMA from running when debugger services are unavailable (dotnet-dump host scenario).
  • Adds dotnet-dump-scoped script verification and documents the local workflow in documentation/clrma.md.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
FileDescription
src/tests/SOS.UnitTests/Scripts/NestedExceptionTest.scriptAdds DOTNETDUMP-only validation of clrma output structure (provider + exception type/HResult).
src/SOS/Strike/sos.defExports the new clrma command from the SOS module.
src/SOS/Strike/clrma/managedanalysis.cppAllows CLRMA to proceed even when debugger services are null (dotnet-dump), relying on host target/runtime.
src/SOS/Strike/clrma/clrma.cppImplements the new clrma command and its printing helpers.
src/SOS/SOS.Hosting/Commands/SOSCommand.csRegisters clrma as a top-level hosted command.
src/SOS/extensions/extensions.cppAdds null-guards for missing debugger services to avoid crashes in dotnet-dump scenarios.
documentation/clrma.mdDocuments how to run clrma under dotnet-dump and provides sample output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadsrc/SOS/extensions/extensions.cpp Outdated
Comment threaddocumentation/clrma.md Outdated
steveisokand others added 3 commits June 7, 2026 09:29
The clrma SOS command was only compiled and exported on Windows, so under
dotnet-dump on Linux/macOS it failed with 'Unrecognized SOS command clrma',
breaking the NestedExceptionTest CLRMA verification on every non-Windows leg.
Compile the clrma sources into the Unix SOS build and export clrma in
sos_unixexports.src. Port the native code to the cross-platform debugger
services: source the debug interfaces from the ExtQuery globals (no COM
IDebugClient on Unix), map IDebugControl/IDebugSymbols3 to the available
IDebugControl2/IDebugSymbols compat interfaces, widen ASCII module names from
GetModuleNames (no GetModuleNameStringWide), and guard the last-event-thread
path (no GetThreadIdsByIndex). Use W() literals and basic_string<WCHAR> so
UTF-16 strings match WCHAR/BSTR where wchar_t differs from WCHAR on Unix.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
In _DEBUG builds, debugreturn.h (pulled in via exts.h -> contract.h)
defines 'return' as a macro. The Alpine/musl rootfs uses libstdc++
10.2.1 whose <vector> has constexpr relocate helpers containing
return statements, which break when the macro is active. Including
managedanalysis.h (which pulls in <vector>) before exts.h matches the
sibling files and resolves the compile error.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@noahfalknoahfalk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd only suggest we keep this if we can cut it down to an unseen Windows-only command. I don't think we want to create any customer expectations that this is publicly supported or xplat.

Comment threadsrc/SOS/Strike/clrma/exception.cpp
Comment threadsrc/SOS/Strike/clrma/exception.cpp
m_debugControl = debugControl.Detach();
m_debugSymbols = debugSymbols.Detach();
#else
// On Unix there is no COM IDebugClient. The cross-platform debugger services (ILLDBServices,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to support CLRMA on non-Windows systems? Until we have a scenario that requires it I'd suggest we don't create expand our feature support.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For testing purposes I think having something that works on linux and mac makes sense. I hid the command from the actual help list.

Comment threadsrc/SOS/SOS.Hosting/Commands/SOSCommand.cs Outdated
Make clrma a hidden command and apply review feedback from PR dotnet#5865:
- Add a reusable Hidden flag to CommandAttribute and filter hidden
commands out of the help/soshelp command list (CommandService.
GetAllCommandHelp). The command stays registered and invocable on all
hosts/platforms; it just isn't advertised. clrma is marked Hidden.
- Document why exception.cpp uses W()/manual-copy instead of L"" with
wcslen/wcscpy (wchar_t != WCHAR on Unix; W() yields UTF-16).
- Harden InternalOutputVaList: use int length, guard negative vsnprintf
returns, and always va_end(argsCopy) before returning.
- clrma.md: grammar fix and an internal-validation note clarifying clrma
is not a supported public command.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@steveisok
steveisok merged commit 7a1c84f into dotnet:mainJun 10, 2026
19 checks passed
@steveisok
steveisok deleted the add-clrma-cmd branch June 10, 2026 12:54
@leculver

Copy link
Copy Markdown
Contributor

Hey Steve, this is causing dotnet/runtime cDac tests to fail. The cDac stress is choking on a quirk from how a particular API in the dac returns E_INVALIDPOINTER on a particular valid input. This "fix" resolves the problem by matching the regular dac's odd behavior and fixes the break: dotnet/runtime#129297.

leculver added a commit to dotnet/runtime that referenced this pull request Jun 11, 2026
…ior (#129297)
The legacy DAC (ClrDataAccess::GetObjectStringData) returns E_INVALIDARG
when called on a valid string with no output buffer (stringData == null
or count == 0), while still populating *pNeeded. The cDAC implementation
returned S_OK in that case, which trips the cDAC-vs-DAC HResult parity
assert (SOSDacImpl.cs ValidateHResult) when clrma sizes an exception
string. Mirror the DAC: populate *pNeeded via CopyStringToBuffer, then
return E_INVALIDARG for the no-buffer case.
This fixes the build/test-break in the cDac introduced by
dotnet/diagnostics#5865.
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Jul 12, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@steveisok@leculver@noahfalk
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Add CLRMA diagnostic command runnable under dotnet-dump - #5865

Merged
steveisok merged 5 commits into
dotnet:mainfrom
steveisok:add-clrma-cmd
Jun 10, 2026
Merged

Add CLRMA diagnostic command runnable under dotnet-dump#5865
steveisok merged 5 commits into
dotnet:mainfrom
steveisok:add-clrma-cmd

Conversation

@steveisok

Copy link
Copy Markdown
Member

Adds a native SOS 'clrma' command that drives the CLRMA contract (CLRMACreateInstance -> ICLRManagedAnalysis: AssociateClient/GetThread/GetException) and prints the managed thread stack and current/nested exceptions. This lets the Watson/!analyze code path be exercised locally in any SOS host (notably dotnet-dump) without windbg/lldb, as a proxy for Watson bucketing. Registered as a top-level command for DbgEng !clrma parity and framed as a CLRMA-provider diagnostic.

Fixes two latent blockers that only surface in the dotnet-dump host (where Extensions debugger services are null):

  • AssociateClient gated the whole CLRMA path on GetDebuggerServices() != null; now uses the target obtained from the host.

  • InternalOutputVaList/TraceHostingError dereferenced a null GetDebuggerServices() when CLRMA logging was enabled; now null-guarded.

Adds a dotnet-dump-scoped clrma verification to NestedExceptionTest.script and documents the local workflow in documentation/clrma.md.

Adds a native SOS 'clrma' command that drives the CLRMA contract (CLRMACreateInstance -> ICLRManagedAnalysis: AssociateClient/GetThread/GetException) and prints the managed thread stack and current/nested exceptions. This lets the Watson/!analyze code path be exercised locally in any SOS host (notably dotnet-dump) without windbg/lldb, as a proxy for Watson bucketing. Registered as a top-level command for DbgEng !clrma parity and framed as a CLRMA-provider diagnostic.
Fixes two latent blockers that only surface in the dotnet-dump host (where Extensions debugger services are null):
- AssociateClient gated the whole CLRMA path on GetDebuggerServices() != null; now uses the target obtained from the host.
- InternalOutputVaList/TraceHostingError dereferenced a null GetDebuggerServices() when CLRMA logging was enabled; now null-guarded.
Adds a dotnet-dump-scoped clrma verification to NestedExceptionTest.script and documents the local workflow in documentation/clrma.md.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@steveisok
steveisok requested a review from a team as a code ownerJune 6, 2026 00:10
CopilotAI review requested due to automatic review settings June 6, 2026 00:10

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new SOS diagnostic command (clrma) to exercise the CLRMA contract end-to-end in any SOS host (notably dotnet-dump), enabling local validation of the Watson/!analyze managed-analysis path and addressing dotnet-dump-specific null debugger-services scenarios.

Changes:

  • Introduces a new native SOS clrma command that prints managed stack and exception (current/nested) details via ICLRManagedAnalysis.
  • Removes an AssociateClient gate that prevented CLRMA from running when debugger services are unavailable (dotnet-dump host scenario).
  • Adds dotnet-dump-scoped script verification and documents the local workflow in documentation/clrma.md.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
FileDescription
src/tests/SOS.UnitTests/Scripts/NestedExceptionTest.scriptAdds DOTNETDUMP-only validation of clrma output structure (provider + exception type/HResult).
src/SOS/Strike/sos.defExports the new clrma command from the SOS module.
src/SOS/Strike/clrma/managedanalysis.cppAllows CLRMA to proceed even when debugger services are null (dotnet-dump), relying on host target/runtime.
src/SOS/Strike/clrma/clrma.cppImplements the new clrma command and its printing helpers.
src/SOS/SOS.Hosting/Commands/SOSCommand.csRegisters clrma as a top-level hosted command.
src/SOS/extensions/extensions.cppAdds null-guards for missing debugger services to avoid crashes in dotnet-dump scenarios.
documentation/clrma.mdDocuments how to run clrma under dotnet-dump and provides sample output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadsrc/SOS/extensions/extensions.cpp Outdated
Comment threaddocumentation/clrma.md Outdated
steveisokand others added 3 commits June 7, 2026 09:29
The clrma SOS command was only compiled and exported on Windows, so under
dotnet-dump on Linux/macOS it failed with 'Unrecognized SOS command clrma',
breaking the NestedExceptionTest CLRMA verification on every non-Windows leg.
Compile the clrma sources into the Unix SOS build and export clrma in
sos_unixexports.src. Port the native code to the cross-platform debugger
services: source the debug interfaces from the ExtQuery globals (no COM
IDebugClient on Unix), map IDebugControl/IDebugSymbols3 to the available
IDebugControl2/IDebugSymbols compat interfaces, widen ASCII module names from
GetModuleNames (no GetModuleNameStringWide), and guard the last-event-thread
path (no GetThreadIdsByIndex). Use W() literals and basic_string<WCHAR> so
UTF-16 strings match WCHAR/BSTR where wchar_t differs from WCHAR on Unix.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
In _DEBUG builds, debugreturn.h (pulled in via exts.h -> contract.h)
defines 'return' as a macro. The Alpine/musl rootfs uses libstdc++
10.2.1 whose <vector> has constexpr relocate helpers containing
return statements, which break when the macro is active. Including
managedanalysis.h (which pulls in <vector>) before exts.h matches the
sibling files and resolves the compile error.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@noahfalknoahfalk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd only suggest we keep this if we can cut it down to an unseen Windows-only command. I don't think we want to create any customer expectations that this is publicly supported or xplat.

Comment threadsrc/SOS/Strike/clrma/exception.cpp
Comment threadsrc/SOS/Strike/clrma/exception.cpp
m_debugControl = debugControl.Detach();
m_debugSymbols = debugSymbols.Detach();
#else
// On Unix there is no COM IDebugClient. The cross-platform debugger services (ILLDBServices,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to support CLRMA on non-Windows systems? Until we have a scenario that requires it I'd suggest we don't create expand our feature support.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For testing purposes I think having something that works on linux and mac makes sense. I hid the command from the actual help list.

Comment threadsrc/SOS/SOS.Hosting/Commands/SOSCommand.cs Outdated
Make clrma a hidden command and apply review feedback from PR dotnet#5865:
- Add a reusable Hidden flag to CommandAttribute and filter hidden
commands out of the help/soshelp command list (CommandService.
GetAllCommandHelp). The command stays registered and invocable on all
hosts/platforms; it just isn't advertised. clrma is marked Hidden.
- Document why exception.cpp uses W()/manual-copy instead of L"" with
wcslen/wcscpy (wchar_t != WCHAR on Unix; W() yields UTF-16).
- Harden InternalOutputVaList: use int length, guard negative vsnprintf
returns, and always va_end(argsCopy) before returning.
- clrma.md: grammar fix and an internal-validation note clarifying clrma
is not a supported public command.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@steveisok
steveisok merged commit 7a1c84f into dotnet:mainJun 10, 2026
19 checks passed
@steveisok
steveisok deleted the add-clrma-cmd branch June 10, 2026 12:54
@leculver

Copy link
Copy Markdown
Contributor

Hey Steve, this is causing dotnet/runtime cDac tests to fail. The cDac stress is choking on a quirk from how a particular API in the dac returns E_INVALIDPOINTER on a particular valid input. This "fix" resolves the problem by matching the regular dac's odd behavior and fixes the break: dotnet/runtime#129297.

leculver added a commit to dotnet/runtime that referenced this pull request Jun 11, 2026
…ior (#129297)
The legacy DAC (ClrDataAccess::GetObjectStringData) returns E_INVALIDARG
when called on a valid string with no output buffer (stringData == null
or count == 0), while still populating *pNeeded. The cDAC implementation
returned S_OK in that case, which trips the cDAC-vs-DAC HResult parity
assert (SOSDacImpl.cs ValidateHResult) when clrma sizes an exception
string. Mirror the DAC: populate *pNeeded via CopyStringToBuffer, then
return E_INVALIDARG for the no-buffer case.
This fixes the build/test-break in the cDac introduced by
dotnet/diagnostics#5865.
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Jul 12, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@steveisok@leculver@noahfalk
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Add CLRMA diagnostic command runnable under dotnet-dump - #5865

Merged
steveisok merged 5 commits into
dotnet:mainfrom
steveisok:add-clrma-cmd
Jun 10, 2026
Merged

Add CLRMA diagnostic command runnable under dotnet-dump#5865
steveisok merged 5 commits into
dotnet:mainfrom
steveisok:add-clrma-cmd

Conversation

@steveisok

Copy link
Copy Markdown
Member

Adds a native SOS 'clrma' command that drives the CLRMA contract (CLRMACreateInstance -> ICLRManagedAnalysis: AssociateClient/GetThread/GetException) and prints the managed thread stack and current/nested exceptions. This lets the Watson/!analyze code path be exercised locally in any SOS host (notably dotnet-dump) without windbg/lldb, as a proxy for Watson bucketing. Registered as a top-level command for DbgEng !clrma parity and framed as a CLRMA-provider diagnostic.

Fixes two latent blockers that only surface in the dotnet-dump host (where Extensions debugger services are null):

  • AssociateClient gated the whole CLRMA path on GetDebuggerServices() != null; now uses the target obtained from the host.

  • InternalOutputVaList/TraceHostingError dereferenced a null GetDebuggerServices() when CLRMA logging was enabled; now null-guarded.

Adds a dotnet-dump-scoped clrma verification to NestedExceptionTest.script and documents the local workflow in documentation/clrma.md.

Adds a native SOS 'clrma' command that drives the CLRMA contract (CLRMACreateInstance -> ICLRManagedAnalysis: AssociateClient/GetThread/GetException) and prints the managed thread stack and current/nested exceptions. This lets the Watson/!analyze code path be exercised locally in any SOS host (notably dotnet-dump) without windbg/lldb, as a proxy for Watson bucketing. Registered as a top-level command for DbgEng !clrma parity and framed as a CLRMA-provider diagnostic.
Fixes two latent blockers that only surface in the dotnet-dump host (where Extensions debugger services are null):
- AssociateClient gated the whole CLRMA path on GetDebuggerServices() != null; now uses the target obtained from the host.
- InternalOutputVaList/TraceHostingError dereferenced a null GetDebuggerServices() when CLRMA logging was enabled; now null-guarded.
Adds a dotnet-dump-scoped clrma verification to NestedExceptionTest.script and documents the local workflow in documentation/clrma.md.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@steveisok
steveisok requested a review from a team as a code ownerJune 6, 2026 00:10
CopilotAI review requested due to automatic review settings June 6, 2026 00:10

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new SOS diagnostic command (clrma) to exercise the CLRMA contract end-to-end in any SOS host (notably dotnet-dump), enabling local validation of the Watson/!analyze managed-analysis path and addressing dotnet-dump-specific null debugger-services scenarios.

Changes:

  • Introduces a new native SOS clrma command that prints managed stack and exception (current/nested) details via ICLRManagedAnalysis.
  • Removes an AssociateClient gate that prevented CLRMA from running when debugger services are unavailable (dotnet-dump host scenario).
  • Adds dotnet-dump-scoped script verification and documents the local workflow in documentation/clrma.md.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
FileDescription
src/tests/SOS.UnitTests/Scripts/NestedExceptionTest.scriptAdds DOTNETDUMP-only validation of clrma output structure (provider + exception type/HResult).
src/SOS/Strike/sos.defExports the new clrma command from the SOS module.
src/SOS/Strike/clrma/managedanalysis.cppAllows CLRMA to proceed even when debugger services are null (dotnet-dump), relying on host target/runtime.
src/SOS/Strike/clrma/clrma.cppImplements the new clrma command and its printing helpers.
src/SOS/SOS.Hosting/Commands/SOSCommand.csRegisters clrma as a top-level hosted command.
src/SOS/extensions/extensions.cppAdds null-guards for missing debugger services to avoid crashes in dotnet-dump scenarios.
documentation/clrma.mdDocuments how to run clrma under dotnet-dump and provides sample output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadsrc/SOS/extensions/extensions.cpp Outdated
Comment threaddocumentation/clrma.md Outdated
steveisokand others added 3 commits June 7, 2026 09:29
The clrma SOS command was only compiled and exported on Windows, so under
dotnet-dump on Linux/macOS it failed with 'Unrecognized SOS command clrma',
breaking the NestedExceptionTest CLRMA verification on every non-Windows leg.
Compile the clrma sources into the Unix SOS build and export clrma in
sos_unixexports.src. Port the native code to the cross-platform debugger
services: source the debug interfaces from the ExtQuery globals (no COM
IDebugClient on Unix), map IDebugControl/IDebugSymbols3 to the available
IDebugControl2/IDebugSymbols compat interfaces, widen ASCII module names from
GetModuleNames (no GetModuleNameStringWide), and guard the last-event-thread
path (no GetThreadIdsByIndex). Use W() literals and basic_string<WCHAR> so
UTF-16 strings match WCHAR/BSTR where wchar_t differs from WCHAR on Unix.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
In _DEBUG builds, debugreturn.h (pulled in via exts.h -> contract.h)
defines 'return' as a macro. The Alpine/musl rootfs uses libstdc++
10.2.1 whose <vector> has constexpr relocate helpers containing
return statements, which break when the macro is active. Including
managedanalysis.h (which pulls in <vector>) before exts.h matches the
sibling files and resolves the compile error.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@noahfalknoahfalk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd only suggest we keep this if we can cut it down to an unseen Windows-only command. I don't think we want to create any customer expectations that this is publicly supported or xplat.

Comment threadsrc/SOS/Strike/clrma/exception.cpp
Comment threadsrc/SOS/Strike/clrma/exception.cpp
m_debugControl = debugControl.Detach();
m_debugSymbols = debugSymbols.Detach();
#else
// On Unix there is no COM IDebugClient. The cross-platform debugger services (ILLDBServices,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to support CLRMA on non-Windows systems? Until we have a scenario that requires it I'd suggest we don't create expand our feature support.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For testing purposes I think having something that works on linux and mac makes sense. I hid the command from the actual help list.

Comment threadsrc/SOS/SOS.Hosting/Commands/SOSCommand.cs Outdated
Make clrma a hidden command and apply review feedback from PR dotnet#5865:
- Add a reusable Hidden flag to CommandAttribute and filter hidden
commands out of the help/soshelp command list (CommandService.
GetAllCommandHelp). The command stays registered and invocable on all
hosts/platforms; it just isn't advertised. clrma is marked Hidden.
- Document why exception.cpp uses W()/manual-copy instead of L"" with
wcslen/wcscpy (wchar_t != WCHAR on Unix; W() yields UTF-16).
- Harden InternalOutputVaList: use int length, guard negative vsnprintf
returns, and always va_end(argsCopy) before returning.
- clrma.md: grammar fix and an internal-validation note clarifying clrma
is not a supported public command.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@steveisok
steveisok merged commit 7a1c84f into dotnet:mainJun 10, 2026
19 checks passed
@steveisok
steveisok deleted the add-clrma-cmd branch June 10, 2026 12:54
@leculver

Copy link
Copy Markdown
Contributor

Hey Steve, this is causing dotnet/runtime cDac tests to fail. The cDac stress is choking on a quirk from how a particular API in the dac returns E_INVALIDPOINTER on a particular valid input. This "fix" resolves the problem by matching the regular dac's odd behavior and fixes the break: dotnet/runtime#129297.

leculver added a commit to dotnet/runtime that referenced this pull request Jun 11, 2026
…ior (#129297)
The legacy DAC (ClrDataAccess::GetObjectStringData) returns E_INVALIDARG
when called on a valid string with no output buffer (stringData == null
or count == 0), while still populating *pNeeded. The cDAC implementation
returned S_OK in that case, which trips the cDAC-vs-DAC HResult parity
assert (SOSDacImpl.cs ValidateHResult) when clrma sizes an exception
string. Mirror the DAC: populate *pNeeded via CopyStringToBuffer, then
return E_INVALIDARG for the no-buffer case.
This fixes the build/test-break in the cDac introduced by
dotnet/diagnostics#5865.
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Jul 12, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@steveisok@leculver@noahfalk