1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
|
"""
Test lldb-mi startup options.
"""
from __future__ import print_function
import lldbmi_testcase
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
import os
class MiStartupOptionsTestCase(lldbmi_testcase.MiTestCaseBase):
mydir = TestBase.compute_mydir(__file__)
@skipIfRemote # We do not currently support remote debugging via the MI.
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfDarwin
def test_lldbmi_executable_option_file(self):
"""Test that 'lldb-mi --interpreter %s' loads executable file."""
self.spawnLldbMi(args="%s" % self.myexe)
# Test that the executable is loaded when file was specified
self.expect("-file-exec-and-symbols \"%s\"" % self.myexe)
self.expect("\^done")
# Test that lldb-mi is ready when executable was loaded
self.expect(self.child_prompt, exactly=True)
# Run to main
self.runCmd("-break-insert -f main")
self.expect("\^done,bkpt={number=\"1\"")
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
# Continue
self.runCmd("-exec-continue")
self.expect("\^running")
self.expect("\*stopped,reason=\"exited-normally\"")
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfDarwin
def test_lldbmi_executable_option_unknown_file(self):
"""Test that 'lldb-mi --interpreter %s' fails on unknown executable file."""
# Prepare path to executable
path = "unknown_file"
self.spawnLldbMi(args="%s" % path)
# Test that the executable isn't loaded when unknown file was specified
self.expect("-file-exec-and-symbols \"%s\"" % path)
self.expect(
"\^error,msg=\"Command 'file-exec-and-symbols'. Target binary '%s' is invalid. error: unable to find executable for '%s'\"" %
(path, path))
# Test that lldb-mi is ready when executable was loaded
self.expect(self.child_prompt, exactly=True)
@skipIfRemote # We do not currently support remote debugging via the MI.
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfDarwin
def test_lldbmi_executable_option_absolute_path(self):
"""Test that 'lldb-mi --interpreter %s' loads executable which is specified via absolute path."""
# Prepare path to executable
self.spawnLldbMi(args="%s" % self.myexe)
# Test that the executable is loaded when file was specified using
# absolute path
self.expect("-file-exec-and-symbols \"%s\"" % self.myexe)
self.expect("\^done")
# Test that lldb-mi is ready when executable was loaded
self.expect(self.child_prompt, exactly=True)
# Run
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"exited-normally\"")
@skipIfRemote # We do not currently support remote debugging via the MI.
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfDarwin
def test_lldbmi_executable_option_relative_path(self):
"""Test that 'lldb-mi --interpreter %s' loads executable which is specified via relative path."""
# Prepare path to executable
path = os.path.relpath(self.myexe, self.getBuildDir())
self.spawnLldbMi(args="%s" % path)
# Test that the executable is loaded when file was specified using
# relative path
self.expect("-file-exec-and-symbols \"%s\"" % path)
self.expect("\^done")
# Test that lldb-mi is ready when executable was loaded
self.expect(self.child_prompt, exactly=True)
# Run
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"exited-normally\"")
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfDarwin
def test_lldbmi_executable_option_unknown_path(self):
"""Test that 'lldb-mi --interpreter %s' fails on executable file which is specified via unknown path."""
# Prepare path to executable
path = "unknown_dir" + self.myexe
self.spawnLldbMi(args="%s" % path)
# Test that the executable isn't loaded when file was specified using
# unknown path
self.expect("-file-exec-and-symbols \"%s\"" % path)
self.expect(
"\^error,msg=\"Command 'file-exec-and-symbols'. Target binary '%s' is invalid. error: unable to find executable for '%s'\"" %
(path, path))
# Test that lldb-mi is ready when executable was loaded
self.expect(self.child_prompt, exactly=True)
def copyScript(self, sourceFile):
"""copy the script to builddir and replace a.out with the full path"""
destFile = os.path.join(os.path.dirname(self.myexe),
sourceFile+'.script')
with open(sourceFile, 'r') as src:
with open(destFile, 'w+') as dest:
dest.write(src.read().replace("a.out", self.myexe))
return destFile
@skipIfRemote # We do not currently support remote debugging via the MI.
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfLinux # llvm.org/pr22841: lldb-mi tests fail on all Linux buildbots
@skipIfDarwin
def test_lldbmi_source_option_start_script(self):
"""Test that 'lldb-mi --interpreter' can execute user's commands after initial commands were executed."""
# Prepared source file
sourceFile = self.copyScript("start_script")
self.spawnLldbMi(args="--source %s" % sourceFile)
# After '-file-exec-and-symbols a.out'
self.expect("-file-exec-and-symbols %s" % self.myexe)
self.expect("\^done")
# After '-break-insert -f main'
self.expect("-break-insert -f main")
self.expect("\^done,bkpt={number=\"1\"")
# After '-exec-run'
self.expect("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
# After '-break-insert main.cpp:BP_return'
line = line_number('main.cpp', '//BP_return')
self.expect("-break-insert main.cpp:%d" % line)
self.expect("\^done,bkpt={number=\"2\"")
# After '-exec-continue'
self.expect("-exec-continue")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
# Test that lldb-mi is ready after execution of --source start_script
self.expect(self.child_prompt, exactly=True)
# Try to evaluate 'a' expression
self.runCmd("-data-evaluate-expression a")
self.expect("\^done,value=\"10\"")
self.expect(self.child_prompt, exactly=True)
os.unlink(sourceFile)
@skipIfRemote # We do not currently support remote debugging via the MI.
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfLinux # llvm.org/pr22841: lldb-mi tests fail on all Linux buildbots
@skipIfDarwin
def test_lldbmi_source_option_start_script_exit(self):
"""Test that 'lldb-mi --interpreter' can execute a prepared file which passed via --source option."""
# Prepared source file
sourceFile = self.copyScript("start_script_exit")
self.spawnLldbMi(args="--source %s" % sourceFile)
# After '-file-exec-and-symbols a.out'
self.expect("-file-exec-and-symbols %s" % self.myexe)
self.expect("\^done")
# After '-break-insert -f main'
self.expect("-break-insert -f main")
self.expect("\^done,bkpt={number=\"1\"")
# After '-exec-run'
self.expect("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
# After '-break-insert main.cpp:BP_return'
line = line_number('main.cpp', '//BP_return')
self.expect("-break-insert main.cpp:%d" % line)
self.expect("\^done,bkpt={number=\"2\"")
# After '-exec-continue'
self.expect("-exec-continue")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
# After '-data-evaluate-expression a'
self.expect("-data-evaluate-expression a")
self.expect("\^done,value=\"10\"")
# After '-gdb-exit'
self.expect("-gdb-exit")
self.expect("\^exit")
self.expect("\*stopped,reason=\"exited-normally\"")
os.unlink(sourceFile)
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfDarwin
def test_lldbmi_source_option_start_script_error(self):
"""Test that 'lldb-mi --interpreter' stops execution of initial commands in case of error."""
# Prepared source file
sourceFile = self.copyScript("start_script_error")
self.spawnLldbMi(args="--source %s" % sourceFile)
# After '-file-exec-and-symbols a.out'
self.expect("-file-exec-and-symbols %s" % self.myexe)
self.expect("\^done")
# After '-break-ins -f main'
self.expect("-break-ins -f main")
self.expect("\^error")
# Test that lldb-mi is ready after execution of --source start_script
self.expect(self.child_prompt, exactly=True)
os.unlink(sourceFile)
@skipIfRemote # We do not currently support remote debugging via the MI.
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfDarwin
def test_lldbmi_log_option(self):
"""Test that 'lldb-mi --log' creates a log file in the current directory."""
logDirectory = self.getBuildDir()
self.spawnLldbMi(args="%s --log" % self.myexe)
# Test that the executable is loaded when file was specified
self.expect("-file-exec-and-symbols \"%s\"" % self.myexe)
self.expect("\^done")
# Test that lldb-mi is ready when executable was loaded
self.expect(self.child_prompt, exactly=True)
# Run
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"exited-normally\"")
# Check log file is created
import glob
import os
logFile = glob.glob(logDirectory + "/lldb-mi-*.log")
if not logFile:
self.fail("log file not found")
# Delete log
for f in logFile:
os.remove(f)
@skipIfRemote # We do not currently support remote debugging via the MI.
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfDarwin
def test_lldbmi_log_directory_option(self):
"""Test that 'lldb-mi --log --log-dir' creates a log file in the directory specified by --log-dir."""
# Create log in temp directory
import tempfile
logDirectory = tempfile.gettempdir()
self.spawnLldbMi(
args="%s --log --log-dir=%s" %
(self.myexe, logDirectory))
# Test that the executable is loaded when file was specified
self.expect("-file-exec-and-symbols \"%s\"" % self.myexe)
self.expect("\^done")
# Test that lldb-mi is ready when executable was loaded
self.expect(self.child_prompt, exactly=True)
# Run
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"exited-normally\"")
# Check log file is created
import glob
import os
logFile = glob.glob(logDirectory + "/lldb-mi-*.log")
if not logFile:
self.fail("log file not found")
# Delete log
for f in logFile:
os.remove(f)
|