public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Mike Frysinger <vapier@gentoo.org>
To: Nicholas Clifton <nickc@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: RFA: AArch64 sim
Date: Tue, 10 Nov 2015 07:32:00 -0000	[thread overview]
Message-ID: <20151110073245.GN5154@vapier.lan> (raw)
In-Reply-To: <55A90CBA.40007@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 5606 bytes --]

On 17 Jul 2015 15:10, Nicholas Clifton wrote:
> >> +++ include/gdb/sim-aarch64.h
> 
> >> +#ifdef __cplusplus
> >> +extern "C" { // }
> >> +#endif
> >
> > hmm, i see a few arches do this, but most don't.  is there any reason we should
> > keep this ?  or should we scrub all targets to not do this ?
> 
> It is your call.  I saw that other header files in this directory were 
> doing it, so I thought that it would be wise to follow their example. 
> The extra code does not hurt when compiling with C and I presume that it 
> is necessary when compiling with C++.  (I do not know this for sure 
> though - I hate C++).  I am happy to remove the code if you want however.

i've posted a patch to clean up the others.  you should trim it from this
one in the meantime.

> >> +typedef enum
> >> +{
> >> +  STATUS_READY   = 0, /* May continue stepping or running.  */
> >> +  STATUS_RETURN  = 1, /* Via normal return from initial frame.  */
> >> +  STATUS_HALT    = 2, /* Via HALT pseudo-instruction.  */
> >> +  STATUS_BREAK   = 3, /* Via BRK instruction.  */
> >> +  STATUS_CALLOUT = 4, /* Via CALLOUT pseudo-instruction.  */
> >> +  STATUS_ERROR   = 5, /* Simulator detected problem.  */
> >> +  STATUS_MAX     = 6
> >> +} StatusCode;
> >
> > a scan of the code indicates that most of this looks like you're setting state
> > and then acting on it later yourself when you really should be calling
> > sim_engine_halt directly.  any reason for doing it this way ?
> 
> Originally it was simply historical - this is the way the code was 
> written in the smallaarch64sim.  Now it is because it allows better 
> tracing and disassembler output, and cleaner code - the halt and error 
> returns are only handled in one place.

i'm not seeing how this is cleaner.  when you call sim_engine_halt, the
code stops at that point.  there is no returning/etc... afterwards.

plus, when i look at some of these funcs, they only ever return READY.
which leads to a lot of return code paths that are pointless.

+#define STORE_FUNC(TYPE, NAME, N)                                      \
+  StatusCode                                                           \
+  aarch64_set_mem_##NAME (sim_cpu *cpu, uint64_t address, TYPE value)  \
+  {                                                                    \
+    TRACE_MEMORY (cpu,                                                 \
+                 "write of %" PRIx64 " (%d bytes) to %" PRIx64,        \
+                 (uint64_t) value, N, address);                        \
+                                                                       \
+    sim_core_write_unaligned_##N (cpu, 0, write_map, address, value);  \
+    return STATUS_READY;                                               \
+  }
...
+static StatusCode
+stur32 (sim_cpu *cpu, int32_t offset)
+{
+  unsigned rn = uimm (cpu->instr, 9, 5);
+  unsigned rd = uimm (cpu->instr, 4, 0);
+
+  return aarch64_set_mem_u32 (cpu,
+                             aarch64_get_reg_u64 (cpu, rn, SP_OK) + offset,
+                             aarch64_get_reg_u32 (cpu, rd, NO_SP));
+}
...
+static StatusCode
+dexLoadUnscaledImmediate (sim_cpu *cpu)
... i scanned a bunch of these and they look like above ...
+       case 0:  return sturb (cpu, imm);
+       case 1:  return ldurb32 (cpu, imm);
+       case 2:  return ldursb64 (cpu, imm);
+       case 3:  return ldursb32 (cpu, imm);
+       case 4:  return sturh (cpu, imm);
+       case 5:  return ldurh32 (cpu, imm);
+       case 6:  return ldursh64 (cpu, imm);
+       case 7:  return ldursh32 (cpu, imm);
+       case 8:  return stur32 (cpu, imm);
+       case 9:  return ldur32 (cpu, imm);
+       case 10: return ldursw (cpu, imm);
+       case 12: return stur64 (cpu, imm);
+       case 13: return ldur64 (cpu, imm);
...

in this func, the only thing that doesn't return READY are:
+         return_NYI;
+         return_UNALLOC;

which look like:
+#define return_UNALLOC                                                 \
+  do                                                                   \
+    {                                                                  \
+      if (TRACE_INSN_P (cpu))                                          \
+       {                                                               \
+         aarch64_print_insn (CPU_STATE (cpu), aarch64_get_PC (cpu));   \
+         TRACE_INSN (cpu,                                              \
+                     "Unallocated instruction detected at sim line %d,"\
+                     " exe addr %" PRIx64,                             \
+                     __LINE__, aarch64_get_PC (cpu));                  \
+       }                                                               \
+      cpu->errorCode = ERROR_UNALLOC;                                  \
+      return STATUS_ERROR;                                             \
+    }                                                                  \
+  while (1)

so instead of returning, just call sim_engine_halt directly

in fact, i only see the errorCode field being set.  nowhere is it being
read.  you might think "wait but there's aarch64_get_ErrorCode and 
aarch64_get_error_text" ... except nothing calls those functions.

so i can't see how errorCode adds any value, just noise, nor does it have
any impact on debugging/tracing output.

> Is this version OK to apply ?

you should scan the files and trim trailing whitespace while you're at it.
sed -i -r 's:[[:space:]]+$::' *.[ch]
-mike

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  reply	other threads:[~2015-11-10  7:32 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-28 12:25 Nick Clifton
2015-07-02  9:17 ` Andre Vieira
2015-07-02 13:53   ` Nicholas Clifton
2015-07-02 14:43     ` Andre Vieira
     [not found]     ` <55954DEE.50609@arm.com>
2015-07-02 15:20       ` Nicholas Clifton
2015-07-07 17:12 ` Mike Frysinger
2015-07-15 16:58 ` Nick Clifton
2015-07-16 15:19   ` Mike Frysinger
2015-07-17 14:10     ` Nicholas Clifton
2015-11-10  7:32       ` Mike Frysinger [this message]
2015-11-19 14:51         ` Nick Clifton
2015-11-20  9:13           ` Mike Frysinger
2015-11-20 10:56             ` Nick Clifton
2015-11-20 19:28               ` Mike Frysinger
2015-11-24  8:50                 ` Nick Clifton

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=20151110073245.GN5154@vapier.lan \
    --to=vapier@gentoo.org \
    --cc=gdb-patches@sourceware.org \
    --cc=nickc@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).