2 * Kernel Debugger Architecture Independent Main Code
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
8 * Copyright (C) 1999-2004 Silicon Graphics, Inc. All Rights Reserved.
9 * Copyright (C) 2000 Stephane Eranian <eranian@hpl.hp.com>
10 * Xscale (R) modifications copyright (C) 2003 Intel Corporation.
11 * Copyright (c) 2009 Wind River Systems, Inc. All Rights Reserved.
14 #include <linux/ctype.h>
15 #include <linux/types.h>
16 #include <linux/string.h>
17 #include <linux/kernel.h>
18 #include <linux/kmsg_dump.h>
19 #include <linux/reboot.h>
20 #include <linux/sched.h>
21 #include <linux/sched/loadavg.h>
22 #include <linux/sched/stat.h>
23 #include <linux/sched/debug.h>
24 #include <linux/sysrq.h>
25 #include <linux/smp.h>
26 #include <linux/utsname.h>
27 #include <linux/vmalloc.h>
28 #include <linux/atomic.h>
29 #include <linux/module.h>
30 #include <linux/moduleparam.h>
32 #include <linux/init.h>
33 #include <linux/kallsyms.h>
34 #include <linux/kgdb.h>
35 #include <linux/kdb.h>
36 #include <linux/notifier.h>
37 #include <linux/interrupt.h>
38 #include <linux/delay.h>
39 #include <linux/nmi.h>
40 #include <linux/time.h>
41 #include <linux/ptrace.h>
42 #include <linux/sysctl.h>
43 #include <linux/cpu.h>
44 #include <linux/kdebug.h>
45 #include <linux/proc_fs.h>
46 #include <linux/uaccess.h>
47 #include <linux/slab.h>
48 #include <linux/security.h>
49 #include "kdb_private.h"
51 #undef MODULE_PARAM_PREFIX
52 #define MODULE_PARAM_PREFIX "kdb."
54 static int kdb_cmd_enabled = CONFIG_KDB_DEFAULT_ENABLE;
55 module_param_named(cmd_enable, kdb_cmd_enabled, int, 0600);
57 char kdb_grep_string[KDB_GREP_STRLEN];
58 int kdb_grepping_flag;
59 EXPORT_SYMBOL(kdb_grepping_flag);
61 int kdb_grep_trailing;
64 * Kernel debugger state flags
66 unsigned int kdb_flags;
69 * kdb_lock protects updates to kdb_initial_cpu. Used to
70 * single thread processors through the kernel debugger.
72 int kdb_initial_cpu = -1; /* cpu number that owns kdb */
74 int kdb_state; /* General KDB state */
76 struct task_struct *kdb_current_task;
77 struct pt_regs *kdb_current_regs;
79 const char *kdb_diemsg;
80 static int kdb_go_count;
81 #ifdef CONFIG_KDB_CONTINUE_CATASTROPHIC
82 static unsigned int kdb_continue_catastrophic =
83 CONFIG_KDB_CONTINUE_CATASTROPHIC;
85 static unsigned int kdb_continue_catastrophic;
88 /* kdb_cmds_head describes the available commands. */
89 static LIST_HEAD(kdb_cmds_head);
91 typedef struct _kdbmsg {
92 int km_diag; /* kdb diagnostic */
93 char *km_msg; /* Corresponding message text */
96 #define KDBMSG(msgnum, text) \
97 { KDB_##msgnum, text }
99 static kdbmsg_t kdbmsgs[] = {
100 KDBMSG(NOTFOUND, "Command Not Found"),
101 KDBMSG(ARGCOUNT, "Improper argument count, see usage."),
102 KDBMSG(BADWIDTH, "Illegal value for BYTESPERWORD use 1, 2, 4 or 8, "
103 "8 is only allowed on 64 bit systems"),
104 KDBMSG(BADRADIX, "Illegal value for RADIX use 8, 10 or 16"),
105 KDBMSG(NOTENV, "Cannot find environment variable"),
106 KDBMSG(NOENVVALUE, "Environment variable should have value"),
107 KDBMSG(NOTIMP, "Command not implemented"),
108 KDBMSG(ENVFULL, "Environment full"),
109 KDBMSG(ENVBUFFULL, "Environment buffer full"),
110 KDBMSG(TOOMANYBPT, "Too many breakpoints defined"),
111 #ifdef CONFIG_CPU_XSCALE
112 KDBMSG(TOOMANYDBREGS, "More breakpoints than ibcr registers defined"),
114 KDBMSG(TOOMANYDBREGS, "More breakpoints than db registers defined"),
116 KDBMSG(DUPBPT, "Duplicate breakpoint address"),
117 KDBMSG(BPTNOTFOUND, "Breakpoint not found"),
118 KDBMSG(BADMODE, "Invalid IDMODE"),
119 KDBMSG(BADINT, "Illegal numeric value"),
120 KDBMSG(INVADDRFMT, "Invalid symbolic address format"),
121 KDBMSG(BADREG, "Invalid register name"),
122 KDBMSG(BADCPUNUM, "Invalid cpu number"),
123 KDBMSG(BADLENGTH, "Invalid length field"),
124 KDBMSG(NOBP, "No Breakpoint exists"),
125 KDBMSG(BADADDR, "Invalid address"),
126 KDBMSG(NOPERM, "Permission denied"),
130 static const int __nkdb_err = ARRAY_SIZE(kdbmsgs);
134 * Initial environment. This is all kept static and local to
135 * this file. We don't want to rely on the memory allocation
136 * mechanisms in the kernel, so we use a very limited allocate-only
137 * heap for new and altered environment variables. The entire
138 * environment is limited to a fixed number of entries (add more
139 * to __env[] if required) and a fixed amount of heap (add more to
140 * KDB_ENVBUFSIZE if required).
143 static char *__env[31] = {
144 #if defined(CONFIG_SMP)
151 "MDCOUNT=8", /* lines of md output */
157 static const int __nenv = ARRAY_SIZE(__env);
159 struct task_struct *kdb_curr_task(int cpu)
161 struct task_struct *p = curr_task(cpu);
163 if ((task_thread_info(p)->flags & _TIF_MCA_INIT) && KDB_TSK(cpu))
170 * Update the permissions flags (kdb_cmd_enabled) to match the
171 * current lockdown state.
173 * Within this function the calls to security_locked_down() are "lazy". We
174 * avoid calling them if the current value of kdb_cmd_enabled already excludes
175 * flags that might be subject to lockdown. Additionally we deliberately check
176 * the lockdown flags independently (even though read lockdown implies write
177 * lockdown) since that results in both simpler code and clearer messages to
178 * the user on first-time debugger entry.
180 * The permission masks during a read+write lockdown permits the following
181 * flags: INSPECT, SIGNAL, REBOOT (and ALWAYS_SAFE).
183 * The INSPECT commands are not blocked during lockdown because they are
184 * not arbitrary memory reads. INSPECT covers the backtrace family (sometimes
185 * forcing them to have no arguments) and lsmod. These commands do expose
186 * some kernel state but do not allow the developer seated at the console to
187 * choose what state is reported. SIGNAL and REBOOT should not be controversial,
188 * given these are allowed for root during lockdown already.
190 static void kdb_check_for_lockdown(void)
192 const int write_flags = KDB_ENABLE_MEM_WRITE |
193 KDB_ENABLE_REG_WRITE |
194 KDB_ENABLE_FLOW_CTRL;
195 const int read_flags = KDB_ENABLE_MEM_READ |
198 bool need_to_lockdown_write = false;
199 bool need_to_lockdown_read = false;
201 if (kdb_cmd_enabled & (KDB_ENABLE_ALL | write_flags))
202 need_to_lockdown_write =
203 security_locked_down(LOCKDOWN_DBG_WRITE_KERNEL);
205 if (kdb_cmd_enabled & (KDB_ENABLE_ALL | read_flags))
206 need_to_lockdown_read =
207 security_locked_down(LOCKDOWN_DBG_READ_KERNEL);
209 /* De-compose KDB_ENABLE_ALL if required */
210 if (need_to_lockdown_write || need_to_lockdown_read)
211 if (kdb_cmd_enabled & KDB_ENABLE_ALL)
212 kdb_cmd_enabled = KDB_ENABLE_MASK & ~KDB_ENABLE_ALL;
214 if (need_to_lockdown_write)
215 kdb_cmd_enabled &= ~write_flags;
217 if (need_to_lockdown_read)
218 kdb_cmd_enabled &= ~read_flags;
222 * Check whether the flags of the current command, the permissions of the kdb
223 * console and the lockdown state allow a command to be run.
225 static bool kdb_check_flags(kdb_cmdflags_t flags, int permissions,
228 /* permissions comes from userspace so needs massaging slightly */
229 permissions &= KDB_ENABLE_MASK;
230 permissions |= KDB_ENABLE_ALWAYS_SAFE;
232 /* some commands change group when launched with no arguments */
234 permissions |= permissions << KDB_ENABLE_NO_ARGS_SHIFT;
236 flags |= KDB_ENABLE_ALL;
238 return permissions & flags;
242 * kdbgetenv - This function will return the character string value of
243 * an environment variable.
245 * match A character string representing an environment variable.
247 * NULL No environment variable matches 'match'
248 * char* Pointer to string value of environment variable.
250 char *kdbgetenv(const char *match)
253 int matchlen = strlen(match);
256 for (i = 0; i < __nenv; i++) {
262 if ((strncmp(match, e, matchlen) == 0)
263 && ((e[matchlen] == '\0')
264 || (e[matchlen] == '='))) {
265 char *cp = strchr(e, '=');
266 return cp ? ++cp : "";
273 * kdballocenv - This function is used to allocate bytes for
274 * environment entries.
276 * match A character string representing a numeric value
278 * *value the unsigned long representation of the env variable 'match'
280 * Zero on success, a kdb diagnostic on failure.
282 * We use a static environment buffer (envbuffer) to hold the values
283 * of dynamically generated environment variables (see kdb_set). Buffer
284 * space once allocated is never free'd, so over time, the amount of space
285 * (currently 512 bytes) will be exhausted if env variables are changed
288 static char *kdballocenv(size_t bytes)
290 #define KDB_ENVBUFSIZE 512
291 static char envbuffer[KDB_ENVBUFSIZE];
292 static int envbufsize;
295 if ((KDB_ENVBUFSIZE - envbufsize) >= bytes) {
296 ep = &envbuffer[envbufsize];
303 * kdbgetulenv - This function will return the value of an unsigned
304 * long-valued environment variable.
306 * match A character string representing a numeric value
308 * *value the unsigned long representation of the env variable 'match'
310 * Zero on success, a kdb diagnostic on failure.
312 static int kdbgetulenv(const char *match, unsigned long *value)
316 ep = kdbgetenv(match);
320 return KDB_NOENVVALUE;
322 *value = simple_strtoul(ep, NULL, 0);
328 * kdbgetintenv - This function will return the value of an
329 * integer-valued environment variable.
331 * match A character string representing an integer-valued env variable
333 * *value the integer representation of the environment variable 'match'
335 * Zero on success, a kdb diagnostic on failure.
337 int kdbgetintenv(const char *match, int *value)
342 diag = kdbgetulenv(match, &val);
349 * kdb_setenv() - Alter an existing environment variable or create a new one.
350 * @var: Name of the variable
351 * @val: Value of the variable
353 * Return: Zero on success, a kdb diagnostic on failure.
355 static int kdb_setenv(const char *var, const char *val)
359 size_t varlen, vallen;
361 varlen = strlen(var);
362 vallen = strlen(val);
363 ep = kdballocenv(varlen + vallen + 2);
365 return KDB_ENVBUFFULL;
367 sprintf(ep, "%s=%s", var, val);
369 for (i = 0; i < __nenv; i++) {
371 && ((strncmp(__env[i], var, varlen) == 0)
372 && ((__env[i][varlen] == '\0')
373 || (__env[i][varlen] == '=')))) {
380 * Wasn't existing variable. Fit into slot.
382 for (i = 0; i < __nenv-1; i++) {
383 if (__env[i] == (char *)0) {
393 * kdb_printenv() - Display the current environment variables.
395 static void kdb_printenv(void)
399 for (i = 0; i < __nenv; i++) {
401 kdb_printf("%s\n", __env[i]);
406 * kdbgetularg - This function will convert a numeric string into an
407 * unsigned long value.
409 * arg A character string representing a numeric value
411 * *value the unsigned long representation of arg.
413 * Zero on success, a kdb diagnostic on failure.
415 int kdbgetularg(const char *arg, unsigned long *value)
420 val = simple_strtoul(arg, &endp, 0);
424 * Also try base 16, for us folks too lazy to type the
427 val = simple_strtoul(arg, &endp, 16);
437 int kdbgetu64arg(const char *arg, u64 *value)
442 val = simple_strtoull(arg, &endp, 0);
446 val = simple_strtoull(arg, &endp, 16);
457 * kdb_set - This function implements the 'set' command. Alter an
458 * existing environment variable or create a new one.
460 int kdb_set(int argc, const char **argv)
463 * we can be invoked two ways:
464 * set var=value argv[1]="var", argv[2]="value"
465 * set var = value argv[1]="var", argv[2]="=", argv[3]="value"
466 * - if the latter, shift 'em down.
477 * Censor sensitive variables
479 if (strcmp(argv[1], "PROMPT") == 0 &&
480 !kdb_check_flags(KDB_ENABLE_MEM_READ, kdb_cmd_enabled, false))
484 * Check for internal variables
486 if (strcmp(argv[1], "KDBDEBUG") == 0) {
487 unsigned int debugflags;
490 debugflags = simple_strtoul(argv[2], &cp, 0);
491 if (cp == argv[2] || debugflags & ~KDB_DEBUG_FLAG_MASK) {
492 kdb_printf("kdb: illegal debug flags '%s'\n",
496 kdb_flags = (kdb_flags & ~KDB_DEBUG(MASK))
497 | (debugflags << KDB_DEBUG_FLAG_SHIFT);
503 * Tokenizer squashed the '=' sign. argv[1] is variable
504 * name, argv[2] = value.
506 return kdb_setenv(argv[1], argv[2]);
509 static int kdb_check_regs(void)
511 if (!kdb_current_regs) {
512 kdb_printf("No current kdb registers."
513 " You may need to select another task\n");
520 * kdbgetaddrarg - This function is responsible for parsing an
521 * address-expression and returning the value of the expression,
522 * symbol name, and offset to the caller.
524 * The argument may consist of a numeric value (decimal or
525 * hexadecimal), a symbol name, a register name (preceded by the
526 * percent sign), an environment variable with a numeric value
527 * (preceded by a dollar sign) or a simple arithmetic expression
528 * consisting of a symbol name, +/-, and a numeric constant value
531 * argc - count of arguments in argv
532 * argv - argument vector
533 * *nextarg - index to next unparsed argument in argv[]
534 * regs - Register state at time of KDB entry
536 * *value - receives the value of the address-expression
537 * *offset - receives the offset specified, if any
538 * *name - receives the symbol name, if any
539 * *nextarg - index to next unparsed argument in argv[]
541 * zero is returned on success, a kdb diagnostic code is
544 int kdbgetaddrarg(int argc, const char **argv, int *nextarg,
545 unsigned long *value, long *offset,
549 unsigned long off = 0;
559 * If the enable flags prohibit both arbitrary memory access
560 * and flow control then there are no reasonable grounds to
561 * provide symbol lookup.
563 if (!kdb_check_flags(KDB_ENABLE_MEM_READ | KDB_ENABLE_FLOW_CTRL,
564 kdb_cmd_enabled, false))
568 * Process arguments which follow the following syntax:
570 * symbol | numeric-address [+/- numeric-offset]
572 * $environment-variable
578 symname = (char *)argv[*nextarg];
581 * If there is no whitespace between the symbol
582 * or address and the '+' or '-' symbols, we
583 * remember the character and replace it with a
584 * null so the symbol/value can be properly parsed
586 cp = strpbrk(symname, "+-");
592 if (symname[0] == '$') {
593 diag = kdbgetulenv(&symname[1], &addr);
596 } else if (symname[0] == '%') {
597 diag = kdb_check_regs();
600 /* Implement register values with % at a later time as it is
605 found = kdbgetsymval(symname, &symtab);
607 addr = symtab.sym_start;
609 diag = kdbgetularg(argv[*nextarg], &addr);
616 found = kdbnearsym(addr, &symtab);
624 if (offset && name && *name)
625 *offset = addr - symtab.sym_start;
627 if ((*nextarg > argc)
632 * check for +/- and offset
635 if (symbol == '\0') {
636 if ((argv[*nextarg][0] != '+')
637 && (argv[*nextarg][0] != '-')) {
639 * Not our argument. Return.
643 positive = (argv[*nextarg][0] == '+');
647 positive = (symbol == '+');
650 * Now there must be an offset!
652 if ((*nextarg > argc)
653 && (symbol == '\0')) {
654 return KDB_INVADDRFMT;
658 cp = (char *)argv[*nextarg];
662 diag = kdbgetularg(cp, &off);
678 static void kdb_cmderror(int diag)
683 kdb_printf("no error detected (diagnostic is %d)\n", diag);
687 for (i = 0; i < __nkdb_err; i++) {
688 if (kdbmsgs[i].km_diag == diag) {
689 kdb_printf("diag: %d: %s\n", diag, kdbmsgs[i].km_msg);
694 kdb_printf("Unknown diag %d\n", -diag);
698 * kdb_defcmd, kdb_defcmd2 - This function implements the 'defcmd'
699 * command which defines one command as a set of other commands,
700 * terminated by endefcmd. kdb_defcmd processes the initial
701 * 'defcmd' command, kdb_defcmd2 is invoked from kdb_parse for
702 * the following commands until 'endefcmd'.
704 * argc argument count
705 * argv argument vector
707 * zero for success, a kdb diagnostic if error
710 kdbtab_t cmd; /* Macro command */
711 struct list_head statements; /* Associated statement list */
714 struct kdb_macro_statement {
715 char *statement; /* Statement text */
716 struct list_head list_node; /* Statement list node */
719 static struct kdb_macro *kdb_macro;
720 static bool defcmd_in_progress;
722 /* Forward references */
723 static int kdb_exec_defcmd(int argc, const char **argv);
725 static int kdb_defcmd2(const char *cmdstr, const char *argv0)
727 struct kdb_macro_statement *kms;
732 if (strcmp(argv0, "endefcmd") == 0) {
733 defcmd_in_progress = false;
734 if (!list_empty(&kdb_macro->statements))
735 kdb_register(&kdb_macro->cmd);
739 kms = kmalloc(sizeof(*kms), GFP_KDB);
741 kdb_printf("Could not allocate new kdb macro command: %s\n",
746 kms->statement = kdb_strdup(cmdstr, GFP_KDB);
747 list_add_tail(&kms->list_node, &kdb_macro->statements);
752 static int kdb_defcmd(int argc, const char **argv)
756 if (defcmd_in_progress) {
757 kdb_printf("kdb: nested defcmd detected, assuming missing "
759 kdb_defcmd2("endefcmd", "endefcmd");
763 struct kdb_macro *kmp;
764 struct kdb_macro_statement *kms;
766 list_for_each_entry(kp, &kdb_cmds_head, list_node) {
767 if (kp->func == kdb_exec_defcmd) {
768 kdb_printf("defcmd %s \"%s\" \"%s\"\n",
769 kp->name, kp->usage, kp->help);
770 kmp = container_of(kp, struct kdb_macro, cmd);
771 list_for_each_entry(kms, &kmp->statements,
773 kdb_printf("%s", kms->statement);
774 kdb_printf("endefcmd\n");
781 if (in_dbg_master()) {
782 kdb_printf("Command only available during kdb_init()\n");
785 kdb_macro = kzalloc(sizeof(*kdb_macro), GFP_KDB);
789 mp = &kdb_macro->cmd;
790 mp->func = kdb_exec_defcmd;
792 mp->flags = KDB_ENABLE_ALWAYS_SAFE;
793 mp->name = kdb_strdup(argv[1], GFP_KDB);
796 mp->usage = kdb_strdup(argv[2], GFP_KDB);
799 mp->help = kdb_strdup(argv[3], GFP_KDB);
802 if (mp->usage[0] == '"') {
803 strcpy(mp->usage, argv[2]+1);
804 mp->usage[strlen(mp->usage)-1] = '\0';
806 if (mp->help[0] == '"') {
807 strcpy(mp->help, argv[3]+1);
808 mp->help[strlen(mp->help)-1] = '\0';
811 INIT_LIST_HEAD(&kdb_macro->statements);
812 defcmd_in_progress = true;
821 kdb_printf("Could not allocate new kdb_macro entry for %s\n", argv[1]);
826 * kdb_exec_defcmd - Execute the set of commands associated with this
829 * argc argument count
830 * argv argument vector
832 * zero for success, a kdb diagnostic if error
834 static int kdb_exec_defcmd(int argc, const char **argv)
838 struct kdb_macro *kmp;
839 struct kdb_macro_statement *kms;
844 list_for_each_entry(kp, &kdb_cmds_head, list_node) {
845 if (strcmp(kp->name, argv[0]) == 0)
848 if (list_entry_is_head(kp, &kdb_cmds_head, list_node)) {
849 kdb_printf("kdb_exec_defcmd: could not find commands for %s\n",
853 kmp = container_of(kp, struct kdb_macro, cmd);
854 list_for_each_entry(kms, &kmp->statements, list_node) {
856 * Recursive use of kdb_parse, do not use argv after this point.
859 kdb_printf("[%s]kdb> %s\n", kmp->cmd.name, kms->statement);
860 ret = kdb_parse(kms->statement);
867 /* Command history */
868 #define KDB_CMD_HISTORY_COUNT 32
869 #define CMD_BUFLEN 200 /* kdb_printf: max printline
871 static unsigned int cmd_head, cmd_tail;
872 static unsigned int cmdptr;
873 static char cmd_hist[KDB_CMD_HISTORY_COUNT][CMD_BUFLEN];
874 static char cmd_cur[CMD_BUFLEN];
877 * The "str" argument may point to something like | grep xyz
879 static void parse_grep(const char *str)
882 char *cp = (char *)str, *cp2;
884 /* sanity check: we should have been called with the \ first */
890 if (!str_has_prefix(cp, "grep ")) {
891 kdb_printf("invalid 'pipe', see grephelp\n");
897 cp2 = strchr(cp, '\n');
899 *cp2 = '\0'; /* remove the trailing newline */
902 kdb_printf("invalid 'pipe', see grephelp\n");
905 /* now cp points to a nonzero length search string */
907 /* allow it be "x y z" by removing the "'s - there must
910 cp2 = strchr(cp, '"');
912 kdb_printf("invalid quoted string, see grephelp\n");
915 *cp2 = '\0'; /* end the string where the 2nd " was */
917 kdb_grep_leading = 0;
919 kdb_grep_leading = 1;
923 kdb_grep_trailing = 0;
924 if (*(cp+len-1) == '$') {
925 kdb_grep_trailing = 1;
931 if (len >= KDB_GREP_STRLEN) {
932 kdb_printf("search string too long\n");
935 strcpy(kdb_grep_string, cp);
941 * kdb_parse - Parse the command line, search the command table for a
942 * matching command and invoke the command function. This
943 * function may be called recursively, if it is, the second call
944 * will overwrite argv and cbuf. It is the caller's
945 * responsibility to save their argv if they recursively call
948 * cmdstr The input command line to be parsed.
949 * regs The registers at the time kdb was entered.
951 * Zero for success, a kdb diagnostic if failure.
953 * Limited to 20 tokens.
955 * Real rudimentary tokenization. Basically only whitespace
956 * is considered a token delimiter (but special consideration
957 * is taken of the '=' sign as used by the 'set' command).
959 * The algorithm used to tokenize the input string relies on
960 * there being at least one whitespace (or otherwise useless)
961 * character between tokens as the character immediately following
962 * the token is altered in-place to a null-byte to terminate the
968 int kdb_parse(const char *cmdstr)
970 static char *argv[MAXARGC];
972 static char cbuf[CMD_BUFLEN+2];
976 int escaped, ignore_errors = 0, check_grep = 0;
979 * First tokenize the command string.
983 if (KDB_FLAG(CMD_INTERRUPT)) {
984 /* Previous command was interrupted, newline must not
985 * repeat the command */
986 KDB_FLAG_CLEAR(CMD_INTERRUPT);
987 KDB_STATE_SET(PAGER);
988 argc = 0; /* no repeat */
991 if (*cp != '\n' && *cp != '\0') {
995 /* skip whitespace */
998 if ((*cp == '\0') || (*cp == '\n') ||
999 (*cp == '#' && !defcmd_in_progress))
1001 /* special case: check for | grep pattern */
1006 if (cpp >= cbuf + CMD_BUFLEN) {
1007 kdb_printf("kdb_parse: command buffer "
1008 "overflow, command ignored\n%s\n",
1010 return KDB_NOTFOUND;
1012 if (argc >= MAXARGC - 1) {
1013 kdb_printf("kdb_parse: too many arguments, "
1014 "command ignored\n%s\n", cmdstr);
1015 return KDB_NOTFOUND;
1020 /* Copy to next unquoted and unescaped
1021 * whitespace or '=' */
1022 while (*cp && *cp != '\n' &&
1023 (escaped || quoted || !isspace(*cp))) {
1024 if (cpp >= cbuf + CMD_BUFLEN)
1038 else if (*cp == '\'' || *cp == '"')
1041 if (*cpp == '=' && !quoted)
1045 *cpp++ = '\0'; /* Squash a ws or '=' character */
1052 if (defcmd_in_progress) {
1053 int result = kdb_defcmd2(cmdstr, argv[0]);
1054 if (!defcmd_in_progress) {
1055 argc = 0; /* avoid repeat on endefcmd */
1060 if (argv[0][0] == '-' && argv[0][1] &&
1061 (argv[0][1] < '0' || argv[0][1] > '9')) {
1066 list_for_each_entry(tp, &kdb_cmds_head, list_node) {
1068 * If this command is allowed to be abbreviated,
1069 * check to see if this is it.
1071 if (tp->minlen && (strlen(argv[0]) <= tp->minlen) &&
1072 (strncmp(argv[0], tp->name, tp->minlen) == 0))
1075 if (strcmp(argv[0], tp->name) == 0)
1080 * If we don't find a command by this name, see if the first
1081 * few characters of this match any of the known commands.
1082 * e.g., md1c20 should match md.
1084 if (list_entry_is_head(tp, &kdb_cmds_head, list_node)) {
1085 list_for_each_entry(tp, &kdb_cmds_head, list_node) {
1086 if (strncmp(argv[0], tp->name, strlen(tp->name)) == 0)
1091 if (!list_entry_is_head(tp, &kdb_cmds_head, list_node)) {
1094 if (!kdb_check_flags(tp->flags, kdb_cmd_enabled, argc <= 1))
1098 result = (*tp->func)(argc-1, (const char **)argv);
1099 if (result && ignore_errors && result > KDB_CMD_GO)
1101 KDB_STATE_CLEAR(CMD);
1103 if (tp->flags & KDB_REPEAT_WITH_ARGS)
1106 argc = tp->flags & KDB_REPEAT_NO_ARGS ? 1 : 0;
1108 *(argv[argc]) = '\0';
1113 * If the input with which we were presented does not
1114 * map to an existing command, attempt to parse it as an
1115 * address argument and display the result. Useful for
1116 * obtaining the address of a variable, or the nearest symbol
1117 * to an address contained in a register.
1120 unsigned long value;
1125 if (kdbgetaddrarg(0, (const char **)argv, &nextarg,
1126 &value, &offset, &name)) {
1127 return KDB_NOTFOUND;
1130 kdb_printf("%s = ", argv[0]);
1131 kdb_symbol_print(value, NULL, KDB_SP_DEFAULT);
1138 static int handle_ctrl_cmd(char *cmd)
1143 /* initial situation */
1144 if (cmd_head == cmd_tail)
1148 if (cmdptr != cmd_tail)
1149 cmdptr = (cmdptr + KDB_CMD_HISTORY_COUNT - 1) %
1150 KDB_CMD_HISTORY_COUNT;
1151 strscpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN);
1154 if (cmdptr != cmd_head)
1155 cmdptr = (cmdptr+1) % KDB_CMD_HISTORY_COUNT;
1156 strscpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN);
1163 * kdb_reboot - This function implements the 'reboot' command. Reboot
1164 * the system immediately, or loop for ever on failure.
1166 static int kdb_reboot(int argc, const char **argv)
1168 emergency_restart();
1169 kdb_printf("Hmm, kdb_reboot did not reboot, spinning here\n");
1176 static void kdb_dumpregs(struct pt_regs *regs)
1178 int old_lvl = console_loglevel;
1179 console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH;
1184 console_loglevel = old_lvl;
1187 static void kdb_set_current_task(struct task_struct *p)
1189 kdb_current_task = p;
1191 if (kdb_task_has_cpu(p)) {
1192 kdb_current_regs = KDB_TSKREGS(kdb_process_cpu(p));
1195 kdb_current_regs = NULL;
1198 static void drop_newline(char *buf)
1200 size_t len = strlen(buf);
1204 if (*(buf + len - 1) == '\n')
1205 *(buf + len - 1) = '\0';
1209 * kdb_local - The main code for kdb. This routine is invoked on a
1210 * specific processor, it is not global. The main kdb() routine
1211 * ensures that only one processor at a time is in this routine.
1212 * This code is called with the real reason code on the first
1213 * entry to a kdb session, thereafter it is called with reason
1214 * SWITCH, even if the user goes back to the original cpu.
1216 * reason The reason KDB was invoked
1217 * error The hardware-defined error code
1218 * regs The exception frame at time of fault/breakpoint.
1219 * db_result Result code from the break or debug point.
1221 * 0 KDB was invoked for an event which it wasn't responsible
1222 * 1 KDB handled the event for which it was invoked.
1223 * KDB_CMD_GO User typed 'go'.
1224 * KDB_CMD_CPU User switched to another cpu.
1225 * KDB_CMD_SS Single step.
1227 static int kdb_local(kdb_reason_t reason, int error, struct pt_regs *regs,
1228 kdb_dbtrap_t db_result)
1232 struct task_struct *kdb_current =
1233 kdb_curr_task(raw_smp_processor_id());
1235 KDB_DEBUG_STATE("kdb_local 1", reason);
1237 kdb_check_for_lockdown();
1240 if (reason == KDB_REASON_DEBUG) {
1241 /* special case below */
1243 kdb_printf("\nEntering kdb (current=0x%px, pid %d) ",
1244 kdb_current, kdb_current ? kdb_current->pid : 0);
1245 #if defined(CONFIG_SMP)
1246 kdb_printf("on processor %d ", raw_smp_processor_id());
1251 case KDB_REASON_DEBUG:
1254 * If re-entering kdb after a single step
1255 * command, don't print the message.
1257 switch (db_result) {
1259 kdb_printf("\nEntering kdb (0x%px, pid %d) ",
1260 kdb_current, kdb_current->pid);
1261 #if defined(CONFIG_SMP)
1262 kdb_printf("on processor %d ", raw_smp_processor_id());
1264 kdb_printf("due to Debug @ " kdb_machreg_fmt "\n",
1265 instruction_pointer(regs));
1270 KDB_DEBUG_STATE("kdb_local 4", reason);
1271 return 1; /* kdba_db_trap did the work */
1273 kdb_printf("kdb: Bad result from kdba_db_trap: %d\n",
1280 case KDB_REASON_ENTER:
1281 if (KDB_STATE(KEYBOARD))
1282 kdb_printf("due to Keyboard Entry\n");
1284 kdb_printf("due to KDB_ENTER()\n");
1286 case KDB_REASON_KEYBOARD:
1287 KDB_STATE_SET(KEYBOARD);
1288 kdb_printf("due to Keyboard Entry\n");
1290 case KDB_REASON_ENTER_SLAVE:
1291 /* drop through, slaves only get released via cpu switch */
1292 case KDB_REASON_SWITCH:
1293 kdb_printf("due to cpu switch\n");
1295 case KDB_REASON_OOPS:
1296 kdb_printf("Oops: %s\n", kdb_diemsg);
1297 kdb_printf("due to oops @ " kdb_machreg_fmt "\n",
1298 instruction_pointer(regs));
1301 case KDB_REASON_SYSTEM_NMI:
1302 kdb_printf("due to System NonMaskable Interrupt\n");
1304 case KDB_REASON_NMI:
1305 kdb_printf("due to NonMaskable Interrupt @ "
1306 kdb_machreg_fmt "\n",
1307 instruction_pointer(regs));
1309 case KDB_REASON_SSTEP:
1310 case KDB_REASON_BREAK:
1311 kdb_printf("due to %s @ " kdb_machreg_fmt "\n",
1312 reason == KDB_REASON_BREAK ?
1313 "Breakpoint" : "SS trap", instruction_pointer(regs));
1315 * Determine if this breakpoint is one that we
1316 * are interested in.
1318 if (db_result != KDB_DB_BPT) {
1319 kdb_printf("kdb: error return from kdba_bp_trap: %d\n",
1321 KDB_DEBUG_STATE("kdb_local 6", reason);
1322 return 0; /* Not for us, dismiss it */
1325 case KDB_REASON_RECURSE:
1326 kdb_printf("due to Recursion @ " kdb_machreg_fmt "\n",
1327 instruction_pointer(regs));
1330 kdb_printf("kdb: unexpected reason code: %d\n", reason);
1331 KDB_DEBUG_STATE("kdb_local 8", reason);
1332 return 0; /* Not for us, dismiss it */
1337 * Initialize pager context.
1340 KDB_STATE_CLEAR(SUPPRESS);
1341 kdb_grepping_flag = 0;
1342 /* ensure the old search does not leak into '/' commands */
1343 kdb_grep_string[0] = '\0';
1347 *(cmd_hist[cmd_head]) = '\0';
1350 /* PROMPT can only be set if we have MEM_READ permission. */
1351 snprintf(kdb_prompt_str, CMD_BUFLEN, kdbgetenv("PROMPT"),
1352 raw_smp_processor_id());
1353 if (defcmd_in_progress)
1354 strncat(kdb_prompt_str, "[defcmd]", CMD_BUFLEN);
1357 * Fetch command from keyboard
1359 cmdbuf = kdb_getstr(cmdbuf, CMD_BUFLEN, kdb_prompt_str);
1360 if (*cmdbuf != '\n') {
1362 if (cmdptr == cmd_head) {
1363 strscpy(cmd_hist[cmd_head], cmd_cur,
1365 *(cmd_hist[cmd_head] +
1366 strlen(cmd_hist[cmd_head])-1) = '\0';
1368 if (!handle_ctrl_cmd(cmdbuf))
1369 *(cmd_cur+strlen(cmd_cur)-1) = '\0';
1371 goto do_full_getstr;
1373 strscpy(cmd_hist[cmd_head], cmd_cur,
1377 cmd_head = (cmd_head+1) % KDB_CMD_HISTORY_COUNT;
1378 if (cmd_head == cmd_tail)
1379 cmd_tail = (cmd_tail+1) % KDB_CMD_HISTORY_COUNT;
1383 diag = kdb_parse(cmdbuf);
1384 if (diag == KDB_NOTFOUND) {
1385 drop_newline(cmdbuf);
1386 kdb_printf("Unknown kdb command: '%s'\n", cmdbuf);
1389 if (diag == KDB_CMD_GO
1390 || diag == KDB_CMD_CPU
1391 || diag == KDB_CMD_SS
1392 || diag == KDB_CMD_KGDB)
1398 KDB_DEBUG_STATE("kdb_local 9", diag);
1404 * kdb_print_state - Print the state data for the current processor
1407 * text Identifies the debug point
1408 * value Any integer value to be printed, e.g. reason code.
1410 void kdb_print_state(const char *text, int value)
1412 kdb_printf("state: %s cpu %d value %d initial %d state %x\n",
1413 text, raw_smp_processor_id(), value, kdb_initial_cpu,
1418 * kdb_main_loop - After initial setup and assignment of the
1419 * controlling cpu, all cpus are in this loop. One cpu is in
1420 * control and will issue the kdb prompt, the others will spin
1421 * until 'go' or cpu switch.
1423 * To get a consistent view of the kernel stacks for all
1424 * processes, this routine is invoked from the main kdb code via
1425 * an architecture specific routine. kdba_main_loop is
1426 * responsible for making the kernel stacks consistent for all
1427 * processes, there should be no difference between a blocked
1428 * process and a running process as far as kdb is concerned.
1430 * reason The reason KDB was invoked
1431 * error The hardware-defined error code
1432 * reason2 kdb's current reason code.
1433 * Initially error but can change
1434 * according to kdb state.
1435 * db_result Result code from break or debug point.
1436 * regs The exception frame at time of fault/breakpoint.
1437 * should always be valid.
1439 * 0 KDB was invoked for an event which it wasn't responsible
1440 * 1 KDB handled the event for which it was invoked.
1442 int kdb_main_loop(kdb_reason_t reason, kdb_reason_t reason2, int error,
1443 kdb_dbtrap_t db_result, struct pt_regs *regs)
1446 /* Stay in kdb() until 'go', 'ss[b]' or an error */
1449 * All processors except the one that is in control
1452 KDB_DEBUG_STATE("kdb_main_loop 1", reason);
1453 while (KDB_STATE(HOLD_CPU)) {
1454 /* state KDB is turned off by kdb_cpu to see if the
1455 * other cpus are still live, each cpu in this loop
1458 if (!KDB_STATE(KDB))
1462 KDB_STATE_CLEAR(SUPPRESS);
1463 KDB_DEBUG_STATE("kdb_main_loop 2", reason);
1464 if (KDB_STATE(LEAVING))
1465 break; /* Another cpu said 'go' */
1466 /* Still using kdb, this processor is in control */
1467 result = kdb_local(reason2, error, regs, db_result);
1468 KDB_DEBUG_STATE("kdb_main_loop 3", result);
1470 if (result == KDB_CMD_CPU)
1473 if (result == KDB_CMD_SS) {
1474 KDB_STATE_SET(DOING_SS);
1478 if (result == KDB_CMD_KGDB) {
1479 if (!KDB_STATE(DOING_KGDB))
1480 kdb_printf("Entering please attach debugger "
1481 "or use $D#44+ or $3#33\n");
1484 if (result && result != 1 && result != KDB_CMD_GO)
1485 kdb_printf("\nUnexpected kdb_local return code %d\n",
1487 KDB_DEBUG_STATE("kdb_main_loop 4", reason);
1490 if (KDB_STATE(DOING_SS))
1491 KDB_STATE_CLEAR(SSBPT);
1493 /* Clean up any keyboard devices before leaving */
1494 kdb_kbd_cleanup_state();
1500 * kdb_mdr - This function implements the guts of the 'mdr', memory
1502 * mdr <addr arg>,<byte count>
1504 * addr Start address
1505 * count Number of bytes
1507 * Always 0. Any errors are detected and printed by kdb_getarea.
1509 static int kdb_mdr(unsigned long addr, unsigned int count)
1513 if (kdb_getarea(c, addr))
1515 kdb_printf("%02x", c);
1523 * kdb_md - This function implements the 'md', 'md1', 'md2', 'md4',
1524 * 'md8' 'mdr' and 'mds' commands.
1526 * md|mds [<addr arg> [<line count> [<radix>]]]
1527 * mdWcN [<addr arg> [<line count> [<radix>]]]
1528 * where W = is the width (1, 2, 4 or 8) and N is the count.
1529 * for eg., md1c20 reads 20 bytes, 1 at a time.
1530 * mdr <addr arg>,<byte count>
1532 static void kdb_md_line(const char *fmtstr, unsigned long addr,
1533 int symbolic, int nosect, int bytesperword,
1534 int num, int repeat, int phys)
1536 /* print just one line of data */
1537 kdb_symtab_t symtab;
1544 memset(cbuf, '\0', sizeof(cbuf));
1546 kdb_printf("phys " kdb_machreg_fmt0 " ", addr);
1548 kdb_printf(kdb_machreg_fmt0 " ", addr);
1550 for (i = 0; i < num && repeat--; i++) {
1552 if (kdb_getphysword(&word, addr, bytesperword))
1554 } else if (kdb_getword(&word, addr, bytesperword))
1556 kdb_printf(fmtstr, word);
1558 kdbnearsym(word, &symtab);
1560 memset(&symtab, 0, sizeof(symtab));
1561 if (symtab.sym_name) {
1562 kdb_symbol_print(word, &symtab, 0);
1565 kdb_printf(" %s %s "
1568 kdb_machreg_fmt, symtab.mod_name,
1569 symtab.sec_name, symtab.sec_start,
1570 symtab.sym_start, symtab.sym_end);
1572 addr += bytesperword;
1580 cp = wc.c + 8 - bytesperword;
1585 #define printable_char(c) \
1586 ({unsigned char __c = c; isascii(__c) && isprint(__c) ? __c : '.'; })
1587 for (j = 0; j < bytesperword; j++)
1588 *c++ = printable_char(*cp++);
1589 addr += bytesperword;
1590 #undef printable_char
1593 kdb_printf("%*s %s\n", (int)((num-i)*(2*bytesperword + 1)+1),
1597 static int kdb_md(int argc, const char **argv)
1599 static unsigned long last_addr;
1600 static int last_radix, last_bytesperword, last_repeat;
1601 int radix = 16, mdcount = 8, bytesperword = KDB_WORD_SIZE, repeat;
1603 char fmtchar, fmtstr[64];
1612 kdbgetintenv("MDCOUNT", &mdcount);
1613 kdbgetintenv("RADIX", &radix);
1614 kdbgetintenv("BYTESPERWORD", &bytesperword);
1616 /* Assume 'md <addr>' and start with environment values */
1617 repeat = mdcount * 16 / bytesperword;
1619 if (strcmp(argv[0], "mdr") == 0) {
1620 if (argc == 2 || (argc == 0 && last_addr != 0))
1623 return KDB_ARGCOUNT;
1624 } else if (isdigit(argv[0][2])) {
1625 bytesperword = (int)(argv[0][2] - '0');
1626 if (bytesperword == 0) {
1627 bytesperword = last_bytesperword;
1628 if (bytesperword == 0)
1631 last_bytesperword = bytesperword;
1632 repeat = mdcount * 16 / bytesperword;
1635 else if (argv[0][3] == 'c' && argv[0][4]) {
1637 repeat = simple_strtoul(argv[0] + 4, &p, 10);
1638 mdcount = ((repeat * bytesperword) + 15) / 16;
1641 last_repeat = repeat;
1642 } else if (strcmp(argv[0], "md") == 0)
1644 else if (strcmp(argv[0], "mds") == 0)
1646 else if (strcmp(argv[0], "mdp") == 0) {
1650 return KDB_NOTFOUND;
1654 return KDB_ARGCOUNT;
1657 bytesperword = last_bytesperword;
1658 repeat = last_repeat;
1662 mdcount = ((repeat * bytesperword) + 15) / 16;
1667 int diag, nextarg = 1;
1668 diag = kdbgetaddrarg(argc, argv, &nextarg, &addr,
1672 if (argc > nextarg+2)
1673 return KDB_ARGCOUNT;
1675 if (argc >= nextarg) {
1676 diag = kdbgetularg(argv[nextarg], &val);
1678 mdcount = (int) val;
1682 repeat = mdcount * 16 / bytesperword;
1685 if (argc >= nextarg+1) {
1686 diag = kdbgetularg(argv[nextarg+1], &val);
1692 if (strcmp(argv[0], "mdr") == 0) {
1695 ret = kdb_mdr(addr, mdcount);
1696 last_addr += mdcount;
1697 last_repeat = mdcount;
1698 last_bytesperword = bytesperword; // to make REPEAT happy
1713 return KDB_BADRADIX;
1718 if (bytesperword > KDB_WORD_SIZE)
1719 return KDB_BADWIDTH;
1721 switch (bytesperword) {
1723 sprintf(fmtstr, "%%16.16l%c ", fmtchar);
1726 sprintf(fmtstr, "%%8.8l%c ", fmtchar);
1729 sprintf(fmtstr, "%%4.4l%c ", fmtchar);
1732 sprintf(fmtstr, "%%2.2l%c ", fmtchar);
1735 return KDB_BADWIDTH;
1738 last_repeat = repeat;
1739 last_bytesperword = bytesperword;
1741 if (strcmp(argv[0], "mds") == 0) {
1743 /* Do not save these changes as last_*, they are temporary mds
1746 bytesperword = KDB_WORD_SIZE;
1748 kdbgetintenv("NOSECT", &nosect);
1751 /* Round address down modulo BYTESPERWORD */
1753 addr &= ~(bytesperword-1);
1755 while (repeat > 0) {
1757 int n, z, num = (symbolic ? 1 : (16 / bytesperword));
1759 if (KDB_FLAG(CMD_INTERRUPT))
1761 for (a = addr, z = 0; z < repeat; a += bytesperword, ++z) {
1763 if (kdb_getphysword(&word, a, bytesperword)
1766 } else if (kdb_getword(&word, a, bytesperword) || word)
1769 n = min(num, repeat);
1770 kdb_md_line(fmtstr, addr, symbolic, nosect, bytesperword,
1772 addr += bytesperword * n;
1774 z = (z + num - 1) / num;
1776 int s = num * (z-2);
1777 kdb_printf(kdb_machreg_fmt0 "-" kdb_machreg_fmt0
1778 " zero suppressed\n",
1779 addr, addr + bytesperword * s - 1);
1780 addr += bytesperword * s;
1790 * kdb_mm - This function implements the 'mm' command.
1791 * mm address-expression new-value
1793 * mm works on machine words, mmW works on bytes.
1795 static int kdb_mm(int argc, const char **argv)
1800 unsigned long contents;
1804 if (argv[0][2] && !isdigit(argv[0][2]))
1805 return KDB_NOTFOUND;
1808 return KDB_ARGCOUNT;
1811 diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL);
1816 return KDB_ARGCOUNT;
1817 diag = kdbgetaddrarg(argc, argv, &nextarg, &contents, NULL, NULL);
1821 if (nextarg != argc + 1)
1822 return KDB_ARGCOUNT;
1824 width = argv[0][2] ? (argv[0][2] - '0') : (KDB_WORD_SIZE);
1825 diag = kdb_putword(addr, contents, width);
1829 kdb_printf(kdb_machreg_fmt " = " kdb_machreg_fmt "\n", addr, contents);
1835 * kdb_go - This function implements the 'go' command.
1836 * go [address-expression]
1838 static int kdb_go(int argc, const char **argv)
1845 if (raw_smp_processor_id() != kdb_initial_cpu) {
1846 kdb_printf("go must execute on the entry cpu, "
1847 "please use \"cpu %d\" and then execute go\n",
1849 return KDB_BADCPUNUM;
1853 diag = kdbgetaddrarg(argc, argv, &nextarg,
1854 &addr, &offset, NULL);
1858 return KDB_ARGCOUNT;
1862 if (KDB_FLAG(CATASTROPHIC)) {
1863 kdb_printf("Catastrophic error detected\n");
1864 kdb_printf("kdb_continue_catastrophic=%d, ",
1865 kdb_continue_catastrophic);
1866 if (kdb_continue_catastrophic == 0 && kdb_go_count++ == 0) {
1867 kdb_printf("type go a second time if you really want "
1871 if (kdb_continue_catastrophic == 2) {
1872 kdb_printf("forcing reboot\n");
1873 kdb_reboot(0, NULL);
1875 kdb_printf("attempting to continue\n");
1881 * kdb_rd - This function implements the 'rd' command.
1883 static int kdb_rd(int argc, const char **argv)
1885 int len = kdb_check_regs();
1886 #if DBG_MAX_REG_NUM > 0
1898 for (i = 0; i < DBG_MAX_REG_NUM; i++) {
1899 rsize = dbg_reg_def[i].size * 2;
1902 if (len + strlen(dbg_reg_def[i].name) + 4 + rsize > 80) {
1907 len += kdb_printf(" ");
1908 switch(dbg_reg_def[i].size * 8) {
1910 rname = dbg_get_reg(i, ®8, kdb_current_regs);
1913 len += kdb_printf("%s: %02x", rname, reg8);
1916 rname = dbg_get_reg(i, ®16, kdb_current_regs);
1919 len += kdb_printf("%s: %04x", rname, reg16);
1922 rname = dbg_get_reg(i, ®32, kdb_current_regs);
1925 len += kdb_printf("%s: %08x", rname, reg32);
1928 rname = dbg_get_reg(i, ®64, kdb_current_regs);
1931 len += kdb_printf("%s: %016llx", rname, reg64);
1934 len += kdb_printf("%s: ??", dbg_reg_def[i].name);
1942 kdb_dumpregs(kdb_current_regs);
1948 * kdb_rm - This function implements the 'rm' (register modify) command.
1949 * rm register-name new-contents
1951 * Allows register modification with the same restrictions as gdb
1953 static int kdb_rm(int argc, const char **argv)
1955 #if DBG_MAX_REG_NUM > 0
1965 return KDB_ARGCOUNT;
1967 * Allow presence or absence of leading '%' symbol.
1973 diag = kdbgetu64arg(argv[2], ®64);
1977 diag = kdb_check_regs();
1982 for (i = 0; i < DBG_MAX_REG_NUM; i++) {
1983 if (strcmp(rname, dbg_reg_def[i].name) == 0) {
1989 switch(dbg_reg_def[i].size * 8) {
1992 dbg_set_reg(i, ®8, kdb_current_regs);
1996 dbg_set_reg(i, ®16, kdb_current_regs);
2000 dbg_set_reg(i, ®32, kdb_current_regs);
2003 dbg_set_reg(i, ®64, kdb_current_regs);
2009 kdb_printf("ERROR: Register set currently not implemented\n");
2014 #if defined(CONFIG_MAGIC_SYSRQ)
2016 * kdb_sr - This function implements the 'sr' (SYSRQ key) command
2017 * which interfaces to the soi-disant MAGIC SYSRQ functionality.
2018 * sr <magic-sysrq-code>
2020 static int kdb_sr(int argc, const char **argv)
2023 !kdb_check_flags(KDB_ENABLE_ALL, kdb_cmd_enabled, false);
2026 return KDB_ARGCOUNT;
2029 __handle_sysrq(*argv[1], check_mask);
2034 #endif /* CONFIG_MAGIC_SYSRQ */
2037 * kdb_ef - This function implements the 'regs' (display exception
2038 * frame) command. This command takes an address and expects to
2039 * find an exception frame at that address, formats and prints
2041 * regs address-expression
2045 static int kdb_ef(int argc, const char **argv)
2053 return KDB_ARGCOUNT;
2056 diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL);
2059 show_regs((struct pt_regs *)addr);
2063 #if defined(CONFIG_MODULES)
2065 * kdb_lsmod - This function implements the 'lsmod' command. Lists
2066 * currently loaded kernel modules.
2067 * Mostly taken from userland lsmod.
2069 static int kdb_lsmod(int argc, const char **argv)
2074 return KDB_ARGCOUNT;
2076 kdb_printf("Module Size modstruct Used by\n");
2077 list_for_each_entry(mod, kdb_modules, list) {
2078 if (mod->state == MODULE_STATE_UNFORMED)
2081 kdb_printf("%-20s%8u 0x%px ", mod->name,
2082 mod->core_layout.size, (void *)mod);
2083 #ifdef CONFIG_MODULE_UNLOAD
2084 kdb_printf("%4d ", module_refcount(mod));
2086 if (mod->state == MODULE_STATE_GOING)
2087 kdb_printf(" (Unloading)");
2088 else if (mod->state == MODULE_STATE_COMING)
2089 kdb_printf(" (Loading)");
2091 kdb_printf(" (Live)");
2092 kdb_printf(" 0x%px", mod->core_layout.base);
2094 #ifdef CONFIG_MODULE_UNLOAD
2096 struct module_use *use;
2098 list_for_each_entry(use, &mod->source_list,
2100 kdb_printf("%s ", use->target->name);
2109 #endif /* CONFIG_MODULES */
2112 * kdb_env - This function implements the 'env' command. Display the
2113 * current environment variables.
2116 static int kdb_env(int argc, const char **argv)
2120 if (KDB_DEBUG(MASK))
2121 kdb_printf("KDBDEBUG=0x%x\n",
2122 (kdb_flags & KDB_DEBUG(MASK)) >> KDB_DEBUG_FLAG_SHIFT);
2127 #ifdef CONFIG_PRINTK
2129 * kdb_dmesg - This function implements the 'dmesg' command to display
2130 * the contents of the syslog buffer.
2131 * dmesg [lines] [adjust]
2133 static int kdb_dmesg(int argc, const char **argv)
2141 struct kmsg_dump_iter iter;
2146 return KDB_ARGCOUNT;
2149 lines = simple_strtol(argv[1], &cp, 0);
2153 adjust = simple_strtoul(argv[2], &cp, 0);
2154 if (*cp || adjust < 0)
2159 /* disable LOGGING if set */
2160 diag = kdbgetintenv("LOGGING", &logging);
2161 if (!diag && logging) {
2162 const char *setargs[] = { "set", "LOGGING", "0" };
2163 kdb_set(2, setargs);
2166 kmsg_dump_rewind(&iter);
2167 while (kmsg_dump_get_line(&iter, 1, NULL, 0, NULL))
2172 kdb_printf("buffer only contains %d lines, nothing "
2174 else if (adjust - lines >= n)
2175 kdb_printf("buffer only contains %d lines, last %d "
2176 "lines printed\n", n, n - adjust);
2179 } else if (lines > 0) {
2180 skip = n - lines - adjust;
2183 kdb_printf("buffer only contains %d lines, "
2184 "nothing printed\n", n);
2186 } else if (skip < 0) {
2189 kdb_printf("buffer only contains %d lines, first "
2190 "%d lines printed\n", n, lines);
2196 if (skip >= n || skip < 0)
2199 kmsg_dump_rewind(&iter);
2200 while (kmsg_dump_get_line(&iter, 1, buf, sizeof(buf), &len)) {
2207 if (KDB_FLAG(CMD_INTERRUPT))
2210 kdb_printf("%.*s\n", (int)len - 1, buf);
2215 #endif /* CONFIG_PRINTK */
2217 /* Make sure we balance enable/disable calls, must disable first. */
2218 static atomic_t kdb_nmi_disabled;
2220 static int kdb_disable_nmi(int argc, const char *argv[])
2222 if (atomic_read(&kdb_nmi_disabled))
2224 atomic_set(&kdb_nmi_disabled, 1);
2225 arch_kgdb_ops.enable_nmi(0);
2229 static int kdb_param_enable_nmi(const char *val, const struct kernel_param *kp)
2231 if (!atomic_add_unless(&kdb_nmi_disabled, -1, 0))
2233 arch_kgdb_ops.enable_nmi(1);
2237 static const struct kernel_param_ops kdb_param_ops_enable_nmi = {
2238 .set = kdb_param_enable_nmi,
2240 module_param_cb(enable_nmi, &kdb_param_ops_enable_nmi, NULL, 0600);
2243 * kdb_cpu - This function implements the 'cpu' command.
2246 * KDB_CMD_CPU for success, a kdb diagnostic if error
2248 static void kdb_cpu_status(void)
2250 int i, start_cpu, first_print = 1;
2251 char state, prev_state = '?';
2253 kdb_printf("Currently on cpu %d\n", raw_smp_processor_id());
2254 kdb_printf("Available cpus: ");
2255 for (start_cpu = -1, i = 0; i < NR_CPUS; i++) {
2256 if (!cpu_online(i)) {
2257 state = 'F'; /* cpu is offline */
2258 } else if (!kgdb_info[i].enter_kgdb) {
2259 state = 'D'; /* cpu is online but unresponsive */
2261 state = ' '; /* cpu is responding to kdb */
2262 if (kdb_task_state_char(KDB_TSK(i)) == '-')
2263 state = '-'; /* idle task */
2265 if (state != prev_state) {
2266 if (prev_state != '?') {
2270 kdb_printf("%d", start_cpu);
2271 if (start_cpu < i-1)
2272 kdb_printf("-%d", i-1);
2273 if (prev_state != ' ')
2274 kdb_printf("(%c)", prev_state);
2280 /* print the trailing cpus, ignoring them if they are all offline */
2281 if (prev_state != 'F') {
2284 kdb_printf("%d", start_cpu);
2285 if (start_cpu < i-1)
2286 kdb_printf("-%d", i-1);
2287 if (prev_state != ' ')
2288 kdb_printf("(%c)", prev_state);
2293 static int kdb_cpu(int argc, const char **argv)
2295 unsigned long cpunum;
2304 return KDB_ARGCOUNT;
2306 diag = kdbgetularg(argv[1], &cpunum);
2313 if ((cpunum >= CONFIG_NR_CPUS) || !kgdb_info[cpunum].enter_kgdb)
2314 return KDB_BADCPUNUM;
2316 dbg_switch_cpu = cpunum;
2319 * Switch to other cpu
2324 /* The user may not realize that ps/bta with no parameters does not print idle
2325 * or sleeping system daemon processes, so tell them how many were suppressed.
2327 void kdb_ps_suppressed(void)
2329 int idle = 0, daemon = 0;
2331 const struct task_struct *p, *g;
2332 for_each_online_cpu(cpu) {
2333 p = kdb_curr_task(cpu);
2334 if (kdb_task_state(p, "-"))
2337 for_each_process_thread(g, p) {
2338 if (kdb_task_state(p, "ims"))
2341 if (idle || daemon) {
2343 kdb_printf("%d idle process%s (state -)%s\n",
2344 idle, idle == 1 ? "" : "es",
2345 daemon ? " and " : "");
2347 kdb_printf("%d sleeping system daemon (state [ims]) "
2348 "process%s", daemon,
2349 daemon == 1 ? "" : "es");
2350 kdb_printf(" suppressed,\nuse 'ps A' to see all.\n");
2354 void kdb_ps1(const struct task_struct *p)
2360 copy_from_kernel_nofault(&tmp, (char *)p, sizeof(unsigned long)))
2363 cpu = kdb_process_cpu(p);
2364 kdb_printf("0x%px %8d %8d %d %4d %c 0x%px %c%s\n",
2365 (void *)p, p->pid, p->parent->pid,
2366 kdb_task_has_cpu(p), kdb_process_cpu(p),
2367 kdb_task_state_char(p),
2368 (void *)(&p->thread),
2369 p == kdb_curr_task(raw_smp_processor_id()) ? '*' : ' ',
2371 if (kdb_task_has_cpu(p)) {
2372 if (!KDB_TSK(cpu)) {
2373 kdb_printf(" Error: no saved data for this cpu\n");
2375 if (KDB_TSK(cpu) != p)
2376 kdb_printf(" Error: does not match running "
2377 "process table (0x%px)\n", KDB_TSK(cpu));
2383 * kdb_ps - This function implements the 'ps' command which shows a
2384 * list of the active processes.
2386 * ps [<state_chars>] Show processes, optionally selecting only those whose
2387 * state character is found in <state_chars>.
2389 static int kdb_ps(int argc, const char **argv)
2391 struct task_struct *g, *p;
2396 kdb_ps_suppressed();
2397 kdb_printf("%-*s Pid Parent [*] cpu State %-*s Command\n",
2398 (int)(2*sizeof(void *))+2, "Task Addr",
2399 (int)(2*sizeof(void *))+2, "Thread");
2400 mask = argc ? argv[1] : kdbgetenv("PS");
2401 /* Run the active tasks first */
2402 for_each_online_cpu(cpu) {
2403 if (KDB_FLAG(CMD_INTERRUPT))
2405 p = kdb_curr_task(cpu);
2406 if (kdb_task_state(p, mask))
2410 /* Now the real tasks */
2411 for_each_process_thread(g, p) {
2412 if (KDB_FLAG(CMD_INTERRUPT))
2414 if (kdb_task_state(p, mask))
2422 * kdb_pid - This function implements the 'pid' command which switches
2423 * the currently active process.
2426 static int kdb_pid(int argc, const char **argv)
2428 struct task_struct *p;
2433 return KDB_ARGCOUNT;
2436 if (strcmp(argv[1], "R") == 0) {
2437 p = KDB_TSK(kdb_initial_cpu);
2439 diag = kdbgetularg(argv[1], &val);
2443 p = find_task_by_pid_ns((pid_t)val, &init_pid_ns);
2445 kdb_printf("No task with pid=%d\n", (pid_t)val);
2449 kdb_set_current_task(p);
2451 kdb_printf("KDB current process is %s(pid=%d)\n",
2452 kdb_current_task->comm,
2453 kdb_current_task->pid);
2458 static int kdb_kgdb(int argc, const char **argv)
2460 return KDB_CMD_KGDB;
2464 * kdb_help - This function implements the 'help' and '?' commands.
2466 static int kdb_help(int argc, const char **argv)
2470 kdb_printf("%-15.15s %-20.20s %s\n", "Command", "Usage", "Description");
2471 kdb_printf("-----------------------------"
2472 "-----------------------------\n");
2473 list_for_each_entry(kt, &kdb_cmds_head, list_node) {
2475 if (KDB_FLAG(CMD_INTERRUPT))
2477 if (!kdb_check_flags(kt->flags, kdb_cmd_enabled, true))
2479 if (strlen(kt->usage) > 20)
2481 kdb_printf("%-15.15s %-20s%s%s\n", kt->name,
2482 kt->usage, space, kt->help);
2488 * kdb_kill - This function implements the 'kill' commands.
2490 static int kdb_kill(int argc, const char **argv)
2494 struct task_struct *p;
2497 return KDB_ARGCOUNT;
2499 sig = simple_strtol(argv[1], &endp, 0);
2502 if ((sig >= 0) || !valid_signal(-sig)) {
2503 kdb_printf("Invalid signal parameter.<-signal>\n");
2508 pid = simple_strtol(argv[2], &endp, 0);
2512 kdb_printf("Process ID must be large than 0.\n");
2516 /* Find the process. */
2517 p = find_task_by_pid_ns(pid, &init_pid_ns);
2519 kdb_printf("The specified process isn't found.\n");
2522 p = p->group_leader;
2523 kdb_send_sig(p, sig);
2528 * Most of this code has been lifted from kernel/timer.c::sys_sysinfo().
2529 * I cannot call that code directly from kdb, it has an unconditional
2530 * cli()/sti() and calls routines that take locks which can stop the debugger.
2532 static void kdb_sysinfo(struct sysinfo *val)
2534 u64 uptime = ktime_get_mono_fast_ns();
2536 memset(val, 0, sizeof(*val));
2537 val->uptime = div_u64(uptime, NSEC_PER_SEC);
2538 val->loads[0] = avenrun[0];
2539 val->loads[1] = avenrun[1];
2540 val->loads[2] = avenrun[2];
2541 val->procs = nr_threads-1;
2548 * kdb_summary - This function implements the 'summary' command.
2550 static int kdb_summary(int argc, const char **argv)
2556 return KDB_ARGCOUNT;
2558 kdb_printf("sysname %s\n", init_uts_ns.name.sysname);
2559 kdb_printf("release %s\n", init_uts_ns.name.release);
2560 kdb_printf("version %s\n", init_uts_ns.name.version);
2561 kdb_printf("machine %s\n", init_uts_ns.name.machine);
2562 kdb_printf("nodename %s\n", init_uts_ns.name.nodename);
2563 kdb_printf("domainname %s\n", init_uts_ns.name.domainname);
2565 now = __ktime_get_real_seconds();
2566 kdb_printf("date %ptTs tz_minuteswest %d\n", &now, sys_tz.tz_minuteswest);
2568 kdb_printf("uptime ");
2569 if (val.uptime > (24*60*60)) {
2570 int days = val.uptime / (24*60*60);
2571 val.uptime %= (24*60*60);
2572 kdb_printf("%d day%s ", days, days == 1 ? "" : "s");
2574 kdb_printf("%02ld:%02ld\n", val.uptime/(60*60), (val.uptime/60)%60);
2576 kdb_printf("load avg %ld.%02ld %ld.%02ld %ld.%02ld\n",
2577 LOAD_INT(val.loads[0]), LOAD_FRAC(val.loads[0]),
2578 LOAD_INT(val.loads[1]), LOAD_FRAC(val.loads[1]),
2579 LOAD_INT(val.loads[2]), LOAD_FRAC(val.loads[2]));
2581 /* Display in kilobytes */
2582 #define K(x) ((x) << (PAGE_SHIFT - 10))
2583 kdb_printf("\nMemTotal: %8lu kB\nMemFree: %8lu kB\n"
2584 "Buffers: %8lu kB\n",
2585 K(val.totalram), K(val.freeram), K(val.bufferram));
2590 * kdb_per_cpu - This function implements the 'per_cpu' command.
2592 static int kdb_per_cpu(int argc, const char **argv)
2595 int cpu, diag, nextarg = 1;
2596 unsigned long addr, symaddr, val, bytesperword = 0, whichcpu = ~0UL;
2598 if (argc < 1 || argc > 3)
2599 return KDB_ARGCOUNT;
2601 diag = kdbgetaddrarg(argc, argv, &nextarg, &symaddr, NULL, NULL);
2606 diag = kdbgetularg(argv[2], &bytesperword);
2611 bytesperword = KDB_WORD_SIZE;
2612 else if (bytesperword > KDB_WORD_SIZE)
2613 return KDB_BADWIDTH;
2614 sprintf(fmtstr, "%%0%dlx ", (int)(2*bytesperword));
2616 diag = kdbgetularg(argv[3], &whichcpu);
2619 if (whichcpu >= nr_cpu_ids || !cpu_online(whichcpu)) {
2620 kdb_printf("cpu %ld is not online\n", whichcpu);
2621 return KDB_BADCPUNUM;
2625 /* Most architectures use __per_cpu_offset[cpu], some use
2626 * __per_cpu_offset(cpu), smp has no __per_cpu_offset.
2628 #ifdef __per_cpu_offset
2629 #define KDB_PCU(cpu) __per_cpu_offset(cpu)
2632 #define KDB_PCU(cpu) __per_cpu_offset[cpu]
2634 #define KDB_PCU(cpu) 0
2637 for_each_online_cpu(cpu) {
2638 if (KDB_FLAG(CMD_INTERRUPT))
2641 if (whichcpu != ~0UL && whichcpu != cpu)
2643 addr = symaddr + KDB_PCU(cpu);
2644 diag = kdb_getword(&val, addr, bytesperword);
2646 kdb_printf("%5d " kdb_bfd_vma_fmt0 " - unable to "
2647 "read, diag=%d\n", cpu, addr, diag);
2650 kdb_printf("%5d ", cpu);
2651 kdb_md_line(fmtstr, addr,
2652 bytesperword == KDB_WORD_SIZE,
2653 1, bytesperword, 1, 1, 0);
2660 * display help for the use of cmd | grep pattern
2662 static int kdb_grep_help(int argc, const char **argv)
2664 kdb_printf("Usage of cmd args | grep pattern:\n");
2665 kdb_printf(" Any command's output may be filtered through an ");
2666 kdb_printf("emulated 'pipe'.\n");
2667 kdb_printf(" 'grep' is just a key word.\n");
2668 kdb_printf(" The pattern may include a very limited set of "
2669 "metacharacters:\n");
2670 kdb_printf(" pattern or ^pattern or pattern$ or ^pattern$\n");
2671 kdb_printf(" And if there are spaces in the pattern, you may "
2673 kdb_printf(" \"pat tern\" or \"^pat tern\" or \"pat tern$\""
2674 " or \"^pat tern$\"\n");
2679 * kdb_register() - This function is used to register a kernel debugger
2681 * @cmd: pointer to kdb command
2683 * Note that it's the job of the caller to keep the memory for the cmd
2684 * allocated until unregister is called.
2686 int kdb_register(kdbtab_t *cmd)
2690 list_for_each_entry(kp, &kdb_cmds_head, list_node) {
2691 if (strcmp(kp->name, cmd->name) == 0) {
2692 kdb_printf("Duplicate kdb cmd: %s, func %p help %s\n",
2693 cmd->name, cmd->func, cmd->help);
2698 list_add_tail(&cmd->list_node, &kdb_cmds_head);
2701 EXPORT_SYMBOL_GPL(kdb_register);
2704 * kdb_register_table() - This function is used to register a kdb command
2706 * @kp: pointer to kdb command table
2707 * @len: length of kdb command table
2709 void kdb_register_table(kdbtab_t *kp, size_t len)
2712 list_add_tail(&kp->list_node, &kdb_cmds_head);
2718 * kdb_unregister() - This function is used to unregister a kernel debugger
2719 * command. It is generally called when a module which
2720 * implements kdb command is unloaded.
2721 * @cmd: pointer to kdb command
2723 void kdb_unregister(kdbtab_t *cmd)
2725 list_del(&cmd->list_node);
2727 EXPORT_SYMBOL_GPL(kdb_unregister);
2729 static kdbtab_t maintab[] = {
2733 .help = "Display Memory Contents, also mdWcN, e.g. md8c1",
2735 .flags = KDB_ENABLE_MEM_READ | KDB_REPEAT_NO_ARGS,
2739 .usage = "<vaddr> <bytes>",
2740 .help = "Display Raw Memory",
2741 .flags = KDB_ENABLE_MEM_READ | KDB_REPEAT_NO_ARGS,
2745 .usage = "<paddr> <bytes>",
2746 .help = "Display Physical Memory",
2747 .flags = KDB_ENABLE_MEM_READ | KDB_REPEAT_NO_ARGS,
2752 .help = "Display Memory Symbolically",
2753 .flags = KDB_ENABLE_MEM_READ | KDB_REPEAT_NO_ARGS,
2757 .usage = "<vaddr> <contents>",
2758 .help = "Modify Memory Contents",
2759 .flags = KDB_ENABLE_MEM_WRITE | KDB_REPEAT_NO_ARGS,
2763 .usage = "[<vaddr>]",
2764 .help = "Continue Execution",
2766 .flags = KDB_ENABLE_REG_WRITE |
2767 KDB_ENABLE_ALWAYS_SAFE_NO_ARGS,
2772 .help = "Display Registers",
2773 .flags = KDB_ENABLE_REG_READ,
2777 .usage = "<reg> <contents>",
2778 .help = "Modify Registers",
2779 .flags = KDB_ENABLE_REG_WRITE,
2784 .help = "Display exception frame",
2785 .flags = KDB_ENABLE_MEM_READ,
2789 .usage = "[<vaddr>]",
2790 .help = "Stack traceback",
2792 .flags = KDB_ENABLE_MEM_READ | KDB_ENABLE_INSPECT_NO_ARGS,
2797 .help = "Display stack for process <pid>",
2798 .flags = KDB_ENABLE_INSPECT,
2802 .usage = "[<state_chars>|A]",
2803 .help = "Backtrace all processes whose state matches",
2804 .flags = KDB_ENABLE_INSPECT,
2809 .help = "Backtrace current process on each cpu",
2810 .flags = KDB_ENABLE_INSPECT,
2815 .help = "Backtrace process given its struct task address",
2816 .flags = KDB_ENABLE_MEM_READ | KDB_ENABLE_INSPECT_NO_ARGS,
2821 .help = "Show environment variables",
2822 .flags = KDB_ENABLE_ALWAYS_SAFE,
2827 .help = "Set environment variables",
2828 .flags = KDB_ENABLE_ALWAYS_SAFE,
2833 .help = "Display Help Message",
2835 .flags = KDB_ENABLE_ALWAYS_SAFE,
2840 .help = "Display Help Message",
2841 .flags = KDB_ENABLE_ALWAYS_SAFE,
2845 .usage = "<cpunum>",
2846 .help = "Switch to new cpu",
2847 .flags = KDB_ENABLE_ALWAYS_SAFE_NO_ARGS,
2852 .help = "Enter kgdb mode",
2857 .usage = "[<state_chars>|A]",
2858 .help = "Display active task list",
2859 .flags = KDB_ENABLE_INSPECT,
2863 .usage = "<pidnum>",
2864 .help = "Switch to another task",
2865 .flags = KDB_ENABLE_INSPECT,
2870 .help = "Reboot the machine immediately",
2871 .flags = KDB_ENABLE_REBOOT,
2873 #if defined(CONFIG_MODULES)
2877 .help = "List loaded kernel modules",
2878 .flags = KDB_ENABLE_INSPECT,
2881 #if defined(CONFIG_MAGIC_SYSRQ)
2885 .help = "Magic SysRq key",
2886 .flags = KDB_ENABLE_ALWAYS_SAFE,
2889 #if defined(CONFIG_PRINTK)
2893 .help = "Display syslog buffer",
2894 .flags = KDB_ENABLE_ALWAYS_SAFE,
2899 .usage = "name \"usage\" \"help\"",
2900 .help = "Define a set of commands, down to endefcmd",
2902 * Macros are always safe because when executed each
2903 * internal command re-enters kdb_parse() and is safety
2904 * checked individually.
2906 .flags = KDB_ENABLE_ALWAYS_SAFE,
2910 .usage = "<-signal> <pid>",
2911 .help = "Send a signal to a process",
2912 .flags = KDB_ENABLE_SIGNAL,
2914 { .name = "summary",
2915 .func = kdb_summary,
2917 .help = "Summarize the system",
2919 .flags = KDB_ENABLE_ALWAYS_SAFE,
2921 { .name = "per_cpu",
2922 .func = kdb_per_cpu,
2923 .usage = "<sym> [<bytes>] [<cpu>]",
2924 .help = "Display per_cpu variables",
2926 .flags = KDB_ENABLE_MEM_READ,
2928 { .name = "grephelp",
2929 .func = kdb_grep_help,
2931 .help = "Display help on | grep",
2932 .flags = KDB_ENABLE_ALWAYS_SAFE,
2936 static kdbtab_t nmicmd = {
2937 .name = "disable_nmi",
2938 .func = kdb_disable_nmi,
2940 .help = "Disable NMI entry to KDB",
2941 .flags = KDB_ENABLE_ALWAYS_SAFE,
2944 /* Initialize the kdb command table. */
2945 static void __init kdb_inittab(void)
2947 kdb_register_table(maintab, ARRAY_SIZE(maintab));
2948 if (arch_kgdb_ops.enable_nmi)
2949 kdb_register_table(&nmicmd, 1);
2952 /* Execute any commands defined in kdb_cmds. */
2953 static void __init kdb_cmd_init(void)
2956 for (i = 0; kdb_cmds[i]; ++i) {
2957 diag = kdb_parse(kdb_cmds[i]);
2959 kdb_printf("kdb command %s failed, kdb diag %d\n",
2962 if (defcmd_in_progress) {
2963 kdb_printf("Incomplete 'defcmd' set, forcing endefcmd\n");
2964 kdb_parse("endefcmd");
2968 /* Initialize kdb_printf, breakpoint tables and kdb state */
2969 void __init kdb_init(int lvl)
2971 static int kdb_init_lvl = KDB_NOT_INITIALIZED;
2974 if (kdb_init_lvl == KDB_INIT_FULL || lvl <= kdb_init_lvl)
2976 for (i = kdb_init_lvl; i < lvl; i++) {
2978 case KDB_NOT_INITIALIZED:
2979 kdb_inittab(); /* Initialize Command Table */
2980 kdb_initbptab(); /* Initialize Breakpoints */
2982 case KDB_INIT_EARLY:
2983 kdb_cmd_init(); /* Build kdb_cmds tables */