]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmdCmdExec.cpp
MFV r288408:
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MICmdCmdExec.cpp
1 //===-- MICmdCmdExec.cpp ----------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 //++
11 // File:        MICmdCmdExec.cpp
12 //
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.
21 //
22 // Environment: Compilers:  Visual C++ 12.
23 //                          gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
24 //              Libraries:  See MIReadmetxt.
25 //
26 // Copyright:   None.
27 //--
28
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"
34
35 // In-house headers:
36 #include "MICmdCmdExec.h"
37 #include "MICmnMIResultRecord.h"
38 #include "MICmnMIValueConst.h"
39 #include "MICmnLLDBDebugger.h"
40 #include "MICmnLLDBDebugSessionInfo.h"
41 #include "MIDriver.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"
50
51 //++ ------------------------------------------------------------------------------------
52 // Details: CMICmdCmdExecRun constructor.
53 // Type:    Method.
54 // Args:    None.
55 // Return:  None.
56 // Throws:  None.
57 //--
58 CMICmdCmdExecRun::CMICmdCmdExecRun(void)
59 {
60     // Command factory matches this name with that received from the stdin stream
61     m_strMiCmd = "exec-run";
62
63     // Required by the CMICmdFactory when registering *this command
64     m_pSelfCreatorFn = &CMICmdCmdExecRun::CreateSelf;
65 }
66
67 //++ ------------------------------------------------------------------------------------
68 // Details: CMICmdCmdExecRun destructor.
69 // Type:    Overrideable.
70 // Args:    None.
71 // Return:  None.
72 // Throws:  None.
73 //--
74 CMICmdCmdExecRun::~CMICmdCmdExecRun(void)
75 {
76 }
77
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.
81 // Type:    Overridden.
82 // Args:    None.
83 // Return:  MIstatus::success - Functional succeeded.
84 //          MIstatus::failure - Functional failed.
85 // Throws:  None.
86 //--
87 bool
88 CMICmdCmdExecRun::Execute(void)
89 {
90     CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance());
91     lldb::SBError error;
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);
96
97     if ((!process.IsValid()) || (error.Fail()))
98     {
99         SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INVALID_PROCESS), m_cmdData.strMiCmd.c_str(), errMsg.GetData()));
100         return MIstatus::failure;
101     }
102
103     // Save the process in the session info
104     rSessionInfo.m_lldbProcess = process;
105
106     if (!CMIDriver::Instance().SetDriverStateRunningDebugging())
107     {
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;
111     }
112     return MIstatus::success;
113 }
114
115 //++ ------------------------------------------------------------------------------------
116 // Details: The invoker requires this function. The command prepares a MI Record Result
117 //          for the work carried out in the Execute().
118 // Type:    Overridden.
119 // Args:    None.
120 // Return:  MIstatus::success - Functional succeeded.
121 //          MIstatus::failure - Functional failed.
122 // Throws:  None.
123 //--
124 bool
125 CMICmdCmdExecRun::Acknowledge(void)
126 {
127     if (m_lldbResult.GetErrorSize() > 0)
128     {
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;
133     }
134     else
135     {
136         const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
137         m_miResultRecord = miRecordResult;
138
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();
151     }
152
153     return MIstatus::success;
154 }
155
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.
160 // Args:    None.
161 // Return:  CMICmdBase * - Pointer to a new command.
162 // Throws:  None.
163 //--
164 CMICmdBase *
165 CMICmdCmdExecRun::CreateSelf(void)
166 {
167     return new CMICmdCmdExecRun();
168 }
169
170 //---------------------------------------------------------------------------------------
171 //---------------------------------------------------------------------------------------
172 //---------------------------------------------------------------------------------------
173
174 //++ ------------------------------------------------------------------------------------
175 // Details: CMICmdCmdExecContinue constructor.
176 // Type:    Method.
177 // Args:    None.
178 // Return:  None.
179 // Throws:  None.
180 //--
181 CMICmdCmdExecContinue::CMICmdCmdExecContinue(void)
182 {
183     // Command factory matches this name with that received from the stdin stream
184     m_strMiCmd = "exec-continue";
185
186     // Required by the CMICmdFactory when registering *this command
187     m_pSelfCreatorFn = &CMICmdCmdExecContinue::CreateSelf;
188 }
189
190 //++ ------------------------------------------------------------------------------------
191 // Details: CMICmdCmdExecContinue destructor.
192 // Type:    Overrideable.
193 // Args:    None.
194 // Return:  None.
195 // Throws:  None.
196 //--
197 CMICmdCmdExecContinue::~CMICmdCmdExecContinue(void)
198 {
199 }
200
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.
204 // Type:    Overridden.
205 // Args:    None.
206 // Return:  MIstatus::success - Functional succeeded.
207 //          MIstatus::failure - Functional failed.
208 // Throws:  None.
209 //--
210 bool
211 CMICmdCmdExecContinue::Execute(void)
212 {
213     const MIchar *pCmd = "continue";
214     CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance());
215     const lldb::ReturnStatus rtn = rSessionInfo.m_rLldbDebugger.GetCommandInterpreter().HandleCommand(pCmd, m_lldbResult);
216     MIunused(rtn);
217
218     if (m_lldbResult.GetErrorSize() == 0)
219     {
220         // CODETAG_DEBUG_SESSION_RUNNING_PROG_RECEIVED_SIGINT_PAUSE_PROGRAM
221         if (!CMIDriver::Instance().SetDriverStateRunningDebugging())
222         {
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;
226         }
227     }
228     else
229     {
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.")
235         {
236             CMIDriver::Instance().SetExitApplicationFlag(true);
237         }
238     }
239
240     return MIstatus::success;
241 }
242
243 //++ ------------------------------------------------------------------------------------
244 // Details: The invoker requires this function. The command prepares a MI Record Result
245 //          for the work carried out in the Execute().
246 // Type:    Overridden.
247 // Args:    None.
248 // Return:  MIstatus::success - Functional succeeded.
249 //          MIstatus::failure - Functional failed.
250 // Throws:  None.
251 //--
252 bool
253 CMICmdCmdExecContinue::Acknowledge(void)
254 {
255     if (m_lldbResult.GetErrorSize() > 0)
256     {
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;
261     }
262     else
263     {
264         const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
265         m_miResultRecord = miRecordResult;
266     }
267
268     return MIstatus::success;
269 }
270
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.
275 // Args:    None.
276 // Return:  CMICmdBase * - Pointer to a new command.
277 // Throws:  None.
278 //--
279 CMICmdBase *
280 CMICmdCmdExecContinue::CreateSelf(void)
281 {
282     return new CMICmdCmdExecContinue();
283 }
284
285 //---------------------------------------------------------------------------------------
286 //---------------------------------------------------------------------------------------
287 //---------------------------------------------------------------------------------------
288
289 //++ ------------------------------------------------------------------------------------
290 // Details: CMICmdCmdExecNext constructor.
291 // Type:    Method.
292 // Args:    None.
293 // Return:  None.
294 // Throws:  None.
295 //--
296 CMICmdCmdExecNext::CMICmdCmdExecNext(void)
297     : m_constStrArgThread("thread")
298     , m_constStrArgNumber("number")
299 {
300     // Command factory matches this name with that received from the stdin stream
301     m_strMiCmd = "exec-next";
302
303     // Required by the CMICmdFactory when registering *this command
304     m_pSelfCreatorFn = &CMICmdCmdExecNext::CreateSelf;
305 }
306
307 //++ ------------------------------------------------------------------------------------
308 // Details: CMICmdCmdExecNext destructor.
309 // Type:    Overrideable.
310 // Args:    None.
311 // Return:  None.
312 // Throws:  None.
313 //--
314 CMICmdCmdExecNext::~CMICmdCmdExecNext(void)
315 {
316 }
317
318 //++ ------------------------------------------------------------------------------------
319 // Details: The invoker requires this function. The parses the command line options
320 //          arguments to extract values for each of those arguments.
321 // Type:    Overridden.
322 // Args:    None.
323 // Return:  MIstatus::success - Functional succeeded.
324 //          MIstatus::failure - Functional failed.
325 // Throws:  None.
326 //--
327 bool
328 CMICmdCmdExecNext::ParseArgs(void)
329 {
330     bool bOk =
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());
334 }
335
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.
339 // Type:    Overridden.
340 // Args:    None.
341 // Return:  MIstatus::success - Functional succeeded.
342 //          MIstatus::failure - Functional failed.
343 // Throws:  None.
344 //--
345 bool
346 CMICmdCmdExecNext::Execute(void)
347 {
348     CMICMDBASE_GETOPTION(pArgThread, OptionLong, m_constStrArgThread);
349
350     // Retrieve the --thread option's thread ID (only 1)
351     MIuint64 nThreadId = UINT64_MAX;
352     if (!pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId))
353     {
354         SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_THREAD_INVALID), m_cmdData.strMiCmd.c_str(), m_constStrArgThread.c_str()));
355         return MIstatus::failure;
356     }
357
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);
364
365     return MIstatus::success;
366 }
367
368 //++ ------------------------------------------------------------------------------------
369 // Details: The invoker requires this function. The command prepares a MI Record Result
370 //          for the work carried out in the Execute().
371 // Type:    Overridden.
372 // Args:    None.
373 // Return:  MIstatus::success - Functional succeeded.
374 //          MIstatus::failure - Functional failed.
375 // Throws:  None.
376 //--
377 bool
378 CMICmdCmdExecNext::Acknowledge(void)
379 {
380     if (m_lldbResult.GetErrorSize() > 0)
381     {
382         const MIchar *pLldbErr = m_lldbResult.GetError();
383         MIunused(pLldbErr);
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;
388     }
389     else
390     {
391         const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
392         m_miResultRecord = miRecordResult;
393     }
394
395     return MIstatus::success;
396 }
397
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.
402 // Args:    None.
403 // Return:  CMICmdBase * - Pointer to a new command.
404 // Throws:  None.
405 //--
406 CMICmdBase *
407 CMICmdCmdExecNext::CreateSelf(void)
408 {
409     return new CMICmdCmdExecNext();
410 }
411
412 //---------------------------------------------------------------------------------------
413 //---------------------------------------------------------------------------------------
414 //---------------------------------------------------------------------------------------
415
416 //++ ------------------------------------------------------------------------------------
417 // Details: CMICmdCmdExecStep constructor.
418 // Type:    Method.
419 // Args:    None.
420 // Return:  None.
421 // Throws:  None.
422 //--
423 CMICmdCmdExecStep::CMICmdCmdExecStep(void)
424     : m_constStrArgThread("thread")
425     , m_constStrArgNumber("number")
426 {
427     // Command factory matches this name with that received from the stdin stream
428     m_strMiCmd = "exec-step";
429
430     // Required by the CMICmdFactory when registering *this command
431     m_pSelfCreatorFn = &CMICmdCmdExecStep::CreateSelf;
432 }
433
434 //++ ------------------------------------------------------------------------------------
435 // Details: CMICmdCmdExecStep destructor.
436 // Type:    Overrideable.
437 // Args:    None.
438 // Return:  None.
439 // Throws:  None.
440 //--
441 CMICmdCmdExecStep::~CMICmdCmdExecStep(void)
442 {
443 }
444
445 //++ ------------------------------------------------------------------------------------
446 // Details: The invoker requires this function. The parses the command line options
447 //          arguments to extract values for each of those arguments.
448 // Type:    Overridden.
449 // Args:    None.
450 // Return:  MIstatus::success - Functional succeeded.
451 //          MIstatus::failure - Functional failed.
452 // Throws:  None.
453 //--
454 bool
455 CMICmdCmdExecStep::ParseArgs(void)
456 {
457     bool bOk =
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());
461 }
462
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.
466 // Type:    Overridden.
467 // Args:    None.
468 // Return:  MIstatus::success - Functional succeeded.
469 //          MIstatus::failure - Functional failed.
470 // Throws:  None.
471 //--
472 bool
473 CMICmdCmdExecStep::Execute(void)
474 {
475     CMICMDBASE_GETOPTION(pArgThread, OptionLong, m_constStrArgThread);
476
477     // Retrieve the --thread option's thread ID (only 1)
478     MIuint64 nThreadId = UINT64_MAX;
479     if (!pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId))
480     {
481         SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND), m_cmdData.strMiCmd.c_str(), m_constStrArgThread.c_str()));
482         return MIstatus::failure;
483     }
484
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);
491
492     return MIstatus::success;
493 }
494
495 //++ ------------------------------------------------------------------------------------
496 // Details: The invoker requires this function. The command prepares a MI Record Result
497 //          for the work carried out in the Execute().
498 // Type:    Overridden.
499 // Args:    None.
500 // Return:  MIstatus::success - Functional succeeded.
501 //          MIstatus::failure - Functional failed.
502 // Throws:  None.
503 //--
504 bool
505 CMICmdCmdExecStep::Acknowledge(void)
506 {
507     if (m_lldbResult.GetErrorSize() > 0)
508     {
509         const MIchar *pLldbErr = m_lldbResult.GetError();
510         MIunused(pLldbErr);
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;
515     }
516     else
517     {
518         const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
519         m_miResultRecord = miRecordResult;
520     }
521
522     return MIstatus::success;
523 }
524
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.
529 // Args:    None.
530 // Return:  CMICmdBase * - Pointer to a new command.
531 // Throws:  None.
532 //--
533 CMICmdBase *
534 CMICmdCmdExecStep::CreateSelf(void)
535 {
536     return new CMICmdCmdExecStep();
537 }
538
539 //---------------------------------------------------------------------------------------
540 //---------------------------------------------------------------------------------------
541 //---------------------------------------------------------------------------------------
542
543 //++ ------------------------------------------------------------------------------------
544 // Details: CMICmdCmdExecNextInstruction constructor.
545 // Type:    Method.
546 // Args:    None.
547 // Return:  None.
548 // Throws:  None.
549 //--
550 CMICmdCmdExecNextInstruction::CMICmdCmdExecNextInstruction(void)
551     : m_constStrArgThread("thread")
552     , m_constStrArgNumber("number")
553 {
554     // Command factory matches this name with that received from the stdin stream
555     m_strMiCmd = "exec-next-instruction";
556
557     // Required by the CMICmdFactory when registering *this command
558     m_pSelfCreatorFn = &CMICmdCmdExecNextInstruction::CreateSelf;
559 }
560
561 //++ ------------------------------------------------------------------------------------
562 // Details: CMICmdCmdExecNextInstruction destructor.
563 // Type:    Overrideable.
564 // Args:    None.
565 // Return:  None.
566 // Throws:  None.
567 //--
568 CMICmdCmdExecNextInstruction::~CMICmdCmdExecNextInstruction(void)
569 {
570 }
571
572 //++ ------------------------------------------------------------------------------------
573 // Details: The invoker requires this function. The parses the command line options
574 //          arguments to extract values for each of those arguments.
575 // Type:    Overridden.
576 // Args:    None.
577 // Return:  MIstatus::success - Functional succeeded.
578 //          MIstatus::failure - Functional failed.
579 // Throws:  None.
580 //--
581 bool
582 CMICmdCmdExecNextInstruction::ParseArgs(void)
583 {
584     bool bOk =
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());
588 }
589
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.
593 // Type:    Overridden.
594 // Args:    None.
595 // Return:  MIstatus::success - Functional succeeded.
596 //          MIstatus::failure - Functional failed.
597 // Throws:  None.
598 //--
599 bool
600 CMICmdCmdExecNextInstruction::Execute(void)
601 {
602     CMICMDBASE_GETOPTION(pArgThread, OptionLong, m_constStrArgThread);
603
604     // Retrieve the --thread option's thread ID (only 1)
605     MIuint64 nThreadId = UINT64_MAX;
606     if (!pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId))
607     {
608         SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND), m_cmdData.strMiCmd.c_str(), m_constStrArgThread.c_str()));
609         return MIstatus::failure;
610     }
611
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);
618
619     return MIstatus::success;
620 }
621
622 //++ ------------------------------------------------------------------------------------
623 // Details: The invoker requires this function. The command prepares a MI Record Result
624 //          for the work carried out in the Execute().
625 // Type:    Overridden.
626 // Args:    None.
627 // Return:  MIstatus::success - Functional succeeded.
628 //          MIstatus::failure - Functional failed.
629 // Throws:  None.
630 //--
631 bool
632 CMICmdCmdExecNextInstruction::Acknowledge(void)
633 {
634     if (m_lldbResult.GetErrorSize() > 0)
635     {
636         const MIchar *pLldbErr = m_lldbResult.GetError();
637         MIunused(pLldbErr);
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;
642     }
643     else
644     {
645         const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
646         m_miResultRecord = miRecordResult;
647     }
648
649     return MIstatus::success;
650 }
651
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.
656 // Args:    None.
657 // Return:  CMICmdBase * - Pointer to a new command.
658 // Throws:  None.
659 //--
660 CMICmdBase *
661 CMICmdCmdExecNextInstruction::CreateSelf(void)
662 {
663     return new CMICmdCmdExecNextInstruction();
664 }
665
666 //---------------------------------------------------------------------------------------
667 //---------------------------------------------------------------------------------------
668 //---------------------------------------------------------------------------------------
669
670 //++ ------------------------------------------------------------------------------------
671 // Details: CMICmdCmdExecStepInstruction constructor.
672 // Type:    Method.
673 // Args:    None.
674 // Return:  None.
675 // Throws:  None.
676 //--
677 CMICmdCmdExecStepInstruction::CMICmdCmdExecStepInstruction(void)
678     : m_constStrArgThread("thread")
679     , m_constStrArgNumber("number")
680 {
681     // Command factory matches this name with that received from the stdin stream
682     m_strMiCmd = "exec-step-instruction";
683
684     // Required by the CMICmdFactory when registering *this command
685     m_pSelfCreatorFn = &CMICmdCmdExecStepInstruction::CreateSelf;
686 }
687
688 //++ ------------------------------------------------------------------------------------
689 // Details: CMICmdCmdExecStepInstruction destructor.
690 // Type:    Overrideable.
691 // Args:    None.
692 // Return:  None.
693 // Throws:  None.
694 //--
695 CMICmdCmdExecStepInstruction::~CMICmdCmdExecStepInstruction(void)
696 {
697 }
698
699 //++ ------------------------------------------------------------------------------------
700 // Details: The invoker requires this function. The parses the command line options
701 //          arguments to extract values for each of those arguments.
702 // Type:    Overridden.
703 // Args:    None.
704 // Return:  MIstatus::success - Functional succeeded.
705 //          MIstatus::failure - Functional failed.
706 // Throws:  None.
707 //--
708 bool
709 CMICmdCmdExecStepInstruction::ParseArgs(void)
710 {
711     bool bOk =
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());
715 }
716
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.
720 // Type:    Overridden.
721 // Args:    None.
722 // Return:  MIstatus::success - Functional succeeded.
723 //          MIstatus::failure - Functional failed.
724 // Throws:  None.
725 //--
726 bool
727 CMICmdCmdExecStepInstruction::Execute(void)
728 {
729     CMICMDBASE_GETOPTION(pArgThread, OptionLong, m_constStrArgThread);
730
731     // Retrieve the --thread option's thread ID (only 1)
732     MIuint64 nThreadId = UINT64_MAX;
733     if (!pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId))
734     {
735         SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND), m_cmdData.strMiCmd.c_str(), m_constStrArgThread.c_str()));
736         return MIstatus::failure;
737     }
738
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);
745
746     return MIstatus::success;
747 }
748
749 //++ ------------------------------------------------------------------------------------
750 // Details: The invoker requires this function. The command prepares a MI Record Result
751 //          for the work carried out in the Execute().
752 // Type:    Overridden.
753 // Args:    None.
754 // Return:  MIstatus::success - Functional succeeded.
755 //          MIstatus::failure - Functional failed.
756 // Throws:  None.
757 //--
758 bool
759 CMICmdCmdExecStepInstruction::Acknowledge(void)
760 {
761     if (m_lldbResult.GetErrorSize() > 0)
762     {
763         const MIchar *pLldbErr = m_lldbResult.GetError();
764         MIunused(pLldbErr);
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;
769     }
770     else
771     {
772         const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
773         m_miResultRecord = miRecordResult;
774     }
775
776     return MIstatus::success;
777 }
778
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.
783 // Args:    None.
784 // Return:  CMICmdBase * - Pointer to a new command.
785 // Throws:  None.
786 //--
787 CMICmdBase *
788 CMICmdCmdExecStepInstruction::CreateSelf(void)
789 {
790     return new CMICmdCmdExecStepInstruction();
791 }
792
793 //---------------------------------------------------------------------------------------
794 //---------------------------------------------------------------------------------------
795 //---------------------------------------------------------------------------------------
796
797 //++ ------------------------------------------------------------------------------------
798 // Details: CMICmdCmdExecFinish constructor.
799 // Type:    Method.
800 // Args:    None.
801 // Return:  None.
802 // Throws:  None.
803 //--
804 CMICmdCmdExecFinish::CMICmdCmdExecFinish(void)
805     : m_constStrArgThread("thread")
806     , m_constStrArgFrame("frame")
807 {
808     // Command factory matches this name with that received from the stdin stream
809     m_strMiCmd = "exec-finish";
810
811     // Required by the CMICmdFactory when registering *this command
812     m_pSelfCreatorFn = &CMICmdCmdExecFinish::CreateSelf;
813 }
814
815 //++ ------------------------------------------------------------------------------------
816 // Details: CMICmdCmdExecFinish destructor.
817 // Type:    Overrideable.
818 // Args:    None.
819 // Return:  None.
820 // Throws:  None.
821 //--
822 CMICmdCmdExecFinish::~CMICmdCmdExecFinish(void)
823 {
824 }
825
826 //++ ------------------------------------------------------------------------------------
827 // Details: The invoker requires this function. The parses the command line options
828 //          arguments to extract values for each of those arguments.
829 // Type:    Overridden.
830 // Args:    None.
831 // Return:  MIstatus::success - Functional succeeded.
832 //          MIstatus::failure - Functional failed.
833 // Throws:  None.
834 //--
835 bool
836 CMICmdCmdExecFinish::ParseArgs(void)
837 {
838     bool bOk =
839         m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgThread, true, true, CMICmdArgValListBase::eArgValType_Number, 1)));
840     bOk = bOk &&
841           m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgFrame, false, false, CMICmdArgValListBase::eArgValType_Number, 1)));
842     return (bOk && ParseValidateCmdOptions());
843 }
844
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.
848 // Type:    Overridden.
849 // Args:    None.
850 // Return:  MIstatus::success - Functional succeeded.
851 //          MIstatus::failure - Functional failed.
852 // Throws:  None.
853 //--
854 bool
855 CMICmdCmdExecFinish::Execute(void)
856 {
857     CMICMDBASE_GETOPTION(pArgThread, OptionLong, m_constStrArgThread);
858
859     // Retrieve the --thread option's thread ID (only 1)
860     MIuint64 nThreadId = UINT64_MAX;
861     if (!pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId))
862     {
863         SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND), m_cmdData.strMiCmd.c_str(), m_constStrArgThread.c_str()));
864         return MIstatus::failure;
865     }
866
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);
873
874     return MIstatus::success;
875 }
876
877 //++ ------------------------------------------------------------------------------------
878 // Details: The invoker requires this function. The command prepares a MI Record Result
879 //          for the work carried out in the Execute().
880 // Type:    Overridden.
881 // Args:    None.
882 // Return:  MIstatus::success - Functional succeeded.
883 //          MIstatus::failure - Functional failed.
884 // Throws:  None.
885 //--
886 bool
887 CMICmdCmdExecFinish::Acknowledge(void)
888 {
889     if (m_lldbResult.GetErrorSize() > 0)
890     {
891         const MIchar *pLldbErr = m_lldbResult.GetError();
892         MIunused(pLldbErr);
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;
897     }
898     else
899     {
900         const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
901         m_miResultRecord = miRecordResult;
902     }
903
904     return MIstatus::success;
905 }
906
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.
911 // Args:    None.
912 // Return:  CMICmdBase * - Pointer to a new command.
913 // Throws:  None.
914 //--
915 CMICmdBase *
916 CMICmdCmdExecFinish::CreateSelf(void)
917 {
918     return new CMICmdCmdExecFinish();
919 }
920
921 //---------------------------------------------------------------------------------------
922 //---------------------------------------------------------------------------------------
923 //---------------------------------------------------------------------------------------
924
925 //++ ------------------------------------------------------------------------------------
926 // Details: CMICmdCmdExecInterrupt constructor.
927 // Type:    Method.
928 // Args:    None.
929 // Return:  None.
930 // Throws:  None.
931 //--
932 CMICmdCmdExecInterrupt::CMICmdCmdExecInterrupt(void)
933 {
934     // Command factory matches this name with that received from the stdin stream
935     m_strMiCmd = "exec-interrupt";
936
937     // Required by the CMICmdFactory when registering *this command
938     m_pSelfCreatorFn = &CMICmdCmdExecInterrupt::CreateSelf;
939 }
940
941 //++ ------------------------------------------------------------------------------------
942 // Details: CMICmdCmdExecInterrupt destructor.
943 // Type:    Overrideable.
944 // Args:    None.
945 // Return:  None.
946 // Throws:  None.
947 //--
948 CMICmdCmdExecInterrupt::~CMICmdCmdExecInterrupt(void)
949 {
950 }
951
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.
955 // Type:    Overridden.
956 // Args:    None.
957 // Return:  MIstatus::success - Functional succeeded.
958 //          MIstatus::failure - Functional failed.
959 // Throws:  None.
960 //--
961 bool
962 CMICmdCmdExecInterrupt::Execute(void)
963 {
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);
968     MIunused(status);
969
970     // CODETAG_DEBUG_SESSION_RUNNING_PROG_RECEIVED_SIGINT_PAUSE_PROGRAM
971     if (!CMIDriver::Instance().SetDriverStateRunningNotDebugging())
972     {
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;
976     }
977
978     return MIstatus::success;
979 }
980
981 //++ ------------------------------------------------------------------------------------
982 // Details: The invoker requires this function. The command prepares a MI Record Result
983 //          for the work carried out in the Execute().
984 // Type:    Overridden.
985 // Args:    None.
986 // Return:  MIstatus::success - Functional succeeded.
987 //          MIstatus::failure - Functional failed.
988 // Throws:  None.
989 //--
990 bool
991 CMICmdCmdExecInterrupt::Acknowledge(void)
992 {
993     if (m_lldbResult.GetErrorSize() > 0)
994     {
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;
999     }
1000     else
1001     {
1002         const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done);
1003         m_miResultRecord = miRecordResult;
1004     }
1005
1006     return MIstatus::success;
1007 }
1008
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.
1013 // Args:    None.
1014 // Return:  CMICmdBase * - Pointer to a new command.
1015 // Throws:  None.
1016 //--
1017 CMICmdBase *
1018 CMICmdCmdExecInterrupt::CreateSelf(void)
1019 {
1020     return new CMICmdCmdExecInterrupt();
1021 }