Update patch according to clayborg's remarks

http://reviews.llvm.org/D6965

Files:
  test/tools/lldb-mi/TestMiExec.py
  test/tools/lldb-mi/TestMiInterpreterExec.py
  tools/lldb-mi/MICmdArgValListOfN.h
  tools/lldb-mi/MICmdCmdExec.cpp
  tools/lldb-mi/MICmdCmdExec.h
  tools/lldb-mi/MICmdCommands.cpp
  tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp
  tools/lldb-mi/MICmnLLDBDebugSessionInfo.h

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
Index: test/tools/lldb-mi/TestMiExec.py
===================================================================
--- test/tools/lldb-mi/TestMiExec.py
+++ test/tools/lldb-mi/TestMiExec.py
@@ -60,7 +60,6 @@
 
     @lldbmi_test
     @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
-    @unittest2.skip("reviews.llvm.org/D6965: requires this patch")
     def test_lldbmi_exec_arguments_set(self):
         """Test that 'lldb-mi --interpreter' can pass args using -exec-arguments."""
 
@@ -91,7 +90,8 @@
         #self.runCmd("-data-evaluate-expression argv[2]")
         #self.expect("\^done,value=\"2nd arg\"")
         self.runCmd("-interpreter-exec command \"print argv[2]\"")
-        self.expect("\"2nd arg\"")
+        #FIXME: lldb-mi doesn't handle inner quotes
+        self.expect("\"\\\\\\\"2nd arg\\\\\\\"\"") #FIXME: self.expect("\"2nd arg\"")
         #self.runCmd("-data-evaluate-expression argv[3]")
         #self.expect("\^done,value=\"third_arg\"")
         self.runCmd("-interpreter-exec command \"print argv[3]\"")
@@ -103,7 +103,6 @@
 
     @lldbmi_test
     @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
-    @unittest2.skip("reviews.llvm.org/D6965: requires this patch")
     def test_lldbmi_exec_arguments_reset(self):
         """Test that 'lldb-mi --interpreter' can reset previously set args using -exec-arguments."""
 
@@ -363,7 +362,6 @@
 
     @lldbmi_test
     @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
-    @unittest2.skip("reviews.llvm.org/D6965: requires this patch")
     def test_lldbmi_exec_finish(self):
         """Test that 'lldb-mi --interpreter' works for -exec-finish."""
 
Index: test/tools/lldb-mi/TestMiInterpreterExec.py
===================================================================
--- test/tools/lldb-mi/TestMiInterpreterExec.py
+++ test/tools/lldb-mi/TestMiInterpreterExec.py
@@ -49,7 +49,6 @@
 
     @lldbmi_test
     @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
-    @unittest2.skip("reviews.llvm.org/D6965: requires this patch")
     def test_lldbmi_settings_set_target_run_args(self):
         """Test that 'lldb-mi --interpreter' can set target arguments by 'setting set target.run-args' command."""
 
Index: tools/lldb-mi/MICmdArgValListOfN.h
===================================================================
--- tools/lldb-mi/MICmdArgValListOfN.h
+++ tools/lldb-mi/MICmdArgValListOfN.h
@@ -56,7 +56,7 @@
                                    const ArgValType_e veType);
     //
     const VecArgObjPtr_t &GetExpectedOptions(void) const;
-    template <class T1, typename T2> bool GetExpectedOption(T2 &vrwValue) const;
+    template <class T1, typename T2> bool GetExpectedOption(T2 &vrwValue, const VecArgObjPtr_t::size_type vnAt = 0) const;
 
     // Overridden:
   public:
@@ -76,18 +76,22 @@
 //          parsed from the command's options string.
 // Type:    Template method.
 // Args:    vrwValue    - (W) Templated type return value.
+//          vnAt        - (R) Value at the specific position.
 //          T1          - The argument value's class type of the data hold in the list of options.
 //          T2          - The type pf the variable which holds the value wanted.
 // Return:  MIstatus::success - Functional succeeded.
 //          MIstatus::failure - Functional failed. List of object was empty.
 // Throws:  None.
 //--
 template <class T1, typename T2>
 bool
-CMICmdArgValListOfN::GetExpectedOption(T2 &vrwValue) const
+CMICmdArgValListOfN::GetExpectedOption(T2 &vrwValue, const VecArgObjPtr_t::size_type vnAt) const
 {
     const VecArgObjPtr_t &rVecOptions(GetExpectedOptions());
-    VecArgObjPtr_t::const_iterator it2 = rVecOptions.begin();
+    if (rVecOptions.size() <= vnAt)
+        return MIstatus::failure;
+
+    VecArgObjPtr_t::const_iterator it2 = rVecOptions.begin() + vnAt;
     if (it2 != rVecOptions.end())
     {
         const T1 *pOption = static_cast<T1 *>(*it2);
Index: tools/lldb-mi/MICmdCmdExec.cpp
===================================================================
--- tools/lldb-mi/MICmdCmdExec.cpp
+++ tools/lldb-mi/MICmdCmdExec.cpp
@@ -18,6 +18,7 @@
 //              CMICmdCmdExecStepInstruction    implementation.
 //              CMICmdCmdExecFinish             implementation.
 //              CMICmdCmdExecInterrupt          implementation.
+//              CMICmdCmdExecArguments          implementation.
 //
 // Environment: Compilers:  Visual C++ 12.
 //                          gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
@@ -90,10 +91,7 @@
     CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance());
     lldb::SBError error;
     lldb::SBStream errMsg;
-    uint32_t launch_flags = lldb::LaunchFlags::eLaunchFlagDebug;
-    lldb::SBProcess process = rSessionInfo.GetTarget().Launch(rSessionInfo.GetListener(), nullptr, nullptr, nullptr, nullptr,
-                                                              nullptr, nullptr, launch_flags, false, error);
-
+    lldb::SBProcess process = rSessionInfo.GetTarget().Launch(rSessionInfo.m_lldbLaunchInfo, error);
     if ((!process.IsValid()) || (error.Fail()))
     {
         SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INVALID_PROCESS), m_cmdData.strMiCmd.c_str(), errMsg.GetData()));
@@ -1016,3 +1014,113 @@
 {
     return new CMICmdCmdExecInterrupt();
 }
+
+//---------------------------------------------------------------------------------------
+//---------------------------------------------------------------------------------------
+//---------------------------------------------------------------------------------------
+
+//++ ------------------------------------------------------------------------------------
+// Details: CMICmdCmdExecArguments constructor.
+// Type:    Method.
+// Args:    None.
+// Return:  None.
+// Throws:  None.
+//--
+CMICmdCmdExecArguments::CMICmdCmdExecArguments(void)
+    : m_constStrArgArguments("arguments")
+{
+    // Command factory matches this name with that received from the stdin stream
+    m_strMiCmd = "exec-arguments";
+
+    // Required by the CMICmdFactory when registering *this command
+    m_pSelfCreatorFn = &CMICmdCmdExecArguments::CreateSelf;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: CMICmdCmdExecArguments destructor.
+// Type:    Overrideable.
+// Args:    None.
+// Return:  None.
+// Throws:  None.
+//--
+CMICmdCmdExecArguments::~CMICmdCmdExecArguments(void)
+{
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: The invoker requires this function. The parses the command line options
+//          arguments to extract values for each of those arguments.
+// Type:    Overridden.
+// Args:    None.
+// Return:  MIstatus::success - Function succeeded.
+//          MIstatus::failure - Function failed.
+// Throws:  None.
+//--
+bool
+CMICmdCmdExecArguments::ParseArgs(void)
+{
+    bool bOk = m_setCmdArgs.Add(
+        *(new CMICmdArgValListOfN(m_constStrArgArguments, false, true, CMICmdArgValListBase::eArgValType_StringAnything)));
+    return (bOk && ParseValidateCmdOptions());
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: The invoker requires this function. The command does work in this function.
+//          The command is likely to communicate with the LLDB SBDebugger in here.
+// Type:    Overridden.
+// Args:    None.
+// Return:  MIstatus::success - Function succeeded.
+//          MIstatus::failure - Function failed.
+// Throws:  None.
+//--
+bool
+CMICmdCmdExecArguments::Execute(void)
+{
+    CMICMDBASE_GETOPTION(pArgArguments, ListOfN, m_constStrArgArguments);
+
+    CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance());
+    rSessionInfo.m_lldbLaunchInfo.SetArguments(NULL, false);
+
+    CMIUtilString strArg;
+    size_t nArgIndex = 0;
+    while (pArgArguments->GetExpectedOption<CMICmdArgValString, CMIUtilString>(strArg, nArgIndex))
+    {
+        const char *argv[2] = { strArg.c_str(), NULL };
+        rSessionInfo.m_lldbLaunchInfo.SetArguments(argv, true);
+        ++nArgIndex;
+    }
+
+    return MIstatus::success;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: The invoker requires this function. The command prepares a MI Record Result
+//          for the work carried out in the Execute().
+// Type:    Overridden.
+// Args:    None.
+// Return:  MIstatus::success - Function succeeded.
+//          MIstatus::failure - Function failed.
+// Throws:  None.
+//--
+bool
+CMICmdCmdExecArguments::Acknowledge(void)
+{
+    const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done);
+    m_miResultRecord = miRecordResult;
+
+    return MIstatus::success;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Required by the CMICmdFactory when registering *this command. The factory
+//          calls this function to create an instance of *this command.
+// Type:    Static method.
+// Args:    None.
+// Return:  CMICmdBase * - Pointer to a new command.
+// Throws:  None.
+//--
+CMICmdBase *
+CMICmdCmdExecArguments::CreateSelf(void)
+{
+    return new CMICmdCmdExecArguments();
+}
Index: tools/lldb-mi/MICmdCmdExec.h
===================================================================
--- tools/lldb-mi/MICmdCmdExec.h
+++ tools/lldb-mi/MICmdCmdExec.h
@@ -18,6 +18,7 @@
 //              CMICmdCmdExecStepInstruction    interface.
 //              CMICmdCmdExecFinish             interface.
 //              CMICmdCmdExecInterrupt          interface.
+//              CMICmdCmdExecArguments          interface.
 //
 //              To implement new MI commands derive a new command class from the command base
 //              class. To enable the new command for interpretation add the new command class
@@ -307,3 +308,35 @@
   private:
     lldb::SBCommandReturnObject m_lldbResult;
 };
+
+//++ ============================================================================
+// Details: MI command class. MI commands derived from the command base class.
+//          *this class implements MI command "exec-arguments".
+// Gotchas: None.
+// Authors: Ilia Kirianovskii 25/11/2014.
+// Changes: None.
+//--
+class CMICmdCmdExecArguments : public CMICmdBase
+{
+    // Statics:
+  public:
+    // Required by the CMICmdFactory when registering *this command
+    static CMICmdBase *CreateSelf(void);
+
+    // Methods:
+  public:
+    /* ctor */ CMICmdCmdExecArguments(void);
+
+    // Overridden:
+  public:
+    // From CMICmdInvoker::ICmd
+    virtual bool Execute(void);
+    virtual bool Acknowledge(void);
+    virtual bool ParseArgs(void);
+    // From CMICmnBase
+    /* dtor */ virtual ~CMICmdCmdExecArguments(void);
+
+    // Attributes:
+  private:
+    const CMIUtilString m_constStrArgArguments;
+};
Index: tools/lldb-mi/MICmdCommands.cpp
===================================================================
--- tools/lldb-mi/MICmdCommands.cpp
+++ tools/lldb-mi/MICmdCommands.cpp
@@ -98,6 +98,7 @@
     bOk &= Register<CMICmdCmdDataWriteMemory>();
     bOk &= Register<CMICmdCmdEnablePrettyPrinting>();
     bOk &= Register<CMICmdCmdEnvironmentCd>();
+    bOk &= Register<CMICmdCmdExecArguments>();
     bOk &= Register<CMICmdCmdExecContinue>();
     bOk &= Register<CMICmdCmdExecInterrupt>();
     bOk &= Register<CMICmdCmdExecFinish>();
Index: tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp
===================================================================
--- tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp
+++ tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp
@@ -49,6 +49,7 @@
 CMICmnLLDBDebugSessionInfo::CMICmnLLDBDebugSessionInfo(void)
     : m_nBrkPointCntMax(INT32_MAX)
     , m_currentSelectedThread(LLDB_INVALID_THREAD_ID)
+    , m_lldbLaunchInfo(NULL)
     , m_constStrSharedDataKeyWkDir("Working Directory")
     , m_constStrSharedDataSolibPath("Solib Path")
 {
@@ -84,6 +85,7 @@
 
     m_currentSelectedThread = LLDB_INVALID_THREAD_ID;
     CMICmnLLDBDebugSessionInfoVarObj::VarObjIdResetToZero();
+    m_lldbLaunchInfo.SetListener(GetListener());
 
     m_bInitialized = MIstatus::success;
 
Index: tools/lldb-mi/MICmnLLDBDebugSessionInfo.h
===================================================================
--- tools/lldb-mi/MICmnLLDBDebugSessionInfo.h
+++ tools/lldb-mi/MICmnLLDBDebugSessionInfo.h
@@ -183,6 +183,7 @@
     const MIuint m_nBrkPointCntMax;
     VecActiveThreadId_t m_vecActiveThreadId;
     lldb::tid_t m_currentSelectedThread;
+    lldb::SBLaunchInfo m_lldbLaunchInfo;
 
     // These are keys that can be used to access the shared data map
     // Note: This list is expected to grow and will be moved and abstracted in the future.
_______________________________________________
lldb-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits

Reply via email to