From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 56336 invoked by alias); 19 Sep 2019 16:18:32 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 56328 invoked by uid 89); 19 Sep 2019 16:18:32 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 19 Sep 2019 16:18:30 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 3405E69B16; Thu, 19 Sep 2019 16:18:28 +0000 (UTC) Subject: [PATCH][gdb] Catch exception when constructing the highlighter To: Tom Tromey Cc: gdb-patches@sourceware.org, Pedro Alves References: <20190727155155.32417-1-tom@tromey.com> <20190727155155.32417-3-tom@tromey.com> <332da42c-ae75-a148-221f-4f7bb815f40f@suse.de> <87v9u05en8.fsf@tromey.com> <87pnjywzmz.fsf@tromey.com> <44701c2c-21a7-0211-cc45-b6214ecfb165@suse.de> <87woe4saz0.fsf@tromey.com> From: Tom de Vries Openpgp: preference=signencrypt Message-ID: <2e0b9a76-a897-167e-6d4b-46174bfc6da7@suse.de> Date: Thu, 19 Sep 2019 16:18:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <87woe4saz0.fsf@tromey.com> Content-Type: multipart/mixed; boundary="------------51C9A88EF8D805B57F589ADB" X-IsSubscribed: yes X-SW-Source: 2019-09/txt/msg00368.txt.bz2 This is a multi-part message in MIME format. --------------51C9A88EF8D805B57F589ADB Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-length: 799 [ was: Re: [PATCH v2 2/2] Add Rust support to source highlighting ] On 19-09-19 14:54, Tom Tromey wrote: >>>>>> "Tom" == Tom de Vries writes: > > Tom> Well, it does work, but your question makes me realize that that's an > Tom> implementation artefact of the library, which could change for newer > Tom> version (or perhaps there are older versions where that differs). So it > Tom> should be safer to wrap highlighter construction as well. > > Tom> Updated the patch accordingly, and also added a PR number to both patches. > > Looks good to me -- but the bad news is you'll probably now want a > similar patch on master. Ok, committed to 8.3 branch. Here's the proposed commit for master. Ok for trunk if testing on x86_64-linux finishes without problems? Thanks, - Tom --------------51C9A88EF8D805B57F589ADB Content-Type: text/x-patch; name="0001-gdb-Catch-exception-when-constructing-the-highlighter.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename*0="0001-gdb-Catch-exception-when-constructing-the-highlighter.p"; filename*1="atch" Content-length: 2015 [gdb] Catch exception when constructing the highlighter Currently in source_cache::ensure we catch the exception that triggers when highlighter->highlight is called: ... try { std::istringstream input (contents); std::ostringstream output; highlighter->highlight (input, output, lang_name, fullname); ... and the file used earlier in the construction of the highlighter: ... highlighter = new srchilite::SourceHighlight ("esc.outlang"); ... is missing. The fact that this exception triggers when highlighter->highlight is called is an implementation artefact of libsource-highlight.so though, and this could be different for older or newer versions. Make things more robust by also catching exceptions thrown during construction of the highlighter. This makes the handling on master equivalent with what has been committed for 8.3.1. Tested on x86_64-linux. gdb/ChangeLog: 2019-09-19 Tom de Vries PR gdb/25009 * source-cache.c (source_cache::ensure): Catch exception thrown during construction of the highlighter. --- gdb/source-cache.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gdb/source-cache.c b/gdb/source-cache.c index 7a52ce9458..1fe6da8132 100644 --- a/gdb/source-cache.c +++ b/gdb/source-cache.c @@ -190,14 +190,14 @@ source_cache::ensure (struct symtab *s) conditional compilation in source-cache.h. */ static srchilite::SourceHighlight *highlighter; - if (highlighter == nullptr) - { - highlighter = new srchilite::SourceHighlight ("esc.outlang"); - highlighter->setStyleFile ("esc.style"); - } - try { + if (highlighter == nullptr) + { + highlighter = new srchilite::SourceHighlight ("esc.outlang"); + highlighter->setStyleFile ("esc.style"); + } + std::istringstream input (contents); std::ostringstream output; highlighter->highlight (input, output, lang_name, fullname); --------------51C9A88EF8D805B57F589ADB--