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

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).