Repository: rust
Issue: rust-lldb hangs when printing non-trivial type
Labels: T-compiler,WG-debugging

Someone mentioned that rust-lldb has issues printing nested types.  To test this I wrote the following testcase:

```rust
#[derive(Debug)]
struct Deep {
  s: String
}

#[derive(Debug)]
enum Something {
  Variant(Deep)
}

#[derive(Debug)]
struct Shallow {
  s: String,
  val: usize,
  ch: char,
  something: Something
}

fn main() {
  let d = Deep {
    s: String::from("g00")
  };
  let something = Something::Variant(d);
  let o = Shallow {
    s: String::from("w00"),
    val: 42,
    ch: 'q',
    something
  };
  let a = 7;
  let b = 11;
  let c = a * b;
  println!("{c}");
  println!("{:?}", o);
}
```

I built a debug version of this and ran `rust-lldb` on it:
```
$ rust-lldb ~/tmp/bld/cargo/debug/playground
```

I set a breakpoint on `main`, step until `a` is set and print it:

```
(lldb) breakpoint set --name main
Breakpoint 1: 2 locations.
(lldb) run
Process 6366 launched: '/Users/jan/tmp/bld/cargo/debug/playground' (x86_64)
Process 6366 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.2
    frame #0: 0x0000000100003960 playground`main
playground`main:
->  0x100003960 <+0>: pushq  %rbp
    0x100003961 <+1>: movq   %rsp, %rbp
    0x100003964 <+4>: movq   %rsi, %rdx
    0x100003967 <+7>: movslq %edi, %rsi
Target 0: (playground) stopped.
(lldb) cont
Process 6366 resuming
Process 6366 stopped
* thread #1, name = 'main', queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x000000010000349b playground`playground::main::hf49c7f512596a7cd at main.rs:30:7
   27  	    ch: 'q',
   28  	    something
   29  	  };
-> 30  	  let a = 7;
   31  	  let b = 11;
   32  	  let c = a * b;
   33  	  println!("{c}");
Target 0: (playground) stopped.
(lldb) n
Process 6366 stopped
* thread #1, name = 'main', queue = 'com.apple.main-thread', stop reason = step over
    frame #0: 0x00000001000034a5 playground`playground::main::hf49c7f512596a7cd at main.rs:31:7
   28  	    something
   29  	  };
   30  	  let a = 7;
-> 31  	  let b = 11;
   32  	  let c = a * b;
   33  	  println!("{c}");
   34  	  println!("{:?}", o);
Target 0: (playground) stopped.
(lldb) print a
(int) $0 = 7
```

If I print `o`:

```
(lldb) print o
```

.. lldb seemingly hangs.  I have to mash Ctrl+C until it stops.

If I restart `rust-lldb` and instead set a breakpoint inside main I get a different result.

```
(lldb) breakpoint set --file main.rs --line 31
Breakpoint 1: where = playground`playground::main::hf49c7f512596a7cd + 21 at main.rs:31:7, address = 0x00000001000034a5
(lldb) run
Process 6323 launched: '/Users/jan/tmp/bld/cargo/debug/playground' (x86_64)
Process 6323 stopped
* thread #1, name = 'main', queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x00000001000034a5 playground`playground::main::hf49c7f512596a7cd at main.rs:31:7
   28  	    something
   29  	  };
   30  	  let a = 7;
-> 31  	  let b = 11;
   32  	  let c = a * b;
   33  	  println!("{c}");
   34  	  println!("{:?}", o);
Target 0: (playground) stopped.
(lldb) print a
(int) $0 = 7
(lldb) print o
(playground::Shallow) $1 = {
  s = "" {
    vec = size=0
  }
  val = 4294967296
  ch = U+0x00000050 U'P'
  something =
}
(lldb) 
```

(Output of `o` indeed looks broken, but that's a separate issue).

# Versions

```
$ rust-lldb --version
lldb-1403.0.17.67
Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)
$ rustc --version
rustc 1.72.0 (5680fa18f 2023-08-23)
```

Running on x64.