2 * Kernel Debugger Architecture Dependent Stack Traceback
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.
11 #include <linux/config.h>
12 #include <linux/ctype.h>
13 #include <linux/string.h>
14 #include <linux/kernel.h>
15 #include <linux/sched.h>
16 #include <linux/kallsyms.h>
17 #include <linux/kdb.h>
18 #include <linux/kdbprivate.h>
19 #include <asm/system.h>
20 #include <asm/sections.h>
25 * Print one back trace entry.
28 * ip Current program counter.
29 * symtab Information about symbol that ip falls within.
30 * ar Activation record for this frame.
31 * argcount Maximum number of arguments to print.
43 bt_print_one(kdb_machreg_t ip, const kdb_ar_t *ar,
44 const kdb_symtab_t *symtab, int argcount,
45 struct unw_frame_info *info /* FIXME: should be part of ar for ia64 */)
47 int btsymarg = 0; /* Convert arguments to symbols */
48 int btsp = 0; /* Print stack and backing store pointers */
49 int nosect = 0; /* Suppress section data */
50 kdb_machreg_t sp, bsp, cfm; /* FIXME: should be part of ar for ia64 */
52 kdbgetintenv("BTSYMARG", &btsymarg);
53 kdbgetintenv("BTSP", &btsp);
54 kdbgetintenv("NOSECT", &nosect);
56 unw_get_sp(info, &sp); /* FIXME: should be part of ar for ia64 */
57 unw_get_bsp(info, &bsp); /* FIXME: should be part of ar for ia64 */
58 unw_get_cfm(info, &cfm); /* FIXME: info/cfm should be part of ar for ia64 */
59 kdb_symbol_print(ip, symtab, KDB_SP_VALUE|KDB_SP_NEWLINE);
60 /* FIXME: number of args should be set in prologue code */
61 ((kdb_ar_t *)ar)->args = (cfm >> 7) & 0x7f; /* sol */
63 ((kdb_ar_t *)ar)->args = cfm & 0x7f; /* no in/local, use sof instead */
64 if (argcount && ar->args) {
65 int i, argc = ar->args;
67 kdb_printf(" args (");
71 for(i = 0; i < argc; i++){
72 /* FIXME: prologue code should extract arguments */
75 if (unw_access_gr(info, i+32, &arg, &nat, 0))
80 kdb_printf("0x%lx", arg);
84 kdb_symtab_t arg_symtab;
86 for(i = 0; i < argc; i++){
87 /* FIXME: prologue code should extract arguments */
89 if (unw_access_gr(info, i+32, &arg, &nat, 0))
91 if (kdbnearsym(arg, &arg_symtab)) {
92 kdb_printf(" arg %d ", i);
93 kdb_symbol_print(arg, &arg_symtab, KDB_SP_DEFAULT|KDB_SP_NEWLINE);
98 if (symtab->sym_name) {
100 kdb_printf(" %s", symtab->mod_name);
101 if (symtab->sec_name)
102 kdb_printf(" %s 0x%lx", symtab->sec_name, symtab->sec_start);
103 kdb_printf(" 0x%lx", symtab->sym_start);
105 kdb_printf(" 0x%lx", symtab->sym_end);
108 if (strncmp(symtab->sym_name, "ia64_spinlock_contention", 24) == 0) {
111 kdb_printf(" r31 (spinlock address) ");
112 if (unw_access_gr(info, 31, &r31, &nat, 0))
114 kdb_symbol_print(r31, NULL, KDB_SP_VALUE|KDB_SP_NEWLINE);
118 kdb_printf(" sp 0x%016lx bsp 0x%016lx cfm 0x%016lx info->pfs_loc 0x%016lx 0x%016lx\n",
119 sp, bsp, cfm, (u64) info->pfs_loc, info->pfs_loc ? *(info->pfs_loc) : 0);
125 * Unwind the ia64 backtrace for a specified process.
129 * p Pointer to task structure to unwind.
133 * zero for success, a kdb diagnostic if error
141 kdba_bt_stack(int argcount, const struct task_struct *p)
145 struct unw_frame_info info; /* FIXME: should be part of ar */
146 struct switch_stack *sw; /* FIXME: should be part of ar */
147 struct pt_regs *regs = NULL; /* FIXME: should be part of ar */
149 int btsp = 0; /* Backtrace the kdb code as well */
150 u64 *prev_pfs_loc = NULL;
151 extern char __attribute__ ((weak)) ia64_spinlock_contention_pre3_4[];
152 extern char __attribute__ ((weak)) ia64_spinlock_contention_pre3_4_end[];
154 /* FIXME: All the arch specific code should be in activation records, not here */
155 memset(&ar, 0, sizeof(ar));
158 * Upon entering kdb_main_loop, the stack frame looks like this:
160 * +---------------------+
162 * +---------------------+
166 * +=====================+ <--- top of stack upon entering kdb
168 * +---------------------+
172 * +---------------------+
173 * | struct switch_stack |
174 * +=====================+ <--- kdb_running_process[cpu].arch.sw from do_kdba_main_loop
176 * When looking at another process, we do not have the address of the
177 * current pt_regs, it is NULL. If the process has saved its state, use
178 * that pt_regs instead.
181 kdbgetintenv("BTSP", &btsp);
183 if (kdb_task_has_cpu(p)) {
184 struct kdb_running_process *krp = kdb_running_process + kdb_process_cpu(p);
193 /* Not running, assume blocked */
194 sw = (struct switch_stack *) (p->thread.ksp + 16);
197 kdb_printf("Process does not have a switch_stack, cannot backtrace\n");
202 unw_init_frame_info(&info, (struct task_struct *)p, sw); /* FIXME: should be using activation records */
204 /* If we have the address of pt_regs, suppress backtrace on the frames below
205 * pt_regs. No point in displaying kdb itself, unless the user is debugging
206 * the unwinder using set BTSP=1.
209 kdb_machreg_t sp; /* FIXME: should be part of ar for ia64 */
210 if (user_mode(regs)) {
211 kdb_printf("Process was interrupted in user mode, no backtrace available\n");
215 unw_get_sp(&info, &sp);
216 if (sp >= (kdb_machreg_t)regs)
218 } while (unw_unwind(&info) >= 0 && count++ < 200); /* FIXME: should be using activation records */
224 /* Avoid unsightly console message from unw_unwind() when attempting
225 * to unwind through the Interrupt Vector Table which has no unwind
226 * information. dispatch_illegal_op_fault() is an exception, it sits
227 * in the 0x3c00 slot.
229 if (info.ip >= (u64)__start_ivt_text && info.ip < (u64)__end_ivt_text) {
230 if (info.ip < (u64)__start_ivt_text + 0x3c00 ||
231 info.ip >= (u64)__start_ivt_text + 0x4000)
235 /* WAR for spinlock contention from leaf functions. ia64_spinlock_contention_pre3_4
236 * has ar.pfs == r0. Leaf functions do not modify ar.pfs so ar.pfs remains
237 * as 0, stopping the backtrace. Record the previous ar.pfs when the current
238 * IP is in ia64_spinlock_contention_pre3_4 then unwind, if pfs_loc has not changed
239 * after unwind then use pt_regs.ar_pfs which is where the real ar.pfs is for
242 if (prev_pfs_loc && regs && info.pfs_loc == prev_pfs_loc)
243 info.pfs_loc = ®s->ar_pfs;
244 prev_pfs_loc = (info.ip >= (u64)ia64_spinlock_contention_pre3_4 &&
245 info.ip < (u64)ia64_spinlock_contention_pre3_4_end) ?
248 unw_get_ip(&info, &ip); /* FIXME: should be using activation records */
252 kdbnearsym(ip, &symtab);
253 if (!symtab.sym_name) {
254 kdb_printf("0x%0*lx - No name. May be an area that has no unwind data\n",
255 (int)(2*sizeof(ip)), ip);
258 bt_print_one(ip, &ar, &symtab, argcount, &info);
259 } while (unw_unwind(&info) >= 0 && count++ < 200); /* FIXME: should be using activation records */
261 kdb_printf("bt truncated, count limit reached\n");
267 kdba_bt_address(kdb_machreg_t addr, int argcount)
269 kdb_printf("Backtrace from a stack address is not supported on ia64\n");
276 * Do a backtrace for a specified process.
279 * p Struct task pointer extracted by 'bt' command.
284 * zero for success, a kdb diagnostic if error
290 kdba_bt_process(const struct task_struct *p, int argcount)
292 return kdba_bt_stack(argcount, p);