From: Simon Marchi <simon.marchi@ericsson.com>
To: Martin Richtarsky <s@martinien.de>, <gdb@sourceware.org>
Subject: Re: MI: -var-create does not resolve typedefs
Date: Tue, 17 Jul 2018 14:38:00 -0000 [thread overview]
Message-ID: <920a0f43-7ccf-5805-61d7-7fb645d4fbb3@ericsson.com> (raw)
In-Reply-To: <8d8b95e9218d09f8d808936b4a9f163e-EhVcX1dJRwNeRwQRAQsKVxcwfgFLV15YQUBGAEFbWkA3VF0NQVpwH1FRQ15bQyoDWllYRVlWWQ1e-webmailer1@server03.webmailer.hosteurope.de>
On 2018-07-13 04:19 PM, Martin Richtarsky wrote:
> Hi,
>
> the result of the -var-create command is documented here [1] as follows:
>
> 'type'
>
> The varobj's type. This is a string representation of the type, as
> would be printed by the GDB CLI.
>
> However, for a typedef this does not seem to hold:
>
> $ cat mi.cpp
> #include <string>
> #include <vector>
>
> typedef std::vector<std::string> StringVec;
> typedef int MyInt;
>
> int main()
> {
> size_t a = 0;
> StringVec sv;
> MyInt i;
> return 0;
> }
>
> $ g++ -g2 mi.cpp
> $ gdb --interpreter=mi a.out
> ...
> 1-var-create - * "a"
> 1^done,name="var1",numchild="0",value="4195792",type="size_t",thread-id="1",has_more="0"
> (gdb)
> 2-var-create - * "sv"
> 2^done,name="var2",numchild="1",value="{...}",type="StringVec",thread-id="1",has_more="0"
> (gdb)
> ptype(a)
> &"ptype(a)\n"
> ~"type = unsigned long\n"
> ^done
> (gdb)
> ptype(sv)
> &"ptype(sv)\n"
> ~"type = class std::vector<std::basic_string<char, std::char_traits<char>,
> std::allocator<char> >, std::allocator<std::basic_string<char,
> std::char_traits<char>, std::allocator<char> > > > [with _Tp =
> std::basic_string<char, std::char_traits<char>, std::allocator<char> >,
> _Alloc = std::allocator<std::basic_string<char, std::char_traits<char>,
> std::allocator<char> > >] : protected std::_Vector_base<_Tp, _Alloc> {\n"
> ~" public:\n"
>
>
> Note how ptype resolves the typedef, but -var-create just shows the alias.
>
> The issue can be solved by a simple patch:
>
> --- a/gdb/varobj-orig.c
> +++ b/gdb/varobj.c
> @@ -905,7 +905,7 @@ varobj_get_type (struct varobj *var)
> if (CPLUS_FAKE_CHILD (var) || !var->root->is_valid)
> return std::string ();
>
> - return type_to_string (var->type);
> + return type_to_string (check_typedef(var->type));
> }
>
> /* Obtain the type of an object variable. */
>
>
> This would also solve the issue I'm having when using MI with a split
> dwarf build and a gold index [2]
>
> Is this a bug or is the typedef intentionally not resolved?
>
> [1]
> https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Variable-Objects.html
> [2] https://sourceware.org/bugzilla/show_bug.cgi?id=23042
>
> Best regards,
> Martin
>
Hi Martin,
I think it's on purpose that it gives the original type representation, as used
in the code. That type is going to end up in the "variables" view of the various
frontends. The type name as used in the code is more meaningful to the user than
the possibly complex resolved type.
Also, it's always possible for the frontend to ask GDB to resolve the typedef, but
it's not possible to go back. So resolving the typedef right away would loose some
important information. If people think it would be useful, it would probably be
possible to add a "resolved_type" field to the -var-create response. That's not
really what you are after though I believe.
As mentioned in the doc [1], ptype's goal is to resolve typedefs, whereas whatis does
not. I don't see any reason why -var-create should follow ptype's behavior specifically.
Simon
[1] https://sourceware.org/gdb/onlinedocs/gdb/Symbols.html
next prev parent reply other threads:[~2018-07-17 14:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-13 20:19 Martin Richtarsky
2018-07-17 14:38 ` Simon Marchi [this message]
2018-09-07 14:50 ` Martin Richtarsky
2018-09-08 11:01 ` 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=920a0f43-7ccf-5805-61d7-7fb645d4fbb3@ericsson.com \
--to=simon.marchi@ericsson.com \
--cc=gdb@sourceware.org \
--cc=s@martinien.de \
/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