2014-05-16 18:51:01 +08:00
|
|
|
//===-- MICmdBase.cpp -------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// In-house headers:
|
|
|
|
#include "MICmdBase.h"
|
2015-11-02 19:43:40 +08:00
|
|
|
#include "MICmdArgValConsume.h"
|
2016-09-07 04:57:50 +08:00
|
|
|
#include "MICmdArgValOptionLong.h"
|
|
|
|
#include "MICmnLLDBDebugSessionInfo.h"
|
|
|
|
#include "MICmnMIValueConst.h"
|
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: CMICmdBase 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
|
|
|
CMICmdBase::CMICmdBase()
|
2016-09-07 04:57:50 +08:00
|
|
|
: m_pSelfCreatorFn(nullptr),
|
|
|
|
m_rLLDBDebugSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()),
|
|
|
|
m_bHasResultRecordExtra(false), m_constStrArgThreadGroup("thread-group"),
|
|
|
|
m_constStrArgThread("thread"), m_constStrArgFrame("frame"),
|
|
|
|
m_constStrArgConsume("--"), m_ThreadGrpArgMandatory(false),
|
|
|
|
m_ThreadArgMandatory(false), m_FrameArgMandatory(false) {}
|
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: CMICmdBase 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
|
|
|
CMICmdBase::~CMICmdBase() {}
|
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: The invoker requires this function.
|
|
|
|
// Type: Overridden.
|
|
|
|
// Args: None.
|
|
|
|
// Return: SMICmdData & - *this command's present status/data/information.
|
|
|
|
// Throws: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2016-09-07 04:57:50 +08:00
|
|
|
const SMICmdData &CMICmdBase::GetCmdData() const { return m_cmdData; }
|
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: The invoker requires this function.
|
|
|
|
// Type: Overridden.
|
|
|
|
// Args: None.
|
|
|
|
// Return: CMIUtilString & - *this command's current error description.
|
|
|
|
// Empty string indicates command status ok.
|
|
|
|
// Throws: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2016-09-07 04:57:50 +08:00
|
|
|
const CMIUtilString &CMICmdBase::GetErrorDescription() const {
|
|
|
|
return m_strCurrentErrDescription;
|
2014-05-16 18:51:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
//++
|
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
// Details: The CMICmdFactory requires this function. Retrieve the command and
|
|
|
|
// argument
|
2014-11-18 02:06:21 +08:00
|
|
|
// options description string.
|
|
|
|
// Type: Overridden.
|
|
|
|
// Args: None.
|
2015-07-07 22:04:40 +08:00
|
|
|
// Return: CMIUtilString & - Command 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
|
|
|
const CMIUtilString &CMICmdBase::GetMiCmd() const { return m_strMiCmd; }
|
2014-05-16 18:51:01 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
//++
|
|
|
|
//------------------------------------------------------------------------------------
|
2015-10-30 00:30:47 +08:00
|
|
|
// Details: Help parse the arguments that are common to all commands.
|
|
|
|
// Args: None.
|
|
|
|
// Return: None
|
|
|
|
// Throws: None.
|
|
|
|
//--
|
2016-09-07 04:57:50 +08:00
|
|
|
void CMICmdBase::AddCommonArgs() {
|
|
|
|
m_setCmdArgs.Add(new CMICmdArgValOptionLong(
|
|
|
|
m_constStrArgThreadGroup, m_ThreadGrpArgMandatory, true,
|
|
|
|
CMICmdArgValListBase::eArgValType_ThreadGrp, 1));
|
|
|
|
m_setCmdArgs.Add(new CMICmdArgValOptionLong(
|
|
|
|
m_constStrArgThread, m_ThreadArgMandatory, true,
|
|
|
|
CMICmdArgValListBase::eArgValType_Number, 1));
|
|
|
|
m_setCmdArgs.Add(
|
|
|
|
new CMICmdArgValOptionLong(m_constStrArgFrame, m_FrameArgMandatory, true,
|
|
|
|
CMICmdArgValListBase::eArgValType_Number, 1));
|
|
|
|
m_setCmdArgs.Add(new CMICmdArgValConsume(m_constStrArgConsume, false));
|
2015-10-30 00:30:47 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
//++
|
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
// Details: The invoker requires this function. A command must be given working
|
|
|
|
// data and
|
|
|
|
// provide data about its status or provide information to other
|
|
|
|
// objects.
|
2014-11-18 02:06:21 +08:00
|
|
|
// Type: Overridden.
|
|
|
|
// Args: None.
|
2015-07-23 01:07:27 +08:00
|
|
|
// Return: None.
|
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
|
|
|
void CMICmdBase::SetCmdData(const SMICmdData &vCmdData) {
|
|
|
|
m_cmdData = vCmdData;
|
2014-05-16 18:51:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
//++
|
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
// Details: The command factory requires this function. The factory calls this
|
|
|
|
// function
|
2014-11-18 02:06:21 +08:00
|
|
|
// so it can obtain *this command's creation function.
|
|
|
|
// Type: Overridden.
|
|
|
|
// Args: None.
|
|
|
|
// Return: CMICmdFactory::CmdCreatorFnPtr - Function pointer.
|
|
|
|
// Throws: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2016-09-07 04:57:50 +08:00
|
|
|
CMICmdFactory::CmdCreatorFnPtr CMICmdBase::GetCmdCreatorFn() const {
|
|
|
|
return m_pSelfCreatorFn;
|
2014-05-16 18:51:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
//++
|
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
// Details: If a command is an event type (has callbacks registered with
|
|
|
|
// SBListener) it
|
|
|
|
// needs to inform the Invoker that it has finished its work so that
|
|
|
|
// the
|
|
|
|
// Invoker can tidy up and call the commands Acknowledge function (yes
|
|
|
|
// the
|
|
|
|
// command itself could call the Acknowledge itself but not doing that
|
|
|
|
// way).
|
2014-11-18 02:06:21 +08:00
|
|
|
// Type: Overridden.
|
|
|
|
// Args: None.
|
|
|
|
// Return: None.
|
|
|
|
// Throws: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2016-09-07 04:57:50 +08:00
|
|
|
void CMICmdBase::CmdFinishedTellInvoker() const {
|
|
|
|
CMICmdInvoker::Instance().CmdExecuteFinished(const_cast<CMICmdBase &>(*this));
|
2014-05-16 18:51:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
//++
|
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
// Details: Returns the final version of the MI result record built up in the
|
|
|
|
// command's
|
2014-11-18 02:06:21 +08:00
|
|
|
// Acknowledge function. The one line text of MI result.
|
|
|
|
// Type: Overridden.
|
|
|
|
// Args: None.
|
|
|
|
// Return: CMIUtilString & - MI text version of the MI result record.
|
|
|
|
// Throws: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2016-09-07 04:57:50 +08:00
|
|
|
const CMIUtilString &CMICmdBase::GetMIResultRecord() const {
|
|
|
|
return m_miResultRecord.GetString();
|
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: Retrieve from the command additional MI result to its 1 line
|
|
|
|
// response.
|
|
|
|
// Because of using LLDB additional 'fake'/hack output is sometimes
|
|
|
|
// required to
|
2014-11-18 02:06:21 +08:00
|
|
|
// help the driver client operate i.e. Eclipse.
|
|
|
|
// Type: Overridden.
|
|
|
|
// Args: None.
|
|
|
|
// Return: CMIUtilString & - MI text version of the MI result record.
|
|
|
|
// Throws: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2016-09-07 04:57:50 +08:00
|
|
|
const CMIUtilString &CMICmdBase::GetMIResultRecordExtra() const {
|
|
|
|
return m_miResultRecordExtra;
|
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: Hss *this command got additional MI result to its 1 line response.
|
2016-09-07 04:57:50 +08:00
|
|
|
// Because of using LLDB additional 'fake'/hack output is sometimes
|
|
|
|
// required to
|
2014-11-18 02:06:21 +08:00
|
|
|
// help the driver client operate i.e. Eclipse.
|
|
|
|
// Type: Overridden.
|
|
|
|
// Args: None.
|
2016-09-07 04:57:50 +08:00
|
|
|
// Return: bool - True = Yes have additional MI output, false = no nothing
|
|
|
|
// extra.
|
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 CMICmdBase::HasMIResultRecordExtra() const {
|
|
|
|
return m_bHasResultRecordExtra;
|
2014-05-16 18:51:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
//++
|
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
// Details: Short cut function to enter error information into the command's
|
|
|
|
// metadata
|
2014-11-18 02:06:21 +08:00
|
|
|
// object and set the command's error status.
|
|
|
|
// Type: Method.
|
2017-05-12 12:51:55 +08:00
|
|
|
// Args: rErrMsg - (R) Status description.
|
2014-11-18 02:06:21 +08:00
|
|
|
// Return: None.
|
|
|
|
// Throws: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2016-09-07 04:57:50 +08:00
|
|
|
void CMICmdBase::SetError(const CMIUtilString &rErrMsg) {
|
|
|
|
m_cmdData.bCmdValid = false;
|
|
|
|
m_cmdData.strErrorDescription = rErrMsg;
|
|
|
|
m_cmdData.bCmdExecutedSuccessfully = false;
|
2014-11-18 02:06:21 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const CMICmnMIValueResult valueResult("msg", CMICmnMIValueConst(rErrMsg));
|
|
|
|
const CMICmnMIResultRecord miResultRecord(
|
|
|
|
m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error,
|
|
|
|
valueResult);
|
|
|
|
m_miResultRecord = miResultRecord;
|
|
|
|
m_cmdData.strMiCmdResultRecord = miResultRecord.GetString();
|
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: Ask a command to provide its unique identifier.
|
|
|
|
// Type: Method.
|
|
|
|
// Args: A unique identifier for this command class.
|
|
|
|
// Return: None.
|
|
|
|
// Throws: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2016-09-07 04:57:50 +08:00
|
|
|
MIuint CMICmdBase::GetGUID() {
|
|
|
|
MIuint64 vptr = reinterpret_cast<MIuint64>(this);
|
|
|
|
MIuint id = (vptr)&0xFFFFFFFF;
|
|
|
|
id ^= (vptr >> 32) & 0xFFFFFFFF;
|
2014-05-16 18:51:01 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return id;
|
2014-05-16 18:51:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
//++
|
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
// Details: The invoker requires this function. The parses the command line
|
|
|
|
// options
|
2014-11-18 02:06:21 +08:00
|
|
|
// arguments to extract values for each of those arguments.
|
|
|
|
// Type: Overridden.
|
|
|
|
// Args: None.
|
|
|
|
// Return: MIstatus::success - Functional succeeded.
|
|
|
|
// MIstatus::failure - Functional failed.
|
|
|
|
// Throws: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2016-09-07 04:57:50 +08:00
|
|
|
bool CMICmdBase::ParseArgs() {
|
|
|
|
// Do nothing - override to implement
|
2014-05-16 18:51:01 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return MIstatus::success;
|
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: Having previously given CMICmdArgSet m_setCmdArgs all the argument
|
|
|
|
// or option
|
|
|
|
// definitions for the command to handle proceed to parse and validate
|
|
|
|
// the
|
|
|
|
// command's options text for those arguments and extract the values
|
|
|
|
// for each if
|
2014-11-18 02:06:21 +08:00
|
|
|
// any.
|
|
|
|
// Type: Method.
|
|
|
|
// Args: None.
|
|
|
|
// Return: MIstatus::success - Functional succeeded.
|
|
|
|
// MIstatus::failure - Functional failed.
|
|
|
|
// Throws: None.
|
2014-08-09 00:47:42 +08:00
|
|
|
//--
|
2016-09-07 04:57:50 +08:00
|
|
|
bool CMICmdBase::ParseValidateCmdOptions() {
|
|
|
|
CMICmdArgContext argCntxt(m_cmdData.strMiCmdOption);
|
|
|
|
if (m_setCmdArgs.Validate(m_cmdData.strMiCmd, argCntxt))
|
|
|
|
return MIstatus::success;
|
2014-11-18 02:06:21 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_ARGS),
|
|
|
|
m_cmdData.strMiCmd.c_str(),
|
|
|
|
m_setCmdArgs.GetErrorDescription().c_str()));
|
2014-08-09 00:47:42 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return MIstatus::failure;
|
2014-08-09 00:47:42 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
//++
|
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
// Details: If the MI Driver is not operating via a client i.e. Eclipse but say
|
|
|
|
// operating
|
|
|
|
// on a executable passed in as a argument to the drive then what
|
|
|
|
// should the driver
|
|
|
|
// do on a command failing? Either continue operating or exit the
|
|
|
|
// application.
|
|
|
|
// Override this function where a command failure cannot allow the
|
|
|
|
// driver to
|
2014-11-18 02:06:21 +08:00
|
|
|
// continue operating.
|
|
|
|
// Type: Overrideable.
|
|
|
|
// Args: None.
|
2016-09-07 04:57:50 +08:00
|
|
|
// Return: bool - True = Fatal if command fails, false = can continue if
|
|
|
|
// command fails.
|
2014-11-18 02:06:21 +08:00
|
|
|
// Throws: None.
|
2014-08-09 00:47:42 +08:00
|
|
|
//--
|
2016-09-07 04:57:50 +08:00
|
|
|
bool CMICmdBase::GetExitAppOnCommandFailure() const { return false; }
|