diff options
| author | manuel <manuel@mausz.at> | 2012-03-27 11:51:08 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2012-03-27 11:51:08 +0200 |
| commit | 4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b (patch) | |
| tree | 868c52e06f207b5ec8a3cc141f4b8b2bdfcc165c /lib/debug.c | |
| parent | eae0bd57f0a26314a94785061888d193d186944a (diff) | |
| download | progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.tar.gz progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.tar.bz2 progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.zip | |
reorganize file structure to match the upstream requirements
Diffstat (limited to 'lib/debug.c')
| -rw-r--r-- | lib/debug.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/debug.c b/lib/debug.c new file mode 100644 index 0000000..b4f8c2d --- /dev/null +++ b/lib/debug.c | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | #include <debug.h> | ||
| 2 | #include <stdarg.h> | ||
| 3 | #include <stdbool.h> | ||
| 4 | #include <stddef.h> | ||
| 5 | #include <stdio.h> | ||
| 6 | #include <string.h> | ||
| 7 | |||
| 8 | /* Prints the call stack, that is, a list of addresses, one in | ||
| 9 | each of the functions we are nested within. gdb or addr2line | ||
| 10 | may be applied to kernel.o to translate these into file names, | ||
| 11 | line numbers, and function names. */ | ||
| 12 | void | ||
| 13 | debug_backtrace (void) | ||
| 14 | { | ||
| 15 | static bool explained; | ||
| 16 | void **frame; | ||
| 17 | |||
| 18 | printf ("Call stack: %p", __builtin_return_address (0)); | ||
| 19 | for (frame = __builtin_frame_address (1); | ||
| 20 | (uintptr_t) frame >= 0x1000 && frame[0] != NULL; | ||
| 21 | frame = frame[0]) | ||
| 22 | printf (" %p", frame[1]); | ||
| 23 | printf (".\n"); | ||
| 24 | |||
| 25 | if (!explained) | ||
| 26 | { | ||
| 27 | explained = true; | ||
| 28 | printf ("The `backtrace' program can make call stacks useful.\n" | ||
| 29 | "Read \"Backtraces\" in the \"Debugging Tools\" chapter\n" | ||
| 30 | "of the Pintos documentation for more information.\n"); | ||
| 31 | } | ||
| 32 | } | ||
