Skip to content

Commit 91bceb8

Browse files
authored
Rollup merge of rust-lang#55767 - tromey:disable-some-pretty-printers, r=alexcrichton
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 821bad3 + 30178b4 commit 91bceb8

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
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-9
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,34 @@
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
1713
// ignore-android: FIXME(#10381)
14+
// min-gdb-version: 7.11
15+
1816
// compile-flags:-g
1917

2018
// gdb-command: run
2119

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

2524
// gdb-command: print empty_struct
26-
// gdb-check:$2 = EmptyStruct
25+
// gdbg-check:$2 = EmptyStruct
26+
// gdbr-check:$2 = gdb_pretty_struct_and_enums::EmptyStruct
2727

2828
// gdb-command: print c_style_enum1
2929
// gdbg-check:$3 = CStyleEnumVar1
30-
// gdbr-check:$3 = gdb_pretty_struct_and_enums_pre_gdb_7_7::CStyleEnum::CStyleEnumVar1
30+
// gdbr-check:$3 = gdb_pretty_struct_and_enums::CStyleEnum::CStyleEnumVar1
3131

3232
// gdb-command: print c_style_enum2
3333
// gdbg-check:$4 = CStyleEnumVar2
34-
// gdbr-check:$4 = gdb_pretty_struct_and_enums_pre_gdb_7_7::CStyleEnum::CStyleEnumVar2
34+
// gdbr-check:$4 = gdb_pretty_struct_and_enums::CStyleEnum::CStyleEnumVar2
3535

3636
// gdb-command: print c_style_enum3
3737
// gdbg-check:$5 = CStyleEnumVar3
38-
// gdbr-check:$5 = gdb_pretty_struct_and_enums_pre_gdb_7_7::CStyleEnum::CStyleEnumVar3
38+
// gdbr-check:$5 = gdb_pretty_struct_and_enums::CStyleEnum::CStyleEnumVar3
3939

4040
#![allow(dead_code, unused_variables)]
4141

0 commit comments

Comments
 (0)