Fix bug reported and analyzed by Olivier Crete:
[deliverable/binutils-gdb.git] / gdb / utils.c
index 504890ebf154137963c6d1d3de0242ce20b25dd1..10c40c710d35b90de285478f5b88e76ba12bf329 100644 (file)
@@ -51,6 +51,7 @@
 #include "charset.h"
 #include "annotate.h"
 #include "filenames.h"
+#include "symfile.h"
 
 #include "inferior.h"          /* for signed_pointer_to_address */
 
@@ -260,6 +261,19 @@ make_cleanup_ui_file_delete (struct ui_file *arg)
   return make_my_cleanup (&cleanup_chain, do_ui_file_delete, arg);
 }
 
+static void
+do_free_section_addr_info (void *arg)
+{
+  free_section_addr_info (arg);
+}
+
+struct cleanup *
+make_cleanup_free_section_addr_info (struct section_addr_info *addrs)
+{
+  return make_my_cleanup (&cleanup_chain, do_free_section_addr_info, addrs);
+}
+
+
 struct cleanup *
 make_my_cleanup (struct cleanup **pmy_chain, make_cleanup_ftype *function,
                 void *arg)
@@ -752,8 +766,8 @@ internal_vproblem (struct internal_problem *problem,
      so that the user knows that they are living on the edge.  */
   {
     char *msg;
-    xvasprintf (&msg, fmt, ap);
-    xasprintf (&reason, "\
+    msg = xstrvprintf (fmt, ap);
+    reason = xstrprintf ("\
 %s:%d: %s: %s\n\
 A problem internal to GDB has been detected,\n\
 further debugging may prove unreliable.", file, line, problem->name, msg);
@@ -838,7 +852,7 @@ internal_error (const char *file, int line, const char *string, ...)
 }
 
 static struct internal_problem internal_warning_problem = {
-  "internal-error", AUTO_BOOLEAN_AUTO, AUTO_BOOLEAN_AUTO
+  "internal-warning", AUTO_BOOLEAN_AUTO, AUTO_BOOLEAN_AUTO
 };
 
 void
@@ -974,51 +988,14 @@ void
 request_quit (int signo)
 {
   quit_flag = 1;
-  /* Restore the signal handler.  Harmless with BSD-style signals, needed
-     for System V-style signals.  So just always do it, rather than worrying
-     about USG defines and stuff like that.  */
+  /* Restore the signal handler.  Harmless with BSD-style signals,
+     needed for System V-style signals.  */
   signal (signo, request_quit);
 
   if (immediate_quit)
     quit ();
 }
 \f
-/* Memory management stuff (malloc friends).  */
-
-static void *
-mmalloc (void *md, size_t size)
-{
-  return malloc (size);                /* NOTE: GDB's only call to malloc() */
-}
-
-static void *
-mrealloc (void *md, void *ptr, size_t size)
-{
-  if (ptr == 0)                        /* Guard against old realloc's */
-    return mmalloc (md, size);
-  else
-    return realloc (ptr, size);        /* NOTE: GDB's only call to ralloc() */
-}
-
-static void *
-mcalloc (void *md, size_t number, size_t size)
-{
-  return calloc (number, size);        /* NOTE: GDB's only call to calloc() */
-}
-
-static void
-mfree (void *md, void *ptr)
-{
-  free (ptr);                  /* NOTE: GDB's only call to free() */
-}
-
-/* This used to do something interesting with USE_MMALLOC.
- * It can be retired any time.  -- chastain 2004-01-19.  */
-void
-init_malloc (void *md)
-{
-}
-
 /* Called when a memory allocation fails, with the number of bytes of
    memory requested in SIZE. */
 
@@ -1037,18 +1014,17 @@ nomem (long size)
     }
 }
 
-/* The xmmalloc() family of memory management routines.
+/* The xmalloc() (libiberty.h) family of memory management routines.
 
-   These are are like the mmalloc() family except that they implement
+   These are like the ISO-C malloc() 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.
+   problems.  */
 
-   All these routines are implemented using the mmalloc() family. */
+/* NOTE: These are declared using PTR to ensure consistency with
+   "libiberty.h".  xfree() is GDB local.  */
 
-void *
-xmmalloc (void *md, size_t size)
+PTR                            /* OK: PTR */
+xmalloc (size_t size)
 {
   void *val;
 
@@ -1057,15 +1033,15 @@ xmmalloc (void *md, size_t size)
   if (size == 0)
     size = 1;
 
-  val = mmalloc (md, size);
+  val = malloc (size);         /* OK: malloc */
   if (val == NULL)
     nomem (size);
 
   return (val);
 }
 
-void *
-xmrealloc (void *md, void *ptr, size_t size)
+PTR                            /* OK: PTR */
+xrealloc (PTR ptr, size_t size)        /* OK: PTR */
 {
   void *val;
 
@@ -1075,17 +1051,17 @@ xmrealloc (void *md, void *ptr, size_t size)
     size = 1;
 
   if (ptr != NULL)
-    val = mrealloc (md, ptr, size);
+    val = realloc (ptr, size); /* OK: realloc */
   else
-    val = mmalloc (md, size);
+    val = malloc (size);               /* OK: malloc */
   if (val == NULL)
     nomem (size);
 
   return (val);
 }
 
-void *
-xmcalloc (void *md, size_t number, size_t size)
+PTR                            /* OK: PTR */
+xcalloc (size_t number, size_t size)
 {
   void *mem;
 
@@ -1097,53 +1073,18 @@ xmcalloc (void *md, size_t number, size_t size)
       size = 1;
     }
 
-  mem = mcalloc (md, number, size);
+  mem = calloc (number, size);         /* OK: xcalloc */
   if (mem == NULL)
     nomem (number * size);
 
   return mem;
 }
 
-void
-xmfree (void *md, void *ptr)
-{
-  if (ptr != NULL)
-    mfree (md, ptr);
-}
-
-/* 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                            /* OK: PTR */
-xmalloc (size_t size)
-{
-  return xmmalloc (NULL, size);
-}
-
-PTR                            /* OK: PTR */
-xrealloc (PTR ptr, size_t size)        /* OK: PTR */
-{
-  return xmrealloc (NULL, ptr, size);
-}
-
-PTR                            /* OK: PTR */
-xcalloc (size_t number, size_t size)
-{
-  return xmcalloc (NULL, number, size);
-}
-
 void
 xfree (void *ptr)
 {
-  xmfree (NULL, ptr);
+  if (ptr != NULL)
+    free (ptr);                /* OK: free */
 }
 \f
 
@@ -1156,7 +1097,7 @@ xstrprintf (const char *format, ...)
   char *ret;
   va_list args;
   va_start (args, format);
-  xvasprintf (&ret, format, args);
+  ret = xstrvprintf (format, args);
   va_end (args);
   return ret;
 }
@@ -1166,27 +1107,32 @@ xasprintf (char **ret, const char *format, ...)
 {
   va_list args;
   va_start (args, format);
-  xvasprintf (ret, format, args);
+  (*ret) = xstrvprintf (format, args);
   va_end (args);
 }
 
 void
 xvasprintf (char **ret, const char *format, va_list ap)
 {
-  int status = vasprintf (ret, format, ap);
-  /* NULL could be returned due to a memory allocation problem; a
-     badly format string; or something else. */
-  if ((*ret) == NULL)
-    internal_error (__FILE__, __LINE__,
-                   "vasprintf returned NULL buffer (errno %d)", errno);
-  /* A negative status with a non-NULL buffer shouldn't never
-     happen. But to be sure. */
+  (*ret) = xstrvprintf (format, ap);
+}
+
+char *
+xstrvprintf (const char *format, va_list ap)
+{
+  char *ret = NULL;
+  int status = vasprintf (&ret, format, ap);
+  /* NULL is returned when there was a memory allocation problem.  */
+  if (ret == NULL)
+    nomem (0);
+  /* A negative status (the printed length) with a non-NULL buffer
+     should never happen, but just to be sure.  */
   if (status < 0)
     internal_error (__FILE__, __LINE__,
                    "vasprintf call failed (errno %d)", errno);
+  return ret;
 }
 
-
 /* My replacement for the read system call.
    Used like `read' but keeps going if `read' returns too soon.  */
 
@@ -1225,7 +1171,7 @@ savestring (const char *ptr, size_t size)
 char *
 msavestring (void *md, const char *ptr, size_t size)
 {
-  char *p = (char *) xmmalloc (md, size + 1);
+  char *p = (char *) xmalloc (size + 1);
   memcpy (p, ptr, size);
   p[size] = 0;
   return p;
@@ -2260,7 +2206,7 @@ vfprintf_maybe_filtered (struct ui_file *stream, const char *format,
   char *linebuffer;
   struct cleanup *old_cleanups;
 
-  xvasprintf (&linebuffer, format, args);
+  linebuffer = xstrvprintf (format, args);
   old_cleanups = make_cleanup (xfree, linebuffer);
   fputs_maybe_filtered (linebuffer, stream, filter);
   do_cleanups (old_cleanups);
@@ -2279,7 +2225,7 @@ vfprintf_unfiltered (struct ui_file *stream, const char *format, va_list args)
   char *linebuffer;
   struct cleanup *old_cleanups;
 
-  xvasprintf (&linebuffer, format, args);
+  linebuffer = xstrvprintf (format, args);
   old_cleanups = make_cleanup (xfree, linebuffer);
   fputs_unfiltered (linebuffer, stream);
   do_cleanups (old_cleanups);
@@ -2610,23 +2556,23 @@ initialize_utils (void)
   c = add_set_cmd ("width", class_support, var_uinteger, &chars_per_line,
                   "Set number of characters gdb thinks are in a line.",
                   &setlist);
-  add_show_from_set (c, &showlist);
+  deprecated_add_show_from_set (c, &showlist);
   set_cmd_sfunc (c, set_width_command);
 
   c = add_set_cmd ("height", class_support, var_uinteger, &lines_per_page,
                   "Set number of lines gdb thinks are in a page.", &setlist);
-  add_show_from_set (c, &showlist);
+  deprecated_add_show_from_set (c, &showlist);
   set_cmd_sfunc (c, set_height_command);
 
   init_page_info ();
 
-  add_show_from_set
+  deprecated_add_show_from_set
     (add_set_cmd ("demangle", class_support, var_boolean,
                  (char *) &demangle,
                  "Set demangling of encoded C++/ObjC names when displaying symbols.",
                  &setprintlist), &showprintlist);
 
-  add_show_from_set
+  deprecated_add_show_from_set
     (add_set_cmd ("pagination", class_support,
                  var_boolean, (char *) &pagination_enabled,
                  "Set state of pagination.", &setlist), &showlist);
@@ -2639,13 +2585,13 @@ initialize_utils (void)
               "Disable pagination");
     }
 
-  add_show_from_set
+  deprecated_add_show_from_set
     (add_set_cmd ("sevenbit-strings", class_support, var_boolean,
                  (char *) &sevenbit_strings,
                  "Set printing of 8-bit characters in strings as \\nnn.",
                  &setprintlist), &showprintlist);
 
-  add_show_from_set
+  deprecated_add_show_from_set
     (add_set_cmd ("asm-demangle", class_support, var_boolean,
                  (char *) &asm_demangle,
                  "Set demangling of C++/ObjC names in disassembly listings.",
This page took 0.027859 seconds and 4 git commands to generate.