"""
Test thread creation after process attach.
"""
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class CreateAfterAttachTestCase(TestBase):
def setUp(self):
TestBase.setUp(self)
self.break_1 = line_number("main.cpp", "// Set first breakpoint here")
self.break_2 = line_number("main.cpp", "// Set second breakpoint here")
self.break_3 = line_number("main.cpp", "// Set third breakpoint here")
@skipIfWindows
@skipIfiOSSimulator
@expectedFailureNetBSD
def test_create_after_attach(self):
"""Test thread creation after process attach."""
self.build()
exe = self.getBuildArtifact("a.out")
popen = self.spawnSubprocess(os.path.realpath(exe))
pid = popen.pid
self.runCmd("process attach -p " + str(pid))
target = self.dbg.GetSelectedTarget()
process = target.GetProcess()
self.assertTrue(process, PROCESS_IS_VALID)
lldbutil.run_break_set_by_file_and_line(
self, "main.cpp", self.break_1, num_expected_locations=1
)
lldbutil.run_break_set_by_file_and_line(
self, "main.cpp", self.break_2, num_expected_locations=1
)
lldbutil.run_break_set_by_file_and_line(
self, "main.cpp", self.break_3, num_expected_locations=1
)
self.runCmd("continue")
self.expect(
"thread list",
STOPPED_DUE_TO_BREAKPOINT,
substrs=["stopped", "* thread #", "main", "stop reason = breakpoint"],
)
self.runCmd("expression main_thread_continue = 1")
self.runCmd("continue")
self.expect(
"thread list",
STOPPED_DUE_TO_BREAKPOINT,
substrs=[
"stopped",
"* thread #",
"thread_2_func",
"stop reason = breakpoint",
],
)
self.runCmd("expression child_thread_continue = 1")
self.runCmd("continue")
self.expect(
"thread list",
STOPPED_DUE_TO_BREAKPOINT,
substrs=[
"stopped",
"* thread #",
"thread_1_func",
"stop reason = breakpoint",
],
)
self.runCmd("continue")
self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED)