summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect
diff options
context:
space:
mode:
authorTamas Berghammer <tberghammer@google.com>2015-12-08 14:08:19 +0000
committerTamas Berghammer <tberghammer@google.com>2015-12-08 14:08:19 +0000
commitccd6cffba3545bec41864b0c3fa4ca7cc3e854c5 (patch)
tree47ae8040ff8d1ce1485f2789a848bd181403c605 /lldb/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect
parent59d092f883a44c35822f3038128a11452801c7a4 (diff)
downloadbcm5719-llvm-ccd6cffba3545bec41864b0c3fa4ca7cc3e854c5.tar.gz
bcm5719-llvm-ccd6cffba3545bec41864b0c3fa4ca7cc3e854c5.zip
Modify "platform connect" to connect to processes as well
The standard remote debugging workflow with gdb is to start the application on the remote host under gdbserver (e.g.: gdbserver :5039 a.out) and then connect to it with gdb. The same workflow is supported by debugserver/lldb-gdbserver with a very similar syntax but to access all features of lldb we need to be connected also to an lldb-platform instance running on the target. Before this change this had to be done manually with starting a separate lldb-platform on the target machine and then connecting to it with lldb before connecting to the process. This change modifies the behavior of "platform connect" with automatically connecting to the process instance if it was started by the remote platform. With this command replacing gdbserver in a gdb based worflow is usually as simple as replacing the command to execute gdbserver with executing lldb-platform. Differential revision: http://reviews.llvm.org/D14952 llvm-svn: 255016
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect')
-rw-r--r--lldb/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/Makefile5
-rw-r--r--lldb/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/TestPlatformProcessConnect.py55
-rw-r--r--lldb/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/main.cpp7
3 files changed, 67 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/Makefile b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/Makefile
new file mode 100644
index 00000000000..314f1cb2f07
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/Makefile
@@ -0,0 +1,5 @@
+LEVEL = ../../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/TestPlatformProcessConnect.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/TestPlatformProcessConnect.py
new file mode 100644
index 00000000000..676c154e55d
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/TestPlatformProcessConnect.py
@@ -0,0 +1,55 @@
+from __future__ import print_function
+
+import gdbremote_testcase
+from lldbsuite.test.lldbtest import *
+import lldbsuite.test.lldbutil as lldbutil
+
+class TestPlatformProcessConnect(gdbremote_testcase.GdbRemoteTestCaseBase):
+ mydir = TestBase.compute_mydir(__file__)
+
+ @llgs_test
+ @no_debug_info_test
+ @skipIf(remote=False)
+ def test_platform_process_connect(self):
+ self.build()
+ self.init_llgs_test(False)
+
+ working_dir = lldb.remote_platform.GetWorkingDirectory()
+ err = lldb.remote_platform.Put(lldb.SBFileSpec(os.path.join(os.getcwd(), "a.out")),
+ lldb.SBFileSpec(os.path.join(working_dir, "a.out")))
+ if err.Fail():
+ raise RuntimeError("Unable copy '%s' to '%s'.\n>>> %s" % (f, wd, err.GetCString()))
+
+ port_file = "%s/port" % working_dir
+ commandline_args = ["platform", "--listen", "*:0", "--socket-file", port_file, "--", "%s/a.out" % working_dir, "foo"]
+ self.spawnSubprocess(self.debug_monitor_exe, commandline_args, install_remote=False)
+ self.addTearDownHook(self.cleanupSubprocesses)
+ new_port = self.run_shell_cmd("while [ ! -f %s ]; do sleep 0.25; done && cat %s" % (port_file, port_file))
+
+ new_debugger = lldb.SBDebugger.Create()
+ new_debugger.SetAsync(False)
+ def del_debugger():
+ del new_debugger
+ self.addTearDownHook(del_debugger)
+
+ new_platform = lldb.SBPlatform(lldb.remote_platform.GetName())
+ new_debugger.SetSelectedPlatform(new_platform)
+ new_interpreter = new_debugger.GetCommandInterpreter()
+
+ m = re.search("(.*):[0-9]+", configuration.lldb_platform_url)
+ command = "platform connect %s:%s" % (m.group(1), new_port)
+ result = lldb.SBCommandReturnObject()
+ new_interpreter.HandleCommand(command, result)
+ self.assertTrue(result.Succeeded(), "platform process connect failed: %s" % result.GetOutput())
+
+ target = new_debugger.GetSelectedTarget()
+ process = target.GetProcess()
+ thread = process.GetThreadAtIndex(0)
+
+ breakpoint = target.BreakpointCreateByName("main")
+ process.Continue()
+
+ frame = thread.GetFrameAtIndex(0)
+ self.assertEqual(frame.GetFunction().GetName(), "main")
+ self.assertEqual(frame.FindVariable("argc").GetValueAsSigned(), 2)
+ process.Continue()
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/main.cpp b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/main.cpp
new file mode 100644
index 00000000000..70ae5094fde
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/main.cpp
@@ -0,0 +1,7 @@
+#include <cstdio>
+
+int main (int argc, char **argv)
+{
+ printf("argc: %d\n", argc);
+ return argv[0][0];
+}
OpenPOWER on IntegriCloud