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 --- a/lldb/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/TestPlatformClient.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/TestPlatformClient.py @@ -14,7 +14,10 @@ class MyResponder(MockGDBServerResponder): def qfProcessInfo(self, packet): if "all_users:1" in packet: - return "pid:10;ppid:1;uid:2;gid:3;euid:4;egid:5;name:" + binascii.hexlify("/a/process") + ";args:" + name = binascii.hexlify("/a/process") + args = "-".join(map(binascii.hexlify, + ["/system/bin/sh", "-c", "/data/local/tmp/lldb-server"])) + return "pid:10;ppid:1;uid:2;gid:3;euid:4;egid:5;name:" + name + ";args:" + args + ";" else: return "E04" @@ -23,6 +26,7 @@ self.runCmd("platform select remote-linux") try: + self.runCmd("log enable gdb-remote all") self.runCmd("platform connect connect://localhost:%d" % self.server.port) self.assertTrue(self.dbg.GetSelectedPlatform().IsConnected()) @@ -31,7 +35,8 @@ self.expect("platform process list -xv", substrs=[ "PID PARENT USER GROUP EFF USER EFF GROUP", - "10 1 2 3 4 5"]) + "10 1 2 3 4 5", + "/system/bin/sh -c /data/local/tmp/lldb-server"]) self.expect("platform process list", error="error: no processes were found on the \"remote-linux\" platform") finally: diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp --- a/lldb/source/Host/linux/Host.cpp +++ b/lldb/source/Host/linux/Host.cpp @@ -156,6 +156,8 @@ while (!Rest.empty()) { llvm::StringRef Arg; std::tie(Arg, Rest) = Rest.split('\0'); + if (Arg.empty()) + continue; process_info.GetArguments().AppendArgument(Arg); } } @@ -192,7 +194,7 @@ auto BufferOrError = getProcFile(pid, "environ"); if (!BufferOrError) return; - + std::unique_ptr Environ = std::move(*BufferOrError); llvm::StringRef Rest = Environ->getBuffer(); while (!Rest.empty()) { diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -1927,6 +1927,27 @@ std::string name; extractor.GetHexByteString(name); process_info.GetExecutableFile().SetFile(name, FileSpec::Style::native); + } else if (name.equals("args")) { + StringExtractor extractor(value); + std::stringstream stream(value); + + auto extractOneArg = [&](std::string &arg) { + std::string hex_arg; + if (!getline(stream, hex_arg, '-')) + return false; + extractor = StringExtractor(hex_arg); + extractor.GetHexByteString(arg); + return true; + }; + + std::string arg; + if (!extractOneArg(arg)) + continue; + process_info.SetArg0(arg); + process_info.GetArguments().AppendArgument(arg); + + while (extractOneArg(arg)) + process_info.GetArguments().AppendArgument(arg); } else if (name.equals("cputype")) { value.getAsInteger(0, cpu); } else if (name.equals("cpusubtype")) { diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp @@ -1184,6 +1184,15 @@ proc_info.GetEffectiveUserID(), proc_info.GetEffectiveGroupID()); response.PutCString("name:"); response.PutStringAsRawHex8(proc_info.GetExecutableFile().GetCString()); + + response.PutChar(';'); + response.PutCString("args:"); + response.PutStringAsRawHex8(proc_info.GetArg0()); + for (auto &arg : proc_info.GetArguments()) { + response.PutChar('-'); + response.PutStringAsRawHex8(arg.c_str()); + } + response.PutChar(';'); const ArchSpec &proc_arch = proc_info.GetArchitecture(); if (proc_arch.IsValid()) { diff --git a/lldb/source/Utility/ProcessInfo.cpp b/lldb/source/Utility/ProcessInfo.cpp --- a/lldb/source/Utility/ProcessInfo.cpp +++ b/lldb/source/Utility/ProcessInfo.cpp @@ -39,6 +39,8 @@ } const char *ProcessInfo::GetName() const { + if (m_executable.GetFilename().IsEmpty()) + return GetArguments().GetArgumentAtIndex(0); return m_executable.GetFilename().GetCString(); }