public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [committed][gdb/testsuite] Add gdb.base/eh_return.exp
@ 2020-08-16 11:31 Tom de Vries
  2020-08-26 17:20 ` Luis Machado
  0 siblings, 1 reply; 5+ messages in thread
From: Tom de Vries @ 2020-08-16 11:31 UTC (permalink / raw)
  To: gdb-patches

Hi,

In PR25350, an internal error was reported:
...
(gdb) break *eh2+0x7e
Breakpoint 1 at 0x13e2: file small.c, line 38.
(gdb) run
Starting program: a.out
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".

Breakpoint 1, 0x00005555555553e2 in eh2 (
frame.c:558: internal-error: frame_id get_frame_id(frame_info*): \
  Assertion `stashed' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
...

The internal error does not reproduce after recent commit 547ce8f00b
"[gdb/backtrace] Fix printing of fortran string args".

Add the corresponding test-case as regression test, given that the code is
rather atypical.

Tested on x86_64-linux.

Committed to trunk.

Thanks,
- Tom

[gdb/testsuite] Add gdb.base/eh_return.exp

gdb/testsuite/ChangeLog:

2020-08-16  Tom de Vries  <tdevries@suse.de>

	PR gdb/25350
	* gdb.base/eh_return.c: New test.
	* gdb.base/eh_return.exp: New file.

---
 gdb/testsuite/gdb.base/eh_return.c   | 98 ++++++++++++++++++++++++++++++++++++
 gdb/testsuite/gdb.base/eh_return.exp | 47 +++++++++++++++++
 2 files changed, 145 insertions(+)

diff --git a/gdb/testsuite/gdb.base/eh_return.c b/gdb/testsuite/gdb.base/eh_return.c
new file mode 100644
index 0000000000..80eea9c783
--- /dev/null
+++ b/gdb/testsuite/gdb.base/eh_return.c
@@ -0,0 +1,98 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   It was copied from gcc repo, gcc/testsuite/gcc.target/aarch64/eh_return.c.
+
+   Copyright 2020 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 <stdlib.h>
+#include <stdio.h>
+
+int val, test, failed;
+
+int main (void);
+
+void
+eh0 (void *p)
+{
+  val = (int)(long)p & 7;
+  if (val)
+    abort ();
+}
+
+void
+eh1 (void *p, int x)
+{
+  void *q = __builtin_alloca (x);
+  eh0 (q);
+  __builtin_eh_return (0, p);
+}
+
+void
+eh2a (int a,int b,int c,int d,int e,int f,int g,int h, void *p)
+{
+  val = a + b + c + d + e + f + g + h +  (int)(long)p & 7;
+}
+
+void
+eh2 (void *p)
+{
+  eh2a (val, val, val, val, val, val, val, val, p);
+  __builtin_eh_return (0, p);
+}
+
+
+void
+continuation (void)
+{
+  test++;
+  main ();
+}
+
+void
+fail (void)
+{
+  failed = 1;
+  printf ("failed\n");
+  continuation ();
+}
+
+void
+do_test1 (void)
+{
+  if (!val)
+    eh1 (continuation, 100);
+  fail ();
+}
+
+void
+do_test2 (void)
+{
+  if (!val)
+    eh2 (continuation);
+  fail ();
+}
+
+int
+main (void)
+{
+  if (test == 0)
+    do_test1 ();
+  if (test == 1)
+    do_test2 ();
+  if (failed || test != 2)
+    exit (1);
+  exit (0);
+}
diff --git a/gdb/testsuite/gdb.base/eh_return.exp b/gdb/testsuite/gdb.base/eh_return.exp
new file mode 100644
index 0000000000..e38398ed37
--- /dev/null
+++ b/gdb/testsuite/gdb.base/eh_return.exp
@@ -0,0 +1,47 @@
+# Copyright 2020 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/>.  */
+
+# Check if executable generated from eh_return.c assert when setting a
+# breakpoint at the last insn of eh, and running to it.
+
+standard_testfile
+
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
+    return -1
+}
+
+set address -1
+
+# Get the address of the last insn in function eh2.
+gdb_test_multiple "disassemble eh2" "" {
+    -re -wrap "($hex)\[^\r\n\]*\r\nEnd of assembler dump." {
+	set address $expect_out(1,string)
+	pass $gdb_test_name
+    }
+}
+
+if { $address == -1 } {
+    return 0
+}
+
+clean_restart ${binfile}
+
+gdb_breakpoint "*$address" message
+
+# The assert did not reproduce when running to main, and continuing to the
+# breakpoint, so instead, run to the breakpoint.
+gdb_run_cmd
+
+gdb_test "" "Breakpoint .*" "hit breakpoint"

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

* Re: [committed][gdb/testsuite] Add gdb.base/eh_return.exp
  2020-08-16 11:31 [committed][gdb/testsuite] Add gdb.base/eh_return.exp Tom de Vries
@ 2020-08-26 17:20 ` Luis Machado
  2020-08-26 18:02   ` Tom de Vries
  0 siblings, 1 reply; 5+ messages in thread
From: Luis Machado @ 2020-08-26 17:20 UTC (permalink / raw)
  To: Tom de Vries, gdb-patches

On 8/16/20 8:31 AM, Tom de Vries wrote:
> Hi,
> 
> In PR25350, an internal error was reported:
> ...
> (gdb) break *eh2+0x7e
> Breakpoint 1 at 0x13e2: file small.c, line 38.
> (gdb) run
> Starting program: a.out
> [Thread debugging using libthread_db enabled]
> Using host libthread_db library "/usr/lib/libthread_db.so.1".
> 
> Breakpoint 1, 0x00005555555553e2 in eh2 (
> frame.c:558: internal-error: frame_id get_frame_id(frame_info*): \
>    Assertion `stashed' failed.
> A problem internal to GDB has been detected,
> further debugging may prove unreliable.
> ...
> 
> The internal error does not reproduce after recent commit 547ce8f00b
> "[gdb/backtrace] Fix printing of fortran string args".
> 
> Add the corresponding test-case as regression test, given that the code is
> rather atypical.
> 
> Tested on x86_64-linux.

This doesn't work so well on aarch64-linux because the breakpoint 
location from before running the program doesn't exists after running 
it. Things get relocated.

--

(gdb) break *0x000000000000099c^M
Breakpoint 1 at 0x99c: file 
/home/luis.machado/work/tcwg/build/binutils-gdb-master/gdb/testsuite/../../../../repos/binutils-gdb/gdb/testsuite/gdb.base/eh_return.c, 
line 54.^M
(gdb) PASS: gdb.base/eh_return.exp: setting breakpoint at 
*0x000000000000099c
run ^M
Starting program: 
/home/luis.machado/work/tcwg/build/binutils-gdb-master/gdb/testsuite/outputs/gdb.base/eh_return/eh_return 
^M
Warning:^M
Cannot insert breakpoint 1.^M
Cannot access memory at address 0x99c^M
^M
(gdb) FAIL: gdb.base/eh_return.exp: hit breakpoint

--

Shouldn't we insert a breakpoint after the relocation has happened? Or 
add the breakpoint to a symbolic reference?

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

* Re: [committed][gdb/testsuite] Add gdb.base/eh_return.exp
  2020-08-26 17:20 ` Luis Machado
@ 2020-08-26 18:02   ` Tom de Vries
  2020-08-26 23:14     ` Tom de Vries
  0 siblings, 1 reply; 5+ messages in thread
From: Tom de Vries @ 2020-08-26 18:02 UTC (permalink / raw)
  To: Luis Machado, gdb-patches

On 8/26/20 7:20 PM, Luis Machado wrote:
> On 8/16/20 8:31 AM, Tom de Vries wrote:
>> Hi,
>>
>> In PR25350, an internal error was reported:
>> ...
>> (gdb) break *eh2+0x7e
>> Breakpoint 1 at 0x13e2: file small.c, line 38.
>> (gdb) run
>> Starting program: a.out
>> [Thread debugging using libthread_db enabled]
>> Using host libthread_db library "/usr/lib/libthread_db.so.1".
>>
>> Breakpoint 1, 0x00005555555553e2 in eh2 (
>> frame.c:558: internal-error: frame_id get_frame_id(frame_info*): \
>>    Assertion `stashed' failed.
>> A problem internal to GDB has been detected,
>> further debugging may prove unreliable.
>> ...
>>
>> The internal error does not reproduce after recent commit 547ce8f00b
>> "[gdb/backtrace] Fix printing of fortran string args".
>>
>> Add the corresponding test-case as regression test, given that the
>> code is
>> rather atypical.
>>
>> Tested on x86_64-linux.
> 
> This doesn't work so well on aarch64-linux because the breakpoint
> location from before running the program doesn't exists after running
> it. Things get relocated.
> 

Right, I don't think that's architecture-related.

I'm running into the same issue on x86_64-linux with target board
unix/-fPIE/-pie.

> -- 
> 
> (gdb) break *0x000000000000099c^M
> Breakpoint 1 at 0x99c: file
> /home/luis.machado/work/tcwg/build/binutils-gdb-master/gdb/testsuite/../../../../repos/binutils-gdb/gdb/testsuite/gdb.base/eh_return.c,
> line 54.^M
> (gdb) PASS: gdb.base/eh_return.exp: setting breakpoint at
> *0x000000000000099c
> run ^M
> Starting program:
> /home/luis.machado/work/tcwg/build/binutils-gdb-master/gdb/testsuite/outputs/gdb.base/eh_return/eh_return
> ^M
> Warning:^M
> Cannot insert breakpoint 1.^M
> Cannot access memory at address 0x99c^M
> ^M
> (gdb) FAIL: gdb.base/eh_return.exp: hit breakpoint
> 
> -- 
> 
> Shouldn't we insert a breakpoint after the relocation has happened?

As I mentioned in the test-case:
...
# The assert did not reproduce when running to main, and continuing to
# the breakpoint, so instead, run to the breakpoint.
...
So I'm afraid that's not going to work.

> Or
> add the breakpoint to a symbolic reference?

Yeah, that might work.  If not, we'll have to restrict this to no-pie.

Thanks,
- Tom

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

* Re: [committed][gdb/testsuite] Add gdb.base/eh_return.exp
  2020-08-26 18:02   ` Tom de Vries
@ 2020-08-26 23:14     ` Tom de Vries
  2020-08-31  8:47       ` Tom de Vries
  0 siblings, 1 reply; 5+ messages in thread
From: Tom de Vries @ 2020-08-26 23:14 UTC (permalink / raw)
  To: Luis Machado, gdb-patches

On 8/26/20 8:02 PM, Tom de Vries wrote:
> On 8/26/20 7:20 PM, Luis Machado wrote:
>> On 8/16/20 8:31 AM, Tom de Vries wrote:
>>> Hi,
>>>
>>> In PR25350, an internal error was reported:
>>> ...
>>> (gdb) break *eh2+0x7e
>>> Breakpoint 1 at 0x13e2: file small.c, line 38.
>>> (gdb) run
>>> Starting program: a.out
>>> [Thread debugging using libthread_db enabled]
>>> Using host libthread_db library "/usr/lib/libthread_db.so.1".
>>>
>>> Breakpoint 1, 0x00005555555553e2 in eh2 (
>>> frame.c:558: internal-error: frame_id get_frame_id(frame_info*): \
>>>    Assertion `stashed' failed.
>>> A problem internal to GDB has been detected,
>>> further debugging may prove unreliable.
>>> ...
>>>
>>> The internal error does not reproduce after recent commit 547ce8f00b
>>> "[gdb/backtrace] Fix printing of fortran string args".
>>>
>>> Add the corresponding test-case as regression test, given that the
>>> code is
>>> rather atypical.
>>>
>>> Tested on x86_64-linux.
>>
>> This doesn't work so well on aarch64-linux because the breakpoint
>> location from before running the program doesn't exists after running
>> it. Things get relocated.
>>
> 
> Right, I don't think that's architecture-related.
> 
> I'm running into the same issue on x86_64-linux with target board
> unix/-fPIE/-pie.
> 
>> -- 
>>
>> (gdb) break *0x000000000000099c^M
>> Breakpoint 1 at 0x99c: file
>> /home/luis.machado/work/tcwg/build/binutils-gdb-master/gdb/testsuite/../../../../repos/binutils-gdb/gdb/testsuite/gdb.base/eh_return.c,
>> line 54.^M
>> (gdb) PASS: gdb.base/eh_return.exp: setting breakpoint at
>> *0x000000000000099c
>> run ^M
>> Starting program:
>> /home/luis.machado/work/tcwg/build/binutils-gdb-master/gdb/testsuite/outputs/gdb.base/eh_return/eh_return
>> ^M
>> Warning:^M
>> Cannot insert breakpoint 1.^M
>> Cannot access memory at address 0x99c^M
>> ^M
>> (gdb) FAIL: gdb.base/eh_return.exp: hit breakpoint
>>
>> -- 
>>
>> Shouldn't we insert a breakpoint after the relocation has happened?
> 
> As I mentioned in the test-case:
> ...
> # The assert did not reproduce when running to main, and continuing to
> # the breakpoint, so instead, run to the breakpoint.
> ...
> So I'm afraid that's not going to work.
> 
>> Or
>> add the breakpoint to a symbolic reference?
> 
> Yeah, that might work.  If not, we'll have to restrict this to no-pie.

So, I tried this using:
...
$ git diff
diff --git a/gdb/testsuite/gdb.base/eh_return.c
b/gdb/testsuite/gdb.base/eh_ret
urn.c
index 80eea9c783..ba8c1c51aa 100644
--- a/gdb/testsuite/gdb.base/eh_return.c
+++ b/gdb/testsuite/gdb.base/eh_return.c
@@ -51,6 +51,8 @@ eh2 (void *p)
 {
   eh2a (val, val, val, val, val, val, val, val, p);
   __builtin_eh_return (0, p);
+ here:
+  (void)0;
 }


diff --git a/gdb/testsuite/gdb.base/eh_return.exp
b/gdb/testsuite/gdb.base/eh_r
eturn.exp
index e38398ed37..182b2ed86d 100644
--- a/gdb/testsuite/gdb.base/eh_return.exp
+++ b/gdb/testsuite/gdb.base/eh_return.exp
@@ -22,23 +22,9 @@ if {[prepare_for_testing "failed to prepare"
 clean_restart ${binfile}

-gdb_breakpoint "*$address" message
+gdb_breakpoint "eh2:here" message

 # The assert did not reproduce when running to main, and continuing to the
 # breakpoint, so instead, run to the breakpoint.
...

But then we run into another internal-error while setting the
breakpoint, see PR25067:
...
src/gdb/linespec.c:3233: internal-error: void decode_line_full(const
event_location*, int, program_space*, symtab*, int, linespec_result*,
const char*, const char*): Assertion `result.size () == 1 ||
canonical->pre_expanded' failed.^M
A problem internal to GDB has been detected,^M
further debugging may prove unreliable.^M
...

Thanks,
- Tom

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

* Re: [committed][gdb/testsuite] Add gdb.base/eh_return.exp
  2020-08-26 23:14     ` Tom de Vries
@ 2020-08-31  8:47       ` Tom de Vries
  0 siblings, 0 replies; 5+ messages in thread
From: Tom de Vries @ 2020-08-31  8:47 UTC (permalink / raw)
  To: Luis Machado, gdb-patches

[-- Attachment #1: Type: text/plain, Size: 4048 bytes --]

On 8/27/20 1:14 AM, Tom de Vries wrote:
> On 8/26/20 8:02 PM, Tom de Vries wrote:
>> On 8/26/20 7:20 PM, Luis Machado wrote:
>>> On 8/16/20 8:31 AM, Tom de Vries wrote:
>>>> Hi,
>>>>
>>>> In PR25350, an internal error was reported:
>>>> ...
>>>> (gdb) break *eh2+0x7e
>>>> Breakpoint 1 at 0x13e2: file small.c, line 38.
>>>> (gdb) run
>>>> Starting program: a.out
>>>> [Thread debugging using libthread_db enabled]
>>>> Using host libthread_db library "/usr/lib/libthread_db.so.1".
>>>>
>>>> Breakpoint 1, 0x00005555555553e2 in eh2 (
>>>> frame.c:558: internal-error: frame_id get_frame_id(frame_info*): \
>>>>    Assertion `stashed' failed.
>>>> A problem internal to GDB has been detected,
>>>> further debugging may prove unreliable.
>>>> ...
>>>>
>>>> The internal error does not reproduce after recent commit 547ce8f00b
>>>> "[gdb/backtrace] Fix printing of fortran string args".
>>>>
>>>> Add the corresponding test-case as regression test, given that the
>>>> code is
>>>> rather atypical.
>>>>
>>>> Tested on x86_64-linux.
>>>
>>> This doesn't work so well on aarch64-linux because the breakpoint
>>> location from before running the program doesn't exists after running
>>> it. Things get relocated.
>>>
>>
>> Right, I don't think that's architecture-related.
>>
>> I'm running into the same issue on x86_64-linux with target board
>> unix/-fPIE/-pie.
>>
>>> -- 
>>>
>>> (gdb) break *0x000000000000099c^M
>>> Breakpoint 1 at 0x99c: file
>>> /home/luis.machado/work/tcwg/build/binutils-gdb-master/gdb/testsuite/../../../../repos/binutils-gdb/gdb/testsuite/gdb.base/eh_return.c,
>>> line 54.^M
>>> (gdb) PASS: gdb.base/eh_return.exp: setting breakpoint at
>>> *0x000000000000099c
>>> run ^M
>>> Starting program:
>>> /home/luis.machado/work/tcwg/build/binutils-gdb-master/gdb/testsuite/outputs/gdb.base/eh_return/eh_return
>>> ^M
>>> Warning:^M
>>> Cannot insert breakpoint 1.^M
>>> Cannot access memory at address 0x99c^M
>>> ^M
>>> (gdb) FAIL: gdb.base/eh_return.exp: hit breakpoint
>>>
>>> -- 
>>>
>>> Shouldn't we insert a breakpoint after the relocation has happened?
>>
>> As I mentioned in the test-case:
>> ...
>> # The assert did not reproduce when running to main, and continuing to
>> # the breakpoint, so instead, run to the breakpoint.
>> ...
>> So I'm afraid that's not going to work.
>>
>>> Or
>>> add the breakpoint to a symbolic reference?
>>
>> Yeah, that might work.  If not, we'll have to restrict this to no-pie.
> 
> So, I tried this using:
> ...
> $ git diff
> diff --git a/gdb/testsuite/gdb.base/eh_return.c
> b/gdb/testsuite/gdb.base/eh_ret
> urn.c
> index 80eea9c783..ba8c1c51aa 100644
> --- a/gdb/testsuite/gdb.base/eh_return.c
> +++ b/gdb/testsuite/gdb.base/eh_return.c
> @@ -51,6 +51,8 @@ eh2 (void *p)
>  {
>    eh2a (val, val, val, val, val, val, val, val, p);
>    __builtin_eh_return (0, p);
> + here:
> +  (void)0;
>  }
> 
> 
> diff --git a/gdb/testsuite/gdb.base/eh_return.exp
> b/gdb/testsuite/gdb.base/eh_r
> eturn.exp
> index e38398ed37..182b2ed86d 100644
> --- a/gdb/testsuite/gdb.base/eh_return.exp
> +++ b/gdb/testsuite/gdb.base/eh_return.exp
> @@ -22,23 +22,9 @@ if {[prepare_for_testing "failed to prepare"
>  clean_restart ${binfile}
> 
> -gdb_breakpoint "*$address" message
> +gdb_breakpoint "eh2:here" message
> 
>  # The assert did not reproduce when running to main, and continuing to the
>  # breakpoint, so instead, run to the breakpoint.
> ...
> 
> But then we run into another internal-error while setting the
> breakpoint, see PR25067:
> ...
> src/gdb/linespec.c:3233: internal-error: void decode_line_full(const
> event_location*, int, program_space*, symtab*, int, linespec_result*,
> const char*, const char*): Assertion `result.size () == 1 ||
> canonical->pre_expanded' failed.^M
> A problem internal to GDB has been detected,^M
> further debugging may prove unreliable.^M
> ...
> 

Something I didn't realize when trying this out: __builtin_eh_return is
a noreturn builtin, so adding a label after it doesn't work.

So I've gone with nopie.

Committed as attached.

Thanks,
- Tom

[-- Attachment #2: 0001-gdb-testsuite-Add-nopie-to-gdb.base-eh_return.exp.patch --]
[-- Type: text/x-patch, Size: 1269 bytes --]

[gdb/testsuite] Add nopie to gdb.base/eh_return.exp

When running test-case gdb.base/eh_return.exp with target board
unix/-fPIE/-pie, we run into:
...
(gdb) break *0x88e^M
Breakpoint 1 at 0x88e: file eh_return.c, line 54.^M
(gdb) PASS: gdb.base/eh_return.exp: setting breakpoint at *0x88e
run ^M
Starting program: eh_return ^M
Warning:^M
Cannot insert breakpoint 1.^M
Cannot access memory at address 0x88e^M
^M
(gdb) FAIL: gdb.base/eh_return.exp: hit breakpoint
...

The problem is that gdb does not support setting breakpoints on unrelocated
addresses.

Fix this by using nopie for the test-case.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-08-31  Tom de Vries  <tdevries@suse.de>

	* gdb.base/eh_return.exp: Use nopie.

---
 gdb/testsuite/gdb.base/eh_return.exp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/gdb.base/eh_return.exp b/gdb/testsuite/gdb.base/eh_return.exp
index e38398ed37..78a4af4b0c 100644
--- a/gdb/testsuite/gdb.base/eh_return.exp
+++ b/gdb/testsuite/gdb.base/eh_return.exp
@@ -18,7 +18,8 @@
 
 standard_testfile
 
-if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile \
+	 {debug nopie}]} {
     return -1
 }
 

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

end of thread, other threads:[~2020-08-31  8:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-16 11:31 [committed][gdb/testsuite] Add gdb.base/eh_return.exp Tom de Vries
2020-08-26 17:20 ` Luis Machado
2020-08-26 18:02   ` Tom de Vries
2020-08-26 23:14     ` Tom de Vries
2020-08-31  8:47       ` Tom de Vries

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).