Print this page
5231 ::printf doesn't handle enums
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Richard Lowe <richlowe@richlowe.net>
Reviewed by: Alex Reece <alex@delphix.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/mdb/common/mdb/mdb_print.c
          +++ new/usr/src/cmd/mdb/common/mdb/mdb_print.c
↓ open down ↓ 18 lines elided ↑ open up ↑
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
  24   24   */
  25   25  
  26   26  /*
  27   27   * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
  28   28   * Copyright (c) 2012 Joyent, Inc. All rights reserved.
       29 + * Copyright (c) 2014 Nexenta Systems, Inc. All rights reserved.
  29   30   */
  30   31  
  31   32  #include <mdb/mdb_modapi.h>
  32   33  #include <mdb/mdb_target.h>
  33   34  #include <mdb/mdb_argvec.h>
  34   35  #include <mdb/mdb_string.h>
  35   36  #include <mdb/mdb_stdlib.h>
  36   37  #include <mdb/mdb_err.h>
  37   38  #include <mdb/mdb_debug.h>
  38   39  #include <mdb/mdb_fmt.h>
↓ open down ↓ 2514 lines elided ↑ open up ↑
2553 2554                  int32_t i4;
2554 2555                  int16_t i2;
2555 2556                  int8_t i1;
2556 2557          } u;
2557 2558  
2558 2559          if (mdb_ctf_type_resolve(id, &base) == -1) {
2559 2560                  mdb_warn("could not resolve type");
2560 2561                  return (DCMD_ABORT);
2561 2562          }
2562 2563  
2563      -        if (mdb_ctf_type_kind(base) != CTF_K_INTEGER) {
2564      -                mdb_warn("expected integer type\n");
2565      -                return (DCMD_ABORT);
2566      -        }
2567      -
2568      -        if (mdb_ctf_type_encoding(base, &e) != 0) {
2569      -                mdb_warn("could not get type encoding");
2570      -                return (DCMD_ABORT);
     2564 +        switch (mdb_ctf_type_kind(base)) {
     2565 +                case CTF_K_ENUM:
     2566 +                        e.cte_format = CTF_INT_SIGNED;
     2567 +                        e.cte_offset = 0;
     2568 +                        e.cte_bits = mdb_ctf_type_size(id) * NBBY;
     2569 +                        break;
     2570 +                case CTF_K_INTEGER:
     2571 +                        if (mdb_ctf_type_encoding(base, &e) != 0) {
     2572 +                                mdb_warn("could not get type encoding");
     2573 +                                return (DCMD_ABORT);
     2574 +                        }
     2575 +                        break;
     2576 +                default:
     2577 +                        mdb_warn("expected integer type\n");
     2578 +                        return (DCMD_ABORT);
2571 2579          }
2572 2580  
2573 2581          if (sign)
2574 2582                  sign = e.cte_format & CTF_INT_SIGNED;
2575 2583  
2576 2584          size = e.cte_bits / NBBY;
2577 2585  
2578 2586          /*
2579 2587           * Check to see if our life has been complicated by the presence of
2580 2588           * a bitfield.  If it has, we will print it using logic that is only
↓ open down ↓ 162 lines elided ↑ open up ↑
2743 2751                          mdb_warn("failed to read pointer at %llx", addr);
2744 2752                          return (DCMD_ERR);
2745 2753                  }
2746 2754  
2747 2755                  if (mdb_readstr(buf, sizeof (buf) - 1, value) < 0) {
2748 2756                          mdb_warn("failed to read string at %llx", value);
2749 2757                          return (DCMD_ERR);
2750 2758                  }
2751 2759  
2752 2760                  mdb_printf(fmt, buf);
     2761 +                return (0);
     2762 +        }
     2763 +
     2764 +        if (mdb_ctf_type_kind(base) == CTF_K_ENUM) {
     2765 +                const char *strval;
     2766 +                int value;
     2767 +
     2768 +                if (mdb_vread(&value, sizeof (value), addr) == -1) {
     2769 +                        mdb_warn("failed to read pointer at %llx", addr);
     2770 +                        return (DCMD_ERR);
     2771 +                }
     2772 +
     2773 +                if ((strval = mdb_ctf_enum_name(id, value))) {
     2774 +                        mdb_printf(fmt, strval);
     2775 +                } else {
     2776 +                        (void) mdb_snprintf(buf, sizeof (buf), "<%d>", value);
     2777 +                        mdb_printf(fmt, buf);
     2778 +                }
     2779 +
2753 2780                  return (0);
2754 2781          }
2755 2782  
2756 2783          if (mdb_ctf_type_kind(base) != CTF_K_ARRAY) {
2757 2784                  mdb_warn("exepected pointer or array type\n");
2758 2785                  return (DCMD_ABORT);
2759 2786          }
2760 2787  
2761 2788          if (mdb_ctf_array_info(base, &r) == -1 ||
2762 2789              mdb_ctf_type_resolve(r.mta_contents, &base) == -1 ||
↓ open down ↓ 394 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX