summaryrefslogtreecommitdiffstats
path: root/sys/ddb
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2006-07-12 21:22:44 +0000
committerjhb <jhb@FreeBSD.org>2006-07-12 21:22:44 +0000
commita72b0bcd7fd4baed9952beefc6398b3d79c789d9 (patch)
treef2aff187736391b024e6cf6f28e95e5708a2d927 /sys/ddb
parent883bd6a55eef6005b2e79ccc0c939a365bebb656 (diff)
downloadFreeBSD-src-a72b0bcd7fd4baed9952beefc6398b3d79c789d9.zip
FreeBSD-src-a72b0bcd7fd4baed9952beefc6398b3d79c789d9.tar.gz
Simplify the pager support in DDB. Allowing different db commands to
install custom pager functions didn't actually happen in practice (they all just used the simple pager and passed in a local quit pointer). So, just hardcode the simple pager as the only pager and make it set a global db_pager_quit flag that db commands can check when the user hits 'q' (or a suitable variant) at the pager prompt. Also, now that it's easy to do so, enable paging by default for all ddb commands. Any command that wishes to honor the quit flag can do so by checking db_pager_quit. Note that the pager can also be effectively disabled by setting $lines to 0. Other fixes: - 'show idt' on i386 and pc98 now actually checks the quit flag and terminates early. - 'show intr' now actually checks the quit flag and terminates early.
Diffstat (limited to 'sys/ddb')
-rw-r--r--sys/ddb/db_command.c8
-rw-r--r--sys/ddb/db_output.c69
-rw-r--r--sys/ddb/db_output.h2
-rw-r--r--sys/ddb/db_ps.c14
-rw-r--r--sys/ddb/db_thread.c6
-rw-r--r--sys/ddb/ddb.h7
6 files changed, 47 insertions, 59 deletions
diff --git a/sys/ddb/db_command.c b/sys/ddb/db_command.c
index c15edaa..c92d52f 100644
--- a/sys/ddb/db_command.c
+++ b/sys/ddb/db_command.c
@@ -392,8 +392,9 @@ db_command(last_cmdp, cmd_table)
/*
* Execute the command.
*/
+ db_enable_pager();
(*cmd->fcn)(addr, have_addr, count, modif);
- db_setup_paging(NULL, NULL, -1);
+ db_disable_pager();
if (cmd->flag & CS_SET_DOT) {
/*
@@ -675,16 +676,13 @@ db_stack_trace_all(db_expr_t dummy, boolean_t dummy2, db_expr_t dummy3,
{
struct proc *p;
struct thread *td;
- int quit;
- quit = 0;
- db_setup_paging(db_simple_pager, &quit, db_lines_per_page);
LIST_FOREACH(p, &allproc, p_list) {
FOREACH_THREAD_IN_PROC(p, td) {
db_printf("\nTracing command %s pid %d tid %ld td %p\n",
p->p_comm, p->p_pid, (long)td->td_tid, td);
db_trace_thread(td, -1);
- if (quit)
+ if (db_pager_quit)
return;
}
}
diff --git a/sys/ddb/db_output.c b/sys/ddb/db_output.c
index fccae29..e9f0c82 100644
--- a/sys/ddb/db_output.c
+++ b/sys/ddb/db_output.c
@@ -66,15 +66,15 @@ db_expr_t db_tab_stop_width = 8; /* how wide are tab stops? */
((((i) + db_tab_stop_width) / db_tab_stop_width) * db_tab_stop_width)
db_expr_t db_max_width = 79; /* output line width */
db_expr_t db_lines_per_page = 20; /* lines per page */
+volatile int db_pager_quit; /* user requested quit */
static int db_newlines; /* # lines this page */
-static int db_maxlines = -1; /* max lines/page when paging */
-static db_page_calloutfcn_t *db_page_callout = NULL;
-static void *db_page_callout_arg = NULL;
+static int db_maxlines; /* max lines/page when paging */
static int ddb_use_printf = 0;
SYSCTL_INT(_debug, OID_AUTO, ddb_use_printf, CTLFLAG_RW, &ddb_use_printf, 0,
"use printf for all ddb output");
static void db_putchar(int c, void *arg);
+static void db_pager(void);
/*
* Force pending whitespace.
@@ -120,12 +120,10 @@ db_putchar(c, arg)
return;
if (c == '\r' || c == '\n')
db_check_interrupt();
- if (c == '\n' && db_maxlines > 0 && db_page_callout != NULL) {
+ if (c == '\n' && db_maxlines > 0) {
db_newlines++;
- if (db_newlines >= db_maxlines) {
- db_maxlines = -1;
- db_page_callout(db_page_callout_arg);
- }
+ if (db_newlines >= db_maxlines)
+ db_pager();
}
return;
}
@@ -149,12 +147,10 @@ db_putchar(c, arg)
db_output_position = 0;
db_last_non_space = 0;
db_check_interrupt();
- if (db_maxlines > 0 && db_page_callout != NULL) {
+ if (db_maxlines > 0) {
db_newlines++;
- if (db_newlines >= db_maxlines) {
- db_maxlines = -1;
- db_page_callout(db_page_callout_arg);
- }
+ if (db_newlines >= db_maxlines)
+ db_pager();
}
}
else if (c == '\r') {
@@ -181,27 +177,34 @@ db_putchar(c, arg)
}
/*
- * Register callout for providing a pager for output.
+ * Turn on the pager.
*/
void
-db_setup_paging(db_page_calloutfcn_t *callout, void *arg, int maxlines)
+db_enable_pager(void)
{
-
- if (db_page_callout == NULL || callout == NULL || arg ==
- db_page_callout_arg) {
- db_page_callout = callout;
- db_page_callout_arg = arg;
- db_maxlines = maxlines;
+ if (db_maxlines == 0) {
+ db_maxlines = db_lines_per_page;
db_newlines = 0;
+ db_pager_quit = 0;
}
}
/*
- * A simple paging callout function. If the argument is not null, it
- * points to an integer that will be set to 1 if the user asks to quit.
+ * Turn off the pager.
*/
void
-db_simple_pager(void *arg)
+db_disable_pager(void)
+{
+ db_maxlines = 0;
+}
+
+/*
+ * A simple paging callout function. It supports several simple more(1)-like
+ * commands as well as a quit command that sets db_pager_quit which db
+ * commands can poll to see if they should terminate early.
+ */
+void
+db_pager(void)
{
int c, done;
@@ -214,20 +217,18 @@ db_simple_pager(void *arg)
case 'j':
case '\n':
/* Just one more line. */
- db_setup_paging(db_simple_pager, arg, 1);
+ db_maxlines = 1;
done++;
break;
case 'd':
/* Half a page. */
- db_setup_paging(db_simple_pager, arg,
- db_lines_per_page / 2);
+ db_maxlines = db_lines_per_page / 2;
done++;
break;
case 'f':
case ' ':
/* Another page. */
- db_setup_paging(db_simple_pager, arg,
- db_lines_per_page);
+ db_maxlines = db_lines_per_page;
done++;
break;
case 'q':
@@ -235,11 +236,10 @@ db_simple_pager(void *arg)
case 'x':
case 'X':
/* Quit */
- if (arg != NULL) {
- *(int *)arg = 1;
- done++;
- break;
- }
+ db_maxlines = 0;
+ db_pager_quit = 1;
+ done++;
+ break;
#if 0
/* FALLTHROUGH */
default:
@@ -248,6 +248,7 @@ db_simple_pager(void *arg)
}
}
db_printf(" \r");
+ db_newlines = 0;
}
/*
diff --git a/sys/ddb/db_output.h b/sys/ddb/db_output.h
index 7615ea6..480c40d 100644
--- a/sys/ddb/db_output.h
+++ b/sys/ddb/db_output.h
@@ -38,6 +38,8 @@
* Printing routines for kernel debugger.
*/
+void db_disable_pager(void);
+void db_enable_pager(void);
void db_end_line(void);
void db_force_whitespace(void);
int db_print_position(void);
diff --git a/sys/ddb/db_ps.c b/sys/ddb/db_ps.c
index 39dff4c..f220de0 100644
--- a/sys/ddb/db_ps.c
+++ b/sys/ddb/db_ps.c
@@ -73,23 +73,21 @@ db_ps(db_expr_t addr, boolean_t hasaddr, db_expr_t count, char *modif)
struct ucred *cred;
struct pgrp *pgrp;
char state[9];
- int np, quit, rflag, sflag, dflag, lflag, wflag;
+ int np, rflag, sflag, dflag, lflag, wflag;
np = nprocs;
- quit = 0;
if (!LIST_EMPTY(&allproc))
p = LIST_FIRST(&allproc);
else
p = &proc0;
- db_setup_paging(db_simple_pager, &quit, db_lines_per_page);
#ifdef __LP64__
db_printf(" pid uid ppid pgrp state wmesg wchan cmd\n");
#else
db_printf(" pid uid ppid pgrp state wmesg wchan cmd\n");
#endif
- while (--np >= 0 && !quit) {
+ while (--np >= 0 && !db_pager_quit) {
if (p == NULL) {
db_printf("oops, ran out of processes early!\n");
break;
@@ -191,7 +189,7 @@ db_ps(db_expr_t addr, boolean_t hasaddr, db_expr_t count, char *modif)
#endif
FOREACH_THREAD_IN_PROC(p, td) {
dumpthread(p, td, p->p_flag & P_HADTHREADS);
- if (quit)
+ if (db_pager_quit)
break;
}
@@ -363,7 +361,7 @@ DB_SHOW_COMMAND(proc, db_show_proc)
{
struct thread *td;
struct proc *p;
- int i, quit;
+ int i;
/* Determine which process to examine. */
if (have_addr)
@@ -371,8 +369,6 @@ DB_SHOW_COMMAND(proc, db_show_proc)
else
p = kdb_thread->td_proc;
- quit = 0;
- db_setup_paging(db_simple_pager, &quit, db_lines_per_page);
db_printf("Process %d (%s) at %p:\n", p->p_pid, p->p_comm, p);
db_printf(" state: ");
switch (p->p_state) {
@@ -411,7 +407,7 @@ DB_SHOW_COMMAND(proc, db_show_proc)
db_printf(" threads: %d\n", p->p_numthreads);
FOREACH_THREAD_IN_PROC(p, td) {
dumpthread(p, td, 1);
- if (quit)
+ if (db_pager_quit)
break;
}
}
diff --git a/sys/ddb/db_thread.c b/sys/ddb/db_thread.c
index a946dd8..13c3878 100644
--- a/sys/ddb/db_thread.c
+++ b/sys/ddb/db_thread.c
@@ -93,13 +93,9 @@ db_show_threads(db_expr_t addr, boolean_t hasaddr, db_expr_t cnt, char *mod)
jmp_buf jb;
void *prev_jb;
struct thread *thr;
- int pager_quit;
- db_setup_paging(db_simple_pager, &pager_quit, db_lines_per_page);
-
- pager_quit = 0;
thr = kdb_thr_first();
- while (!pager_quit && thr != NULL) {
+ while (!db_pager_quit && thr != NULL) {
db_printf(" %6ld (%p) ", (long)thr->td_tid, thr);
prev_jb = kdb_jmpbuf(jb);
if (setjmp(jb) == 0) {
diff --git a/sys/ddb/ddb.h b/sys/ddb/ddb.h
index 549e24e..716740b 100644
--- a/sys/ddb/ddb.h
+++ b/sys/ddb/ddb.h
@@ -52,8 +52,6 @@ int DB_CALL(db_expr_t, db_expr_t *, int, db_expr_t[]);
typedef void db_cmdfcn_t(db_expr_t addr, boolean_t have_addr, db_expr_t count,
char *modif);
-typedef void db_page_calloutfcn_t(void *arg);
-
#define DB_COMMAND(cmd_name, func_name) \
DB_FUNC(cmd_name, func_name, db_cmd_set, 0, NULL)
#define DB_SHOW_COMMAND(cmd_name, func_name) \
@@ -85,6 +83,7 @@ extern int db_indent;
extern int db_inst_count;
extern int db_load_count;
extern int db_store_count;
+extern volatile int db_pager_quit;
extern db_expr_t db_radix;
extern db_expr_t db_max_width;
extern db_expr_t db_tab_stop_width;
@@ -118,8 +117,6 @@ int db_readline(char *lstart, int lsize);
void db_restart_at_pc(boolean_t watchpt);
int db_set_variable(db_expr_t value);
void db_set_watchpoints(void);
-void db_setup_paging(db_page_calloutfcn_t *callout, void *arg,
- int maxlines);
void db_skip_to_eol(void);
boolean_t db_stop_at_pc(boolean_t *is_breakpoint);
#define db_strcpy strcpy
@@ -149,8 +146,6 @@ db_cmdfcn_t db_trace_until_matching_cmd;
db_cmdfcn_t db_watchpoint_cmd;
db_cmdfcn_t db_write_cmd;
-db_page_calloutfcn_t db_simple_pager;
-
/*
* Command table.
*/
OpenPOWER on IntegriCloud