From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16195 invoked by alias); 12 Jul 2011 18:31:50 -0000 Received: (qmail 16183 invoked by uid 22791); 12 Jul 2011 18:31:48 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD 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, 12 Jul 2011 18:31:35 +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 p6CIVYYv010389 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 12 Jul 2011 14:31:35 -0400 Received: from host1.jankratochvil.net ([10.3.113.13]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p6CIVWur021786 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 12 Jul 2011 14:31:34 -0400 Received: from host1.jankratochvil.net (localhost [127.0.0.1]) by host1.jankratochvil.net (8.14.4/8.14.4) with ESMTP id p6CIVVoe015476 for ; Tue, 12 Jul 2011 20:31:31 +0200 Received: (from jkratoch@localhost) by host1.jankratochvil.net (8.14.4/8.14.4/Submit) id p6CIVUTO015471 for gdb-patches@sourceware.org; Tue, 12 Jul 2011 20:31:30 +0200 Date: Tue, 12 Jul 2011 19:20:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: [doc patch] whatis vs. ptype - the difference Message-ID: <20110712183130.GA15349@host1.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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/msg00308.txt.bz2 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 * 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