From: Gary Benson <gbenson@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/8] Make internal_vproblem always work
Date: Wed, 06 Aug 2014 10:34:00 -0000 [thread overview]
Message-ID: <1407319948-2264-2-git-send-email-gbenson@redhat.com> (raw)
In-Reply-To: <1407319948-2264-1-git-send-email-gbenson@redhat.com>
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
next prev parent reply other threads:[~2014-08-06 10:34 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-06 10:12 [PATCH 0/8] Error handling cleanups Gary Benson
2014-08-06 10:12 ` [PATCH 2/8] Make error usable earlier Gary Benson
2014-08-06 10:12 ` [PATCH 8/8] Unify startup and option-parsing warnings Gary Benson
2014-08-06 10:12 ` [PATCH 4/8] Replace hardwired error handlers in tui_initialize_io Gary Benson
2014-08-06 10:12 ` [PATCH 3/8] Make warning usable earlier Gary Benson
2014-08-06 10:25 ` [PATCH 5/8] Replace hardwired error handler in captured_main Gary Benson
2014-08-06 10:25 ` [PATCH 7/8] Replace all usage errors with calls to error Gary Benson
2014-08-06 10:34 ` Gary Benson [this message]
2014-08-06 10:52 ` [PATCH 6/8] Replace hardwired error handler in go32_create_inferior Gary Benson
2014-08-06 16:59 ` Eli Zaretskii
2014-08-08 11:38 ` Gary Benson
2014-08-28 14:09 ` [PATCH 0/8] Error handling cleanups Pedro Alves
2014-08-29 9:19 ` [COMMITTED PATCH " Gary Benson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1407319948-2264-2-git-send-email-gbenson@redhat.com \
--to=gbenson@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox