blob: f7d461bfcd28facc16924ed6c71ed4285ee8b000 [file] [log] [blame]
Deepak Panickal6f9c4682014-05-16 10:51:01 +00001//===-- 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 Panickal6f9c4682014-05-16 10:51:01 +000010// 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 Turner1d6af022014-11-17 18:06:21 +000021// Details: CMIUtilDebug constructor.
22// Type: Method.
23// Args: None.
24// Return: None.
25// Throws: None.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000026//--
Zachary Turner1d6af022014-11-17 18:06:21 +000027CMIUtilDebug::CMIUtilDebug(void)
Deepak Panickal6f9c4682014-05-16 10:51:01 +000028{
29}
30
31//++ ------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +000032// Details: CMIUtilDebug destructor.
33// Type: Method.
34// Args: None.
35// Return: None.
36// Throws: None.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000037//--
Zachary Turner1d6af022014-11-17 18:06:21 +000038CMIUtilDebug::~CMIUtilDebug(void)
Deepak Panickal6f9c4682014-05-16 10:51:01 +000039{
40}
41
42//++ ------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +000043// 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 Panickal6f9c4682014-05-16 10:51:01 +000049//--
Zachary Turner1d6af022014-11-17 18:06:21 +000050void
51CMIUtilDebug::ShowDlgWaitForDbgAttach(void)
Deepak Panickal6f9c4682014-05-16 10:51:01 +000052{
Zachary Turner1d6af022014-11-17 18:06:21 +000053 const CMIUtilString strCaption(CMIDriver::Instance().GetAppNameShort());
Deepak Panickal6f9c4682014-05-16 10:51:01 +000054#ifdef _WIN32
Zachary Turner1d6af022014-11-17 18:06:21 +000055 ::MessageBoxA(NULL, "Attach your debugger now", strCaption.c_str(), MB_OK);
Deepak Panickal6f9c4682014-05-16 10:51:01 +000056#else
Zachary Turner1d6af022014-11-17 18:06:21 +000057// ToDo: Implement other platform version of an Ok to continue dialog box
Deepak Panickal6f9c4682014-05-16 10:51:01 +000058#endif // _WIN32
59}
60
61//++ ------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +000062// 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 Panickal6f9c4682014-05-16 10:51:01 +000072//--
Zachary Turner1d6af022014-11-17 18:06:21 +000073void
74CMIUtilDebug::WaitForDbgAttachInfinteLoop(void)
Deepak Panickal6f9c4682014-05-16 10:51:01 +000075{
Zachary Turner1d6af022014-11-17 18:06:21 +000076 MIuint i = 0;
77 while (i == 0)
78 {
79 const std::chrono::milliseconds time(100);
80 std::this_thread::sleep_for(time);
81 }
Deepak Panickal6f9c4682014-05-16 10:51:01 +000082}
83
84//---------------------------------------------------------------------------------------
85//---------------------------------------------------------------------------------------
86//---------------------------------------------------------------------------------------
87
88// Instantiations:
Zachary Turner1d6af022014-11-17 18:06:21 +000089CMICmnLog &CMIUtilDebugFnTrace::ms_rLog = CMICmnLog::Instance();
90MIuint CMIUtilDebugFnTrace::ms_fnDepthCnt = 0;
Deepak Panickal6f9c4682014-05-16 10:51:01 +000091
92//++ ------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +000093// Details: CMIUtilDebugFnTrace constructor.
94// Type: Method.
95// Args: vFnName - (R) The text to insert into the log.
96// Return: None.
97// Throws: None.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000098//--
Zachary Turner1d6af022014-11-17 18:06:21 +000099CMIUtilDebugFnTrace::CMIUtilDebugFnTrace(const CMIUtilString &vFnName)
100 : m_strFnName(vFnName)
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000101{
Zachary Turner1d6af022014-11-17 18:06:21 +0000102 const CMIUtilString txt(CMIUtilString::Format("%d>%s", ++ms_fnDepthCnt, m_strFnName.c_str()));
103 ms_rLog.Write(txt, CMICmnLog::eLogVerbosity_FnTrace);
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000104}
105
106//++ ------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +0000107// Details: CMIUtilDebugFnTrace destructor.
108// Type: Method.
109// Args: None.
110// Return: None.
111// Throws: None.
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000112//--
Zachary Turner1d6af022014-11-17 18:06:21 +0000113CMIUtilDebugFnTrace::~CMIUtilDebugFnTrace(void)
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000114{
Zachary Turner1d6af022014-11-17 18:06:21 +0000115 const CMIUtilString txt(CMIUtilString::Format("%d<%s", ms_fnDepthCnt--, m_strFnName.c_str()));
116 ms_rLog.Write(txt, CMICmnLog::eLogVerbosity_FnTrace);
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000117}