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/lldb-enumerations.h"
28 #include "MICmdArgValListOfN.h"
29 #include "MICmdArgValNumber.h"
30 #include "MICmdArgValOptionLong.h"
31 #include "MICmdArgValOptionShort.h"
32 #include "MICmdArgValString.h"
33 #include "MICmdArgValThreadGrp.h"
34 #include "MICmdCmdExec.h"
35 #include "MICmnLLDBDebugSessionInfo.h"
36 #include "MICmnLLDBDebugger.h"
37 #include "MICmnMIOutOfBandRecord.h"
38 #include "MICmnMIResultRecord.h"
39 #include "MICmnMIValueConst.h"
40 #include "MICmnStreamStdout.h"
44 //------------------------------------------------------------------------------------
45 // Details: CMICmdCmdExecRun constructor.
51 CMICmdCmdExecRun::CMICmdCmdExecRun() : m_constStrArgStart("start") {
52 // Command factory matches this name with that received from the stdin stream
53 m_strMiCmd = "exec-run";
55 // Required by the CMICmdFactory when registering *this command
56 m_pSelfCreatorFn = &CMICmdCmdExecRun::CreateSelf;
60 //------------------------------------------------------------------------------------
61 // Details: CMICmdCmdExecRun destructor.
62 // Type: Overrideable.
67 CMICmdCmdExecRun::~CMICmdCmdExecRun() {}
70 //------------------------------------------------------------------------------------
71 // Details: The invoker requires this function. It parses the command line
73 // arguments to extract values for each of those arguments.
76 // Return: MIstatus::success - Functional succeeded.
77 // MIstatus::failure - Functional failed.
80 bool CMICmdCmdExecRun::ParseArgs() {
81 m_setCmdArgs.Add(new CMICmdArgValOptionLong(
82 m_constStrArgStart, false, true,
83 CMICmdArgValListBase::eArgValType_OptionLong, 0));
84 return ParseValidateCmdOptions();
88 //------------------------------------------------------------------------------------
89 // Details: The invoker requires this function. The command does work in this
91 // The command is likely to communicate with the LLDB SBDebugger in
95 // Return: MIstatus::success - Functional succeeded.
96 // MIstatus::failure - Functional failed.
99 bool CMICmdCmdExecRun::Execute() {
100 CMICmnLLDBDebugSessionInfo &rSessionInfo(
101 CMICmnLLDBDebugSessionInfo::Instance());
103 lldb::SBStream errMsg;
104 lldb::SBLaunchInfo launchInfo = rSessionInfo.GetTarget().GetLaunchInfo();
105 launchInfo.SetListener(rSessionInfo.GetListener());
107 // Run to first instruction or main() requested?
108 CMICMDBASE_GETOPTION(pArgStart, OptionLong, m_constStrArgStart);
109 if (pArgStart->GetFound()) {
110 launchInfo.SetLaunchFlags(launchInfo.GetLaunchFlags() |
111 lldb::eLaunchFlagStopAtEntry);
114 lldb::SBProcess process = rSessionInfo.GetTarget().Launch(launchInfo, error);
115 if ((!process.IsValid()) || (error.Fail())) {
116 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INVALID_PROCESS),
117 m_cmdData.strMiCmd.c_str(),
119 return MIstatus::failure;
122 if (!CMIDriver::Instance().SetDriverStateRunningDebugging()) {
123 const CMIUtilString &rErrMsg(CMIDriver::Instance().GetErrorDescription());
124 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_SET_NEW_DRIVER_STATE),
125 m_cmdData.strMiCmd.c_str(),
127 return MIstatus::failure;
129 return MIstatus::success;
133 //------------------------------------------------------------------------------------
134 // Details: The invoker requires this function. The command prepares a MI Record
136 // for the work carried out in the Execute().
137 // Called only if Execute() set status as successful on completion.
140 // Return: MIstatus::success - Functional succeeded.
141 // MIstatus::failure - Functional failed.
144 bool CMICmdCmdExecRun::Acknowledge() {
145 const CMICmnMIResultRecord miRecordResult(
146 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
147 m_miResultRecord = miRecordResult;
149 CMICmnLLDBDebugSessionInfo &rSessionInfo(
150 CMICmnLLDBDebugSessionInfo::Instance());
151 lldb::pid_t pid = rSessionInfo.GetProcess().GetProcessID();
152 // Give the client '=thread-group-started,id="i1" pid="xyz"'
153 m_bHasResultRecordExtra = true;
154 const CMICmnMIValueConst miValueConst2("i1");
155 const CMICmnMIValueResult miValueResult2("id", miValueConst2);
156 const CMIUtilString strPid(CMIUtilString::Format("%lld", pid));
157 const CMICmnMIValueConst miValueConst(strPid);
158 const CMICmnMIValueResult miValueResult("pid", miValueConst);
159 CMICmnMIOutOfBandRecord miOutOfBand(
160 CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupStarted, miValueResult2);
161 miOutOfBand.Add(miValueResult);
162 m_miResultRecordExtra = miOutOfBand.GetString();
164 return MIstatus::success;
168 //------------------------------------------------------------------------------------
169 // Details: Required by the CMICmdFactory when registering *this command. The
171 // calls this function to create an instance of *this command.
172 // Type: Static method.
174 // Return: CMICmdBase * - Pointer to a new command.
177 CMICmdBase *CMICmdCmdExecRun::CreateSelf() { return new CMICmdCmdExecRun(); }
179 //---------------------------------------------------------------------------------------
180 //---------------------------------------------------------------------------------------
181 //---------------------------------------------------------------------------------------
184 //------------------------------------------------------------------------------------
185 // Details: CMICmdCmdExecContinue constructor.
191 CMICmdCmdExecContinue::CMICmdCmdExecContinue() {
192 // Command factory matches this name with that received from the stdin stream
193 m_strMiCmd = "exec-continue";
195 // Required by the CMICmdFactory when registering *this command
196 m_pSelfCreatorFn = &CMICmdCmdExecContinue::CreateSelf;
200 //------------------------------------------------------------------------------------
201 // Details: CMICmdCmdExecContinue destructor.
202 // Type: Overrideable.
207 CMICmdCmdExecContinue::~CMICmdCmdExecContinue() {}
210 //------------------------------------------------------------------------------------
211 // Details: The invoker requires this function. The command does work in this
213 // The command is likely to communicate with the LLDB SBDebugger in
217 // Return: MIstatus::success - Functional succeeded.
218 // MIstatus::failure - Functional failed.
221 bool CMICmdCmdExecContinue::Execute() {
222 const char *pCmd = "continue";
223 CMICmnLLDBDebugSessionInfo &rSessionInfo(
224 CMICmnLLDBDebugSessionInfo::Instance());
225 const lldb::ReturnStatus rtn =
226 rSessionInfo.GetDebugger().GetCommandInterpreter().HandleCommand(
230 if (m_lldbResult.GetErrorSize() == 0) {
231 // CODETAG_DEBUG_SESSION_RUNNING_PROG_RECEIVED_SIGINT_PAUSE_PROGRAM
232 if (!CMIDriver::Instance().SetDriverStateRunningDebugging()) {
233 const CMIUtilString &rErrMsg(CMIDriver::Instance().GetErrorDescription());
234 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_SET_NEW_DRIVER_STATE),
235 m_cmdData.strMiCmd.c_str(),
237 return MIstatus::failure;
240 // ToDo: Re-evaluate if this is required when application near finished as
241 // this is parsing LLDB error message
242 // which seems a hack and is code brittle
243 const char *pLldbErr = m_lldbResult.GetError();
244 const CMIUtilString strLldbMsg(CMIUtilString(pLldbErr).StripCREndOfLine());
245 if (strLldbMsg == "error: Process must be launched.") {
246 CMIDriver::Instance().SetExitApplicationFlag(true);
250 return MIstatus::success;
254 //------------------------------------------------------------------------------------
255 // Details: The invoker requires this function. The command prepares a MI Record
257 // for the work carried out in the Execute().
260 // Return: MIstatus::success - Functional succeeded.
261 // MIstatus::failure - Functional failed.
264 bool CMICmdCmdExecContinue::Acknowledge() {
265 if (m_lldbResult.GetErrorSize() > 0) {
266 const CMICmnMIValueConst miValueConst(m_lldbResult.GetError());
267 const CMICmnMIValueResult miValueResult("message", miValueConst);
268 const CMICmnMIResultRecord miRecordResult(
269 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error,
271 m_miResultRecord = miRecordResult;
273 const CMICmnMIResultRecord miRecordResult(
274 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
275 m_miResultRecord = miRecordResult;
278 return MIstatus::success;
282 //------------------------------------------------------------------------------------
283 // Details: Required by the CMICmdFactory when registering *this command. The
285 // calls this function to create an instance of *this command.
286 // Type: Static method.
288 // Return: CMICmdBase * - Pointer to a new command.
291 CMICmdBase *CMICmdCmdExecContinue::CreateSelf() {
292 return new CMICmdCmdExecContinue();
295 //---------------------------------------------------------------------------------------
296 //---------------------------------------------------------------------------------------
297 //---------------------------------------------------------------------------------------
300 //------------------------------------------------------------------------------------
301 // Details: CMICmdCmdExecNext constructor.
307 CMICmdCmdExecNext::CMICmdCmdExecNext() : m_constStrArgNumber("number") {
308 // Command factory matches this name with that received from the stdin stream
309 m_strMiCmd = "exec-next";
311 // Required by the CMICmdFactory when registering *this command
312 m_pSelfCreatorFn = &CMICmdCmdExecNext::CreateSelf;
316 //------------------------------------------------------------------------------------
317 // Details: CMICmdCmdExecNext destructor.
318 // Type: Overrideable.
323 CMICmdCmdExecNext::~CMICmdCmdExecNext() {}
326 //------------------------------------------------------------------------------------
327 // Details: The invoker requires this function. The parses the command line
329 // arguments to extract values for each of those arguments.
332 // Return: MIstatus::success - Functional succeeded.
333 // MIstatus::failure - Functional failed.
336 bool CMICmdCmdExecNext::ParseArgs() {
337 m_setCmdArgs.Add(new CMICmdArgValNumber(m_constStrArgNumber, false, false));
338 return ParseValidateCmdOptions();
342 //------------------------------------------------------------------------------------
343 // Details: The invoker requires this function. The command does work in this
345 // The command is likely to communicate with the LLDB SBDebugger in
349 // Return: MIstatus::success - Functional succeeded.
350 // MIstatus::failure - Functional failed.
353 bool CMICmdCmdExecNext::Execute() {
354 CMICMDBASE_GETOPTION(pArgThread, OptionLong, m_constStrArgThread);
356 // Retrieve the --thread option's thread ID (only 1)
357 MIuint64 nThreadId = UINT64_MAX;
358 if (pArgThread->GetFound() &&
359 !pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) {
360 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_THREAD_INVALID),
361 m_cmdData.strMiCmd.c_str(),
362 m_constStrArgThread.c_str()));
363 return MIstatus::failure;
366 CMICmnLLDBDebugSessionInfo &rSessionInfo(
367 CMICmnLLDBDebugSessionInfo::Instance());
368 lldb::SBDebugger &rDebugger = rSessionInfo.GetDebugger();
369 CMIUtilString strCmd("thread step-over");
370 if (nThreadId != UINT64_MAX)
371 strCmd += CMIUtilString::Format(" %llu", nThreadId);
372 rDebugger.GetCommandInterpreter().HandleCommand(strCmd.c_str(), m_lldbResult,
375 return MIstatus::success;
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 if (m_lldbResult.GetErrorSize() > 0) {
391 const char *pLldbErr = m_lldbResult.GetError();
393 const CMICmnMIValueConst miValueConst(m_lldbResult.GetError());
394 const CMICmnMIValueResult miValueResult("message", miValueConst);
395 const CMICmnMIResultRecord miRecordResult(
396 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error,
398 m_miResultRecord = miRecordResult;
400 const CMICmnMIResultRecord miRecordResult(
401 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
402 m_miResultRecord = miRecordResult;
405 return MIstatus::success;
409 //------------------------------------------------------------------------------------
410 // Details: Required by the CMICmdFactory when registering *this command. The
412 // calls this function to create an instance of *this command.
413 // Type: Static method.
415 // Return: CMICmdBase * - Pointer to a new command.
418 CMICmdBase *CMICmdCmdExecNext::CreateSelf() { return new CMICmdCmdExecNext(); }
420 //---------------------------------------------------------------------------------------
421 //---------------------------------------------------------------------------------------
422 //---------------------------------------------------------------------------------------
425 //------------------------------------------------------------------------------------
426 // Details: CMICmdCmdExecStep constructor.
432 CMICmdCmdExecStep::CMICmdCmdExecStep() : m_constStrArgNumber("number") {
433 // Command factory matches this name with that received from the stdin stream
434 m_strMiCmd = "exec-step";
436 // Required by the CMICmdFactory when registering *this command
437 m_pSelfCreatorFn = &CMICmdCmdExecStep::CreateSelf;
441 //------------------------------------------------------------------------------------
442 // Details: CMICmdCmdExecStep destructor.
443 // Type: Overrideable.
448 CMICmdCmdExecStep::~CMICmdCmdExecStep() {}
451 //------------------------------------------------------------------------------------
452 // Details: The invoker requires this function. The parses the command line
454 // arguments to extract values for each of those arguments.
457 // Return: MIstatus::success - Functional succeeded.
458 // MIstatus::failure - Functional failed.
461 bool CMICmdCmdExecStep::ParseArgs() {
462 m_setCmdArgs.Add(new CMICmdArgValNumber(m_constStrArgNumber, false, false));
463 return ParseValidateCmdOptions();
467 //------------------------------------------------------------------------------------
468 // Details: The invoker requires this function. The command does work in this
470 // The command is likely to communicate with the LLDB SBDebugger in
474 // Return: MIstatus::success - Functional succeeded.
475 // MIstatus::failure - Functional failed.
478 bool CMICmdCmdExecStep::Execute() {
479 CMICMDBASE_GETOPTION(pArgThread, OptionLong, m_constStrArgThread);
481 // Retrieve the --thread option's thread ID (only 1)
482 MIuint64 nThreadId = UINT64_MAX;
483 if (pArgThread->GetFound() &&
484 !pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) {
485 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND),
486 m_cmdData.strMiCmd.c_str(),
487 m_constStrArgThread.c_str()));
488 return MIstatus::failure;
491 CMICmnLLDBDebugSessionInfo &rSessionInfo(
492 CMICmnLLDBDebugSessionInfo::Instance());
493 lldb::SBDebugger &rDebugger = rSessionInfo.GetDebugger();
494 CMIUtilString strCmd("thread step-in");
495 if (nThreadId != UINT64_MAX)
496 strCmd += CMIUtilString::Format(" %llu", nThreadId);
497 rDebugger.GetCommandInterpreter().HandleCommand(strCmd.c_str(), m_lldbResult,
500 return MIstatus::success;
504 //------------------------------------------------------------------------------------
505 // Details: The invoker requires this function. The command prepares a MI Record
507 // for the work carried out in the Execute().
510 // Return: MIstatus::success - Functional succeeded.
511 // MIstatus::failure - Functional failed.
514 bool CMICmdCmdExecStep::Acknowledge() {
515 if (m_lldbResult.GetErrorSize() > 0) {
516 const char *pLldbErr = m_lldbResult.GetError();
518 const CMICmnMIValueConst miValueConst(m_lldbResult.GetError());
519 const CMICmnMIValueResult miValueResult("message", miValueConst);
520 const CMICmnMIResultRecord miRecordResult(
521 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error,
523 m_miResultRecord = miRecordResult;
525 const CMICmnMIResultRecord miRecordResult(
526 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
527 m_miResultRecord = miRecordResult;
530 return MIstatus::success;
534 //------------------------------------------------------------------------------------
535 // Details: Required by the CMICmdFactory when registering *this command. The
537 // calls this function to create an instance of *this command.
538 // Type: Static method.
540 // Return: CMICmdBase * - Pointer to a new command.
543 CMICmdBase *CMICmdCmdExecStep::CreateSelf() { return new CMICmdCmdExecStep(); }
545 //---------------------------------------------------------------------------------------
546 //---------------------------------------------------------------------------------------
547 //---------------------------------------------------------------------------------------
550 //------------------------------------------------------------------------------------
551 // Details: CMICmdCmdExecNextInstruction constructor.
557 CMICmdCmdExecNextInstruction::CMICmdCmdExecNextInstruction()
558 : m_constStrArgNumber("number") {
559 // Command factory matches this name with that received from the stdin stream
560 m_strMiCmd = "exec-next-instruction";
562 // Required by the CMICmdFactory when registering *this command
563 m_pSelfCreatorFn = &CMICmdCmdExecNextInstruction::CreateSelf;
567 //------------------------------------------------------------------------------------
568 // Details: CMICmdCmdExecNextInstruction destructor.
569 // Type: Overrideable.
574 CMICmdCmdExecNextInstruction::~CMICmdCmdExecNextInstruction() {}
577 //------------------------------------------------------------------------------------
578 // Details: The invoker requires this function. The parses the command line
580 // arguments to extract values for each of those arguments.
583 // Return: MIstatus::success - Functional succeeded.
584 // MIstatus::failure - Functional failed.
587 bool CMICmdCmdExecNextInstruction::ParseArgs() {
588 m_setCmdArgs.Add(new CMICmdArgValNumber(m_constStrArgNumber, false, false));
589 return ParseValidateCmdOptions();
593 //------------------------------------------------------------------------------------
594 // Details: The invoker requires this function. The command does work in this
596 // The command is likely to communicate with the LLDB SBDebugger in
600 // Return: MIstatus::success - Functional succeeded.
601 // MIstatus::failure - Functional failed.
604 bool CMICmdCmdExecNextInstruction::Execute() {
605 CMICMDBASE_GETOPTION(pArgThread, OptionLong, m_constStrArgThread);
607 // Retrieve the --thread option's thread ID (only 1)
608 MIuint64 nThreadId = UINT64_MAX;
609 if (pArgThread->GetFound() &&
610 !pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) {
611 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND),
612 m_cmdData.strMiCmd.c_str(),
613 m_constStrArgThread.c_str()));
614 return MIstatus::failure;
617 CMICmnLLDBDebugSessionInfo &rSessionInfo(
618 CMICmnLLDBDebugSessionInfo::Instance());
619 lldb::SBDebugger &rDebugger = rSessionInfo.GetDebugger();
620 CMIUtilString strCmd("thread step-inst-over");
621 if (nThreadId != UINT64_MAX)
622 strCmd += CMIUtilString::Format(" %llu", nThreadId);
623 rDebugger.GetCommandInterpreter().HandleCommand(strCmd.c_str(), m_lldbResult,
626 return MIstatus::success;
630 //------------------------------------------------------------------------------------
631 // Details: The invoker requires this function. The command prepares a MI Record
633 // for the work carried out in the Execute().
636 // Return: MIstatus::success - Functional succeeded.
637 // MIstatus::failure - Functional failed.
640 bool CMICmdCmdExecNextInstruction::Acknowledge() {
641 if (m_lldbResult.GetErrorSize() > 0) {
642 const char *pLldbErr = m_lldbResult.GetError();
644 const CMICmnMIValueConst miValueConst(m_lldbResult.GetError());
645 const CMICmnMIValueResult miValueResult("message", miValueConst);
646 const CMICmnMIResultRecord miRecordResult(
647 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error,
649 m_miResultRecord = miRecordResult;
651 const CMICmnMIResultRecord miRecordResult(
652 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
653 m_miResultRecord = miRecordResult;
656 return MIstatus::success;
660 //------------------------------------------------------------------------------------
661 // Details: Required by the CMICmdFactory when registering *this command. The
663 // calls this function to create an instance of *this command.
664 // Type: Static method.
666 // Return: CMICmdBase * - Pointer to a new command.
669 CMICmdBase *CMICmdCmdExecNextInstruction::CreateSelf() {
670 return new CMICmdCmdExecNextInstruction();
673 //---------------------------------------------------------------------------------------
674 //---------------------------------------------------------------------------------------
675 //---------------------------------------------------------------------------------------
678 //------------------------------------------------------------------------------------
679 // Details: CMICmdCmdExecStepInstruction constructor.
685 CMICmdCmdExecStepInstruction::CMICmdCmdExecStepInstruction()
686 : m_constStrArgNumber("number") {
687 // Command factory matches this name with that received from the stdin stream
688 m_strMiCmd = "exec-step-instruction";
690 // Required by the CMICmdFactory when registering *this command
691 m_pSelfCreatorFn = &CMICmdCmdExecStepInstruction::CreateSelf;
695 //------------------------------------------------------------------------------------
696 // Details: CMICmdCmdExecStepInstruction destructor.
697 // Type: Overrideable.
702 CMICmdCmdExecStepInstruction::~CMICmdCmdExecStepInstruction() {}
705 //------------------------------------------------------------------------------------
706 // Details: The invoker requires this function. The parses the command line
708 // arguments to extract values for each of those arguments.
711 // Return: MIstatus::success - Functional succeeded.
712 // MIstatus::failure - Functional failed.
715 bool CMICmdCmdExecStepInstruction::ParseArgs() {
716 m_setCmdArgs.Add(new CMICmdArgValNumber(m_constStrArgNumber, false, false));
717 return ParseValidateCmdOptions();
721 //------------------------------------------------------------------------------------
722 // Details: The invoker requires this function. The command does work in this
724 // The command is likely to communicate with the LLDB SBDebugger in
728 // Return: MIstatus::success - Functional succeeded.
729 // MIstatus::failure - Functional failed.
732 bool CMICmdCmdExecStepInstruction::Execute() {
733 CMICMDBASE_GETOPTION(pArgThread, OptionLong, m_constStrArgThread);
735 // Retrieve the --thread option's thread ID (only 1)
736 MIuint64 nThreadId = UINT64_MAX;
737 if (pArgThread->GetFound() &&
738 !pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) {
739 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND),
740 m_cmdData.strMiCmd.c_str(),
741 m_constStrArgThread.c_str()));
742 return MIstatus::failure;
745 CMICmnLLDBDebugSessionInfo &rSessionInfo(
746 CMICmnLLDBDebugSessionInfo::Instance());
747 lldb::SBDebugger &rDebugger = rSessionInfo.GetDebugger();
748 CMIUtilString strCmd("thread step-inst");
749 if (nThreadId != UINT64_MAX)
750 strCmd += CMIUtilString::Format(" %llu", nThreadId);
751 rDebugger.GetCommandInterpreter().HandleCommand(strCmd.c_str(), m_lldbResult,
754 return MIstatus::success;
758 //------------------------------------------------------------------------------------
759 // Details: The invoker requires this function. The command prepares a MI Record
761 // for the work carried out in the Execute().
764 // Return: MIstatus::success - Functional succeeded.
765 // MIstatus::failure - Functional failed.
768 bool CMICmdCmdExecStepInstruction::Acknowledge() {
769 if (m_lldbResult.GetErrorSize() > 0) {
770 const char *pLldbErr = m_lldbResult.GetError();
772 const CMICmnMIValueConst miValueConst(m_lldbResult.GetError());
773 const CMICmnMIValueResult miValueResult("message", miValueConst);
774 const CMICmnMIResultRecord miRecordResult(
775 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error,
777 m_miResultRecord = miRecordResult;
779 const CMICmnMIResultRecord miRecordResult(
780 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
781 m_miResultRecord = miRecordResult;
784 return MIstatus::success;
788 //------------------------------------------------------------------------------------
789 // Details: Required by the CMICmdFactory when registering *this command. The
791 // calls this function to create an instance of *this command.
792 // Type: Static method.
794 // Return: CMICmdBase * - Pointer to a new command.
797 CMICmdBase *CMICmdCmdExecStepInstruction::CreateSelf() {
798 return new CMICmdCmdExecStepInstruction();
801 //---------------------------------------------------------------------------------------
802 //---------------------------------------------------------------------------------------
803 //---------------------------------------------------------------------------------------
806 //------------------------------------------------------------------------------------
807 // Details: CMICmdCmdExecFinish constructor.
813 CMICmdCmdExecFinish::CMICmdCmdExecFinish() {
814 // Command factory matches this name with that received from the stdin stream
815 m_strMiCmd = "exec-finish";
817 // Required by the CMICmdFactory when registering *this command
818 m_pSelfCreatorFn = &CMICmdCmdExecFinish::CreateSelf;
822 //------------------------------------------------------------------------------------
823 // Details: CMICmdCmdExecFinish destructor.
824 // Type: Overrideable.
829 CMICmdCmdExecFinish::~CMICmdCmdExecFinish() {}
832 //------------------------------------------------------------------------------------
833 // Details: The invoker requires this function. The parses the command line
835 // arguments to extract values for each of those arguments.
838 // Return: MIstatus::success - Functional succeeded.
839 // MIstatus::failure - Functional failed.
842 bool CMICmdCmdExecFinish::ParseArgs() { return ParseValidateCmdOptions(); }
845 //------------------------------------------------------------------------------------
846 // Details: The invoker requires this function. The command does work in this
848 // The command is likely to communicate with the LLDB SBDebugger in
852 // Return: MIstatus::success - Functional succeeded.
853 // MIstatus::failure - Functional failed.
856 bool CMICmdCmdExecFinish::Execute() {
857 CMICMDBASE_GETOPTION(pArgThread, OptionLong, m_constStrArgThread);
859 // Retrieve the --thread option's thread ID (only 1)
860 MIuint64 nThreadId = UINT64_MAX;
861 if (pArgThread->GetFound() &&
862 !pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) {
863 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND),
864 m_cmdData.strMiCmd.c_str(),
865 m_constStrArgThread.c_str()));
866 return MIstatus::failure;
869 CMICmnLLDBDebugSessionInfo &rSessionInfo(
870 CMICmnLLDBDebugSessionInfo::Instance());
871 lldb::SBDebugger &rDebugger = rSessionInfo.GetDebugger();
872 CMIUtilString strCmd("thread step-out");
873 if (nThreadId != UINT64_MAX)
874 strCmd += CMIUtilString::Format(" %llu", nThreadId);
875 rDebugger.GetCommandInterpreter().HandleCommand(strCmd.c_str(), m_lldbResult,
878 return MIstatus::success;
882 //------------------------------------------------------------------------------------
883 // Details: The invoker requires this function. The command prepares a MI Record
885 // for the work carried out in the Execute().
888 // Return: MIstatus::success - Functional succeeded.
889 // MIstatus::failure - Functional failed.
892 bool CMICmdCmdExecFinish::Acknowledge() {
893 if (m_lldbResult.GetErrorSize() > 0) {
894 const char *pLldbErr = m_lldbResult.GetError();
896 const CMICmnMIValueConst miValueConst(m_lldbResult.GetError());
897 const CMICmnMIValueResult miValueResult("message", miValueConst);
898 const CMICmnMIResultRecord miRecordResult(
899 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error,
901 m_miResultRecord = miRecordResult;
903 const CMICmnMIResultRecord miRecordResult(
904 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
905 m_miResultRecord = miRecordResult;
908 return MIstatus::success;
912 //------------------------------------------------------------------------------------
913 // Details: Required by the CMICmdFactory when registering *this command. The
915 // calls this function to create an instance of *this command.
916 // Type: Static method.
918 // Return: CMICmdBase * - Pointer to a new command.
921 CMICmdBase *CMICmdCmdExecFinish::CreateSelf() {
922 return new CMICmdCmdExecFinish();
925 //---------------------------------------------------------------------------------------
926 //---------------------------------------------------------------------------------------
927 //---------------------------------------------------------------------------------------
930 //------------------------------------------------------------------------------------
931 // Details: CMICmdCmdExecInterrupt constructor.
937 CMICmdCmdExecInterrupt::CMICmdCmdExecInterrupt() {
938 // Command factory matches this name with that received from the stdin stream
939 m_strMiCmd = "exec-interrupt";
941 // Required by the CMICmdFactory when registering *this command
942 m_pSelfCreatorFn = &CMICmdCmdExecInterrupt::CreateSelf;
946 //------------------------------------------------------------------------------------
947 // Details: CMICmdCmdExecInterrupt destructor.
948 // Type: Overrideable.
953 CMICmdCmdExecInterrupt::~CMICmdCmdExecInterrupt() {}
956 //------------------------------------------------------------------------------------
957 // Details: The invoker requires this function. The command does work in this
959 // The command is likely to communicate with the LLDB SBDebugger in
963 // Return: MIstatus::success - Functional succeeded.
964 // MIstatus::failure - Functional failed.
967 bool CMICmdCmdExecInterrupt::Execute() {
968 CMICmnLLDBDebugSessionInfo &rSessionInfo(
969 CMICmnLLDBDebugSessionInfo::Instance());
970 lldb::SBDebugger &rDebugger = rSessionInfo.GetDebugger();
971 CMIUtilString strCmd("process interrupt");
972 const lldb::ReturnStatus status =
973 rDebugger.GetCommandInterpreter().HandleCommand(strCmd.c_str(),
974 m_lldbResult, false);
977 // CODETAG_DEBUG_SESSION_RUNNING_PROG_RECEIVED_SIGINT_PAUSE_PROGRAM
978 if (!CMIDriver::Instance().SetDriverStateRunningNotDebugging()) {
979 const CMIUtilString &rErrMsg(CMIDriver::Instance().GetErrorDescription());
981 CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_SET_NEW_DRIVER_STATE),
982 strCmd.c_str(), rErrMsg.c_str()));
983 return MIstatus::failure;
986 return MIstatus::success;
990 //------------------------------------------------------------------------------------
991 // Details: The invoker requires this function. The command prepares a MI Record
993 // for the work carried out in the Execute().
996 // Return: MIstatus::success - Functional succeeded.
997 // MIstatus::failure - Functional failed.
1000 bool CMICmdCmdExecInterrupt::Acknowledge() {
1001 if (m_lldbResult.GetErrorSize() > 0) {
1002 const CMICmnMIValueConst miValueConst(m_lldbResult.GetError());
1003 const CMICmnMIValueResult miValueResult("message", miValueConst);
1004 const CMICmnMIResultRecord miRecordResult(
1005 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error,
1007 m_miResultRecord = miRecordResult;
1009 const CMICmnMIResultRecord miRecordResult(
1010 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done);
1011 m_miResultRecord = miRecordResult;
1014 return MIstatus::success;
1018 //------------------------------------------------------------------------------------
1019 // Details: Required by the CMICmdFactory when registering *this command. The
1021 // calls this function to create an instance of *this command.
1022 // Type: Static method.
1024 // Return: CMICmdBase * - Pointer to a new command.
1027 CMICmdBase *CMICmdCmdExecInterrupt::CreateSelf() {
1028 return new CMICmdCmdExecInterrupt();
1031 //---------------------------------------------------------------------------------------
1032 //---------------------------------------------------------------------------------------
1033 //---------------------------------------------------------------------------------------
1036 //------------------------------------------------------------------------------------
1037 // Details: CMICmdCmdExecArguments constructor.
1043 CMICmdCmdExecArguments::CMICmdCmdExecArguments()
1044 : m_constStrArgArguments("arguments") {
1045 // Command factory matches this name with that received from the stdin stream
1046 m_strMiCmd = "exec-arguments";
1048 // Required by the CMICmdFactory when registering *this command
1049 m_pSelfCreatorFn = &CMICmdCmdExecArguments::CreateSelf;
1053 //------------------------------------------------------------------------------------
1054 // Details: CMICmdCmdExecArguments destructor.
1055 // Type: Overrideable.
1060 CMICmdCmdExecArguments::~CMICmdCmdExecArguments() {}
1063 //------------------------------------------------------------------------------------
1064 // Details: The invoker requires this function. The parses the command line
1066 // arguments to extract values for each of those arguments.
1067 // Type: Overridden.
1069 // Return: MIstatus::success - Function succeeded.
1070 // MIstatus::failure - Function failed.
1073 bool CMICmdCmdExecArguments::ParseArgs() {
1074 m_setCmdArgs.Add(new CMICmdArgValListOfN(
1075 m_constStrArgArguments, false, true,
1076 CMICmdArgValListBase::eArgValType_StringAnything));
1077 return ParseValidateCmdOptions();
1081 //------------------------------------------------------------------------------------
1082 // Details: The invoker requires this function. The command does work in this
1084 // The command is likely to communicate with the LLDB SBDebugger in
1086 // Type: Overridden.
1088 // Return: MIstatus::success - Function succeeded.
1089 // MIstatus::failure - Function failed.
1092 bool CMICmdCmdExecArguments::Execute() {
1093 CMICMDBASE_GETOPTION(pArgArguments, ListOfN, m_constStrArgArguments);
1095 CMICmnLLDBDebugSessionInfo &rSessionInfo(
1096 CMICmnLLDBDebugSessionInfo::Instance());
1097 lldb::SBTarget sbTarget = rSessionInfo.GetTarget();
1098 if (!sbTarget.IsValid()) {
1099 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INVALID_TARGET_CURRENT),
1100 m_cmdData.strMiCmd.c_str()));
1101 return MIstatus::failure;
1104 lldb::SBLaunchInfo sbLaunchInfo = sbTarget.GetLaunchInfo();
1105 sbLaunchInfo.SetArguments(NULL, false);
1107 CMIUtilString strArg;
1108 size_t nArgIndex = 0;
1109 while (pArgArguments->GetExpectedOption<CMICmdArgValString, CMIUtilString>(
1110 strArg, nArgIndex)) {
1111 const char *argv[2] = {strArg.c_str(), NULL};
1112 sbLaunchInfo.SetArguments(argv, true);
1116 sbTarget.SetLaunchInfo(sbLaunchInfo);
1118 return MIstatus::success;
1122 //------------------------------------------------------------------------------------
1123 // Details: The invoker requires this function. The command prepares a MI Record
1125 // for the work carried out in the Execute().
1126 // Type: Overridden.
1128 // Return: MIstatus::success - Function succeeded.
1129 // MIstatus::failure - Function failed.
1132 bool CMICmdCmdExecArguments::Acknowledge() {
1133 const CMICmnMIResultRecord miRecordResult(
1134 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done);
1135 m_miResultRecord = miRecordResult;
1137 return MIstatus::success;
1141 //------------------------------------------------------------------------------------
1142 // Details: Required by the CMICmdFactory when registering *this command. The
1144 // calls this function to create an instance of *this command.
1145 // Type: Static method.
1147 // Return: CMICmdBase * - Pointer to a new command.
1150 CMICmdBase *CMICmdCmdExecArguments::CreateSelf() {
1151 return new CMICmdCmdExecArguments();
1154 //---------------------------------------------------------------------------------------
1155 //---------------------------------------------------------------------------------------
1156 //---------------------------------------------------------------------------------------
1159 //------------------------------------------------------------------------------------
1160 // Details: CMICmdCmdExecAbort constructor.
1166 CMICmdCmdExecAbort::CMICmdCmdExecAbort() {
1167 // Command factory matches this name with that received from the stdin stream
1168 m_strMiCmd = "exec-abort";
1170 // Required by the CMICmdFactory when registering *this command
1171 m_pSelfCreatorFn = &CMICmdCmdExecAbort::CreateSelf;
1175 //------------------------------------------------------------------------------------
1176 // Details: CMICmdCmdExecAbort destructor.
1177 // Type: Overrideable.
1182 CMICmdCmdExecAbort::~CMICmdCmdExecAbort() {}
1185 //------------------------------------------------------------------------------------
1186 // Details: The invoker requires this function. The command does work in this
1188 // The command is likely to communicate with the LLDB SBDebugger in
1190 // Type: Overridden.
1192 // Return: MIstatus::success - Function succeeded.
1193 // MIstatus::failure - Function failed.
1196 bool CMICmdCmdExecAbort::Execute() {
1197 CMICmnLLDBDebugSessionInfo &rSessionInfo(
1198 CMICmnLLDBDebugSessionInfo::Instance());
1199 lldb::SBProcess sbProcess = rSessionInfo.GetProcess();
1200 if (!sbProcess.IsValid()) {
1201 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INVALID_PROCESS),
1202 m_cmdData.strMiCmd.c_str()));
1203 return MIstatus::failure;
1206 lldb::SBError sbError = sbProcess.Destroy();
1207 if (sbError.Fail()) {
1208 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_LLDBPROCESS_DESTROY),
1209 m_cmdData.strMiCmd.c_str(),
1210 sbError.GetCString()));
1211 return MIstatus::failure;
1214 return MIstatus::success;
1218 //------------------------------------------------------------------------------------
1219 // Details: The invoker requires this function. The command prepares a MI Record
1221 // for the work carried out in the Execute().
1222 // Type: Overridden.
1224 // Return: MIstatus::success - Function succeeded.
1225 // MIstatus::failure - Function failed.
1228 bool CMICmdCmdExecAbort::Acknowledge() {
1229 const CMICmnMIResultRecord miRecordResult(
1230 m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done);
1231 m_miResultRecord = miRecordResult;
1232 return MIstatus::success;
1236 //------------------------------------------------------------------------------------
1237 // Details: Required by the CMICmdFactory when registering *this command. The
1239 // calls this function to create an instance of *this command.
1240 // Type: Static method.
1242 // Return: CMICmdBase * - Pointer to a new command.
1245 CMICmdBase *CMICmdCmdExecAbort::CreateSelf() {
1246 return new CMICmdCmdExecAbort();