-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlkmd_main.c
3339 lines (2995 loc) · 82 KB
/
lkmd_main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Kernel Debugger Architecture Independent Main Code
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file "COPYING" in the main directory of this archive
* for more details.
*
* Copyright (C) 1999-2004 Silicon Graphics, Inc. All Rights Reserved.
* Copyright (C) 2000 Stephane Eranian <eranian@hpl.hp.com>
*/
#include <linux/ctype.h>
#include <linux/string.h>
#include <linux/kernel.h>
#include <linux/reboot.h>
#include <linux/sched.h>
#include <linux/smp.h>
#include <linux/utsname.h>
#include <linux/vmalloc.h>
#include <linux/module.h>
#include <linux/mm.h>
#include <linux/init.h>
#include <linux/kallsyms.h>
#include <linux/notifier.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/nmi.h>
#include <linux/ptrace.h>
#include <linux/cpu.h>
#include <linux/kdebug.h>
#include "lkmd.h"
#include "lkmd_private.h"
// #include <acpi/acpi_bus.h>
#include <linux/acpi.h>
// #include <asm/system.h>
#include <asm/kdebug.h>
#include <linux/proc_fs.h>
#include <asm/uaccess.h>
/*
* Kernel debugger state flags
*/
volatile int kdb_flags;
/*
* kdb_lock protects updates to kdb_initial_cpu. Used to
* single thread processors through the kernel debugger.
*/
static DEFINE_SPINLOCK(kdb_lock);
volatile int kdb_initial_cpu = -1; /* cpu number that owns kdb */
int kdb_seqno = 2; /* how many times kdb has been entered */
volatile int kdb_nextline = 1;
static volatile int kdb_new_cpu; /* Which cpu to switch to */
volatile int kdb_state[NR_CPUS]; /* Per cpu state */
const struct task_struct *lkmd_current_task;
struct pt_regs *kdb_current_regs;
int kdb_on = 1; /* Default is on */
const char *kdb_diemsg;
#ifdef kdba_setjmp
/*
* Must have a setjmp buffer per CPU. Switching cpus will
* cause the jump buffer to be setup for the new cpu, and
* subsequent switches (and pager aborts) will use the
* appropriate per-processor values.
*/
kdb_jmp_buf *kdbjmpbuf;
#endif /* kdba_setjmp */
/*
* kdb_commands describes the available commands.
*/
static kdbtab_t *kdb_commands;
static int kdb_max_commands;
typedef struct _kdbmsg {
int km_diag; /* kdb diagnostic */
char *km_msg; /* Corresponding message text */
} kdbmsg_t;
#define KDBMSG(msgnum, text) \
{ KDB_##msgnum, text }
static kdbmsg_t kdbmsgs[] = {
KDBMSG(NOTFOUND,"Command Not Found"),
KDBMSG(ARGCOUNT, "Improper argument count, see usage."),
KDBMSG(BADWIDTH, "Illegal value for BYTESPERWORD use 1, 2, 4 or 8, 8 is only allowed on 64 bit systems"),
KDBMSG(BADRADIX, "Illegal value for RADIX use 8, 10 or 16"),
KDBMSG(NOTENV, "Cannot find environment variable"),
KDBMSG(NOENVVALUE, "Environment variable should have value"),
KDBMSG(NOTIMP, "Command not implemented"),
KDBMSG(ENVFULL, "Environment full"),
KDBMSG(ENVBUFFULL, "Environment buffer full"),
KDBMSG(TOOMANYBPT, "Too many breakpoints defined"),
KDBMSG(TOOMANYDBREGS, "More breakpoints than db registers defined"),
KDBMSG(DUPBPT, "Duplicate breakpoint address"),
KDBMSG(BPTNOTFOUND, "Breakpoint not found"),
KDBMSG(BADMODE, "Invalid IDMODE"),
KDBMSG(BADINT, "Illegal numeric value"),
KDBMSG(INVADDRFMT, "Invalid symbolic address format"),
KDBMSG(BADREG, "Invalid register name"),
KDBMSG(BADCPUNUM, "Invalid cpu number"),
KDBMSG(BADLENGTH, "Invalid length field"),
KDBMSG(NOBP, "No Breakpoint exists"),
KDBMSG(BADADDR, "Invalid address"),
};
#undef KDBMSG
static const int __nkdb_err = sizeof(kdbmsgs) / sizeof(kdbmsg_t);
/*
* Initial environment. This is all kept static and local to
* this file. We don't want to rely on the memory allocation
* mechanisms in the kernel, so we use a very limited allocate-only
* heap for new and altered environment variables. The entire
* environment is limited to a fixed number of entries (add more
* to __env[] if required) and a fixed amount of heap (add more to
* KDB_ENVBUFSIZE if required).
*/
static char *__env[] = {
#if defined(CONFIG_SMP)
"PROMPT=[%d]LKMD> ",
"MOREPROMPT=[%d]more> ",
#else
"PROMPT=LKMD> ",
"MOREPROMPT=more> ",
#endif
"RADIX=16",
"LINES=24",
"COLUMNS=80",
"MDCOUNT=8", /* lines of md output */
"BTARGS=9", /* 9 possible args in bt */
KDB_PLATFORM_ENV,
"DTABCOUNT=30",
"NOSECT=1",
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
};
static const int __nenv = (sizeof(__env) / sizeof(char *));
/* external commands: */
// int kdb_debuginfo_print(int argc, const char **argv);
// int kdb_pxhelp(int argc, const char **argv);
// int kdb_walkhelp(int argc, const char **argv);
// int kdb_walk(int argc, const char **argv);
struct task_struct *kdb_curr_task(int cpu)
{
struct task_struct *p = lkmd_curr_task(cpu);
#ifdef _TIF_MCA_INIT
struct kdb_running_process *krp = kdb_running_process + cpu;
if ((task_thread_info(p)->flags & _TIF_MCA_INIT) && krp->p)
p = krp->p;
#endif
return p;
}
/*
* kdbgetenv
*
* This function will return the character string value of
* an environment variable.
*
* Parameters:
* match A character string representing an environment variable.
* Outputs:
* None.
* Returns:
* NULL No environment variable matches 'match'
* char* Pointer to string value of environment variable.
* Locking:
* No locking considerations required.
* Remarks:
*/
char *kdbgetenv(const char *match)
{
char **ep = __env;
int matchlen = strlen(match);
int i;
for(i = 0; i < __nenv; i++) {
char *e = *ep++;
if (!e) continue;
if ((strncmp(match, e, matchlen) == 0) && ((e[matchlen] == '\0') ||(e[matchlen] == '='))) {
char *cp = strchr(e, '=');
return (cp ? ++cp :"");
}
}
return NULL;
}
/*
* kdballocenv
*
* This function is used to allocate bytes for environment entries.
*
* Parameters:
* match A character string representing a numeric value
* Outputs:
* *value the unsigned long represntation of the env variable 'match'
* Returns:
* Zero on success, a kdb diagnostic on failure.
* Locking:
* No locking considerations required. Must be called with all
* processors halted.
* Remarks:
* We use a static environment buffer (envbuffer) to hold the values
* of dynamically generated environment variables (see kdb_set). Buffer
* space once allocated is never free'd, so over time, the amount of space
* (currently 512 bytes) will be exhausted if env variables are changed
* frequently.
*/
static char *kdballocenv(size_t bytes)
{
#define KDB_ENVBUFSIZE 512
static char envbuffer[KDB_ENVBUFSIZE];
static int envbufsize;
char *ep = NULL;
if ((KDB_ENVBUFSIZE - envbufsize) >= bytes) {
ep = &envbuffer[envbufsize];
envbufsize += bytes;
}
return ep;
}
/*
* kdbgetulenv
*
* This function will return the value of an unsigned long-valued
* environment variable.
*
* Parameters:
* match A character string representing a numeric value
* Outputs:
* *value the unsigned long represntation of the env variable 'match'
* Returns:
* Zero on success, a kdb diagnostic on failure.
* Locking:
* No locking considerations required.
* Remarks:
*/
static int kdbgetulenv(const char *match, unsigned long *value)
{
char *ep;
ep = kdbgetenv(match);
if (!ep) return KDB_NOTENV;
if (strlen(ep) == 0) return KDB_NOENVVALUE;
*value = simple_strtoul(ep, NULL, 0);
return 0;
}
/*
* kdbgetintenv
*
* This function will return the value of an integer-valued
* environment variable.
*
* Parameters:
* match A character string representing an integer-valued env variable
* Outputs:
* *value the integer representation of the environment variable 'match'
* Returns:
* Zero on success, a kdb diagnostic on failure.
* Locking:
* No locking considerations required.
* Remarks:
*/
int kdbgetintenv(const char *match, int *value) {
unsigned long val;
int diag;
diag = kdbgetulenv(match, &val);
if (!diag) {
*value = (int) val;
}
return diag;
}
/*
* kdbgetularg
*
* This function will convert a numeric string
* into an unsigned long value.
*
* Parameters:
* arg A character string representing a numeric value
* Outputs:
* *value the unsigned long represntation of arg.
* Returns:
* Zero on success, a kdb diagnostic on failure.
* Locking:
* No locking considerations required.
* Remarks:
*/
int kdbgetularg(const char *arg, unsigned long *value)
{
char *endp;
unsigned long val;
val = simple_strtoul(arg, &endp, 0);
if (endp == arg) {
/*
* Try base 16, for us folks too lazy to type the
* leading 0x...
*/
val = simple_strtoul(arg, &endp, 16);
if (endp == arg)
return KDB_BADINT;
}
*value = val;
return 0;
}
/*
* kdb_set
*
* This function implements the 'set' command. Alter an existing
* environment variable or create a new one.
*
* Inputs:
* argc argument count
* argv argument vector
* Outputs:
* None.
* Returns:
* zero for success, a kdb diagnostic if error
* Locking:
* none.
* Remarks:
*/
static int kdb_set(int argc, const char **argv)
{
int i;
char *ep;
size_t varlen, vallen;
/*
* we can be invoked two ways:
* set var=value argv[1]="var", argv[2]="value"
* set var = value argv[1]="var", argv[2]="=", argv[3]="value"
* - if the latter, shift 'em down.
*/
if (argc == 3) {
argv[2] = argv[3];
argc--;
}
if (argc != 2)
return KDB_ARGCOUNT;
/*
* Check for internal variables
*/
if (strcmp(argv[1], "KDBDEBUG") == 0) {
unsigned int debugflags;
char *cp;
debugflags = simple_strtoul(argv[2], &cp, 0);
if (cp == argv[2] || debugflags & ~KDB_DEBUG_FLAG_MASK) {
lkmd_printf("kdb: illegal debug flags '%s'\n",
argv[2]);
return 0;
}
kdb_flags = (kdb_flags & ~(KDB_DEBUG_FLAG_MASK << KDB_DEBUG_FLAG_SHIFT))
| (debugflags << KDB_DEBUG_FLAG_SHIFT);
return 0;
}
/*
* Tokenizer squashed the '=' sign. argv[1] is variable
* name, argv[2] = value.
*/
varlen = strlen(argv[1]);
vallen = strlen(argv[2]);
ep = kdballocenv(varlen + vallen + 2);
if (ep == (char *)0)
return KDB_ENVBUFFULL;
sprintf(ep, "%s=%s", argv[1], argv[2]);
ep[varlen+vallen+1]='\0';
for(i=0; i<__nenv; i++) {
if (__env[i]
&& ((strncmp(__env[i], argv[1], varlen)==0)
&& ((__env[i][varlen] == '\0')
|| (__env[i][varlen] == '=')))) {
__env[i] = ep;
return 0;
}
}
/*
* Wasn't existing variable. Fit into slot.
*/
for(i=0; i<__nenv-1; i++) {
if (__env[i] == (char *)0) {
__env[i] = ep;
return 0;
}
}
return KDB_ENVFULL;
}
static int kdb_check_regs(void)
{
if (!kdb_current_regs) {
lkmd_printf("No current kdb registers."
" You may need to select another task\n");
return KDB_BADREG;
}
return 0;
}
/*
* kdbgetaddrarg
*
* This function is responsible for parsing an
* address-expression and returning the value of
* the expression, symbol name, and offset to the caller.
*
* The argument may consist of a numeric value (decimal or
* hexidecimal), a symbol name, a register name (preceeded
* by the percent sign), an environment variable with a numeric
* value (preceeded by a dollar sign) or a simple arithmetic
* expression consisting of a symbol name, +/-, and a numeric
* constant value (offset).
*
* Parameters:
* argc - count of arguments in argv
* argv - argument vector
* *nextarg - index to next unparsed argument in argv[]
* regs - Register state at time of KDB entry
* Outputs:
* *value - receives the value of the address-expression
* *offset - receives the offset specified, if any
* *name - receives the symbol name, if any
* *nextarg - index to next unparsed argument in argv[]
*
* Returns:
* zero is returned on success, a kdb diagnostic code is
* returned on error.
*
* Locking:
* No locking requirements.
*
* Remarks:
*
*/
int kdbgetaddrarg(int argc, const char **argv, int *nextarg,
kdb_machreg_t *value, long *offset,
char **name)
{
kdb_machreg_t addr;
unsigned long off = 0;
int positive;
int diag;
int found = 0;
char *symname;
char symbol = '\0';
char *cp;
kdb_symtab_t symtab;
/*
* Process arguments which follow the following syntax:
*
* symbol | numeric-address [+/- numeric-offset]
* %register
* $environment-variable
*/
if (*nextarg > argc) {
return KDB_ARGCOUNT;
}
symname = (char *)argv[*nextarg];
/*
* If there is no whitespace between the symbol
* or address and the '+' or '-' symbols, we
* remember the character and replace it with a
* null so the symbol/value can be properly parsed
*/
if ((cp = strpbrk(symname, "+-")) != NULL) {
symbol = *cp;
*cp++ = '\0';
}
if (symname[0] == '$') {
diag = kdbgetulenv(&symname[1], &addr);
if (diag)
return diag;
} else if (symname[0] == '%') {
if ((diag = kdb_check_regs()))
return diag;
diag = kdba_getregcontents(&symname[1], kdb_current_regs, &addr);
if (diag)
return diag;
} else {
found = lkmd_get_sym_val(symname, &symtab);
if (found) {
addr = symtab.sym_start;
} else {
diag = kdbgetularg(argv[*nextarg], &addr);
if (diag)
return diag;
}
}
if (!found)
found = kdbnearsym(addr, &symtab);
(*nextarg)++;
if (name)
*name = symname;
if (value)
*value = addr;
if (offset && name && *name)
*offset = addr - symtab.sym_start;
if ((*nextarg > argc)
&& (symbol == '\0'))
return 0;
/*
* check for +/- and offset
*/
if (symbol == '\0') {
if ((argv[*nextarg][0] != '+')
&& (argv[*nextarg][0] != '-')) {
/*
* Not our argument. Return.
*/
return 0;
} else {
positive = (argv[*nextarg][0] == '+');
(*nextarg)++;
}
} else
positive = (symbol == '+');
/*
* Now there must be an offset!
*/
if ((*nextarg > argc)
&& (symbol == '\0')) {
return KDB_INVADDRFMT;
}
if (!symbol) {
cp = (char *)argv[*nextarg];
(*nextarg)++;
}
diag = kdbgetularg(cp, &off);
if (diag)
return diag;
if (!positive)
off = -off;
if (offset)
*offset += off;
if (value)
*value += off;
return 0;
}
static void kdb_cmderror(int diag)
{
int i;
if (diag >= 0) {
lkmd_printf("no error detected (diagnostic is %d)\n", diag);
return;
}
for(i=0; i<__nkdb_err; i++) {
if (kdbmsgs[i].km_diag == diag) {
lkmd_printf("diag: %d: %s\n", diag, kdbmsgs[i].km_msg);
return;
}
}
lkmd_printf("Unknown diag %d\n", -diag);
}
#define CMD_BUFLEN 200 /* lkmd_printf: max printline size == 256 */
static char cmd_cur[CMD_BUFLEN];
/*
* kdb_parse
*
* Parse the command line, search the command table for a
* matching command and invoke the command function.
* This function may be called recursively, if it is, the second call
* will overwrite argv and cbuf. It is the caller's responsibility to
* save their argv if they recursively call kdb_parse().
*
* Parameters:
* cmdstr The input command line to be parsed.
* regs The registers at the time kdb was entered.
* Outputs:
* None.
* Returns:
* Zero for success, a kdb diagnostic if failure.
* Locking:
* None.
* Remarks:
* Limited to 20 tokens.
*
* Real rudimentary tokenization. Basically only whitespace
* is considered a token delimeter (but special consideration
* is taken of the '=' sign as used by the 'set' command).
*
* The algorithm used to tokenize the input string relies on
* there being at least one whitespace (or otherwise useless)
* character between tokens as the character immediately following
* the token is altered in-place to a null-byte to terminate the
* token string.
*/
#define MAXARGC 20
int kdb_parse(const char *cmdstr)
{
static char *argv[MAXARGC];
static int argc = 0;
static char cbuf[CMD_BUFLEN+2];
char *cp;
char *cpp, quoted;
kdbtab_t *tp;
int i, escaped, ignore_errors = 0;
/*
* First tokenize the command string.
*/
cp = (char *)cmdstr;
if (KDB_FLAG(CMD_INTERRUPT)) {
/* Previous command was interrupted, newline must not repeat the command */
KDB_FLAG_CLEAR(CMD_INTERRUPT);
argc = 0; /* no repeat */
}
if (*cp != '\n' && *cp != '\0') {
argc = 0;
cpp = cbuf;
while (*cp) {
/* skip whitespace */
while (isspace(*cp)) cp++;
if ((*cp == '\0') || (*cp == '\n'))
break;
if (cpp >= cbuf + CMD_BUFLEN) {
lkmd_printf("kdb_parse: command buffer overflow, command ignored\n%s\n", cmdstr);
return KDB_NOTFOUND;
}
if (argc >= MAXARGC - 1) {
lkmd_printf("kdb_parse: too many arguments, command ignored\n%s\n", cmdstr);
return KDB_NOTFOUND;
}
argv[argc++] = cpp;
escaped = 0;
quoted = '\0';
/* Copy to next unquoted and unescaped whitespace or '=' */
while (*cp && *cp != '\n' && (escaped || quoted || !isspace(*cp))) {
if (cpp >= cbuf + CMD_BUFLEN)
break;
if (escaped) {
escaped = 0;
*cpp++ = *cp++;
continue;
}
if (*cp == '\\') {
escaped = 1;
++cp;
continue;
}
if (*cp == quoted) {
quoted = '\0';
} else if (*cp == '\'' || *cp == '"') {
quoted = *cp;
}
if ((*cpp = *cp++) == '=' && !quoted)
break;
++cpp;
}
*cpp++ = '\0'; /* Squash a ws or '=' character */
}
}
if (!argc)
return 0;
if (argv[0][0] == '-' && argv[0][1] && (argv[0][1] < '0' || argv[0][1] > '9')) {
ignore_errors = 1;
++argv[0];
}
for(tp=kdb_commands, i=0; i < kdb_max_commands; i++,tp++) {
if (tp->cmd_name) {
/*
* If this command is allowed to be abbreviated,
* check to see if this is it.
*/
if (tp->cmd_minlen && (strlen(argv[0]) <= tp->cmd_minlen)) {
if (strncmp(argv[0], tp->cmd_name, tp->cmd_minlen) == 0)
break;
}
if (strcmp(argv[0], tp->cmd_name) == 0)
break;
}
}
/*
* If we don't find a command by this name, see if the first
* few characters of this match any of the known commands.
* e.g., md1c20 should match md.
*/
if (i == kdb_max_commands) {
for(tp = kdb_commands, i = 0; i < kdb_max_commands; i++, tp++) {
if (tp->cmd_name) {
if (strncmp(argv[0], tp->cmd_name, strlen(tp->cmd_name))==0)
break;
}
}
}
if (i < kdb_max_commands) {
int result;
KDB_STATE_SET(CMD);
result = (*tp->cmd_func)(argc-1,
(const char**)argv);
if (result && ignore_errors && result > KDB_CMD_GO)
result = 0;
KDB_STATE_CLEAR(CMD);
switch (tp->cmd_repeat) {
case KDB_REPEAT_NONE:
argc = 0;
if (argv[0])
*(argv[0]) = '\0';
break;
case KDB_REPEAT_NO_ARGS:
argc = 1;
if (argv[1])
*(argv[1]) = '\0';
break;
case KDB_REPEAT_WITH_ARGS:
break;
}
return result;
}
/*
* If the input with which we were presented does not
* map to an existing command, attempt to parse it as an
* address argument and display the result. Useful for
* obtaining the address of a variable, or the nearest symbol
* to an address contained in a register.
*/
{
kdb_machreg_t value;
char *name = NULL;
long offset;
int nextarg = 0;
if (kdbgetaddrarg(0, (const char **)argv, &nextarg,
&value, &offset, &name)) {
return KDB_NOTFOUND;
}
lkmd_printf("%s = ", argv[0]);
kdb_symbol_print(value, NULL, KDB_SP_DEFAULT);
lkmd_printf("\n");
return 0;
}
}
/*
* kdb_reboot
*
* This function implements the 'reboot' command. Reboot the system
* immediately.
*
* Inputs:
* argc argument count
* argv argument vector
* Outputs:
* None.
* Returns:
* zero for success, a kdb diagnostic if error
* Locking:
* none.
* Remarks:
* Shouldn't return from this function.
*/
static int kdb_reboot(int argc, const char **argv)
{
emergency_restart();
lkmd_printf("Hmm, kdb_reboot did not reboot, spinning here\n");
while (1) {};
/* NOTREACHED */
return 0;
}
static int kdb_quiet(int reason)
{
return (reason == KDB_REASON_CPU_UP || reason == KDB_REASON_SILENT);
}
/*
* kdb_local
*
* The main code for kdb. This routine is invoked on a specific
* processor, it is not global. The main kdb() routine ensures
* that only one processor at a time is in this routine. This
* code is called with the real reason code on the first entry
* to a kdb session, thereafter it is called with reason SWITCH,
* even if the user goes back to the original cpu.
*
* Inputs:
* reason The reason KDB was invoked
* error The hardware-defined error code
* regs The exception frame at time of fault/breakpoint. NULL
* for reason SILENT or CPU_UP, otherwise valid.
* db_result Result code from the break or debug point.
* Returns:
* 0 KDB was invoked for an event which it wasn't responsible
* 1 KDB handled the event for which it was invoked.
* KDB_CMD_GO User typed 'go'.
* KDB_CMD_CPU User switched to another cpu.
* KDB_CMD_SS Single step.
* KDB_CMD_SSB Single step until branch.
* Locking:
* none
* Remarks:
* none
*/
static int kdb_local(kdb_reason_t reason, int error, struct pt_regs *regs, kdb_dbtrap_t db_result)
{
char *cmdbuf;
int diag;
struct task_struct *kdb_current = kdb_curr_task(smp_processor_id());
KDB_DEBUG_STATE("kdb_local 1", reason);
if (kdb_quiet(reason)) {
/* no message */
} else if (reason == KDB_REASON_DEBUG) {
/* special case below */
} else {
lkmd_printf("\nEntering LKMD (current=0x%p, pid %d) ", kdb_current, kdb_current->pid);
#if defined(CONFIG_SMP)
lkmd_printf("on processor %d ", smp_processor_id());
#endif
}
switch (reason) {
case KDB_REASON_DEBUG:
{
/* If re-entering kdb after a single step command, don't print the message. */
switch(db_result) {
case KDB_DB_BPT:
lkmd_printf("\nEntering LKMD (0x%p, pid %d) ", kdb_current, kdb_current->pid);
#if defined(CONFIG_SMP)
lkmd_printf("on processor %d ", smp_processor_id());
#endif
lkmd_printf("due to Debug @ " kdb_machreg_fmt "\n", kdba_getpc(regs));
break;
case KDB_DB_SSB:
/* In the midst of ssb command. Just return. */
KDB_DEBUG_STATE("kdb_local 3", reason);
return KDB_CMD_SSB; /* Continue with SSB command */
break;
case KDB_DB_SS:
break;
case KDB_DB_SSBPT:
KDB_DEBUG_STATE("kdb_local 4", reason);
return 1; /* kdba_db_trap did the work */
default:
lkmd_printf("kdb: Bad result from kdba_db_trap: %d\n", db_result);
break;
}
}
break;
case KDB_REASON_ENTER:
if (KDB_STATE(KEYBOARD))
lkmd_printf("due to Keyboard Entry @ " kdb_machreg_fmt "\n", kdba_getpc(regs));
else {
lkmd_printf("due to KDB_ENTER() @ " kdb_machreg_fmt "\n", kdba_getpc(regs));
}
break;
case KDB_REASON_KEYBOARD:
KDB_STATE_SET(KEYBOARD);
lkmd_printf("due to Keyboard Entry\n");
break;
case KDB_REASON_ENTER_SLAVE: /* drop through, slaves only get released via cpu switch */
case KDB_REASON_SWITCH:
lkmd_printf("due to cpu switch\n");
if (KDB_STATE(GO_SWITCH)) {
KDB_STATE_CLEAR(GO_SWITCH);
KDB_DEBUG_STATE("kdb_local 5", reason);
return KDB_CMD_GO;
}
break;
case KDB_REASON_OOPS:
lkmd_printf("Oops: %s\n", kdb_diemsg);
lkmd_printf("due to oops @ " kdb_machreg_fmt "\n", kdba_getpc(regs));
kdba_dumpregs(regs, NULL, NULL);
break;
case KDB_REASON_NMI:
lkmd_printf("due to NonMaskable Interrupt @ " kdb_machreg_fmt "\n",
kdba_getpc(regs));
kdba_dumpregs(regs, NULL, NULL);
break;
case KDB_REASON_BREAK:
lkmd_printf("due to Breakpoint @ " kdb_machreg_fmt "\n", kdba_getpc(regs));
/* Determine if this breakpoint is one that we are interested in. */
if (db_result != KDB_DB_BPT) {
lkmd_printf("kdb: error return from kdba_bp_trap: %d\n", db_result);
KDB_DEBUG_STATE("kdb_local 6", reason);
return 0; /* Not for us, dismiss it */
}
break;
case KDB_REASON_RECURSE:
lkmd_printf("due to Recursion @ " kdb_machreg_fmt "\n", kdba_getpc(regs));
break;
case KDB_REASON_CPU_UP:
case KDB_REASON_SILENT:
KDB_DEBUG_STATE("kdb_local 7", reason);
if (reason == KDB_REASON_CPU_UP)
kdba_cpu_up();
return KDB_CMD_GO; /* Silent entry, silent exit */
break;
default:
lkmd_printf("kdb: unexpected reason code: %d\n", reason);
KDB_DEBUG_STATE("kdb_local 8", reason);
return 0; /* Not for us, dismiss it */
}
kdba_set_current_task(kdb_current);
while (1) {
/* Initialize pager context. */