Correctly quote arguments in LLDB driver

Summary:
LLDB driver was simply tacking quotes around the strings in lldb commands, hoping that will work.
This changes it to properly escape quotes and backslashes.

Reviewers: clayborg

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D8083

llvm-svn: 231394
This commit is contained in:
Pavel Labath 2015-03-05 19:17:56 +00:00
parent 1fe2a8d8f5
commit aa1ae6f660
1 changed files with 18 additions and 12 deletions

View File

@ -956,6 +956,18 @@ CleanupAfterCommandSourcing (int fds[2])
}
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,13 +1017,13 @@ Driver::MainLoop ()
{
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");
@ -1019,23 +1031,17 @@ Driver::MainLoop ()
{
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");