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.
+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>
* ctf-create.c (ctf_compress_write): Fix double-free.
type's references. */
static char *
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;
{
ctf_id_t new_id;
char *str = NULL, *bit = NULL, *buf = NULL;
+ const char *nonroot_leader = "";
+ const char *nonroot_trailer = "";
+ if (flag == CTF_ADD_NONROOT)
+ {
+ nonroot_leader = "{";
+ nonroot_trailer = "}";
+ }
+
buf = ctf_type_aname (fp, id);
if (!buf)
goto oom;
buf = ctf_type_aname (fp, id);
if (!buf)
goto oom;
if (ctf_is_slice (fp, id, &enc))
{
ctf_type_encoding (fp, id, &enc);
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)
- 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)
if (asprintf (&str, "%s -> ", name) < 0)
return (ctf_set_errno (state->cds_fp, ENOMEM));
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. */
{
free (str);
return -1; /* errno is set for us. */
- 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. */
{
free (str);
return -1; /* errno is set for us. */
if (asprintf (&str, "%s -> ", name) < 0)
return (ctf_set_errno (state->cds_fp, ENOMEM));
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. */
{
free (str);
return -1; /* errno is set for us. */
/* Dump a single type into the cds_items. */
static int
/* 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;
{
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");
goto err;
str = ctf_str_append (str, "\n");
goto end; /* errno is set for us. */
break;
case CTF_SECT_TYPE:
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:
goto end; /* errno is set for us. */
break;
case CTF_SECT_STR: