1 /*---------------------------------------------------------------------------*
2   Project: panic demo
3   File:    panic.c
4 
5   Copyright 2002 Nintendo.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Log: panic.c,v $
14   Revision 1.2  02/20/2006 04:13:11  mitu
15   changed include path from dolphin/ to revolution/.
16 
17   Revision 1.1  01/13/2006 11:24:13  hiratsu
18   Initial check in.
19 
20 
21     4     02/09/05 9:50 Hashida
22     Deleted #include <alloca.h> since SN ProDG doesn't have the header
23     file.
24 
25     3     8/26/02 13:57 Shiki
26     Clean up.
27 
28     2     8/22/02 10:49:00 Shiki
29     Added another const keyword to the OSPanic() function prototype.
30 
31     1     8/20/02 21:55:00 Shiki
32     Initial check-in.
33   $NoKeywords: $
34  *---------------------------------------------------------------------------*/
35 
36 #include <stdarg.h>
37 #include <stdio.h>
38 #include <revolution/os.h>
39 
40 // Define program-specific OSPanic() function for the assertion message.
OSPanic(const char * file,int line,const char * msg,...)41 void OSPanic(const char* file, int line, const char* msg, ...)
42 {
43     va_list marker;
44     u32     i;
45     u32*    p;
46     int     len;
47     GXColor bg = {   0,   0, 255, 0 };
48     GXColor fg = { 255, 255, 255, 0 };
49     char    message[4096];
50 
51     va_start(marker, msg);
52     len = vsprintf(message, msg, marker);
53     va_end(marker);
54     len += sprintf(message + len, " in \"%s\" on line %d.\n", file, line);
55 
56     // Stack crawl
57     len += sprintf(message + len, "\nAddress:    Back Chain LR Save\n");
58     for (i = 0, p = (u32*) OSGetStackPointer(); // get current sp
59          p && (u32) p != 0xffffffff && i++ < 16;
60          p = (u32*) *p)                         // get caller sp
61     {
62         len += sprintf(message + len, "0x%08x: 0x%08x 0x%08x\n", p, p[0], p[1]);
63     }
64 
65     OSFatal(fg, bg, message);
66     // NOT REACHED HERE
67 }
68 
main(void)69 void main(void)
70 {
71     OSReport("This program illustrates how to capture OS assertion message\n"
72              "at the user-level.\n");
73     OSReport("Note: This program simply crashes with NDEBUG build.\n");
74 
75     // Do something really bad to raise an assertion failure. (DEBUG build only)
76     OSFree(NULL);
77     OSReport("Done.\n");
78 }
79