freebsd-dev/sys/amd64/include
Bruce Evans bd20334ca0 Abort single stepping in ddb if the trap is not for single-stepping.
This is not very easy to do, since ddb didn't know when traps are
for single-stepping.  It more or less assumed that traps are either
breakpoints or single-step, but even for x86 this became inadequate
with the release of the i386 in ~1986, and FreeBSD passes it other
trap types for NMIs and panics.

On x86, teach ddb when a trap is for single stepping using the %dr6
register.  Unknown traps are now treated almost the same as breakpoints
instead of as the same as single-steps.  Previously, the classification
of breakpoints was almost correct and everything else was unknown so
had to be treated as a single-step.  Now the classification of single-
steps is precise, the classification of breakpoints is almost correct
(as before) and everything else is unknown and treated like a
breakpoint.

This fixes:
- breakpoints not set by ddb, including the main one in kdb_enter(),
  were treated as single-steps and not stopped on when stepping
  (except for the usual, simple case of a step with residual count 1).
  As special cases, kdb_enter() didn't stop for fatal traps or panics
- similarly for "hardware breakpoints".

Use a new MD macro IS_SSTEP_TRAP(type, code) to code to classify
single-steps.  This is excessively complicated for bug-for-bug and
backwards compatibilty.  Design errors apparently started in Mach
in ~1990 or perhaps in the FreeBSD interface in ~1993.  Common trap
types like single steps should have a unique MI code (like the TRAP*
codes for user SIGTRAP) so that debuggers don't need macros like
IS_SSTEP_TRAP() to decode them.  But 'type' is actually an ambiguous
MD trap number, and code was always 0 (now it is (int)%dr6 on x86).
So it was impossible to determine the trap type from the args.
Global variables had to be used.

There is already a classification macro db_pc_is_single_step(), but
this just gets in the way.  It is only used to recover from bugs in
IS_BREAKPOINT_TRAP().  On some arches, IS_BREAKPOINT_TRAP() just
duplicates the ambiguity in 'type' and misclassifies single-steps as
breakpoints.  It defaults to 'false', which is the opposite of what is
needed for bug-for-bug compatibility.

When this is cleaned up, MI classification bits should be passed in
'code'.  This could be done now for positive-logic bits, since 'code'
was always 0, but some negative logic is needed for compatibility so
a simple MI classificition is not usable yet.

After reading %dr6, clear the single-step bit in it so that the type
of the next debugger trap can be decoded.  This is a little
ddb-specific.  ddb doesn't understand the need to clear this bit and
doing it before calling kdb is easiest.  gdb would need to reverse
this to support hardware breakpoints, but it just doesn't support
them now since gdbstub doesn't support %dr*.

Fix a bug involving %dr6: when emulating a single-step trap for vm86,
set the bit for it in %dr6.  Userland debuggers need this.  ddb now
needs this for vm86 bios calls.  The bit gets copied to 'code' then
cleared again.

Fix related style bugs:
- when clearing bits for hardware breakpoints in %dr6, spell the mask
  as ~0xf on both amd64 and i386 to get the correct number of bits
  using sign extension and not need a comment about using the wrong
  mask on amd64 (amd64 traps for invalid results but clearing the
  reserved top bits didn't trap since they are 0).
- rewrite my old wrong comments about using %dr6 for ddb watchpoints.
2016-09-15 17:24:23 +00:00
..
pc Add more UEFI/e820 memory types from latest specifications. 2016-07-24 09:15:11 +00:00
xen x86/xen: Consolidate xen-os.h in a single place 2015-10-21 10:04:35 +00:00
_align.h
_bus.h
_inttypes.h
_limits.h
_stdint.h
_types.h
acpica_machdep.h
apm_bios.h
asm.h Revert r274772: it is not valid on MIPS 2014-11-25 03:50:31 +00:00
asmacros.h Extend earlier addition of stack frames to most of support.S. This makes 2014-11-13 22:11:44 +00:00
atomic.h atomic: Add testandclear on i386/amd64 2016-05-16 07:19:33 +00:00
bus_dma.h
bus.h
clock.h xen: implement an early timer for Xen PVH 2014-03-11 10:20:42 +00:00
counter.h Replace a number of conflations of mp_ncpus and mp_maxid with either 2016-07-06 14:09:49 +00:00
cpu.h amd64/i386: introduce APIC hooks for different APIC implementations. 2014-06-16 08:43:03 +00:00
cpufunc.h For amd64 non-PCID machines, and for i386 machines with support for 2015-12-03 11:14:14 +00:00
cputypes.h Remove 'cpu' and 'cpu_class' on amd64. 2016-09-15 17:05:54 +00:00
db_machdep.h Abort single stepping in ddb if the trap is not for single-stepping. 2016-09-15 17:24:23 +00:00
dump.h Factor out duplicated code from dumpsys() on each architecture into generic 2015-01-07 01:01:39 +00:00
elf.h
endian.h
exec.h
fdt.h
float.h
floatingpoint.h
fpu.h Add FPU_KERN_NOCTX flag to the fpu_kern_enter() function on amd64. 2016-09-11 09:14:07 +00:00
frame.h
gdb_machdep.h
ieeefp.h
in_cksum.h Rationalize BSD license on sys/*/include/in_cksum.h 2015-08-05 19:05:12 +00:00
intr_machdep.h Fix build for !SMP kernels after the Xen MSIX workaround. 2016-08-22 21:23:17 +00:00
iodev.h
kdb.h
limits.h
md_var.h On amd64, declare sse2_pagezero() and start using it again, but only 2016-08-29 13:07:21 +00:00
memdev.h
metadata.h Move amd64 metadata.h to x86 and share with i386 2016-01-07 19:47:26 +00:00
minidump.h
mp_watchdog.h
nexusvar.h
npx.h
ofw_machdep.h
param.h Enable DEVICE_NUMA with up to 8 domains by default on amd64. 2016-04-12 21:23:44 +00:00
pcb.h Add FPU_KERN_NOCTX flag to the fpu_kern_enter() function on amd64. 2016-09-11 09:14:07 +00:00
pci_cfgreg.h
pcpu.h Rewrite amd64 PCID implementation to follow an algorithm described in 2015-05-09 19:11:01 +00:00
pmap.h Add locking annotations to amd64 struct md_page members. 2016-05-10 09:58:51 +00:00
pmc_mdep.h Use single instance of the identical INKERNEL() and PMC_IN_KERNEL() 2015-07-02 14:37:21 +00:00
ppireg.h
proc.h Eliminate pvh_global_lock from the amd64 pmap. 2016-05-14 23:35:11 +00:00
profile.h
psl.h
ptrace.h
pvclock.h Generalized parts of the XEN timer code into a generic pvclock 2015-02-04 08:26:43 +00:00
reg.h
reloc.h
resource.h Add support for managing PCI bus numbers. As with BARs and PCI-PCI bridge 2014-02-12 04:30:37 +00:00
runq.h
segments.h
setjmp.h
sf_buf.h Merge all MD sf_buf allocators into one MI, residing in kern/subr_sfbuf.c 2014-08-05 09:44:10 +00:00
sigframe.h
signal.h
smp.h Merge common parts of i386 and amd64 md_var.h and smp.h into 2015-12-07 17:41:20 +00:00
specialreg.h
stack.h Merge stack(9) implementations for i386 and amd64 under x86/. 2015-09-11 03:24:07 +00:00
stdarg.h
sysarch.h
timerreg.h
trap.h
tss.h
ucontext.h
varargs.h
vdso.h
vm.h Reassign copyright statements on several files from Advanced 2015-04-23 14:22:20 +00:00
vmm_dev.h Restructure memory allocation in bhyve to support "devmem". 2015-06-18 06:00:17 +00:00
vmm_instruction_emul.h Deprecate the 3-way return values from vm_gla2gpa() and vm_copy_setup(). 2015-05-06 16:25:20 +00:00
vmm.h sys/amd64: Small spelling fixes. 2016-05-03 22:13:04 +00:00
vmparam.h Retire VM_FREEPOOL_CACHE as the next step in eliminating PG_CACHE pages. 2015-06-08 04:59:32 +00:00