<rdar://problem/10374840>

Fixed an issue with the gdb format stuff for any aliases that expand to
contain a "--".

llvm-svn: 144240
This commit is contained in:
Greg Clayton 2011-11-09 23:25:03 +00:00
parent 856977cb15
commit 93c62e6607
1 changed files with 49 additions and 3 deletions

View File

@ -898,6 +898,36 @@ StripLeadingSpaces (std::string &s)
} }
} }
static size_t
FindArgumentTerminator (const std::string &s)
{
printf ("FindArgumentTerminator( s = '%s') => ", s.c_str());
const size_t s_len = s.size();
size_t offset = 0;
while (offset < s_len)
{
size_t pos = s.find ("--", offset);
if (pos == std::string::npos)
break;
if (pos > 0)
{
if (isspace(s[pos-1]))
{
// Check if the string ends "\s--" (where \s is a space character)
// or if we have "\s--\s".
if ((pos + 2 >= s_len) || isspace(s[pos+2]))
{
printf ("%zu\n", pos);
return pos;
}
}
}
offset = pos + 2;
}
printf ("-1\n");
return std::string::npos;
}
static bool static bool
ExtractCommand (std::string &command_string, std::string &command, std::string &suffix, char &quote_char) ExtractCommand (std::string &command_string, std::string &command, std::string &suffix, char &quote_char)
{ {
@ -1367,9 +1397,25 @@ CommandInterpreter::HandleCommand (const char *command_line,
Options *command_options = cmd_obj->GetOptions(); Options *command_options = cmd_obj->GetOptions();
if (command_options && command_options->SupportsLongOption("gdb-format")) if (command_options && command_options->SupportsLongOption("gdb-format"))
{ {
revised_command_line.Printf (" --gdb-format=%s", suffix.c_str() + 1); std::string gdb_format_option ("--gdb-format=");
if (wants_raw_input && command_string.find ("-- ") == std::string::npos) gdb_format_option += (suffix.c_str() + 1);
revised_command_line.Printf (" --");
bool inserted = false;
std::string &cmd = revised_command_line.GetString();
size_t arg_terminator_idx = FindArgumentTerminator (cmd);
if (arg_terminator_idx != std::string::npos)
{
// Insert the gdb format option before the "--" that terminates options
gdb_format_option.append(1,' ');
cmd.insert(arg_terminator_idx, gdb_format_option);
inserted = true;
}
if (!inserted)
revised_command_line.Printf (" %s", gdb_format_option.c_str());
if (wants_raw_input && FindArgumentTerminator(cmd) == std::string::npos)
revised_command_line.PutCString (" --");
} }
else else
{ {