-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.c
47 lines (41 loc) · 948 Bytes
/
debug.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdio.h>
#include <stdlib.h>
#include "debug.h"
/**
* This function was taken from the Pintos operating system.
* See:
* http://courses.cs.vt.edu/~cs3204/fall2009/pintos/doc/pintos_1.html#SEC12
* for more information on Pintos's license.
* */
void
debug_backtrace (void)
{
void **frame;
printf ("Call stack: %p \n", __builtin_return_address (0));
for (frame = __builtin_frame_address (1);
(void*) frame >= (void*) 0x1000 &&
frame[0] != NULL;
frame = frame[0])
{
printf (" %p", frame[1]);
}
printf (".\n");
};
void
hexdump (void* _start, size_t sz)
{
unsigned char* start = _start;
size_t sigbyte = 0;
unsigned i;
while (sigbyte < sz)
{
printf ("%x: ", sigbyte);
for (i = 0; i < 16; i++)
{
unsigned char b = *start++;
printf ("%x ", b);
}
printf ("\n");
sigbyte += 16;
}
};