From patchwork Wed Jun 16 12:10:01 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Brook X-Patchwork-Id: 55874 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4EDE31007D2 for ; Wed, 16 Jun 2010 22:12:58 +1000 (EST) Received: from localhost ([127.0.0.1]:33469 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OOrUF-00020y-Eq for incoming@patchwork.ozlabs.org; Wed, 16 Jun 2010 08:12:55 -0400 Received: from [140.186.70.92] (port=46326 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OOrRb-0008Pr-K7 for qemu-devel@nongnu.org; Wed, 16 Jun 2010 08:10:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OOrRa-0001R0-0R for qemu-devel@nongnu.org; Wed, 16 Jun 2010 08:10:11 -0400 Received: from mail.codesourcery.com ([38.113.113.100]:60254) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OOrRZ-0001Qn-OJ for qemu-devel@nongnu.org; Wed, 16 Jun 2010 08:10:09 -0400 Received: (qmail 8226 invoked from network); 16 Jun 2010 12:10:07 -0000 Received: from unknown (HELO wren.localnet) (paul@127.0.0.2) by mail.codesourcery.com with ESMTPA; 16 Jun 2010 12:10:07 -0000 To: qemu-devel@nongnu.org From: Paul Brook Organization: CodeSourcery Date: Wed, 16 Jun 2010 13:10:01 +0100 MIME-Version: 1.0 Message-Id: <201006161310.02211.paul@codesourcery.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Subject: [Qemu-devel] [PATCH,APPLIED] GDB exit status for semihosting X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Report exit status to GDB when a semihosted application exits. Signed-off-by: Paul Brook --- 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()) {