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/intel/kmdb/kaif.c
          +++ new/usr/src/cmd/mdb/intel/kmdb/kaif.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  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 2007 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
       24 + *
       25 + * Copyright 2018 Joyent, Inc.
  24   26   */
  25   27  
  26      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  27      -
  28   28  /*
  29   29   * The debugger/"PROM" interface layer
  30   30   *
  31   31   * It makes more sense on SPARC. In reality, these interfaces deal with three
  32   32   * things: setting break/watchpoints, stepping, and interfacing with the KDI to
  33   33   * set up kmdb's IDT handlers.
  34   34   */
  35   35  
  36   36  #include <kmdb/kmdb_dpi_impl.h>
  37   37  #include <kmdb/kmdb_kdi.h>
↓ open down ↓ 558 lines elided ↑ open up ↑
 596  596                   * pre-step value.  We'll also need to turn TF back off.
 597  597                   */
 598  598                  (void) kmdb_dpi_get_register(FLAGS_REG_NAME, &fl);
 599  599                  (void) kmdb_dpi_set_register(FLAGS_REG_NAME,
 600  600                      ((fl & ~(KREG_EFLAGS_TF_MASK|KREG_EFLAGS_IF_MASK)) |
 601  601                      (oldfl & KREG_EFLAGS_IF_MASK)));
 602  602                  return (0);
 603  603          }
 604  604  }
 605  605  
 606      -/*
 607      - * The target has already configured the chip for branch step, leaving us to
 608      - * actually make the machine go.  Due to a number of issues involving
 609      - * the potential alteration of system state via instructions like sti, cli,
 610      - * pushfl, and popfl, we're going to treat this like a normal system resume.
 611      - * All CPUs will be released, on the kernel's IDT.  Our primary concern is
 612      - * the alteration/storage of our TF'd EFLAGS via pushfl and popfl.  There's no
 613      - * real workaround - we don't have opcode breakpoints - so the best we can do is
 614      - * to ensure that the world won't end if someone does bad things to EFLAGS.
 615      - *
 616      - * Two things can happen:
 617      - *  1. EFLAGS.TF may be cleared, either maliciously or via a popfl from saved
 618      - *     state.  The CPU will continue execution beyond the branch, and will not
 619      - *     reenter the debugger unless brought/sent in by other means.
 620      - *  2. Someone may pushlf the TF'd EFLAGS, and may stash a copy of it somewhere.
 621      - *     When the saved version is popfl'd back into place, the debugger will be
 622      - *     re-entered on a single-step trap.
 623      - */
 624      -static void
 625      -kaif_step_branch(void)
 626      -{
 627      -        kreg_t fl;
 628      -
 629      -        (void) kmdb_dpi_get_register(FLAGS_REG_NAME, &fl);
 630      -        (void) kmdb_dpi_set_register(FLAGS_REG_NAME,
 631      -            (fl | (1 << KREG_EFLAGS_TF_SHIFT)));
 632      -
 633      -        kmdb_dpi_resume_master();
 634      -
 635      -        (void) kmdb_dpi_set_register(FLAGS_REG_NAME, fl);
 636      -}
 637      -
 638  606  /*ARGSUSED*/
 639  607  static uintptr_t
 640  608  kaif_call(uintptr_t funcva, uint_t argc, const uintptr_t argv[])
 641  609  {
 642  610          return (kaif_invoke(funcva, argc, argv));
 643  611  }
 644  612  
 645  613  static void
 646  614  dump_crumb(kdi_crumb_t *krmp)
 647  615  {
↓ open down ↓ 69 lines elided ↑ open up ↑
 717  685  }
 718  686  
 719  687  static void
 720  688  kaif_modchg_cancel(void)
 721  689  {
 722  690          ASSERT(kaif_modchg_cb != NULL);
 723  691  
 724  692          kaif_modchg_cb = NULL;
 725  693  }
 726  694  
 727      -static void
 728      -kaif_msr_add(const kdi_msr_t *msrs)
 729      -{
 730      -        kdi_msr_t *save;
 731      -        size_t nr_msrs = 0;
 732      -        size_t i;
 733      -
 734      -        while (msrs[nr_msrs].msr_num != 0)
 735      -                nr_msrs++;
 736      -        /* we want to copy the terminating kdi_msr_t too */
 737      -        nr_msrs++;
 738      -
 739      -        save = mdb_zalloc(sizeof (kdi_msr_t) * nr_msrs * kaif_ncpusave,
 740      -            UM_SLEEP);
 741      -
 742      -        for (i = 0; i < kaif_ncpusave; i++)
 743      -                bcopy(msrs, &save[nr_msrs * i], sizeof (kdi_msr_t) * nr_msrs);
 744      -
 745      -        kmdb_kdi_set_debug_msrs(save);
 746      -}
 747      -
 748      -static uint64_t
 749      -kaif_msr_get(int cpuid, uint_t num)
 750      -{
 751      -        kdi_cpusave_t *save;
 752      -        kdi_msr_t *msr;
 753      -        int i;
 754      -
 755      -        if ((save = kaif_cpuid2save(cpuid)) == NULL)
 756      -                return (-1); /* errno is set for us */
 757      -
 758      -        msr = save->krs_msr;
 759      -
 760      -        for (i = 0; msr[i].msr_num != 0; i++) {
 761      -                if (msr[i].msr_num == num && (msr[i].msr_type & KDI_MSR_READ))
 762      -                        return (msr[i].kdi_msr_val);
 763      -        }
 764      -
 765      -        return (0);
 766      -}
 767      -
 768  695  void
 769  696  kaif_trap_set_debugger(void)
 770  697  {
 771  698          kmdb_kdi_idt_switch(NULL);
 772  699  }
 773  700  
 774  701  void
 775  702  kaif_trap_set_saved(kaif_cpusave_t *cpusave)
 776  703  {
 777  704          kmdb_kdi_idt_switch(cpusave);
↓ open down ↓ 99 lines elided ↑ open up ↑
 877  804          kaif_set_register,
 878  805          kaif_brkpt_arm,
 879  806          kaif_brkpt_disarm,
 880  807          kaif_wapt_validate,
 881  808          kaif_wapt_reserve,
 882  809          kaif_wapt_release,
 883  810          kaif_wapt_arm,
 884  811          kaif_wapt_disarm,
 885  812          kaif_wapt_match,
 886  813          kaif_step,
 887      -        kaif_step_branch,
 888  814          kaif_call,
 889  815          kaif_dump_crumbs,
 890      -        kaif_msr_add,
 891      -        kaif_msr_get,
 892  816  };
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX