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