From: Helge Deller <deller@gmx.de>
To: qemu-devel@nongnu.org
Subject: [PATCH][RFC] Add crash handler for qemu-linux-user
Date: Thu, 10 Aug 2023 01:07:47 +0200 [thread overview]
Message-ID: <ZNQcQxcL/22LmrVP@p100> (raw)
If there is an internal program error in qemu source code
which triggers a SIGSEGV, qemu will currently assume this
is a SIGSEGV of the target and print:
(hppa-chroot)root@p100:/# cat /proc/self/maps
**
ERROR:../../home/cvs/qemu/qemu/accel/tcg/cpu-exec.c:532:cpu_exec_longjmp_cleanup: assertion failed: (cpu == current_cpu)
Bail out! ERROR:../../home/cvs/qemu/qemu/accel/tcg/cpu-exec.c:532:cpu_exec_longjmp_cleanup: assertion failed: (cpu == current_cpu)
**
This error message is very misleading for developers and end-users.
The attached patch will print instead:
(hppa-chroot)root@p100:/# cat /proc/self/maps
QEMU host internal error: signal=11, errno=0, code=1, addr=(nil)
QEMU host backtrace:
[0x7fd285445039]
[0x7fd28561af80]
[0x7fd28544eba9]
[0x7fd28544ebcb]
[0x7fd285459631]
[0x7fd28545d833]
[0x7fd285463e78]
[0x7fd2853fbd2d]
[0x7fd2853f57f9]
[0x7fd2856056a8]
[0x7fd285606d8f]
[0x7fd2853f60a5]
Note that glibc's backtrace() does not resolve the addresses to function
names, which is why only addresses are show above.
Is such a patch useful?
Ideas on how to get the function names resolved, e.g. including a
static build of libunwind?
Note, that the patch below includes the sigsegv-trigger (just run
"cat /proc/self/maps" in the chroot) for testing purposes.
Opinions?
Helge
Signed-off-by: Helge Deller <deller@gmx.de>
diff --git a/linux-user/signal.c b/linux-user/signal.c
index 748a98f3e5..5d01ab61b8 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -23,6 +23,7 @@
#include <sys/ucontext.h>
#include <sys/resource.h>
+#include <execinfo.h>
#include "qemu.h"
#include "user-internals.h"
@@ -781,6 +782,27 @@ static inline void rewind_if_in_safe_syscall(void *puc)
}
}
+static void qemu_show_backtrace(siginfo_t *info)
+{
+ void *array[20];
+ char **strings;
+ int size, i;
+
+ fprintf(stderr, "QEMU host internal error: signal=%d, errno=%d, code=%d, addr=%p\n",
+ info->si_signo, info->si_errno, info->si_code, info->si_addr);
+ size = backtrace (array, 20);
+ strings = backtrace_symbols (array, size);
+ if (strings)
+ {
+ fprintf(stderr, "QEMU host backtrace:\n");
+ for (i = 0; i < size; i++)
+ fprintf(stderr, "%s\n", strings[i]);
+ }
+ free (strings);
+ exit(info->si_code);
+}
+
+
static void host_signal_handler(int host_sig, siginfo_t *info, void *puc)
{
CPUArchState *env = thread_cpu->env_ptr;
@@ -819,6 +841,11 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc)
if (host_sig == SIGSEGV) {
bool maperr = true;
+ /* did qemu source code crashed? */
+ if (unlikely(!h2g_valid(host_addr))) {
+ qemu_show_backtrace(info);
+ }
+
if (info->si_code == SEGV_ACCERR && h2g_valid(host_addr)) {
/* If this was a write to a TB protected page, restart. */
if (is_write &&
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index a15bce2be2..0267ff7649 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8074,6 +8074,7 @@ static int open_self_maps_1(CPUArchState *cpu_env, int fd, bool smaps)
IntervalTreeNode *s;
int count;
+*(int*)NULL = 1;
for (s = interval_tree_iter_first(map_info, 0, -1); s;
s = interval_tree_iter_next(s, 0, -1)) {
MapInfo *e = container_of(s, MapInfo, itree);
diff --git a/meson.build b/meson.build
index 98e68ef0b1..6db4e029a0 100644
--- a/meson.build
+++ b/meson.build
@@ -4068,6 +4068,8 @@ if targetos == 'darwin'
summary_info += {'Objective-C compiler': ' '.join(meson.get_compiler('objc').cmd_array())}
endif
option_cflags = (get_option('debug') ? ['-g'] : [])
+# add symbol table for backtrace(), not sufficient for qemu-linux-user built as static executable
+option_cflags += ['-rdynamic']
if get_option('optimization') != 'plain'
option_cflags += ['-O' + get_option('optimization')]
endif
next reply other threads:[~2023-08-09 23:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-09 23:07 Helge Deller [this message]
2023-08-10 1:27 ` [PATCH][RFC] Add crash handler for qemu-linux-user Richard Henderson
2023-08-10 9:14 ` Peter Maydell
2023-08-17 10:58 ` Daniel P. Berrangé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZNQcQxcL/22LmrVP@p100 \
--to=deller@gmx.de \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.