Skip to content

Commit e9d4efd

Browse files
fenrus75Ingo Molnar
authored andcommitted
x86: improve the 32 bit Frame Pointer backtracer to also use the traditional backtrace
The 32 bit Frame Pointer backtracer code checks if the EBP is valid to do a backtrace; however currently on a failure it just gives up and prints nothing. That's not very nice; we can do better and still print a decent backtrace. This patch changes the backtracer to use the regular backtracing algorithm at the same time as the EBP backtracer; the EBP backtracer is basically used to figure out which part of the backtrace are reliable vs those which are likely to be noise. Signed-off-by: Arjan van de Ven <arjan@linux.intel.com> Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent bc850d6 commit e9d4efd

1 file changed

Lines changed: 20 additions & 24 deletions

File tree

‎arch/x86/kernel/traps_32.c‎

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -118,36 +118,32 @@ static inline unsigned long print_context_stack(struct thread_info *tinfo,
118118
unsigned long *stack, unsigned long bp,
119119
const struct stacktrace_ops *ops, void *data)
120120
{
121-
#ifdef CONFIG_FRAME_POINTER
122121
struct stack_frame *frame = (struct stack_frame *)bp;
123-
while (valid_stack_ptr(tinfo, frame, sizeof(*frame))) {
124-
struct stack_frame *next;
125-
unsigned long addr;
126122

127-
addr = frame->return_address;
128-
if (__kernel_text_address(addr))
129-
ops->address(data, addr, 1);
130-
/*
131-
* break out of recursive entries (such as
132-
* end_of_stack_stop_unwind_function). Also,
133-
* we can never allow a frame pointer to
134-
* move downwards!
135-
*/
136-
next = frame->next_frame;
137-
bp = (unsigned long) next;
138-
if (next <= frame)
139-
break;
140-
frame = next;
141-
}
142-
#else
123+
/*
124+
* if EBP is "deeper" into the stack than the actual stack pointer,
125+
* we need to rewind the stack pointer a little to start at the
126+
* first stack frame, but only if EBP is in this stack frame.
127+
*/
128+
if (stack > (unsigned long *) bp
129+
&& valid_stack_ptr(tinfo, frame, sizeof(*frame)))
130+
stack = (unsigned long *) bp;
131+
143132
while (valid_stack_ptr(tinfo, stack, sizeof(*stack))) {
144133
unsigned long addr;
145134

146-
addr = *stack++;
147-
if (__kernel_text_address(addr))
148-
ops->address(data, addr, 1);
135+
addr = *stack;
136+
if (__kernel_text_address(addr)) {
137+
if ((unsigned long) stack == bp + 4) {
138+
ops->address(data, addr, 1);
139+
frame = frame->next_frame;
140+
bp = (unsigned long) frame;
141+
} else {
142+
ops->address(data, addr, 0);
143+
}
144+
}
145+
stack++;
149146
}
150-
#endif
151147
return bp;
152148
}
153149

0 commit comments

Comments
 (0)