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

Tom Tromey
2018-11-15T23:25:52Z

>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:

[ ... save_vars and... ]
Pedro> I think that the test should instead be replacing/sed'ing
Pedro> the existing -data-directory option, instead of overriding
Pedro> INTERNAL_GDBFLAGS completely.
Pedro> That's what gdb.base/gdbinit-history.exp does.

I didn't address checking the warning output, but here's a patch for the
rest. Let me know what you think.

Tom

commit 42cbd945dddcc019af24b75aa353fd42d06b17a6
Author: Tom Tromey <tom@tromey.com>
Date: Thu Nov 15 16:23:25 2018 -0700

Use save_vars in gdb.base/warning.exp

This changes gdb.base/warning.exp per Pedro's comments: it now uses
save_vars and it rewrites INTERNAL_GDBFLAGS in place, rather than
replcing it entirely.

gdb/testsuite/ChangeLog
2018-11-15 Tom Tromey <tom@tromey.com>

* gdb.base/warning.exp: Use save_vars. Rewrite INTERNAL_GDBFLAGS
rather than replacing it.

diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 90faeda261..8ad17ca5c5 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2018-11-15 Tom Tromey <tom@tromey.com>
+
+ * gdb.base/warning.exp: Use save_vars. Rewrite INTERNAL_GDBFLAGS
+ rather than replacing it.
+
2018-11-12 Simon Marchi <simon.marchi@polymtl.ca>

* gdb.base/skip.exp: Add standard_testfile. Add "skip delete"
diff --git a/gdb/testsuite/gdb.base/warning.exp b/gdb/testsuite/gdb.base/warning.exp
index 53067f48d5..975d994e30 100644
--- a/gdb/testsuite/gdb.base/warning.exp
+++ b/gdb/testsuite/gdb.base/warning.exp
@@ -25,12 +25,28 @@ set fd [open $tname w]
puts $fd "anything"
close $fd

-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"
-
-set INTERNAL_GDBFLAGS $save
+save_vars { INTERNAL_GDBFLAGS } {
+ set last_was_dd 0
+ set new_list {}
+ foreach opt [split $INTERNAL_GDBFLAGS] {
+ if {$last_was_dd} {
+ # Just drop it.
+ set last_was_dd 0
+ } elseif {[regexp -- "^--?data-directory\$" $opt]} {
+ set last_was_dd 1
+ } elseif {[regexp -- "^--?data-directory=" $opt]} {
+ # Drop but don't drop the next argument.
+ } else {
+ lappend new_list $opt
+ }
+ }
+ lappend new_list -data-directory
+ lappend new_list $tname
+
+ set INTERNAL_GDBFLAGS [join $new_list]
+
+ gdb_start
+
+ # Make sure gdb started up.
+ gdb_test "echo 23\\n" "23"
+}