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 | //++ |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 11 | // File: MIUtilDebug.h |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 12 | // |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 13 | // Overview: Terminal setting termios functions. |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 14 | // |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 15 | // Environment: Compilers: Visual C++ 12. |
| 16 | // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 |
| 17 | // Libraries: See MIReadmetxt. |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 18 | // |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 19 | // Copyright: None. |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 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 | //++ ------------------------------------------------------------------------------------ |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 33 | // Details: CMIUtilDebug constructor. |
| 34 | // Type: Method. |
| 35 | // Args: None. |
| 36 | // Return: None. |
| 37 | // Throws: None. |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 38 | //-- |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 39 | CMIUtilDebug::CMIUtilDebug(void) |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 40 | { |
| 41 | } |
| 42 | |
| 43 | //++ ------------------------------------------------------------------------------------ |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 44 | // Details: CMIUtilDebug destructor. |
| 45 | // Type: 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 | CMIUtilDebug::~CMIUtilDebug(void) |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 51 | { |
| 52 | } |
| 53 | |
| 54 | //++ ------------------------------------------------------------------------------------ |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 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. |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 61 | //-- |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 62 | void |
| 63 | CMIUtilDebug::ShowDlgWaitForDbgAttach(void) |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 64 | { |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 65 | const CMIUtilString strCaption(CMIDriver::Instance().GetAppNameShort()); |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 66 | #ifdef _WIN32 |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 67 | ::MessageBoxA(NULL, "Attach your debugger now", strCaption.c_str(), MB_OK); |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 68 | #else |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 69 | // ToDo: Implement other platform version of an Ok to continue dialog box |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 70 | #endif // _WIN32 |
| 71 | } |
| 72 | |
| 73 | //++ ------------------------------------------------------------------------------------ |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 74 | // Details: Temporarily stall the process/application to give the programmer the |
| 75 | // opportunity to attach a debugger. How to use: Put a break in the programmer |
| 76 | // where you want to visit, run the application then attach your debugger to the |
| 77 | // application. Hit the debugger's pause button and the debugger should should |
| 78 | // show this loop. Change the i variable value to break out of the loop and |
| 79 | // visit your break point. |
| 80 | // Type: Static method. |
| 81 | // Args: None. |
| 82 | // Return: None. |
| 83 | // Throws: None. |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 84 | //-- |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 85 | void |
| 86 | CMIUtilDebug::WaitForDbgAttachInfinteLoop(void) |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 87 | { |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 88 | MIuint i = 0; |
| 89 | while (i == 0) |
| 90 | { |
| 91 | const std::chrono::milliseconds time(100); |
| 92 | std::this_thread::sleep_for(time); |
| 93 | } |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | //--------------------------------------------------------------------------------------- |
| 97 | //--------------------------------------------------------------------------------------- |
| 98 | //--------------------------------------------------------------------------------------- |
| 99 | |
| 100 | // Instantiations: |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 101 | CMICmnLog &CMIUtilDebugFnTrace::ms_rLog = CMICmnLog::Instance(); |
| 102 | MIuint CMIUtilDebugFnTrace::ms_fnDepthCnt = 0; |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 103 | |
| 104 | //++ ------------------------------------------------------------------------------------ |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 105 | // Details: CMIUtilDebugFnTrace constructor. |
| 106 | // Type: Method. |
| 107 | // Args: vFnName - (R) The text to insert into the log. |
| 108 | // Return: None. |
| 109 | // Throws: None. |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 110 | //-- |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 111 | CMIUtilDebugFnTrace::CMIUtilDebugFnTrace(const CMIUtilString &vFnName) |
| 112 | : m_strFnName(vFnName) |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 113 | { |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 114 | const CMIUtilString txt(CMIUtilString::Format("%d>%s", ++ms_fnDepthCnt, m_strFnName.c_str())); |
| 115 | ms_rLog.Write(txt, CMICmnLog::eLogVerbosity_FnTrace); |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | //++ ------------------------------------------------------------------------------------ |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 119 | // Details: CMIUtilDebugFnTrace destructor. |
| 120 | // Type: Method. |
| 121 | // Args: None. |
| 122 | // Return: None. |
| 123 | // Throws: None. |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 124 | //-- |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 125 | CMIUtilDebugFnTrace::~CMIUtilDebugFnTrace(void) |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 126 | { |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 127 | const CMIUtilString txt(CMIUtilString::Format("%d<%s", ms_fnDepthCnt--, m_strFnName.c_str())); |
| 128 | ms_rLog.Write(txt, CMICmnLog::eLogVerbosity_FnTrace); |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 129 | } |