[Lldb-commits] [lldb] r333786 - Fix Module::FindTypes to return the correct number of matches.
Frederic Riss via lldb-commits
lldb-commits at lists.llvm.org
Fri Jun 1 13:14:21 PDT 2018
Author: friss
Date: Fri Jun 1 13:14:21 2018
New Revision: 333786
URL: http://llvm.org/viewvc/llvm-project?rev=333786&view=rev
Log:
Fix Module::FindTypes to return the correct number of matches.
In r331719, I changed Module::FindTypes not to limit the amount
of types returned by the Symbol provider, because we want all
possible matches to be able to filter them. In one code path,
the filtering was applied to the TypeList without changing the
number of types that gets returned. This is turn could cause
consumers to access beyond the end of the TypeList.
This patch fixes this case and also adds an assertion to
TypeList::GetTypeAtIndex to catch those obvious programming
mistakes.
Triggering the condition in which we performed the incorrect
access was not easy. It happened a lot in mixed Swift/ObjectiveC
code, but I was able to trigger it in pure Objective C++ although
in a contrieved way.
rdar://problem/40254997
Added:
lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/class-name-clash/
lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/class-name-clash/Makefile
lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/class-name-clash/TestNameClash.py
lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/class-name-clash/main.mm
lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/class-name-clash/myobject.mm
Modified:
lldb/trunk/source/Core/Module.cpp
lldb/trunk/source/Symbol/TypeList.cpp
Added: lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/class-name-clash/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/class-name-clash/Makefile?rev=333786&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/class-name-clash/Makefile (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/class-name-clash/Makefile Fri Jun 1 13:14:21 2018
@@ -0,0 +1,7 @@
+LEVEL = ../../../make
+OBJCXX_SOURCES := main.mm myobject.mm
+include $(LEVEL)/Makefile.rules
+
+# myobject.o needs to be built without debug info
+myobject.o: myobject.mm
+ $(CXX) -c -o $@ $<
Added: lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/class-name-clash/TestNameClash.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/class-name-clash/TestNameClash.py?rev=333786&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/class-name-clash/TestNameClash.py (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/class-name-clash/TestNameClash.py Fri Jun 1 13:14:21 2018
@@ -0,0 +1,6 @@
+from lldbsuite.test import decorators
+from lldbsuite.test import lldbinline
+
+lldbinline.MakeInlineTest(
+ __file__, globals(), [
+ decorators.skipIfFreeBSD, decorators.skipIfLinux, decorators.skipIfWindows])
Added: lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/class-name-clash/main.mm
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/class-name-clash/main.mm?rev=333786&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/class-name-clash/main.mm (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/class-name-clash/main.mm Fri Jun 1 13:14:21 2018
@@ -0,0 +1,21 @@
+#import <Foundation/Foundation.h>
+
+namespace NS {
+ class MyObject { int i = 42; };
+ NS::MyObject globalObject;
+}
+
+ at interface MyObject: NSObject
+ at end
+
+int main ()
+{
+ @autoreleasepool
+ {
+ MyObject *o = [MyObject alloc];
+ return 0; //% self.expect("fr var o", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["(MyObject"]);
+ //% self.expect("fr var globalObject", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["42"]);
+ }
+}
+
+
Added: lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/class-name-clash/myobject.mm
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/class-name-clash/myobject.mm?rev=333786&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/class-name-clash/myobject.mm (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/objcxx/class-name-clash/myobject.mm Fri Jun 1 13:14:21 2018
@@ -0,0 +1,7 @@
+#import <Foundation/Foundation.h>
+
+ at interface MyObject : NSObject
+ at end
+
+ at implementation MyObject
+ at end
Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=333786&r1=333785&r2=333786&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Fri Jun 1 13:14:21 2018
@@ -1030,6 +1030,7 @@ size_t Module::FindTypes(
std::string name_str(name.AsCString(""));
typesmap.RemoveMismatchedTypes(type_scope, name_str, type_class,
exact_match);
+ num_matches = typesmap.GetSize();
}
}
}
Modified: lldb/trunk/source/Symbol/TypeList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/TypeList.cpp?rev=333786&r1=333785&r2=333786&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/TypeList.cpp (original)
+++ lldb/trunk/source/Symbol/TypeList.cpp Fri Jun 1 13:14:21 2018
@@ -77,6 +77,7 @@ uint32_t TypeList::GetSize() const { ret
TypeSP TypeList::GetTypeAtIndex(uint32_t idx) {
iterator pos, end;
uint32_t i = idx;
+ assert(i < GetSize() && "Accessing past the end of a TypeList");
for (pos = m_types.begin(), end = m_types.end(); pos != end; ++pos) {
if (i == 0)
return *pos;
More information about the lldb-commits
mailing list