View | Details | Raw Unified | Return to bug 127265
Collapse All | Expand All

(-)./ddb/db_command.c (-90 / +132 lines)
Lines 45-50 Link Here
45
#include <sys/systm.h>
45
#include <sys/systm.h>
46
#include <sys/cons.h>
46
#include <sys/cons.h>
47
#include <sys/watchdog.h>
47
#include <sys/watchdog.h>
48
#include <sys/kernel.h>
48
49
49
#include <ddb/ddb.h>
50
#include <ddb/ddb.h>
50
#include <ddb/db_command.h>
51
#include <ddb/db_command.h>
Lines 76-153 Link Here
76
static db_cmdfcn_t	db_watchdog;
77
static db_cmdfcn_t	db_watchdog;
77
78
78
/*
79
/*
80
 * Array containing all command 'tables'. See ddb.h.
81
 */
82
static struct command_table db_command_tables[DB_COMMAND_TABLES_SIZE] = {
83
	STAILQ_HEAD_INITIALIZER(db_command_tables[DB_COMMAND_TABLES_DEFAULT]),
84
	STAILQ_HEAD_INITIALIZER(db_command_tables[DB_COMMAND_TABLES_SHOW]),
85
	STAILQ_HEAD_INITIALIZER(db_command_tables[DB_COMMAND_TABLES_SHOW_ALL])
86
};
87
88
/*
79
 * 'show' commands
89
 * 'show' commands
80
 */
90
 */
81
91
82
static struct command db_show_all_cmds[] = {
92
static struct command db_show_all_cmds[] = {
83
	{ "procs",	db_ps,			0,	0 },
93
	{ { NULL }, "procs",	db_ps,			0,	0 }
84
	{ (char *)0 }
85
};
86
87
static struct command_table db_show_all_table = {
88
	db_show_all_cmds
89
};
94
};
90
95
91
static struct command db_show_cmds[] = {
96
static struct command db_show_cmds[] = {
92
	{ "all",	0,			0,	&db_show_all_table },
97
	{ { NULL }, "all",	0,			0,	&db_command_tables[DB_COMMAND_TABLES_SHOW_ALL] },
93
	{ "registers",	db_show_regs,		0,	0 },
98
	{ { NULL }, "registers",	db_show_regs,		0,	0 },
94
	{ "breaks",	db_listbreak_cmd, 	0,	0 },
99
	{ { NULL }, "breaks",	db_listbreak_cmd, 	0,	0 },
95
	{ "threads",	db_show_threads,	0,	0 },
100
	{ { NULL }, "threads",	db_show_threads,	0,	0 }
96
	{ (char *)0, }
97
};
101
};
98
102
99
static struct command_table db_show_table = {
100
	db_show_cmds,
101
	SET_BEGIN(db_show_cmd_set),
102
	SET_LIMIT(db_show_cmd_set)
103
};
104
	
105
static struct command db_commands[] = {
103
static struct command db_commands[] = {
106
	{ "print",	db_print_cmd,		0,	0 },
104
	{ { NULL }, "print",	db_print_cmd,		0,	0 },
107
	{ "p",		db_print_cmd,		0,	0 },
105
	{ { NULL }, "p",		db_print_cmd,		0,	0 },
108
	{ "examine",	db_examine_cmd,		CS_SET_DOT, 0 },
106
	{ { NULL }, "examine",	db_examine_cmd,		CS_SET_DOT, 0 },
109
	{ "x",		db_examine_cmd,		CS_SET_DOT, 0 },
107
	{ { NULL }, "x",		db_examine_cmd,		CS_SET_DOT, 0 },
110
	{ "search",	db_search_cmd,		CS_OWN|CS_SET_DOT, 0 },
108
	{ { NULL }, "search",	db_search_cmd,		CS_OWN|CS_SET_DOT, 0 },
111
	{ "set",	db_set_cmd,		CS_OWN,	0 },
109
	{ { NULL }, "set",		db_set_cmd,		CS_OWN,	0 },
112
	{ "write",	db_write_cmd,		CS_MORE|CS_SET_DOT, 0 },
110
	{ { NULL }, "write",	db_write_cmd,		CS_MORE|CS_SET_DOT, 0 },
113
	{ "w",		db_write_cmd,		CS_MORE|CS_SET_DOT, 0 },
111
	{ { NULL }, "w",		db_write_cmd,		CS_MORE|CS_SET_DOT, 0 },
114
	{ "delete",	db_delete_cmd,		0,	0 },
112
	{ { NULL }, "delete",	db_delete_cmd,		0,	0 },
115
	{ "d",		db_delete_cmd,		0,	0 },
113
	{ { NULL }, "d",		db_delete_cmd,		0,	0 },
116
	{ "break",	db_breakpoint_cmd,	0,	0 },
114
	{ { NULL }, "break",	db_breakpoint_cmd,	0,	0 },
117
	{ "b",		db_breakpoint_cmd,	0,	0 },
115
	{ { NULL }, "b",		db_breakpoint_cmd,	0,	0 },
118
	{ "dwatch",	db_deletewatch_cmd,	0,	0 },
116
	{ { NULL }, "dwatch",	db_deletewatch_cmd,	0,	0 },
119
	{ "watch",	db_watchpoint_cmd,	CS_MORE,0 },
117
	{ { NULL }, "watch",	db_watchpoint_cmd,	CS_MORE,0 },
120
	{ "dhwatch",	db_deletehwatch_cmd,	0,      0 },
118
	{ { NULL }, "dhwatch",	db_deletehwatch_cmd,	0,      0 },
121
	{ "hwatch",	db_hwatchpoint_cmd,	0,      0 },
119
	{ { NULL }, "hwatch",	db_hwatchpoint_cmd,	0,      0 },
122
	{ "step",	db_single_step_cmd,	0,	0 },
120
	{ { NULL }, "step",	db_single_step_cmd,	0,	0 },
123
	{ "s",		db_single_step_cmd,	0,	0 },
121
	{ { NULL }, "s",		db_single_step_cmd,	0,	0 },
124
	{ "continue",	db_continue_cmd,	0,	0 },
122
	{ { NULL }, "continue",	db_continue_cmd,	0,	0 },
125
	{ "c",		db_continue_cmd,	0,	0 },
123
	{ { NULL }, "c",		db_continue_cmd,	0,	0 },
126
	{ "until",	db_trace_until_call_cmd,0,	0 },
124
	{ { NULL }, "until",	db_trace_until_call_cmd,0,	0 },
127
	{ "next",	db_trace_until_matching_cmd,0,	0 },
125
	{ { NULL }, "next",	db_trace_until_matching_cmd,0,	0 },
128
	{ "match",	db_trace_until_matching_cmd,0,	0 },
126
	{ { NULL }, "match",	db_trace_until_matching_cmd,0,	0 },
129
	{ "trace",	db_stack_trace,		CS_OWN,	0 },
127
	{ { NULL }, "trace",	db_stack_trace,		CS_OWN,	0 },
130
	{ "t",		db_stack_trace,		CS_OWN,	0 },
128
	{ { NULL }, "t",		db_stack_trace,		CS_OWN,	0 },
131
	{ "alltrace",	db_stack_trace_all,	0,	0 },
129
	{ { NULL }, "alltrace",	db_stack_trace_all,	0,	0 },
132
	{ "where",	db_stack_trace,		CS_OWN,	0 },
130
	{ { NULL }, "where",	db_stack_trace,		CS_OWN,	0 },
133
	{ "bt",		db_stack_trace,		CS_OWN,	0 },
131
	{ { NULL }, "bt",		db_stack_trace,		CS_OWN,	0 },
134
	{ "call",	db_fncall,		CS_OWN,	0 },
132
	{ { NULL }, "call",	db_fncall,		CS_OWN,	0 },
135
	{ "show",	0,			0,	&db_show_table },
133
	{ { NULL }, "show",	0,			0,	&db_command_tables[DB_COMMAND_TABLES_SHOW] },
136
	{ "ps",		db_ps,			0,	0 },
134
	{ { NULL }, "ps",		db_ps,			0,	0 },
137
	{ "gdb",	db_gdb,			0,	0 },
135
	{ { NULL }, "gdb",	db_gdb,			0,	0 },
138
	{ "halt",	db_halt,		0,	0 },
136
	{ { NULL }, "halt",	db_halt,		0,	0 },
139
	{ "reboot",	db_reset,		0,	0 },
137
	{ { NULL }, "reboot",	db_reset,		0,	0 },
140
	{ "reset",	db_reset,		0,	0 },
138
	{ { NULL }, "reset",	db_reset,		0,	0 },
141
	{ "kill",	db_kill,		CS_OWN,	0 },
139
	{ { NULL }, "kill",	db_kill,		CS_OWN,	0 },
142
	{ "watchdog",	db_watchdog,		0,	0 },
140
	{ { NULL }, "watchdog",	db_watchdog,		0,	0 },
143
	{ "thread",	db_set_thread,		CS_OWN,	0 },
141
	{ { NULL }, "thread",	db_set_thread,		CS_OWN,	0 }
144
	{ (char *)0, }
145
};
146
147
static struct command_table db_command_table = {
148
	db_commands,
149
	SET_BEGIN(db_cmd_set),
150
	SET_LIMIT(db_cmd_set)
151
};
142
};
152
143
153
static struct command	*db_last_command = 0;
144
static struct command	*db_last_command = 0;
Lines 189-194 Link Here
189
		    struct command_table *cmd_table);
180
		    struct command_table *cmd_table);
190
181
191
/*
182
/*
183
 * Initialize command tables using the commands declared above.
184
 */
185
void
186
db_cmd_init()
187
{
188
	int	cnt;
189
190
	for (cnt=0; cnt<(sizeof(db_commands) / sizeof(struct command)); cnt++)
191
		STAILQ_INSERT_TAIL(&db_command_tables[DB_COMMAND_TABLES_DEFAULT],
192
			&(db_commands[cnt]),
193
			next);
194
	for (cnt=0; cnt<(sizeof(db_show_cmds) / sizeof(struct command)); cnt++)
195
		STAILQ_INSERT_TAIL(&db_command_tables[DB_COMMAND_TABLES_SHOW],
196
			&(db_show_cmds[cnt]),
197
			next);
198
	for (cnt=0; cnt<(sizeof(db_show_all_cmds) / sizeof(struct command)); cnt++)
199
		STAILQ_INSERT_TAIL(&db_command_tables[DB_COMMAND_TABLES_SHOW_ALL],
200
			&(db_show_all_cmds[cnt]),
201
			next);
202
}
203
204
/*
205
 * Called by modules through SYSINIT to extend the command set.
206
 */
207
void db_command_register(list_index, cmd)
208
	int		list_index;
209
	struct command	*cmd;
210
{
211
	if (list_index >= DB_COMMAND_TABLES_SIZE)
212
		panic("Attempting to add a debugger command to an invalid list!");
213
214
#if 0
215
	/* Check that the command is not already present. */
216
	struct command	*scmd;
217
	STAILQ_FOREACH(scmd, &(db_command_tables[list_index]), next) {
218
		if (!strcmp(cmd->name, scmd->name))
219
			panic("The command %s already exists!", cmd->name);
220
	}
221
#endif
222
223
	if (cmd != NULL) {
224
		STAILQ_INSERT_TAIL(&(db_command_tables[list_index]),
225
				cmd, next);
226
	}
227
}
228
229
/*
230
 * Called by SYSUNINIT. Revert what has been done above.
231
 */
232
void db_command_unregister(table_index, command_name)
233
	int	table_index;
234
	char	*command_name;
235
{
236
	struct command	*cmd;
237
238
	STAILQ_FOREACH(cmd, &(db_command_tables[table_index]), next) {
239
		if (!strcmp(command_name,cmd->name)) {
240
			STAILQ_REMOVE(&(db_command_tables[table_index]),
241
					cmd,
242
					command,
243
					next);
244
			break;
245
		}
246
	}
247
}
248
249
/*
192
 * Helper function to match a single command.
250
 * Helper function to match a single command.
193
 */
251
 */
194
static void
252
static void
Lines 236-258 Link Here
236
	struct command_table *table;
294
	struct command_table *table;
237
	struct command	**cmdp;	/* out */
295
	struct command	**cmdp;	/* out */
238
{
296
{
239
	struct command	*cmd;
297
	struct command		*cmd;
240
	struct command	**aux_cmdp;
298
	int			result = CMD_NONE;
241
	int		result = CMD_NONE;
242
299
243
	for (cmd = table->table; cmd->name != 0; cmd++) {
300
	STAILQ_FOREACH(cmd,table,next) {
244
		db_cmd_match(name, cmd, cmdp, &result);
301
		db_cmd_match(name,cmd,cmdp,&result);
245
		if (result == CMD_UNIQUE)
302
		if (result == CMD_UNIQUE)
246
			return (CMD_UNIQUE);
303
			break;
247
	}
304
	}
248
	if (table->aux_tablep != NULL)
305
249
		for (aux_cmdp = table->aux_tablep;
250
		     aux_cmdp < table->aux_tablep_end;
251
		     aux_cmdp++) {
252
			db_cmd_match(name, *aux_cmdp, cmdp, &result);
253
			if (result == CMD_UNIQUE)
254
				return (CMD_UNIQUE);
255
		}
256
	if (result == CMD_NONE) {
306
	if (result == CMD_NONE) {
257
		/* check for 'help' */
307
		/* check for 'help' */
258
		if (name[0] == 'h' && name[1] == 'e'
308
		if (name[0] == 'h' && name[1] == 'e'
Lines 266-284 Link Here
266
db_cmd_list(table)
316
db_cmd_list(table)
267
	struct command_table *table;
317
	struct command_table *table;
268
{
318
{
269
	register struct command *cmd;
319
	register struct command 	*cmd;
270
	register struct command **aux_cmdp;
271
320
272
	for (cmd = table->table; cmd->name != 0; cmd++) {
321
	STAILQ_FOREACH(cmd, table, next) {
273
	    db_printf("%-12s", cmd->name);
322
		db_printf("%-12s", cmd->name);
274
	    db_end_line(12);
323
		db_end_line(12);
275
	}
276
	if (table->aux_tablep == NULL)
277
	    return;
278
	for (aux_cmdp = table->aux_tablep; aux_cmdp < table->aux_tablep_end;
279
	     aux_cmdp++) {
280
	    db_printf("%-12s", (*aux_cmdp)->name);
281
	    db_end_line(12);
282
	}
324
	}
283
}
325
}
284
326
Lines 287-293 Link Here
287
	struct command	**last_cmdp;	/* IN_OUT */
329
	struct command	**last_cmdp;	/* IN_OUT */
288
	struct command_table *cmd_table;
330
	struct command_table *cmd_table;
289
{
331
{
290
	struct command	*cmd;
332
	struct command	*cmd = NULL;
291
	int		t;
333
	int		t;
292
	char		modif[TOK_STRING_SIZE];
334
	char		modif[TOK_STRING_SIZE];
293
	db_expr_t	addr, count;
335
	db_expr_t	addr, count;
Lines 450-456 Link Here
450
	    db_printf("db> ");
492
	    db_printf("db> ");
451
	    (void) db_read_line();
493
	    (void) db_read_line();
452
494
453
	    db_command(&db_last_command, &db_command_table);
495
	    db_command(&db_last_command, &(db_command_tables[DB_COMMAND_TABLES_DEFAULT]));
454
	}
496
	}
455
}
497
}
456
498
(-)./ddb/ddb.h (-21 / +71 lines)
Lines 39-44 Link Here
39
39
40
#include <machine/db_machdep.h>		/* type definitions */
40
#include <machine/db_machdep.h>		/* type definitions */
41
41
42
#include <sys/queue.h>			/* STAILQ_* */
43
#include <sys/kernel.h>			/* SYSINIT */
44
42
#ifndef DB_MAXARGS
45
#ifndef DB_MAXARGS
43
#define	DB_MAXARGS	10
46
#define	DB_MAXARGS	10
44
#endif
47
#endif
Lines 53-75 Link Here
53
	    char *modif);
56
	    char *modif);
54
57
55
#define DB_COMMAND(cmd_name, func_name) \
58
#define DB_COMMAND(cmd_name, func_name) \
56
	DB_FUNC(cmd_name, func_name, db_cmd_set, 0, NULL)
59
	DB_FUNC(cmd_name, func_name, DB_COMMAND_TABLES_DEFAULT, 0, NULL)
57
#define DB_SHOW_COMMAND(cmd_name, func_name) \
60
#define DB_SHOW_COMMAND(cmd_name, func_name) \
58
	DB_FUNC(cmd_name, func_name, db_show_cmd_set, 0, NULL)
61
	DB_FUNC(cmd_name, func_name, DB_COMMAND_TABLES_SHOW, 0, NULL)
62
#define DB_SHOW_ALL_COMMAND(cmd_name, func_name) \
63
	DB_FUNC(cmd_name, func_name, DB_COMMAND_TABLES_SHOW_ALL, 0, NULL)
59
64
60
#define	DB_SET(cmd_name, func_name, set, flag, more)		\
65
/*
61
static const struct command __CONCAT(cmd_name,_cmd) = {		\
66
 * At the moment, there are three command "tables" on the system:
62
	__STRING(cmd_name),					\
67
 * - One for simple commands, whose list one can get by typing 'help'
63
	func_name,						\
68
 *   at debugger prompt.
64
	flag,							\
69
 * - One for sub-commands of 'show'.
65
	more							\
70
 * - The last one for sub-commands of 'show all'.
66
};								\
71
 * All these tables are stored in an array, and the constants defined
67
TEXT_SET(set, __CONCAT(cmd_name,_cmd))
72
 * hereafter give the offset in the array at which the head for each
73
 * table can be found.
74
 */
75
enum {
76
	DB_COMMAND_TABLES_DEFAULT,
77
	DB_COMMAND_TABLES_SHOW,
78
	DB_COMMAND_TABLES_SHOW_ALL,
79
	DB_COMMAND_TABLES_SIZE
80
};
81
82
struct command;
68
83
69
#define DB_FUNC(cmd_name, func_name, set, flag, more)		\
84
/* 
85
 * Declare the function func_name, which is handling db command 
86
 * cmd_name)
87
 */
88
#define DB_FUNC(cmd_name, func_name, list, flag, more)		\
70
static db_cmdfcn_t	func_name;				\
89
static db_cmdfcn_t	func_name;				\
71
								\
90
DB_SET(cmd_name, func_name, list, flag, more);			\
72
DB_SET(cmd_name, func_name, set, flag, more);			\
73
								\
91
								\
74
static void							\
92
static void							\
75
func_name(addr, have_addr, count, modif)			\
93
func_name(addr, have_addr, count, modif)			\
Lines 78-83 Link Here
78
	db_expr_t count;					\
96
	db_expr_t count;					\
79
	char *modif;
97
	char *modif;
80
98
99
/*
100
 * Add command 'cmd_name' to the command table, along
101
 * with the SYSINIT functions to load and unload it.
102
 */
103
#define DB_SET(cmd_name, func_name, list, flag, more)		\
104
static struct command __CONCAT(cmd_name,_cmd) = {		\
105
	{ NULL },						\
106
	__STRING(cmd_name),					\
107
	func_name,						\
108
	flag,							\
109
	more							\
110
};								\
111
								\
112
static void __CONCAT(cmd_name,_db_cmd_add)(void*);		\
113
static void __CONCAT(cmd_name,_db_cmd_rm)(void*);		\
114
								\
115
static void __CONCAT(cmd_name,_db_cmd_add)(void *arg __unused)	\
116
{								\
117
	db_command_register(list, &__CONCAT(cmd_name,_cmd));	\
118
}								\
119
								\
120
static void __CONCAT(cmd_name,_db_cmd_rm)(void *arg __unused)	\
121
{								\
122
	db_command_unregister(list,__STRING(cmd_name));		\
123
}								\
124
								\
125
SYSINIT(cmd_name, SI_SUB_KLD, SI_ORDER_ANY, __CONCAT(cmd_name,_db_cmd_add), NULL);	\
126
SYSUNINIT(cmd_name, SI_SUB_KLD, SI_ORDER_ANY, __CONCAT(cmd_name,_db_cmd_rm), NULL);
127
81
extern db_expr_t db_maxoff;
128
extern db_expr_t db_maxoff;
82
extern int db_indent;
129
extern int db_indent;
83
extern int db_inst_count;
130
extern int db_inst_count;
Lines 124-129 Link Here
124
int		db_trace_thread(struct thread *, int);
171
int		db_trace_thread(struct thread *, int);
125
int		db_value_of_name(const char *name, db_expr_t *valuep);
172
int		db_value_of_name(const char *name, db_expr_t *valuep);
126
int		db_write_bytes(vm_offset_t addr, size_t size, char *data);
173
int		db_write_bytes(vm_offset_t addr, size_t size, char *data);
174
void		db_cmd_init(void);
175
void		db_command_register(int, struct command *);
176
void		db_command_unregister(int, char *);
127
177
128
db_cmdfcn_t	db_breakpoint_cmd;
178
db_cmdfcn_t	db_breakpoint_cmd;
129
db_cmdfcn_t	db_continue_cmd;
179
db_cmdfcn_t	db_continue_cmd;
Lines 147-163 Link Here
147
db_cmdfcn_t	db_write_cmd;
197
db_cmdfcn_t	db_write_cmd;
148
198
149
/*
199
/*
150
 * Command table.
200
 * Declare command table type. It is actually a linked list, so
201
 * as to allow for runtime extensions to the table.
151
 */
202
 */
152
struct command;
203
STAILQ_HEAD(command_table, command);
153
154
struct command_table {
155
	struct command *table;
156
	struct command **aux_tablep;
157
	struct command **aux_tablep_end;
158
};
159
204
205
/*
206
 * Command table entry.
207
 */
160
struct command {
208
struct command {
209
	STAILQ_ENTRY(command)	/* Pointer to the next entry in the */
210
			next;	/* command table */
161
	char *	name;		/* command name */
211
	char *	name;		/* command name */
162
	db_cmdfcn_t *fcn;	/* function to call */
212
	db_cmdfcn_t *fcn;	/* function to call */
163
	int	flag;		/* extra info: */
213
	int	flag;		/* extra info: */
(-)./ddb/db_main.c (+2 lines)
Lines 182-187 Link Here
182
		}
182
		}
183
	}
183
	}
184
	db_add_symbol_table(NULL, NULL, "kld", NULL);
184
	db_add_symbol_table(NULL, NULL, "kld", NULL);
185
186
	db_cmd_init();
185
	return (1);	/* We're the default debugger. */
187
	return (1);	/* We're the default debugger. */
186
}
188
}
187
189
(-)./dev/aic7xxx/aic79xx_osm.c (-1 / +1 lines)
Lines 1423-1429 Link Here
1423
	}
1423
	}
1424
}
1424
}
1425
1425
1426
DB_FUNC(ahd_out, ahd_ddb_out, db_cmd_set, CS_MORE, NULL)
1426
DB_FUNC(ahd_out, ahd_ddb_out, DB_COMMAND_TABLES_DEFAULT, CS_MORE, NULL)
1427
{
1427
{
1428
	db_expr_t old_value;
1428
	db_expr_t old_value;
1429
	db_expr_t new_value;
1429
	db_expr_t new_value;
(-)./gnu/fs/xfs/FreeBSD/support/kdb.c (-1 / +1 lines)
Lines 12-18 Link Here
12
#include <support/kdb.h>
12
#include <support/kdb.h>
13
13
14
#ifdef DDB
14
#ifdef DDB
15
DB_FUNC(xfs, xfs_ddb_cmd, db_cmd_set, CS_MORE, NULL)
15
DB_FUNC(xfs, xfs_ddb_cmd, DB_COMMAND_TABLES_DEFAULT, CS_MORE, NULL)
16
{
16
{
17
	db_error("No commands registered.\n");
17
	db_error("No commands registered.\n");
18
}
18
}
(-)./kern/subr_sleepqueue.c (-1 / +1 lines)
Lines 983-987 Link Here
983
}
983
}
984
984
985
/* Alias 'show sleepqueue' to 'show sleepq'. */
985
/* Alias 'show sleepqueue' to 'show sleepq'. */
986
DB_SET(sleepqueue, db_show_sleepqueue, db_show_cmd_set, 0, NULL);
986
DB_SET(sleepqueue, db_show_sleepqueue, DB_COMMAND_TABLES_SHOW, 0, NULL);
987
#endif
987
#endif

Return to bug 127265