Repository navigation
[debugger visualizers] Add workaround to read Rc strong/weak counts - #163098
Merged
Merged
Conversation
Collaborator
|
rustbot has assigned @Mark-Simulacrum. Use Why was this reviewer chosen?The reviewer was selected based on:
|
Member
|
@bors r+ I agree that visualizing with a changed count makes little sense -- if we want that we should at least use a different field name. But I'm comfortable with this. |
Contributor
jhpratt
added a commit
to jhpratt/rust
that referenced
this pull request
Sep 27, 2026
[debugger visualizers] Add workaround to read `Rc` strong/weak counts Implements a fix with the same goal as rust-lang#162725 of removing the infinite loop. Since `RcInner` is `#[repr(C)]`, we can just directly read the values from their known offsets. Worth noting that LLDB fails to even populate the fields and offsets when this bug occurs, so `#[repr(C)]` is a required invariant to retrieve the values from addresses like this: ``` (lldb) script lldb.frame.var("holder").GetNonSyntheticValue().GetChildAtIndex(0).GetChildAtIndex(0).GetChildAtIndex(0).GetType().GetPointeeType() template<> struct RcInner<unsigned int> { private: unsigned int value; } ``` That `RcInner` should have a `strong` and `weak` field, but because LLDB can't read the type node, it omits them entirely. Thankfully, the `value` field is still read correctly and has an accurate offset. This change has 1 small side effect, which is that the `weak` count is not decremented before it is displayed to the user. We can easily do that in the summary function, but imo it feels weird to lie about the value in memory? The `weak` count starts at 1 because the original `Rc` instance "holds" both a strong and a weak reference. It's mostly an artifact of `Rc`'s implementation, but if you're debugging, that seems like something that might matter.
rust-bors Bot
pushed a commit
that referenced
this pull request
Sep 28, 2026
Rollup of 11 pull requests Successful merges: - #163085 (Suggest similarly named modules in import paths) - #163098 ([debugger visualizers] Add workaround to read `Rc` strong/weak counts) - #163120 (ci: make musl.sh look for patches next to the script) - #163301 (Fix unused_must_use for scenario which may need to keep value) - #163307 (Less `SpanData` in diagnostics) - #152972 (implement PartialEq<VecDeque<U>> for Vec<T>, &[T], &mut [T], [T; N], &[T; N] and &mut [T; N]) - #162536 (Implement Default for NumBuffer) - #163141 (Document safety requirements for intrinsic fallbacks) - #163384 (Various clean-ups around `LayoutCalculator`) - #163405 (Remove some #[linkage] options) - #163413 (mailmap: add Matilde Morrone)
rust-bors Bot
pushed a commit
that referenced
this pull request
Sep 28, 2026
Rollup of 11 pull requests Successful merges: - #163085 (Suggest similarly named modules in import paths) - #163098 ([debugger visualizers] Add workaround to read `Rc` strong/weak counts) - #163120 (ci: make musl.sh look for patches next to the script) - #163301 (Fix unused_must_use for scenario which may need to keep value) - #163307 (Less `SpanData` in diagnostics) - #163389 (`rustc_builtin_macros` cleanup, part 7) - #152972 (implement PartialEq<VecDeque<U>> for Vec<T>, &[T], &mut [T], [T; N], &[T; N] and &mut [T; N]) - #162536 (Implement Default for NumBuffer) - #163141 (Document safety requirements for intrinsic fallbacks) - #163384 (Various clean-ups around `LayoutCalculator`) - #163413 (mailmap: add Matilde Morrone)
rust-bors Bot
pushed a commit
that referenced
this pull request
Sep 28, 2026
Rollup merge of #163098 - Walnut356:rc_usize, r=Mark-Simulacrum [debugger visualizers] Add workaround to read `Rc` strong/weak counts Implements a fix with the same goal as #162725 of removing the infinite loop. Since `RcInner` is `#[repr(C)]`, we can just directly read the values from their known offsets. Worth noting that LLDB fails to even populate the fields and offsets when this bug occurs, so `#[repr(C)]` is a required invariant to retrieve the values from addresses like this: ``` (lldb) script lldb.frame.var("holder").GetNonSyntheticValue().GetChildAtIndex(0).GetChildAtIndex(0).GetChildAtIndex(0).GetType().GetPointeeType() template<> struct RcInner<unsigned int> { private: unsigned int value; } ``` That `RcInner` should have a `strong` and `weak` field, but because LLDB can't read the type node, it omits them entirely. Thankfully, the `value` field is still read correctly and has an accurate offset. This change has 1 small side effect, which is that the `weak` count is not decremented before it is displayed to the user. We can easily do that in the summary function, but imo it feels weird to lie about the value in memory? The `weak` count starts at 1 because the original `Rc` instance "holds" both a strong and a weak reference. It's mostly an artifact of `Rc`'s implementation, but if you're debugging, that seems like something that might matter.
github-actions Bot
pushed a commit
to rust-lang/rust-analyzer
that referenced
this pull request
Oct 1, 2026
Rollup of 11 pull requests Successful merges: - rust-lang/rust#163085 (Suggest similarly named modules in import paths) - rust-lang/rust#163098 ([debugger visualizers] Add workaround to read `Rc` strong/weak counts) - rust-lang/rust#163120 (ci: make musl.sh look for patches next to the script) - rust-lang/rust#163301 (Fix unused_must_use for scenario which may need to keep value) - rust-lang/rust#163307 (Less `SpanData` in diagnostics) - rust-lang/rust#163389 (`rustc_builtin_macros` cleanup, part 7) - rust-lang/rust#152972 (implement PartialEq<VecDeque<U>> for Vec<T>, &[T], &mut [T], [T; N], &[T; N] and &mut [T; N]) - rust-lang/rust#162536 (Implement Default for NumBuffer) - rust-lang/rust#163141 (Document safety requirements for intrinsic fallbacks) - rust-lang/rust#163384 (Various clean-ups around `LayoutCalculator`) - rust-lang/rust#163413 (mailmap: add Matilde Morrone)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements a fix with the same goal as #162725 of removing the infinite loop. Since
RcInneris#[repr(C)], we can just directly read the values from their known offsets. Worth noting that LLDB fails to even populate the fields and offsets when this bug occurs, so#[repr(C)]is a required invariant to retrieve the values from addresses like this:That
RcInnershould have astrongandweakfield, but because LLDB can't read the type node, it omits them entirely. Thankfully, thevaluefield is still read correctly and has an accurate offset.This change has 1 small side effect, which is that the
weakcount is not decremented before it is displayed to the user. We can easily do that in the summary function, but imo it feels weird to lie about the value in memory? Theweakcount starts at 1 because the originalRcinstance "holds" both a strong and a weak reference. It's mostly an artifact ofRc's implementation, but if you're debugging, that seems like something that might matter.