Print this page
9210 remove KMDB branch debugging support
9211 ::crregs could do with cr2/cr3 support
9209 ::ttrace should be able to filter by thread
Reviewed by: Patrick Mooney <patrick.mooney@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/mdb/i86pc/modules/unix/unix.c
          +++ new/usr/src/cmd/mdb/i86pc/modules/unix/unix.c
↓ open down ↓ 12 lines elided ↑ open up ↑
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
  23      - * Copyright 2015 Joyent, Inc.
       23 + * Copyright 2018 Joyent, Inc.
  24   24   */
  25   25  
  26   26  #include <mdb/mdb_modapi.h>
  27   27  #include <mdb/mdb_ctf.h>
  28   28  #include <sys/cpuvar.h>
  29   29  #include <sys/systm.h>
  30   30  #include <sys/traptrace.h>
  31   31  #include <sys/x_call.h>
  32   32  #include <sys/xc_levels.h>
  33   33  #include <sys/avintr.h>
↓ open down ↓ 368 lines elided ↑ open up ↑
 402  402          { TT_SYSC64, "sc64", ttrace_syscall },
 403  403          { TT_INTERRUPT, "intr", ttrace_interrupt },
 404  404          { TT_TRAP, "trap", ttrace_trap },
 405  405          { TT_EVENT, "evnt", ttrace_trap },
 406  406          { 0, NULL, NULL }
 407  407  };
 408  408  
 409  409  typedef struct ttrace_dcmd {
 410  410          processorid_t ttd_cpu;
 411  411          uint_t ttd_extended;
      412 +        uintptr_t ttd_kthread;
 412  413          trap_trace_ctl_t ttd_ttc[NCPU];
 413  414  } ttrace_dcmd_t;
 414  415  
 415  416  #if defined(__amd64)
 416  417  
 417  418  #define DUMP(reg) #reg, regs->r_##reg
 418  419  #define THREEREGS       "         %3s: %16lx %3s: %16lx %3s: %16lx\n"
 419  420  
 420  421  static void
 421  422  ttrace_dumpregs(trap_trace_rec_t *rec)
↓ open down ↓ 49 lines elided ↑ open up ↑
 471  472          }
 472  473  
 473  474          if (cpu == -1) {
 474  475                  mdb_warn("couldn't find %p in any trap trace ctl\n", addr);
 475  476                  return (WALK_ERR);
 476  477          }
 477  478  
 478  479          if (dcmd->ttd_cpu != -1 && cpu != dcmd->ttd_cpu)
 479  480                  return (WALK_NEXT);
 480  481  
      482 +        if (dcmd->ttd_kthread != 0 &&
      483 +            dcmd->ttd_kthread != rec->ttr_curthread)
      484 +                return (WALK_NEXT);
      485 +
 481  486          mdb_printf("%3d %15llx ", cpu, rec->ttr_stamp);
 482  487  
 483  488          for (i = 0; ttrace_hdlr[i].t_hdlr != NULL; i++) {
 484  489                  if (rec->ttr_marker != ttrace_hdlr[i].t_marker)
 485  490                          continue;
 486  491                  mdb_printf("%4s ", ttrace_hdlr[i].t_name);
 487  492                  if (ttrace_hdlr[i].t_hdlr(rec) == -1)
 488  493                          return (WALK_ERR);
 489  494          }
 490  495  
↓ open down ↓ 39 lines elided ↑ open up ↑
 530  535          dcmd.ttd_cpu = -1;
 531  536          dcmd.ttd_extended = FALSE;
 532  537  
 533  538          if (mdb_readsym(ttc, ttc_size, "trap_trace_ctl") == -1) {
 534  539                  mdb_warn("symbol 'trap_trace_ctl' not found; "
 535  540                      "non-TRAPTRACE kernel?\n");
 536  541                  return (DCMD_ERR);
 537  542          }
 538  543  
 539  544          if (mdb_getopts(argc, argv,
 540      -            'x', MDB_OPT_SETBITS, TRUE, &dcmd.ttd_extended, NULL) != argc)
      545 +            'x', MDB_OPT_SETBITS, TRUE, &dcmd.ttd_extended,
      546 +            't', MDB_OPT_UINTPTR, &dcmd.ttd_kthread, NULL) != argc)
 541  547                  return (DCMD_USAGE);
 542  548  
 543  549          if (DCMD_HDRSPEC(flags)) {
 544  550                  mdb_printf("%3s %15s %4s %2s %-*s%s\n", "CPU",
 545  551                      "TIMESTAMP", "TYPE", "Vec", TT_HDLR_WIDTH, "HANDLER",
 546  552                      " EIP");
 547  553          }
 548  554  
 549  555          if (flags & DCMD_ADDRSPEC) {
 550  556                  if (addr >= NCPU) {
↓ open down ↓ 328 lines elided ↑ open up ↑
 879  885  
 880  886          mdb_free(fset, sz);
 881  887          return (DCMD_OK);
 882  888  }
 883  889  
 884  890  #ifdef _KMDB
 885  891  /* ARGSUSED */
 886  892  static int
 887  893  crregs_dcmd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
 888  894  {
 889      -        ulong_t cr0, cr4;
      895 +        ulong_t cr0, cr2, cr3, cr4;
 890  896          static const mdb_bitmask_t cr0_flag_bits[] = {
 891  897                  { "PE",         CR0_PE,         CR0_PE },
 892  898                  { "MP",         CR0_MP,         CR0_MP },
 893  899                  { "EM",         CR0_EM,         CR0_EM },
 894  900                  { "TS",         CR0_TS,         CR0_TS },
 895  901                  { "ET",         CR0_ET,         CR0_ET },
 896  902                  { "NE",         CR0_NE,         CR0_NE },
 897  903                  { "WP",         CR0_WP,         CR0_WP },
 898  904                  { "AM",         CR0_AM,         CR0_AM },
 899  905                  { "NW",         CR0_NW,         CR0_NW },
 900  906                  { "CD",         CR0_CD,         CR0_CD },
 901  907                  { "PG",         CR0_PG,         CR0_PG },
 902  908                  { NULL,         0,              0 }
 903  909          };
 904  910  
      911 +        static const mdb_bitmask_t cr3_flag_bits[] = {
      912 +                { "PCD",        CR3_PCD,        CR3_PCD },
      913 +                { "PWT",        CR3_PWT,        CR3_PWT },
      914 +                { NULL,         0,              0, }
      915 +        };
      916 +
 905  917          static const mdb_bitmask_t cr4_flag_bits[] = {
 906  918                  { "VME",        CR4_VME,        CR4_VME },
 907  919                  { "PVI",        CR4_PVI,        CR4_PVI },
 908  920                  { "TSD",        CR4_TSD,        CR4_TSD },
 909  921                  { "DE",         CR4_DE,         CR4_DE },
 910  922                  { "PSE",        CR4_PSE,        CR4_PSE },
 911  923                  { "PAE",        CR4_PAE,        CR4_PAE },
 912  924                  { "MCE",        CR4_MCE,        CR4_MCE },
 913  925                  { "PGE",        CR4_PGE,        CR4_PGE },
 914  926                  { "PCE",        CR4_PCE,        CR4_PCE },
 915  927                  { "OSFXSR",     CR4_OSFXSR,     CR4_OSFXSR },
 916  928                  { "OSXMMEXCPT", CR4_OSXMMEXCPT, CR4_OSXMMEXCPT },
 917  929                  { "VMXE",       CR4_VMXE,       CR4_VMXE },
 918  930                  { "SMXE",       CR4_SMXE,       CR4_SMXE },
      931 +                { "PCIDE",      CR4_PCIDE,      CR4_PCIDE },
 919  932                  { "OSXSAVE",    CR4_OSXSAVE,    CR4_OSXSAVE },
 920  933                  { "SMEP",       CR4_SMEP,       CR4_SMEP },
 921  934                  { "SMAP",       CR4_SMAP,       CR4_SMAP },
 922  935                  { NULL,         0,              0 }
 923  936          };
 924  937  
 925  938          cr0 = kmdb_unix_getcr0();
      939 +        cr2 = kmdb_unix_getcr2();
      940 +        cr3 = kmdb_unix_getcr3();
 926  941          cr4 = kmdb_unix_getcr4();
 927  942          mdb_printf("%%cr0 = 0x%08x <%b>\n", cr0, cr0, cr0_flag_bits);
      943 +        mdb_printf("%%cr2 = 0x%08x <%a>\n", cr2, cr2);
      944 +
      945 +        if ((cr4 & CR4_PCIDE)) {
      946 +                mdb_printf("%%cr3 = 0x%08x <pfn:%lu pcid:%u>\n",
      947 +                    cr3 >> MMU_PAGESHIFT, cr3 & MMU_PAGEOFFSET);
      948 +        } else {
      949 +                mdb_printf("%%cr3 = 0x%08x <pfn:%lu flags:%b>\n", cr3,
      950 +                    cr3 >> MMU_PAGESHIFT, cr3, cr3_flag_bits);
      951 +        }
      952 +
 928  953          mdb_printf("%%cr4 = 0x%08x <%b>\n", cr4, cr4, cr4_flag_bits);
      954 +
 929  955          return (DCMD_OK);
 930  956  }
 931  957  #endif
 932  958  
 933  959  static const mdb_dcmd_t dcmds[] = {
 934  960          { "gate_desc", ":", "dump a gate descriptor", gate_desc },
 935  961          { "idt", ":[-v]", "dump an IDT", idt },
 936      -        { "ttrace", "[-x]", "dump trap trace buffers", ttrace },
      962 +        { "ttrace", "[-x] [-t kthread]", "dump trap trace buffers", ttrace },
 937  963          { "vatopfn", ":[-a as]", "translate address to physical page",
 938  964              va2pfn_dcmd },
 939  965          { "report_maps", ":[-m]",
 940  966              "Given PFN, report mappings / page table usage",
 941  967              report_maps_dcmd, report_maps_help },
 942  968          { "htables", "", "Given hat_t *, lists all its htable_t * values",
 943  969              htables_dcmd, htables_help },
 944  970          { "ptable", ":[-m]", "Given PFN, dump contents of a page table",
 945  971              ptable_dcmd, ptable_help },
 946  972          { "pte", ":[-p XXXXX] [-l N]", "print human readable page table entry",
↓ open down ↓ 39 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX