aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/debug.c
diff options
context:
space:
mode:
authorklaar36 <klas.arvidsson@liu.se>2015-03-20 17:30:24 +0100
committerklaar36 <klas.arvidsson@liu.se>2015-03-20 17:30:24 +0100
commite7bc50ca8ffcaa6ed68ebd2315f78b0f5a7d10ad (patch)
tree4de97af7207676b69cb6a9aba8cb443cc134855d /src/lib/debug.c
parentb0418a24e709f0632d2ede5b0f327c422931939b (diff)
downloadpintos-rs-e7bc50ca8ffcaa6ed68ebd2315f78b0f5a7d10ad.tar.gz
Initial Pintos
Diffstat (limited to 'src/lib/debug.c')
-rw-r--r--src/lib/debug.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/lib/debug.c b/src/lib/debug.c
new file mode 100644
index 0000000..23668a8
--- /dev/null
+++ b/src/lib/debug.c
@@ -0,0 +1,34 @@
+#include <debug.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+
+/* Prints the call stack, that is, a list of addresses, one in
+ each of the functions we are nested within. gdb or addr2line
+ may be applied to kernel.o to translate these into file names,
+ line numbers, and function names. */
+void
+debug_backtrace (void)
+{
+ static bool explained;
+ void **frame;
+
+ printf ("backtrace ");
+ for (frame = __builtin_frame_address (0);
+ frame != NULL && frame[0] != NULL;
+ frame = frame[0])
+ printf (" %p", frame[1]);
+ printf (".\n");
+
+ if (!explained)
+ {
+ explained = true;
+ printf ("The `backtrace' program can make call stacks useful.\n"
+ "Read \"Backtraces\" in the \"Debugging Tools\" chapter\n"
+ "of the Pintos documentation for more information.\n"
+ "Simply copy-paste the backtrace command line above.\n"
+ );
+ }
+}