summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneal <neal>2008-01-13 00:30:07 +0000
committerneal <neal>2008-01-13 00:30:07 +0000
commita635a615deba4f6994ed479eff466a13bb383f3a (patch)
treedc20c865860e9eff0a5da5dd4c69d2615712477f
parent758b41f7d3f91ed6989711e11cc4dddc54dd5643 (diff)
2008-01-13 Neal H. Walfield <neal@gnu.org>
* backtrace.c: New file. * Makefile.am (libc_parts_a_SOURCES): Add backtrace.c. * assert.h (assertx): Print a back trace.
-rw-r--r--libc-parts/ChangeLog7
-rw-r--r--libc-parts/Makefile.am2
-rw-r--r--libc-parts/assert.h44
-rw-r--r--libc-parts/backtrace.c52
4 files changed, 87 insertions, 18 deletions
diff --git a/libc-parts/ChangeLog b/libc-parts/ChangeLog
index 3fbe735..15f67c6 100644
--- a/libc-parts/ChangeLog
+++ b/libc-parts/ChangeLog
@@ -1,3 +1,10 @@
+2008-01-13 Neal H. Walfield <neal@gnu.org>
+
+ * backtrace.c: New file.
+ * Makefile.am (libc_parts_a_SOURCES): Add backtrace.c.
+
+ * assert.h (assertx): Print a back trace.
+
2008-01-08 Neal H. Walfield <neal@gnu.org>
* setjmp.h: New file.
diff --git a/libc-parts/Makefile.am b/libc-parts/Makefile.am
index f259674..4b12a96 100644
--- a/libc-parts/Makefile.am
+++ b/libc-parts/Makefile.am
@@ -32,7 +32,7 @@ libc_parts_a_SOURCES = $(ARCH_SOURCES) \
assert.h ctype.h c-ctype.h c-ctype.c \
errno.h errno.c \
strtol.c strtoll.c strtoul.c strtoull.c \
- setjmp.h
+ setjmp.h backtrace.c
# For the following routines we want to take the possibly optimized
# versions from the target's GNU C library, rather than duplicating
diff --git a/libc-parts/assert.h b/libc-parts/assert.h
index 8ce8e53..0bdb7ec 100644
--- a/libc-parts/assert.h
+++ b/libc-parts/assert.h
@@ -1,5 +1,5 @@
/* assert.h - Assert declaration for libc-parts.
- Copyright (C) 2003, 2005, 2007 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2005, 2007, 2008 Free Software Foundation, Inc.
Written by Neal H. Walfield <neal@gnu.org>.
This file is part of the GNU Hurd.
@@ -40,22 +40,32 @@ int printf (const char *fmt, ...);
# ifndef NDEBUG
#include <l4/thread.h>
-# define assertx(__ax_expr, __ax_fmt, ...) \
- do { \
- extern const char program_name[]; \
- if (! (__ax_expr)) \
- { \
- printf ("%s (%x):%s:%s:%d: %s failed", \
- program_name, l4_myself (), \
- __FILE__, __func__, __LINE__, \
- #__ax_expr); \
- if ((__ax_fmt) && *(__ax_fmt)) \
- { \
- printf (": " __ax_fmt, ##__VA_ARGS__); \
- } \
- printf ("\n"); \
- for (;;); \
- } \
+# define assertx(__ax_expr, __ax_fmt, ...) \
+ do { \
+ extern const char program_name[]; \
+ if (! (__ax_expr)) \
+ { \
+ printf ("%s (%x):%s:%s:%d: %s failed", \
+ program_name, l4_myself (), \
+ __FILE__, __func__, __LINE__, \
+ #__ax_expr); \
+ if ((__ax_fmt) && *(__ax_fmt)) \
+ { \
+ printf (": " __ax_fmt, ##__VA_ARGS__); \
+ } \
+ printf ("\n"); \
+ \
+ extern int backtrace (void **array, int size); \
+ \
+ void *a[10]; \
+ int count = backtrace (a, sizeof (a) / sizeof (a[0])); \
+ int i; \
+ for (i = 0; i < count; i ++) \
+ printf ("Backtrace: %p%s", a[i], i == count - 1 ? "" : " -> "); \
+ printf ("\n"); \
+ \
+ for (;;); \
+ } \
} while (0)
# define assert(__a_expr) \
diff --git a/libc-parts/backtrace.c b/libc-parts/backtrace.c
new file mode 100644
index 0000000..293dad0
--- /dev/null
+++ b/libc-parts/backtrace.c
@@ -0,0 +1,52 @@
+/* backtrace.c - Gather a backtrace.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Neal H. Walfield <neal@gnu.org>.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define RA(level) \
+ if (level < size && __builtin_return_address ((level) + 1)) \
+ *array = __builtin_return_address ((level) + 1); \
+ else \
+ return level;
+
+int
+backtrace (void **array, int size)
+{
+ RA(0);
+ RA(1);
+ RA(2);
+ RA(3);
+ RA(4);
+ RA(5);
+ RA(6);
+ RA(7);
+ RA(9);
+ RA(10);
+ RA(11);
+ RA(12);
+ RA(13);
+ RA(14);
+ RA(15);
+ RA(16);
+ RA(17);
+ RA(18);
+ RA(19);
+ RA(20);
+ return 20;
+}