1import lldb 2from lldbsuite.test.lldbtest import * 3from lldbsuite.test.decorators import * 4from lldbsuite.test.gdbclientutils import * 5from lldbsuite.test.lldbgdbclient import GDBRemoteTestBase 6 7class TestNoLocalFile(GDBRemoteTestBase): 8 """ Test the case where there is NO local copy of the file 9 being debugged. We shouldn't immediately error out, but 10 rather lldb should ask debugserver if it knows about the file. """ 11 12 mydir = TestBase.compute_mydir(__file__) 13 14 @skipIfXmlSupportMissing 15 def test(self): 16 self.absent_file = '/nosuch_dir/nosuch_subdir/nosuch_executable' 17 self.a_packet_file = None 18 class MyResponder(MockGDBServerResponder): 19 def __init__(self, testcase): 20 MockGDBServerResponder.__init__(self) 21 self.after_launch = False 22 self.testcase = testcase 23 self.current_thread = 0 24 25 def A(self, packet): 26 # This is the main test, we want to see that lldb DID send the 27 # A packet to get debugserver to load the file. 28 # Skip the length and second length: 29 print("Got A packet: {0}".format(packet)) 30 a_arr = packet.split(",") 31 self.testcase.a_packet_file = bytearray.fromhex(a_arr[2]).decode() 32 return "OK" 33 34 def qXferRead(self, obj, annex, offset, length): 35 if annex == "target.xml": 36 return """<?xml version="1.0"?> 37 <target version="1.0"> 38 <architecture>i386:x86-64</architecture> 39 <feature name="org.gnu.gdb.i386.core"> 40 <reg name="rip" bitsize="64" regnum="0" type="code_ptr" group="general"/> 41 </feature> 42 </target>""", False 43 else: 44 return None, False 45 46 def qC(self): 47 if not self.after_launch: 48 return "QC0" 49 return "0" 50 51 def qfThreadInfo(self): 52 if not self.after_launch: 53 return "OK" 54 return "m0" 55 56 def qsThreadInfo(self): 57 if not self.after_launch: 58 return "OK" 59 return "l" 60 61 def qLaunchSuccess(self): 62 return "OK" 63 64 def qProcessInfo(self): 65 return "$pid:10b70;parent-pid:10b20;real-uid:1f6;real-gid:14;effective-uid:1f6;effective-gid:14;cputype:1000007;cpusubtype:8;ptrsize:8;ostype:macosx;vendor:apple;endian:little;" 66 67 68 error = lldb.SBError() 69 self.server.responder = MyResponder(self) 70 target = self.dbg.CreateTarget(None, "x86_64-apple-macosx", "remote-macosx", False, error) 71 self.assertSuccess(error, "Made a valid target") 72 launch_info = target.GetLaunchInfo() 73 launch_info.SetExecutableFile(lldb.SBFileSpec(self.absent_file), True) 74 flags = launch_info.GetLaunchFlags() 75 flags |= lldb.eLaunchFlagStopAtEntry 76 launch_info.SetLaunchFlags(flags) 77 78 process = self.connect(target) 79 self.assertTrue(process.IsValid(), "Process is valid") 80 81 # We need to fetch the connected event: 82 lldbutil.expect_state_changes(self, self.dbg.GetListener(), process, [lldb.eStateConnected]) 83 84 self.server.responder.after_launch = True 85 86 process = target.Launch(launch_info, error) 87 88 self.assertSuccess(error, "Successfully launched.") 89 self.assertEqual(process.GetState(), lldb.eStateStopped, "Should be stopped at entry") 90 self.assertIsNotNone(self.a_packet_file, "A packet was sent") 91 self.assertEqual(self.absent_file, self.a_packet_file, "The A packet file was correct") 92