gdb: Use C++11 std::chrono
[deliverable/binutils-gdb.git] / gdb / gdbserver / debug.c
index 54f2665d929187aface5a9b30d5d11b87373869a..0e6a3a6850550be0bd9d28edbc567c2e779e8ada 100644 (file)
@@ -17,7 +17,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "server.h"
-#include "gdb_sys_time.h"
+#include <chrono>
 
 /* Enable miscellaneous debugging output.  The name is historical - it
    was originally used to debug LinuxThreads support.  */
@@ -27,8 +27,7 @@ int debug_threads;
 int debug_timestamp;
 
 /* Print a debugging message.
-   If the text begins a new line it is preceded by a timestamp, if the
-   system has gettimeofday.
+   If the text begins a new line it is preceded by a timestamp.
    We don't get fancy with newline checking, we just check whether the
    previous call ended with "\n".  */
 
@@ -41,14 +40,13 @@ debug_vprintf (const char *format, va_list ap)
 
   if (debug_timestamp && new_line)
     {
-      struct timeval tm;
+      using namespace std::chrono;
 
-      gettimeofday (&tm, NULL);
+      steady_clock::time_point now = steady_clock::now ();
+      seconds s = duration_cast<seconds> (now.time_since_epoch ());
+      microseconds us = duration_cast<microseconds> (now.time_since_epoch ()) - s;
 
-      /* If gettimeofday doesn't exist, and as a portability solution it has
-        been replaced with, e.g., time, then it doesn't make sense to print
-        the microseconds field.  Is there a way to check for that?  */
-      fprintf (stderr, "%ld:%06ld ", (long) tm.tv_sec, (long) tm.tv_usec);
+      fprintf (stderr, "%ld.%06ld ", (long) s.count (), (long) us.count ());
     }
 #endif
 
This page took 0.025097 seconds and 4 git commands to generate.