public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jose E.Marchesi <jemarch@sourceware.org>
To: bfd-cvs@sourceware.org, gdb-cvs@sourceware.org
Subject: [binutils-gdb] libctf: dump: support non-root type dumping
Date: Thu, 03 Oct 2019 16:32:00 -0000	[thread overview]
Message-ID: <20191003163205.78756.qmail@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b4f0e09cd18e0dbeeecd303ed54f6f113146e857

commit b4f0e09cd18e0dbeeecd303ed54f6f113146e857
Author: Nick Alcock <nick.alcock@oracle.com>
Date:   Sat Jul 13 20:49:19 2019 +0100

    libctf: dump: support non-root type dumping
    
    Use the recently-added ctf_type_iter_all function to iterate over
    non-root types, too, indicating them via {....} surrounding the type
    description in the dump.
    
    libctf/
    	* ctf-dump.c (ctf_dump): Use ctf_type_iter_all to dump types, not
    	ctf_type_iter.
    	(ctf_dump_type): Pass down the flag from ctf_type_iter_all.
    	(ctf_dump_format_type): Add non-root-type { } notation.
    	Add root flag to prototype.
    	(ctf_dump_label): Adjust accordingly.
    	(ctf_dump_objts): Likewise.
    	(ctf_dump_var): Likewise.

Diff:
---
 libctf/ChangeLog  | 11 +++++++++++
 libctf/ctf-dump.c | 37 +++++++++++++++++++++++++------------
 2 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/libctf/ChangeLog b/libctf/ChangeLog
index 9e72d84..09353da 100644
--- a/libctf/ChangeLog
+++ b/libctf/ChangeLog
@@ -1,5 +1,16 @@
 2019-07-13  Nick Alcock  <nick.alcock@oracle.com>
 
+	* ctf-dump.c (ctf_dump): Use ctf_type_iter_all to dump types, not
+	ctf_type_iter.
+	(ctf_dump_type): Pass down the flag from ctf_type_iter_all.
+	(ctf_dump_format_type): Add non-root-type { } notation.
+	Add root flag to prototype.
+	(ctf_dump_label): Adjust accordingly.
+	(ctf_dump_objts): Likewise.
+	(ctf_dump_var): Likewise.
+
+2019-07-13  Nick Alcock  <nick.alcock@oracle.com>
+
 	* ctf-create.c (ctf_compress_write): Fix double-free.
 
 2019-07-13  Nick Alcock  <nick.alcock@oracle.com>
diff --git a/libctf/ctf-dump.c b/libctf/ctf-dump.c
index acb882b..0c0c224 100644
--- a/libctf/ctf-dump.c
+++ b/libctf/ctf-dump.c
@@ -95,7 +95,7 @@ ctf_is_slice (ctf_file_t *fp, ctf_id_t id, ctf_encoding_t *enc)
    type's references.  */
 
 static char *
-ctf_dump_format_type (ctf_file_t *fp, ctf_id_t id)
+ctf_dump_format_type (ctf_file_t *fp, ctf_id_t id, int flag)
 {
   ctf_id_t new_id;
   char *str = NULL, *bit = NULL, *buf = NULL;
@@ -104,8 +104,16 @@ ctf_dump_format_type (ctf_file_t *fp, ctf_id_t id)
   do
     {
       ctf_encoding_t enc;
+      const char *nonroot_leader = "";
+      const char *nonroot_trailer = "";
 
       id = new_id;
+      if (flag == CTF_ADD_NONROOT)
+	{
+	  nonroot_leader = "{";
+	  nonroot_trailer = "}";
+	}
+
       buf = ctf_type_aname (fp, id);
       if (!buf)
 	goto oom;
@@ -115,15 +123,17 @@ ctf_dump_format_type (ctf_file_t *fp, ctf_id_t id)
       if (ctf_is_slice (fp, id, &enc))
 	{
 	  ctf_type_encoding (fp, id, &enc);
-	  if (asprintf (&bit, " %lx: [slice 0x%x:0x%x]",
-			id, enc.cte_offset, enc.cte_bits) < 0)
+	  if (asprintf (&bit, " %s%lx: [slice 0x%x:0x%x]%s",
+			nonroot_leader, id, enc.cte_offset, enc.cte_bits,
+			nonroot_trailer) < 0)
 	    goto oom;
 	}
       else
 	{
-	  if (asprintf (&bit, " %lx: %s (size 0x%lx)", id, buf[0] == '\0' ?
-			"(nameless)" : buf,
-			(unsigned long) ctf_type_size (fp, id)) < 0)
+	  if (asprintf (&bit, " %s%lx: %s (size 0x%lx)%s", nonroot_leader,
+			id, buf[0] == '\0' ? "(nameless)" : buf,
+			(unsigned long) ctf_type_size (fp, id),
+			nonroot_trailer) < 0)
 	    goto oom;
 	}
       free (buf);
@@ -292,7 +302,8 @@ ctf_dump_label (const char *name, const ctf_lblinfo_t *info,
   if (asprintf (&str, "%s -> ", name) < 0)
     return (ctf_set_errno (state->cds_fp, ENOMEM));
 
-  if ((typestr = ctf_dump_format_type (state->cds_fp, info->ctb_type)) == NULL)
+  if ((typestr = ctf_dump_format_type (state->cds_fp, info->ctb_type,
+				       CTF_ADD_ROOT)) == NULL)
     {
       free (str);
       return -1;			/* errno is set for us.  */
@@ -348,7 +359,8 @@ ctf_dump_objts (ctf_file_t *fp, ctf_dump_state_t *state)
 	}
 
       /* Variable type.  */
-      if ((typestr = ctf_dump_format_type (state->cds_fp, type)) == NULL)
+      if ((typestr = ctf_dump_format_type (state->cds_fp, type,
+					   CTF_ADD_ROOT)) == NULL)
 	{
 	  free (str);
 	  return -1;			/* errno is set for us.  */
@@ -464,7 +476,8 @@ ctf_dump_var (const char *name, ctf_id_t type, void *arg)
   if (asprintf (&str, "%s -> ", name) < 0)
     return (ctf_set_errno (state->cds_fp, ENOMEM));
 
-  if ((typestr = ctf_dump_format_type (state->cds_fp, type)) == NULL)
+  if ((typestr = ctf_dump_format_type (state->cds_fp, type,
+				       CTF_ADD_ROOT)) == NULL)
     {
       free (str);
       return -1;			/* errno is set for us.  */
@@ -529,14 +542,14 @@ ctf_dump_member (const char *name, ctf_id_t id, unsigned long offset,
 /* Dump a single type into the cds_items.  */
 
 static int
-ctf_dump_type (ctf_id_t id, void *arg)
+ctf_dump_type (ctf_id_t id, int flag, void *arg)
 {
   char *str;
   ctf_dump_state_t *state = arg;
   ctf_dump_membstate_t membstate = { &str, state->cds_fp };
   size_t len;
 
-  if ((str = ctf_dump_format_type (state->cds_fp, id)) == NULL)
+  if ((str = ctf_dump_format_type (state->cds_fp, id, flag)) == NULL)
     goto err;
 
   str = ctf_str_append (str, "\n");
@@ -641,7 +654,7 @@ ctf_dump (ctf_file_t *fp, ctf_dump_state_t **statep, ctf_sect_names_t sect,
 	    goto end;			/* errno is set for us.  */
 	  break;
 	case CTF_SECT_TYPE:
-	  if (ctf_type_iter (fp, ctf_dump_type, state) < 0)
+	  if (ctf_type_iter_all (fp, ctf_dump_type, state) < 0)
 	    goto end;			/* errno is set for us.  */
 	  break;
 	case CTF_SECT_STR:


                 reply	other threads:[~2019-10-03 16:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20191003163205.78756.qmail@sourceware.org \
    --to=jemarch@sourceware.org \
    --cc=bfd-cvs@sourceware.org \
    --cc=gdb-cvs@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).