[Lldb-commits] [lldb] r144240 - /lldb/trunk/source/Interpreter/CommandInterpreter.cpp

Greg Clayton gclayton at apple.com
Wed Nov 9 15:25:03 PST 2011


Author: gclayton
Date: Wed Nov  9 17:25:03 2011
New Revision: 144240

URL: http://llvm.org/viewvc/llvm-project?rev=144240&view=rev
Log:
<rdar://problem/10374840>

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


Modified:
    lldb/trunk/source/Interpreter/CommandInterpreter.cpp

Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=144240&r1=144239&r2=144240&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Wed Nov  9 17:25:03 2011
@@ -898,6 +898,36 @@
     }
 }
 
+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
 ExtractCommand (std::string &command_string, std::string &command, std::string &suffix, char &quote_char)
 {
@@ -1367,9 +1397,25 @@
                         Options *command_options = cmd_obj->GetOptions();
                         if (command_options && command_options->SupportsLongOption("gdb-format"))
                         {
-                            revised_command_line.Printf (" --gdb-format=%s", suffix.c_str() + 1);
-                            if (wants_raw_input && command_string.find ("-- ") == std::string::npos)
-                                revised_command_line.Printf (" --");
+                            std::string gdb_format_option ("--gdb-format=");
+                            gdb_format_option += (suffix.c_str() + 1);
+    
+                            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
                         {





More information about the lldb-commits mailing list