asmith updated this revision to Diff 182704.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D56230/new/
https://reviews.llvm.org/D56230
Files:
include/lldb/Utility/Args.h
source/Host/windows/ProcessLauncherWindows.cpp
source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
source/Utility/Args.cpp
unittests/Utility/ArgsTest.cpp
Index: unittests/Utility/ArgsTest.cpp
===================================================================
--- unittests/Utility/ArgsTest.cpp
+++ unittests/Utility/ArgsTest.cpp
@@ -189,3 +189,15 @@
EXPECT_STREQ("foo", ref[0]);
EXPECT_STREQ("bar", ref[1]);
}
+
+#if defined(_WIN32)
+TEST(ArgsTest, GetFlattenWindowsCommandString) {
+ Args args;
+ args.AppendArgument("D:\\launcher.exe");
+ args.AppendArgument("--log=abc def");
+
+ std::string stdstr;
+ ASSERT_TRUE(args.GetFlattenWindowsCommandString(stdstr));
+ EXPECT_EQ(stdstr, "\"D:\\launcher.exe\" \"--log=abc def\"");
+}
+#endif
Index: source/Utility/Args.cpp
===================================================================
--- source/Utility/Args.cpp
+++ source/Utility/Args.cpp
@@ -13,6 +13,7 @@
#include "lldb/Utility/Stream.h"
#include "lldb/Utility/StringList.h"
#include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/Program.h"
using namespace lldb;
using namespace lldb_private;
@@ -240,6 +241,18 @@
return !m_entries.empty();
}
+bool Args::GetFlattenWindowsCommandString(std::string &command) const {
+ if (m_entries.empty())
+ return false;
+
+ std::vector<llvm::StringRef> args;
+ for (size_t i = 0; i < m_entries.size(); ++i)
+ args.push_back(m_entries[i].ref);
+
+ command = llvm::sys::flattenWindowsCommandLine(args);
+ return true;
+}
+
void Args::SetCommandString(llvm::StringRef command) {
Clear();
m_argv.clear();
Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
===================================================================
--- source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -126,14 +126,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
@@ -952,16 +952,18 @@
char debugserver_path[PATH_MAX];
FileSpec &debugserver_file_spec = launch_info.GetExecutableFile();
+ Environment host_env = Host::GetEnvironment();
+
// 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_env.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 =
@@ -1004,7 +1006,6 @@
Args &debugserver_args = launch_info.GetArguments();
debugserver_args.Clear();
- char arg_cstr[PATH_MAX];
// Start args with "debugserver /file/path -r --"
debugserver_args.AppendArgument(llvm::StringRef(debugserver_path));
@@ -1114,29 +1115,27 @@
}
}
}
-
- const char *env_debugserver_log_file = getenv("LLDB_DEBUGSERVER_LOG_FILE");
- if (env_debugserver_log_file) {
- ::snprintf(arg_cstr, sizeof(arg_cstr), "--log-file=%s",
- env_debugserver_log_file);
- debugserver_args.AppendArgument(llvm::StringRef(arg_cstr));
+ std::string env_debugserver_log_file =
+ host_env.lookup("LLDB_DEBUGSERVER_LOG_FILE");
+ if (!env_debugserver_log_file.empty()) {
+ debugserver_args.AppendArgument(
+ llvm::formatv("--log-file={0}", env_debugserver_log_file).str());
}
#if defined(__APPLE__)
const char *env_debugserver_log_flags =
getenv("LLDB_DEBUGSERVER_LOG_FLAGS");
if (env_debugserver_log_flags) {
- ::snprintf(arg_cstr, sizeof(arg_cstr), "--log-flags=%s",
- env_debugserver_log_flags);
- debugserver_args.AppendArgument(llvm::StringRef(arg_cstr));
+ debugserver_args.AppendArgument(
+ llvm::formatv("--log-flags={0}", env_debugserver_log_flags).str());
}
#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);
- debugserver_args.AppendArgument(llvm::StringRef(arg_cstr));
+ std::string env_debugserver_log_channels =
+ host_env.lookup("LLDB_SERVER_LOG_CHANNELS");
+ if (!env_debugserver_log_channels.empty()) {
+ debugserver_args.AppendArgument(
+ llvm::formatv("--log-channels={0}", env_debugserver_log_channels)
+ .str());
}
#endif
@@ -1148,15 +1147,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_env.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);
@@ -1166,7 +1165,7 @@
}
// Copy the current environment to the gdbserver/debugserver instance
- launch_info.GetEnvironment() = Host::GetEnvironment();
+ launch_info.GetEnvironment() = host_env;
// Close STDIN, STDOUT and STDERR.
launch_info.AppendCloseFileAction(STDIN_FILENO);
@@ -1302,14 +1301,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() {
Index: source/Host/windows/ProcessLauncherWindows.cpp
===================================================================
--- source/Host/windows/ProcessLauncherWindows.cpp
+++ source/Host/windows/ProcessLauncherWindows.cpp
@@ -85,7 +85,7 @@
env_block = environment.data();
executable = launch_info.GetExecutableFile().GetPath();
- launch_info.GetArguments().GetQuotedCommandString(commandLine);
+ launch_info.GetArguments().GetFlattenWindowsCommandString(commandLine);
std::wstring wexecutable, wcommandLine, wworkingDirectory;
llvm::ConvertUTF8toWide(executable, wexecutable);
Index: include/lldb/Utility/Args.h
===================================================================
--- include/lldb/Utility/Args.h
+++ include/lldb/Utility/Args.h
@@ -118,6 +118,8 @@
bool GetQuotedCommandString(std::string &command) const;
+ bool GetFlattenWindowsCommandString(std::string &command) const;
+
//------------------------------------------------------------------
/// Gets the number of arguments left in this command object.
///
_______________________________________________
lldb-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits