From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1684226637; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kEPbscjJ1RHLFedCfBSJwtelkSebVDdyG4TLxfqqLdg=; b=p2nxJBdIamhj+z6wNmoIqGk3UYpuUqce4oBQbDlhcEaT8DcRlkRi6ivvssLPCMTSCAVB+L oKHEUEh6Xo1J8y0fL6H6WvIWFKlRMHtisE34lJ4h+WzPT+1JUAurX4MCBzMSRDuzncPLHW NBrnsEuZctazFAjNkksyYdW9FM8tk8s= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1684226637; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kEPbscjJ1RHLFedCfBSJwtelkSebVDdyG4TLxfqqLdg=; b=q9m/Zr7mQDQXzTOyHweuHvmSOm4NgfzCV79ruEdpS+ms6hztlJh3YDACi3YmVac9wTK3Vb oj67beTNoTyGT5Aw== 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 From: Tom de Vries 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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 ())); -- 2.35.3