Skip to content

lldb hashmap pretty printer broken #81814

Closed

Description

@ehuss

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 {}

Activity

  1. artemmukhin commented on Feb 6, 2021

    @artemmukhin
    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.

  2. ehuss commented on Feb 6, 2021

    @ehuss
    ContributorAuthor

    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.

  3. artemmukhin commented on Feb 6, 2021

    @artemmukhin
    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.

  4. added a commit that references this issue on Feb 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions