Add support for better backtraces

At the cost of performance.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
diff --git a/Kconfig b/Kconfig
index 215e6db..0813fed 100644
--- a/Kconfig
+++ b/Kconfig
@@ -252,6 +252,14 @@
 		implementation.  Say y.  If you have networking bugs, try turning this
 		off, and if that helps, tell someone.
 
+config BETTER_BACKTRACE
+	bool "Better backtraces, less optimizations"
+	default n
+	help
+		The kernel uses the frame pointer and call stacks for backtraces.
+		Tail-call optimizations remove some of this information.  Say 'Y' here
+		to have better backtraces, at the expense of performance.
+
 endmenu
 
 menu "Misc/Old Options"
diff --git a/Makefile b/Makefile
index 5a95b57..12fe6c3 100644
--- a/Makefile
+++ b/Makefile
@@ -369,6 +369,9 @@
 else
 CFLAGS_KERNEL += -m32 -gstabs
 endif
+ifeq ($(CONFIG_BETTER_BACKTRACE),y)
+CFLAGS_KERNEL += -fno-optimize-sibling-calls
+endif
 
 # TODO: do we need this, or can we rely on the compiler's defines?
 CFLAGS_KERNEL += -D$(ARCH)
diff --git a/Makelocal.template b/Makelocal.template
index 54816b0..23ef9c6 100644
--- a/Makelocal.template
+++ b/Makelocal.template
@@ -2,7 +2,10 @@
 #CFLAGS_USER += -DCONFIG_APPSERVER
 #CFLAGS_USER += -DCONFIG_SYSCALL_TRAP
 #CFLAGS_USER += -g
+# Turn this on for better backtraces, but worse performance
+#CFLAGS_USER += -fno-optimize-sibling-calls
 #CFLAGS_TESTS += -static
+#CFLAGS_TESTS += -fno-optimize-sibling-calls
 export CFLAGS_USER CFLAGS_TESTS
 
 # brho's custom targets.  Customize to your system.