* [PATCH] Avoid bad breakpoints with --gc-sections
@ 2022-01-18 19:37 Tom Tromey
2022-01-19 14:17 ` Simon Marchi
0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2022-01-18 19:37 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
We found a case where --gc-sections can cause gdb to set an invalid
breakpoint. In the included test case, gdb will set a breakpoint with
two locations, one of which is 0x0.
The code in lnp_state_machine::check_line_address is intended to
filter out this sort of problem, but in this case, the entire CU is
empty, causing unrelocated_lowpc==0x0 -- which circumvents the check.
It seems to me that if a CU is empty like this, then it is ok to
simply ignore the line table, as there won't be any locations anyway.
---
gdb/dwarf2/read.c | 3 +-
gdb/testsuite/gdb.ada/inline-section-gc.exp | 39 +++++++++++++++++++
.../gdb.ada/inline-section-gc/callee.adb | 23 +++++++++++
.../gdb.ada/inline-section-gc/callee.ads | 17 ++++++++
.../gdb.ada/inline-section-gc/caller.adb | 21 ++++++++++
5 files changed, 102 insertions(+), 1 deletion(-)
create mode 100644 gdb/testsuite/gdb.ada/inline-section-gc.exp
create mode 100644 gdb/testsuite/gdb.ada/inline-section-gc/callee.adb
create mode 100644 gdb/testsuite/gdb.ada/inline-section-gc/callee.ads
create mode 100644 gdb/testsuite/gdb.ada/inline-section-gc/caller.adb
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 3fe6c3ab90c..099def6833b 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -10631,7 +10631,8 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
/* Decode line number information if present. We do this before
processing child DIEs, so that the line header table is available
for DW_AT_decl_file. */
- handle_DW_AT_stmt_list (die, cu, fnd, lowpc);
+ if (lowpc != highpc)
+ handle_DW_AT_stmt_list (die, cu, fnd, lowpc);
/* Process all dies in compilation unit. */
if (die->child != NULL)
diff --git a/gdb/testsuite/gdb.ada/inline-section-gc.exp b/gdb/testsuite/gdb.ada/inline-section-gc.exp
new file mode 100644
index 00000000000..7830fb087af
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/inline-section-gc.exp
@@ -0,0 +1,39 @@
+# Copyright 2022 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/>.
+
+load_lib "ada.exp"
+
+if { [skip_ada_tests] } { return -1 }
+
+standard_ada_testfile caller
+
+set options {
+ debug
+ optimize=-O2
+ additional_flags=-ffunction-sections
+ additional_flags=-largs
+ additional_flags=-Wl,--gc-sections
+ additional_flags=-margs
+ additional_flags=-gnatn
+}
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable $options] != ""} {
+ return -1
+}
+
+clean_restart ${testfile}
+
+set bp_location [gdb_get_line_number "BREAK" ${testdir}/callee.adb]
+gdb_test "break callee.adb:$bp_location" \
+ "Breakpoint $decimal at $hex: file .*callee.adb, line $bp_location."
diff --git a/gdb/testsuite/gdb.ada/inline-section-gc/callee.adb b/gdb/testsuite/gdb.ada/inline-section-gc/callee.adb
new file mode 100644
index 00000000000..9ece3cdc20a
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/inline-section-gc/callee.adb
@@ -0,0 +1,23 @@
+-- Copyright 2022 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/>.
+
+with System;
+
+procedure Callee is
+ Data : Integer;
+ for Data'Address use System'To_Address (16#4000_0000#);
+begin
+ Data := 0; -- BREAK
+end Callee;
diff --git a/gdb/testsuite/gdb.ada/inline-section-gc/callee.ads b/gdb/testsuite/gdb.ada/inline-section-gc/callee.ads
new file mode 100644
index 00000000000..e13168d5fb5
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/inline-section-gc/callee.ads
@@ -0,0 +1,17 @@
+-- Copyright 2022 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/>.
+
+procedure Callee;
+pragma Inline (Callee);
diff --git a/gdb/testsuite/gdb.ada/inline-section-gc/caller.adb b/gdb/testsuite/gdb.ada/inline-section-gc/caller.adb
new file mode 100644
index 00000000000..170227258c4
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/inline-section-gc/caller.adb
@@ -0,0 +1,21 @@
+-- Copyright 2022 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/>.
+
+with Callee;
+
+procedure Caller is
+begin
+ Callee;
+end Caller;
--
2.31.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Avoid bad breakpoints with --gc-sections
2022-01-18 19:37 [PATCH] Avoid bad breakpoints with --gc-sections Tom Tromey
@ 2022-01-19 14:17 ` Simon Marchi
2022-01-20 14:14 ` Tom Tromey
0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2022-01-19 14:17 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
On 2022-01-18 14:37, Tom Tromey via Gdb-patches wrote:
> We found a case where --gc-sections can cause gdb to set an invalid
> breakpoint. In the included test case, gdb will set a breakpoint with
> two locations, one of which is 0x0.
>
> The code in lnp_state_machine::check_line_address is intended to
> filter out this sort of problem, but in this case, the entire CU is
> empty, causing unrelocated_lowpc==0x0 -- which circumvents the check.
>
> It seems to me that if a CU is empty like this, then it is ok to
> simply ignore the line table, as there won't be any locations anyway.
Looks good to me. Can you just please add a small comment to indicate
what the test does / its intent?
Thanks,
Simon
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Avoid bad breakpoints with --gc-sections
2022-01-19 14:17 ` Simon Marchi
@ 2022-01-20 14:14 ` Tom Tromey
0 siblings, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2022-01-20 14:14 UTC (permalink / raw)
To: Simon Marchi; +Cc: Tom Tromey, gdb-patches
Simon> Looks good to me. Can you just please add a small comment to indicate
Simon> what the test does / its intent?
Will do.
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-01-20 14:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-18 19:37 [PATCH] Avoid bad breakpoints with --gc-sections Tom Tromey
2022-01-19 14:17 ` Simon Marchi
2022-01-20 14:14 ` Tom Tromey
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).