[5/6] sim: callback: convert time interface to 64-bit

Message ID 20210424184144.23736-5-vapier@gentoo.org
State New
Headers show
Series
  • [1/6] gdb: callback: always include necessary headers
Related show

Commit Message

Mike Frysinger via Gdb-patches April 24, 2021, 6:41 p.m.
Rather than rely on time_t being the right size between the host &
target, have the interface always be 64-bit.  We can figure out if
we need to truncate when actually outputting it to the right target.
---
 include/gdb/callback.h |  3 ++-
 sim/common/callback.c  | 11 +++++++----
 2 files changed, 9 insertions(+), 5 deletions(-)

-- 
2.30.2

Comments

Tom Tromey April 24, 2021, 9:11 p.m. | #1
>>>>> "Mike" == Mike Frysinger via Gdb-patches <gdb-patches@sourceware.org> writes:


Mike> Rather than rely on time_t being the right size between the host &
Mike> target, have the interface always be 64-bit.  We can figure out if
Mike> we need to truncate when actually outputting it to the right target.

Mike> -  long (*time) (host_callback *, long *);
Mike> +  int64_t (*time) (host_callback *, int64_t *);

It is possible to remove the 'int64_t *' parameter here?
The Linux time(2) man page says:

       The tloc argument is obsolescent and should always be NULL in new code.
       When tloc is NULL, the call cannot fail.

And, it does seem redundant.

Tom
Mike Frysinger via Gdb-patches April 24, 2021, 10:36 p.m. | #2
On 24 Apr 2021 15:11, Tom Tromey wrote:
> >>>>> "Mike" == Mike Frysinger via Gdb-patches <gdb-patches@sourceware.org> writes:

> 

> Mike> Rather than rely on time_t being the right size between the host &

> Mike> target, have the interface always be 64-bit.  We can figure out if

> Mike> we need to truncate when actually outputting it to the right target.

> 

> Mike> -  long (*time) (host_callback *, long *);

> Mike> +  int64_t (*time) (host_callback *, int64_t *);

> 

> It is possible to remove the 'int64_t *' parameter here?

> The Linux time(2) man page says:

> 

>        The tloc argument is obsolescent and should always be NULL in new code.

>        When tloc is NULL, the call cannot fail.

> 

> And, it does seem redundant.


sure, if we're going to change the API, might as well only do it once.
it'll simplify the body too.
-mike

Patch

diff --git a/include/gdb/callback.h b/include/gdb/callback.h
index 11a941259f64..f86fe7e4c548 100644
--- a/include/gdb/callback.h
+++ b/include/gdb/callback.h
@@ -47,6 +47,7 @@ 
 
 #include <ansidecl.h>
 #include <stdarg.h>
+#include <stdint.h>
 /* Needed for enum bfd_endian.  */
 #include "bfd.h"
 
@@ -78,7 +79,7 @@  struct host_callback_struct
   int (*read_stdin) ( host_callback *, char *, int);
   int (*rename) (host_callback *, const char *, const char *);
   int (*system) (host_callback *, const char *);
-  long (*time) (host_callback *, long *);
+  int64_t (*time) (host_callback *, int64_t *);
   int (*unlink) (host_callback *, const char *);
   int (*write) (host_callback *,int, const char *, int);
   int (*write_stdout) (host_callback *, const char *, int);
diff --git a/sim/common/callback.c b/sim/common/callback.c
index 2b27226f0060..da8ea3e2f10c 100644
--- a/sim/common/callback.c
+++ b/sim/common/callback.c
@@ -420,12 +420,15 @@  os_system (host_callback *p, const char *s)
   return result;
 }
 
-static long
-os_time (host_callback *p, long *t)
+static int64_t
+os_time (host_callback *p, int64_t *t64)
 {
-  long result;
+  int64_t result;
+  time_t t;
 
-  result = time (t);
+  result = time (&t);
+  if (t64)
+    *t64 = t;
   p->last_errno = errno;
   return result;
 }