[Lldb-commits] [PATCH] Correctly quote arguments in LLDB driver
Pavel Labath
labath at google.com
Thu Mar 5 11:20:11 PST 2015
REPOSITORY
rL LLVM
http://reviews.llvm.org/D8083
Files:
lldb/trunk/tools/driver/Driver.cpp
Index: lldb/trunk/tools/driver/Driver.cpp
===================================================================
--- lldb/trunk/tools/driver/Driver.cpp
+++ lldb/trunk/tools/driver/Driver.cpp
@@ -956,6 +956,18 @@
}
+std::string
+EscapeString (std::string arg)
+{
+ std::string::size_type pos = 0;
+ while ((pos = arg.find_first_of("\"\\", pos)) != std::string::npos)
+ {
+ arg.insert (pos, 1, '\\');
+ pos += 2;
+ }
+ return '"' + arg + '"';
+}
+
void
Driver::MainLoop ()
{
@@ -1005,37 +1017,31 @@
{
char arch_name[64];
if (m_debugger.GetDefaultArchitecture (arch_name, sizeof (arch_name)))
- commands_stream.Printf("target create --arch=%s \"%s\"", arch_name, m_option_data.m_args[0].c_str());
+ commands_stream.Printf("target create --arch=%s %s", arch_name, EscapeString(m_option_data.m_args[0]).c_str());
else
- commands_stream.Printf("target create \"%s\"", m_option_data.m_args[0].c_str());
+ commands_stream.Printf("target create %s", EscapeString(m_option_data.m_args[0]).c_str());
if (!m_option_data.m_core_file.empty())
{
- commands_stream.Printf(" --core \"%s\"", m_option_data.m_core_file.c_str());
+ commands_stream.Printf(" --core %s", EscapeString(m_option_data.m_core_file).c_str());
}
commands_stream.Printf("\n");
if (num_args > 1)
{
commands_stream.Printf ("settings set -- target.run-args ");
for (size_t arg_idx = 1; arg_idx < num_args; ++arg_idx)
- {
- const char *arg_cstr = m_option_data.m_args[arg_idx].c_str();
- if (strchr(arg_cstr, '"') == NULL)
- commands_stream.Printf(" \"%s\"", arg_cstr);
- else
- commands_stream.Printf(" '%s'", arg_cstr);
- }
+ commands_stream.Printf(" %s", EscapeString(m_option_data.m_args[arg_idx]).c_str());
commands_stream.Printf("\n");
}
}
else if (!m_option_data.m_core_file.empty())
{
- commands_stream.Printf("target create --core \"%s\"\n", m_option_data.m_core_file.c_str());
+ commands_stream.Printf("target create --core %s\n", EscapeString(m_option_data.m_core_file).c_str());
}
else if (!m_option_data.m_process_name.empty())
{
- commands_stream.Printf ("process attach --name \"%s\"", m_option_data.m_process_name.c_str());
+ commands_stream.Printf ("process attach --name %s", EscapeString(m_option_data.m_process_name).c_str());
if (m_option_data.m_wait_for)
commands_stream.Printf(" --waitfor");
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8083.21290.patch
Type: text/x-patch
Size: 2721 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150305/66612530/attachment.bin>
More information about the lldb-commits
mailing list