upstream proposed fix for PR/30158
Signed-off-by: Héctor Orón Martínez <zumbi@debian.org>
Héctor Orón Martínez
1 year, 2 months ago
0 | gdb 13.1 crashes while running the rust compiler's debugger tests. | |
1 | The crash has a number of causes. | |
2 | ||
3 | First, the rust compiler still uses the C++-like _Z mangling, but with | |
4 | its own twist -- some hex digits added to the end of a symbol. So, | |
5 | while gdb finds the correct name of "main": | |
6 | ||
7 | (top-gdb) p name | |
8 | $13 = 0x292e0c0 "rustc_gdb_1031745::main" | |
9 | ||
10 | It isn't found in the minsyms, because C++ demangling yields: | |
11 | ||
12 | [99] t 0x90c0 _ZN17rustc_gdb_10317454main17h5b5be7fe16a97225E section .text rustc_gdb_1031745::main::h5b5be7fe16a97225 zko06yobckx336v | |
13 | ||
14 | This could perhaps be fixed. I also filed a new PR to suggest | |
15 | preferring the linkage name of the main program. | |
16 | ||
17 | Next, the rust compiler emits both a DW_TAG_subprogram and a | |
18 | DW_TAG_namespace for "main". This happens because the file is named | |
19 | "main.rs" -- i.e., the bug is specific to the source file name. The | |
20 | crash also seems to require the nested function inside of 'main', at | |
21 | least for me. The namespace always is generated, but perhaps this | |
22 | changes the ordering in the DWARF. | |
23 | ||
24 | When inside_main_func looks up the main symbol, it finds the namespace | |
25 | symbol rather than the function. (I filed a bug about fixing gdb's | |
26 | symbol tables -- long overdue.) | |
27 | ||
28 | Meanwhile, as I think it's important to fix this crash sooner rather | |
29 | than later, this patch changes inside_main_func to check that the | |
30 | symbol that is found is LOC_BLOCK. This perhaps should have been done | |
31 | in the first place, anyway. | |
32 | ||
33 | Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30158 | |
34 | --- | |
35 | gdb/frame.c | 8 ++++++ | |
36 | gdb/testsuite/gdb.rust/main-crash.exp | 35 +++++++++++++++++++++++++++ | |
37 | gdb/testsuite/gdb.rust/main.rs | 30 +++++++++++++++++++++++ | |
38 | 3 files changed, 73 insertions(+) | |
39 | create mode 100644 gdb/testsuite/gdb.rust/main-crash.exp | |
40 | create mode 100644 gdb/testsuite/gdb.rust/main.rs | |
41 | ||
42 | diff --git a/gdb/frame.c b/gdb/frame.c | |
43 | index 9b867b6cd9c..de3c7de440d 100644 | |
44 | --- a/gdb/frame.c | |
45 | +++ b/gdb/frame.c | |
46 | @@ -2551,6 +2551,14 @@ inside_main_func (frame_info_ptr this_frame) | |
47 | if (bs.symbol == nullptr) | |
48 | return false; | |
49 | ||
50 | + /* We might have found some unrelated symbol. For example, the | |
51 | + Rust compiler can emit both a subprogram and a namespace with | |
52 | + the same name in the same scope; and due to how gdb's symbol | |
53 | + tables currently work, we can't request the one we'd | |
54 | + prefer. */ | |
55 | + if (bs.symbol->aclass () != LOC_BLOCK) | |
56 | + return false; | |
57 | + | |
58 | const struct block *block = bs.symbol->value_block (); | |
59 | gdb_assert (block != nullptr); | |
60 | sym_addr = block->start (); | |
61 | diff --git a/gdb/testsuite/gdb.rust/main-crash.exp b/gdb/testsuite/gdb.rust/main-crash.exp | |
62 | new file mode 100644 | |
63 | index 00000000000..9c513f91c1d | |
64 | --- /dev/null | |
65 | +++ b/gdb/testsuite/gdb.rust/main-crash.exp | |
66 | @@ -0,0 +1,35 @@ | |
67 | +# Copyright (C) 2023 Free Software Foundation, Inc. | |
68 | + | |
69 | +# This program is free software; you can redistribute it and/or modify | |
70 | +# it under the terms of the GNU General Public License as published by | |
71 | +# the Free Software Foundation; either version 3 of the License, or | |
72 | +# (at your option) any later version. | |
73 | +# | |
74 | +# This program is distributed in the hope that it will be useful, | |
75 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
76 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
77 | +# GNU General Public License for more details. | |
78 | +# | |
79 | +# You should have received a copy of the GNU General Public License | |
80 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
81 | + | |
82 | +# Regression test for a crash in inside_main_func. | |
83 | + | |
84 | +load_lib rust-support.exp | |
85 | +require allow_rust_tests | |
86 | + | |
87 | +standard_testfile main.rs | |
88 | +if {[prepare_for_testing "failed to prepare" $testfile $srcfile \ | |
89 | + {debug rust}]} { | |
90 | + return -1 | |
91 | +} | |
92 | + | |
93 | +set line [gdb_get_line_number "BREAK"] | |
94 | +# The bug was that this would crash. | |
95 | +if {![runto ${srcfile}:$line]} { | |
96 | + untested "could not run to breakpoint" | |
97 | + return -1 | |
98 | +} | |
99 | + | |
100 | +# Test that gdb is alive. | |
101 | +gdb_test "print 23" " = 23" | |
102 | diff --git a/gdb/testsuite/gdb.rust/main.rs b/gdb/testsuite/gdb.rust/main.rs | |
103 | new file mode 100644 | |
104 | index 00000000000..8902446551e | |
105 | --- /dev/null | |
106 | +++ b/gdb/testsuite/gdb.rust/main.rs | |
107 | @@ -0,0 +1,30 @@ | |
108 | +// Copyright (C) 2016-2023 Free Software Foundation, Inc. | |
109 | + | |
110 | +// This program is free software; you can redistribute it and/or modify | |
111 | +// it under the terms of the GNU General Public License as published by | |
112 | +// the Free Software Foundation; either version 3 of the License, or | |
113 | +// (at your option) any later version. | |
114 | +// | |
115 | +// This program is distributed in the hope that it will be useful, | |
116 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
117 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
118 | +// GNU General Public License for more details. | |
119 | +// | |
120 | +// You should have received a copy of the GNU General Public License | |
121 | +// along with this program. If not, see <http://www.gnu.org/licenses/>. | |
122 | + | |
123 | +#![allow(dead_code)] | |
124 | +#![allow(unused_variables)] | |
125 | +#![allow(unused_assignments)] | |
126 | + | |
127 | +fn global_fn(x: u8) { | |
128 | + // BREAK | |
129 | +} | |
130 | + | |
131 | +fn main() { | |
132 | + fn nested(y: u8) { | |
133 | + global_fn(y) | |
134 | + } | |
135 | + | |
136 | + nested(23); | |
137 | +} | |
138 | -- | |
139 | 2.39.1 |