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