From: Kevin Buettner <kevinb@redhat.com>
To: Guinevere Larsen <guinevere@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH v7 0/5] Introduce syntax for linker-namespace specific symbols
Date: Sat, 7 Nov 2026 20:58:57 -0700 [thread overview]
Message-ID: <4f1aeae3-fd3a-43ff-b419-ffec1965786d@redhat.com> (raw)
In-Reply-To: <20260601192251.60958-1-guinevere@redhat.com>
On 6/1/26 12:22 PM, Guinevere Larsen wrote:
> This series adds support for the syntax [[N]]::foo to find symbols that
> belong to specific namespaces, while also making GDB's behavior more
> consistent when a namespace is not specified. This needs 2 preparatory
> patches and 2 patches actually implementing this feature, and one final
> patch to make symtab searching more consistent with the [[N]]::foo
> syntax.
>
> Patch 1 is a small refactor, creating a function to figure out the
> current linker namespace. Patch 2 is an essential fix, updating how we
> calculate a variable's copy relocation to take linker namespaces into
> account.
>
> Patches 3 and 4 implement the new syntax, adding the necessary
> supporting code and updating error messages when symbols can't be found
> - where it made sense. Patch 5 is a small change to the find_symtab
> function, to prefer symtabs from the current linker namespace.
First, I'm sure that it'll come as no surprise that this series needs a
rebase now.
I had my AI code reviewers look at it - they were able to sort out the
rebase and do a review anyway.
The major finding is that the ]] token is a problem. I asked the AI to
demo this for me in a terminal. Here is its example:
ai-user@ai-sandbox:~$ mkdir -p ~/demo-dblbracket && cd ~/demo-dblbracket &&
cat > demo.c <<'EOF'> int a[3] = {10, 20, 30};
> int b[2] = {1, 2};
> int main (void) { return a[b[0]]; }
> EOFai-user@ai-sandbox:demo-dblbracket$ gcc -g -O0 demo.c -o demo && ls -la demo
-rwxr-xr-x 1 ai-user ai-user 13496 Nov 7 19:16 demo
ai-user@ai-sandbox:demo-dblbracket$ ~/builds/binutils-gdb-patch-review-basel
ine-install/bin/gdb -q ./demo
Reading symbols from ./demo...
(gdb) break main
Breakpoint 1 at 0x40044a: file demo.c, line 3.
(gdb) run
Starting program: /home/ai-user/demo-dblbracket/demo
[ debuginfod stuff snipped ]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Breakpoint 1, main () at demo.c:3
3 int main (void) { return a[b[0]]; }
(gdb) print b[0]
$1 = 1
(gdb) print a[b[0]]
$2 = 20
(gdb) print a[b[1]] * 2
$3 = 60
(gdb) quit
A debugging session is active.
Inferior 1 [process 2232454] will be killed.
Quit anyway? (y or n) y
ai-user@ai-sandbox:demo-dblbracket$ ~/builds/binutils-gdb-patch-review-insta
ll/bin/gdb -q ./demo
Reading symbols from ./demo...
(gdb) set debuginfod enabled off
(gdb) break main
Breakpoint 1 at 0x40044a: file demo.c, line 3.
(gdb) run
Starting program: /home/ai-user/demo-dblbracket/demo
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Breakpoint 1, main () at demo.c:3
3 int main (void) { return a[b[0]]; }
(gdb) print a[b[0]]
❌️ A syntax error in expression, near `]]'.
(gdb) print a[0]
$1 = 10
(gdb) print [[0]]::b
$2 = {1, 2}
(gdb) quit
A debugging session is active.
Inferior 1 [process 2234693] will be killed.
Quit anyway? (y or n) y
GLM 5.3 Flash (whose suggestion was endorsed by Opus 5.5) made this
recommendation:
While reviewing the v7 series ("Introduce syntax for linker-namespace
specific symbols") we found one problem worth fixing before the next
round: patch 3/5 adds standalone double-square tokens for "[[" and
"]]" in tokentab2, matched unconditionally by the lexer. Those
two-character sequences are legitimate text in existing languages,
so this breaks:
* C nested subscripts: print a[b[0]]
The trailing "]]" is consumed as one token, giving a syntax
error. Without the series the same expression parses.
* Objective-C nested message sends: print [[obj alloc] init]
The leading "[[" is consumed as the namespace-open token, and
the parse fails immediately.
Both are confirmed by running the same expressions with and without
the series applied, and neither case is covered by any existing
test.
Recommended fix: do not add standalone "[[" and "]]" tokens.
Instead, have the lexer recognize only the complete namespace
construct as a single token:
* On seeing "[[", peek ahead. Emit the namespace token only
when the input matches [[<digits>]] (whitespace already
allowed by the grammar may be skipped within the match),
carrying the integer as the token's value.
* Otherwise, fall back to lexing "[" normally. In particular,
no "]]" token is needed at all, which leaves "]]" free for
array subscripts and Objective-C.
The parser rule then consumes that one token and uses its numeric
value. Since the grammar already restricts N to an integer, the
integer check simply moves into the lexer. One error path needs
care: "[[foo]]" should still produce a namespace-related
diagnostic rather than a generic syntax error.
Please also add tests for both cases above in v8; nothing in the
current testsuite would have caught this.
Additionally, Opus 5.5 also posited a scenario regarding non-stop mode.
This is GLM 5.3's write-up:
Another finding from the v7 review (5/5 and 3/5): new code paths can
now throw from get_selected_frame.
1/5 adds get_current_linker_namespace (), which calls
get_frame_pc (get_selected_frame ()). That is fine for the
$_linker_namespace convenience variable, which already needed a
selected frame. But 5/5's find_symtab calls it for every
lookup_symtab / for_each_symtab call while more than one namespace
is active, and those run from code that never needed a selected
frame before:
* linespec: break file.c:NN, and automatic breakpoint re-set
* list
* MI -symbol-list-lines and -data-disassemble
* the ada, m2 and pascal parsers
3/5 also calls it from the name_not_typename minimal-symbol
fallback.
Scenario: in non-stop or background mode, with the selected thread
running and dlmopen namespaces active, "break lib.c:30" now fails
with "Selected thread is running." instead of working. Breakpoint
re-set also runs at events where the user cannot control which
thread is selected, so the failure can appear long after the
original command.
Suggested fix: get_current_linker_namespace () should return 0
(meaning "unknown" / do not restrict the search) when
!has_stack_frames () or the selected thread is running, and that
behaviour should be documented in solib.h.
This one is confirmed by code reading only so far; the reproducer
above has not been run against a rebased series.
Kevin
prev parent reply other threads:[~2026-11-08 3:59 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-01 19:22 Guinevere Larsen
2026-06-01 19:22 ` [PATCH v7 1/5] gdb: Create helper function for the current namespace Guinevere Larsen
2026-06-01 19:22 ` [PATCH v7 2/5] gdb: make lookup_minimal_symbol_linkage work with linker namespaces Guinevere Larsen
2026-06-01 19:22 ` [PATCH v7 3/5] gdb: Make the parser recognize the [[N]] syntax for variables Guinevere Larsen
2026-06-01 19:22 ` [PATCH v7 4/5] gdb: extend the [[N]]::foo syntax for files Guinevere Larsen
2026-06-01 19:22 ` [PATCH v7 5/5] gdb: prefer symtabs for the current linker namespace Guinevere Larsen
2026-06-03 18:26 ` Guinevere Larsen
2026-06-03 19:16 ` [PATCH v7 5/5] Fixed " Guinevere Larsen
2026-06-22 20:35 ` [PING][PATCH v7 0/5] Introduce syntax for linker-namespace specific symbols Guinevere Larsen
2026-08-06 18:46 ` Guinevere Larsen
2026-09-02 19:32 ` Guinevere Larsen
2026-09-18 12:55 ` Guinevere Larsen
2026-10-19 19:19 ` [PINGv3][PATCH " Guinevere Larsen
2026-11-08 3:58 ` Kevin Buettner [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4f1aeae3-fd3a-43ff-b419-ffec1965786d@redhat.com \
--to=kevinb@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=guinevere@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox