1import lldb 2import binascii 3import os 4from lldbsuite.test.lldbtest import * 5from lldbsuite.test.decorators import * 6from gdbclientutils import * 7 8def hexlify(string): 9 return binascii.hexlify(string.encode()).decode() 10 11class TestPlatformClient(GDBRemoteTestBase): 12 13 def test_process_list_with_all_users(self): 14 """Test connecting to a remote linux platform""" 15 16 class MyResponder(MockGDBServerResponder): 17 def __init__(self): 18 MockGDBServerResponder.__init__(self) 19 self.currentQsProc = 0 20 self.all_users = False 21 22 def qfProcessInfo(self, packet): 23 if "all_users:1" in packet: 24 self.all_users = True 25 name = hexlify("/a/test_process") 26 args = "-".join(map(hexlify, 27 ["/system/bin/sh", "-c", "/data/local/tmp/lldb-server"])) 28 return "pid:10;ppid:1;uid:2;gid:3;euid:4;egid:5;name:" + name + ";args:" + args + ";" 29 else: 30 self.all_users = False 31 return "E04" 32 33 def qsProcessInfo(self): 34 if self.all_users: 35 if self.currentQsProc == 0: 36 self.currentQsProc = 1 37 name = hexlify("/b/another_test_process") 38 # This intentionally has a badly encoded argument 39 args = "X".join(map(hexlify, 40 ["/system/bin/ls", "--help"])) 41 return "pid:11;ppid:2;uid:3;gid:4;euid:5;egid:6;name:" + name + ";args:" + args + ";" 42 elif self.currentQsProc == 1: 43 self.currentQsProc = 0 44 return "E04" 45 else: 46 return "E04" 47 48 self.server.responder = MyResponder() 49 50 try: 51 self.runCmd("platform select remote-linux") 52 self.runCmd("platform connect connect://" + self.server.get_connect_address()) 53 self.assertTrue(self.dbg.GetSelectedPlatform().IsConnected()) 54 self.expect("platform process list -x", 55 substrs=["2 matching processes were found", "test_process", "another_test_process"]) 56 self.expect("platform process list -xv", 57 substrs=[ 58 "PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE ARGUMENTS", 59 "10 1 2 3 4 5 /system/bin/sh -c /data/local/tmp/lldb-server", 60 "11 2 3 4 5 6"]) 61 self.expect("platform process list -xv", substrs=["/system/bin/ls"], matching=False) 62 self.expect("platform process list", 63 error=True, 64 substrs=["error: no processes were found on the \"remote-linux\" platform"]) 65 finally: 66 self.dbg.GetSelectedPlatform().DisconnectRemote() 67