db_output.c (150842) | db_output.c (160312) |
---|---|
1/*- 2 * Mach Operating System 3 * Copyright (c) 1991,1990 Carnegie Mellon University 4 * All Rights Reserved. 5 * 6 * Permission to use, copy, modify and distribute this software and its 7 * documentation is hereby granted, provided that both the copyright 8 * notice and this permission notice appear in all copies of the --- 19 unchanged lines hidden (view full) --- 28 * Date: 7/90 29 */ 30 31/* 32 * Printf and character output for debugger. 33 */ 34 35#include <sys/cdefs.h> | 1/*- 2 * Mach Operating System 3 * Copyright (c) 1991,1990 Carnegie Mellon University 4 * All Rights Reserved. 5 * 6 * Permission to use, copy, modify and distribute this software and its 7 * documentation is hereby granted, provided that both the copyright 8 * notice and this permission notice appear in all copies of the --- 19 unchanged lines hidden (view full) --- 28 * Date: 7/90 29 */ 30 31/* 32 * Printf and character output for debugger. 33 */ 34 35#include <sys/cdefs.h> |
36__FBSDID("$FreeBSD: head/sys/ddb/db_output.c 150842 2005-10-02 22:57:31Z cognet $"); | 36__FBSDID("$FreeBSD: head/sys/ddb/db_output.c 160312 2006-07-12 21:22:44Z jhb $"); |
37 38#include <sys/param.h> 39#include <sys/systm.h> 40#include <sys/cons.h> 41#include <sys/kdb.h> 42#include <sys/kernel.h> 43#include <sys/sysctl.h> 44 --- 16 unchanged lines hidden (view full) --- 61 */ 62static int db_output_position = 0; /* output column */ 63static int db_last_non_space = 0; /* last non-space character */ 64db_expr_t db_tab_stop_width = 8; /* how wide are tab stops? */ 65#define NEXT_TAB(i) \ 66 ((((i) + db_tab_stop_width) / db_tab_stop_width) * db_tab_stop_width) 67db_expr_t db_max_width = 79; /* output line width */ 68db_expr_t db_lines_per_page = 20; /* lines per page */ | 37 38#include <sys/param.h> 39#include <sys/systm.h> 40#include <sys/cons.h> 41#include <sys/kdb.h> 42#include <sys/kernel.h> 43#include <sys/sysctl.h> 44 --- 16 unchanged lines hidden (view full) --- 61 */ 62static int db_output_position = 0; /* output column */ 63static int db_last_non_space = 0; /* last non-space character */ 64db_expr_t db_tab_stop_width = 8; /* how wide are tab stops? */ 65#define NEXT_TAB(i) \ 66 ((((i) + db_tab_stop_width) / db_tab_stop_width) * db_tab_stop_width) 67db_expr_t db_max_width = 79; /* output line width */ 68db_expr_t db_lines_per_page = 20; /* lines per page */ |
69volatile int db_pager_quit; /* user requested quit */ |
|
69static int db_newlines; /* # lines this page */ | 70static int db_newlines; /* # lines this page */ |
70static int db_maxlines = -1; /* max lines/page when paging */ 71static db_page_calloutfcn_t *db_page_callout = NULL; 72static void *db_page_callout_arg = NULL; | 71static int db_maxlines; /* max lines/page when paging */ |
73static int ddb_use_printf = 0; 74SYSCTL_INT(_debug, OID_AUTO, ddb_use_printf, CTLFLAG_RW, &ddb_use_printf, 0, 75 "use printf for all ddb output"); 76 77static void db_putchar(int c, void *arg); | 72static int ddb_use_printf = 0; 73SYSCTL_INT(_debug, OID_AUTO, ddb_use_printf, CTLFLAG_RW, &ddb_use_printf, 0, 74 "use printf for all ddb output"); 75 76static void db_putchar(int c, void *arg); |
77static void db_pager(void); |
|
78 79/* 80 * Force pending whitespace. 81 */ 82void 83db_force_whitespace() 84{ 85 register int last_print, next_tab; --- 29 unchanged lines hidden (view full) --- 115 * both the console and the message buffer. 116 */ 117 if (!kdb_active || ddb_use_printf) { 118 printf("%c", c); 119 if (!kdb_active) 120 return; 121 if (c == '\r' || c == '\n') 122 db_check_interrupt(); | 78 79/* 80 * Force pending whitespace. 81 */ 82void 83db_force_whitespace() 84{ 85 register int last_print, next_tab; --- 29 unchanged lines hidden (view full) --- 115 * both the console and the message buffer. 116 */ 117 if (!kdb_active || ddb_use_printf) { 118 printf("%c", c); 119 if (!kdb_active) 120 return; 121 if (c == '\r' || c == '\n') 122 db_check_interrupt(); |
123 if (c == '\n' && db_maxlines > 0 && db_page_callout != NULL) { | 123 if (c == '\n' && db_maxlines > 0) { |
124 db_newlines++; | 124 db_newlines++; |
125 if (db_newlines >= db_maxlines) { 126 db_maxlines = -1; 127 db_page_callout(db_page_callout_arg); 128 } | 125 if (db_newlines >= db_maxlines) 126 db_pager(); |
129 } 130 return; 131 } 132 133 /* Otherwise, output data directly to the console. */ 134 if (c > ' ' && c <= '~') { 135 /* 136 * Printing character. --- 7 unchanged lines hidden (view full) --- 144 } 145 else if (c == '\n') { 146 /* Newline */ 147 db_force_whitespace(); 148 cnputc(c); 149 db_output_position = 0; 150 db_last_non_space = 0; 151 db_check_interrupt(); | 127 } 128 return; 129 } 130 131 /* Otherwise, output data directly to the console. */ 132 if (c > ' ' && c <= '~') { 133 /* 134 * Printing character. --- 7 unchanged lines hidden (view full) --- 142 } 143 else if (c == '\n') { 144 /* Newline */ 145 db_force_whitespace(); 146 cnputc(c); 147 db_output_position = 0; 148 db_last_non_space = 0; 149 db_check_interrupt(); |
152 if (db_maxlines > 0 && db_page_callout != NULL) { | 150 if (db_maxlines > 0) { |
153 db_newlines++; | 151 db_newlines++; |
154 if (db_newlines >= db_maxlines) { 155 db_maxlines = -1; 156 db_page_callout(db_page_callout_arg); 157 } | 152 if (db_newlines >= db_maxlines) 153 db_pager(); |
158 } 159 } 160 else if (c == '\r') { 161 /* Return */ 162 db_force_whitespace(); 163 cnputc(c); 164 db_output_position = 0; 165 db_last_non_space = 0; --- 10 unchanged lines hidden (view full) --- 176 else if (c == '\007') { 177 /* bell */ 178 cnputc(c); 179 } 180 /* other characters are assumed non-printing */ 181} 182 183/* | 154 } 155 } 156 else if (c == '\r') { 157 /* Return */ 158 db_force_whitespace(); 159 cnputc(c); 160 db_output_position = 0; 161 db_last_non_space = 0; --- 10 unchanged lines hidden (view full) --- 172 else if (c == '\007') { 173 /* bell */ 174 cnputc(c); 175 } 176 /* other characters are assumed non-printing */ 177} 178 179/* |
184 * Register callout for providing a pager for output. | 180 * Turn on the pager. |
185 */ 186void | 181 */ 182void |
187db_setup_paging(db_page_calloutfcn_t *callout, void *arg, int maxlines) | 183db_enable_pager(void) |
188{ | 184{ |
189 190 if (db_page_callout == NULL || callout == NULL || arg == 191 db_page_callout_arg) { 192 db_page_callout = callout; 193 db_page_callout_arg = arg; 194 db_maxlines = maxlines; | 185 if (db_maxlines == 0) { 186 db_maxlines = db_lines_per_page; |
195 db_newlines = 0; | 187 db_newlines = 0; |
188 db_pager_quit = 0; |
|
196 } 197} 198 199/* | 189 } 190} 191 192/* |
200 * A simple paging callout function. If the argument is not null, it 201 * points to an integer that will be set to 1 if the user asks to quit. | 193 * Turn off the pager. |
202 */ 203void | 194 */ 195void |
204db_simple_pager(void *arg) | 196db_disable_pager(void) |
205{ | 197{ |
198 db_maxlines = 0; 199} 200 201/* 202 * A simple paging callout function. It supports several simple more(1)-like 203 * commands as well as a quit command that sets db_pager_quit which db 204 * commands can poll to see if they should terminate early. 205 */ 206void 207db_pager(void) 208{ |
|
206 int c, done; 207 208 db_printf("--More--\r"); 209 done = 0; 210 while (!done) { 211 c = cngetc(); 212 switch (c) { 213 case 'e': 214 case 'j': 215 case '\n': 216 /* Just one more line. */ | 209 int c, done; 210 211 db_printf("--More--\r"); 212 done = 0; 213 while (!done) { 214 c = cngetc(); 215 switch (c) { 216 case 'e': 217 case 'j': 218 case '\n': 219 /* Just one more line. */ |
217 db_setup_paging(db_simple_pager, arg, 1); | 220 db_maxlines = 1; |
218 done++; 219 break; 220 case 'd': 221 /* Half a page. */ | 221 done++; 222 break; 223 case 'd': 224 /* Half a page. */ |
222 db_setup_paging(db_simple_pager, arg, 223 db_lines_per_page / 2); | 225 db_maxlines = db_lines_per_page / 2; |
224 done++; 225 break; 226 case 'f': 227 case ' ': 228 /* Another page. */ | 226 done++; 227 break; 228 case 'f': 229 case ' ': 230 /* Another page. */ |
229 db_setup_paging(db_simple_pager, arg, 230 db_lines_per_page); | 231 db_maxlines = db_lines_per_page; |
231 done++; 232 break; 233 case 'q': 234 case 'Q': 235 case 'x': 236 case 'X': 237 /* Quit */ | 232 done++; 233 break; 234 case 'q': 235 case 'Q': 236 case 'x': 237 case 'X': 238 /* Quit */ |
238 if (arg != NULL) { 239 *(int *)arg = 1; 240 done++; 241 break; 242 } | 239 db_maxlines = 0; 240 db_pager_quit = 1; 241 done++; 242 break; |
243#if 0 244 /* FALLTHROUGH */ 245 default: 246 cnputc('\007'); 247#endif 248 } 249 } 250 db_printf(" \r"); | 243#if 0 244 /* FALLTHROUGH */ 245 default: 246 cnputc('\007'); 247#endif 248 } 249 } 250 db_printf(" \r"); |
251 db_newlines = 0; |
|
251} 252 253/* 254 * Return output position 255 */ 256int 257db_print_position() 258{ --- 52 unchanged lines hidden --- | 252} 253 254/* 255 * Return output position 256 */ 257int 258db_print_position() 259{ --- 52 unchanged lines hidden --- |