summaryrefslogtreecommitdiff
path: root/mysys/stacktrace.c
diff options
context:
space:
mode:
Diffstat (limited to 'mysys/stacktrace.c')
-rw-r--r--mysys/stacktrace.c50
1 files changed, 37 insertions, 13 deletions
diff --git a/mysys/stacktrace.c b/mysys/stacktrace.c
index 175ee8a3025..1766c0f503a 100644
--- a/mysys/stacktrace.c
+++ b/mysys/stacktrace.c
@@ -1,4 +1,5 @@
-/* Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
+/*
+ Copyright (c) 2001, 2011, Oracle and/or its affiliates
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -118,12 +119,8 @@ static int safe_print_str(const char *addr, int max_len)
break;
}
- /* Output a new line if something was printed. */
- if (total != (size_t) max_len)
- my_safe_printf_stderr("%s", "\n");
-
if (nbytes == -1)
- my_safe_printf_stderr("Can't read from address %p\n", addr);
+ my_safe_printf_stderr("Can't read from address %p", addr);
close(fd);
@@ -145,7 +142,7 @@ void my_safe_print_str(const char* val, int max_len)
if (!PTR_SANE(val))
{
- my_safe_printf_stderr("%s", "is an invalid pointer\n");
+ my_safe_printf_stderr("%s", "is an invalid pointer");
return;
}
@@ -217,25 +214,52 @@ static void my_demangle_symbols(char **addrs, int n)
#endif /* BACKTRACE_DEMANGLE */
+#if HAVE_MY_ADDR_RESOLVE
+static int print_with_addr_resolve(void **addrs, int n)
+{
+ int i;
+ const char *err;
+
+ if ((err= my_addr_resolve_init()))
+ {
+ my_safe_printf_stderr("(my_addr_resolve failure: %s)\n", err);
+ return 0;
+ }
+
+ for (i= 0; i < n; i++)
+ {
+ my_addr_loc loc;
+ if (my_addr_resolve(addrs[i], &loc))
+ backtrace_symbols_fd(addrs+i, 1, fileno(stderr));
+ else
+ my_safe_printf_stderr("%s:%u(%s)[%p]\n",
+ loc.file, loc.line, loc.func, addrs[i]);
+ }
+ return 1;
+}
+#endif
+
void my_print_stacktrace(uchar* stack_bottom, ulong thread_stack)
{
void *addrs[128];
- char **strings= NULL;
+ char **strings __attribute__((unused)) = NULL;
int n = backtrace(addrs, array_elements(addrs));
my_safe_printf_stderr("stack_bottom = %p thread_stack 0x%lx\n",
stack_bottom, thread_stack);
+#if HAVE_MY_ADDR_RESOLVE
+ if (print_with_addr_resolve(addrs, n))
+ return;
+#endif
#if BACKTRACE_DEMANGLE
if ((strings= backtrace_symbols(addrs, n)))
{
my_demangle_symbols(strings, n);
free(strings);
+ return;
}
#endif
#if HAVE_BACKTRACE_SYMBOLS_FD
- if (!strings)
- {
- backtrace_symbols_fd(addrs, n, fileno(stderr));
- }
+ backtrace_symbols_fd(addrs, n, fileno(stderr));
#endif
}
@@ -719,7 +743,7 @@ void my_safe_print_str(const char *val, int len)
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
- my_safe_printf_stderr("%s", "is an invalid string pointer\n");
+ my_safe_printf_stderr("%s", "is an invalid string pointer");
}
}
#endif /*__WIN__*/