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
|
"""
Test that the debugger can call a *really* new function.
"""
import os
import lldb
import lldbsuite.test.lldbplatformutil as lldbplatformutil
import lldbsuite.test.lldbutil as lldbutil
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
def getOSName(os):
if os == 'macosx': return 'macOS'
if os == 'ios': return 'iOS'
if os == 'tvos': return 'tvOS'
if os == 'watchos': return 'watchOS'
return os
def getArch(os):
if os == 'macosx': return 'x86_64'
if os == 'ios': return 'arm64'
if os == 'tvos': return 'arm64'
if os == 'watchos': return 'armv7k'
return os
def getTriple(os, version):
return getArch(os) + '-apple-' + os + version
def getOlderVersion(major, minor):
if minor != 0:
return '%d.%d' % (major, minor-1)
return '%d.%d' % (major-1, minor)
class TestAvailability(TestBase):
NO_DEBUG_INFO_TESTCASE = True
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
@swiftTest
@skipIf(oslist=['linux', 'windows'])
def testAvailability(self):
platform_name = lldbplatformutil.getPlatform()
os_name = getOSName(platform_name)
platform = lldb.selected_platform
major = platform.GetOSMajorVersion()
minor = platform.GetOSMinorVersion()
version = '%d.%d'%(major, minor)
program = """
@available(%s %s, *) func f() {}
// ---------------------------------------------------------------------
// Method context.
// ---------------------------------------------------------------------
class C1 {
func method() {
print("in method") // break_1
}
}
C1().method() // break_0
// ---------------------------------------------------------------------
// Generic method context.
// ---------------------------------------------------------------------
class C2 {
func method<T>(_ t: T) {
print("in method") // break_2
}
}
C2().method(0)
// ---------------------------------------------------------------------
// Method in generic class context.
// ---------------------------------------------------------------------
class C3<T> {
func method() {
print("in method") // break_3
}
}
C3<Int>().method()
// ---------------------------------------------------------------------
// Generic method in generic class context.
// ---------------------------------------------------------------------
class C4<U> {
func method<V>(_ v: V) {
print("in method") // break_4
}
}
C4<Int>().method(0)
// ---------------------------------------------------------------------
// Function context.
// ---------------------------------------------------------------------
func f1() {
print("in function") // break_5
}
f1()
// ---------------------------------------------------------------------
// Generic function context.
// ---------------------------------------------------------------------
func f2<T>(_ t: T) {
print("in function") // break_6
}
f2(0)
// ---------------------------------------------------------------------
// Top-level context.
// ---------------------------------------------------------------------
print("in top_level") // break_7
"""
with open(self.getBuildArtifact("main.swift"), 'w') as main:
main.write(program %(os_name, version))
self.build(dictionary={'TRIPLE': getTriple(platform_name,
getOlderVersion(major, minor))})
source_spec = lldb.SBFileSpec("main.swift")
(target, process, thread, brk0) = \
lldbutil.run_to_source_breakpoint(self, "break_0", source_spec)
# Create breakpoints.
breakpoints = []
for i in range(1, 8):
breakpoints.append(target.BreakpointCreateBySourceRegex(
'break_%d'%i, lldb.SBFileSpec("main.swift")))
self.assertTrue(breakpoints[-1] and
breakpoints[-1].GetNumLocations() >= 1,
VALID_BREAKPOINT)
for breakpoint in breakpoints:
threads = lldbutil.continue_to_breakpoint(process, breakpoint)
self.runCmd("expr -d no-run-target -- f()", msg="can call")
|