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

Pedro Alves
2018-11-16T13:31:03Z

On 11/15/2018 11:15 PM, Tom Tromey wrote:
>>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
>
> Pedro> On 10/31/2018 06:18 PM, Tom Tromey wrote:
>>> +set save $INTERNAL_GDBFLAGS
>>> +set INTERNAL_GDBFLAGS "-nw -nx -data-directory $tname"
>>> +
>>> +gdb_start
>>> +
>>> +# Make sure gdb started up.
>>> +gdb_test "echo 23\\n" "23"
>
> Pedro> I guess this could also check that the warning was emitted?
>
> I didn't know how to do that.
> Modify gdb_start maybe?
Hmm, by using gdb_spawn directly, or better, gdb_spawn_with_cmdline_opts
instead of gdb_start?

See patch below; it works here.

Also, looking further into the INTERNAL_GDBFLAGS issue,
it turns out we don't really need to frob INTERNAL_GDBFLAGS.
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.
[...]

(And if it didn't, I'd think we'd just have to make sure to put
our -data-directory last, leaving the original one in place.
I.e., just passing it in gdb_spawn_with_cmdline_opts should work
even in that case.)

So, WDYT of this version?

From 7f3e6bf1b75e049c0abbab2a9cbf3d6e28f855ac Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Fri, 16 Nov 2018 13:13:56 +0000
Subject: [PATCH] warning

---
gdb/testsuite/gdb.base/warning.exp | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

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