This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 1/8] Make internal_vproblem always work


internal_vproblem can be called (via malloc_failure) from almost the
first line of captured_main, but it will crash if called before the
first call to set_width.  This commit makes internal_vproblem work
at any time.

There are two parts to this.  If called before gdb_stderr is set up,
internal_vproblem will fall back to printing the message on regular
stderr and aborting.  If called after gdb_stderr is set up but before
filtered printing is set up, internal_vproblem will operate as usual
except that it can not query whether to quit and/or dump core so it
defaults to doing both.

gdb/
2014-08-05  Gary Benson  <gbenson@redhat.com>

	* utils.h (filtered_printing_initialized): New declaration.
	* utils.c (abort_with_message): New function.
	(internal_vproblem): Use abort_with_message for first level
	recursive internal problems, and if gdb_stderr is not set up.
	Protect calls to target_terminal_ours, begin_line and query.
---
 gdb/ChangeLog |    8 ++++++++
 gdb/utils.c   |   48 ++++++++++++++++++++++++++++++++++++++++--------
 gdb/utils.h   |    3 +++
 3 files changed, 51 insertions(+), 8 deletions(-)

diff --git a/gdb/utils.c b/gdb/utils.c
index 3f753bb..fce5baa 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -577,6 +577,19 @@ error_stream (struct ui_file *stream)
   error (("%s"), message);
 }
 
+/* Emit a message and abort.  */
+
+static void ATTRIBUTE_NORETURN
+abort_with_message (const char *msg)
+{
+  if (gdb_stderr == NULL)
+    fputs (msg, stderr);
+  else
+    fputs_unfiltered (msg, gdb_stderr);
+
+  abort ();		/* NOTE: GDB has only three calls to abort().  */
+}
+
 /* Dump core trying to increase the core soft limit to hard limit first.  */
 
 void
@@ -699,8 +712,7 @@ internal_vproblem (struct internal_problem *problem,
 	break;
       case 1:
 	dejavu = 2;
-	fputs_unfiltered (msg, gdb_stderr);
-	abort ();	/* NOTE: GDB has only three calls to abort().  */
+	abort_with_message (msg);
       default:
 	dejavu = 3;
         /* Newer GLIBC versions put the warn_unused_result attribute
@@ -714,10 +726,6 @@ internal_vproblem (struct internal_problem *problem,
       }
   }
 
-  /* Try to get the message out and at the start of a new line.  */
-  target_terminal_ours ();
-  begin_line ();
-
   /* Create a string containing the full error/warning message.  Need
      to call query with this full string, as otherwize the reason
      (error/warning) and question become separated.  Format using a
@@ -735,8 +743,23 @@ internal_vproblem (struct internal_problem *problem,
     make_cleanup (xfree, reason);
   }
 
+  /* Fall back to abort_with_message if gdb_stderr is not set up.  */
+  if (gdb_stderr == NULL)
+    {
+      fputs (reason, stderr);
+      abort_with_message ("\n");
+    }
+
+  /* Try to get the message out and at the start of a new line.  */
+  if (target_supports_terminal_ours ())
+    target_terminal_ours ();
+  if (filtered_printing_initialized ())
+    begin_line ();
+
   /* Emit the message unless query will emit it below.  */
-  if (problem->should_quit != internal_problem_ask || !confirm)
+  if (problem->should_quit != internal_problem_ask
+      || !confirm
+      || !filtered_printing_initialized ())
     fprintf_unfiltered (gdb_stderr, "%s\n", reason);
 
   if (problem->should_quit == internal_problem_ask)
@@ -744,7 +767,7 @@ internal_vproblem (struct internal_problem *problem,
       /* Default (yes/batch case) is to quit GDB.  When in batch mode
 	 this lessens the likelihood of GDB going into an infinite
 	 loop.  */
-      if (!confirm)
+      if (!confirm || !filtered_printing_initialized ())
 	quit_p = 1;
       else
         quit_p = query (_("%s\nQuit this debugging session? "), reason);
@@ -766,6 +789,8 @@ internal_vproblem (struct internal_problem *problem,
     {
       if (!can_dump_core_warn (LIMIT_MAX, reason))
 	dump_core_p = 0;
+      else if (!filtered_printing_initialized ())
+	dump_core_p = 1;
       else
 	{
 	  /* Default (yes/batch case) is to dump core.  This leaves a GDB
@@ -1738,6 +1763,13 @@ init_page_info (void)
   set_width ();
 }
 
+/* Return nonzero if filtered printing is initialized.  */
+int
+filtered_printing_initialized (void)
+{
+  return wrap_buffer != NULL;
+}
+
 /* Helper for make_cleanup_restore_page_info.  */
 
 static void
diff --git a/gdb/utils.h b/gdb/utils.h
index cc79562..0fddecb 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -245,6 +245,9 @@ extern void fputstrn_filtered (const char *str, int n, int quotr,
 extern void fputstrn_unfiltered (const char *str, int n, int quotr,
 				 struct ui_file * stream);
 
+/* Return nonzero if filtered printing is initialized.  */
+extern int filtered_printing_initialized (void);
+
 /* Display the host ADDR on STREAM formatted as ``0x%x''.  */
 extern void gdb_print_host_address (const void *addr, struct ui_file *stream);
 
-- 
1.7.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]