From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 773583858426; Thu, 12 Oct 2023 07:58:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 773583858426 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1697097539; bh=4GsLj3iceV3A7Rzoe987nY0zGI6ZwroHwsDcbrSG4Os=; h=From:To:Subject:Date:From; b=TwdLCIAqZhG66HF5c/bufAQerhvgcNWlpu6PhU8NX5huzwxnKhCVnIle33k0R7sKK 36dWD72GATochNBTEP9IfAC4fQIwKgERpsdpZH8UFrUpqGjQUNj8ptBxEcq8HoCpA0 l9M+4phs73sqPeqbzkvMTukw8pRs4GgRs4su9v/k= From: "vries at gcc dot gnu.org" To: gdb-prs@sourceware.org Subject: [Bug cli/30966] New: [gdb/cli] pygments finds language based on file name, source-highlight finds language based on debug info Date: Thu, 12 Oct 2023 07:58:59 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: cli X-Bugzilla-Version: HEAD X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: vries at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D30966 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=20 $ gdb -q a.out=20 Reading symbols from a.out... (gdb) start Temporary breakpoint 1 at 0x40051b: file hello.c, line 6. Starting program: /data/vries/gdb/a.out=20 Temporary breakpoint 1, main () at hello.c:6 highlighting: /data/vries/gdb/hello.c 6 printf ("hello\n"); (gdb)=20 ... 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=20 $ gdb -q a.out=20 Reading symbols from a.out... (gdb) start Temporary breakpoint 1 at 0x40051b: file hello, line 6. Starting program: /data/vries/gdb/a.out=20 Temporary breakpoint 1, main () at hello:6 highlighting: /data/vries/gdb/hello 6 printf ("hello\n"); (gdb)=20 ... 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-highli= ght enabled off"). First, with file extension: ... $ gcc hello.c -g=20 $ 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=20 Temporary breakpoint 1, main () at hello.c:6 6 printf ("hello\n"); (gdb)=20 ... Line 6 is highlighted, by pygments. And without: ... $ gcc -x c hello -g=20 $ 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=20 Temporary breakpoint 1, main () at hello:6 6 printf ("hello\n"); (gdb)=20 ... 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=20 - picking the parser for the language guessed from the file name. --=20 You are receiving this mail because: You are on the CC list for the bug.=