From patchwork Mon Jun 24 22:05:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 33365 Received: (qmail 9374 invoked by alias); 24 Jun 2019 22:05:46 -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 9365 invoked by uid 89); 24 Jun 2019 22:05:46 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.5 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=sometime, summer X-HELO: gateway33.websitewelcome.com Received: from gateway33.websitewelcome.com (HELO gateway33.websitewelcome.com) (192.185.146.195) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 24 Jun 2019 22:05:44 +0000 Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway33.websitewelcome.com (Postfix) with ESMTP id 1E7B1546E for ; Mon, 24 Jun 2019 17:05:43 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id fX5qhuqdg2qH7fX5qh3njW; Mon, 24 Jun 2019 17:05:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=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: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=GIgVeBgwM1l74I/V0r41JZ1+aD4PMV+NIu0LG7c5Lyg=; b=vbDkXWWJbiojjBhT6m1eJg8dkK 6DLpz6JeQ3/n5nu2XN7tEVt9S3XqKmw+zLeVs/CNnf+Hc2Wus7CiG27lv+8qmrit9YmjEAPpjmr3C JkWu3Yfhm0xyAVprtEtLxbwN7; Received: from 75-166-12-78.hlrn.qwest.net ([75.166.12.78]:57312 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1hfX5q-000aT7-Iy; Mon, 24 Jun 2019 17:05:42 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Add Rust support to source highlighting Date: Mon, 24 Jun 2019 16:05:39 -0600 Message-Id: <20190624220539.16360-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. Tested with the current and development versions of Source Highlight. gdb/ChangeLog 2019-06-24 Tom Tromey * source-cache.c (get_language_name): Handle rust. (source_cache::get_source_lines): Ignore highlighting exceptions. --- gdb/ChangeLog | 5 +++++ gdb/source-cache.c | 33 ++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/gdb/source-cache.c b/gdb/source-cache.c index 86efe83bf9a..72211aa1c34 100644 --- a/gdb/source-cache.c +++ b/gdb/source-cache.c @@ -153,8 +153,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"; @@ -223,18 +222,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 an + fall back to un-highlighted text. */ + } } } }