blob: 519fd950feb25e46042e27b929f12eaba9f53507 [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
Hafiz Abid Qadeerf6ee79c2016-12-15 15:00:41 +000012#include <windows.h>
Deepak Panickal6f9c4682014-05-16 10:51:01 +000013#endif
14
15// In-house headers:
Deepak Panickal6f9c4682014-05-16 10:51:01 +000016#include "MICmnLog.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000017#include "MIDriver.h"
18#include "MIUtilDebug.h"
Deepak Panickal6f9c4682014-05-16 10:51:01 +000019
Kate Stoneb9c1b512016-09-06 20:57:50 +000020//++
21//------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +000022// Details: CMIUtilDebug constructor.
23// Type: Method.
24// Args: None.
25// Return: None.
26// Throws: None.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000027//--
Kate Stoneb9c1b512016-09-06 20:57:50 +000028CMIUtilDebug::CMIUtilDebug() {}
Deepak Panickal6f9c4682014-05-16 10:51:01 +000029
Kate Stoneb9c1b512016-09-06 20:57:50 +000030//++
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//--
Kate Stoneb9c1b512016-09-06 20:57:50 +000038CMIUtilDebug::~CMIUtilDebug() {}
Deepak Panickal6f9c4682014-05-16 10:51:01 +000039
Kate Stoneb9c1b512016-09-06 20:57:50 +000040//++
41//------------------------------------------------------------------------------------
42// Details: Show a dialog to the process/application halts. It gives the
43// opportunity to
Zachary Turner1d6af022014-11-17 18:06:21 +000044// attach a debugger.
45// Type: Static method.
46// Args: None.
47// Return: None.
48// Throws: None.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000049//--
Kate Stoneb9c1b512016-09-06 20:57:50 +000050void CMIUtilDebug::ShowDlgWaitForDbgAttach() {
51 const CMIUtilString strCaption(CMIDriver::Instance().GetAppNameShort());
Deepak Panickal6f9c4682014-05-16 10:51:01 +000052#ifdef _WIN32
Kate Stoneb9c1b512016-09-06 20:57:50 +000053 ::MessageBoxA(NULL, "Attach your debugger now", strCaption.c_str(), MB_OK);
Deepak Panickal6f9c4682014-05-16 10:51:01 +000054#else
Zachary Turner1d6af022014-11-17 18:06:21 +000055// ToDo: Implement other platform version of an Ok to continue dialog box
Deepak Panickal6f9c4682014-05-16 10:51:01 +000056#endif // _WIN32
57}
58
Kate Stoneb9c1b512016-09-06 20:57:50 +000059//++
60//------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +000061// Details: Temporarily stall the process/application to give the programmer the
Kate Stoneb9c1b512016-09-06 20:57:50 +000062// 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 Turner1d6af022014-11-17 18:06:21 +000070// visit your break point.
71// Type: Static method.
72// Args: None.
73// Return: None.
74// Throws: None.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000075//--
Kate Stoneb9c1b512016-09-06 20:57:50 +000076void 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 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
Kate Stoneb9c1b512016-09-06 20:57:50 +000092//++
93//------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +000094// Details: CMIUtilDebugFnTrace constructor.
95// Type: Method.
96// Args: vFnName - (R) The text to insert into the log.
97// Return: None.
98// Throws: None.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000099//--
Zachary Turner1d6af022014-11-17 18:06:21 +0000100CMIUtilDebugFnTrace::CMIUtilDebugFnTrace(const CMIUtilString &vFnName)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000101 : 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 Panickal6f9c4682014-05-16 10:51:01 +0000105}
106
Kate Stoneb9c1b512016-09-06 20:57:50 +0000107//++
108//------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +0000109// Details: CMIUtilDebugFnTrace destructor.
110// Type: Method.
111// Args: None.
112// Return: None.
113// Throws: None.
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000114//--
Kate Stoneb9c1b512016-09-06 20:57:50 +0000115CMIUtilDebugFnTrace::~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 Panickal6f9c4682014-05-16 10:51:01 +0000119}