From: Simon Marchi <simon.marchi@polymtl.ca>
To: Pedro Alves <pedro@palves.net>, Tom Tromey <tom@tromey.com>,
Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH 4/4] gdb: make internalvar use a variant
Date: Wed, 16 Mar 2022 09:28:54 -0400 [thread overview]
Message-ID: <4138352c-7cef-fe08-47c8-1d69308a542d@polymtl.ca> (raw)
In-Reply-To: <410969bd-7d08-f81d-638a-39dde9ff4fd4@palves.net>
On 2022-03-16 09:26, Pedro Alves wrote:
> On 2022-03-16 02:06, Simon Marchi wrote:
>
>> With std:
>>
>>
>> $1 = {
>> next = 0x60600000ff20,
>> name = 0x602000085350 "salut",
>> v = std::variant<internalvar_void, internalvar_value, internalvar_make_value, internalvar_function, internalvar_integer, internalvar_string> [index 0] = {{<No data fields>}}
>> }
>>
>>> AFAICT from variant.cpp source file, the variant storage is an untyped buffer:
>>>
>>> enum { data_align = detail::typelist_max_alignof< variant_types >::value };
>>>
>>> using aligned_storage_t = typename std::aligned_storage< data_size, data_align >::type;
>>> aligned_storage_t data;
>>>
>>> so I guess printing a nonstd::variant results in pretty opaque output. We'd need a pretty
>>> printer to fix this. Or maybe we just assume that people developing/debugging GDB build
>>> it against a C++17 or higher compiler? (Not sure that's a great assumption.)
>>
>> Do you know off-hand if the std::variant pretty printer is supposed to
>> show the active data field?
>
> I think that's already shown in your "with std" output above. It just happens that
> internalvar_void has no data fields. E.g., with:
> $ cat ./variant.cc
>
> #include <string>
> #include <variant>
>
> int
> main ()
> {
> std::variant<std::string, int> v;
>
> v = "hello";
> v = 1;
>
> return 0;
> }
>
> Stepping through the assignment lines, I get:
>
> (gdb) p v
> $1 = std::variant<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> [index 0] = {"hello"}
> (gdb) n
> (gdb) p v
> $2 = std::variant<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> [index 1] = {1}
>
> I wouldn't say this is super ideal output, as it forces you to count the types to
> know what index 0 and 1 are, though, as well as puts the data far off to the right.
Oh, yeah, thanks for pointing that out, seems obvious now. I was
assigning an integer, so I thought I was printing an integer
internalval, but no.
Simon
next prev parent reply other threads:[~2022-03-16 13:29 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-01 14:07 [PATCH 0/4] Add variant type Simon Marchi
2022-02-01 14:07 ` [PATCH 1/4] gdb: remove internalvar_funcs::destroy Simon Marchi
2022-03-04 16:15 ` Tom Tromey
2022-03-06 16:33 ` Simon Marchi
2022-02-01 14:07 ` [PATCH 2/4] gdb: constify parameter of value_copy Simon Marchi
2022-03-04 16:16 ` Tom Tromey
2022-03-06 16:33 ` Simon Marchi
2022-02-01 14:07 ` [PATCH 3/4] gdbsupport: add variant-lite header Simon Marchi
2022-02-01 14:07 ` [PATCH 4/4] gdb: make internalvar use a variant Simon Marchi
2022-03-04 16:23 ` Tom Tromey
2022-03-07 12:12 ` Pedro Alves
2022-03-16 2:06 ` Simon Marchi
2022-03-16 13:26 ` Pedro Alves
2022-03-16 13:28 ` Simon Marchi [this message]
2022-02-03 0:02 ` [PATCH 0/4] Add variant type Andrew Burgess
2022-02-03 1:32 ` Simon Marchi
2022-02-04 12:44 ` Andrew Burgess
2022-02-04 13:19 ` Simon Marchi
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=4138352c-7cef-fe08-47c8-1d69308a542d@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.org \
--cc=pedro@palves.net \
--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).