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/>. */
24 #ifdef IN_PROCESS_AGENT
25 # define PREFIX "ipa: "
26 # define TOOLNAME "GDBserver in-process agent"
28 # define PREFIX "gdbserver: "
29 # define TOOLNAME "GDBserver"
32 /* Generally useful subroutines used throughout the program. */
35 malloc_failure (long size
)
38 PREFIX
"ran out of memory while trying to allocate %lu bytes\n",
39 (unsigned long) size
);
43 /* Copy a string into a memory buffer.
44 If malloc fails, this will print a message to stderr and exit. */
47 xstrdup (const char *s
)
49 char *ret
= strdup (s
);
51 malloc_failure (strlen (s
) + 1);
55 /* Print the system error message for errno, and also mention STRING
56 as the file name for which the error was encountered.
57 Then return to command level. */
60 perror_with_name (const char *string
)
65 err
= strerror (errno
);
67 err
= "unknown error";
69 combined
= (char *) alloca (strlen (err
) + strlen (string
) + 3);
70 strcpy (combined
, string
);
71 strcat (combined
, ": ");
72 strcat (combined
, err
);
74 error ("%s.", combined
);
77 /* Print an error message and return to command level.
78 STRING is the error message, used as a fprintf string,
79 and ARG is passed as an argument to it. */
82 error (const char *string
,...)
84 #ifndef IN_PROCESS_AGENT
85 extern jmp_buf toplevel
;
88 va_start (args
, string
);
90 vfprintf (stderr
, string
, args
);
91 fprintf (stderr
, "\n");
92 #ifndef IN_PROCESS_AGENT
93 longjmp (toplevel
, 1);
99 /* Print an error message and exit reporting failure.
100 This is for a error that we cannot continue from.
101 STRING and ARG are passed to fprintf. */
105 fatal (const char *string
,...)
108 va_start (args
, string
);
109 fprintf (stderr
, PREFIX
);
110 vfprintf (stderr
, string
, args
);
111 fprintf (stderr
, "\n");
118 warning (const char *string
,...)
121 va_start (args
, string
);
122 fprintf (stderr
, PREFIX
);
123 vfprintf (stderr
, string
, args
);
124 fprintf (stderr
, "\n");
128 /* Report a problem internal to GDBserver, and exit. */
131 internal_error (const char *file
, int line
, const char *fmt
, ...)
134 va_start (args
, fmt
);
137 %s:%d: A problem internal to " TOOLNAME
" has been detected.\n", file
, line
);
138 vfprintf (stderr
, fmt
, args
);
139 fprintf (stderr
, "\n");
144 /* Convert a CORE_ADDR into a HEX string, like %lx.
145 The result is stored in a circular static buffer, NUMCELLS deep. */
148 paddress (CORE_ADDR addr
)
150 return phex_nz (addr
, sizeof (CORE_ADDR
));
153 /* Convert a file descriptor into a printable string. */
156 pfildes (gdb_fildes_t fd
)
159 return phex_nz (fd
, sizeof (gdb_fildes_t
));
161 return plongest (fd
);
This page took 0.033533 seconds and 5 git commands to generate.