forked from crash-utility/crash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
x86.c
5763 lines (4842 loc) · 161 KB
/
x86.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
/* x86.c - core analysis suite
*
* Portions Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc.
* Copyright (C) 2002-2014,2017-2018 David Anderson
* Copyright (C) 2002-2014,2017-2018 Red Hat, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifdef X86
/*
* NOTICE OF APPRECIATION
*
* The stack-trace related code in this file is an extension of the stack
* trace code from the Mach in-kernel debugger "ddb". Sincere thanks to
* the author(s).
*
*/
/*
* Mach Operating System
* Copyright (c) 1991,1990 Carnegie Mellon University
* All Rights Reserved.
*
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or [email protected]
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
*/
#include "defs.h"
#include "xen_hyper_defs.h"
#ifndef MCLX
#include <sys/param.h>
#include <sys/systm.h>
#include <machine/cpu.h>
#include <vm/vm.h>
#include <vm/vm_param.h>
#include <vm/pmap.h>
#include <ddb/ddb.h>
#include <ddb/db_access.h>
#include <ddb/db_sym.h>
#include <ddb/db_variables.h>
/*
* Machine register set.
*/
struct db_variable db_regs[] = {
"cs", &ddb_regs.tf_cs, FCN_NULL,
"ds", &ddb_regs.tf_ds, FCN_NULL,
"es", &ddb_regs.tf_es, FCN_NULL,
#if 0
"fs", &ddb_regs.tf_fs, FCN_NULL,
"gs", &ddb_regs.tf_gs, FCN_NULL,
#endif
"ss", &ddb_regs.tf_ss, FCN_NULL,
"eax", &ddb_regs.tf_eax, FCN_NULL,
"ecx", &ddb_regs.tf_ecx, FCN_NULL,
"edx", &ddb_regs.tf_edx, FCN_NULL,
"ebx", &ddb_regs.tf_ebx, FCN_NULL,
"esp", &ddb_regs.tf_esp, FCN_NULL,
"ebp", &ddb_regs.tf_ebp, FCN_NULL,
"esi", &ddb_regs.tf_esi, FCN_NULL,
"edi", &ddb_regs.tf_edi, FCN_NULL,
"eip", &ddb_regs.tf_eip, FCN_NULL,
"efl", &ddb_regs.tf_eflags, FCN_NULL,
};
struct db_variable *db_eregs = db_regs + sizeof(db_regs)/sizeof(db_regs[0]);
#else
typedef int db_strategy_t; /* search strategy */
#define DB_STGY_ANY 0 /* anything goes */
#define DB_STGY_XTRN 1 /* only external symbols */
#define DB_STGY_PROC 2 /* only procedures */
typedef ulong db_addr_t; /* address - unsigned */
typedef int db_expr_t; /* expression - signed */
/*
* Symbol representation is specific to the symtab style:
* BSD compilers use dbx' nlist, other compilers might use
* a different one
*/
typedef char * db_sym_t; /* opaque handle on symbols */
#define DB_SYM_NULL ((db_sym_t)0)
typedef uint boolean_t;
#endif /* !MCLX */
/*
* Stack trace.
*/
#ifdef MCLX
static db_expr_t db_get_value(db_addr_t, int, boolean_t, struct bt_info *);
#define INKERNEL(va) (machdep->kvtop(CURRENT_CONTEXT(), va, &phys, 0))
#else
#define INKERNEL(va) (((vm_offset_t)(va)) >= USRSTACK)
#endif
struct i386_frame {
struct i386_frame *f_frame;
int f_retaddr;
int f_arg0;
};
#ifdef MCLX
#define NORMAL 0
#define IDT_DIRECT_ENTRY 1
#define IDT_JMP_ERROR_CODE 2
#define RET_FROM_INTR 3
#define SIGNAL_RETURN 4
#else
#define NORMAL 0
#define TRAP 1
#define INTERRUPT 2
#define SYSCALL 3
#endif
#ifndef MCLX
typedef vm_offset_t db_addr_t;
#endif
#ifdef MCLX
struct eframe {
int eframe_found;
int eframe_type;
ulong eframe_addr;
ulong jmp_error_code_eip;
};
static void db_nextframe(struct i386_frame **, db_addr_t *, struct eframe *,
struct bt_info *);
static int dump_eframe(struct eframe *, int, struct bt_info *);
static int eframe_numargs(ulong eip, struct bt_info *);
static int check_for_eframe(char *, struct bt_info *);
static void x86_user_eframe(struct bt_info *);
static ulong x86_next_eframe(ulong addr, struct bt_info *bt);
static void x86_cmd_mach(void);
static int x86_get_smp_cpus(void);
static void x86_display_machine_stats(void);
static void x86_display_cpu_data(unsigned int);
static void x86_display_memmap(void);
static int x86_omit_frame_pointer(void);
static void x86_back_trace_cmd(struct bt_info *);
static int is_rodata_text(ulong);
static int mach_CRASHDEBUG(ulong);
static db_sym_t db_search_symbol(db_addr_t, db_strategy_t,db_expr_t *);
static void db_symbol_values(db_sym_t, char **, db_expr_t *);
static int db_sym_numargs(db_sym_t, int *, char **);
static void x86_dump_line_number(ulong);
static void x86_clear_machdep_cache(void);
static void x86_parse_cmdline_args(void);
static ulong mach_debug = 0;
static int
mach_CRASHDEBUG(ulong dval)
{
if (CRASHDEBUG(dval))
return TRUE;
return (mach_debug >= dval);
}
#else
static void db_nextframe(struct i386_frame **, db_addr_t *);
#endif
#ifdef MCLX
static int db_numargs(struct i386_frame *, struct bt_info *bt);
static void db_print_stack_entry(char *, int, char **, int *,
db_addr_t, struct bt_info *, struct eframe *, int,
struct i386_frame *);
#else
static void db_print_stack_entry (char *, int, char **, int *, db_addr_t);
#endif
/*
* Figure out how many arguments were passed into the frame at "fp".
*/
static int
db_numargs(fp, bt)
struct i386_frame *fp;
struct bt_info *bt;
{
int *argp;
int inst;
int args;
argp = (int *)db_get_value((int)&fp->f_retaddr, 4, FALSE, bt);
/*
* etext is wrong for LKMs. We should attempt to interpret
* the instruction at the return address in all cases. This
* may require better fault handling.
*/
#ifdef MCLX
if (!is_kernel_text((ulong)argp)) {
#else
if (argp < (int *)btext || argp >= (int *)etext) {
#endif
args = 5;
} else {
inst = db_get_value((int)argp, 4, FALSE, bt);
if ((inst & 0xff) == 0x59) /* popl %ecx */
args = 1;
else if ((inst & 0xffff) == 0xc483) /* addl $Ibs, %esp */
args = ((inst >> 16) & 0xff) / 4;
else
args = 5;
}
return (args);
}
#ifdef MCLX
static int
eframe_numargs(ulong eip, struct bt_info *bt)
{
int inst;
int args;
if (!is_kernel_text(eip))
args = 5;
else {
inst = db_get_value((int)eip, 4, FALSE, bt);
if ((inst & 0xff) == 0x59) /* popl %ecx */
args = 1;
else if ((inst & 0xffff) == 0xc483) /* addl $Ibs, %esp */
args = ((inst >> 16) & 0xff) / 4;
else
args = 5;
}
return args;
}
#endif
static void
#ifdef MCLX
db_print_stack_entry(name, narg, argnp, argp, callpc, bt, ep, fnum, frame)
#else
db_print_stack_entry(name, narg, argnp, argp, callpc)
#endif
char *name;
int narg;
char **argnp;
int *argp;
db_addr_t callpc;
#ifdef MCLX
struct bt_info *bt;
struct eframe *ep;
int fnum;
struct i386_frame *frame;
#endif
{
#ifdef MCLX
int i;
db_expr_t arg;
char buf1[BUFSIZE];
char buf2[BUFSIZE];
char buf3[BUFSIZE];
char *sp;
if (!name) {
if (IS_MODULE_VADDR(callpc) &&
module_symbol(callpc, NULL, NULL, buf1, *gdb_output_radix)) {
sprintf(buf2, "(%s)", buf1);
name = buf2;
}
else
name = "(unknown module)";
}
if (strstr(name, "_MODULE_START_")) {
sprintf(buf3, "(%s module)", name + strlen("_MODULE_START_"));
name = buf3;
}
if (BT_REFERENCE_CHECK(bt)) {
switch (bt->ref->cmdflags & (BT_REF_SYMBOL|BT_REF_HEXVAL))
{
case BT_REF_SYMBOL:
if (ep->eframe_found && ep->jmp_error_code_eip) {
if (STREQ(closest_symbol(ep->jmp_error_code_eip),
bt->ref->str) ||
STREQ(closest_symbol(callpc), bt->ref->str))
bt->ref->cmdflags |= BT_REF_FOUND;
} else if (STREQ(name, bt->ref->str))
bt->ref->cmdflags |= BT_REF_FOUND;
break;
case BT_REF_HEXVAL:
if (ep->eframe_found && ep->jmp_error_code_eip &&
(bt->ref->hexval == ep->jmp_error_code_eip))
bt->ref->cmdflags |= BT_REF_FOUND;
else if (bt->ref->hexval == callpc)
bt->ref->cmdflags |= BT_REF_FOUND;
break;
}
return;
} else {
fprintf(fp, "%s#%d [%08lx] ",
fnum < 10 ? " " : "", fnum, (ulong)frame);
if (ep->eframe_found && ep->jmp_error_code_eip)
fprintf(fp, "%s (via %s)",
closest_symbol(callpc),
closest_symbol(ep->jmp_error_code_eip));
else
fprintf(fp, "%s", name);
fprintf(fp, " at %lx\n", callpc);
}
if (ep->eframe_found)
goto done_entry;
if (STREQ(name, "L6"))
goto done_entry;
fprintf(fp, " (");
if ((i = get_function_numargs(callpc)) >= 0)
narg = i;
while (narg) {
if (argnp)
fprintf(fp, "%s=", *argnp++);
arg = db_get_value((int)argp, 4, FALSE, bt);
if ((sp = value_symbol(arg)))
fprintf(fp, "%s", sp);
else if ((bt->flags & BT_SYMBOLIC_ARGS) &&
strlen(value_to_symstr(arg, buf1, 0)))
fprintf(fp, "%s", buf1);
else
fprintf(fp, "%x", arg);
argp++;
if (--narg != 0)
fprintf(fp, ", ");
}
if (i == 0)
fprintf(fp, "void");
fprintf(fp, ")\n");
done_entry:
if (bt->flags & BT_LINE_NUMBERS)
x86_dump_line_number(callpc);
return;
#else
db_printf("%s(", name);
while (narg) {
if (argnp)
db_printf("%s=", *argnp++);
db_printf("%r", db_get_value((int)argp, 4, FALSE, bt));
argp++;
if (--narg != 0)
db_printf(",");
}
db_printf(") at ");
db_printsym(callpc, DB_STGY_PROC);
db_printf("\n");
return;
#endif
}
#ifdef MCLX
static db_sym_t
db_search_symbol(db_addr_t val, db_strategy_t strategy, db_expr_t *offp)
{
struct syment *sp;
ulong offset;
if ((sp = value_search(val, &offset))) {
*offp = (db_expr_t)offset;
return(sp->name);
} else
return DB_SYM_NULL;
}
/*
* Return name and value of a symbol
*/
static void
db_symbol_values(db_sym_t sym, char **namep, db_expr_t *valuep)
{
struct syment *sp;
if (sym == DB_SYM_NULL) {
*namep = 0;
return;
}
if ((sp = symbol_search(sym)) == NULL) {
error(INFO, "db_symbol_values: cannot find symbol: %s\n", sym);
*namep = 0;
return;
}
*namep = sp->name;
if (valuep)
*valuep = sp->value;
#ifndef MCLX
X_db_symbol_values(db_last_symtab, sym, namep, &value);
if (db_symbol_is_ambiguous(sym))
*namep = db_qualify(sym, db_last_symtab->name);
if (valuep)
*valuep = value;
#endif
}
static unsigned db_extend[] = { /* table for sign-extending */
0,
0xFFFFFF80U,
0xFFFF8000U,
0xFF800000U
};
static db_expr_t
db_get_value(addr, size, is_signed, bt)
db_addr_t addr;
int size;
boolean_t is_signed;
struct bt_info * bt;
{
char data[sizeof(int)];
db_expr_t value;
int i;
#ifndef MCLX
db_read_bytes(addr, size, data);
#else
BZERO(data, sizeof(int));
if (INSTACK(addr, bt)) {
if (size == sizeof(ulong))
return (db_expr_t)GET_STACK_ULONG(addr);
else
GET_STACK_DATA(addr, data, size);
} else {
if (!readmem(addr, KVADDR, &value, size, "db_get_value",
RETURN_ON_ERROR))
error(FATAL, "db_get_value: read error: address: %lx\n",
addr);
}
#endif
value = 0;
#if BYTE_MSF
for (i = 0; i < size; i++)
#else /* BYTE_LSF */
for (i = size - 1; i >= 0; i--)
#endif
{
value = (value << 8) + (data[i] & 0xFF);
}
if (size < 4) {
if (is_signed && (value & db_extend[size]) != 0)
value |= db_extend[size];
}
return (value);
}
static int
db_sym_numargs(db_sym_t sym, int *nargp, char **argnames)
{
return FALSE;
}
#endif
/*
* Figure out the next frame up in the call stack.
*/
#ifdef MCLX
static void
db_nextframe(fp, ip, ep, bt)
struct i386_frame **fp; /* in/out */
db_addr_t *ip; /* out */
struct eframe *ep;
struct bt_info *bt;
#else
static void
db_nextframe(fp, ip)
struct i386_frame **fp; /* in/out */
db_addr_t *ip; /* out */
#endif
{
int eip, ebp;
db_expr_t offset;
char *sym, *name;
#ifdef MCLX
static int last_ebp;
static int last_eip;
struct syment *sp;
#endif
eip = db_get_value((int) &(*fp)->f_retaddr, 4, FALSE, bt);
ebp = db_get_value((int) &(*fp)->f_frame, 4, FALSE, bt);
/*
* Figure out frame type, presuming normal.
*/
BZERO(ep, sizeof(struct eframe));
ep->eframe_type = NORMAL;
sym = db_search_symbol(eip, DB_STGY_ANY, &offset);
db_symbol_values(sym, &name, NULL);
if (name != NULL) {
ep->eframe_type = check_for_eframe(name, bt);
#ifndef MCLX
if (!strcmp(name, "calltrap")) {
frame_type = TRAP;
} else if (!strncmp(name, "Xresume", 7)) {
frame_type = INTERRUPT;
} else if (!strcmp(name, "_Xsyscall")) {
frame_type = SYSCALL;
}
#endif
}
switch (ep->eframe_type)
{
case NORMAL:
ep->eframe_found = FALSE;
break;
case IDT_DIRECT_ENTRY:
case RET_FROM_INTR:
case SIGNAL_RETURN:
ep->eframe_found = TRUE;
ep->eframe_addr = x86_next_eframe(last_ebp + sizeof(ulong)*2,
bt);
break;
case IDT_JMP_ERROR_CODE:
ep->eframe_found = TRUE;
ep->eframe_addr = x86_next_eframe(last_ebp + sizeof(ulong) * 4,
bt);
if ((sp = x86_jmp_error_code(last_eip)))
ep->jmp_error_code_eip = sp->value;
break;
default:
error(FATAL, "unknown exception frame type?\n");
}
*ip = (db_addr_t) eip;
*fp = (struct i386_frame *) ebp;
last_ebp = ebp;
last_eip = eip;
return;
#ifndef MCLX
db_print_stack_entry(name, 0, 0, 0, eip);
/*
* Point to base of trapframe which is just above the
* current frame.
*/
tf = (struct trapframe *) ((int)*fp + 8);
esp = (ISPL(tf->tf_cs) == SEL_UPL) ? tf->tf_esp : (int)&tf->tf_esp;
switch (frame_type) {
case TRAP:
if (INKERNEL((int) tf)) {
eip = tf->tf_eip;
ebp = tf->tf_ebp;
db_printf(
"--- trap %#r, eip = %#r, esp = %#r, ebp = %#r ---\n",
tf->tf_trapno, eip, esp, ebp);
}
break;
case SYSCALL:
if (INKERNEL((int) tf)) {
eip = tf->tf_eip;
ebp = tf->tf_ebp;
db_printf(
"--- syscall %#r, eip = %#r, esp = %#r, ebp = %#r ---\n",
tf->tf_eax, eip, esp, ebp);
}
break;
case INTERRUPT:
tf = (struct trapframe *)((int)*fp + 16);
if (INKERNEL((int) tf)) {
eip = tf->tf_eip;
ebp = tf->tf_ebp;
db_printf(
"--- interrupt, eip = %#r, esp = %#r, ebp = %#r ---\n",
eip, esp, ebp);
}
break;
default:
break;
}
*ip = (db_addr_t) eip;
*fp = (struct i386_frame *) ebp;
#endif
}
#ifdef MCLX
void
x86_back_trace_cmd(struct bt_info *bt)
#else
ulong
db_stack_trace_cmd(addr, have_addr, count, modif, task, flags)
db_expr_t addr;
boolean_t have_addr;
db_expr_t count;
char *modif;
ulong task;
ulong flags;
#endif /* MCLX */
{
struct i386_frame *frame;
int *argp;
db_addr_t callpc;
boolean_t first;
#ifdef MCLX
db_expr_t addr;
boolean_t have_addr;
db_expr_t count;
char *modif;
db_addr_t last_callpc;
ulong lastframe;
physaddr_t phys;
int frame_number;
int forced;
struct eframe eframe, *ep;
char dbuf[BUFSIZE];
if (!(bt->flags & BT_USER_SPACE) &&
(!bt->stkptr || !accessible(bt->stkptr))) {
error(INFO, "cannot determine starting stack pointer\n");
if (KVMDUMP_DUMPFILE())
kvmdump_display_regs(bt->tc->processor, fp);
else if (ELF_NOTES_VALID() && DISKDUMP_DUMPFILE())
diskdump_display_regs(bt->tc->processor, fp);
else if (SADUMP_DUMPFILE())
sadump_display_regs(bt->tc->processor, fp);
return;
}
if (bt->flags & BT_USER_SPACE) {
if (KVMDUMP_DUMPFILE())
kvmdump_display_regs(bt->tc->processor, fp);
else if (ELF_NOTES_VALID() && DISKDUMP_DUMPFILE())
diskdump_display_regs(bt->tc->processor, fp);
else if (SADUMP_DUMPFILE())
sadump_display_regs(bt->tc->processor, fp);
fprintf(fp, " #0 [user space]\n");
return;
} else if ((bt->flags & BT_KERNEL_SPACE)) {
if (KVMDUMP_DUMPFILE())
kvmdump_display_regs(bt->tc->processor, fp);
else if (ELF_NOTES_VALID() && DISKDUMP_DUMPFILE())
diskdump_display_regs(bt->tc->processor, fp);
else if (SADUMP_DUMPFILE())
sadump_display_regs(bt->tc->processor, fp);
}
addr = bt->stkptr;
have_addr = TRUE;
count = 50;
modif = (char *)bt->instptr;
mach_debug = bt->debug;
if ((machdep->flags & OMIT_FRAME_PTR) ||
bt->debug ||
(bt->flags & BT_FRAMESIZE_DEBUG) ||
!(bt->flags & BT_OLD_BACK_TRACE)) {
bt->flags &= ~BT_OLD_BACK_TRACE;
lkcd_x86_back_trace(bt, 0, fp);
return;
}
if (mach_CRASHDEBUG(2)) {
fprintf(fp, "--> stkptr: %lx instptr: %lx (%s)\n",
bt->stkptr, bt->instptr, closest_symbol(bt->instptr));
}
#endif
if (count == -1)
count = 65535;
if (!have_addr) {
#ifndef MCLX
frame = (struct i386_frame *)ddb_regs.tf_ebp;
if (frame == NULL)
frame = (struct i386_frame *)(ddb_regs.tf_esp - 4);
callpc = (db_addr_t)ddb_regs.tf_eip;
#endif
} else {
frame = (struct i386_frame *)addr;
lastframe = (ulong)frame;
ep = &eframe;
BZERO(ep, sizeof(struct eframe));
ep->eframe_found = FALSE;
callpc = (db_addr_t)db_get_value((int)&frame->f_retaddr, 4,
FALSE, bt);
if (modif) {
frame_number = 0;
forced = TRUE;
callpc = (db_addr_t)modif;
}
else {
frame_number = 1;
forced = FALSE;
if (!is_kernel_text(callpc))
error(INFO,
"callpc from stack is not a text address\n");
}
}
first = TRUE;
while (count--) {
struct i386_frame *actframe;
int narg;
char * name;
db_expr_t offset;
db_sym_t sym;
#define MAXNARG 16
char *argnames[MAXNARG], **argnp = NULL;
sym = db_search_symbol(callpc, DB_STGY_ANY, &offset);
db_symbol_values(sym, &name, NULL);
/*
* Attempt to determine a (possibly fake) frame that gives
* the caller's pc. It may differ from `frame' if the
* current function never sets up a standard frame or hasn't
* set one up yet or has just discarded one. The last two
* cases can be guessed fairly reliably for code generated
* by gcc. The first case is too much trouble to handle in
* general because the amount of junk on the stack depends
* on the pc (the special handling of "calltrap", etc. in
* db_nextframe() works because the `next' pc is special).
*/
actframe = frame;
if (first && !have_addr) {
#ifdef MCLX
error(FATAL, "cannot handle \"!have_addr\" path #2\n");
#else
int instr;
instr = db_get_value(callpc, 4, FALSE);
if ((instr & 0x00ffffff) == 0x00e58955) {
/* pushl %ebp; movl %esp, %ebp */
actframe = (struct i386_frame *)
(ddb_regs.tf_esp - 4);
} else if ((instr & 0x0000ffff) == 0x0000e589) {
/* movl %esp, %ebp */
actframe = (struct i386_frame *)
ddb_regs.tf_esp;
if (ddb_regs.tf_ebp == 0) {
/* Fake the caller's frame better. */
frame = actframe;
}
} else if ((instr & 0x000000ff) == 0x000000c3) {
/* ret */
actframe = (struct i386_frame *)
(ddb_regs.tf_esp - 4);
} else if (offset == 0) {
/* Probably a symbol in assembler code. */
actframe = (struct i386_frame *)
(ddb_regs.tf_esp - 4);
}
#endif
}
first = FALSE;
argp = &actframe->f_arg0;
narg = MAXNARG;
if (sym != NULL && db_sym_numargs(sym, &narg, argnames)) {
argnp = argnames;
} else {
narg = db_numargs(frame, bt);
}
#ifdef MCLX
if (is_kernel_text(callpc) || IS_MODULE_VADDR(callpc)) {
if (mach_CRASHDEBUG(2))
fprintf(fp,
"--> (1) lastframe: %lx => frame: %lx\n",
lastframe, (ulong)frame);
db_print_stack_entry(name, narg, argnp, argp, callpc,
bt, ep, frame_number++, frame);
if (STREQ(closest_symbol(callpc), "start_secondary"))
break;
if (BT_REFERENCE_FOUND(bt))
return;
if ((ulong)frame < lastframe) {
break;
}
if (INSTACK(frame, bt) &&
((ulong)frame > lastframe))
lastframe = (ulong)frame;
} else {
if (!(forced && frame_number == 1)) {
if (is_kernel_data(callpc)) {
if (mach_CRASHDEBUG(2))
fprintf(fp,
"--> break(1): callpc %lx is data?\n",
callpc);
if (!is_rodata_text(callpc))
break;
}
if (mach_CRASHDEBUG(2))
fprintf(fp,
"--> (2) lastframe: %lx => frame: %lx\n",
lastframe, (ulong)frame);
db_print_stack_entry(name, narg, argnp,
argp, callpc, bt, ep,
frame_number++, frame);
if (BT_REFERENCE_FOUND(bt))
return;
if ((ulong)frame < lastframe) {
break;
}
if (INSTACK(frame, bt) &&
((ulong)frame > lastframe))
lastframe = (ulong)frame;
}
}
if (!INSTACK(frame, bt)) {
if (mach_CRASHDEBUG(2))
fprintf(fp,
"--> break: !INSTACK(frame: %lx, task: %lx)\n",
(ulong)frame, bt->task);
break;
}
#else
db_print_stack_entry(name, narg, argnp, argp, callpc);
#endif
if (actframe != frame) {
/* `frame' belongs to caller. */
callpc = (db_addr_t)
db_get_value((int)&actframe->f_retaddr, 4,
FALSE, bt);
continue;
}
if (ep->eframe_found)
frame_number = dump_eframe(ep, frame_number, bt);
last_callpc = callpc;
skip_frame:
db_nextframe(&frame, &callpc, ep, bt);
if (mach_CRASHDEBUG(2)) {
fprintf(fp,
"--> db_nextframe: frame: %lx callpc: %lx [%s]\n",
(ulong)frame, callpc,
value_to_symstr(callpc, dbuf,0));
if (callpc == last_callpc)
fprintf(fp, "last callpc == callpc!\n");
}
if ((callpc == last_callpc) &&
STREQ(closest_symbol(callpc), "smp_stop_cpu_interrupt"))
goto skip_frame;
if (INSTACK(frame, bt) &&
((ulong)frame < lastframe))
if (mach_CRASHDEBUG(2))
fprintf(fp,
"--> frame pointer reversion?\n");
if (INKERNEL((int) callpc) && !INKERNEL((int) frame)) {
sym = db_search_symbol(callpc, DB_STGY_ANY, &offset);
db_symbol_values(sym, &name, NULL);
if (is_kernel_data(callpc)) {
if (mach_CRASHDEBUG(2))
fprintf(fp,
"--> break(2): callpc %lx is data?\n",
callpc);
if (!is_rodata_text(callpc))
break;
}
if (mach_CRASHDEBUG(2))
fprintf(fp,
"--> (3) lastframe: %lx => frame: %lx\n",
lastframe, (ulong)frame);
db_print_stack_entry(name, 0, 0, 0, callpc, bt, ep,
frame_number++, frame);
if (BT_REFERENCE_FOUND(bt))
return;
if ((ulong)frame < lastframe) {
if (STREQ(closest_symbol(callpc), "reschedule"))
x86_user_eframe(bt);
break;
}
if (INSTACK(frame, bt) &&
((ulong)frame > lastframe))
lastframe = (ulong)frame;
if (mach_CRASHDEBUG(2))
fprintf(fp,
"--> break: INKERNEL(callpc: %lx [%s]) && !INKERNEL(frame: %lx)\n",
callpc, value_to_symstr(callpc, dbuf, 0),
(ulong)frame);
break;
}
if (!INKERNEL((int) frame)) {
if (mach_CRASHDEBUG(2))
fprintf(fp,
"--> break: !INKERNEL(frame: %lx)\n",
(ulong)frame);
break;
}
}
if (mach_CRASHDEBUG(2)) {
fprintf(fp, "--> returning lastframe: %lx\n", lastframe);
}
if (ep->eframe_found)
frame_number = dump_eframe(ep, frame_number, bt);
#ifndef MCLX
return(lastframe);
#endif
}
/*
* The remainder of this file was generated at MCL to segregate
* x86-specific needs.
*/
static int x86_uvtop(struct task_context *, ulong, physaddr_t *, int);
static int x86_kvtop(struct task_context *, ulong, physaddr_t *, int);
static int x86_uvtop_PAE(struct task_context *, ulong, physaddr_t *, int);
static int x86_kvtop_PAE(struct task_context *, ulong, physaddr_t *, int);
static int x86_uvtop_xen_wpt(struct task_context *, ulong, physaddr_t *, int);
static int x86_kvtop_xen_wpt(struct task_context *, ulong, physaddr_t *, int);
static int x86_uvtop_xen_wpt_PAE(struct task_context *, ulong, physaddr_t *, int);
static int x86_kvtop_xen_wpt_PAE(struct task_context *, ulong, physaddr_t *, int);
static int x86_kvtop_remap(ulong, physaddr_t *);
static ulong x86_get_task_pgd(ulong);
static ulong x86_processor_speed(void);
static ulong x86_get_pc(struct bt_info *);
static ulong x86_get_sp(struct bt_info *);
static void x86_get_stack_frame(struct bt_info *, ulong *, ulong *);