qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paul Brook <paul@codesourcery.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH,APPLIED] GDB exit status for semihosting
Date: Wed, 16 Jun 2010 13:10:01 +0100	[thread overview]
Message-ID: <201006161310.02211.paul@codesourcery.com> (raw)

Report exit status to GDB when a semihosted application exits.

Signed-off-by: Paul Brook <paul@codesourcery.com>
---
 arm-semi.c  |    1 +
 gdbstub.c   |   34 ++++++++++++++++++++--------------
 gdbstub.h   |    2 +-
 m68k-semi.c |    1 +
 4 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/arm-semi.c b/arm-semi.c
index 5239ffc..0687b03 100644
--- a/arm-semi.c
+++ b/arm-semi.c
@@ -459,6 +459,7 @@ uint32_t do_arm_semihosting(CPUState *env)
             return 0;
         }
     case SYS_EXIT:
+        gdb_exit(env, 0);
         exit(0);
     default:
         fprintf(stderr, "qemu: Unsupported SemiHosting SWI 0x%02x\n", nr);
diff --git a/gdbstub.c b/gdbstub.c
index 474ed8a..c1852c2 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -2373,6 +2373,26 @@ static void gdb_read_byte(GDBState *s, int ch)
     }
 }
 
+/* Tell the remote gdb that the process has exited.  */
+void gdb_exit(CPUState *env, int code)
+{
+  GDBState *s;
+  char buf[4];
+
+  s = gdbserver_state;
+  if (!s) {
+      return;
+  }
+#ifdef CONFIG_USER_ONLY
+  if (gdbserver_fd < 0 || s->fd < 0) {
+      return;
+  }
+#endif
+
+  snprintf(buf, sizeof(buf), "W%02x", (uint8_t)code);
+  put_packet(s, buf);
+}
+
 #ifdef CONFIG_USER_ONLY
 int
 gdb_queuesig (void)
@@ -2436,20 +2456,6 @@ gdb_handlesig (CPUState *env, int sig)
   return sig;
 }
 
-/* Tell the remote gdb that the process has exited.  */
-void gdb_exit(CPUState *env, int code)
-{
-  GDBState *s;
-  char buf[4];
-
-  s = gdbserver_state;
-  if (gdbserver_fd < 0 || s->fd < 0)
-    return;
-
-  snprintf(buf, sizeof(buf), "W%02x", code);
-  put_packet(s, buf);
-}
-
 /* Tell the remote gdb that the process has exited due to SIG.  */
 void gdb_signalled(CPUState *env, int sig)
 {
diff --git a/gdbstub.h b/gdbstub.h
index 54d753c..219abda 100644
--- a/gdbstub.h
+++ b/gdbstub.h
@@ -17,10 +17,10 @@ typedef void (*gdb_syscall_complete_cb)(CPUState *env,
 void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...);
 int use_gdb_syscalls(void);
 void gdb_set_stop_cpu(CPUState *env);
+void gdb_exit(CPUState *, int);
 #ifdef CONFIG_USER_ONLY
 int gdb_queuesig (void);
 int gdb_handlesig (CPUState *, int);
-void gdb_exit(CPUState *, int);
 void gdb_signalled(CPUState *, int);
 void gdbserver_fork(CPUState *);
 #endif
diff --git a/m68k-semi.c b/m68k-semi.c
index 48e3bd3..d16bc67 100644
--- a/m68k-semi.c
+++ b/m68k-semi.c
@@ -172,6 +172,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr)
     args = env->dregs[1];
     switch (nr) {
     case HOSTED_EXIT:
+        gdb_exit(env, env->dregs[0]);
         exit(env->dregs[0]);
     case HOSTED_OPEN:
         if (use_gdb_syscalls()) {
-- 
1.7.1

                 reply	other threads:[~2010-06-16 12:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=201006161310.02211.paul@codesourcery.com \
    --to=paul@codesourcery.com \
    --cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).