Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{assert_matches, iter, ptr};

use libc::{c_longlong, c_uint};
use rustc_abi::{Align, Endian, Layout, NumScalableVectors, Size};
use rustc_ast::{IntTy, UintTy};
use rustc_codegen_ssa::debuginfo::type_names::{VTableNameKind, cpp_like_debuginfo};
use rustc_codegen_ssa::traits::*;
use rustc_hir::def::{CtorKind, DefKind};
Expand Down Expand Up @@ -795,9 +796,50 @@ fn build_basic_type_di_node<'ll, 'tcx>(
_ => bug!("debuginfo::build_basic_type_di_node - `t` is invalid type"),
};

let ty_di_node = create_basic_type(cx, name, cx.size_of(t), encoding);
// Around LLDB 21 or 22, LLDB started using prebuilt Clang type nodes for primitives rather than
// reading the full DWARF data. These nodes are based on the size and signedness of the
// primitive, and ignore pretty much all other fields. This causes 2 issues:
// 1. type names get normalized to C-style names which isn't ideal. The normalization occurs
// even in generic args.
// 2. if you have a generic type `S<T>`, and 2 instantiations are `S<u64>`
// and `S<usize>` (on a 64-bit target), the use of prebuilt nodes causes a name collision.
// Whichever instantiation is interacted with first will work fine, all others will break a
// bunch of stuff in the LLDB pipeline. To avoid this, we explicitly treat `usize` and `isize`
// as typedefs of their equivalent types. For more info see: llvm/llvm-project#196812

let mut needs_typedef = cpp_like_debuginfo;

let ty_di_node = match t.kind() {
ty::Uint(UintTy::Usize) => {
needs_typedef = true;

let equivalent = match t.primitive_size(cx.tcx).bits() {
8 => cx.tcx.types.u8,
16 => cx.tcx.types.u16,
32 => cx.tcx.types.u32,
64 => cx.tcx.types.u64,
128 => cx.tcx.types.u128,
x => bug!("Unexpected signed int size {x}"),
};
type_di_node(cx, equivalent)
}
ty::Int(IntTy::Isize) => {
needs_typedef = true;

let equivalent = match t.primitive_size(cx.tcx).bits() {
8 => cx.tcx.types.i8,
16 => cx.tcx.types.i16,
32 => cx.tcx.types.i32,
64 => cx.tcx.types.i64,
128 => cx.tcx.types.i128,
x => bug!("Unexpected signed int size: {x}"),
};
type_di_node(cx, equivalent)
}
_ => create_basic_type(cx, name, cx.size_of(t), encoding),
};

if !cpp_like_debuginfo {
if !needs_typedef {
return DINodeCreationResult::new(ty_di_node, false);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/debuginfo/basic-types/lldb_input/non_windows.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"value": false
},
"i": {
"type": "long",
"type": "isize",
"pretty_print": "-1",
"value": -1
},
Expand Down Expand Up @@ -43,7 +43,7 @@
"value": -64
},
"u": {
"type": "unsigned long",
"type": "usize",
"pretty_print": "1",
"value": 1
},
Expand Down
6 changes: 3 additions & 3 deletions tests/debuginfo/basic-types/lldb_input/windows_gnu.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"bless_metadata": {
"python_version": "3.11.9 (tags/v3.11.9:de54cf5, Apr 2 2024, 10:12:12) [MSC v.1938 64 bit (AMD64)]",
"debugger_version": "lldb version 22.1.2 (https://github.com/llvm/llvm-project revision 1ab49a973e210e97d61e5db6557180dcb92c3e98)\n clang revision 1ab49a973e210e97d61e5db6557180dcb92c3e98\n llvm revision 1ab49a973e210e97d61e5db6557180dcb92c3e98",
"debugger_version": "lldb version 22.1.8 (https://github.com/llvm/llvm-project revision ca7933e47d3a3451d81e72ac174dcb5aa28b59d1)\n clang revision ca7933e47d3a3451d81e72ac174dcb5aa28b59d1\n llvm revision ca7933e47d3a3451d81e72ac174dcb5aa28b59d1",
"feature_flags": "LLDBFeature.StaticFields|TypeRecognizers|Float128"
},
"breakpoints": [
Expand All @@ -12,7 +12,7 @@
"value": false
},
"i": {
"type": "long long",
"type": "isize",
"pretty_print": "-1",
"value": -1
},
Expand Down Expand Up @@ -43,7 +43,7 @@
"value": -64
},
"u": {
"type": "unsigned long long",
"type": "usize",
"pretty_print": "1",
"value": 1
},
Expand Down
19 changes: 12 additions & 7 deletions tests/debuginfo/pretty-std/lldb_input/non_windows.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
},
{
"name": "length",
"type": "unsigned long",
"type": "usize",
"offset": 8
}
]
Expand All @@ -171,9 +171,9 @@
"size": 8,
"type_class": 4096
},
"unsigned long": {
"usize": {
"size": 8,
"type_class": 4,
"type_class": 32768,
"basic_type": 16
},
"int": {
Expand All @@ -192,7 +192,7 @@
},
{
"name": "len",
"type": "unsigned long",
"type": "usize",
"offset": 16
}
],
Expand Down Expand Up @@ -281,7 +281,7 @@
"fields": [
{
"name": "__0",
"type": "unsigned long",
"type": "usize",
"offset": 0
}
]
Expand All @@ -297,6 +297,11 @@
"unsigned long"
]
},
"unsigned long": {
"size": 8,
"type_class": 4,
"basic_type": 16
},
"&str": {
"size": 16,
"type_class": 16384,
Expand All @@ -308,7 +313,7 @@
},
{
"name": "length",
"type": "unsigned long",
"type": "usize",
"offset": 8
}
]
Expand All @@ -335,7 +340,7 @@
},
{
"name": "len",
"type": "unsigned long",
"type": "usize",
"offset": 16
}
],
Expand Down
21 changes: 13 additions & 8 deletions tests/debuginfo/pretty-std/lldb_input/windows_gnu.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"bless_metadata": {
"python_version": "3.11.9 (tags/v3.11.9:de54cf5, Apr 2 2024, 10:12:12) [MSC v.1938 64 bit (AMD64)]",
"debugger_version": "lldb version 22.1.2 (https://github.com/llvm/llvm-project revision 1ab49a973e210e97d61e5db6557180dcb92c3e98)\n clang revision 1ab49a973e210e97d61e5db6557180dcb92c3e98\n llvm revision 1ab49a973e210e97d61e5db6557180dcb92c3e98",
"debugger_version": "lldb version 22.1.8 (https://github.com/llvm/llvm-project revision ca7933e47d3a3451d81e72ac174dcb5aa28b59d1)\n clang revision ca7933e47d3a3451d81e72ac174dcb5aa28b59d1\n llvm revision ca7933e47d3a3451d81e72ac174dcb5aa28b59d1",
"feature_flags": "LLDBFeature.StaticFields|TypeRecognizers|Float128"
},
"breakpoints": [
Expand Down Expand Up @@ -173,7 +173,7 @@
},
{
"name": "length",
"type": "unsigned long long",
"type": "usize",
"offset": 8
}
]
Expand All @@ -182,9 +182,9 @@
"size": 8,
"type_class": 4096
},
"unsigned long long": {
"usize": {
"size": 8,
"type_class": 4,
"type_class": 32768,
"basic_type": 18
},
"int": {
Expand All @@ -203,7 +203,7 @@
},
{
"name": "len",
"type": "unsigned long long",
"type": "usize",
"offset": 16
}
],
Expand Down Expand Up @@ -292,7 +292,7 @@
"fields": [
{
"name": "__0",
"type": "unsigned long long",
"type": "usize",
"offset": 0
}
]
Expand All @@ -308,6 +308,11 @@
"unsigned long long"
]
},
"unsigned long long": {
"size": 8,
"type_class": 4,
"basic_type": 18
},
"&str": {
"size": 16,
"type_class": 16384,
Expand All @@ -319,7 +324,7 @@
},
{
"name": "length",
"type": "unsigned long long",
"type": "usize",
"offset": 8
}
]
Expand All @@ -346,7 +351,7 @@
},
{
"name": "len",
"type": "unsigned long long",
"type": "usize",
"offset": 16
}
],
Expand Down
10 changes: 10 additions & 0 deletions tests/debuginfo/rc_arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
//@ lldb-check:[...] strong=11, weak=2 { value = 111 }
//@ lldb-command:v arc
//@ lldb-check:[...] strong=21, weak=2 { data = 222 }
//@ lldb-command:continue
//@ lldb-command:v rc_u64
//@ lldb-check:[...] rc_u64 = strong=1, weak=1 { value = 10 }
//@ lldb-command:v rc_usize
//@ lldb-check:[...] rc_usize = strong=1, weak=1 { value = 20 }

// === CDB TESTS ==================================================================================

Expand Down Expand Up @@ -132,6 +137,11 @@ fn main() {
let slice_arc_weak = Arc::downgrade(&slice_arc);

zzz(); // #break

let rc_u64 = Rc::new(10u64);
let rc_usize = Rc::new(20usize);

zzz(); // #break
}

fn inc_ref_count<T: Clone>(rc: &T, count: usize) {
Expand Down
Loading