2014-05-16 18:51:01 +08:00
|
|
|
//===-- MICmnBase.cpp -------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// Third party headers
|
2014-11-18 02:06:21 +08:00
|
|
|
#include <stdarg.h> // va_list, va_start, var_end
|
2014-05-16 18:51:01 +08:00
|
|
|
|
|
|
|
// In-house headers:
|
|
|
|
#include "MICmnBase.h"
|
|
|
|
#include "MICmnLog.h"
|
|
|
|
#include "MICmnStreamStderr.h"
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
//++
|
|
|
|
//------------------------------------------------------------------------------------
|
2014-11-18 02:06:21 +08:00
|
|
|
// Details: CMICmnBase constructor.
|
|
|
|
// Type: Method.
|
|
|
|
// Args: None.
|
|
|
|
// Return: None.
|
|
|
|
// Throws: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2015-08-04 18:24:20 +08:00
|
|
|
CMICmnBase::CMICmnBase()
|
2016-09-07 04:57:50 +08:00
|
|
|
: m_strMILastErrorDescription(CMIUtilString()), m_bInitialized(false),
|
|
|
|
m_pLog(&CMICmnLog::Instance()), m_clientUsageRefCnt(0) {}
|
2014-05-16 18:51:01 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
//++
|
|
|
|
//------------------------------------------------------------------------------------
|
2014-11-18 02:06:21 +08:00
|
|
|
// Details: CMICmnBase destructor.
|
|
|
|
// Type: Overrideable.
|
|
|
|
// Args: None.
|
|
|
|
// Return: None.
|
|
|
|
// Throws: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2016-09-07 04:57:50 +08:00
|
|
|
CMICmnBase::~CMICmnBase() { m_pLog = NULL; }
|
2014-05-16 18:51:01 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
//++
|
|
|
|
//------------------------------------------------------------------------------------
|
2014-11-18 02:06:21 +08:00
|
|
|
// Details: Retrieve whether *this object has an error description set.
|
|
|
|
// Type: Method.
|
|
|
|
// Args: None.
|
2015-07-07 22:04:40 +08:00
|
|
|
// Return: bool - True = Yes already defined, false = empty description.
|
2014-11-18 02:06:21 +08:00
|
|
|
// Throws: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2016-09-07 04:57:50 +08:00
|
|
|
bool CMICmnBase::HaveErrorDescription() const {
|
|
|
|
return m_strMILastErrorDescription.empty();
|
2014-05-16 18:51:01 +08:00
|
|
|
}
|
2014-11-18 02:06:21 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
//++
|
|
|
|
//------------------------------------------------------------------------------------
|
2014-11-18 02:06:21 +08:00
|
|
|
// Details: Retrieve MI's last error condition.
|
|
|
|
// Type: Method.
|
|
|
|
// Args: None.
|
|
|
|
// Return: CMIUtilString & - Text description.
|
|
|
|
// Throws: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2016-09-07 04:57:50 +08:00
|
|
|
const CMIUtilString &CMICmnBase::GetErrorDescription() const {
|
|
|
|
return m_strMILastErrorDescription;
|
2014-05-16 18:51:01 +08:00
|
|
|
}
|
2014-11-18 02:06:21 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
//++
|
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
// Details: Set MI's error condition description. This may be accessed by
|
|
|
|
// clients and
|
|
|
|
// seen by users. Message is available to the client using the server
|
|
|
|
// and sent
|
2014-11-18 02:06:21 +08:00
|
|
|
// to the Logger.
|
|
|
|
// Type: Method.
|
|
|
|
// Args: vrTxt - (R) Text description.
|
|
|
|
// Return: None.
|
|
|
|
// Throws: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2016-09-07 04:57:50 +08:00
|
|
|
void CMICmnBase::SetErrorDescription(const CMIUtilString &vrTxt) const {
|
|
|
|
m_strMILastErrorDescription = vrTxt;
|
|
|
|
if (!vrTxt.empty()) {
|
|
|
|
const CMIUtilString txt(CMIUtilString::Format("Error: %s", vrTxt.c_str()));
|
|
|
|
CMICmnStreamStderr::Instance().Write(txt);
|
|
|
|
}
|
2014-05-16 18:51:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
//++
|
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
// Details: Set MI's error condition description. This may be accessed by
|
|
|
|
// clients and
|
|
|
|
// seen by users. Message is available to the client using the server
|
|
|
|
// and sent
|
2014-11-18 02:06:21 +08:00
|
|
|
// to the Logger.
|
|
|
|
// Type: Method.
|
|
|
|
// Args: vrTxt - (R) Text description.
|
|
|
|
// Return: None.
|
|
|
|
// Throws: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2016-09-07 04:57:50 +08:00
|
|
|
void CMICmnBase::SetErrorDescriptionNoLog(const CMIUtilString &vrTxt) const {
|
|
|
|
m_strMILastErrorDescription = vrTxt;
|
2014-05-16 18:51:01 +08:00
|
|
|
}
|
2014-11-18 02:06:21 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
//++
|
|
|
|
//------------------------------------------------------------------------------------
|
2014-11-18 02:06:21 +08:00
|
|
|
// Details: Clear MI's error condition description.
|
|
|
|
// Type: Method.
|
|
|
|
// Args: None.
|
|
|
|
// Return: None.
|
|
|
|
// Throws: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2016-09-07 04:57:50 +08:00
|
|
|
void CMICmnBase::ClrErrorDescription() const {
|
|
|
|
m_strMILastErrorDescription.clear();
|
2014-05-16 18:51:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
//++
|
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
// Details: Set MI's error condition description. This may be accessed by
|
|
|
|
// clients and
|
|
|
|
// seen by users. Message is available to the client using the server
|
|
|
|
// and sent
|
2014-11-18 02:06:21 +08:00
|
|
|
// to the Logger.
|
|
|
|
// Type: Method.
|
|
|
|
// Args: vFormat - (R) Format string.
|
|
|
|
// ... - (R) Variable number of CMIUtilString type objects.
|
|
|
|
// Return: None.
|
|
|
|
// Throws: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
Do not pass non-POD type variables through variadic function
Summary:
Cannot pass object of non-POD type 'const CMIUtilString' through variadic function.
This behavior is undefined according to C++11 5.2.2/7:
> Passing a potentially-evaluated argument of class type having a non-trivial copy constructor, a non-trivial move contructor, or a non-trivial destructor, with no corresponding parameter, is conditionally-supported with implementation-defined semantics.
Replace SetErrorDescriptionn(errMsg); with SetErrorDescription(errMsg);
Original patch by Tobias Nygren (NetBSD).
Sponsored by <The NetBSD Foundation>
Reviewers: clayborg, labath, emaste, joerg, ki.stfu
Reviewed By: labath, ki.stfu
Subscribers: tnn, ki.stfu, #lldb
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D29256
llvm-svn: 293774
2017-02-02 00:02:55 +08:00
|
|
|
void CMICmnBase::SetErrorDescriptionn(const char *vFormat, ...) const {
|
2016-09-07 04:57:50 +08:00
|
|
|
va_list args;
|
|
|
|
va_start(args, vFormat);
|
|
|
|
CMIUtilString strResult = CMIUtilString::FormatValist(vFormat, args);
|
|
|
|
va_end(args);
|
2014-05-16 18:51:01 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SetErrorDescription(strResult);
|
2014-09-09 14:32:02 +08:00
|
|
|
}
|