[parted-devel] [PATCH][1.8.0rc3] Print backtrace when throwing an exception

Otavio Salvador otavio at debian.org
Sat Nov 11 05:27:15 CET 2006


Hello,

I implemented the support to print the backtrace when throwing an
exception. It can probably be improved but it works fine here.

What do you think about merging it on 1.8?

-------------- next part --------------
Sat Nov 11 02:21:25 BRST 2006  Otavio Salvador <otavio at debian.org>
  * Print backtrace stack when throwing an exception
diff -rN -u old-backtrace-on-assert/ChangeLog new-backtrace-on-assert/ChangeLog
--- old-backtrace-on-assert/ChangeLog	2006-11-11 02:24:32.000000000 -0200
+++ new-backtrace-on-assert/ChangeLog	2006-11-11 02:24:32.000000000 -0200
@@ -8,6 +8,8 @@
 
 	* autogen.sh: use -f on autopoint to ensure we have the files
 	updated.
+
+	* configure.ac: add -rdynamic on CFLAGS.
 	
 2006-11-08  Otavio Salvador <otavio at debian.org>
 
diff -rN -u old-backtrace-on-assert/configure.ac new-backtrace-on-assert/configure.ac
--- old-backtrace-on-assert/configure.ac	2006-11-11 02:24:32.000000000 -0200
+++ new-backtrace-on-assert/configure.ac	2006-11-11 02:24:32.000000000 -0200
@@ -438,7 +438,7 @@
 AC_CHECK_FUNCS(canonicalize_file_name)
 CFLAGS="$OLD_CFLAGS"
 
-CFLAGS="$CFLAGS -W -Wall -Wno-unused -Wno-switch -Wno-format"
+CFLAGS="$CFLAGS -W -Wall -Wno-unused -Wno-switch -Wno-format -rdynamic"
 
 if test "$enable_Werror" = yes; then
 	CFLAGS="$CFLAGS -Werror"
diff -rN -u old-backtrace-on-assert/libparted/ChangeLog new-backtrace-on-assert/libparted/ChangeLog
--- old-backtrace-on-assert/libparted/ChangeLog	2006-11-11 02:24:32.000000000 -0200
+++ new-backtrace-on-assert/libparted/ChangeLog	2006-11-11 02:24:32.000000000 -0200
@@ -1,3 +1,10 @@
+2006-11-11  Otavio Salvador  <otavio at debian.org>
+
+	* libparted/debug.c (ped_assert): Print backtrace stack when
+	throwing an exception.
+
+	* libparted/Makefile.am: Add -rdynamic on LDFLAGS.
+
 2006-11-10  Otavio Salvador  <otavio at debian.org>
 
 	* libparted/filesys.c (ped_file_system_type_unregister): Handle
diff -rN -u old-backtrace-on-assert/libparted/debug.c new-backtrace-on-assert/libparted/debug.c
--- old-backtrace-on-assert/libparted/debug.c	2006-11-11 02:24:32.000000000 -0200
+++ new-backtrace-on-assert/libparted/debug.c	2006-11-11 02:24:32.000000000 -0200
@@ -30,6 +30,8 @@
 
 #ifdef DEBUG
 
+#include <execinfo.h>
+
 static void default_handler ( const int level, const char* file, int line,
                 const char* function, const char* msg );
 static PedDebugHandler* debug_handler = &default_handler;
@@ -87,6 +89,21 @@
 	if ( cond )
 		return 1;
 
+	/* Print backtrace stack */
+	void *stack[20];
+	size_t size;
+	char **strings;
+	
+	size = backtrace(stack, 20);
+	strings = backtrace_symbols(stack, size);
+
+	printf(_("Backtrace has %d calls on stack:\n"), size);
+	for (; size > 0; size--, strings++)
+		printf("  %d: %s\n", size, *strings);
+
+	free(strings);
+
+	/* Throw the exception */
 	opt = ped_exception_throw (
 		PED_EXCEPTION_BUG,
 		PED_EXCEPTION_IGNORE_CANCEL,
diff -rN -u old-backtrace-on-assert/libparted/Makefile.am new-backtrace-on-assert/libparted/Makefile.am
--- old-backtrace-on-assert/libparted/Makefile.am	2006-11-11 02:24:32.000000000 -0200
+++ new-backtrace-on-assert/libparted/Makefile.am	2006-11-11 02:24:32.000000000 -0200
@@ -10,7 +10,7 @@
 partedincludedir      =	-I$(top_srcdir)/include
 lib_LTLIBRARIES	      =	libparted.la
 libparted_la_LDFLAGS  = -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
- 			-release $(LT_RELEASE)
+ 						-release $(LT_RELEASE) -rdynamic
 
 libparted_la_SOURCES  = debug.c			\
 			device.c		\

-------------- next part --------------

-- 
        O T A V I O    S A L V A D O R
---------------------------------------------
 E-mail: otavio at debian.org      UIN: 5906116
 GNU/Linux User: 239058     GPG ID: 49A5F855
 Home Page: http://www.freedom.ind.br/otavio
---------------------------------------------
"Microsoft gives you Windows ... Linux gives
 you the whole house."


More information about the parted-devel mailing list