qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] target-arm: return more meaningful exit status
@ 2014-04-07 21:42 Eric Botcazou
  2014-04-08  7:53 ` Peter Maydell
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Botcazou @ 2014-04-07 21:42 UTC (permalink / raw)
  To: qemu-devel

Hi,

this partially addresses a long-standing limitation of the ARM semi-hosting
mode, whereby the only exit status of the emulator is 0, whatever the exit
status of the target executable, by mapping arguments of the SYS_EXIT syscall.

See https://lists.gnu.org/archive/html/qemu-devel/2011-02/msg02178.html for
an earlier attempt.

It's only a partial solution because EXIT_SUCCESS will be returned in all
cases as before, except when the target execution is stopped with SIGABRT.
But that's sufficient to run the testsuite of the compiler for bare board
ARM, e.g. arm-none-eabi with newlib.

Signed-off-by: Eric Botcazou <ebotcazou@adacore.com>
---
 target-arm/arm-semi.c |   23 +++++++++++++++++++++--
 1 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/target-arm/arm-semi.c b/target-arm/arm-semi.c
index ebb5235..dd6c2d9 100644
--- a/target-arm/arm-semi.c
+++ b/target-arm/arm-semi.c
@@ -58,6 +58,9 @@
 #define TARGET_SYS_HEAPINFO    0x16
 #define TARGET_SYS_EXIT        0x18
 
+#define ADP_Stopped_ApplicationExit ((2 << 16) + 38)
+#define ADP_Stopped_RunTimeError    ((2 << 16) + 35)
+
 #ifndef O_BINARY
 #define O_BINARY 0
 #endif
@@ -551,8 +554,24 @@ uint32_t do_arm_semihosting(CPUARMState *env)
             return 0;
         }
     case TARGET_SYS_EXIT:
-        gdb_exit(env, 0);
-        exit(0);
+        {
+            int code;
+
+            switch (args) {
+            case ADP_Stopped_ApplicationExit:
+                 code = EXIT_SUCCESS;
+                 break;
+            case ADP_Stopped_RunTimeError:
+                 code = EXIT_FAILURE;
+                 break;
+            default:
+                 code = -EXIT_FAILURE;
+                 break;
+            }
+
+            gdb_exit(env, code);
+            exit(code);
+        }
     default:
         fprintf(stderr, "qemu: Unsupported SemiHosting SWI 0x%02x\n", nr);
         cpu_dump_state(cs, stderr, fprintf, 0);
-- 
1.7.7

-- 
Eric Botcazou

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

* Re: [Qemu-devel] [PATCH] target-arm: return more meaningful exit status
  2014-04-07 21:42 [Qemu-devel] [PATCH] target-arm: return more meaningful exit status Eric Botcazou
@ 2014-04-08  7:53 ` Peter Maydell
  2014-04-08  8:34   ` Eric Botcazou
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Maydell @ 2014-04-08  7:53 UTC (permalink / raw)
  To: Eric Botcazou; +Cc: QEMU Developers

On 7 April 2014 22:42, Eric Botcazou <ebotcazou@adacore.com> wrote:
> Hi,
>
> this partially addresses a long-standing limitation of the ARM semi-hosting
> mode, whereby the only exit status of the emulator is 0, whatever the exit
> status of the target executable, by mapping arguments of the SYS_EXIT syscall.
>
> See https://lists.gnu.org/archive/html/qemu-devel/2011-02/msg02178.html for
> an earlier attempt.

Since you've found that, can you provide your answer to the objection
raised back then, that this is not permitted by the semihosting API
which we are implementing here?

thanks
-- PMM

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

* Re: [Qemu-devel] [PATCH] target-arm: return more meaningful exit status
  2014-04-08  7:53 ` Peter Maydell
@ 2014-04-08  8:34   ` Eric Botcazou
  2014-04-08  9:38     ` Peter Maydell
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Botcazou @ 2014-04-08  8:34 UTC (permalink / raw)
  To: Peter Maydell; +Cc: QEMU Developers

> Since you've found that, can you provide your answer to the objection
> raised back then, that this is not permitted by the semihosting API
> which we are implementing here?

I don't understand the question: what is not permitted exactly?

-- 
Eric Botcazou

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

* Re: [Qemu-devel] [PATCH] target-arm: return more meaningful exit status
  2014-04-08  8:34   ` Eric Botcazou
@ 2014-04-08  9:38     ` Peter Maydell
  2014-04-08 10:00       ` Eric Botcazou
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Maydell @ 2014-04-08  9:38 UTC (permalink / raw)
  To: Eric Botcazou; +Cc: QEMU Developers

On 8 April 2014 09:34, Eric Botcazou <ebotcazou@adacore.com> wrote:
>> Since you've found that, can you provide your answer to the objection
>> raised back then, that this is not permitted by the semihosting API
>> which we are implementing here?
>
> I don't understand the question: what is not permitted exactly?

The reason we only exit with zero here is because the
semihosting API doesn't provide a way for the application
to report a non-zero exit code. In this case you're
distinguishing "application exit" from the other
failure reasons, which seems OK, though. I'm just
wary of patches trying to fix this issue because
in the past they've generally ignored the fact that
we're implementing a fixed API here and can't make
random additions to it just because they happen to work
with newlib or whatever.

Returning a negative exit code is bogus, though. You
probably just want
   if (args == ADP_Stopped_ApplicationExit) {
       code = EXIT_SUCCESS;
   } else {
       code = EXIT_FAILURE;
   }

thanks
-- PMM

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

* Re: [Qemu-devel] [PATCH] target-arm: return more meaningful exit status
  2014-04-08  9:38     ` Peter Maydell
@ 2014-04-08 10:00       ` Eric Botcazou
  0 siblings, 0 replies; 5+ messages in thread
From: Eric Botcazou @ 2014-04-08 10:00 UTC (permalink / raw)
  To: Peter Maydell; +Cc: QEMU Developers

> The reason we only exit with zero here is because the
> semihosting API doesn't provide a way for the application
> to report a non-zero exit code. In this case you're
> distinguishing "application exit" from the other
> failure reasons, which seems OK, though. I'm just
> wary of patches trying to fix this issue because
> in the past they've generally ignored the fact that
> we're implementing a fixed API here and can't make
> random additions to it just because they happen to work
> with newlib or whatever.

OK, I see.

> Returning a negative exit code is bogus, though. You
> probably just want
>    if (args == ADP_Stopped_ApplicationExit) {
>        code = EXIT_SUCCESS;
>    } else {
>        code = EXIT_FAILURE;
>    }

The idea was to distinguish the supported arguments from the unknown ones 
(newlib only uses the listed two) but that would also work for me.

-- 
Eric Botcazou

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

end of thread, other threads:[~2014-04-08 10:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-07 21:42 [Qemu-devel] [PATCH] target-arm: return more meaningful exit status Eric Botcazou
2014-04-08  7:53 ` Peter Maydell
2014-04-08  8:34   ` Eric Botcazou
2014-04-08  9:38     ` Peter Maydell
2014-04-08 10:00       ` Eric Botcazou

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).