From e031bdfefad08739a986a6ec9c46712533979d98 Mon Sep 17 00:00:00 2001 From: Walter Erquinigo Date: Sat, 12 Oct 2019 01:33:21 +0000 Subject: [PATCH] [platform process list] add a flag for showing the processes of all users Summary: For context: https://reviews.llvm.org/D68293 We need a way to show all the processes on android regardless of the user id. When you run `platform process list`, you only see the processes with the same user as the user that launched lldb-server. However, it's quite useful to see all the processes, though, and it will lay a foundation for full apk debugging support from lldb. Before: ``` PID PARENT USER TRIPLE NAME ====== ====== ========== ======================== ============================ 3234 1 aarch64-unknown-linux-android adbd 8034 3234 aarch64-unknown-linux-android sh 9096 3234 aarch64-unknown-linux-android sh 9098 9096 aarch64-unknown-linux-android lldb-server (lldb) ^D ``` Now: ``` (lldb) platform process list -x 205 matching processes were found on "remote-android" PID PARENT USER TRIPLE NAME ====== ====== ========== ======================== ============================ 1 0 init 524 1 init 525 1 init 531 1 ueventd 568 1 logd 569 1 aarch64-unknown-linux-android servicemanager 570 1 aarch64-unknown-linux-android hwservicemanager 571 1 aarch64-unknown-linux-android vndservicemanager 577 1 aarch64-unknown-linux-android qseecomd 580 577 aarch64-unknown-linux-android qseecomd ... 23816 979 com.android.providers.calendar 24600 979 com.verizon.mips.services 27888 979 com.hualai 28043 2378 com.android.chrome:sandboxed_process0 31449 979 com.att.shm 31779 979 com.samsung.android.authfw 31846 979 com.samsung.android.server.iris 32014 979 com.samsung.android.MtpApplication 32045 979 com.samsung.InputEventApp ``` Reviewers: labath,xiaobai,aadsm,clayborg Subscribers: > llvm-svn: 374584 llvm-svn: 374622 --- .../gdb_remote_client/TestPlatformClient.py | 27 +++++++++++++++++ .../gdb_remote_client/gdbclientutils.py | 35 ++++++++++++++++++++-- lldb/source/Commands/CommandObjectPlatform.cpp | 4 +++ lldb/source/Commands/Options.td | 3 ++ .../gdb-remote/GDBRemoteCommunicationClient.cpp | 3 +- 5 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/TestPlatformClient.py diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/TestPlatformClient.py b/lldb/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/TestPlatformClient.py new file mode 100644 index 0000000..338d27d --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/TestPlatformClient.py @@ -0,0 +1,27 @@ +import lldb +import binascii +import os +from lldbsuite.test.lldbtest import * +from lldbsuite.test.decorators import * +from gdbclientutils import * + + +class TestPlatformClient(GDBRemoteTestBase): + + def test_process_list_with_all_users(self): + """Test connecting to a remote linux platform""" + + self.runCmd("log enable gdb-remote all") + self.runCmd("platform select remote-linux") + + try: + self.runCmd("platform connect connect://localhost:%d" % + self.server.port) + self.assertTrue(self.dbg.GetSelectedPlatform().IsConnected()) + self.expect("platform process list -x", + substrs=["1 matching process was found", "test_process"]) + self.expect("platform process list", + error=True, + substrs=["error: no processes were found on the \"remote-linux\" platform"]) + finally: + self.dbg.GetSelectedPlatform().DisconnectRemote() diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/gdbclientutils.py b/lldb/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/gdbclientutils.py index 621279a..94129c0 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/gdbclientutils.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/gdbclientutils.py @@ -3,6 +3,8 @@ import os.path import threading import socket import lldb +import binascii +import traceback from lldbsuite.support import seven from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbtest_config @@ -160,9 +162,37 @@ class MockGDBServerResponder: return self.QListThreadsInStopReply() if packet.startswith("qMemoryRegionInfo:"): return self.qMemoryRegionInfo() + if packet == "qQueryGDBServer": + return self.qQueryGDBServer() + if packet == "qHostInfo": + return self.qHostInfo() + if packet == "qGetWorkingDir": + return self.qGetWorkingDir() + if packet == "qsProcessInfo": + return self.qsProcessInfo() + if packet.startswith("qfProcessInfo"): + return self.qfProcessInfo(packet) return self.other(packet) + def qsProcessInfo(self): + return "E04" + + def qfProcessInfo(self, packet): + if "all_users:1" in packet: + return "pid:10;ppid:1;uid:1;gid:1;euid:1;egid:1;name:" + binascii.hexlify("/a/test_process") + ";" + else: + return "E04" + + def qGetWorkingDir(self): + return "2f" + + def qHostInfo(self): + return "ptrsize:8;endian:little;" + + def qQueryGDBServer(self): + return "E04" + def interrupt(self): raise self.UnexpectedPacketException() @@ -171,7 +201,7 @@ class MockGDBServerResponder: def vCont(self, packet): raise self.UnexpectedPacketException() - + def readRegisters(self): return "00000000" * self.registerCount @@ -315,6 +345,8 @@ class MockGDBServer: break self._receive(data) except Exception as e: + print("An exception happened when receiving the response from the gdb server. Closing the client...") + traceback.print_exc() self._client.close() break @@ -425,7 +457,6 @@ class MockGDBServer: class InvalidPacketException(Exception): pass - class GDBRemoteTestBase(TestBase): """ Base class for GDB client tests. diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp index 7fb3783..fbd13aa 100644 --- a/lldb/source/Commands/CommandObjectPlatform.cpp +++ b/lldb/source/Commands/CommandObjectPlatform.cpp @@ -1264,6 +1264,10 @@ protected: verbose = true; break; + case 'x': + match_info.SetMatchAllUsers(true); + break; + default: llvm_unreachable("Unimplemented option"); } diff --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td index 477b553..87f5506 100644 --- a/lldb/source/Commands/Options.td +++ b/lldb/source/Commands/Options.td @@ -591,6 +591,9 @@ let Command = "platform process list" in { def platform_process_list_show_args : Option<"show-args", "A">, GroupRange<1, 6>, Desc<"Show process arguments instead of the process executable basename.">; + def platform_process_list_all_users: Option<"all-users", "x">, + GroupRange<1,6>, + Desc<"Show processes matching all user IDs.">; def platform_process_list_verbose : Option<"verbose", "v">, GroupRange<1, 6>, Desc<"Enable verbose output.">; } diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp index 51e3133..f6ef457 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -2176,8 +2176,7 @@ uint32_t GDBRemoteCommunicationClient::FindProcesses( if (match_info.GetProcessInfo().EffectiveGroupIDIsValid()) packet.Printf("egid:%u;", match_info.GetProcessInfo().GetEffectiveGroupID()); - if (match_info.GetProcessInfo().EffectiveGroupIDIsValid()) - packet.Printf("all_users:%u;", match_info.GetMatchAllUsers() ? 1 : 0); + packet.Printf("all_users:%u;", match_info.GetMatchAllUsers() ? 1 : 0); if (match_info.GetProcessInfo().GetArchitecture().IsValid()) { const ArchSpec &match_arch = match_info.GetProcessInfo().GetArchitecture(); -- 2.7.4