Print this page
11584 ::xcall would be useful
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/mdb/common/mdb/mdb_ctf.c
          +++ new/usr/src/cmd/mdb/common/mdb/mdb_ctf.c
↓ open down ↓ 16 lines elided ↑ open up ↑
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  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   * Copyright (c) 2013, 2016 by Delphix. All rights reserved.
  27      - * Copyright (c) 2015, Joyent, Inc.  All rights reserved.
       27 + * Copyright (c) 2018, Joyent, Inc.
  28   28   */
  29   29  
  30   30  #include <mdb/mdb_ctf.h>
  31   31  #include <mdb/mdb_ctf_impl.h>
  32   32  #include <mdb/mdb_err.h>
  33   33  #include <mdb/mdb_modapi.h>
  34   34  #include <mdb/mdb_string.h>
  35   35  #include <mdb/mdb.h>
  36   36  #include <mdb/mdb_debug.h>
  37   37  
↓ open down ↓ 1191 lines elided ↑ open up ↑
1229 1229          char *modbuf = mp->m_modbuf;
1230 1230          mdb_ctf_id_t tgtmid;
1231 1231          char *tgtbuf = mp->m_tgtbuf;
1232 1232          ulong_t tgtoff;
1233 1233          char tgtname[128];
1234 1234  
1235 1235          (void) mdb_snprintf(tgtname, sizeof (tgtname),
1236 1236              "member %s of type %s", name, mp->m_tgtname);
1237 1237  
1238 1238          if (mdb_ctf_member_info(mp->m_tgtid, name, &tgtoff, &tgtmid) != 0) {
1239      -                mdb_ctf_warn(mp->m_flags,
1240      -                    "could not find %s\n", tgtname);
     1239 +                if (mp->m_flags & MDB_CTF_VREAD_IGNORE_ABSENT)
     1240 +                        return (0);
     1241 +                mdb_ctf_warn(mp->m_flags, "could not find %s\n", tgtname);
1241 1242                  return (set_errno(EMDB_CTFNOMEMB));
1242 1243          }
1243 1244  
1244 1245          return (vread_helper(modmid, modbuf + modoff / NBBY,
1245 1246              tgtmid, tgtbuf + tgtoff / NBBY, tgtname, mp->m_flags));
1246 1247  }
1247 1248  
1248 1249  typedef struct enum_value {
1249 1250          int             *ev_modbuf;
1250 1251          const char      *ev_name;
↓ open down ↓ 354 lines elided ↑ open up ↑
1605 1606   * for ::findstack.  If the MDB module is compiled from several source files,
1606 1607   * one must be especially careful to not define different types with the
1607 1608   * same name in different source files, because the compiler can not detect
1608 1609   * this error.
1609 1610   *
1610 1611   * Enums will also be translated by name, so the mdb module will receive
1611 1612   * the enum value it expects even if the target has renumbered the enum.
1612 1613   * Warning: it will therefore only work with enums are only used to store
1613 1614   * legitimate enum values (not several values or-ed together).
1614 1615   *
1615      - * By default, if mdb_ctf_vread() can not find any members or enum values,
1616      - * it will print a descriptive message (with mdb_warn()) and fail.
1617      - * Passing MDB_CTF_VREAD_QUIET in 'flags' will suppress the warning message.
1618      - * Additional flags can be used to ignore specific types of translation
1619      - * failure, but should be used with caution, because they will silently leave
1620      - * the caller's buffer uninitialized.
     1616 + * Flags values:
     1617 + *
     1618 + * MDB_CTF_VREAD_QUIET: keep quiet about failures
     1619 + * MDB_CTF_VREAD_IGNORE_ABSENT: ignore any member that couldn't be found in the
     1620 + * target struct; be careful not to use an uninitialized result.
1621 1621   */
1622 1622  int
1623 1623  mdb_ctf_vread(void *modbuf, const char *target_typename,
1624 1624      const char *mdb_typename, uintptr_t addr, uint_t flags)
1625 1625  {
1626 1626          ctf_file_t *mfp;
1627 1627          ctf_id_t mid;
1628 1628          void *tgtbuf;
1629 1629          size_t size;
1630 1630          mdb_ctf_id_t tgtid;
1631 1631          mdb_ctf_id_t modid;
1632 1632          mdb_module_t *mod;
     1633 +        int ret;
1633 1634  
1634 1635          if ((mod = mdb_get_module()) == NULL || (mfp = mod->mod_ctfp) == NULL) {
1635 1636                  mdb_ctf_warn(flags, "no ctf data found for mdb module %s\n",
1636 1637                      mod->mod_name);
1637 1638                  return (set_errno(EMDB_NOCTF));
1638 1639          }
1639 1640  
1640 1641          if ((mid = ctf_lookup_by_name(mfp, mdb_typename)) == CTF_ERR) {
1641 1642                  mdb_ctf_warn(flags, "couldn't find ctf data for "
1642 1643                      "type %s in mdb module %s\n",
↓ open down ↓ 12 lines elided ↑ open up ↑
1655 1656  
1656 1657          /*
1657 1658           * Read the data out of the target's address space.
1658 1659           */
1659 1660          if ((size = mdb_ctf_type_size(tgtid)) == -1UL) {
1660 1661                  mdb_ctf_warn(flags, "couldn't determine size of type %s\n",
1661 1662                      target_typename);
1662 1663                  return (-1); /* errno is set for us */
1663 1664          }
1664 1665  
1665      -        tgtbuf = mdb_alloc(size, UM_SLEEP | UM_GC);
     1666 +        tgtbuf = mdb_alloc(size, UM_SLEEP);
1666 1667  
1667 1668          if (mdb_vread(tgtbuf, size, addr) < 0) {
1668 1669                  mdb_ctf_warn(flags, "couldn't read %s from %p\n",
1669 1670                      target_typename, addr);
     1671 +                mdb_free(tgtbuf, size);
1670 1672                  return (-1); /* errno is set for us */
1671 1673          }
1672 1674  
1673      -        return (vread_helper(modid, modbuf, tgtid, tgtbuf, NULL, flags));
     1675 +        ret = vread_helper(modid, modbuf, tgtid, tgtbuf, NULL, flags);
     1676 +
     1677 +        mdb_free(tgtbuf, size);
     1678 +
     1679 +        return (ret);
1674 1680  }
1675 1681  
1676 1682  /*
1677 1683   * Note: mdb_ctf_readsym() doesn't take separate parameters for the name
1678 1684   * of the target's type vs the mdb module's type.  Use with complicated
1679 1685   * types (e.g. structs) may result in unnecessary failure if a member of
1680 1686   * the struct has been changed in the target, but is not actually needed
1681 1687   * by the mdb module.  Use mdb_lookup_by_name() + mdb_ctf_vread() to
1682 1688   * avoid this problem.
1683 1689   */
↓ open down ↓ 531 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX