| @@ -1,1529 +1,1563 @@ | | | @@ -1,1529 +1,1563 @@ |
1 | /* $NetBSD: db_command.c,v 1.173 2020/10/30 07:17:29 skrll Exp $ */ | | 1 | /* $NetBSD: db_command.c,v 1.174 2020/10/30 16:08:44 skrll Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1996, 1997, 1998, 1999, 2002, 2009, 2019 | | 4 | * Copyright (c) 1996, 1997, 1998, 1999, 2002, 2009, 2019 |
5 | * The NetBSD Foundation, Inc. | | 5 | * The NetBSD Foundation, Inc. |
6 | * All rights reserved. | | 6 | * All rights reserved. |
7 | * | | 7 | * |
8 | * This code is derived from software contributed to The NetBSD Foundation | | 8 | * This code is derived from software contributed to The NetBSD Foundation |
9 | * by Adam Hamsik, and by Andrew Doran. | | 9 | * by Adam Hamsik, and by Andrew Doran. |
10 | * | | 10 | * |
11 | * Redistribution and use in source and binary forms, with or without | | 11 | * Redistribution and use in source and binary forms, with or without |
12 | * modification, are permitted provided that the following conditions | | 12 | * modification, are permitted provided that the following conditions |
13 | * are met: | | 13 | * are met: |
14 | * 1. Redistributions of source code must retain the above copyright | | 14 | * 1. Redistributions of source code must retain the above copyright |
15 | * notice, this list of conditions and the following disclaimer. | | 15 | * notice, this list of conditions and the following disclaimer. |
16 | * 2. Redistributions in binary form must reproduce the above copyright | | 16 | * 2. Redistributions in binary form must reproduce the above copyright |
17 | * notice, this list of conditions and the following disclaimer in the | | 17 | * notice, this list of conditions and the following disclaimer in the |
18 | * documentation and/or other materials provided with the distribution. | | 18 | * documentation and/or other materials provided with the distribution. |
19 | * | | 19 | * |
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
30 | * POSSIBILITY OF SUCH DAMAGE. | | 30 | * POSSIBILITY OF SUCH DAMAGE. |
31 | */ | | 31 | */ |
32 | | | 32 | |
33 | /* | | 33 | /* |
34 | * Mach Operating System | | 34 | * Mach Operating System |
35 | * Copyright (c) 1991,1990 Carnegie Mellon University | | 35 | * Copyright (c) 1991,1990 Carnegie Mellon University |
36 | * All Rights Reserved. | | 36 | * All Rights Reserved. |
37 | * | | 37 | * |
38 | * Permission to use, copy, modify and distribute this software and its | | 38 | * Permission to use, copy, modify and distribute this software and its |
39 | * documentation is hereby granted, provided that both the copyright | | 39 | * documentation is hereby granted, provided that both the copyright |
40 | * notice and this permission notice appear in all copies of the | | 40 | * notice and this permission notice appear in all copies of the |
41 | * software, derivative works or modified versions, and any portions | | 41 | * software, derivative works or modified versions, and any portions |
42 | * thereof, and that both notices appear in supporting documentation. | | 42 | * thereof, and that both notices appear in supporting documentation. |
43 | * | | 43 | * |
44 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | | 44 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" |
45 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | | 45 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR |
46 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | | 46 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. |
47 | * | | 47 | * |
48 | * Carnegie Mellon requests users of this software to return to | | 48 | * Carnegie Mellon requests users of this software to return to |
49 | * | | 49 | * |
50 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | | 50 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU |
51 | * School of Computer Science | | 51 | * School of Computer Science |
52 | * Carnegie Mellon University | | 52 | * Carnegie Mellon University |
53 | * Pittsburgh PA 15213-3890 | | 53 | * Pittsburgh PA 15213-3890 |
54 | * | | 54 | * |
55 | * any improvements or extensions that they make and grant Carnegie the | | 55 | * any improvements or extensions that they make and grant Carnegie the |
56 | * rights to redistribute these changes. | | 56 | * rights to redistribute these changes. |
57 | */ | | 57 | */ |
58 | | | 58 | |
59 | /* | | 59 | /* |
60 | * Command dispatcher. | | 60 | * Command dispatcher. |
61 | */ | | 61 | */ |
62 | | | 62 | |
63 | #include <sys/cdefs.h> | | 63 | #include <sys/cdefs.h> |
64 | __KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.173 2020/10/30 07:17:29 skrll Exp $"); | | 64 | __KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.174 2020/10/30 16:08:44 skrll Exp $"); |
65 | | | 65 | |
66 | #ifdef _KERNEL_OPT | | 66 | #ifdef _KERNEL_OPT |
67 | #include "opt_aio.h" | | 67 | #include "opt_aio.h" |
68 | #include "opt_ddb.h" | | 68 | #include "opt_ddb.h" |
| | | 69 | #include "opt_fdt.h" |
69 | #include "opt_kgdb.h" | | 70 | #include "opt_kgdb.h" |
70 | #include "opt_mqueue.h" | | 71 | #include "opt_mqueue.h" |
71 | #include "opt_inet.h" | | 72 | #include "opt_inet.h" |
72 | #include "opt_kernhist.h" | | 73 | #include "opt_kernhist.h" |
73 | #include "opt_ddbparam.h" | | 74 | #include "opt_ddbparam.h" |
74 | #include "opt_multiprocessor.h" | | 75 | #include "opt_multiprocessor.h" |
75 | #endif | | 76 | #endif |
76 | | | 77 | |
77 | #include <sys/param.h> | | 78 | #include <sys/param.h> |
78 | #include <sys/systm.h> | | 79 | #include <sys/systm.h> |
79 | #include <sys/reboot.h> | | 80 | #include <sys/reboot.h> |
80 | #include <sys/device.h> | | 81 | #include <sys/device.h> |
81 | #include <sys/lwp.h> | | 82 | #include <sys/lwp.h> |
82 | #include <sys/mbuf.h> | | 83 | #include <sys/mbuf.h> |
83 | #include <sys/namei.h> | | 84 | #include <sys/namei.h> |
84 | #include <sys/pool.h> | | 85 | #include <sys/pool.h> |
85 | #include <sys/proc.h> | | 86 | #include <sys/proc.h> |
86 | #include <sys/vnode.h> | | 87 | #include <sys/vnode.h> |
87 | #include <sys/vmem.h> | | 88 | #include <sys/vmem.h> |
88 | #include <sys/lockdebug.h> | | 89 | #include <sys/lockdebug.h> |
89 | #include <sys/cpu.h> | | 90 | #include <sys/cpu.h> |
90 | #include <sys/buf.h> | | 91 | #include <sys/buf.h> |
91 | #include <sys/module.h> | | 92 | #include <sys/module.h> |
92 | #include <sys/kernhist.h> | | 93 | #include <sys/kernhist.h> |
93 | #include <sys/socketvar.h> | | 94 | #include <sys/socketvar.h> |
94 | #include <sys/queue.h> | | 95 | #include <sys/queue.h> |
95 | | | 96 | |
96 | #include <dev/cons.h> | | 97 | #include <dev/cons.h> |
97 | | | 98 | |
98 | #include <ddb/ddb.h> | | 99 | #include <ddb/ddb.h> |
99 | | | 100 | |
100 | #include <uvm/uvm_extern.h> | | 101 | #include <uvm/uvm_extern.h> |
101 | #include <uvm/uvm_ddb.h> | | 102 | #include <uvm/uvm_ddb.h> |
102 | | | 103 | |
103 | #include <net/route.h> | | 104 | #include <net/route.h> |
104 | | | 105 | |
| | | 106 | #ifdef FDT |
| | | 107 | #include <dev/fdt/fdtvar.h> |
| | | 108 | #include <dev/fdt/fdt_ddb.h> |
| | | 109 | #endif |
| | | 110 | |
105 | /* | | 111 | /* |
106 | * Results of command search. | | 112 | * Results of command search. |
107 | */ | | 113 | */ |
108 | #define CMD_EXACT 0 | | 114 | #define CMD_EXACT 0 |
109 | #define CMD_PREFIX 1 | | 115 | #define CMD_PREFIX 1 |
110 | #define CMD_NONE 2 | | 116 | #define CMD_NONE 2 |
111 | #define CMD_AMBIGUOUS 3 | | 117 | #define CMD_AMBIGUOUS 3 |
112 | | | 118 | |
113 | /* | | 119 | /* |
114 | * Exported global variables | | 120 | * Exported global variables |
115 | */ | | 121 | */ |
116 | bool db_cmd_loop_done; | | 122 | bool db_cmd_loop_done; |
117 | label_t *db_recover; | | 123 | label_t *db_recover; |
118 | db_addr_t db_dot; | | 124 | db_addr_t db_dot; |
119 | db_addr_t db_last_addr; | | 125 | db_addr_t db_last_addr; |
120 | db_addr_t db_prev; | | 126 | db_addr_t db_prev; |
121 | db_addr_t db_next; | | 127 | db_addr_t db_next; |
122 | | | 128 | |
123 | | | 129 | |
124 | /* | | 130 | /* |
125 | * New DDB api for adding and removing commands uses three lists, because | | 131 | * New DDB api for adding and removing commands uses three lists, because |
126 | * we use two types of commands | | 132 | * we use two types of commands |
127 | * a) standard commands without subcommands -> reboot | | 133 | * a) standard commands without subcommands -> reboot |
128 | * b) show commands which are subcommands of show command -> show aio_jobs | | 134 | * b) show commands which are subcommands of show command -> show aio_jobs |
129 | * c) if defined machine specific commands | | 135 | * c) if defined machine specific commands |
130 | * | | 136 | * |
131 | * ddb_add_cmd, ddb_rem_cmd use type (DDB_SHOW_CMD||DDB_BASE_CMD)argument to | | 137 | * ddb_add_cmd, ddb_rem_cmd use type (DDB_SHOW_CMD||DDB_BASE_CMD)argument to |
132 | * add them to representativ lists. | | 138 | * add them to representativ lists. |
133 | */ | | 139 | */ |
134 | | | 140 | |
135 | static const struct db_command db_command_table[]; | | 141 | static const struct db_command db_command_table[]; |
136 | static const struct db_command db_show_cmds[]; | | 142 | static const struct db_command db_show_cmds[]; |
137 | | | 143 | |
138 | #ifdef DB_MACHINE_COMMANDS | | 144 | #ifdef DB_MACHINE_COMMANDS |
139 | /* arch/<arch>/<arch>/db_interface.c */ | | 145 | /* arch/<arch>/<arch>/db_interface.c */ |
140 | extern const struct db_command db_machine_command_table[]; | | 146 | extern const struct db_command db_machine_command_table[]; |
141 | #endif | | 147 | #endif |
142 | | | 148 | |
143 | /* the global queue of all command tables */ | | 149 | /* the global queue of all command tables */ |
144 | TAILQ_HEAD(db_cmd_tbl_en_head, db_cmd_tbl_en); | | 150 | TAILQ_HEAD(db_cmd_tbl_en_head, db_cmd_tbl_en); |
145 | | | 151 | |
146 | /* TAILQ entry used to register command tables */ | | 152 | /* TAILQ entry used to register command tables */ |
147 | struct db_cmd_tbl_en { | | 153 | struct db_cmd_tbl_en { |
148 | const struct db_command *db_cmd; /* cmd table */ | | 154 | const struct db_command *db_cmd; /* cmd table */ |
149 | TAILQ_ENTRY(db_cmd_tbl_en) db_cmd_next; | | 155 | TAILQ_ENTRY(db_cmd_tbl_en) db_cmd_next; |
150 | }; | | 156 | }; |
151 | | | 157 | |
152 | /* head of base commands list */ | | 158 | /* head of base commands list */ |
153 | static struct db_cmd_tbl_en_head db_base_cmd_list = | | 159 | static struct db_cmd_tbl_en_head db_base_cmd_list = |
154 | TAILQ_HEAD_INITIALIZER(db_base_cmd_list); | | 160 | TAILQ_HEAD_INITIALIZER(db_base_cmd_list); |
155 | static struct db_cmd_tbl_en db_base_cmd_builtins = | | 161 | static struct db_cmd_tbl_en db_base_cmd_builtins = |
156 | { .db_cmd = db_command_table }; | | 162 | { .db_cmd = db_command_table }; |
157 | | | 163 | |
158 | /* head of show commands list */ | | 164 | /* head of show commands list */ |
159 | static struct db_cmd_tbl_en_head db_show_cmd_list = | | 165 | static struct db_cmd_tbl_en_head db_show_cmd_list = |
160 | TAILQ_HEAD_INITIALIZER(db_show_cmd_list); | | 166 | TAILQ_HEAD_INITIALIZER(db_show_cmd_list); |
161 | static struct db_cmd_tbl_en db_show_cmd_builtins = | | 167 | static struct db_cmd_tbl_en db_show_cmd_builtins = |
162 | { .db_cmd = db_show_cmds }; | | 168 | { .db_cmd = db_show_cmds }; |
163 | | | 169 | |
164 | /* head of machine commands list */ | | 170 | /* head of machine commands list */ |
165 | static struct db_cmd_tbl_en_head db_mach_cmd_list = | | 171 | static struct db_cmd_tbl_en_head db_mach_cmd_list = |
166 | TAILQ_HEAD_INITIALIZER(db_mach_cmd_list); | | 172 | TAILQ_HEAD_INITIALIZER(db_mach_cmd_list); |
167 | #ifdef DB_MACHINE_COMMANDS | | 173 | #ifdef DB_MACHINE_COMMANDS |
168 | static struct db_cmd_tbl_en db_mach_cmd_builtins = | | 174 | static struct db_cmd_tbl_en db_mach_cmd_builtins = |
169 | { .db_cmd = db_machine_command_table }; | | 175 | { .db_cmd = db_machine_command_table }; |
170 | #endif | | 176 | #endif |
171 | | | 177 | |
172 | /* | | 178 | /* |
173 | * if 'ed' style: 'dot' is set at start of last item printed, | | 179 | * if 'ed' style: 'dot' is set at start of last item printed, |
174 | * and '+' points to next line. | | 180 | * and '+' points to next line. |
175 | * Otherwise: 'dot' points to next item, '..' points to last. | | 181 | * Otherwise: 'dot' points to next item, '..' points to last. |
176 | */ | | 182 | */ |
177 | static bool db_ed_style = true; | | 183 | static bool db_ed_style = true; |
178 | | | 184 | |
179 | static void db_init_commands(void); | | 185 | static void db_init_commands(void); |
180 | static int db_register_tbl_entry(uint8_t type, | | 186 | static int db_register_tbl_entry(uint8_t type, |
181 | struct db_cmd_tbl_en *list_ent); | | 187 | struct db_cmd_tbl_en *list_ent); |
182 | static void db_cmd_list(const struct db_cmd_tbl_en_head *); | | 188 | static void db_cmd_list(const struct db_cmd_tbl_en_head *); |
183 | static int db_cmd_search(const char *, struct db_cmd_tbl_en_head *, | | 189 | static int db_cmd_search(const char *, struct db_cmd_tbl_en_head *, |
184 | const struct db_command **); | | 190 | const struct db_command **); |
185 | static int db_cmd_search_table(const char *, const struct db_command *, | | 191 | static int db_cmd_search_table(const char *, const struct db_command *, |
186 | const struct db_command **); | | 192 | const struct db_command **); |
187 | static void db_cmd_search_failed(char *, int); | | 193 | static void db_cmd_search_failed(char *, int); |
188 | static const struct db_command *db_read_command(void); | | 194 | static const struct db_command *db_read_command(void); |
189 | static void db_command(const struct db_command **); | | 195 | static void db_command(const struct db_command **); |
190 | static void db_buf_print_cmd(db_expr_t, bool, db_expr_t, const char *); | | 196 | static void db_buf_print_cmd(db_expr_t, bool, db_expr_t, const char *); |
191 | static void db_event_print_cmd(db_expr_t, bool, db_expr_t, const char *); | | 197 | static void db_event_print_cmd(db_expr_t, bool, db_expr_t, const char *); |
192 | static void db_fncall(db_expr_t, bool, db_expr_t, const char *); | | 198 | static void db_fncall(db_expr_t, bool, db_expr_t, const char *); |
193 | static void db_help_print_cmd(db_expr_t, bool, db_expr_t, const char *); | | 199 | static void db_help_print_cmd(db_expr_t, bool, db_expr_t, const char *); |
194 | static void db_lock_print_cmd(db_expr_t, bool, db_expr_t, const char *); | | 200 | static void db_lock_print_cmd(db_expr_t, bool, db_expr_t, const char *); |
195 | static void db_show_all_locks(db_expr_t, bool, db_expr_t, const char *); | | 201 | static void db_show_all_locks(db_expr_t, bool, db_expr_t, const char *); |
196 | static void db_show_lockstats(db_expr_t, bool, db_expr_t, const char *); | | 202 | static void db_show_lockstats(db_expr_t, bool, db_expr_t, const char *); |
197 | static void db_show_all_freelists(db_expr_t, bool, db_expr_t, const char *); | | 203 | static void db_show_all_freelists(db_expr_t, bool, db_expr_t, const char *); |
198 | static void db_mount_print_cmd(db_expr_t, bool, db_expr_t, const char *); | | 204 | static void db_mount_print_cmd(db_expr_t, bool, db_expr_t, const char *); |
199 | static void db_show_all_mount(db_expr_t, bool, db_expr_t, const char *); | | 205 | static void db_show_all_mount(db_expr_t, bool, db_expr_t, const char *); |
200 | static void db_mbuf_print_cmd(db_expr_t, bool, db_expr_t, const char *); | | 206 | static void db_mbuf_print_cmd(db_expr_t, bool, db_expr_t, const char *); |
201 | static void db_map_print_cmd(db_expr_t, bool, db_expr_t, const char *); | | 207 | static void db_map_print_cmd(db_expr_t, bool, db_expr_t, const char *); |
202 | static void db_namecache_print_cmd(db_expr_t, bool, db_expr_t, | | 208 | static void db_namecache_print_cmd(db_expr_t, bool, db_expr_t, |
203 | const char *); | | 209 | const char *); |
204 | static void db_object_print_cmd(db_expr_t, bool, db_expr_t, const char *); | | 210 | static void db_object_print_cmd(db_expr_t, bool, db_expr_t, const char *); |
205 | static void db_page_print_cmd(db_expr_t, bool, db_expr_t, const char *); | | 211 | static void db_page_print_cmd(db_expr_t, bool, db_expr_t, const char *); |
206 | static void db_show_all_pages(db_expr_t, bool, db_expr_t, const char *); | | 212 | static void db_show_all_pages(db_expr_t, bool, db_expr_t, const char *); |
207 | static void db_pool_print_cmd(db_expr_t, bool, db_expr_t, const char *); | | 213 | static void db_pool_print_cmd(db_expr_t, bool, db_expr_t, const char *); |
208 | static void db_reboot_cmd(db_expr_t, bool, db_expr_t, const char *); | | 214 | static void db_reboot_cmd(db_expr_t, bool, db_expr_t, const char *); |
209 | static void db_sifting_cmd(db_expr_t, bool, db_expr_t, const char *); | | 215 | static void db_sifting_cmd(db_expr_t, bool, db_expr_t, const char *); |
210 | static void db_socket_print_cmd(db_expr_t, bool, db_expr_t, const char *); | | 216 | static void db_socket_print_cmd(db_expr_t, bool, db_expr_t, const char *); |
211 | static void db_stack_trace_cmd(db_expr_t, bool, db_expr_t, const char *); | | 217 | static void db_stack_trace_cmd(db_expr_t, bool, db_expr_t, const char *); |
212 | static void db_sync_cmd(db_expr_t, bool, db_expr_t, const char *); | | 218 | static void db_sync_cmd(db_expr_t, bool, db_expr_t, const char *); |
213 | static void db_whatis_cmd(db_expr_t, bool, db_expr_t, const char *); | | 219 | static void db_whatis_cmd(db_expr_t, bool, db_expr_t, const char *); |
214 | static void db_uvmexp_print_cmd(db_expr_t, bool, db_expr_t, const char *); | | 220 | static void db_uvmexp_print_cmd(db_expr_t, bool, db_expr_t, const char *); |
215 | #ifdef KERNHIST | | 221 | #ifdef KERNHIST |
216 | static void db_kernhist_print_cmd(db_expr_t, bool, db_expr_t, const char *); | | 222 | static void db_kernhist_print_cmd(db_expr_t, bool, db_expr_t, const char *); |
217 | #endif | | 223 | #endif |
218 | static void db_vnode_print_cmd(db_expr_t, bool, db_expr_t, const char *); | | 224 | static void db_vnode_print_cmd(db_expr_t, bool, db_expr_t, const char *); |
219 | static void db_vnode_lock_print_cmd(db_expr_t, bool, db_expr_t, | | 225 | static void db_vnode_lock_print_cmd(db_expr_t, bool, db_expr_t, |
220 | const char *); | | 226 | const char *); |
221 | static void db_vmem_print_cmd(db_expr_t, bool, db_expr_t, const char *); | | 227 | static void db_vmem_print_cmd(db_expr_t, bool, db_expr_t, const char *); |
| | | 228 | #ifdef FDT |
| | | 229 | static void db_fdt_print_cmd(db_expr_t, bool, db_expr_t, const char *); |
| | | 230 | #endif |
222 | | | 231 | |
223 | static const struct db_command db_show_cmds[] = { | | 232 | static const struct db_command db_show_cmds[] = { |
224 | { DDB_ADD_CMD("all", NULL, | | 233 | { DDB_ADD_CMD("all", NULL, |
225 | CS_COMPAT, NULL,NULL,NULL) }, | | 234 | CS_COMPAT, NULL,NULL,NULL) }, |
226 | #ifdef AIO | | 235 | #ifdef AIO |
227 | { DDB_ADD_CMD("aio_jobs", db_show_aio_jobs, 0, | | 236 | { DDB_ADD_CMD("aio_jobs", db_show_aio_jobs, 0, |
228 | "Show aio jobs",NULL,NULL) }, | | 237 | "Show aio jobs",NULL,NULL) }, |
229 | #endif | | 238 | #endif |
230 | #ifdef _KERNEL | | 239 | #ifdef _KERNEL |
231 | { DDB_ADD_CMD("breaks", db_listbreak_cmd, 0, | | 240 | { DDB_ADD_CMD("breaks", db_listbreak_cmd, 0, |
232 | "Display all breaks.",NULL,NULL) }, | | 241 | "Display all breaks.",NULL,NULL) }, |
233 | #endif | | 242 | #endif |
234 | { DDB_ADD_CMD("buf", db_buf_print_cmd, 0, | | 243 | { DDB_ADD_CMD("buf", db_buf_print_cmd, 0, |
235 | "Print the struct buf at address.", "[/f] address",NULL) }, | | 244 | "Print the struct buf at address.", "[/f] address",NULL) }, |
236 | /* added from all sub cmds */ | | 245 | /* added from all sub cmds */ |
237 | { DDB_ADD_CMD("callout", db_show_callout, | | 246 | { DDB_ADD_CMD("callout", db_show_callout, |
238 | 0 ,"List all used callout functions.",NULL,NULL) }, | | 247 | 0 ,"List all used callout functions.",NULL,NULL) }, |
239 | { DDB_ADD_CMD("devices", db_show_all_devices, 0,NULL,NULL,NULL) }, | | 248 | { DDB_ADD_CMD("devices", db_show_all_devices, 0,NULL,NULL,NULL) }, |
240 | { DDB_ADD_CMD("event", db_event_print_cmd, 0, | | 249 | { DDB_ADD_CMD("event", db_event_print_cmd, 0, |
241 | "Print all the non-zero evcnt(9) event counters.", "[/fitm]",NULL) }, | | 250 | "Print all the non-zero evcnt(9) event counters.", "[/fitm]",NULL) }, |
| | | 251 | #ifdef FDT |
| | | 252 | { DDB_ADD_CMD("fdt", db_fdt_print_cmd, 0, |
| | | 253 | "Show FDT information", NULL, NULL) }, |
| | | 254 | #endif |
242 | { DDB_ADD_CMD("files", db_show_files_cmd, 0, | | 255 | { DDB_ADD_CMD("files", db_show_files_cmd, 0, |
243 | "Print the files open by process at address", | | 256 | "Print the files open by process at address", |
244 | "[/f] address", NULL) }, | | 257 | "[/f] address", NULL) }, |
245 | { DDB_ADD_CMD("freelists", db_show_all_freelists, | | 258 | { DDB_ADD_CMD("freelists", db_show_all_freelists, |
246 | 0 ,"Show all freelists", NULL, NULL) }, | | 259 | 0 ,"Show all freelists", NULL, NULL) }, |
247 | #ifdef KERNHIST | | 260 | #ifdef KERNHIST |
248 | { DDB_ADD_CMD("kernhist", db_kernhist_print_cmd, 0, | | 261 | { DDB_ADD_CMD("kernhist", db_kernhist_print_cmd, 0, |
249 | "Print the UVM history logs.", | | 262 | "Print the UVM history logs.", |
250 | NULL,NULL) }, | | 263 | NULL,NULL) }, |
251 | #endif | | 264 | #endif |
252 | /* added from all sub cmds */ | | 265 | /* added from all sub cmds */ |
253 | { DDB_ADD_CMD("locks", db_show_all_locks, | | 266 | { DDB_ADD_CMD("locks", db_show_all_locks, |
254 | 0 ,"Show all held locks", "[/t]", NULL) }, | | 267 | 0 ,"Show all held locks", "[/t]", NULL) }, |
255 | { DDB_ADD_CMD("lock", db_lock_print_cmd, 0,NULL,NULL,NULL) }, | | 268 | { DDB_ADD_CMD("lock", db_lock_print_cmd, 0,NULL,NULL,NULL) }, |
256 | { DDB_ADD_CMD("lockstats", | | 269 | { DDB_ADD_CMD("lockstats", |
257 | db_show_lockstats, 0, | | 270 | db_show_lockstats, 0, |
258 | "Print statistics of locks", NULL, NULL) }, | | 271 | "Print statistics of locks", NULL, NULL) }, |
259 | { DDB_ADD_CMD("map", db_map_print_cmd, 0, | | 272 | { DDB_ADD_CMD("map", db_map_print_cmd, 0, |
260 | "Print the vm_map at address.", "[/f] address",NULL) }, | | 273 | "Print the vm_map at address.", "[/f] address",NULL) }, |
261 | { DDB_ADD_CMD("mbuf", db_mbuf_print_cmd, 0,NULL,NULL, | | 274 | { DDB_ADD_CMD("mbuf", db_mbuf_print_cmd, 0,NULL,NULL, |
262 | "-c prints all mbuf chains") }, | | 275 | "-c prints all mbuf chains") }, |
263 | { DDB_ADD_CMD("module", db_show_module_cmd, 0, | | 276 | { DDB_ADD_CMD("module", db_show_module_cmd, 0, |
264 | "Print kernel modules", NULL, NULL) }, | | 277 | "Print kernel modules", NULL, NULL) }, |
265 | { DDB_ADD_CMD("mount", db_show_all_mount, 0, | | 278 | { DDB_ADD_CMD("mount", db_show_all_mount, 0, |
266 | "Print all mount structures.", "[/f]", NULL) }, | | 279 | "Print all mount structures.", "[/f]", NULL) }, |
267 | { DDB_ADD_CMD("mount", db_mount_print_cmd, 0, | | 280 | { DDB_ADD_CMD("mount", db_mount_print_cmd, 0, |
268 | "Print the mount structure at address.", "[/f] address",NULL) }, | | 281 | "Print the mount structure at address.", "[/f] address",NULL) }, |
269 | #ifdef MQUEUE | | 282 | #ifdef MQUEUE |
270 | { DDB_ADD_CMD("mqueue", db_show_mqueue_cmd, 0, | | 283 | { DDB_ADD_CMD("mqueue", db_show_mqueue_cmd, 0, |
271 | "Print the message queues", NULL, NULL) }, | | 284 | "Print the message queues", NULL, NULL) }, |
272 | #endif | | 285 | #endif |
273 | { DDB_ADD_CMD("ncache", db_namecache_print_cmd, 0, | | 286 | { DDB_ADD_CMD("ncache", db_namecache_print_cmd, 0, |
274 | "Dump the namecache list.", "address",NULL) }, | | 287 | "Dump the namecache list.", "address",NULL) }, |
275 | { DDB_ADD_CMD("object", db_object_print_cmd, 0, | | 288 | { DDB_ADD_CMD("object", db_object_print_cmd, 0, |
276 | "Print the vm_object at address.", "[/f] address",NULL) }, | | 289 | "Print the vm_object at address.", "[/f] address",NULL) }, |
277 | { DDB_ADD_CMD("page", db_page_print_cmd, 0, | | 290 | { DDB_ADD_CMD("page", db_page_print_cmd, 0, |
278 | "Print the vm_page at address.", "[/f] address",NULL) }, | | 291 | "Print the vm_page at address.", "[/f] address",NULL) }, |
279 | { DDB_ADD_CMD("pages", db_show_all_pages, | | 292 | { DDB_ADD_CMD("pages", db_show_all_pages, |
280 | 0 ,"List all used memory pages.",NULL,NULL) }, | | 293 | 0 ,"List all used memory pages.",NULL,NULL) }, |
281 | { DDB_ADD_CMD("panic", db_show_panic, 0, | | 294 | { DDB_ADD_CMD("panic", db_show_panic, 0, |
282 | "Print the current panic string",NULL,NULL) }, | | 295 | "Print the current panic string",NULL,NULL) }, |
283 | { DDB_ADD_CMD("pool", db_pool_print_cmd, 0, | | 296 | { DDB_ADD_CMD("pool", db_pool_print_cmd, 0, |
284 | "Print the pool at address.", "[/clp] address",NULL) }, | | 297 | "Print the pool at address.", "[/clp] address",NULL) }, |
285 | /* added from all sub cmds */ | | 298 | /* added from all sub cmds */ |
286 | { DDB_ADD_CMD("pools", db_show_all_pools, | | 299 | { DDB_ADD_CMD("pools", db_show_all_pools, |
287 | 0 ,"Show all pools",NULL,NULL) }, | | 300 | 0 ,"Show all pools",NULL,NULL) }, |
288 | { DDB_ADD_CMD("proc", db_show_proc, | | 301 | { DDB_ADD_CMD("proc", db_show_proc, |
289 | 0 ,"Print process information.",NULL,NULL) }, | | 302 | 0 ,"Print process information.",NULL,NULL) }, |
290 | /* added from all sub cmds */ | | 303 | /* added from all sub cmds */ |
291 | { DDB_ADD_CMD("procs", db_show_all_procs, | | 304 | { DDB_ADD_CMD("procs", db_show_all_procs, |
292 | 0 ,"List all processes.",NULL,NULL) }, | | 305 | 0 ,"List all processes.",NULL,NULL) }, |
293 | { DDB_ADD_CMD("registers", db_show_regs, 0, | | 306 | { DDB_ADD_CMD("registers", db_show_regs, 0, |
294 | "Display the register set.", "[/u]",NULL) }, | | 307 | "Display the register set.", "[/u]",NULL) }, |
295 | #if defined(INET) | | 308 | #if defined(INET) |
296 | { DDB_ADD_CMD("routes", db_show_routes, 0,NULL,NULL,NULL) }, | | 309 | { DDB_ADD_CMD("routes", db_show_routes, 0,NULL,NULL,NULL) }, |
297 | #endif | | 310 | #endif |
298 | { DDB_ADD_CMD("sched_qs", db_show_sched_qs, 0, | | 311 | { DDB_ADD_CMD("sched_qs", db_show_sched_qs, 0, |
299 | "Print the state of the scheduler's run queues.", | | 312 | "Print the state of the scheduler's run queues.", |
300 | NULL,NULL) }, | | 313 | NULL,NULL) }, |
301 | { DDB_ADD_CMD("socket", db_socket_print_cmd, 0,NULL,NULL,NULL) }, | | 314 | { DDB_ADD_CMD("socket", db_socket_print_cmd, 0,NULL,NULL,NULL) }, |
302 | { DDB_ADD_CMD("uvmexp", db_uvmexp_print_cmd, 0, | | 315 | { DDB_ADD_CMD("uvmexp", db_uvmexp_print_cmd, 0, |
303 | "Print a selection of UVM counters and statistics.", | | 316 | "Print a selection of UVM counters and statistics.", |
304 | NULL,NULL) }, | | 317 | NULL,NULL) }, |
305 | { DDB_ADD_CMD("vmem", db_vmem_print_cmd, 0, | | 318 | { DDB_ADD_CMD("vmem", db_vmem_print_cmd, 0, |
306 | "Print the vmem usage.", "[/a] address", NULL) }, | | 319 | "Print the vmem usage.", "[/a] address", NULL) }, |
307 | { DDB_ADD_CMD("vmems", db_show_all_vmems, 0, | | 320 | { DDB_ADD_CMD("vmems", db_show_all_vmems, 0, |
308 | "Show all vmems.", NULL, NULL) }, | | 321 | "Show all vmems.", NULL, NULL) }, |
309 | { DDB_ADD_CMD("vnode", db_vnode_print_cmd, 0, | | 322 | { DDB_ADD_CMD("vnode", db_vnode_print_cmd, 0, |
310 | "Print the vnode at address.", "[/f] address",NULL) }, | | 323 | "Print the vnode at address.", "[/f] address",NULL) }, |
311 | { DDB_ADD_CMD("vnode_lock", db_vnode_lock_print_cmd, 0, | | 324 | { DDB_ADD_CMD("vnode_lock", db_vnode_lock_print_cmd, 0, |
312 | "Print the vnode having that address as v_lock.", | | 325 | "Print the vnode having that address as v_lock.", |
313 | "[/f] address",NULL) }, | | 326 | "[/f] address",NULL) }, |
314 | #ifdef _KERNEL | | 327 | #ifdef _KERNEL |
315 | { DDB_ADD_CMD("watches", db_listwatch_cmd, 0, | | 328 | { DDB_ADD_CMD("watches", db_listwatch_cmd, 0, |
316 | "Display all watchpoints.", NULL,NULL) }, | | 329 | "Display all watchpoints.", NULL,NULL) }, |
317 | #endif | | 330 | #endif |
318 | { DDB_ADD_CMD(NULL, NULL, 0,NULL,NULL,NULL) } | | 331 | { DDB_ADD_CMD(NULL, NULL, 0,NULL,NULL,NULL) } |
319 | }; | | 332 | }; |
320 | | | 333 | |
321 | static const struct db_command db_command_table[] = { | | 334 | static const struct db_command db_command_table[] = { |
322 | { DDB_ADD_CMD("b", db_breakpoint_cmd, 0, | | 335 | { DDB_ADD_CMD("b", db_breakpoint_cmd, 0, |
323 | "Set a breakpoint at address", "[/u] address[,count].",NULL) }, | | 336 | "Set a breakpoint at address", "[/u] address[,count].",NULL) }, |
324 | { DDB_ADD_CMD("break", db_breakpoint_cmd, 0, | | 337 | { DDB_ADD_CMD("break", db_breakpoint_cmd, 0, |
325 | "Set a breakpoint at address", "[/u] address[,count].",NULL) }, | | 338 | "Set a breakpoint at address", "[/u] address[,count].",NULL) }, |
326 | { DDB_ADD_CMD("bt", db_stack_trace_cmd, 0, | | 339 | { DDB_ADD_CMD("bt", db_stack_trace_cmd, 0, |
327 | "Show backtrace.", "See help trace.",NULL) }, | | 340 | "Show backtrace.", "See help trace.",NULL) }, |
328 | { DDB_ADD_CMD("c", db_continue_cmd, 0, | | 341 | { DDB_ADD_CMD("c", db_continue_cmd, 0, |
329 | "Continue execution.", "[/c]",NULL) }, | | 342 | "Continue execution.", "[/c]",NULL) }, |
330 | { DDB_ADD_CMD("call", db_fncall, CS_OWN, | | 343 | { DDB_ADD_CMD("call", db_fncall, CS_OWN, |
331 | "Call the function", "address[(expression[,...])]",NULL) }, | | 344 | "Call the function", "address[(expression[,...])]",NULL) }, |
332 | { DDB_ADD_CMD("callout", db_show_callout, 0, NULL, | | 345 | { DDB_ADD_CMD("callout", db_show_callout, 0, NULL, |
333 | NULL,NULL ) }, | | 346 | NULL,NULL ) }, |
334 | { DDB_ADD_CMD("continue", db_continue_cmd, 0, | | 347 | { DDB_ADD_CMD("continue", db_continue_cmd, 0, |
335 | "Continue execution.", "[/c]",NULL) }, | | 348 | "Continue execution.", "[/c]",NULL) }, |
336 | { DDB_ADD_CMD("d", db_delete_cmd, 0, | | 349 | { DDB_ADD_CMD("d", db_delete_cmd, 0, |
337 | "Delete a breakpoint.", "address | #number",NULL) }, | | 350 | "Delete a breakpoint.", "address | #number",NULL) }, |
338 | { DDB_ADD_CMD("delete", db_delete_cmd, 0, | | 351 | { DDB_ADD_CMD("delete", db_delete_cmd, 0, |
339 | "Delete a breakpoint.", "address | #number",NULL) }, | | 352 | "Delete a breakpoint.", "address | #number",NULL) }, |
340 | { DDB_ADD_CMD("dmesg", db_dmesg, 0, | | 353 | { DDB_ADD_CMD("dmesg", db_dmesg, 0, |
341 | "Show kernel message buffer.", "[count]",NULL) }, | | 354 | "Show kernel message buffer.", "[count]",NULL) }, |
342 | { DDB_ADD_CMD("dwatch", db_deletewatch_cmd, 0, | | 355 | { DDB_ADD_CMD("dwatch", db_deletewatch_cmd, 0, |
343 | "Delete the watchpoint.", "address",NULL) }, | | 356 | "Delete the watchpoint.", "address",NULL) }, |
344 | { DDB_ADD_CMD("examine", db_examine_cmd, CS_SET_DOT, | | 357 | { DDB_ADD_CMD("examine", db_examine_cmd, CS_SET_DOT, |
345 | "Display the address locations.", | | 358 | "Display the address locations.", |
346 | "[/modifier] address[,count]",NULL) }, | | 359 | "[/modifier] address[,count]",NULL) }, |
347 | { DDB_ADD_CMD("exit", db_continue_cmd, 0, | | 360 | { DDB_ADD_CMD("exit", db_continue_cmd, 0, |
348 | "Continue execution.", "[/c]",NULL) }, | | 361 | "Continue execution.", "[/c]",NULL) }, |
349 | { DDB_ADD_CMD("help", db_help_print_cmd, CS_OWN|CS_NOREPEAT, | | 362 | { DDB_ADD_CMD("help", db_help_print_cmd, CS_OWN|CS_NOREPEAT, |
350 | "Display help about commands", | | 363 | "Display help about commands", |
351 | "Use other commands as arguments.",NULL) }, | | 364 | "Use other commands as arguments.",NULL) }, |
352 | { DDB_ADD_CMD("kill", db_kill_proc, CS_OWN, | | 365 | { DDB_ADD_CMD("kill", db_kill_proc, CS_OWN, |
353 | "Send a signal to the process","pid[,signal_number]", | | 366 | "Send a signal to the process","pid[,signal_number]", |
354 | " pid:\t\t\tthe process id (may need 0t prefix for decimal)\n" | | 367 | " pid:\t\t\tthe process id (may need 0t prefix for decimal)\n" |
355 | " signal_number:\tthe signal to send") }, | | 368 | " signal_number:\tthe signal to send") }, |
356 | #ifdef KGDB | | 369 | #ifdef KGDB |
357 | { DDB_ADD_CMD("kgdb", db_kgdb_cmd, 0, NULL,NULL,NULL) }, | | 370 | { DDB_ADD_CMD("kgdb", db_kgdb_cmd, 0, NULL,NULL,NULL) }, |
358 | #endif | | 371 | #endif |
359 | { DDB_ADD_CMD("machine",NULL,CS_MACH, | | 372 | { DDB_ADD_CMD("machine",NULL,CS_MACH, |
360 | "Architecture specific functions.",NULL,NULL) }, | | 373 | "Architecture specific functions.",NULL,NULL) }, |
361 | { DDB_ADD_CMD("match", db_trace_until_matching_cmd,0, | | 374 | { DDB_ADD_CMD("match", db_trace_until_matching_cmd,0, |
362 | "Stop at the matching return instruction.","See help next",NULL) }, | | 375 | "Stop at the matching return instruction.","See help next",NULL) }, |
363 | { DDB_ADD_CMD("next", db_trace_until_matching_cmd,0, | | 376 | { DDB_ADD_CMD("next", db_trace_until_matching_cmd,0, |
364 | "Stop at the matching return instruction.","[/p]",NULL) }, | | 377 | "Stop at the matching return instruction.","[/p]",NULL) }, |
365 | { DDB_ADD_CMD("p", db_print_cmd, 0, | | 378 | { DDB_ADD_CMD("p", db_print_cmd, 0, |
366 | "Print address according to the format.", | | 379 | "Print address according to the format.", |
367 | "[/axzodurc] address [address ...]",NULL) }, | | 380 | "[/axzodurc] address [address ...]",NULL) }, |
368 | { DDB_ADD_CMD("print", db_print_cmd, 0, | | 381 | { DDB_ADD_CMD("print", db_print_cmd, 0, |
369 | "Print address according to the format.", | | 382 | "Print address according to the format.", |
370 | "[/axzodurc] address [address ...]",NULL) }, | | 383 | "[/axzodurc] address [address ...]",NULL) }, |
371 | { DDB_ADD_CMD("ps", db_show_all_procs, 0, | | 384 | { DDB_ADD_CMD("ps", db_show_all_procs, 0, |
372 | "Print all processes.","See show all procs",NULL) }, | | 385 | "Print all processes.","See show all procs",NULL) }, |
373 | { DDB_ADD_CMD("quit", db_continue_cmd, 0, | | 386 | { DDB_ADD_CMD("quit", db_continue_cmd, 0, |
374 | "Continue execution.", "[/c]",NULL) }, | | 387 | "Continue execution.", "[/c]",NULL) }, |
375 | { DDB_ADD_CMD("reboot", db_reboot_cmd, CS_OWN, | | 388 | { DDB_ADD_CMD("reboot", db_reboot_cmd, CS_OWN, |
376 | "Reboot","0x1 RB_ASKNAME, 0x2 RB_SINGLE, 0x4 RB_NOSYNC, 0x8 RB_HALT," | | 389 | "Reboot","0x1 RB_ASKNAME, 0x2 RB_SINGLE, 0x4 RB_NOSYNC, 0x8 RB_HALT," |
377 | "0x40 RB_KDB, 0x100 RB_DUMP, 0x808 RB_POWERDOWN",NULL) }, | | 390 | "0x40 RB_KDB, 0x100 RB_DUMP, 0x808 RB_POWERDOWN",NULL) }, |
378 | { DDB_ADD_CMD("s", db_single_step_cmd, 0, | | 391 | { DDB_ADD_CMD("s", db_single_step_cmd, 0, |
379 | "Single-step count times.","[/p] [,count]",NULL) }, | | 392 | "Single-step count times.","[/p] [,count]",NULL) }, |
380 | { DDB_ADD_CMD("search", db_search_cmd, CS_OWN|CS_SET_DOT, | | 393 | { DDB_ADD_CMD("search", db_search_cmd, CS_OWN|CS_SET_DOT, |
381 | "Search memory from address for value.", | | 394 | "Search memory from address for value.", |
382 | "[/bhl] address value [mask] [,count]",NULL) }, | | 395 | "[/bhl] address value [mask] [,count]",NULL) }, |
383 | { DDB_ADD_CMD("set", db_set_cmd, CS_OWN, | | 396 | { DDB_ADD_CMD("set", db_set_cmd, CS_OWN, |
384 | "Set the named variable","$variable [=] expression",NULL) }, | | 397 | "Set the named variable","$variable [=] expression",NULL) }, |
385 | { DDB_ADD_CMD("show", NULL, CS_SHOW, | | 398 | { DDB_ADD_CMD("show", NULL, CS_SHOW, |
386 | "Show kernel stats.", NULL,NULL) }, | | 399 | "Show kernel stats.", NULL,NULL) }, |
387 | { DDB_ADD_CMD("sifting", db_sifting_cmd, CS_OWN, | | 400 | { DDB_ADD_CMD("sifting", db_sifting_cmd, CS_OWN, |
388 | "Search the symbol tables ","[/F] string",NULL) }, | | 401 | "Search the symbol tables ","[/F] string",NULL) }, |
389 | { DDB_ADD_CMD("step", db_single_step_cmd, 0, | | 402 | { DDB_ADD_CMD("step", db_single_step_cmd, 0, |
390 | "Single-step count times.","[/p] [,count]",NULL) }, | | 403 | "Single-step count times.","[/p] [,count]",NULL) }, |
391 | { DDB_ADD_CMD("sync", db_sync_cmd, CS_OWN, | | 404 | { DDB_ADD_CMD("sync", db_sync_cmd, CS_OWN, |
392 | "Force a crash dump, and then reboot.",NULL,NULL) }, | | 405 | "Force a crash dump, and then reboot.",NULL,NULL) }, |
393 | { DDB_ADD_CMD("trace", db_stack_trace_cmd, 0, | | 406 | { DDB_ADD_CMD("trace", db_stack_trace_cmd, 0, |
394 | "Stack trace from frame-address.", | | 407 | "Stack trace from frame-address.", |
395 | "[/u[l]] [frame-address][,count]",NULL) }, | | 408 | "[/u[l]] [frame-address][,count]",NULL) }, |
396 | { DDB_ADD_CMD("until", db_trace_until_call_cmd,0, | | 409 | { DDB_ADD_CMD("until", db_trace_until_call_cmd,0, |
397 | "Stop at the next call or return instruction.","[/p]",NULL) }, | | 410 | "Stop at the next call or return instruction.","[/p]",NULL) }, |
398 | { DDB_ADD_CMD("w", db_write_cmd, CS_MORE|CS_SET_DOT, | | 411 | { DDB_ADD_CMD("w", db_write_cmd, CS_MORE|CS_SET_DOT, |
399 | "Write the expressions at succeeding locations.", | | 412 | "Write the expressions at succeeding locations.", |
400 | "[/bhl] address expression [expression ...]",NULL) }, | | 413 | "[/bhl] address expression [expression ...]",NULL) }, |
401 | { DDB_ADD_CMD("watch", db_watchpoint_cmd, CS_MORE, | | 414 | { DDB_ADD_CMD("watch", db_watchpoint_cmd, CS_MORE, |
402 | "Set a watchpoint for a region. ","address[,size]",NULL) }, | | 415 | "Set a watchpoint for a region. ","address[,size]",NULL) }, |
403 | { DDB_ADD_CMD("whatis", db_whatis_cmd, 0, | | 416 | { DDB_ADD_CMD("whatis", db_whatis_cmd, 0, |
404 | "Describe what an address is", "address", NULL) }, | | 417 | "Describe what an address is", "address", NULL) }, |
405 | { DDB_ADD_CMD("write", db_write_cmd, CS_MORE|CS_SET_DOT, | | 418 | { DDB_ADD_CMD("write", db_write_cmd, CS_MORE|CS_SET_DOT, |
406 | "Write the expressions at succeeding locations.", | | 419 | "Write the expressions at succeeding locations.", |
407 | "[/bhl] address expression [expression ...]",NULL) }, | | 420 | "[/bhl] address expression [expression ...]",NULL) }, |
408 | { DDB_ADD_CMD("x", db_examine_cmd, CS_SET_DOT, | | 421 | { DDB_ADD_CMD("x", db_examine_cmd, CS_SET_DOT, |
409 | "Display the address locations.", | | 422 | "Display the address locations.", |
410 | "[/modifier] address[,count]",NULL) }, | | 423 | "[/modifier] address[,count]",NULL) }, |
411 | { DDB_ADD_CMD(NULL, NULL, 0, NULL, NULL, NULL) } | | 424 | { DDB_ADD_CMD(NULL, NULL, 0, NULL, NULL, NULL) } |
412 | }; | | 425 | }; |
413 | | | 426 | |
414 | static const struct db_command *db_last_command = NULL; | | 427 | static const struct db_command *db_last_command = NULL; |
415 | #if defined(DDB_COMMANDONENTER) | | 428 | #if defined(DDB_COMMANDONENTER) |
416 | char db_cmd_on_enter[DB_LINE_MAXLEN + 1] = ___STRING(DDB_COMMANDONENTER); | | 429 | char db_cmd_on_enter[DB_LINE_MAXLEN + 1] = ___STRING(DDB_COMMANDONENTER); |
417 | #else /* defined(DDB_COMMANDONENTER) */ | | 430 | #else /* defined(DDB_COMMANDONENTER) */ |
418 | char db_cmd_on_enter[DB_LINE_MAXLEN + 1] = ""; | | 431 | char db_cmd_on_enter[DB_LINE_MAXLEN + 1] = ""; |
419 | #endif /* defined(DDB_COMMANDONENTER) */ | | 432 | #endif /* defined(DDB_COMMANDONENTER) */ |
420 | #define DB_LINE_SEP ';' | | 433 | #define DB_LINE_SEP ';' |
421 | | | 434 | |
422 | /* | | 435 | /* |
423 | * Execute commandlist after ddb start | | 436 | * Execute commandlist after ddb start |
424 | * This function goes through the command list created from commands and ';' | | 437 | * This function goes through the command list created from commands and ';' |
425 | */ | | 438 | */ |
426 | static void | | 439 | static void |
427 | db_execute_commandlist(const char *cmdlist) | | 440 | db_execute_commandlist(const char *cmdlist) |
428 | { | | 441 | { |
429 | const char *cmd = cmdlist; | | 442 | const char *cmd = cmdlist; |
430 | const struct db_command *dummy = NULL; | | 443 | const struct db_command *dummy = NULL; |
431 | | | 444 | |
432 | while (*cmd != '\0') { | | 445 | while (*cmd != '\0') { |
433 | const char *ep = cmd; | | 446 | const char *ep = cmd; |
434 | | | 447 | |
435 | while (*ep != '\0' && *ep != DB_LINE_SEP) { | | 448 | while (*ep != '\0' && *ep != DB_LINE_SEP) { |
436 | ep++; | | 449 | ep++; |
437 | } | | 450 | } |
438 | db_set_line(cmd, ep); | | 451 | db_set_line(cmd, ep); |
439 | db_command(&dummy); | | 452 | db_command(&dummy); |
440 | cmd = ep; | | 453 | cmd = ep; |
441 | if (*cmd == DB_LINE_SEP) { | | 454 | if (*cmd == DB_LINE_SEP) { |
442 | cmd++; | | 455 | cmd++; |
443 | } | | 456 | } |
444 | } | | 457 | } |
445 | } | | 458 | } |
446 | | | 459 | |
447 | /* Initialize ddb command tables */ | | 460 | /* Initialize ddb command tables */ |
448 | void | | 461 | void |
449 | db_init_commands(void) | | 462 | db_init_commands(void) |
450 | { | | 463 | { |
451 | static bool done = false; | | 464 | static bool done = false; |
452 | | | 465 | |
453 | if (done) return; | | 466 | if (done) return; |
454 | done = true; | | 467 | done = true; |
455 | | | 468 | |
456 | /* register command tables */ | | 469 | /* register command tables */ |
457 | (void)db_register_tbl_entry(DDB_BASE_CMD, &db_base_cmd_builtins); | | 470 | (void)db_register_tbl_entry(DDB_BASE_CMD, &db_base_cmd_builtins); |
458 | #ifdef DB_MACHINE_COMMANDS | | 471 | #ifdef DB_MACHINE_COMMANDS |
459 | (void)db_register_tbl_entry(DDB_MACH_CMD, &db_mach_cmd_builtins); | | 472 | (void)db_register_tbl_entry(DDB_MACH_CMD, &db_mach_cmd_builtins); |
460 | #endif | | 473 | #endif |
461 | (void)db_register_tbl_entry(DDB_SHOW_CMD, &db_show_cmd_builtins); | | 474 | (void)db_register_tbl_entry(DDB_SHOW_CMD, &db_show_cmd_builtins); |
462 | } | | 475 | } |
463 | | | 476 | |
464 | | | 477 | |
465 | /* | | 478 | /* |
466 | * Add command table to the specified list | | 479 | * Add command table to the specified list |
467 | * Arg: | | 480 | * Arg: |
468 | * int type specifies type of command table DDB_SHOW_CMD|DDB_BASE_CMD|DDB_MAC_CMD | | 481 | * int type specifies type of command table DDB_SHOW_CMD|DDB_BASE_CMD|DDB_MAC_CMD |
469 | * *cmd_tbl poiter to static allocated db_command table | | 482 | * *cmd_tbl poiter to static allocated db_command table |
470 | * | | 483 | * |
471 | * Command table must be NULL terminated array of struct db_command | | 484 | * Command table must be NULL terminated array of struct db_command |
472 | */ | | 485 | */ |
473 | int | | 486 | int |
474 | db_register_tbl(uint8_t type, const struct db_command *cmd_tbl) | | 487 | db_register_tbl(uint8_t type, const struct db_command *cmd_tbl) |
475 | { | | 488 | { |
476 | struct db_cmd_tbl_en *list_ent; | | 489 | struct db_cmd_tbl_en *list_ent; |
477 | | | 490 | |
478 | /* empty list - ignore */ | | 491 | /* empty list - ignore */ |
479 | if (cmd_tbl->name == 0) | | 492 | if (cmd_tbl->name == 0) |
480 | return 0; | | 493 | return 0; |
481 | | | 494 | |
482 | /* force builtin commands to be registered first */ | | 495 | /* force builtin commands to be registered first */ |
483 | db_init_commands(); | | 496 | db_init_commands(); |
484 | | | 497 | |
485 | /* now create a list entry for this table */ | | 498 | /* now create a list entry for this table */ |
486 | list_ent = db_zalloc(sizeof(*list_ent)); | | 499 | list_ent = db_zalloc(sizeof(*list_ent)); |
487 | if (list_ent == NULL) | | 500 | if (list_ent == NULL) |
488 | return ENOMEM; | | 501 | return ENOMEM; |
489 | list_ent->db_cmd=cmd_tbl; | | 502 | list_ent->db_cmd=cmd_tbl; |
490 | | | 503 | |
491 | /* and register it */ | | 504 | /* and register it */ |
492 | return db_register_tbl_entry(type, list_ent); | | 505 | return db_register_tbl_entry(type, list_ent); |
493 | } | | 506 | } |
494 | | | 507 | |
495 | static int | | 508 | static int |
496 | db_register_tbl_entry(uint8_t type, struct db_cmd_tbl_en *list_ent) | | 509 | db_register_tbl_entry(uint8_t type, struct db_cmd_tbl_en *list_ent) |
497 | { | | 510 | { |
498 | struct db_cmd_tbl_en_head *list; | | 511 | struct db_cmd_tbl_en_head *list; |
499 | | | 512 | |
500 | switch(type) { | | 513 | switch(type) { |
501 | case DDB_BASE_CMD: | | 514 | case DDB_BASE_CMD: |
502 | list = &db_base_cmd_list; | | 515 | list = &db_base_cmd_list; |
503 | break; | | 516 | break; |
504 | case DDB_SHOW_CMD: | | 517 | case DDB_SHOW_CMD: |
505 | list = &db_show_cmd_list; | | 518 | list = &db_show_cmd_list; |
506 | break; | | 519 | break; |
507 | case DDB_MACH_CMD: | | 520 | case DDB_MACH_CMD: |
508 | list = &db_mach_cmd_list; | | 521 | list = &db_mach_cmd_list; |
509 | break; | | 522 | break; |
510 | default: | | 523 | default: |
511 | return ENOENT; | | 524 | return ENOENT; |
512 | } | | 525 | } |
513 | | | 526 | |
514 | TAILQ_INSERT_TAIL(list, list_ent, db_cmd_next); | | 527 | TAILQ_INSERT_TAIL(list, list_ent, db_cmd_next); |
515 | | | 528 | |
516 | return 0; | | 529 | return 0; |
517 | } | | 530 | } |
518 | | | 531 | |
519 | /* | | 532 | /* |
520 | * Remove command table specified with db_cmd address == cmd_tbl | | 533 | * Remove command table specified with db_cmd address == cmd_tbl |
521 | */ | | 534 | */ |
522 | int | | 535 | int |
523 | db_unregister_tbl(uint8_t type,const struct db_command *cmd_tbl) | | 536 | db_unregister_tbl(uint8_t type,const struct db_command *cmd_tbl) |
524 | { | | 537 | { |
525 | struct db_cmd_tbl_en *list_ent; | | 538 | struct db_cmd_tbl_en *list_ent; |
526 | struct db_cmd_tbl_en_head *list; | | 539 | struct db_cmd_tbl_en_head *list; |
527 | | | 540 | |
528 | /* find list on which the entry should live */ | | 541 | /* find list on which the entry should live */ |
529 | switch (type) { | | 542 | switch (type) { |
530 | case DDB_BASE_CMD: | | 543 | case DDB_BASE_CMD: |
531 | list=&db_base_cmd_list; | | 544 | list=&db_base_cmd_list; |
532 | break; | | 545 | break; |
533 | case DDB_SHOW_CMD: | | 546 | case DDB_SHOW_CMD: |
534 | list=&db_show_cmd_list; | | 547 | list=&db_show_cmd_list; |
535 | break; | | 548 | break; |
536 | case DDB_MACH_CMD: | | 549 | case DDB_MACH_CMD: |
537 | list=&db_mach_cmd_list; | | 550 | list=&db_mach_cmd_list; |
538 | break; | | 551 | break; |
539 | default: | | 552 | default: |
540 | return EINVAL; | | 553 | return EINVAL; |
541 | } | | 554 | } |
542 | | | 555 | |
543 | TAILQ_FOREACH (list_ent, list, db_cmd_next) { | | 556 | TAILQ_FOREACH (list_ent, list, db_cmd_next) { |
544 | if (list_ent->db_cmd == cmd_tbl){ | | 557 | if (list_ent->db_cmd == cmd_tbl){ |
545 | TAILQ_REMOVE(list, | | 558 | TAILQ_REMOVE(list, |
546 | list_ent, db_cmd_next); | | 559 | list_ent, db_cmd_next); |
547 | db_free(list_ent, sizeof(*list_ent)); | | 560 | db_free(list_ent, sizeof(*list_ent)); |
548 | return 0; | | 561 | return 0; |
549 | } | | 562 | } |
550 | } | | 563 | } |
551 | return ENOENT; | | 564 | return ENOENT; |
552 | } | | 565 | } |
553 | | | 566 | |
554 | #ifndef _KERNEL | | 567 | #ifndef _KERNEL |
555 | #define cnpollc(c) __nothing | | 568 | #define cnpollc(c) __nothing |
556 | #endif | | 569 | #endif |
557 | | | 570 | |
558 | /* | | 571 | /* |
559 | * This function is called via db_trap() or directly from | | 572 | * This function is called via db_trap() or directly from |
560 | * machine trap code. | | 573 | * machine trap code. |
561 | */ | | 574 | */ |
562 | void | | 575 | void |
563 | db_command_loop(void) | | 576 | db_command_loop(void) |
564 | { | | 577 | { |
565 | label_t db_jmpbuf; | | 578 | label_t db_jmpbuf; |
566 | label_t *savejmp; | | 579 | label_t *savejmp; |
567 | | | 580 | |
568 | /* | | 581 | /* |
569 | * Initialize 'prev' and 'next' to dot. | | 582 | * Initialize 'prev' and 'next' to dot. |
570 | */ | | 583 | */ |
571 | db_prev = db_dot; | | 584 | db_prev = db_dot; |
572 | db_next = db_dot; | | 585 | db_next = db_dot; |
573 | | | 586 | |
574 | db_cmd_loop_done = false; | | 587 | db_cmd_loop_done = false; |
575 | | | 588 | |
576 | /* Init default command tables add machine, base, | | 589 | /* Init default command tables add machine, base, |
577 | show command tables to the list */ | | 590 | show command tables to the list */ |
578 | db_init_commands(); | | 591 | db_init_commands(); |
579 | | | 592 | |
580 | /* save context for return from ddb */ | | 593 | /* save context for return from ddb */ |
581 | savejmp = db_recover; | | 594 | savejmp = db_recover; |
582 | db_recover = &db_jmpbuf; | | 595 | db_recover = &db_jmpbuf; |
583 | (void) setjmp(&db_jmpbuf); | | 596 | (void) setjmp(&db_jmpbuf); |
584 | | | 597 | |
585 | /* | | 598 | /* |
586 | * Execute default ddb start commands only if this is the | | 599 | * Execute default ddb start commands only if this is the |
587 | * first entry into DDB, in case the start commands fault | | 600 | * first entry into DDB, in case the start commands fault |
588 | * and we recurse into here. | | 601 | * and we recurse into here. |
589 | */ | | 602 | */ |
590 | if (!savejmp) | | 603 | if (!savejmp) |
591 | db_execute_commandlist(db_cmd_on_enter); | | 604 | db_execute_commandlist(db_cmd_on_enter); |
592 | | | 605 | |
593 | (void) setjmp(&db_jmpbuf); | | 606 | (void) setjmp(&db_jmpbuf); |
594 | while (!db_cmd_loop_done) { | | 607 | while (!db_cmd_loop_done) { |
595 | if (db_print_position() != 0) | | 608 | if (db_print_position() != 0) |
596 | db_printf("\n"); | | 609 | db_printf("\n"); |
597 | db_output_line = 0; | | 610 | db_output_line = 0; |
598 | cnpollc(1); | | 611 | cnpollc(1); |
599 | (void) db_read_line(); | | 612 | (void) db_read_line(); |
600 | cnpollc(0); | | 613 | cnpollc(0); |
601 | db_command(&db_last_command); | | 614 | db_command(&db_last_command); |
602 | } | | 615 | } |
603 | | | 616 | |
604 | db_recover = savejmp; | | 617 | db_recover = savejmp; |
605 | } | | 618 | } |
606 | | | 619 | |
607 | /* | | 620 | /* |
608 | * Search command table for command prefix | | 621 | * Search command table for command prefix |
609 | */ | | 622 | */ |
610 | static int | | 623 | static int |
611 | db_cmd_search_table(const char *name, | | 624 | db_cmd_search_table(const char *name, |
612 | const struct db_command *table, | | 625 | const struct db_command *table, |
613 | const struct db_command **cmdp) | | 626 | const struct db_command **cmdp) |
614 | { | | 627 | { |
615 | | | 628 | |
616 | const struct db_command *cmd; | | 629 | const struct db_command *cmd; |
617 | int result; | | 630 | int result; |
618 | | | 631 | |
619 | result = CMD_NONE; | | 632 | result = CMD_NONE; |
620 | *cmdp = NULL; | | 633 | *cmdp = NULL; |
621 | | | 634 | |
622 | for (cmd = table; cmd->name != 0; cmd++) { | | 635 | for (cmd = table; cmd->name != 0; cmd++) { |
623 | const char *lp; | | 636 | const char *lp; |
624 | const char *rp; | | 637 | const char *rp; |
625 | | | 638 | |
626 | lp = name; | | 639 | lp = name; |
627 | rp = cmd->name; | | 640 | rp = cmd->name; |
628 | while (*lp != '\0' && *lp == *rp) { | | 641 | while (*lp != '\0' && *lp == *rp) { |
629 | rp++; | | 642 | rp++; |
630 | lp++; | | 643 | lp++; |
631 | } | | 644 | } |
632 | | | 645 | |
633 | if (*lp != '\0') /* mismatch or extra chars in name */ | | 646 | if (*lp != '\0') /* mismatch or extra chars in name */ |
634 | continue; | | 647 | continue; |
635 | | | 648 | |
636 | if (*rp == '\0') { /* exact match */ | | 649 | if (*rp == '\0') { /* exact match */ |
637 | *cmdp = cmd; | | 650 | *cmdp = cmd; |
638 | return (CMD_EXACT); | | 651 | return (CMD_EXACT); |
639 | } | | 652 | } |
640 | | | 653 | |
641 | /* prefix match: end of name, not end of command */ | | 654 | /* prefix match: end of name, not end of command */ |
642 | if (result == CMD_NONE) { | | 655 | if (result == CMD_NONE) { |
643 | result = CMD_PREFIX; | | 656 | result = CMD_PREFIX; |
644 | *cmdp = cmd; | | 657 | *cmdp = cmd; |
645 | } | | 658 | } |
646 | else if (result == CMD_PREFIX) { | | 659 | else if (result == CMD_PREFIX) { |
647 | result = CMD_AMBIGUOUS; | | 660 | result = CMD_AMBIGUOUS; |
648 | *cmdp = NULL; | | 661 | *cmdp = NULL; |
649 | } | | 662 | } |
650 | } | | 663 | } |
651 | | | 664 | |
652 | return (result); | | 665 | return (result); |
653 | } | | 666 | } |
654 | | | 667 | |
655 | | | 668 | |
656 | /* | | 669 | /* |
657 | * Search list of command tables for command | | 670 | * Search list of command tables for command |
658 | */ | | 671 | */ |
659 | static int | | 672 | static int |
660 | db_cmd_search(const char *name, | | 673 | db_cmd_search(const char *name, |
661 | struct db_cmd_tbl_en_head *list_head, | | 674 | struct db_cmd_tbl_en_head *list_head, |
662 | const struct db_command **cmdp) | | 675 | const struct db_command **cmdp) |
663 | { | | 676 | { |
664 | struct db_cmd_tbl_en *list_ent; | | 677 | struct db_cmd_tbl_en *list_ent; |
665 | const struct db_command *found_command; | | 678 | const struct db_command *found_command; |
666 | bool accept_prefix_match; | | 679 | bool accept_prefix_match; |
667 | int result; | | 680 | int result; |
668 | | | 681 | |
669 | result = CMD_NONE; | | 682 | result = CMD_NONE; |
670 | found_command = NULL; | | 683 | found_command = NULL; |
671 | accept_prefix_match = true; | | 684 | accept_prefix_match = true; |
672 | | | 685 | |
673 | TAILQ_FOREACH(list_ent, list_head, db_cmd_next) { | | 686 | TAILQ_FOREACH(list_ent, list_head, db_cmd_next) { |
674 | const struct db_command *cmd; | | 687 | const struct db_command *cmd; |
675 | int found; | | 688 | int found; |
676 | | | 689 | |
677 | found = db_cmd_search_table(name, list_ent->db_cmd, &cmd); | | 690 | found = db_cmd_search_table(name, list_ent->db_cmd, &cmd); |
678 | if (found == CMD_EXACT) { | | 691 | if (found == CMD_EXACT) { |
679 | result = CMD_EXACT; | | 692 | result = CMD_EXACT; |
680 | found_command = cmd; | | 693 | found_command = cmd; |
681 | break; | | 694 | break; |
682 | } | | 695 | } |
683 | | | 696 | |
684 | if (found == CMD_PREFIX) { | | 697 | if (found == CMD_PREFIX) { |
685 | if (accept_prefix_match) { | | 698 | if (accept_prefix_match) { |
686 | /* | | 699 | /* |
687 | * Continue search, but note current result | | 700 | * Continue search, but note current result |
688 | * in case we won't find anything else. | | 701 | * in case we won't find anything else. |
689 | */ | | 702 | */ |
690 | accept_prefix_match = false; | | 703 | accept_prefix_match = false; |
691 | result = CMD_PREFIX; | | 704 | result = CMD_PREFIX; |
692 | found_command = cmd; | | 705 | found_command = cmd; |
693 | } else { | | 706 | } else { |
694 | /* | | 707 | /* |
695 | * Watch out for globally ambiguous | | 708 | * Watch out for globally ambiguous |
696 | * prefix match that is not locally | | 709 | * prefix match that is not locally |
697 | * ambiguous - with one match in one | | 710 | * ambiguous - with one match in one |
698 | * table and another match(es) in | | 711 | * table and another match(es) in |
699 | * another table. | | 712 | * another table. |
700 | */ | | 713 | */ |
701 | result = CMD_AMBIGUOUS; | | 714 | result = CMD_AMBIGUOUS; |
702 | found_command = NULL; | | 715 | found_command = NULL; |
703 | } | | 716 | } |
704 | } | | 717 | } |
705 | else if (found == CMD_AMBIGUOUS) { | | 718 | else if (found == CMD_AMBIGUOUS) { |
706 | accept_prefix_match = false; | | 719 | accept_prefix_match = false; |
707 | result = CMD_AMBIGUOUS; | | 720 | result = CMD_AMBIGUOUS; |
708 | found_command = NULL; | | 721 | found_command = NULL; |
709 | } | | 722 | } |
710 | } | | 723 | } |
711 | | | 724 | |
712 | *cmdp = found_command; | | 725 | *cmdp = found_command; |
713 | return result; | | 726 | return result; |
714 | } | | 727 | } |
715 | | | 728 | |
716 | static void | | 729 | static void |
717 | db_cmd_search_failed(char *name, int search_result) | | 730 | db_cmd_search_failed(char *name, int search_result) |
718 | { | | 731 | { |
719 | if (search_result == CMD_NONE) | | 732 | if (search_result == CMD_NONE) |
720 | db_printf("No such command: %s\n", name); | | 733 | db_printf("No such command: %s\n", name); |
721 | else | | 734 | else |
722 | db_printf("Ambiguous command: %s\n", name); | | 735 | db_printf("Ambiguous command: %s\n", name); |
723 | } | | 736 | } |
724 | | | 737 | |
725 | | | 738 | |
726 | /* | | 739 | /* |
727 | * List commands to the console. | | 740 | * List commands to the console. |
728 | */ | | 741 | */ |
729 | static void | | 742 | static void |
730 | db_cmd_list(const struct db_cmd_tbl_en_head *list) | | 743 | db_cmd_list(const struct db_cmd_tbl_en_head *list) |
731 | { | | 744 | { |
732 | | | 745 | |
733 | struct db_cmd_tbl_en *list_ent; | | 746 | struct db_cmd_tbl_en *list_ent; |
734 | const struct db_command *table; | | 747 | const struct db_command *table; |
735 | size_t i, j, w, columns, lines, numcmds, width=0; | | 748 | size_t i, j, w, columns, lines, numcmds, width=0; |
736 | const char *p; | | 749 | const char *p; |
737 | | | 750 | |
738 | TAILQ_FOREACH(list_ent,list,db_cmd_next) { | | 751 | TAILQ_FOREACH(list_ent,list,db_cmd_next) { |
739 | table = list_ent->db_cmd; | | 752 | table = list_ent->db_cmd; |
740 | for (i = 0; table[i].name != NULL; i++) { | | 753 | for (i = 0; table[i].name != NULL; i++) { |
741 | w = strlen(table[i].name); | | 754 | w = strlen(table[i].name); |
742 | if (w > width) | | 755 | if (w > width) |
743 | width = w; | | 756 | width = w; |
744 | } | | 757 | } |
745 | } | | 758 | } |
746 | | | 759 | |
747 | width = DB_NEXT_TAB(width); | | 760 | width = DB_NEXT_TAB(width); |
748 | | | 761 | |
749 | columns = db_max_width / width; | | 762 | columns = db_max_width / width; |
750 | if (columns == 0) | | 763 | if (columns == 0) |
751 | columns = 1; | | 764 | columns = 1; |
752 | | | 765 | |
753 | TAILQ_FOREACH(list_ent,list,db_cmd_next) { | | 766 | TAILQ_FOREACH(list_ent,list,db_cmd_next) { |
754 | table = list_ent->db_cmd; | | 767 | table = list_ent->db_cmd; |
755 | | | 768 | |
756 | for (numcmds = 0; table[numcmds].name != NULL; numcmds++) | | 769 | for (numcmds = 0; table[numcmds].name != NULL; numcmds++) |
757 | ; | | 770 | ; |
758 | lines = (numcmds + columns - 1) / columns; | | 771 | lines = (numcmds + columns - 1) / columns; |
759 | | | 772 | |
760 | for (i = 0; i < lines; i++) { | | 773 | for (i = 0; i < lines; i++) { |
761 | for (j = 0; j < columns; j++) { | | 774 | for (j = 0; j < columns; j++) { |
762 | p = table[j * lines + i].name; | | 775 | p = table[j * lines + i].name; |
763 | if (p) | | 776 | if (p) |
764 | db_printf("%s", p); | | 777 | db_printf("%s", p); |
765 | if (j * lines + i + lines >= numcmds) { | | 778 | if (j * lines + i + lines >= numcmds) { |
766 | db_putchar('\n'); | | 779 | db_putchar('\n'); |
767 | break; | | 780 | break; |
768 | } | | 781 | } |
769 | if (p) { | | 782 | if (p) { |
770 | w = strlen(p); | | 783 | w = strlen(p); |
771 | while (w < width) { | | 784 | while (w < width) { |
772 | w = DB_NEXT_TAB(w); | | 785 | w = DB_NEXT_TAB(w); |
773 | db_putchar('\t'); | | 786 | db_putchar('\t'); |
774 | } | | 787 | } |
775 | } | | 788 | } |
776 | } | | 789 | } |
777 | } | | 790 | } |
778 | } | | 791 | } |
779 | return; | | 792 | return; |
780 | } | | 793 | } |
781 | | | 794 | |
782 | /* | | 795 | /* |
783 | * Read complete command with all subcommands, starting with current | | 796 | * Read complete command with all subcommands, starting with current |
784 | * db_tok_string. If subcommand is missing, print the list of all | | 797 | * db_tok_string. If subcommand is missing, print the list of all |
785 | * subcommands. If command/subcommand is not found, print an error | | 798 | * subcommands. If command/subcommand is not found, print an error |
786 | * message. Returns pointer to "leaf" command or NULL. | | 799 | * message. Returns pointer to "leaf" command or NULL. |
787 | */ | | 800 | */ |
788 | static const struct db_command * | | 801 | static const struct db_command * |
789 | db_read_command(void) | | 802 | db_read_command(void) |
790 | { | | 803 | { |
791 | const struct db_command *command; | | 804 | const struct db_command *command; |
792 | struct db_cmd_tbl_en_head *list; | | 805 | struct db_cmd_tbl_en_head *list; |
793 | int found; | | 806 | int found; |
794 | int t; | | 807 | int t; |
795 | | | 808 | |
796 | list = &db_base_cmd_list; | | 809 | list = &db_base_cmd_list; |
797 | do { | | 810 | do { |
798 | found = db_cmd_search(db_tok_string, list, &command); | | 811 | found = db_cmd_search(db_tok_string, list, &command); |
799 | if (command == NULL) { | | 812 | if (command == NULL) { |
800 | db_cmd_search_failed(db_tok_string, found); | | 813 | db_cmd_search_failed(db_tok_string, found); |
801 | db_flush_lex(); | | 814 | db_flush_lex(); |
802 | return NULL; | | 815 | return NULL; |
803 | } | | 816 | } |
804 | | | 817 | |
805 | if (command->flag == CS_SHOW) | | 818 | if (command->flag == CS_SHOW) |
806 | list = &db_show_cmd_list; | | 819 | list = &db_show_cmd_list; |
807 | else if (command->flag == CS_MACH) | | 820 | else if (command->flag == CS_MACH) |
808 | list = &db_mach_cmd_list; | | 821 | list = &db_mach_cmd_list; |
809 | else if (command->flag == CS_COMPAT) | | 822 | else if (command->flag == CS_COMPAT) |
810 | /* same list */; | | 823 | /* same list */; |
811 | else | | 824 | else |
812 | break; /* expect no more subcommands */ | | 825 | break; /* expect no more subcommands */ |
813 | | | 826 | |
814 | t = db_read_token(); /* read subcommand */ | | 827 | t = db_read_token(); /* read subcommand */ |
815 | if (t != tIDENT) { | | 828 | if (t != tIDENT) { |
816 | /* if none given - just print all of them */ | | 829 | /* if none given - just print all of them */ |
817 | db_cmd_list(list); | | 830 | db_cmd_list(list); |
818 | db_flush_lex(); | | 831 | db_flush_lex(); |
819 | return NULL; | | 832 | return NULL; |
820 | } | | 833 | } |
821 | } while (list != NULL); | | 834 | } while (list != NULL); |
822 | | | 835 | |
823 | return command; | | 836 | return command; |
824 | } | | 837 | } |
825 | | | 838 | |
826 | /* | | 839 | /* |
827 | * Parse command line and execute apropriate function. | | 840 | * Parse command line and execute apropriate function. |
828 | */ | | 841 | */ |
829 | static void | | 842 | static void |
830 | db_command(const struct db_command **last_cmdp) | | 843 | db_command(const struct db_command **last_cmdp) |
831 | { | | 844 | { |
832 | static db_expr_t last_count = 0; | | 845 | static db_expr_t last_count = 0; |
833 | | | 846 | |
834 | int t; | | 847 | int t; |
835 | const struct db_command *command; | | 848 | const struct db_command *command; |
836 | db_expr_t addr, count; | | 849 | db_expr_t addr, count; |
837 | bool have_addr; | | 850 | bool have_addr; |
838 | char modif[TOK_STRING_SIZE]; | | 851 | char modif[TOK_STRING_SIZE]; |
839 | | | 852 | |
840 | command = NULL; | | 853 | command = NULL; |
841 | have_addr = false; | | 854 | have_addr = false; |
842 | count = -1; | | 855 | count = -1; |
843 | | | 856 | |
844 | t = db_read_token(); | | 857 | t = db_read_token(); |
845 | if ((t == tEOL) || (t == tCOMMA)) { | | 858 | if ((t == tEOL) || (t == tCOMMA)) { |
846 | /* | | 859 | /* |
847 | * An empty line repeats last command, at 'next'. | | 860 | * An empty line repeats last command, at 'next'. |
848 | * Only a count repeats the last command with the new count. | | 861 | * Only a count repeats the last command with the new count. |
849 | */ | | 862 | */ |
850 | command = *last_cmdp; | | 863 | command = *last_cmdp; |
851 | | | 864 | |
852 | if (!command) | | 865 | if (!command) |
853 | return; | | 866 | return; |
854 | | | 867 | |
855 | addr = (db_expr_t)db_next; | | 868 | addr = (db_expr_t)db_next; |
856 | if (t == tCOMMA) { | | 869 | if (t == tCOMMA) { |
857 | if (!db_expression(&count)) { | | 870 | if (!db_expression(&count)) { |
858 | db_printf("Count missing\n"); | | 871 | db_printf("Count missing\n"); |
859 | db_flush_lex(); | | 872 | db_flush_lex(); |
860 | return; | | 873 | return; |
861 | } | | 874 | } |
862 | } else | | 875 | } else |
863 | count = last_count; | | 876 | count = last_count; |
864 | modif[0] = '\0'; | | 877 | modif[0] = '\0'; |
865 | db_skip_to_eol(); | | 878 | db_skip_to_eol(); |
866 | | | 879 | |
867 | } else if (t == tEXCL) { | | 880 | } else if (t == tEXCL) { |
868 | db_fncall(0, 0, 0, NULL); | | 881 | db_fncall(0, 0, 0, NULL); |
869 | return; | | 882 | return; |
870 | | | 883 | |
871 | } else if (t != tIDENT) { | | 884 | } else if (t != tIDENT) { |
872 | db_printf("?\n"); | | 885 | db_printf("?\n"); |
873 | db_flush_lex(); | | 886 | db_flush_lex(); |
874 | return; | | 887 | return; |
875 | | | 888 | |
876 | } else { | | 889 | } else { |
877 | | | 890 | |
878 | command = db_read_command(); | | 891 | command = db_read_command(); |
879 | if (command == NULL) | | 892 | if (command == NULL) |
880 | return; | | 893 | return; |
881 | | | 894 | |
882 | if ((command->flag & CS_OWN) == 0) { | | 895 | if ((command->flag & CS_OWN) == 0) { |
883 | | | 896 | |
884 | /* | | 897 | /* |
885 | * Standard syntax: | | 898 | * Standard syntax: |
886 | * command [/modifier] [addr] [,count] | | 899 | * command [/modifier] [addr] [,count] |
887 | */ | | 900 | */ |
888 | t = db_read_token(); /* get modifier */ | | 901 | t = db_read_token(); /* get modifier */ |
889 | if (t == tSLASH) { | | 902 | if (t == tSLASH) { |
890 | t = db_read_token(); | | 903 | t = db_read_token(); |
891 | if (t != tIDENT) { | | 904 | if (t != tIDENT) { |
892 | db_printf("Bad modifier\n"); | | 905 | db_printf("Bad modifier\n"); |
893 | db_flush_lex(); | | 906 | db_flush_lex(); |
894 | return; | | 907 | return; |
895 | } | | 908 | } |
896 | /* save modifier */ | | 909 | /* save modifier */ |
897 | strlcpy(modif, db_tok_string, sizeof(modif)); | | 910 | strlcpy(modif, db_tok_string, sizeof(modif)); |
898 | | | 911 | |
899 | } else { | | 912 | } else { |
900 | db_unread_token(t); | | 913 | db_unread_token(t); |
901 | modif[0] = '\0'; | | 914 | modif[0] = '\0'; |
902 | } | | 915 | } |
903 | | | 916 | |
904 | if (db_expression(&addr)) { /*get address*/ | | 917 | if (db_expression(&addr)) { /*get address*/ |
905 | db_dot = (db_addr_t) addr; | | 918 | db_dot = (db_addr_t) addr; |
906 | db_last_addr = db_dot; | | 919 | db_last_addr = db_dot; |
907 | have_addr = true; | | 920 | have_addr = true; |
908 | } else { | | 921 | } else { |
909 | addr = (db_expr_t) db_dot; | | 922 | addr = (db_expr_t) db_dot; |
910 | } | | 923 | } |
911 | | | 924 | |
912 | t = db_read_token(); | | 925 | t = db_read_token(); |
913 | if (t == tCOMMA) { /*Get count*/ | | 926 | if (t == tCOMMA) { /*Get count*/ |
914 | if (!db_expression(&count)) { | | 927 | if (!db_expression(&count)) { |
915 | db_printf("Count missing\n"); | | 928 | db_printf("Count missing\n"); |
916 | db_flush_lex(); | | 929 | db_flush_lex(); |
917 | return; | | 930 | return; |
918 | } | | 931 | } |
919 | } else { | | 932 | } else { |
920 | db_unread_token(t); | | 933 | db_unread_token(t); |
921 | } | | 934 | } |
922 | if ((command->flag & CS_MORE) == 0) { | | 935 | if ((command->flag & CS_MORE) == 0) { |
923 | db_skip_to_eol(); | | 936 | db_skip_to_eol(); |
924 | } | | 937 | } |
925 | } | | 938 | } |
926 | } | | 939 | } |
927 | | | 940 | |
928 | if (command != NULL && command->flag & CS_NOREPEAT) { | | 941 | if (command != NULL && command->flag & CS_NOREPEAT) { |
929 | *last_cmdp = NULL; | | 942 | *last_cmdp = NULL; |
930 | last_count = 0; | | 943 | last_count = 0; |
931 | } else { | | 944 | } else { |
932 | *last_cmdp = command; | | 945 | *last_cmdp = command; |
933 | last_count = count; | | 946 | last_count = count; |
934 | } | | 947 | } |
935 | | | 948 | |
936 | | | 949 | |
937 | if (command != NULL) { | | 950 | if (command != NULL) { |
938 | /* | | 951 | /* |
939 | * Execute the command. | | 952 | * Execute the command. |
940 | */ | | 953 | */ |
941 | if (command->fcn != NULL) | | 954 | if (command->fcn != NULL) |
942 | (*command->fcn)(addr, have_addr, count, modif); | | 955 | (*command->fcn)(addr, have_addr, count, modif); |
943 | | | 956 | |
944 | if (command->flag & CS_SET_DOT) { | | 957 | if (command->flag & CS_SET_DOT) { |
945 | /* | | 958 | /* |
946 | * If command changes dot, set dot to | | 959 | * If command changes dot, set dot to |
947 | * previous address displayed (if 'ed' style). | | 960 | * previous address displayed (if 'ed' style). |
948 | */ | | 961 | */ |
949 | if (db_ed_style) | | 962 | if (db_ed_style) |
950 | db_dot = db_prev; | | 963 | db_dot = db_prev; |
951 | else | | 964 | else |
952 | db_dot = db_next; | | 965 | db_dot = db_next; |
953 | } else { | | 966 | } else { |
954 | /* | | 967 | /* |
955 | * If command does not change dot, | | 968 | * If command does not change dot, |
956 | * set 'next' location to be the same. | | 969 | * set 'next' location to be the same. |
957 | */ | | 970 | */ |
958 | db_next = db_dot; | | 971 | db_next = db_dot; |
959 | } | | 972 | } |
960 | } | | 973 | } |
961 | } | | 974 | } |
962 | | | 975 | |
963 | /* | | 976 | /* |
964 | * Print help for commands | | 977 | * Print help for commands |
965 | */ | | 978 | */ |
966 | static void | | 979 | static void |
967 | db_help_print_cmd(db_expr_t addr, bool have_addr, db_expr_t count, | | 980 | db_help_print_cmd(db_expr_t addr, bool have_addr, db_expr_t count, |
968 | const char *modif) | | 981 | const char *modif) |
969 | { | | 982 | { |
970 | const struct db_command *command; | | 983 | const struct db_command *command; |
971 | int t; | | 984 | int t; |
972 | | | 985 | |
973 | t = db_read_token(); | | 986 | t = db_read_token(); |
974 | | | 987 | |
975 | /* is there another command after the "help"? */ | | 988 | /* is there another command after the "help"? */ |
976 | if (t != tIDENT) { | | 989 | if (t != tIDENT) { |
977 | /* print base commands */ | | 990 | /* print base commands */ |
978 | db_cmd_list(&db_base_cmd_list); | | 991 | db_cmd_list(&db_base_cmd_list); |
979 | return; | | 992 | return; |
980 | } | | 993 | } |
981 | | | 994 | |
982 | command = db_read_command(); | | 995 | command = db_read_command(); |
983 | if (command == NULL) | | 996 | if (command == NULL) |
984 | return; | | 997 | return; |
985 | | | 998 | |
986 | #ifdef DDB_VERBOSE_HELP | | 999 | #ifdef DDB_VERBOSE_HELP |
987 | db_printf("Command: %s\n", command->name); | | 1000 | db_printf("Command: %s\n", command->name); |
988 | if (command->cmd_descr != NULL) | | 1001 | if (command->cmd_descr != NULL) |
989 | db_printf(" Description: %s\n", command->cmd_descr); | | 1002 | db_printf(" Description: %s\n", command->cmd_descr); |
990 | if (command->cmd_arg != NULL) | | 1003 | if (command->cmd_arg != NULL) |
991 | db_printf(" Arguments: %s\n", command->cmd_arg); | | 1004 | db_printf(" Arguments: %s\n", command->cmd_arg); |
992 | if (command->cmd_arg_help != NULL) | | 1005 | if (command->cmd_arg_help != NULL) |
993 | db_printf(" Arguments description:\n%s\n", | | 1006 | db_printf(" Arguments description:\n%s\n", |
994 | command->cmd_arg_help); | | 1007 | command->cmd_arg_help); |
995 | if ((command->cmd_arg == NULL) && (command->cmd_descr == NULL)) | | 1008 | if ((command->cmd_arg == NULL) && (command->cmd_descr == NULL)) |
996 | db_printf(" No help message.\n"); | | 1009 | db_printf(" No help message.\n"); |
997 | #endif | | 1010 | #endif |
998 | | | 1011 | |
999 | db_skip_to_eol(); | | 1012 | db_skip_to_eol(); |
1000 | } | | 1013 | } |
1001 | | | 1014 | |
1002 | /*ARGSUSED*/ | | 1015 | /*ARGSUSED*/ |
1003 | static void | | 1016 | static void |
1004 | db_map_print_cmd(db_expr_t addr, bool have_addr, db_expr_t count, | | 1017 | db_map_print_cmd(db_expr_t addr, bool have_addr, db_expr_t count, |
1005 | const char *modif) | | 1018 | const char *modif) |
1006 | { | | 1019 | { |
1007 | #ifdef _KERNEL | | 1020 | #ifdef _KERNEL |
1008 | bool full = false; | | 1021 | bool full = false; |
1009 | | | 1022 | |
1010 | if (modif[0] == 'f') | | 1023 | if (modif[0] == 'f') |
1011 | full = true; | | 1024 | full = true; |
1012 | | | 1025 | |
1013 | if (have_addr == false) | | 1026 | if (have_addr == false) |
1014 | addr = (db_expr_t)(uintptr_t)db_read_ptr("kernel_map"); | | 1027 | addr = (db_expr_t)(uintptr_t)db_read_ptr("kernel_map"); |
1015 | | | 1028 | |
1016 | uvm_map_printit((struct vm_map *)(uintptr_t) addr, full, db_printf); | | 1029 | uvm_map_printit((struct vm_map *)(uintptr_t) addr, full, db_printf); |
1017 | #else | | 1030 | #else |
1018 | db_kernelonly(); | | 1031 | db_kernelonly(); |
1019 | #endif /* XXX CRASH(8) */ | | 1032 | #endif /* XXX CRASH(8) */ |
1020 | } | | 1033 | } |
1021 | | | 1034 | |
1022 | /*ARGSUSED*/ | | 1035 | /*ARGSUSED*/ |
1023 | static void | | 1036 | static void |
1024 | db_object_print_cmd(db_expr_t addr, bool have_addr, | | 1037 | db_object_print_cmd(db_expr_t addr, bool have_addr, |
1025 | db_expr_t count, const char *modif) | | 1038 | db_expr_t count, const char *modif) |
1026 | { | | 1039 | { |
1027 | #ifdef _KERNEL /* XXX CRASH(8) */ | | 1040 | #ifdef _KERNEL /* XXX CRASH(8) */ |
1028 | bool full = false; | | 1041 | bool full = false; |
1029 | | | 1042 | |
1030 | if (modif[0] == 'f') | | 1043 | if (modif[0] == 'f') |
1031 | full = true; | | 1044 | full = true; |
1032 | | | 1045 | |
1033 | uvm_object_printit((struct uvm_object *)(uintptr_t) addr, full, | | 1046 | uvm_object_printit((struct uvm_object *)(uintptr_t) addr, full, |
1034 | db_printf); | | 1047 | db_printf); |
1035 | #else | | 1048 | #else |
1036 | db_kernelonly(); | | 1049 | db_kernelonly(); |
1037 | #endif | | 1050 | #endif |
1038 | } | | 1051 | } |
1039 | | | 1052 | |
1040 | /*ARGSUSED*/ | | 1053 | /*ARGSUSED*/ |
1041 | static void | | 1054 | static void |
1042 | db_page_print_cmd(db_expr_t addr, bool have_addr, | | 1055 | db_page_print_cmd(db_expr_t addr, bool have_addr, |
1043 | db_expr_t count, const char *modif) | | 1056 | db_expr_t count, const char *modif) |
1044 | { | | 1057 | { |
1045 | #ifdef _KERNEL /* XXX CRASH(8) */ | | 1058 | #ifdef _KERNEL /* XXX CRASH(8) */ |
1046 | bool full = false; | | 1059 | bool full = false; |
1047 | | | 1060 | |
1048 | if (modif[0] == 'f') | | 1061 | if (modif[0] == 'f') |
1049 | full = true; | | 1062 | full = true; |
1050 | | | 1063 | |
1051 | uvm_page_printit((struct vm_page *)(uintptr_t) addr, full, db_printf); | | 1064 | uvm_page_printit((struct vm_page *)(uintptr_t) addr, full, db_printf); |
1052 | #else | | 1065 | #else |
1053 | db_kernelonly(); | | 1066 | db_kernelonly(); |
1054 | #endif | | 1067 | #endif |
1055 | } | | 1068 | } |
1056 | | | 1069 | |
1057 | /*ARGSUSED*/ | | 1070 | /*ARGSUSED*/ |
1058 | static void | | 1071 | static void |
1059 | db_show_all_pages(db_expr_t addr, bool have_addr, | | 1072 | db_show_all_pages(db_expr_t addr, bool have_addr, |
1060 | db_expr_t count, const char *modif) | | 1073 | db_expr_t count, const char *modif) |
1061 | { | | 1074 | { |
1062 | | | 1075 | |
1063 | #ifdef _KERNEL /* XXX CRASH(8) */ | | 1076 | #ifdef _KERNEL /* XXX CRASH(8) */ |
1064 | uvm_page_printall(db_printf); | | 1077 | uvm_page_printall(db_printf); |
1065 | #else | | 1078 | #else |
1066 | db_kernelonly(); | | 1079 | db_kernelonly(); |
1067 | #endif | | 1080 | #endif |
1068 | } | | 1081 | } |
1069 | | | 1082 | |
1070 | /*ARGSUSED*/ | | 1083 | /*ARGSUSED*/ |
1071 | static void | | 1084 | static void |
1072 | db_buf_print_cmd(db_expr_t addr, bool have_addr, | | 1085 | db_buf_print_cmd(db_expr_t addr, bool have_addr, |
1073 | db_expr_t count, const char *modif) | | 1086 | db_expr_t count, const char *modif) |
1074 | { | | 1087 | { |
1075 | #ifdef _KERNEL /* XXX CRASH(8) */ | | 1088 | #ifdef _KERNEL /* XXX CRASH(8) */ |
1076 | bool full = false; | | 1089 | bool full = false; |
1077 | | | 1090 | |
1078 | if (modif[0] == 'f') | | 1091 | if (modif[0] == 'f') |
1079 | full = true; | | 1092 | full = true; |
1080 | | | 1093 | |
1081 | vfs_buf_print((struct buf *)(uintptr_t) addr, full, db_printf); | | 1094 | vfs_buf_print((struct buf *)(uintptr_t) addr, full, db_printf); |
1082 | #else | | 1095 | #else |
1083 | db_kernelonly(); | | 1096 | db_kernelonly(); |
1084 | #endif | | 1097 | #endif |
1085 | } | | 1098 | } |
1086 | | | 1099 | |
1087 | /*ARGSUSED*/ | | 1100 | /*ARGSUSED*/ |
1088 | static void | | 1101 | static void |
1089 | db_event_print_cmd(db_expr_t addr, bool have_addr, | | 1102 | db_event_print_cmd(db_expr_t addr, bool have_addr, |
1090 | db_expr_t count, const char *modif) | | 1103 | db_expr_t count, const char *modif) |
1091 | { | | 1104 | { |
1092 | bool showzero = false; | | 1105 | bool showzero = false; |
1093 | bool showall = true; | | 1106 | bool showall = true; |
1094 | bool showintr = false; | | 1107 | bool showintr = false; |
1095 | bool showtrap = false; | | 1108 | bool showtrap = false; |
1096 | bool showmisc = false; | | 1109 | bool showmisc = false; |
1097 | struct evcnt ev, *evp; | | 1110 | struct evcnt ev, *evp; |
1098 | char buf[80]; | | 1111 | char buf[80]; |
1099 | int i; | | 1112 | int i; |
1100 | | | 1113 | |
1101 | i = 0; | | 1114 | i = 0; |
1102 | while (modif[i]) { | | 1115 | while (modif[i]) { |
1103 | switch (modif[i]) { | | 1116 | switch (modif[i]) { |
1104 | case 'f': | | 1117 | case 'f': |
1105 | showzero = true; | | 1118 | showzero = true; |
1106 | break; | | 1119 | break; |
1107 | case 'i': | | 1120 | case 'i': |
1108 | showintr = true; | | 1121 | showintr = true; |
1109 | showall = false; | | 1122 | showall = false; |
1110 | break; | | 1123 | break; |
1111 | case 't': | | 1124 | case 't': |
1112 | showtrap = true; | | 1125 | showtrap = true; |
1113 | showall = false; | | 1126 | showall = false; |
1114 | break; | | 1127 | break; |
1115 | case 'm': | | 1128 | case 'm': |
1116 | showmisc = true; | | 1129 | showmisc = true; |
1117 | showall = false; | | 1130 | showall = false; |
1118 | break; | | 1131 | break; |
1119 | } | | 1132 | } |
1120 | i++; | | 1133 | i++; |
1121 | } | | 1134 | } |
1122 | | | 1135 | |
1123 | if (showall) | | 1136 | if (showall) |
1124 | showmisc = showintr = showtrap = true; | | 1137 | showmisc = showintr = showtrap = true; |
1125 | | | 1138 | |
1126 | evp = (struct evcnt *)db_read_ptr("allevents"); | | 1139 | evp = (struct evcnt *)db_read_ptr("allevents"); |
1127 | while (evp != NULL) { | | 1140 | while (evp != NULL) { |
1128 | db_read_bytes((db_addr_t)evp, sizeof(ev), (char *)&ev); | | 1141 | db_read_bytes((db_addr_t)evp, sizeof(ev), (char *)&ev); |
1129 | evp = ev.ev_list.tqe_next; | | 1142 | evp = ev.ev_list.tqe_next; |
1130 | if (ev.ev_count == 0 && !showzero) | | 1143 | if (ev.ev_count == 0 && !showzero) |
1131 | continue; | | 1144 | continue; |
1132 | if (ev.ev_type == EVCNT_TYPE_INTR && !showintr) | | 1145 | if (ev.ev_type == EVCNT_TYPE_INTR && !showintr) |
1133 | continue; | | 1146 | continue; |
1134 | if (ev.ev_type == EVCNT_TYPE_TRAP && !showtrap) | | 1147 | if (ev.ev_type == EVCNT_TYPE_TRAP && !showtrap) |
1135 | continue; | | 1148 | continue; |
1136 | if (ev.ev_type == EVCNT_TYPE_MISC && !showmisc) | | 1149 | if (ev.ev_type == EVCNT_TYPE_MISC && !showmisc) |
1137 | continue; | | 1150 | continue; |
1138 | db_read_bytes((db_addr_t)ev.ev_group, ev.ev_grouplen + 1, buf); | | 1151 | db_read_bytes((db_addr_t)ev.ev_group, ev.ev_grouplen + 1, buf); |
1139 | db_printf("evcnt type %d: %s ", ev.ev_type, buf); | | 1152 | db_printf("evcnt type %d: %s ", ev.ev_type, buf); |
1140 | db_read_bytes((db_addr_t)ev.ev_name, ev.ev_namelen + 1, buf); | | 1153 | db_read_bytes((db_addr_t)ev.ev_name, ev.ev_namelen + 1, buf); |
1141 | db_printf("%s = %lld\n", buf, (long long)ev.ev_count); | | 1154 | db_printf("%s = %lld\n", buf, (long long)ev.ev_count); |
1142 | } | | 1155 | } |
1143 | } | | 1156 | } |
1144 | | | 1157 | |
1145 | /*ARGSUSED*/ | | 1158 | /*ARGSUSED*/ |
1146 | static void | | 1159 | static void |
1147 | db_vnode_print_cmd(db_expr_t addr, bool have_addr, | | 1160 | db_vnode_print_cmd(db_expr_t addr, bool have_addr, |
1148 | db_expr_t count, const char *modif) | | 1161 | db_expr_t count, const char *modif) |
1149 | { | | 1162 | { |
1150 | #ifdef _KERNEL /* XXX CRASH(8) */ | | 1163 | #ifdef _KERNEL /* XXX CRASH(8) */ |
1151 | bool full = false; | | 1164 | bool full = false; |
1152 | | | 1165 | |
1153 | if (modif[0] == 'f') | | 1166 | if (modif[0] == 'f') |
1154 | full = true; | | 1167 | full = true; |
1155 | | | 1168 | |
1156 | vfs_vnode_print((struct vnode *)(uintptr_t) addr, full, db_printf); | | 1169 | vfs_vnode_print((struct vnode *)(uintptr_t) addr, full, db_printf); |
1157 | #else | | 1170 | #else |
1158 | db_kernelonly(); | | 1171 | db_kernelonly(); |
1159 | #endif | | 1172 | #endif |
1160 | } | | 1173 | } |
1161 | | | 1174 | |
1162 | /*ARGSUSED*/ | | 1175 | /*ARGSUSED*/ |
1163 | static void | | 1176 | static void |
1164 | db_vnode_lock_print_cmd(db_expr_t addr, bool have_addr, | | 1177 | db_vnode_lock_print_cmd(db_expr_t addr, bool have_addr, |
1165 | db_expr_t count, const char *modif) | | 1178 | db_expr_t count, const char *modif) |
1166 | { | | 1179 | { |
1167 | #ifdef _KERNEL /* XXX CRASH(8) */ | | 1180 | #ifdef _KERNEL /* XXX CRASH(8) */ |
1168 | bool full = false; | | 1181 | bool full = false; |
1169 | | | 1182 | |
1170 | if (modif[0] == 'f') | | 1183 | if (modif[0] == 'f') |
1171 | full = true; | | 1184 | full = true; |
1172 | | | 1185 | |
1173 | vfs_vnode_lock_print((struct vnode *)(uintptr_t) addr, full, db_printf); | | 1186 | vfs_vnode_lock_print((struct vnode *)(uintptr_t) addr, full, db_printf); |
1174 | #else | | 1187 | #else |
1175 | db_kernelonly(); | | 1188 | db_kernelonly(); |
1176 | #endif | | 1189 | #endif |
1177 | } | | 1190 | } |
1178 | | | 1191 | |
1179 | /*ARGSUSED*/ | | 1192 | /*ARGSUSED*/ |
1180 | static void | | 1193 | static void |
1181 | db_vmem_print_cmd(db_expr_t addr, bool have_addr, | | 1194 | db_vmem_print_cmd(db_expr_t addr, bool have_addr, |
1182 | db_expr_t count, const char *modif) | | 1195 | db_expr_t count, const char *modif) |
1183 | { | | 1196 | { |
1184 | | | 1197 | |
1185 | #ifdef _KERNEL /* XXX CRASH(8) */ | | 1198 | #ifdef _KERNEL /* XXX CRASH(8) */ |
1186 | vmem_print((uintptr_t) addr, modif, db_printf); | | 1199 | vmem_print((uintptr_t) addr, modif, db_printf); |
1187 | #else | | 1200 | #else |
1188 | db_kernelonly(); | | 1201 | db_kernelonly(); |
1189 | #endif | | 1202 | #endif |
1190 | } | | 1203 | } |
1191 | | | 1204 | |
1192 | static void | | 1205 | static void |
1193 | db_mount_print_cmd(db_expr_t addr, bool have_addr, | | 1206 | db_mount_print_cmd(db_expr_t addr, bool have_addr, |
1194 | db_expr_t count, const char *modif) | | 1207 | db_expr_t count, const char *modif) |
1195 | { | | 1208 | { |
1196 | #ifdef _KERNEL /* XXX CRASH(8) */ | | 1209 | #ifdef _KERNEL /* XXX CRASH(8) */ |
1197 | bool full = false; | | 1210 | bool full = false; |
1198 | | | 1211 | |
1199 | if (modif[0] == 'f') | | 1212 | if (modif[0] == 'f') |
1200 | full = true; | | 1213 | full = true; |
1201 | | | 1214 | |
1202 | vfs_mount_print((struct mount *)(uintptr_t) addr, full, db_printf); | | 1215 | vfs_mount_print((struct mount *)(uintptr_t) addr, full, db_printf); |
1203 | #endif | | 1216 | #endif |
1204 | } | | 1217 | } |
1205 | | | 1218 | |
1206 | static void | | 1219 | static void |
1207 | db_show_all_mount(db_expr_t addr, bool have_addr, db_expr_t count, const char *modif) | | 1220 | db_show_all_mount(db_expr_t addr, bool have_addr, db_expr_t count, const char *modif) |
1208 | { | | 1221 | { |
1209 | #ifdef _KERNEL /* XXX CRASH(8) */ | | 1222 | #ifdef _KERNEL /* XXX CRASH(8) */ |
1210 | bool full = false; | | 1223 | bool full = false; |
1211 | | | 1224 | |
1212 | if (modif[0] == 'f') | | 1225 | if (modif[0] == 'f') |
1213 | full = true; | | 1226 | full = true; |
1214 | | | 1227 | |
1215 | vfs_mount_print_all(full, db_printf); | | 1228 | vfs_mount_print_all(full, db_printf); |
1216 | #else | | 1229 | #else |
1217 | db_kernelonly(); | | 1230 | db_kernelonly(); |
1218 | #endif | | 1231 | #endif |
1219 | } | | 1232 | } |
1220 | | | 1233 | |
1221 | /*ARGSUSED*/ | | 1234 | /*ARGSUSED*/ |
1222 | static void | | 1235 | static void |
1223 | db_mbuf_print_cmd(db_expr_t addr, bool have_addr, | | 1236 | db_mbuf_print_cmd(db_expr_t addr, bool have_addr, |
1224 | db_expr_t count, const char *modif) | | 1237 | db_expr_t count, const char *modif) |
1225 | { | | 1238 | { |
1226 | | | 1239 | |
1227 | #ifdef _KERNEL /* XXX CRASH(8) */ | | 1240 | #ifdef _KERNEL /* XXX CRASH(8) */ |
1228 | m_print((const struct mbuf *)(uintptr_t) addr, modif, db_printf); | | 1241 | m_print((const struct mbuf *)(uintptr_t) addr, modif, db_printf); |
1229 | #else | | 1242 | #else |
1230 | db_kernelonly(); | | 1243 | db_kernelonly(); |
1231 | #endif | | 1244 | #endif |
1232 | } | | 1245 | } |
1233 | | | 1246 | |
1234 | /*ARGSUSED*/ | | 1247 | /*ARGSUSED*/ |
1235 | static void | | 1248 | static void |
1236 | db_pool_print_cmd(db_expr_t addr, bool have_addr, | | 1249 | db_pool_print_cmd(db_expr_t addr, bool have_addr, |
1237 | db_expr_t count, const char *modif) | | 1250 | db_expr_t count, const char *modif) |
1238 | { | | 1251 | { |
1239 | | | 1252 | |
1240 | #ifdef _KERNEL /* XXX CRASH(8) */ | | 1253 | #ifdef _KERNEL /* XXX CRASH(8) */ |
1241 | pool_printit((struct pool *)(uintptr_t) addr, modif, db_printf); | | 1254 | pool_printit((struct pool *)(uintptr_t) addr, modif, db_printf); |
1242 | #else | | 1255 | #else |
1243 | db_kernelonly(); | | 1256 | db_kernelonly(); |
1244 | #endif | | 1257 | #endif |
1245 | } | | 1258 | } |
1246 | | | 1259 | |
1247 | /*ARGSUSED*/ | | 1260 | /*ARGSUSED*/ |
1248 | static void | | 1261 | static void |
1249 | db_namecache_print_cmd(db_expr_t addr, bool have_addr, | | 1262 | db_namecache_print_cmd(db_expr_t addr, bool have_addr, |
1250 | db_expr_t count, const char *modif) | | 1263 | db_expr_t count, const char *modif) |
1251 | { | | 1264 | { |
1252 | | | 1265 | |
1253 | #ifdef _KERNEL /* XXX CRASH(8) */ | | 1266 | #ifdef _KERNEL /* XXX CRASH(8) */ |
1254 | namecache_print((struct vnode *)(uintptr_t) addr, db_printf); | | 1267 | namecache_print((struct vnode *)(uintptr_t) addr, db_printf); |
1255 | #else | | 1268 | #else |
1256 | db_kernelonly(); | | 1269 | db_kernelonly(); |
1257 | #endif | | 1270 | #endif |
1258 | } | | 1271 | } |
1259 | | | 1272 | |
1260 | /*ARGSUSED*/ | | 1273 | /*ARGSUSED*/ |
1261 | static void | | 1274 | static void |
1262 | db_uvmexp_print_cmd(db_expr_t addr, bool have_addr, | | 1275 | db_uvmexp_print_cmd(db_expr_t addr, bool have_addr, |
1263 | db_expr_t count, const char *modif) | | 1276 | db_expr_t count, const char *modif) |
1264 | { | | 1277 | { |
1265 | | | 1278 | |
1266 | #ifdef _KERNEL /* XXX CRASH(8) */ | | 1279 | #ifdef _KERNEL /* XXX CRASH(8) */ |
1267 | uvmexp_print(db_printf); | | 1280 | uvmexp_print(db_printf); |
1268 | #else | | 1281 | #else |
1269 | db_kernelonly(); | | 1282 | db_kernelonly(); |
1270 | #endif | | 1283 | #endif |
1271 | } | | 1284 | } |
1272 | | | 1285 | |
1273 | /*ARGSUSED */ | | 1286 | /*ARGSUSED */ |
1274 | static void | | 1287 | static void |
1275 | db_socket_print_cmd(db_expr_t addr, bool have_addr, db_expr_t count, | | 1288 | db_socket_print_cmd(db_expr_t addr, bool have_addr, db_expr_t count, |
1276 | const char *modif) | | 1289 | const char *modif) |
1277 | { | | 1290 | { |
1278 | | | 1291 | |
1279 | #ifdef _KERNEL /* XXX CRASH(8) */ | | 1292 | #ifdef _KERNEL /* XXX CRASH(8) */ |
1280 | socket_print(modif, db_printf); | | 1293 | socket_print(modif, db_printf); |
1281 | #else | | 1294 | #else |
1282 | db_kernelonly(); | | 1295 | db_kernelonly(); |
1283 | #endif | | 1296 | #endif |
1284 | } | | 1297 | } |
1285 | | | 1298 | |
1286 | #ifdef KERNHIST | | 1299 | #ifdef KERNHIST |
1287 | /*ARGSUSED*/ | | 1300 | /*ARGSUSED*/ |
1288 | static void | | 1301 | static void |
1289 | db_kernhist_print_cmd(db_expr_t addr, bool have_addr, | | 1302 | db_kernhist_print_cmd(db_expr_t addr, bool have_addr, |
1290 | db_expr_t count, const char *modif) | | 1303 | db_expr_t count, const char *modif) |
1291 | { | | 1304 | { |
1292 | | | 1305 | |
1293 | if (!have_addr) | | 1306 | if (!have_addr) |
1294 | addr = 0; | | 1307 | addr = 0; |
1295 | | | 1308 | |
1296 | if (count == -1) | | 1309 | if (count == -1) |
1297 | count = 0; | | 1310 | count = 0; |
1298 | | | 1311 | |
1299 | kernhist_print((void *)(uintptr_t)addr, count, modif, db_printf); | | 1312 | kernhist_print((void *)(uintptr_t)addr, count, modif, db_printf); |
1300 | } | | 1313 | } |
1301 | #endif | | 1314 | #endif |
1302 | | | 1315 | |
1303 | /*ARGSUSED*/ | | 1316 | /*ARGSUSED*/ |
1304 | static void | | 1317 | static void |
1305 | db_lock_print_cmd(db_expr_t addr, bool have_addr, | | 1318 | db_lock_print_cmd(db_expr_t addr, bool have_addr, |
1306 | db_expr_t count, const char *modif) | | 1319 | db_expr_t count, const char *modif) |
1307 | { | | 1320 | { |
1308 | | | 1321 | |
1309 | lockdebug_lock_print(have_addr ? (void *)(uintptr_t)addr : NULL, | | 1322 | lockdebug_lock_print(have_addr ? (void *)(uintptr_t)addr : NULL, |
1310 | db_printf); | | 1323 | db_printf); |
1311 | } | | 1324 | } |
1312 | | | 1325 | |
1313 | static void | | 1326 | static void |
1314 | db_show_all_locks(db_expr_t addr, bool have_addr, | | 1327 | db_show_all_locks(db_expr_t addr, bool have_addr, |
1315 | db_expr_t count, const char *modif) | | 1328 | db_expr_t count, const char *modif) |
1316 | { | | 1329 | { |
1317 | | | 1330 | |
1318 | #ifdef _KERNEL /* XXX CRASH(8) */ | | 1331 | #ifdef _KERNEL /* XXX CRASH(8) */ |
1319 | lockdebug_show_all_locks(db_printf, modif); | | 1332 | lockdebug_show_all_locks(db_printf, modif); |
1320 | #else | | 1333 | #else |
1321 | db_kernelonly(); | | 1334 | db_kernelonly(); |
1322 | #endif | | 1335 | #endif |
1323 | } | | 1336 | } |
1324 | | | 1337 | |
1325 | static void | | 1338 | static void |
1326 | db_show_all_freelists(db_expr_t addr, bool have_addr, | | 1339 | db_show_all_freelists(db_expr_t addr, bool have_addr, |
1327 | db_expr_t count, const char *modif) | | 1340 | db_expr_t count, const char *modif) |
1328 | { | | 1341 | { |
1329 | | | 1342 | |
1330 | #ifdef _KERNEL /* XXX CRASH(8) */ | | 1343 | #ifdef _KERNEL /* XXX CRASH(8) */ |
1331 | uvm_page_print_freelists(db_printf); | | 1344 | uvm_page_print_freelists(db_printf); |
1332 | #else | | 1345 | #else |
1333 | db_kernelonly(); | | 1346 | db_kernelonly(); |
1334 | #endif | | 1347 | #endif |
1335 | } | | 1348 | } |
1336 | | | 1349 | |
1337 | static void | | 1350 | static void |
1338 | db_show_lockstats(db_expr_t addr, bool have_addr, | | 1351 | db_show_lockstats(db_expr_t addr, bool have_addr, |
1339 | db_expr_t count, const char *modif) | | 1352 | db_expr_t count, const char *modif) |
1340 | { | | 1353 | { |
1341 | | | 1354 | |
1342 | #ifdef _KERNEL /* XXX CRASH(8) */ | | 1355 | #ifdef _KERNEL /* XXX CRASH(8) */ |
1343 | lockdebug_show_lockstats(db_printf); | | 1356 | lockdebug_show_lockstats(db_printf); |
1344 | #else | | 1357 | #else |
1345 | db_kernelonly(); | | 1358 | db_kernelonly(); |
1346 | #endif | | 1359 | #endif |
1347 | } | | 1360 | } |
1348 | | | 1361 | |
| | | 1362 | #ifdef FDT |
| | | 1363 | /*ARGSUSED*/ |
| | | 1364 | static void |
| | | 1365 | db_fdt_print_cmd(db_expr_t addr, bool have_addr, |
| | | 1366 | db_expr_t count, const char *modif) |
| | | 1367 | { |
| | | 1368 | #ifdef _KERNEL /* XXX CRASH(8) */ |
| | | 1369 | bool full = false; |
| | | 1370 | |
| | | 1371 | if (modif[0] == 'f') |
| | | 1372 | full = true; |
| | | 1373 | |
| | | 1374 | fdt_print(have_addr ? (void *)(uintptr_t)addr : fdtbus_get_data(), |
| | | 1375 | full, db_printf); |
| | | 1376 | #else |
| | | 1377 | also; |
| | | 1378 | db_kernelonly(); |
| | | 1379 | #endif |
| | | 1380 | } |
| | | 1381 | #endif |
| | | 1382 | |
1349 | /* | | 1383 | /* |
1350 | * Call random function: | | 1384 | * Call random function: |
1351 | * !expr(arg,arg,arg) | | 1385 | * !expr(arg,arg,arg) |
1352 | */ | | 1386 | */ |
1353 | /*ARGSUSED*/ | | 1387 | /*ARGSUSED*/ |
1354 | static void | | 1388 | static void |
1355 | db_fncall(db_expr_t addr, bool have_addr, | | 1389 | db_fncall(db_expr_t addr, bool have_addr, |
1356 | db_expr_t count, const char *modif) | | 1390 | db_expr_t count, const char *modif) |
1357 | { | | 1391 | { |
1358 | #ifdef _KERNEL | | 1392 | #ifdef _KERNEL |
1359 | db_expr_t fn_addr; | | 1393 | db_expr_t fn_addr; |
1360 | #define MAXARGS 11 | | 1394 | #define MAXARGS 11 |
1361 | db_expr_t args[MAXARGS]; | | 1395 | db_expr_t args[MAXARGS]; |
1362 | int nargs = 0; | | 1396 | int nargs = 0; |
1363 | db_expr_t retval; | | 1397 | db_expr_t retval; |
1364 | db_expr_t (*func)(db_expr_t, ...); | | 1398 | db_expr_t (*func)(db_expr_t, ...); |
1365 | int t; | | 1399 | int t; |
1366 | | | 1400 | |
1367 | if (!db_expression(&fn_addr)) { | | 1401 | if (!db_expression(&fn_addr)) { |
1368 | db_printf("Bad function\n"); | | 1402 | db_printf("Bad function\n"); |
1369 | db_flush_lex(); | | 1403 | db_flush_lex(); |
1370 | return; | | 1404 | return; |
1371 | } | | 1405 | } |
1372 | func = (db_expr_t (*)(db_expr_t, ...))(uintptr_t) fn_addr; | | 1406 | func = (db_expr_t (*)(db_expr_t, ...))(uintptr_t) fn_addr; |
1373 | | | 1407 | |
1374 | t = db_read_token(); | | 1408 | t = db_read_token(); |
1375 | if (t == tLPAREN) { | | 1409 | if (t == tLPAREN) { |
1376 | if (db_expression(&args[0])) { | | 1410 | if (db_expression(&args[0])) { |
1377 | nargs++; | | 1411 | nargs++; |
1378 | while ((t = db_read_token()) == tCOMMA) { | | 1412 | while ((t = db_read_token()) == tCOMMA) { |
1379 | if (nargs == MAXARGS) { | | 1413 | if (nargs == MAXARGS) { |
1380 | db_printf("Too many arguments\n"); | | 1414 | db_printf("Too many arguments\n"); |
1381 | db_flush_lex(); | | 1415 | db_flush_lex(); |
1382 | return; | | 1416 | return; |
1383 | } | | 1417 | } |
1384 | if (!db_expression(&args[nargs])) { | | 1418 | if (!db_expression(&args[nargs])) { |
1385 | db_printf("Argument missing\n"); | | 1419 | db_printf("Argument missing\n"); |
1386 | db_flush_lex(); | | 1420 | db_flush_lex(); |
1387 | return; | | 1421 | return; |
1388 | } | | 1422 | } |
1389 | nargs++; | | 1423 | nargs++; |
1390 | } | | 1424 | } |
1391 | db_unread_token(t); | | 1425 | db_unread_token(t); |
1392 | } | | 1426 | } |
1393 | if (db_read_token() != tRPAREN) { | | 1427 | if (db_read_token() != tRPAREN) { |
1394 | db_printf("?\n"); | | 1428 | db_printf("?\n"); |
1395 | db_flush_lex(); | | 1429 | db_flush_lex(); |
1396 | return; | | 1430 | return; |
1397 | } | | 1431 | } |
1398 | } | | 1432 | } |
1399 | db_skip_to_eol(); | | 1433 | db_skip_to_eol(); |
1400 | | | 1434 | |
1401 | while (nargs < MAXARGS) { | | 1435 | while (nargs < MAXARGS) { |
1402 | args[nargs++] = 0; | | 1436 | args[nargs++] = 0; |
1403 | } | | 1437 | } |
1404 | | | 1438 | |
1405 | retval = (*func)(args[0], args[1], args[2], args[3], args[4], | | 1439 | retval = (*func)(args[0], args[1], args[2], args[3], args[4], |
1406 | args[5], args[6], args[7], args[8], args[9]); | | 1440 | args[5], args[6], args[7], args[8], args[9]); |
1407 | db_printf("%s\n", db_num_to_str(retval)); | | 1441 | db_printf("%s\n", db_num_to_str(retval)); |
1408 | #else /* _KERNEL */ | | 1442 | #else /* _KERNEL */ |
1409 | db_kernelonly(); | | 1443 | db_kernelonly(); |
1410 | #endif /* _KERNEL */ | | 1444 | #endif /* _KERNEL */ |
1411 | } | | 1445 | } |
1412 | | | 1446 | |
1413 | static void | | 1447 | static void |
1414 | db_reboot_cmd(db_expr_t addr, bool have_addr, | | 1448 | db_reboot_cmd(db_expr_t addr, bool have_addr, |
1415 | db_expr_t count, const char *modif) | | 1449 | db_expr_t count, const char *modif) |
1416 | { | | 1450 | { |
1417 | #ifdef _KERNEL | | 1451 | #ifdef _KERNEL |
1418 | db_expr_t bootflags; | | 1452 | db_expr_t bootflags; |
1419 | | | 1453 | |
1420 | /* Flags, default to RB_AUTOBOOT */ | | 1454 | /* Flags, default to RB_AUTOBOOT */ |
1421 | if (!db_expression(&bootflags)) | | 1455 | if (!db_expression(&bootflags)) |
1422 | bootflags = (db_expr_t)RB_AUTOBOOT; | | 1456 | bootflags = (db_expr_t)RB_AUTOBOOT; |
1423 | if (db_read_token() != tEOL) { | | 1457 | if (db_read_token() != tEOL) { |
1424 | db_error("?\n"); | | 1458 | db_error("?\n"); |
1425 | /*NOTREACHED*/ | | 1459 | /*NOTREACHED*/ |
1426 | } | | 1460 | } |
1427 | /* | | 1461 | /* |
1428 | * We are leaving DDB, never to return upward. | | 1462 | * We are leaving DDB, never to return upward. |
1429 | * Clear db_recover so that we can debug faults in functions | | 1463 | * Clear db_recover so that we can debug faults in functions |
1430 | * called from cpu_reboot. | | 1464 | * called from cpu_reboot. |
1431 | */ | | 1465 | */ |
1432 | db_recover = 0; | | 1466 | db_recover = 0; |
1433 | /* Avoid all mutex errors */ | | 1467 | /* Avoid all mutex errors */ |
1434 | lockdebug_dismiss(); | | 1468 | lockdebug_dismiss(); |
1435 | panicstr = "reboot forced via kernel debugger"; | | 1469 | panicstr = "reboot forced via kernel debugger"; |
1436 | /* Make it possible to break into the debugger again */ | | 1470 | /* Make it possible to break into the debugger again */ |
1437 | spl0(); | | 1471 | spl0(); |
1438 | kern_reboot((int)bootflags, NULL); | | 1472 | kern_reboot((int)bootflags, NULL); |
1439 | #else /* _KERNEL */ | | 1473 | #else /* _KERNEL */ |
1440 | db_kernelonly(); | | 1474 | db_kernelonly(); |
1441 | #endif /* _KERNEL */ | | 1475 | #endif /* _KERNEL */ |
1442 | } | | 1476 | } |
1443 | | | 1477 | |
1444 | static void | | 1478 | static void |
1445 | db_sifting_cmd(db_expr_t addr, bool have_addr, | | 1479 | db_sifting_cmd(db_expr_t addr, bool have_addr, |
1446 | db_expr_t count, const char *modif) | | 1480 | db_expr_t count, const char *modif) |
1447 | { | | 1481 | { |
1448 | int mode, t; | | 1482 | int mode, t; |
1449 | | | 1483 | |
1450 | t = db_read_token(); | | 1484 | t = db_read_token(); |
1451 | if (t == tSLASH) { | | 1485 | if (t == tSLASH) { |
1452 | t = db_read_token(); | | 1486 | t = db_read_token(); |
1453 | if (t != tIDENT) { | | 1487 | if (t != tIDENT) { |
1454 | bad_modifier: | | 1488 | bad_modifier: |
1455 | db_printf("Bad modifier\n"); | | 1489 | db_printf("Bad modifier\n"); |
1456 | db_flush_lex(); | | 1490 | db_flush_lex(); |
1457 | return; | | 1491 | return; |
1458 | } | | 1492 | } |
1459 | if (!strcmp(db_tok_string, "F")) | | 1493 | if (!strcmp(db_tok_string, "F")) |
1460 | mode = 'F'; | | 1494 | mode = 'F'; |
1461 | else | | 1495 | else |
1462 | goto bad_modifier; | | 1496 | goto bad_modifier; |
1463 | t = db_read_token(); | | 1497 | t = db_read_token(); |
1464 | } else | | 1498 | } else |
1465 | mode = 0; | | 1499 | mode = 0; |
1466 | | | 1500 | |
1467 | if (t == tIDENT) | | 1501 | if (t == tIDENT) |
1468 | db_sifting(db_tok_string, mode); | | 1502 | db_sifting(db_tok_string, mode); |
1469 | else { | | 1503 | else { |
1470 | db_printf("Bad argument (non-string)\n"); | | 1504 | db_printf("Bad argument (non-string)\n"); |
1471 | db_flush_lex(); | | 1505 | db_flush_lex(); |
1472 | } | | 1506 | } |
1473 | } | | 1507 | } |
1474 | | | 1508 | |
1475 | static void | | 1509 | static void |
1476 | db_stack_trace_cmd(db_expr_t addr, bool have_addr, db_expr_t count, const char *modif) | | 1510 | db_stack_trace_cmd(db_expr_t addr, bool have_addr, db_expr_t count, const char *modif) |
1477 | { | | 1511 | { |
1478 | register const char *cp = modif; | | 1512 | register const char *cp = modif; |
1479 | register char c; | | 1513 | register char c; |
1480 | void (*pr)(const char *, ...); | | 1514 | void (*pr)(const char *, ...); |
1481 | | | 1515 | |
1482 | pr = db_printf; | | 1516 | pr = db_printf; |
1483 | while ((c = *cp++) != 0) | | 1517 | while ((c = *cp++) != 0) |
1484 | if (c == 'l') | | 1518 | if (c == 'l') |
1485 | pr = (void (*)(const char *, ...))printf; | | 1519 | pr = (void (*)(const char *, ...))printf; |
1486 | | | 1520 | |
1487 | if (count == -1) | | 1521 | if (count == -1) |
1488 | count = 65535; | | 1522 | count = 65535; |
1489 | | | 1523 | |
1490 | db_stack_trace_print(addr, have_addr, count, modif, pr); | | 1524 | db_stack_trace_print(addr, have_addr, count, modif, pr); |
1491 | } | | 1525 | } |
1492 | | | 1526 | |
1493 | static void | | 1527 | static void |
1494 | db_sync_cmd(db_expr_t addr, bool have_addr, | | 1528 | db_sync_cmd(db_expr_t addr, bool have_addr, |
1495 | db_expr_t count, const char *modif) | | 1529 | db_expr_t count, const char *modif) |
1496 | { | | 1530 | { |
1497 | #ifdef _KERNEL | | 1531 | #ifdef _KERNEL |
1498 | /* | | 1532 | /* |
1499 | * We are leaving DDB, never to return upward. | | 1533 | * We are leaving DDB, never to return upward. |
1500 | * Clear db_recover so that we can debug faults in functions | | 1534 | * Clear db_recover so that we can debug faults in functions |
1501 | * called from cpu_reboot. | | 1535 | * called from cpu_reboot. |
1502 | */ | | 1536 | */ |
1503 | db_recover = 0; | | 1537 | db_recover = 0; |
1504 | panicstr = "dump forced via kernel debugger"; | | 1538 | panicstr = "dump forced via kernel debugger"; |
1505 | kern_reboot(RB_DUMP, NULL); | | 1539 | kern_reboot(RB_DUMP, NULL); |
1506 | #else /* _KERNEL */ | | 1540 | #else /* _KERNEL */ |
1507 | db_kernelonly(); | | 1541 | db_kernelonly(); |
1508 | #endif /* _KERNEL */ | | 1542 | #endif /* _KERNEL */ |
1509 | } | | 1543 | } |
1510 | | | 1544 | |
1511 | /* | | 1545 | /* |
1512 | * Describe what an address is | | 1546 | * Describe what an address is |
1513 | */ | | 1547 | */ |
1514 | void | | 1548 | void |
1515 | db_whatis_cmd(db_expr_t address, bool have_addr, | | 1549 | db_whatis_cmd(db_expr_t address, bool have_addr, |
1516 | db_expr_t count, const char *modif) | | 1550 | db_expr_t count, const char *modif) |
1517 | { | | 1551 | { |
1518 | const uintptr_t addr = (uintptr_t)address; | | 1552 | const uintptr_t addr = (uintptr_t)address; |
1519 | | | 1553 | |
1520 | db_lwp_whatis(addr, db_printf); | | 1554 | db_lwp_whatis(addr, db_printf); |
1521 | #ifdef _KERNEL /* XXX CRASH(8) */ | | 1555 | #ifdef _KERNEL /* XXX CRASH(8) */ |
1522 | pool_whatis(addr, db_printf); | | 1556 | pool_whatis(addr, db_printf); |
1523 | vmem_whatis(addr, db_printf); | | 1557 | vmem_whatis(addr, db_printf); |
1524 | uvm_whatis(addr, db_printf); | | 1558 | uvm_whatis(addr, db_printf); |
1525 | module_whatis(addr, db_printf); | | 1559 | module_whatis(addr, db_printf); |
1526 | #else | | 1560 | #else |
1527 | db_kernelonly(); | | 1561 | db_kernelonly(); |
1528 | #endif | | 1562 | #endif |
1529 | } | | 1563 | } |