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 A24CC3858C36 for ; Fri, 10 Nov 2023 12:59:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A24CC3858C36 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A24CC3858C36 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.220.29 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699621171; cv=none; b=N3QZxKBFnc/qFUSAPvxzuZrCTkaGmE9+vZIHM5usPfoNcdN81SARNlrUCYQs+hKvX33I41dJbvJFMsgSFADf0V8kxET8efJQhItfRHnOMVI6zSERGJAe9VvXfr2uS6lR8VBZTFPBALuI66KHbhhPjiqFf3HRHWj1As+1gPLWIbY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699621171; c=relaxed/simple; bh=GU6qZupYKjNI9hbJheZf0a1Xqfnen41qcR8qEOoHDw4=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=T/G6iCDL+6sxh22H/rpkZC201RoT+jzGbrG+0WxWZ9MrNY4WaUlPyuwX2m2chVGsmScEKMPOhFzBQSVA/oDBhURGAy8q6bZs/OWNxk/tIBkKlYmlsjmTqmd61aHIee0HuXdIMqw+Vh2qkwHxH2eRS5H0qvlH0gcwxtkj2sdCotg= ARC-Authentication-Results: i=1; server2.sourceware.org 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 81E5E1F8BD for ; Fri, 10 Nov 2023 12:59:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1699621168; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DJBxAob50JLsewe8p1kmdV5VugkEX2i08RrjeK5Zmxk=; b=XibIJOAadrib3A4PFWiePNwenS2bFcYJP3ZEOdbD7f7nCZobpYZAOyyCRLhe2K3/ieVsn1 2ajTq+IYXlUK6q/DXH1OUlTekfbi1Gd3sh+SbtzUvnpVoM4h0dyYd9/D/wM4U2tQUFuwG4 Wbc7qeWiTjnHofqx4f1hkqgA34M52nM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1699621168; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DJBxAob50JLsewe8p1kmdV5VugkEX2i08RrjeK5Zmxk=; b=kxf8jfB+yAGa6mwTiMPZoBtVdOw52nM2UPPf9q+8VgqCuFxQMBW+CYJD+g9WUBK7RY9/nr GuyfkHpb3n+3xvBw== 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 700B6139B7 for ; Fri, 10 Nov 2023 12:59:28 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id qHlaGjApTmUlLQAAMHmgww (envelope-from ) for ; Fri, 10 Nov 2023 12:59:28 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH 2/3] [gdb/tui] Add tui_win_info::{box_width,box_size} Date: Fri, 10 Nov 2023 14:00:50 +0100 Message-Id: <20231110130051.21239-2-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231110130051.21239-1-tdevries@suse.de> References: <20231110130051.21239-1-tdevries@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,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_source_window::set_contents we have: ... /* Take hilite (window border) into account, when calculating the number of lines. */ int nlines = height - 2; ... The '2' represents the total size of the window border (or box, in can_box terms), in this case one line at the top and one line at the bottom. Likewise, '1' is used to represent the width of the window border. Introduce new functions: - tui_win_info::box_width () and - tui_win_info::box_size () that can be used instead instead of these hardcoded constants. Implement these such that they return 0 when can_box () == false. Tested patch completeness by making all windows unboxed: ... @@ -85,7 +85,7 @@ struct tui_win_info /* Return true if this window can be boxed. */ virtual bool can_box () const { - return true; + return false; } int box_width () const ... and test-driving TUI. This required eliminating an assert in tui_source_window_base::show_source_content, I've included that part as well. Tested on x86_64-linux. --- gdb/tui/tui-data.h | 12 ++++++++++++ gdb/tui/tui-disasm.c | 2 +- gdb/tui/tui-regs.c | 10 +++++----- gdb/tui/tui-source.c | 4 ++-- gdb/tui/tui-wingeneral.c | 2 +- gdb/tui/tui-winsource.c | 20 ++++++++++++-------- gdb/tui/tui-winsource.h | 4 ++-- 7 files changed, 35 insertions(+), 19 deletions(-) diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h index a1e44f77cc1..5bb5ef9d941 100644 --- a/gdb/tui/tui-data.h +++ b/gdb/tui/tui-data.h @@ -88,6 +88,18 @@ struct tui_win_info return true; } + /* Return the width of the box. */ + int box_width () const + { + return can_box () ? 1 : 0; + } + + /* Return the size of the box. */ + int box_size () const + { + return 2 * box_width (); + } + /* Resize this window. The parameters are used to set the window's size and position. */ virtual void resize (int height, int width, diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c index c1ed491c558..4e9c2341ddd 100644 --- a/gdb/tui/tui-disasm.c +++ b/gdb/tui/tui-disasm.c @@ -341,7 +341,7 @@ tui_disasm_window::set_contents (struct gdbarch *arch, cur_pc = tui_location.addr (); /* Window size, excluding highlight box. */ - max_lines = height - 2; + max_lines = height - box_size (); /* Get temporary table that will hold all strings (addr & insn). */ std::vector asm_lines; diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c index 1a351e60cee..01538d49961 100644 --- a/gdb/tui/tui-regs.c +++ b/gdb/tui/tui-regs.c @@ -281,15 +281,15 @@ tui_data_window::display_registers_from (int start_element_no) for (i = 0; i < start_element_no; i++) m_regs_content[i].y = 0; - m_regs_column_count = (width - 2) / m_item_width; + m_regs_column_count = (width - box_size ()) / m_item_width; if (m_regs_column_count == 0) m_regs_column_count = 1; - m_item_width = (width - 2) / m_regs_column_count; + m_item_width = (width - box_size ()) / m_regs_column_count; /* Now create each data "sub" window, and write the display into it. */ int cur_y = 1; - while (i < m_regs_content.size () && cur_y <= height - 2) + while (i < m_regs_content.size () && cur_y <= height - box_size ()) { for (int j = 0; j < m_regs_column_count && i < m_regs_content.size (); @@ -325,7 +325,7 @@ tui_data_window::display_reg_element_at_line (int start_element_no, int last_line_no, first_line_on_last_page; last_line_no = last_regs_line_no (); - first_line_on_last_page = last_line_no - (height - 2); + first_line_on_last_page = last_line_no - (height - box_size ()); if (first_line_on_last_page < 0) first_line_on_last_page = 0; @@ -400,7 +400,7 @@ tui_data_window::erase_data_content (const char *prompt) check_and_display_highlight_if_needed (); if (prompt != NULL) { - int half_width = (width - 2) / 2; + int half_width = (width - box_size ()) / 2; int x_pos; if (strlen (prompt) >= half_width) diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c index 6625f0cf088..5e9a954f7c2 100644 --- a/gdb/tui/tui-source.c +++ b/gdb/tui/tui-source.c @@ -53,7 +53,7 @@ tui_source_window::set_contents (struct gdbarch *arch, /* Take hilite (window border) into account, when calculating the number of lines. */ - int nlines = height - 2; + int nlines = height - box_size (); std::string srclines; const std::vector *offsets; @@ -201,7 +201,7 @@ tui_source_window::line_is_displayed (int line) const void tui_source_window::maybe_update (frame_info_ptr fi, symtab_and_line sal) { - int start_line = (sal.line - ((height - 2) / 2)) + 1; + int start_line = (sal.line - ((height - box_size ()) / 2)) + 1; if (start_line <= 0) start_line = 1; diff --git a/gdb/tui/tui-wingeneral.c b/gdb/tui/tui-wingeneral.c index 5e1b3d2e62e..af4fc746cba 100644 --- a/gdb/tui/tui-wingeneral.c +++ b/gdb/tui/tui-wingeneral.c @@ -106,7 +106,7 @@ box_win (struct tui_win_info *win_info, { /* Emit "+-TITLE-+" -- so 2 characters on the right and 2 on the left. */ - int max_len = win_info->width - 2 - 2; + int max_len = win_info->width - win_info->box_size () - 2; if (win_info->title ().size () <= max_len) mvwaddstr (win, 0, 2, win_info->title ().c_str ()); diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c index 7eabc522d85..83ce48090a0 100644 --- a/gdb/tui/tui-winsource.c +++ b/gdb/tui/tui-winsource.c @@ -211,7 +211,7 @@ void tui_source_window_base::do_erase_source_content (const char *str) { int x_pos; - int half_width = (width - 2) / 2; + int half_width = (width - box_size ()) / 2; m_content.clear (); if (handle != NULL) @@ -347,7 +347,7 @@ tui_source_window_base::refresh_window () gdb_assert (pad_width > 0 || m_pad.get () == nullptr); gdb_assert (pad_x + view_width <= pad_width || m_pad.get () == nullptr); - int sminrow = y + 1; + int sminrow = y + box_width (); int smincol = x + left_margin; int smaxrow = sminrow + m_content.size () - 1; int smaxcol = smincol + view_width - 1; @@ -412,11 +412,15 @@ tui_source_window_base::show_source_content () for (int lineno = 0; lineno < m_content.size (); lineno++) show_source_line (lineno); - /* Calling check_and_display_highlight_if_needed will call refresh_window - (so long as the current window can be boxed), which will ensure that - the newly loaded window content is copied to the screen. */ - gdb_assert (can_box ()); - check_and_display_highlight_if_needed (); + if (can_box ()) + { + /* Calling check_and_display_highlight_if_needed will call refresh_window + (so long as the current window can be boxed), which will ensure that + the newly loaded window content is copied to the screen. */ + check_and_display_highlight_if_needed (); + } + else + refresh_window (); } tui_source_window_base::tui_source_window_base () @@ -693,7 +697,7 @@ tui_source_window_base::update_exec_info (bool refresh_p) if (src_element->is_exec_point) element[TUI_EXEC_POS] = '>'; - mvwaddstr (handle.get (), i + 1, 1, element); + mvwaddstr (handle.get (), i + box_width (), box_width (), element); show_line_number (i); } diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h index 4a355121906..dccce0efca1 100644 --- a/gdb/tui/tui-winsource.h +++ b/gdb/tui/tui-winsource.h @@ -206,13 +206,13 @@ struct tui_source_window_base : public tui_win_info /* Return the size of the left margin space, this is the space used to display things like breakpoint markers. */ int left_margin () const - { return 1 + TUI_EXECINFO_SIZE + extra_margin (); } + { return box_width () + TUI_EXECINFO_SIZE + extra_margin (); } /* Return the width of the area that is available for window content. This is the window width minus the borders and the left margin, which is used for displaying things like breakpoint markers. */ int view_width () const - { return width - left_margin () - 1; } + { return width - left_margin () - box_width (); } void show_source_content (); -- 2.35.3