Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Jul 2022 13:03:38 GMT
From:      Toomas Soome <tsoome@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: f4ca0fdbe69d - main - loader.efi: faults could try to print out call trace
Message-ID:  <202207141303.26ED3cTi005420@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by tsoome:

URL: https://cgit.FreeBSD.org/src/commit/?id=f4ca0fdbe69db4ab8147406e753d869d77485c2c

commit f4ca0fdbe69db4ab8147406e753d869d77485c2c
Author:     Toomas Soome <tsoome@FreeBSD.org>
AuthorDate: 2022-06-08 12:23:05 +0000
Commit:     Toomas Soome <tsoome@FreeBSD.org>
CommitDate: 2022-07-14 12:59:26 +0000

    loader.efi: faults could try to print out call trace
    
    with grab_faults, we can try to print out the trace of function calls.
    Without symbol table, we can not translate addresses to function names,
    but even addresses can help to track the bugs.
    
    For loader functions, print out absolute address, so it could be
    searched from objdump -d output.
    
    Reviewed by:    imp
    Differential Revision:  https://reviews.freebsd.org/D35433
---
 stand/efi/loader/arch/amd64/trap.c | 37 +++++++++++++++++++++++++++++++++++++
 stand/efi/loader/loader_efi.h      |  3 +++
 2 files changed, 40 insertions(+)

diff --git a/stand/efi/loader/arch/amd64/trap.c b/stand/efi/loader/arch/amd64/trap.c
index 1a4306b00e0a..81357e558185 100644
--- a/stand/efi/loader/arch/amd64/trap.c
+++ b/stand/efi/loader/arch/amd64/trap.c
@@ -78,11 +78,21 @@ static uint32_t loader_tss;		/* Loader TSS segment */
 static struct region_descriptor fw_gdt;	/* Descriptor of pristine GDT */
 static EFI_PHYSICAL_ADDRESS loader_gdt_pa; /* Address of loader shadow GDT */
 
+struct frame {
+	struct frame	*fr_savfp;
+	uintptr_t	fr_savpc;
+};
+
 void report_exc(struct trapframe *tf);
 void
 report_exc(struct trapframe *tf)
 {
+	struct frame *fp;
+	uintptr_t pc, base;
+	char buf[80];
+	int ret;
 
+	base = (uintptr_t)boot_img->ImageBase;
 	/*
 	 * printf() depends on loader runtime and UEFI firmware health
 	 * to produce the console output, in case of exception, the
@@ -108,6 +118,33 @@ report_exc(struct trapframe *tf)
 	    tf->tf_rdi, tf->tf_rsi, tf->tf_rdx, tf->tf_rcx, tf->tf_r8,
 	    tf->tf_r9, tf->tf_rax, tf->tf_rbx, tf->tf_rbp, tf->tf_r10,
 	    tf->tf_r11, tf->tf_r12, tf->tf_r13, tf->tf_r14, tf->tf_r15);
+
+	fp = (struct frame *)tf->tf_rbp;
+	pc = tf->tf_rip;
+
+	printf("Stack trace:\n");
+	pager_open();
+	while (fp != NULL || pc != 0) {
+		char *source = "PC";
+
+		if (pc >= base && pc < base + boot_img->ImageSize) {
+			pc -= base;
+			source = "loader PC";
+		}
+		(void) snprintf(buf, sizeof (buf), "FP %016lx: %s 0x%016lx\n",
+		    (uintptr_t)fp, source, pc);
+		if (pager_output(buf))
+			break;
+
+		if (fp != NULL)
+			fp = fp->fr_savfp;
+
+		if (fp != NULL)
+			pc = fp->fr_savpc;
+		else
+			pc = 0;
+	}
+	pager_close();
 	printf("Machine stopped.\n");
 }
 
diff --git a/stand/efi/loader/loader_efi.h b/stand/efi/loader/loader_efi.h
index d1958d62fe10..49434698fa03 100644
--- a/stand/efi/loader/loader_efi.h
+++ b/stand/efi/loader/loader_efi.h
@@ -32,6 +32,7 @@
 
 #include <stand.h>
 #include <readin.h>
+#include <efi.h>
 
 #ifdef __amd64__
 enum {
@@ -42,6 +43,8 @@ enum {
 extern int copy_staging;
 #endif
 
+extern EFI_LOADED_IMAGE *boot_img;
+
 int	efi_autoload(void);
 
 int	efi_copy_init(void);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202207141303.26ED3cTi005420>