Skip to content

Allow the GcInfoDumper to report scratch registers at safe points (DECODE_NO_VALIDATION) - #129615

Merged
hoyosjs merged 1 commit into
mainfrom
hoyosjs-patch-1
Jul 16, 2026
Merged

hoyosjs merged 1 commit into
mainfrom
hoyosjs-patch-1

Conversation

@hoyosjs

@hoyosjs hoyosjs commented Jun 19, 2026

Copy link
Copy Markdown
Member

A checked/debug build can hit  _ASSERTE(flags & ActiveStackFrame) in TGcInfoDecoder<...>::ReportRegisterToGC when the  GcInfoDumper  is used to dump a method whose GC info reports a scratch register live at a safe point. This is reachable today through SOS's gcinfo, e.g. AMD64 GC info reporting rax live at a partially interruptible safe point. GcInfoDumper::EnumerateStateChanges constructs its decoder with DECODE_NO_VALIDATION and calls  EnumerateLiveSlots(&regdisp, /reportScratchSlots/ true, flags | NoReportUntracked, ...). At safe points it deliberately sets flags = 0 (not ActiveStackFrame ) but still asks for scratch slots, because the dumper's job is to display every encoded slot at every offset - it is not performing a real stackwalk. The assert was written for the real-GC contract (scratch registers are only valid on the active/leaf frame) and does not account for the dumper's explicit  DECODE_NO_VALIDATION mode.

…CODE_NO_VALIDATION)

A checked/debug build can hit  _ASSERTE(flags & ActiveStackFrame)  ("Scratch registers cannot be reported for non-leaf frames") in  TGcInfoDecoder<...>::ReportRegisterToGC  when the  GcInfoDumper  is used to dump a method whose GC info reports a scratch register live at a safe point. This is reachable today through SOS's  gcinfo, e.g. AMD64 GC info reporting rax live at a partially-interruptible safe point. GcInfoDumper::EnumerateStateChanges constructs its decoder with  DECODE_NO_VALIDATION  and calls  EnumerateLiveSlots(&regdisp, /*reportScratchSlots*/ true, flags | NoReportUntracked, ...) . At safe points it deliberately sets  flags = 0  (not  ActiveStackFrame ) but still asks for scratch slots, because the dumper's job is to display every encoded slot at every offset - it is not performing a real stackwalk. The assert was written for the real-GC contract (scratch registers are only valid on the active/leaf frame) and does not account for the dumper's explicit  DECODE_NO_VALIDATION mode.
Copilot AI review requested due to automatic review settings June 19, 2026 11:16
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @anicka-net, @dotnet/gc
See info in area-owners.md if you want to be subscribed.

Copilot AI 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

This PR adjusts TGcInfoDecoder<...>::ReportRegisterToGC debug-time validation so that scratch registers can be reported even when the decoder is running in DECODE_NO_VALIDATION mode (used by GC info dumping / display scenarios), avoiding _ASSERTE(flags & ActiveStackFrame) failures.

Changes:

  • Relax the scratch-register invariant assertion in ReportRegisterToGC to allow DECODE_NO_VALIDATION as an alternate “display-only” contract.
  • Apply the same adjustment across the platform-specific ReportRegisterToGC implementations (AMD64, ARM, ARM64, LoongArch64, RISC-V 64).

@github-actions

Copy link
Copy Markdown
Contributor

Copilot Code Review

Holistic Assessment

Motivation: Justified — the GcInfoDumper intentionally sets flags = 0 (clearing ActiveStackFrame) at safe points while asking for scratch slots via reportScratchSlots = true and DECODE_NO_VALIDATION. The existing _ASSERTE only accounts for the real-GC contract and fires spuriously in checked/debug builds when using SOS's gcinfo command.

Approach: Correct and minimal. Relaxing the debug assertion by checking m_Flags & DECODE_NO_VALIDATION is exactly the right fix — it mirrors the existing pattern used in the VALIDATE_ROOT macro (line 59) and is properly scoped since DECODE_NO_VALIDATION is only set by the GcInfoDumper.

Summary: ✅ LGTM. The change is a clean, surgical fix to 5 identical debug-only assertions across all architecture-specific ReportRegisterToGC methods. The fix is consistent, the comments are accurate, and the assertion relaxation cannot weaken checks on real GC code paths.


Detailed Findings

Detailed Findings

✅ Correctness — Assert relaxation is properly scoped

DECODE_NO_VALIDATION is only set in one place in the codebase — gcinfodumper.cpp:888 — when constructing the decoder for display/diagnostic purposes. The relaxed assertion (flags & ActiveStackFrame) || (m_Flags & DECODE_NO_VALIDATION) cannot weaken the check for any real stack walk or GC enumeration path.

✅ Consistency — Pattern matches existing codebase convention

The VALIDATE_ROOT macro at line 59 of the same file already uses !(m_Flags & DECODE_NO_VALIDATION) to skip validation in dumper mode. This PR applies the same principle to the scratch-register assertions, making the debug-mode behavior consistent throughout the decoder.

✅ Completeness — All architecture variants updated

All 5 platform-specific ReportRegisterToGC methods (AMD64, ARM, ARM64, LoongArch64, RISC-V64) receive identical changes. No instances were missed.

✅ Comments — Accurate and helpful

The updated comments correctly explain why the relaxation is needed and reference the gcinfodumper by name, making the intent clear for future readers.

Note

This review was created by GitHub Copilot.

Generated by Code Review for issue #129615 · ● 13.8M · ◷

@hoyosjs
hoyosjs requested review from davidwrighton and jkotas June 19, 2026 19:45
@hoyosjs
hoyosjs merged commit f89572a into main Jul 16, 2026
116 checks passed
@hoyosjs
hoyosjs deleted the hoyosjs-patch-1 branch July 16, 2026 07:50
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants