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/>. */
21 #ifdef IN_PROCESS_AGENT
22 # define PREFIX "ipa: "
23 # define TOOLNAME "GDBserver in-process agent"
25 # define PREFIX "gdbserver: "
26 # define TOOLNAME "GDBserver"
29 /* Generally useful subroutines used throughout the program. */
32 malloc_failure (long size
)
35 PREFIX
"ran out of memory while trying to allocate %lu bytes\n",
36 (unsigned long) size
);
40 /* Copy a string into a memory buffer.
41 If malloc fails, this will print a message to stderr and exit. */
44 xstrdup (const char *s
)
46 char *ret
= strdup (s
);
48 malloc_failure (strlen (s
) + 1);
52 /* Print the system error message for errno, and also mention STRING
53 as the file name for which the error was encountered.
54 Then return to command level. */
57 perror_with_name (const char *string
)
62 err
= strerror (errno
);
64 err
= "unknown error";
66 combined
= (char *) alloca (strlen (err
) + strlen (string
) + 3);
67 strcpy (combined
, string
);
68 strcat (combined
, ": ");
69 strcat (combined
, err
);
71 error ("%s.", combined
);
74 /* Print an error message and return to command level.
75 STRING is the error message, used as a fprintf string,
76 and ARG is passed as an argument to it. */
79 error (const char *string
,...)
81 #ifndef IN_PROCESS_AGENT
82 extern jmp_buf toplevel
;
85 va_start (args
, string
);
87 vfprintf (stderr
, string
, args
);
88 fprintf (stderr
, "\n");
89 #ifndef IN_PROCESS_AGENT
90 longjmp (toplevel
, 1);
96 /* Print an error message and exit reporting failure.
97 This is for a error that we cannot continue from.
98 STRING and ARG are passed to fprintf. */
102 fatal (const char *string
,...)
105 va_start (args
, string
);
106 fprintf (stderr
, PREFIX
);
107 vfprintf (stderr
, string
, args
);
108 fprintf (stderr
, "\n");
115 warning (const char *string
,...)
118 va_start (args
, string
);
119 fprintf (stderr
, PREFIX
);
120 vfprintf (stderr
, string
, args
);
121 fprintf (stderr
, "\n");
125 /* Report a problem internal to GDBserver, and exit. */
128 internal_error (const char *file
, int line
, const char *fmt
, ...)
131 va_start (args
, fmt
);
134 %s:%d: A problem internal to " TOOLNAME
" has been detected.\n", file
, line
);
135 vfprintf (stderr
, fmt
, args
);
136 fprintf (stderr
, "\n");
141 /* Convert a CORE_ADDR into a HEX string, like %lx.
142 The result is stored in a circular static buffer, NUMCELLS deep. */
145 paddress (CORE_ADDR addr
)
147 return phex_nz (addr
, sizeof (CORE_ADDR
));
150 /* Convert a file descriptor into a printable string. */
153 pfildes (gdb_fildes_t fd
)
156 return phex_nz (fd
, sizeof (gdb_fildes_t
));
158 return plongest (fd
);
This page took 0.033511 seconds and 5 git commands to generate.