diff options
author | Alexander van Heukelum <heukelum@fastmail.fm> | 2008-10-04 17:12:46 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-10-13 04:33:45 -0400 |
commit | 8a541665b9063c5006b370d4488cf9f6beb6083f (patch) | |
tree | fe3411f956e0be63f9eee4ca6c49df2276be4571 | |
parent | 802a67de0cbd1ef10df80ad48b840e2103b13e52 (diff) |
dumpstack: x86: various small unification steps
- define STACKSLOTS_PER_LINE and use it
- define get_bp macro to hide the %%ebp/%%rbp difference
- i386: check task==NULL in dump_trace, like x86_64
- i386: show_trace(NULL, ...) uses current automatically
- x86_64: use [#%d] for die_counter, like i386
- whitespace and comments
Signed-off-by: Alexander van Heukelum <heukelum@fastmail.fm>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r-- | arch/x86/kernel/dumpstack_32.c | 23 | ||||
-rw-r--r-- | arch/x86/kernel/dumpstack_64.c | 15 |
2 files changed, 20 insertions, 18 deletions
diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c index 9a8920abe4ba..201ee359a1a9 100644 --- a/arch/x86/kernel/dumpstack_32.c +++ b/arch/x86/kernel/dumpstack_32.c | |||
@@ -16,8 +16,11 @@ | |||
16 | 16 | ||
17 | #include <asm/stacktrace.h> | 17 | #include <asm/stacktrace.h> |
18 | 18 | ||
19 | #define STACKSLOTS_PER_LINE 8 | ||
20 | #define get_bp(bp) asm("movl %%ebp, %0" : "=r" (bp) :) | ||
21 | |||
19 | int panic_on_unrecovered_nmi; | 22 | int panic_on_unrecovered_nmi; |
20 | int kstack_depth_to_print = 24; | 23 | int kstack_depth_to_print = 3 * STACKSLOTS_PER_LINE; |
21 | static unsigned int code_bytes = 64; | 24 | static unsigned int code_bytes = 64; |
22 | static int die_counter; | 25 | static int die_counter; |
23 | 26 | ||
@@ -82,7 +85,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs, | |||
82 | if (!stack) { | 85 | if (!stack) { |
83 | unsigned long dummy; | 86 | unsigned long dummy; |
84 | stack = &dummy; | 87 | stack = &dummy; |
85 | if (task != current) | 88 | if (task && task != current) |
86 | stack = (unsigned long *)task->thread.sp; | 89 | stack = (unsigned long *)task->thread.sp; |
87 | } | 90 | } |
88 | 91 | ||
@@ -90,7 +93,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs, | |||
90 | if (!bp) { | 93 | if (!bp) { |
91 | if (task == current) { | 94 | if (task == current) { |
92 | /* Grab bp right from our regs */ | 95 | /* Grab bp right from our regs */ |
93 | asm("movl %%ebp, %0" : "=r" (bp) :); | 96 | get_bp(bp); |
94 | } else { | 97 | } else { |
95 | /* bp is the last reg pushed by switch_to */ | 98 | /* bp is the last reg pushed by switch_to */ |
96 | bp = *(unsigned long *) task->thread.sp; | 99 | bp = *(unsigned long *) task->thread.sp; |
@@ -167,7 +170,7 @@ void show_trace(struct task_struct *task, struct pt_regs *regs, | |||
167 | 170 | ||
168 | static void | 171 | static void |
169 | show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs, | 172 | show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs, |
170 | unsigned long *sp, unsigned long bp, char *log_lvl) | 173 | unsigned long *sp, unsigned long bp, char *log_lvl) |
171 | { | 174 | { |
172 | unsigned long *stack; | 175 | unsigned long *stack; |
173 | int i; | 176 | int i; |
@@ -183,7 +186,7 @@ show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs, | |||
183 | for (i = 0; i < kstack_depth_to_print; i++) { | 186 | for (i = 0; i < kstack_depth_to_print; i++) { |
184 | if (kstack_end(stack)) | 187 | if (kstack_end(stack)) |
185 | break; | 188 | break; |
186 | if (i && ((i % 8) == 0)) | 189 | if (i && ((i % STACKSLOTS_PER_LINE) == 0)) |
187 | printk("\n%s", log_lvl); | 190 | printk("\n%s", log_lvl); |
188 | printk(" %08lx", *stack++); | 191 | printk(" %08lx", *stack++); |
189 | touch_nmi_watchdog(); | 192 | touch_nmi_watchdog(); |
@@ -207,7 +210,7 @@ void dump_stack(void) | |||
207 | 210 | ||
208 | #ifdef CONFIG_FRAME_POINTER | 211 | #ifdef CONFIG_FRAME_POINTER |
209 | if (!bp) | 212 | if (!bp) |
210 | asm("movl %%ebp, %0" : "=r" (bp):); | 213 | get_bp(bp); |
211 | #endif | 214 | #endif |
212 | 215 | ||
213 | printk("Pid: %d, comm: %.20s %s %s %.*s\n", | 216 | printk("Pid: %d, comm: %.20s %s %s %.*s\n", |
@@ -215,8 +218,7 @@ void dump_stack(void) | |||
215 | init_utsname()->release, | 218 | init_utsname()->release, |
216 | (int)strcspn(init_utsname()->version, " "), | 219 | (int)strcspn(init_utsname()->version, " "), |
217 | init_utsname()->version); | 220 | init_utsname()->version); |
218 | 221 | show_trace(NULL, NULL, &stack, bp); | |
219 | show_trace(current, NULL, &stack, bp); | ||
220 | } | 222 | } |
221 | 223 | ||
222 | EXPORT_SYMBOL(dump_stack); | 224 | EXPORT_SYMBOL(dump_stack); |
@@ -249,7 +251,7 @@ void show_registers(struct pt_regs *regs) | |||
249 | 251 | ||
250 | ip = (u8 *)regs->ip - code_prologue; | 252 | ip = (u8 *)regs->ip - code_prologue; |
251 | if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) { | 253 | if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) { |
252 | /* try starting at EIP */ | 254 | /* try starting at IP */ |
253 | ip = (u8 *)regs->ip; | 255 | ip = (u8 *)regs->ip; |
254 | code_len = code_len - code_prologue + 1; | 256 | code_len = code_len - code_prologue + 1; |
255 | } | 257 | } |
@@ -317,13 +319,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr) | |||
317 | 319 | ||
318 | if (kexec_should_crash(current)) | 320 | if (kexec_should_crash(current)) |
319 | crash_kexec(regs); | 321 | crash_kexec(regs); |
320 | |||
321 | if (in_interrupt()) | 322 | if (in_interrupt()) |
322 | panic("Fatal exception in interrupt"); | 323 | panic("Fatal exception in interrupt"); |
323 | |||
324 | if (panic_on_oops) | 324 | if (panic_on_oops) |
325 | panic("Fatal exception"); | 325 | panic("Fatal exception"); |
326 | |||
327 | oops_exit(); | 326 | oops_exit(); |
328 | do_exit(signr); | 327 | do_exit(signr); |
329 | } | 328 | } |
diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c index 7fd32944ceac..13379a988292 100644 --- a/arch/x86/kernel/dumpstack_64.c +++ b/arch/x86/kernel/dumpstack_64.c | |||
@@ -16,8 +16,11 @@ | |||
16 | 16 | ||
17 | #include <asm/stacktrace.h> | 17 | #include <asm/stacktrace.h> |
18 | 18 | ||
19 | #define STACKSLOTS_PER_LINE 4 | ||
20 | #define get_bp(bp) asm("movl %%rbp, %0" : "=r" (bp) :) | ||
21 | |||
19 | int panic_on_unrecovered_nmi; | 22 | int panic_on_unrecovered_nmi; |
20 | int kstack_depth_to_print = 12; | 23 | int kstack_depth_to_print = 3 * STACKSLOTS_PER_LINE; |
21 | static unsigned int code_bytes = 64; | 24 | static unsigned int code_bytes = 64; |
22 | static int die_counter; | 25 | static int die_counter; |
23 | 26 | ||
@@ -177,7 +180,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs, | |||
177 | if (!bp) { | 180 | if (!bp) { |
178 | if (task == current) { | 181 | if (task == current) { |
179 | /* Grab bp right from our regs */ | 182 | /* Grab bp right from our regs */ |
180 | asm("movq %%rbp, %0" : "=r" (bp) : ); | 183 | get_bp(bp); |
181 | } else { | 184 | } else { |
182 | /* bp is the last reg pushed by switch_to */ | 185 | /* bp is the last reg pushed by switch_to */ |
183 | bp = *(unsigned long *) task->thread.sp; | 186 | bp = *(unsigned long *) task->thread.sp; |
@@ -329,7 +332,7 @@ show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs, | |||
329 | if (((long) stack & (THREAD_SIZE-1)) == 0) | 332 | if (((long) stack & (THREAD_SIZE-1)) == 0) |
330 | break; | 333 | break; |
331 | } | 334 | } |
332 | if (i && ((i % 4) == 0)) | 335 | if (i && ((i % STACKSLOTS_PER_LINE) == 0)) |
333 | printk("\n%s", log_lvl); | 336 | printk("\n%s", log_lvl); |
334 | printk(" %016lx", *stack++); | 337 | printk(" %016lx", *stack++); |
335 | touch_nmi_watchdog(); | 338 | touch_nmi_watchdog(); |
@@ -353,7 +356,7 @@ void dump_stack(void) | |||
353 | 356 | ||
354 | #ifdef CONFIG_FRAME_POINTER | 357 | #ifdef CONFIG_FRAME_POINTER |
355 | if (!bp) | 358 | if (!bp) |
356 | asm("movq %%rbp, %0" : "=r" (bp) : ); | 359 | get_bp(bp); |
357 | #endif | 360 | #endif |
358 | 361 | ||
359 | printk("Pid: %d, comm: %.20s %s %s %.*s\n", | 362 | printk("Pid: %d, comm: %.20s %s %s %.*s\n", |
@@ -396,7 +399,7 @@ void show_registers(struct pt_regs *regs) | |||
396 | 399 | ||
397 | ip = (u8 *)regs->ip - code_prologue; | 400 | ip = (u8 *)regs->ip - code_prologue; |
398 | if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) { | 401 | if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) { |
399 | /* try starting at RIP */ | 402 | /* try starting at IP */ |
400 | ip = (u8 *)regs->ip; | 403 | ip = (u8 *)regs->ip; |
401 | code_len = code_len - code_prologue + 1; | 404 | code_len = code_len - code_prologue + 1; |
402 | } | 405 | } |
@@ -475,7 +478,7 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr) | |||
475 | 478 | ||
476 | int __kprobes __die(const char *str, struct pt_regs *regs, long err) | 479 | int __kprobes __die(const char *str, struct pt_regs *regs, long err) |
477 | { | 480 | { |
478 | printk(KERN_EMERG "%s: %04lx [%u] ", str, err & 0xffff, ++die_counter); | 481 | printk(KERN_EMERG "%s: %04lx [#%d] ", str, err & 0xffff, ++die_counter); |
479 | #ifdef CONFIG_PREEMPT | 482 | #ifdef CONFIG_PREEMPT |
480 | printk("PREEMPT "); | 483 | printk("PREEMPT "); |
481 | #endif | 484 | #endif |