public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: Kevin Buettner <kevinb@redhat.com>,
	Tom de Vries via Gdb-patches <gdb-patches@sourceware.org>
Subject: [PATCH][gdb/testsuite] Add gdb.opt/break-on-_exit.exp
Date: Thu, 4 Nov 2021 12:20:14 +0100	[thread overview]
Message-ID: <33a30d8d-247e-fba8-c9f1-b8ff0bd001b2@suse.de> (raw)
In-Reply-To: <20211102101329.565a324b@f35-m1>

[-- 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 \\(\\) .*"

  reply	other threads:[~2021-11-04 11:20 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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     ` Tom de Vries [this message]
2021-11-09 16:35       ` [PATCH][gdb/testsuite] Add gdb.opt/break-on-_exit.exp 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=33a30d8d-247e-fba8-c9f1-b8ff0bd001b2@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    --cc=kevinb@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).