Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 1 | //===-- MIUtilDebug.cpp -----------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | //++ |
| 11 | // File: MIUtilDebug.h |
| 12 | // |
| 13 | // Overview: Terminal setting termios functions. |
| 14 | // |
| 15 | // Environment: Compilers: Visual C++ 12. |
| 16 | // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 |
| 17 | // Libraries: See MIReadmetxt. |
| 18 | // |
| 19 | // Copyright: None. |
| 20 | //-- |
| 21 | |
| 22 | // Third party headers: |
| 23 | #ifdef _WIN32 |
| 24 | #include <Windows.h> |
| 25 | #endif |
| 26 | |
| 27 | // In-house headers: |
| 28 | #include "MIUtilDebug.h" |
| 29 | #include "MIDriver.h" |
| 30 | #include "MICmnLog.h" |
| 31 | |
| 32 | //++ ------------------------------------------------------------------------------------ |
| 33 | // Details: CMIUtilDebug constructor. |
| 34 | // Type: Method. |
| 35 | // Args: None. |
| 36 | // Return: None. |
| 37 | // Throws: None. |
| 38 | //-- |
| 39 | CMIUtilDebug::CMIUtilDebug( void ) |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | //++ ------------------------------------------------------------------------------------ |
| 44 | // Details: CMIUtilDebug destructor. |
| 45 | // Type: Method. |
| 46 | // Args: None. |
| 47 | // Return: None. |
| 48 | // Throws: None. |
| 49 | //-- |
| 50 | CMIUtilDebug::~CMIUtilDebug( void ) |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | //++ ------------------------------------------------------------------------------------ |
| 55 | // Details: Show a dialog to the process/application halts. It gives the opportunity to |
| 56 | // attach a debugger. |
| 57 | // Type: Static method. |
| 58 | // Args: None. |
| 59 | // Return: None. |
| 60 | // Throws: None. |
| 61 | //-- |
| 62 | void CMIUtilDebug::ShowDlgWaitForDbgAttach( void ) |
| 63 | { |
| 64 | const CMIUtilString strCaption( CMIDriver::Instance().GetAppNameShort() ); |
| 65 | #ifdef _WIN32 |
| 66 | ::MessageBoxA( NULL, "Attach your debugger now", strCaption.c_str(), MB_OK ); |
| 67 | #else |
| 68 | // ToDo: Implement other platform version of an Ok to continue dialog box |
| 69 | #endif // _WIN32 |
| 70 | } |
| 71 | |
| 72 | //++ ------------------------------------------------------------------------------------ |
| 73 | // Details: Temporarily stall the process/application to give the programmer the |
| 74 | // opportunity to attach a debugger. How to use: Put a break in the programmer |
| 75 | // where you want to visit, run the application then attach your debugger to the |
| 76 | // application. Hit the debugger's pause button and the debugger should should |
| 77 | // show this loop. Change the i variable value to break out of the loop and |
| 78 | // visit your break point. |
| 79 | // Type: Static method. |
| 80 | // Args: None. |
| 81 | // Return: None. |
| 82 | // Throws: None. |
| 83 | //-- |
| 84 | void CMIUtilDebug::WaitForDbgAttachInfinteLoop( void ) |
| 85 | { |
| 86 | MIuint i = 0; |
| 87 | while( i == 0 ) |
| 88 | { |
| 89 | const std::chrono::milliseconds time( 100 ); |
| 90 | std::this_thread::sleep_for( time ); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | //--------------------------------------------------------------------------------------- |
| 95 | //--------------------------------------------------------------------------------------- |
| 96 | //--------------------------------------------------------------------------------------- |
| 97 | |
| 98 | // Instantiations: |
| 99 | CMICmnLog & CMIUtilDebugFnTrace::ms_rLog = CMICmnLog::Instance(); |
| 100 | MIuint CMIUtilDebugFnTrace::ms_fnDepthCnt = 0; |
| 101 | |
| 102 | //++ ------------------------------------------------------------------------------------ |
| 103 | // Details: CMIUtilDebugFnTrace constructor. |
| 104 | // Type: Method. |
| 105 | // Args: vFnName - (R) The text to insert into the log. |
| 106 | // Return: None. |
| 107 | // Throws: None. |
| 108 | //-- |
| 109 | CMIUtilDebugFnTrace::CMIUtilDebugFnTrace( const CMIUtilString & vFnName ) |
| 110 | : m_strFnName( vFnName ) |
| 111 | { |
| 112 | const CMIUtilString txt( CMIUtilString::Format( "%d>%s", ++ms_fnDepthCnt, m_strFnName.c_str() ) ); |
| 113 | ms_rLog.Write( txt, CMICmnLog::eLogVerbosity_FnTrace ); |
| 114 | } |
| 115 | |
| 116 | //++ ------------------------------------------------------------------------------------ |
| 117 | // Details: CMIUtilDebugFnTrace destructor. |
| 118 | // Type: Method. |
| 119 | // Args: None. |
| 120 | // Return: None. |
| 121 | // Throws: None. |
| 122 | //-- |
| 123 | CMIUtilDebugFnTrace::~CMIUtilDebugFnTrace( void ) |
| 124 | { |
| 125 | const CMIUtilString txt( CMIUtilString::Format( "%d<%s", ms_fnDepthCnt--, m_strFnName.c_str() ) ); |
| 126 | ms_rLog.Write( txt, CMICmnLog::eLogVerbosity_FnTrace ); |
| 127 | } |
| 128 | |