From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id F1CC3385840C for ; Fri, 6 Jan 2023 10:25:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F1CC3385840C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673000758; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3rWgRC5QO2FZeE0yVVJsLJ9yICNaNeoAPISPQEe6a8o=; b=JN4Bi8W8BkW2MRIxw1pil77oGg4ElGrjmIjI4tCV9Wo9Zm7+kMNSoBu8jjp5R4RFJAXJ+W 6bBDnJbmF734+zT46zkwK6qQJq3VkhkBHflJDQmDfXkz+yQCe3KQv1/4FcKi0vSGBfnG9N QBI/uWgoSwdKVWZMm0BDFem0QOZRnqc= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-259-_E8XwacaMnecCnjJZyYUrQ-1; Fri, 06 Jan 2023 05:25:57 -0500 X-MC-Unique: _E8XwacaMnecCnjJZyYUrQ-1 Received: by mail-ej1-f72.google.com with SMTP id hd17-20020a170907969100b007c117851c81so880728ejc.10 for ; Fri, 06 Jan 2023 02:25:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3rWgRC5QO2FZeE0yVVJsLJ9yICNaNeoAPISPQEe6a8o=; b=p46sdhiO6AK+IixXsrvui/ph+ODmesMfo/cGLp6ChbafyjQTk4vUfoRA4GyEvGgs4D nH1bfPicnIolLPktI3kwT/EPNIqO793Wto3VARbR6+cnUEANlE4c/blRzGH2ZQ40bvtU TAE9qcLzFSGX/8f95Wifil4a/qN5o0Y2OFG9dGPV+GAkoBG8A0KqnDXQlvWyrSmWRVb0 0u6URHUQwZ5VZyaKVJlLAVo0i6xMSNdG2Or1O5B041GY7T4fSJuil52UaELaliCj9hjX Kn9rL79FgjS9wrmvG8LNzQdVFq1Ikb1VK3xgi4MIzOF7L5Dq5kCkWaPgq2Xn7cQgbSgr DFcw== X-Gm-Message-State: AFqh2kojez32subC4url5BBAAKk8x/jW87jEy1jN0c2BxlbvhJQCV9m5 mn0418ziuEU37wCllEY6PObjQVjbzoEAjEDeuxhpTiEPTCERA4nnZXKNorNw5E6BJR6XpypQNmk Fk8dZSf5Hq9hQk5cQ/q3416Jr0pOLal1bdXetFamuFWoNacFsr4ZRsqlx4OX0hbqZZvW1ltS5dA == X-Received: by 2002:a17:907:d387:b0:7c1:6fd3:1ef3 with SMTP id vh7-20020a170907d38700b007c16fd31ef3mr46607434ejc.33.1673000756419; Fri, 06 Jan 2023 02:25:56 -0800 (PST) X-Google-Smtp-Source: AMrXdXs6b5IGIap8G3MgFelpgbsxwiZoydGpHAs0UagAyV10KpHARPM8xNF3MkYgqhrcJZpkCgFPMQ== X-Received: by 2002:a17:907:d387:b0:7c1:6fd3:1ef3 with SMTP id vh7-20020a170907d38700b007c16fd31ef3mr46607415ejc.33.1673000756020; Fri, 06 Jan 2023 02:25:56 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id 17-20020a170906329100b007c0bb571da5sm269336ejw.41.2023.01.06.02.25.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 02:25:55 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 04/15] gdb/testsuite/tui: more testing of the 'focus' command Date: Fri, 6 Jan 2023 10:25:31 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: I noticed that we didn't have much testing of the tui 'focus' command, so I started adding some. This exposed a bug in GDB, we are able to focus windows that should not be focusable, e.g. the 'status' window. This is harmless until we then do 'focus next' or 'focus prev', along this code path we assert that the currently focused window is focusable, which obviously, is no longer true, so GDB fails with an assertion error. The fix is simple; add some code to the tui_set_focus_command function that checks if the selected window is focusable. If it is not then an error is thrown. --- gdb/testsuite/gdb.tui/tui-focus.c | 22 ++++++++++ gdb/testsuite/gdb.tui/tui-focus.exp | 66 +++++++++++++++++++++++++++++ gdb/tui/tui-win.c | 3 ++ 3 files changed, 91 insertions(+) create mode 100644 gdb/testsuite/gdb.tui/tui-focus.c create mode 100644 gdb/testsuite/gdb.tui/tui-focus.exp diff --git a/gdb/testsuite/gdb.tui/tui-focus.c b/gdb/testsuite/gdb.tui/tui-focus.c new file mode 100644 index 00000000000..3a264f239ed --- /dev/null +++ b/gdb/testsuite/gdb.tui/tui-focus.c @@ -0,0 +1,22 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2023 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +int +main () +{ + return 0; +} diff --git a/gdb/testsuite/gdb.tui/tui-focus.exp b/gdb/testsuite/gdb.tui/tui-focus.exp new file mode 100644 index 00000000000..156ced44e05 --- /dev/null +++ b/gdb/testsuite/gdb.tui/tui-focus.exp @@ -0,0 +1,66 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Minimal testcase that just checks that the various "layout $foo" +# commands do not cause gdb to crash. + +tuiterm_env + +standard_testfile + +if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile}]} { + return -1 +} + +if {[skip_tui_tests]} { + return +} + +# Run a series of tests based on various test specifications. +# +# Each test specification is a tuple where the first item is the name of a +# window, and the second item is a boolean indicating if we expect that +# window to be present in the default (src) layout. +##foreach spec {{src true} {cmd true} {status true} {regs false} {asm false}} {} +foreach spec {{status false}} { + lassign $spec window valid_p + with_test_prefix "window=$window" { + + Term::clean_restart 24 80 $binfile + if {![Term::prepare_for_tui]} { + unsupported "TUI not supported" + return + } + + Term::command_no_prompt_prefix "focus $window" + + if {$valid_p} { + Term::check_region_contents "check focus message" 0 16 80 1 \ + "^Focus set to $window window\\.\\s*" + } else { + if {$window == "status"} { + Term::check_region_contents "check focus error" 0 16 80 1 \ + "^Window \"$window\" cannot be focused\\s*" + } else { + Term::check_region_contents "check focus error" 0 16 80 1 \ + "^Unrecognized window name \"$window\"\\s*" + } + } + + Term::check_box "check src box" 0 0 80 15 + + Term::command "focus prev" + } +} diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c index 58372005ff8..9c088899817 100644 --- a/gdb/tui/tui-win.c +++ b/gdb/tui/tui-win.c @@ -723,6 +723,9 @@ tui_set_focus_command (const char *arg, int from_tty) if (!win_info->is_visible ()) error (_("Window \"%s\" is not visible"), arg); + if (!win_info->can_focus ()) + error (_("Window \"%s\" cannot be focused"), arg); + tui_set_win_focus_to (win_info); gdb_printf (_("Focus set to %s window.\n"), tui_win_with_focus ()->name ()); -- 2.25.4