[Lldb-commits] [lldb] r231070 - Allow to pass an executable file via lldb-mi arguments (MI)

Ilia K ki.stfu at gmail.com
Tue Mar 3 07:14:33 PST 2015


Author: ki.stfu
Date: Tue Mar  3 09:14:32 2015
New Revision: 231070

URL: http://llvm.org/viewvc/llvm-project?rev=231070&view=rev
Log:
Allow to pass an executable file via lldb-mi arguments (MI)

Summary:
# Allow to pass an executable file via lldb-mi arguments
# Add tests
# Fix (gdb) prompt in CMIDriver::LocalDebugSessionStartupExecuteCommands
# Fix prompt in CMIDriver::InterpretCommandThisDriver: use the lldb-mi prompt instead of a hard-coded value.

All tests pass on OS X.

Reviewers: abidh, clayborg

Reviewed By: clayborg

Subscribers: lldb-commits, clayborg, abidh

Differential Revision: http://reviews.llvm.org/D8001

Added:
    lldb/trunk/test/tools/lldb-mi/startup_options/
    lldb/trunk/test/tools/lldb-mi/startup_options/Makefile
    lldb/trunk/test/tools/lldb-mi/startup_options/TestMiStartupOptions.py
    lldb/trunk/test/tools/lldb-mi/startup_options/main.cpp
Modified:
    lldb/trunk/tools/lldb-mi/MICmnConfig.h
    lldb/trunk/tools/lldb-mi/MIDriver.cpp

Added: lldb/trunk/test/tools/lldb-mi/startup_options/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-mi/startup_options/Makefile?rev=231070&view=auto
==============================================================================
--- lldb/trunk/test/tools/lldb-mi/startup_options/Makefile (added)
+++ lldb/trunk/test/tools/lldb-mi/startup_options/Makefile Tue Mar  3 09:14:32 2015
@@ -0,0 +1,5 @@
+LEVEL = ../../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules

Added: lldb/trunk/test/tools/lldb-mi/startup_options/TestMiStartupOptions.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-mi/startup_options/TestMiStartupOptions.py?rev=231070&view=auto
==============================================================================
--- lldb/trunk/test/tools/lldb-mi/startup_options/TestMiStartupOptions.py (added)
+++ lldb/trunk/test/tools/lldb-mi/startup_options/TestMiStartupOptions.py Tue Mar  3 09:14:32 2015
@@ -0,0 +1,136 @@
+"""
+Test lldb-mi startup options.
+"""
+
+# adjust path for lldbmi_testcase.py
+import sys, os.path
+sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
+
+import lldbmi_testcase
+from lldbtest import *
+import unittest2
+
+class MiStartupOptionsTestCase(lldbmi_testcase.MiTestCaseBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    @lldbmi_test
+    @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
+    @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
+    def test_lldbmi_executable_option_file(self):
+        """Test that 'lldb-mi --interpreter %s' loads executable file."""
+
+        self.spawnLldbMi(args = "%s" % self.myexe)
+
+        # Test that lldb-mi is ready after startup
+        self.expect(self.child_prompt, exactly = True)
+
+        # Test that the executable is loaded when file was specified
+        self.expect("-file-exec-and-symbols \"%s\"" % self.myexe)
+        self.expect("\^done")
+
+        # Test that lldb-mi is ready when executable was loaded
+        self.expect(self.child_prompt, exactly = True)
+
+        # Run
+        self.runCmd("-exec-run")
+        self.expect("\^running")
+        self.expect("\*stopped,reason=\"exited-normally\"")
+
+    @lldbmi_test
+    @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
+    @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
+    def test_lldbmi_executable_option_unknown_file(self):
+        """Test that 'lldb-mi --interpreter %s' fails on unknown executable file."""
+
+        # Prepare path to executable
+        path = "unknown_file"
+
+        self.spawnLldbMi(args = "%s" % path)
+
+        # Test that lldb-mi is ready after startup
+        self.expect(self.child_prompt, exactly = True)
+
+        # Test that the executable isn't loaded when unknown file was specified
+        self.expect("-file-exec-and-symbols \"%s\"" % path)
+        self.expect("\^error,msg=\"Command 'file-exec-and-symbols'. Target binary '%s' is invalid. error: unable to find executable for '%s'\"" % (path, path))
+
+        # Test that lldb-mi is ready when executable was loaded
+        self.expect(self.child_prompt, exactly = True)
+
+    @lldbmi_test
+    @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
+    @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
+    def test_lldbmi_executable_option_absolute_path(self):
+        """Test that 'lldb-mi --interpreter %s' loads executable which is specified via absolute path."""
+
+        # Prepare path to executable
+        import os
+        path = os.path.join(os.getcwd(), self.myexe)
+
+        self.spawnLldbMi(args = "%s" % path)
+
+        # Test that lldb-mi is ready after startup
+        self.expect(self.child_prompt, exactly = True)
+
+        # Test that the executable is loaded when file was specified using absolute path
+        self.expect("-file-exec-and-symbols \"%s\"" % path)
+        self.expect("\^done")
+
+        # Test that lldb-mi is ready when executable was loaded
+        self.expect(self.child_prompt, exactly = True)
+
+        # Run
+        self.runCmd("-exec-run")
+        self.expect("\^running")
+        self.expect("\*stopped,reason=\"exited-normally\"")
+
+    @lldbmi_test
+    @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
+    @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
+    def test_lldbmi_executable_option_relative_path(self):
+        """Test that 'lldb-mi --interpreter %s' loads executable which is specified via relative path."""
+
+        # Prepare path to executable
+        path = "./%s" % self.myexe
+
+        self.spawnLldbMi(args = "%s" % path)
+
+        # Test that lldb-mi is ready after startup
+        self.expect(self.child_prompt, exactly = True)
+
+        # Test that the executable is loaded when file was specified using relative path
+        self.expect("-file-exec-and-symbols \"%s\"" % path)
+        self.expect("\^done")
+
+        # Test that lldb-mi is ready when executable was loaded
+        self.expect(self.child_prompt, exactly = True)
+
+        # Run
+        self.runCmd("-exec-run")
+        self.expect("\^running")
+        self.expect("\*stopped,reason=\"exited-normally\"")
+
+    @lldbmi_test
+    @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
+    @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
+    def test_lldbmi_executable_option_unknown_path(self):
+        """Test that 'lldb-mi --interpreter %s' fails on executable file which is specified via unknown path."""
+
+        # Prepare path to executable
+        path = "unknown_dir/%s" % self.myexe
+
+        self.spawnLldbMi(args = "%s" % path)
+
+        # Test that lldb-mi is ready after startup
+        self.expect(self.child_prompt, exactly = True)
+
+        # Test that the executable isn't loaded when file was specified using unknown path
+        self.expect("-file-exec-and-symbols \"%s\"" % path)
+        self.expect("\^error,msg=\"Command 'file-exec-and-symbols'. Target binary '%s' is invalid. error: unable to find executable for '%s'\"" % (path, path))
+
+        # Test that lldb-mi is ready when executable was loaded
+        self.expect(self.child_prompt, exactly = True)
+
+if __name__ == '__main__':
+    unittest2.main()

Added: lldb/trunk/test/tools/lldb-mi/startup_options/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-mi/startup_options/main.cpp?rev=231070&view=auto
==============================================================================
--- lldb/trunk/test/tools/lldb-mi/startup_options/main.cpp (added)
+++ lldb/trunk/test/tools/lldb-mi/startup_options/main.cpp Tue Mar  3 09:14:32 2015
@@ -0,0 +1,14 @@
+//===-- main.cpp ------------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+int
+main(int argc, char const *argv[])
+{
+    return 0;
+}

Modified: lldb/trunk/tools/lldb-mi/MICmnConfig.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnConfig.h?rev=231070&r1=231069&r2=231070&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnConfig.h (original)
+++ lldb/trunk/tools/lldb-mi/MICmnConfig.h Tue Mar  3 09:14:32 2015
@@ -47,4 +47,4 @@
 #define MICONFIG_GIVE_WARNING_CMD_ARGS_NOT_HANDLED 1
 
 // 1 = Enable MI Driver in MI mode to create a local debug session, 0 = Report "Not implemented"
-#define MICONFIG_ENABLE_MI_DRIVER_MI_MODE_CMDLINE_ARG_EXECUTABLE_DEBUG_SESSION 0
+#define MICONFIG_ENABLE_MI_DRIVER_MI_MODE_CMDLINE_ARG_EXECUTABLE_DEBUG_SESSION 1

Modified: lldb/trunk/tools/lldb-mi/MIDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIDriver.cpp?rev=231070&r1=231069&r2=231070&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MIDriver.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MIDriver.cpp Tue Mar  3 09:14:32 2015
@@ -913,11 +913,12 @@ CMIDriver::InterpretCommandThisDriver(co
     const CMICmnMIValueConst vconst = CMICmnMIValueConst(msg);
     const CMICmnMIValueResult valueResult("msg", vconst);
     const CMICmnMIResultRecord miResultRecord(cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error, valueResult);
-    m_rStdOut.WriteMIResponse(miResultRecord.GetString());
-    m_rStdOut.WriteMIResponse("(gdb)");
+    bool bOk = m_rStdOut.WriteMIResponse(miResultRecord.GetString());
+    if (bOk && m_rStdin.GetEnablePrompt())
+        bOk = m_rStdOut.WriteMIResponse(m_rStdin.GetPrompt());
 
     // Proceed to wait for or execute next command
-    return MIstatus::success;
+    return bOk;
 }
 
 //++ ------------------------------------------------------------------------------------
@@ -1173,8 +1174,11 @@ bool
 CMIDriver::LocalDebugSessionStartupExecuteCommands(void)
 {
     const CMIUtilString strCmd(CMIUtilString::Format("-file-exec-and-symbols \"%s\"", m_strCmdLineArgExecuteableFileNamePath.AddSlashes().c_str()));
-    const bool bOk = CMICmnStreamStdout::TextToStdout(strCmd);
-    return (bOk && InterpretCommand(strCmd));
+    bool bOk = CMICmnStreamStdout::TextToStdout(strCmd);
+    bOk = bOk && InterpretCommand(strCmd);
+    if (bOk && m_rStdin.GetEnablePrompt())
+        bOk = m_rStdOut.WriteMIResponse(m_rStdin.GetPrompt());
+    return bOk;
 }
 
 //++ ------------------------------------------------------------------------------------





More information about the lldb-commits mailing list