From patchwork Sat Jul 27 15:51:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 33827 Received: (qmail 130078 invoked by alias); 27 Jul 2019 15:52:11 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 130065 invoked by uid 89); 27 Jul 2019 15:52:11 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=gdbs, gdb's, un-highlighted, disallow X-HELO: gateway34.websitewelcome.com Received: from gateway34.websitewelcome.com (HELO gateway34.websitewelcome.com) (192.185.148.231) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 27 Jul 2019 15:51:59 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway34.websitewelcome.com (Postfix) with ESMTP id 0E8B511889A1 for ; Sat, 27 Jul 2019 10:51:58 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id rOzGhCLij2PzOrOzGhIniA; Sat, 27 Jul 2019 10:51:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=7QzhVcfGGXAAu5OEGr53yZj6EKZg4jEmc4TG+pju+8I=; b=w8IBsTED8Aj+wR2OPU1gnQN5xf tGGNkywIP98So4KSBDm19KJe7lqqkNw1DGjQc0LyGbHGd93p8CqTesWibxRroTjFLouLYToLlqSpp dpV/wzBpR+jF+jYrD0R1W7ayg; Received: from 97-122-178-82.hlrn.qwest.net ([97.122.178.82]:51944 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1hrOzF-0008DQ-Qn; Sat, 27 Jul 2019 10:51:57 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 2/2] Add Rust support to source highlighting Date: Sat, 27 Jul 2019 09:51:55 -0600 Message-Id: <20190727155155.32417-3-tom@tromey.com> In-Reply-To: <20190727155155.32417-1-tom@tromey.com> References: <20190727155155.32417-1-tom@tromey.com> Currently, no release of GNU Source Highlight supports Rust. However, I've checked in a patch to do so there, and I plan to make a new release sometime this summer. This patch prepares gdb for that by adding support for Rust to the source highlighting code. Because Source Highlight will throw an exception if the language is unrecognized, this also changes gdb to ignore exceptions here. This will cause gdb to fall back to un-highlighted source text. This updates gdb's configure script to reject the combination of Source Highlight and -static-libstdc++. This is done because it's not possible to use -static-libstdc++ and then catch exceptions from a shared library. Tested with the current and development versions of Source Highlight. gdb/ChangeLog 2019-07-27 Tom Tromey * configure: Rebuild. * configure.ac: Disallow the combination of -static-libstdc++ and source highlight. * source-cache.c (get_language_name): Handle rust. (source_cache::get_source_lines): Ignore highlighting exceptions. --- gdb/ChangeLog | 8 ++++++++ gdb/configure | 6 ++++++ gdb/configure.ac | 8 ++++++++ gdb/source-cache.c | 33 ++++++++++++++++++++++----------- 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/gdb/configure b/gdb/configure index 12954d1f74a..cd92b70958c 100755 --- a/gdb/configure +++ b/gdb/configure @@ -11296,6 +11296,12 @@ $as_echo "no - pkg-config not found" >&6; } as_fn_error $? "pkg-config was not found in your system" "$LINENO" 5 fi else + case "$LDFLAGS" in + *static-libstdc*) + as_fn_error $? "source highlight is incompatible with -static-libstdc++; either use --disable-source-highlight or --without-static-standard-libraries" "$LINENO" 5 + ;; + esac + if ${pkg_config_prog_path} --exists source-highlight; then SRCHIGH_CFLAGS=`${pkg_config_prog_path} --cflags source-highlight` SRCHIGH_LIBS=`${pkg_config_prog_path} --libs source-highlight` diff --git a/gdb/configure.ac b/gdb/configure.ac index 2a43d12df76..3dc4b7549b1 100644 --- a/gdb/configure.ac +++ b/gdb/configure.ac @@ -1217,6 +1217,14 @@ if test "${enable_source_highlight}" != "no"; then AC_MSG_ERROR([pkg-config was not found in your system]) fi else + case "$LDFLAGS" in + *static-libstdc*) + AC_MSG_ERROR([source highlight is incompatible with -static-libstdc++; dnl +either use --disable-source-highlight or dnl +--without-static-standard-libraries]) + ;; + esac + if ${pkg_config_prog_path} --exists source-highlight; then SRCHIGH_CFLAGS=`${pkg_config_prog_path} --cflags source-highlight` SRCHIGH_LIBS=`${pkg_config_prog_path} --libs source-highlight` diff --git a/gdb/source-cache.c b/gdb/source-cache.c index f5bb641a22b..06a244ebbf0 100644 --- a/gdb/source-cache.c +++ b/gdb/source-cache.c @@ -154,8 +154,7 @@ get_language_name (enum language lang) break; case language_rust: - /* Not handled by Source Highlight. */ - break; + return "rust.lang"; case language_ada: return "ada.lang"; @@ -224,18 +223,30 @@ source_cache::get_source_lines (struct symtab *s, int first_line, highlighter->setStyleFile ("esc.style"); } - std::ostringstream output; - highlighter->highlight (input, output, lang_name, fullname); + try + { + std::ostringstream output; + highlighter->highlight (input, output, lang_name, fullname); - source_text result = { fullname, output.str () }; - m_source_map.push_back (std::move (result)); + source_text result = { fullname, output.str () }; + m_source_map.push_back (std::move (result)); - if (m_source_map.size () > MAX_ENTRIES) - m_source_map.erase (m_source_map.begin ()); + if (m_source_map.size () > MAX_ENTRIES) + m_source_map.erase (m_source_map.begin ()); - *lines = extract_lines (m_source_map.back (), first_line, - last_line); - return true; + *lines = extract_lines (m_source_map.back (), first_line, + last_line); + return true; + } + catch (...) + { + /* Source Highlight will throw an exception if + highlighting fails. One possible reason it can + fail is if the language is unknown -- which + matters to gdb because Rust support wasn't added + until after 3.1.8. Ignore exceptions here and + fall back to un-highlighted text. */ + } } } }