Author: Raphael Isemann Date: 2021-10-19T11:49:47+02:00 New Revision: cfaa5c344d5bc73aae0ec39d57d98acf7463fccf
URL: https://github.com/llvm/llvm-project/commit/cfaa5c344d5bc73aae0ec39d57d98acf7463fccf DIFF: https://github.com/llvm/llvm-project/commit/cfaa5c344d5bc73aae0ec39d57d98acf7463fccf.diff LOG: [lldb] Filter duplicates in Target::GetScratchTypeSystems `Target::GetScratchTypeSystems` returns the list of scratch TypeSystems. The current implementation is iterating over all LanguageType values and retrieves the respective TypeSystem for each LanguageType. All C/C++/Obj-C LanguageTypes are however mapped to the same ScratchTypeSystemClang instance, so the current implementation adds this single TypeSystem instance several times to the list of TypeSystems (once for every LanguageType that we support). The only observable effect of this is that `SBTarget.FindTypes` for builtin types currently queries the ScratchTypeSystemClang several times (and also adds the same result several times). Reviewed By: bulbazord, labath Differential Revision: https://reviews.llvm.org/D111931 Added: lldb/test/API/lang/c/builtin-types/TestCBuiltinTypes.py Modified: lldb/source/Target/Target.cpp Removed: ################################################################################ diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 995527e2e8da1..7f39da697eb0f 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -60,6 +60,7 @@ #include "lldb/Utility/Timer.h" #include "llvm/ADT/ScopeExit.h" +#include "llvm/ADT/SetVector.h" #include <memory> #include <mutex> @@ -2231,7 +2232,10 @@ std::vector<TypeSystem *> Target::GetScratchTypeSystems(bool create_on_demand) { if (!m_valid) return {}; - std::vector<TypeSystem *> scratch_type_systems; + // Some TypeSystem instances are associated with several LanguageTypes so + // they will show up several times in the loop below. The SetVector filters + // out all duplicates as they serve no use for the caller. + llvm::SetVector<TypeSystem *> scratch_type_systems; LanguageSet languages_for_expressions = Language::GetLanguagesSupportingTypeSystemsForExpressions(); @@ -2247,10 +2251,10 @@ std::vector<TypeSystem *> Target::GetScratchTypeSystems(bool create_on_demand) { "system available", Language::GetNameForLanguageType(language)); else - scratch_type_systems.emplace_back(&type_system_or_err.get()); + scratch_type_systems.insert(&type_system_or_err.get()); } - return scratch_type_systems; + return scratch_type_systems.takeVector(); } PersistentExpressionState * diff --git a/lldb/test/API/lang/c/builtin-types/TestCBuiltinTypes.py b/lldb/test/API/lang/c/builtin-types/TestCBuiltinTypes.py new file mode 100644 index 0000000000000..634441196b93a --- /dev/null +++ b/lldb/test/API/lang/c/builtin-types/TestCBuiltinTypes.py @@ -0,0 +1,20 @@ +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @no_debug_info_test + def test_FindTypes_on_scratch_AST(self): + """ + Tests FindTypes invoked with only LLDB's scratch AST present. + """ + target = self.dbg.GetDummyTarget() + # There should be only one instance of 'unsigned long' in our single + # scratch AST. Note: FindTypes/SBType hahave no filter by language, so + # pick something that is unlikely to also be found in the scratch + # TypeSystem of other language plugins. + self.assertEqual(len(target.FindTypes("unsigned long")), 1) _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits