[Lldb-commits] [lldb] r221643 - Added a testcase that checks that fairly complicated

Sean Callanan scallanan at apple.com
Mon Nov 10 16:14:00 PST 2014


Author: spyffe
Date: Mon Nov 10 18:14:00 2014
New Revision: 221643

URL: http://llvm.org/viewvc/llvm-project?rev=221643&view=rev
Log:
Added a testcase that checks that fairly complicated
structures are parsed safely by the Objective-C runtime.

Also made some modifications to the way we parse structs
in the runtime to avoid mis-parsing @ followed by the name
of the next field.

<rdar://problem/18887634>

Added:
    lldb/trunk/test/lang/objcxx/objcxx-ivar-vector/
    lldb/trunk/test/lang/objcxx/objcxx-ivar-vector/TestIvarVector.py
    lldb/trunk/test/lang/objcxx/objcxx-ivar-vector/main.mm
Modified:
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp?rev=221643&r1=221642&r2=221643&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp Mon Nov 10 18:14:00 2014
@@ -43,6 +43,7 @@ AppleObjCTypeEncodingParser::ReadQuotedS
     StreamString buffer;
     while (type.HasAtLeast(1) && type.Peek() != '"')
         buffer.Printf("%c",type.Next());
+    assert(type.Next() == '"');
     return buffer.GetString();
 }
 
@@ -173,7 +174,46 @@ AppleObjCTypeEncodingParser::BuildObjCOb
     std::string name;
     
     if (type.NextIf('"'))
+    {
+        // We have to be careful here.  We're used to seeing
+        //   @"NSString"
+        // but in records it is possible that the string following an @ is the name of the next field and @ means "id".
+        // This is the case if anything unquoted except for "}", the end of the type, or another name follows the quoted string.
+        //
+        // E.g.
+        // - @"NSString"@ means "id, followed by a field named NSString of type id"
+        // - @"NSString"} means "a pointer to NSString and the end of the struct"
+        // - @"NSString""nextField" means "a pointer to NSString and a field named nextField"
+        // - @"NSString" followed by the end of the string means "a pointer to NSString"
+        //
+        // As a result, the rule is: If we see @ followed by a quoted string, we peek.
+        // - If we see }, ), ], the end of the string, or a quote ("), the quoted string is a class name.
+        // - If we see anything else, the quoted string is a field name and we push it back onto type.
+
         name = ReadQuotedString(type);
+        
+        if (type.HasAtLeast(1))
+        {
+            switch (type.Peek())
+            {
+            default:
+                // roll back
+                type.PutBack(name.length() + 1);
+                name.clear();
+                break;
+            case '}':
+            case ')':
+            case ']':
+            case '"':
+                // the quoted string is a class name – see the rule
+                break;
+            }
+        }
+        else
+        {
+            // the quoted string is a class name – see the rule
+        }
+    }
     
     if (for_expression && !name.empty())
     {

Added: lldb/trunk/test/lang/objcxx/objcxx-ivar-vector/TestIvarVector.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/objcxx/objcxx-ivar-vector/TestIvarVector.py?rev=221643&view=auto
==============================================================================
--- lldb/trunk/test/lang/objcxx/objcxx-ivar-vector/TestIvarVector.py (added)
+++ lldb/trunk/test/lang/objcxx/objcxx-ivar-vector/TestIvarVector.py Mon Nov 10 18:14:00 2014
@@ -0,0 +1,4 @@
+import lldbinline
+import lldbtest
+
+lldbinline.MakeInlineTest(__file__, globals(), [lldbtest.skipIfFreeBSD,lldbtest.skipIfLinux,lldbtest.skipIfWindows])

Added: lldb/trunk/test/lang/objcxx/objcxx-ivar-vector/main.mm
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/objcxx/objcxx-ivar-vector/main.mm?rev=221643&view=auto
==============================================================================
--- lldb/trunk/test/lang/objcxx/objcxx-ivar-vector/main.mm (added)
+++ lldb/trunk/test/lang/objcxx/objcxx-ivar-vector/main.mm Mon Nov 10 18:14:00 2014
@@ -0,0 +1,33 @@
+#import <Foundation/Foundation.h>
+
+#include <vector>
+
+ at interface MyElement : NSObject {
+}
+ at end
+
+ at interface MyClass : NSObject {
+  std::vector<MyElement *> elements;
+};
+
+-(void)doSomething;
+
+ at end
+
+ at implementation MyClass
+
+-(void)doSomething
+{
+  NSLog(@"Hello"); //% self.expect("expression -- elements", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["vector", "MyElement"]);
+}
+
+ at end
+
+int main ()
+{
+  @autoreleasepool
+  {
+    MyClass *c = [MyClass alloc];
+    [c doSomething];
+  }
+}





More information about the lldb-commits mailing list