[Lldb-commits] [lldb] r200996 - <rdar://problem/12857181>

Enrico Granata egranata at apple.com
Fri Feb 7 14:12:55 PST 2014


Author: enrico
Date: Fri Feb  7 16:12:55 2014
New Revision: 200996

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

When a user says

type formatter add ... unsigned int

he most probably means to deal with the "unsigned int" type. However, given how the LLDB command parser works, that command will try to add the formatter to the TWO types 'unsigned' AND 'int'

Since this is unlikely to be what the user wants, warn about it, and suggest they can use quotes to override the debugger's understanding


Modified:
    lldb/trunk/source/Commands/CommandObjectType.cpp

Modified: lldb/trunk/source/Commands/CommandObjectType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectType.cpp?rev=200996&r1=200995&r2=200996&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectType.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectType.cpp Fri Feb  7 16:12:55 2014
@@ -95,7 +95,32 @@ public:
     
 };
 
-
+static bool
+WarnOnPotentialUnquotedUnsignedType (Args& command, CommandReturnObject &result)
+{
+    for (int idx = 0; idx < command.GetArgumentCount(); idx++)
+    {
+        const char* arg = command.GetArgumentAtIndex(idx);
+        if (idx+1 < command.GetArgumentCount())
+        {
+            if (arg && 0 == strcmp(arg,"unsigned"))
+            {
+                const char* next = command.GetArgumentAtIndex(idx+1);
+                if (next &&
+                    (0 == strcmp(next, "int") ||
+                     0 == strcmp(next, "short") ||
+                     0 == strcmp(next, "char") ||
+                     0 == strcmp(next, "long")))
+                {
+                    result.AppendWarningWithFormat("%s %s being treated as two types. if you meant the combined type name use quotes, as in \"%s %s\"\n",
+                                                   arg,next,arg,next);
+                    return true;
+                }
+            }
+        }
+    }
+    return false;
+}
 
 class CommandObjectTypeSummaryAdd :
     public CommandObjectParsed,
@@ -454,6 +479,8 @@ protected:
     bool
     DoExecute (Args& command, CommandReturnObject &result)
     {
+        WarnOnPotentialUnquotedUnsignedType(command, result);
+        
         if (m_options.handwrite_python)
             return Execute_HandwritePython(command, result);
         else if (m_options.is_class_based)
@@ -810,6 +837,8 @@ protected:
         if (!category_sp)
             return false;
         
+        WarnOnPotentialUnquotedUnsignedType(command, result);
+        
         for (size_t i = 0; i < argc; i++)
         {
             const char* typeA = command.GetArgumentAtIndex(i);
@@ -1769,6 +1798,8 @@ CommandObjectTypeSummaryAdd::CommandObje
 bool
 CommandObjectTypeSummaryAdd::DoExecute (Args& command, CommandReturnObject &result)
 {
+    WarnOnPotentialUnquotedUnsignedType(command, result);
+
     if (m_options.m_is_add_script)
     {
 #ifndef LLDB_DISABLE_PYTHON
@@ -4183,6 +4214,8 @@ protected:
         
         Error error;
         
+        WarnOnPotentialUnquotedUnsignedType(command, result);
+        
         for (size_t i = 0; i < argc; i++)
         {
             const char* typeA = command.GetArgumentAtIndex(i);





More information about the lldb-commits mailing list