blob: c78506221b44777b4039e827a2cb13945c6db0ef [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
10//++
Zachary Turner1d6af022014-11-17 18:06:21 +000011// File: MIUtilDebug.h
Deepak Panickal6f9c4682014-05-16 10:51:01 +000012//
Zachary Turner1d6af022014-11-17 18:06:21 +000013// Overview: Terminal setting termios functions.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000014//
Zachary Turner1d6af022014-11-17 18:06:21 +000015// Environment: Compilers: Visual C++ 12.
16// gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17// Libraries: See MIReadmetxt.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000018//
Zachary Turner1d6af022014-11-17 18:06:21 +000019// Copyright: None.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000020//--
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 Turner1d6af022014-11-17 18:06:21 +000033// Details: CMIUtilDebug constructor.
34// Type: Method.
35// Args: None.
36// Return: None.
37// Throws: None.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000038//--
Zachary Turner1d6af022014-11-17 18:06:21 +000039CMIUtilDebug::CMIUtilDebug(void)
Deepak Panickal6f9c4682014-05-16 10:51:01 +000040{
41}
42
43//++ ------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +000044// Details: CMIUtilDebug destructor.
45// Type: 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 +000050CMIUtilDebug::~CMIUtilDebug(void)
Deepak Panickal6f9c4682014-05-16 10:51:01 +000051{
52}
53
54//++ ------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +000055// 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 Panickal6f9c4682014-05-16 10:51:01 +000061//--
Zachary Turner1d6af022014-11-17 18:06:21 +000062void
63CMIUtilDebug::ShowDlgWaitForDbgAttach(void)
Deepak Panickal6f9c4682014-05-16 10:51:01 +000064{
Zachary Turner1d6af022014-11-17 18:06:21 +000065 const CMIUtilString strCaption(CMIDriver::Instance().GetAppNameShort());
Deepak Panickal6f9c4682014-05-16 10:51:01 +000066#ifdef _WIN32
Zachary Turner1d6af022014-11-17 18:06:21 +000067 ::MessageBoxA(NULL, "Attach your debugger now", strCaption.c_str(), MB_OK);
Deepak Panickal6f9c4682014-05-16 10:51:01 +000068#else
Zachary Turner1d6af022014-11-17 18:06:21 +000069// ToDo: Implement other platform version of an Ok to continue dialog box
Deepak Panickal6f9c4682014-05-16 10:51:01 +000070#endif // _WIN32
71}
72
73//++ ------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +000074// 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 Panickal6f9c4682014-05-16 10:51:01 +000084//--
Zachary Turner1d6af022014-11-17 18:06:21 +000085void
86CMIUtilDebug::WaitForDbgAttachInfinteLoop(void)
Deepak Panickal6f9c4682014-05-16 10:51:01 +000087{
Zachary Turner1d6af022014-11-17 18:06:21 +000088 MIuint i = 0;
89 while (i == 0)
90 {
91 const std::chrono::milliseconds time(100);
92 std::this_thread::sleep_for(time);
93 }
Deepak Panickal6f9c4682014-05-16 10:51:01 +000094}
95
96//---------------------------------------------------------------------------------------
97//---------------------------------------------------------------------------------------
98//---------------------------------------------------------------------------------------
99
100// Instantiations:
Zachary Turner1d6af022014-11-17 18:06:21 +0000101CMICmnLog &CMIUtilDebugFnTrace::ms_rLog = CMICmnLog::Instance();
102MIuint CMIUtilDebugFnTrace::ms_fnDepthCnt = 0;
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000103
104//++ ------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +0000105// Details: CMIUtilDebugFnTrace constructor.
106// Type: Method.
107// Args: vFnName - (R) The text to insert into the log.
108// Return: None.
109// Throws: None.
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000110//--
Zachary Turner1d6af022014-11-17 18:06:21 +0000111CMIUtilDebugFnTrace::CMIUtilDebugFnTrace(const CMIUtilString &vFnName)
112 : m_strFnName(vFnName)
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000113{
Zachary Turner1d6af022014-11-17 18:06:21 +0000114 const CMIUtilString txt(CMIUtilString::Format("%d>%s", ++ms_fnDepthCnt, m_strFnName.c_str()));
115 ms_rLog.Write(txt, CMICmnLog::eLogVerbosity_FnTrace);
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000116}
117
118//++ ------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +0000119// Details: CMIUtilDebugFnTrace destructor.
120// Type: Method.
121// Args: None.
122// Return: None.
123// Throws: None.
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000124//--
Zachary Turner1d6af022014-11-17 18:06:21 +0000125CMIUtilDebugFnTrace::~CMIUtilDebugFnTrace(void)
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000126{
Zachary Turner1d6af022014-11-17 18:06:21 +0000127 const CMIUtilString txt(CMIUtilString::Format("%d<%s", ms_fnDepthCnt--, m_strFnName.c_str()));
128 ms_rLog.Write(txt, CMICmnLog::eLogVerbosity_FnTrace);
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000129}