[Bug breakpoints/34112] New: rbreak `file:regex` sets breakpoints for matches outside of `file` [reproducer attached]

daniel at armengod dot cat sourceware-bugzilla@sourceware.org
Mon Apr 27 20:24:28 GMT 2026


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

            Bug ID: 34112
           Summary: rbreak `file:regex` sets breakpoints for matches
                    outside of `file` [reproducer attached]
           Product: gdb
           Version: 17.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: breakpoints
          Assignee: unassigned at sourceware dot org
          Reporter: daniel at armengod dot cat
  Target Milestone: ---

Encountered "organically" while debugging a program designed around a plugin
architecture that makes heavy use of `dlopen()`ed objects. Such architecture
naturally produces many functions with the same names (e.g. `plugin_init()`,
`plugin_fini()`, `plugin_interface_foobar()`, ...) across different files.

It is not necessary to use `dlopen()` to reproduce. Collisions with functions
declared with internal linkage trigger this issue as well.

### Steps to reproduce ###

Load into GDB a program that has at least one function with the same name in
two locations.

For example, a program consisting of `lib.c` and `prog.c`:

lib.c
static char* naming_collision_oops() {
        return "Unfortunately-named function from library.\n";
}

char* lib_public_interface() {
        return naming_collision_oops();
}

prog.c
#include <stdio.h>

char* naming_collision_oops() {
        return "Unfortunately-named function from main program.\n";
}

char* lib_public_interface();

int main() {
        char* ret;
        ret = naming_collision_oops();
        printf("%s", ret);
        ret = lib_public_interface();
        printf("%s", ret);
}

Compile:
gcc -g -c -o lib.o lib.c
gcc -g prog.c lib.o -o prog

### Expected results ###

When run under GDB, `rbreak prog.c:naming_collision_oops` should place one
breakpoint at `naming_collision_oops` defined in `prog.c`.

### Actual results ###

When run under GDB, `rbreak prog.c:naming_collision_oops` places two
breakpoints, one for each occurrence of `naming_collision_oops()`

Terminal transcript of the reproducer found at the end of this message.

### Related bugs ###

I haven't found any duplicates in the issue tracker. The most related issue,
which hopefully hints at the underlying root cause, is issue 14340. From its
description:

>rbreak_command first calls search_symbols to collect the list of symbols that match the regexp (or file:regexp).  It then loops over each found symbol calling, essentially, "break file:function" [...]

Tested with GDB nightly at the time of writing.

### Actual results -- transcript ###

daniel@batou:~/gdb-rbreak/static-prog$ gdb ./prog
GNU gdb (GDB) 17.1.90.20260427-git
Copyright (C) 2025 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./prog...
(gdb) rbreak prog.c:naming_collision_oops
Breakpoint 1 at 0x113d: naming_collision_oops. (2 locations)
char *naming_collision_oops();
Successfully created breakpoint 1.
(gdb) info break
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   <MULTIPLE>         
1.1                         y   0x000000000000113d in naming_collision_oops at
prog.c:4
1.2                         y   0x00000000000011ab in naming_collision_oops at
lib.c:2
(gdb) r
Starting program: /home/daniel/gdb-rbreak/static-prog/prog 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1.1, naming_collision_oops () at prog.c:4
4               return "Unfortunately-named function from main program.\n";
(gdb) c
Continuing.
Unfortunately-named function from main program.

Breakpoint 1.2, naming_collision_oops () at lib.c:2
2               return "Unfortunately-named function from library.\n";
(gdb) c
Continuing.
Unfortunately-named function from library.
[Inferior 1 (process 309342) exited normally]
(gdb) q

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


More information about the Gdb-prs mailing list