From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22723 invoked by alias); 21 Sep 2009 16:43:23 -0000 Received: (qmail 22710 invoked by uid 22791); 21 Sep 2009 16:43:22 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_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; Mon, 21 Sep 2009 16:43:14 +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.13.8/8.13.8) with ESMTP id n8LGhA1L014621; Mon, 21 Sep 2009 12:43:10 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n8LGh9kS020740; Mon, 21 Sep 2009 12:43:09 -0400 Received: from opsy.redhat.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n8LGh8ja027863; Mon, 21 Sep 2009 12:43:09 -0400 Received: by opsy.redhat.com (Postfix, from userid 500) id 44108378198; Mon, 21 Sep 2009 10:43:08 -0600 (MDT) From: Tom Tromey To: Doug Evans Cc: gdb-patches@sourceware.org Subject: Re: [RFC] printing/setting flag register fields References: <20090918235632.0DDC6843AC@ruffy.mtv.corp.google.com> <20090920180036.GA19867@caradoc.them.org> Reply-To: tromey@redhat.com Date: Mon, 21 Sep 2009 16:43:00 -0000 In-Reply-To: (Doug Evans's message of "Sun, 20 Sep 2009 11:35:31 -0700") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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: 2009-09/txt/msg00670.txt.bz2 >>>>> "Doug" == Doug Evans writes: Doug> An off-the-cuff example is an option to ptype to print field Doug> offsets for structs in general. [I'm assuming such a facility Doug> doesn't already exist.] That would probably be more useful than Doug> always printing the offsets anyway. I once wrote a simple, C/C++-only patch to add pahole-like output to ptype. I appended it. Also in the archer repository there is a "pahole" command written in Python. It does something similar. I like the idea of an option to ptype. Tom diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c index 56d12f9..c38fc31 100644 --- a/gdb/c-typeprint.c +++ b/gdb/c-typeprint.c @@ -744,6 +744,9 @@ c_type_print_base (struct type *type, struct ui_file *stream, int show, } else if (show > 0 || TYPE_TAG_NAME (type) == NULL) { + int bitpos, field_size; + int is_union = TYPE_CODE (type) == TYPE_CODE_UNION; + cp_type_print_derivation_info (stream, type); fprintf_filtered (stream, "{\n"); @@ -830,6 +833,7 @@ c_type_print_base (struct type *type, struct ui_file *stream, int show, /* If there is a base class for this type, do not print the field that it occupies. */ + bitpos = 0; len = TYPE_NFIELDS (type); for (i = TYPE_N_BASECLASSES (type); i < len; i++) { @@ -871,6 +875,25 @@ c_type_print_base (struct type *type, struct ui_file *stream, int show, } } + if (!is_union && bitpos != TYPE_FIELD_BITPOS (type, i)) + { + fprintf_filtered (stream, + "\n /* XXX %d bit hole, try to pack */\n\n", + TYPE_FIELD_BITPOS (type, i) - bitpos); + bitpos = TYPE_FIELD_BITPOS (type, i); + } + if (TYPE_FIELD_PACKED (type, i)) + field_size = TYPE_FIELD_BITSIZE (type, i); + else + field_size = 8 * TYPE_LENGTH (TYPE_FIELD_TYPE (type, i)); /* FIXME */ + + if (is_union) + print_spaces_filtered (14, stream); + else + fprintf_filtered (stream, " /* %3d %3d */", + bitpos / 8, field_size / 8); + bitpos += field_size; + print_spaces_filtered (level + 4, stream); if (TYPE_FIELD_STATIC (type, i)) { @@ -1036,6 +1059,8 @@ c_type_print_base (struct type *type, struct ui_file *stream, int show, } } + if (level) + print_spaces_filtered (14, stream); fprintfi_filtered (level, stream, "}"); if (TYPE_LOCALTYPE_PTR (type) && show >= 0)