From be454f056fc7637da6d1922c532d73831dc072db Mon Sep 17 00:00:00 2001 From: Arlo Siemsen Date: Thu, 14 Oct 2021 10:26:42 -0700 Subject: [PATCH] Change `char` type in debuginfo to DW_ATE_UTF Rust previously encoded the `char` type as DW_ATE_unsigned_char. The more appropriate encoding is DW_ATE_UTF. Clang uses this same debug encoding for char32_t. This fixes the display of `char` types in Windows debuggers as well as LLDB. --- compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs | 4 ++-- src/test/debuginfo/basic-types.rs | 3 ++- src/test/debuginfo/borrowed-basic.rs | 3 +-- src/test/debuginfo/borrowed-unique-basic.rs | 3 +-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index ef87b7b1a7e07..4ca92b3efe098 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -87,7 +87,7 @@ const DW_ATE_signed: c_uint = 0x05; #[allow(non_upper_case_globals)] const DW_ATE_unsigned: c_uint = 0x07; #[allow(non_upper_case_globals)] -const DW_ATE_unsigned_char: c_uint = 0x08; +const DW_ATE_UTF: c_uint = 0x10; pub const UNKNOWN_LINE_NUMBER: c_uint = 0; pub const UNKNOWN_COLUMN_NUMBER: c_uint = 0; @@ -933,7 +933,7 @@ fn basic_type_metadata<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'l ty::Never => ("!", DW_ATE_unsigned), ty::Tuple(elements) if elements.is_empty() => ("()", DW_ATE_unsigned), ty::Bool => ("bool", DW_ATE_boolean), - ty::Char => ("char", DW_ATE_unsigned_char), + ty::Char => ("char", DW_ATE_UTF), ty::Int(int_ty) if cpp_like_debuginfo => (int_ty.msvc_basic_name(), DW_ATE_signed), ty::Uint(uint_ty) if cpp_like_debuginfo => (uint_ty.msvc_basic_name(), DW_ATE_unsigned), ty::Float(float_ty) if cpp_like_debuginfo => (float_ty.msvc_basic_name(), DW_ATE_float), diff --git a/src/test/debuginfo/basic-types.rs b/src/test/debuginfo/basic-types.rs index c8879856b9670..07d33be2a071f 100644 --- a/src/test/debuginfo/basic-types.rs +++ b/src/test/debuginfo/basic-types.rs @@ -104,7 +104,8 @@ // cdb-check:b : false [Type: bool] // cdb-command:dx i // cdb-check:i : -1 [Type: [...]] -// The variable 'c' doesn't appear for some reason... +// cdb-command:dx c +// cdb-check:c : 0x61 'a' [Type: char32_t] // cdb-command:dx i8 // cdb-check:i8 : 68 [Type: char] // cdb-command:dx i16 diff --git a/src/test/debuginfo/borrowed-basic.rs b/src/test/debuginfo/borrowed-basic.rs index c3868d46ba485..b4bb7c146d9df 100644 --- a/src/test/debuginfo/borrowed-basic.rs +++ b/src/test/debuginfo/borrowed-basic.rs @@ -14,8 +14,7 @@ // gdb-check:$2 = -1 // gdb-command:print *char_ref -// gdbg-check:$3 = 97 -// gdbr-check:$3 = 97 'a' +// gdb-check:$3 = 97 // gdb-command:print *i8_ref // gdbg-check:$4 = 68 'D' diff --git a/src/test/debuginfo/borrowed-unique-basic.rs b/src/test/debuginfo/borrowed-unique-basic.rs index b39f24e029e31..f38cbc10dd3ac 100644 --- a/src/test/debuginfo/borrowed-unique-basic.rs +++ b/src/test/debuginfo/borrowed-unique-basic.rs @@ -16,8 +16,7 @@ // gdb-check:$2 = -1 // gdb-command:print *char_ref -// gdbg-check:$3 = 97 -// gdbr-check:$3 = 97 'a' +// gdb-check:$3 = 97 // gdb-command:print/d *i8_ref // gdb-check:$4 = 68