.debug ignore - to squash with efi:keep efi
Subsystems (4)
PATCH 1/1 .debug ignore - to squash with efi:keep efi
From: Nadav Amit <[email protected]>
--- .gitignore | 1 + 1 file changed, 1 insertion(+)
.gitignore +1 -0
@@ -7,6 +7,7 @@ tags *.flat *.efi *.elf +*.debug *.patch .pc patches
Signature · 1 line
2.34.1
v3 cover arm64: improve debuggability
From: Nadav Amit <[email protected]>
My recent experience in debugging ARM64 tests on EFI was not as fun as I expected it to be.
There were several reasons for that besides the questionable definition of "fun":
1. ARM64 is not compiled with frame pointers and there is no stack unwinder when the stack is dumped.
2. Building an EFI drops the debug information.
3. The addresses that are printed on dump_stack() and the use of GDB are hard because taking code relocation into account is non trivial.
The patches help both ARM64 and EFI for this matter. The image address is printed when EFI is used to allow the use of GDB. Symbols are emitted into a separate debug file. The frame pointer is included and special entry is added upon an exception to allow backtracing across exceptions.
[ PowerPC: Please ack patches 1,2 ]
[ x86: Please ack patches 1,2,5 ]
v2->v3:
* Consider PowerPC for reloc and related fixes [Andrew]
v1->v2:
* Andrew comments [see in individual patches]
* Few cleanups
Nadav Amit (6):
efi: keep efi debug information in a separate file lib/stack: print base addresses on relocation setups
arm64: enable frame pointer and support stack unwinding
arm64: stack: update trace stack on exception
efi: print address of image
arm64: dump stack on bad exception
.gitignore | 1 + Makefile | 2 +- arm/Makefile.arm | 3 -- arm/Makefile.arm64 | 2 ++ arm/Makefile.common | 8 +++++- arm/cstart64.S | 13 +++++++++ lib/arm64/asm-offsets.c | 6 +++- lib/arm64/asm/stack.h | 3 ++ lib/arm64/processor.c | 1 + lib/arm64/stack.c | 62 +++++++++++++++++++++++++++++++++++++++++ lib/efi.c | 4 +++ lib/stack.c | 31 +++++++++++++++++++-- powerpc/Makefile.common | 1 + x86/Makefile.common | 5 +++- 14 files changed, 133 insertions(+), 9 deletions(-) create mode 100644 lib/arm64/stack.c
Signature · 1 line
2.34.1
Re: [kvm-unit-tests PATCH v3 0/6] arm64: improve debuggability
Quoted 40 lines · Nadav Amit
From: Nadav Amit <[email protected]>
My recent experience in debugging ARM64 tests on EFI was not as fun as I expected it to be.
There were several reasons for that besides the questionable definition of "fun":
1. ARM64 is not compiled with frame pointers and there is no stack unwinder when the stack is dumped.
2. Building an EFI drops the debug information.
3. The addresses that are printed on
dump_stack()and the use of GDB are hard because taking code relocation into account is non trivial.The patches help both ARM64 and EFI for this matter. The image address is printed when EFI is used to allow the use of GDB. Symbols are emitted into a separate debug file. The frame pointer is included and special entry is added upon an exception to allow backtracing across exceptions.
[ PowerPC: Please ack patches 1,2 ]
[ x86: Please ack patches 1,2,5 ]
v2->v3:
* Consider PowerPC for reloc and related fixes [Andrew]
v1->v2:
* Andrew comments [see in individual patches]
* Few cleanupsNadav Amit (6):
efi: keep efi debug information in a separate file lib/stack: print base addresses on relocation setups
arm64: enable frame pointer and support stack unwinding
arm64: stack: update trace stack on exception
efi: print address of image
arm64: dump stack on bad exception
Quoted 20 lines
.gitignore | 1 + Makefile | 2 +- arm/Makefile.arm | 3 -- arm/Makefile.arm64 | 2 ++ arm/Makefile.common | 8 +++++- arm/cstart64.S | 13 +++++++++ lib/arm64/asm-offsets.c | 6 +++- lib/arm64/asm/stack.h | 3 ++ lib/arm64/processor.c | 1 + lib/arm64/stack.c | 62 +++++++++++++++++++++++++++++++++++++++++ lib/efi.c | 4 +++ lib/stack.c | 31 +++++++++++++++++++-- powerpc/Makefile.common | 1 + x86/Makefile.common | 5 +++- 14 files changed, 133 insertions(+), 9 deletions(-) create mode 100644 lib/arm64/stack.cSignature · 1 line
2.34.1
Merged. arm64 backtraces will be really nice to have!
Thanks, Nadav!
drew
PATCH v3 1/6 efi: keep efi debug information in a separate file
In reply to Nadav AmitFrom: Nadav Amit <[email protected]>
Debugging tests that run on EFI is hard because the debug information is not included in the EFI file. Dump it into a separeate .debug file to allow the use of gdb or pretty_print_stacks script.
---
v2->v3:
* Add *.debug to .gitignore [Andrew]
v1->v2:
* Making clean should remove .debug [Andrew]
* x86 EFI support [Andrew]
--- .gitignore | 1 + arm/Makefile.common | 5 ++++- x86/Makefile.common | 5 ++++- 3 files changed, 9 insertions(+), 2 deletions(-)
.gitignore +1 -0
@@ -7,6 +7,7 @@ tags *.flat *.efi *.elf +*.debug *.patch .pc patches
arm/Makefile.common +4 -1
@@ -78,6 +78,9 @@ ifeq ($(CONFIG_EFI),y) %.efi: %.so $(call arch_elf_check, $^) + $(OBJCOPY) --only-keep-debug $^ [email protected] + $(OBJCOPY) --strip-debug $^ + $(OBJCOPY) [email protected] $^ $(OBJCOPY) \ -j .text -j .sdata -j .data -j .dynamic -j .dynsym \ -j .rel -j .rela -j .rel.* -j .rela.* -j .rel* -j .rela* \
@@ -103,7 +106,7 @@ $(libeabi): $(eabiobjs) $(AR) rcs $@ $^ arm_clean: asm_offsets_clean - $(RM) $(TEST_DIR)/*.{o,flat,elf,so,efi} $(libeabi) $(eabiobjs) \ + $(RM) $(TEST_DIR)/*.{o,flat,elf,so,efi,debug} $(libeabi) $(eabiobjs) \ $(TEST_DIR)/.*.d $(TEST_DIR)/efi/.*.d lib/arm/.*.d generated-files = $(asm-offsets)
x86/Makefile.common +4 -1
@@ -54,6 +54,9 @@ ifeq ($(CONFIG_EFI),y) @chmod a-x $@ %.efi: %.so + $(OBJCOPY) --only-keep-debug $^ [email protected] + $(OBJCOPY) --strip-debug $^ + $(OBJCOPY) [email protected] $^ $(OBJCOPY) \ -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel \ -j .rela -j .reloc -S --target=$(FORMAT) $< $@
@@ -124,4 +127,4 @@ arch_clean: $(RM) $(TEST_DIR)/*.o $(TEST_DIR)/*.flat $(TEST_DIR)/*.elf \ $(TEST_DIR)/.*.d lib/x86/.*.d \ $(TEST_DIR)/efi/*.o $(TEST_DIR)/efi/.*.d \ - $(TEST_DIR)/*.so $(TEST_DIR)/*.efi + $(TEST_DIR)/*.so $(TEST_DIR)/*.efi $(TEST_DIR)/*.debug
Signature · 1 line
2.34.1
PATCH v3 2/6 lib/stack: print base addresses on relocation setups
In reply to Nadav AmitFrom: Nadav Amit <[email protected]>
Making sense from dumped stacks when running EFI tests is very hard due to the relocation. Fix it by adjusting the address back to the original address.
Introduce CONFIG_RELOC, which would be set on arm64 and on EFI configs.
---v2->v3:
* Mark PowerPC as relocatable as well [Andrew]
* Fixing incorrect Makefile [Andrew]
v1->v2:
* Introduce CONFIG_RELOC to support ARM64 [Andrew]
--- Makefile | 2 +- arm/Makefile.arm64 | 1 + lib/stack.c | 31 +++++++++++++++++++++++++++++-- powerpc/Makefile.common | 1 + 4 files changed, 32 insertions(+), 3 deletions(-)
Makefile +1 -1
@@ -40,7 +40,7 @@ OBJDIRS += $(LIBFDT_objdir) # EFI App ifeq ($(CONFIG_EFI),y) -EFI_CFLAGS := -DCONFIG_EFI +EFI_CFLAGS := -DCONFIG_EFI -DCONFIG_RELOC # The following CFLAGS and LDFLAGS come from: # - GNU-EFI/Makefile.defaults # - GNU-EFI/apps/Makefile
arm/Makefile.arm64 +1 -0
@@ -12,6 +12,7 @@ CFLAGS += -mstrict-align mno_outline_atomics := $(call cc-option, -mno-outline-atomics, "") CFLAGS += $(mno_outline_atomics) +CFLAGS += -DCONFIG_RELOC define arch_elf_check = $(if $(shell ! $(READELF) -rW $(1) >&/dev/null && echo "nok"),
lib/stack.c +29 -2
@@ -6,13 +6,38 @@*/ #include <libcflat.h> +#include <stdbool.h> #include <stack.h> #define MAX_DEPTH 20 +#ifdef CONFIG_RELOC +extern char _text, _etext; + +static bool base_address (const void *rebased_addr,unsigned long *addr) +{ +unsigned long ra = (unsigned long )rebased_addr; +unsigned long start = (unsigned long )&_text; +unsigned long end = (unsigned long )&_etext; + +if (ra < start || ra >= end) +return false; + + *addr = ra - start; +return true; +} +#else +static bool base_address (const void *rebased_addr,unsigned long *addr) +{ + *addr = (unsigned long )rebased_addr; +return true; +} +#endif +static void print_stack (const void **return_addrs,int depth,bool top_is_return_address) { +unsigned long addr;int i =0 ;printf ("\tSTACK:" );
@@ -20,12 +45,14 @@ static void print_stack(const void **return_addrs, int depth,/* @addr indicates a non-return address, as expected by the stack * pretty printer script. */ if (depth >0 && !top_is_return_address) { -printf (" @%lx" , (unsigned long ) return_addrs[0 ]); +if (base_address (return_addrs[0 ], &addr)) +printf (" @%lx" , addr); i++; }for (; i < depth; i++) { -printf (" %lx" , (unsigned long ) return_addrs[i]); +if (base_address (return_addrs[i], &addr)) +printf (" %lx" , addr); }printf ("\n" ); }
powerpc/Makefile.common +1 -0
@@ -24,6 +24,7 @@ CFLAGS += -ffreestanding CFLAGS += -O2 -msoft-float -mno-altivec $(mabi_no_altivec) CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -I lib CFLAGS += -Wa,-mregnames +CFLAGS += -DCONFIG_RELOC # We want to keep intermediate files .PRECIOUS: %.o
Signature · 1 line
2.34.1
Re: [kvm-unit-tests PATCH v3 2/6] lib/stack: print base addresses on relocation setups
On Wed, Jun 28, 2023 at 12:13:51AM +0000, Nadav Amit wrote:
...
powerpc/Makefile.common CFLAGS += -ffreestanding · line 28
Quoted 10 lines
powerpc/Makefile.common +1
-0@@ -24,6 +24,7 @@ CFLAGS += -ffreestanding CFLAGS += -O2 -msoft-float -mno-altivec $(mabi_no_altivec) CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -I lib CFLAGS += -Wa,-mregnames +CFLAGS += -DCONFIG_RELOC
I dropped this change. powerpc doesn't define _text and _etext. I'll leave it to the ppc people to decide if they want this and want to add _text and _etext to get it.
Thanks,
drew
Re: [kvm-unit-tests PATCH v3 2/6] lib/stack: print base addresses on relocation setups
Quoted 8 lines · Andrew Jones
!! External Email
On Wed, Jun 28, 2023 at 12:13:51AM +0000, Nadav Amit wrote:
...
Quoted 14 lines
Quoted 10 lines
powerpc/Makefile.common +0
-0@@ -24,6 +24,7 @@ CFLAGS += -ffreestanding CFLAGS += -O2 -msoft-float -mno-altivec $(mabi_no_altivec)CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -I lib CFLAGS += -Wa,-mregnames
+CFLAGS += -DCONFIG_RELOCI dropped this change. powerpc doesn't define
_textand_etext. I'll leave it to the ppc people to decide if they want this and want to add_textand_etextto get it.
Thanks for taking care of it. Sorry for not noticing. I am always not inclined to change arch’s that I don’t use.
PATCH v3 3/6 arm64: enable frame pointer and support stack unwinding
In reply to Nadav AmitFrom: Nadav Amit <[email protected]>
Enable frame pointers for arm64 and perform stack unwinding based on arm64 convention.
---v1->v2:
* Adding SPDX [checkpatch]
* Moving some unused declarations to next patch [Andrew]
* Adding recursion prevention
--- arm/Makefile.arm | 3 --- arm/Makefile.arm64 | 1 + arm/Makefile.common | 3 +++ lib/arm64/asm/stack.h | 3 +++ lib/arm64/stack.c | 44 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 lib/arm64/stack.c
arm/Makefile.arm +0 -3
@@ -11,9 +11,6 @@ ifeq ($(CONFIG_EFI),y) $(error Cannot build arm32 tests as EFI apps) endif -# stack.o relies on frame pointers. -KEEP_FRAME_POINTER := y - CFLAGS += $(machine) CFLAGS += -mcpu=$(PROCESSOR) CFLAGS += -mno-unaligned-access
arm/Makefile.arm64 +1 -0
@@ -22,6 +22,7 @@ define arch_elf_check = endef cstart.o = $(TEST_DIR)/cstart64.o +cflatobjs += lib/arm64/stack.o cflatobjs += lib/arm64/processor.o cflatobjs += lib/arm64/spinlock.o cflatobjs += lib/arm64/gic-v3-its.o lib/arm64/gic-v3-its-cmd.o
arm/Makefile.common +3 -0
@@ -22,6 +22,9 @@ $(TEST_DIR)/sieve.elf: AUXFLAGS = 0x1 ################################################################## AUXFLAGS ?= 0x0 +# stack.o relies on frame pointers. +KEEP_FRAME_POINTER := y + CFLAGS += -std=gnu99 CFLAGS += -ffreestanding CFLAGS += -O2
lib/arm64/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/arm64/stack.c new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v3 4/6 arm64: stack: update trace stack on exception
In reply to Nadav AmitFrom: Nadav Amit <[email protected]>
Using gdb for backtracing or dumping the stack following an exception is not very helpful as the exact location of the exception is not saved.
Add an additional frame to save the location of the exception.
One delicate point is dealing with the pretty_print_stacks script. When the stack is dumped, the script would not print the right address for the exception address: for every return address it deducts "1" before looking for the instruction location in the code (using addr2line). As a somewhat hacky solution add "1" for the exception address when dumping the stack.
---v1->v2:
* .globl before label [Andrew]
* Some comments [Andrew]
--- arm/cstart64.S | 13 +++++++++++++ lib/arm64/asm-offsets.c | 6 +++++- lib/arm64/stack.c | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-)
arm/cstart64.S +13 -0
@@ -314,6 +314,13 @@ exceptions_init: mrs x2, spsr_el1 stp x1, x2, [sp, #S_PC] + /* + * Save a frame pointer using the link to allow unwinding of + * exceptions. + */ + stp x29, x1, [sp, #S_FP] + add x29, sp, #S_FP + mov x0, \vec mov x1, sp mrs x2, esr_el1
@@ -349,6 +356,9 @@ exceptions_init: eret .endm +.globl vector_stub_start +vector_stub_start: + vector_stub el1t_sync, 0 vector_stub el1t_irq, 1 vector_stub el1t_fiq, 2
@@ -369,6 +379,9 @@ vector_stub el0_irq_32, 13 vector_stub el0_fiq_32, 14 vector_stub el0_error_32, 15 +.globl vector_stub_end +vector_stub_end: + .section .text.ex .macro ventry, label
lib/arm64/asm-offsets.c +5 -1
@@ -25,6 +25,10 @@ int main(void)OFFSET (S_PSTATE , pt_regs, pstate);OFFSET (S_ORIG_X0 , pt_regs, orig_x0);OFFSET (S_SYSCALLNO , pt_regs, syscallno); -DEFINE (S_FRAME_SIZE ,sizeof (struct pt_regs )); + +/* FP and LR (16 bytes) go on the frame above pt_regs */ +DEFINE (S_FP ,sizeof (struct pt_regs )); +DEFINE (S_FRAME_SIZE , (sizeof (struct pt_regs ) +16 )); +return 0 ; }
lib/arm64/stack.c +18 -0
@@ -6,12 +6,16 @@#include <stdbool.h> #include <stack.h> +extern char vector_stub_start, vector_stub_end; +int backtrace_frame (const void *frame,const void **return_addrs,int max_depth) {const void *fp = frame;static bool walking;void *lr;int depth; +bool is_exception = false; +unsigned long addr;if (walking) {printf ("RECURSIVE STACK WALK!!!\n" );
@@ -31,6 +35,20 @@ int backtrace_frame(const void *frame, const void **return_addrs, int max_depth) : ); return_addrs[depth] = lr; + +/* +* If this is an exception, add 1 to the pointer so when the +* pretty_print_stacks script is run it would get the right +* address (it deducts 1 to find the call address, but we want +* the actual address). +*/ +if (is_exception) + return_addrs[depth] +=1 ; + +/* Check if we are in the exception handlers for the next entry */ + addr = (unsigned long )lr; + is_exception = (addr >= (unsigned long )&vector_stub_start && + addr < (unsigned long )&vector_stub_end); } walking = false;
Signature · 1 line
2.34.1
PATCH v3 5/6 efi: print address of image
In reply to Nadav AmitFrom: Nadav Amit <[email protected]>
Using gdb to debug tests that are run from efi is very hard without knowing the base address in which the image was loaded. Print the address so it can be used while debugging.
--- lib/efi.c | 4 ++++ 1 file changed, 4 insertions(+)
lib/efi.c +4 -0
@@ -19,6 +19,8 @@ extern int __argc, __envc;extern char *__argv[100 ];extern char *__environ[200 ]; +extern char _text; +extern int main (int argc,char **argv,char **envp);efi_system_table_t *efi_system_table =NULL ;
@@ -363,6 +365,8 @@ efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab) goto efi_main_error; } +printf ("Address of image is: 0x%lx\n" , (unsigned long )&_text); +/* Run the test case */ ret =main (__argc, __argv, __environ);
Signature · 1 line
2.34.1
PATCH v3 6/6 arm64: dump stack on bad exception
In reply to Nadav AmitFrom: Nadav Amit <[email protected]>
Upon a bad exception, the stack is rather useful for debugging, splat it out.
--- lib/arm64/processor.c | 1 + 1 file changed, 1 insertion(+)
lib/arm64/processor.c +1 -0
@@ -130,6 +130,7 @@ static void bad_exception(enum vector v, struct pt_regs *regs,printf ("Vector: %d (%s)\n" , v, vector_names[v]);printf ("ESR_EL1: %8s%08x, ec=%#x (%s)\n" ,"" , esr, ec, ec_names[ec]);printf ("FAR_EL1: %016lx (%svalid)\n" , far, far_valid ?"" :"not " ); +dump_stack ();printf ("Exception frame registers:\n" );show_regs (regs);abort ();
Signature · 1 line
2.34.1
Quoted 1 line · Nadav Amit
From: Nadav Amit <[email protected]>
Missing s-o-b.
Quoted 20 lines
--- .gitignore | 1 + 1 file changed, 1 insertion(+).gitignore +1
-0@@ -7,6 +7,7 @@ tags *.flat *.efi *.elf +*.debug *.patch .pc patchesSignature · 1 line
2.34.1
The patch threading is busted. Everything in the thread, including the cover letter, is in reply to this patch.
Thanks,
drew
Quoted 20 lines · Andrew Jones
Quoted 1 line · Nadav Amit
From: Nadav Amit <[email protected]>
Missing s-o-b.
Quoted 15 lines
--- .gitignore | 1 + 1 file changed, 1 insertion(+).gitignore +1
-0@@ -7,6 +7,7 @@ tags *.flat *.efi *.elf +*.debug *.patch
Quoted 9 lines
Quoted 5 lines
.gitignore +0
-0.pc patchesSignature · 1 line
2.34.1The patch threading is busted. Everything in the thread, including the cover letter, is in reply to this patch.
OK, I see the .gitignore hunk in patch 1, which is good, since it certainly doesn't need its own patch. I'll just ignore this "patch".
Thanks,
drew
Quoted 37 lines · Andrew Jones
!! External Email
Quoted 20 lines · Andrew Jones
Quoted 1 line · Nadav Amit
From: Nadav Amit <[email protected]>
Missing s-o-b.
Quoted 15 lines
---
.gitignore | 1 +1 file changed, 1 insertion(+).gitignore +1
-0@@ -7,6 +7,7 @@ tags *.flat *.efi *.elf +*.debug *.patchQuoted 9 lines
Quoted 5 lines
.pc
patches
--
2.34.1The patch threading is busted. Everything in the thread, including the cover letter, is in reply to this patch.
Quoted 2 lines
OK, I see the .gitignore hunk in patch 1, which is good, since it certainly doesn't need its own patch. I'll just ignore this "patch”.
Embarrassing… Will send v4.
Quoted 12 lines · Nadav Amit
Quoted 7 lines · Andrew Jones
OK, I see the .gitignore hunk in patch 1, which is good, since it certainly doesn't need its own patch. I'll just ignore this "patch”.
Embarrassing… Will send v4.
My double mistake. So I see this patch was not supposed to be sent, but other than that - you should have the series. Let me know if anything is wrong (as otherwise I won’t send v4).
Quoted 8 lines · Nadav Amit
Quoted 8 lines · Nadav Amit
Quoted 5 lines · Andrew Jones
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
OK, I see the .gitignore hunk in patch 1, which is good, since it certainly doesn't need its own patch. I'll just ignore this "patch”.
Embarrassing… Will send v4.
My double mistake. So I see this patch was not supposed to be sent, but other than that - you should have the series. Let me know if anything is wrong (as otherwise I won’t send v4).
The series looks good. I plan to queue it, but was hoping to see some acks from x86 and maybe ppc people first.
(I had to switch to this email address because I can't authenticate to the mail service used for my @linux.dev address right now... Hopefully that'll get resolved soon.)
Thanks,
drew