From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: gdb-patches@sourceware.org
Subject: [doc patch] whatis vs. ptype - the difference
Date: Tue, 12 Jul 2011 19:20:00 -0000 [thread overview]
Message-ID: <20110712183130.GA15349@host1.jankratochvil.net> (raw)
Hi,
another possibility is to fix it - that `ptype var' strips the typedefs looks
wrong. But GDB people are used how it works.
The patch just describes the current behavior. With my English waiting for
a doc review.
Thanks,
Jan
gdb/doc/
2011-07-12 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.texinfo (whatis, ptype): Highlight their differences. Describe
typedefs unrolling. Extend the sample code by an inned typedef and
outer typedefs unrolling.
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -13864,14 +13864,20 @@ __read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
@item whatis [@var{arg}]
Print the data type of @var{arg}, which can be either an expression or
a data type. With no argument, print the data type of @code{$}, the
-last value in the value history. If @var{arg} is an expression, it is
-not actually evaluated, and any side-effecting operations (such as
-assignments or function calls) inside it do not take place. If
-@var{arg} is a type name, it may be the name of a type or typedef, or
-for C code it may have the form @samp{class @var{class-name}},
-@samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or
-@samp{enum @var{enum-tag}}.
-@xref{Expressions, ,Expressions}.
+last value in the value history.
+
+If @var{arg} is an expression (@pxref{Expressions, ,Expressions}), it is not
+actually evaluated, and any side-effecting operations (such as assignments or
+function calls) inside it do not take place. @code{whatis} prints the type of
+@var{arg} as used in the source code, possibly including any typedefs.
+@code{whatis} never prints fields of compound types like @samp{struct}s.
+
+If @var{arg} is a type name, it may be the name of a type or typedef, or for
+C code it may have the form @samp{class @var{class-name}}, @samp{struct
+@var{struct-tag}}, @samp{union @var{union-tag}} or @samp{enum @var{enum-tag}}.
+@code{whatis} unrolls in such case only one layer of outer typedef at a time.
+Any inner typedefs --- such as fields of @samp{struct} or typedefs at the
+pointer target --- are always preserved by both @code{whatis} and @code{ptype}.
@kindex ptype
@item ptype [@var{arg}]
@@ -13879,10 +13885,18 @@ for C code it may have the form @samp{class @var{class-name}},
detailed description of the type, instead of just the name of the type.
@xref{Expressions, ,Expressions}.
-For example, for this variable declaration:
+@code{ptype} always unrolls all outer typedefs contrary to @code{whatis}.
+@code{ptype} of an expression (variable) will not print its real type including
+possible typedefs as present in the source code -- use @code{whatis} for that
+purpose. Any inner typedefs --- such as fields of @samp{struct} or typedefs at
+the pointer target --- are always preserved by both @code{whatis} and
+@code{ptype}.
@smallexample
-struct complex @{double real; double imag;@} v;
+typedef double real_t;
+struct complex @{ real_t real; double imag; @};
+typedef struct complex complex_t;
+complex_t v;
@end smallexample
@noindent
@@ -13891,10 +13905,19 @@ the two commands give this output:
@smallexample
@group
(@value{GDBP}) whatis v
-type = struct complex
+type = complex_t
(@value{GDBP}) ptype v
type = struct complex @{
- double real;
+ real_t real;
+ double imag;
+@}
+(@value{GDBP}) whatis complex_t
+type = struct complex
+(@value{GDBP}) whatis struct complex
+type = struct complex
+(@value{GDBP}) ptype struct complex
+type = struct complex @{
+ real_t real;
double imag;
@}
@end group
next reply other threads:[~2011-07-12 18:31 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-12 19:20 Jan Kratochvil [this message]
2011-07-12 20:28 ` Eli Zaretskii
2011-07-12 20:38 ` Jan Kratochvil
2011-07-12 20:43 ` Eli Zaretskii
2011-07-12 20:30 ` Tom Tromey
2011-07-15 14:17 ` Eli Zaretskii
2011-07-15 18:07 ` Jan Kratochvil
2011-07-19 13:52 ` Pedro Alves
2011-07-26 2:58 ` ping: " Jan Kratochvil
2011-07-26 8:36 ` Eli Zaretskii
2011-07-26 18:11 ` Jan Kratochvil
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=20110712183130.GA15349@host1.jankratochvil.net \
--to=jan.kratochvil@redhat.com \
--cc=gdb-patches@sourceware.org \
/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