2005-01-06 01:34:41 +00:00
|
|
|
/*-
|
1993-06-12 14:58:17 +00:00
|
|
|
* Mach Operating System
|
|
|
|
* Copyright (c) 1991,1990 Carnegie Mellon University
|
|
|
|
* All Rights Reserved.
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1993-06-12 14:58:17 +00:00
|
|
|
* Permission to use, copy, modify and distribute this software and its
|
|
|
|
* documentation is hereby granted, provided that both the copyright
|
|
|
|
* notice and this permission notice appear in all copies of the
|
|
|
|
* software, derivative works or modified versions, and any portions
|
|
|
|
* thereof, and that both notices appear in supporting documentation.
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
|
|
|
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
|
1993-06-12 14:58:17 +00:00
|
|
|
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
|
|
|
|
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1993-06-12 14:58:17 +00:00
|
|
|
* Carnegie Mellon requests users of this software to return to
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1993-06-12 14:58:17 +00:00
|
|
|
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
|
|
|
* School of Computer Science
|
|
|
|
* Carnegie Mellon University
|
|
|
|
* Pittsburgh PA 15213-3890
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1993-06-12 14:58:17 +00:00
|
|
|
* any improvements or extensions that they make and grant Carnegie the
|
|
|
|
* rights to redistribute these changes.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Author: David B. Golub, Carnegie Mellon University
|
|
|
|
* Date: 7/90
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Commands to run process.
|
|
|
|
*/
|
2003-06-10 22:09:23 +00:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <sys/param.h>
|
2004-07-10 23:47:20 +00:00
|
|
|
#include <sys/kdb.h>
|
2005-04-14 05:25:40 +00:00
|
|
|
#include <sys/proc.h>
|
2004-07-10 23:47:20 +00:00
|
|
|
|
|
|
|
#include <machine/kdb.h>
|
|
|
|
#include <machine/pcb.h>
|
1995-12-10 19:08:32 +00:00
|
|
|
|
1995-12-07 12:48:31 +00:00
|
|
|
#include <vm/vm.h>
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1995-12-10 19:08:32 +00:00
|
|
|
#include <ddb/ddb.h>
|
1993-06-12 14:58:17 +00:00
|
|
|
#include <ddb/db_break.h>
|
|
|
|
#include <ddb/db_access.h>
|
|
|
|
|
1995-12-10 13:32:43 +00:00
|
|
|
static int db_run_mode;
|
1993-06-12 14:58:17 +00:00
|
|
|
#define STEP_NONE 0
|
|
|
|
#define STEP_ONCE 1
|
|
|
|
#define STEP_RETURN 2
|
|
|
|
#define STEP_CALLT 3
|
|
|
|
#define STEP_CONTINUE 4
|
2014-10-11 20:25:19 +00:00
|
|
|
#define STEP_INVISIBLE 5
|
1993-06-12 14:58:17 +00:00
|
|
|
#define STEP_COUNT 6
|
|
|
|
|
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
|
|
|
static bool db_sstep_multiple;
|
2015-05-21 15:16:18 +00:00
|
|
|
static bool db_sstep_print;
|
1995-12-10 13:32:43 +00:00
|
|
|
static int db_loop_count;
|
|
|
|
static int db_call_depth;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
int db_inst_count;
|
|
|
|
int db_load_count;
|
|
|
|
int db_store_count;
|
|
|
|
|
2015-11-27 19:03:59 +00:00
|
|
|
#ifdef SOFTWARE_SSTEP
|
|
|
|
db_breakpoint_t db_not_taken_bkpt = 0;
|
|
|
|
db_breakpoint_t db_taken_bkpt = 0;
|
|
|
|
#endif
|
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
#ifndef db_set_single_step
|
2004-07-10 23:47:20 +00:00
|
|
|
void db_set_single_step(void);
|
1993-06-12 14:58:17 +00:00
|
|
|
#endif
|
|
|
|
#ifndef db_clear_single_step
|
2004-07-10 23:47:20 +00:00
|
|
|
void db_clear_single_step(void);
|
1995-11-29 10:25:50 +00:00
|
|
|
#endif
|
2015-11-27 19:03:59 +00:00
|
|
|
#ifndef db_pc_is_singlestep
|
|
|
|
static bool
|
|
|
|
db_pc_is_singlestep(db_addr_t pc)
|
|
|
|
{
|
2004-11-21 18:11:02 +00:00
|
|
|
#ifdef SOFTWARE_SSTEP
|
2015-11-27 19:03:59 +00:00
|
|
|
if ((db_not_taken_bkpt != 0 && pc == db_not_taken_bkpt->address)
|
|
|
|
|| (db_taken_bkpt != 0 && pc == db_taken_bkpt->address))
|
|
|
|
return (true);
|
|
|
|
#endif
|
|
|
|
return (false);
|
|
|
|
}
|
2004-11-21 18:11:02 +00:00
|
|
|
#endif
|
|
|
|
|
2015-05-21 15:16:18 +00:00
|
|
|
bool
|
2016-09-09 15:53:42 +00:00
|
|
|
db_stop_at_pc(int type, int code, bool *is_breakpoint, bool *is_watchpoint)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
2015-05-23 14:59:27 +00:00
|
|
|
db_addr_t pc;
|
|
|
|
db_breakpoint_t bkpt;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
2016-09-09 15:53:42 +00:00
|
|
|
*is_breakpoint = IS_BREAKPOINT_TRAP(type, code);
|
|
|
|
*is_watchpoint = IS_WATCHPOINT_TRAP(type, code);
|
2004-11-21 18:11:02 +00:00
|
|
|
pc = PC_REGS();
|
2015-11-27 19:03:59 +00:00
|
|
|
if (db_pc_is_singlestep(pc))
|
2015-05-18 22:27:46 +00:00
|
|
|
*is_breakpoint = false;
|
2004-11-21 18:11:02 +00:00
|
|
|
|
2004-07-10 23:47:20 +00:00
|
|
|
db_clear_single_step();
|
1993-06-12 14:58:17 +00:00
|
|
|
db_clear_breakpoints();
|
|
|
|
db_clear_watchpoints();
|
|
|
|
|
|
|
|
#ifdef FIXUP_PC_AFTER_BREAK
|
|
|
|
if (*is_breakpoint) {
|
|
|
|
/*
|
|
|
|
* Breakpoint trap. Fix up the PC if the
|
|
|
|
* machine requires it.
|
|
|
|
*/
|
|
|
|
FIXUP_PC_AFTER_BREAK
|
2004-07-10 23:47:20 +00:00
|
|
|
pc = PC_REGS();
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now check for a breakpoint at this address.
|
|
|
|
*/
|
|
|
|
bkpt = db_find_breakpoint_here(pc);
|
|
|
|
if (bkpt) {
|
|
|
|
if (--bkpt->count == 0) {
|
|
|
|
bkpt->count = bkpt->init_count;
|
2015-05-18 22:27:46 +00:00
|
|
|
*is_breakpoint = true;
|
|
|
|
return (true); /* stop here */
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
2016-09-09 14:09:50 +00:00
|
|
|
return (false); /* continue the countdown */
|
1993-06-12 14:58:17 +00:00
|
|
|
} else if (*is_breakpoint) {
|
2001-09-15 11:06:07 +00:00
|
|
|
#ifdef BKPT_SKIP
|
|
|
|
BKPT_SKIP;
|
1998-06-07 17:13:14 +00:00
|
|
|
#endif
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
1995-05-30 08:16:23 +00:00
|
|
|
|
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
|
|
|
*is_breakpoint = false; /* might be a breakpoint, but not ours */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If stepping, then abort if the trap type is unexpected.
|
|
|
|
* Breakpoints owned by us are expected and were handled above.
|
|
|
|
* Single-steps are expected and are handled below. All others
|
|
|
|
* are unexpected.
|
|
|
|
*
|
|
|
|
* If the MD layer doesn't tell us when it is stepping, use the
|
|
|
|
* bad historical default that all unexepected traps.
|
|
|
|
*/
|
|
|
|
#ifndef IS_SSTEP_TRAP
|
|
|
|
#define IS_SSTEP_TRAP(type, code) true
|
|
|
|
#endif
|
|
|
|
if (db_run_mode != STEP_CONTINUE && !IS_SSTEP_TRAP(type, code)) {
|
|
|
|
printf("Stepping aborted\n");
|
|
|
|
db_run_mode = STEP_NONE;
|
|
|
|
return (true);
|
|
|
|
}
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
if (db_run_mode == STEP_INVISIBLE) {
|
|
|
|
db_run_mode = STEP_CONTINUE;
|
2015-05-18 22:27:46 +00:00
|
|
|
return (false); /* continue */
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
if (db_run_mode == STEP_COUNT) {
|
2015-05-18 22:27:46 +00:00
|
|
|
return (false); /* continue */
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
if (db_run_mode == STEP_ONCE) {
|
|
|
|
if (--db_loop_count > 0) {
|
|
|
|
if (db_sstep_print) {
|
|
|
|
db_printf("\t\t");
|
|
|
|
db_print_loc_and_inst(pc);
|
|
|
|
}
|
2015-05-18 22:27:46 +00:00
|
|
|
return (false); /* continue */
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (db_run_mode == STEP_RETURN) {
|
|
|
|
/* continue until matching return */
|
2002-06-23 20:03:03 +00:00
|
|
|
db_expr_t ins;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
2015-05-18 22:27:46 +00:00
|
|
|
ins = db_get_value(pc, sizeof(int), false);
|
1993-06-12 14:58:17 +00:00
|
|
|
if (!inst_trap_return(ins) &&
|
|
|
|
(!inst_return(ins) || --db_call_depth != 0)) {
|
|
|
|
if (db_sstep_print) {
|
|
|
|
if (inst_call(ins) || inst_return(ins)) {
|
2015-05-23 14:59:27 +00:00
|
|
|
int i;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
db_printf("[after %6d] ", db_inst_count);
|
|
|
|
for (i = db_call_depth; --i > 0; )
|
|
|
|
db_printf(" ");
|
|
|
|
db_print_loc_and_inst(pc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (inst_call(ins))
|
|
|
|
db_call_depth++;
|
2015-05-18 22:27:46 +00:00
|
|
|
return (false); /* continue */
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (db_run_mode == STEP_CALLT) {
|
|
|
|
/* continue until call or return */
|
2002-06-23 20:03:03 +00:00
|
|
|
db_expr_t ins;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
2015-05-18 22:27:46 +00:00
|
|
|
ins = db_get_value(pc, sizeof(int), false);
|
1993-06-12 14:58:17 +00:00
|
|
|
if (!inst_call(ins) &&
|
|
|
|
!inst_return(ins) &&
|
|
|
|
!inst_trap_return(ins)) {
|
2015-05-18 22:27:46 +00:00
|
|
|
return (false); /* continue */
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
db_run_mode = STEP_NONE;
|
2015-05-18 22:27:46 +00:00
|
|
|
return (true);
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-05-21 15:16:18 +00:00
|
|
|
db_restart_at_pc(bool watchpt)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
2015-05-23 14:59:27 +00:00
|
|
|
db_addr_t pc = PC_REGS();
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
if ((db_run_mode == STEP_COUNT) ||
|
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
|
|
|
((db_run_mode == STEP_ONCE) && db_sstep_multiple) ||
|
1993-06-12 14:58:17 +00:00
|
|
|
(db_run_mode == STEP_RETURN) ||
|
|
|
|
(db_run_mode == STEP_CALLT)) {
|
|
|
|
/*
|
|
|
|
* We are about to execute this instruction,
|
|
|
|
* so count it now.
|
|
|
|
*/
|
2014-08-14 16:01:51 +00:00
|
|
|
#ifdef SOFTWARE_SSTEP
|
|
|
|
db_expr_t ins =
|
|
|
|
#endif
|
2015-05-18 22:27:46 +00:00
|
|
|
db_get_value(pc, sizeof(int), false);
|
1993-06-12 14:58:17 +00:00
|
|
|
db_inst_count++;
|
|
|
|
db_load_count += inst_load(ins);
|
|
|
|
db_store_count += inst_store(ins);
|
|
|
|
#ifdef SOFTWARE_SSTEP
|
|
|
|
/* XXX works on mips, but... */
|
|
|
|
if (inst_branch(ins) || inst_call(ins)) {
|
|
|
|
ins = db_get_value(next_instr_address(pc,1),
|
2015-05-18 22:27:46 +00:00
|
|
|
sizeof(int), false);
|
1993-06-12 14:58:17 +00:00
|
|
|
db_inst_count++;
|
|
|
|
db_load_count += inst_load(ins);
|
|
|
|
db_store_count += inst_store(ins);
|
|
|
|
}
|
2001-08-15 03:38:49 +00:00
|
|
|
#endif /* SOFTWARE_SSTEP */
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (db_run_mode == STEP_CONTINUE) {
|
|
|
|
if (watchpt || db_find_breakpoint_here(pc)) {
|
|
|
|
/*
|
|
|
|
* Step over breakpoint/watchpoint.
|
|
|
|
*/
|
|
|
|
db_run_mode = STEP_INVISIBLE;
|
2004-07-10 23:47:20 +00:00
|
|
|
db_set_single_step();
|
1993-06-12 14:58:17 +00:00
|
|
|
} else {
|
|
|
|
db_set_breakpoints();
|
|
|
|
db_set_watchpoints();
|
|
|
|
}
|
|
|
|
} else {
|
2004-07-10 23:47:20 +00:00
|
|
|
db_set_single_step();
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SOFTWARE_SSTEP
|
|
|
|
/*
|
|
|
|
* Software implementation of single-stepping.
|
|
|
|
* If your machine does not have a trace mode
|
|
|
|
* similar to the vax or sun ones you can use
|
|
|
|
* this implementation, done for the mips.
|
|
|
|
* Just define the above conditional and provide
|
|
|
|
* the functions/macros defined below.
|
|
|
|
*
|
2015-05-21 15:16:18 +00:00
|
|
|
* extern bool
|
1993-06-12 14:58:17 +00:00
|
|
|
* inst_branch(), returns true if the instruction might branch
|
|
|
|
* extern unsigned
|
|
|
|
* branch_taken(), return the address the instruction might
|
|
|
|
* branch to
|
|
|
|
* db_getreg_val(); return the value of a user register,
|
|
|
|
* as indicated in the hardware instruction
|
|
|
|
* encoding, e.g. 8 for r8
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1993-06-12 14:58:17 +00:00
|
|
|
* next_instr_address(pc,bd) returns the address of the first
|
|
|
|
* instruction following the one at "pc",
|
|
|
|
* which is either in the taken path of
|
|
|
|
* the branch (bd==1) or not. This is
|
|
|
|
* for machines (mips) with branch delays.
|
|
|
|
*
|
|
|
|
* A single-step may involve at most 2 breakpoints -
|
|
|
|
* one for branch-not-taken and one for branch taken.
|
|
|
|
* If one of these addresses does not already have a breakpoint,
|
|
|
|
* we allocate a breakpoint and save it here.
|
|
|
|
* These breakpoints are deleted on return.
|
1995-05-30 08:16:23 +00:00
|
|
|
*/
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
void
|
2004-07-10 23:47:20 +00:00
|
|
|
db_set_single_step(void)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
2004-07-10 23:47:20 +00:00
|
|
|
db_addr_t pc = PC_REGS(), brpc;
|
|
|
|
unsigned inst;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* User was stopped at pc, e.g. the instruction
|
|
|
|
* at pc was not executed.
|
|
|
|
*/
|
2015-05-18 22:27:46 +00:00
|
|
|
inst = db_get_value(pc, sizeof(int), false);
|
2008-08-02 12:49:43 +00:00
|
|
|
if (inst_branch(inst) || inst_call(inst) || inst_return(inst)) {
|
2004-07-10 23:47:20 +00:00
|
|
|
brpc = branch_taken(inst, pc);
|
|
|
|
if (brpc != pc) { /* self-branches are hopeless */
|
|
|
|
db_taken_bkpt = db_set_temp_breakpoint(brpc);
|
|
|
|
}
|
|
|
|
pc = next_instr_address(pc, 1);
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
2004-07-10 23:47:20 +00:00
|
|
|
pc = next_instr_address(pc, 0);
|
1993-06-12 14:58:17 +00:00
|
|
|
db_not_taken_bkpt = db_set_temp_breakpoint(pc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-07-10 23:47:20 +00:00
|
|
|
db_clear_single_step(void)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (db_not_taken_bkpt != 0) {
|
2004-07-10 23:47:20 +00:00
|
|
|
db_delete_temp_breakpoint(db_not_taken_bkpt);
|
|
|
|
db_not_taken_bkpt = 0;
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
1998-07-05 10:12:18 +00:00
|
|
|
if (db_taken_bkpt != 0) {
|
2004-07-10 23:47:20 +00:00
|
|
|
db_delete_temp_breakpoint(db_taken_bkpt);
|
|
|
|
db_taken_bkpt = 0;
|
1998-07-05 10:12:18 +00:00
|
|
|
}
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
|
2001-08-15 03:38:49 +00:00
|
|
|
#endif /* SOFTWARE_SSTEP */
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
extern int db_cmd_loop_done;
|
|
|
|
|
|
|
|
/* single-step */
|
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
2015-05-21 15:16:18 +00:00
|
|
|
db_single_step_cmd(db_expr_t addr, bool have_addr, db_expr_t count, char *modif)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
2015-05-21 15:16:18 +00:00
|
|
|
bool print = false;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
if (count == -1)
|
|
|
|
count = 1;
|
|
|
|
|
|
|
|
if (modif[0] == 'p')
|
2015-05-18 22:27:46 +00:00
|
|
|
print = true;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
db_run_mode = STEP_ONCE;
|
|
|
|
db_loop_count = count;
|
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
|
|
|
db_sstep_multiple = (count != 1);
|
1993-06-12 14:58:17 +00:00
|
|
|
db_sstep_print = print;
|
|
|
|
db_inst_count = 0;
|
|
|
|
db_load_count = 0;
|
|
|
|
db_store_count = 0;
|
|
|
|
|
|
|
|
db_cmd_loop_done = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* trace and print until call/return */
|
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
2015-05-21 15:16:18 +00:00
|
|
|
db_trace_until_call_cmd(db_expr_t addr, bool have_addr, db_expr_t count,
|
2014-10-12 18:01:52 +00:00
|
|
|
char *modif)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
2015-05-21 15:16:18 +00:00
|
|
|
bool print = false;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
if (modif[0] == 'p')
|
2015-05-18 22:27:46 +00:00
|
|
|
print = true;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
db_run_mode = STEP_CALLT;
|
|
|
|
db_sstep_print = print;
|
|
|
|
db_inst_count = 0;
|
|
|
|
db_load_count = 0;
|
|
|
|
db_store_count = 0;
|
|
|
|
|
|
|
|
db_cmd_loop_done = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
2015-05-21 15:16:18 +00:00
|
|
|
db_trace_until_matching_cmd(db_expr_t addr, bool have_addr, db_expr_t count,
|
|
|
|
char *modif)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
2015-05-21 15:16:18 +00:00
|
|
|
bool print = false;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
if (modif[0] == 'p')
|
2015-05-18 22:27:46 +00:00
|
|
|
print = true;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
db_run_mode = STEP_RETURN;
|
|
|
|
db_call_depth = 1;
|
|
|
|
db_sstep_print = print;
|
|
|
|
db_inst_count = 0;
|
|
|
|
db_load_count = 0;
|
|
|
|
db_store_count = 0;
|
|
|
|
|
|
|
|
db_cmd_loop_done = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* continue */
|
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
2015-05-21 15:16:18 +00:00
|
|
|
db_continue_cmd(db_expr_t addr, bool have_addr, db_expr_t count, char *modif)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
|
|
|
if (modif[0] == 'c')
|
|
|
|
db_run_mode = STEP_COUNT;
|
|
|
|
else
|
|
|
|
db_run_mode = STEP_CONTINUE;
|
|
|
|
db_inst_count = 0;
|
|
|
|
db_load_count = 0;
|
|
|
|
db_store_count = 0;
|
|
|
|
|
|
|
|
db_cmd_loop_done = 1;
|
|
|
|
}
|