From 5bb926e3c9bc00edef45b8a119469fc70e92990d Mon Sep 17 00:00:00 2001 From: Raul E Rangel Date: Mon, 29 Jun 2020 11:28:25 -0600 Subject: arch/x86/exception: Print stack on exception It's useful to see the stack when an exception happens so you can see the variables on the stack, and also manually recreate the back trace. If you need to recreate the back trace, you will need to add -fno-omit-frame-pointer to the CFLAGS. BUG=b:159081993 TEST=Caused an exception and saw the stack dumped. Then I manually recreated the back trace. 0xcc6fff6c: 0xcc6ce02e <- 0xcc6ce02e is in dev_initialize 0xcc6fff68: 0xcc6fff88 <-- frame 1 0xcc6fff64: 0x00000005 0xcc6fff60: 0x000000dc 0xcc6fff5c: 0x00000000 0xcc6fff58: 0x00000200 0xcc6fff54: 0x00000000 0xcc6fff50: 0x00000400 0xcc6fff4c: 0xcc6d72d4 <- 0xcc6d72d4 is in setup_default_ebdad 0xcc6fff48: 0xcc6fff68 <-ebp 0xcc6fff44: 0x00000005 0xcc6fff40: 0xcc6f571c <-esp Signed-off-by: Raul E Rangel Change-Id: I3822ea7aa23202ecc98612850402eeb4b1f7b5ef Reviewed-on: https://review.coreboot.org/c/coreboot/+/42884 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin --- src/arch/x86/exception.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/arch/x86') diff --git a/src/arch/x86/exception.c b/src/arch/x86/exception.c index 318a219ac9..958ebfc41c 100644 --- a/src/arch/x86/exception.c +++ b/src/arch/x86/exception.c @@ -544,7 +544,18 @@ void x86_exception(struct eregs *info) printk(BIOS_EMERG, "\n%p:\t", code + i); printk(BIOS_EMERG, "%.2x ", code[i]); } - die(""); + + /* Align to 4-byte boundary and up the stack. */ + u32 *ptr = (u32 *)(ALIGN_DOWN((uintptr_t)info->esp, sizeof(u32)) + MDUMP_SIZE - 4); + for (i = 0; i < MDUMP_SIZE / sizeof(u32); ++i, --ptr) { + printk(BIOS_EMERG, "\n%p:\t0x%08x", ptr, *ptr); + if ((uintptr_t)ptr == info->ebp) + printk(BIOS_EMERG, " <-ebp"); + else if ((uintptr_t)ptr == info->esp) + printk(BIOS_EMERG, " <-esp"); + } + + die("\n"); #endif } -- cgit v1.2.3