Skip to content

Commit f6d9029

Browse files
authored
Rollup merge of rust-lang#55767 - tromey:disable-some-pretty-printers, r=nikomatsakis
Disable some pretty-printers when gdb is rust-enabled A rust-enabled gdb already knows how to display string slices, structs, tuples, and enums (and after rust-lang#54004, the pretty-printers can't handle enums at all). This patch disables these pretty-printers when gdb is rust-enabled. The "gdb-pretty-struct-and-enums-pre-gdb-7-7.rs" test is renamed, because it does not seem to depend on any behavior of that version of gdb, and because gdb 7.7 is 4 years old now.
2 parents 0c5947a + 764e2a7 commit f6d9029

File tree

2 files changed

+34
-28
lines changed

2 files changed

+34
-28
lines changed

src/etc/gdb_rust_pretty_printing.py

+25-18
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
if sys.version_info[0] >= 3:
1919
xrange = range
2020

21+
rust_enabled = 'set language rust' in gdb.execute('complete set language ru', to_string = True)
22+
2123
#===============================================================================
2224
# GDB Pretty Printing Module for Rust
2325
#===============================================================================
@@ -99,27 +101,9 @@ def rust_pretty_printer_lookup_function(gdb_val):
99101
val = GdbValue(gdb_val)
100102
type_kind = val.type.get_type_kind()
101103

102-
if type_kind == rustpp.TYPE_KIND_EMPTY:
103-
return RustEmptyPrinter(val)
104-
105-
if type_kind == rustpp.TYPE_KIND_REGULAR_STRUCT:
106-
return RustStructPrinter(val,
107-
omit_first_field = False,
108-
omit_type_name = False,
109-
is_tuple_like = False)
110-
111-
if type_kind == rustpp.TYPE_KIND_STRUCT_VARIANT:
112-
return RustStructPrinter(val,
113-
omit_first_field = True,
114-
omit_type_name = False,
115-
is_tuple_like = False)
116-
117104
if type_kind == rustpp.TYPE_KIND_SLICE:
118105
return RustSlicePrinter(val)
119106

120-
if type_kind == rustpp.TYPE_KIND_STR_SLICE:
121-
return RustStringSlicePrinter(val)
122-
123107
if type_kind == rustpp.TYPE_KIND_STD_VEC:
124108
return RustStdVecPrinter(val)
125109

@@ -138,6 +122,29 @@ def rust_pretty_printer_lookup_function(gdb_val):
138122
if type_kind == rustpp.TYPE_KIND_OS_STRING:
139123
return RustOsStringPrinter(val)
140124

125+
# Checks after this point should only be for "compiler" types --
126+
# things that gdb's Rust language support knows about.
127+
if rust_enabled:
128+
return None
129+
130+
if type_kind == rustpp.TYPE_KIND_EMPTY:
131+
return RustEmptyPrinter(val)
132+
133+
if type_kind == rustpp.TYPE_KIND_REGULAR_STRUCT:
134+
return RustStructPrinter(val,
135+
omit_first_field = False,
136+
omit_type_name = False,
137+
is_tuple_like = False)
138+
139+
if type_kind == rustpp.TYPE_KIND_STRUCT_VARIANT:
140+
return RustStructPrinter(val,
141+
omit_first_field = True,
142+
omit_type_name = False,
143+
is_tuple_like = False)
144+
145+
if type_kind == rustpp.TYPE_KIND_STR_SLICE:
146+
return RustStringSlicePrinter(val)
147+
141148
if type_kind == rustpp.TYPE_KIND_TUPLE:
142149
return RustStructPrinter(val,
143150
omit_first_field = False,

src/test/debuginfo/gdb-pretty-struct-and-enums-pre-gdb-7-7.rs src/test/debuginfo/gdb-pretty-struct-and-enums.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,33 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// ignore-bitrig
12-
// ignore-solaris
13-
// ignore-windows failing on win32 bot
14-
// ignore-freebsd: gdb package too new
1511
// ignore-tidy-linelength
1612
// ignore-lldb
17-
// ignore-android: FIXME(#10381)
13+
// min-gdb-version: 7.11
14+
1815
// compile-flags:-g
1916

2017
// gdb-command: run
2118

2219
// gdb-command: print regular_struct
23-
// gdb-check:$1 = RegularStruct = {the_first_field = 101, the_second_field = 102.5, the_third_field = false}
20+
// gdbg-check:$1 = RegularStruct = {the_first_field = 101, the_second_field = 102.5, the_third_field = false}
21+
// gdbr-check:$1 = gdb_pretty_struct_and_enums::RegularStruct {the_first_field: 101, the_second_field: 102.5, the_third_field: false}
2422

2523
// gdb-command: print empty_struct
26-
// gdb-check:$2 = EmptyStruct
24+
// gdbg-check:$2 = EmptyStruct
25+
// gdbr-check:$2 = gdb_pretty_struct_and_enums::EmptyStruct
2726

2827
// gdb-command: print c_style_enum1
2928
// gdbg-check:$3 = CStyleEnumVar1
30-
// gdbr-check:$3 = gdb_pretty_struct_and_enums_pre_gdb_7_7::CStyleEnum::CStyleEnumVar1
29+
// gdbr-check:$3 = gdb_pretty_struct_and_enums::CStyleEnum::CStyleEnumVar1
3130

3231
// gdb-command: print c_style_enum2
3332
// gdbg-check:$4 = CStyleEnumVar2
34-
// gdbr-check:$4 = gdb_pretty_struct_and_enums_pre_gdb_7_7::CStyleEnum::CStyleEnumVar2
33+
// gdbr-check:$4 = gdb_pretty_struct_and_enums::CStyleEnum::CStyleEnumVar2
3534

3635
// gdb-command: print c_style_enum3
3736
// gdbg-check:$5 = CStyleEnumVar3
38-
// gdbr-check:$5 = gdb_pretty_struct_and_enums_pre_gdb_7_7::CStyleEnum::CStyleEnumVar3
37+
// gdbr-check:$5 = gdb_pretty_struct_and_enums::CStyleEnum::CStyleEnumVar3
3938

4039
#![allow(dead_code, unused_variables)]
4140

0 commit comments

Comments
 (0)