asmith created this revision.
asmith added reviewers: zturner, llvm-commits.
Herald added a subscriber: lldb-commits.

Repository:
  rLLDB LLDB

https://reviews.llvm.org/D56230

Files:
  source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp

Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
===================================================================
--- source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -125,14 +125,14 @@
 
 GDBRemoteCommunication::PacketResult
 GDBRemoteCommunication::SendPacketNoLock(llvm::StringRef payload) {
-    StreamString packet(0, 4, eByteOrderBig);
-    packet.PutChar('$');
-    packet.Write(payload.data(), payload.size());
-    packet.PutChar('#');
-    packet.PutHex8(CalculcateChecksum(payload));
-    std::string packet_str = packet.GetString();
-
-    return SendRawPacketNoLock(packet_str);
+  StreamString packet(0, 4, eByteOrderBig);
+  packet.PutChar('$');
+  packet.Write(payload.data(), payload.size());
+  packet.PutChar('#');
+  packet.PutHex8(CalculcateChecksum(payload));
+  std::string packet_str = packet.GetString();
+
+  return SendRawPacketNoLock(packet_str);
 }
 
 GDBRemoteCommunication::PacketResult
@@ -953,14 +953,15 @@
 
   // Always check to see if we have an environment override for the path to the
   // debugserver to use and use it if we do.
-  const char *env_debugserver_path = getenv("LLDB_DEBUGSERVER_PATH");
-  if (env_debugserver_path) {
+  std::string env_debugserver_path =
+      Host::GetEnvironment().lookup("LLDB_DEBUGSERVER_PATH");
+  if (!env_debugserver_path.empty()) {
     debugserver_file_spec.SetFile(env_debugserver_path,
                                   FileSpec::Style::native);
     if (log)
       log->Printf("GDBRemoteCommunication::%s() gdb-remote stub exe path set "
                   "from environment variable: %s",
-                  __FUNCTION__, env_debugserver_path);
+                  __FUNCTION__, env_debugserver_path.c_str());
   } else
     debugserver_file_spec = g_debugserver_file_spec;
   bool debugserver_exists =
@@ -1113,11 +1114,11 @@
         }
       }
     }
-
-    const char *env_debugserver_log_file = getenv("LLDB_DEBUGSERVER_LOG_FILE");
-    if (env_debugserver_log_file) {
+    std::string env_debugserver_log_file =
+        Host::GetEnvironment().lookup("LLDB_DEBUGSERVER_LOG_FILE");
+    if (!env_debugserver_log_file.empty()) {
       ::snprintf(arg_cstr, sizeof(arg_cstr), "--log-file=%s",
-                 env_debugserver_log_file);
+                 env_debugserver_log_file.c_str());
       debugserver_args.AppendArgument(llvm::StringRef(arg_cstr));
     }
 
@@ -1130,11 +1131,12 @@
       debugserver_args.AppendArgument(llvm::StringRef(arg_cstr));
     }
 #else
-    const char *env_debugserver_log_channels =
-        getenv("LLDB_SERVER_LOG_CHANNELS");
-    if (env_debugserver_log_channels) {
-      ::snprintf(arg_cstr, sizeof(arg_cstr), "--log-channels=%s",
-                 env_debugserver_log_channels);
+    std::string env_debugserver_log_channels =
+        Host::GetEnvironment().lookup("LLDB_SERVER_LOG_CHANNELS");
+    if (!env_debugserver_log_channels.empty()) {
+      // Double quote the string.
+      ::snprintf(arg_cstr, sizeof(arg_cstr), "--log-channels=\"%s\"",
+                 env_debugserver_log_channels.c_str());
       debugserver_args.AppendArgument(llvm::StringRef(arg_cstr));
     }
 #endif
@@ -1147,15 +1149,15 @@
       char env_var_name[64];
       snprintf(env_var_name, sizeof(env_var_name),
                "LLDB_DEBUGSERVER_EXTRA_ARG_%" PRIu32, env_var_index++);
-      const char *extra_arg = getenv(env_var_name);
-      has_env_var = extra_arg != nullptr;
+      std::string extra_arg = Host::GetEnvironment().lookup(env_var_name);
+      has_env_var = !extra_arg.empty();
 
       if (has_env_var) {
         debugserver_args.AppendArgument(llvm::StringRef(extra_arg));
         if (log)
           log->Printf("GDBRemoteCommunication::%s adding env var %s contents "
                       "to stub command line (%s)",
-                      __FUNCTION__, env_var_name, extra_arg);
+                      __FUNCTION__, env_var_name, extra_arg.c_str());
       }
     } while (has_env_var);
 
@@ -1301,14 +1303,14 @@
 
 GDBRemoteCommunication::ScopedTimeout::ScopedTimeout(
     GDBRemoteCommunication &gdb_comm, std::chrono::seconds timeout)
-  : m_gdb_comm(gdb_comm), m_timeout_modified(false) {
-    auto curr_timeout = gdb_comm.GetPacketTimeout();
-    // Only update the timeout if the timeout is greater than the current
-    // timeout. If the current timeout is larger, then just use that.
-    if (curr_timeout < timeout) {
-      m_timeout_modified = true;
-      m_saved_timeout = m_gdb_comm.SetPacketTimeout(timeout);
-    }
+    : m_gdb_comm(gdb_comm), m_timeout_modified(false) {
+  auto curr_timeout = gdb_comm.GetPacketTimeout();
+  // Only update the timeout if the timeout is greater than the current
+  // timeout. If the current timeout is larger, then just use that.
+  if (curr_timeout < timeout) {
+    m_timeout_modified = true;
+    m_saved_timeout = m_gdb_comm.SetPacketTimeout(timeout);
+  }
 }
 
 GDBRemoteCommunication::ScopedTimeout::~ScopedTimeout() {
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to