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