/* General utility routines for GDB, the GNU debugger.
- Copyright 1986, 1989, 1990, 1991, 1992, 1995 Free Software Foundation, Inc.
+ Copyright 1986, 89, 90, 91, 92, 95, 1996 Free Software Foundation, Inc.
This file is part of GDB.
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "defs.h"
-#if !defined(__GO32__) && !defined(__WIN32__) && !defined(MPW)
-#include <sys/ioctl.h>
-#include <sys/param.h>
-#include <pwd.h>
-#endif
#ifdef ANSI_PROTOTYPES
#include <stdarg.h>
#else
/* Prototypes for local functions */
-#if defined (NO_MMALLOC) || defined (NO_MMALLOC_CHECK)
-#else
+static void vfprintf_maybe_filtered PARAMS ((FILE *, const char *, va_list, int));
-static void
-malloc_botch PARAMS ((void));
+static void fputs_maybe_filtered PARAMS ((const char *, FILE *, int));
-#endif /* NO_MMALLOC, etc */
+#if !defined (NO_MMALLOC) && !defined (NO_MMCHECK)
+static void malloc_botch PARAMS ((void));
+#endif
static void
fatal_dump_core PARAMS((char *, ...));
/* ARGSUSED */
void
null_cleanup (arg)
- char **arg;
+ PTR arg;
{
}
fprintf_unfiltered (gdb_stderr, "\n");
va_end (args);
+#ifndef _WIN32
signal (SIGQUIT, SIG_DFL);
kill (getpid (), SIGQUIT);
+#endif
/* We should never get here, but just in case... */
exit (1);
}
}
-#if defined(__GO32__)||defined(WINGDB)
+#if defined(__GO32__) || defined(_WIN32)
/* In the absence of signals, poll keyboard for a quit.
Called from #define QUIT pollquit() in xm-go32.h. */
{
if (kbhit ())
{
+#ifndef _WIN32
int k = getkey ();
if (k == 1) {
quit_flag = 1;
/* We just ignore it */
fprintf_unfiltered (gdb_stderr, "CTRL-A to quit, CTRL-B to quit harder\n");
}
+#else
+ abort ();
+#endif
}
}
#endif
-#if defined(__GO32__)||defined(WINGDB)
+#if defined(__GO32__) || defined(_WIN32)
void notice_quit()
{
if (kbhit ())
{
+#ifndef _WIN32
int k = getkey ();
if (k == 1) {
quit_flag = 1;
{
fprintf_unfiltered (gdb_stderr, "CTRL-A to quit, CTRL-B to quit harder\n");
}
+#else
+ abort ();
+#endif
}
}
#else
\f
/* Memory management stuff (malloc friends). */
-#if defined (NO_MMALLOC)
-
/* Make a substitute size_t for non-ANSI compilers. */
-#ifdef _AIX
-#include <stddef.h>
-#else /* Not AIX */
-#ifndef __STDC__
+#ifndef HAVE_STDDEF_H
#ifndef size_t
#define size_t unsigned int
#endif
#endif
-#endif /* Not AIX */
+
+#if defined (NO_MMALLOC)
PTR
mmalloc (md, size)
#endif /* NO_MMALLOC */
-#if defined (NO_MMALLOC) || defined (NO_MMALLOC_CHECK)
+#if defined (NO_MMALLOC) || defined (NO_MMCHECK)
void
init_malloc (md)
{
}
-#else /* have mmalloc and want corruption checking */
+#else /* Have mmalloc and want corruption checking */
static void
malloc_botch ()
by MD, to detect memory corruption. Note that MD may be NULL to specify
the default heap that grows via sbrk.
- Note that for freshly created regions, we must call mmcheck prior to any
+ Note that for freshly created regions, we must call mmcheckf prior to any
mallocs in the region. Otherwise, any region which was allocated prior to
installing the checking hooks, which is later reallocated or freed, will
fail the checks! The mmcheck function only allows initial hooks to be
Returns zero on failure, non-zero on success. */
+#ifndef MMCHECK_FORCE
+#define MMCHECK_FORCE 0
+#endif
+
void
init_malloc (md)
PTR md;
{
- if (!mmcheck (md, malloc_botch))
+ if (!mmcheckf (md, malloc_botch, MMCHECK_FORCE))
{
- warning ("internal error: failed to install memory consistency checks");
+ /* Don't use warning(), which relies on current_target being set
+ to something other than dummy_target, until after
+ initialize_all_files(). */
+
+ fprintf_unfiltered
+ (gdb_stderr, "warning: failed to install memory consistency checks; ");
+ fprintf_unfiltered
+ (gdb_stderr, "configuration should define NO_MMCHECK or MMCHECK_FORCE\n");
}
mmtrace ();
PTR
xmalloc (size)
- long size;
+ size_t size;
{
return (xmmalloc ((PTR) NULL, size));
}
PTR
xrealloc (ptr, size)
PTR ptr;
- long size;
+ size_t size;
{
return (xmrealloc ((PTR) NULL, ptr, size));
}
static void
vfprintf_maybe_filtered (stream, format, args, filter)
FILE *stream;
- char *format;
+ const char *format;
va_list args;
int filter;
{
/* These defaults will be used if we are unable to get the correct
values from termcap. */
-#if defined(__GO32__) || defined(__WIN32__)
+#if defined(__GO32__)
lines_per_page = ScreenRows();
chars_per_line = ScreenCols();
#else
lines_per_page = 24;
chars_per_line = 80;
-#ifndef MPW
+#if !defined MPW && !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. */
SIGWINCH_HANDLER_BODY
#endif
\f
-#ifdef HAVE_LONG_DOUBLE
-/* Support for converting target fp numbers into host long double format. */
+/* Support for converting target fp numbers into host DOUBLEST format. */
/* XXX - This code should really be in libiberty/floatformat.c, however
configuration issues with libiberty made this very difficult to do in the
return result;
}
-/* Convert from FMT to a long double.
+/* Convert from FMT to a DOUBLEST.
FROM is the address of the extended float.
- Store the long double in *TO. */
+ Store the DOUBLEST in *TO. */
void
-floatformat_to_long_double (fmt, from, to)
+floatformat_to_doublest (fmt, from, to)
const struct floatformat *fmt;
char *from;
- long double *to;
+ DOUBLEST *to;
{
unsigned char *ufrom = (unsigned char *)from;
- long double dto;
+ DOUBLEST dto;
long exponent;
unsigned long mant;
unsigned int mant_bits, mant_off;
}
}
+#ifdef HAVE_LONG_DOUBLE
/* Return the fractional part of VALUE, and put the exponent of VALUE in *EPTR.
The range of the returned value is >= 0.5 and < 1.0. This is equivalent to
frexp, but operates on the long double data type. */
*eptr = exp;
return value/tmp;
}
+#endif /* HAVE_LONG_DOUBLE */
-/* The converse: convert the long double *FROM to an extended float
+
+/* The converse: convert the DOUBLEST *FROM to an extended float
and store where TO points. Neither FROM nor TO have any alignment
restrictions. */
void
-floatformat_from_long_double (fmt, from, to)
+floatformat_from_doublest (fmt, from, to)
CONST struct floatformat *fmt;
- long double *from;
+ DOUBLEST *from;
char *to;
{
- long double dfrom;
+ DOUBLEST dfrom;
int exponent;
- long double mant;
+ DOUBLEST mant;
unsigned int mant_bits, mant_off;
int mant_bits_left;
unsigned char *uto = (unsigned char *)to;
/* How to tell an infinity from an ordinary number? FIXME-someday */
+#ifdef HAVE_LONG_DOUBLE
mant = ldfrexp (dfrom, &exponent);
+#else
+ mant = frexp (dfrom, &exponent);
+#endif
+
put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start, fmt->exp_len,
exponent + fmt->exp_bias - 1);
if (mant_bits_left == fmt->man_len
&& fmt->intbit == floatformat_intbit_no)
{
- mant_long &= 0x7fffffff;
+ mant_long <<= 1;
mant_bits -= 1;
}
- else if (mant_bits < 32)
+
+ if (mant_bits < 32)
{
/* The bits we want are in the most significant MANT_BITS bits of
mant_long. Move them to the least significant. */
}
}
-#endif /* HAVE_LONG_DOUBLE */
+/* temporary storage using circular buffer */
+#define MAXCELLS 16
+#define CELLSIZE 32
+char*
+get_cell()
+{
+ static char buf[MAXCELLS][CELLSIZE];
+ static int cell=0;
+ if (++cell>MAXCELLS) cell=0;
+ return buf[cell];
+}
+
+/* print routines to handle variable size regs, etc */
+char*
+paddr(addr)
+ t_addr addr;
+{
+ char *paddr_str=get_cell();
+ switch (sizeof(t_addr))
+ {
+ case 8:
+ sprintf(paddr_str,"%08x%08x",
+ (unsigned long)(addr>>32),(unsigned long)(addr&0xffffffff));
+ break;
+ case 4:
+ sprintf(paddr_str,"%08x",(unsigned long)addr);
+ break;
+ case 2:
+ sprintf(paddr_str,"%04x",(unsigned short)(addr&0xffff));
+ break;
+ default:
+ sprintf(paddr_str,"%x",addr);
+ }
+ return paddr_str;
+}
+
+char*
+preg(reg)
+ t_reg reg;
+{
+ char *preg_str=get_cell();
+ switch (sizeof(t_reg))
+ {
+ case 8:
+ sprintf(preg_str,"%08x%08x",
+ (unsigned long)(reg>>32),(unsigned long)(reg&0xffffffff));
+ break;
+ case 4:
+ sprintf(preg_str,"%08x",(unsigned long)reg);
+ break;
+ case 2:
+ sprintf(preg_str,"%04x",(unsigned short)(reg&0xffff));
+ break;
+ default:
+ sprintf(preg_str,"%x",reg);
+ }
+ return preg_str;
+}
+