From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id B09033858418 for ; Thu, 22 Feb 2024 13:13:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B09033858418 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 B09033858418 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708607608; cv=none; b=GtZomA9sOegf7PJyvENF4fdlX0pkOM3CAxJRSVc90lExSwTitQgeu2SAfVUrpd6w1FB8TkTCmNIJczV5bhPRKbSWvYKR0D9W/1Vr8Zst+l/N0MeJpa6JPVUUelim+empLb7+O3isv+xNy78zJwOupGsylYumPJ+5mloxkYgkSAg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708607608; c=relaxed/simple; bh=pKy9xj8BIBW3mjUdBe7Lpg0gbCgejzLUMTHvej0iOpA=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature: Message-ID:Date:MIME-Version:Subject:From:To; b=OtiqHFN3ZF5vB7ajMpUVCEJ050pkaHETuGC6LIJ4T7OUkK5vVPBZ5jFbjXiioERG3q+hHN+p/kQe5f7n2yEIyURoUuLyfaqepW+umnJWcZC7duPDX8gKUzjoXgNZn0fGGq+UD9kwsNPZrs6vQQvpAMNiL2X+UHpwDTcX6kfqDdM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id C483E1F7B5; Thu, 22 Feb 2024 13:13:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1708607603; h=from:from:reply-to: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=7e/EQhDz6rFLABZ7CGQ46CiKvQDUZjigF989oADNq1A=; b=ebk4N3AigaAO+OYajpEIneRChZ+ynRUyG6Pp4EQh6LAqMrOa4PlryiLpmTdu6oaTCHBdVJ OVUineCsRhaqEcrjwMJDBKefEBCYw7d1Lx7QzVx1DGmDUL8B7JTBxOWgR5wCfeAeeLR+rj ddX5Lr2/AvxoOcwlODtFwQJdIJW/UsM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1708607603; h=from:from:reply-to: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=7e/EQhDz6rFLABZ7CGQ46CiKvQDUZjigF989oADNq1A=; b=do4vQT79rQGffdGOrnftrPgGRyPgSrFJeUAepeSmbWqouxjdLkRoxBdAvzc0rIMYPHMrbg KoBQkyW2y7OvFFAQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1708607603; h=from:from:reply-to: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=7e/EQhDz6rFLABZ7CGQ46CiKvQDUZjigF989oADNq1A=; b=ebk4N3AigaAO+OYajpEIneRChZ+ynRUyG6Pp4EQh6LAqMrOa4PlryiLpmTdu6oaTCHBdVJ OVUineCsRhaqEcrjwMJDBKefEBCYw7d1Lx7QzVx1DGmDUL8B7JTBxOWgR5wCfeAeeLR+rj ddX5Lr2/AvxoOcwlODtFwQJdIJW/UsM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1708607603; h=from:from:reply-to: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=7e/EQhDz6rFLABZ7CGQ46CiKvQDUZjigF989oADNq1A=; b=do4vQT79rQGffdGOrnftrPgGRyPgSrFJeUAepeSmbWqouxjdLkRoxBdAvzc0rIMYPHMrbg KoBQkyW2y7OvFFAQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id A72C813A8C; Thu, 22 Feb 2024 13:13:23 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id U2ZyJ3NI12UfNgAAD6G6ig (envelope-from ); Thu, 22 Feb 2024 13:13:23 +0000 Message-ID: <668e8103-04e8-4ae1-934a-e64f6fd4dc40@suse.de> Date: Thu, 22 Feb 2024 14:13:21 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] [gdb/tui] Factor out tui_noscroll_window et al Content-Language: en-US From: Tom de Vries To: Simon Marchi , Tom Tromey Cc: gdb-patches@sourceware.org References: <20231112150601.25484-1-tdevries@suse.de> <87r0kttwba.fsf@tromey.com> <24af4ea8-5426-4ce4-b1c5-12858b38a952@simark.ca> <549c2044-4ec2-4072-a554-6a66e7ddee1d@suse.de> In-Reply-To: <549c2044-4ec2-4072-a554-6a66e7ddee1d@suse.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Level: Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ebk4N3Ai; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=do4vQT79 X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.48 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; XM_UA_NO_VERSION(0.01)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; NEURAL_HAM_LONG(-1.00)[-1.000]; BAYES_HAM(-3.00)[100.00%]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+]; MX_GOOD(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; NEURAL_HAM_SHORT(-0.18)[-0.920]; RCVD_TLS_ALL(0.00)[]; MID_RHS_MATCH_FROM(0.00)[] X-Spam-Score: -4.48 X-Rspamd-Queue-Id: C483E1F7B5 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00,BODY_8BITS,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: On 2/22/24 13:07, Tom de Vries wrote: > On 2/21/24 18:32, Simon Marchi wrote: >> On 11/13/23 12:08, Tom Tromey wrote: >>>>>>>> "Tom" == Tom de Vries writes: >>> >>> Tom> +/* A TUI window that doesn't scroll.  */ >>> Tom> + >>> Tom> +struct tui_noscroll_window : public virtual tui_win_info { >>> >>> The "{" should be on the next line. >>> >>> Tom> +/* A TUI window that occupies a single line.  */ >>> Tom> + >>> Tom> +struct tui_oneline_window : public virtual tui_win_info { >>> >>> Some of these only have a single use.  That seems like overkill to me, >>> unless we're introducing another use someday. >>> >>> Tom> +#define TUI_SRC_WIN \ >>> Tom> +  (dynamic_cast (tui_win_list[SRC_WIN])) >>> Tom> +#define TUI_DISASM_WIN \ >>> Tom> +  (dynamic_cast (tui_win_list[DISASSEM_WIN])) >>> >>> I think these should use gdb::checked_static_cast. >> >> Actually, since the base is virtual, dynamic_cast is needed.  Try >> changing development to false in bfd/development.sh, you'll get: >> >>        CXX    tui/tui-layout.o >>      In file included from >> /home/smarchi/src/binutils-gdb/gdb/tui/tui-data.h:31, >>                       from >> /home/smarchi/src/binutils-gdb/gdb/tui/tui-command.h:25, >>                       from >> /home/smarchi/src/binutils-gdb/gdb/tui/tui-layout.c:31: >> >> /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/gdb-checked-static-cast.h: In instantiation of ‘T gdb::checked_static_cast(V*) [with T = tui_cmd_window*; V = tui_win_info]’: >>      /home/smarchi/src/binutils-gdb/gdb/tui/tui-layout.c:79:3: >> required from here >> >> /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/gdb-checked-static-cast.h:64:14: error: cannot convert from pointer to base class ‘tui_win_info’ to pointer to derived class ‘tui_cmd_window’ because the base is virtual >>         64 |   T result = static_cast (v); >>            |              ^~~~~~~~~~~~~~~~~~ >> >> It might be a good idea to add a static_cast in the DEVELOPMENT branch >> of checked_static_cast to catch this kind of mistake.  I think it could >> be written this way to be succinct (but untested): >> >> >>        T result = static_cast (v); >>      #ifdef DEVELOPMENT >>        gdb_assert (result == dynamic_cast (v)); >>      #endif >> >>        return result; >> >> IOW, this patch: >> > > Hi Simon, > > LGTM.  Also I can confirm that the patch catches the problem show above > (which was reported as PR31399). > > I'll write a fix for that PR, and test with your patch applied as well. > A note on the checked_static_cast patch, or rather the static_cast it self. It catches the problem at build time for TUI_STATUS_WIN and TUI_CMD_WIN, but not for the other 3. I think the problem exists though for all 5 windows (tui_win_info is a virtual base of all 5 windows), so I'm gonna use dynamic_cast for all of them. IWBN to catch the other 3 cases as well, but I'm not sure if or how this can be done. Thanks, - Tom > Thanks, > - Tom > > >> diff --git a/gdbsupport/gdb-checked-static-cast.h >> b/gdbsupport/gdb-checked-static-cast.h >> index b6ce8c8bb04..e935bb359f0 100644 >> --- a/gdbsupport/gdb-checked-static-cast.h >> +++ b/gdbsupport/gdb-checked-static-cast.h >> @@ -54,14 +54,9 @@ checked_static_cast (V *v) >>                   || std::is_base_of::value, >>                   "types must be related"); >> >> -#ifdef DEVELOPMENT >> -  if (v == nullptr) >> -    return nullptr; >> - >> -  T result = dynamic_cast (v); >> -  gdb_assert (result != nullptr); >> -#else >>     T result = static_cast (v); >> +#ifdef DEVELOPMENT >> +  gdb_assert (result == dynamic_cast (v)); >>   #endif >> >>     return result; >> >> Simon >