History log of /haiku/src/system/kernel/arch/x86/arch_user_debugger.cpp
Revision Date Author Comments
# 6f3a5c9a 16-Jul-2020 Adrien Destugues <pulkomandy@pulkomandy.tk>

Debugger: add AVX support

- Unify storage of "FPU" registers between debugger and signal handler
to use xsave format on both sides
- Handle YMM registers in Debugger (they are the same as XMM, but wider)

Tested:
- The system still boots with and without AVX
- The hello_avx test program can be debugged and the full value of YMM is visible

This changes the API of vregs in signal.h but not the ABI (structure are
declared differently but memory layout is the same). This changes the
API and ABI of arch_debugger.h for x86_64, but I don't think anything
outside Haiku uses it (did we ever have a 64bit compatible gdb?)

Change-Id: If93680ffa0339c19bab517876b4e029f5d66b240
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3038
Reviewed-by: Rene Gollent <rene@gollent.com>


# 99f00556 20-Apr-2016 Ingo Weinhold <ingo_weinhold@gmx.de>

kernel: +arch_get_thread_debug_cpu_state()

Similar to arch_get_debug_cpu_state(), but the thread whose CPU state
to retrieve is specified. Works only for threads that aren't running,
and on x86-64 we can get the FPU state only when the thread was
interrupted in userland.
Not implemented for the incomplete architecture ports.


# 396b7422 10-Sep-2014 Paweł Dziepak <pdziepak@quarnos.org>

kernel/x86_64: save fpu state at interrupts

The kernel is allowed to use fpu anywhere so we must make sure that
user state is not clobbered by saving fpu state at interrupt entry.
There is no need to do that in case of system calls since all fpu
data registers are caller saved.

We do not need, though, to save the whole fpu state at task swich
(again, thanks to calling convention). Only status and control
registers are preserved. This patch actually adds xmm0-15 register
to clobber list of task swich code, but the only reason of that is
to make sure that nothing bad happens inside the function that
executes that task swich. Inspection of the generated code shows
that no xmm registers are actually saved.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>


# 735f6748 16-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

x86: Debugger can now use dr3


# 271b27d5 25-Jul-2013 Alex Smith <alex@alex-smith.me.uk>

x86_64: Set vector in iframe/debug state to 99 for syscalls.

Although syscalls are done through SYSCALL and therefore don't actually
have an interrupt number, set it to 99 (the syscall vector on 32-bit)
in the iframe so that a syscall frame can be identified. Also added
vector/error_code to x86_64_debug_cpu_state for Debugger to use, not
sure why I didn't put them there in the first place.


# 8a190335 07-Aug-2012 Alex Smith <alex@alex-smith.me.uk>

Implemented user debugging support for x86_64.

Reused x86 arch_user_debugger.cpp, with a few minor changes to make
the code work for both 32 and 64 bit. Something isn't quite working
right, if a breakpoint is hit the kernel will hang. Other than that
everything appears to work correctly.


# b5c9d24a 09-Jul-2012 Alex Smith <alex@alex-smith.me.uk>

Implemented threading for x86_64.

* Thread creation and switching is working fine, however threads do not yet
get interrupted because I've not implemented hardware interrupt handling
yet (I'll do that next).
* I've made some changes to struct iframe: I've removed the e/r prefixes
from the member names for both 32/64, so now they're just named ip, ax,
bp, etc. This makes it easier to write code that works with both 32/64
without having to deal with different iframe member names.


# 5e9bb17d 08-Jul-2012 Alex Smith <alex@alex-smith.me.uk>

Renamed remaining i386_* functions to x86_* for consistency.


# 4304bb98 04-Jul-2012 Alex Smith <alex@alex-smith.me.uk>

Added arch_cpu.cpp to the x86_64 build.

* Some things are currently ifndef'd out completely for x86_64 because
they aren't implemented, there's a few other ifdef's to handle x86_64
differences but most of the code works unchanged.
* Renamed some i386_* functions to x86_*.
* Added a temporary method for setting the current thread on x86_64
(a global variable, not SMP safe). This will be changed to be done
via the GS segment but I've not implemented that yet.


# 24df6592 11-Jun-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged signals-merge branch into trunk with the following changes:
* Reorganized the kernel locking related to threads and teams.
* We now discriminate correctly between process and thread signals. Signal
handlers have been moved to teams. Fixes #5679.
* Implemented real-time signal support, including signal queuing, SA_SIGINFO
support, sigqueue(), sigwaitinfo(), sigtimedwait(), waitid(), and the addition
of the real-time signal range. Closes #1935 and #2695.
* Gave SIGBUS a separate signal number. Fixes #6704.
* Implemented <time.h> clock and timer support, and fixed/completed alarm() and
[set]itimer(). Closes #5682.
* Implemented support for thread cancellation. Closes #5686.
* Moved send_signal() from <signal.h> to <OS.h>. Fixes #7554.
* Lots over smaller more or less related changes.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42116 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4535495d 10-Jan-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged the signals branch into trunk, with these changes:
* The team and thread kernel structures have been renamed to Team and Thread
respectively and moved into the new BKernel namespace.
* Several (kernel add-on) sources have been converted from C to C++ since
private kernel headers are included that are no longer C compatible.

Changes after merging:
* Fixed gcc 2 build (warnings mainly in the scary firewire bus manager).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40196 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b2acbcbf 26-Dec-2010 Michael Lotz <mmlr@mlotz.ch>

CID 8122, 2210 (pointing at the same), 8121 and 2209 (pointing at the same):
Taking the size of a pointer instead of the actual extended registers struct.
Not sure this is used, but if it is it made the whole fpu/sse state in the
debugger useless.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39960 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 13b81a3b 30-Oct-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added new thread flag THREAD_FLAGS_SINGLE_STEP, which is set to indicate that
userland single-stepping is enabled for the thread.
* x86_exit_user_debug_at_kernel_entry(): Always store DR6 and DR7 in the CPU
structure, not only when breakpoints are installed.
* x86_handle_debug_exception(): When encountering a syscall single-step, also
set the THREAD_FLAGS_DEBUG_THREAD thread flag. Otherwise the
B_THREAD_DEBUG_STOP would be ignored.
* x86 interrupt handling, DISABLE_BREAKPOINTS():
- Renamed to STOP_USER_DEBUGGING().
- Now it also call x86_exit_user_debug_at_kernel_entry() when
THREAD_FLAGS_SINGLE_STEP is set, so that the debug registers are saved.

Fixes #6751.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39201 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e40e5ebf 13-Jul-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

arch_clear_watchpoint(): Passed incorrect flag to clear_breakpoint(), so
watchpoints would never be cleared.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37503 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 45538a5e 18-Apr-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

x86_handle_debug_exception(): The values of dr6 and dr7 are only stored in
the CPU info, if x86_exit_user_debug_at_kernel_entry() was executed before,
i.e. if the debug exception occurred in userlands. In all other cases we need
to read the current register values. Fixes #5742, a regression introduced in
r35951.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36340 a95241bf-73f2-0310-859d-f6bbb57e9c96


# feddedab 25-Mar-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

x86:
Added fields for temporary storage of the debug registers dr6 and dr7 to the
arch_cpu_info structure. The actual registers are stored at the beginning of
x86_exit_user_debug_at_kernel_entry() and read in
x86_handle_debug_exception().
The problem was that x86_exit_user_debug_at_kernel_entry() itself overwrote
dr7 and, if kernel breakpoints were enabled, dr6 could be overwritten anytime
after. So x86_handle_debug_exception() would find incorrect values in the
registers (definitely in dr7) and thus interpret the detected debug condition
incorrectly. Usually watchpoints were recognized as breakpoints.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35951 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 8b3d3d8a 25-Feb-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Correctly handle cases when a thread single-steps into the kernel as it can
happen on syscalls or "int" instructions. The debug exception handler sets
the thread debug flags B_THREAD_DEBUG_STOP and
B_THREAD_DEBUG_NOTIFY_SINGLE_STEP (new) and lets the thread continue. Before
leaving the kernel the thread is stopped and a single-step notification is
sent. Fixes #3487.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35620 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 8ad4a2e9 01-Oct-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Improved comment.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33392 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0b11ecb1 21-Jul-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Always include the public arch_debugger.h headers. The structures defined
there are prefixed with the respective architecture name. Useful for remote
debugging a different architecture.
* <x86/arch_debugger.h>: Introduced a structure for the FPU state, so that it
isn't left to the debugger.
* Removed the _kern_get_thread_cpu_state() syscall. Was originally intended for
bdb compatiblity, but isn't really needed.
* Kernel x86 arch_get_debug_cpu_state(): The use of fnsave was broken, since
it reinits the FPU after saving the state. This resulted in weird results
when debugging functions using the FPU. We now use fxsave, if available.
Otherwise fnsave + frstor should be used -- not fully implemented yet.
Same for arch_set_debug_cpu_state().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31682 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b0f12d64 23-Jun-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Added transparent software breakpoint support for user debuggers:
* The bulk of the work -- i.e. juggling the software and hardware breakpoints,
watchpoints, and memory reads/writes -- is done in the new class
BreakpointManager.
* For the architectures a few capability macros have to be defined, one
pointing to the software breakpoint instruction opcode. Done for x86.
* Some more simplifications in the user debugger code, made possible by the
recently introduced debugger_changed_condition attribute.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31214 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 568ade58 13-Jun-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

User debugger support:
* Generalized address checks. The debugger can now also read the commpage.
* Added new syscall _kern_get_thread_cpu_state() to get the CPU state of a
not running thread. Introduced arch_get_thread_debug_cpu_state() for that
purpose, which is only implemented for x86 ATM (uses the new
i386_get_thread_user_iframe()).
* Don't allow a debugger to change a thread's "esp" anymore. That's the esp
register in the kernel. "user_esp" can still be changed.
* Generally set RF (resume flag) in eflags in interrupt handlers, not only
after a instruction breakpoint debug exception. This should prevent
breakpoints from being triggered more than once (e.g. when the breakpoint is
on an instruction that can cause a page fault). I still saw those with bdb
in VMware, but that might be a VMware bug.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31045 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 8342d4cd 16-Apr-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Updated to use add_debugger_command_etc().
* Added "step" debugger command to single-step to the next instruction (of the
topmost iframe).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30212 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 8753babd 16-Apr-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Handle kernel debug exceptions similar to those in userland. This allows to
continue kernel breakpoints -- we would just retrigger the breakpoint when
continuing before.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30210 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 31d9352f 16-Apr-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Make sure kernel breakpoints are installed on all CPUs.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30209 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b4476702 16-Apr-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Removed most of the special-casing for kernel breakpoints in the kernel
enter/exit code. There's no real reason not to keep kernel breakpoints
enabled when in userland (unless there are breakpoints installed for the
team, of course).
* Enabled kernel breakpoints by default (check your kernel_debug_config.h,
if you have overridden it!), since they don't really add any overhead
anymore.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30206 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a8f9741c 04-Jul-2008 Michael Lotz <mmlr@mlotz.ch>

* Removed -Wno-unused from all KernelMergeObjects in kernel Jamfiles.
* Fixed most of the warnings resulting from that by removing actually not used
variables or moving declaration into the #IF. Left unused functions there
though, as I wouldn't know if they are supposed to be used again.
* Fixed two statements with no effect (clamping to MAX_ANCILLARY_DATA_LEN in
socket.cpp and unsetting fCounterSem in MessagingService.cpp).
* Some style cleanups.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26253 a95241bf-73f2-0310-859d-f6bbb57e9c96


# bb107c4e 22-May-2008 Axel Dörfler <axeld@pinc-software.de>

Patch by Jan Klötzke:
* In vm86 mode CS will have arbitrary values so we check for both USER_CODE_SEG
and the VM flag in EFLAGS. This is also done when entering interrupt gates.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25607 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 34b3b26b 10-Jan-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged branch haiku/branches/developer/bonefish/optimization revision
23139 into trunk, with roughly the following changes (for details svn
log the branch):
* The int 99 syscall handler is now fully in assembly.
* Added a sysenter/sysexit handler and use it on Pentiums that support
it (via commpage).
* Got rid of i386_handle_trap(). A bit of functionality was moved into
the assembly handler which now uses a jump table to call C functions
handling the respective interrupt.
* Some optimizations to get user debugger support code out of the
interrupt handling path.
* Introduced a thread::flags fields which allows to skip handling of
rare events (signals, user debug enabling/disabling) on the
common interrupt handling path.
* Got rid of the explicit iframe stack. The iframes can still be
retrieved by iterating through the stack frames.
* Made the commpage an architecture independent feature. It's used for
the real time data stuff (instead of creating a separate area).
* The x86 CPU modules can now provide processor optimized versions for
common functions (currently memcpy() only). They are used in the
kernel and are provided to the userland via commpage entries.
* Introduced build system feature allowing easy use of C structure
member offsets in assembly code.

Changes after merging:
* Fixed merge conflict in src/system/kernel/arch/x86/arch_debug.cpp
(caused by refactoring and introduction of "call" debugger command).



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23370 a95241bf-73f2-0310-859d-f6bbb57e9c96


# bc5f008a 02-Sep-2007 Ingo Weinhold <ingo_weinhold@gmx.de>

Added "breakpoint", "watchpoint", "breakpoints", and "watchpoints"
kernel debugger commands, which can set/clear/list in-kernel break- and
watchpoints. Only available when KERNEL_BREAKPOINTS is defined.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22153 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 667f1eeb 02-Sep-2007 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added support for setting (hardware) break-/watchpoints in the kernel.
Can be enabled by defining KERNEL_BREAKPOINTS in arch/user_debugger.h
and will provide the arch_{set,clear}_kernel_{break,watch}point()
function. Hitting a break-/watchpoint will throw the thread into KDL.
* Finally added a comment, what's the point of
i386_reinit_user_debug_after_context_switch(), since I wonder every
time I see it. Should be optimized aways soon.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22150 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 7eee76e6 27-Apr-2006 Michael Lotz <mmlr@mlotz.ch>

Implemented lazy FPU state save/restore. In the end mostly ported from NewOS. SMP safe.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17251 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 06be24a7 01-Nov-2005 Axel Dörfler <axeld@pinc-software.de>

The spurious debug exception sometimes comes very often in QEMU - it's now only
printed when tracing is turned on.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14634 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 2d690920 13-Apr-2005 Axel Dörfler <axeld@pinc-software.de>

Renamed system/core to system/kernel.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12360 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 396b74228eefcf4bc21333e05c1909b8692d1b86 10-Sep-2014 Paweł Dziepak <pdziepak@quarnos.org>

kernel/x86_64: save fpu state at interrupts

The kernel is allowed to use fpu anywhere so we must make sure that
user state is not clobbered by saving fpu state at interrupt entry.
There is no need to do that in case of system calls since all fpu
data registers are caller saved.

We do not need, though, to save the whole fpu state at task swich
(again, thanks to calling convention). Only status and control
registers are preserved. This patch actually adds xmm0-15 register
to clobber list of task swich code, but the only reason of that is
to make sure that nothing bad happens inside the function that
executes that task swich. Inspection of the generated code shows
that no xmm registers are actually saved.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>


# 735f67481fa904ae6bb5d0763f515fd7b93d5529 16-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

x86: Debugger can now use dr3


# 271b27d5a3003bac4e3fdd0c5a170ee33a197566 25-Jul-2013 Alex Smith <alex@alex-smith.me.uk>

x86_64: Set vector in iframe/debug state to 99 for syscalls.

Although syscalls are done through SYSCALL and therefore don't actually
have an interrupt number, set it to 99 (the syscall vector on 32-bit)
in the iframe so that a syscall frame can be identified. Also added
vector/error_code to x86_64_debug_cpu_state for Debugger to use, not
sure why I didn't put them there in the first place.


# 8a1903353eedd95266c7241aada3a314c5d35a55 07-Aug-2012 Alex Smith <alex@alex-smith.me.uk>

Implemented user debugging support for x86_64.

Reused x86 arch_user_debugger.cpp, with a few minor changes to make
the code work for both 32 and 64 bit. Something isn't quite working
right, if a breakpoint is hit the kernel will hang. Other than that
everything appears to work correctly.


# b5c9d24abcc3599375153ed310b495ea944d46a0 09-Jul-2012 Alex Smith <alex@alex-smith.me.uk>

Implemented threading for x86_64.

* Thread creation and switching is working fine, however threads do not yet
get interrupted because I've not implemented hardware interrupt handling
yet (I'll do that next).
* I've made some changes to struct iframe: I've removed the e/r prefixes
from the member names for both 32/64, so now they're just named ip, ax,
bp, etc. This makes it easier to write code that works with both 32/64
without having to deal with different iframe member names.


# 5e9bb17da7b9cdd76ff9072486fab90688cf8c36 08-Jul-2012 Alex Smith <alex@alex-smith.me.uk>

Renamed remaining i386_* functions to x86_* for consistency.


# 4304bb9894335fe5e5bd667a1f27dc7605c2e5b9 04-Jul-2012 Alex Smith <alex@alex-smith.me.uk>

Added arch_cpu.cpp to the x86_64 build.

* Some things are currently ifndef'd out completely for x86_64 because
they aren't implemented, there's a few other ifdef's to handle x86_64
differences but most of the code works unchanged.
* Renamed some i386_* functions to x86_*.
* Added a temporary method for setting the current thread on x86_64
(a global variable, not SMP safe). This will be changed to be done
via the GS segment but I've not implemented that yet.


# 24df65921befcd0ad0c5c7866118f922da61cb96 11-Jun-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged signals-merge branch into trunk with the following changes:
* Reorganized the kernel locking related to threads and teams.
* We now discriminate correctly between process and thread signals. Signal
handlers have been moved to teams. Fixes #5679.
* Implemented real-time signal support, including signal queuing, SA_SIGINFO
support, sigqueue(), sigwaitinfo(), sigtimedwait(), waitid(), and the addition
of the real-time signal range. Closes #1935 and #2695.
* Gave SIGBUS a separate signal number. Fixes #6704.
* Implemented <time.h> clock and timer support, and fixed/completed alarm() and
[set]itimer(). Closes #5682.
* Implemented support for thread cancellation. Closes #5686.
* Moved send_signal() from <signal.h> to <OS.h>. Fixes #7554.
* Lots over smaller more or less related changes.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42116 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4535495d80c86e19e2610e7444a4fcefe3e0f8e6 10-Jan-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged the signals branch into trunk, with these changes:
* The team and thread kernel structures have been renamed to Team and Thread
respectively and moved into the new BKernel namespace.
* Several (kernel add-on) sources have been converted from C to C++ since
private kernel headers are included that are no longer C compatible.

Changes after merging:
* Fixed gcc 2 build (warnings mainly in the scary firewire bus manager).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40196 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b2acbcbfb30fc1184e24ab139a6d584d94c22b03 26-Dec-2010 Michael Lotz <mmlr@mlotz.ch>

CID 8122, 2210 (pointing at the same), 8121 and 2209 (pointing at the same):
Taking the size of a pointer instead of the actual extended registers struct.
Not sure this is used, but if it is it made the whole fpu/sse state in the
debugger useless.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39960 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 13b81a3b8eed9750171419427cf6be4a8822c25c 30-Oct-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added new thread flag THREAD_FLAGS_SINGLE_STEP, which is set to indicate that
userland single-stepping is enabled for the thread.
* x86_exit_user_debug_at_kernel_entry(): Always store DR6 and DR7 in the CPU
structure, not only when breakpoints are installed.
* x86_handle_debug_exception(): When encountering a syscall single-step, also
set the THREAD_FLAGS_DEBUG_THREAD thread flag. Otherwise the
B_THREAD_DEBUG_STOP would be ignored.
* x86 interrupt handling, DISABLE_BREAKPOINTS():
- Renamed to STOP_USER_DEBUGGING().
- Now it also call x86_exit_user_debug_at_kernel_entry() when
THREAD_FLAGS_SINGLE_STEP is set, so that the debug registers are saved.

Fixes #6751.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39201 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e40e5ebf8cfad45b09b4f2adfaa0f731e52ac791 13-Jul-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

arch_clear_watchpoint(): Passed incorrect flag to clear_breakpoint(), so
watchpoints would never be cleared.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37503 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 45538a5e3173993560f2469efbf0e1da25de4d2e 18-Apr-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

x86_handle_debug_exception(): The values of dr6 and dr7 are only stored in
the CPU info, if x86_exit_user_debug_at_kernel_entry() was executed before,
i.e. if the debug exception occurred in userlands. In all other cases we need
to read the current register values. Fixes #5742, a regression introduced in
r35951.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36340 a95241bf-73f2-0310-859d-f6bbb57e9c96


# feddedab0ca4fa1c553af10a3ed6066a840d0bea 25-Mar-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

x86:
Added fields for temporary storage of the debug registers dr6 and dr7 to the
arch_cpu_info structure. The actual registers are stored at the beginning of
x86_exit_user_debug_at_kernel_entry() and read in
x86_handle_debug_exception().
The problem was that x86_exit_user_debug_at_kernel_entry() itself overwrote
dr7 and, if kernel breakpoints were enabled, dr6 could be overwritten anytime
after. So x86_handle_debug_exception() would find incorrect values in the
registers (definitely in dr7) and thus interpret the detected debug condition
incorrectly. Usually watchpoints were recognized as breakpoints.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35951 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 8b3d3d8a1574eed1d59d052651fefa9af6b1fa6d 25-Feb-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Correctly handle cases when a thread single-steps into the kernel as it can
happen on syscalls or "int" instructions. The debug exception handler sets
the thread debug flags B_THREAD_DEBUG_STOP and
B_THREAD_DEBUG_NOTIFY_SINGLE_STEP (new) and lets the thread continue. Before
leaving the kernel the thread is stopped and a single-step notification is
sent. Fixes #3487.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35620 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 8ad4a2e9714d8090f67324b3842778ef09319674 01-Oct-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Improved comment.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33392 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0b11ecb18c9afe14114fac959f698a2bfa5b7230 21-Jul-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Always include the public arch_debugger.h headers. The structures defined
there are prefixed with the respective architecture name. Useful for remote
debugging a different architecture.
* <x86/arch_debugger.h>: Introduced a structure for the FPU state, so that it
isn't left to the debugger.
* Removed the _kern_get_thread_cpu_state() syscall. Was originally intended for
bdb compatiblity, but isn't really needed.
* Kernel x86 arch_get_debug_cpu_state(): The use of fnsave was broken, since
it reinits the FPU after saving the state. This resulted in weird results
when debugging functions using the FPU. We now use fxsave, if available.
Otherwise fnsave + frstor should be used -- not fully implemented yet.
Same for arch_set_debug_cpu_state().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31682 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b0f12d64f42dc8f5bbabf4cbcdf25178b3eb3749 23-Jun-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Added transparent software breakpoint support for user debuggers:
* The bulk of the work -- i.e. juggling the software and hardware breakpoints,
watchpoints, and memory reads/writes -- is done in the new class
BreakpointManager.
* For the architectures a few capability macros have to be defined, one
pointing to the software breakpoint instruction opcode. Done for x86.
* Some more simplifications in the user debugger code, made possible by the
recently introduced debugger_changed_condition attribute.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31214 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 568ade58d054e27ce4cd9da0d4e73ecb79563b96 13-Jun-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

User debugger support:
* Generalized address checks. The debugger can now also read the commpage.
* Added new syscall _kern_get_thread_cpu_state() to get the CPU state of a
not running thread. Introduced arch_get_thread_debug_cpu_state() for that
purpose, which is only implemented for x86 ATM (uses the new
i386_get_thread_user_iframe()).
* Don't allow a debugger to change a thread's "esp" anymore. That's the esp
register in the kernel. "user_esp" can still be changed.
* Generally set RF (resume flag) in eflags in interrupt handlers, not only
after a instruction breakpoint debug exception. This should prevent
breakpoints from being triggered more than once (e.g. when the breakpoint is
on an instruction that can cause a page fault). I still saw those with bdb
in VMware, but that might be a VMware bug.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31045 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 8342d4cdd2444061f1b0b7d11ef28cfe02cae187 16-Apr-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Updated to use add_debugger_command_etc().
* Added "step" debugger command to single-step to the next instruction (of the
topmost iframe).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30212 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 8753babd62c48e44f20506dd2bcb464f57756650 16-Apr-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Handle kernel debug exceptions similar to those in userland. This allows to
continue kernel breakpoints -- we would just retrigger the breakpoint when
continuing before.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30210 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 31d9352ff6fb0ee3dfb1dc63259370b6c61b3334 16-Apr-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Make sure kernel breakpoints are installed on all CPUs.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30209 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b447670286ce35b20725cc585c250f03a08d15aa 16-Apr-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Removed most of the special-casing for kernel breakpoints in the kernel
enter/exit code. There's no real reason not to keep kernel breakpoints
enabled when in userland (unless there are breakpoints installed for the
team, of course).
* Enabled kernel breakpoints by default (check your kernel_debug_config.h,
if you have overridden it!), since they don't really add any overhead
anymore.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30206 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a8f9741c8c2815234e87b78167738057b976b537 04-Jul-2008 Michael Lotz <mmlr@mlotz.ch>

* Removed -Wno-unused from all KernelMergeObjects in kernel Jamfiles.
* Fixed most of the warnings resulting from that by removing actually not used
variables or moving declaration into the #IF. Left unused functions there
though, as I wouldn't know if they are supposed to be used again.
* Fixed two statements with no effect (clamping to MAX_ANCILLARY_DATA_LEN in
socket.cpp and unsetting fCounterSem in MessagingService.cpp).
* Some style cleanups.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26253 a95241bf-73f2-0310-859d-f6bbb57e9c96


# bb107c4e29877ab7be19fbe8c52eef01d44b03cd 22-May-2008 Axel Dörfler <axeld@pinc-software.de>

Patch by Jan Klötzke:
* In vm86 mode CS will have arbitrary values so we check for both USER_CODE_SEG
and the VM flag in EFLAGS. This is also done when entering interrupt gates.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25607 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 34b3b26b3b8c46ba46ddde037b10dd173f4936d6 10-Jan-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged branch haiku/branches/developer/bonefish/optimization revision
23139 into trunk, with roughly the following changes (for details svn
log the branch):
* The int 99 syscall handler is now fully in assembly.
* Added a sysenter/sysexit handler and use it on Pentiums that support
it (via commpage).
* Got rid of i386_handle_trap(). A bit of functionality was moved into
the assembly handler which now uses a jump table to call C functions
handling the respective interrupt.
* Some optimizations to get user debugger support code out of the
interrupt handling path.
* Introduced a thread::flags fields which allows to skip handling of
rare events (signals, user debug enabling/disabling) on the
common interrupt handling path.
* Got rid of the explicit iframe stack. The iframes can still be
retrieved by iterating through the stack frames.
* Made the commpage an architecture independent feature. It's used for
the real time data stuff (instead of creating a separate area).
* The x86 CPU modules can now provide processor optimized versions for
common functions (currently memcpy() only). They are used in the
kernel and are provided to the userland via commpage entries.
* Introduced build system feature allowing easy use of C structure
member offsets in assembly code.

Changes after merging:
* Fixed merge conflict in src/system/kernel/arch/x86/arch_debug.cpp
(caused by refactoring and introduction of "call" debugger command).



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23370 a95241bf-73f2-0310-859d-f6bbb57e9c96


# bc5f008afbe993ef4b6a27593c29640cb173d262 02-Sep-2007 Ingo Weinhold <ingo_weinhold@gmx.de>

Added "breakpoint", "watchpoint", "breakpoints", and "watchpoints"
kernel debugger commands, which can set/clear/list in-kernel break- and
watchpoints. Only available when KERNEL_BREAKPOINTS is defined.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22153 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 667f1eeb67a4160a43f49c0be9d4d8b7c070afdd 02-Sep-2007 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added support for setting (hardware) break-/watchpoints in the kernel.
Can be enabled by defining KERNEL_BREAKPOINTS in arch/user_debugger.h
and will provide the arch_{set,clear}_kernel_{break,watch}point()
function. Hitting a break-/watchpoint will throw the thread into KDL.
* Finally added a comment, what's the point of
i386_reinit_user_debug_after_context_switch(), since I wonder every
time I see it. Should be optimized aways soon.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22150 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 7eee76e65a81333e46c8f319d39ccb7f95be53be 27-Apr-2006 Michael Lotz <mmlr@mlotz.ch>

Implemented lazy FPU state save/restore. In the end mostly ported from NewOS. SMP safe.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17251 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 06be24a7486df93108171263622708a815ae88a3 01-Nov-2005 Axel Dörfler <axeld@pinc-software.de>

The spurious debug exception sometimes comes very often in QEMU - it's now only
printed when tracing is turned on.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14634 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 2d690920ac4d0cd27eb3c118fb2b0862615869e0 13-Apr-2005 Axel Dörfler <axeld@pinc-software.de>

Renamed system/core to system/kernel.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12360 a95241bf-73f2-0310-859d-f6bbb57e9c96