Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Mark Mitchell <mark@codesourcery.com>
To: gdb-patches@gcc.gnu.org
Subject: PATCH: Introduce gdb_gettimeofday
Date: Tue, 08 Mar 2005 23:29:00 -0000	[thread overview]
Message-ID: <200503082329.j28NTaN1029372@sethra.codesourcery.com> (raw)


Some systems (Windows) don't have gettimeofday.  This patch introduces
a new utility function gdb_gettimeofday; on UNIX systems this is just
a wrapper for gettimeofday, while on other systems it relies on
fallback methods.  (In particular, on Windows, we use "time", at least
for now.)

Tested by building on both Windows (with other patches not yet
submitted) and on x86_64-uknown-linux-gnu, and by running the
testsuite on the latter platform with no regressions.  I'll check for
copyrights before submission, if this is approved. 

OK?

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2005-03-08  Mark Mitchell  <mark@codesourcery.com>

	* config.in (HAVE_GETTIMEOFDAY): #undef it.
	* configure.ac (gettimeofday): Call AC_CHECK_FUNCS for it.
	* configure: Regenerated.
	* defs.h (gdb_gettimeofday): Declare.
	* event-loop.c (create_timer): Use it, instead of gettimeofday.
	(handle_timer_event): Likewise.
	(poll_timers): Likewise.
	* remote-fileio.c (remote_fileio_func_fstat): Likewise.
	(remote_fileio_func_gettimeofday): Likewise.
	* utils.c (<sys/time.h>): Include it.
	(gdb_gettimeofday): New function.
	* mi/mi-main.c (mi_load_progress): Use gdb_gettimeofday, instead
	of gettimeofday.
	
Index: config.in
===================================================================
RCS file: /cvs/src/src/gdb/config.in,v
retrieving revision 1.76
diff -c -5 -p -r1.76 config.in
*** config.in	21 Jan 2005 13:49:22 -0000	1.76
--- config.in	8 Mar 2005 23:20:48 -0000
***************
*** 251,260 ****
--- 251,263 ----
  #undef HAVE_GETPAGESIZE
  
  /* Define as 1 if you have gettext and don't want to use GNU gettext. */
  #undef HAVE_GETTEXT
  
+ /* Define to 1 if you have the `gettimeofday' function. */
+ #undef HAVE_GETTIMEOFDAY
+ 
  /* Define to 1 if you have the <gnu/libc-version.h> header file. */
  #undef HAVE_GNU_LIBC_VERSION_H
  
  /* Define if <sys/procfs.h> has gregset_t. */
  #undef HAVE_GREGSET_T
Index: configure.ac
===================================================================
RCS file: /cvs/src/src/gdb/configure.ac,v
retrieving revision 1.12
diff -c -5 -p -r1.12 configure.ac
*** configure.ac	22 Feb 2005 23:25:11 -0000	1.12
--- configure.ac	8 Mar 2005 23:20:49 -0000
*************** AC_CHECK_FUNCS(setpgid setpgrp)
*** 454,463 ****
--- 454,464 ----
  AC_CHECK_FUNCS(sigaction sigprocmask sigsetmask)
  AC_CHECK_FUNCS(socketpair)
  AC_CHECK_FUNCS(syscall)
  AC_CHECK_FUNCS(ttrace)
  AC_CHECK_FUNCS(wborder)
+ AC_CHECK_FUNCS(gettimeofday)
  
  # Check the return and argument types of ptrace.  No canned test for
  # this, so roll our own.
  gdb_ptrace_headers='
  #if HAVE_SYS_TYPES_H
Index: defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.181
diff -c -5 -p -r1.181 defs.h
*** defs.h	14 Feb 2005 14:37:37 -0000	1.181
--- defs.h	8 Mar 2005 23:20:49 -0000
*************** extern int use_windows;
*** 1206,1211 ****
--- 1206,1218 ----
     this incorrect coding style.  */
  
  extern ULONGEST align_up (ULONGEST v, int n);
  extern ULONGEST align_down (ULONGEST v, int n);
  
+ /* Forward declaration so that <sys/time.h> does not to be included
+    here.  */
+ struct timeval;
+ /* Like gettimeofday, but always returns the local time, and uses
+    whatever time functionality is available on the system.  */ 
+ extern int gdb_gettimeofday (struct timeval *tp);
+ 
  #endif /* #ifndef DEFS_H */
Index: event-loop.c
===================================================================
RCS file: /cvs/src/src/gdb/event-loop.c,v
retrieving revision 1.24
diff -c -5 -p -r1.24 event-loop.c
*** event-loop.c	12 Feb 2005 00:39:18 -0000	1.24
--- event-loop.c	8 Mar 2005 23:20:49 -0000
*************** create_timer (int milliseconds, timer_ha
*** 973,983 ****
    /* compute seconds */
    delta.tv_sec = milliseconds / 1000;
    /* compute microseconds */
    delta.tv_usec = (milliseconds % 1000) * 1000;
  
!   gettimeofday (&time_now, NULL);
  
    timer_ptr = (struct gdb_timer *) xmalloc (sizeof (gdb_timer));
    timer_ptr->when.tv_sec = time_now.tv_sec + delta.tv_sec;
    timer_ptr->when.tv_usec = time_now.tv_usec + delta.tv_usec;
    /* carry? */
--- 973,983 ----
    /* compute seconds */
    delta.tv_sec = milliseconds / 1000;
    /* compute microseconds */
    delta.tv_usec = (milliseconds % 1000) * 1000;
  
!   gdb_gettimeofday (&time_now);
  
    timer_ptr = (struct gdb_timer *) xmalloc (sizeof (gdb_timer));
    timer_ptr->when.tv_sec = time_now.tv_sec + delta.tv_sec;
    timer_ptr->when.tv_usec = time_now.tv_usec + delta.tv_usec;
    /* carry? */
*************** static void
*** 1069,1079 ****
  handle_timer_event (int dummy)
  {
    struct timeval time_now;
    struct gdb_timer *timer_ptr, *saved_timer;
  
!   gettimeofday (&time_now, NULL);
    timer_ptr = timer_list.first_timer;
  
    while (timer_ptr != NULL)
      {
        if ((timer_ptr->when.tv_sec > time_now.tv_sec) ||
--- 1069,1079 ----
  handle_timer_event (int dummy)
  {
    struct timeval time_now;
    struct gdb_timer *timer_ptr, *saved_timer;
  
!   gdb_gettimeofday (&time_now);
    timer_ptr = timer_list.first_timer;
  
    while (timer_ptr != NULL)
      {
        if ((timer_ptr->when.tv_sec > time_now.tv_sec) ||
*************** poll_timers (void)
*** 1105,1115 ****
    struct timeval time_now, delta;
    gdb_event *event_ptr;
  
    if (timer_list.first_timer != NULL)
      {
!       gettimeofday (&time_now, NULL);
        delta.tv_sec = timer_list.first_timer->when.tv_sec - time_now.tv_sec;
        delta.tv_usec = timer_list.first_timer->when.tv_usec - time_now.tv_usec;
        /* borrow? */
        if (delta.tv_usec < 0)
  	{
--- 1105,1115 ----
    struct timeval time_now, delta;
    gdb_event *event_ptr;
  
    if (timer_list.first_timer != NULL)
      {
!       gdb_gettimeofday (&time_now);
        delta.tv_sec = timer_list.first_timer->when.tv_sec - time_now.tv_sec;
        delta.tv_usec = timer_list.first_timer->when.tv_usec - time_now.tv_usec;
        /* borrow? */
        if (delta.tv_usec < 0)
  	{
Index: remote-fileio.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-fileio.c,v
retrieving revision 1.12
diff -c -5 -p -r1.12 remote-fileio.c
*** remote-fileio.c	14 Feb 2005 18:10:10 -0000	1.12
--- remote-fileio.c	8 Mar 2005 23:20:49 -0000
*************** remote_fileio_func_fstat (char *buf)
*** 1136,1146 ****
        st.st_size = 0;
        st.st_blksize = 512;
  #if HAVE_STRUCT_STAT_ST_BLOCKS
        st.st_blocks = 0;
  #endif
!       if (!gettimeofday (&tv, NULL))
  	st.st_atime = st.st_mtime = st.st_ctime = tv.tv_sec;
        else
          st.st_atime = st.st_mtime = st.st_ctime = (time_t) 0;
        ret = 0;
      }
--- 1136,1146 ----
        st.st_size = 0;
        st.st_blksize = 512;
  #if HAVE_STRUCT_STAT_ST_BLOCKS
        st.st_blocks = 0;
  #endif
!       if (!gdb_gettimeofday (&tv))
  	st.st_atime = st.st_mtime = st.st_ctime = tv.tv_sec;
        else
          st.st_atime = st.st_mtime = st.st_ctime = (time_t) 0;
        ret = 0;
      }
*************** remote_fileio_func_gettimeofday (char *b
*** 1194,1204 ****
        remote_fileio_reply (-1, FILEIO_EINVAL);
        return;
      }
  
    remote_fio_no_longjmp = 1;
!   ret = gettimeofday (&tv, NULL);
  
    if (ret == -1)
      {
        remote_fileio_return_errno (-1);
        return;
--- 1194,1204 ----
        remote_fileio_reply (-1, FILEIO_EINVAL);
        return;
      }
  
    remote_fio_no_longjmp = 1;
!   ret = gdb_gettimeofday (&tv);
  
    if (ret == -1)
      {
        remote_fileio_return_errno (-1);
        return;
Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.157
diff -c -5 -p -r1.157 utils.c
*** utils.c	24 Feb 2005 13:51:35 -0000	1.157
--- utils.c	8 Mar 2005 23:20:50 -0000
***************
*** 55,64 ****
--- 55,65 ----
  #include "symfile.h"
  
  #include "inferior.h"		/* for signed_pointer_to_address */
  
  #include <sys/param.h>		/* For MAXPATHLEN */
+ #include <sys/time.h>
  
  #include "gdb_curses.h"
  
  #include "readline/readline.h"
  
*************** align_down (ULONGEST v, int n)
*** 3094,3098 ****
--- 3095,3116 ----
  {
    /* Check that N is really a power of two.  */
    gdb_assert (n && (n & (n-1)) == 0);
    return (v & -n);
  }
+ 
+ /* A wrapper around gettimeofday.  On systems that do not have
+    gettimeofday, use other methods to get the current time.  */
+ int
+ gdb_gettimeofday (struct timeval *tp)
+ {
+ #ifdef HAVE_GETTIMEOFDAY
+   return gettimeofday (tp, NULL);
+ #else
+   /* On systems without gettimeofday, use the low-resolution "time"
+      function.  */
+   time_t system_time;
+   time (&tp->tv_sec);
+   tp->tv_usec = 0;
+   return 0;
+ #endif
+ }
Index: mi/mi-main.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-main.c,v
retrieving revision 1.76
diff -c -5 -p -r1.76 mi-main.c
*** mi/mi-main.c	21 Feb 2005 03:59:23 -0000	1.76
--- mi/mi-main.c	8 Mar 2005 23:20:50 -0000
*************** mi_load_progress (const char *section_na
*** 1375,1385 ****
        && !current_interp_named_p (INTERP_MI1))
      return;
  
    update_threshold.tv_sec = 0;
    update_threshold.tv_usec = 500000;
!   gettimeofday (&time_now, NULL);
  
    delta.tv_usec = time_now.tv_usec - last_update.tv_usec;
    delta.tv_sec = time_now.tv_sec - last_update.tv_sec;
  
    if (delta.tv_usec < 0)
--- 1375,1385 ----
        && !current_interp_named_p (INTERP_MI1))
      return;
  
    update_threshold.tv_sec = 0;
    update_threshold.tv_usec = 500000;
!   gdb_gettimeofday (&time_now);
  
    delta.tv_usec = time_now.tv_usec - last_update.tv_usec;
    delta.tv_sec = time_now.tv_sec - last_update.tv_sec;
  
    if (delta.tv_usec < 0)


             reply	other threads:[~2005-03-08 23:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-08 23:29 Mark Mitchell [this message]
2005-03-09 10:31 ` Mark Kettenis
2005-03-09 16:01   ` Mark Mitchell
2005-03-09 19:25     ` Stan Shebs
2005-03-09 19:28       ` Mark Mitchell
2005-03-09 22:14         ` Mark Kettenis

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=200503082329.j28NTaN1029372@sethra.codesourcery.com \
    --to=mark@codesourcery.com \
    --cc=gdb-patches@gcc.gnu.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