From: Tom de Vries <tdevries@suse.de>
To: Simon Marchi <simark@simark.ca>, Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] [gdb/tui] Factor out tui_noscroll_window et al
Date: Thu, 22 Feb 2024 13:07:35 +0100 [thread overview]
Message-ID: <549c2044-4ec2-4072-a554-6a66e7ddee1d@suse.de> (raw)
In-Reply-To: <24af4ea8-5426-4ce4-b1c5-12858b38a952@simark.ca>
On 2/21/24 18:32, Simon Marchi wrote:
> On 11/13/23 12:08, Tom Tromey wrote:
>>>>>>> "Tom" == Tom de Vries <tdevries@suse.de> 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_source_window *> (tui_win_list[SRC_WIN]))
>> Tom> +#define TUI_DISASM_WIN \
>> Tom> + (dynamic_cast<tui_disasm_window *> (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<T> (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<T> (v);
> #ifdef DEVELOPMENT
> gdb_assert (result == dynamic_cast<T> (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.
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<T_no_P, V>::value,
> "types must be related");
>
> -#ifdef DEVELOPMENT
> - if (v == nullptr)
> - return nullptr;
> -
> - T result = dynamic_cast<T> (v);
> - gdb_assert (result != nullptr);
> -#else
> T result = static_cast<T> (v);
> +#ifdef DEVELOPMENT
> + gdb_assert (result == dynamic_cast<T> (v));
> #endif
>
> return result;
>
> Simon
next prev parent reply other threads:[~2024-02-22 12:07 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-12 15:06 Tom de Vries
2023-11-13 9:37 ` Tom de Vries
2023-11-13 17:09 ` Tom Tromey
2023-11-14 15:02 ` Tom de Vries
2023-11-13 17:08 ` Tom Tromey
2023-11-13 21:03 ` Tom de Vries
2023-11-14 14:13 ` Tom Tromey
2024-02-21 17:32 ` Simon Marchi
2024-02-22 12:07 ` Tom de Vries [this message]
2024-02-22 13:13 ` Tom de Vries
2024-02-22 15:07 ` Tom Tromey
2024-02-22 15:26 ` Tom de Vries
2024-02-23 1:39 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=549c2044-4ec2-4072-a554-6a66e7ddee1d@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
--cc=simark@simark.ca \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).