Date: Wed, 12 Jul 2006 12:34:22 GMT From: John Baldwin <jhb@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 101364 for review Message-ID: <200607121234.k6CCYMrj025558@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=101364 Change 101364 by jhb@jhb_mutex on 2006/07/12 12:33:40 Simplify the pager stuff in ddb. Everyone who uses paging just uses db_simple_pager(). So, just make that the only pager and instead of setting a quit variable that each db command has to register, add a global variable db_pager_quit that db commands can query to see if the user has requested a quit. Now always enable paging for all ddb commands (though it is up to individual commands to honor db_pager_quit). To try to facilitate quick exit for commands that don't check db_pager_quit, turn off paging for the rest of the current command once a quit has been requested. Affected files ... .. //depot/projects/smpng/sys/ddb/db_command.c#29 edit .. //depot/projects/smpng/sys/ddb/db_output.c#17 edit .. //depot/projects/smpng/sys/ddb/db_output.h#4 edit .. //depot/projects/smpng/sys/ddb/ddb.h#22 edit Differences ... ==== //depot/projects/smpng/sys/ddb/db_command.c#29 (text+ko) ==== @@ -392,8 +392,9 @@ /* * 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) { /* ==== //depot/projects/smpng/sys/ddb/db_output.c#17 (text+ko) ==== @@ -66,15 +66,15 @@ ((((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 @@ 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_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 @@ } /* - * 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_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_simple_pager(void *arg) +db_pager(void) { int c, done; @@ -214,20 +217,18 @@ 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 @@ 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: ==== //depot/projects/smpng/sys/ddb/db_output.h#4 (text+ko) ==== @@ -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); ==== //depot/projects/smpng/sys/ddb/ddb.h#22 (text+ko) ==== @@ -52,8 +52,6 @@ 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_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 @@ 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_watchpoint_cmd; db_cmdfcn_t db_write_cmd; -db_page_calloutfcn_t db_simple_pager; - /* * Command table. */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200607121234.k6CCYMrj025558>