|
|
8e15ce |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
8e15ce |
From: Peter Jones <pjones@redhat.com>
|
|
|
8e15ce |
Date: Wed, 27 Jan 2016 09:22:42 -0500
|
|
|
8e15ce |
Subject: [PATCH] Make grub_fatal() also backtrace.
|
|
|
8e15ce |
|
|
|
8e15ce |
---
|
|
|
8e15ce |
grub-core/Makefile.core.def | 3 ++
|
|
|
8e15ce |
grub-core/kern/misc.c | 8 +++++-
|
|
|
8e15ce |
grub-core/lib/arm64/backtrace.c | 62 +++++++++++++++++++++++++++++++++++++++++
|
|
|
8e15ce |
grub-core/lib/backtrace.c | 2 ++
|
|
|
8e15ce |
grub-core/lib/i386/backtrace.c | 14 +++++++++-
|
|
|
8e15ce |
5 files changed, 87 insertions(+), 2 deletions(-)
|
|
|
8e15ce |
create mode 100644 grub-core/lib/arm64/backtrace.c
|
|
|
8e15ce |
|
|
|
8e15ce |
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
|
|
|
b35c50 |
index c15e91943b..058c88ac3a 100644
|
|
|
8e15ce |
--- a/grub-core/Makefile.core.def
|
|
|
8e15ce |
+++ b/grub-core/Makefile.core.def
|
|
|
8e15ce |
@@ -188,6 +188,9 @@ kernel = {
|
|
|
8e15ce |
|
|
|
8e15ce |
softdiv = lib/division.c;
|
|
|
8e15ce |
|
|
|
8e15ce |
+ x86 = lib/i386/backtrace.c;
|
|
|
8e15ce |
+ x86 = lib/backtrace.c;
|
|
|
8e15ce |
+
|
|
|
8e15ce |
i386 = kern/i386/dl.c;
|
|
|
8e15ce |
i386_xen = kern/i386/dl.c;
|
|
|
8e15ce |
i386_xen_pvh = kern/i386/dl.c;
|
|
|
8e15ce |
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
|
|
|
b35c50 |
index 63b586d09c..a3e215155b 100644
|
|
|
8e15ce |
--- a/grub-core/kern/misc.c
|
|
|
8e15ce |
+++ b/grub-core/kern/misc.c
|
|
|
8e15ce |
@@ -24,6 +24,7 @@
|
|
|
8e15ce |
#include <grub/term.h>
|
|
|
8e15ce |
#include <grub/env.h>
|
|
|
8e15ce |
#include <grub/i18n.h>
|
|
|
8e15ce |
+#include <grub/backtrace.h>
|
|
|
8e15ce |
|
|
|
8e15ce |
union printf_arg
|
|
|
8e15ce |
{
|
|
|
8e15ce |
@@ -1199,8 +1200,13 @@ grub_printf_fmt_check (const char *fmt, const char *fmt_expected)
|
|
|
8e15ce |
static void __attribute__ ((noreturn))
|
|
|
8e15ce |
grub_abort (void)
|
|
|
8e15ce |
{
|
|
|
8e15ce |
+#ifndef GRUB_UTIL
|
|
|
8e15ce |
+#if defined(__i386__) || defined(__x86_64__)
|
|
|
8e15ce |
+ grub_backtrace();
|
|
|
8e15ce |
+#endif
|
|
|
8e15ce |
+#endif
|
|
|
8e15ce |
grub_printf ("\nAborted.");
|
|
|
8e15ce |
-
|
|
|
8e15ce |
+
|
|
|
8e15ce |
#ifndef GRUB_UTIL
|
|
|
8e15ce |
if (grub_term_inputs)
|
|
|
8e15ce |
#endif
|
|
|
8e15ce |
diff --git a/grub-core/lib/arm64/backtrace.c b/grub-core/lib/arm64/backtrace.c
|
|
|
8e15ce |
new file mode 100644
|
|
|
b35c50 |
index 0000000000..1079b5380e
|
|
|
8e15ce |
--- /dev/null
|
|
|
8e15ce |
+++ b/grub-core/lib/arm64/backtrace.c
|
|
|
8e15ce |
@@ -0,0 +1,62 @@
|
|
|
8e15ce |
+/*
|
|
|
8e15ce |
+ * GRUB -- GRand Unified Bootloader
|
|
|
8e15ce |
+ * Copyright (C) 2009 Free Software Foundation, Inc.
|
|
|
8e15ce |
+ *
|
|
|
8e15ce |
+ * GRUB is free software: you can redistribute it and/or modify
|
|
|
8e15ce |
+ * it under the terms of the GNU General Public License as published by
|
|
|
8e15ce |
+ * the Free Software Foundation, either version 3 of the License, or
|
|
|
8e15ce |
+ * (at your option) any later version.
|
|
|
8e15ce |
+ *
|
|
|
8e15ce |
+ * GRUB is distributed in the hope that it will be useful,
|
|
|
8e15ce |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
8e15ce |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
8e15ce |
+ * GNU General Public License for more details.
|
|
|
8e15ce |
+ *
|
|
|
8e15ce |
+ * You should have received a copy of the GNU General Public License
|
|
|
8e15ce |
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
|
|
8e15ce |
+ */
|
|
|
8e15ce |
+
|
|
|
8e15ce |
+#include <grub/misc.h>
|
|
|
8e15ce |
+#include <grub/command.h>
|
|
|
8e15ce |
+#include <grub/err.h>
|
|
|
8e15ce |
+#include <grub/dl.h>
|
|
|
8e15ce |
+#include <grub/mm.h>
|
|
|
8e15ce |
+#include <grub/term.h>
|
|
|
8e15ce |
+#include <grub/backtrace.h>
|
|
|
8e15ce |
+
|
|
|
8e15ce |
+#define MAX_STACK_FRAME 102400
|
|
|
8e15ce |
+
|
|
|
8e15ce |
+void
|
|
|
8e15ce |
+grub_backtrace_pointer (int frame)
|
|
|
8e15ce |
+{
|
|
|
8e15ce |
+ while (1)
|
|
|
8e15ce |
+ {
|
|
|
8e15ce |
+ void *lp = __builtin_return_address (frame);
|
|
|
8e15ce |
+ if (!lp)
|
|
|
8e15ce |
+ break;
|
|
|
8e15ce |
+
|
|
|
8e15ce |
+ lp = __builtin_extract_return_addr (lp);
|
|
|
8e15ce |
+
|
|
|
8e15ce |
+ grub_printf ("%p: ", lp);
|
|
|
8e15ce |
+ grub_backtrace_print_address (lp);
|
|
|
8e15ce |
+ grub_printf (" (");
|
|
|
8e15ce |
+ for (i = 0; i < 2; i++)
|
|
|
8e15ce |
+ grub_printf ("%p,", ((void **)ptr) [i + 2]);
|
|
|
8e15ce |
+ grub_printf ("%p)\n", ((void **)ptr) [i + 2]);
|
|
|
8e15ce |
+ nptr = *(void **)ptr;
|
|
|
8e15ce |
+ if (nptr < ptr || (void **) nptr - (void **) ptr > MAX_STACK_FRAME
|
|
|
8e15ce |
+ || nptr == ptr)
|
|
|
8e15ce |
+ {
|
|
|
8e15ce |
+ grub_printf ("Invalid stack frame at %p (%p)\n", ptr, nptr);
|
|
|
8e15ce |
+ break;
|
|
|
8e15ce |
+ }
|
|
|
8e15ce |
+ ptr = nptr;
|
|
|
8e15ce |
+ }
|
|
|
8e15ce |
+}
|
|
|
8e15ce |
+
|
|
|
8e15ce |
+void
|
|
|
8e15ce |
+grub_backtrace (void)
|
|
|
8e15ce |
+{
|
|
|
8e15ce |
+ grub_backtrace_pointer (1);
|
|
|
8e15ce |
+}
|
|
|
8e15ce |
+
|
|
|
8e15ce |
diff --git a/grub-core/lib/backtrace.c b/grub-core/lib/backtrace.c
|
|
|
b35c50 |
index 825a8800e2..c0ad6ab8be 100644
|
|
|
8e15ce |
--- a/grub-core/lib/backtrace.c
|
|
|
8e15ce |
+++ b/grub-core/lib/backtrace.c
|
|
|
8e15ce |
@@ -29,6 +29,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
|
|
|
8e15ce |
void
|
|
|
8e15ce |
grub_backtrace_print_address (void *addr)
|
|
|
8e15ce |
{
|
|
|
8e15ce |
+#ifndef GRUB_UTIL
|
|
|
8e15ce |
grub_dl_t mod;
|
|
|
8e15ce |
|
|
|
8e15ce |
FOR_DL_MODULES (mod)
|
|
|
8e15ce |
@@ -44,6 +45,7 @@ grub_backtrace_print_address (void *addr)
|
|
|
8e15ce |
}
|
|
|
8e15ce |
}
|
|
|
8e15ce |
|
|
|
8e15ce |
+#endif
|
|
|
8e15ce |
grub_printf ("%p", addr);
|
|
|
8e15ce |
}
|
|
|
8e15ce |
|
|
|
8e15ce |
diff --git a/grub-core/lib/i386/backtrace.c b/grub-core/lib/i386/backtrace.c
|
|
|
b35c50 |
index c3e03c7275..c67273db3a 100644
|
|
|
8e15ce |
--- a/grub-core/lib/i386/backtrace.c
|
|
|
8e15ce |
+++ b/grub-core/lib/i386/backtrace.c
|
|
|
8e15ce |
@@ -15,11 +15,23 @@
|
|
|
8e15ce |
* You should have received a copy of the GNU General Public License
|
|
|
8e15ce |
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
|
|
8e15ce |
*/
|
|
|
8e15ce |
+#include <config.h>
|
|
|
8e15ce |
+#ifdef GRUB_UTIL
|
|
|
8e15ce |
+#define REALLY_GRUB_UTIL GRUB_UTIL
|
|
|
8e15ce |
+#undef GRUB_UTIL
|
|
|
8e15ce |
+#endif
|
|
|
8e15ce |
+
|
|
|
8e15ce |
+#include <grub/symbol.h>
|
|
|
8e15ce |
+#include <grub/dl.h>
|
|
|
8e15ce |
+
|
|
|
8e15ce |
+#ifdef REALLY_GRUB_UTIL
|
|
|
8e15ce |
+#define GRUB_UTIL REALLY_GRUB_UTIL
|
|
|
8e15ce |
+#undef REALLY_GRUB_UTIL
|
|
|
8e15ce |
+#endif
|
|
|
8e15ce |
|
|
|
8e15ce |
#include <grub/misc.h>
|
|
|
8e15ce |
#include <grub/command.h>
|
|
|
8e15ce |
#include <grub/err.h>
|
|
|
8e15ce |
-#include <grub/dl.h>
|
|
|
8e15ce |
#include <grub/mm.h>
|
|
|
8e15ce |
#include <grub/term.h>
|
|
|
8e15ce |
#include <grub/backtrace.h>
|