1 /* General utility routines for the remote server for GDB.
2 Copyright (C) 1986-2014 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/>. */
25 #ifdef IN_PROCESS_AGENT
26 # define PREFIX "ipa: "
27 # define TOOLNAME "GDBserver in-process agent"
29 # define PREFIX "gdbserver: "
30 # define TOOLNAME "GDBserver"
33 /* Generally useful subroutines used throughout the program. */
36 malloc_failure (long size
)
39 PREFIX
"ran out of memory while trying to allocate %lu bytes\n",
40 (unsigned long) size
);
44 /* Copy a string into a memory buffer.
45 If malloc fails, this will print a message to stderr and exit. */
48 xstrdup (const char *s
)
50 char *ret
= strdup (s
);
52 malloc_failure (strlen (s
) + 1);
56 /* Print the system error message for errno, and also mention STRING
57 as the file name for which the error was encountered.
58 Then return to command level. */
61 perror_with_name (const char *string
)
66 err
= strerror (errno
);
68 err
= "unknown error";
70 combined
= (char *) alloca (strlen (err
) + strlen (string
) + 3);
71 strcpy (combined
, string
);
72 strcat (combined
, ": ");
73 strcat (combined
, err
);
75 error ("%s.", combined
);
78 /* Print an error message and return to command level.
79 STRING is the error message, used as a fprintf string,
80 and ARG is passed as an argument to it. */
83 error (const char *string
,...)
85 #ifndef IN_PROCESS_AGENT
86 extern jmp_buf toplevel
;
89 va_start (args
, string
);
91 vfprintf (stderr
, string
, args
);
92 fprintf (stderr
, "\n");
93 #ifndef IN_PROCESS_AGENT
94 longjmp (toplevel
, 1);
100 /* Print an error message and exit reporting failure.
101 This is for a error that we cannot continue from.
102 STRING and ARG are passed to fprintf. */
106 fatal (const char *string
,...)
109 va_start (args
, string
);
110 fprintf (stderr
, PREFIX
);
111 vfprintf (stderr
, string
, args
);
112 fprintf (stderr
, "\n");
119 warning (const char *string
,...)
122 va_start (args
, string
);
123 fprintf (stderr
, PREFIX
);
124 vfprintf (stderr
, string
, args
);
125 fprintf (stderr
, "\n");
129 /* Report a problem internal to GDBserver, and exit. */
132 internal_error (const char *file
, int line
, const char *fmt
, ...)
135 va_start (args
, fmt
);
138 %s:%d: A problem internal to " TOOLNAME
" has been detected.\n", file
, line
);
139 vfprintf (stderr
, fmt
, args
);
140 fprintf (stderr
, "\n");
145 /* Convert a CORE_ADDR into a HEX string, like %lx.
146 The result is stored in a circular static buffer, NUMCELLS deep. */
149 paddress (CORE_ADDR addr
)
151 return phex_nz (addr
, sizeof (CORE_ADDR
));
154 /* Convert a file descriptor into a printable string. */
157 pfildes (gdb_fildes_t fd
)
160 return phex_nz (fd
, sizeof (gdb_fildes_t
));
162 return plongest (fd
);
This page took 0.033245 seconds and 5 git commands to generate.