wallace updated this revision to Diff 223061.
wallace added a comment.

- Encoding differently the arguments. Now it shouldn't have any corner cases
- I'm also sending from the server all the args, including arg0
- In the client, when displaying the process name, I'm using arg0 as fallback 
if the exe path is empty
- Fixed formatting

I still need to finish testing


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68293/new/

https://reviews.llvm.org/D68293

Files:
  lldb/source/Host/linux/Host.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
  lldb/source/Utility/ProcessInfo.cpp

Index: lldb/source/Utility/ProcessInfo.cpp
===================================================================
--- lldb/source/Utility/ProcessInfo.cpp
+++ 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();
 }
 
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
@@ -1176,6 +1176,18 @@
   response.PutCString("name:");
   response.PutStringAsRawHex8(proc_info.GetExecutableFile().GetCString());
   response.PutChar(';');
+  response.PutCString("args:");
+  response.PutStringAsRawHex8(proc_info.GetArg0());
+  // for (auto it = proc_info.GetArguments().begin(); it !=
+  // proc_info.GetArguments().end(); ++it) {
+  //  response.PutChar('-');
+  // response.PutStringAsRawHex8(it->c_str());
+  //
+  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()) {
     const llvm::Triple &proc_triple = proc_arch.GetTriple();
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -1199,10 +1199,9 @@
             if (!value.getAsInteger(0, pointer_byte_size))
               ++num_keys_decoded;
           } else if (name.equals("os_version") ||
-                     name.equals(
-                         "version")) // Older debugserver binaries used the
-                                     // "version" key instead of
-                                     // "os_version"...
+                     name.equals("version")) // Older debugserver binaries used
+                                             // the "version" key instead of
+                                             // "os_version"...
           {
             if (!m_os_version.tryParse(value))
               ++num_keys_decoded;
@@ -1927,6 +1926,28 @@
         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")) {
@@ -2067,7 +2088,7 @@
                  !vendor_name.empty()) {
         llvm::Triple triple(llvm::Twine("-") + vendor_name + "-" + os_name);
         if (!environment.empty())
-            triple.setEnvironmentName(environment);
+          triple.setEnvironmentName(environment);
 
         assert(triple.getObjectFormat() != llvm::Triple::UnknownObjectFormat);
         assert(triple.getObjectFormat() != llvm::Triple::Wasm);
@@ -2580,7 +2601,7 @@
      * The reply from '?' packet could be as simple as 'S05'. There is no packet
      * which can
      * give us pid and/or tid. Assume pid=tid=1 in such cases.
-    */
+     */
     if (response.IsUnsupportedResponse() && IsConnected()) {
       m_curr_tid = 1;
       return true;
@@ -2753,7 +2774,7 @@
      * be as simple as 'S05'. There is no packet which can give us pid and/or
      * tid.
      * Assume pid=tid=1 in such cases.
-    */
+     */
     if ((response.IsUnsupportedResponse() || response.IsNormalResponse()) &&
         thread_ids.size() == 0 && IsConnected()) {
       thread_ids.push_back(1);
Index: lldb/source/Host/linux/Host.cpp
===================================================================
--- lldb/source/Host/linux/Host.cpp
+++ 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);
   }
 }
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to