summaryrefslogtreecommitdiffstats
path: root/sys/ddb
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2016-11-07 12:10:17 +0000
committerkib <kib@FreeBSD.org>2016-11-07 12:10:17 +0000
commit664c82e536131bd88cdfa97cb2b4859c20f222a4 (patch)
tree9718576c2fcbdd55f946b5b10383d6a15996d840 /sys/ddb
parente83371ccf28a104b7d819fb6f0b7e927374dae47 (diff)
downloadFreeBSD-src-664c82e536131bd88cdfa97cb2b4859c20f222a4.zip
FreeBSD-src-664c82e536131bd88cdfa97cb2b4859c20f222a4.tar.gz
Merge bde improvements for ddb on x86, mostly for single-stepping and
vm86 mode. MFC r304085 (by bde): Fix the variables $esp, $ds, $es, $fs, $gs and $ss in vm86 mode. Fix PC_REGS() so that printing of instructions works in some useful cases. MFC r304962 (by bde): Expand error messages: print symbol names, parentheses and shift tokens, and negative shift counts. Fix error messages. MFC r305612 (by bde): Fix single-stepping of instructions emulated by vm86. MFC r305661 (by bde): Give the full syntax of the 'count' arg for all commmands that support it. Give the full syntax of the 'addr' arg for these commands and some others. Rename it from 'address' for the generic command. Fix description of how 'count' is supposed to work for the 'break' command. Don't (mis)describe the syntax of the comma for the 'step' command. Expand the description for the generic command. Give the full syntax for the 'examine' command. It was also missing the possible values for the modifier. MFC r305663 (by bde): Fix stopping when the specified breakpoint count is reached. MFC r305665 (by bde): Pass the trap type and code down from db_trap() to db_stop_at_pc() so that the latter can easily determine what the trap type actually is after callers are fixed to encode the type unambigously. MFC r305807 (by bde): Use the MI macro TRAPF_USERMODE() instead of open-coded checks for SEL_UPL and sometimes PSL_VM. Fix logic errors in treating vm86 bioscall mode as kernel mode. The main place checked all the necessary flags, but put the necessary parentheses for the PSL_VM and PCB_VM86CALL checks in the wrong place. MFC r305811 (by bz): Try to fix LINT builds after r305807. MFC r305840 (by bde): Abort single stepping in ddb if the trap is not for single-stepping. MFC r305862 (by bde): Ifdef the new dr6 variable for KDB. MFC r305864 (by bde): Statically initialize the run mode to the one that will become current on first entry. Don't reset to the run mode to STEP_NONE when stopping, and remove STEP_NONE. MFC r305865 (by bde): Fix decoding of tf_rsp on amd64, and move TF_HAS_STACKREGS() to the i386-only section, and fix a comment about the amd64 kernel trapframe not having stackregs. MFC r305897 (by bde): Silently ignore unexpected single-step traps. MFC r306311 (by bde): Determine the operand/address size of %cs in a new function db_segsize(). Use db_segsize() to set the default operand/address size for disassembling. Fix db_print_loc_and_inst() to ask for the normal format and not the alternate in normal operation. Use db_segsize() to avoid trying to print a garbage stack trace if %cs is 16 bits.
Diffstat (limited to 'sys/ddb')
-rw-r--r--sys/ddb/db_examine.c2
-rw-r--r--sys/ddb/db_expr.c36
-rw-r--r--sys/ddb/db_main.c5
-rw-r--r--sys/ddb/db_run.c40
-rw-r--r--sys/ddb/ddb.h3
5 files changed, 59 insertions, 27 deletions
diff --git a/sys/ddb/db_examine.c b/sys/ddb/db_examine.c
index de2bbe4..a1e5a28 100644
--- a/sys/ddb/db_examine.c
+++ b/sys/ddb/db_examine.c
@@ -241,7 +241,7 @@ db_print_loc_and_inst(db_addr_t loc)
db_printsym(loc, DB_STGY_PROC);
if (db_search_symbol(loc, DB_STGY_PROC, &off) != C_DB_SYM_NULL) {
db_printf(":\t");
- (void)db_disasm(loc, true);
+ (void)db_disasm(loc, false);
}
}
diff --git a/sys/ddb/db_expr.c b/sys/ddb/db_expr.c
index db17f36..c206a57 100644
--- a/sys/ddb/db_expr.c
+++ b/sys/ddb/db_expr.c
@@ -57,7 +57,8 @@ db_term(db_expr_t *valuep)
if (!db_value_of_name(db_tok_string, valuep) &&
!db_value_of_name_pcpu(db_tok_string, valuep) &&
!db_value_of_name_vnet(db_tok_string, valuep)) {
- db_error("Symbol not found\n");
+ db_printf("Symbol '%s' not found\n", db_tok_string);
+ db_error(NULL);
/*NOTREACHED*/
}
return (true);
@@ -89,12 +90,14 @@ db_term(db_expr_t *valuep)
}
if (t == tLPAREN) {
if (!db_expression(valuep)) {
- db_error("Syntax error\n");
+ db_printf("Expression syntax error after '%c'\n", '(');
+ db_error(NULL);
/*NOTREACHED*/
}
t = db_read_token();
if (t != tRPAREN) {
- db_error("Syntax error\n");
+ db_printf("Expression syntax error -- expected '%c'\n", ')');
+ db_error(NULL);
/*NOTREACHED*/
}
return (true);
@@ -164,7 +167,9 @@ db_mult_expr(db_expr_t *valuep)
while (t == tSTAR || t == tSLASH || t == tPCT || t == tHASH ||
t == tBIT_AND ) {
if (!db_term(&rhs)) {
- db_printf("Expression syntax error after '%c'\n", '!');
+ db_printf("Expression syntax error after '%c'\n",
+ t == tSTAR ? '*' : t == tSLASH ? '/' : t == tPCT ? '%' :
+ t == tHASH ? '#' : '&');
db_error(NULL);
/*NOTREACHED*/
}
@@ -177,7 +182,7 @@ db_mult_expr(db_expr_t *valuep)
break;
default:
if (rhs == 0) {
- db_error("Divide by 0\n");
+ db_error("Division by 0\n");
/*NOTREACHED*/
}
if (t == tSLASH)
@@ -199,7 +204,6 @@ db_add_expr(db_expr_t *valuep)
{
db_expr_t lhs, rhs;
int t;
- char c;
if (!db_mult_expr(&lhs))
return (false);
@@ -207,8 +211,8 @@ db_add_expr(db_expr_t *valuep)
t = db_read_token();
while (t == tPLUS || t == tMINUS || t == tBIT_OR) {
if (!db_mult_expr(&rhs)) {
- c = db_tok_string[0];
- db_printf("Expression syntax error after '%c'\n", c);
+ db_printf("Expression syntax error after '%c'\n",
+ t == tPLUS ? '+' : t == tMINUS ? '-' : '|');
db_error(NULL);
/*NOTREACHED*/
}
@@ -243,11 +247,14 @@ db_shift_expr(db_expr_t *valuep)
t = db_read_token();
while (t == tSHIFT_L || t == tSHIFT_R) {
if (!db_add_expr(&rhs)) {
- db_error("Syntax error\n");
+ db_printf("Expression syntax error after '%s'\n",
+ t == tSHIFT_L ? "<<" : ">>");
+ db_error(NULL);
/*NOTREACHED*/
}
if (rhs < 0) {
- db_error("Negative shift amount\n");
+ db_printf("Negative shift amount %jd\n", (intmax_t)rhs);
+ db_error(NULL);
/*NOTREACHED*/
}
if (t == tSHIFT_L)
@@ -269,7 +276,6 @@ db_logical_relation_expr(
{
db_expr_t lhs, rhs;
int t;
- char op[3];
if (!db_shift_expr(&lhs))
return (false);
@@ -277,11 +283,11 @@ db_logical_relation_expr(
t = db_read_token();
while (t == tLOG_EQ || t == tLOG_NOT_EQ || t == tGREATER ||
t == tGREATER_EQ || t == tLESS || t == tLESS_EQ) {
- op[0] = db_tok_string[0];
- op[1] = db_tok_string[1];
- op[2] = 0;
if (!db_shift_expr(&rhs)) {
- db_printf("Expression syntax error after \"%s\"\n", op);
+ db_printf("Expression syntax error after '%s'\n",
+ t == tLOG_EQ ? "==" : t == tLOG_NOT_EQ ? "!=" :
+ t == tGREATER ? ">" : t == tGREATER_EQ ? ">=" :
+ t == tLESS ? "<" : "<=");
db_error(NULL);
/*NOTREACHED*/
}
diff --git a/sys/ddb/db_main.c b/sys/ddb/db_main.c
index 3345bb6..da6a513 100644
--- a/sys/ddb/db_main.c
+++ b/sys/ddb/db_main.c
@@ -226,10 +226,7 @@ db_trap(int type, int code)
if (cnunavailable())
return (0);
- bkpt = IS_BREAKPOINT_TRAP(type, code);
- watchpt = IS_WATCHPOINT_TRAP(type, code);
-
- if (db_stop_at_pc(&bkpt)) {
+ if (db_stop_at_pc(type, code, &bkpt, &watchpt)) {
if (db_inst_count) {
db_printf("After %d instructions (%d loads, %d stores),\n",
db_inst_count, db_load_count, db_store_count);
diff --git a/sys/ddb/db_run.c b/sys/ddb/db_run.c
index 5250651..4d8d3c7 100644
--- a/sys/ddb/db_run.c
+++ b/sys/ddb/db_run.c
@@ -48,15 +48,15 @@ __FBSDID("$FreeBSD$");
#include <ddb/db_break.h>
#include <ddb/db_access.h>
-static int db_run_mode;
-#define STEP_NONE 0
#define STEP_ONCE 1
#define STEP_RETURN 2
#define STEP_CALLT 3
#define STEP_CONTINUE 4
#define STEP_INVISIBLE 5
#define STEP_COUNT 6
+static int db_run_mode = STEP_CONTINUE;
+static bool db_sstep_multiple;
static bool db_sstep_print;
static int db_loop_count;
static int db_call_depth;
@@ -90,13 +90,14 @@ db_pc_is_singlestep(db_addr_t pc)
#endif
bool
-db_stop_at_pc(bool *is_breakpoint)
+db_stop_at_pc(int type, int code, bool *is_breakpoint, bool *is_watchpoint)
{
db_addr_t pc;
db_breakpoint_t bkpt;
+ *is_breakpoint = IS_BREAKPOINT_TRAP(type, code);
+ *is_watchpoint = IS_WATCHPOINT_TRAP(type, code);
pc = PC_REGS();
-
if (db_pc_is_singlestep(pc))
*is_breakpoint = false;
@@ -125,13 +126,39 @@ db_stop_at_pc(bool *is_breakpoint)
*is_breakpoint = true;
return (true); /* stop here */
}
+ return (false); /* continue the countdown */
} else if (*is_breakpoint) {
#ifdef BKPT_SKIP
BKPT_SKIP;
#endif
}
- *is_breakpoint = false;
+ *is_breakpoint = false; /* might be a breakpoint, but not ours */
+
+ /*
+ * If not stepping, then silently ignore single-step traps
+ * (except for clearing the single-step-flag above).
+ *
+ * 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.
+ *
+ * Only do either of these if the MD layer claims to classify
+ * single-step traps unambiguously (by defining IS_SSTEP_TRAP).
+ * Otherwise, fall through to the bad historical behaviour
+ * given by turning unexpected traps into expected traps: if not
+ * stepping, then expect only breakpoints and stop, and if
+ * stepping, then expect only single-steps and step.
+ */
+#ifdef IS_SSTEP_TRAP
+ if (db_run_mode == STEP_CONTINUE && IS_SSTEP_TRAP(type, code))
+ return (false);
+ if (db_run_mode != STEP_CONTINUE && !IS_SSTEP_TRAP(type, code)) {
+ printf("Stepping aborted\n");
+ return (true);
+ }
+#endif
if (db_run_mode == STEP_INVISIBLE) {
db_run_mode = STEP_CONTINUE;
@@ -184,7 +211,6 @@ db_stop_at_pc(bool *is_breakpoint)
return (false); /* continue */
}
}
- db_run_mode = STEP_NONE;
return (true);
}
@@ -194,6 +220,7 @@ db_restart_at_pc(bool watchpt)
db_addr_t pc = PC_REGS();
if ((db_run_mode == STEP_COUNT) ||
+ ((db_run_mode == STEP_ONCE) && db_sstep_multiple) ||
(db_run_mode == STEP_RETURN) ||
(db_run_mode == STEP_CALLT)) {
/*
@@ -321,6 +348,7 @@ db_single_step_cmd(db_expr_t addr, bool have_addr, db_expr_t count, char *modif)
db_run_mode = STEP_ONCE;
db_loop_count = count;
+ db_sstep_multiple = (count != 1);
db_sstep_print = print;
db_inst_count = 0;
db_load_count = 0;
diff --git a/sys/ddb/ddb.h b/sys/ddb/ddb.h
index a2adcdf..fcf772b 100644
--- a/sys/ddb/ddb.h
+++ b/sys/ddb/ddb.h
@@ -215,7 +215,8 @@ void db_restart_at_pc(bool watchpt);
int db_set_variable(db_expr_t value);
void db_set_watchpoints(void);
void db_skip_to_eol(void);
-bool db_stop_at_pc(bool *is_breakpoint);
+bool db_stop_at_pc(int type, int code, bool *is_breakpoint,
+ bool *is_watchpoint);
#define db_strcpy strcpy
void db_trace_self(void);
int db_trace_thread(struct thread *, int);
OpenPOWER on IntegriCloud