From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30589 invoked by alias); 28 Aug 2007 17:14:42 -0000 Received: (qmail 30076 invoked by uid 22791); 28 Aug 2007 17:14:39 -0000 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 28 Aug 2007 17:14:27 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 7FACB2AAB7F; Tue, 28 Aug 2007 13:14:25 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id vbxT3tj6z-UM; Tue, 28 Aug 2007 13:14:25 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 2AB7C2AAB7A; Tue, 28 Aug 2007 13:14:25 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id E8309E7B58; Tue, 28 Aug 2007 10:14:22 -0700 (PDT) Date: Tue, 28 Aug 2007 17:14:00 -0000 From: Joel Brobecker To: Carlos Eduardo Seo Cc: gdb-patches@sourceware.org Subject: Re: [patch] ptype: show members of an unnamed struct inside an union Message-ID: <20070828171422.GB3874@adacore.com> References: <46C4D20E.1010703@linux.vnet.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <46C4D20E.1010703@linux.vnet.ibm.com> User-Agent: Mutt/1.4.2.2i 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: 2007-08/txt/msg00494.txt.bz2 Carlos, > The attached patched fixes an issue described on this post: > > http://sourceware.org/ml/gdb-patches/2002-04/msg01114.html > > Any comments? It actually seems to me that the current behavior is expected. It's not actually a question of named vs unnamed structure, but rather a question of nesting. Consider the following example: struct inner { int mapping; }; struct outer { int a; struct inner b; struct { int c; struct { int d; } e; } f; }; Doing a "ptype" on type "outer" yields: type = struct outer { int a; struct inner b; struct { int c; struct {...} e; } f; } Basically, the idea here is to avoid going too deep into the type structure by only printing complete information for the immediate fields of our structure (that's nesting level 1). For nesting level 2, we print the type name only (eg: "struct inner b"), or, when the field has an unnamed type, a concise description of that type: That's why we printed "struct { int c; ... }". For nesting level 3, we try to be even more concise, which means the type name if we have one, or "struct {...}" if we don't. See also the description of the function you tried to modify: SHOW positive means print details about the type (e.g. enum values), and print structure elements passing SHOW - 1 for show. SHOW negative means just print the type name or struct tag if there is one. If there is no name, print something sensible but concise like "struct {...}". SHOW zero means just print the type name or struct tag if there is one. If there is no name, print something sensible but not as concise like "struct {int x; int y;}". So, in order to get the type description for our nested structure, we just need to get one level deeper by doing the following: (gdb) ptype my_outer.f type = struct { int c; struct { int d; } e; } Similarly in your example: (gdb) ptype mypage.u type = union { struct { int mapping; }; } I looked at the current GDB documentation for "ptype" and couldn't find anything that confirmed my analysis. I think a contribution to the documentation would be very much appreciated. In the meantime, I will submit a testcase in our testsuite that would have failed if you patch had been applied. -- Joel