Re: [PATCH v2] Avoid crash when calling warning too early

Pedro Alves
2018-11-19T15:27:49Z

On 11/18/2018 06:46 PM, Tom Tromey wrote:
>>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
>
> Pedro> Hmm, by using gdb_spawn directly, or better, gdb_spawn_with_cmdline_opts
> Pedro> instead of gdb_start?
>
> [...]
>
> Pedro> So, WDYT of this version?
>
> Look good to me, thanks.
>
I've pushed it in now.

From 6769f2765db0d94eeb8437b41a925e2bd871f514 Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Mon, 19 Nov 2018 15:08:46 +0000
Subject: [PATCH] gdb.base/warning.exp tweaks

#1- Check that the warning is emitted.

#2- Avoid overriding INTERNAL_GDBFLAGS, as per documentated in
gdb/testsuite/README:

~~~
The testsuite does not override a value provided by the user.
~~~

We don't actually need to tweak INTERNAL_GDBFLAGS, we just need to
append out -data-directory to GDBFLAGS, because each passed
-data-directory option leads to a call to the warning:

$ ./gdb -data-directory=foo -data-directory=bar
Warning: foo: No such file or directory.
Warning: bar: No such file or directory.
[...]

gdb/ChangeLog
2018-11-19 Pedro Alves <palves@redhat.com>

* gdb.base/warning.exp: Don't override INTERNAL_FLAGS. Use
gdb_spawn_with_cmdline_opts instead of gdb_start. Check that we
see the expected warning.
---
gdb/testsuite/ChangeLog | 6 ++++++
gdb/testsuite/gdb.base/warning.exp | 10 +++++-----
2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index c0de6f2d6c..9acaa79e2b 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2018-11-19 Pedro Alves <palves@redhat.com>
+
+ * gdb.base/warning.exp: Don't override INTERNAL_FLAGS. Use
+ gdb_spawn_with_cmdline_opts instead of gdb_start. Check that we
+ see the expected warning.
+
2018-11-16 Alan Hayward <alan.hayward@arm.com>

PR gdb/22736:
diff --git a/gdb/testsuite/gdb.base/warning.exp b/gdb/testsuite/gdb.base/warning.exp
index 53067f48d5..134218acb9 100644
--- a/gdb/testsuite/gdb.base/warning.exp
+++ b/gdb/testsuite/gdb.base/warning.exp
@@ -25,12 +25,12 @@ set fd [open $tname w]
puts $fd "anything"
close $fd

-set save $INTERNAL_GDBFLAGS
-set INTERNAL_GDBFLAGS "-nw -nx -data-directory $tname"
+gdb_spawn_with_cmdline_opts \
+ "-iex \"set pagination off\" -data-directory $tname"

-gdb_start
+# Make sure we see the warning.
+gdb_test "" "warning: $tname is not a directory.*" \
+ "got warning"

# Make sure gdb started up.
gdb_test "echo 23\\n" "23"
-
-set INTERNAL_GDBFLAGS $save
--
2.14.4