Boston, MA 02111-1307, USA. */
#include "defs.h"
+#include "gdb_assert.h"
#include <ctype.h>
#include "gdb_string.h"
#include "event-top.h"
#include <readline/readline.h>
+#ifndef MALLOC_INCOMPATIBLE
+#ifdef NEED_DECLARATION_MALLOC
+extern PTR malloc ();
+#endif
+#ifdef NEED_DECLARATION_REALLOC
+extern PTR realloc ();
+#endif
+#ifdef NEED_DECLARATION_FREE
+extern void free ();
+#endif
+#endif
+
#undef XMALLOC
#define XMALLOC(TYPE) ((TYPE*) xmalloc (sizeof (TYPE)))
\f
/* Memory management stuff (malloc friends). */
-/* Make a substitute size_t for non-ANSI compilers. */
-
-#ifndef HAVE_STDDEF_H
-#ifndef size_t
-#define size_t unsigned int
-#endif
-#endif
-
#if !defined (USE_MMALLOC)
-PTR
-mcalloc (PTR md, size_t number, size_t size)
-{
- return calloc (number, size);
-}
+/* NOTE: These must use PTR so that their definition matches the
+ declaration found in "mmalloc.h". */
PTR
mmalloc (PTR md, size_t size)
{
- return malloc (size);
+ return malloc (size); /* NOTE: GDB's only call to malloc() */
}
PTR
mrealloc (PTR md, PTR ptr, size_t size)
{
if (ptr == 0) /* Guard against old realloc's */
- return malloc (size);
+ return mmalloc (md, size);
else
- return realloc (ptr, size);
+ return realloc (ptr, size); /* NOTE: GDB's only call to ralloc() */
+}
+
+PTR
+mcalloc (PTR md, size_t number, size_t size)
+{
+ return calloc (number, size); /* NOTE: GDB's only call to calloc() */
}
void
mfree (PTR md, PTR ptr)
{
- xfree (ptr);
+ free (ptr); /* NOTE: GDB's only call to free() */
}
#endif /* USE_MMALLOC */
}
}
-/* Like mmalloc but get error if no storage available, and protect against
- the caller wanting to allocate zero bytes. Whether to return NULL for
- a zero byte request, or translate the request into a request for one
- byte of zero'd storage, is a religious issue. */
+/* The xmmalloc() family of memory management routines.
-PTR
-xmmalloc (PTR md, long size)
+ These are are like the mmalloc() family except that they implement
+ consistent semantics and guard against typical memory management
+ problems: if a malloc fails, an internal error is thrown; if
+ free(NULL) is called, it is ignored; if *alloc(0) is called, NULL
+ is returned.
+
+ All these routines are implemented using the mmalloc() family. */
+
+void *
+xmmalloc (void *md, size_t size)
{
- register PTR val;
+ void *val;
if (size == 0)
{
val = NULL;
}
- else if ((val = mmalloc (md, size)) == NULL)
+ else
{
- nomem (size);
+ val = mmalloc (md, size);
+ if (val == NULL)
+ nomem (size);
}
return (val);
}
-/* Like mrealloc but get error if no storage available. */
-
-PTR
-xmrealloc (PTR md, PTR ptr, long size)
+void *
+xmrealloc (void *md, void *ptr, size_t size)
{
- register PTR val;
+ void *val;
- if (ptr != NULL)
+ if (size == 0)
{
- val = mrealloc (md, ptr, size);
+ if (ptr != NULL)
+ mfree (md, ptr);
+ val = NULL;
}
else
{
- val = mmalloc (md, size);
- }
- if (val == NULL)
- {
- nomem (size);
+ if (ptr != NULL)
+ {
+ val = mrealloc (md, ptr, size);
+ }
+ else
+ {
+ val = mmalloc (md, size);
+ }
+ if (val == NULL)
+ {
+ nomem (size);
+ }
}
return (val);
}
-/* Like malloc but get error if no storage available, and protect against
- the caller wanting to allocate zero bytes. */
+void *
+xmcalloc (void *md, size_t number, size_t size)
+{
+ void *mem;
+ if (number == 0 || size == 0)
+ mem = NULL;
+ else
+ {
+ mem = mcalloc (md, number, size);
+ if (mem == NULL)
+ nomem (number * size);
+ }
+ return mem;
+}
-PTR
-xmalloc (size_t size)
+void
+xmfree (void *md, void *ptr)
{
- return (xmmalloc ((PTR) NULL, size));
+ if (ptr != NULL)
+ mfree (md, ptr);
}
-/* Like calloc but get error if no storage available */
+/* The xmalloc() (libiberty.h) family of memory management routines.
+
+ These are like the ISO-C malloc() family except that they implement
+ consistent semantics and guard against typical memory management
+ problems. See xmmalloc() above for further information.
+
+ All these routines are wrappers to the xmmalloc() family. */
+
+/* NOTE: These are declared using PTR to ensure consistency with
+ "libiberty.h". xfree() is GDB local. */
PTR
-xcalloc (size_t number, size_t size)
+xmalloc (size_t size)
{
- void *mem = mcalloc (NULL, number, size);
- if (mem == NULL)
- nomem (number * size);
- return mem;
+ return xmmalloc (NULL, size);
}
-/* Like mrealloc but get error if no storage available. */
-
PTR
xrealloc (PTR ptr, size_t size)
{
- return (xmrealloc ((PTR) NULL, ptr, size));
+ return xmrealloc (NULL, ptr, size);
}
-/* Free up space allocated by one of xmalloc(), xcalloc(), or
- xrealloc(). */
+PTR
+xcalloc (size_t number, size_t size)
+{
+ return xmcalloc (NULL, number, size);
+}
void
xfree (void *ptr)
{
- if (ptr != NULL)
- free (ptr);
+ xmfree (NULL, ptr);
}
\f
/* Automatically answer "yes" if input is not from a terminal. */
if (!input_from_terminal_p ())
return 1;
-#ifdef MPW
- /* FIXME Automatically answer "yes" if called from MacGDB. */
- if (mac_app)
- return 1;
-#endif /* MPW */
+ /* OBSOLETE #ifdef MPW */
+ /* OBSOLETE *//* FIXME Automatically answer "yes" if called from MacGDB. */
+ /* OBSOLETE if (mac_app) */
+ /* OBSOLETE return 1; */
+ /* OBSOLETE #endif *//* MPW */
while (1)
{
if (annotation_level > 1)
printf_filtered ("\n\032\032query\n");
-#ifdef MPW
- /* If not in MacGDB, move to a new line so the entered line doesn't
- have a prompt on the front of it. */
- if (!mac_app)
- fputs_unfiltered ("\n", gdb_stdout);
-#endif /* MPW */
+ /* OBSOLETE #ifdef MPW */
+ /* OBSOLETE *//* If not in MacGDB, move to a new line so the entered line doesn't */
+ /* OBSOLETE have a prompt on the front of it. */
+ /* OBSOLETE if (!mac_app) */
+ /* OBSOLETE fputs_unfiltered ("\n", gdb_stdout); */
+ /* OBSOLETE #endif *//* MPW */
wrap_here ("");
gdb_flush (gdb_stdout);
lines_per_page = 24;
chars_per_line = 80;
-#if !defined (MPW) && !defined (_WIN32)
+#if !defined (_WIN32)
/* No termcap under MPW, although might be cool to do something
by looking at worksheet or console window sizes. */
/* Initialize the screen height and width from termcap. */
}
}
+/* Check if VAL (which is assumed to be a floating point number whose
+ format is described by FMT) is negative. */
+
+int
+floatformat_is_negative (const struct floatformat *fmt, char *val)
+{
+ unsigned char *uval = (unsigned char *) val;
+
+ return get_field (uval, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1);
+}
+
+/* Check if VAL is "not a number" (NaN) for FMT. */
+
+int
+floatformat_is_nan (const struct floatformat *fmt, char *val)
+{
+ unsigned char *uval = (unsigned char *) val;
+ long exponent;
+ unsigned long mant;
+ unsigned int mant_bits, mant_off;
+ int mant_bits_left;
+
+ if (! fmt->exp_nan)
+ return 0;
+
+ exponent = get_field (uval, fmt->byteorder, fmt->totalsize,
+ fmt->exp_start, fmt->exp_len);
+
+ if (exponent != fmt->exp_nan)
+ return 0;
+
+ mant_bits_left = fmt->man_len;
+ mant_off = fmt->man_start;
+
+ while (mant_bits_left > 0)
+ {
+ mant_bits = min (mant_bits_left, 32);
+
+ mant = get_field (uval, fmt->byteorder, fmt->totalsize,
+ mant_off, mant_bits);
+
+ /* If there is an explicit integer bit, mask it off. */
+ if (mant_off == fmt->man_start
+ && fmt->intbit == floatformat_intbit_yes)
+ mant &= ~(1 << (mant_bits - 1));
+
+ if (mant)
+ return 1;
+
+ mant_off += mant_bits;
+ mant_bits_left -= mant_bits;
+ }
+
+ return 0;
+}
+
+/* Convert the mantissa of VAL (which is assumed to be a floating
+ point number whose format is described by FMT) into a hexadecimal
+ and store it in a static string. Return a pointer to that string. */
+
+char *
+floatformat_mantissa (const struct floatformat *fmt, char *val)
+{
+ unsigned char *uval = (unsigned char *) val;
+ unsigned long mant;
+ unsigned int mant_bits, mant_off;
+ int mant_bits_left;
+ static char res[50];
+ char buf[9];
+
+ /* Make sure we have enough room to store the mantissa. */
+ gdb_assert (sizeof res > ((fmt->man_len + 7) / 8) * 2);
+
+ mant_off = fmt->man_start;
+ mant_bits_left = fmt->man_len;
+ mant_bits = (mant_bits_left % 32) > 0 ? mant_bits_left % 32 : 32;
+
+ mant = get_field (uval, fmt->byteorder, fmt->totalsize,
+ mant_off, mant_bits);
+
+ sprintf (res, "%lx", mant);
+
+ mant_off += mant_bits;
+ mant_bits_left -= mant_bits;
+
+ while (mant_bits_left > 0)
+ {
+ mant = get_field (uval, fmt->byteorder, fmt->totalsize,
+ mant_off, 32);
+
+ sprintf (buf, "%08lx", mant);
+ strcat (res, buf);
+
+ mant_off += 32;
+ mant_bits_left -= 32;
+ }
+
+ return res;
+}
+
/* print routines to handle variable size regs, etc. */
/* temporary storage using circular buffer */