1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: dbg_Default.cpp 4 5 Copyright (C)2009-2012 Nintendo Co., Ltd. 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 $Rev: 48011 $ 14 *---------------------------------------------------------------------------*/ 15 16 #include <nn/Result.h> 17 #include <nn/math.h> 18 #include <nn/dbg.h> 19 #include <nn/dbg/dbg_Default.h> 20 #include <nn/init.h> 21 22 using namespace nn::dbg; 23 24 25 namespace nn { namespace dbg { 26 27 namespace 28 { 29 template <typename T> Replace(T & var,T v)30 inline T Replace(T& var, T v) 31 { 32 T old = var; 33 var = v; 34 return old; 35 } 36 37 void HandleBreak(nn::dbg::BreakReason reason, nn::Result* pResult, 38 const char* filename, int lineno, const char* fmt, std::va_list args) NN_IS_UNUSED_FUNC; HandleBreak(nn::dbg::BreakReason reason,nn::Result * pResult,const char * filename,int lineno,const char * fmt,std::va_list args)39 void HandleBreak(nn::dbg::BreakReason reason, nn::Result* pResult, 40 const char* filename, int lineno, const char* fmt, std::va_list args) 41 { 42 ExceptionScreen::PrepareDisplaybuffer(); 43 44 // Wait one frame 45 os::Thread::Sleep(fnd::TimeSpan::FromMilliSeconds(20)); 46 47 DirectPrint* pdp = ExceptionScreen::GetDirectPrint(); 48 49 math::VEC2 pos(0, 0); 50 51 pdp->SetFillSpace(true); 52 53 switch(reason) 54 { 55 case BREAK_REASON_PANIC: pdp->Printf(pos, "Panic!"); break; 56 case BREAK_REASON_ASSERT: pdp->Printf(pos, "Assertion failed"); break; 57 case BREAK_REASON_USER: pdp->Printf(pos, "User Break"); break; 58 default: pdp->Printf(pos, "unknown break reason %d", reason); break; 59 } 60 pos.x += DirectPrint::FONT_WIDTH; 61 pos.y += DirectPrint::FONT_HEIGHT; 62 63 if( pResult != NULL ) 64 { 65 pdp->Printf(pos, "%-13s 0x%08X", "Result:", pResult->GetPrintableBits()); 66 pos.y += DirectPrint::FONT_HEIGHT; 67 } 68 if( filename != NULL ) 69 { 70 pdp->Printf(pos, true, true, "%-13s %s(%d)", "File(Line):", filename, lineno); 71 pos.y += DirectPrint::FONT_HEIGHT; 72 } 73 if( fmt != NULL ) 74 { 75 pdp->Printf(pos, "Message:"); 76 pos.x += DirectPrint::FONT_WIDTH * 2; 77 pos.y += DirectPrint::FONT_HEIGHT; 78 79 pdp->Printf(pos, "----"); 80 pos.y += DirectPrint::FONT_HEIGHT; 81 82 const f32 prevX = Replace(pos.x, 0.f); 83 pdp->VPrintf(pos, fmt, args); 84 pos.x = prevX; 85 pos.y = pdp->GetLastCursorPos().y + DirectPrint::FONT_HEIGHT; 86 87 pdp->Printf(pos, "----"); 88 pos.y += DirectPrint::FONT_HEIGHT; 89 } 90 91 pos.x = 0; 92 pdp->Printf(pos, "stop."); 93 pdp->Flush(); 94 } 95 } 96 SetDefaultExceptionHandler()97 void SetDefaultExceptionHandler() 98 { 99 #if NN_PLATFORM_HAS_MMU 100 #if ! defined(NN_HARDWARE_CTR_LEGACY) 101 nn::dbg::ExceptionScreen::Create(init::GetAllocator()); 102 #endif 103 #endif // if NN_PLATFORM_HAS_MMU 104 } 105 SetDefaultBreakHandler()106 void SetDefaultBreakHandler() 107 { 108 #if NN_PLATFORM_HAS_MMU 109 #if ! defined(NN_HARDWARE_CTR_LEGACY) 110 nn::dbg::SetBreakHandler(&HandleBreak); 111 #endif 112 #endif // if NN_PLATFORM_HAS_MMU 113 } 114 115 }} 116