2014-05-16 18:51:01 +08:00
|
|
|
//===-- MIUtilDebug.cpp -----------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
//++
|
2014-11-18 02:06:21 +08:00
|
|
|
// File: MIUtilDebug.h
|
2014-05-16 18:51:01 +08:00
|
|
|
//
|
2014-11-18 02:06:21 +08:00
|
|
|
// Overview: Terminal setting termios functions.
|
2014-05-16 18:51:01 +08:00
|
|
|
//
|
2014-11-18 02:06:21 +08:00
|
|
|
// Environment: Compilers: Visual C++ 12.
|
|
|
|
// gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
|
|
|
|
// Libraries: See MIReadmetxt.
|
2014-05-16 18:51:01 +08:00
|
|
|
//
|
2014-11-18 02:06:21 +08:00
|
|
|
// Copyright: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
|
|
|
|
|
|
|
// Third party headers:
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include <Windows.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// In-house headers:
|
|
|
|
#include "MIUtilDebug.h"
|
|
|
|
#include "MIDriver.h"
|
|
|
|
#include "MICmnLog.h"
|
|
|
|
|
|
|
|
//++ ------------------------------------------------------------------------------------
|
2014-11-18 02:06:21 +08:00
|
|
|
// Details: CMIUtilDebug constructor.
|
|
|
|
// Type: Method.
|
|
|
|
// Args: None.
|
|
|
|
// Return: None.
|
|
|
|
// Throws: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2014-11-18 02:06:21 +08:00
|
|
|
CMIUtilDebug::CMIUtilDebug(void)
|
2014-05-16 18:51:01 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//++ ------------------------------------------------------------------------------------
|
2014-11-18 02:06:21 +08:00
|
|
|
// Details: CMIUtilDebug destructor.
|
|
|
|
// Type: Method.
|
|
|
|
// Args: None.
|
|
|
|
// Return: None.
|
|
|
|
// Throws: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2014-11-18 02:06:21 +08:00
|
|
|
CMIUtilDebug::~CMIUtilDebug(void)
|
2014-05-16 18:51:01 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//++ ------------------------------------------------------------------------------------
|
2014-11-18 02:06:21 +08:00
|
|
|
// Details: Show a dialog to the process/application halts. It gives the opportunity to
|
|
|
|
// attach a debugger.
|
|
|
|
// Type: Static method.
|
|
|
|
// Args: None.
|
|
|
|
// Return: None.
|
|
|
|
// Throws: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2014-11-18 02:06:21 +08:00
|
|
|
void
|
|
|
|
CMIUtilDebug::ShowDlgWaitForDbgAttach(void)
|
2014-05-16 18:51:01 +08:00
|
|
|
{
|
2014-11-18 02:06:21 +08:00
|
|
|
const CMIUtilString strCaption(CMIDriver::Instance().GetAppNameShort());
|
2014-05-16 18:51:01 +08:00
|
|
|
#ifdef _WIN32
|
2014-11-18 02:06:21 +08:00
|
|
|
::MessageBoxA(NULL, "Attach your debugger now", strCaption.c_str(), MB_OK);
|
2014-05-16 18:51:01 +08:00
|
|
|
#else
|
2014-11-18 02:06:21 +08:00
|
|
|
// ToDo: Implement other platform version of an Ok to continue dialog box
|
2014-05-16 18:51:01 +08:00
|
|
|
#endif // _WIN32
|
|
|
|
}
|
|
|
|
|
|
|
|
//++ ------------------------------------------------------------------------------------
|
2014-11-18 02:06:21 +08:00
|
|
|
// Details: Temporarily stall the process/application to give the programmer the
|
|
|
|
// opportunity to attach a debugger. How to use: Put a break in the programmer
|
|
|
|
// where you want to visit, run the application then attach your debugger to the
|
|
|
|
// application. Hit the debugger's pause button and the debugger should should
|
|
|
|
// show this loop. Change the i variable value to break out of the loop and
|
|
|
|
// visit your break point.
|
|
|
|
// Type: Static method.
|
|
|
|
// Args: None.
|
|
|
|
// Return: None.
|
|
|
|
// Throws: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2014-11-18 02:06:21 +08:00
|
|
|
void
|
|
|
|
CMIUtilDebug::WaitForDbgAttachInfinteLoop(void)
|
2014-05-16 18:51:01 +08:00
|
|
|
{
|
2014-11-18 02:06:21 +08:00
|
|
|
MIuint i = 0;
|
|
|
|
while (i == 0)
|
|
|
|
{
|
|
|
|
const std::chrono::milliseconds time(100);
|
|
|
|
std::this_thread::sleep_for(time);
|
|
|
|
}
|
2014-05-16 18:51:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------
|
|
|
|
//---------------------------------------------------------------------------------------
|
|
|
|
//---------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Instantiations:
|
2014-11-18 02:06:21 +08:00
|
|
|
CMICmnLog &CMIUtilDebugFnTrace::ms_rLog = CMICmnLog::Instance();
|
|
|
|
MIuint CMIUtilDebugFnTrace::ms_fnDepthCnt = 0;
|
2014-05-16 18:51:01 +08:00
|
|
|
|
|
|
|
//++ ------------------------------------------------------------------------------------
|
2014-11-18 02:06:21 +08:00
|
|
|
// Details: CMIUtilDebugFnTrace constructor.
|
|
|
|
// Type: Method.
|
|
|
|
// Args: vFnName - (R) The text to insert into the log.
|
|
|
|
// Return: None.
|
|
|
|
// Throws: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2014-11-18 02:06:21 +08:00
|
|
|
CMIUtilDebugFnTrace::CMIUtilDebugFnTrace(const CMIUtilString &vFnName)
|
|
|
|
: m_strFnName(vFnName)
|
2014-05-16 18:51:01 +08:00
|
|
|
{
|
2014-11-18 02:06:21 +08:00
|
|
|
const CMIUtilString txt(CMIUtilString::Format("%d>%s", ++ms_fnDepthCnt, m_strFnName.c_str()));
|
|
|
|
ms_rLog.Write(txt, CMICmnLog::eLogVerbosity_FnTrace);
|
2014-05-16 18:51:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//++ ------------------------------------------------------------------------------------
|
2014-11-18 02:06:21 +08:00
|
|
|
// Details: CMIUtilDebugFnTrace destructor.
|
|
|
|
// Type: Method.
|
|
|
|
// Args: None.
|
|
|
|
// Return: None.
|
|
|
|
// Throws: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2014-11-18 02:06:21 +08:00
|
|
|
CMIUtilDebugFnTrace::~CMIUtilDebugFnTrace(void)
|
2014-05-16 18:51:01 +08:00
|
|
|
{
|
2014-11-18 02:06:21 +08:00
|
|
|
const CMIUtilString txt(CMIUtilString::Format("%d<%s", ms_fnDepthCnt--, m_strFnName.c_str()));
|
|
|
|
ms_rLog.Write(txt, CMICmnLog::eLogVerbosity_FnTrace);
|
2014-05-16 18:51:01 +08:00
|
|
|
}
|