From patchwork Sun Mar 19 15:35:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 66618 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BEC153858032 for ; Sun, 19 Mar 2023 15:35:34 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from alt-proxy28.mail.unifiedlayer.com (alt-proxy28.mail.unifiedlayer.com [74.220.216.123]) by sourceware.org (Postfix) with ESMTPS id 663C43858D1E for ; Sun, 19 Mar 2023 15:35:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 663C43858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw11.mail.unifiedlayer.com (unknown [10.0.90.126]) by progateway1.mail.pro1.eigbox.com (Postfix) with ESMTP id 8EDDB1003A10D for ; Sun, 19 Mar 2023 15:35:18 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id dv42puNQLA6Qfdv42p6pwV; Sun, 19 Mar 2023 15:35:18 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=TYtTCTch c=1 sm=1 tr=0 ts=64172bb6 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=k__wU0fu6RkA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=CCpqsmhAAAAA:8 a=7TmaS0D2TWCmNRk2jYkA:9 a=ul9cdbp4aOFLsgKbc677:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Q8mex27cRzV8eIrYMU1RMv4NH6ouO9/l81Ad2QJHo1Y=; b=HmxvPIqe/zawBqP/bJ9vSDwx1X 7xEayPPgWnHYz8bh+6/HSpfIysGUuEhk5oJeDldZXGYRGYM/wOD9VlLpFZjFWDUsj/wzLR480g5uO E/GZu7QDBDl3hfuvBz91QXEUH; Received: from 71-211-185-113.hlrn.qwest.net ([71.211.185.113]:43772 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pdv42-002GxD-7Z; Sun, 19 Mar 2023 09:35:18 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Use rust_demangle to fix a crash Date: Sun, 19 Mar 2023 09:35:06 -0600 Message-Id: <20230319153506.3382669-1-tom@tromey.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 71.211.185.113 X-Source-L: No X-Exim-ID: 1pdv42-002GxD-7Z X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-185-113.hlrn.qwest.net (localhost.localdomain) [71.211.185.113]:43772 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3025.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_ABUSEAT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" 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 --- gdb/defs.h | 8 ++++---- gdb/rust-lang.h | 4 ++-- gdb/testsuite/gdb.rust/methods.exp | 3 +++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/gdb/defs.h b/gdb/defs.h index 90748c586f4..a83171e92b9 100644 --- a/gdb/defs.h +++ b/gdb/defs.h @@ -204,9 +204,9 @@ extern void quit_serial_event_clear (void); these languages, so some symbols could be successfully demangled by several languages. For that reason, the constants here are sorted in the order we'll attempt demangling them. For example: Rust uses - C++ mangling, so must come after C++; Ada must come last (see - ada_sniff_from_mangled_name). (Keep this order in sync with the - 'languages' array in language.c.) */ + a C++-compatible mangling, so must come before C++; Ada must come + last (see ada_sniff_from_mangled_name). (Keep this order in sync + with the 'languages' array in language.c.) */ enum language { @@ -214,6 +214,7 @@ enum language language_auto, /* Placeholder for automatic setting */ language_c, /* C */ language_objc, /* Objective-C */ + language_rust, /* Rust */ language_cplus, /* C++ */ language_d, /* D */ language_go, /* Go */ @@ -222,7 +223,6 @@ enum language language_asm, /* Assembly language */ language_pascal, /* Pascal */ language_opencl, /* OpenCL */ - language_rust, /* Rust */ language_minimal, /* All other languages, minimal support only */ language_ada, /* Ada */ nr_languages diff --git a/gdb/rust-lang.h b/gdb/rust-lang.h index 37a22e7a404..efe721c5707 100644 --- a/gdb/rust-lang.h +++ b/gdb/rust-lang.h @@ -93,7 +93,7 @@ class rust_language : public language_defn (const char *mangled, gdb::unique_xmalloc_ptr *demangled) const override { - *demangled = gdb_demangle (mangled, DMGL_PARAMS | DMGL_ANSI); + demangled->reset (rust_demangle (mangled, 0)); return *demangled != NULL; } @@ -102,7 +102,7 @@ class rust_language : public language_defn gdb::unique_xmalloc_ptr demangle_symbol (const char *mangled, int options) const override { - return gdb_demangle (mangled, options); + return gdb::unique_xmalloc_ptr (rust_demangle (mangled, options)); } /* See language.h. */ diff --git a/gdb/testsuite/gdb.rust/methods.exp b/gdb/testsuite/gdb.rust/methods.exp index 8374ab162ec..72be6a11ab0 100644 --- a/gdb/testsuite/gdb.rust/methods.exp +++ b/gdb/testsuite/gdb.rust/methods.exp @@ -59,3 +59,6 @@ gdb_test "print *self" " = 23" gdb_test "info functions HasMethods::new" \ "fn methods::HasMethods::new\\(\\) -> methods::HasMethods;" +# Regression test for PR rust/20367 and PR rust/30211. This used to +# crash. +gdb_test_no_output "complete break what"