Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "defs.h"
-
+#if !defined(__GO32__)
#include <sys/ioctl.h>
#include <sys/param.h>
#include <pwd.h>
+#endif
#include <varargs.h>
#include <ctype.h>
#include <string.h>
#include "terminal.h"
#include "bfd.h"
#include "target.h"
+#include "demangle.h"
/* Prototypes for local functions */
while ((ptr = cleanup_chain) != old_chain)
{
cleanup_chain = ptr->next;
- free (ptr);
+ free ((PTR)ptr);
}
}
wrap_here(""); /* Force out any buffered output */
fflush (stdout);
if (error_pre_print)
- fprintf (stderr, error_pre_print);
+ fprintf_filtered (stderr, error_pre_print);
string = va_arg (args, char *);
- vfprintf (stderr, string, args);
- fprintf (stderr, "\n");
+ vfprintf_filtered (stderr, string, args);
+ fprintf_filtered (stderr, "\n");
va_end (args);
return_to_top_level ();
}
exit (1);
}
+/* The strerror() function can return NULL for errno values that are
+ out of range. Provide a "safe" version that always returns a
+ printable string. */
+
+char *
+safe_strerror (errnum)
+ int errnum;
+{
+ char *msg;
+ static char buf[32];
+
+ if ((msg = strerror (errnum)) == NULL)
+ {
+ sprintf (buf, "(undocumented errno %d)", errnum);
+ msg = buf;
+ }
+ return (msg);
+}
+
+/* The strsignal() function can return NULL for signal values that are
+ out of range. Provide a "safe" version that always returns a
+ printable string. */
+
+char *
+safe_strsignal (signo)
+ int signo;
+{
+ char *msg;
+ static char buf[32];
+
+ if ((msg = strsignal (signo)) == NULL)
+ {
+ sprintf (buf, "(undocumented signal %d)", signo);
+ msg = buf;
+ }
+ return (msg);
+}
+
+
/* Print the system error message for errno, and also mention STRING
as the file name for which the error was encountered.
Then return to command level. */
perror_with_name (string)
char *string;
{
- extern int sys_nerr;
- extern char *sys_errlist[];
char *err;
char *combined;
- if (errno < sys_nerr)
- err = sys_errlist[errno];
- else
- err = "unknown error";
-
+ err = safe_strerror (errno);
combined = (char *) alloca (strlen (err) + strlen (string) + 3);
strcpy (combined, string);
strcat (combined, ": ");
char *string;
int errcode;
{
- extern int sys_nerr;
- extern char *sys_errlist[];
char *err;
char *combined;
- if (errcode < sys_nerr)
- err = sys_errlist[errcode];
- else
- err = "unknown error";
-
+ err = safe_strerror (errcode);
combined = (char *) alloca (strlen (err) + strlen (string) + 3);
strcpy (combined, string);
strcat (combined, ": ");
strcat (combined, err);
- printf ("%s.\n", combined);
+ fprintf (stderr, "%s.\n", combined);
}
/* Control C eventually causes this to be called, at a convenient time. */
{
target_terminal_ours ();
wrap_here ((char *)0); /* Force out any pending output */
+#if !defined(__GO32__)
#ifdef HAVE_TERMIO
ioctl (fileno (stdout), TCFLSH, 1);
#else /* not HAVE_TERMIO */
#else
error ("Quit (expect signal %d when inferior is resumed)", SIGINT);
#endif /* TIOCGPGRP */
+#endif
}
/* Control C comes here */
PTR ptr;
long size;
{
- return (realloc (ptr, size));
+ if (ptr == 0) /* Guard against old realloc's */
+ return malloc (size);
+ else
+ return realloc (ptr, size);
}
void
warning ("internal error: failed to install memory consistency checks");
}
- (void) mmtrace ();
+ mmtrace ();
}
#endif /* Have mmalloc and want corruption checking */
int size;
{
register char *p = (char *) xmalloc (size + 1);
- bcopy (ptr, p, size);
+ memcpy (p, ptr, size);
p[size] = 0;
return p;
}
int size;
{
register char *p = (char *) xmmalloc (md, size + 1);
- bcopy (ptr, p, size);
+ memcpy (p, ptr, size);
p[size] = 0;
return p;
}
while (1)
{
+ wrap_here (""); /* Flush any buffered output */
+ fflush (stdout);
va_start (args);
ctlstr = va_arg (args, char *);
- vfprintf (stdout, ctlstr, args);
+ vfprintf_filtered (stdout, ctlstr, args);
va_end (args);
- printf ("(y or n) ");
+ printf_filtered ("(y or n) ");
fflush (stdout);
answer = fgetc (stdin);
clearerr (stdin); /* in case of C-d */
return 1;
if (answer == 'N')
return 0;
- printf ("Please answer y or n.\n");
+ printf_filtered ("Please answer y or n.\n");
}
}
int quoter;
{
- if (c < 040 || (sevenbit_strings && c >= 0177)) {
+ c &= 0xFF; /* Avoid sign bit follies */
+
+ if ( c < 0x20 || /* Low control chars */
+ (c >= 0x7F && c < 0xA0) || /* DEL, High controls */
+ (sevenbit_strings && c >= 0x80)) { /* high order bit set */
switch (c)
{
case '\n':
&& (isalnum(c) || (c) == '_' || (c) == CPLUS_MARKER))
char buf[SYMBOL_MAX+1];
-# define SLOP 5 /* How much room to leave in buf */
+# define DMSLOP 5 /* How much room to leave in buf */
char *p;
if (linebuffer == NULL)
int i = 0;
/* collect non-interesting characters into buf */
- while ( *p != (char) 0 && !SYMBOL_CHAR(*p) && i < (int)sizeof(buf)-SLOP ) {
+ while (*p != (char) 0 && !SYMBOL_CHAR(*p) && i < (int)sizeof(buf)-DMSLOP ) {
buf[i++] = *p;
p++;
}
while (i < SYMBOL_MAX
&& *p != (char) 0
&& SYMBOL_CHAR(*p)
- && i < (int)sizeof(buf) - SLOP) {
+ && i < (int)sizeof(buf) - DMSLOP) {
buf[i++] = *p;
p++;
}
/* This won't blow up if the restrictions described above are
followed. */
- (void) vsprintf (linebuffer, format, args);
+ vsprintf (linebuffer, format, args);
fputs_filtered (linebuffer, stream);
}
fprintf_filtered (va_alist)
va_dcl
{
+ va_list args;
FILE *stream;
char *format;
+
+ va_start (args);
+ stream = va_arg (args, FILE *);
+ format = va_arg (args, char *);
+
+ /* This won't blow up if the restrictions described above are
+ followed. */
+ vfprintf_filtered (stream, format, args);
+ va_end (args);
+}
+
+/* Like fprintf_filtered, but prints it's result indent.
+ Called as fprintfi_filtered (spaces, format, arg1, arg2, ...); */
+
+/* VARARGS */
+void
+fprintfi_filtered (va_alist)
+ va_dcl
+{
va_list args;
+ int spaces;
+ FILE *stream;
+ char *format;
va_start (args);
+ spaces = va_arg (args, int);
stream = va_arg (args, FILE *);
format = va_arg (args, char *);
+ print_spaces_filtered (spaces, stream);
/* This won't blow up if the restrictions described above are
followed. */
va_end (args);
}
+/* Like printf_filtered, but prints it's result indented.
+ Called as printfi_filtered (spaces, format, arg1, arg2, ...); */
+
+/* VARARGS */
+void
+printfi_filtered (va_alist)
+ va_dcl
+{
+ va_list args;
+ int spaces;
+ char *format;
+
+ va_start (args);
+ spaces = va_arg (args, int);
+ format = va_arg (args, char *);
+ print_spaces_filtered (spaces, stdout);
+ vfprintf_filtered (stdout, format, args);
+ va_end (args);
+}
+
/* Easy */
void
\f
/* C++ demangler stuff. */
+/* Make a copy of a symbol, applying C++ demangling if demangling is enabled
+ and a demangled version exists. Note that the value returned from
+ cplus_demangle is already allocated in malloc'd memory. */
+
+char *
+strdup_demangled (name)
+ const char *name;
+{
+ char *demangled = NULL;
+
+ if (demangle)
+ {
+ demangled = cplus_demangle (name, DMGL_PARAMS | DMGL_ANSI);
+ }
+ return ((demangled != NULL) ? demangled : strdup (name));
+}
+
+
/* Print NAME on STREAM, demangling if necessary. */
void
fprint_symbol (stream, name)
char *name;
{
char *demangled;
- if ((!demangle) || NULL == (demangled = cplus_demangle (name, 1)))
+ if ((!demangle)
+ || NULL == (demangled = cplus_demangle (name, DMGL_PARAMS | DMGL_ANSI)))
fputs_filtered (name, stream);
else
{
free (demangled);
}
}
+
+/* Do a strcmp() type operation on STRING1 and STRING2, ignoring any
+ differences in whitespace. Returns 0 if they match, non-zero if they
+ don't (slightly different than strcmp()'s range of return values).
+
+ As an extra hack, string1=="FOO(ARGS)" matches string2=="FOO".
+ This "feature" is useful for demangle_and_match(), which is used
+ when searching for matching C++ function names (such as if the
+ user types 'break FOO', where FOO is a mangled C++ function). */
+
+static int
+strcmp_iw (string1, string2)
+ const char *string1;
+ const char *string2;
+{
+ while ((*string1 != '\0') && (*string2 != '\0'))
+ {
+ while (isspace (*string1))
+ {
+ string1++;
+ }
+ while (isspace (*string2))
+ {
+ string2++;
+ }
+ if (*string1 != *string2)
+ {
+ break;
+ }
+ if (*string1 != '\0')
+ {
+ string1++;
+ string2++;
+ }
+ }
+ return (*string1 != '\0' && *string1 != '(') || (*string2 != '\0');
+}
+
+/* Demangle NAME and compare the result with LOOKFOR, ignoring any differences
+ in whitespace.
+
+ If a match is found, returns a pointer to the demangled version of NAME
+ in malloc'd memory, which needs to be freed by the caller after use.
+ If a match is not found, returns NULL.
+
+ OPTIONS is a flags word that controls the demangling process and is just
+ passed on to the demangler.
+
+ When the caller sees a non-NULL result, it knows that NAME is the mangled
+ equivalent of LOOKFOR, and it can use either NAME, the "official demangled"
+ version of NAME (the return value) or the "unofficial demangled" version
+ of NAME (LOOKFOR, which it already knows). */
+
+char *
+demangle_and_match (name, lookfor, options)
+ const char *name;
+ const char *lookfor;
+ int options;
+{
+ char *demangled;
+
+ if ((demangled = cplus_demangle (name, options)) != NULL)
+ {
+ if (strcmp_iw (demangled, lookfor) != 0)
+ {
+ free (demangled);
+ demangled = NULL;
+ }
+ }
+ return (demangled);
+}
+
\f
void
_initialize_utils ()
/* These defaults will be used if we are unable to get the correct
values from termcap. */
+#if defined(__GO32__)
+ lines_per_page = ScreenRows();
+ chars_per_line = ScreenCols();
+#else
lines_per_page = 24;
chars_per_line = 80;
/* Initialize the screen height and width from termcap. */
}
}
+#if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
+
+ /* If there is a better way to determine the window size, use it. */
+ SIGWINCH_HANDLER ();
+#endif
+#endif
/* If the output is not a terminal, don't paginate it. */
if (!ISATTY (stdout))
lines_per_page = UINT_MAX;
&setprintlist),
&showprintlist);
}
+
+/* Machine specific function to handle SIGWINCH signal. */
+
+#ifdef SIGWINCH_HANDLER_BODY
+ SIGWINCH_HANDLER_BODY
+#endif