]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* General utility routines for the remote server for GDB. |
1d506c26 | 2 | Copyright (C) 1986-2024 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 | 18 | |
c906108c | 19 | |
fa593d66 PA |
20 | #ifdef IN_PROCESS_AGENT |
21 | # define PREFIX "ipa: " | |
22 | # define TOOLNAME "GDBserver in-process agent" | |
23 | #else | |
24 | # define PREFIX "gdbserver: " | |
25 | # define TOOLNAME "GDBserver" | |
26 | #endif | |
27 | ||
c906108c SS |
28 | /* Generally useful subroutines used throughout the program. */ |
29 | ||
171fba11 PA |
30 | /* If in release mode, just exit. This avoids potentially littering |
31 | the filesystem of small embedded targets with core files. If in | |
32 | development mode however, abort, producing core files to help with | |
33 | debugging GDBserver. */ | |
34 | static void ATTRIBUTE_NORETURN | |
35 | abort_or_exit () | |
36 | { | |
37 | #ifdef DEVELOPMENT | |
38 | abort (); | |
39 | #else | |
40 | exit (1); | |
41 | #endif | |
42 | } | |
43 | ||
d26e3629 KY |
44 | void |
45 | malloc_failure (long size) | |
bca929d3 | 46 | { |
493e2a69 MS |
47 | fprintf (stderr, |
48 | PREFIX "ran out of memory while trying to allocate %lu bytes\n", | |
bca929d3 | 49 | (unsigned long) size); |
171fba11 | 50 | abort_or_exit (); |
bca929d3 DE |
51 | } |
52 | ||
ef87c8bb | 53 | /* Print an error message and return to top level. */ |
c906108c | 54 | |
0729219d | 55 | void |
ef87c8bb | 56 | verror (const char *string, va_list args) |
c906108c | 57 | { |
860789c7 | 58 | #ifdef IN_PROCESS_AGENT |
c906108c | 59 | fflush (stdout); |
c906108c | 60 | vfprintf (stderr, string, args); |
c906108c | 61 | fprintf (stderr, "\n"); |
fa593d66 | 62 | exit (1); |
860789c7 GB |
63 | #else |
64 | throw_verror (GENERIC_ERROR, string, args); | |
fa593d66 | 65 | #endif |
c906108c SS |
66 | } |
67 | ||
0a30fbc4 | 68 | void |
ef87c8bb | 69 | vwarning (const char *string, va_list args) |
0a30fbc4 | 70 | { |
fa593d66 | 71 | fprintf (stderr, PREFIX); |
0a30fbc4 DJ |
72 | vfprintf (stderr, string, args); |
73 | fprintf (stderr, "\n"); | |
0a30fbc4 | 74 | } |
aa5ca48f | 75 | |
171fba11 | 76 | /* Report a problem internal to GDBserver, and abort/exit. */ |
e92d13d5 PA |
77 | |
78 | void | |
ef87c8bb | 79 | internal_verror (const char *file, int line, const char *fmt, va_list args) |
e92d13d5 | 80 | { |
e92d13d5 | 81 | fprintf (stderr, "\ |
fa593d66 | 82 | %s:%d: A problem internal to " TOOLNAME " has been detected.\n", file, line); |
e92d13d5 PA |
83 | vfprintf (stderr, fmt, args); |
84 | fprintf (stderr, "\n"); | |
171fba11 | 85 | abort_or_exit (); |
e92d13d5 PA |
86 | } |
87 | ||
e3d6ba5d GB |
88 | /* Report a problem internal to GDBserver. */ |
89 | ||
90 | void | |
91 | internal_vwarning (const char *file, int line, const char *fmt, va_list args) | |
92 | { | |
93 | fprintf (stderr, "\ | |
94 | %s:%d: A problem internal to " TOOLNAME " has been detected.\n", file, line); | |
95 | vfprintf (stderr, fmt, args); | |
96 | fprintf (stderr, "\n"); | |
97 | } | |
98 | ||
5c3216e2 OS |
99 | /* Convert a CORE_ADDR into a HEX string, like %lx. |
100 | The result is stored in a circular static buffer, NUMCELLS deep. */ | |
101 | ||
523e454f | 102 | const char * |
5c3216e2 OS |
103 | paddress (CORE_ADDR addr) |
104 | { | |
105 | return phex_nz (addr, sizeof (CORE_ADDR)); | |
106 | } |