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
|
"""
Test that resilient APIs work regardless of the combination of library and executable
"""
import subprocess
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil
import os
import os.path
import unittest2
import sys
if sys.version_info.major == 2:
import commands as subprocess
else:
import subprocess
def execute_command(command):
# print '%% %s' % (command)
(exit_status, output) = subprocess.getstatusoutput(command)
return exit_status
class TestSwiftResilience(TestBase):
@skipUnlessDarwin
@swiftTest
# Because we rename the .swiftmodule files after building the
# N_AST symbol table entry is out of sync, whereas dsymutil
# captures the right one before the rename.
@skipIf(debug_info=no_match(["dsym"]))
def test_cross_module_extension_a_a(self):
"""Test that LLDB can debug across resilient boundaries"""
self.build()
self.doTestWithFlavor("a", "a")
@skipUnlessDarwin
@swiftTest
@skipIf(debug_info=no_match(["dsym"]))
def test_cross_module_extension_a_b(self):
"""Test that LLDB can debug across resilient boundaries"""
self.build()
self.doTestWithFlavor("a", "b")
@skipUnlessDarwin
@swiftTest
@skipIf(debug_info=no_match(["dsym"]))
def test_cross_module_extension_b_a(self):
"""Test that LLDB can debug across resilient boundaries"""
self.build()
self.doTestWithFlavor("b", "a")
@skipUnlessDarwin
@swiftTest
@skipIf(debug_info=no_match(["dsym"]))
def test_cross_module_extension_b_b(self):
"""Test that LLDB can debug across resilient boundaries"""
self.build()
self.doTestWithFlavor("b", "b")
def createSymlinks(self, exe_flavor, mod_flavor):
execute_command("cp " + self.getBuildArtifact("main." + exe_flavor) + " " + self.getBuildArtifact("main"))
execute_command("ln -sf " + self.getBuildArtifact("main." + exe_flavor + ".dSYM") + " " + self.getBuildArtifact("main.dSYM"))
execute_command("cp " + self.getBuildArtifact("libmod." + exe_flavor + ".dylib") + " " + self.getBuildArtifact("libmod.dylib"))
execute_command("ln -sf " + self.getBuildArtifact("libmod." + exe_flavor + ".dylib.dSYM") + " " + self.getBuildArtifact("libmod.dylib.dSYM"))
execute_command("ln -sf " + self.getBuildArtifact("mod." + exe_flavor + ".o") + " " + self.getBuildArtifact("mod.o"))
execute_command("ln -sf " + self.getBuildArtifact("mod." + exe_flavor + ".swiftinterface") + " " + self.getBuildArtifact("mod.swiftinterface"))
def cleanupSymlinks(self):
execute_command(
"rm " +
self.getBuildArtifact("main") + " " +
self.getBuildArtifact("main.dSYM") + " " +
self.getBuildArtifact("libmod.dylib") + " " +
self.getBuildArtifact("libmod.dylib.dSYM") + " " +
self.getBuildArtifact("mod.swiftdoc") + " " +
self.getBuildArtifact("mod.swiftmodule"))
def check_global(self, symbol_name, substrs):
self.expect("target var " + symbol_name,
DATA_TYPES_DISPLAYED_CORRECTLY,
substrs=substrs)
self.expect("expr " + symbol_name,
DATA_TYPES_DISPLAYED_CORRECTLY,
substrs=substrs)
def doTestWithFlavor(self, exe_flavor, mod_flavor):
self.createSymlinks(exe_flavor, mod_flavor)
target, process, _, breakpoint = lldbutil.run_to_source_breakpoint(
self, "break here", lldb.SBFileSpec("main.swift"),
exe_name=self.getBuildArtifact("main"),
extra_images=['mod'])
dylib_breakpoint = target.BreakpointCreateByName("fA")
# main.swift
self.check_global("g_main_b", ["world"])
self.check_global("g_main_s", ["a = 1"])
self.check_global("g_main_t", ["a = 1", "a = 1"])
self.check_global("g_main_nested_t", ["a = 1"])
self.check_global("g_main_c", ["a = 1"])
self.check_global("g_main_nested_c", ["a = 1"])
# Test defining global variables in the expression evaluator.
self.expect("expr -- var $g_main_b = g_main_b; $g_main_b",
substrs=["world"])
self.expect("expr -- var $g_main_s = S(); $g_main_s", substrs=["a = 1"])
self.expect("expr -- var $g_main_t = (S(), S()); $g_main_t",
substrs=["a = 1", "a = 1"])
self.expect("expr -- var $g_main_c = g_main_c; $g_main_c",
substrs=["a = 1"])
threads = lldbutil.continue_to_breakpoint(process, dylib_breakpoint)
self.assertTrue(len(threads) == 1)
# Test global variable inside the module defining S.
self.check_global("g_b", ["hello"])
self.check_global("g_s", ["a = 1"])
self.check_global("g_t", ["a = 1", "a = 1"])
self.check_global("g_c", ["a = 1"])
# Test defining global variables in the expression evaluator
# inside the module defining S.
self.expect("expr -- var $g_b = g_b; $g_b", substrs=["hello"])
self.expect("expr -- var $g_s = S(); $g_s", substrs=["a = 1"])
self.expect("expr -- var $g_t = (S(), S()); $g_t",
substrs=["a = 1", "a = 1"])
self.expect("expr -- var $g_c = g_c; $g_c", substrs=["a = 1"])
threads = lldbutil.continue_to_breakpoint(process, breakpoint)
# Back in main.swift
self.assertTrue(len(threads) == 1)
frame = threads[0].frames[0]
# Try 'frame variable'
var = frame.FindVariable("s")
child = var.GetChildMemberWithName("a")
lldbutil.check_variable(self, child, False, value="1")
# Try the expression parser
self.expect("expr s.a", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["1"])
self.expect(
"expr fA(s)",
DATA_TYPES_DISPLAYED_CORRECTLY,
substrs=["1"])
process.Kill()
self.cleanupSymlinks()
|