Commit | Line | Data |
---|---|---|
87ce2a04 | 1 | /* Debugging routines for the remote server for GDB. |
32d0add0 | 2 | Copyright (C) 2014-2015 Free Software Foundation, Inc. |
87ce2a04 DE |
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" | |
438e1e42 | 20 | #include "gdb_sys_time.h" |
87ce2a04 DE |
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, if the | |
31 | system has gettimeofday. | |
32 | We don't get fancy with newline checking, we just check whether the | |
33 | previous call ended with "\n". */ | |
34 | ||
35 | void | |
34abf635 | 36 | debug_vprintf (const char *format, va_list ap) |
87ce2a04 | 37 | { |
0b04e523 | 38 | #if !defined (IN_PROCESS_AGENT) |
87ce2a04 DE |
39 | /* N.B. Not thread safe, and can't be used, as is, with IPA. */ |
40 | static int new_line = 1; | |
41 | ||
42 | if (debug_timestamp && new_line) | |
43 | { | |
44 | struct timeval tm; | |
45 | ||
46 | gettimeofday (&tm, NULL); | |
47 | ||
48 | /* If gettimeofday doesn't exist, and as a portability solution it has | |
49 | been replaced with, e.g., time, then it doesn't make sense to print | |
50 | the microseconds field. Is there a way to check for that? */ | |
51 | fprintf (stderr, "%ld:%06ld ", (long) tm.tv_sec, (long) tm.tv_usec); | |
52 | } | |
53 | #endif | |
54 | ||
34abf635 | 55 | vfprintf (stderr, format, ap); |
87ce2a04 | 56 | |
0b04e523 | 57 | #if !defined (IN_PROCESS_AGENT) |
34abf635 GB |
58 | if (*format) |
59 | new_line = format[strlen (format) - 1] == '\n'; | |
87ce2a04 DE |
60 | #endif |
61 | } | |
62 | ||
63 | /* Flush debugging output. | |
64 | This is called, for example, when starting an inferior to ensure all debug | |
65 | output thus far appears before any inferior output. */ | |
66 | ||
67 | void | |
68 | debug_flush (void) | |
69 | { | |
70 | fflush (stderr); | |
71 | } | |
72 | ||
73 | /* Notify the user that the code is entering FUNCTION_NAME. | |
74 | FUNCTION_NAME is the name of the calling function, or NULL if unknown. | |
75 | ||
76 | This is intended to be called via the debug_enter macro. */ | |
77 | ||
78 | void | |
79 | do_debug_enter (const char *function_name) | |
80 | { | |
81 | if (function_name != NULL) | |
82 | debug_printf (">>>> entering %s\n", function_name); | |
83 | } | |
84 | ||
85 | /* Notify the user that the code is exiting FUNCTION_NAME. | |
86 | FUNCTION_NAME is the name of the calling function, or NULL if unknown. | |
87 | ||
88 | This is intended to be called via the debug_exit macro. */ | |
89 | ||
90 | void | |
91 | do_debug_exit (const char *function_name) | |
92 | { | |
93 | if (function_name != NULL) | |
94 | debug_printf ("<<<< exiting %s\n", function_name); | |
95 | } |