public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug cli/30966] New: [gdb/cli] pygments finds language based on file name, source-highlight finds language based on debug info
@ 2023-10-12  7:58 vries at gcc dot gnu.org
  2023-10-12  8:20 ` [Bug cli/30966] " vries at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: vries at gcc dot gnu.org @ 2023-10-12  7:58 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=30966

            Bug ID: 30966
           Summary: [gdb/cli] pygments finds language based on file name,
                    source-highlight finds language based on debug info
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: cli
          Assignee: unassigned at sourceware dot org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

Consider a hello world, and gdb running to the first line:
...
$ gcc hello.c -g 
$ gdb -q a.out 
Reading symbols from a.out...
(gdb) start
Temporary breakpoint 1 at 0x40051b: file hello.c, line 6.
Starting program: /data/vries/gdb/a.out 

Temporary breakpoint 1, main () at hello.c:6
highlighting: /data/vries/gdb/hello.c
6         printf ("hello\n");
(gdb) 
...
Line 6 is highlighted, by source-highlight.

Likewise if we use an identical file that does not have a file extension:
...
$ gcc -x c hello -g 
$ gdb -q a.out 
Reading symbols from a.out...
(gdb) start
Temporary breakpoint 1 at 0x40051b: file hello, line 6.
Starting program: /data/vries/gdb/a.out 

Temporary breakpoint 1, main () at hello:6
highlighting: /data/vries/gdb/hello
6         printf ("hello\n");
(gdb) 
...
This is because the debug info contains the language, and that language is used
to pick the source-highlight parser, see source-cache.c:get_language_name.

Now let's try the same with pygments (by using "maint set gnu-source-highlight
enabled off").

First, with file extension:
...
$ gcc hello.c -g 
$ gdb -q -iex "maint set gnu-source-highlight enabled off" a.out
Reading symbols from a.out...
(gdb) start
Temporary breakpoint 1 at 0x40051b: file hello.c, line 6.
Starting program: /data/vries/gdb/a.out 

Temporary breakpoint 1, main () at hello.c:6
6         printf ("hello\n");
(gdb) 
...
Line 6 is highlighted, by pygments.

And without:
...
$ gcc -x c hello -g 
$ gdb -q -iex "maint set gnu-source-highlight enabled off" a.out
Reading symbols from a.out...
(gdb) start
Temporary breakpoint 1 at 0x40051b: file hello, line 6.
Starting program: /data/vries/gdb/a.out 

Temporary breakpoint 1, main () at hello:6
6         printf ("hello\n");
(gdb) 
...
Line 6 is not highlighted, because the pygments method doesn't try to figure
out which parser to use based on language in the debug info.

Conversely, if gdb can't decide what parser to use for source-highlight, it
gives up (and falls back to pygments), even though source-highlight might be
able to figure out which parser to use based on the file extension.

If both source-highlight and pygments are available, the two complement each
other, such that we're likely to get highlighting.

But if only one is available, that's not the case, and each method should be
improved to try both:
- picking the parser for the language from the debug info, and 
- picking the parser for the language guessed from the file name.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug cli/30966] [gdb/cli] pygments finds language based on file name, source-highlight finds language based on debug info
  2023-10-12  7:58 [Bug cli/30966] New: [gdb/cli] pygments finds language based on file name, source-highlight finds language based on debug info vries at gcc dot gnu.org
@ 2023-10-12  8:20 ` vries at gcc dot gnu.org
  2023-10-12  9:18 ` sam at gentoo dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: vries at gcc dot gnu.org @ 2023-10-12  8:20 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=30966

--- Comment #1 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #0)
> Conversely, if gdb can't decide what parser to use for source-highlight, it
> gives up (and falls back to pygments), even though source-highlight might be
> able to figure out which parser to use based on the file extension.

See https://www.gnu.org/software/src-highlite/source-highlight-lib.html which
shows the example ./lib/examples/source-highlight-console-main.cpp with this
bit:
...
             // we have a file name so we detect the input source language
             srchilite::LangMap langMap(DATADIR, "lang.map");
             string lang = langMap.getMappedFileNameFromFileName(argv[1]);
             if (lang != "") {
                 inputLang = lang;
...

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug cli/30966] [gdb/cli] pygments finds language based on file name, source-highlight finds language based on debug info
  2023-10-12  7:58 [Bug cli/30966] New: [gdb/cli] pygments finds language based on file name, source-highlight finds language based on debug info vries at gcc dot gnu.org
  2023-10-12  8:20 ` [Bug cli/30966] " vries at gcc dot gnu.org
@ 2023-10-12  9:18 ` sam at gentoo dot org
  2023-10-18 16:57 ` vries at gcc dot gnu.org
  2023-10-20 20:22 ` cvs-commit at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: sam at gentoo dot org @ 2023-10-12  9:18 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=30966

Sam James <sam at gentoo dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sam at gentoo dot org

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug cli/30966] [gdb/cli] pygments finds language based on file name, source-highlight finds language based on debug info
  2023-10-12  7:58 [Bug cli/30966] New: [gdb/cli] pygments finds language based on file name, source-highlight finds language based on debug info vries at gcc dot gnu.org
  2023-10-12  8:20 ` [Bug cli/30966] " vries at gcc dot gnu.org
  2023-10-12  9:18 ` sam at gentoo dot org
@ 2023-10-18 16:57 ` vries at gcc dot gnu.org
  2023-10-20 20:22 ` cvs-commit at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: vries at gcc dot gnu.org @ 2023-10-18 16:57 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=30966

--- Comment #2 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #1)
> (In reply to Tom de Vries from comment #0)
> > Conversely, if gdb can't decide what parser to use for source-highlight, it
> > gives up (and falls back to pygments), even though source-highlight might be
> > able to figure out which parser to use based on the file extension.
> 
> See https://www.gnu.org/software/src-highlite/source-highlight-lib.html
> which shows the example ./lib/examples/source-highlight-console-main.cpp
> with this bit:
> ...
>              // we have a file name so we detect the input source language
>              srchilite::LangMap langMap(DATADIR, "lang.map");
>              string lang = langMap.getMappedFileNameFromFileName(argv[1]);
>              if (lang != "") {
>                  inputLang = lang;
> ...

https://sourceware.org/pipermail/gdb-patches/2023-October/203387.html

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug cli/30966] [gdb/cli] pygments finds language based on file name, source-highlight finds language based on debug info
  2023-10-12  7:58 [Bug cli/30966] New: [gdb/cli] pygments finds language based on file name, source-highlight finds language based on debug info vries at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-10-18 16:57 ` vries at gcc dot gnu.org
@ 2023-10-20 20:22 ` cvs-commit at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-10-20 20:22 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=30966

--- Comment #3 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tom de Vries <vries@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=eefa43c9366e3665f1451d6bbfd46b84dea0d15d

commit eefa43c9366e3665f1451d6bbfd46b84dea0d15d
Author: Tom de Vries <tdevries@suse.de>
Date:   Fri Oct 20 22:23:13 2023 +0200

    [gdb/cli] Allow source-highlight to autodetect language

    Currently when gdb asks the source-highlight library to highlight a file,
it
    tells it what language file to use.

    For instance, if gdb learns from the debug info that the file is
language_c,
    the language file "c.lang" is used.  This mapping is hardcoded in
    get_language_name.

    However, if gdb doesn't know what language file to use, it falls back to
using
    python pygments, and in absence of that, unhighlighted source text.

    In the case of python pygments, it autodetects which language to use based
on
    the file name.

    Add the same capability when using the source-highlight library.

    Tested on x86_64-linux.

    Verified that it works by:
    - making get_language_name return nullptr for language_c, and
    - checking that source-highlight still manages to highlight a hello world.

    Reviewed-By: Guinevere Larsen <blarsen@redhat.com>
    Approved-By: Tom Tromey <tom@tromey.com>

    PR cli/30966
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30966

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-10-20 20:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-12  7:58 [Bug cli/30966] New: [gdb/cli] pygments finds language based on file name, source-highlight finds language based on debug info vries at gcc dot gnu.org
2023-10-12  8:20 ` [Bug cli/30966] " vries at gcc dot gnu.org
2023-10-12  9:18 ` sam at gentoo dot org
2023-10-18 16:57 ` vries at gcc dot gnu.org
2023-10-20 20:22 ` cvs-commit at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).