summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test/commands/process
diff options
context:
space:
mode:
authorRaphael Isemann <teemperor@gmail.com>2019-09-01 09:12:37 +0000
committerRaphael Isemann <teemperor@gmail.com>2019-09-01 09:12:37 +0000
commit29872606d220420d53fde7cc5e3bea15f8da62e7 (patch)
tree47d7a82ccea48a6dd10a2d8ecb6b3c3127724131 /lldb/packages/Python/lldbsuite/test/commands/process
parentadfdcb9c2652aeee585b9005fd6c67be06af8ea9 (diff)
downloadbcm5719-llvm-29872606d220420d53fde7cc5e3bea15f8da62e7.tar.gz
bcm5719-llvm-29872606d220420d53fde7cc5e3bea15f8da62e7.zip
[lldb] Restructure test folders to match LLDB command hierarchy
Summary: As discussed on lldb-dev, this patch moves some LLDB tests into a hierarchy that more closely resembles the commands we use in the LLDB interpreter. This patch should only move tests that use the command interpreter and shouldn't touch any tests that primarily test the SB API. Reviewers: #lldb, jfb, JDevlieghere Reviewed By: #lldb, JDevlieghere Subscribers: dexonsmith, arphaman, JDevlieghere, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D67033 llvm-svn: 370605
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/commands/process')
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/process/attach-resume/Makefile7
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/process/attach-resume/TestAttachResume.py93
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/process/attach-resume/main.cpp35
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/process/attach/Makefile7
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/process/attach/TestProcessAttach.py91
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/process/attach/attach_denied/Makefile14
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/process/attach/attach_denied/TestAttachDenied.py46
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/process/attach/attach_denied/entitlements.plist8
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/process/attach/attach_denied/main.cpp108
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/process/attach/main.cpp20
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/Makefile5
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/TestLaunchWithShellExpand.py120
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/file1.txt0
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/file2.txt0
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/file3.txt0
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/file4.txy0
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/file5.tyx0
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/foo bar0
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/main.cpp5
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/process/launch/Makefile7
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/process/launch/TestProcessLaunch.py205
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/process/launch/input-file.txt2
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/process/launch/main.cpp17
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/process/launch/print_cwd.cpp21
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/process/launch/print_env.cpp10
25 files changed, 821 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/commands/process/attach-resume/Makefile b/lldb/packages/Python/lldbsuite/test/commands/process/attach-resume/Makefile
new file mode 100644
index 00000000000..13d40a13b3e
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/process/attach-resume/Makefile
@@ -0,0 +1,7 @@
+LEVEL = ../../make
+
+CXX_SOURCES := main.cpp
+ENABLE_THREADS := YES
+EXE := AttachResume
+
+include $(LEVEL)/Makefile.rules
diff --git a/lldb/packages/Python/lldbsuite/test/commands/process/attach-resume/TestAttachResume.py b/lldb/packages/Python/lldbsuite/test/commands/process/attach-resume/TestAttachResume.py
new file mode 100644
index 00000000000..2c402e6a31a
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/process/attach-resume/TestAttachResume.py
@@ -0,0 +1,93 @@
+"""
+Test process attach/resume.
+"""
+
+from __future__ import print_function
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+exe_name = "AttachResume" # Must match Makefile
+
+
+class AttachResumeTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @skipIfRemote
+ @expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr19310')
+ @expectedFailureNetBSD
+ @skipIfWindows # llvm.org/pr24778, llvm.org/pr21753
+ def test_attach_continue_interrupt_detach(self):
+ """Test attach/continue/interrupt/detach"""
+ self.build()
+ self.process_attach_continue_interrupt_detach()
+
+ def process_attach_continue_interrupt_detach(self):
+ """Test attach/continue/interrupt/detach"""
+
+ exe = self.getBuildArtifact(exe_name)
+
+ popen = self.spawnSubprocess(exe)
+ self.addTearDownHook(self.cleanupSubprocesses)
+
+ self.runCmd("process attach -p " + str(popen.pid))
+
+ self.setAsync(True)
+ listener = self.dbg.GetListener()
+ process = self.dbg.GetSelectedTarget().GetProcess()
+
+ self.runCmd("c")
+ lldbutil.expect_state_changes(
+ self, listener, process, [
+ lldb.eStateRunning])
+
+ self.runCmd("process interrupt")
+ lldbutil.expect_state_changes(
+ self, listener, process, [
+ lldb.eStateStopped])
+
+ # be sure to continue/interrupt/continue (r204504)
+ self.runCmd("c")
+ lldbutil.expect_state_changes(
+ self, listener, process, [
+ lldb.eStateRunning])
+
+ self.runCmd("process interrupt")
+ lldbutil.expect_state_changes(
+ self, listener, process, [
+ lldb.eStateStopped])
+
+ # Second interrupt should have no effect.
+ self.expect(
+ "process interrupt",
+ patterns=["Process is not running"],
+ error=True)
+
+ # check that this breakpoint is auto-cleared on detach (r204752)
+ self.runCmd("br set -f main.cpp -l %u" %
+ (line_number('main.cpp', '// Set breakpoint here')))
+
+ self.runCmd("c")
+ lldbutil.expect_state_changes(
+ self, listener, process, [
+ lldb.eStateRunning, lldb.eStateStopped])
+ self.expect('br list', 'Breakpoint not hit',
+ substrs=['hit count = 1'])
+
+ # Make sure the breakpoint is not hit again.
+ self.expect("expr debugger_flag = false", substrs=[" = false"])
+
+ self.runCmd("c")
+ lldbutil.expect_state_changes(
+ self, listener, process, [
+ lldb.eStateRunning])
+
+ # make sure to detach while in running state (r204759)
+ self.runCmd("detach")
+ lldbutil.expect_state_changes(
+ self, listener, process, [
+ lldb.eStateDetached])
diff --git a/lldb/packages/Python/lldbsuite/test/commands/process/attach-resume/main.cpp b/lldb/packages/Python/lldbsuite/test/commands/process/attach-resume/main.cpp
new file mode 100644
index 00000000000..82aad70eed5
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/process/attach-resume/main.cpp
@@ -0,0 +1,35 @@
+#include <stdio.h>
+#include <fcntl.h>
+
+#include <chrono>
+#include <thread>
+
+volatile bool debugger_flag = true; // The debugger will flip this to false
+
+void *start(void *data)
+{
+ int i;
+ size_t idx = (size_t)data;
+ for (i=0; i<30; i++)
+ {
+ if ( idx == 0 && debugger_flag)
+ std::this_thread::sleep_for(std::chrono::microseconds(1)); // Set breakpoint here
+ std::this_thread::sleep_for(std::chrono::seconds(1));
+ }
+ return 0;
+}
+
+int main(int argc, char const *argv[])
+{
+ lldb_enable_attach();
+
+ static const size_t nthreads = 16;
+ std::thread threads[nthreads];
+ size_t i;
+
+ for (i=0; i<nthreads; i++)
+ threads[i] = std::move(std::thread(start, (void*)i));
+
+ for (i=0; i<nthreads; i++)
+ threads[i].join();
+}
diff --git a/lldb/packages/Python/lldbsuite/test/commands/process/attach/Makefile b/lldb/packages/Python/lldbsuite/test/commands/process/attach/Makefile
new file mode 100644
index 00000000000..a964853f534
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/process/attach/Makefile
@@ -0,0 +1,7 @@
+LEVEL = ../../make
+
+CXX_SOURCES := main.cpp
+
+EXE := ProcessAttach
+
+include $(LEVEL)/Makefile.rules
diff --git a/lldb/packages/Python/lldbsuite/test/commands/process/attach/TestProcessAttach.py b/lldb/packages/Python/lldbsuite/test/commands/process/attach/TestProcessAttach.py
new file mode 100644
index 00000000000..6210ba0eefc
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/process/attach/TestProcessAttach.py
@@ -0,0 +1,91 @@
+"""
+Test process attach.
+"""
+
+from __future__ import print_function
+
+
+import os
+import lldb
+import shutil
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+exe_name = "ProcessAttach" # Must match Makefile
+
+
+class ProcessAttachTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ NO_DEBUG_INFO_TESTCASE = True
+
+ @skipIfiOSSimulator
+ @expectedFailureNetBSD
+ def test_attach_to_process_by_id(self):
+ """Test attach by process id"""
+ self.build()
+ exe = self.getBuildArtifact(exe_name)
+
+ # Spawn a new process
+ popen = self.spawnSubprocess(exe)
+ self.addTearDownHook(self.cleanupSubprocesses)
+
+ self.runCmd("process attach -p " + str(popen.pid))
+
+ target = self.dbg.GetSelectedTarget()
+
+ process = target.GetProcess()
+ self.assertTrue(process, PROCESS_IS_VALID)
+
+ @expectedFailureNetBSD
+ def test_attach_to_process_from_different_dir_by_id(self):
+ """Test attach by process id"""
+ newdir = self.getBuildArtifact("newdir")
+ try:
+ os.mkdir(newdir)
+ except OSError as e:
+ if e.errno != os.errno.EEXIST:
+ raise
+ testdir = self.getBuildDir()
+ exe = os.path.join(newdir, 'proc_attach')
+ self.buildProgram('main.cpp', exe)
+ self.addTearDownHook(lambda: shutil.rmtree(newdir))
+
+ # Spawn a new process
+ popen = self.spawnSubprocess(exe)
+ self.addTearDownHook(self.cleanupSubprocesses)
+
+ os.chdir(newdir)
+ self.addTearDownHook(lambda: os.chdir(testdir))
+ self.runCmd("process attach -p " + str(popen.pid))
+
+ target = self.dbg.GetSelectedTarget()
+
+ process = target.GetProcess()
+ self.assertTrue(process, PROCESS_IS_VALID)
+
+ @expectedFailureNetBSD
+ def test_attach_to_process_by_name(self):
+ """Test attach by process name"""
+ self.build()
+ exe = self.getBuildArtifact(exe_name)
+
+ # Spawn a new process
+ popen = self.spawnSubprocess(exe)
+ self.addTearDownHook(self.cleanupSubprocesses)
+
+ self.runCmd("process attach -n " + exe_name)
+
+ target = self.dbg.GetSelectedTarget()
+
+ process = target.GetProcess()
+ self.assertTrue(process, PROCESS_IS_VALID)
+
+ def tearDown(self):
+ # Destroy process before TestBase.tearDown()
+ self.dbg.GetSelectedTarget().GetProcess().Destroy()
+
+ # Call super's tearDown().
+ TestBase.tearDown(self)
diff --git a/lldb/packages/Python/lldbsuite/test/commands/process/attach/attach_denied/Makefile b/lldb/packages/Python/lldbsuite/test/commands/process/attach/attach_denied/Makefile
new file mode 100644
index 00000000000..3c1f73515eb
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/process/attach/attach_denied/Makefile
@@ -0,0 +1,14 @@
+LEVEL = ../../../make
+
+CXX_SOURCES := main.cpp
+
+EXE := AttachDenied
+
+all: AttachDenied sign
+
+include $(LEVEL)/Makefile.rules
+
+sign: entitlements.plist AttachDenied
+ifeq ($(OS),Darwin)
+ codesign -s - -f --entitlements $^
+endif
diff --git a/lldb/packages/Python/lldbsuite/test/commands/process/attach/attach_denied/TestAttachDenied.py b/lldb/packages/Python/lldbsuite/test/commands/process/attach/attach_denied/TestAttachDenied.py
new file mode 100644
index 00000000000..49499554c2e
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/process/attach/attach_denied/TestAttachDenied.py
@@ -0,0 +1,46 @@
+"""
+Test denied process attach.
+"""
+
+from __future__ import print_function
+
+
+import time
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+exe_name = 'AttachDenied' # Must match Makefile
+
+
+class AttachDeniedTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+ NO_DEBUG_INFO_TESTCASE = True
+
+ @skipIfWindows
+ @skipIfiOSSimulator
+ @skipIfDarwinEmbedded # ptrace(ATTACH_REQUEST...) won't work on ios/tvos/etc
+ def test_attach_to_process_by_id_denied(self):
+ """Test attach by process id denied"""
+ self.build()
+ exe = self.getBuildArtifact(exe_name)
+
+ # Use a file as a synchronization point between test and inferior.
+ pid_file_path = lldbutil.append_to_process_working_directory(self,
+ "pid_file_%d" % (int(time.time())))
+ self.addTearDownHook(
+ lambda: self.run_platform_command(
+ "rm %s" %
+ (pid_file_path)))
+
+ # Spawn a new process
+ popen = self.spawnSubprocess(exe, [pid_file_path])
+ self.addTearDownHook(self.cleanupSubprocesses)
+
+ pid = lldbutil.wait_for_file_on_target(self, pid_file_path)
+
+ self.expect('process attach -p ' + pid,
+ startstr='error: attach failed:',
+ error=True)
diff --git a/lldb/packages/Python/lldbsuite/test/commands/process/attach/attach_denied/entitlements.plist b/lldb/packages/Python/lldbsuite/test/commands/process/attach/attach_denied/entitlements.plist
new file mode 100644
index 00000000000..3d60e8bd0b9
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/process/attach/attach_denied/entitlements.plist
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>com.apple.security.cs.debugger</key>
+ <true/>
+</dict>
+</plist>
diff --git a/lldb/packages/Python/lldbsuite/test/commands/process/attach/attach_denied/main.cpp b/lldb/packages/Python/lldbsuite/test/commands/process/attach/attach_denied/main.cpp
new file mode 100644
index 00000000000..ff1fccae4b1
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/process/attach/attach_denied/main.cpp
@@ -0,0 +1,108 @@
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <sys/ptrace.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+
+#if defined(PTRACE_ATTACH)
+#define ATTACH_REQUEST PTRACE_ATTACH
+#define DETACH_REQUEST PTRACE_DETACH
+#elif defined(PT_ATTACH)
+#define ATTACH_REQUEST PT_ATTACH
+#define DETACH_REQUEST PT_DETACH
+#else
+#error "Unsupported platform"
+#endif
+
+bool writePid (const char* file_name, const pid_t pid)
+{
+ char *tmp_file_name = (char *)malloc(strlen(file_name) + 16);
+ strcpy(tmp_file_name, file_name);
+ strcat(tmp_file_name, "_tmp");
+ int fd = open (tmp_file_name, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR);
+ if (fd == -1)
+ {
+ fprintf (stderr, "open(%s) failed: %s\n", tmp_file_name, strerror (errno));
+ free(tmp_file_name);
+ return false;
+ }
+ char buffer[64];
+ snprintf (buffer, sizeof(buffer), "%ld", (long)pid);
+
+ bool res = true;
+ if (write (fd, buffer, strlen (buffer)) == -1)
+ {
+ fprintf (stderr, "write(%s) failed: %s\n", buffer, strerror (errno));
+ res = false;
+ }
+ close (fd);
+
+ if (rename (tmp_file_name, file_name) == -1)
+ {
+ fprintf (stderr, "rename(%s, %s) failed: %s\n", tmp_file_name, file_name, strerror (errno));
+ res = false;
+ }
+ free(tmp_file_name);
+
+ return res;
+}
+
+void signal_handler (int)
+{
+}
+
+int main (int argc, char const *argv[])
+{
+ if (argc < 2)
+ {
+ fprintf (stderr, "invalid number of command line arguments\n");
+ return 1;
+ }
+
+ const pid_t pid = fork ();
+ if (pid == -1)
+ {
+ fprintf (stderr, "fork failed: %s\n", strerror (errno));
+ return 1;
+ }
+
+ if (pid > 0)
+ {
+ // Make pause call to return when a signal is received. Normally this happens when the
+ // test runner tries to terminate us.
+ signal (SIGHUP, signal_handler);
+ signal (SIGTERM, signal_handler);
+ if (ptrace (ATTACH_REQUEST, pid, NULL, 0) == -1)
+ {
+ fprintf (stderr, "ptrace(ATTACH) failed: %s\n", strerror (errno));
+ }
+ else
+ {
+ if (writePid (argv[1], pid))
+ pause (); // Waiting for the debugger trying attach to the child.
+
+ if (ptrace (DETACH_REQUEST, pid, NULL, 0) != 0)
+ fprintf (stderr, "ptrace(DETACH) failed: %s\n", strerror (errno));
+ }
+
+ kill (pid, SIGTERM);
+ int status = 0;
+ if (waitpid (pid, &status, 0) == -1)
+ fprintf (stderr, "waitpid failed: %s\n", strerror (errno));
+ }
+ else
+ {
+ // child inferior.
+ pause ();
+ }
+
+ printf ("Exiting now\n");
+ return 0;
+}
diff --git a/lldb/packages/Python/lldbsuite/test/commands/process/attach/main.cpp b/lldb/packages/Python/lldbsuite/test/commands/process/attach/main.cpp
new file mode 100644
index 00000000000..46ffacc0a84
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/process/attach/main.cpp
@@ -0,0 +1,20 @@
+#include <stdio.h>
+
+#include <chrono>
+#include <thread>
+
+int main(int argc, char const *argv[]) {
+ int temp;
+ lldb_enable_attach();
+
+ // Waiting to be attached by the debugger.
+ temp = 0;
+
+ while (temp < 30) // Waiting to be attached...
+ {
+ std::this_thread::sleep_for(std::chrono::seconds(2));
+ temp++;
+ }
+
+ printf("Exiting now\n");
+}
diff --git a/lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/Makefile b/lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/Makefile
new file mode 100644
index 00000000000..8a7102e347a
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/Makefile
@@ -0,0 +1,5 @@
+LEVEL = ../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules
diff --git a/lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/TestLaunchWithShellExpand.py b/lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/TestLaunchWithShellExpand.py
new file mode 100644
index 00000000000..1ba812159fb
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/TestLaunchWithShellExpand.py
@@ -0,0 +1,120 @@
+"""
+Test that argdumper is a viable launching strategy.
+"""
+from __future__ import print_function
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class LaunchWithShellExpandTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @expectedFailureAll(
+ oslist=[
+ "windows",
+ "linux",
+ "freebsd"],
+ bugnumber="llvm.org/pr24778 llvm.org/pr22627")
+ @skipIfDarwinEmbedded # iOS etc don't launch the binary via a shell, so arg expansion won't happen
+ @expectedFailureNetBSD
+ def test(self):
+ self.build()
+ exe = self.getBuildArtifact("a.out")
+
+ self.runCmd("target create %s" % exe)
+
+ # Create the target
+ target = self.dbg.CreateTarget(exe)
+
+ # Create any breakpoints we need
+ breakpoint = target.BreakpointCreateBySourceRegex(
+ 'break here', lldb.SBFileSpec("main.cpp", False))
+ self.assertTrue(breakpoint, VALID_BREAKPOINT)
+
+ self.runCmd(
+ "process launch -X true -w %s -- fi*.tx? () > <" %
+ (self.getSourceDir()))
+
+ process = self.process()
+
+ self.assertTrue(process.GetState() == lldb.eStateStopped,
+ STOPPED_DUE_TO_BREAKPOINT)
+
+ thread = process.GetThreadAtIndex(0)
+
+ self.assertTrue(thread.IsValid(),
+ "Process stopped at 'main' should have a valid thread")
+
+ stop_reason = thread.GetStopReason()
+
+ self.assertTrue(
+ stop_reason == lldb.eStopReasonBreakpoint,
+ "Thread in process stopped in 'main' should have a stop reason of eStopReasonBreakpoint")
+
+ self.expect("frame variable argv[1]", substrs=['file1.txt'])
+ self.expect("frame variable argv[2]", substrs=['file2.txt'])
+ self.expect("frame variable argv[3]", substrs=['file3.txt'])
+ self.expect("frame variable argv[4]", substrs=['file4.txy'])
+ self.expect("frame variable argv[5]", substrs=['()'])
+ self.expect("frame variable argv[6]", substrs=['>'])
+ self.expect("frame variable argv[7]", substrs=['<'])
+ self.expect(
+ "frame variable argv[5]",
+ substrs=['file5.tyx'],
+ matching=False)
+ self.expect(
+ "frame variable argv[8]",
+ substrs=['file5.tyx'],
+ matching=False)
+
+ self.runCmd("process kill")
+
+ self.runCmd(
+ 'process launch -X true -w %s -- "foo bar"' %
+ (self.getSourceDir()))
+
+ process = self.process()
+
+ self.assertTrue(process.GetState() == lldb.eStateStopped,
+ STOPPED_DUE_TO_BREAKPOINT)
+
+ thread = process.GetThreadAtIndex(0)
+
+ self.assertTrue(thread.IsValid(),
+ "Process stopped at 'main' should have a valid thread")
+
+ stop_reason = thread.GetStopReason()
+
+ self.assertTrue(
+ stop_reason == lldb.eStopReasonBreakpoint,
+ "Thread in process stopped in 'main' should have a stop reason of eStopReasonBreakpoint")
+
+ self.expect("frame variable argv[1]", substrs=['foo bar'])
+
+ self.runCmd("process kill")
+
+ self.runCmd('process launch -X true -w %s -- foo\ bar'
+ % (self.getBuildDir()))
+
+ process = self.process()
+
+ self.assertTrue(process.GetState() == lldb.eStateStopped,
+ STOPPED_DUE_TO_BREAKPOINT)
+
+ thread = process.GetThreadAtIndex(0)
+
+ self.assertTrue(thread.IsValid(),
+ "Process stopped at 'main' should have a valid thread")
+
+ stop_reason = thread.GetStopReason()
+
+ self.assertTrue(
+ stop_reason == lldb.eStopReasonBreakpoint,
+ "Thread in process stopped in 'main' should have a stop reason of eStopReasonBreakpoint")
+
+ self.expect("frame variable argv[1]", substrs=['foo bar'])
diff --git a/lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/file1.txt b/lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/file1.txt
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/file1.txt
diff --git a/lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/file2.txt b/lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/file2.txt
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/file2.txt
diff --git a/lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/file3.txt b/lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/file3.txt
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/file3.txt
diff --git a/lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/file4.txy b/lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/file4.txy
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/file4.txy
diff --git a/lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/file5.tyx b/lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/file5.tyx
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/file5.tyx
diff --git a/lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/foo bar b/lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/foo bar
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/foo bar
diff --git a/lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/main.cpp b/lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/main.cpp
new file mode 100644
index 00000000000..cbef8d1e6da
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/process/launch-with-shellexpand/main.cpp
@@ -0,0 +1,5 @@
+int
+main (int argc, char const **argv)
+{
+ return 0; // break here
+}
diff --git a/lldb/packages/Python/lldbsuite/test/commands/process/launch/Makefile b/lldb/packages/Python/lldbsuite/test/commands/process/launch/Makefile
new file mode 100644
index 00000000000..313da706b4a
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/process/launch/Makefile
@@ -0,0 +1,7 @@
+LEVEL = ../../make
+
+CXX_SOURCES := main.cpp
+#CXX_SOURCES := print-cwd.cpp
+
+include $(LEVEL)/Makefile.rules
+
diff --git a/lldb/packages/Python/lldbsuite/test/commands/process/launch/TestProcessLaunch.py b/lldb/packages/Python/lldbsuite/test/commands/process/launch/TestProcessLaunch.py
new file mode 100644
index 00000000000..a2b27c2e590
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/process/launch/TestProcessLaunch.py
@@ -0,0 +1,205 @@
+"""
+Test lldb process launch flags.
+"""
+
+from __future__ import print_function
+
+import os
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+import six
+
+
+class ProcessLaunchTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+ NO_DEBUG_INFO_TESTCASE = True
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ self.runCmd("settings set auto-confirm true")
+
+ def tearDown(self):
+ self.runCmd("settings clear auto-confirm")
+ TestBase.tearDown(self)
+
+ @not_remote_testsuite_ready
+ def test_io(self):
+ """Test that process launch I/O redirection flags work properly."""
+ self.build()
+ exe = self.getBuildArtifact("a.out")
+ self.expect("file " + exe,
+ patterns=["Current executable set to .*a.out"])
+
+ in_file = os.path.join(self.getSourceDir(), "input-file.txt")
+ out_file = lldbutil.append_to_process_working_directory(self, "output-test.out")
+ err_file = lldbutil.append_to_process_working_directory(self, "output-test.err")
+
+ # Make sure the output files do not exist before launching the process
+ try:
+ os.remove(out_file)
+ except OSError:
+ pass
+
+ try:
+ os.remove(err_file)
+ except OSError:
+ pass
+
+ launch_command = "process launch -i '{0}' -o '{1}' -e '{2}' -w '{3}'".format(
+ in_file, out_file, err_file, self.get_process_working_directory())
+
+ if lldb.remote_platform:
+ self.runCmd('platform put-file "{local}" "{remote}"'.format(
+ local=in_file, remote=in_file))
+
+ self.expect(launch_command,
+ patterns=["Process .* launched: .*a.out"])
+
+ success = True
+ err_msg = ""
+
+ out = lldbutil.read_file_on_target(self, out_file)
+ if out != "This should go to stdout.\n":
+ success = False
+ err_msg = err_msg + " ERROR: stdout file does not contain correct output.\n"
+
+
+ err = lldbutil.read_file_on_target(self, err_file)
+ if err != "This should go to stderr.\n":
+ success = False
+ err_msg = err_msg + " ERROR: stderr file does not contain correct output.\n"
+
+ if not success:
+ self.fail(err_msg)
+
+ # rdar://problem/9056462
+ # The process launch flag '-w' for setting the current working directory
+ # not working?
+ @not_remote_testsuite_ready
+ @expectedFailureAll(oslist=["linux"], bugnumber="llvm.org/pr20265")
+ @expectedFailureNetBSD
+ def test_set_working_dir_nonexisting(self):
+ """Test that '-w dir' fails to set the working dir when running the inferior with a dir which doesn't exist."""
+ d = {'CXX_SOURCES': 'print_cwd.cpp'}
+ self.build(dictionary=d)
+ self.setTearDownCleanup(d)
+ exe = self.getBuildArtifact("a.out")
+ self.runCmd("file " + exe)
+
+ mywd = 'my_working_dir'
+ out_file_name = "my_working_dir_test.out"
+ err_file_name = "my_working_dir_test.err"
+
+ my_working_dir_path = self.getBuildArtifact(mywd)
+ out_file_path = os.path.join(my_working_dir_path, out_file_name)
+ err_file_path = os.path.join(my_working_dir_path, err_file_name)
+
+ # Check that we get an error when we have a nonexisting path
+ invalid_dir_path = mywd + 'z'
+ launch_command = "process launch -w %s -o %s -e %s" % (
+ invalid_dir_path, out_file_path, err_file_path)
+
+ self.expect(
+ launch_command, error=True, patterns=[
+ "error:.* No such file or directory: %s" %
+ invalid_dir_path])
+
+ @not_remote_testsuite_ready
+ def test_set_working_dir_existing(self):
+ """Test that '-w dir' sets the working dir when running the inferior."""
+ d = {'CXX_SOURCES': 'print_cwd.cpp'}
+ self.build(dictionary=d)
+ self.setTearDownCleanup(d)
+ exe = self.getBuildArtifact("a.out")
+ self.runCmd("file " + exe)
+
+ mywd = 'my_working_dir'
+ out_file_name = "my_working_dir_test.out"
+ err_file_name = "my_working_dir_test.err"
+
+ my_working_dir_path = self.getBuildArtifact(mywd)
+ lldbutil.mkdir_p(my_working_dir_path)
+ out_file_path = os.path.join(my_working_dir_path, out_file_name)
+ err_file_path = os.path.join(my_working_dir_path, err_file_name)
+
+ # Make sure the output files do not exist before launching the process
+ try:
+ os.remove(out_file_path)
+ os.remove(err_file_path)
+ except OSError:
+ pass
+
+ launch_command = "process launch -w %s -o %s -e %s" % (
+ my_working_dir_path, out_file_path, err_file_path)
+
+ self.expect(launch_command,
+ patterns=["Process .* launched: .*a.out"])
+
+ success = True
+ err_msg = ""
+
+ # Check to see if the 'stdout' file was created
+ try:
+ out_f = open(out_file_path)
+ except IOError:
+ success = False
+ err_msg = err_msg + "ERROR: stdout file was not created.\n"
+ else:
+ # Check to see if the 'stdout' file contains the right output
+ line = out_f.readline()
+ if self.TraceOn():
+ print("line:", line)
+ if not re.search(mywd, line):
+ success = False
+ err_msg = err_msg + "The current working directory was not set correctly.\n"
+ out_f.close()
+
+ # Try to delete the 'stdout' and 'stderr' files
+ try:
+ os.remove(out_file_path)
+ os.remove(err_file_path)
+ except OSError:
+ pass
+
+ if not success:
+ self.fail(err_msg)
+
+ def test_environment_with_special_char(self):
+ """Test that environment variables containing '*' and '}' are handled correctly by the inferior."""
+ source = 'print_env.cpp'
+ d = {'CXX_SOURCES': source}
+ self.build(dictionary=d)
+ self.setTearDownCleanup(d)
+ exe = self.getBuildArtifact("a.out")
+
+ evil_var = 'INIT*MIDDLE}TAIL'
+
+ target = self.dbg.CreateTarget(exe)
+ main_source_spec = lldb.SBFileSpec(source)
+ breakpoint = target.BreakpointCreateBySourceRegex(
+ '// Set breakpoint here.', main_source_spec)
+
+ process = target.LaunchSimple(None,
+ ['EVIL=' + evil_var],
+ self.get_process_working_directory())
+ self.assertEqual(
+ process.GetState(),
+ lldb.eStateStopped,
+ PROCESS_STOPPED)
+
+ threads = lldbutil.get_threads_stopped_at_breakpoint(
+ process, breakpoint)
+ self.assertEqual(len(threads), 1)
+ frame = threads[0].GetFrameAtIndex(0)
+ sbvalue = frame.EvaluateExpression("evil")
+ value = sbvalue.GetSummary().strip('"')
+
+ self.assertEqual(value, evil_var)
+ process.Continue()
+ self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED)
diff --git a/lldb/packages/Python/lldbsuite/test/commands/process/launch/input-file.txt b/lldb/packages/Python/lldbsuite/test/commands/process/launch/input-file.txt
new file mode 100644
index 00000000000..cc269ba0ff8
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/process/launch/input-file.txt
@@ -0,0 +1,2 @@
+This should go to stdout.
+This should go to stderr.
diff --git a/lldb/packages/Python/lldbsuite/test/commands/process/launch/main.cpp b/lldb/packages/Python/lldbsuite/test/commands/process/launch/main.cpp
new file mode 100644
index 00000000000..f2035d55167
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/process/launch/main.cpp
@@ -0,0 +1,17 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int
+main (int argc, char **argv)
+{
+ char buffer[1024];
+
+ fgets (buffer, sizeof (buffer), stdin);
+ fprintf (stdout, "%s", buffer);
+
+
+ fgets (buffer, sizeof (buffer), stdin);
+ fprintf (stderr, "%s", buffer);
+
+ return 0;
+}
diff --git a/lldb/packages/Python/lldbsuite/test/commands/process/launch/print_cwd.cpp b/lldb/packages/Python/lldbsuite/test/commands/process/launch/print_cwd.cpp
new file mode 100644
index 00000000000..b4b073fbcb8
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/process/launch/print_cwd.cpp
@@ -0,0 +1,21 @@
+#include <stdio.h>
+
+#ifdef _MSC_VER
+#define _CRT_NONSTDC_NO_WARNINGS
+#include <direct.h>
+#undef getcwd
+#define getcwd(buffer, length) _getcwd(buffer, length)
+#else
+#include <unistd.h>
+#endif
+
+int
+main (int argc, char **argv)
+{
+ char buffer[1024];
+
+ fprintf(stdout, "stdout: %s\n", getcwd(buffer, 1024));
+ fprintf(stderr, "stderr: %s\n", getcwd(buffer, 1024));
+
+ return 0;
+}
diff --git a/lldb/packages/Python/lldbsuite/test/commands/process/launch/print_env.cpp b/lldb/packages/Python/lldbsuite/test/commands/process/launch/print_env.cpp
new file mode 100644
index 00000000000..8c6df8ea01a
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/process/launch/print_env.cpp
@@ -0,0 +1,10 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+int main (int argc, char **argv)
+{
+ char *evil = getenv("EVIL");
+
+ return 0; // Set breakpoint here.
+}
OpenPOWER on IntegriCloud