"""
Test that the lldb driver's batch mode works correctly.
"""
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
from lldbsuite.test.lldbpexpect import PExpectTest
class DriverBatchModeTest(PExpectTest):
source = "main.c"
@skipIf(macos_version=["<", "14.0"], asan=True)
@skipIf(oslist=["linux"], archs=["arm", "aarch64"])
@expectedFlakeyFreeBSD("llvm.org/pr25172 fails rarely on the buildbot")
def test_batch_mode_run_crash(self):
"""Test that the lldb driver's batch mode works correctly."""
self.build()
exe = self.getBuildArtifact("a.out")
extra_args = [
"-b",
"-o",
"break set -n main",
"-o",
"run",
"-o",
"continue",
"-k",
"frame var touch_me_not",
"--",
"CRASH",
]
self.launch(executable=exe, extra_args=extra_args)
child = self.child
child.expect_exact("run")
child.expect_exact("continue")
child.expect_exact("About to crash")
child.expect_exact("(char *) touch_me_not")
self.expect_prompt()
self.expect("frame variable touch_me_not", substrs=["(char *) touch_me_not"])
@skipIf(macos_version=["<", "14.0"], asan=True)
@skipIf(oslist=["linux"], archs=["arm", "aarch64"])
@expectedFlakeyFreeBSD("llvm.org/pr25172 fails rarely on the buildbot")
def test_batch_mode_run_exit(self):
"""Test that the lldb driver's batch mode works correctly."""
self.build()
exe = self.getBuildArtifact("a.out")
extra_args = [
"-b",
"-o",
"break set -n main",
"-o",
"run",
"-o",
"continue",
"--",
"NOCRASH",
]
self.launch(executable=exe, extra_args=extra_args)
child = self.child
child.expect_exact("run")
child.expect_exact("continue")
child.expect_exact("Got there on time and it did not crash.")
child.expect_exact("exited")
import pexpect
child.expect(pexpect.EOF)
@skipIf(macos_version=["<", "14.0"], asan=True)
@skipIf(oslist=["linux"], archs=["arm", "aarch64"])
@expectedFlakeyFreeBSD("llvm.org/pr25172 fails rarely on the buildbot")
def test_batch_mode_launch_stop_at_entry(self):
"""Test that the lldb driver's batch mode works correctly for process launch."""
self.build()
exe = self.getBuildArtifact("a.out")
extra_args = [
"-b",
"-o",
"process launch --stop-at-entry",
"-o",
"continue",
]
self.launch(executable=exe, extra_args=extra_args)
child = self.child
child.expect("Process ([0-9]+) launched:")
child.expect_exact("continue")
child.expect_exact("Got there on time and it did not crash.")
child.expect_exact("exited")
import pexpect
child.expect(pexpect.EOF)
def closeVictim(self):
if self.victim is not None:
self.victim.close()
self.victim = None
@skipIf(macos_version=["<", "14.0"], asan=True)
@skipIf(oslist=["linux"], archs=["arm", "aarch64"])
@expectedFlakeyFreeBSD("llvm.org/pr25172 fails rarely on the buildbot")
@expectedFailureNetBSD
def test_batch_mode_attach_exit(self):
"""Test that the lldb driver's batch mode works correctly."""
self.build()
self.setTearDownCleanup()
exe = self.getBuildArtifact("a.out")
import pexpect
self.victim = pexpect.spawn("%s WAIT" % (exe))
if self.victim is None:
self.fail("Could not spawn ", exe, ".")
self.addTearDownHook(self.closeVictim)
self.victim.expect("PID: ([0-9]+) END")
victim_pid = int(self.victim.match.group(1))
self.victim.expect("Waiting")
extra_args = [
"-b",
"-o",
"process attach -p %d" % victim_pid,
"-o",
"breakpoint set --file '%s' -p 'Stop here to unset keep_waiting' -N keep_waiting"
% self.source,
"-o",
"continue",
"-o",
"break delete keep_waiting",
"-o",
"expr keep_waiting = 0",
"-o",
"continue",
]
self.launch(executable=exe, extra_args=extra_args)
child = self.child
child.expect_exact("attach")
child.expect_exact(self.PROMPT + "continue")
child.expect_exact(self.PROMPT + "continue")
child.expect_exact("Process %d exited with status" % (victim_pid))
self.victim.expect(pexpect.EOF)
child.expect(pexpect.EOF)