Use bfd_get_current_time in places where it is suitable
[binutils-gdb.git] / gdbserver / utils.cc
blob511364cfed298c7b00c6b4d43c4094a5b3b5c872
1 /* General utility routines for the remote server for GDB.
2 Copyright (C) 1986-2023 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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/>. */
19 #include "server.h"
21 #ifdef IN_PROCESS_AGENT
22 # define PREFIX "ipa: "
23 # define TOOLNAME "GDBserver in-process agent"
24 #else
25 # define PREFIX "gdbserver: "
26 # define TOOLNAME "GDBserver"
27 #endif
29 /* Generally useful subroutines used throughout the program. */
31 /* If in release mode, just exit. This avoids potentially littering
32 the filesystem of small embedded targets with core files. If in
33 development mode however, abort, producing core files to help with
34 debugging GDBserver. */
35 static void ATTRIBUTE_NORETURN
36 abort_or_exit ()
38 #ifdef DEVELOPMENT
39 abort ();
40 #else
41 exit (1);
42 #endif
45 void
46 malloc_failure (long size)
48 fprintf (stderr,
49 PREFIX "ran out of memory while trying to allocate %lu bytes\n",
50 (unsigned long) size);
51 abort_or_exit ();
54 /* Print an error message and return to top level. */
56 void
57 verror (const char *string, va_list args)
59 #ifdef IN_PROCESS_AGENT
60 fflush (stdout);
61 vfprintf (stderr, string, args);
62 fprintf (stderr, "\n");
63 exit (1);
64 #else
65 throw_verror (GENERIC_ERROR, string, args);
66 #endif
69 void
70 vwarning (const char *string, va_list args)
72 fprintf (stderr, PREFIX);
73 vfprintf (stderr, string, args);
74 fprintf (stderr, "\n");
77 /* Report a problem internal to GDBserver, and abort/exit. */
79 void
80 internal_verror (const char *file, int line, const char *fmt, va_list args)
82 fprintf (stderr, "\
83 %s:%d: A problem internal to " TOOLNAME " has been detected.\n", file, line);
84 vfprintf (stderr, fmt, args);
85 fprintf (stderr, "\n");
86 abort_or_exit ();
89 /* Report a problem internal to GDBserver. */
91 void
92 internal_vwarning (const char *file, int line, const char *fmt, va_list args)
94 fprintf (stderr, "\
95 %s:%d: A problem internal to " TOOLNAME " has been detected.\n", file, line);
96 vfprintf (stderr, fmt, args);
97 fprintf (stderr, "\n");
100 /* Convert a CORE_ADDR into a HEX string, like %lx.
101 The result is stored in a circular static buffer, NUMCELLS deep. */
103 char *
104 paddress (CORE_ADDR addr)
106 return phex_nz (addr, sizeof (CORE_ADDR));