Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

lldb hashmap pretty printer broken #81814

Closed
ehuss opened this issue Feb 6, 2021 · 3 comments · Fixed by #81834
Closed

lldb hashmap pretty printer broken #81814

ehuss opened this issue Feb 6, 2021 · 3 comments · Fixed by #81834
Labels
C-bug Category: This is a bug.

Comments

@ehuss
Copy link
Contributor

ehuss commented Feb 6, 2021

The LLDB provider for hash maps has been broken since #79234.

Repro:

use std::collections::*;
fn main() {
    let mut map = HashMap::new();
    map.insert(1, 2);
    eprintln!("{:?}", map);
}

Run this, notice that it doesn't print any values for the hash map:

rustc -g foo.rs
rust-lldb foo
(lldb) b 5
(lldb) r
(lldb) p map
(std::collections::hash::map::HashMap<int, int, std::collections::hash::map::RandomState>) $0 = size=1 {}

Using an older version works (1.49 or earler):

(lldb) p map
(std::collections::hash::map::HashMap<int, int, std::collections::hash::map::RandomState>) $0 = size=1 {
  [0] = {
    0 = 1
    1 = 2
  }
}

I don't understand the motivation for #79234, as you can see the older versions are able to display the type. @ortem can you clarify what is going on?

I did some debugging, and the pair_type_size and data_ptr values are invalid.


Another way to check this is to run the src/test/debuginfo/pretty-std-collections.rs test. Due to #81813 it hasn't been running on CI.

It has a check for the following output:

$2 = size=4 { [0] = { 0 = 1 1 = 10 } [1] = { 0 = 2 1 = 20 } [2] = { 0 = 3 1 = 30 } [3] = { 0 = 4 1 = 40 } }
$3 = size=4 { [0] = 1 [1] = 2 [2] = 3 [3] = 4 }

But the actual output is:

$2 = size=4 {}
$3 = size=4 {}
@artemmukhin
Copy link
Contributor

@ehuss I checked the issue with two different LLDB:

  • rust-lldb shipped with 1.51.0-nightly
  • LLDB built from LLVM 10.0.1 sources with Rust patches

by adding the following code to the StdHashMapSyntheticProvider#update method:

from pprint import pprint
pprint("Without GetTypedefedType(): " + table.type.template_args[0].GetName())
pprint("IsTypedefType(): " + str(table.type.template_args[0].IsTypedefType()))
pprint("With GetTypedefedType(): " + table.type.template_args[0].GetTypedefedType().GetName())

rust-lldb

(lldb) version
lldb-1200.0.44.2
Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)
(lldb) p map
'Without GetTypedefedType(): (i32, i32)'
'IsTypedefType(): False'
'With GetTypedefedType(): '
(std::collections::hash::map::HashMap<int, int, std::collections::hash::map::RandomState>) $0 = size=1 {}

LLVM upstream with Rust patches

(lldb) version
lldb version 10.0.1 rust-enabled
(lldb) p map
'Without GetTypedefedType(): T'
'IsTypedefType(): True'
'With GetTypedefedType(): (i32, i32)'
(std::collections::hash::map::HashMap<i32, i32, std::collections::hash::map::RandomState>) map = size=1 {
  [0] = (0 = 1, 1 = 2)
}

So it seems like the problem only occurs with rust-lldb.

Probably this is due to the lack of Rust patches in rust-lldb. AFAIU the Rust patches still have not been added to rust-lldb (I remember this related issue rust-lang/lldb#20).

To fix this problem, the following code should be used insted:

self.pair_type = table.type.template_args[0]
if self.pair_type.IsTypedefType():
    self.pair_type = self.pair_type.GetTypedefedType()

I've opened a PR with these changes: #81834.

However, I believe that rust-lldb should use Rust patches not only to avoid this specific problem but to provide a much better debugging experience, with proper type rendering (e.g. i32 instead of int), some expression evaluation support, and so forth. It is really unfortunate that Rust debugging support is not maintained enough except for some independent forks, for example, https://github.com/vadimcn/llvm-project/commits/rust-lldb and CLion's LLDB.

@ehuss
Copy link
Contributor Author

ehuss commented Feb 6, 2021

I may be misunderstanding you, but rust-lldb is just a shell script that runs the system lldb. Building lldb with patches was removed a long time ago (#62592), and I suspect is not coming back in the foreseeable future.

@artemmukhin
Copy link
Contributor

@ehuss Oh, that's even worse since macOS LLDB has very poor Rust support. I believe that debugging support is crucial for any compiled programming language, surely including Rust. So it would be really great to consider shipping rust-enabled LLDB and, more importantly, to maintain and improve Rust support in both GDB and LLDB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants