Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Add dw2-aranges.exp
@ 2024-11-06 16:32 Alexandra Hájková
  2024-11-06 17:58 ` Keith Seitz
  2024-11-06 18:58 ` Kevin Buettner
  0 siblings, 2 replies; 4+ messages in thread
From: Alexandra Hájková @ 2024-11-06 16:32 UTC (permalink / raw)
  To: gdb-patches; +Cc: ahajkova

This test tests GDB is able to load a file with the
.debug_aranges section Address size set to 0.

The test was originally written by Jan Kratochvil to test
commit 927aa2e778dce440f4de5de8fc37ead1683a804e
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date:   Fri Dec 8 22:44:12 2017 +0000

      DWARF-5: .debug_names index consumer

The test was passing from the beginning.
This test has been living in the Fedora tree
for a long time, it seems to be a reasonable
some bad debug information.

If dwarf2/aranges.c is modified to turn off the
address_size check, GDB will crash with SIGPE
when loading the executable with the address size
set to zero.

I modified the DWARF assembler to make it possible
to set the Addres size to zero in a .debug_aranges section
and used a DWARF assembler to produce the assembly file.

Co-Authored-By: Jan Kratochvil <jan.kratochvil@redhat.com>
---
 gdb/testsuite/gdb.dwarf2/dw2-aranges.c   | 24 +++++++++++++
 gdb/testsuite/gdb.dwarf2/dw2-aranges.exp | 44 ++++++++++++++++++++++++
 gdb/testsuite/lib/dwarf.exp              | 15 ++++++--
 3 files changed, 81 insertions(+), 2 deletions(-)
 create mode 100644 gdb/testsuite/gdb.dwarf2/dw2-aranges.c
 create mode 100644 gdb/testsuite/gdb.dwarf2/dw2-aranges.exp

diff --git a/gdb/testsuite/gdb.dwarf2/dw2-aranges.c b/gdb/testsuite/gdb.dwarf2/dw2-aranges.c
new file mode 100644
index 00000000000..28025188495
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/dw2-aranges.c
@@ -0,0 +1,24 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2024 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/>.  */
+
+/* Dummy main function.  */
+
+int
+main (void)
+{
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-aranges.exp b/gdb/testsuite/gdb.dwarf2/dw2-aranges.exp
new file mode 100644
index 00000000000..59e7e27ac96
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/dw2-aranges.exp
@@ -0,0 +1,44 @@
+# Copyright 2004-2024 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/>.
+
+# Test .debug_aranges containing zero address_size.
+
+# This test can only be run on targets which support DWARF-2 and use gas.
+# For now pick a sampling of likely targets.
+load_lib dwarf.exp
+
+if {![dwarf2_support]} {
+    verbose "Skipping $gdb_test_file_name."
+    return 0
+}
+
+standard_testfile .c -2.S
+set asm_file [standard_output_file $srcfile2]
+
+Dwarf::assemble $asm_file {
+    cu { label cu_start } {
+	compile_unit {{language @DW_LANG_C}} {
+	}
+    }
+    aranges { addr_zero true } cu_start {
+    }
+}
+
+if { [prepare_for_testing "failed to prepare" $binfile  [list $asm_file $srcfile ]] } {
+    return -1
+}
+
+# Failed gdb_load would abort the testcase execution earlier.
+pass "file loaded"
diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
index 6a5afec3fc8..1002c75dd09 100644
--- a/gdb/testsuite/lib/dwarf.exp
+++ b/gdb/testsuite/lib/dwarf.exp
@@ -2759,8 +2759,11 @@ namespace eval Dwarf {
 	    set addr_op .4byte
 	}
 
-	_op $addr_op $arange_start "Address range start$comment"
-	_op $addr_op $arange_length "Address range length$comment"
+	# Do not emit address ranges when the Address size is set to 0.
+	if { $_addr_size > 0 } {
+	    _op $addr_op $arange_start "Address range start$comment"
+	    _op $addr_op $arange_length "Address range length$comment"
+	}
     }
 
     # Emit a DWARF .debug_aranges unit.
@@ -2797,6 +2800,7 @@ namespace eval Dwarf {
 	    { cu_is_64 0 }
 	    { section_version 2 }
 	    { seg_size 0 }
+	    { addr_zero false }
 	}
 	set _seg_size $seg_size
 
@@ -2806,6 +2810,10 @@ namespace eval Dwarf {
 	    set _addr_size 4
 	}
 
+	if { $addr_zero } {
+	    set _addr_size 0
+	}
+
 	# Switch to .debug_aranges section.
 	_section .debug_aranges
 
@@ -2853,6 +2861,9 @@ namespace eval Dwarf {
 
 	# Padding.
 	set tuple_size [expr 2 * $_addr_size + $_seg_size]
+	if {$tuple_size == 0} {
+	    set tuple_size 1
+	}
 	while { 1 } {
 	    if { [expr $offset % $tuple_size] == 0 } {
 		break
-- 
2.46.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Add dw2-aranges.exp
  2024-11-06 16:32 [PATCH] Add dw2-aranges.exp Alexandra Hájková
@ 2024-11-06 17:58 ` Keith Seitz
  2024-11-06 18:58 ` Kevin Buettner
  1 sibling, 0 replies; 4+ messages in thread
From: Keith Seitz @ 2024-11-06 17:58 UTC (permalink / raw)
  To: Alexandra Hájková, gdb-patches

On 11/6/24 8:32 AM, Alexandra Hájková wrote:
> 
> I modified the DWARF assembler to make it possible
> to set the Addres size to zero in a .debug_aranges section
> and used a DWARF assembler to produce the assembly file.

Nice. I've only had a quick glance at this, but something
obvious did grab my attention. Please make change locally.
You don't need a v2 just for this.

> diff --git a/gdb/testsuite/gdb.dwarf2/dw2-aranges.exp b/gdb/testsuite/gdb.dwarf2/dw2-aranges.exp
> new file mode 100644
> index 00000000000..59e7e27ac96
> --- /dev/null
> +++ b/gdb/testsuite/gdb.dwarf2/dw2-aranges.exp
> @@ -0,0 +1,44 @@
> +# Copyright 2004-2024 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/>.
> +
> +# Test .debug_aranges containing zero address_size.
> +
> +# This test can only be run on targets which support DWARF-2 and use gas.
> +# For now pick a sampling of likely targets.
> +load_lib dwarf.exp
> +
> +if {![dwarf2_support]} {
> +    verbose "Skipping $gdb_test_file_name."
> +    return 0
> +}

Nowadays, we use "require dwarf2_support".

Keith

> +
> +standard_testfile .c -2.S
> +set asm_file [standard_output_file $srcfile2]
> +
> +Dwarf::assemble $asm_file {
> +    cu { label cu_start } {
> +	compile_unit {{language @DW_LANG_C}} {
> +	}
> +    }
> +    aranges { addr_zero true } cu_start {
> +    }
> +}
> +
> +if { [prepare_for_testing "failed to prepare" $binfile  [list $asm_file $srcfile ]] } {
> +    return -1
> +}
> +
> +# Failed gdb_load would abort the testcase execution earlier.
> +pass "file loaded"
> diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
> index 6a5afec3fc8..1002c75dd09 100644
> --- a/gdb/testsuite/lib/dwarf.exp
> +++ b/gdb/testsuite/lib/dwarf.exp
> @@ -2759,8 +2759,11 @@ namespace eval Dwarf {
>   	    set addr_op .4byte
>   	}
>   
> -	_op $addr_op $arange_start "Address range start$comment"
> -	_op $addr_op $arange_length "Address range length$comment"
> +	# Do not emit address ranges when the Address size is set to 0.
> +	if { $_addr_size > 0 } {
> +	    _op $addr_op $arange_start "Address range start$comment"
> +	    _op $addr_op $arange_length "Address range length$comment"
> +	}
>       }
>   
>       # Emit a DWARF .debug_aranges unit.
> @@ -2797,6 +2800,7 @@ namespace eval Dwarf {
>   	    { cu_is_64 0 }
>   	    { section_version 2 }
>   	    { seg_size 0 }
> +	    { addr_zero false }
>   	}
>   	set _seg_size $seg_size
>   
> @@ -2806,6 +2810,10 @@ namespace eval Dwarf {
>   	    set _addr_size 4
>   	}
>   
> +	if { $addr_zero } {
> +	    set _addr_size 0
> +	}
> +
>   	# Switch to .debug_aranges section.
>   	_section .debug_aranges
>   
> @@ -2853,6 +2861,9 @@ namespace eval Dwarf {
>   
>   	# Padding.
>   	set tuple_size [expr 2 * $_addr_size + $_seg_size]
> +	if {$tuple_size == 0} {
> +	    set tuple_size 1
> +	}
>   	while { 1 } {
>   	    if { [expr $offset % $tuple_size] == 0 } {
>   		break


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Add dw2-aranges.exp
  2024-11-06 16:32 [PATCH] Add dw2-aranges.exp Alexandra Hájková
  2024-11-06 17:58 ` Keith Seitz
@ 2024-11-06 18:58 ` Kevin Buettner
  1 sibling, 0 replies; 4+ messages in thread
From: Kevin Buettner @ 2024-11-06 18:58 UTC (permalink / raw)
  To: Alexandra Hájková; +Cc: gdb-patches

Hi Sasha,

The actual patches in this commit LGTM (once Keith's concern is
addressed), but I'd like to see some changes to the commit log...

> This test tests GDB is able to load a file with the
> .debug_aranges section Address size set to 0.

Maybe say:

    This test checks that GDB is able to load DWARF information when
    .debug_aranges has a section address size that is set to 0.

> The test was originally written by Jan Kratochvil to test
> commit 927aa2e778dce440f4de5de8fc37ead1683a804e
> Author: Jan Kratochvil <jan.kratochvil@redhat.com>
> Date:   Fri Dec 8 22:44:12 2017 +0000
> 
>       DWARF-5: .debug_names index consumer

I think that this can be written more compactly, perhaps like this:

    This test was originally written by Jan Kratochvil to test commit
    927aa2e778d from 2017, titled "DWARF-5:  .debug_names index
    consumer".

> The test was passing from the beginning.
> This test has been living in the Fedora tree
> for a long time, it seems to be a reasonable
> some bad debug information.

Maybe change this to:

    This test was originally written using a static .S file and has
    been present in the Fedora tree for a long time.

> If dwarf2/aranges.c is modified to turn off the
> address_size check, GDB will crash with SIGPE

s/SIGPE/SIGFPE/

(I think.)

> when loading the executable with the address size

s/the address/address/

> set to zero.
> 
> I modified the DWARF assembler to make it possible
> to set the Addres size to zero in a .debug_aranges section

s/Addres/address/

> and used a DWARF assembler to produce the assembly file.

s/a DWARF/the DWARF/

With those changes (assuming you're okay with them) and with
Keith's change to use "require dwarf2_support",...

Approved-by: Kevin Buettner <kevinb@redhat.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] Add dw2-aranges.exp
@ 2024-11-06 16:31 Alexandra Hájková
  0 siblings, 0 replies; 4+ messages in thread
From: Alexandra Hájková @ 2024-11-06 16:31 UTC (permalink / raw)
  To: gdb-patches; +Cc: ahajkova

This test tests GDB is able to load a file with the
.debug_aranges section Address size set to 0.

The test was originally written by Jan Kratochvil to test
commit 927aa2e778dce440f4de5de8fc37ead1683a804e
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date:   Fri Dec 8 22:44:12 2017 +0000

      DWARF-5: .debug_names index consumer

The test was passing from the beginning.
This test has been living in the Fedora tree
for a long time, it seems to be a reasonable
some bad debug information.

If dwarf2/aranges.c is modified to turn off the
address_size check, GDB will crash with SIGPE
when loading the executable with the address size
set to zero.

I modified the DWARF assembler to make it possible
to set the Addres size to zero in a .debug_aranges section
and used a DWARF assembler to produce the assembly file.

Co-Authored-By: Jan Kratochvil <jan.kratochvil@redhat.com>
---
 gdb/testsuite/gdb.dwarf2/dw2-aranges.c   | 24 +++++++++++++
 gdb/testsuite/gdb.dwarf2/dw2-aranges.exp | 45 ++++++++++++++++++++++++
 gdb/testsuite/lib/dwarf.exp              | 15 ++++++--
 3 files changed, 82 insertions(+), 2 deletions(-)
 create mode 100644 gdb/testsuite/gdb.dwarf2/dw2-aranges.c
 create mode 100644 gdb/testsuite/gdb.dwarf2/dw2-aranges.exp

diff --git a/gdb/testsuite/gdb.dwarf2/dw2-aranges.c b/gdb/testsuite/gdb.dwarf2/dw2-aranges.c
new file mode 100644
index 00000000000..28025188495
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/dw2-aranges.c
@@ -0,0 +1,24 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2024 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/>.  */
+
+/* Dummy main function.  */
+
+int
+main (void)
+{
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-aranges.exp b/gdb/testsuite/gdb.dwarf2/dw2-aranges.exp
new file mode 100644
index 00000000000..b9174cad14f
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/dw2-aranges.exp
@@ -0,0 +1,45 @@
+# Copyright 2004-2024 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/>.
+
+# Test .debug_aranges containing zero address_size.
+
+# This test can only be run on targets which support DWARF-2 and use gas.
+# For now pick a sampling of likely targets.
+load_lib dwarf.exp
+
+if {![dwarf2_support]} {
+    verbose "Skipping $gdb_test_file_name."
+    return 0
+}
+
+standard_testfile .c -2.S
+set asm_file [standard_output_file $srcfile2]
+
+Dwarf::assemble $asm_file {
+    cu { label cu_start } {
+	compile_unit {{language @DW_LANG_C}} {
+	}
+    }
+    aranges { addr_zero true } cu_start {
+	arange {} 0 0
+    }
+}
+
+if { [prepare_for_testing "failed to prepare" $binfile  [list $asm_file $srcfile ]] } {
+    return -1
+}
+
+# Failed gdb_load would abort the testcase execution earlier.
+pass "file loaded"
diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
index 6a5afec3fc8..e5823c7b646 100644
--- a/gdb/testsuite/lib/dwarf.exp
+++ b/gdb/testsuite/lib/dwarf.exp
@@ -2759,8 +2759,11 @@ namespace eval Dwarf {
 	    set addr_op .4byte
 	}
 
-	_op $addr_op $arange_start "Address range start$comment"
-	_op $addr_op $arange_length "Address range length$comment"
+	# Do not emit address ranges when the Address size i set to 0.
+	if { $_addr_size > 0 } {
+	    _op $addr_op $arange_start "Address range start$comment"
+	    _op $addr_op $arange_length "Address range length$comment"
+	}
     }
 
     # Emit a DWARF .debug_aranges unit.
@@ -2797,6 +2800,7 @@ namespace eval Dwarf {
 	    { cu_is_64 0 }
 	    { section_version 2 }
 	    { seg_size 0 }
+	    { addr_zero 0 }
 	}
 	set _seg_size $seg_size
 
@@ -2806,6 +2810,10 @@ namespace eval Dwarf {
 	    set _addr_size 4
 	}
 
+	if { $addr_zero == true } {
+	    set _addr_size 0
+	}
+
 	# Switch to .debug_aranges section.
 	_section .debug_aranges
 
@@ -2853,6 +2861,9 @@ namespace eval Dwarf {
 
 	# Padding.
 	set tuple_size [expr 2 * $_addr_size + $_seg_size]
+	if {$tuple_size == 0} {
+	    set tuple_size 1
+	}
 	while { 1 } {
 	    if { [expr $offset % $tuple_size] == 0 } {
 		break
-- 
2.46.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-11-06 18:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-06 16:32 [PATCH] Add dw2-aranges.exp Alexandra Hájková
2024-11-06 17:58 ` Keith Seitz
2024-11-06 18:58 ` Kevin Buettner
  -- strict thread matches above, loose matches on Subject: below --
2024-11-06 16:31 Alexandra Hájková

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox