]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/lldb-mi/MIUtilDebug.cpp
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / tools / lldb-mi / MIUtilDebug.cpp
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 //--
28 CMIUtilDebug::CMIUtilDebug() {}
29
30 //++
31 //------------------------------------------------------------------------------------
32 // Details: CMIUtilDebug destructor.
33 // Type:    Method.
34 // Args:    None.
35 // Return:  None.
36 // Throws:  None.
37 //--
38 CMIUtilDebug::~CMIUtilDebug() {}
39
40 //++
41 //------------------------------------------------------------------------------------
42 // Details: Show a dialog to the process/application halts. It gives the
43 // opportunity to
44 //          attach a debugger.
45 // Type:    Static method.
46 // Args:    None.
47 // Return:  None.
48 // Throws:  None.
49 //--
50 void CMIUtilDebug::ShowDlgWaitForDbgAttach() {
51   const CMIUtilString strCaption(CMIDriver::Instance().GetAppNameShort());
52 #ifdef _WIN32
53   ::MessageBoxA(NULL, "Attach your debugger now", strCaption.c_str(), MB_OK);
54 #else
55 // ToDo: Implement other platform version of an Ok to continue dialog box
56 #endif // _WIN32
57 }
58
59 //++
60 //------------------------------------------------------------------------------------
61 // Details: Temporarily stall the process/application to give the programmer the
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
70 //          visit your break point.
71 // Type:    Static method.
72 // Args:    None.
73 // Return:  None.
74 // Throws:  None.
75 //--
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   }
82 }
83
84 //---------------------------------------------------------------------------------------
85 //---------------------------------------------------------------------------------------
86 //---------------------------------------------------------------------------------------
87
88 // Instantiations:
89 CMICmnLog &CMIUtilDebugFnTrace::ms_rLog = CMICmnLog::Instance();
90 MIuint CMIUtilDebugFnTrace::ms_fnDepthCnt = 0;
91
92 //++
93 //------------------------------------------------------------------------------------
94 // Details: CMIUtilDebugFnTrace constructor.
95 // Type:    Method.
96 // Args:    vFnName - (R) The text to insert into the log.
97 // Return:  None.
98 // Throws:  None.
99 //--
100 CMIUtilDebugFnTrace::CMIUtilDebugFnTrace(const CMIUtilString &vFnName)
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);
105 }
106
107 //++
108 //------------------------------------------------------------------------------------
109 // Details: CMIUtilDebugFnTrace destructor.
110 // Type:    Method.
111 // Args:    None.
112 // Return:  None.
113 // Throws:  None.
114 //--
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);
119 }