summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test
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
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')
-rw-r--r--lldb/packages/Python/lldbsuite/test/lldbtest.py6
-rw-r--r--lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py31
-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
5 files changed, 87 insertions, 17 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 2922445b9a4..4b0fb37ef14 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -1115,7 +1115,7 @@ def skipIfLinuxClang(func):
# @skipIf(bugnumber, ["linux"], "gcc", ['>=', '4.9'], ['i386']), skip for gcc>=4.9 on linux with i386
# TODO: refactor current code, to make skipIfxxx functions to call this function
-def skipIf(bugnumber=None, oslist=None, compiler=None, compiler_version=None, archs=None, debug_info=None, swig_version=None, py_version=None):
+def skipIf(bugnumber=None, oslist=None, compiler=None, compiler_version=None, archs=None, debug_info=None, swig_version=None, py_version=None, remote=None):
def fn(self):
oslist_passes = oslist is None or self.getPlatform() in oslist
compiler_passes = compiler is None or (compiler in self.getCompiler() and self.expectedCompilerVersion(compiler_version))
@@ -1123,13 +1123,15 @@ def skipIf(bugnumber=None, oslist=None, compiler=None, compiler_version=None, ar
debug_info_passes = debug_info is None or self.debug_info in debug_info
swig_version_passes = (swig_version is None) or (not hasattr(lldb, 'swig_version')) or (check_expected_version(swig_version[0], swig_version[1], lldb.swig_version))
py_version_passes = (py_version is None) or check_expected_version(py_version[0], py_version[1], sys.version_info)
+ remote_passes = (remote is None) or (remote == (lldb.remote_platform is not None))
return (oslist_passes and
compiler_passes and
arch_passes and
debug_info_passes and
swig_version_passes and
- py_version_passes)
+ py_version_passes and
+ remote_passes)
local_vars = locals()
args = [x for x in inspect.getargspec(skipIf).args]
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
index f796c6d02ed..113e01e36ba 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
@@ -147,29 +147,30 @@ class GdbRemoteTestCaseBase(TestBase):
return stub_port
+ def run_shell_cmd(self, cmd):
+ platform = self.dbg.GetSelectedPlatform()
+ shell_cmd = lldb.SBPlatformShellCommand(cmd)
+ err = platform.Run(shell_cmd)
+ if err.Fail() or shell_cmd.GetStatus():
+ m = "remote_platform.RunShellCommand('%s') failed:\n" % cmd
+ m += ">>> return code: %d\n" % shell_cmd.GetStatus()
+ if err.Fail():
+ m += ">>> %s\n" % str(err).strip()
+ m += ">>> %s\n" % (shell_cmd.GetOutput() or
+ "Command generated no output.")
+ raise Exception(m)
+ return shell_cmd.GetOutput().strip()
+
def init_llgs_test(self, use_named_pipe=True):
if lldb.remote_platform:
- def run_shell_cmd(cmd):
- platform = self.dbg.GetSelectedPlatform()
- shell_cmd = lldb.SBPlatformShellCommand(cmd)
- err = platform.Run(shell_cmd)
- if err.Fail() or shell_cmd.GetStatus():
- m = "remote_platform.RunShellCommand('%s') failed:\n" % cmd
- m += ">>> return code: %d\n" % shell_cmd.GetStatus()
- if err.Fail():
- m += ">>> %s\n" % str(err).strip()
- m += ">>> %s\n" % (shell_cmd.GetOutput() or
- "Command generated no output.")
- raise Exception(m)
- return shell_cmd.GetOutput().strip()
# Remote platforms don't support named pipe based port negotiation
use_named_pipe = False
# Grab the ppid from /proc/[shell pid]/stat
- shell_stat = run_shell_cmd("cat /proc/$$/stat")
+ shell_stat = self.run_shell_cmd("cat /proc/$$/stat")
# [pid] ([executable]) [state] [*ppid*]
pid = re.match(r"^\d+ \(.+\) . (\d+)", shell_stat).group(1)
- ls_output = run_shell_cmd("ls -l /proc/%s/exe" % pid)
+ ls_output = self.run_shell_cmd("ls -l /proc/%s/exe" % pid)
exe = ls_output.split()[-1]
# If the binary has been deleted, the link name has " (deleted)" appended.
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