gdb: Use C++11 std::chrono
[deliverable/binutils-gdb.git] / gdb / gdbserver / debug.c
1 /* Debugging routines for the remote server for GDB.
2 Copyright (C) 2014-2016 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19 #include "server.h"
20 #include <chrono>
21
22 /* Enable miscellaneous debugging output. The name is historical - it
23 was originally used to debug LinuxThreads support. */
24 int debug_threads;
25
26 /* Include timestamps in debugging output. */
27 int debug_timestamp;
28
29 /* Print a debugging message.
30 If the text begins a new line it is preceded by a timestamp.
31 We don't get fancy with newline checking, we just check whether the
32 previous call ended with "\n". */
33
34 void
35 debug_vprintf (const char *format, va_list ap)
36 {
37 #if !defined (IN_PROCESS_AGENT)
38 /* N.B. Not thread safe, and can't be used, as is, with IPA. */
39 static int new_line = 1;
40
41 if (debug_timestamp && new_line)
42 {
43 using namespace std::chrono;
44
45 steady_clock::time_point now = steady_clock::now ();
46 seconds s = duration_cast<seconds> (now.time_since_epoch ());
47 microseconds us = duration_cast<microseconds> (now.time_since_epoch ()) - s;
48
49 fprintf (stderr, "%ld.%06ld ", (long) s.count (), (long) us.count ());
50 }
51 #endif
52
53 vfprintf (stderr, format, ap);
54
55 #if !defined (IN_PROCESS_AGENT)
56 if (*format)
57 new_line = format[strlen (format) - 1] == '\n';
58 #endif
59 }
60
61 /* Flush debugging output.
62 This is called, for example, when starting an inferior to ensure all debug
63 output thus far appears before any inferior output. */
64
65 void
66 debug_flush (void)
67 {
68 fflush (stderr);
69 }
70
71 /* Notify the user that the code is entering FUNCTION_NAME.
72 FUNCTION_NAME is the name of the calling function, or NULL if unknown.
73
74 This is intended to be called via the debug_enter macro. */
75
76 void
77 do_debug_enter (const char *function_name)
78 {
79 if (function_name != NULL)
80 debug_printf (">>>> entering %s\n", function_name);
81 }
82
83 /* Notify the user that the code is exiting FUNCTION_NAME.
84 FUNCTION_NAME is the name of the calling function, or NULL if unknown.
85
86 This is intended to be called via the debug_exit macro. */
87
88 void
89 do_debug_exit (const char *function_name)
90 {
91 if (function_name != NULL)
92 debug_printf ("<<<< exiting %s\n", function_name);
93 }
This page took 0.032001 seconds and 4 git commands to generate.