[Lldb-commits] [PATCH] Add -exec-arguments command

Greg Clayton clayborg at gmail.com
Mon Feb 2 10:22:54 PST 2015


The fix I requested should be easy to implement as noted above in the code comments.

Step 1:
1 - Add a "SBLaunchInfo m_lldbLaunchInfo" as a member variable in the CMICmnLLDBDebugSessionInfo class next to the "SBTarget m_lldbTarget" member variable
2 - Add a SBAttachInfo for attaching as well if needed
3 - Make code changes I specify above
4 - Hook up more calls to modify data in the SBLaunchInfo and SBAttachInfo
5 - Remove SBArgs.h and SBArgs.cpp

This will provide the cleanest implementation and allow of the most flexibility in setting the environment variables (just modify SBLaunchInfo), working directory (modify SBLaunchInfo), etc, then when you launch you get to just use the launch info you have built up.


================
Comment at: tools/lldb-mi/MICmdCmdExec.cpp:95-99
@@ -92,5 +94,7 @@
     lldb::SBStream errMsg;
-    uint32_t launch_flags = lldb::LaunchFlags::eLaunchFlagDebug;
-    lldb::SBProcess process = rSessionInfo.m_lldbTarget.Launch(rSessionInfo.m_rLlldbListener, nullptr, nullptr, nullptr, nullptr, nullptr,
+    const uint32_t launch_flags = lldb::LaunchFlags::eLaunchFlagDebug;
+    lldb::SBProcess process = rSessionInfo.m_lldbTarget.Launch(rSessionInfo.m_rLlldbListener,
+                                                               rSessionInfo.m_lldbTarget.GetRunArguments().GetConstArgumentVector(),
+                                                               nullptr, nullptr, nullptr, nullptr,
                                                                nullptr, launch_flags, false, error);
 
----------------
If we store a SBLaunchInfo in CMICmnLLDBDebugSessionInfo then this becomes:


```
    lldb::SBProcess process = rSessionInfo.m_lldbTarget.Launch(rSessionInfo.m_lldbLaunchInfo, error);

```

And the SBLaunchInfo doesn't require the lldb::LaunchFlags::eLaunchFlagDebug as that is implied by the launch itself. You can set it in the m_lldbLaunchInfo if you want when you construct it inside CMICmnLLDBDebugSessionInfo.

================
Comment at: tools/lldb-mi/MICmdCmdExec.cpp:1076-1110
@@ +1075,37 @@
+
+//++ ------------------------------------------------------------------------------------
+// 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);
+
+    lldb::SBArgs sbArgs(true);
+    CMIUtilString strArg;
+    size_t nArgIndex = 0;
+    while (pArgArguments->GetExpectedOption<CMICmdArgValString, CMIUtilString>(strArg, nArgIndex))
+    {
+        sbArgs.AppendArgument(strArg.c_str());
+        ++nArgIndex;
+    }
+
+    CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance());
+    lldb::SBTarget sbTarget = rSessionInfo.m_lldbTarget;
+    if (!sbTarget.IsValid())
+    {
+        SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INVALID_TARGET_CURRENT), m_cmdData.strMiCmd.c_str()));
+        return MIstatus::failure;
+    }
+
+    sbTarget.SetRunArguments(sbArgs);
+
+    return MIstatus::success;
+}
+
----------------
If we store a SBLaunchInfo in CMICmnLLDBDebugSessionInfo we can turn this function into:


```
bool
CMICmdCmdExecArguments::Execute(void)
{
    CMICMDBASE_GETOPTION(pArgArguments, ListOfN, m_constStrArgArguments);

    CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance());
    const char *argv[2] = { nullptr, nullptr };
    const bool append = true;
    CMIUtilString strArg;
    size_t nArgIndex = 0;
    while (pArgArguments->GetExpectedOption<CMICmdArgValString, CMIUtilString>(strArg, nArgIndex))
    {
        argv[0] = strArg.c_str();
        rSessionInfo.m_lldbLaunchInfo.SetArguments (argv, append);
        ++nArgIndex;
    }

    return MIstatus::success;
}
```

http://reviews.llvm.org/D6965

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the lldb-commits mailing list