Skip to content

Commit 6e7eef7

Browse files
committed
Use rust_demangle to fix a crash
PR rust/30211 points out a crash caused by a particular completion. This turns out to happen because a Rust minsym winds up in a C++-specific path in strncmp_iw_with_mode, which ultimately causes the completer to pass invalid arguments to string::append. This patch fixes the bug by reordering the language constants so that Rust comes before C++, and then using rust_demangle. This ensures that minsyms are correctly marked as "Rust", avoiding this code and thus the crash. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=20367 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30211 Reviewed-By: Andrew Burgess <aburgess@redhat.com>
1 parent 0fea10f commit 6e7eef7

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

gdb/defs.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,16 @@ extern void quit_serial_event_clear (void);
204204
these languages, so some symbols could be successfully demangled by
205205
several languages. For that reason, the constants here are sorted
206206
in the order we'll attempt demangling them. For example: Rust uses
207-
C++ mangling, so must come after C++; Ada must come last (see
208-
ada_sniff_from_mangled_name). (Keep this order in sync with the
209-
'languages' array in language.c.) */
207+
a C++-compatible mangling, so must come before C++; Ada must come
208+
last (see ada_sniff_from_mangled_name). */
210209

211210
enum language
212211
{
213212
language_unknown, /* Language not known */
214213
language_auto, /* Placeholder for automatic setting */
215214
language_c, /* C */
216215
language_objc, /* Objective-C */
216+
language_rust, /* Rust */
217217
language_cplus, /* C++ */
218218
language_d, /* D */
219219
language_go, /* Go */
@@ -222,7 +222,6 @@ enum language
222222
language_asm, /* Assembly language */
223223
language_pascal, /* Pascal */
224224
language_opencl, /* OpenCL */
225-
language_rust, /* Rust */
226225
language_minimal, /* All other languages, minimal support only */
227226
language_ada, /* Ada */
228227
nr_languages

gdb/rust-lang.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class rust_language : public language_defn
9393
(const char *mangled, gdb::unique_xmalloc_ptr<char> *demangled)
9494
const override
9595
{
96-
*demangled = gdb_demangle (mangled, DMGL_PARAMS | DMGL_ANSI);
96+
demangled->reset (rust_demangle (mangled, 0));
9797
return *demangled != NULL;
9898
}
9999

@@ -102,7 +102,7 @@ class rust_language : public language_defn
102102
gdb::unique_xmalloc_ptr<char> demangle_symbol (const char *mangled,
103103
int options) const override
104104
{
105-
return gdb_demangle (mangled, options);
105+
return gdb::unique_xmalloc_ptr<char> (rust_demangle (mangled, options));
106106
}
107107

108108
/* See language.h. */

gdb/testsuite/gdb.rust/methods.exp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,6 @@ gdb_test "print *self" " = 23"
5959
gdb_test "info functions HasMethods::new" \
6060
"fn methods::HasMethods::new\\(\\) -> methods::HasMethods;"
6161

62+
# Regression test for PR rust/20367 and PR rust/30211. This used to
63+
# crash.
64+
gdb_test_no_output "complete break what"

0 commit comments

Comments
 (0)