Skip to content

Commit cfaa5c3

Browse files
committed
[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
1 parent e41ebbe commit cfaa5c3

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

lldb/source/Target/Target.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include "lldb/Utility/Timer.h"
6161

6262
#include "llvm/ADT/ScopeExit.h"
63+
#include "llvm/ADT/SetVector.h"
6364

6465
#include <memory>
6566
#include <mutex>
@@ -2231,7 +2232,10 @@ std::vector<TypeSystem *> Target::GetScratchTypeSystems(bool create_on_demand) {
22312232
if (!m_valid)
22322233
return {};
22332234

2234-
std::vector<TypeSystem *> scratch_type_systems;
2235+
// Some TypeSystem instances are associated with several LanguageTypes so
2236+
// they will show up several times in the loop below. The SetVector filters
2237+
// out all duplicates as they serve no use for the caller.
2238+
llvm::SetVector<TypeSystem *> scratch_type_systems;
22352239

22362240
LanguageSet languages_for_expressions =
22372241
Language::GetLanguagesSupportingTypeSystemsForExpressions();
@@ -2247,10 +2251,10 @@ std::vector<TypeSystem *> Target::GetScratchTypeSystems(bool create_on_demand) {
22472251
"system available",
22482252
Language::GetNameForLanguageType(language));
22492253
else
2250-
scratch_type_systems.emplace_back(&type_system_or_err.get());
2254+
scratch_type_systems.insert(&type_system_or_err.get());
22512255
}
22522256

2253-
return scratch_type_systems;
2257+
return scratch_type_systems.takeVector();
22542258
}
22552259

22562260
PersistentExpressionState *
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
from lldbsuite.test.lldbtest import *
4+
from lldbsuite.test import lldbutil
5+
6+
class TestCase(TestBase):
7+
8+
mydir = TestBase.compute_mydir(__file__)
9+
10+
@no_debug_info_test
11+
def test_FindTypes_on_scratch_AST(self):
12+
"""
13+
Tests FindTypes invoked with only LLDB's scratch AST present.
14+
"""
15+
target = self.dbg.GetDummyTarget()
16+
# There should be only one instance of 'unsigned long' in our single
17+
# scratch AST. Note: FindTypes/SBType hahave no filter by language, so
18+
# pick something that is unlikely to also be found in the scratch
19+
# TypeSystem of other language plugins.
20+
self.assertEqual(len(target.FindTypes("unsigned long")), 1)

0 commit comments

Comments
 (0)