From 8194e927cc66e8cceb9890240ad75363b3ca6d53 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Mon, 25 Jul 2016 11:01:54 -0400 Subject: Handle correctly passing a bad interpreter name to new-ui When a bad interpreter name is passed to new-ui, such as: (gdb) new-ui bloop /dev/pts/10 A partially created UI is left in the UI list, with interp set to NULL. Trying to do anything that will print on this UI (such as "start") will cause a segmentation fault. Changes in v2: - Use with_test_prefix to namespace test procedures - Give an explicit stable test name - Add a "bad terminal path" test - Remove useless runto_main - Add missing intro comments I did not factor out the pty spawn, as there is some magic involved I don't quite understand. But it wouldn't bring that much anyway. gdb/ChangeLog: * top.h (make_delete_ui_cleanup): New declaration. * top.c (delete_ui_cleanup): New function. (make_delete_ui_cleanup): New function. (new_ui_command): Create restore_ui cleanup earlier, create a delete_ui cleanup and discard it on success. gdb/testsuite/ChangeLog: * gdb.base/new-ui.exp (do_test_invalid_args): New procedure. --- gdb/testsuite/gdb.base/new-ui.exp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'gdb/testsuite/gdb.base') diff --git a/gdb/testsuite/gdb.base/new-ui.exp b/gdb/testsuite/gdb.base/new-ui.exp index f3f66db..22e8b79 100644 --- a/gdb/testsuite/gdb.base/new-ui.exp +++ b/gdb/testsuite/gdb.base/new-ui.exp @@ -143,4 +143,31 @@ proc do_test {} { } } -do_test +# Test missing / invalid arguments. + +proc do_test_invalid_args {} { + global testfile + + clean_restart $testfile + + spawn -pty + set extra_tty_name $spawn_out(slave,name) + + # Test bad terminal path. + gdb_test "new-ui console /non/existent/path" \ + "opening terminal failed: No such file or directory\." \ + "new-ui with bad terminal path" + + # Test bad interpreter name. + gdb_test "new-ui bloop $extra_tty_name" \ + "Interpreter `bloop' unrecognized" \ + "new-ui with bad interpreter name" + + # Test that we can continue working normally. + if ![runto_main] { + fail "could not run to main" + } +} + +with_test_prefix "do_test" do_test +with_test_prefix "do_test_invalid_args" do_test_invalid_args -- cgit v1.1