]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdbserver/utils.cc
aarch64: Remove unused code
[thirdparty/binutils-gdb.git] / gdbserver / utils.cc
CommitLineData
c906108c 1/* General utility routines for the remote server for GDB.
213516ef 2 Copyright (C) 1986-2023 Free Software Foundation, Inc.
c906108c 3
c5aa993b 4 This file is part of GDB.
c906108c 5
c5aa993b
JM
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
a9762ec7 8 the Free Software Foundation; either version 3 of the License, or
c5aa993b 9 (at your option) any later version.
c906108c 10
c5aa993b
JM
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.
c906108c 15
c5aa993b 16 You should have received a copy of the GNU General Public License
a9762ec7 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
18
19#include "server.h"
c906108c 20
fa593d66
PA
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
28
c906108c
SS
29/* Generally useful subroutines used throughout the program. */
30
171fba11
PA
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. */
35static void ATTRIBUTE_NORETURN
36abort_or_exit ()
37{
38#ifdef DEVELOPMENT
39 abort ();
40#else
41 exit (1);
42#endif
43}
44
d26e3629
KY
45void
46malloc_failure (long size)
bca929d3 47{
493e2a69
MS
48 fprintf (stderr,
49 PREFIX "ran out of memory while trying to allocate %lu bytes\n",
bca929d3 50 (unsigned long) size);
171fba11 51 abort_or_exit ();
bca929d3
DE
52}
53
ef87c8bb 54/* Print an error message and return to top level. */
c906108c 55
0729219d 56void
ef87c8bb 57verror (const char *string, va_list args)
c906108c 58{
860789c7 59#ifdef IN_PROCESS_AGENT
c906108c 60 fflush (stdout);
c906108c 61 vfprintf (stderr, string, args);
c906108c 62 fprintf (stderr, "\n");
fa593d66 63 exit (1);
860789c7
GB
64#else
65 throw_verror (GENERIC_ERROR, string, args);
fa593d66 66#endif
c906108c
SS
67}
68
0a30fbc4 69void
ef87c8bb 70vwarning (const char *string, va_list args)
0a30fbc4 71{
fa593d66 72 fprintf (stderr, PREFIX);
0a30fbc4
DJ
73 vfprintf (stderr, string, args);
74 fprintf (stderr, "\n");
0a30fbc4 75}
aa5ca48f 76
171fba11 77/* Report a problem internal to GDBserver, and abort/exit. */
e92d13d5
PA
78
79void
ef87c8bb 80internal_verror (const char *file, int line, const char *fmt, va_list args)
e92d13d5 81{
e92d13d5 82 fprintf (stderr, "\
fa593d66 83%s:%d: A problem internal to " TOOLNAME " has been detected.\n", file, line);
e92d13d5
PA
84 vfprintf (stderr, fmt, args);
85 fprintf (stderr, "\n");
171fba11 86 abort_or_exit ();
e92d13d5
PA
87}
88
e3d6ba5d
GB
89/* Report a problem internal to GDBserver. */
90
91void
92internal_vwarning (const char *file, int line, const char *fmt, va_list args)
93{
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");
98}
99
5c3216e2
OS
100/* Convert a CORE_ADDR into a HEX string, like %lx.
101 The result is stored in a circular static buffer, NUMCELLS deep. */
102
103char *
104paddress (CORE_ADDR addr)
105{
106 return phex_nz (addr, sizeof (CORE_ADDR));
107}