[Lldb-commits] [lldb] [LLDB] Add a target.launch-working-dir setting (PR #113521)
David Spickett via lldb-commits
lldb-commits at lists.llvm.org
Thu Oct 31 02:46:09 PDT 2024
================
@@ -206,3 +207,70 @@ def test_environment_with_special_char(self):
self.assertEqual(value, evil_var)
process.Continue()
self.assertState(process.GetState(), lldb.eStateExited, PROCESS_EXITED)
+
+ def test_target_launch_working_dir_prop(self):
+ """Test that the setting `target.launch-working-dir` is correctly used when launching a process."""
+ 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"
+
+ 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)
+ another_working_dir_path = Path(
+ os.path.join(my_working_dir_path, "..")
+ ).resolve()
+
+ # Check that we correctly override the working dir
+ launch_command = f"process launch -w {my_working_dir_path} -o {out_file_path}"
+
+ self.expect(
+ launch_command,
+ patterns=["Process .* launched: .*a.out"],
+ )
+
+ out = lldbutil.read_file_on_target(self, out_file_path)
+ self.assertIn(f"stdout: {my_working_dir_path}", out)
+
+ # Check that we can unset the setting
+ self.runCmd(f"settings set target.launch-working-dir ''")
+ launch_command = f"process launch -o {out_file_path}"
+
+ self.expect(
+ launch_command,
+ patterns=["Process .* launched: .*a.out"],
+ )
+
+ out = lldbutil.read_file_on_target(self, out_file_path)
+ self.assertNotIn(f"stdout: {another_working_dir_path}", out)
+
+ # Check that we correctly set the working dir
+ self.runCmd(
+ f"settings set target.launch-working-dir {another_working_dir_path}"
+ )
+ launch_command = f"process launch -o {out_file_path}"
+
+ self.expect(
+ launch_command,
+ patterns=["Process .* launched: .*a.out"],
+ )
+
+ out = lldbutil.read_file_on_target(self, out_file_path)
+ self.assertIn(f"stdout: {another_working_dir_path}", out)
+
+ # Check that we can unset the setting
----------------
DavidSpickett wrote:
and here.
https://github.com/llvm/llvm-project/pull/113521
More information about the lldb-commits
mailing list