From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17858 invoked by alias); 26 Jul 2011 01:01:23 -0000 Received: (qmail 17849 invoked by uid 22791); 26 Jul 2011 01:01:22 -0000 X-SWARE-Spam-Status: No, hits=-7.0 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 26 Jul 2011 01:01:02 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p6Q110TB032406 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 25 Jul 2011 21:01:00 -0400 Received: from host1.jankratochvil.net (ovpn-116-20.ams2.redhat.com [10.36.116.20]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p6Q10vBe001113 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 25 Jul 2011 21:00:59 -0400 Received: from host1.jankratochvil.net (localhost [127.0.0.1]) by host1.jankratochvil.net (8.14.4/8.14.4) with ESMTP id p6Q10t0r025875; Tue, 26 Jul 2011 03:00:55 +0200 Received: (from jkratoch@localhost) by host1.jankratochvil.net (8.14.4/8.14.4/Submit) id p6Q10s78022879; Tue, 26 Jul 2011 03:00:54 +0200 Date: Tue, 26 Jul 2011 02:58:00 -0000 From: Jan Kratochvil To: Eli Zaretskii Cc: gdb-patches@sourceware.org Subject: ping: Re: [doc patch] whatis vs. ptype - the difference Message-ID: <20110726010054.GA30935@host1.jankratochvil.net> References: <20110712183130.GA15349@host1.jankratochvil.net> <8339i7j4ng.fsf@gnu.org> <20110715153335.GA25834@host1.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20110715153335.GA25834@host1.jankratochvil.net> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-07/txt/msg00716.txt.bz2 Hi Eli, OK to check it in as is? Thanks, Jan On Fri, 15 Jul 2011 17:33:35 +0200, Jan Kratochvil wrote: On Fri, 15 Jul 2011 11:04:51 +0200, Eli Zaretskii wrote: > How about the text below? Great; I just have changed there members->methods. is a compound data type, such as @code{struct} or @code{class}, @code{whatis} never prints their fields or [-members.-]{+methods.+} IMO any "child" of a struct is a member. Such member can be field, method or typedef(*). Therefore the text would either state just "member" or state "field, method or typedef". Stating "field or member" seems weird to me. (*) That is a class typedef, not a subject of ptype unrolling. class typedef is IMO an uncommon construct: class C { typedef int t; t i; } c; Plus whatis does not unroll one level, that is a bug, going to fix it. > The only nit that I'm not yet sure about is at the end: "typedefs > ... at the pointer target". What do you mean by that? can you show an > example? Sorry, thanks for finding it. So far I had wrong ptype expectation myself, pointer target typedefs _are_ unrolled by typedef. Changed the text + extended the sample code accordingly. First is included informal wdiff between Eli's text and this one. The patch with ChangeLog at the bottom is against FSF GDB HEAD. ------------------------------------------------------------------------------ wdiff against Eli's text: @@ -13876,7 +13876,7 @@ defined using a @code{typedef}, @code{whatis} will @emph{not} print the data type underlying the @code{typedef}. If the type of the variable or the expression is a compound data type, such as @code{struct} or @code{class}, @code{whatis} never prints their fields or [-members.-]{+methods.+} It just prints the @code{struct}/@code{class} name (a.k.a.@: its @dfn{tag}). If you want to see the members of such a compound data type, use @code{ptype}. @@ -13901,9 +13901,10 @@ Contrary to @code{whatis}, @code{ptype} always unrolls any @code{typedef}s in its argument declaration, whether the argument is a variable, expression, or a data type. This means that @code{ptype} of a variable or an expression will not print literally its type as present in the source code---use @code{whatis} for that.[-Any-] @code{typedef}s[-in fields of a @samp{struct} or-] at the pointer [-target-]{+or reference targets are also unrolled. Only @code{typedef}s of+} {+fields, methods and inner @code{class typedef}s of @code{struct}s,+} {+@code{class}es and @code{union}s+} are [-always preserved by-]{+not unrolled even with+} @code{ptype}. For example, for this variable declaration: @@ -13911,7 +13912,8 @@ For example, for this variable declaration: typedef double real_t; struct complex @{ real_t real; double imag; @}; typedef struct complex complex_t; complex_t [-v;-]{+var;+} {+real_t *real_pointer_var;+} @end smallexample @noindent @@ -13919,9 +13921,9 @@ the two commands give this output: @smallexample @group (@value{GDBP}) whatis [-v-]{+var+} type = complex_t (@value{GDBP}) ptype [-v-]{+var+} type = struct complex @{ real_t real; double imag; @@ -13935,6 +13937,10 @@ type = struct complex @{ real_t real; double imag; @} {+(@value{GDBP}) whatis real_pointer_var+} {+type = real_t *+} {+(@value{GDBP}) ptype real_pointer_var+} {+type = double *+} @end group @end smallexample ------------------------------------------------------------------------------ against FSF GDB HEAD: 2011-07-15 Jan Kratochvil Eli Zaretskii * gdb.texinfo (whatis, ptype): Highlight their differences. Describe typedefs unrolling. Extend the sample code by an inner typedef and outer typedefs unrolling. --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -13862,16 +13862,34 @@ __read_nocancel + 6 in section .text of /usr/lib64/libc.so.6 @kindex whatis @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}. +Print the data type of @var{arg}, which can be either an expression +or a name of 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 (@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. + +If @var{arg} is a variable or an expression, @code{whatis} prints its +literal type as it is used in the source code. If the type was +defined using a @code{typedef}, @code{whatis} will @emph{not} print +the data type underlying the @code{typedef}. If the type of the +variable or the expression is a compound data type, such as +@code{struct} or @code{class}, @code{whatis} never prints their +fields or methods. It just prints the @code{struct}/@code{class} +name (a.k.a.@: its @dfn{tag}). If you want to see the members of +such a compound data type, use @code{ptype}. + +If @var{arg} is a type name that was defined using @code{typedef}, +@code{whatis} @dfn{unrolls} only one level of that @code{typedef}. +Unrolling means that @code{whatis} will show the underlying type used +in the @code{typedef} declaration of @var{arg}. However, if that +underlying type is also a @code{typedef}, @code{whatis} will not +unroll it. + +For C code, the type names may also have the form @samp{class +@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union +@var{union-tag}} or @samp{enum @var{enum-tag}}. @kindex ptype @item ptype [@var{arg}] @@ -13879,10 +13897,23 @@ 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}. +Contrary to @code{whatis}, @code{ptype} always unrolls any +@code{typedef}s in its argument declaration, whether the argument is +a variable, expression, or a data type. This means that @code{ptype} +of a variable or an expression will not print literally its type as +present in the source code---use @code{whatis} for that. @code{typedef}s at +the pointer or reference targets are also unrolled. Only @code{typedef}s of +fields, methods and inner @code{class typedef}s of @code{struct}s, +@code{class}es and @code{union}s are not unrolled even with @code{ptype}. + For example, for this variable declaration: @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 var; +real_t *real_pointer_var; @end smallexample @noindent @@ -13890,13 +13921,26 @@ the two commands give this output: @smallexample @group -(@value{GDBP}) whatis v +(@value{GDBP}) whatis var +type = complex_t +(@value{GDBP}) ptype var +type = struct complex @{ + real_t real; + double imag; +@} +(@value{GDBP}) whatis complex_t +type = struct complex +(@value{GDBP}) whatis struct complex type = struct complex -(@value{GDBP}) ptype v +(@value{GDBP}) ptype struct complex type = struct complex @{ - double real; + real_t real; double imag; @} +(@value{GDBP}) whatis real_pointer_var +type = real_t * +(@value{GDBP}) ptype real_pointer_var +type = double * @end group @end smallexample