From patchwork Tue May 16 08:43:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 69444 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C951B38AA258 for ; Tue, 16 May 2023 08:49:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C951B38AA258 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684226994; bh=6ajc8wc1wnQy7S1DY/Yl2uGWNj8EkUPmDApXwVikBCI=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ELgkD+g7SFBUEt+R9yqlnmrT7xcgT0aowfBct8pG6TQyJIhiBDmPaN5aXGvcpJI3g fdZkMKm4n61mJJ/G8m1ki2jMbfR+oGAD7ap1sRHZyX/sJJ4Kl4bdr9dLFzqAbcdxo+ ORQ1gAo9REV4yLUIhlvgpakgsR29jERsH9uZZl4c= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id B3BDA3857359 for ; Tue, 16 May 2023 08:43:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B3BDA3857359 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D821D21B49; Tue, 16 May 2023 08:43:57 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C121513A12; Tue, 16 May 2023 08:43:57 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id MO46Lk1CY2SiMwAAMHmgww (envelope-from ); Tue, 16 May 2023 08:43:57 +0000 To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 1/3] [gdb/tui] Add set tui status-window-mode Date: Tue, 16 May 2023 10:43:50 +0200 Message-Id: <20230516084352.27225-2-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230516084352.27225-1-tdevries@suse.de> References: <20230516084352.27225-1-tdevries@suse.de> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Currently, the status window attributes are hardcoded to standout. Add a new command "set tui status-window-mode " that controls the attributes for the status window, using the same options as used for "set tui border-mode" and "set tui active-border-mode". The default is standout, so there's no change in behaviour. Tested on x86_64-linux. Reviewed-By: Eli Zaretskii --- gdb/doc/gdb.texinfo | 6 +++ gdb/testsuite/gdb.tui/basic.exp | 13 +++++ gdb/testsuite/lib/tuiterm.exp | 84 +++++++++++++++++++++++++-------- gdb/tui/tui-stack.c | 10 ++-- gdb/tui/tui-win.c | 56 ++++++++++++++++++++++ gdb/tui/tui-win.h | 3 ++ 6 files changed, 146 insertions(+), 26 deletions(-) diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 531147f6e6b..77bc4323912 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -30302,6 +30302,12 @@ Use extra bright or bold mode. Use extra bright or bold and standout mode. @end table +@item set tui status-window-mode @var{mode} +@kindex set tui status-window-mode +Select the display attributes for the contents of the status window. +The @var{mode} is as for @code{set tui border-mode} and +@code{set tui border-active-mode}. The default is standout mode. + @item set tui tab-width @var{nchars} @kindex set tui tab-width @kindex tabset diff --git a/gdb/testsuite/gdb.tui/basic.exp b/gdb/testsuite/gdb.tui/basic.exp index ec1e9945e8f..4cff8ea41d7 100644 --- a/gdb/testsuite/gdb.tui/basic.exp +++ b/gdb/testsuite/gdb.tui/basic.exp @@ -106,3 +106,16 @@ Term::check_contents "split layout contents" \ Term::check_box "source box in split layout" 0 0 80 8 Term::check_box "asm box in split layout" 0 7 80 8 + +set re_noattr "\[^<\]" + +set status_window_line 15 + +set status [Term::get_line_with_attrs $status_window_line] +gdb_assert { [regexp "^$re_noattr*$" $status] == 1} \ + "status window: reverse" + +Term::command "set tui status-window-mode normal" + +set status [Term::get_line_with_attrs $status_window_line] +gdb_assert { [regexp "^$re_noattr*$" $status] == 1} "status window: normal" diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp index 5e4235da942..8305e83e982 100644 --- a/gdb/testsuite/lib/tuiterm.exp +++ b/gdb/testsuite/lib/tuiterm.exp @@ -547,6 +547,18 @@ namespace eval Term { } } + # Reset the attributes in attributes array UPVAR_NAME to the default values. + proc reset_attrs { upvar_name } { + upvar $upvar_name var + array set var { + intensity normal + fg default + bg default + underline 0 + reverse 0 + } + } + # Select Graphic Rendition. # # https://vt100.net/docs/vt510-rm/SGR.html @@ -557,11 +569,7 @@ namespace eval Term { foreach item $args { switch -exact -- $item { "" - 0 { - set _attrs(intensity) normal - set _attrs(fg) default - set _attrs(bg) default - set _attrs(underline) 0 - set _attrs(reverse) 0 + reset_attrs _attrs } 1 { set _attrs(intensity) bold @@ -666,13 +674,7 @@ namespace eval Term { set _cur_col 0 set _cur_row 0 set _resize_count 0 - array set _attrs { - intensity normal - fg default - bg default - underline 0 - reverse 0 - } + reset_attrs _attrs _clear_lines 0 $_rows } @@ -873,10 +875,25 @@ namespace eval Term { wait_for "^$str" } - # Return the text of screen line N, without attributes. Lines are - # 0-based. If C is given, stop before column C. Columns are also - # zero-based. - proc get_line {n {c ""}} { + # Apply the attribute list in ATTRS to attributes array UPVAR_NAME. + # Return a string annotating the changed attributes. + proc apply_attrs { upvar_name attrs } { + set res "" + upvar $upvar_name var + foreach { attr val } $attrs { + if { $var($attr) != $val } { + append res "<$attr:$val>" + set var($attr) $val + } + } + + return $res + } + + # Return the text of screen line N. Lines are 0-based. If C is given, + # stop before column C. Columns are also zero-based. If ATTRS, annotate + # with attributes. + proc get_line_1 {n c attrs} { variable _rows # This can happen during resizing, if the cursor seems to # temporarily be off-screen. @@ -889,13 +906,37 @@ namespace eval Term { variable _chars set c [_default $c $_cols] set x 0 + if { $attrs } { + reset_attrs line_attrs + } while {$x < $c} { + if { $attrs } { + set char_attrs [lindex $_chars($x,$n) 1] + append result [apply_attrs line_attrs $char_attrs] + } append result [lindex $_chars($x,$n) 0] incr x } + if { $attrs } { + reset_attrs zero_attrs + set char_attrs [array get zero_attrs] + append result [apply_attrs line_attrs $char_attrs] + } return $result } + # Return the text of screen line N, without attributes. Lines are + # 0-based. If C is given, stop before column C. Columns are also + # zero-based. + proc get_line {n {c ""} } { + return [get_line_1 $n $c 0] + } + + # As get_line, but annotate with attributes. + proc get_line_with_attrs {n {c ""}} { + return [get_line_1 $n $c 1] + } + # Get just the character at (X, Y). proc get_char {x y} { variable _chars @@ -1069,8 +1110,8 @@ namespace eval Term { } # A debugging function to dump the current screen, with line - # numbers. - proc dump_screen {} { + # numbers. If ATTRS, annotate with attributes. + proc dump_screen { {attrs 0} } { variable _rows variable _cols variable _cur_row @@ -1080,10 +1121,15 @@ namespace eval Term { for {set y 0} {$y < $_rows} {incr y} { set fmt [format %5d $y] - verbose -log "$fmt [get_line $y]" + verbose -log "$fmt [get_line_1 $y "" $attrs]" } } + # As dump_screen, but with attributes annotation. + proc dump_screen_with_attrs {} { + return [dump_screen 1] + } + # A debugging function to dump a box from the current screen, with line # numbers. proc dump_box { x y width height } { diff --git a/gdb/tui/tui-stack.c b/gdb/tui/tui-stack.c index 76b8f066abb..153a285f37c 100644 --- a/gdb/tui/tui-stack.c +++ b/gdb/tui/tui-stack.c @@ -37,6 +37,7 @@ #include "tui/tui-winsource.h" #include "tui/tui-file.h" #include "tui/tui-location.h" +#include "tui/tui-win.h" #include "gdb_curses.h" @@ -234,15 +235,10 @@ tui_locator_window::rerender () std::string string = make_status_line (); scrollok (handle.get (), FALSE); wmove (handle.get (), 0, 0); - /* We ignore the return value from wstandout and wstandend, casting them - to void in order to avoid a compiler warning. The warning itself was - introduced by a patch to ncurses 5.7 dated 2009-08-29, changing these - macro to expand to code that causes the compiler to generate an - unused-value warning. */ - (void) wstandout (handle.get ()); + wattron (handle.get (), tui_status_window_attrs); waddstr (handle.get (), string.c_str ()); wclrtoeol (handle.get ()); - (void) wstandend (handle.get ()); + wattroff (handle.get (), tui_status_window_attrs); refresh_window (); wmove (handle.get (), 0, 0); } diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c index 6710b3e17e5..7926e2d7a18 100644 --- a/gdb/tui/tui-win.c +++ b/gdb/tui/tui-win.c @@ -346,6 +346,42 @@ tui_set_var_cmd (const char *null_args, tui_rehighlight_all (); } +/* Value of "tui status-window-mode". */ + +static const char *tui_status_window_mode = "standout"; + +/* See tui-win.h. */ + +int tui_status_window_attrs; + +/* Show value of "tui status-window-mode". */ + +static void +show_tui_status_window_mode (struct ui_file *file, + int from_tty, + struct cmd_list_element *c, + const char *value) +{ + gdb_printf (file, _("\ +The attribute mode to use for the TUI status window is \"%s\".\n"), + value); +} + +/* Set value of "tui status-window-mode". */ + +static void +set_tui_status_window_mode (const char *null_args, + int from_tty, struct cmd_list_element *c) +{ + struct tui_translate *entry + = translate (tui_status_window_mode, tui_border_mode_translate); + if (tui_status_window_attrs == entry->value) + return; + + tui_status_window_attrs = entry->value; + if (tui_active) + tui_show_locator_content (); +} /* True if TUI resizes should print a message. This is used by the @@ -1251,6 +1287,22 @@ This variable controls the attributes to use for the active window border:\n\ show_tui_active_border_mode, &tui_setlist, &tui_showlist); + add_setshow_enum_cmd ("status-window-mode", no_class, tui_border_mode_enums, + &tui_status_window_mode, _("\ +Set the attribute mode to use for the TUI status window."), _("\ +Show the attribute mode to use for the TUI status window."), _("\ +This variable controls the attributes to use for the status window:\n\ + normal normal display\n\ + standout use highlight mode of terminal\n\ + reverse use reverse video mode\n\ + half use half bright\n\ + half-standout use half bright and standout mode\n\ + bold use extra bright or bold\n\ + bold-standout use extra bright or bold with standout mode"), + set_tui_status_window_mode, + show_tui_status_window_mode, + &tui_setlist, &tui_showlist); + add_setshow_zuinteger_cmd ("tab-width", no_class, &internal_tab_width, _("\ Set the tab width, in characters, for the TUI."), _("\ @@ -1305,4 +1357,8 @@ When enabled, the left margin will use '_' and '0' instead of spaces."), tui_border_style.changed.attach (tui_rehighlight_all, "tui-win"); tui_active_border_style.changed.attach (tui_rehighlight_all, "tui-win"); + + /* Assign default value. */ + tui_status_window_attrs + = translate (tui_status_window_mode, tui_border_mode_translate)->value; } diff --git a/gdb/tui/tui-win.h b/gdb/tui/tui-win.h index 3d35f1dfb7f..5ace83a742a 100644 --- a/gdb/tui/tui-win.h +++ b/gdb/tui/tui-win.h @@ -38,6 +38,9 @@ extern chtype tui_border_hline; extern int tui_border_attrs; extern int tui_active_border_attrs; +/* Attributes for the contents of the status window. */ +extern int tui_status_window_attrs; + extern bool tui_update_variables (); extern void tui_initialize_win (void); From patchwork Tue May 16 08:43:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 69445 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D3472382D810 for ; Tue, 16 May 2023 08:50:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D3472382D810 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684227025; bh=kEPbscjJ1RHLFedCfBSJwtelkSebVDdyG4TLxfqqLdg=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=uZPtxXR7QCT7ST7W/k+JCJvc3yIh2jn1hVE+26BN9k6Mi7zQDHJE8t1NOPZ925reE OXBdkeep7REFI/Gq1KjILiedUK2on89aE0/lh7fOwyhsOtlEYIjFsBASyu/szH9bIS KZJqPE+Z9qz+jX/jpB5ZEWe6jNBJ8udPLOQkmDjU= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 5A1D93898C70 for ; Tue, 16 May 2023 08:43:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5A1D93898C70 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id F181A1FD72; Tue, 16 May 2023 08:43:57 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id DC255138F5; Tue, 16 May 2023 08:43:57 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8FCoNE1CY2SiMwAAMHmgww (envelope-from ); Tue, 16 May 2023 08:43:57 +0000 To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/3] [gdb/tui] Use ">" marker in register window Date: Tue, 16 May 2023 10:43:51 +0200 Message-Id: <20230516084352.27225-3-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230516084352.27225-1-tdevries@suse.de> References: <20230516084352.27225-1-tdevries@suse.de> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" In TUI's source and assembly windows, we show the current execution point using both: - highlighting, and - a ">" marker. In TUI's register window, we show changed registers just using highlighting. Make behaviour more similar by also using a ">" marker for changed registers. This in preparation for a "set tui contents-highlight on/off" that optionally disables the highlighting, leaving just the ">" markers. Tested on x86_64-linux. --- gdb/testsuite/gdb.tui/regs-2.c | 36 +++++++++++++++++ gdb/testsuite/gdb.tui/regs-2.exp | 66 ++++++++++++++++++++++++++++++++ gdb/tui/tui-regs.c | 45 +++++++++++++++++++++- 3 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 gdb/testsuite/gdb.tui/regs-2.c create mode 100644 gdb/testsuite/gdb.tui/regs-2.exp diff --git a/gdb/testsuite/gdb.tui/regs-2.c b/gdb/testsuite/gdb.tui/regs-2.c new file mode 100644 index 00000000000..d65293e31b2 --- /dev/null +++ b/gdb/testsuite/gdb.tui/regs-2.c @@ -0,0 +1,36 @@ +/* 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 +foo (void) +{ + return 1; +} + +int +bar (void) +{ + return 2; +} + +int +main (void) +{ + foo (); + bar (); + return 0; +} diff --git a/gdb/testsuite/gdb.tui/regs-2.exp b/gdb/testsuite/gdb.tui/regs-2.exp new file mode 100644 index 00000000000..50f3d48512d --- /dev/null +++ b/gdb/testsuite/gdb.tui/regs-2.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 . + +# Test of ">" marker in TUI register window. + +require allow_tui_tests +require {!is_remote host} +require is_x86_64_m64_target + +tuiterm_env + +standard_testfile + +if { [build_executable "failed to prepare" ${testfile} ${srcfile}] == -1 } { + return -1 +} + +set cols 80 +set lines 24 +set reg_lines 8 +set screen_dim [list $lines $cols] +set reg_box [list 0 0 $cols $reg_lines] + +Term::clean_restart {*}$screen_dim $testfile + +if {![runto_main]} { + perror "test suppressed" + return +} + +if {![Term::enter_tui]} { + unsupported "TUI not supported" + return +} + +Term::command "layout regs" +Term::check_box "register box" {*}$reg_box + +set re_border "\\|" +set re_ws " " +set re_any "\[^\r\n\]" + +set re "B\\+>$re_ws*$decimal$re_ws*foo \\(\\);$re_ws*" +Term::check_contents "before call to foo" "$re_border$re$re_border" + +# Step over foo, set rax to 1. +Term::command "next" +set re "rax$re_ws*0x1$re_ws$re_any*" +Term::check_contents "rax after foo" "$re_border$re$re_border" + +# Step over bar, set rax to 2. Check that the ">" marker is used. +Term::command "next" +set re "rax$re_ws*>0x2$re_ws$re_any*" +Term::check_contents "rax after bar" "$re_border$re$re_border" diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c index 50a238401df..af3b21b0f9d 100644 --- a/gdb/tui/tui-regs.c +++ b/gdb/tui/tui-regs.c @@ -494,8 +494,49 @@ tui_data_item_window::rerender (WINDOW *handle, int field_width) to code that causes the compiler to generate an unused-value warning. */ (void) wstandout (handle); - - mvwaddnstr (handle, y, x, content.c_str (), field_width - 1); + + const char *s = content.c_str (); + int print_width = field_width - 1; + if (highlight) + { + off_t last_space_offset; + + /* Calculate last_space_offset. */ + { + const char *i = s; + const char *last_space = nullptr; + /* Skip register name. */ + while (*i != ' ') + i++; + /* Find last space before value. */ + while (*i == ' ') + { + last_space = i; + i++; + } + last_space_offset = last_space - s; + } + + /* Write the bit before the last space. */ + int total = 0; + int n = last_space_offset; + n = std::min (n, print_width); + mvwaddnstr (handle, y, x, s, n); + total += n; + print_width -= n; + + /* Replace the last space with ">". */ + n = 1; + n = std::min (n, print_width); + waddnstr (handle, ">", n); + total += n; + print_width -= n; + + /* Write the rest. */ + waddnstr (handle, s + total, print_width); + } + else + mvwaddnstr (handle, y, x, s, print_width); if (content.size () < field_width) waddstr (handle, n_spaces (field_width - content.size ())); From patchwork Tue May 16 08:43:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 69447 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C87E43945C18 for ; Tue, 16 May 2023 08:50:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C87E43945C18 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684227057; bh=jdMouL+vuOtlxNvsry2cETeMpor8FV7t9jAjcNYy/KM=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=L+ssEVduTXEVIrpnhOCCDSLsf8RZUl/+4dJ3l/dmp1mJqGxGkd8JeMN23ENbddsgj fcg2Gnw69gmiX6HLCkM4Wmn/bU3EmwHbf9113FvK3ck32L81Jo9CuBq8JPVNYP5fXV kKCNw8W5GyxJHxW7uAHrfW6/RUupkaSA75/D1N7I= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 6A8923898C72 for ; Tue, 16 May 2023 08:43:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6A8923898C72 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1771221B4F; Tue, 16 May 2023 08:43:58 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 01A6913A12; Tue, 16 May 2023 08:43:57 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id uH/YOk1CY2SiMwAAMHmgww (envelope-from ); Tue, 16 May 2023 08:43:57 +0000 To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 3/3] [gdb/tui] Add set tui contents-highlight on/off Date: Tue, 16 May 2023 10:43:52 +0200 Message-Id: <20230516084352.27225-4-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230516084352.27225-1-tdevries@suse.de> References: <20230516084352.27225-1-tdevries@suse.de> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" TUI highlights various parts of TUI windows: - highlighting of the current execution point in the assembly and source windows, - highlighting of changed registers in the register window. Add a new command "set tui contents-highlight on/off" that allows us to disable this. The default is on, so there's no change in behaviour. Note that the highlighting in all three windows is shadowed by the ">" marker, so we're not losing information by switching off the highlighting. Tested on x86_64-linux. Reviewed-By: Eli Zaretskii --- gdb/doc/gdb.texinfo | 7 ++++ gdb/testsuite/gdb.tui/source.exp | 59 ++++++++++++++++++++++++++++++++ gdb/tui/tui-regs.c | 4 +-- gdb/tui/tui-regs.h | 4 +-- gdb/tui/tui-win.c | 39 +++++++++++++++++++++ gdb/tui/tui-win.h | 4 +++ gdb/tui/tui-winsource.c | 4 +-- 7 files changed, 115 insertions(+), 6 deletions(-) create mode 100644 gdb/testsuite/gdb.tui/source.exp diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 77bc4323912..836cf9623ad 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -30322,6 +30322,13 @@ The default display uses more space for line numbers; the compact display uses only as much space as is needed for the line numbers in the current file. +@item set tui contents-highlight @r{[}on@r{|}off@r{]} +@kindex set tui contents-highlight +Determine whether TUI windows contents is highlighted, such as highlighting +of the current execution point in the assembly and source windows, +and highlighting of changed registers in the register window. The +default is @code{on}. + @kindex set debug tui @item set debug tui @r{[}on|off@r{]} Turn on or off display of @value{GDBN} internal debug messages relating diff --git a/gdb/testsuite/gdb.tui/source.exp b/gdb/testsuite/gdb.tui/source.exp new file mode 100644 index 00000000000..d6b231dc43f --- /dev/null +++ b/gdb/testsuite/gdb.tui/source.exp @@ -0,0 +1,59 @@ +# 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 . + +# Check that "set tui compact-source on" has the intended effect. + +require allow_tui_tests + +tuiterm_env + +standard_testfile main-one-line.c + +if {[build_executable "failed to prepare" ${testfile} ${srcfile}] == -1} { + return -1 +} + +Term::clean_restart 24 80 $binfile + +gdb_test_no_output "maint set tui-left-margin-verbose on" + +if { ![runto_main] } { + return -1 +} + +if {![Term::enter_tui]} { + unsupported "TUI not supported" + return +} + + +set screen_line_with_main 6 +set screen_line [Term::get_line_with_attrs $screen_line_with_main] + +set src_line_with_main [gdb_get_line_number "int main"] + +set re "int main () { return 0; }" +set re "${src_line_with_main}_$re" +set re [string_to_regexp $re] +gdb_assert { [regexp $re $screen_line] == 1} "src line: reverse" + +Term::command "set tui contents-highlight off" +Term::command "set style enabled off" +set screen_line [Term::get_line_with_attrs $screen_line_with_main] + +set re "int main () { return 0; }" +set re "${src_line_with_main}_$re " +set re [string_to_regexp $re] +gdb_assert { [regexp $re $screen_line] == 1} "src line: normal" diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c index af3b21b0f9d..43724d9dd14 100644 --- a/gdb/tui/tui-regs.c +++ b/gdb/tui/tui-regs.c @@ -487,7 +487,7 @@ tui_data_window::check_register_values (frame_info_ptr frame) void tui_data_item_window::rerender (WINDOW *handle, int field_width) { - if (highlight) + if (tui_contents_highlight && highlight) /* We ignore the return value, casting it to void in order to avoid a compiler warning. The warning itself was introduced by a patch to ncurses 5.7 dated 2009-08-29, changing this macro to expand @@ -540,7 +540,7 @@ tui_data_item_window::rerender (WINDOW *handle, int field_width) if (content.size () < field_width) waddstr (handle, n_spaces (field_width - content.size ())); - if (highlight) + if (tui_contents_highlight && highlight) /* We ignore the return value, casting it to void in order to avoid a compiler warning. The warning itself was introduced by a patch to ncurses 5.7 dated 2009-08-29, changing this macro to expand diff --git a/gdb/tui/tui-regs.h b/gdb/tui/tui-regs.h index 5adff6300aa..e0f299d4410 100644 --- a/gdb/tui/tui-regs.h +++ b/gdb/tui/tui-regs.h @@ -68,6 +68,8 @@ struct tui_data_window : public tui_win_info return m_current_group; } + void rerender () override; + protected: void do_scroll_vertical (int num_to_scroll) override; @@ -75,8 +77,6 @@ struct tui_data_window : public tui_win_info { } - void rerender () override; - private: /* Display the registers in the content from 'start_element_no' diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c index 7926e2d7a18..e0ad6551c59 100644 --- a/gdb/tui/tui-win.c +++ b/gdb/tui/tui-win.c @@ -916,6 +916,33 @@ tui_show_tab_width (struct ui_file *file, int from_tty, /* See tui-win.h. */ +bool tui_contents_highlight = true; + +static void +show_tui_contents_highlight (ui_file *file, + int from_tty, + cmd_list_element *c, + const char *value) +{ + gdb_printf (file, _("\ +Highlighting TUI windows content is %s.\n"), + value); +} + +static void +set_tui_contents_highlight (const char *ignore, int from_tty, + cmd_list_element *c) +{ + if (TUI_SRC_WIN != nullptr) + TUI_SRC_WIN->refill (); + if (TUI_DISASM_WIN != nullptr) + TUI_DISASM_WIN->refill (); + if (TUI_DATA_WIN != nullptr) + TUI_DATA_WIN->rerender (); +} + +/* See tui-win.h. */ + bool compact_source = false; /* Callback for "set tui compact-source". */ @@ -1330,6 +1357,18 @@ in a compact form. The compact form uses less horizontal space."), tui_set_compact_source, tui_show_compact_source, &tui_setlist, &tui_showlist); + add_setshow_boolean_cmd ("contents-highlight", class_tui, + &tui_contents_highlight, _("\ +Set whether TUI windows contents is highlighted."), _("\ +Show whether TUI windows contents is highlighted."), _("\ +Determine whether TUI windows contents is highlighted, such as highlighting\n\ +of the current execution point in the assembly and source windows,\n\ +highlighting of the status window, and highlighting of changed registers in\n\ +the register window."), + set_tui_contents_highlight, + show_tui_contents_highlight, + &tui_setlist, &tui_showlist); + add_setshow_boolean_cmd ("tui-current-position", class_maintenance, &style_tui_current_position, _("\ Set whether to style text highlighted by the TUI's current position indicator."), diff --git a/gdb/tui/tui-win.h b/gdb/tui/tui-win.h index 5ace83a742a..ab1a4e177a9 100644 --- a/gdb/tui/tui-win.h +++ b/gdb/tui/tui-win.h @@ -61,4 +61,8 @@ extern bool style_tui_current_position; /* Whether to replace the spaces in the left margin with '_' and '0'. */ extern bool tui_left_margin_verbose; +/* Whether to highlight various parts of the windows content using standout + and reverse. */ +extern bool tui_contents_highlight; + #endif /* TUI_TUI_WIN_H */ diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c index 3c4ce501e5e..f245eecc965 100644 --- a/gdb/tui/tui-winsource.c +++ b/gdb/tui/tui-winsource.c @@ -301,13 +301,13 @@ tui_source_window_base::show_source_line (int lineno) struct tui_source_element *line; line = &m_content[lineno]; - if (line->is_exec_point) + if (tui_contents_highlight && line->is_exec_point) tui_set_reverse_mode (m_pad.get (), true); wmove (m_pad.get (), lineno, 0); puts_to_pad_with_skip (line->line.c_str (), m_pad_offset); - if (line->is_exec_point) + if (tui_contents_highlight && line->is_exec_point) tui_set_reverse_mode (m_pad.get (), false); }