[Lldb-commits] [lldb] 5d66f9f - [gdb-remote] Sort entries in QEnvironment*

Fangrui Song via lldb-commits lldb-commits at lists.llvm.org
Sat Jul 22 16:45:37 PDT 2023


Author: Fangrui Song
Date: 2023-07-22T16:45:32-07:00
New Revision: 5d66f9fd8e97c05a5dba317d3ad2566e61ead1ff

URL: https://github.com/llvm/llvm-project/commit/5d66f9fd8e97c05a5dba317d3ad2566e61ead1ff
DIFF: https://github.com/llvm/llvm-project/commit/5d66f9fd8e97c05a5dba317d3ad2566e61ead1ff.diff

LOG: [gdb-remote] Sort entries in QEnvironment*

Similar to ae316ac66ffff430997e342772fc4629c1acece0 for
QEMU_(UN)SET_ENV.
The iteration order of StringMap is not guaranteed to be deterministic.
Sort the entries to give deterministic packets for the tests added by
D108018.

Added: 
    

Modified: 
    lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
    lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index 36e046d7466ebb..c6503129685ab4 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -35,6 +35,7 @@
 #include "lldb/Host/Config.h"
 #include "lldb/Utility/StringExtractorGDBRemote.h"
 
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/JSON.h"
 
@@ -826,8 +827,12 @@ llvm::Error GDBRemoteCommunicationClient::LaunchProcess(const Args &args) {
 }
 
 int GDBRemoteCommunicationClient::SendEnvironment(const Environment &env) {
-  for (const auto &KV : env) {
-    int r = SendEnvironmentPacket(Environment::compose(KV).c_str());
+  llvm::SmallVector<std::pair<llvm::StringRef, llvm::StringRef>, 0> vec;
+  for (const auto &kv : env)
+    vec.emplace_back(kv.first(), kv.second);
+  llvm::sort(vec, llvm::less_first());
+  for (const auto &[k, v] : vec) {
+    int r = SendEnvironmentPacket((k + "=" + v).str().c_str());
     if (r != 0)
       return r;
   }

diff  --git a/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py b/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py
index 65281044d93b47..2f4c8d799a6f02 100644
--- a/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py
+++ b/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py
@@ -371,12 +371,12 @@ def vRun(self, packet):
 
         self.assertPacketLogContains(
             [
+                "QEnvironment:EQUALS=foo=bar",
+                "QEnvironmentHexEncoded:4e45454453454e433d66726f6224",
+                "QEnvironmentHexEncoded:4e45454453454e43323d66722a6f62",
                 "QEnvironmentHexEncoded:4e45454453454e43333d66726f7d62",
                 "QEnvironmentHexEncoded:4e45454453454e43343d6623726f62",
                 "QEnvironment:PLAIN=foo",
-                "QEnvironmentHexEncoded:4e45454453454e43323d66722a6f62",
-                "QEnvironmentHexEncoded:4e45454453454e433d66726f6224",
-                "QEnvironment:EQUALS=foo=bar",
             ]
         )
 
@@ -425,12 +425,12 @@ def QEnvironment(self, packet):
 
         self.assertPacketLogContains(
             [
+                "QEnvironmentHexEncoded:455155414c533d666f6f3d626172",
+                "QEnvironmentHexEncoded:4e45454453454e433d66726f6224",
+                "QEnvironmentHexEncoded:4e45454453454e43323d66722a6f62",
                 "QEnvironmentHexEncoded:4e45454453454e43333d66726f7d62",
                 "QEnvironmentHexEncoded:4e45454453454e43343d6623726f62",
                 "QEnvironmentHexEncoded:504c41494e3d666f6f",
-                "QEnvironmentHexEncoded:4e45454453454e43323d66722a6f62",
-                "QEnvironmentHexEncoded:4e45454453454e433d66726f6224",
-                "QEnvironmentHexEncoded:455155414c533d666f6f3d626172",
             ]
         )
 


        


More information about the lldb-commits mailing list