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 // Third party headers:
11 #ifdef _WIN32
12 #include <windows.h>
13 #endif
14 
15 // In-house headers:
16 #include "MICmnLog.h"
17 #include "MIDriver.h"
18 #include "MIUtilDebug.h"
19 
20 //++
21 //------------------------------------------------------------------------------------
22 // Details: CMIUtilDebug constructor.
23 // Type:    Method.
24 // Args:    None.
25 // Return:  None.
26 // Throws:  None.
27 //--
CMIUtilDebug()28 CMIUtilDebug::CMIUtilDebug() {}
29 
30 //++
31 //------------------------------------------------------------------------------------
32 // Details: CMIUtilDebug destructor.
33 // Type:    Method.
34 // Args:    None.
35 // Return:  None.
36 // Throws:  None.
37 //--
~CMIUtilDebug()38 CMIUtilDebug::~CMIUtilDebug() {}
39 
40 //++
41 //------------------------------------------------------------------------------------
42 // Details: Temporarily stall the process/application to give the programmer the
43 //          opportunity to attach a debugger. How to use: Put a break in the
44 //          programmer
45 //          where you want to visit, run the application then attach your
46 //          debugger to the
47 //          application. Hit the debugger's pause button and the debugger should
48 //          should
49 //          show this loop. Change the i variable value to break out of the loop
50 //          and
51 //          visit your break point.
52 // Type:    Static method.
53 // Args:    None.
54 // Return:  None.
55 // Throws:  None.
56 //--
WaitForDbgAttachInfinteLoop()57 void CMIUtilDebug::WaitForDbgAttachInfinteLoop() {
58   MIuint i = 0;
59   while (i == 0) {
60     const std::chrono::milliseconds time(100);
61     std::this_thread::sleep_for(time);
62   }
63 }
64 
65 //---------------------------------------------------------------------------------------
66 //---------------------------------------------------------------------------------------
67 //---------------------------------------------------------------------------------------
68 
69 // Instantiations:
70 CMICmnLog &CMIUtilDebugFnTrace::ms_rLog = CMICmnLog::Instance();
71 MIuint CMIUtilDebugFnTrace::ms_fnDepthCnt = 0;
72 
73 //++
74 //------------------------------------------------------------------------------------
75 // Details: CMIUtilDebugFnTrace constructor.
76 // Type:    Method.
77 // Args:    vFnName - (R) The text to insert into the log.
78 // Return:  None.
79 // Throws:  None.
80 //--
CMIUtilDebugFnTrace(const CMIUtilString & vFnName)81 CMIUtilDebugFnTrace::CMIUtilDebugFnTrace(const CMIUtilString &vFnName)
82     : m_strFnName(vFnName) {
83   const CMIUtilString txt(
84       CMIUtilString::Format("%d>%s", ++ms_fnDepthCnt, m_strFnName.c_str()));
85   ms_rLog.Write(txt, CMICmnLog::eLogVerbosity_FnTrace);
86 }
87 
88 //++
89 //------------------------------------------------------------------------------------
90 // Details: CMIUtilDebugFnTrace destructor.
91 // Type:    Method.
92 // Args:    None.
93 // Return:  None.
94 // Throws:  None.
95 //--
~CMIUtilDebugFnTrace()96 CMIUtilDebugFnTrace::~CMIUtilDebugFnTrace() {
97   const CMIUtilString txt(
98       CMIUtilString::Format("%d<%s", ms_fnDepthCnt--, m_strFnName.c_str()));
99   ms_rLog.Write(txt, CMICmnLog::eLogVerbosity_FnTrace);
100 }
101