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