Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Kevin Buettner <kevinb@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH] PPC sim: Don't close file descriptors 0, 1, or 2
Date: Mon, 16 Nov 2015 21:58:00 -0000	[thread overview]
Message-ID: <20151116145807.4aedd84f@pinnacle.lan> (raw)

In my testing, this patch eliminates all of the "unresolved testcases"
when testing GDB against the powerpc simulator.

E.g. for gdb.base.exp, I see this in the log file:

    (gdb) next
    66	    return (value); /* set breakpoint 19 here */
    (gdb) PASS: gdb.base/break.exp: next over recursive call
    backtrace
    #0  factorial (value=120) at testsuite/gdb.base/break.c:66
    #1  0x10000428 in factorial (value=6) at testsuite/gdb.base/break.c:64
    #2  0x10000370 in main (argc=1, argv=0xdfffee20, envp=0xdfffee28) at testsuite/gdb.base/break.c:47
    (gdb) PASS: gdb.base/break.exp: backtrace from factorial(5.1)
    continue
    Continuing.
    720
    ERROR: Process no longer exists
    UNRESOLVED: gdb.base/break.exp: continue until exit at recursive next test

With this patch/change in place, this bit of the test runs as expected:

    (gdb) next
    66	    return (value); /* set breakpoint 19 here */
    (gdb) PASS: gdb.base/break.exp: next over recursive call
    backtrace
    #0  factorial (value=120) at testsuite/gdb.base/break.c:66
    #1  0x10000428 in factorial (value=6) at testsuite/gdb.base/break.c:64
    #2  0x10000370 in main (argc=1, argv=0xdfffee20, envp=0xdfffee28) at testsuite/gdb.base/break.c:47
    (gdb) PASS: gdb.base/break.exp: backtrace from factorial(5.1)
    continue
    Continuing.
    720
    [Inferior 1 (process 42000) exited normally]

This occurs because the powerpc simulator closes, on behalf of the
testcase, the file descriptors associated with stdin, stdout, and
stderr.  GDB still needs these descriptors to communicate with the
user or, in this case, with the testing framework.

sim/ppc/ChangeLog:
    
    	* emul_netbsd.c (do_close): Don't close file descriptors 0, 1,
    	or 2.
---
 sim/ppc/emul_netbsd.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/sim/ppc/emul_netbsd.c b/sim/ppc/emul_netbsd.c
index 6bef370..5e39975 100644
--- a/sim/ppc/emul_netbsd.c
+++ b/sim/ppc/emul_netbsd.c
@@ -440,8 +440,13 @@ do_close(os_emul_data *emul,
 
   SYS(close);
 
-  /* Can't combine these statements, cuz close sets errno. */
-  status = close(d);
+  /* Do not close stdin, stdout, or stderr. GDB may still need access to
+     these descriptors.  */
+  if (d == 0 || d == 1 || d == 2)
+    status = 0;
+  else
+    status = close(d);
+
   emul_write_status(processor, status, errno);
 }
 


             reply	other threads:[~2015-11-16 21:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-16 21:58 Kevin Buettner [this message]
2015-11-16 23:53 ` Mike Frysinger
2015-11-17  4:05   ` Kevin Buettner
2015-11-17  5:41     ` Mike Frysinger
2015-11-17 20:32       ` Kevin Buettner
2015-11-17 21:05         ` Mike Frysinger
2015-12-07 20:29           ` Kevin Buettner
2015-12-30  0:18             ` Mike Frysinger

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=20151116145807.4aedd84f@pinnacle.lan \
    --to=kevinb@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /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