Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 274316e

Browse files
committedOct 16, 2019
[android/process list] support showing process arguments
Summary: The qfProcessInfo and qsProcessInfo packets currently don't set the processes' arguments, however the platform process list -v command tries to print it. In this diff I'm adding the arguments as part of the packet, and now the command shows the arguments just like on mac. On Mac: 507 1 wallace 1876110778 wallace 1876110778 x86_64-apple-macosx /usr/libexec/secd 503 1 wallace 1876110778 wallace 1876110778 x86_64-apple-macosx /usr/libexec/secinitd 501 1 wallace 1876110778 wallace 1876110778 x86_64-apple-macosx /usr/libexec/languageassetd --firstLogin 497 1 wallace 1876110778 wallace 1876110778 x86_64-apple-macosx /usr/libexec/trustd --agent 496 1 wallace 1876110778 wallace 1876110778 x86_64-apple-macosx /usr/libexec/lsd 494 1 wallace 1876110778 wallace 1876110778 x86_64-apple-macosx /System/Library/Frameworks/CoreTelephony.framework/Support/CommCenter -L 491 1 wallace 1876110778 wallace 1876110778 x86_64-apple-macosx /usr/sbin/distnoted agent 489 1 wallace 1876110778 wallace 1876110778 x86_64-apple-macosx /usr/libexec/UserEventAgent (Aqua) 484 1 wallace 1876110778 wallace 1876110778 x86_64-apple-macosx /usr/sbin/cfprefsd agent 483 1 wallace 1876110778 wallace 1876110778 x86_64-apple-macosx /System/Library/Frameworks/LocalAuthentication.framework/Support/coreauthd On android: 1561 1016 root 0 0 aarch64-unknown-linux-android /system/bin/ip6tables-restore--noflush -w -v 1805 982 1000 1000 1000 android:drmService 1811 982 10189 10189 10189 com.qualcomm.embms:remote 1999 1 1000 1000 1000 aarch64-unknown-linux-android /system/bin/tlc_serverCCM 2332 982 10038 10038 10038 com.android.systemui 2378 983 1053 1053 1053 webview_zygote 2448 982 5013 5013 5013 com.sec.location.nsflp2 2465 982 10027 10027 10027 com.google.android.gms.persistent Differential Revision: https://reviews.llvm.org/D68293 git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@375029 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent e45c2cf commit 274316e

File tree

8 files changed

+234
-126
lines changed

8 files changed

+234
-126
lines changed
 

‎docs/lldb-gdb-remote.txt

+119-116
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CXX_SOURCES := main.cpp
2+
3+
EXE := TestProcess
4+
5+
include Makefile.rules
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
Test process list.
3+
"""
4+
5+
from __future__ import print_function
6+
7+
8+
import os
9+
import lldb
10+
import shutil
11+
from lldbsuite.test.decorators import *
12+
from lldbsuite.test.lldbtest import *
13+
from lldbsuite.test import lldbutil
14+
15+
16+
class ProcessListTestCase(TestBase):
17+
18+
mydir = TestBase.compute_mydir(__file__)
19+
20+
NO_DEBUG_INFO_TESTCASE = True
21+
22+
def test_process_list_with_args(self):
23+
"""Test process list show process args"""
24+
self.build()
25+
exe = self.getBuildArtifact("TestProcess")
26+
27+
# Spawn a new process
28+
popen = self.spawnSubprocess(exe, args=["arg1", "--arg2", "arg3"])
29+
self.addTearDownHook(self.cleanupSubprocesses)
30+
31+
self.expect("platform process list -v",
32+
substrs=["TestProcess arg1 --arg2 arg3", str(popen.pid)])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <stdio.h>
2+
3+
#include <chrono>
4+
#include <thread>
5+
6+
int main(int argc, char const *argv[]) {
7+
std::this_thread::sleep_for(std::chrono::seconds(30));
8+
return 0;
9+
}

‎packages/Python/lldbsuite/test/functionalities/gdb_remote_client/TestPlatformClient.py

+36-4
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,61 @@
55
from lldbsuite.test.decorators import *
66
from gdbclientutils import *
77

8+
def hexlify(string):
9+
return binascii.hexlify(string.encode()).decode()
810

911
class TestPlatformClient(GDBRemoteTestBase):
1012

1113
def test_process_list_with_all_users(self):
1214
"""Test connecting to a remote linux platform"""
1315

1416
class MyResponder(MockGDBServerResponder):
17+
def __init__(self):
18+
MockGDBServerResponder.__init__(self)
19+
self.currentQsProc = 0
20+
self.all_users = False
21+
1522
def qfProcessInfo(self, packet):
1623
if "all_users:1" in packet:
17-
return "pid:10;ppid:1;uid:1;gid:1;euid:1;egid:1;name:" + binascii.hexlify("/a/test_process".encode()).decode() + ";"
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 + ";"
1829
else:
30+
self.all_users = False
1931
return "E04"
2032

21-
self.server.responder = MyResponder()
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"
2247

23-
self.runCmd("platform select remote-linux")
48+
self.server.responder = MyResponder()
2449

2550
try:
51+
self.runCmd("platform select remote-linux")
2652
self.runCmd("platform connect connect://localhost:%d" %
2753
self.server.port)
2854
self.assertTrue(self.dbg.GetSelectedPlatform().IsConnected())
2955
self.expect("platform process list -x",
30-
substrs=["1 matching process was found", "test_process"])
56+
substrs=["2 matching processes were found", "test_process", "another_test_process"])
57+
self.expect("platform process list -xv",
58+
substrs=[
59+
"PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE ARGUMENTS",
60+
"10 1 2 3 4 5 /system/bin/sh -c /data/local/tmp/lldb-server",
61+
"11 2 3 4 5 6"])
62+
self.expect("platform process list -xv", substrs=["/system/bin/ls"], matching=False)
3163
self.expect("platform process list",
3264
error=True,
3365
substrs=["error: no processes were found on the \"remote-linux\" platform"])

‎source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -1927,6 +1927,26 @@ bool GDBRemoteCommunicationClient::DecodeProcessInfoResponse(
19271927
std::string name;
19281928
extractor.GetHexByteString(name);
19291929
process_info.GetExecutableFile().SetFile(name, FileSpec::Style::native);
1930+
} else if (name.equals("args")) {
1931+
llvm::StringRef encoded_args(value), hex_arg;
1932+
1933+
bool is_arg0 = true;
1934+
while (!encoded_args.empty()) {
1935+
std::tie(hex_arg, encoded_args) = encoded_args.split('-');
1936+
std::string arg;
1937+
StringExtractor extractor(hex_arg);
1938+
if (extractor.GetHexByteString(arg) * 2 != hex_arg.size()) {
1939+
// In case of wrong encoding, we discard all the arguments
1940+
process_info.GetArguments().Clear();
1941+
process_info.SetArg0("");
1942+
break;
1943+
}
1944+
if (is_arg0)
1945+
process_info.SetArg0(arg);
1946+
else
1947+
process_info.GetArguments().AppendArgument(arg);
1948+
is_arg0 = false;
1949+
}
19301950
} else if (name.equals("cputype")) {
19311951
value.getAsInteger(0, cpu);
19321952
} else if (name.equals("cpusubtype")) {

‎source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,15 @@ void GDBRemoteCommunicationServerCommon::CreateProcessInfoResponse(
11851185
proc_info.GetEffectiveUserID(), proc_info.GetEffectiveGroupID());
11861186
response.PutCString("name:");
11871187
response.PutStringAsRawHex8(proc_info.GetExecutableFile().GetCString());
1188+
1189+
response.PutChar(';');
1190+
response.PutCString("args:");
1191+
response.PutStringAsRawHex8(proc_info.GetArg0());
1192+
for (auto &arg : proc_info.GetArguments()) {
1193+
response.PutChar('-');
1194+
response.PutStringAsRawHex8(arg.ref());
1195+
}
1196+
11881197
response.PutChar(';');
11891198
const ArchSpec &proc_arch = proc_info.GetArchitecture();
11901199
if (proc_arch.IsValid()) {

‎source/Utility/ProcessInfo.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,11 @@ void ProcessInstanceInfo::DumpAsTableRow(Stream &s, UserIDResolver &resolver,
227227
}
228228

229229
if (verbose || show_args) {
230+
s.PutCString(m_arg0);
230231
const uint32_t argc = m_arguments.GetArgumentCount();
231-
if (argc > 0) {
232-
for (uint32_t i = 0; i < argc; i++) {
233-
if (i > 0)
234-
s.PutChar(' ');
235-
s.PutCString(m_arguments.GetArgumentAtIndex(i));
236-
}
232+
for (uint32_t i = 0; i < argc; i++) {
233+
s.PutChar(' ');
234+
s.PutCString(m_arguments.GetArgumentAtIndex(i));
237235
}
238236
} else {
239237
s.PutCString(GetName());

0 commit comments

Comments
 (0)
This repository has been archived.