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 //===----------------------------------------------------------------------===//
11 // File: MICmdCmdExec.cpp
13 // Overview: CMICmdCmdExecRun implementation.
14 // CMICmdCmdExecContinue implementation.
15 // CMICmdCmdExecNext implementation.
16 // CMICmdCmdExecStep implementation.
17 // CMICmdCmdExecNextInstruction implementation.
18 // CMICmdCmdExecStepInstruction implementation.
19 // CMICmdCmdExecFinish implementation.
20 // CMICmdCmdExecInterrupt implementation.
22 // Environment: Compilers: Visual C++ 12.
23 // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
24 // Libraries: See MIReadmetxt.
29 // Third Party Headers:
30 #include <lldb/API/SBCommandInterpreter.h>
31 #include <lldb/API/SBProcess.h>
32 #include <lldb/API/SBStream.h>
33 #include "lldb/lldb-enumerations.h"
36 #include "MICmdCmdExec.h"
37 #include "MICmnMIResultRecord.h"
38 #include "MICmnMIValueConst.h"
39 #include "MICmnLLDBDebugger.h"
40 #include "MICmnLLDBDebugSessionInfo.h"
42 #include "MICmdArgValNumber.h"
43 #include "MICmdArgValString.h"
44 #include "MICmdArgValThreadGrp.h"
45 #include "MICmdArgValOptionLong.h"
46 #include "MICmdArgValOptionShort.h"
47 #include "MICmdArgValListOfN.h"
48 #include "MICmnStreamStdout.h"
49 #include "MICmnMIOutOfBandRecord.h"
51 //++ ------------------------------------------------------------------------------------
52 // Details: CMICmdCmdExecRun constructor.
58 CMICmdCmdExecRun::CMICmdCmdExecRun(void)
60 // Command factory matches this name with that received from the stdin stream
61 m_strMiCmd = "exec-run";
63 // Required by the CMICmdFactory when registering *this command
64 m_pSelfCreatorFn = &CMICmdCmdExecRun::CreateSelf;
67 //++ ------------------------------------------------------------------------------------
68 // Details: CMICmdCmdExecRun destructor.
69 // Type: Overrideable.
74 CMICmdCmdExecRun::~CMICmdCmdExecRun(void)
78 //++ ------------------------------------------------------------------------------------
79 // Details: The invoker requires this function. The command does work in this function.
80 // The command is likely to communicate with the LLDB SBDebugger in here.
83 // Return: MIstatus::success - Functional succeeded.
84 // MIstatus::failure - Functional failed.
88 CMICmdCmdExecRun::Execute(void)
90 CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance());
92 lldb::SBStream errMsg;
93 uint32_t launch_flags = lldb::LaunchFlags::eLaunchFlagDebug;
94 lldb::SBProcess process = rSessionInfo.m_lldbTarget.Launch(rSessionInfo.m_rLlldbListener, nullptr, nullptr, nullptr, nullptr, nullptr,
95 nullptr, launch_flags, false, error);
97 if ((!process.IsValid()) || (error.Fail()))
99 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INVALID_PROCESS), m_cmdData.strMiCmd.c_str(), errMsg.GetData()));
100 return MIstatus::failure;
103 // Save the process in the session info
104 rSessionInfo.m_lldbProcess = process;
106 if (!CMIDriver::Instance().SetDriverStateRunningDebugging())
108 const CMIUtilString &rErrMsg(CMIDriver::Instance().GetErrorDescription());
109 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_SET_NEW_DRIVER_STATE), m_cmdData.strMiCmd.c_str(), rErrMsg.c_str()));
110 return MIstatus::failure;
112 return MIstatus::success;
115 //++ ------------------------------------------------------------------------------------
116 // Details: The invoker requires this function. The command prepares a MI Record Result
117 // for the work carried out in the Execute().
120 // Return: MIstatus::success - Functional succeeded.
121 // MIstatus::failure - Functional failed.
125 CMICmdCmdExecRun::Acknowledge(void)
127 if (m_lldbResult.GetErrorSize() > 0)
129 const CMICmnMIValueConst miValueConst(m_lldbResult.GetError());
130 const CMICmnMIValueResult miValueResult("message", miValueConst);
131 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error, miValueResult);
132 m_miResultRecord = miRecordResult;
136 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
137 m_miResultRecord = miRecordResult;
139 CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance());
140 lldb::pid_t pid = rSessionInfo.m_lldbProcess.GetProcessID();
141 // Give the client '=thread-group-started,id="i1" pid="xyz"'
142 m_bHasResultRecordExtra = true;
143 const CMICmnMIValueConst miValueConst2("i1");
144 const CMICmnMIValueResult miValueResult2("id", miValueConst2);
145 const CMIUtilString strPid(CMIUtilString::Format("%lld", pid));
146 const CMICmnMIValueConst miValueConst(strPid);
147 const CMICmnMIValueResult miValueResult("pid", miValueConst);
148 CMICmnMIOutOfBandRecord miOutOfBand(CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupStarted, miValueResult2);
149 miOutOfBand.Add(miValueResult);
150 m_miResultRecordExtra = miOutOfBand.GetString();
153 return MIstatus::success;
156 //++ ------------------------------------------------------------------------------------
157 // Details: Required by the CMICmdFactory when registering *this command. The factory
158 // calls this function to create an instance of *this command.
159 // Type: Static method.
161 // Return: CMICmdBase * - Pointer to a new command.
165 CMICmdCmdExecRun::CreateSelf(void)
167 return new CMICmdCmdExecRun();
170 //---------------------------------------------------------------------------------------
171 //---------------------------------------------------------------------------------------
172 //---------------------------------------------------------------------------------------
174 //++ ------------------------------------------------------------------------------------
175 // Details: CMICmdCmdExecContinue constructor.
181 CMICmdCmdExecContinue::CMICmdCmdExecContinue(void)
183 // Command factory matches this name with that received from the stdin stream
184 m_strMiCmd = "exec-continue";
186 // Required by the CMICmdFactory when registering *this command
187 m_pSelfCreatorFn = &CMICmdCmdExecContinue::CreateSelf;
190 //++ ------------------------------------------------------------------------------------
191 // Details: CMICmdCmdExecContinue destructor.
192 // Type: Overrideable.
197 CMICmdCmdExecContinue::~CMICmdCmdExecContinue(void)
201 //++ ------------------------------------------------------------------------------------
202 // Details: The invoker requires this function. The command does work in this function.
203 // The command is likely to communicate with the LLDB SBDebugger in here.
206 // Return: MIstatus::success - Functional succeeded.
207 // MIstatus::failure - Functional failed.
211 CMICmdCmdExecContinue::Execute(void)
213 const MIchar *pCmd = "continue";
214 CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance());
215 const lldb::ReturnStatus rtn = rSessionInfo.m_rLldbDebugger.GetCommandInterpreter().HandleCommand(pCmd, m_lldbResult);
218 if (m_lldbResult.GetErrorSize() == 0)
220 // CODETAG_DEBUG_SESSION_RUNNING_PROG_RECEIVED_SIGINT_PAUSE_PROGRAM
221 if (!CMIDriver::Instance().SetDriverStateRunningDebugging())
223 const CMIUtilString &rErrMsg(CMIDriver::Instance().GetErrorDescription());
224 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_SET_NEW_DRIVER_STATE), m_cmdData.strMiCmd.c_str(), rErrMsg.c_str()));
225 return MIstatus::failure;
230 // ToDo: Re-evaluate if this is required when application near finished as this is parsing LLDB error message
231 // which seems a hack and is code brittle
232 const MIchar *pLldbErr = m_lldbResult.GetError();
233 const CMIUtilString strLldbMsg(CMIUtilString(pLldbErr).StripCREndOfLine());
234 if (strLldbMsg == "error: Process must be launched.")
236 CMIDriver::Instance().SetExitApplicationFlag(true);
240 return MIstatus::success;
243 //++ ------------------------------------------------------------------------------------
244 // Details: The invoker requires this function. The command prepares a MI Record Result
245 // for the work carried out in the Execute().
248 // Return: MIstatus::success - Functional succeeded.
249 // MIstatus::failure - Functional failed.
253 CMICmdCmdExecContinue::Acknowledge(void)
255 if (m_lldbResult.GetErrorSize() > 0)
257 const CMICmnMIValueConst miValueConst(m_lldbResult.GetError());
258 const CMICmnMIValueResult miValueResult("message", miValueConst);
259 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error, miValueResult);
260 m_miResultRecord = miRecordResult;
264 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
265 m_miResultRecord = miRecordResult;
268 return MIstatus::success;
271 //++ ------------------------------------------------------------------------------------
272 // Details: Required by the CMICmdFactory when registering *this command. The factory
273 // calls this function to create an instance of *this command.
274 // Type: Static method.
276 // Return: CMICmdBase * - Pointer to a new command.
280 CMICmdCmdExecContinue::CreateSelf(void)
282 return new CMICmdCmdExecContinue();
285 //---------------------------------------------------------------------------------------
286 //---------------------------------------------------------------------------------------
287 //---------------------------------------------------------------------------------------
289 //++ ------------------------------------------------------------------------------------
290 // Details: CMICmdCmdExecNext constructor.
296 CMICmdCmdExecNext::CMICmdCmdExecNext(void)
297 : m_constStrArgThread("thread")
298 , 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;
307 //++ ------------------------------------------------------------------------------------
308 // Details: CMICmdCmdExecNext destructor.
309 // Type: Overrideable.
314 CMICmdCmdExecNext::~CMICmdCmdExecNext(void)
318 //++ ------------------------------------------------------------------------------------
319 // Details: The invoker requires this function. The parses the command line options
320 // arguments to extract values for each of those arguments.
323 // Return: MIstatus::success - Functional succeeded.
324 // MIstatus::failure - Functional failed.
328 CMICmdCmdExecNext::ParseArgs(void)
331 m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgThread, true, true, CMICmdArgValListBase::eArgValType_Number, 1)));
332 bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValNumber(m_constStrArgNumber, false, false)));
333 return (bOk && ParseValidateCmdOptions());
336 //++ ------------------------------------------------------------------------------------
337 // Details: The invoker requires this function. The command does work in this function.
338 // The command is likely to communicate with the LLDB SBDebugger in here.
341 // Return: MIstatus::success - Functional succeeded.
342 // MIstatus::failure - Functional failed.
346 CMICmdCmdExecNext::Execute(void)
348 CMICMDBASE_GETOPTION(pArgThread, OptionLong, m_constStrArgThread);
350 // Retrieve the --thread option's thread ID (only 1)
351 MIuint64 nThreadId = UINT64_MAX;
352 if (!pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId))
354 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_THREAD_INVALID), m_cmdData.strMiCmd.c_str(), m_constStrArgThread.c_str()));
355 return MIstatus::failure;
358 CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance());
359 lldb::SBDebugger &rDebugger = rSessionInfo.m_rLldbDebugger;
360 CMIUtilString strCmd("thread step-over");
361 if (nThreadId != UINT64_MAX)
362 strCmd += CMIUtilString::Format(" %llu", nThreadId);
363 rDebugger.GetCommandInterpreter().HandleCommand(strCmd.c_str(), m_lldbResult, false);
365 return MIstatus::success;
368 //++ ------------------------------------------------------------------------------------
369 // Details: The invoker requires this function. The command prepares a MI Record Result
370 // for the work carried out in the Execute().
373 // Return: MIstatus::success - Functional succeeded.
374 // MIstatus::failure - Functional failed.
378 CMICmdCmdExecNext::Acknowledge(void)
380 if (m_lldbResult.GetErrorSize() > 0)
382 const MIchar *pLldbErr = m_lldbResult.GetError();
384 const CMICmnMIValueConst miValueConst(m_lldbResult.GetError());
385 const CMICmnMIValueResult miValueResult("message", miValueConst);
386 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error, miValueResult);
387 m_miResultRecord = miRecordResult;
391 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
392 m_miResultRecord = miRecordResult;
395 return MIstatus::success;
398 //++ ------------------------------------------------------------------------------------
399 // Details: Required by the CMICmdFactory when registering *this command. The factory
400 // calls this function to create an instance of *this command.
401 // Type: Static method.
403 // Return: CMICmdBase * - Pointer to a new command.
407 CMICmdCmdExecNext::CreateSelf(void)
409 return new CMICmdCmdExecNext();
412 //---------------------------------------------------------------------------------------
413 //---------------------------------------------------------------------------------------
414 //---------------------------------------------------------------------------------------
416 //++ ------------------------------------------------------------------------------------
417 // Details: CMICmdCmdExecStep constructor.
423 CMICmdCmdExecStep::CMICmdCmdExecStep(void)
424 : m_constStrArgThread("thread")
425 , m_constStrArgNumber("number")
427 // Command factory matches this name with that received from the stdin stream
428 m_strMiCmd = "exec-step";
430 // Required by the CMICmdFactory when registering *this command
431 m_pSelfCreatorFn = &CMICmdCmdExecStep::CreateSelf;
434 //++ ------------------------------------------------------------------------------------
435 // Details: CMICmdCmdExecStep destructor.
436 // Type: Overrideable.
441 CMICmdCmdExecStep::~CMICmdCmdExecStep(void)
445 //++ ------------------------------------------------------------------------------------
446 // Details: The invoker requires this function. The parses the command line options
447 // arguments to extract values for each of those arguments.
450 // Return: MIstatus::success - Functional succeeded.
451 // MIstatus::failure - Functional failed.
455 CMICmdCmdExecStep::ParseArgs(void)
458 m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgThread, true, true, CMICmdArgValListBase::eArgValType_Number, 1)));
459 bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValNumber(m_constStrArgNumber, false, false)));
460 return (bOk && ParseValidateCmdOptions());
463 //++ ------------------------------------------------------------------------------------
464 // Details: The invoker requires this function. The command does work in this function.
465 // The command is likely to communicate with the LLDB SBDebugger in here.
468 // Return: MIstatus::success - Functional succeeded.
469 // MIstatus::failure - Functional failed.
473 CMICmdCmdExecStep::Execute(void)
475 CMICMDBASE_GETOPTION(pArgThread, OptionLong, m_constStrArgThread);
477 // Retrieve the --thread option's thread ID (only 1)
478 MIuint64 nThreadId = UINT64_MAX;
479 if (!pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId))
481 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND), m_cmdData.strMiCmd.c_str(), m_constStrArgThread.c_str()));
482 return MIstatus::failure;
485 CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance());
486 lldb::SBDebugger &rDebugger = rSessionInfo.m_rLldbDebugger;
487 CMIUtilString strCmd("thread step-in");
488 if (nThreadId != UINT64_MAX)
489 strCmd += CMIUtilString::Format(" %llu", nThreadId);
490 rDebugger.GetCommandInterpreter().HandleCommand(strCmd.c_str(), m_lldbResult, false);
492 return MIstatus::success;
495 //++ ------------------------------------------------------------------------------------
496 // Details: The invoker requires this function. The command prepares a MI Record Result
497 // for the work carried out in the Execute().
500 // Return: MIstatus::success - Functional succeeded.
501 // MIstatus::failure - Functional failed.
505 CMICmdCmdExecStep::Acknowledge(void)
507 if (m_lldbResult.GetErrorSize() > 0)
509 const MIchar *pLldbErr = m_lldbResult.GetError();
511 const CMICmnMIValueConst miValueConst(m_lldbResult.GetError());
512 const CMICmnMIValueResult miValueResult("message", miValueConst);
513 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error, miValueResult);
514 m_miResultRecord = miRecordResult;
518 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
519 m_miResultRecord = miRecordResult;
522 return MIstatus::success;
525 //++ ------------------------------------------------------------------------------------
526 // Details: Required by the CMICmdFactory when registering *this command. The factory
527 // calls this function to create an instance of *this command.
528 // Type: Static method.
530 // Return: CMICmdBase * - Pointer to a new command.
534 CMICmdCmdExecStep::CreateSelf(void)
536 return new CMICmdCmdExecStep();
539 //---------------------------------------------------------------------------------------
540 //---------------------------------------------------------------------------------------
541 //---------------------------------------------------------------------------------------
543 //++ ------------------------------------------------------------------------------------
544 // Details: CMICmdCmdExecNextInstruction constructor.
550 CMICmdCmdExecNextInstruction::CMICmdCmdExecNextInstruction(void)
551 : m_constStrArgThread("thread")
552 , m_constStrArgNumber("number")
554 // Command factory matches this name with that received from the stdin stream
555 m_strMiCmd = "exec-next-instruction";
557 // Required by the CMICmdFactory when registering *this command
558 m_pSelfCreatorFn = &CMICmdCmdExecNextInstruction::CreateSelf;
561 //++ ------------------------------------------------------------------------------------
562 // Details: CMICmdCmdExecNextInstruction destructor.
563 // Type: Overrideable.
568 CMICmdCmdExecNextInstruction::~CMICmdCmdExecNextInstruction(void)
572 //++ ------------------------------------------------------------------------------------
573 // Details: The invoker requires this function. The parses the command line options
574 // arguments to extract values for each of those arguments.
577 // Return: MIstatus::success - Functional succeeded.
578 // MIstatus::failure - Functional failed.
582 CMICmdCmdExecNextInstruction::ParseArgs(void)
585 m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgThread, true, true, CMICmdArgValListBase::eArgValType_Number, 1)));
586 bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValNumber(m_constStrArgNumber, false, false)));
587 return (bOk && ParseValidateCmdOptions());
590 //++ ------------------------------------------------------------------------------------
591 // Details: The invoker requires this function. The command does work in this function.
592 // The command is likely to communicate with the LLDB SBDebugger in here.
595 // Return: MIstatus::success - Functional succeeded.
596 // MIstatus::failure - Functional failed.
600 CMICmdCmdExecNextInstruction::Execute(void)
602 CMICMDBASE_GETOPTION(pArgThread, OptionLong, m_constStrArgThread);
604 // Retrieve the --thread option's thread ID (only 1)
605 MIuint64 nThreadId = UINT64_MAX;
606 if (!pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId))
608 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND), m_cmdData.strMiCmd.c_str(), m_constStrArgThread.c_str()));
609 return MIstatus::failure;
612 CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance());
613 lldb::SBDebugger &rDebugger = rSessionInfo.m_rLldbDebugger;
614 CMIUtilString strCmd("thread step-inst-over");
615 if (nThreadId != UINT64_MAX)
616 strCmd += CMIUtilString::Format(" %llu", nThreadId);
617 rDebugger.GetCommandInterpreter().HandleCommand(strCmd.c_str(), m_lldbResult, false);
619 return MIstatus::success;
622 //++ ------------------------------------------------------------------------------------
623 // Details: The invoker requires this function. The command prepares a MI Record Result
624 // for the work carried out in the Execute().
627 // Return: MIstatus::success - Functional succeeded.
628 // MIstatus::failure - Functional failed.
632 CMICmdCmdExecNextInstruction::Acknowledge(void)
634 if (m_lldbResult.GetErrorSize() > 0)
636 const MIchar *pLldbErr = m_lldbResult.GetError();
638 const CMICmnMIValueConst miValueConst(m_lldbResult.GetError());
639 const CMICmnMIValueResult miValueResult("message", miValueConst);
640 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error, miValueResult);
641 m_miResultRecord = miRecordResult;
645 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
646 m_miResultRecord = miRecordResult;
649 return MIstatus::success;
652 //++ ------------------------------------------------------------------------------------
653 // Details: Required by the CMICmdFactory when registering *this command. The factory
654 // calls this function to create an instance of *this command.
655 // Type: Static method.
657 // Return: CMICmdBase * - Pointer to a new command.
661 CMICmdCmdExecNextInstruction::CreateSelf(void)
663 return new CMICmdCmdExecNextInstruction();
666 //---------------------------------------------------------------------------------------
667 //---------------------------------------------------------------------------------------
668 //---------------------------------------------------------------------------------------
670 //++ ------------------------------------------------------------------------------------
671 // Details: CMICmdCmdExecStepInstruction constructor.
677 CMICmdCmdExecStepInstruction::CMICmdCmdExecStepInstruction(void)
678 : m_constStrArgThread("thread")
679 , m_constStrArgNumber("number")
681 // Command factory matches this name with that received from the stdin stream
682 m_strMiCmd = "exec-step-instruction";
684 // Required by the CMICmdFactory when registering *this command
685 m_pSelfCreatorFn = &CMICmdCmdExecStepInstruction::CreateSelf;
688 //++ ------------------------------------------------------------------------------------
689 // Details: CMICmdCmdExecStepInstruction destructor.
690 // Type: Overrideable.
695 CMICmdCmdExecStepInstruction::~CMICmdCmdExecStepInstruction(void)
699 //++ ------------------------------------------------------------------------------------
700 // Details: The invoker requires this function. The parses the command line options
701 // arguments to extract values for each of those arguments.
704 // Return: MIstatus::success - Functional succeeded.
705 // MIstatus::failure - Functional failed.
709 CMICmdCmdExecStepInstruction::ParseArgs(void)
712 m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgThread, true, true, CMICmdArgValListBase::eArgValType_Number, 1)));
713 bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValNumber(m_constStrArgNumber, false, false)));
714 return (bOk && ParseValidateCmdOptions());
717 //++ ------------------------------------------------------------------------------------
718 // Details: The invoker requires this function. The command does work in this function.
719 // The command is likely to communicate with the LLDB SBDebugger in here.
722 // Return: MIstatus::success - Functional succeeded.
723 // MIstatus::failure - Functional failed.
727 CMICmdCmdExecStepInstruction::Execute(void)
729 CMICMDBASE_GETOPTION(pArgThread, OptionLong, m_constStrArgThread);
731 // Retrieve the --thread option's thread ID (only 1)
732 MIuint64 nThreadId = UINT64_MAX;
733 if (!pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId))
735 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND), m_cmdData.strMiCmd.c_str(), m_constStrArgThread.c_str()));
736 return MIstatus::failure;
739 CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance());
740 lldb::SBDebugger &rDebugger = rSessionInfo.m_rLldbDebugger;
741 CMIUtilString strCmd("thread step-inst");
742 if (nThreadId != UINT64_MAX)
743 strCmd += CMIUtilString::Format(" %llu", nThreadId);
744 rDebugger.GetCommandInterpreter().HandleCommand(strCmd.c_str(), m_lldbResult, false);
746 return MIstatus::success;
749 //++ ------------------------------------------------------------------------------------
750 // Details: The invoker requires this function. The command prepares a MI Record Result
751 // for the work carried out in the Execute().
754 // Return: MIstatus::success - Functional succeeded.
755 // MIstatus::failure - Functional failed.
759 CMICmdCmdExecStepInstruction::Acknowledge(void)
761 if (m_lldbResult.GetErrorSize() > 0)
763 const MIchar *pLldbErr = m_lldbResult.GetError();
765 const CMICmnMIValueConst miValueConst(m_lldbResult.GetError());
766 const CMICmnMIValueResult miValueResult("message", miValueConst);
767 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error, miValueResult);
768 m_miResultRecord = miRecordResult;
772 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
773 m_miResultRecord = miRecordResult;
776 return MIstatus::success;
779 //++ ------------------------------------------------------------------------------------
780 // Details: Required by the CMICmdFactory when registering *this command. The factory
781 // calls this function to create an instance of *this command.
782 // Type: Static method.
784 // Return: CMICmdBase * - Pointer to a new command.
788 CMICmdCmdExecStepInstruction::CreateSelf(void)
790 return new CMICmdCmdExecStepInstruction();
793 //---------------------------------------------------------------------------------------
794 //---------------------------------------------------------------------------------------
795 //---------------------------------------------------------------------------------------
797 //++ ------------------------------------------------------------------------------------
798 // Details: CMICmdCmdExecFinish constructor.
804 CMICmdCmdExecFinish::CMICmdCmdExecFinish(void)
805 : m_constStrArgThread("thread")
806 , m_constStrArgFrame("frame")
808 // Command factory matches this name with that received from the stdin stream
809 m_strMiCmd = "exec-finish";
811 // Required by the CMICmdFactory when registering *this command
812 m_pSelfCreatorFn = &CMICmdCmdExecFinish::CreateSelf;
815 //++ ------------------------------------------------------------------------------------
816 // Details: CMICmdCmdExecFinish destructor.
817 // Type: Overrideable.
822 CMICmdCmdExecFinish::~CMICmdCmdExecFinish(void)
826 //++ ------------------------------------------------------------------------------------
827 // Details: The invoker requires this function. The parses the command line options
828 // arguments to extract values for each of those arguments.
831 // Return: MIstatus::success - Functional succeeded.
832 // MIstatus::failure - Functional failed.
836 CMICmdCmdExecFinish::ParseArgs(void)
839 m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgThread, true, true, CMICmdArgValListBase::eArgValType_Number, 1)));
841 m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgFrame, false, false, CMICmdArgValListBase::eArgValType_Number, 1)));
842 return (bOk && ParseValidateCmdOptions());
845 //++ ------------------------------------------------------------------------------------
846 // Details: The invoker requires this function. The command does work in this function.
847 // The command is likely to communicate with the LLDB SBDebugger in here.
850 // Return: MIstatus::success - Functional succeeded.
851 // MIstatus::failure - Functional failed.
855 CMICmdCmdExecFinish::Execute(void)
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->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId))
863 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND), m_cmdData.strMiCmd.c_str(), m_constStrArgThread.c_str()));
864 return MIstatus::failure;
867 CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance());
868 lldb::SBDebugger &rDebugger = rSessionInfo.m_rLldbDebugger;
869 CMIUtilString strCmd("thread step-out");
870 if (nThreadId != UINT64_MAX)
871 strCmd += CMIUtilString::Format(" %llu", nThreadId);
872 rDebugger.GetCommandInterpreter().HandleCommand(strCmd.c_str(), m_lldbResult, false);
874 return MIstatus::success;
877 //++ ------------------------------------------------------------------------------------
878 // Details: The invoker requires this function. The command prepares a MI Record Result
879 // for the work carried out in the Execute().
882 // Return: MIstatus::success - Functional succeeded.
883 // MIstatus::failure - Functional failed.
887 CMICmdCmdExecFinish::Acknowledge(void)
889 if (m_lldbResult.GetErrorSize() > 0)
891 const MIchar *pLldbErr = m_lldbResult.GetError();
893 const CMICmnMIValueConst miValueConst(m_lldbResult.GetError());
894 const CMICmnMIValueResult miValueResult("message", miValueConst);
895 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error, miValueResult);
896 m_miResultRecord = miRecordResult;
900 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
901 m_miResultRecord = miRecordResult;
904 return MIstatus::success;
907 //++ ------------------------------------------------------------------------------------
908 // Details: Required by the CMICmdFactory when registering *this command. The factory
909 // calls this function to create an instance of *this command.
910 // Type: Static method.
912 // Return: CMICmdBase * - Pointer to a new command.
916 CMICmdCmdExecFinish::CreateSelf(void)
918 return new CMICmdCmdExecFinish();
921 //---------------------------------------------------------------------------------------
922 //---------------------------------------------------------------------------------------
923 //---------------------------------------------------------------------------------------
925 //++ ------------------------------------------------------------------------------------
926 // Details: CMICmdCmdExecInterrupt constructor.
932 CMICmdCmdExecInterrupt::CMICmdCmdExecInterrupt(void)
934 // Command factory matches this name with that received from the stdin stream
935 m_strMiCmd = "exec-interrupt";
937 // Required by the CMICmdFactory when registering *this command
938 m_pSelfCreatorFn = &CMICmdCmdExecInterrupt::CreateSelf;
941 //++ ------------------------------------------------------------------------------------
942 // Details: CMICmdCmdExecInterrupt destructor.
943 // Type: Overrideable.
948 CMICmdCmdExecInterrupt::~CMICmdCmdExecInterrupt(void)
952 //++ ------------------------------------------------------------------------------------
953 // Details: The invoker requires this function. The command does work in this function.
954 // The command is likely to communicate with the LLDB SBDebugger in here.
957 // Return: MIstatus::success - Functional succeeded.
958 // MIstatus::failure - Functional failed.
962 CMICmdCmdExecInterrupt::Execute(void)
964 CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance());
965 lldb::SBDebugger &rDebugger = rSessionInfo.m_rLldbDebugger;
966 CMIUtilString strCmd("process interrupt");
967 const lldb::ReturnStatus status = rDebugger.GetCommandInterpreter().HandleCommand(strCmd.c_str(), m_lldbResult, false);
970 // CODETAG_DEBUG_SESSION_RUNNING_PROG_RECEIVED_SIGINT_PAUSE_PROGRAM
971 if (!CMIDriver::Instance().SetDriverStateRunningNotDebugging())
973 const CMIUtilString &rErrMsg(CMIDriver::Instance().GetErrorDescription());
974 SetErrorDescription(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_SET_NEW_DRIVER_STATE), strCmd.c_str(), rErrMsg.c_str()));
975 return MIstatus::failure;
978 return MIstatus::success;
981 //++ ------------------------------------------------------------------------------------
982 // Details: The invoker requires this function. The command prepares a MI Record Result
983 // for the work carried out in the Execute().
986 // Return: MIstatus::success - Functional succeeded.
987 // MIstatus::failure - Functional failed.
991 CMICmdCmdExecInterrupt::Acknowledge(void)
993 if (m_lldbResult.GetErrorSize() > 0)
995 const CMICmnMIValueConst miValueConst(m_lldbResult.GetError());
996 const CMICmnMIValueResult miValueResult("message", miValueConst);
997 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error, miValueResult);
998 m_miResultRecord = miRecordResult;
1002 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done);
1003 m_miResultRecord = miRecordResult;
1006 return MIstatus::success;
1009 //++ ------------------------------------------------------------------------------------
1010 // Details: Required by the CMICmdFactory when registering *this command. The factory
1011 // calls this function to create an instance of *this command.
1012 // Type: Static method.
1014 // Return: CMICmdBase * - Pointer to a new command.
1018 CMICmdCmdExecInterrupt::CreateSelf(void)
1020 return new CMICmdCmdExecInterrupt();