From owner-p4-projects@FreeBSD.ORG Wed Jul 9 10:58:18 2003 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 136F837B405; Wed, 9 Jul 2003 10:58:18 -0700 (PDT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AC97437B401 for ; Wed, 9 Jul 2003 10:58:17 -0700 (PDT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id DA52343F93 for ; Wed, 9 Jul 2003 10:58:16 -0700 (PDT) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.6/8.12.6) with ESMTP id h69HwG0U021049 for ; Wed, 9 Jul 2003 10:58:16 -0700 (PDT) (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.6/8.12.6/Submit) id h69HwGAB021046 for perforce@freebsd.org; Wed, 9 Jul 2003 10:58:16 -0700 (PDT) Date: Wed, 9 Jul 2003 10:58:16 -0700 (PDT) Message-Id: <200307091758.h69HwGAB021046@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jhb@freebsd.org using -f From: John Baldwin To: Perforce Change Reviews Subject: PERFORCE change 34250 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Jul 2003 17:58:19 -0000 http://perforce.freebsd.org/chv.cgi?CH=34250 Change 34250 by jhb@jhb_laptop on 2003/07/09 10:58:01 First cut at adding generic pager support into ddb's output routines. Convert 'ps' to use this method. By the way, I think it would be a good idea if ps just showed procs and a separate 'show threads' command showed actual threads. This is how mach does things apparently. Affected files ... .. //depot/projects/smpng/sys/ddb/db_command.c#13 edit .. //depot/projects/smpng/sys/ddb/db_output.c#4 edit .. //depot/projects/smpng/sys/ddb/db_ps.c#21 edit .. //depot/projects/smpng/sys/ddb/ddb.h#8 edit Differences ... ==== //depot/projects/smpng/sys/ddb/db_command.c#13 (text+ko) ==== @@ -343,7 +343,9 @@ /* * Execute the command. */ + db_setup_paging(NULL, NULL, -1); (*cmd->fcn)(addr, have_addr, count, modif); + db_setup_paging(NULL, NULL, -1); if (cmd->flag & CS_SET_DOT) { /* ==== //depot/projects/smpng/sys/ddb/db_output.c#4 (text+ko) ==== @@ -62,6 +62,10 @@ #define NEXT_TAB(i) \ ((((i) + db_tab_stop_width) / db_tab_stop_width) * db_tab_stop_width) db_expr_t db_max_width = 79; /* output line width */ +static int db_newlines = 0; /* # lines this page */ +static int db_maxlines = -1; /* max lines per page */ +static db_page_calloutfcn_t *db_page_callout = NULL; +static void *db_page_callout_arg = NULL; static void db_putchar(int c, void *arg); @@ -98,6 +102,7 @@ int c; /* character to output */ void * arg; { + if (c > ' ' && c <= '~') { /* * Printing character. @@ -115,6 +120,14 @@ db_output_position = 0; db_last_non_space = 0; db_check_interrupt(); + if (db_maxlines > 0 && db_page_callout != NULL) { + db_newlines++; + if (db_newlines >= db_maxlines) { + db_maxlines = -1; + db_page_callout(db_page_callout_arg); + db_newlines = 0; + } + } } else if (c == '\r') { /* Return */ @@ -139,6 +152,56 @@ } /* + * Register callout for providing a pager for output. + */ +void +db_setup_paging(db_page_calloutfcn_t *callout, void *arg, int maxlines) +{ + + db_page_callout = callout; + db_page_callout_arg = arg; + db_maxlines = maxlines; +} + +/* + * 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. + */ +void +db_simple_pager(void *arg) +{ + int c; + + db_printf("--More--\r"); + for (;;) { + c = cngetc(); + switch (c) { + case '\n': + /* Just one more line. */ + db_setup_paging(db_simple_pager, arg, 1); + return; + case ' ': + /* Another page. */ + db_setup_paging(db_simple_pager, arg, + DB_LINES_PER_PAGE); + return; + case 'q': + case 'Q': + case 'x': + case 'X': + /* Quit */ + if (arg != NULL) { + *(int *)arg = 1; + return; + } + /* FALLTHROUGH */ + default: + cnputc('\007'); + } + } +} + +/* * Return output position */ int ==== //depot/projects/smpng/sys/ddb/db_ps.c#21 (text+ko) ==== @@ -55,13 +55,13 @@ db_expr_t dummy3; char * dummy4; { - int np; - int nl = 0; volatile struct proc *p, *pp; volatile struct thread *td; char *state; + int np, quit; np = nprocs; + quit = 0; /* sx_slock(&allproc_lock); */ if (!LIST_EMPTY(&allproc)) @@ -69,32 +69,9 @@ else p = &proc0; + db_setup_paging(db_simple_pager, &quit, DB_LINES_PER_PAGE); db_printf(" pid proc addr uid ppid pgrp flag stat wmesg wchan cmd\n"); - while (--np >= 0) { - /* - * XXX just take 20 for now... - */ - if (nl++ >= 20) { - int c; - - db_printf("--More--"); - c = cngetc(); - db_printf("\r"); - /* - * A whole screenfull or just one line? - */ - switch (c) { - case '\n': /* just one line */ - nl = 20; - break; - case ' ': - nl = 0; /* another screenfull */ - break; - default: /* exit */ - db_printf("\n"); - return; - } - } + while (--np >= 0 && !quit) { if (p == NULL) { printf("oops, ran out of processes early!\n"); break; @@ -131,7 +108,8 @@ db_printf("(threaded) %s\n", p->p_comm); FOREACH_THREAD_IN_PROC(p, td) { dumpthread(p, td); - nl++; + if (quit) + break; } /* PROC_UNLOCK(p); */ @@ -145,6 +123,7 @@ static void dumpthread(volatile struct proc *p, volatile struct thread *td) { + if (p->p_flag & P_SA) db_printf( " thread %p ksegrp %p ", td, td->td_ksegrp); if (TD_ON_SLEEPQ(td)) { ==== //depot/projects/smpng/sys/ddb/ddb.h#8 (text+ko) ==== @@ -39,9 +39,13 @@ #include /* type definitions */ +#define DB_LINES_PER_PAGE 20 + 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_SET(cmd_name, func_name, db_cmd_set, 0, NULL) #define DB_SHOW_COMMAND(cmd_name, func_name) \ @@ -100,6 +104,8 @@ int db_readline(char *lstart, int lsize); void db_restart_at_pc(boolean_t watchpt); 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 @@ -139,6 +145,8 @@ db_cmdfcn_t vm_page_print; #endif +db_page_calloutfcn_t db_simple_pager; + /* Scare the user with backtrace of curthread to console. */ void db_print_backtrace(void);