From 20f0d60db4fb5083779c4c9182bbc692f7d2bac5 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 5 Oct 2018 14:54:35 -0600 Subject: Avoid crash when calling warning too early I noticed that if you pass the name of an existing file (not a directory) as the argument to --data-directory, gdb will crash: $ ./gdb -nx --data-directory ./gdb ../../binutils-gdb/gdb/target.c:590:56: runtime error: member call on null pointer of type 'struct target_ops' This was later reported as PR gdb/23838. This happens because warning ends up calling target_supports_terminal_ours, which calls current_top_target, which returns nullptr this early. This fixes the problem by handling this case specially in target_supports_terminal_ours. I also changed target_supports_terminal_ours to return bool. gdb/ChangeLog 2018-11-08 Tom Tromey PR gdb/23555: PR gdb/23838: * target.h (target_supports_terminal_ours): Return bool. * target.c (target_supports_terminal_ours): Handle case where current_top_target returns nullptr. Return bool. gdb/testsuite/ChangeLog 2018-11-08 Tom Tromey PR gdb/23555: PR gdb/23838: * gdb.base/warning.exp: New file. --- gdb/target.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gdb/target.h') diff --git a/gdb/target.h b/gdb/target.h index a3000c8..6f4b73b 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -1577,7 +1577,7 @@ extern int target_remove_breakpoint (struct gdbarch *gdbarch, /* Return true if the target stack has a non-default "terminal_ours" method. */ -extern int target_supports_terminal_ours (void); +extern bool target_supports_terminal_ours (void); /* Kill the inferior process. Make it go away. */ -- cgit v1.1