9 from lldbsuite
.test
.decorators
import *
10 from lldbsuite
.test
.lldbtest
import *
11 from lldbsuite
.test
import lldbutil
13 exe_name
= "ProcessAttach" # Must match Makefile
16 class ProcessAttachTestCase(TestBase
):
17 NO_DEBUG_INFO_TESTCASE
= True
20 # Call super's setUp().
22 # Find the line number to break for main.c.
23 self
.line
= line_number("main.cpp", "// Waiting to be attached...")
26 def test_attach_to_process_by_id(self
):
27 """Test attach by process id"""
29 exe
= self
.getBuildArtifact(exe_name
)
32 popen
= self
.spawnSubprocess(exe
)
34 self
.runCmd("process attach -p " + str(popen
.pid
))
36 target
= self
.dbg
.GetSelectedTarget()
38 process
= target
.GetProcess()
39 self
.assertTrue(process
, PROCESS_IS_VALID
)
42 def test_attach_to_process_by_id_autocontinue(self
):
43 """Test attach by process id"""
45 exe
= self
.getBuildArtifact(exe_name
)
48 popen
= self
.spawnSubprocess(exe
)
50 self
.runCmd("process attach -c -p " + str(popen
.pid
))
52 target
= self
.dbg
.GetSelectedTarget()
54 process
= target
.GetProcess()
55 self
.assertTrue(process
, PROCESS_IS_VALID
)
56 self
.assertTrue(process
.GetState(), lldb
.eStateRunning
)
58 @skipIfWindows # This is flakey on Windows AND when it fails, it hangs: llvm.org/pr48806
59 def test_attach_to_process_from_different_dir_by_id(self
):
60 """Test attach by process id"""
61 newdir
= self
.getBuildArtifact("newdir")
65 if e
.errno
!= os
.errno
.EEXIST
:
67 testdir
= self
.getBuildDir()
68 exe
= os
.path
.join(newdir
, "proc_attach")
69 self
.buildProgram("main.cpp", exe
)
70 self
.addTearDownHook(lambda: shutil
.rmtree(newdir
))
73 popen
= self
.spawnSubprocess(exe
)
76 sourcedir
= self
.getSourceDir()
77 self
.addTearDownHook(lambda: os
.chdir(sourcedir
))
78 self
.runCmd("process attach -p " + str(popen
.pid
))
80 target
= self
.dbg
.GetSelectedTarget()
82 process
= target
.GetProcess()
83 self
.assertTrue(process
, PROCESS_IS_VALID
)
85 def test_attach_to_process_by_name(self
):
86 """Test attach by process name"""
88 exe
= self
.getBuildArtifact(exe_name
)
91 popen
= self
.spawnSubprocess(exe
)
93 self
.runCmd("process attach -n " + exe_name
)
95 target
= self
.dbg
.GetSelectedTarget()
97 process
= target
.GetProcess()
98 self
.assertTrue(process
, PROCESS_IS_VALID
)
100 @skipIfWindows # This test is flaky on Windows
101 @expectedFailureNetBSD
102 def test_attach_to_process_by_id_correct_executable_offset(self
):
104 Test that after attaching to a process the executable offset
105 is determined correctly on FreeBSD. This is a regression test
106 for dyld plugin getting the correct executable path,
107 and therefore being able to identify it in the module list.
111 exe
= self
.getBuildArtifact(exe_name
)
113 # In order to reproduce, we must spawn using a relative path
114 popen
= self
.spawnSubprocess(os
.path
.relpath(exe
))
116 self
.runCmd("process attach -p " + str(popen
.pid
))
118 # Make sure we did not attach too early.
119 lldbutil
.run_break_set_by_file_and_line(
120 self
, "main.cpp", self
.line
, num_expected_locations
=1, loc_exact
=False
122 self
.runCmd("process continue")
123 self
.expect("v g_val", substrs
=["12345"])
126 # Destroy process before TestBase.tearDown()
127 self
.dbg
.GetSelectedTarget().GetProcess().Destroy()
129 # Call super's tearDown().
130 TestBase
.tearDown(self
)