2013-05-03 00:10:27 +00:00
|
|
|
"""
|
|
|
|
|
Test process attach.
|
|
|
|
|
"""
|
|
|
|
|
|
2015-10-23 17:04:29 +00:00
|
|
|
|
2015-11-03 19:20:39 +00:00
|
|
|
|
2013-05-03 00:10:27 +00:00
|
|
|
import os
|
|
|
|
|
import lldb
|
2017-09-03 01:44:35 +00:00
|
|
|
import shutil
|
2016-02-04 23:04:17 +00:00
|
|
|
from lldbsuite.test.decorators import *
|
2015-11-03 02:06:18 +00:00
|
|
|
from lldbsuite.test.lldbtest import *
|
2016-02-04 23:04:17 +00:00
|
|
|
from lldbsuite.test import lldbutil
|
2013-05-03 00:10:27 +00:00
|
|
|
|
2014-03-07 00:01:11 +00:00
|
|
|
exe_name = "ProcessAttach" # Must match Makefile
|
|
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2013-05-03 00:10:27 +00:00
|
|
|
class ProcessAttachTestCase(TestBase):
|
|
|
|
|
|
2013-12-10 23:19:29 +00:00
|
|
|
mydir = TestBase.compute_mydir(__file__)
|
2013-05-03 00:10:27 +00:00
|
|
|
|
2016-11-01 18:50:34 +00:00
|
|
|
NO_DEBUG_INFO_TESTCASE = True
|
|
|
|
|
|
2015-11-05 00:46:25 +00:00
|
|
|
@skipIfiOSSimulator
|
2019-03-04 16:54:06 +00:00
|
|
|
@expectedFailureNetBSD
|
2015-09-30 10:12:40 +00:00
|
|
|
def test_attach_to_process_by_id(self):
|
2013-05-03 00:10:27 +00:00
|
|
|
"""Test attach by process id"""
|
2015-09-30 10:12:40 +00:00
|
|
|
self.build()
|
2018-01-30 18:29:16 +00:00
|
|
|
exe = self.getBuildArtifact(exe_name)
|
2013-05-03 00:10:27 +00:00
|
|
|
|
|
|
|
|
# Spawn a new process
|
|
|
|
|
popen = self.spawnSubprocess(exe)
|
|
|
|
|
|
|
|
|
|
self.runCmd("process attach -p " + str(popen.pid))
|
|
|
|
|
|
|
|
|
|
target = self.dbg.GetSelectedTarget()
|
|
|
|
|
|
|
|
|
|
process = target.GetProcess()
|
|
|
|
|
self.assertTrue(process, PROCESS_IS_VALID)
|
|
|
|
|
|
2019-03-04 16:54:06 +00:00
|
|
|
@expectedFailureNetBSD
|
2020-05-27 13:10:19 -07:00
|
|
|
@skipIfReproducer # FIXME: Unexpected packet during (active) replay
|
2017-09-03 01:44:35 +00:00
|
|
|
def test_attach_to_process_from_different_dir_by_id(self):
|
|
|
|
|
"""Test attach by process id"""
|
2018-01-30 18:29:16 +00:00
|
|
|
newdir = self.getBuildArtifact("newdir")
|
2017-09-03 01:44:35 +00:00
|
|
|
try:
|
2018-01-30 18:29:16 +00:00
|
|
|
os.mkdir(newdir)
|
2018-02-08 23:10:29 +00:00
|
|
|
except OSError as e:
|
2017-09-03 01:44:35 +00:00
|
|
|
if e.errno != os.errno.EEXIST:
|
|
|
|
|
raise
|
2018-01-30 18:29:16 +00:00
|
|
|
testdir = self.getBuildDir()
|
2017-09-13 02:44:24 +00:00
|
|
|
exe = os.path.join(newdir, 'proc_attach')
|
|
|
|
|
self.buildProgram('main.cpp', exe)
|
|
|
|
|
self.addTearDownHook(lambda: shutil.rmtree(newdir))
|
2017-09-03 01:44:35 +00:00
|
|
|
|
|
|
|
|
# Spawn a new process
|
|
|
|
|
popen = self.spawnSubprocess(exe)
|
|
|
|
|
|
2018-01-30 18:29:16 +00:00
|
|
|
os.chdir(newdir)
|
2017-09-13 02:44:24 +00:00
|
|
|
self.addTearDownHook(lambda: os.chdir(testdir))
|
2017-09-03 01:44:35 +00:00
|
|
|
self.runCmd("process attach -p " + str(popen.pid))
|
|
|
|
|
|
|
|
|
|
target = self.dbg.GetSelectedTarget()
|
|
|
|
|
|
|
|
|
|
process = target.GetProcess()
|
|
|
|
|
self.assertTrue(process, PROCESS_IS_VALID)
|
|
|
|
|
|
2019-03-04 16:54:06 +00:00
|
|
|
@expectedFailureNetBSD
|
2015-09-30 10:12:40 +00:00
|
|
|
def test_attach_to_process_by_name(self):
|
2013-05-03 00:10:27 +00:00
|
|
|
"""Test attach by process name"""
|
2015-09-30 10:12:40 +00:00
|
|
|
self.build()
|
2018-01-30 18:29:16 +00:00
|
|
|
exe = self.getBuildArtifact(exe_name)
|
2013-05-03 00:10:27 +00:00
|
|
|
|
|
|
|
|
# Spawn a new process
|
|
|
|
|
popen = self.spawnSubprocess(exe)
|
|
|
|
|
|
2014-03-07 00:01:11 +00:00
|
|
|
self.runCmd("process attach -n " + exe_name)
|
2013-05-03 00:10:27 +00:00
|
|
|
|
2013-05-08 23:45:06 +00:00
|
|
|
target = self.dbg.GetSelectedTarget()
|
|
|
|
|
|
2013-05-03 23:04:47 +00:00
|
|
|
process = target.GetProcess()
|
2013-05-03 00:10:27 +00:00
|
|
|
self.assertTrue(process, PROCESS_IS_VALID)
|
|
|
|
|
|
2015-09-30 10:12:40 +00:00
|
|
|
def tearDown(self):
|
|
|
|
|
# Destroy process before TestBase.tearDown()
|
|
|
|
|
self.dbg.GetSelectedTarget().GetProcess().Destroy()
|
|
|
|
|
|
|
|
|
|
# Call super's tearDown().
|
|
|
|
|
TestBase.tearDown(self)
|