1 //===-- MICmdCmdExec.cpp ----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Overview: CMICmdCmdExecRun implementation.
11 // CMICmdCmdExecContinue implementation.
12 // CMICmdCmdExecNext implementation.
13 // CMICmdCmdExecStep implementation.
14 // CMICmdCmdExecNextInstruction implementation.
15 // CMICmdCmdExecStepInstruction implementation.
16 // CMICmdCmdExecFinish implementation.
17 // CMICmdCmdExecInterrupt implementation.
18 // CMICmdCmdExecArguments implementation.
19 // CMICmdCmdExecAbort implementation.
21 // Third Party Headers:
22 #include "lldb/API/SBCommandInterpreter.h"
23 #include "lldb/API/SBProcess.h"
24 #include "lldb/API/SBStream.h"
25 #include "lldb/API/SBThread.h"
26 #include "lldb/lldb-enumerations.h"
29 #include "MICmdArgValListOfN.h"
30 #include "MICmdArgValNumber.h"
31 #include "MICmdArgValOptionLong.h"
32 #include "MICmdArgValOptionShort.h"
33 #include "MICmdArgValString.h"
34 #include "MICmdArgValThreadGrp.h"
35 #include "MICmdCmdExec.h"
36 #include "MICmnLLDBDebugSessionInfo.h"
37 #include "MICmnLLDBDebugger.h"
38 #include "MICmnMIOutOfBandRecord.h"
39 #include "MICmnMIResultRecord.h"
40 #include "MICmnMIValueConst.h"
41 #include "MICmnStreamStdout.h"
45 //------------------------------------------------------------------------------------
46 // Details: CMICmdCmdExecRun constructor.
52 CMICmdCmdExecRun::CMICmdCmdExecRun() : m_constStrArgStart("start") {
53 // Command factory matches this name with that received from the stdin stream
54 m_strMiCmd = "exec-run";
56 // Required by the CMICmdFactory when registering *this command
57 m_pSelfCreatorFn = &CMICmdCmdExecRun::CreateSelf;
61 //------------------------------------------------------------------------------------
62 // Details: CMICmdCmdExecRun destructor.
63 // Type: Overrideable.
68 CMICmdCmdExecRun::~CMICmdCmdExecRun() {}
71 //------------------------------------------------------------------------------------
72 // Details: The invoker requires this function. It parses the command line
74 // arguments to extract values for each of those arguments.
77 // Return: MIstatus::success - Functional succeeded.
78 // MIstatus::failure - Functional failed.
81 bool CMICmdCmdExecRun::ParseArgs() {
82 m_setCmdArgs.Add(new CMICmdArgValOptionLong(
83 m_constStrArgStart, false, true,
84 CMICmdArgValListBase::eArgValType_OptionLong, 0));
85 return ParseValidateCmdOptions();
89 //------------------------------------------------------------------------------------
90 // Details: The invoker requires this function. The command does work in this
92 // The command is likely to communicate with the LLDB SBDebugger in
96 // Return: MIstatus::success - Functional succeeded.
97 // MIstatus::failure - Functional failed.
100 bool CMICmdCmdExecRun::Execute() {
101 CMICmnLLDBDebugSessionInfo &rSessionInfo(
102 CMICmnLLDBDebugSessionInfo::Instance());
105 // Check we have a valid target.
106 // Note: target created via 'file-exec-and-symbols' command.
107 lldb::SBTarget sbTarget = rSessionInfo.GetTarget();
108 if (!sbTarget.IsValid() ||
109 sbTarget == rSessionInfo.GetDebugger().GetDummyTarget()) {
110 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INVALID_TARGET_CURRENT),
111 m_cmdData.strMiCmd.c_str()));
112 return MIstatus::failure;
117 lldb::SBStream errMsg;
118 lldb::SBLaunchInfo launchInfo = rSessionInfo.GetTarget().GetLaunchInfo();
119 launchInfo.SetListener(rSessionInfo.GetListener());
121 // Run to first instruction or main() requested?
122 CMICMDBASE_GETOPTION(pArgStart, OptionLong, m_constStrArgStart);
123 if (pArgStart->GetFound()) {
124 launchInfo.SetLaunchFlags(launchInfo.GetLaunchFlags() |
125 lldb::eLaunchFlagStopAtEntry);
128 lldb::SBProcess process = rSessionInfo.GetTarget().Launch(launchInfo, error);
129 if (!process.IsValid()) {
130 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INVALID_PROCESS),
131 m_cmdData.strMiCmd.c_str(),
133 return MIstatus::failure;
136 const auto successHandler = [this] {
137 if (!CMIDriver::Instance().SetDriverStateRunningDebugging()) {
138 const CMIUtilString &rErrMsg(CMIDriver::Instance().GetErrorDescription());
139 SetError(CMIUtilString::Format(
140 MIRSRC(IDS_CMD_ERR_SET_NEW_DRIVER_STATE),
141 m_cmdData.strMiCmd.c_str(), rErrMsg.c_str()));
142 return MIstatus::failure;
144 return MIstatus::success;
147 return HandleSBErrorWithSuccess(error, successHandler);
151 //------------------------------------------------------------------------------------
152 // Details: The invoker requires this function. The command prepares a MI Record
154 // for the work carried out in the Execute().
155 // Called only if Execute() set status as successful on completion.
158 // Return: MIstatus::success - Functional succeeded.
159 // MIstatus::failure - Functional failed.
162 bool CMICmdCmdExecRun::Acknowledge() {
163 m_miResultRecord = CMICmnMIResultRecord(
164 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
166 CMICmnLLDBDebugSessionInfo &rSessionInfo(
167 CMICmnLLDBDebugSessionInfo::Instance());
168 lldb::pid_t pid = rSessionInfo.GetProcess().GetProcessID();
169 // Give the client '=thread-group-started,id="i1" pid="xyz"'
170 m_bHasResultRecordExtra = true;
171 const CMICmnMIValueConst miValueConst2("i1");
172 const CMICmnMIValueResult miValueResult2("id", miValueConst2);
173 const CMIUtilString strPid(CMIUtilString::Format("%lld", pid));
174 const CMICmnMIValueConst miValueConst(strPid);
175 const CMICmnMIValueResult miValueResult("pid", miValueConst);
176 CMICmnMIOutOfBandRecord miOutOfBand(
177 CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupStarted, miValueResult2);
178 miOutOfBand.Add(miValueResult);
179 m_miResultRecordExtra = miOutOfBand.GetString();
181 return MIstatus::success;
185 //------------------------------------------------------------------------------------
186 // Details: Required by the CMICmdFactory when registering *this command. The
188 // calls this function to create an instance of *this command.
189 // Type: Static method.
191 // Return: CMICmdBase * - Pointer to a new command.
194 CMICmdBase *CMICmdCmdExecRun::CreateSelf() { return new CMICmdCmdExecRun(); }
196 //---------------------------------------------------------------------------------------
197 //---------------------------------------------------------------------------------------
198 //---------------------------------------------------------------------------------------
201 //------------------------------------------------------------------------------------
202 // Details: CMICmdCmdExecContinue constructor.
208 CMICmdCmdExecContinue::CMICmdCmdExecContinue() {
209 // Command factory matches this name with that received from the stdin stream
210 m_strMiCmd = "exec-continue";
212 // Required by the CMICmdFactory when registering *this command
213 m_pSelfCreatorFn = &CMICmdCmdExecContinue::CreateSelf;
217 //------------------------------------------------------------------------------------
218 // Details: CMICmdCmdExecContinue destructor.
219 // Type: Overrideable.
224 CMICmdCmdExecContinue::~CMICmdCmdExecContinue() {}
227 //------------------------------------------------------------------------------------
228 // Details: The invoker requires this function. The command does work in this
230 // The command is likely to communicate with the LLDB SBDebugger in
234 // Return: MIstatus::success - Functional succeeded.
235 // MIstatus::failure - Functional failed.
238 bool CMICmdCmdExecContinue::Execute() {
239 const auto successHandler = [this] {
240 // CODETAG_DEBUG_SESSION_RUNNING_PROG_RECEIVED_SIGINT_PAUSE_PROGRAM
241 if (!CMIDriver::Instance().SetDriverStateRunningDebugging()) {
242 const CMIUtilString &rErrMsg(CMIDriver::Instance().GetErrorDescription());
243 SetError(CMIUtilString::Format(
244 MIRSRC(IDS_CMD_ERR_SET_NEW_DRIVER_STATE),
245 m_cmdData.strMiCmd.c_str(), rErrMsg.c_str()));
246 return MIstatus::failure;
248 return MIstatus::success;
251 return HandleSBErrorWithSuccess(
252 CMICmnLLDBDebugSessionInfo::Instance().GetProcess().Continue(),
257 //------------------------------------------------------------------------------------
258 // Details: The invoker requires this function. The command prepares a MI Record
260 // for the work carried out in the Execute().
263 // Return: MIstatus::success - Functional succeeded.
264 // MIstatus::failure - Functional failed.
267 bool CMICmdCmdExecContinue::Acknowledge() {
268 m_miResultRecord = CMICmnMIResultRecord(
269 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
270 return MIstatus::success;
274 //------------------------------------------------------------------------------------
275 // Details: Required by the CMICmdFactory when registering *this command. The
277 // calls this function to create an instance of *this command.
278 // Type: Static method.
280 // Return: CMICmdBase * - Pointer to a new command.
283 CMICmdBase *CMICmdCmdExecContinue::CreateSelf() {
284 return new CMICmdCmdExecContinue();
287 //---------------------------------------------------------------------------------------
288 //---------------------------------------------------------------------------------------
289 //---------------------------------------------------------------------------------------
292 //------------------------------------------------------------------------------------
293 // Details: CMICmdCmdExecNext constructor.
299 CMICmdCmdExecNext::CMICmdCmdExecNext() : m_constStrArgNumber("number") {
300 // Command factory matches this name with that received from the stdin stream
301 m_strMiCmd = "exec-next";
303 // Required by the CMICmdFactory when registering *this command
304 m_pSelfCreatorFn = &CMICmdCmdExecNext::CreateSelf;
308 //------------------------------------------------------------------------------------
309 // Details: CMICmdCmdExecNext destructor.
310 // Type: Overrideable.
315 CMICmdCmdExecNext::~CMICmdCmdExecNext() {}
318 //------------------------------------------------------------------------------------
319 // Details: The invoker requires this function. The parses the command line
321 // arguments to extract values for each of those arguments.
324 // Return: MIstatus::success - Functional succeeded.
325 // MIstatus::failure - Functional failed.
328 bool CMICmdCmdExecNext::ParseArgs() {
329 m_setCmdArgs.Add(new CMICmdArgValNumber(m_constStrArgNumber, false, false));
330 return ParseValidateCmdOptions();
334 //------------------------------------------------------------------------------------
335 // Details: The invoker requires this function. The command does work in this
337 // The command is likely to communicate with the LLDB SBDebugger in
341 // Return: MIstatus::success - Functional succeeded.
342 // MIstatus::failure - Functional failed.
345 bool CMICmdCmdExecNext::Execute() {
346 CMICMDBASE_GETOPTION(pArgThread, OptionLong, m_constStrArgThread);
348 // Retrieve the --thread option's thread ID (only 1)
349 MIuint64 nThreadId = UINT64_MAX;
350 if (pArgThread->GetFound() &&
351 !pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) {
352 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_THREAD_INVALID),
353 m_cmdData.strMiCmd.c_str(),
354 m_constStrArgThread.c_str()));
355 return MIstatus::failure;
358 CMICmnLLDBDebugSessionInfo &rSessionInfo(
359 CMICmnLLDBDebugSessionInfo::Instance());
362 if (nThreadId != UINT64_MAX) {
363 lldb::SBThread sbThread = rSessionInfo.GetProcess().GetThreadByIndexID(nThreadId);
364 if (!sbThread.IsValid()) {
365 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_THREAD_INVALID),
366 m_cmdData.strMiCmd.c_str(),
367 m_constStrArgThread.c_str()));
368 return MIstatus::failure;
370 sbThread.StepOver(lldb::eOnlyDuringStepping, error);
372 rSessionInfo.GetProcess().GetSelectedThread().StepOver(
373 lldb::eOnlyDuringStepping, error);
375 return HandleSBError(error);
379 //------------------------------------------------------------------------------------
380 // Details: The invoker requires this function. The command prepares a MI Record
382 // for the work carried out in the Execute().
385 // Return: MIstatus::success - Functional succeeded.
386 // MIstatus::failure - Functional failed.
389 bool CMICmdCmdExecNext::Acknowledge() {
390 m_miResultRecord = CMICmnMIResultRecord(
391 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
392 return MIstatus::success;
396 //------------------------------------------------------------------------------------
397 // Details: Required by the CMICmdFactory when registering *this command. The
399 // calls this function to create an instance of *this command.
400 // Type: Static method.
402 // Return: CMICmdBase * - Pointer to a new command.
405 CMICmdBase *CMICmdCmdExecNext::CreateSelf() { return new CMICmdCmdExecNext(); }
407 //---------------------------------------------------------------------------------------
408 //---------------------------------------------------------------------------------------
409 //---------------------------------------------------------------------------------------
412 //------------------------------------------------------------------------------------
413 // Details: CMICmdCmdExecStep constructor.
419 CMICmdCmdExecStep::CMICmdCmdExecStep() : m_constStrArgNumber("number") {
420 // Command factory matches this name with that received from the stdin stream
421 m_strMiCmd = "exec-step";
423 // Required by the CMICmdFactory when registering *this command
424 m_pSelfCreatorFn = &CMICmdCmdExecStep::CreateSelf;
428 //------------------------------------------------------------------------------------
429 // Details: CMICmdCmdExecStep destructor.
430 // Type: Overrideable.
435 CMICmdCmdExecStep::~CMICmdCmdExecStep() {}
438 //------------------------------------------------------------------------------------
439 // Details: The invoker requires this function. The parses the command line
441 // arguments to extract values for each of those arguments.
444 // Return: MIstatus::success - Functional succeeded.
445 // MIstatus::failure - Functional failed.
448 bool CMICmdCmdExecStep::ParseArgs() {
449 m_setCmdArgs.Add(new CMICmdArgValNumber(m_constStrArgNumber, false, false));
450 return ParseValidateCmdOptions();
454 //------------------------------------------------------------------------------------
455 // Details: The invoker requires this function. The command does work in this
457 // The command is likely to communicate with the LLDB SBDebugger in
461 // Return: MIstatus::success - Functional succeeded.
462 // MIstatus::failure - Functional failed.
465 bool CMICmdCmdExecStep::Execute() {
466 CMICMDBASE_GETOPTION(pArgThread, OptionLong, m_constStrArgThread);
468 // Retrieve the --thread option's thread ID (only 1)
469 MIuint64 nThreadId = UINT64_MAX;
470 if (pArgThread->GetFound() &&
471 !pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) {
472 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND),
473 m_cmdData.strMiCmd.c_str(),
474 m_constStrArgThread.c_str()));
475 return MIstatus::failure;
478 CMICmnLLDBDebugSessionInfo &rSessionInfo(
479 CMICmnLLDBDebugSessionInfo::Instance());
482 if (nThreadId != UINT64_MAX) {
483 lldb::SBThread sbThread =
484 rSessionInfo.GetProcess().GetThreadByIndexID(nThreadId);
485 if (!sbThread.IsValid()) {
486 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_THREAD_INVALID),
487 m_cmdData.strMiCmd.c_str(),
488 m_constStrArgThread.c_str()));
489 return MIstatus::failure;
491 sbThread.StepInto(nullptr, LLDB_INVALID_LINE_NUMBER, error);
493 rSessionInfo.GetProcess().GetSelectedThread().StepInto(
494 nullptr, LLDB_INVALID_LINE_NUMBER, error);
496 return HandleSBError(error);
500 //------------------------------------------------------------------------------------
501 // Details: The invoker requires this function. The command prepares a MI Record
503 // for the work carried out in the Execute().
506 // Return: MIstatus::success - Functional succeeded.
507 // MIstatus::failure - Functional failed.
510 bool CMICmdCmdExecStep::Acknowledge() {
511 m_miResultRecord = CMICmnMIResultRecord(
512 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
513 return MIstatus::success;
517 //------------------------------------------------------------------------------------
518 // Details: Required by the CMICmdFactory when registering *this command. The
520 // calls this function to create an instance of *this command.
521 // Type: Static method.
523 // Return: CMICmdBase * - Pointer to a new command.
526 CMICmdBase *CMICmdCmdExecStep::CreateSelf() { return new CMICmdCmdExecStep(); }
528 //---------------------------------------------------------------------------------------
529 //---------------------------------------------------------------------------------------
530 //---------------------------------------------------------------------------------------
533 //------------------------------------------------------------------------------------
534 // Details: CMICmdCmdExecNextInstruction constructor.
540 CMICmdCmdExecNextInstruction::CMICmdCmdExecNextInstruction()
541 : m_constStrArgNumber("number") {
542 // Command factory matches this name with that received from the stdin stream
543 m_strMiCmd = "exec-next-instruction";
545 // Required by the CMICmdFactory when registering *this command
546 m_pSelfCreatorFn = &CMICmdCmdExecNextInstruction::CreateSelf;
550 //------------------------------------------------------------------------------------
551 // Details: CMICmdCmdExecNextInstruction destructor.
552 // Type: Overrideable.
557 CMICmdCmdExecNextInstruction::~CMICmdCmdExecNextInstruction() {}
560 //------------------------------------------------------------------------------------
561 // Details: The invoker requires this function. The parses the command line
563 // arguments to extract values for each of those arguments.
566 // Return: MIstatus::success - Functional succeeded.
567 // MIstatus::failure - Functional failed.
570 bool CMICmdCmdExecNextInstruction::ParseArgs() {
571 m_setCmdArgs.Add(new CMICmdArgValNumber(m_constStrArgNumber, false, false));
572 return ParseValidateCmdOptions();
576 //------------------------------------------------------------------------------------
577 // Details: The invoker requires this function. The command does work in this
579 // The command is likely to communicate with the LLDB SBDebugger in
583 // Return: MIstatus::success - Functional succeeded.
584 // MIstatus::failure - Functional failed.
587 bool CMICmdCmdExecNextInstruction::Execute() {
588 CMICMDBASE_GETOPTION(pArgThread, OptionLong, m_constStrArgThread);
590 // Retrieve the --thread option's thread ID (only 1)
591 MIuint64 nThreadId = UINT64_MAX;
592 if (pArgThread->GetFound() &&
593 !pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) {
594 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND),
595 m_cmdData.strMiCmd.c_str(),
596 m_constStrArgThread.c_str()));
597 return MIstatus::failure;
600 CMICmnLLDBDebugSessionInfo &rSessionInfo(
601 CMICmnLLDBDebugSessionInfo::Instance());
604 if (nThreadId != UINT64_MAX) {
605 lldb::SBThread sbThread =
606 rSessionInfo.GetProcess().GetThreadByIndexID(nThreadId);
607 if (!sbThread.IsValid()) {
608 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_THREAD_INVALID),
609 m_cmdData.strMiCmd.c_str(),
610 m_constStrArgThread.c_str()));
611 return MIstatus::failure;
613 sbThread.StepInstruction(true, error);
615 rSessionInfo.GetProcess().GetSelectedThread().StepInstruction(
618 return HandleSBError(error);
622 //------------------------------------------------------------------------------------
623 // Details: The invoker requires this function. The command prepares a MI Record
625 // for the work carried out in the Execute().
628 // Return: MIstatus::success - Functional succeeded.
629 // MIstatus::failure - Functional failed.
632 bool CMICmdCmdExecNextInstruction::Acknowledge() {
633 m_miResultRecord = CMICmnMIResultRecord(
634 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
635 return MIstatus::success;
639 //------------------------------------------------------------------------------------
640 // Details: Required by the CMICmdFactory when registering *this command. The
642 // calls this function to create an instance of *this command.
643 // Type: Static method.
645 // Return: CMICmdBase * - Pointer to a new command.
648 CMICmdBase *CMICmdCmdExecNextInstruction::CreateSelf() {
649 return new CMICmdCmdExecNextInstruction();
652 //---------------------------------------------------------------------------------------
653 //---------------------------------------------------------------------------------------
654 //---------------------------------------------------------------------------------------
657 //------------------------------------------------------------------------------------
658 // Details: CMICmdCmdExecStepInstruction constructor.
664 CMICmdCmdExecStepInstruction::CMICmdCmdExecStepInstruction()
665 : m_constStrArgNumber("number") {
666 // Command factory matches this name with that received from the stdin stream
667 m_strMiCmd = "exec-step-instruction";
669 // Required by the CMICmdFactory when registering *this command
670 m_pSelfCreatorFn = &CMICmdCmdExecStepInstruction::CreateSelf;
674 //------------------------------------------------------------------------------------
675 // Details: CMICmdCmdExecStepInstruction destructor.
676 // Type: Overrideable.
681 CMICmdCmdExecStepInstruction::~CMICmdCmdExecStepInstruction() {}
684 //------------------------------------------------------------------------------------
685 // Details: The invoker requires this function. The parses the command line
687 // arguments to extract values for each of those arguments.
690 // Return: MIstatus::success - Functional succeeded.
691 // MIstatus::failure - Functional failed.
694 bool CMICmdCmdExecStepInstruction::ParseArgs() {
695 m_setCmdArgs.Add(new CMICmdArgValNumber(m_constStrArgNumber, false, false));
696 return ParseValidateCmdOptions();
700 //------------------------------------------------------------------------------------
701 // Details: The invoker requires this function. The command does work in this
703 // The command is likely to communicate with the LLDB SBDebugger in
707 // Return: MIstatus::success - Functional succeeded.
708 // MIstatus::failure - Functional failed.
711 bool CMICmdCmdExecStepInstruction::Execute() {
712 CMICMDBASE_GETOPTION(pArgThread, OptionLong, m_constStrArgThread);
714 // Retrieve the --thread option's thread ID (only 1)
715 MIuint64 nThreadId = UINT64_MAX;
716 if (pArgThread->GetFound() &&
717 !pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) {
718 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND),
719 m_cmdData.strMiCmd.c_str(),
720 m_constStrArgThread.c_str()));
721 return MIstatus::failure;
724 CMICmnLLDBDebugSessionInfo &rSessionInfo(
725 CMICmnLLDBDebugSessionInfo::Instance());
728 if (nThreadId != UINT64_MAX) {
729 lldb::SBThread sbThread =
730 rSessionInfo.GetProcess().GetThreadByIndexID(nThreadId);
731 if (!sbThread.IsValid()) {
732 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_THREAD_INVALID),
733 m_cmdData.strMiCmd.c_str(),
734 m_constStrArgThread.c_str()));
735 return MIstatus::failure;
737 sbThread.StepInstruction(false, error);
739 rSessionInfo.GetProcess().GetSelectedThread().StepInstruction(
742 return HandleSBError(error);
746 //------------------------------------------------------------------------------------
747 // Details: The invoker requires this function. The command prepares a MI Record
749 // for the work carried out in the Execute().
752 // Return: MIstatus::success - Functional succeeded.
753 // MIstatus::failure - Functional failed.
756 bool CMICmdCmdExecStepInstruction::Acknowledge() {
757 m_miResultRecord = CMICmnMIResultRecord(
758 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
759 return MIstatus::success;
763 //------------------------------------------------------------------------------------
764 // Details: Required by the CMICmdFactory when registering *this command. The
766 // calls this function to create an instance of *this command.
767 // Type: Static method.
769 // Return: CMICmdBase * - Pointer to a new command.
772 CMICmdBase *CMICmdCmdExecStepInstruction::CreateSelf() {
773 return new CMICmdCmdExecStepInstruction();
776 //---------------------------------------------------------------------------------------
777 //---------------------------------------------------------------------------------------
778 //---------------------------------------------------------------------------------------
781 //------------------------------------------------------------------------------------
782 // Details: CMICmdCmdExecFinish constructor.
788 CMICmdCmdExecFinish::CMICmdCmdExecFinish() {
789 // Command factory matches this name with that received from the stdin stream
790 m_strMiCmd = "exec-finish";
792 // Required by the CMICmdFactory when registering *this command
793 m_pSelfCreatorFn = &CMICmdCmdExecFinish::CreateSelf;
797 //------------------------------------------------------------------------------------
798 // Details: CMICmdCmdExecFinish destructor.
799 // Type: Overrideable.
804 CMICmdCmdExecFinish::~CMICmdCmdExecFinish() {}
807 //------------------------------------------------------------------------------------
808 // Details: The invoker requires this function. The parses the command line
810 // arguments to extract values for each of those arguments.
813 // Return: MIstatus::success - Functional succeeded.
814 // MIstatus::failure - Functional failed.
817 bool CMICmdCmdExecFinish::ParseArgs() { return ParseValidateCmdOptions(); }
820 //------------------------------------------------------------------------------------
821 // Details: The invoker requires this function. The command does work in this
823 // The command is likely to communicate with the LLDB SBDebugger in
827 // Return: MIstatus::success - Functional succeeded.
828 // MIstatus::failure - Functional failed.
831 bool CMICmdCmdExecFinish::Execute() {
832 CMICMDBASE_GETOPTION(pArgThread, OptionLong, m_constStrArgThread);
834 // Retrieve the --thread option's thread ID (only 1)
835 MIuint64 nThreadId = UINT64_MAX;
836 if (pArgThread->GetFound() &&
837 !pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) {
838 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND),
839 m_cmdData.strMiCmd.c_str(),
840 m_constStrArgThread.c_str()));
841 return MIstatus::failure;
844 CMICmnLLDBDebugSessionInfo &rSessionInfo(
845 CMICmnLLDBDebugSessionInfo::Instance());
848 if (nThreadId != UINT64_MAX) {
849 lldb::SBThread sbThread =
850 rSessionInfo.GetProcess().GetThreadByIndexID(nThreadId);
851 if (!sbThread.IsValid()) {
852 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_THREAD_INVALID),
853 m_cmdData.strMiCmd.c_str(),
854 m_constStrArgThread.c_str()));
855 return MIstatus::failure;
857 sbThread.StepOut(error);
859 rSessionInfo.GetProcess().GetSelectedThread().StepOut(error);
861 return HandleSBError(error);
865 //------------------------------------------------------------------------------------
866 // Details: The invoker requires this function. The command prepares a MI Record
868 // for the work carried out in the Execute().
871 // Return: MIstatus::success - Functional succeeded.
872 // MIstatus::failure - Functional failed.
875 bool CMICmdCmdExecFinish::Acknowledge() {
876 m_miResultRecord = CMICmnMIResultRecord(
877 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
878 return MIstatus::success;
882 //------------------------------------------------------------------------------------
883 // Details: Required by the CMICmdFactory when registering *this command. The
885 // calls this function to create an instance of *this command.
886 // Type: Static method.
888 // Return: CMICmdBase * - Pointer to a new command.
891 CMICmdBase *CMICmdCmdExecFinish::CreateSelf() {
892 return new CMICmdCmdExecFinish();
895 //---------------------------------------------------------------------------------------
896 //---------------------------------------------------------------------------------------
897 //---------------------------------------------------------------------------------------
900 //------------------------------------------------------------------------------------
901 // Details: CMICmdCmdExecInterrupt constructor.
907 CMICmdCmdExecInterrupt::CMICmdCmdExecInterrupt() {
908 // Command factory matches this name with that received from the stdin stream
909 m_strMiCmd = "exec-interrupt";
911 // Required by the CMICmdFactory when registering *this command
912 m_pSelfCreatorFn = &CMICmdCmdExecInterrupt::CreateSelf;
916 //------------------------------------------------------------------------------------
917 // Details: CMICmdCmdExecInterrupt destructor.
918 // Type: Overrideable.
923 CMICmdCmdExecInterrupt::~CMICmdCmdExecInterrupt() {}
926 //------------------------------------------------------------------------------------
927 // Details: The invoker requires this function. The command does work in this
929 // The command is likely to communicate with the LLDB SBDebugger in
933 // Return: MIstatus::success - Functional succeeded.
934 // MIstatus::failure - Functional failed.
937 bool CMICmdCmdExecInterrupt::Execute() {
938 const auto successHandler = [this] {
939 // CODETAG_DEBUG_SESSION_RUNNING_PROG_RECEIVED_SIGINT_PAUSE_PROGRAM
940 if (!CMIDriver::Instance().SetDriverStateRunningNotDebugging()) {
941 const CMIUtilString &rErrMsg(CMIDriver::Instance().GetErrorDescription());
942 SetErrorDescription(CMIUtilString::Format(
943 MIRSRC(IDS_CMD_ERR_SET_NEW_DRIVER_STATE),
944 m_cmdData.strMiCmd.c_str(),
946 return MIstatus::failure;
948 return MIstatus::success;
951 return HandleSBErrorWithSuccess(
952 CMICmnLLDBDebugSessionInfo::Instance().GetProcess().Stop(),
957 //------------------------------------------------------------------------------------
958 // Details: The invoker requires this function. The command prepares a MI Record
960 // for the work carried out in the Execute().
963 // Return: MIstatus::success - Functional succeeded.
964 // MIstatus::failure - Functional failed.
967 bool CMICmdCmdExecInterrupt::Acknowledge() {
968 m_miResultRecord = CMICmnMIResultRecord(
969 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done);
970 return MIstatus::success;
974 //------------------------------------------------------------------------------------
975 // Details: Required by the CMICmdFactory when registering *this command. The
977 // calls this function to create an instance of *this command.
978 // Type: Static method.
980 // Return: CMICmdBase * - Pointer to a new command.
983 CMICmdBase *CMICmdCmdExecInterrupt::CreateSelf() {
984 return new CMICmdCmdExecInterrupt();
987 //---------------------------------------------------------------------------------------
988 //---------------------------------------------------------------------------------------
989 //---------------------------------------------------------------------------------------
992 //------------------------------------------------------------------------------------
993 // Details: CMICmdCmdExecArguments constructor.
999 CMICmdCmdExecArguments::CMICmdCmdExecArguments()
1000 : m_constStrArgArguments("arguments") {
1001 // Command factory matches this name with that received from the stdin stream
1002 m_strMiCmd = "exec-arguments";
1004 // Required by the CMICmdFactory when registering *this command
1005 m_pSelfCreatorFn = &CMICmdCmdExecArguments::CreateSelf;
1009 //------------------------------------------------------------------------------------
1010 // Details: CMICmdCmdExecArguments destructor.
1011 // Type: Overrideable.
1016 CMICmdCmdExecArguments::~CMICmdCmdExecArguments() {}
1019 //------------------------------------------------------------------------------------
1020 // Details: The invoker requires this function. The parses the command line
1022 // arguments to extract values for each of those arguments.
1023 // Type: Overridden.
1025 // Return: MIstatus::success - Function succeeded.
1026 // MIstatus::failure - Function failed.
1029 bool CMICmdCmdExecArguments::ParseArgs() {
1030 m_setCmdArgs.Add(new CMICmdArgValListOfN(
1031 m_constStrArgArguments, false, true,
1032 CMICmdArgValListBase::eArgValType_StringAnything));
1033 return ParseValidateCmdOptions();
1037 //------------------------------------------------------------------------------------
1038 // Details: The invoker requires this function. The command does work in this
1040 // The command is likely to communicate with the LLDB SBDebugger in
1042 // Type: Overridden.
1044 // Return: MIstatus::success - Function succeeded.
1045 // MIstatus::failure - Function failed.
1048 bool CMICmdCmdExecArguments::Execute() {
1049 CMICMDBASE_GETOPTION(pArgArguments, ListOfN, m_constStrArgArguments);
1051 CMICmnLLDBDebugSessionInfo &rSessionInfo(
1052 CMICmnLLDBDebugSessionInfo::Instance());
1053 lldb::SBTarget sbTarget = rSessionInfo.GetTarget();
1054 if (!sbTarget.IsValid()) {
1055 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INVALID_TARGET_CURRENT),
1056 m_cmdData.strMiCmd.c_str()));
1057 return MIstatus::failure;
1060 lldb::SBLaunchInfo sbLaunchInfo = sbTarget.GetLaunchInfo();
1061 sbLaunchInfo.SetArguments(NULL, false);
1063 CMIUtilString strArg;
1064 size_t nArgIndex = 0;
1065 while (pArgArguments->GetExpectedOption<CMICmdArgValString, CMIUtilString>(
1066 strArg, nArgIndex)) {
1067 const char *argv[2] = {strArg.c_str(), NULL};
1068 sbLaunchInfo.SetArguments(argv, true);
1072 sbTarget.SetLaunchInfo(sbLaunchInfo);
1074 return MIstatus::success;
1078 //------------------------------------------------------------------------------------
1079 // Details: The invoker requires this function. The command prepares a MI Record
1081 // for the work carried out in the Execute().
1082 // Type: Overridden.
1084 // Return: MIstatus::success - Function succeeded.
1085 // MIstatus::failure - Function failed.
1088 bool CMICmdCmdExecArguments::Acknowledge() {
1089 m_miResultRecord = CMICmnMIResultRecord(
1090 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done);
1091 return MIstatus::success;
1095 //------------------------------------------------------------------------------------
1096 // Details: Required by the CMICmdFactory when registering *this command. The
1098 // calls this function to create an instance of *this command.
1099 // Type: Static method.
1101 // Return: CMICmdBase * - Pointer to a new command.
1104 CMICmdBase *CMICmdCmdExecArguments::CreateSelf() {
1105 return new CMICmdCmdExecArguments();
1108 //---------------------------------------------------------------------------------------
1109 //---------------------------------------------------------------------------------------
1110 //---------------------------------------------------------------------------------------
1113 //------------------------------------------------------------------------------------
1114 // Details: CMICmdCmdExecAbort constructor.
1120 CMICmdCmdExecAbort::CMICmdCmdExecAbort() {
1121 // Command factory matches this name with that received from the stdin stream
1122 m_strMiCmd = "exec-abort";
1124 // Required by the CMICmdFactory when registering *this command
1125 m_pSelfCreatorFn = &CMICmdCmdExecAbort::CreateSelf;
1129 //------------------------------------------------------------------------------------
1130 // Details: CMICmdCmdExecAbort destructor.
1131 // Type: Overrideable.
1136 CMICmdCmdExecAbort::~CMICmdCmdExecAbort() {}
1139 //------------------------------------------------------------------------------------
1140 // Details: The invoker requires this function. The command does work in this
1142 // The command is likely to communicate with the LLDB SBDebugger in
1144 // Type: Overridden.
1146 // Return: MIstatus::success - Function succeeded.
1147 // MIstatus::failure - Function failed.
1150 bool CMICmdCmdExecAbort::Execute() {
1151 CMICmnLLDBDebugSessionInfo &rSessionInfo(
1152 CMICmnLLDBDebugSessionInfo::Instance());
1153 lldb::SBProcess sbProcess = rSessionInfo.GetProcess();
1154 if (!sbProcess.IsValid()) {
1155 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INVALID_PROCESS),
1156 m_cmdData.strMiCmd.c_str()));
1157 return MIstatus::failure;
1160 lldb::SBError sbError = sbProcess.Destroy();
1161 if (sbError.Fail()) {
1162 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_LLDBPROCESS_DESTROY),
1163 m_cmdData.strMiCmd.c_str(),
1164 sbError.GetCString()));
1165 return MIstatus::failure;
1168 return MIstatus::success;
1172 //------------------------------------------------------------------------------------
1173 // Details: The invoker requires this function. The command prepares a MI Record
1175 // for the work carried out in the Execute().
1176 // Type: Overridden.
1178 // Return: MIstatus::success - Function succeeded.
1179 // MIstatus::failure - Function failed.
1182 bool CMICmdCmdExecAbort::Acknowledge() {
1183 m_miResultRecord = CMICmnMIResultRecord(
1184 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done);
1185 return MIstatus::success;
1189 //------------------------------------------------------------------------------------
1190 // Details: Required by the CMICmdFactory when registering *this command. The
1192 // calls this function to create an instance of *this command.
1193 // Type: Static method.
1195 // Return: CMICmdBase * - Pointer to a new command.
1198 CMICmdBase *CMICmdCmdExecAbort::CreateSelf() {
1199 return new CMICmdCmdExecAbort();