libctf: create: non-root-visible types should not appear in name tables
[deliverable/binutils-gdb.git] / gdbserver / utils.cc
CommitLineData
c906108c 1/* General utility routines for the remote server for GDB.
b811d2c2 2 Copyright (C) 1986-2020 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
d26e3629
KY
31void
32malloc_failure (long size)
bca929d3 33{
493e2a69
MS
34 fprintf (stderr,
35 PREFIX "ran out of memory while trying to allocate %lu bytes\n",
bca929d3
DE
36 (unsigned long) size);
37 exit (1);
38}
39
c906108c
SS
40/* Print the system error message for errno, and also mention STRING
41 as the file name for which the error was encountered.
42 Then return to command level. */
43
44void
54363045 45perror_with_name (const char *string)
c906108c 46{
5c44784c 47 const char *err;
c906108c
SS
48 char *combined;
49
ab7d13f0 50 err = safe_strerror (errno);
43d5792c 51 if (err == NULL)
c906108c
SS
52 err = "unknown error";
53
54 combined = (char *) alloca (strlen (err) + strlen (string) + 3);
55 strcpy (combined, string);
56 strcat (combined, ": ");
57 strcat (combined, err);
58
59 error ("%s.", combined);
60}
61
ef87c8bb 62/* Print an error message and return to top level. */
c906108c 63
0729219d 64void
ef87c8bb 65verror (const char *string, va_list args)
c906108c 66{
860789c7 67#ifdef IN_PROCESS_AGENT
c906108c 68 fflush (stdout);
c906108c 69 vfprintf (stderr, string, args);
c906108c 70 fprintf (stderr, "\n");
fa593d66 71 exit (1);
860789c7
GB
72#else
73 throw_verror (GENERIC_ERROR, string, args);
fa593d66 74#endif
c906108c
SS
75}
76
0a30fbc4 77void
ef87c8bb 78vwarning (const char *string, va_list args)
0a30fbc4 79{
fa593d66 80 fprintf (stderr, PREFIX);
0a30fbc4
DJ
81 vfprintf (stderr, string, args);
82 fprintf (stderr, "\n");
0a30fbc4 83}
aa5ca48f 84
e92d13d5
PA
85/* Report a problem internal to GDBserver, and exit. */
86
87void
ef87c8bb 88internal_verror (const char *file, int line, const char *fmt, va_list args)
e92d13d5 89{
e92d13d5 90 fprintf (stderr, "\
fa593d66 91%s:%d: A problem internal to " TOOLNAME " has been detected.\n", file, line);
e92d13d5
PA
92 vfprintf (stderr, fmt, args);
93 fprintf (stderr, "\n");
e92d13d5
PA
94 exit (1);
95}
96
e3d6ba5d
GB
97/* Report a problem internal to GDBserver. */
98
99void
100internal_vwarning (const char *file, int line, const char *fmt, va_list args)
101{
102 fprintf (stderr, "\
103%s:%d: A problem internal to " TOOLNAME " has been detected.\n", file, line);
104 vfprintf (stderr, fmt, args);
105 fprintf (stderr, "\n");
106}
107
5c3216e2
OS
108/* Convert a CORE_ADDR into a HEX string, like %lx.
109 The result is stored in a circular static buffer, NUMCELLS deep. */
110
111char *
112paddress (CORE_ADDR addr)
113{
114 return phex_nz (addr, sizeof (CORE_ADDR));
115}
This page took 1.519376 seconds and 4 git commands to generate.