Bug 25009

Summary: terminate called after throwing an instance of 'srchilite::ParserException'
Product: gdb Reporter: Tom de Vries <vries>
Component: gdbAssignee: Not yet assigned to anyone <unassigned>
Severity: normal    
Priority: P2    
Version: 8.3   
Target Milestone: 8.3.1   
Host: Target:
Build: Last reconfirmed:

Description Tom de Vries 2019-09-18 12:22:54 UTC
I recently updated my regular build setup to include an installed
libsource-highlight.so by installing package libsource-highlight-devel
in openSUSE Leap 15.1.

Subsequently I ran into this error in the gdb 8.3 branch:
$ ./install/bin/gdb -q a.out -ex start
Reading symbols from a.out...
Temporary breakpoint 1 at 0x40053b: file hello.c, line 9.
Starting program: /data/gdb_versions/devel/a.out

Temporary breakpoint 1, main () at hello.c:9
terminate called after throwing an instance of 'srchilite::ParserException'
  what():  error during the parsing of a definition file
Aborted (core dumped)

This exception happens when the library attempts to access
/usr/share/source-highlight/esc.outlang, which is not there, because
it's contained in another package (source-highlight). Installing that
package fixes the error.
Comment 1 Tom de Vries 2019-09-18 12:31:27 UTC
This is fixed by master commit d806ea2d0e " Add Rust support to source highlighting".
Comment 2 cvs-commit@gcc.gnu.org 2019-09-19 14:19:15 UTC
The gdb-8.3-branch branch has been updated by Tom de Vries <vries@sourceware.org>:


commit ef93dd73bcaefd1736cbc9aaf9a0178be7976b6e
Author: Tom Tromey <tom@tromey.com>
Date:   Thu Sep 19 16:18:33 2019 +0200

    Add --with-static-standard-libraries to the top level
    [ Backport of master commit c1a5d03a89. ]
    gdb should normally not be linked with -static-libstdc++.  Currently
    this has not caused problems, but it's incompatible with catching an
    exception thrown from a shared library -- and a subsequent patch
    changes gdb to do just this.
    This patch adds a new --with-static-standard-libraries flag to the
    top-level configure.  It defaults to "auto", which means enabled if
    gcc is being built, and disabled otherwise.
    2019-08-19  Tom Tromey  <tom@tromey.com>
    	PR gdb/25009
    	* configure: Rebuild.
    	* configure.ac: Add --with-static-standard-libraries.
Comment 3 cvs-commit@gcc.gnu.org 2019-09-19 14:19:20 UTC
The gdb-8.3-branch branch has been updated by Tom de Vries <vries@sourceware.org>:


commit 60cdff2f2222a49df78a682ad9f2c1c7faf1eb49
Author: Tom Tromey <tom@tromey.com>
Date:   Thu Sep 19 16:18:33 2019 +0200

    Add Rust support to source highlighting
    [ Backport of master commit d806ea2d0e. ]
    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.
    2019-08-19  Tom Tromey  <tom@tromey.com>
    	PR gdb/25009
    	* 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.
Comment 4 Tom de Vries 2019-09-19 14:20:27 UTC
Fixed on 8.3.1 branch.
Comment 5 cvs-commit@gcc.gnu.org 2019-09-19 17:50:19 UTC
The master branch has been updated by Tom de Vries <vries@sourceware.org>:


commit f64e2f4045485f99b4ce6649fdab874dacccd5a6
Author: Tom de Vries <tdevries@suse.de>
Date:   Thu Sep 19 19:49:39 2019 +0200

    [gdb] Catch exception when constructing the highlighter
    Currently in source_cache::ensure we catch the exception that triggers when
    highlighter->highlight is called:
                 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.
    2019-09-19  Tom de Vries  <tdevries@suse.de>
    	PR gdb/25009
    	* source-cache.c (source_cache::ensure): Catch exception thrown during
    	construction of the highlighter.
Comment 6 Tom de Vries 2019-09-19 17:51:23 UTC
And now master has the same fix as in 8.3.1.

Marking resolved-fixed.