Print this page
12259 CTF shouldn't assume enum size

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/ctfdump/ctfdump.c
          +++ new/usr/src/cmd/ctfdump/ctfdump.c
↓ open down ↓ 2 lines elided ↑ open up ↑
   3    3   * Common Development and Distribution License ("CDDL"), version 1.0.
   4    4   * You may only use this file in accordance with the terms of version
   5    5   * 1.0 of the CDDL.
   6    6   *
   7    7   * A full copy of the text of the CDDL should have accompanied this
   8    8   * source.  A copy of the CDDL is also available via the Internet at
   9    9   * http://www.illumos.org/license/CDDL.
  10   10   */
  11   11  
  12   12  /*
  13      - * Copyright 2019, Joyent, Inc.
       13 + * Copyright 2020 Joyent, Inc.
  14   14   */
  15   15  
  16   16  /*
  17   17   * Dump information about CTF containers.
  18   18   */
  19   19  
  20   20  #include <stdio.h>
  21   21  #include <unistd.h>
  22   22  #include <libctf.h>
  23   23  #include <libgen.h>
↓ open down ↓ 582 lines elided ↑ open up ↑
 606  606                          g_stats.cs_structsz += size;
 607  607                          g_stats.cs_sszmax = MAX(size, g_stats.cs_sszmax);
 608  608                  } else {
 609  609                          g_stats.cs_numembs += count;
 610  610                          g_stats.cs_numax = MAX(count, g_stats.cs_numax);
 611  611                          g_stats.cs_unionsz += size;
 612  612                          g_stats.cs_uszmax = MAX(count, g_stats.cs_uszmax);
 613  613                  }
 614  614                  break;
 615  615          case CTF_K_ENUM:
 616      -                ctfdump_printf(CTFDUMP_TYPES, "%s\n", name);
      616 +                size = ctf_type_size(g_fp, id);
      617 +
      618 +                /* Only the oddest enums are worth reporting on size. */
      619 +                if (size != CTF_ERR && size != sizeof (int)) {
      620 +                        ctfdump_printf(CTFDUMP_TYPES, "%s (%zd bytes)\n",
      621 +                            name, size);
      622 +                } else {
      623 +                        ctfdump_printf(CTFDUMP_TYPES, "%s\n", name);
      624 +                }
      625 +
 617  626                  count = 0;
 618  627                  if (ctf_enum_iter(g_fp, id, ctfdump_enum_cb, &count) != 0)
 619  628                          ctfdump_fatal("failed to iterate enumerators of %s: "
 620  629                              "%s\n", name, ctf_errmsg(ctf_errno(g_fp)));
 621  630                  g_stats.cs_nemembs += count;
 622  631                  g_stats.cs_nemax = MAX(g_stats.cs_nemax, count);
 623  632                  break;
 624  633          case CTF_K_FORWARD:
 625  634                  ctfdump_printf(CTFDUMP_TYPES, "forward %s\n", name);
 626  635                  break;
↓ open down ↓ 171 lines elided ↑ open up ↑
 798  807                  if (is_anon_refname(name))
 799  808                          break;
 800  809  
 801  810                  printf("%s {\n", name);
 802  811  
 803  812                  if (ctf_enum_iter(g_fp, id, ctfsrc_enum_cb, NULL) != 0) {
 804  813                          ctfdump_fatal("failed to iterate enumerators of %s: "
 805  814                              "%s\n", name, ctf_errmsg(ctf_errno(g_fp)));
 806  815                  }
 807  816  
 808      -                printf("};\n\n");
      817 +                size = ctf_type_size(g_fp, id);
      818 +
      819 +                /* Only the oddest enums are worth reporting on size. */
      820 +                if (size != CTF_ERR && size != sizeof (int)) {
      821 +                        printf("} /* 0x%x bytes */;\n\n", size);
      822 +                } else {
      823 +                        printf("};\n\n");
      824 +                }
 809  825                  break;
 810  826          case CTF_K_TYPEDEF:
 811  827                  /*
 812  828                   * If this fails, it's probably because the referent type is in
 813  829                   * a parent container that was not supplied via -p.
 814  830                   */
 815  831                  if (ctfsrc_refname(id, refname, sizeof (refname)) == NULL) {
 816  832                          printf("typedef %s %s;\n\n", refname, name);
 817  833                          break;
 818  834                  }
↓ open down ↓ 443 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX