Add __FILE__ and __LINE__ parameter to internal_error() /
[deliverable/binutils-gdb.git] / gdb / utils.c
index 9cfdd3f24581c3e99cc09d2f728cd11b5bf6fcd3..0d2595a050a6209ab2981918703ab41f7b54a7ef 100644 (file)
@@ -40,7 +40,7 @@
 #undef reg
 #endif
 
-#include "signals.h"
+#include <signal.h>
 #include "gdbcmd.h"
 #include "serial.h"
 #include "bfd.h"
@@ -215,14 +215,17 @@ make_cleanup_bfd_close (bfd *abfd)
 static void
 do_close_cleanup (void *arg)
 {
-  close ((int) arg);
+  int *fd = arg;
+  close (*fd);
+  xfree (fd);
 }
 
 struct cleanup *
 make_cleanup_close (int fd)
 {
-  /* int into void*. Outch!! */
-  return make_cleanup (do_close_cleanup, (void *) fd);
+  int *saved_fd = xmalloc (sizeof (fd));
+  *saved_fd = fd;
+  return make_cleanup (do_close_cleanup, saved_fd);
 }
 
 static void
@@ -386,7 +389,8 @@ free_current_contents (void *ptr)
 {
   void **location = ptr;
   if (location == NULL)
-    internal_error ("free_current_contents: NULL pointer");
+    internal_error (__FILE__, __LINE__,
+                   "free_current_contents: NULL pointer");
   if (*location != NULL)
     {
       xfree (*location);
@@ -667,7 +671,8 @@ error_init (void)
    want to continue, dump core, or just exit. */
 
 NORETURN void
-internal_verror (const char *fmt, va_list ap)
+internal_verror (const char *file, int line,
+                const char *fmt, va_list ap)
 {
   static char msg[] = "Internal GDB error: recursive internal error.\n";
   static int dejavu = 0;
@@ -692,7 +697,7 @@ internal_verror (const char *fmt, va_list ap)
 
   /* Try to get the message out */
   target_terminal_ours ();
-  fputs_unfiltered ("gdb-internal-error: ", gdb_stderr);
+  fprintf_unfiltered (gdb_stderr, "%s:%d: gdb-internal-error: ", file, line);
   vfprintf_unfiltered (gdb_stderr, fmt, ap);
   fputs_unfiltered ("\n", gdb_stderr);
 
@@ -728,12 +733,12 @@ Create a core file containing the current state of GDB? ");
 }
 
 NORETURN void
-internal_error (char *string, ...)
+internal_error (const char *file, int line, const char *string, ...)
 {
   va_list ap;
   va_start (ap, string);
 
-  internal_verror (string, ap);
+  internal_verror (file, line, string, ap);
   va_end (ap);
 }
 
@@ -999,11 +1004,13 @@ nomem (long size)
 {
   if (size > 0)
     {
-      internal_error ("virtual memory exhausted: can't allocate %ld bytes.", size);
+      internal_error (__FILE__, __LINE__,
+                     "virtual memory exhausted: can't allocate %ld bytes.", size);
     }
   else
     {
-      internal_error ("virtual memory exhausted.");
+      internal_error (__FILE__, __LINE__,
+                     "virtual memory exhausted.");
     }
 }
 
@@ -1108,13 +1115,15 @@ xvasprintf (char **ret, const char *format, va_list ap)
   /* NULL could be returned due to a memory allocation problem; a
      badly format string; or something else. */
   if ((*ret) == NULL)
-    internal_error ("%s:%d: vasprintf returned NULL buffer (errno %d)",
-                   __FILE__, __LINE__, errno);
+    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. */
   if (status < 0)
-    internal_error ("%s:%d: vasprintf call failed (errno %d)",
-                   __FILE__, __LINE__, errno);
+    internal_error (__FILE__, __LINE__,
+                   "vasprintf call failed (errno %d)",
+                   errno);
 }
 
 
@@ -1857,6 +1866,15 @@ putchar_unfiltered (int c)
   return c;
 }
 
+/* Write character C to gdb_stdout using GDB's paging mechanism and return C.
+   May return nonlocally.  */
+
+int
+putchar_filtered (int c)
+{
+  return fputc_filtered (c, gdb_stdout);
+}
+
 int
 fputc_unfiltered (int c, struct ui_file *stream)
 {
@@ -2870,7 +2888,8 @@ CORE_ADDR
 host_pointer_to_address (void *ptr)
 {
   if (sizeof (ptr) != TYPE_LENGTH (builtin_type_ptr))
-    internal_error ("core_addr_to_void_ptr: bad cast");
+    internal_error (__FILE__, __LINE__,
+                   "core_addr_to_void_ptr: bad cast");
   return POINTER_TO_ADDRESS (builtin_type_ptr, &ptr);
 }
 
@@ -2879,7 +2898,8 @@ address_to_host_pointer (CORE_ADDR addr)
 {
   void *ptr;
   if (sizeof (ptr) != TYPE_LENGTH (builtin_type_ptr))
-    internal_error ("core_addr_to_void_ptr: bad cast");
+    internal_error (__FILE__, __LINE__,
+                   "core_addr_to_void_ptr: bad cast");
   ADDRESS_TO_POINTER (builtin_type_ptr, &ptr, addr);
   return ptr;
 }
This page took 0.025007 seconds and 4 git commands to generate.