aboutsummaryrefslogtreecommitdiff
path: root/gdb/utils.c
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2017-08-06 21:45:08 +0100
committerAndrew Burgess <andrew.burgess@embecosm.com>2017-09-10 09:49:34 +0100
commit72542b8ee6558677bed21dd880b68dc2e541c9c7 (patch)
tree9018fec49285f23109dfbf4a3ea9465ee18f5eac /gdb/utils.c
parent502b834c1a6712d9bbe0beba98727c8365429cd2 (diff)
downloadbinutils-72542b8ee6558677bed21dd880b68dc2e541c9c7.zip
binutils-72542b8ee6558677bed21dd880b68dc2e541c9c7.tar.gz
binutils-72542b8ee6558677bed21dd880b68dc2e541c9c7.tar.bz2
gdb: Remove check for gdb_stderr == NULL
Recent changes made gdb_stderr a macro: #define gdb_stderr (*current_ui_gdb_stderr_ptr ()) and current_ui_gdb_stderr_ptr return this: &current_ui->m_gdb_stderr The problem is that this is undefined if current_ui is NULL, which can happen early on during gdb start up. If we run into an error during early gdb start up then we write the error message to gdb_stderr. However, if we are too early during the start up then current_ui is NULL, and using the gdb_stderr macro triggers undefined behaviour. We try to avoid this using a check 'gdb_stderr == NULL' which was fine before the recent changes, but now, still triggers undefined behaviour. A better check is instead 'current_ui == NULL' which is what I use in this patch. Triggering this failure is pretty hard, most of the really early errors are only triggered if pretty basic things are not as expected, for example, if the default signal handlers are not as expected. Seeing one of these errors trigger usually means that someone working on gdb has made an incorrect change. Still, the errors are present in gdb, and should we ever trigger one it would be nice if gdb didn't crash. For testing this change I've been applying this patch which adds an unconditional error into a function called early during gdb start up. Later in the same function is a real error call which, in some circumstances could be triggered: ## START ## diff --git a/gdb/common/signals-state-save-restore.c b/gdb/common/signals-state-save-restore.c index d11a9ae006c..d75ba70f894 100644 --- a/gdb/common/signals-state-save-restore.c +++ b/gdb/common/signals-state-save-restore.c @@ -37,6 +37,9 @@ static sigset_t original_signal_mask; void save_original_signals_state (void) { + + internal_error (__FILE__, __LINE__, "example error"); + #ifdef HAVE_SIGACTION int i; int res; ## END ## gdb/ChangeLog: * utils.c (abort_with_message): Don't compare gdb_stderr to NULL, check current_ui instead. (internal_vproblem): Likewise.
Diffstat (limited to 'gdb/utils.c')
-rw-r--r--gdb/utils.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/gdb/utils.c b/gdb/utils.c
index a7a97e2..b709af9 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -316,7 +316,7 @@ error_stream (const string_file &stream)
static void ATTRIBUTE_NORETURN
abort_with_message (const char *msg)
{
- if (gdb_stderr == NULL)
+ if (current_ui == NULL)
fputs (msg, stderr);
else
fputs_unfiltered (msg, gdb_stderr);
@@ -478,7 +478,7 @@ internal_vproblem (struct internal_problem *problem,
}
/* Fall back to abort_with_message if gdb_stderr is not set up. */
- if (gdb_stderr == NULL)
+ if (current_ui == NULL)
{
fputs (reason, stderr);
abort_with_message ("\n");