gdbserver: Move remote_debug to a single place
[deliverable/binutils-gdb.git] / gdb / gdbserver / debug.c
CommitLineData
87ce2a04 1/* Debugging routines for the remote server for GDB.
42a4f53d 2 Copyright (C) 2014-2019 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"
dcb07cfa 20#include <chrono>
87ce2a04 21
c1bc0935
AH
22#if !defined (IN_PROCESS_AGENT)
23int remote_debug = 0;
24#endif
25
87ce2a04
DE
26/* Enable miscellaneous debugging output. The name is historical - it
27 was originally used to debug LinuxThreads support. */
28int debug_threads;
29
30/* Include timestamps in debugging output. */
31int debug_timestamp;
32
33/* Print a debugging message.
dcb07cfa 34 If the text begins a new line it is preceded by a timestamp.
87ce2a04
DE
35 We don't get fancy with newline checking, we just check whether the
36 previous call ended with "\n". */
37
38void
34abf635 39debug_vprintf (const char *format, va_list ap)
87ce2a04 40{
0b04e523 41#if !defined (IN_PROCESS_AGENT)
87ce2a04
DE
42 /* N.B. Not thread safe, and can't be used, as is, with IPA. */
43 static int new_line = 1;
44
45 if (debug_timestamp && new_line)
46 {
dcb07cfa 47 using namespace std::chrono;
87ce2a04 48
dcb07cfa
PA
49 steady_clock::time_point now = steady_clock::now ();
50 seconds s = duration_cast<seconds> (now.time_since_epoch ());
51 microseconds us = duration_cast<microseconds> (now.time_since_epoch ()) - s;
87ce2a04 52
dcb07cfa 53 fprintf (stderr, "%ld.%06ld ", (long) s.count (), (long) us.count ());
87ce2a04
DE
54 }
55#endif
56
34abf635 57 vfprintf (stderr, format, ap);
87ce2a04 58
0b04e523 59#if !defined (IN_PROCESS_AGENT)
34abf635
GB
60 if (*format)
61 new_line = format[strlen (format) - 1] == '\n';
87ce2a04
DE
62#endif
63}
64
65/* Flush debugging output.
66 This is called, for example, when starting an inferior to ensure all debug
67 output thus far appears before any inferior output. */
68
69void
70debug_flush (void)
71{
72 fflush (stderr);
73}
74
75/* Notify the user that the code is entering FUNCTION_NAME.
76 FUNCTION_NAME is the name of the calling function, or NULL if unknown.
77
78 This is intended to be called via the debug_enter macro. */
79
80void
81do_debug_enter (const char *function_name)
82{
83 if (function_name != NULL)
84 debug_printf (">>>> entering %s\n", function_name);
85}
86
87/* Notify the user that the code is exiting FUNCTION_NAME.
88 FUNCTION_NAME is the name of the calling function, or NULL if unknown.
89
90 This is intended to be called via the debug_exit macro. */
91
92void
93do_debug_exit (const char *function_name)
94{
95 if (function_name != NULL)
96 debug_printf ("<<<< exiting %s\n", function_name);
97}
This page took 0.645451 seconds and 4 git commands to generate.