[Lldb-commits] [lldb] r331719 - Really test type lookup in TestCppTypeLookup.py

Frederic Riss via lldb-commits lldb-commits at lists.llvm.org
Mon May 7 20:08:46 PDT 2018


Author: friss
Date: Mon May  7 20:08:46 2018
New Revision: 331719

URL: http://llvm.org/viewvc/llvm-project?rev=331719&view=rev
Log:
Really test type lookup in TestCppTypeLookup.py

Summary:
... and fix one bug found this way. Currently, the test works not because
types are looked up correctly, but because by injecting local variables
we also materialize the types for Clang. If we disable the local variable
injection, then one check fails.

The reason of the failure is that FindTypes is run with max_matches==1
and this value is passed down to the symbol lookup functions. When the
search is performed only on the basename (like it's the case for an
entity defined in the root namespace), then the search will stop after
having found one match on the basename. But that match might be in a
namespace, we were really just looking up the basename in the accelerator
tables.

The solution is to not pass max_matches down, but to search without a
limit and let RemoveMismatchedTypes do its job afterwards. Note the
patch includes 2 hunks with the same change, but only the latter is
tested. I couldn't find a way to create a testcase for the other
branch of the if ('image lookup -t' allows me to get there, but it
only ever returns one type anyway).

Reviewers: clayborg, jingham

Subscribers: lldb-commits

Differential Revision: https://reviews.llvm.org/D46548

Modified:
    lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestCppTypeLookup.py
    lldb/trunk/source/Core/Module.cpp

Modified: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestCppTypeLookup.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestCppTypeLookup.py?rev=331719&r1=331718&r2=331719&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestCppTypeLookup.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/type_lookup/TestCppTypeLookup.py Mon May  7 20:08:46 2018
@@ -38,6 +38,11 @@ class TestCppTypeLookup(TestBase):
         # Get frame for current thread
         frame = thread.GetSelectedFrame()
 
+        # We are testing LLDB's type lookup machinery, but if we inject local
+        # variables, the types for those will be found because they have been
+        # imported through the variable, not because the type lookup worked.
+        self.runCmd("settings set target.experimental.inject-local-vars false")
+
         # Make sure we don't accidentally accept structures that exist only
         # in namespaces when evaluating expressions with top level types.
         # Prior to the revision that added this test, we would accidentally

Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=331719&r1=331718&r2=331719&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Mon May  7 20:08:46 2018
@@ -997,6 +997,7 @@ size_t Module::FindTypes(
   const bool append = true;
   TypeClass type_class = eTypeClassAny;
   TypeMap typesmap;
+
   if (Type::GetTypeScopeAndBasename(type_name_cstr, type_scope, type_basename,
                                     type_class)) {
     // Check if "name" starts with "::" which means the qualified type starts
@@ -1019,12 +1020,12 @@ size_t Module::FindTypes(
       // The "type_name_cstr" will have been modified if we have a valid type
       // class prefix (like "struct", "class", "union", "typedef" etc).
       FindTypes_Impl(sc, ConstString(type_basename), nullptr, append,
-                     max_matches, searched_symbol_files, typesmap);
+                     UINT_MAX, searched_symbol_files, typesmap);
       typesmap.RemoveMismatchedTypes(type_scope, type_basename, type_class,
                                      exact_match);
       num_matches = typesmap.GetSize();
     } else {
-      num_matches = FindTypes_Impl(sc, name, nullptr, append, max_matches,
+      num_matches = FindTypes_Impl(sc, name, nullptr, append, UINT_MAX,
                                    searched_symbol_files, typesmap);
       if (exact_match) {
         std::string name_str(name.AsCString(""));




More information about the lldb-commits mailing list