LibXenon
Bare-metal Xbox 360 homebrew library
Loading...
Searching...
No Matches
debug.c
Go to the documentation of this file.
1#include <stdlib.h>
2#include <debug.h>
3#include <ppc/register.h>
4#include <ppc/xenonsprs.h>
5
6void buffer_dump(void * buf, int size){
7 int i;
8 char* cbuf=(char*) buf;
9
10 printf("[Buffer dump] at %p, size=%d\n",buf,size);
11
12 while(size>0){
13 for(i=0;i<16;++i){
14 printf("%02x ",*cbuf);
15 ++cbuf;
16 }
17 printf("\n");
18 size-=16;
19 }
20}
21
22extern unsigned char elfldr_start[]; // also end of .text ...
23
24static int seems_valid(unsigned int p){
25 return p>=0x80000000 && p<(unsigned int)elfldr_start;
26}
27
28#define DO_RA(x) if(seems_valid(addr) && x<max_depth){ addr=(unsigned int)__builtin_return_address(x); printf("%p; ",addr); }
29
30void stack_trace(int max_depth)
31{
32 unsigned int addr=0x80000000;
33
34 printf("[Stack trace] ");
35
36 DO_RA(0);
37 DO_RA(1);
38 DO_RA(2);
39 DO_RA(3);
40 DO_RA(4);
41 DO_RA(5);
42 DO_RA(6);
43 DO_RA(7);
44 DO_RA(8);
45 DO_RA(9);
46 DO_RA(10);
47 DO_RA(11);
48 DO_RA(12);
49 DO_RA(13);
50 DO_RA(14);
51 DO_RA(15);
52
53 printf("\n");
54}
55
56void data_breakpoint(void * address, int on_read, int on_write)
57{
58 if (on_read || on_write)
59 mtspr(dabrx,6);
60 else
61 mtspr(dabrx,0);
62
63 unsigned int db=((unsigned int)address)&~7;
64
65 db|=4; // virtual address
66
67 if (on_read)
68 db|=1;
69
70 if (on_write)
71 db|=2;
72
73 mtspr(dabr,db);
74}
uint32_t address
Definition: ata.h:0
void data_breakpoint(void *address, int on_read, int on_write)
Definition: debug.c:56
#define DO_RA(x)
Definition: debug.c:28
void stack_trace(int max_depth)
Definition: debug.c:30
unsigned char elfldr_start[]
void buffer_dump(void *buf, int size)
Definition: debug.c:6
u32 size
Definition: iso9660.c:537
#define mtspr(rn, v)
Definition: register.h:24
#define dabr
Definition: xenonsprs.h:53
#define dabrx
Definition: xenonsprs.h:54