| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
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 |
| @@ -51,31 +51,32 @@ | | | @@ -51,31 +51,32 @@ |
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> |
| @@ -92,26 +93,31 @@ __KERNEL_RCSID(0, "$NetBSD: db_command.c | | | @@ -92,26 +93,31 @@ __KERNEL_RCSID(0, "$NetBSD: db_command.c |
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; |
| @@ -209,46 +215,53 @@ static void db_reboot_cmd(db_expr_t, boo | | | @@ -209,46 +215,53 @@ static void db_reboot_cmd(db_expr_t, boo |
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) }, |
| @@ -1336,26 +1349,47 @@ db_show_all_freelists(db_expr_t addr, bo | | | @@ -1336,26 +1349,47 @@ db_show_all_freelists(db_expr_t addr, bo |
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]; |