* [PATCH] gdb: fix breakpoints on inline functions qualified with source file name
@ 2026-07-30 6:15 Markus Metzger
2026-08-06 15:08 ` Guinevere Larsen
0 siblings, 1 reply; 3+ messages in thread
From: Markus Metzger @ 2026-07-30 6:15 UTC (permalink / raw)
To: gdb-patches
On 'break foo.[hc]:foo', GDB only searches the symbols of foo.[hc] on file
scope. If foo has been inlined, GDB would not find it.
On 'break foo', however, GDB also searches local blocks for inline
function symbols in iterate_over_all_matching_symtabs(), which is called
indirectly from add_matching_symbols_to_info().
Add that functionality to add_matching_symbols_to_info() in case it is
called with a list of file symtabs to search.
---
gdb/linespec.c | 14 ++++++++++
gdb/testsuite/gdb.base/break-inline2.c | 33 ++++++++++++++++++++++++
gdb/testsuite/gdb.base/break-inline2.exp | 30 +++++++++++++++++++++
gdb/testsuite/gdb.base/break-inline2.h | 28 ++++++++++++++++++++
4 files changed, 105 insertions(+)
create mode 100644 gdb/testsuite/gdb.base/break-inline2.c
create mode 100644 gdb/testsuite/gdb.base/break-inline2.exp
create mode 100644 gdb/testsuite/gdb.base/break-inline2.h
diff --git a/gdb/linespec.c b/gdb/linespec.c
index b6505ba283d..384c989ef2f 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -4276,6 +4276,20 @@ add_matching_symbols_to_info (const char *name,
set_current_program_space (elt_pspace);
iterate_over_file_blocks (elt, lookup_name, SEARCH_VFT, add_symbol);
+ /* Search local blocks for inline functions, too. */
+ const blockvector *bv = elt->compunit ().blockvector ();
+ for (int i = FIRST_LOCAL_BLOCK; i < bv->num_blocks (); i++)
+ {
+ const struct block *block = bv->block (i);
+ info->state->language->for_each_symbol
+ (block, lookup_name, SEARCH_VFT,
+ [&] (block_symbol *bsym)
+ {
+ if (bsym->symbol->is_inlined ())
+ add_symbol (bsym);
+ });
+ }
+
/* If no new symbols were found in this iteration and this symtab
is in assembler, we might actually be looking for a label for
which we don't have debug info. Check for a minimal symbol in
diff --git a/gdb/testsuite/gdb.base/break-inline2.c b/gdb/testsuite/gdb.base/break-inline2.c
new file mode 100644
index 00000000000..797ab07da31
--- /dev/null
+++ b/gdb/testsuite/gdb.base/break-inline2.c
@@ -0,0 +1,33 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2026 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "break-inline2.h"
+
+static int
+test (void)
+{
+ int f = foo ();
+ int b = bar ();
+ return f + b;
+}
+
+int
+main (void)
+{
+ /* Don't make breakpoints on foo and main bind to the same address. */
+ return test ();
+}
diff --git a/gdb/testsuite/gdb.base/break-inline2.exp b/gdb/testsuite/gdb.base/break-inline2.exp
new file mode 100644
index 00000000000..b10cdece118
--- /dev/null
+++ b/gdb/testsuite/gdb.base/break-inline2.exp
@@ -0,0 +1,30 @@
+# Copyright (C) 2026 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+standard_testfile
+
+if {[prepare_for_testing "failed to prepare" "$testfile" "$srcfile"]} {
+ return
+}
+
+if {![runto_main]} {
+ return
+}
+
+gdb_breakpoint "$testfile.h:foo" -message -allow-pending
+gdb_breakpoint bar -message -allow-pending
+
+gdb_continue_to_breakpoint "foo" ".*foo.entry.*"
+gdb_continue_to_breakpoint "bar" ".*bar.entry.*"
diff --git a/gdb/testsuite/gdb.base/break-inline2.h b/gdb/testsuite/gdb.base/break-inline2.h
new file mode 100644
index 00000000000..e60d054e85b
--- /dev/null
+++ b/gdb/testsuite/gdb.base/break-inline2.h
@@ -0,0 +1,28 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2026 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+static inline int __attribute__((always_inline))
+foo (void) /* foo.entry */
+{ /* foo.entry */
+ return 42; /* foo.entry */
+}
+
+static inline int __attribute__((always_inline))
+bar (void) /* bar.entry */
+{ /* bar.entry */
+ return 42; /* bar.entry */
+}
--
2.34.1
Intel Deutschland GmbH
Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany
Tel: +49 89 991 430, www.intel.de
Managing Directors: Harry Demas, Jeffrey Schneiderman, Yin Chong Sorrell
Chairperson of the Supervisory Board: Nicole Lau
Registered Seat: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] gdb: fix breakpoints on inline functions qualified with source file name
2026-07-30 6:15 [PATCH] gdb: fix breakpoints on inline functions qualified with source file name Markus Metzger
@ 2026-08-06 15:08 ` Guinevere Larsen
2026-08-13 9:56 ` Metzger, Markus T
0 siblings, 1 reply; 3+ messages in thread
From: Guinevere Larsen @ 2026-08-06 15:08 UTC (permalink / raw)
To: Markus Metzger, gdb-patches
On 7/30/26 3:15 AM, Markus Metzger wrote:
> On 'break foo.[hc]:foo', GDB only searches the symbols of foo.[hc] on file
> scope. If foo has been inlined, GDB would not find it.
>
> On 'break foo', however, GDB also searches local blocks for inline
> function symbols in iterate_over_all_matching_symtabs(), which is called
> indirectly from add_matching_symbols_to_info().
>
> Add that functionality to add_matching_symbols_to_info() in case it is
> called with a list of file symtabs to search.
> ---
Hi Markus!
I looked through and confirmed it fixes the test case you added, so all
looks good!
I wonder, though, does it make sense to add this code to some common
place, so that future code isn't going to forget to add this handling a
well. Have you tried adding it to the iterate_over_file_blocks code?
--
Cheers,
Guinevere Larsen
it/its
she/her (deprecated)
> gdb/linespec.c | 14 ++++++++++
> gdb/testsuite/gdb.base/break-inline2.c | 33 ++++++++++++++++++++++++
> gdb/testsuite/gdb.base/break-inline2.exp | 30 +++++++++++++++++++++
> gdb/testsuite/gdb.base/break-inline2.h | 28 ++++++++++++++++++++
> 4 files changed, 105 insertions(+)
> create mode 100644 gdb/testsuite/gdb.base/break-inline2.c
> create mode 100644 gdb/testsuite/gdb.base/break-inline2.exp
> create mode 100644 gdb/testsuite/gdb.base/break-inline2.h
>
> diff --git a/gdb/linespec.c b/gdb/linespec.c
> index b6505ba283d..384c989ef2f 100644
> --- a/gdb/linespec.c
> +++ b/gdb/linespec.c
> @@ -4276,6 +4276,20 @@ add_matching_symbols_to_info (const char *name,
> set_current_program_space (elt_pspace);
> iterate_over_file_blocks (elt, lookup_name, SEARCH_VFT, add_symbol);
>
> + /* Search local blocks for inline functions, too. */
> + const blockvector *bv = elt->compunit ().blockvector ();
> + for (int i = FIRST_LOCAL_BLOCK; i < bv->num_blocks (); i++)
> + {
> + const struct block *block = bv->block (i);
> + info->state->language->for_each_symbol
> + (block, lookup_name, SEARCH_VFT,
> + [&] (block_symbol *bsym)
> + {
> + if (bsym->symbol->is_inlined ())
> + add_symbol (bsym);
> + });
> + }
> +
> /* If no new symbols were found in this iteration and this symtab
> is in assembler, we might actually be looking for a label for
> which we don't have debug info. Check for a minimal symbol in
> diff --git a/gdb/testsuite/gdb.base/break-inline2.c b/gdb/testsuite/gdb.base/break-inline2.c
> new file mode 100644
> index 00000000000..797ab07da31
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/break-inline2.c
> @@ -0,0 +1,33 @@
> +/* This testcase is part of GDB, the GNU debugger.
> +
> + Copyright 2026 Free Software Foundation, Inc.
> +
> + This program is free software; you can redistribute it and/or modify
> + it under the terms of the GNU General Public License as published by
> + the Free Software Foundation; either version 3 of the License, or
> + (at your option) any later version.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program. If not, see <http://www.gnu.org/licenses/>. */
> +
> +#include "break-inline2.h"
> +
> +static int
> +test (void)
> +{
> + int f = foo ();
> + int b = bar ();
> + return f + b;
> +}
> +
> +int
> +main (void)
> +{
> + /* Don't make breakpoints on foo and main bind to the same address. */
> + return test ();
> +}
> diff --git a/gdb/testsuite/gdb.base/break-inline2.exp b/gdb/testsuite/gdb.base/break-inline2.exp
> new file mode 100644
> index 00000000000..b10cdece118
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/break-inline2.exp
> @@ -0,0 +1,30 @@
> +# Copyright (C) 2026 Free Software Foundation, Inc.
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +
> +standard_testfile
> +
> +if {[prepare_for_testing "failed to prepare" "$testfile" "$srcfile"]} {
> + return
> +}
> +
> +if {![runto_main]} {
> + return
> +}
> +
> +gdb_breakpoint "$testfile.h:foo" -message -allow-pending
> +gdb_breakpoint bar -message -allow-pending
> +
> +gdb_continue_to_breakpoint "foo" ".*foo.entry.*"
> +gdb_continue_to_breakpoint "bar" ".*bar.entry.*"
> diff --git a/gdb/testsuite/gdb.base/break-inline2.h b/gdb/testsuite/gdb.base/break-inline2.h
> new file mode 100644
> index 00000000000..e60d054e85b
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/break-inline2.h
> @@ -0,0 +1,28 @@
> +/* This testcase is part of GDB, the GNU debugger.
> +
> + Copyright 2026 Free Software Foundation, Inc.
> +
> + This program is free software; you can redistribute it and/or modify
> + it under the terms of the GNU General Public License as published by
> + the Free Software Foundation; either version 3 of the License, or
> + (at your option) any later version.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program. If not, see <http://www.gnu.org/licenses/>. */
> +
> +static inline int __attribute__((always_inline))
> +foo (void) /* foo.entry */
> +{ /* foo.entry */
> + return 42; /* foo.entry */
> +}
> +
> +static inline int __attribute__((always_inline))
> +bar (void) /* bar.entry */
> +{ /* bar.entry */
> + return 42; /* bar.entry */
> +}
^ permalink raw reply [flat|nested] 3+ messages in thread* RE: [PATCH] gdb: fix breakpoints on inline functions qualified with source file name
2026-08-06 15:08 ` Guinevere Larsen
@ 2026-08-13 9:56 ` Metzger, Markus T
0 siblings, 0 replies; 3+ messages in thread
From: Metzger, Markus T @ 2026-08-13 9:56 UTC (permalink / raw)
To: Guinevere Larsen; +Cc: gdb-patches
Thanks for your review,
>I wonder, though, does it make sense to add this code to some common
>place, so that future code isn't going to forget to add this handling a
>well. Have you tried adding it to the iterate_over_file_blocks code?
I added iterate_over_local_blocks() similar to iterate_over_file_blocks().
Regards,
Markus.
________________________________________
Intel Deutschland GmbH
Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany
Tel: +49 (89) 99143-0
www.intel.de
Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman
Chairperson of the Supervisory Board: Sonja Pierer
Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928
This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-08-13 9:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-30 6:15 [PATCH] gdb: fix breakpoints on inline functions qualified with source file name Markus Metzger
2026-08-06 15:08 ` Guinevere Larsen
2026-08-13 9:56 ` Metzger, Markus T
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox