arm: fix building by adding a feature
Subsystems (2)
cover arm: fix building by adding a feature
The main motivator of this series is to get the arm build fixed. 522667917 "lib: backtrace printing" added a common backtrace() function, but we missed that arm's __builtin_return_address only accepts the input 0, and thus the function, which calls it with all values 0 to 20, can't compile on arm. To fix backtrace() for arm, the easiest thing to do is to override it with a backtrace that works. So this series makes some cleanups to stack tracing support and adds the support for ARM.
Andrew Jones (8):
x86: change exit to abort again
x86: trivial: there's no dump_stack.o
pretty_print_stacks: keep the 'STACK:' line
pretty_print_stacks: use elf file for the kernel
pretty_print_stacks: addr2line may need a cross prefix
stack: share api prototypes
stack: copy common asm/stack.h bits to all arches
arm: stack: add dump_stack support
arm/Makefile.arm | 4 ++++ configure | 2 ++ lib/arm/asm/stack.h | 11 +++++++++++ lib/arm/processor.c | 1 + lib/arm/stack.c | 41 +++++++++++++++++++++++++++++++++++++++++ lib/arm64/asm/stack.h | 8 ++++++++ lib/powerpc/asm/stack.h | 8 ++++++++ lib/ppc64/asm/stack.h | 8 ++++++++ lib/stack.h | 9 +++++---- lib/x86/asm/stack.h | 3 --- lib/x86/desc.c | 2 +- scripts/pretty_print_stacks.py | 14 +++++++++++--- x86/Makefile.common | 2 +- 13 files changed, 101 insertions(+), 12 deletions(-) create mode 100644 lib/arm/stack.c
Signature · 1 line
2.4.11
PATCH 1/8 x86: change exit to abort again
This is needed again because ed0a50e5 "x86: lib: debug dump on unhandled exceptions" must have missed it in a rebase.
--- lib/x86/desc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/x86/desc.c +1 -1
@@ -96,7 +96,7 @@ static void unhandled_exception(struct ex_regs *regs, bool cpu)#endif );dump_frame_stack ((void *) regs->rip, (void *) regs->rbp); -exit (7 ); +abort (); }static void check_exception_table (struct ex_regs *regs)
Signature · 1 line
2.4.11
PATCH 2/8 x86: trivial: there's no dump_stack.o
In reply to Andrew Jones--- x86/Makefile.common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
x86/Makefile.common +1 -1
@@ -20,7 +20,7 @@ $(libcflat): CFLAGS += -ffreestanding -I lib CFLAGS += -m$(bits) CFLAGS += -O1 -# dump_stack.o relies on frame pointers. +# stack.o relies on frame pointers. KEEP_FRAME_POINTER := y libgcc := $(shell $(CC) -m$(bits) --print-libgcc-file-name)
Signature · 1 line
2.4.11
PATCH 3/8 pretty_print_stacks: keep the 'STACK:' line
In reply to Andrew JonesIt's sometimes useful to have the addresses for searching in a disassembly. Anyway, there's no reason to drop it.
--- scripts/pretty_print_stacks.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/pretty_print_stacks.py +2 -1
@@ -67,8 +67,9 @@ def main(): if line == '': break + puts(line) + if not line.strip().startswith('STACK:'): - puts(line) continue try:
Signature · 1 line
2.4.11
PATCH 4/8 pretty_print_stacks: use elf file for the kernel
In reply to Andrew Jonesx86 doesn't seem to care, but other architectures do.
--- scripts/pretty_print_stacks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/pretty_print_stacks.py +1 -1
@@ -58,7 +58,7 @@ def main(): sys.stderr.write('usage: %s <kernel>\n' % sys.argv[0]) sys.exit(1) - binary = sys.argv[1] + binary = sys.argv[1].replace("flat", "elf") try: while True:
Signature · 1 line
2.4.11
PATCH 5/8 pretty_print_stacks: addr2line may need a cross prefix
In reply to Andrew Jones--- configure | 2 ++ scripts/pretty_print_stacks.py | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-)
configure +2 -0
@@ -7,6 +7,7 @@ ld=ld objcopy=objcopy objdump=objdump ar=ar +addr2line=addr2line arch=`uname -m | sed -e 's/i.86/i386/;s/arm.*/arm/;s/ppc64.*/ppc64/'` host=$arch cross_prefix=
@@ -154,6 +155,7 @@ LD=$cross_prefix$ld OBJCOPY=$cross_prefix$objcopy OBJDUMP=$cross_prefix$objdump AR=$cross_prefix$ar +ADDR2LINE=$cross_prefix$addr2line API=$api TEST_DIR=$testdir FIRMWARE=$firmware
scripts/pretty_print_stacks.py +8 -1
@@ -5,6 +5,8 @@ import subprocess import sys import traceback +config = {} + # Subvert output buffering. def puts(string): sys.stdout.write(string)
@@ -25,7 +27,7 @@ def pretty_print_stack(binary, line): # Output like this: # 0x004002be: start64 at path/to/kvm-unit-tests/x86/cstart64.S:208 # (inlined by) test_ept_violation at path/to/kvm-unit-tests/x86/vmx_tests.c:1719 (discriminator 1) - cmd = ['addr2line', '-e', binary, '-i', '-f', '--pretty', '--address'] + cmd = [config["ADDR2LINE"], '-e', binary, '-i', '-f', '--pretty', '--address'] cmd.extend(addrs) p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
@@ -60,6 +62,11 @@ def main(): binary = sys.argv[1].replace("flat", "elf") + with open("config.mak") as config_file: + for line in config_file: + name, val = line.partition("=")[::2] + config[name.strip()] = val.strip() + try: while True: # Subvert input buffering.
Signature · 1 line
2.4.11
PATCH 6/8 stack: share api prototypes
In reply to Andrew Jones--- lib/stack.h | 9 +++++---- lib/x86/asm/stack.h | 3 --- 2 files changed, 5 insertions(+), 7 deletions(-)
lib/stack.h +5 -4
@@ -4,7 +4,10 @@#include <libcflat.h> #include <asm/stack.h> -#ifndef HAVE_ARCH_BACKTRACE_FRAME +#ifdef HAVE_ARCH_BACKTRACE_FRAME +extern int backtrace_frame (const void *frame,const void **return_addrs, +int max_depth); +#else static inline int backtrace_frame(const void *frame __unused, const void **return_addrs __unused, int max_depth __unused)
@@ -13,8 +16,6 @@ backtrace_frame(const void *frame __unused, const void **return_addrs __unused, }#endif -#ifndef HAVE_ARCH_BACKTRACE -int backtrace (const void **return_addrs,int max_depth); -#endif +extern int backtrace (const void **return_addrs,int max_depth);#endif
lib/x86/asm/stack.h +0 -3
@@ -6,9 +6,6 @@#endif #define HAVE_ARCH_BACKTRACE_FRAME -int backtrace_frame (const void *frame,const void **return_addrs,int max_depth); -#define HAVE_ARCH_BACKTRACE -int backtrace (const void **return_addrs,int max_depth);#endif
Signature · 1 line
2.4.11
PATCH 7/8 stack: copy common asm/stack.h bits to all arches
In reply to Andrew Jones--- lib/arm/asm/stack.h | 8 ++++++++ lib/arm64/asm/stack.h | 8 ++++++++ lib/powerpc/asm/stack.h | 8 ++++++++ lib/ppc64/asm/stack.h | 8 ++++++++ 4 files changed, 32 insertions(+)
lib/arm/asm/stack.h +8 -0
@@ -0,0 +1,8 @@ +#ifndef _ASMARM_STACK_H_ +#define _ASMARM_STACK_H_ + +#ifndef _STACK_H_ +#error Do not directly include <asm/stack.h>. Just use <stack.h>. +#endif + +#endif
lib/arm64/asm/stack.h +8 -0
@@ -0,0 +1,8 @@ +#ifndef _ASMARM64_STACK_H_ +#define _ASMARM64_STACK_H_ + +#ifndef _STACK_H_ +#error Do not directly include <asm/stack.h>. Just use <stack.h>. +#endif + +#endif
lib/powerpc/asm/stack.h +8 -0
@@ -0,0 +1,8 @@ +#ifndef _ASMPOWERPC_STACK_H_ +#define _ASMPOWERPC_STACK_H_ + +#ifndef _STACK_H_ +#error Do not directly include <asm/stack.h>. Just use <stack.h>. +#endif + +#endif
lib/ppc64/asm/stack.h +8 -0
@@ -0,0 +1,8 @@ +#ifndef _ASMPPC64_STACK_H_ +#define _ASMPPC64_STACK_H_ + +#ifndef _STACK_H_ +#error Do not directly include <asm/stack.h>. Just use <stack.h>. +#endif + +#endif
Signature · 1 line
2.4.11
PATCH 8/8 arm: stack: add dump_stack support
In reply to Andrew JonesThis actually fixes the arm build too, as arm's __builtin_return_address doesn't allow any input other than zero, and thus the common backtrace() wasn't compiling.
--- arm/Makefile.arm | 4 ++++ lib/arm/asm/stack.h | 3 +++ lib/arm/processor.c | 1 + lib/arm/stack.c | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 lib/arm/stack.c
arm/Makefile.arm +4 -0
@@ -8,12 +8,16 @@ ldarch = elf32-littlearm kernel_offset = 0x10000 machine = -marm +# stack.o relies on frame pointers. +KEEP_FRAME_POINTER := y + CFLAGS += $(machine) CFLAGS += -mcpu=$(PROCESSOR) cstart.o = $(TEST_DIR)/cstart.o cflatobjs += lib/arm/spinlock.o cflatobjs += lib/arm/processor.o +cflatobjs += lib/arm/stack.o # arm specific tests tests =
lib/arm/asm/stack.h +3 -0
@@ -5,4 +5,7 @@#error Do not directly include <asm/stack.h>. Just use <stack.h>.#endif +#define HAVE_ARCH_BACKTRACE_FRAME +#define HAVE_ARCH_BACKTRACE +#endif
lib/arm/processor.c +1 -0
@@ -108,6 +108,7 @@ void do_handle_exception(enum vector v, struct pt_regs *regs) asmvolatile ("mrc p15, 0, %0, c5, c0, 1" :"=r" (fsr));printf ("IFAR: %08lx IFSR: %08lx\n" , far, fsr); } +dump_frame_stack ((void *)regs->ARM_pc, (void *)regs->ARM_fp);abort (); }
lib/arm/stack.c new file +41 -0
41 lines not on this page · raw message
Signature · 1 line
2.4.11
Re: [kvm-unit-tests PATCH 4/8] pretty_print_stacks: use elf file for the kernel
In reply to Andrew JonesQuoted 12 lines · Andrew Jones
x86 doesn't seem to care, but other architectures do.
Signed-off-by Andrew Jones <[email protected]>--- scripts/pretty_print_stacks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/pretty_print_stacks.py +0
-0
scripts/pretty_print_stacks.py def main(): · line 61
Quoted 5 lines
scripts/pretty_print_stacks.py +1
-1@@ -58,7 +58,7 @@ def main(): sys.stderr.write('usage: %s <kernel>\n' % sys.argv[0]) sys.exit(1) - binary = sys.argv[1] + binary = sys.argv[1].replace("flat", "elf")
grr... I should have used (".flat", ".elf") since the string 'flat' could easily show up in other parts of a test name.
Quoted 6 lines
scripts/pretty_print_stacks.py +0
-0try: while True:Signature · 1 line
2.4.11
Re: [kvm-unit-tests PATCH 1/8] x86: change exit to abort again
In reply to Andrew JonesQuoted 4 lines · Andrew Jones
This is needed again because
ed0a50e5"x86: lib: debug dump on unhandled exceptions" must have missed it in a rebase.Signed-off-by Andrew Jones <[email protected]>
Re: [kvm-unit-tests PATCH 2/8] x86: trivial: there's no dump_stack.o
In reply to Andrew JonesQuoted 1 line · Andrew Jones
Signed-off-by Andrew Jones <[email protected]>
Re: [kvm-unit-tests PATCH 3/8] pretty_print_stacks: keep the 'STACK:' line
In reply to Andrew JonesQuoted 4 lines · Andrew Jones
It's sometimes useful to have the addresses for searching in a disassembly. Anyway, there's no reason to drop it.
Signed-off-by Andrew Jones <[email protected]>
Re: [kvm-unit-tests PATCH 5/8] pretty_print_stacks: addr2line may need a cross prefix
In reply to Andrew JonesQuoted 40 lines · Andrew Jones
Signed-off-by Andrew Jones <[email protected]>--- configure | 2 ++ scripts/pretty_print_stacks.py | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-)configure +2
-0@@ -7,6 +7,7 @@ ld=ld objcopy=objcopy objdump=objdump ar=ar +addr2line=addr2line arch=`uname -m | sed -e 's/i.86/i386/;s/arm.*/arm/;s/ppc64.*/ppc64/'` host=$arch cross_prefix=@@ -154,6 +155,7 @@ LD=$cross_prefix$ld OBJCOPY=$cross_prefix$objcopy OBJDUMP=$cross_prefix$objdump AR=$cross_prefix$ar +ADDR2LINE=$cross_prefix$addr2line API=$api TEST_DIR=$testdir FIRMWARE=$firmwarescripts/pretty_print_stacks.py +2
-0@@ -5,6 +5,8 @@ import subprocess import sys import traceback +config = {} + # Subvert output buffering. def puts(string): sys.stdout.write(string)
scripts/pretty_print_stacks.py def pretty_print_stack(binary, line): · line 30
Quoted 5 lines
scripts/pretty_print_stacks.py +1
-1@@ -25,7 +27,7 @@ def pretty_print_stack(binary, line): # Output like this: # 0x004002be: start64 at path/to/kvm-unit-tests/x86/cstart64.S:208 # (inlined by) test_ept_violation at path/to/kvm-unit-tests/x86/vmx_tests.c:1719 (discriminator 1) - cmd = ['addr2line', '-e', binary, '-i', '-f', '--pretty', '--address'] + cmd = [config["ADDR2LINE"], '-e', binary, '-i', '-f', '--pretty', '--address']
Perhaps config.get('ADDR2LINE', 'addr2line') so my old config still works?
scripts/pretty_print_stacks.py def main(): · line 67
Quoted 10 lines
scripts/pretty_print_stacks.py +3
-0cmd.extend(addrs) p = subprocess.Popen(cmd, stdout=subprocess.PIPE)@@ -60,6 +62,11 @@ def main(): binary = sys.argv[1].replace("flat", "elf") + with open("config.mak") as config_file: + for line in config_file: + name, val = line.partition("=")[::2]
Very elegant trick here! I always do name, _, val = line.partition("=")!
Quoted 8 lines
scripts/pretty_print_stacks.py +2
-1+ config[name.strip()] = val.strip() + try: while True: # Subvert input buffering. --2.4.11
Otherwise, reviewed-by: Peter Feiner <[email protected]>
Re: [kvm-unit-tests PATCH 6/8] stack: share api prototypes
In reply to Andrew JonesQuoted 1 line · Andrew Jones
Signed-off-by Andrew Jones <[email protected]>
Re: [kvm-unit-tests PATCH 7/8] stack: copy common asm/stack.h bits to all arches
In reply to Andrew JonesQuoted 1 line · Andrew Jones
Signed-off-by Andrew Jones <[email protected]>
Re: [kvm-unit-tests PATCH 8/8] arm: stack: add dump_stack support
In reply to Andrew JonesQuoted 69 lines · Andrew Jones
This actually fixes the arm build too, as arm's
__builtin_return_addressdoesn't allow any input other than zero, and thus the commonbacktrace()wasn't compiling.Signed-off-by Andrew Jones <[email protected]>--- arm/Makefile.arm | 4 ++++ lib/arm/asm/stack.h | 3 +++ lib/arm/processor.c | 1 + lib/arm/stack.c | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 lib/arm/stack.carm/Makefile.arm +4
-0@@ -8,12 +8,16 @@ ldarch = elf32-littlearm kernel_offset = 0x10000 machine = -marm +# stack.o relies on frame pointers. +KEEP_FRAME_POINTER := y + CFLAGS += $(machine) CFLAGS += -mcpu=$(PROCESSOR) cstart.o = $(TEST_DIR)/cstart.o cflatobjs += lib/arm/spinlock.o cflatobjs += lib/arm/processor.o +cflatobjs += lib/arm/stack.o # arm specific tests tests =lib/arm/asm/stack.h +3
-0@@ -5,4 +5,7 @@#error Do not directly include <asm/stack.h>. Just use <stack.h>.#endif +#define HAVE_ARCH_BACKTRACE_FRAME +#define HAVE_ARCH_BACKTRACE +#endif lib/arm/processor.c +1
-0@@ -108,6 +108,7 @@ void do_handle_exception(enum vector v, struct pt_regs *regs) asmvolatile ("mrc p15, 0, %0, c5, c0, 1" :"=r" (fsr));printf ("IFAR: %08lx IFSR: %08lx\n" , far, fsr); } +dump_frame_stack ((void *)regs->ARM_pc, (void *)regs->ARM_fp);abort (); }lib/arm/stack.c new file +5
-0@@ -0,0 +1,41 @@ +/* +* backtrace support (this is a modified lib/x86/stack.c) +* +* Copyright (C) 2016, Red Hat Inc, Andrew Jones <[email protected]> +*
lib/arm/stack.c line 15
Quoted 10 lines
lib/arm/stack.c new file +10
-0+* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include <libcflat.h> +#include <stack.h> + +int backtrace_frame (const void *frame,const void **return_addrs, +int max_depth) +{ +static int walking; +int depth =0 ;
Nit: unnecessary initialization.
lib/arm/stack.c line 25
Quoted 10 lines
lib/arm/stack.c new file +10
-0+const unsigned long *fp = (unsigned long *)frame; + +if (walking) { +printf ("RECURSIVE STACK WALK!!!\n" ); +return 0 ; + } + walking =1 ; + +for (depth =0 ; depth < max_depth; depth++) { +if (!fp)
Interesting difference in termination case here from x86. Instead of checking for a null return address, you check for a null frame address. Any particular reason why?
Quoted 17 lines
lib/arm/stack.c new file +16
-1+break ; + return_addrs[depth] = (void *)fp[0 ]; +if (return_addrs[depth] ==0 ) +break ; + fp = (unsigned long *)fp[-1 ]; + } + + walking =0 ; +return depth; +} + +int backtrace (const void **return_addrs,int max_depth) +{ +return backtrace_frame (__builtin_frame_address (0 ), + return_addrs, max_depth); +} --
Quoted 2 lines
2.4.11
Nice fix!
Peter Feiner
Reviewed-byRe: [kvm-unit-tests PATCH 4/8] pretty_print_stacks: use elf file for the kernel
In reply to Andrew JonesQuoted 4 lines · Andrew Jones
Quoted 3 lines · Andrew Jones
x86 doesn't seem to care, but other architectures do.
Signed-off-by Andrew Jones <[email protected]>
With "." fix,
Re: [kvm-unit-tests PATCH 5/8] pretty_print_stacks: addr2line may need a cross prefix
In reply to Peter FeinerQuoted 35 lines · Peter Feiner
Quoted 34 lines · Andrew Jones
Signed-off-by Andrew Jones <[email protected]>--- configure | 2 ++ scripts/pretty_print_stacks.py | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-)configure +2
-0@@ -7,6 +7,7 @@ ld=ld objcopy=objcopy objdump=objdump ar=ar +addr2line=addr2line arch=`uname -m | sed -e 's/i.86/i386/;s/arm.*/arm/;s/ppc64.*/ppc64/'` host=$arch cross_prefix=@@ -154,6 +155,7 @@ LD=$cross_prefix$ld OBJCOPY=$cross_prefix$objcopy OBJDUMP=$cross_prefix$objdump AR=$cross_prefix$ar +ADDR2LINE=$cross_prefix$addr2line API=$api TEST_DIR=$testdir FIRMWARE=$firmwarescripts/pretty_print_stacks.py +0
-0@@ -5,6 +5,8 @@ import subprocess import sys import traceback
Quoted 13 lines
scripts/pretty_print_stacks.py def pretty_print_stack(binary, line): · line 30
Quoted 11 lines
scripts/pretty_print_stacks.py +3
-1+config = {} + # Subvert output buffering. def puts(string): sys.stdout.write(string)@@ -25,7 +27,7 @@ def pretty_print_stack(binary, line): # Output like this: # 0x004002be: start64 at path/to/kvm-unit-tests/x86/cstart64.S:208 # (inlined by) test_ept_violation at path/to/kvm-unit-tests/x86/vmx_tests.c:1719 (discriminator 1) - cmd = ['addr2line', '-e', binary, '-i', '-f', '--pretty', '--address'] + cmd = [config["ADDR2LINE"], '-e', binary, '-i', '-f', '--pretty', '--address']Perhaps
config.get('ADDR2LINE', 'addr2line')so my old config still works?
OK, will do in v2.
Quoted 28 lines
scripts/pretty_print_stacks.py def main(): · line 67
Quoted 11 lines
scripts/pretty_print_stacks.py +3
-0cmd.extend(addrs) p = subprocess.Popen(cmd, stdout=subprocess.PIPE)@@ -60,6 +62,11 @@ def main(): binary = sys.argv[1].replace("flat", "elf") + with open("config.mak") as config_file: + for line in config_file: + name, val = line.partition("=")[::2]Very elegant trick here! I always do name, _, val =
line.partition("=")!Quoted 8 lines
scripts/pretty_print_stacks.py +2
-1+ config[name.strip()] = val.strip() + try: while True: # Subvert input buffering. --2.4.11
Otherwise, reviewed-by: Peter Feiner <[email protected]> --
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [kvm-unit-tests PATCH 8/8] arm: stack: add dump_stack support
In reply to Peter FeinerQuoted 74 lines · Peter Feiner
Quoted 73 lines · Andrew Jones
This actually fixes the arm build too, as arm's
__builtin_return_addressdoesn't allow any input other than zero, and thus the commonbacktrace()wasn't compiling.Signed-off-by Andrew Jones <[email protected]>--- arm/Makefile.arm | 4 ++++ lib/arm/asm/stack.h | 3 +++ lib/arm/processor.c | 1 + lib/arm/stack.c | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 lib/arm/stack.carm/Makefile.arm +4
-0@@ -8,12 +8,16 @@ ldarch = elf32-littlearm kernel_offset = 0x10000 machine = -marm +# stack.o relies on frame pointers. +KEEP_FRAME_POINTER := y + CFLAGS += $(machine) CFLAGS += -mcpu=$(PROCESSOR) cstart.o = $(TEST_DIR)/cstart.o cflatobjs += lib/arm/spinlock.o cflatobjs += lib/arm/processor.o +cflatobjs += lib/arm/stack.o # arm specific tests tests =lib/arm/asm/stack.h +3
-0@@ -5,4 +5,7 @@#error Do not directly include <asm/stack.h>. Just use <stack.h>.#endif +#define HAVE_ARCH_BACKTRACE_FRAME +#define HAVE_ARCH_BACKTRACE +#endif lib/arm/processor.c +1
-0@@ -108,6 +108,7 @@ void do_handle_exception(enum vector v, struct pt_regs *regs) asmvolatile ("mrc p15, 0, %0, c5, c0, 1" :"=r" (fsr));printf ("IFAR: %08lx IFSR: %08lx\n" , far, fsr); } +dump_frame_stack ((void *)regs->ARM_pc, (void *)regs->ARM_fp);abort (); }lib/arm/stack.c new file +9
-0@@ -0,0 +1,41 @@ +/* +* backtrace support (this is a modified lib/x86/stack.c) +* +* Copyright (C) 2016, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include <libcflat.h> +#include <stack.h>
Quoted 8 lines
lib/arm/stack.c line 15
Quoted 6 lines
lib/arm/stack.c new file +6
-0+ +int backtrace_frame (const void *frame,const void **return_addrs, +int max_depth) +{ +static int walking; +int depth =0 ;Nit: unnecessary initialization.
/me catches the nit and flings it over to lib/x86/stack.c :-)
I'll fix for v2.
Quoted 15 lines
lib/arm/stack.c line 25
Quoted 11 lines
lib/arm/stack.c new file +10
-0+const unsigned long *fp = (unsigned long *)frame; + +if (walking) { +printf ("RECURSIVE STACK WALK!!!\n" ); +return 0 ; + } + walking =1 ; + +for (depth =0 ; depth < max_depth; depth++) { +if (!fp)Interesting difference in termination case here from x86. Instead of checking for a null return address, you check for a null frame address. Any particular reason why?
When I configured a unit test that had more than one vcpu, then if I dereferenced a null frame, address zero, I actually got non-zero junk. Then fp was getting updated to fffffffc, and when I dereferenced that (an unmapped address) it led to an exception. So I just threw this test in to make sure that can't happen. It'll also keep me safe in case regs->ARM_fp is ever null in do_handle_exception.
Quoted 26 lines
Quoted 18 lines
lib/arm/stack.c new file +16
-1+break ; + return_addrs[depth] = (void *)fp[0 ]; +if (return_addrs[depth] ==0 ) +break ; + fp = (unsigned long *)fp[-1 ]; + } + + walking =0 ; +return depth; +} + +int backtrace (const void **return_addrs,int max_depth) +{ +return backtrace_frame (__builtin_frame_address (0 ), + return_addrs, max_depth); +} --Quoted 2 lines
2.4.11
Nice fix!
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html