public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH][gdb/testsuite] Work around skip_prologue problems in gdb.threads/process-dies-while-detaching.exp
@ 2021-10-29 19:24 Tom de Vries
  2021-11-02 11:38 ` Tom de Vries
  0 siblings, 1 reply; 11+ messages in thread
From: Tom de Vries @ 2021-10-29 19:24 UTC (permalink / raw)
  To: gdb-patches

Hi,

On powerpc64le-linux, I run into:
...
[Inferior 1 (process 5156) exited normally]^M
(gdb) FAIL: gdb.threads/process-dies-while-detaching.exp: single-process: \
  detach: detach: continue to breakpoint: _exit (the program exited)
...

What happens is the following:
- a breakpoint is set on _exit,
- a continue is issued
- the continue is supposed to hit the breakpoint, but instead
  the program exits.

I traced this down to the breakpoint on _exit being set too far from function
entry.  This is caused by the skip_prologue function (in rs6000-tdep.c)
optimistically ignoring insns it doesn't recognize.  In particular, it walks
past the system call instruction "sc" which initiates the actual exit.

While this needs fixing, we don't want to be testing this behaviour in this
test-case.

[ Initially I tried to fix it by setting a breakpoint on "*_exit" instead, but
that one only sets one location.  The breakpoint on "_exit" sets two
locations, one in /lib64/libc.so.6 and one in /lib64/ld64.so.2.  I tried on
x86_64 and there the breakpoint on "*_exit" mapped to the /lib64/libc.so.6
location, and the test-case passed.  But on powerpc it mapped to the
/lib64/ld64.so.2 location and I still got the same failures. ]

Fix this by setting two breakpoints on the calls to _exit and exit instead.

Tested on x86_64-linux and powerpc64le-linux.

Any comments?

Thanks,
- Tom

[gdb/testsuite] Work around skip_prologue problems in gdb.threads/process-dies-while-detaching.exp

---
 gdb/testsuite/gdb.threads/process-dies-while-detaching.c   | 4 ++--
 gdb/testsuite/gdb.threads/process-dies-while-detaching.exp | 8 ++++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/gdb/testsuite/gdb.threads/process-dies-while-detaching.c b/gdb/testsuite/gdb.threads/process-dies-while-detaching.c
index 502b4622614..c4c0b0a648b 100644
--- a/gdb/testsuite/gdb.threads/process-dies-while-detaching.c
+++ b/gdb/testsuite/gdb.threads/process-dies-while-detaching.c
@@ -46,7 +46,7 @@ void *
 thread_function (void *arg)
 {
   pthread_barrier_wait (&start_threads_barrier);
-  _exit (0);
+  _exit (0); /* Exit in thread.  */
 }
 
 /* The fork child's entry point.  */
@@ -63,7 +63,7 @@ child_function (void)
     pthread_create (&threads[i], NULL, thread_function, NULL);
   pthread_barrier_wait (&start_threads_barrier);
 
-  exit (0);
+  exit (0); /* Exit in child.  */
 }
 
 /* This is defined by the .exp file if testing the multi-process
diff --git a/gdb/testsuite/gdb.threads/process-dies-while-detaching.exp b/gdb/testsuite/gdb.threads/process-dies-while-detaching.exp
index cabbc4faacc..bbf1e0e6740 100644
--- a/gdb/testsuite/gdb.threads/process-dies-while-detaching.exp
+++ b/gdb/testsuite/gdb.threads/process-dies-while-detaching.exp
@@ -126,8 +126,12 @@ proc detach_and_expect_exit {inf_output_re test} {
 # Run to _exit in the child.
 
 proc continue_to_exit_bp {} {
-    gdb_breakpoint "_exit" temporary
-    gdb_continue_to_breakpoint "_exit" ".*_exit.*"
+    set line [gdb_get_line_number "Exit in child"]
+    gdb_breakpoint $line temporary
+    set line [gdb_get_line_number "Exit in thread"]
+    gdb_breakpoint $line temporary
+    gdb_continue_to_breakpoint "exit" ".*exit.*"
+    delete_breakpoints
 }
 
 # If testing single-process, simply detach from the process.

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

* Re: [PATCH][gdb/testsuite] Work around skip_prologue problems in gdb.threads/process-dies-while-detaching.exp
  2021-10-29 19:24 [PATCH][gdb/testsuite] Work around skip_prologue problems in gdb.threads/process-dies-while-detaching.exp Tom de Vries
@ 2021-11-02 11:38 ` Tom de Vries
  2021-11-02 17:13   ` Kevin Buettner
  0 siblings, 1 reply; 11+ messages in thread
From: Tom de Vries @ 2021-11-02 11:38 UTC (permalink / raw)
  To: gdb-patches

On 10/29/21 9:24 PM, Tom de Vries via Gdb-patches wrote:
> Hi,
> 
> On powerpc64le-linux, I run into:
> ...
> [Inferior 1 (process 5156) exited normally]^M
> (gdb) FAIL: gdb.threads/process-dies-while-detaching.exp: single-process: \
>   detach: detach: continue to breakpoint: _exit (the program exited)
> ...
> 
> What happens is the following:
> - a breakpoint is set on _exit,
> - a continue is issued
> - the continue is supposed to hit the breakpoint, but instead
>   the program exits.
> 
> I traced this down to the breakpoint on _exit being set too far from function
> entry.  This is caused by the skip_prologue function (in rs6000-tdep.c)
> optimistically ignoring insns it doesn't recognize.  In particular, it walks
> past the system call instruction "sc" which initiates the actual exit.
> 
> While this needs fixing,

Filed here: https://sourceware.org/bugzilla/show_bug.cgi?id=28527 .

Submitted patch here:
https://sourceware.org/pipermail/gdb-patches/2021-November/183016.html .

Thanks,
- Tom

> we don't want to be testing this behaviour in this
> test-case.
> 
> [ Initially I tried to fix it by setting a breakpoint on "*_exit" instead, but
> that one only sets one location.  The breakpoint on "_exit" sets two
> locations, one in /lib64/libc.so.6 and one in /lib64/ld64.so.2.  I tried on
> x86_64 and there the breakpoint on "*_exit" mapped to the /lib64/libc.so.6
> location, and the test-case passed.  But on powerpc it mapped to the
> /lib64/ld64.so.2 location and I still got the same failures. ]
> 
> Fix this by setting two breakpoints on the calls to _exit and exit instead.
> 
> Tested on x86_64-linux and powerpc64le-linux.
> 
> Any comments?
> 
> Thanks,
> - Tom
> 
> [gdb/testsuite] Work around skip_prologue problems in gdb.threads/process-dies-while-detaching.exp
> 
> ---
>  gdb/testsuite/gdb.threads/process-dies-while-detaching.c   | 4 ++--
>  gdb/testsuite/gdb.threads/process-dies-while-detaching.exp | 8 ++++++--
>  2 files changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/gdb/testsuite/gdb.threads/process-dies-while-detaching.c b/gdb/testsuite/gdb.threads/process-dies-while-detaching.c
> index 502b4622614..c4c0b0a648b 100644
> --- a/gdb/testsuite/gdb.threads/process-dies-while-detaching.c
> +++ b/gdb/testsuite/gdb.threads/process-dies-while-detaching.c
> @@ -46,7 +46,7 @@ void *
>  thread_function (void *arg)
>  {
>    pthread_barrier_wait (&start_threads_barrier);
> -  _exit (0);
> +  _exit (0); /* Exit in thread.  */
>  }
>  
>  /* The fork child's entry point.  */
> @@ -63,7 +63,7 @@ child_function (void)
>      pthread_create (&threads[i], NULL, thread_function, NULL);
>    pthread_barrier_wait (&start_threads_barrier);
>  
> -  exit (0);
> +  exit (0); /* Exit in child.  */
>  }
>  
>  /* This is defined by the .exp file if testing the multi-process
> diff --git a/gdb/testsuite/gdb.threads/process-dies-while-detaching.exp b/gdb/testsuite/gdb.threads/process-dies-while-detaching.exp
> index cabbc4faacc..bbf1e0e6740 100644
> --- a/gdb/testsuite/gdb.threads/process-dies-while-detaching.exp
> +++ b/gdb/testsuite/gdb.threads/process-dies-while-detaching.exp
> @@ -126,8 +126,12 @@ proc detach_and_expect_exit {inf_output_re test} {
>  # Run to _exit in the child.
>  
>  proc continue_to_exit_bp {} {
> -    gdb_breakpoint "_exit" temporary
> -    gdb_continue_to_breakpoint "_exit" ".*_exit.*"
> +    set line [gdb_get_line_number "Exit in child"]
> +    gdb_breakpoint $line temporary
> +    set line [gdb_get_line_number "Exit in thread"]
> +    gdb_breakpoint $line temporary
> +    gdb_continue_to_breakpoint "exit" ".*exit.*"
> +    delete_breakpoints
>  }
>  
>  # If testing single-process, simply detach from the process.
> 

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

* Re: [PATCH][gdb/testsuite] Work around skip_prologue problems in gdb.threads/process-dies-while-detaching.exp
  2021-11-02 11:38 ` Tom de Vries
@ 2021-11-02 17:13   ` Kevin Buettner
  2021-11-04 11:20     ` [PATCH][gdb/testsuite] Add gdb.opt/break-on-_exit.exp Tom de Vries
  0 siblings, 1 reply; 11+ messages in thread
From: Kevin Buettner @ 2021-11-02 17:13 UTC (permalink / raw)
  To: Tom de Vries via Gdb-patches

On Tue, 2 Nov 2021 12:38:26 +0100
Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> wrote:

> On 10/29/21 9:24 PM, Tom de Vries via Gdb-patches wrote:
> > Hi,
> > 
> > On powerpc64le-linux, I run into:
> > ...
> > [Inferior 1 (process 5156) exited normally]^M
> > (gdb) FAIL: gdb.threads/process-dies-while-detaching.exp: single-process: \
> >   detach: detach: continue to breakpoint: _exit (the program exited)
> > ...
> > 
> > What happens is the following:
> > - a breakpoint is set on _exit,
> > - a continue is issued
> > - the continue is supposed to hit the breakpoint, but instead
> >   the program exits.
> > 
> > I traced this down to the breakpoint on _exit being set too far from function
> > entry.  This is caused by the skip_prologue function (in rs6000-tdep.c)
> > optimistically ignoring insns it doesn't recognize.  In particular, it walks
> > past the system call instruction "sc" which initiates the actual exit.
> > 
> > While this needs fixing,  
> 
> Filed here: https://sourceware.org/bugzilla/show_bug.cgi?id=28527 .
> 
> Submitted patch here:
> https://sourceware.org/pipermail/gdb-patches/2021-November/183016.html .
> 
> Thanks,
> - Tom
> 
> > we don't want to be testing this behaviour in this
> > test-case.

Since you've fixed the problem in skip_prologue(), I'd prefer that this
testsuite patch not go in.

Kevin


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

* [PATCH][gdb/testsuite] Add gdb.opt/break-on-_exit.exp
  2021-11-02 17:13   ` Kevin Buettner
@ 2021-11-04 11:20     ` Tom de Vries
  2021-11-09 16:35       ` Kevin Buettner
  0 siblings, 1 reply; 11+ messages in thread
From: Tom de Vries @ 2021-11-04 11:20 UTC (permalink / raw)
  To: Kevin Buettner, Tom de Vries via Gdb-patches

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

[ was: Re: [PATCH][gdb/testsuite] Work around skip_prologue problems in
gdb.threads/process-dies-while-detaching.exp ]

On 11/2/21 6:13 PM, Kevin Buettner wrote:
> On Tue, 2 Nov 2021 12:38:26 +0100
> Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> wrote:
> 
>> On 10/29/21 9:24 PM, Tom de Vries via Gdb-patches wrote:
>>> Hi,
>>>
>>> On powerpc64le-linux, I run into:
>>> ...
>>> [Inferior 1 (process 5156) exited normally]^M
>>> (gdb) FAIL: gdb.threads/process-dies-while-detaching.exp: single-process: \
>>>   detach: detach: continue to breakpoint: _exit (the program exited)
>>> ...
>>>
>>> What happens is the following:
>>> - a breakpoint is set on _exit,
>>> - a continue is issued
>>> - the continue is supposed to hit the breakpoint, but instead
>>>   the program exits.
>>>
>>> I traced this down to the breakpoint on _exit being set too far from function
>>> entry.  This is caused by the skip_prologue function (in rs6000-tdep.c)
>>> optimistically ignoring insns it doesn't recognize.  In particular, it walks
>>> past the system call instruction "sc" which initiates the actual exit.
>>>
>>> While this needs fixing,  
>>
>> Filed here: https://sourceware.org/bugzilla/show_bug.cgi?id=28527 .
>>
>> Submitted patch here:
>> https://sourceware.org/pipermail/gdb-patches/2021-November/183016.html .
>>
>> Thanks,
>> - Tom
>>
>>> we don't want to be testing this behaviour in this
>>> test-case.
> 
> Since you've fixed the problem in skip_prologue(), I'd prefer that this
> testsuite patch not go in.

One possible objection would be that otherwise we no longer excercise
the problem, so here's a test-case for that.

Any comments?

Thanks,
- Tom

[-- Attachment #2: 0001-gdb-testsuite-Add-gdb.opt-break-on-_exit.exp.patch --]
[-- Type: text/x-patch, Size: 4294 bytes --]

[gdb/testsuite] Add gdb.opt/break-on-_exit.exp

Add a test-case to excercise the problem reported in PR28527 and fixed in
commit a50bdb99afe "[gdb/tdep, rs6000] Don't skip system call in
skip_prologue": set a breakpoint on _exit, and verify that it triggers.

Tested on x86_64-linux and ppc64le-linux.

---
 gdb/testsuite/gdb.opt/break-on-_exit.c   | 26 +++++++++++++
 gdb/testsuite/gdb.opt/break-on-_exit.exp | 66 ++++++++++++++++++++++++++++++++
 2 files changed, 92 insertions(+)

diff --git a/gdb/testsuite/gdb.opt/break-on-_exit.c b/gdb/testsuite/gdb.opt/break-on-_exit.c
new file mode 100644
index 00000000000..d8da66193a8
--- /dev/null
+++ b/gdb/testsuite/gdb.opt/break-on-_exit.c
@@ -0,0 +1,26 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2021 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 <unistd.h>
+
+int
+main (void)
+{
+  _exit (0);
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.opt/break-on-_exit.exp b/gdb/testsuite/gdb.opt/break-on-_exit.exp
new file mode 100644
index 00000000000..38476412862
--- /dev/null
+++ b/gdb/testsuite/gdb.opt/break-on-_exit.exp
@@ -0,0 +1,66 @@
+# Copyright 2021 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/>.  */
+
+# Set a breakpoint on libc's _exit, and verify that it triggers.  The function
+# tends to do a syscall immediately after the prologue, and if the breakpoint is
+# set past the syscall due to faulty prologue skipping, the breakpoint will not
+# trigger.
+#
+# In particular, we're trying to excercise the instruction analysis
+# functionality of prologue skipping.  If the non-minimal symbols are
+# read for libc, then that functionality might not be used because f.i.
+# line-info is used instead.  Also, if the minimal symbols are not read
+# for libc, then the breakpoint is set on the exec-local _exit@plt instead,
+# and that functionality will also not be used.
+#
+# We may get the required setup in case of a libc with misssing separate
+# debuginfo, but we want the same effect if that debuginfo is installed.
+#
+# So, we use -readnever to read minimal symbols, but not non-miminal symbols.
+#
+# Because the code at _exit may be and usually is optimized, the test is in
+# the gdb.opt directory.
+
+standard_testfile
+
+# See if we have target board readnow.exp or similar.
+if { [lsearch -exact $GDBFLAGS -readnow] != -1 \
+	 || [lsearch -exact $GDBFLAGS --readnow] != -1 } {
+    untested "--readnever not allowed in combination with --readnow"
+    return -1
+}
+
+save_vars { GDBFLAGS } {
+    append GDBFLAGS " -readnever"
+
+    if {[prepare_for_testing "failed to prepare" $testfile $srcfile nodebug]} {
+	return -1
+    }
+}
+
+if ![runto_main] then {
+    return 0
+}
+
+gdb_breakpoint "_exit"
+
+# Give some background information about the breakpoint(s) and corresponding
+# the shared lib(s).
+gdb_test "info breakpoints"
+gdb_test "info shared"
+
+# If the skip_prologue analysis of _exit is too eager, we may not hit the
+# breakpoint.
+gdb_continue_to_breakpoint "_exit" "_exit \\(\\) .*"

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

* Re: [PATCH][gdb/testsuite] Add gdb.opt/break-on-_exit.exp
  2021-11-04 11:20     ` [PATCH][gdb/testsuite] Add gdb.opt/break-on-_exit.exp Tom de Vries
@ 2021-11-09 16:35       ` Kevin Buettner
  2021-11-09 16:58         ` Tom de Vries
  0 siblings, 1 reply; 11+ messages in thread
From: Kevin Buettner @ 2021-11-09 16:35 UTC (permalink / raw)
  To: Tom de Vries; +Cc: gdb-patches

On Thu, 4 Nov 2021 12:20:14 +0100
Tom de Vries <tdevries@suse.de> wrote:

> [ was: Re: [PATCH][gdb/testsuite] Work around skip_prologue problems in
> gdb.threads/process-dies-while-detaching.exp ]
> 
> On 11/2/21 6:13 PM, Kevin Buettner wrote:
> > On Tue, 2 Nov 2021 12:38:26 +0100
> > Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> wrote:
> >   
> >> On 10/29/21 9:24 PM, Tom de Vries via Gdb-patches wrote:  
> >>> Hi,
> >>>
> >>> On powerpc64le-linux, I run into:
> >>> ...
> >>> [Inferior 1 (process 5156) exited normally]^M
> >>> (gdb) FAIL: gdb.threads/process-dies-while-detaching.exp: single-process: \
> >>>   detach: detach: continue to breakpoint: _exit (the program exited)
> >>> ...
> >>>
> >>> What happens is the following:
> >>> - a breakpoint is set on _exit,
> >>> - a continue is issued
> >>> - the continue is supposed to hit the breakpoint, but instead
> >>>   the program exits.
> >>>
> >>> I traced this down to the breakpoint on _exit being set too far from function
> >>> entry.  This is caused by the skip_prologue function (in rs6000-tdep.c)
> >>> optimistically ignoring insns it doesn't recognize.  In particular, it walks
> >>> past the system call instruction "sc" which initiates the actual exit.
> >>>
> >>> While this needs fixing,    
> >>
> >> Filed here: https://sourceware.org/bugzilla/show_bug.cgi?id=28527 .
> >>
> >> Submitted patch here:
> >> https://sourceware.org/pipermail/gdb-patches/2021-November/183016.html .
> >>
> >> Thanks,
> >> - Tom
> >>  
> >>> we don't want to be testing this behaviour in this
> >>> test-case.  
> > 
> > Since you've fixed the problem in skip_prologue(), I'd prefer that this
> > testsuite patch not go in.  
> 
> One possible objection would be that otherwise we no longer excercise
> the problem, so here's a test-case for that.
> 
> Any comments?

I've been trying (and failing) to reproduce this by hand on Fedora 35
ppc64le.   Here's what I'm doing...

[kev@f35-ppc64le-1 tmp]$ tail -9 break-on-_exit.c 
#include <unistd.h>

int
main (void)
{
  _exit (0);

  return 0;
}
[kev@f35-ppc64le-1 tmp]$ gcc -o break-on-_exit break-on-_exit.c
[kev@f35-ppc64le-1 tmp]$ gdb --readnever break-on-_exit 
GNU gdb (GDB) Fedora 11.1-2.fc35
Copyright (C) 2021 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 "ppc64le-redhat-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 break-on-_exit...
(No debugging symbols found in break-on-_exit)
(gdb) start
Temporary breakpoint 1 at 0x10000708
Starting program: /mesquite2/tmp/break-on-_exit 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Temporary breakpoint 1, 0x0000000010000708 in main ()
(gdb) b _exit
Breakpoint 2 at 0x7ffff7decc1c (2 locations)
(gdb) info breakpoints
Num     Type           Disp Enb Address            What
2       breakpoint     keep y   <MULTIPLE>         
2.1                         y   0x00007ffff7decc1c <_exit+60>
2.2                         y   0x00007ffff7fc9970 <_exit+64>
(gdb) info shared
From                To                  Syms Read   Shared Object Library
0x00007ffff7f91080  0x00007ffff7fcc224  Yes (*)     /lib64/ld64.so.2
0x00007ffff7d00a80  0x00007ffff7eaebbc  Yes (*)     /lib64/libc.so.6
(*): Shared library is missing debugging information.
(gdb) c
Continuing.

Breakpoint 2, 0x00007ffff7decc1c in _exit () from /lib64/libc.so.6
(gdb) x/20i _exit
   0x7ffff7decbe0 <_exit>:	addis   r2,r12,21
   0x7ffff7decbe4 <_exit+4>:	addi    r2,r2,-23776
   0x7ffff7decbe8 <_exit+8>:	mflr    r0
   0x7ffff7decbec <_exit+12>:	nop
   0x7ffff7decbf0 <_exit+16>:	std     r29,-24(r1)
   0x7ffff7decbf4 <_exit+20>:	std     r31,-8(r1)
   0x7ffff7decbf8 <_exit+24>:	ld      r9,-29160(r2)
   0x7ffff7decbfc <_exit+28>:	mr      r31,r3
   0x7ffff7decc00 <_exit+32>:	std     r30,-16(r1)
   0x7ffff7decc04 <_exit+36>:	add     r29,r9,r13
   0x7ffff7decc08 <_exit+40>:	ld      r9,-28776(r13)
   0x7ffff7decc0c <_exit+44>:	li      r30,-4096
   0x7ffff7decc10 <_exit+48>:	mr      r3,r31
   0x7ffff7decc14 <_exit+52>:	andis.  r9,r9,16
   0x7ffff7decc18 <_exit+56>:	std     r0,16(r1)
=> 0x7ffff7decc1c <_exit+60>:	li      r0,234
   0x7ffff7decc20 <_exit+64>:	beq     0x7ffff7decc74 <_exit+148>
   0x7ffff7decc24 <_exit+68>:	nop
   0x7ffff7decc28 <_exit+72>:	nop
   0x7ffff7decc2c <_exit+76>:	ori     r2,r2,0
(gdb) 

I'm guessing that _exit looks different in your environment?

Kevin


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

* Re: [PATCH][gdb/testsuite] Add gdb.opt/break-on-_exit.exp
  2021-11-09 16:35       ` Kevin Buettner
@ 2021-11-09 16:58         ` Tom de Vries
  2021-11-09 17:29           ` Kevin Buettner
  0 siblings, 1 reply; 11+ messages in thread
From: Tom de Vries @ 2021-11-09 16:58 UTC (permalink / raw)
  To: Kevin Buettner; +Cc: gdb-patches

On 11/9/21 5:35 PM, Kevin Buettner wrote:
> On Thu, 4 Nov 2021 12:20:14 +0100
> Tom de Vries <tdevries@suse.de> wrote:
> 
>> [ was: Re: [PATCH][gdb/testsuite] Work around skip_prologue problems in
>> gdb.threads/process-dies-while-detaching.exp ]
>>
>> On 11/2/21 6:13 PM, Kevin Buettner wrote:
>>> On Tue, 2 Nov 2021 12:38:26 +0100
>>> Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> wrote:
>>>   
>>>> On 10/29/21 9:24 PM, Tom de Vries via Gdb-patches wrote:  
>>>>> Hi,
>>>>>
>>>>> On powerpc64le-linux, I run into:
>>>>> ...
>>>>> [Inferior 1 (process 5156) exited normally]^M
>>>>> (gdb) FAIL: gdb.threads/process-dies-while-detaching.exp: single-process: \
>>>>>   detach: detach: continue to breakpoint: _exit (the program exited)
>>>>> ...
>>>>>
>>>>> What happens is the following:
>>>>> - a breakpoint is set on _exit,
>>>>> - a continue is issued
>>>>> - the continue is supposed to hit the breakpoint, but instead
>>>>>   the program exits.
>>>>>
>>>>> I traced this down to the breakpoint on _exit being set too far from function
>>>>> entry.  This is caused by the skip_prologue function (in rs6000-tdep.c)
>>>>> optimistically ignoring insns it doesn't recognize.  In particular, it walks
>>>>> past the system call instruction "sc" which initiates the actual exit.
>>>>>
>>>>> While this needs fixing,    
>>>>
>>>> Filed here: https://sourceware.org/bugzilla/show_bug.cgi?id=28527 .
>>>>
>>>> Submitted patch here:
>>>> https://sourceware.org/pipermail/gdb-patches/2021-November/183016.html .
>>>>
>>>> Thanks,
>>>> - Tom
>>>>  
>>>>> we don't want to be testing this behaviour in this
>>>>> test-case.  
>>>
>>> Since you've fixed the problem in skip_prologue(), I'd prefer that this
>>> testsuite patch not go in.  
>>
>> One possible objection would be that otherwise we no longer excercise
>> the problem, so here's a test-case for that.
>>
>> Any comments?
> 
> I've been trying (and failing) to reproduce this by hand on Fedora 35
> ppc64le.   Here's what I'm doing...
> 
> [kev@f35-ppc64le-1 tmp]$ tail -9 break-on-_exit.c 
> #include <unistd.h>
> 
> int
> main (void)
> {
>   _exit (0);
> 
>   return 0;
> }
> [kev@f35-ppc64le-1 tmp]$ gcc -o break-on-_exit break-on-_exit.c
> [kev@f35-ppc64le-1 tmp]$ gdb --readnever break-on-_exit 
> GNU gdb (GDB) Fedora 11.1-2.fc35
> Copyright (C) 2021 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 "ppc64le-redhat-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 break-on-_exit...
> (No debugging symbols found in break-on-_exit)
> (gdb) start
> Temporary breakpoint 1 at 0x10000708
> Starting program: /mesquite2/tmp/break-on-_exit 
> [Thread debugging using libthread_db enabled]
> Using host libthread_db library "/lib64/libthread_db.so.1".
> 
> Temporary breakpoint 1, 0x0000000010000708 in main ()
> (gdb) b _exit
> Breakpoint 2 at 0x7ffff7decc1c (2 locations)
> (gdb) info breakpoints
> Num     Type           Disp Enb Address            What
> 2       breakpoint     keep y   <MULTIPLE>         
> 2.1                         y   0x00007ffff7decc1c <_exit+60>
> 2.2                         y   0x00007ffff7fc9970 <_exit+64>
> (gdb) info shared
> From                To                  Syms Read   Shared Object Library
> 0x00007ffff7f91080  0x00007ffff7fcc224  Yes (*)     /lib64/ld64.so.2
> 0x00007ffff7d00a80  0x00007ffff7eaebbc  Yes (*)     /lib64/libc.so.6
> (*): Shared library is missing debugging information.
> (gdb) c
> Continuing.
> 
> Breakpoint 2, 0x00007ffff7decc1c in _exit () from /lib64/libc.so.6
> (gdb) x/20i _exit
>    0x7ffff7decbe0 <_exit>:	addis   r2,r12,21
>    0x7ffff7decbe4 <_exit+4>:	addi    r2,r2,-23776
>    0x7ffff7decbe8 <_exit+8>:	mflr    r0
>    0x7ffff7decbec <_exit+12>:	nop
>    0x7ffff7decbf0 <_exit+16>:	std     r29,-24(r1)
>    0x7ffff7decbf4 <_exit+20>:	std     r31,-8(r1)
>    0x7ffff7decbf8 <_exit+24>:	ld      r9,-29160(r2)
>    0x7ffff7decbfc <_exit+28>:	mr      r31,r3
>    0x7ffff7decc00 <_exit+32>:	std     r30,-16(r1)
>    0x7ffff7decc04 <_exit+36>:	add     r29,r9,r13
>    0x7ffff7decc08 <_exit+40>:	ld      r9,-28776(r13)
>    0x7ffff7decc0c <_exit+44>:	li      r30,-4096
>    0x7ffff7decc10 <_exit+48>:	mr      r3,r31
>    0x7ffff7decc14 <_exit+52>:	andis.  r9,r9,16
>    0x7ffff7decc18 <_exit+56>:	std     r0,16(r1)
> => 0x7ffff7decc1c <_exit+60>:	li      r0,234
>    0x7ffff7decc20 <_exit+64>:	beq     0x7ffff7decc74 <_exit+148>
>    0x7ffff7decc24 <_exit+68>:	nop
>    0x7ffff7decc28 <_exit+72>:	nop
>    0x7ffff7decc2c <_exit+76>:	ori     r2,r2,0
> (gdb) 
> 

Hi Kevin, thanks for looking into this.

> I'm guessing that _exit looks different in your environment?

Indeed, as show in the log message of commit
a50bdb99afe3ce2374407cbe7ddc625c1a0b74f7:
...
    Dump of assembler code for function _exit:
       0x00007ffff7e42ea0 <+0>:     12 00 4c 3c     addis   r2,r12,18
       0x00007ffff7e42ea4 <+4>:     60 43 42 38     addi    r2,r2,17248
       0x00007ffff7e42ea8 <+8>:     00 00 00 60     nop
       0x00007ffff7e42eac <+12>:    f8 ff e1 fb     std     r31,-8(r1)
       0x00007ffff7e42eb0 <+16>:    78 1b 7f 7c     mr      r31,r3
       0x00007ffff7e42eb4 <+20>:    f0 ff c1 fb     std     r30,-16(r1)
       0x00007ffff7e42eb8 <+24>:    ea 00 00 38     li      r0,234
       0x00007ffff7e42ebc <+28>:    a0 8b 22 e9     ld      r9,-29792(r2)
       0x00007ffff7e42ec0 <+32>:    78 fb e3 7f     mr      r3,r31
       0x00007ffff7e42ec4 <+36>:    14 6a c9 7f     add     r30,r9,r13
       0x00007ffff7e42ec8 <+40>:    02 00 00 44     sc
       0x00007ffff7e42ecc <+44>:    26 00 00 7c     mfcr    r0
       0x00007ffff7e42ed0 <+48>:    00 10 09 74     andis.  r9,r0,4096
...

That's is why I put the test-case in the gdb.opt dir: it will excercise
the code provided by glibc, which tends to be optimized, and different
across os instances.

The fact that it's not necessarily reproducible across os instances is
not great, but OTOH it means that we do exercise real life code (much
like the original test-case setting a breakpoint on _exit does, but in a
more minimal way).

Thanks,
- Tom

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

* Re: [PATCH][gdb/testsuite] Add gdb.opt/break-on-_exit.exp
  2021-11-09 16:58         ` Tom de Vries
@ 2021-11-09 17:29           ` Kevin Buettner
  2021-11-10 10:57             ` [PATCH][gdb/testsuite] Add gdb.arch/ppc64-break-on-_exit.exp Tom de Vries
  2021-11-10 11:56             ` [PATCH][gdb/testsuite] Add gdb.opt/break-on-_exit.exp Tom de Vries
  0 siblings, 2 replies; 11+ messages in thread
From: Kevin Buettner @ 2021-11-09 17:29 UTC (permalink / raw)
  To: Tom de Vries; +Cc: gdb-patches

On Tue, 9 Nov 2021 17:58:17 +0100
Tom de Vries <tdevries@suse.de> wrote:

> On 11/9/21 5:35 PM, Kevin Buettner wrote:
> > On Thu, 4 Nov 2021 12:20:14 +0100
> > Tom de Vries <tdevries@suse.de> wrote:
> >   
> >> [ was: Re: [PATCH][gdb/testsuite] Work around skip_prologue problems in
> >> gdb.threads/process-dies-while-detaching.exp ]
> >>
> >> On 11/2/21 6:13 PM, Kevin Buettner wrote:  
> >>> On Tue, 2 Nov 2021 12:38:26 +0100
> >>> Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> wrote:
> >>>     
> >>>> On 10/29/21 9:24 PM, Tom de Vries via Gdb-patches wrote:    
> >>>>> Hi,
> >>>>>
> >>>>> On powerpc64le-linux, I run into:
> >>>>> ...
> >>>>> [Inferior 1 (process 5156) exited normally]^M
> >>>>> (gdb) FAIL: gdb.threads/process-dies-while-detaching.exp: single-process: \
> >>>>>   detach: detach: continue to breakpoint: _exit (the program exited)
> >>>>> ...
> >>>>>
> >>>>> What happens is the following:
> >>>>> - a breakpoint is set on _exit,
> >>>>> - a continue is issued
> >>>>> - the continue is supposed to hit the breakpoint, but instead
> >>>>>   the program exits.
> >>>>>
> >>>>> I traced this down to the breakpoint on _exit being set too far from function
> >>>>> entry.  This is caused by the skip_prologue function (in rs6000-tdep.c)
> >>>>> optimistically ignoring insns it doesn't recognize.  In particular, it walks
> >>>>> past the system call instruction "sc" which initiates the actual exit.
> >>>>>
> >>>>> While this needs fixing,      
> >>>>
> >>>> Filed here: https://sourceware.org/bugzilla/show_bug.cgi?id=28527 .
> >>>>
> >>>> Submitted patch here:
> >>>> https://sourceware.org/pipermail/gdb-patches/2021-November/183016.html .
> >>>>
> >>>> Thanks,
> >>>> - Tom
> >>>>    
> >>>>> we don't want to be testing this behaviour in this
> >>>>> test-case.    
> >>>
> >>> Since you've fixed the problem in skip_prologue(), I'd prefer that this
> >>> testsuite patch not go in.    
> >>
> >> One possible objection would be that otherwise we no longer excercise
> >> the problem, so here's a test-case for that.
> >>
> >> Any comments?  
> > 
> > I've been trying (and failing) to reproduce this by hand on Fedora 35
> > ppc64le.   Here's what I'm doing...
> > 
> > [kev@f35-ppc64le-1 tmp]$ tail -9 break-on-_exit.c 
> > #include <unistd.h>
> > 
> > int
> > main (void)
> > {
> >   _exit (0);
> > 
> >   return 0;
> > }
> > [kev@f35-ppc64le-1 tmp]$ gcc -o break-on-_exit break-on-_exit.c
> > [kev@f35-ppc64le-1 tmp]$ gdb --readnever break-on-_exit 
> > GNU gdb (GDB) Fedora 11.1-2.fc35
> > Copyright (C) 2021 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 "ppc64le-redhat-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 break-on-_exit...
> > (No debugging symbols found in break-on-_exit)
> > (gdb) start
> > Temporary breakpoint 1 at 0x10000708
> > Starting program: /mesquite2/tmp/break-on-_exit 
> > [Thread debugging using libthread_db enabled]
> > Using host libthread_db library "/lib64/libthread_db.so.1".
> > 
> > Temporary breakpoint 1, 0x0000000010000708 in main ()
> > (gdb) b _exit
> > Breakpoint 2 at 0x7ffff7decc1c (2 locations)
> > (gdb) info breakpoints
> > Num     Type           Disp Enb Address            What
> > 2       breakpoint     keep y   <MULTIPLE>         
> > 2.1                         y   0x00007ffff7decc1c <_exit+60>
> > 2.2                         y   0x00007ffff7fc9970 <_exit+64>
> > (gdb) info shared
> > From                To                  Syms Read   Shared Object Library
> > 0x00007ffff7f91080  0x00007ffff7fcc224  Yes (*)     /lib64/ld64.so.2
> > 0x00007ffff7d00a80  0x00007ffff7eaebbc  Yes (*)     /lib64/libc.so.6
> > (*): Shared library is missing debugging information.
> > (gdb) c
> > Continuing.
> > 
> > Breakpoint 2, 0x00007ffff7decc1c in _exit () from /lib64/libc.so.6
> > (gdb) x/20i _exit
> >    0x7ffff7decbe0 <_exit>:	addis   r2,r12,21
> >    0x7ffff7decbe4 <_exit+4>:	addi    r2,r2,-23776
> >    0x7ffff7decbe8 <_exit+8>:	mflr    r0
> >    0x7ffff7decbec <_exit+12>:	nop
> >    0x7ffff7decbf0 <_exit+16>:	std     r29,-24(r1)
> >    0x7ffff7decbf4 <_exit+20>:	std     r31,-8(r1)
> >    0x7ffff7decbf8 <_exit+24>:	ld      r9,-29160(r2)
> >    0x7ffff7decbfc <_exit+28>:	mr      r31,r3
> >    0x7ffff7decc00 <_exit+32>:	std     r30,-16(r1)
> >    0x7ffff7decc04 <_exit+36>:	add     r29,r9,r13
> >    0x7ffff7decc08 <_exit+40>:	ld      r9,-28776(r13)
> >    0x7ffff7decc0c <_exit+44>:	li      r30,-4096
> >    0x7ffff7decc10 <_exit+48>:	mr      r3,r31
> >    0x7ffff7decc14 <_exit+52>:	andis.  r9,r9,16
> >    0x7ffff7decc18 <_exit+56>:	std     r0,16(r1)  
> > => 0x7ffff7decc1c <_exit+60>:	li      r0,234  
> >    0x7ffff7decc20 <_exit+64>:	beq     0x7ffff7decc74 <_exit+148>
> >    0x7ffff7decc24 <_exit+68>:	nop
> >    0x7ffff7decc28 <_exit+72>:	nop
> >    0x7ffff7decc2c <_exit+76>:	ori     r2,r2,0
> > (gdb) 
> >   
> 
> Hi Kevin, thanks for looking into this.
> 
> > I'm guessing that _exit looks different in your environment?  
> 
> Indeed, as show in the log message of commit
> a50bdb99afe3ce2374407cbe7ddc625c1a0b74f7:
> ...
>     Dump of assembler code for function _exit:
>        0x00007ffff7e42ea0 <+0>:     12 00 4c 3c     addis   r2,r12,18
>        0x00007ffff7e42ea4 <+4>:     60 43 42 38     addi    r2,r2,17248
>        0x00007ffff7e42ea8 <+8>:     00 00 00 60     nop
>        0x00007ffff7e42eac <+12>:    f8 ff e1 fb     std     r31,-8(r1)
>        0x00007ffff7e42eb0 <+16>:    78 1b 7f 7c     mr      r31,r3
>        0x00007ffff7e42eb4 <+20>:    f0 ff c1 fb     std     r30,-16(r1)
>        0x00007ffff7e42eb8 <+24>:    ea 00 00 38     li      r0,234
>        0x00007ffff7e42ebc <+28>:    a0 8b 22 e9     ld      r9,-29792(r2)
>        0x00007ffff7e42ec0 <+32>:    78 fb e3 7f     mr      r3,r31
>        0x00007ffff7e42ec4 <+36>:    14 6a c9 7f     add     r30,r9,r13
>        0x00007ffff7e42ec8 <+40>:    02 00 00 44     sc
>        0x00007ffff7e42ecc <+44>:    26 00 00 7c     mfcr    r0
>        0x00007ffff7e42ed0 <+48>:    00 10 09 74     andis.  r9,r0,4096
> ...
> 
> That's is why I put the test-case in the gdb.opt dir: it will excercise
> the code provided by glibc, which tends to be optimized, and different
> across os instances.
> 
> The fact that it's not necessarily reproducible across os instances is
> not great, but OTOH it means that we do exercise real life code (much
> like the original test-case setting a breakpoint on _exit does, but in a
> more minimal way).

Thanks for the clarifications.

I think your new test is okay, though (of course) it would have been
nice to have a test which doesn't depend on particular OS instances.

Kevin


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

* [PATCH][gdb/testsuite] Add gdb.arch/ppc64-break-on-_exit.exp
  2021-11-09 17:29           ` Kevin Buettner
@ 2021-11-10 10:57             ` Tom de Vries
  2021-11-10 23:50               ` Kevin Buettner
  2021-11-10 11:56             ` [PATCH][gdb/testsuite] Add gdb.opt/break-on-_exit.exp Tom de Vries
  1 sibling, 1 reply; 11+ messages in thread
From: Tom de Vries @ 2021-11-10 10:57 UTC (permalink / raw)
  To: Kevin Buettner; +Cc: gdb-patches

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

[was: Re: [PATCH][gdb/testsuite] Add gdb.opt/break-on-_exit.exp ]

On 11/9/21 6:29 PM, Kevin Buettner wrote:
> On Tue, 9 Nov 2021 17:58:17 +0100
> Tom de Vries <tdevries@suse.de> wrote:
> 
>> On 11/9/21 5:35 PM, Kevin Buettner wrote:
>>> On Thu, 4 Nov 2021 12:20:14 +0100
>>> Tom de Vries <tdevries@suse.de> wrote:
>>>   
>>>> [ was: Re: [PATCH][gdb/testsuite] Work around skip_prologue problems in
>>>> gdb.threads/process-dies-while-detaching.exp ]
>>>>
>>>> On 11/2/21 6:13 PM, Kevin Buettner wrote:  
>>>>> On Tue, 2 Nov 2021 12:38:26 +0100
>>>>> Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> wrote:
>>>>>     
>>>>>> On 10/29/21 9:24 PM, Tom de Vries via Gdb-patches wrote:    
>>>>>>> Hi,
>>>>>>>
>>>>>>> On powerpc64le-linux, I run into:
>>>>>>> ...
>>>>>>> [Inferior 1 (process 5156) exited normally]^M
>>>>>>> (gdb) FAIL: gdb.threads/process-dies-while-detaching.exp: single-process: \
>>>>>>>   detach: detach: continue to breakpoint: _exit (the program exited)
>>>>>>> ...
>>>>>>>
>>>>>>> What happens is the following:
>>>>>>> - a breakpoint is set on _exit,
>>>>>>> - a continue is issued
>>>>>>> - the continue is supposed to hit the breakpoint, but instead
>>>>>>>   the program exits.
>>>>>>>
>>>>>>> I traced this down to the breakpoint on _exit being set too far from function
>>>>>>> entry.  This is caused by the skip_prologue function (in rs6000-tdep.c)
>>>>>>> optimistically ignoring insns it doesn't recognize.  In particular, it walks
>>>>>>> past the system call instruction "sc" which initiates the actual exit.
>>>>>>>
>>>>>>> While this needs fixing,      
>>>>>>
>>>>>> Filed here: https://sourceware.org/bugzilla/show_bug.cgi?id=28527 .
>>>>>>
>>>>>> Submitted patch here:
>>>>>> https://sourceware.org/pipermail/gdb-patches/2021-November/183016.html .
>>>>>>
>>>>>> Thanks,
>>>>>> - Tom
>>>>>>    
>>>>>>> we don't want to be testing this behaviour in this
>>>>>>> test-case.    
>>>>>
>>>>> Since you've fixed the problem in skip_prologue(), I'd prefer that this
>>>>> testsuite patch not go in.    
>>>>
>>>> One possible objection would be that otherwise we no longer excercise
>>>> the problem, so here's a test-case for that.
>>>>
>>>> Any comments?  
>>>
>>> I've been trying (and failing) to reproduce this by hand on Fedora 35
>>> ppc64le.   Here's what I'm doing...
>>>
>>> [kev@f35-ppc64le-1 tmp]$ tail -9 break-on-_exit.c 
>>> #include <unistd.h>
>>>
>>> int
>>> main (void)
>>> {
>>>   _exit (0);
>>>
>>>   return 0;
>>> }
>>> [kev@f35-ppc64le-1 tmp]$ gcc -o break-on-_exit break-on-_exit.c
>>> [kev@f35-ppc64le-1 tmp]$ gdb --readnever break-on-_exit 
>>> GNU gdb (GDB) Fedora 11.1-2.fc35
>>> Copyright (C) 2021 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 "ppc64le-redhat-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 break-on-_exit...
>>> (No debugging symbols found in break-on-_exit)
>>> (gdb) start
>>> Temporary breakpoint 1 at 0x10000708
>>> Starting program: /mesquite2/tmp/break-on-_exit 
>>> [Thread debugging using libthread_db enabled]
>>> Using host libthread_db library "/lib64/libthread_db.so.1".
>>>
>>> Temporary breakpoint 1, 0x0000000010000708 in main ()
>>> (gdb) b _exit
>>> Breakpoint 2 at 0x7ffff7decc1c (2 locations)
>>> (gdb) info breakpoints
>>> Num     Type           Disp Enb Address            What
>>> 2       breakpoint     keep y   <MULTIPLE>         
>>> 2.1                         y   0x00007ffff7decc1c <_exit+60>
>>> 2.2                         y   0x00007ffff7fc9970 <_exit+64>
>>> (gdb) info shared
>>> From                To                  Syms Read   Shared Object Library
>>> 0x00007ffff7f91080  0x00007ffff7fcc224  Yes (*)     /lib64/ld64.so.2
>>> 0x00007ffff7d00a80  0x00007ffff7eaebbc  Yes (*)     /lib64/libc.so.6
>>> (*): Shared library is missing debugging information.
>>> (gdb) c
>>> Continuing.
>>>
>>> Breakpoint 2, 0x00007ffff7decc1c in _exit () from /lib64/libc.so.6
>>> (gdb) x/20i _exit
>>>    0x7ffff7decbe0 <_exit>:	addis   r2,r12,21
>>>    0x7ffff7decbe4 <_exit+4>:	addi    r2,r2,-23776
>>>    0x7ffff7decbe8 <_exit+8>:	mflr    r0
>>>    0x7ffff7decbec <_exit+12>:	nop
>>>    0x7ffff7decbf0 <_exit+16>:	std     r29,-24(r1)
>>>    0x7ffff7decbf4 <_exit+20>:	std     r31,-8(r1)
>>>    0x7ffff7decbf8 <_exit+24>:	ld      r9,-29160(r2)
>>>    0x7ffff7decbfc <_exit+28>:	mr      r31,r3
>>>    0x7ffff7decc00 <_exit+32>:	std     r30,-16(r1)
>>>    0x7ffff7decc04 <_exit+36>:	add     r29,r9,r13
>>>    0x7ffff7decc08 <_exit+40>:	ld      r9,-28776(r13)
>>>    0x7ffff7decc0c <_exit+44>:	li      r30,-4096
>>>    0x7ffff7decc10 <_exit+48>:	mr      r3,r31
>>>    0x7ffff7decc14 <_exit+52>:	andis.  r9,r9,16
>>>    0x7ffff7decc18 <_exit+56>:	std     r0,16(r1)  
>>> => 0x7ffff7decc1c <_exit+60>:	li      r0,234  
>>>    0x7ffff7decc20 <_exit+64>:	beq     0x7ffff7decc74 <_exit+148>
>>>    0x7ffff7decc24 <_exit+68>:	nop
>>>    0x7ffff7decc28 <_exit+72>:	nop
>>>    0x7ffff7decc2c <_exit+76>:	ori     r2,r2,0
>>> (gdb) 
>>>   
>>
>> Hi Kevin, thanks for looking into this.
>>
>>> I'm guessing that _exit looks different in your environment?  
>>
>> Indeed, as show in the log message of commit
>> a50bdb99afe3ce2374407cbe7ddc625c1a0b74f7:
>> ...
>>     Dump of assembler code for function _exit:
>>        0x00007ffff7e42ea0 <+0>:     12 00 4c 3c     addis   r2,r12,18
>>        0x00007ffff7e42ea4 <+4>:     60 43 42 38     addi    r2,r2,17248
>>        0x00007ffff7e42ea8 <+8>:     00 00 00 60     nop
>>        0x00007ffff7e42eac <+12>:    f8 ff e1 fb     std     r31,-8(r1)
>>        0x00007ffff7e42eb0 <+16>:    78 1b 7f 7c     mr      r31,r3
>>        0x00007ffff7e42eb4 <+20>:    f0 ff c1 fb     std     r30,-16(r1)
>>        0x00007ffff7e42eb8 <+24>:    ea 00 00 38     li      r0,234
>>        0x00007ffff7e42ebc <+28>:    a0 8b 22 e9     ld      r9,-29792(r2)
>>        0x00007ffff7e42ec0 <+32>:    78 fb e3 7f     mr      r3,r31
>>        0x00007ffff7e42ec4 <+36>:    14 6a c9 7f     add     r30,r9,r13
>>        0x00007ffff7e42ec8 <+40>:    02 00 00 44     sc
>>        0x00007ffff7e42ecc <+44>:    26 00 00 7c     mfcr    r0
>>        0x00007ffff7e42ed0 <+48>:    00 10 09 74     andis.  r9,r0,4096
>> ...
>>
>> That's is why I put the test-case in the gdb.opt dir: it will excercise
>> the code provided by glibc, which tends to be optimized, and different
>> across os instances.
>>
>> The fact that it's not necessarily reproducible across os instances is
>> not great, but OTOH it means that we do exercise real life code (much
>> like the original test-case setting a breakpoint on _exit does, but in a
>> more minimal way).
> 
> Thanks for the clarifications.
> 
> I think your new test is okay, though (of course) it would have been
> nice to have a test which doesn't depend on particular OS instances.

Well, how about this one?  Does it reproduce for you, also in source
file mode ("if { 1 }" -> "if { 0 }" in the case-case) ?

[ I think there is some standard way of choosing between source and
assembly mode rather than using 1 or 0, but I can't find it. ]

Thanks,
- Tom

[-- Attachment #2: 0001-gdb-testsuite-Add-gdb.arch-ppc64-break-on-_exit.exp.patch --]
[-- Type: text/x-patch, Size: 10357 bytes --]

[gdb/testsuite] Add gdb.arch/ppc64-break-on-_exit.exp

Add a regression test-case for commit a50bdb99afe "[gdb/tdep, rs6000] Don't
skip system call in skip_prologue":
- set a breakpoint on a local copy of glibc's _exit, and
- verify that it triggers.

The test-case uses an assembly file by default, but also has the possibility
to use a C source file instead.

Tested on ppc64le-linux.  Verified that the test-case fails without
aforementioned commit, and passes with the commit.  Both with assembly
and C source.

---
 gdb/testsuite/gdb.arch/ppc64-break-on-_exit-main.c |  27 +++++
 gdb/testsuite/gdb.arch/ppc64-break-on-_exit.c      | 112 +++++++++++++++++++++
 gdb/testsuite/gdb.arch/ppc64-break-on-_exit.exp    |  56 +++++++++++
 gdb/testsuite/gdb.arch/ppc64-break-on-_exit.s      | 108 ++++++++++++++++++++
 4 files changed, 303 insertions(+)

diff --git a/gdb/testsuite/gdb.arch/ppc64-break-on-_exit-main.c b/gdb/testsuite/gdb.arch/ppc64-break-on-_exit-main.c
new file mode 100644
index 00000000000..77253140e36
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/ppc64-break-on-_exit-main.c
@@ -0,0 +1,27 @@
+/* This file is part of GDB, the GNU debugger.
+
+   Copyright 2021 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 <unistd.h>
+
+__thread int __libc_errno;
+
+int
+main ()
+{
+  _exit (22);
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.arch/ppc64-break-on-_exit.c b/gdb/testsuite/gdb.arch/ppc64-break-on-_exit.c
new file mode 100644
index 00000000000..8638a7a6b70
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/ppc64-break-on-_exit.c
@@ -0,0 +1,112 @@
+/* This file is part of GDB, the GNU debugger.
+
+   Copyright 2021 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/>.  */
+
+/* This file was generated from glibc's 2.31 _exit.c, by doing a glibc build
+   on ppc64le-linux, copying the command line, adding -g0 -save-temps and
+   recuding the _exit.i file.  */
+
+void _exit (int status);
+
+extern __thread int __libc_errno;
+
+void
+_exit (int status)
+{
+  while (1)
+    {
+      ({
+	long int sc_err __attribute__ ((unused));
+	long int sc_ret
+	  = ({
+	      register long int r0 __asm__ ("r0");
+	      register long int r3 __asm__ ("r3");
+	      register long int r4 __asm__ ("r4");
+	      register long int r5 __asm__ ("r5");
+	      register long int r6 __asm__ ("r6");
+	      register long int r7 __asm__ ("r7");
+	      register long int r8 __asm__ ("r8");
+	      long int arg1 = (long int) (status);
+
+	      r0 = 234;
+
+	      extern void __illegally_sized_syscall_arg1 (void);
+	      if (__builtin_classify_type (status) != 5 && sizeof (status) > 8)
+		__illegally_sized_syscall_arg1 ();
+
+	      r3 = arg1;
+	      __asm__ __volatile__ ("sc\n\t" "mfcr  %0\n\t" "0:"
+				    : "=&r" (r0), "=&r" (r3), "=&r" (r4),
+				      "=&r" (r5), "=&r" (r6), "=&r" (r7),
+				      "=&r" (r8) : "0" (r0), "1" (r3)
+				    : "r9", "r10", "r11", "r12", "cr0", "ctr", "memory");
+	      sc_err = r0;
+
+	      r3;
+	    });
+
+	if (((void) (sc_ret), __builtin_expect ((sc_err) & (1 << 28), 0)))
+	  {
+	    (__libc_errno = ((sc_ret)));
+	    sc_ret = -1L;
+	  }
+
+	sc_ret;
+      });
+
+      ({
+	long int sc_err __attribute__ ((unused));
+	long int sc_ret
+	  = ({
+	      register long int r0 __asm__ ("r0");
+	      register long int r3 __asm__ ("r3");
+	      register long int r4 __asm__ ("r4");
+	      register long int r5 __asm__ ("r5");
+	      register long int r6 __asm__ ("r6");
+	      register long int r7 __asm__ ("r7");
+	      register long int r8 __asm__ ("r8");
+	      long int arg1 = (long int) (status);
+
+	      r0 = 1;
+
+	      extern void __illegally_sized_syscall_arg1 (void);
+	      if (__builtin_classify_type (status) != 5 && sizeof (status) > 8)
+		__illegally_sized_syscall_arg1 ();
+
+	      r3 = arg1;
+	      __asm__ __volatile__ ("sc\n\t" "mfcr  %0\n\t" "0:"
+				    : "=&r" (r0), "=&r" (r3), "=&r" (r4),
+				      "=&r" (r5), "=&r" (r6), "=&r" (r7),
+				      "=&r" (r8) : "0" (r0), "1" (r3)
+				    : "r9", "r10", "r11", "r12", "cr0", "ctr", "memory");
+	      sc_err = r0;
+
+	      r3;
+	    });
+
+	if (((void) (sc_ret), __builtin_expect ((sc_err) & (1 << 28), 0)))
+	  {
+	    (__libc_errno = ((sc_ret)));
+	    sc_ret = -1L;
+	  }
+
+	sc_ret;
+      });
+
+
+      asm (".long 0");
+    }
+}
diff --git a/gdb/testsuite/gdb.arch/ppc64-break-on-_exit.exp b/gdb/testsuite/gdb.arch/ppc64-break-on-_exit.exp
new file mode 100644
index 00000000000..b2fef8e8b76
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/ppc64-break-on-_exit.exp
@@ -0,0 +1,56 @@
+# Copyright 2021 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/>.
+
+# Set a breakpoint on a local copy of glibc's _exit, and verify that it
+# triggers.  The function does a syscall immediately after the prologue, and
+# if the breakpoint is set past the syscall due to faulty prologue skipping,
+# the breakpoint will not trigger.
+#
+# In particular, we're trying to excercise the instruction analysis
+# functionality of prologue skipping.  If non-minimal symbols are
+# read, then that functionality might not be used because f.i.
+# line-info is used instead.  So, we use nodebug.
+
+if {![istarget "powerpc*"] || ![is_lp64_target]} {
+    unsupported "Not powerpc64"
+    return
+}
+
+set flags { nodebug }
+if { 1 } {
+    standard_testfile .s -main.c
+} else {
+    standard_testfile .c -main.c
+    lappend flags optimize=-O2
+    lappend flags additional_flags=-fno-stack-protector
+    lappend flags additional_flags=-mlong-double-128
+    lappend flags additional_flags=-fpic
+    lappend flags additional_flags=-ftls-model=initial-exec
+}
+
+if { [prepare_for_testing "failed to prepare" ${testfile} \
+	  [list $srcfile $srcfile2] $flags] } {
+    return -1
+}
+
+if ![runto_main] then {
+    return 0
+}
+
+gdb_breakpoint "_exit"
+
+# If the skip_prologue analysis of _exit is too eager, we may not hit the
+# breakpoint.
+gdb_continue_to_breakpoint "_exit" "_exit \\(\\).*"
diff --git a/gdb/testsuite/gdb.arch/ppc64-break-on-_exit.s b/gdb/testsuite/gdb.arch/ppc64-break-on-_exit.s
new file mode 100644
index 00000000000..37a9ace2aff
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/ppc64-break-on-_exit.s
@@ -0,0 +1,108 @@
+/* This file is part of GDB, the GNU debugger.
+
+   Copyright 2021 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/>.  */
+
+/* This file was generated from ppc64-break-on-_exit.c.  */
+
+	.file	"ppc64-break-on-_exit.c"
+	.abiversion 2
+	.section	".text"
+	.align 2
+	.p2align 4,,15
+	.globl _exit
+	.type	_exit, @function
+_exit:
+.LCF0:
+0:	addis 2,12,.TOC.-.LCF0@ha
+	addi 2,2,.TOC.-.LCF0@l
+	.localentry	_exit,.-_exit
+	addis 9,2,__libc_errno@got@tprel@ha
+	std 31,-8(1)
+	mr 31,3
+	std 30,-16(1)
+	li 0,234
+	ld 9,__libc_errno@got@tprel@l(9)
+	mr 3,31
+	add 30,9,__libc_errno@tls
+#APP
+ # 28 "src/gdb/testsuite/gdb.arch/ppc64-break-on-_exit.c" 1
+	sc
+	mfcr  0
+	0:
+ # 0 "" 2
+#NO_APP
+	andis. 9,0,0x1000
+	mr 9,3
+	li 0,1
+	mr 3,31
+	bne 0,.L13
+	.p2align 4,,15
+.L2:
+#APP
+ # 67 "src/gdb/testsuite/gdb.arch/ppc64-break-on-_exit.c" 1
+	sc
+	mfcr  0
+	0:
+ # 0 "" 2
+#NO_APP
+	andis. 9,0,0x1000
+	bne 0,.L14
+.L3:
+#APP
+ # 87 "src/gdb/testsuite/gdb.arch/ppc64-break-on-_exit.c" 1
+	.long 0
+ # 0 "" 2
+#NO_APP
+.L15:
+	li 0,234
+	mr 3,31
+#APP
+ # 28 "src/gdb/testsuite/gdb.arch/ppc64-break-on-_exit.c" 1
+	sc
+	mfcr  0
+	0:
+ # 0 "" 2
+#NO_APP
+	andis. 9,0,0x1000
+	mr 9,3
+	li 0,1
+	mr 3,31
+	beq 0,.L2
+.L13:
+	stw 9,0(30)
+#APP
+ # 67 "src/gdb/testsuite/gdb.arch/ppc64-break-on-_exit.c" 1
+	sc
+	mfcr  0
+	0:
+ # 0 "" 2
+#NO_APP
+	andis. 9,0,0x1000
+	beq 0,.L3
+	.p2align 4,,15
+.L14:
+	stw 3,0(30)
+#APP
+ # 87 "src/gdb/testsuite/gdb.arch/ppc64-break-on-_exit.c" 1
+	.long 0
+ # 0 "" 2
+#NO_APP
+	b .L15
+	.long 0
+	.byte 0,0,0,0,0,2,0,0
+	.size	_exit,.-_exit
+	.ident	"GCC: (SUSE Linux) 7.5.0"
+	.section	.note.GNU-stack,"",@progbits

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

* Re: [PATCH][gdb/testsuite] Add gdb.opt/break-on-_exit.exp
  2021-11-09 17:29           ` Kevin Buettner
  2021-11-10 10:57             ` [PATCH][gdb/testsuite] Add gdb.arch/ppc64-break-on-_exit.exp Tom de Vries
@ 2021-11-10 11:56             ` Tom de Vries
  1 sibling, 0 replies; 11+ messages in thread
From: Tom de Vries @ 2021-11-10 11:56 UTC (permalink / raw)
  To: Kevin Buettner; +Cc: gdb-patches

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

On 11/9/21 6:29 PM, Kevin Buettner wrote:
> On Tue, 9 Nov 2021 17:58:17 +0100
> Tom de Vries <tdevries@suse.de> wrote:
> 
>> On 11/9/21 5:35 PM, Kevin Buettner wrote:
>>> On Thu, 4 Nov 2021 12:20:14 +0100
>>> Tom de Vries <tdevries@suse.de> wrote:
>>>   
>>>> [ was: Re: [PATCH][gdb/testsuite] Work around skip_prologue problems in
>>>> gdb.threads/process-dies-while-detaching.exp ]
>>>>
>>>> On 11/2/21 6:13 PM, Kevin Buettner wrote:  
>>>>> On Tue, 2 Nov 2021 12:38:26 +0100
>>>>> Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> wrote:
>>>>>     
>>>>>> On 10/29/21 9:24 PM, Tom de Vries via Gdb-patches wrote:    
>>>>>>> Hi,
>>>>>>>
>>>>>>> On powerpc64le-linux, I run into:
>>>>>>> ...
>>>>>>> [Inferior 1 (process 5156) exited normally]^M
>>>>>>> (gdb) FAIL: gdb.threads/process-dies-while-detaching.exp: single-process: \
>>>>>>>   detach: detach: continue to breakpoint: _exit (the program exited)
>>>>>>> ...
>>>>>>>
>>>>>>> What happens is the following:
>>>>>>> - a breakpoint is set on _exit,
>>>>>>> - a continue is issued
>>>>>>> - the continue is supposed to hit the breakpoint, but instead
>>>>>>>   the program exits.
>>>>>>>
>>>>>>> I traced this down to the breakpoint on _exit being set too far from function
>>>>>>> entry.  This is caused by the skip_prologue function (in rs6000-tdep.c)
>>>>>>> optimistically ignoring insns it doesn't recognize.  In particular, it walks
>>>>>>> past the system call instruction "sc" which initiates the actual exit.
>>>>>>>
>>>>>>> While this needs fixing,      
>>>>>>
>>>>>> Filed here: https://sourceware.org/bugzilla/show_bug.cgi?id=28527 .
>>>>>>
>>>>>> Submitted patch here:
>>>>>> https://sourceware.org/pipermail/gdb-patches/2021-November/183016.html .
>>>>>>
>>>>>> Thanks,
>>>>>> - Tom
>>>>>>    
>>>>>>> we don't want to be testing this behaviour in this
>>>>>>> test-case.    
>>>>>
>>>>> Since you've fixed the problem in skip_prologue(), I'd prefer that this
>>>>> testsuite patch not go in.    
>>>>
>>>> One possible objection would be that otherwise we no longer excercise
>>>> the problem, so here's a test-case for that.
>>>>
>>>> Any comments?  
>>>
>>> I've been trying (and failing) to reproduce this by hand on Fedora 35
>>> ppc64le.   Here's what I'm doing...
>>>
>>> [kev@f35-ppc64le-1 tmp]$ tail -9 break-on-_exit.c 
>>> #include <unistd.h>
>>>
>>> int
>>> main (void)
>>> {
>>>   _exit (0);
>>>
>>>   return 0;
>>> }
>>> [kev@f35-ppc64le-1 tmp]$ gcc -o break-on-_exit break-on-_exit.c
>>> [kev@f35-ppc64le-1 tmp]$ gdb --readnever break-on-_exit 
>>> GNU gdb (GDB) Fedora 11.1-2.fc35
>>> Copyright (C) 2021 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 "ppc64le-redhat-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 break-on-_exit...
>>> (No debugging symbols found in break-on-_exit)
>>> (gdb) start
>>> Temporary breakpoint 1 at 0x10000708
>>> Starting program: /mesquite2/tmp/break-on-_exit 
>>> [Thread debugging using libthread_db enabled]
>>> Using host libthread_db library "/lib64/libthread_db.so.1".
>>>
>>> Temporary breakpoint 1, 0x0000000010000708 in main ()
>>> (gdb) b _exit
>>> Breakpoint 2 at 0x7ffff7decc1c (2 locations)
>>> (gdb) info breakpoints
>>> Num     Type           Disp Enb Address            What
>>> 2       breakpoint     keep y   <MULTIPLE>         
>>> 2.1                         y   0x00007ffff7decc1c <_exit+60>
>>> 2.2                         y   0x00007ffff7fc9970 <_exit+64>
>>> (gdb) info shared
>>> From                To                  Syms Read   Shared Object Library
>>> 0x00007ffff7f91080  0x00007ffff7fcc224  Yes (*)     /lib64/ld64.so.2
>>> 0x00007ffff7d00a80  0x00007ffff7eaebbc  Yes (*)     /lib64/libc.so.6
>>> (*): Shared library is missing debugging information.
>>> (gdb) c
>>> Continuing.
>>>
>>> Breakpoint 2, 0x00007ffff7decc1c in _exit () from /lib64/libc.so.6
>>> (gdb) x/20i _exit
>>>    0x7ffff7decbe0 <_exit>:	addis   r2,r12,21
>>>    0x7ffff7decbe4 <_exit+4>:	addi    r2,r2,-23776
>>>    0x7ffff7decbe8 <_exit+8>:	mflr    r0
>>>    0x7ffff7decbec <_exit+12>:	nop
>>>    0x7ffff7decbf0 <_exit+16>:	std     r29,-24(r1)
>>>    0x7ffff7decbf4 <_exit+20>:	std     r31,-8(r1)
>>>    0x7ffff7decbf8 <_exit+24>:	ld      r9,-29160(r2)
>>>    0x7ffff7decbfc <_exit+28>:	mr      r31,r3
>>>    0x7ffff7decc00 <_exit+32>:	std     r30,-16(r1)
>>>    0x7ffff7decc04 <_exit+36>:	add     r29,r9,r13
>>>    0x7ffff7decc08 <_exit+40>:	ld      r9,-28776(r13)
>>>    0x7ffff7decc0c <_exit+44>:	li      r30,-4096
>>>    0x7ffff7decc10 <_exit+48>:	mr      r3,r31
>>>    0x7ffff7decc14 <_exit+52>:	andis.  r9,r9,16
>>>    0x7ffff7decc18 <_exit+56>:	std     r0,16(r1)  
>>> => 0x7ffff7decc1c <_exit+60>:	li      r0,234  
>>>    0x7ffff7decc20 <_exit+64>:	beq     0x7ffff7decc74 <_exit+148>
>>>    0x7ffff7decc24 <_exit+68>:	nop
>>>    0x7ffff7decc28 <_exit+72>:	nop
>>>    0x7ffff7decc2c <_exit+76>:	ori     r2,r2,0
>>> (gdb) 
>>>   
>>
>> Hi Kevin, thanks for looking into this.
>>
>>> I'm guessing that _exit looks different in your environment?  
>>
>> Indeed, as show in the log message of commit
>> a50bdb99afe3ce2374407cbe7ddc625c1a0b74f7:
>> ...
>>     Dump of assembler code for function _exit:
>>        0x00007ffff7e42ea0 <+0>:     12 00 4c 3c     addis   r2,r12,18
>>        0x00007ffff7e42ea4 <+4>:     60 43 42 38     addi    r2,r2,17248
>>        0x00007ffff7e42ea8 <+8>:     00 00 00 60     nop
>>        0x00007ffff7e42eac <+12>:    f8 ff e1 fb     std     r31,-8(r1)
>>        0x00007ffff7e42eb0 <+16>:    78 1b 7f 7c     mr      r31,r3
>>        0x00007ffff7e42eb4 <+20>:    f0 ff c1 fb     std     r30,-16(r1)
>>        0x00007ffff7e42eb8 <+24>:    ea 00 00 38     li      r0,234
>>        0x00007ffff7e42ebc <+28>:    a0 8b 22 e9     ld      r9,-29792(r2)
>>        0x00007ffff7e42ec0 <+32>:    78 fb e3 7f     mr      r3,r31
>>        0x00007ffff7e42ec4 <+36>:    14 6a c9 7f     add     r30,r9,r13
>>        0x00007ffff7e42ec8 <+40>:    02 00 00 44     sc
>>        0x00007ffff7e42ecc <+44>:    26 00 00 7c     mfcr    r0
>>        0x00007ffff7e42ed0 <+48>:    00 10 09 74     andis.  r9,r0,4096
>> ...
>>
>> That's is why I put the test-case in the gdb.opt dir: it will excercise
>> the code provided by glibc, which tends to be optimized, and different
>> across os instances.
>>
>> The fact that it's not necessarily reproducible across os instances is
>> not great, but OTOH it means that we do exercise real life code (much
>> like the original test-case setting a breakpoint on _exit does, but in a
>> more minimal way).
> 
> Thanks for the clarifications.
> 
> I think your new test is okay

Committed with some of those clarifications, as below.

Thanks for the review,
- Tom


[-- Attachment #2: 0001-gdb-testsuite-Add-gdb.opt-break-on-_exit.exp.patch --]
[-- Type: text/x-patch, Size: 4919 bytes --]

[gdb/testsuite] Add gdb.opt/break-on-_exit.exp

Add a test-case to excercise the problem scenario reported in PR28527 and
fixed in commit a50bdb99afe "[gdb/tdep, rs6000] Don't skip system call in
skip_prologue":
- set a breakpoint on _exit, and
- verify that it triggers.

Note that this is not a regression test for that commit.  Since the actual
code in _exit may vary across os instances, we cannot guarantee that the
problem will always trigger with this test-case.

Rather, this test-case is a version of the original test-case
(gdb.threads/process-dies-while-detaching.exp) that is minimal while still
reproducing the problem reported in PR28527, in that same setting.

The benefit of this test-case is that it exercise real-life code and may
expose similar problems in other settings.  Also, it provides a much easier
test-case to investigate in case a similar problem occurs.

Tested on x86_64-linux and ppc64le-linux.

---
 gdb/testsuite/gdb.opt/break-on-_exit.c   | 26 +++++++++++++
 gdb/testsuite/gdb.opt/break-on-_exit.exp | 66 ++++++++++++++++++++++++++++++++
 2 files changed, 92 insertions(+)

diff --git a/gdb/testsuite/gdb.opt/break-on-_exit.c b/gdb/testsuite/gdb.opt/break-on-_exit.c
new file mode 100644
index 00000000000..d8da66193a8
--- /dev/null
+++ b/gdb/testsuite/gdb.opt/break-on-_exit.c
@@ -0,0 +1,26 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2021 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 <unistd.h>
+
+int
+main (void)
+{
+  _exit (0);
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.opt/break-on-_exit.exp b/gdb/testsuite/gdb.opt/break-on-_exit.exp
new file mode 100644
index 00000000000..38476412862
--- /dev/null
+++ b/gdb/testsuite/gdb.opt/break-on-_exit.exp
@@ -0,0 +1,66 @@
+# Copyright 2021 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/>.  */
+
+# Set a breakpoint on libc's _exit, and verify that it triggers.  The function
+# tends to do a syscall immediately after the prologue, and if the breakpoint is
+# set past the syscall due to faulty prologue skipping, the breakpoint will not
+# trigger.
+#
+# In particular, we're trying to excercise the instruction analysis
+# functionality of prologue skipping.  If the non-minimal symbols are
+# read for libc, then that functionality might not be used because f.i.
+# line-info is used instead.  Also, if the minimal symbols are not read
+# for libc, then the breakpoint is set on the exec-local _exit@plt instead,
+# and that functionality will also not be used.
+#
+# We may get the required setup in case of a libc with misssing separate
+# debuginfo, but we want the same effect if that debuginfo is installed.
+#
+# So, we use -readnever to read minimal symbols, but not non-miminal symbols.
+#
+# Because the code at _exit may be and usually is optimized, the test is in
+# the gdb.opt directory.
+
+standard_testfile
+
+# See if we have target board readnow.exp or similar.
+if { [lsearch -exact $GDBFLAGS -readnow] != -1 \
+	 || [lsearch -exact $GDBFLAGS --readnow] != -1 } {
+    untested "--readnever not allowed in combination with --readnow"
+    return -1
+}
+
+save_vars { GDBFLAGS } {
+    append GDBFLAGS " -readnever"
+
+    if {[prepare_for_testing "failed to prepare" $testfile $srcfile nodebug]} {
+	return -1
+    }
+}
+
+if ![runto_main] then {
+    return 0
+}
+
+gdb_breakpoint "_exit"
+
+# Give some background information about the breakpoint(s) and corresponding
+# the shared lib(s).
+gdb_test "info breakpoints"
+gdb_test "info shared"
+
+# If the skip_prologue analysis of _exit is too eager, we may not hit the
+# breakpoint.
+gdb_continue_to_breakpoint "_exit" "_exit \\(\\) .*"

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

* Re: [PATCH][gdb/testsuite] Add gdb.arch/ppc64-break-on-_exit.exp
  2021-11-10 10:57             ` [PATCH][gdb/testsuite] Add gdb.arch/ppc64-break-on-_exit.exp Tom de Vries
@ 2021-11-10 23:50               ` Kevin Buettner
  2021-11-11  9:51                 ` Tom de Vries
  0 siblings, 1 reply; 11+ messages in thread
From: Kevin Buettner @ 2021-11-10 23:50 UTC (permalink / raw)
  To: Tom de Vries; +Cc: gdb-patches

On Wed, 10 Nov 2021 11:57:27 +0100
Tom de Vries <tdevries@suse.de> wrote:

> > I think your new test is okay, though (of course) it would have been
> > nice to have a test which doesn't depend on particular OS instances.  
> 
> Well, how about this one?  Does it reproduce for you, also in source
> file mode ("if { 1 }" -> "if { 0 }" in the case-case) ?

I tried it both ways, using C source, and also using assembler on
two different versions of ppc64le Fedora, Fedora 35 and Fedora 32.

Testing showed one pass for each of the runs when using builds against
recent upstream sources (w/ your fix).  When tested against the
installed GDB (which does not have your recent ppc related fix), the
tests correctly showed 1 failure per run.

I like this test better!

Kevin


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

* Re: [PATCH][gdb/testsuite] Add gdb.arch/ppc64-break-on-_exit.exp
  2021-11-10 23:50               ` Kevin Buettner
@ 2021-11-11  9:51                 ` Tom de Vries
  0 siblings, 0 replies; 11+ messages in thread
From: Tom de Vries @ 2021-11-11  9:51 UTC (permalink / raw)
  To: Kevin Buettner; +Cc: gdb-patches

On 11/11/21 12:50 AM, Kevin Buettner wrote:
> On Wed, 10 Nov 2021 11:57:27 +0100
> Tom de Vries <tdevries@suse.de> wrote:
> 
>>> I think your new test is okay, though (of course) it would have been
>>> nice to have a test which doesn't depend on particular OS instances.  
>>
>> Well, how about this one?  Does it reproduce for you, also in source
>> file mode ("if { 1 }" -> "if { 0 }" in the case-case) ?
> 
> I tried it both ways, using C source, and also using assembler on
> two different versions of ppc64le Fedora, Fedora 35 and Fedora 32.
> 
> Testing showed one pass for each of the runs when using builds against
> recent upstream sources (w/ your fix).  When tested against the
> installed GDB (which does not have your recent ppc related fix), the
> tests correctly showed 1 failure per run.
> 
> I like this test better!

Nice :)

Thanks for the testing.

I also managed to find the usual recipe for switching between assembler
and compiled version: "if [info exists COMPILE] ".  I've updated the
patch accordingly, and committed.

Thanks
- Tom


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

end of thread, other threads:[~2021-11-11  9:51 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-29 19:24 [PATCH][gdb/testsuite] Work around skip_prologue problems in gdb.threads/process-dies-while-detaching.exp Tom de Vries
2021-11-02 11:38 ` Tom de Vries
2021-11-02 17:13   ` Kevin Buettner
2021-11-04 11:20     ` [PATCH][gdb/testsuite] Add gdb.opt/break-on-_exit.exp Tom de Vries
2021-11-09 16:35       ` Kevin Buettner
2021-11-09 16:58         ` Tom de Vries
2021-11-09 17:29           ` Kevin Buettner
2021-11-10 10:57             ` [PATCH][gdb/testsuite] Add gdb.arch/ppc64-break-on-_exit.exp Tom de Vries
2021-11-10 23:50               ` Kevin Buettner
2021-11-11  9:51                 ` Tom de Vries
2021-11-10 11:56             ` [PATCH][gdb/testsuite] Add gdb.opt/break-on-_exit.exp 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).