Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: Doug Evans <dje@google.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFC] printing/setting flag register fields
Date: Mon, 21 Sep 2009 16:43:00 -0000	[thread overview]
Message-ID: <m3bpl42qqr.fsf@fleche.redhat.com> (raw)
In-Reply-To: <e394668d0909201135u8a28d42t995db6256d75f277@mail.gmail.com> 	(Doug Evans's message of "Sun, 20 Sep 2009 11:35:31 -0700")

>>>>> "Doug" == Doug Evans <dje@google.com> 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)


      parent reply	other threads:[~2009-09-21 16:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-18 23:57 Doug Evans
2009-09-19  7:07 ` Mark Kettenis
2009-09-19  7:38   ` Andreas Schwab
2009-09-20 18:00 ` Daniel Jacobowitz
2009-09-20 18:35   ` Doug Evans
2009-09-20 20:27     ` Daniel Jacobowitz
2009-09-21 16:43     ` Tom Tromey [this message]

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=m3bpl42qqr.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=dje@google.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