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_with_python(self): 16 self.do_test(False) 17 @skipIfXmlSupportMissing 18 def test_with_target_ceate(self): 19 self.do_test(True) 20 21 def do_test(self, use_target_create): 22 self.absent_file = '/nosuch_dir/nosuch_subdir/nosuch_executable' 23 self.a_packet_file = None 24 class MyResponder(MockGDBServerResponder): 25 def __init__(self, testcase): 26 MockGDBServerResponder.__init__(self) 27 self.after_launch = False 28 self.testcase = testcase 29 self.current_thread = 0 30 31 def A(self, packet): 32 # This is the main test, we want to see that lldb DID send the 33 # A packet to get debugserver to load the file. 34 # Skip the length and second length: 35 print("Got A packet: {0}".format(packet)) 36 a_arr = packet.split(",") 37 self.testcase.a_packet_file = bytearray.fromhex(a_arr[2]).decode() 38 return "OK" 39 40 def qXferRead(self, obj, annex, offset, length): 41 if annex == "target.xml": 42 return """<?xml version="1.0"?> 43 <target version="1.0"> 44 <architecture>i386:x86-64</architecture> 45 <feature name="org.gnu.gdb.i386.core"> 46 <reg name="rip" bitsize="64" regnum="0" type="code_ptr" group="general"/> 47 </feature> 48 </target>""", False 49 else: 50 return None, False 51 52 def qC(self): 53 if not self.after_launch: 54 return "QC0" 55 return "0" 56 57 def qfThreadInfo(self): 58 if not self.after_launch: 59 return "OK" 60 return "m0" 61 62 def qsThreadInfo(self): 63 if not self.after_launch: 64 return "OK" 65 return "l" 66 67 def qLaunchSuccess(self): 68 return "OK" 69 70 def qProcessInfo(self): 71 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;" 72 73 74 error = lldb.SBError() 75 self.server.responder = MyResponder(self) 76 target = lldb.SBTarget() 77 if (use_target_create): 78 create_cmd = "target create --arch x86_64-apple-macosx --platform remote-macosx --remote-file {0}".format(self.absent_file) 79 self.runCmd(create_cmd) 80 target = self.dbg.GetSelectedTarget() 81 self.assertTrue(target.IsValid(), "Made a valid target") 82 else: 83 target = self.dbg.CreateTarget(None, "x86_64-apple-macosx", "remote-macosx", False, error) 84 self.assertSuccess(error, "Made a valid target") 85 86 launch_info = target.GetLaunchInfo() 87 if (not use_target_create): 88 launch_info.SetExecutableFile(lldb.SBFileSpec(self.absent_file), True) 89 flags = launch_info.GetLaunchFlags() 90 flags |= lldb.eLaunchFlagStopAtEntry 91 launch_info.SetLaunchFlags(flags) 92 93 process = self.connect(target) 94 self.assertTrue(process.IsValid(), "Process is valid") 95 96 # We need to fetch the connected event: 97 lldbutil.expect_state_changes(self, self.dbg.GetListener(), process, [lldb.eStateConnected]) 98 99 self.server.responder.after_launch = True 100 101 process = target.Launch(launch_info, error) 102 103 self.assertSuccess(error, "Successfully launched.") 104 self.assertState(process.GetState(), lldb.eStateStopped, "Should be stopped at entry") 105 self.assertIsNotNone(self.a_packet_file, "A packet was sent") 106 self.assertEqual(self.absent_file, self.a_packet_file, "The A packet file was correct") 107