14 #include <linux/ctype.h>
15 #include <linux/string.h>
16 #include <linux/kernel.h>
18 #include <linux/reboot.h>
19 #include <linux/sched.h>
22 #include <linux/utsname.h>
25 #include <linux/module.h>
35 #include <linux/time.h>
36 #include <linux/ptrace.h>
37 #include <linux/sysctl.h>
42 #include <linux/slab.h>
71 static int kdb_go_count;
72 #ifdef CONFIG_KDB_CONTINUE_CATASTROPHIC
73 static unsigned int kdb_continue_catastrophic =
74 CONFIG_KDB_CONTINUE_CATASTROPHIC;
76 static unsigned int kdb_continue_catastrophic;
80 static kdbtab_t *kdb_commands;
81 #define KDB_BASE_CMD_MAX 50
84 #define for_each_kdbcmd(cmd, num) \
85 for ((cmd) = kdb_base_commands, (num) = 0; \
86 num < kdb_max_commands; \
87 num++, num == KDB_BASE_CMD_MAX ? cmd = kdb_commands : cmd++)
94 #define KDBMSG(msgnum, text) \
95 { KDB_##msgnum, text }
98 KDBMSG(NOTFOUND,
"Command Not Found"),
99 KDBMSG(ARGCOUNT,
"Improper argument count, see usage."),
100 KDBMSG(BADWIDTH,
"Illegal value for BYTESPERWORD use 1, 2, 4 or 8, "
101 "8 is only allowed on 64 bit systems"),
102 KDBMSG(BADRADIX,
"Illegal value for RADIX use 8, 10 or 16"),
103 KDBMSG(NOTENV,
"Cannot find environment variable"),
104 KDBMSG(NOENVVALUE,
"Environment variable should have value"),
105 KDBMSG(NOTIMP,
"Command not implemented"),
106 KDBMSG(ENVFULL,
"Environment full"),
107 KDBMSG(ENVBUFFULL,
"Environment buffer full"),
108 KDBMSG(TOOMANYBPT,
"Too many breakpoints defined"),
109 #ifdef CONFIG_CPU_XSCALE
110 KDBMSG(TOOMANYDBREGS,
"More breakpoints than ibcr registers defined"),
112 KDBMSG(TOOMANYDBREGS,
"More breakpoints than db registers defined"),
114 KDBMSG(DUPBPT,
"Duplicate breakpoint address"),
115 KDBMSG(BPTNOTFOUND,
"Breakpoint not found"),
116 KDBMSG(BADMODE,
"Invalid IDMODE"),
117 KDBMSG(BADINT,
"Illegal numeric value"),
118 KDBMSG(INVADDRFMT,
"Invalid symbolic address format"),
119 KDBMSG(BADREG,
"Invalid register name"),
120 KDBMSG(BADCPUNUM,
"Invalid cpu number"),
121 KDBMSG(BADLENGTH,
"Invalid length field"),
122 KDBMSG(NOBP,
"No Breakpoint exists"),
123 KDBMSG(BADADDR,
"Invalid address"),
127 static const int __nkdb_err =
sizeof(kdbmsgs) /
sizeof(
kdbmsg_t);
140 static char *__env[] = {
141 #if defined(CONFIG_SMP)
178 static const int __nenv = (
sizeof(__env) /
sizeof(
char *));
202 int matchlen =
strlen(match);
205 for (i = 0; i < __nenv; i++) {
211 if ((
strncmp(match, e, matchlen) == 0)
212 && ((e[matchlen] ==
'\0')
213 || (e[matchlen] ==
'='))) {
215 return cp ? ++cp :
"";
237 static char *kdballocenv(
size_t bytes)
239 #define KDB_ENVBUFSIZE 512
241 static int envbufsize;
244 if ((KDB_ENVBUFSIZE - envbufsize) >= bytes) {
245 ep = &envbuffer[envbufsize];
261 static int kdbgetulenv(
const char *
match,
unsigned long *
value)
269 return KDB_NOENVVALUE;
291 diag = kdbgetulenv(match, &val);
356 size_t varlen, vallen;
375 if (
strcmp(argv[1],
"KDBDEBUG") == 0) {
376 unsigned int debugflags;
398 ep = kdballocenv(varlen + vallen + 2);
400 return KDB_ENVBUFFULL;
402 sprintf(ep,
"%s=%s", argv[1], argv[2]);
404 ep[varlen+vallen+1] =
'\0';
406 for (i = 0; i < __nenv; i++) {
408 && ((
strncmp(__env[i], argv[1], varlen) == 0)
409 && ((__env[i][varlen] ==
'\0')
410 || (__env[i][varlen] ==
'=')))) {
419 for (i = 0; i < __nenv-1; i++) {
420 if (__env[i] == (
char *)0) {
429 static int kdb_check_regs(
void)
431 if (!kdb_current_regs) {
433 " You may need to select another task\n");
465 unsigned long *value,
long *
offset,
469 unsigned long off = 0;
489 symname = (
char *)argv[*nextarg];
503 if (symname[0] ==
'$') {
504 diag = kdbgetulenv(&symname[1], &addr);
507 }
else if (symname[0] ==
'%') {
508 diag = kdb_check_regs();
535 if (offset && name && *name)
538 if ((*nextarg > argc)
546 if (symbol ==
'\0') {
547 if ((argv[*nextarg][0] !=
'+')
548 && (argv[*nextarg][0] !=
'-')) {
554 positive = (argv[*nextarg][0] ==
'+');
558 positive = (symbol ==
'+');
563 if ((*nextarg > argc)
564 && (symbol ==
'\0')) {
565 return KDB_INVADDRFMT;
569 cp = (
char *)argv[*nextarg];
589 static void kdb_cmderror(
int diag)
594 kdb_printf(
"no error detected (diagnostic is %d)\n", diag);
598 for (i = 0; i < __nkdb_err; i++) {
599 if (kdbmsgs[i].km_diag == diag) {
600 kdb_printf(
"diag: %d: %s\n", diag, kdbmsgs[i].km_msg);
629 static int defcmd_set_count;
630 static int defcmd_in_progress;
633 static int kdb_exec_defcmd(
int argc,
const char **argv);
635 static int kdb_defcmd2(
const char *
cmdstr,
const char *argv0)
637 struct defcmd_set *
s = defcmd_set + defcmd_set_count - 1;
638 char **save_command = s->
command;
639 if (
strcmp(argv0,
"endefcmd") == 0) {
640 defcmd_in_progress = 0;
652 kdb_printf(
"Could not allocate new kdb_defcmd table for %s\n",
663 static int kdb_defcmd(
int argc,
const char **argv)
665 struct defcmd_set *save_defcmd_set = defcmd_set, *
s;
666 if (defcmd_in_progress) {
667 kdb_printf(
"kdb: nested defcmd detected, assuming missing "
669 kdb_defcmd2(
"endefcmd",
"endefcmd");
673 for (s = defcmd_set; s < defcmd_set + defcmd_set_count; ++
s) {
676 for (i = 0; i < s->
count; ++
i)
684 defcmd_set =
kmalloc((defcmd_set_count + 1) *
sizeof(*defcmd_set),
687 kdb_printf(
"Could not allocate new defcmd_set entry for %s\n",
689 defcmd_set = save_defcmd_set;
692 memcpy(defcmd_set, save_defcmd_set,
693 defcmd_set_count *
sizeof(*defcmd_set));
694 kfree(save_defcmd_set);
695 s = defcmd_set + defcmd_set_count;
701 if (s->
usage[0] ==
'"') {
705 if (s->
help[0] ==
'"') {
710 defcmd_in_progress = 1;
723 static int kdb_exec_defcmd(
int argc,
const char **argv)
726 struct defcmd_set *
s;
729 for (s = defcmd_set, i = 0; i < defcmd_set_count; ++
i, ++
s) {
733 if (i == defcmd_set_count) {
734 kdb_printf(
"kdb_exec_defcmd: could not find commands for %s\n",
738 for (i = 0; i < s->
count; ++
i) {
751 #define KDB_CMD_HISTORY_COUNT 32
752 #define CMD_BUFLEN 200
754 static unsigned int cmd_head, cmd_tail;
755 static unsigned int cmdptr;
762 static void parse_grep(
const char *
str)
765 char *
cp = (
char *)str, *cp2;
795 kdb_printf(
"invalid quoted string, see grephelp\n");
807 if (*(cp+len-1) ==
'$') {
859 int i, escaped, ignore_errors = 0, check_grep;
875 if (*cp !=
'\n' && *cp !=
'\0') {
882 if ((*cp ==
'\0') || (*cp ==
'\n') ||
883 (*cp ==
'#' && !defcmd_in_progress))
892 "overflow, command ignored\n%s\n",
898 "command ignored\n%s\n", cmdstr);
906 while (*cp && *cp !=
'\n' &&
907 (escaped || quoted || !
isspace(*cp))) {
922 else if (*cp ==
'\'' || *cp ==
'"')
925 if (*cpp ==
'=' && !quoted)
936 if (defcmd_in_progress) {
937 int result = kdb_defcmd2(cmdstr, argv[0]);
938 if (!defcmd_in_progress) {
944 if (argv[0][0] ==
'-' && argv[0][1] &&
945 (argv[0][1] <
'0' || argv[0][1] >
'9')) {
958 && (
strlen(argv[0]) <= tp->cmd_minlen)) {
961 tp->cmd_minlen) == 0) {
966 if (
strcmp(argv[0], tp->cmd_name) == 0)
976 if (i == kdb_max_commands) {
981 strlen(tp->cmd_name)) == 0) {
988 if (i < kdb_max_commands) {
991 result = (*tp->cmd_func)(argc-1, (
const char **)argv);
992 if (result && ignore_errors && result >
KDB_CMD_GO)
995 switch (tp->cmd_repeat) {
1020 unsigned long value;
1027 return KDB_NOTFOUND;
1038 static int handle_ctrl_cmd(
char *
cmd)
1044 if (cmd_head == cmd_tail)
1048 if (cmdptr != cmd_tail)
1053 if (cmdptr != cmd_head)
1065 static int kdb_reboot(
int argc,
const char **argv)
1068 kdb_printf(
"Hmm, kdb_reboot did not reboot, spinning here\n");
1088 kdb_current_task =
p;
1090 if (kdb_task_has_cpu(p)) {
1091 kdb_current_regs = KDB_TSKREGS(kdb_process_cpu(p));
1094 kdb_current_regs =
NULL;
1118 kdb_dbtrap_t db_result)
1127 if (reason == KDB_REASON_DEBUG) {
1130 kdb_printf(
"\nEntering kdb (current=0x%p, pid %d) ",
1131 kdb_current, kdb_current ? kdb_current->
pid : 0);
1132 #if defined(CONFIG_SMP)
1138 case KDB_REASON_DEBUG:
1144 switch (db_result) {
1147 kdb_current, kdb_current->
pid);
1148 #if defined(CONFIG_SMP)
1151 kdb_printf(
"due to Debug @ " kdb_machreg_fmt
"\n",
1168 kdb_printf(
"kdb: Bad result from kdba_db_trap: %d\n",
1175 case KDB_REASON_ENTER:
1181 case KDB_REASON_KEYBOARD:
1185 case KDB_REASON_ENTER_SLAVE:
1187 case KDB_REASON_SWITCH:
1190 case KDB_REASON_OOPS:
1192 kdb_printf(
"due to oops @ " kdb_machreg_fmt
"\n",
1196 case KDB_REASON_NMI:
1198 kdb_machreg_fmt
"\n",
1202 case KDB_REASON_SSTEP:
1203 case KDB_REASON_BREAK:
1204 kdb_printf(
"due to %s @ " kdb_machreg_fmt
"\n",
1205 reason == KDB_REASON_BREAK ?
1211 if (db_result != KDB_DB_BPT) {
1212 kdb_printf(
"kdb: error return from kdba_bp_trap: %d\n",
1218 case KDB_REASON_RECURSE:
1219 kdb_printf(
"due to Recursion @ " kdb_machreg_fmt
"\n",
1223 kdb_printf(
"kdb: unexpected reason code: %d\n", reason);
1237 *(cmd_hist[cmd_head]) =
'\0';
1240 #if defined(CONFIG_SMP)
1246 if (defcmd_in_progress)
1253 if (*cmdbuf !=
'\n') {
1255 if (cmdptr == cmd_head) {
1256 strncpy(cmd_hist[cmd_head], cmd_cur,
1258 *(cmd_hist[cmd_head] +
1259 strlen(cmd_hist[cmd_head])-1) =
'\0';
1261 if (!handle_ctrl_cmd(cmdbuf))
1262 *(cmd_cur+
strlen(cmd_cur)-1) =
'\0';
1264 goto do_full_getstr;
1266 strncpy(cmd_hist[cmd_head], cmd_cur,
1271 if (cmd_head == cmd_tail)
1277 if (diag == KDB_NOTFOUND) {
1278 kdb_printf(
"Unknown kdb command: '%s'\n", cmdbuf);
1305 kdb_printf(
"state: %s cpu %d value %d initial %d state %x\n",
1335 int kdb_main_loop(kdb_reason_t reason, kdb_reason_t reason2,
int error,
1336 kdb_dbtrap_t db_result,
struct pt_regs *regs)
1360 result = kdb_local(reason2, error, regs, db_result);
1379 kdb_printf(
"Entering please attach debugger "
1380 "or use $D#44+ or $3#33\n");
1383 if (result && result != 1 && result !=
KDB_CMD_GO)
1384 kdb_printf(
"\nUnexpected kdb_local return code %d\n",
1408 static int kdb_mdr(
unsigned long addr,
unsigned int count)
1431 static void kdb_md_line(
const char *fmtstr,
unsigned long addr,
1432 int symbolic,
int nosect,
int bytesperword,
1433 int num,
int repeat,
int phys)
1442 memset(cbuf,
'\0',
sizeof(cbuf));
1444 kdb_printf(
"phys " kdb_machreg_fmt0
" ", addr);
1448 for (i = 0; i < num && repeat--; i++) {
1452 }
else if (
kdb_getword(&word, addr, bytesperword))
1458 memset(&symtab, 0,
sizeof(symtab));
1470 addr += bytesperword;
1478 cp =
wc.c + 8 - bytesperword;
1483 #define printable_char(c) \
1484 ({unsigned char __c = c; isascii(__c) && isprint(__c) ? __c : '.'; })
1485 switch (bytesperword) {
1504 #undef printable_char
1507 kdb_printf(
"%*s %s\n", (
int)((num-i)*(2*bytesperword + 1)+1),
1511 static int kdb_md(
int argc,
const char **argv)
1513 static unsigned long last_addr;
1514 static int last_radix, last_bytesperword, last_repeat;
1515 int radix = 16, mdcount = 8, bytesperword = KDB_WORD_SIZE, repeat;
1517 char fmtchar, fmtstr[64];
1530 repeat = mdcount * 16 / bytesperword;
1532 if (
strcmp(argv[0],
"mdr") == 0) {
1534 return KDB_ARGCOUNT;
1536 }
else if (
isdigit(argv[0][2])) {
1537 bytesperword = (
int)(argv[0][2] -
'0');
1538 if (bytesperword == 0) {
1539 bytesperword = last_bytesperword;
1540 if (bytesperword == 0)
1543 last_bytesperword = bytesperword;
1544 repeat = mdcount * 16 / bytesperword;
1547 else if (argv[0][3] ==
'c' && argv[0][4]) {
1550 mdcount = ((repeat * bytesperword) + 15) / 16;
1553 last_repeat = repeat;
1554 }
else if (
strcmp(argv[0],
"md") == 0)
1556 else if (
strcmp(argv[0],
"mds") == 0)
1558 else if (
strcmp(argv[0],
"mdp") == 0) {
1562 return KDB_NOTFOUND;
1566 return KDB_ARGCOUNT;
1569 bytesperword = last_bytesperword;
1570 repeat = last_repeat;
1571 mdcount = ((repeat * bytesperword) + 15) / 16;
1576 int diag, nextarg = 1;
1581 if (argc > nextarg+2)
1582 return KDB_ARGCOUNT;
1584 if (argc >= nextarg) {
1587 mdcount = (
int) val;
1588 repeat = mdcount * 16 / bytesperword;
1591 if (argc >= nextarg+1) {
1598 if (
strcmp(argv[0],
"mdr") == 0)
1599 return kdb_mdr(addr, mdcount);
1612 return KDB_BADRADIX;
1617 if (bytesperword > KDB_WORD_SIZE)
1618 return KDB_BADWIDTH;
1620 switch (bytesperword) {
1622 sprintf(fmtstr,
"%%16.16l%c ", fmtchar);
1625 sprintf(fmtstr,
"%%8.8l%c ", fmtchar);
1628 sprintf(fmtstr,
"%%4.4l%c ", fmtchar);
1631 sprintf(fmtstr,
"%%2.2l%c ", fmtchar);
1634 return KDB_BADWIDTH;
1637 last_repeat = repeat;
1638 last_bytesperword = bytesperword;
1640 if (
strcmp(argv[0],
"mds") == 0) {
1645 bytesperword = KDB_WORD_SIZE;
1652 addr &= ~(bytesperword-1);
1654 while (repeat > 0) {
1656 int n, z, num = (symbolic ? 1 : (16 / bytesperword));
1660 for (a = addr, z = 0; z < repeat; a += bytesperword, ++z) {
1668 n =
min(num, repeat);
1669 kdb_md_line(fmtstr, addr, symbolic, nosect, bytesperword,
1671 addr += bytesperword *
n;
1673 z = (z + num - 1) / num;
1675 int s = num * (z-2);
1676 kdb_printf(kdb_machreg_fmt0
"-" kdb_machreg_fmt0
1677 " zero suppressed\n",
1678 addr, addr + bytesperword * s - 1);
1679 addr += bytesperword *
s;
1694 static int kdb_mm(
int argc,
const char **argv)
1699 unsigned long contents;
1703 if (argv[0][2] && !
isdigit(argv[0][2]))
1704 return KDB_NOTFOUND;
1707 return KDB_ARGCOUNT;
1715 return KDB_ARGCOUNT;
1720 if (nextarg != argc + 1)
1721 return KDB_ARGCOUNT;
1723 width = argv[0][2] ? (argv[0][2] -
'0') : (KDB_WORD_SIZE);
1728 kdb_printf(kdb_machreg_fmt
" = " kdb_machreg_fmt
"\n", addr, contents);
1737 static int kdb_go(
int argc,
const char **argv)
1745 kdb_printf(
"go must execute on the entry cpu, "
1746 "please use \"cpu %d\" and then execute go\n",
1748 return KDB_BADCPUNUM;
1753 &addr, &offset,
NULL);
1757 return KDB_ARGCOUNT;
1761 if (KDB_FLAG(CATASTROPHIC)) {
1764 kdb_continue_catastrophic);
1765 if (kdb_continue_catastrophic == 0 && kdb_go_count++ == 0) {
1766 kdb_printf(
"type go a second time if you really want "
1770 if (kdb_continue_catastrophic == 2) {
1772 kdb_reboot(0,
NULL);
1782 static int kdb_rd(
int argc,
const char **argv)
1784 int len = kdb_check_regs();
1785 #if DBG_MAX_REG_NUM > 0
1830 len +=
kdb_printf(
"%s: %016llx", rname, reg64);
1841 kdb_dumpregs(kdb_current_regs);
1852 static int kdb_rm(
int argc,
const char **argv)
1854 #if DBG_MAX_REG_NUM > 0
1864 return KDB_ARGCOUNT;
1876 diag = kdb_check_regs();
1908 kdb_printf(
"ERROR: Register set currently not implemented\n");
1913 #if defined(CONFIG_MAGIC_SYSRQ)
1919 static int kdb_sr(
int argc,
const char **argv)
1922 return KDB_ARGCOUNT;
1940 static int kdb_ef(
int argc,
const char **argv)
1948 return KDB_ARGCOUNT;
1958 #if defined(CONFIG_MODULES)
1964 static int kdb_lsmod(
int argc,
const char **argv)
1969 return KDB_ARGCOUNT;
1971 kdb_printf(
"Module Size modstruct Used by\n");
1975 mod->core_size, (
void *)mod);
1976 #ifdef CONFIG_MODULE_UNLOAD
1979 if (mod->state == MODULE_STATE_GOING)
1981 else if (mod->state == MODULE_STATE_COMING)
1987 #ifdef CONFIG_MODULE_UNLOAD
1989 struct module_use *use;
2009 static int kdb_env(
int argc,
const char **argv)
2013 for (i = 0; i < __nenv; i++) {
2024 #ifdef CONFIG_PRINTK
2030 static int kdb_dmesg(
int argc,
const char **argv)
2043 return KDB_ARGCOUNT;
2051 if (*cp || adjust < 0)
2058 if (!diag && logging) {
2059 const char *setargs[] = {
"set",
"LOGGING",
"0" };
2063 kmsg_dump_rewind_nolock(&dumper);
2064 while (kmsg_dump_get_line_nolock(&dumper, 1,
NULL, 0,
NULL))
2069 kdb_printf(
"buffer only contains %d lines, nothing "
2071 else if (adjust - lines >= n)
2072 kdb_printf(
"buffer only contains %d lines, last %d "
2073 "lines printed\n", n, n - adjust);
2076 }
else if (lines > 0) {
2077 skip = n - lines - adjust;
2081 "nothing printed\n", n);
2083 }
else if (skip < 0) {
2086 kdb_printf(
"buffer only contains %d lines, first "
2087 "%d lines printed\n", n, lines);
2093 if (skip >= n || skip < 0)
2096 kmsg_dump_rewind_nolock(&dumper);
2097 while (kmsg_dump_get_line_nolock(&dumper, 1, buf,
sizeof(buf), &len)) {
2117 static int kdb_disable_nmi(
int argc,
const char *argv[])
2126 static int kdb_param_enable_nmi(
const char *val,
const struct kernel_param *kp)
2128 if (!atomic_add_unless(&kdb_nmi_disabled, -1, 0))
2135 .set = kdb_param_enable_nmi,
2145 static void kdb_cpu_status(
void)
2147 int i, start_cpu, first_print = 1;
2152 for (start_cpu = -1, i = 0; i <
NR_CPUS; i++) {
2160 if (state != prev_state) {
2161 if (prev_state !=
'?') {
2166 if (start_cpu < i-1)
2168 if (prev_state !=
' ')
2176 if (prev_state !=
'F') {
2180 if (start_cpu < i-1)
2182 if (prev_state !=
' ')
2188 static int kdb_cpu(
int argc,
const char **argv)
2199 return KDB_ARGCOUNT;
2208 if ((cpunum > NR_CPUS) || !
cpu_online(cpunum))
2209 return KDB_BADCPUNUM;
2224 int idle = 0, daemon = 0;
2234 kdb_do_each_thread(g, p) {
2237 } kdb_while_each_thread(g, p);
2238 if (idle || daemon) {
2240 kdb_printf(
"%d idle process%s (state I)%s\n",
2241 idle, idle == 1 ?
"" :
"es",
2242 daemon ?
" and " :
"");
2244 kdb_printf(
"%d sleeping system daemon (state M) "
2245 "process%s", daemon,
2246 daemon == 1 ?
"" :
"es");
2247 kdb_printf(
" suppressed,\nuse 'ps A' to see all.\n");
2264 cpu = kdb_process_cpu(p);
2265 kdb_printf(
"0x%p %8d %8d %d %4d %c 0x%p %c%s\n",
2267 kdb_task_has_cpu(p), kdb_process_cpu(p),
2272 if (kdb_task_has_cpu(p)) {
2273 if (!KDB_TSK(cpu)) {
2274 kdb_printf(
" Error: no saved data for this cpu\n");
2276 if (KDB_TSK(cpu) != p)
2278 "process table (0x%p)\n", KDB_TSK(cpu));
2283 static int kdb_ps(
int argc,
const char **argv)
2290 kdb_printf(
"%-*s Pid Parent [*] cpu State %-*s Command\n",
2291 (
int)(2*
sizeof(
void *))+2,
"Task Addr",
2292 (
int)(2*
sizeof(
void *))+2,
"Thread");
2304 kdb_do_each_thread(g, p) {
2309 } kdb_while_each_thread(g, p);
2319 static int kdb_pid(
int argc,
const char **argv)
2326 return KDB_ARGCOUNT;
2329 if (
strcmp(argv[1],
"R") == 0) {
2344 kdb_printf(
"KDB current process is %s(pid=%d)\n",
2345 kdb_current_task->
comm,
2346 kdb_current_task->
pid);
2356 static int kdb_ll(
int argc,
const char **argv)
2362 unsigned long linkoffset;
2367 return KDB_ARGCOUNT;
2387 kdb_printf(
"%s: cannot duplicate command\n", __func__);
2399 sprintf(buf,
"%s " kdb_machreg_fmt
"\n", command, va);
2404 addr = va + linkoffset;
2414 static int kdb_kgdb(
int argc,
const char **argv)
2422 static int kdb_help(
int argc,
const char **argv)
2427 kdb_printf(
"%-15.15s %-20.20s %s\n",
"Command",
"Usage",
"Description");
2429 "-----------------------------\n");
2432 kdb_printf(
"%-15.15s %-20.20s %s\n", kt->cmd_name,
2433 kt->cmd_usage, kt->cmd_help);
2443 static int kdb_kill(
int argc,
const char **argv)
2451 return KDB_ARGCOUNT;
2457 kdb_printf(
"Invalid signal parameter.<-signal>\n");
2466 kdb_printf(
"Process ID must be large than 0.\n");
2473 kdb_printf(
"The specified process isn't found.\n");
2482 kdb_send_sig_info(p, &
info);
2498 static int mon_day[] = { 31, 29, 31, 30, 31, 30, 31,
2499 31, 30, 31, 30, 31 };
2500 memset(tm, 0,
sizeof(*tm));
2512 if (++tm->
tm_mon == 12) {
2526 static void kdb_sysinfo(
struct sysinfo *val)
2530 memset(val, 0,
sizeof(*val));
2531 val->
uptime = uptime.tv_sec;
2544 static int kdb_summary(
int argc,
const char **argv)
2551 return KDB_ARGCOUNT;
2562 kdb_gmtime(&now, &tm);
2563 kdb_printf(
"date %04d-%02d-%02d %02d:%02d:%02d "
2564 "tz_minuteswest %d\n",
2571 if (val.
uptime > (24*60*60)) {
2572 int days = val.
uptime / (24*60*60);
2573 val.
uptime %= (24*60*60);
2574 kdb_printf(
"%d day%s ", days, days == 1 ?
"" :
"s");
2580 #define LOAD_INT(x) ((x) >> FSHIFT)
2581 #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
2582 kdb_printf(
"load avg %ld.%02ld %ld.%02ld %ld.%02ld\n",
2589 #define K(x) ((x) << (PAGE_SHIFT - 10))
2590 kdb_printf(
"\nMemTotal: %8lu kB\nMemFree: %8lu kB\n"
2591 "Buffers: %8lu kB\n",
2599 static int kdb_per_cpu(
int argc,
const char **argv)
2603 unsigned long addr, symaddr,
val, bytesperword = 0, whichcpu = ~0
UL;
2605 if (argc < 1 || argc > 3)
2606 return KDB_ARGCOUNT;
2618 bytesperword = KDB_WORD_SIZE;
2619 else if (bytesperword > KDB_WORD_SIZE)
2620 return KDB_BADWIDTH;
2621 sprintf(fmtstr,
"%%0%dlx ", (
int)(2*bytesperword));
2627 kdb_printf(
"cpu %ld is not online\n", whichcpu);
2628 return KDB_BADCPUNUM;
2635 #ifdef __per_cpu_offset
2636 #define KDB_PCU(cpu) __per_cpu_offset(cpu)
2639 #define KDB_PCU(cpu) __per_cpu_offset[cpu]
2641 #define KDB_PCU(cpu) 0
2648 if (whichcpu != ~0
UL && whichcpu != cpu)
2650 addr = symaddr +
KDB_PCU(cpu);
2653 kdb_printf(
"%5d " kdb_bfd_vma_fmt0
" - unable to "
2654 "read, diag=%d\n", cpu, addr, diag);
2658 kdb_md_line(fmtstr, addr,
2659 bytesperword == KDB_WORD_SIZE,
2660 1, bytesperword, 1, 1, 0);
2669 static int kdb_grep_help(
int argc,
const char **argv)
2671 kdb_printf(
"Usage of cmd args | grep pattern:\n");
2672 kdb_printf(
" Any command's output may be filtered through an ");
2675 kdb_printf(
" The pattern may include a very limited set of "
2676 "metacharacters:\n");
2677 kdb_printf(
" pattern or ^pattern or pattern$ or ^pattern$\n");
2678 kdb_printf(
" And if there are spaces in the pattern, you may "
2680 kdb_printf(
" \"pat tern\" or \"^pat tern\" or \"pat tern$\""
2681 " or \"^pat tern$\"\n");
2697 #define kdb_command_extend 50
2712 if (kp->cmd_name && (
strcmp(kp->cmd_name, cmd) == 0)) {
2713 kdb_printf(
"Duplicate kdb command registered: "
2714 "%s, func %p help %s\n", cmd, func, help);
2723 if (kp->cmd_name ==
NULL)
2727 if (i >= kdb_max_commands) {
2731 kdb_printf(
"Could not allocate new kdb_command "
2736 memcpy(
new, kdb_commands,
2738 kfree(kdb_commands);
2740 memset(
new + kdb_max_commands, 0,
2748 kp->cmd_func =
func;
2749 kp->cmd_usage =
usage;
2750 kp->cmd_help = help;
2752 kp->cmd_minlen = minlen;
2753 kp->cmd_repeat = repeat;
2801 if (kp->cmd_name && (
strcmp(kp->cmd_name, cmd) == 0)) {
2802 kp->cmd_name =
NULL;
2813 static void __init kdb_inittab(
void)
2819 kp->cmd_name =
NULL;
2822 "Display
Memory Contents, also mdWcN,
e.g. md8c1", 1,
2825 "Display Raw
Memory", 0, KDB_REPEAT_NO_ARGS);
2827 "Display Physical Memory", 0, KDB_REPEAT_NO_ARGS);
2829 "Display Memory Symbolically", 0, KDB_REPEAT_NO_ARGS);
2831 "Modify Memory Contents", 0, KDB_REPEAT_NO_ARGS);
2835 "Display Registers", 0, KDB_REPEAT_NONE);
2837 "Modify Registers", 0, KDB_REPEAT_NONE);
2841 "
Stack traceback", 1, KDB_REPEAT_NONE);
2843 "Display
stack for process <pid>", 0, KDB_REPEAT_NONE);
2845 "Display
stack all processes", 0, KDB_REPEAT_NONE);
2847 "Backtrace
current process on each cpu", 0, KDB_REPEAT_NONE);
2854 "Show
environment variables", 0, KDB_REPEAT_NONE);
2858 "Display Help Message", 1, KDB_REPEAT_NONE);
2860 "Display Help Message", 0, KDB_REPEAT_NONE);
2862 "Switch to new cpu", 0, KDB_REPEAT_NONE);
2864 "Enter kgdb
mode", 0, KDB_REPEAT_NONE);
2866 "Display
active task list", 0, KDB_REPEAT_NONE);
2868 "Switch to another
task", 0, KDB_REPEAT_NONE);
2870 "Reboot
the machine immediately", 0, KDB_REPEAT_NONE);
2871 #if defined(CONFIG_MODULES)
2873 "List loaded kernel modules", 0, KDB_REPEAT_NONE);
2875 #if defined(CONFIG_MAGIC_SYSRQ)
2877 "Magic SysRq key", 0, KDB_REPEAT_NONE);
2879 #if defined(CONFIG_PRINTK)
2881 "Display syslog buffer", 0, KDB_REPEAT_NONE);
2885 "Disable NMI entry to KDB", 0, KDB_REPEAT_NONE);
2888 "Define a set of commands, down to endefcmd", 0, KDB_REPEAT_NONE);
2890 "Send a signal to a process", 0, KDB_REPEAT_NONE);
2892 "Summarize the system", 4, KDB_REPEAT_NONE);
2894 "Display per_cpu variables", 3, KDB_REPEAT_NONE);
2896 "Display help on | grep", 0, KDB_REPEAT_NONE);
2900 static void __init kdb_cmd_init(
void)
2903 for (i = 0; kdb_cmds[
i]; ++
i) {
2906 kdb_printf(
"kdb command %s failed, kdb diag %d\n",
2909 if (defcmd_in_progress) {
2910 kdb_printf(
"Incomplete 'defcmd' set, forcing endefcmd\n");
2923 for (i = kdb_init_lvl; i < lvl; i++) {