Skip to content

DBG: Show the contents of references and pointers with LLDB #10059

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2023

Conversation

artemmukhin
Copy link
Member

@artemmukhin artemmukhin commented Jan 30, 2023

Fixes #9050.
Partially fixes #9252 (LLDB only).

This PR brings automatic dereferencing of Rust references and pointers when debugging with LLDB. For example, now the debugger renders the contents of &Vec, *const Vec and *mut Vec, in addition to previously supported Vec.

Screenshot 2023-01-30 at 13 22 49

Technical information

Previously, for each Rust type regex $type (for String, Vec, etc.), we ran the following LLDB commands:

(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h $type --category Rust
(lldb) type synthetic add -l lldb_lookup.synthetic_lookup -x $type --category Rust

They attach summary_lookup and synthetic_lookup Python functions as summary/synthetic providers for the given types. Actual providers are invoked by these lookup functions. This was done for two main reasons:

It turned out, however, that such flexibility is not needed for LLDB anymore. Moreover, it appeared that the current implementation breaks the automatic dereferencing of pointers provided by LLDB by default when registering pretty-printers just by regex.

So now, for each pair of $type and the corresponding $provider, we run these LLDB commands instead:

(lldb) type summary add -F lldb_formatters.lldb_providers.$provider -e -x -h $type --category Rust
(lldb) type synthetic add -l lldb_formatters.lldb_providers.$provider -x $type --category Rust

changelog: Show the contents of references and pointers when debugging with LLDB

@artemmukhin artemmukhin changed the title #9050: Show the contents of references and pointers with LLDB DBG: Show the contents of references and pointers with LLDB Jan 30, 2023
@artemmukhin artemmukhin force-pushed the ortem/pretty-printers-refactor-loading branch 8 times, most recently from 269142c to 51ee74a Compare January 30, 2023 21:05
@artemmukhin artemmukhin force-pushed the ortem/pretty-printers-refactor-loading branch 5 times, most recently from 073d77f to f230a53 Compare February 1, 2023 19:46
Copy link
Member

@Undin Undin left a comment

Choose a reason for hiding this comment

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

Could you resolve merge conflicts, please?

@artemmukhin artemmukhin force-pushed the ortem/pretty-printers-refactor-loading branch from f230a53 to dc134d0 Compare February 16, 2023 10:36
@artemmukhin
Copy link
Member Author

@Undin I've resolved merge conflicts and reordered the regexes for readability

Copy link
Member

@Undin Undin left a comment

Choose a reason for hiding this comment

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

Works for me!

Don't forget before merge:

  • drop changes on CI
  • describe that multiple dereferences don't work after these changes

Comment on lines +6 to +7
// lldbr-check:[...]xs = size=4 { [0] = (0 = 1, 1 = 10) [1] = (0 = 2, 1 = 20) [2] = (0 = 3, 1 = 30) [3] = (0 = 4, 1 = 40) }
// lldbg-check:[...]$0 = size=4 { [0] = (__0 = 1, __1 = 10) [1] = (__0 = 2, __1 = 20) [2] = (__0 = 3, __1 = 30) [3] = (__0 = 4, __1 = 40) }
Copy link
Member

Choose a reason for hiding this comment

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

Why did it change and how does it affect users? I can't see any difference with macOS lldb but didn't check with MSVC lldb

Copy link
Member Author

Choose a reason for hiding this comment

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

I should not affect users, so the UI representation for HashMap is supposed to be the same.

@intellij-rust/qa Please pay attention to this ^

@artemmukhin artemmukhin force-pushed the ortem/pretty-printers-refactor-loading branch from dc134d0 to d4b7524 Compare March 1, 2023 16:23
This commit brings automatic dereferencing of Rust references and pointers when debugging with LLDB. For example, now the debugger renders the contents of `&Vec`, `*const Vec` and `*mut Vec`, in addition to previously supported `Vec`.

### Technical information

Previously, for each Rust type regex `$type` (for `String`, `Vec`, etc.), we ran the following LLDB commands:
```
(lldb) type summary add -F lldb_lookup.summary_lookup -e -x -h $type --category Rust
(lldb) type synthetic add -l lldb_lookup.synthetic_lookup -x $type --category Rust
```
They attach `summary_lookup` and `synthetic_lookup` Python functions as summary/synthetic providers for the given types. Actual providers are invoked by these lookup functions. This was done for two main reasons:
- for consistency, as GDB pretty-printing API requires us to use lookup functions (https://sourceware.org/gdb/onlinedocs/gdb/Writing-a-Pretty_002dPrinter.html);
- for flexibility, for example, to be able to choose the provider depending not only on the type regex, but also on its type class (`eTypeClassStruct`, `eTypeClassPointer`, etc.).

It turned out, however, that such flexibility is not needed for LLDB anymore. Moreover, it appeared that the current implementation breaks the automatic dereferencing of pointers provided by LLDB by default when registering pretty-printers just by regex.

So now, for each pair of `$type` and the corresponding `$provider`, we run these LLDB commands instead:
```
(lldb) type summary add -F lldb_formatters.lldb_providers.$provider -e -x -h $type --category Rust
(lldb) type synthetic add -l lldb_formatters.lldb_providers.$provider -x $type --category Rust
```
@artemmukhin artemmukhin force-pushed the ortem/pretty-printers-refactor-loading branch from d4b7524 to 2e498db Compare March 1, 2023 16:28
@artemmukhin
Copy link
Member Author

Note: this PR affects how the debugger renders "references to references" &&T and "pointers to pointers" and, more generally, multiple references and pointers. Consider this example:

fn main() {
    let vec = vec![1,2,3];
    let vec_ref = &vec;
    let vec_ref_ref = &vec_ref;

    let s = String::from("abc");
    let s_ref = &s;
    let s_ref_ref = &s_ref;

    println!(); // break
}
Before After
Before After

Once this PR is merged, I will open an issue with a more detailed overview.

@artemmukhin
Copy link
Member Author

bors r=Undin

@bors bors bot merged commit 9e41890 into master Mar 6, 2023
@bors
Copy link
Contributor

bors bot commented Mar 6, 2023

Build succeeded:

@bors bors bot deleted the ortem/pretty-printers-refactor-loading branch March 6, 2023 17:27
@github-actions github-actions bot added this to the v191 milestone Mar 6, 2023
@mili-l mili-l self-assigned this Mar 17, 2023
@mili-l
Copy link
Member

mili-l commented Mar 20, 2023

rust-lang/rust#106679

macOS LLDB MSVC LLDB
Screenshot 2023-03-20 at 12 08 23 Screenshot 2023-03-20 at 12 05 00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Debugger does not show content of &&str Automatically dereference pointer types when debugging with LLDB
3 participants