Skip to content

Commit 7d46b86

Browse files
Merge pull request #445 from adrian-prantl/57756763
Cherry-pick bugfix for rdar://problem/57756763
2 parents 3cf1763 + 0146a04 commit 7d46b86

File tree

14 files changed

+265
-727
lines changed

14 files changed

+265
-727
lines changed

lldb/include/lldb/DataFormatters/FormatCache.h

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,22 @@ class FormatCache {
3333

3434
public:
3535
Entry();
36-
Entry(lldb::TypeFormatImplSP);
37-
Entry(lldb::TypeSummaryImplSP);
38-
Entry(lldb::SyntheticChildrenSP);
39-
Entry(lldb::TypeValidatorImplSP);
40-
Entry(lldb::TypeFormatImplSP, lldb::TypeSummaryImplSP,
41-
lldb::SyntheticChildrenSP, lldb::TypeValidatorImplSP);
4236

37+
template<typename ImplSP> bool IsCached();
4338
bool IsFormatCached();
44-
4539
bool IsSummaryCached();
46-
4740
bool IsSyntheticCached();
48-
4941
bool IsValidatorCached();
5042

51-
lldb::TypeFormatImplSP GetFormat();
52-
53-
lldb::TypeSummaryImplSP GetSummary();
54-
55-
lldb::SyntheticChildrenSP GetSynthetic();
56-
57-
lldb::TypeValidatorImplSP GetValidator();
58-
59-
void SetFormat(lldb::TypeFormatImplSP);
60-
61-
void SetSummary(lldb::TypeSummaryImplSP);
62-
63-
void SetSynthetic(lldb::SyntheticChildrenSP);
43+
void Get(lldb::TypeFormatImplSP &);
44+
void Get(lldb::TypeSummaryImplSP &);
45+
void Get(lldb::SyntheticChildrenSP &);
46+
void Get(lldb::TypeValidatorImplSP &);
6447

65-
void SetValidator(lldb::TypeValidatorImplSP);
48+
void Set(lldb::TypeFormatImplSP);
49+
void Set(lldb::TypeSummaryImplSP);
50+
void Set(lldb::SyntheticChildrenSP);
51+
void Set(lldb::TypeValidatorImplSP);
6652
};
6753
typedef std::map<ConstString, Entry> CacheMap;
6854
CacheMap m_map;
@@ -76,32 +62,19 @@ class FormatCache {
7662
public:
7763
FormatCache();
7864

79-
bool GetFormat(ConstString type, lldb::TypeFormatImplSP &format_sp);
80-
81-
bool GetSummary(ConstString type, lldb::TypeSummaryImplSP &summary_sp);
82-
83-
bool GetSynthetic(ConstString type,
84-
lldb::SyntheticChildrenSP &synthetic_sp);
85-
86-
bool GetValidator(ConstString type,
87-
lldb::TypeValidatorImplSP &summary_sp);
88-
89-
void SetFormat(ConstString type, lldb::TypeFormatImplSP &format_sp);
90-
91-
void SetSummary(ConstString type, lldb::TypeSummaryImplSP &summary_sp);
92-
93-
void SetSynthetic(ConstString type,
94-
lldb::SyntheticChildrenSP &synthetic_sp);
95-
96-
void SetValidator(ConstString type,
97-
lldb::TypeValidatorImplSP &synthetic_sp);
65+
template <typename ImplSP> bool Get(ConstString type, ImplSP &format_impl_sp);
66+
void Set(ConstString type, lldb::TypeFormatImplSP &format_sp);
67+
void Set(ConstString type, lldb::TypeSummaryImplSP &summary_sp);
68+
void Set(ConstString type, lldb::SyntheticChildrenSP &synthetic_sp);
69+
void Set(ConstString type, lldb::TypeValidatorImplSP &synthetic_sp);
9870

9971
void Clear();
10072

10173
uint64_t GetCacheHits() { return m_cache_hits; }
10274

10375
uint64_t GetCacheMisses() { return m_cache_misses; }
10476
};
77+
10578
} // namespace lldb_private
10679

10780
#endif // lldb_FormatCache_h_

lldb/include/lldb/DataFormatters/FormatManager.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,10 @@ class FormatManager : public IFormatChangeListener {
220220
ConstString m_system_category_name;
221221
ConstString m_vectortypes_category_name;
222222

223-
lldb::TypeFormatImplSP GetHardcodedFormat(FormattersMatchData &);
224-
225-
lldb::TypeSummaryImplSP GetHardcodedSummaryFormat(FormattersMatchData &);
226-
227-
lldb::SyntheticChildrenSP
228-
GetHardcodedSyntheticChildren(FormattersMatchData &);
229-
230-
lldb::TypeValidatorImplSP GetHardcodedValidator(FormattersMatchData &);
223+
template <typename ImplSP>
224+
ImplSP Get(ValueObject &valobj, lldb::DynamicValueType use_dynamic);
225+
template <typename ImplSP> ImplSP GetCached(FormattersMatchData &match_data);
226+
template <typename ImplSP> ImplSP GetHardcoded(FormattersMatchData &);
231227

232228
TypeCategoryMap &GetCategories() { return m_categories_map; }
233229

lldb/include/lldb/DataFormatters/LanguageCategory.h

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,11 @@ class LanguageCategory {
2525

2626
LanguageCategory(lldb::LanguageType lang_type);
2727

28-
bool Get(FormattersMatchData &match_data, lldb::TypeFormatImplSP &format_sp);
29-
30-
bool Get(FormattersMatchData &match_data, lldb::TypeSummaryImplSP &format_sp);
31-
32-
bool Get(FormattersMatchData &match_data,
33-
lldb::SyntheticChildrenSP &format_sp);
34-
35-
bool Get(FormattersMatchData &match_data,
36-
lldb::TypeValidatorImplSP &format_sp);
37-
38-
bool GetHardcoded(FormatManager &fmt_mgr, FormattersMatchData &match_data,
39-
lldb::TypeFormatImplSP &format_sp);
40-
28+
template <typename ImplSP>
29+
bool Get(FormattersMatchData &match_data, ImplSP &format_sp);
30+
template <typename ImplSP>
4131
bool GetHardcoded(FormatManager &fmt_mgr, FormattersMatchData &match_data,
42-
lldb::TypeSummaryImplSP &format_sp);
43-
44-
bool GetHardcoded(FormatManager &fmt_mgr, FormattersMatchData &match_data,
45-
lldb::SyntheticChildrenSP &format_sp);
46-
47-
bool GetHardcoded(FormatManager &fmt_mgr, FormattersMatchData &match_data,
48-
lldb::TypeValidatorImplSP &format_sp);
32+
ImplSP &format_sp);
4933

5034
lldb::TypeCategoryImplSP GetCategory() const;
5135

@@ -65,6 +49,9 @@ class LanguageCategory {
6549
HardcodedFormatters::HardcodedSyntheticFinder m_hardcoded_synthetics;
6650
HardcodedFormatters::HardcodedValidatorFinder m_hardcoded_validators;
6751

52+
template <typename ImplSP>
53+
auto &GetHardcodedFinder();
54+
6855
lldb_private::FormatCache m_format_cache;
6956

7057
bool m_enabled;

lldb/include/lldb/DataFormatters/TypeCategory.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,16 +333,16 @@ class TypeCategoryImpl {
333333
return m_enabled_position;
334334
}
335335

336-
bool Get(ValueObject &valobj, const FormattersMatchVector &candidates,
336+
bool Get(lldb::LanguageType lang, const FormattersMatchVector &candidates,
337337
lldb::TypeFormatImplSP &entry, uint32_t *reason = nullptr);
338338

339-
bool Get(ValueObject &valobj, const FormattersMatchVector &candidates,
339+
bool Get(lldb::LanguageType lang, const FormattersMatchVector &candidates,
340340
lldb::TypeSummaryImplSP &entry, uint32_t *reason = nullptr);
341341

342-
bool Get(ValueObject &valobj, const FormattersMatchVector &candidates,
342+
bool Get(lldb::LanguageType lang, const FormattersMatchVector &candidates,
343343
lldb::SyntheticChildrenSP &entry, uint32_t *reason = nullptr);
344344

345-
bool Get(ValueObject &valobj, const FormattersMatchVector &candidates,
345+
bool Get(lldb::LanguageType lang, const FormattersMatchVector &candidates,
346346
lldb::TypeValidatorImplSP &entry, uint32_t *reason = nullptr);
347347

348348
void Clear(FormatCategoryItems items = ALL_ITEM_TYPES);
@@ -394,7 +394,7 @@ class TypeCategoryImpl {
394394

395395
void Disable() { Enable(false, UINT32_MAX); }
396396

397-
bool IsApplicable(ValueObject &valobj);
397+
bool IsApplicable(lldb::LanguageType lang);
398398

399399
uint32_t GetLastEnabledPosition() { return m_enabled_position; }
400400

lldb/include/lldb/DataFormatters/TypeCategoryMap.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,7 @@ class TypeCategoryMap {
7777

7878
uint32_t GetCount() { return m_map.size(); }
7979

80-
lldb::TypeFormatImplSP GetFormat(FormattersMatchData &match_data);
81-
82-
lldb::TypeSummaryImplSP GetSummaryFormat(FormattersMatchData &match_data);
83-
84-
lldb::SyntheticChildrenSP
85-
GetSyntheticChildren(FormattersMatchData &match_data);
86-
87-
lldb::TypeValidatorImplSP GetValidator(FormattersMatchData &match_data);
80+
template <typename ImplSP> void Get(FormattersMatchData &, ImplSP &);
8881

8982
private:
9083
class delete_matching_categories {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
C_SOURCES := a.c b.c
2+
3+
include Makefile.rules
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import lldb
2+
from lldbsuite.test.lldbtest import *
3+
from lldbsuite.test.decorators import *
4+
import lldbsuite.test.lldbutil as lldbutil
5+
6+
7+
class TestDataFormatterCaching(TestBase):
8+
9+
mydir = TestBase.compute_mydir(__file__)
10+
11+
def setUp(self):
12+
TestBase.setUp(self)
13+
14+
def test_with_run_command(self):
15+
"""
16+
Test that hardcoded summary formatter matches aren't improperly cached.
17+
"""
18+
self.build()
19+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
20+
self, 'break here', lldb.SBFileSpec('a.c'))
21+
valobj = self.frame().FindVariable('f')
22+
self.assertEqual(valobj.GetValue(), '4')
23+
bkpt_b = target.BreakpointCreateBySourceRegex('break here',
24+
lldb.SBFileSpec('b.c'))
25+
lldbutil.continue_to_breakpoint(process, bkpt_b)
26+
valobj = self.frame().FindVariable('f4')
27+
self.assertEqual(valobj.GetSummary(), '(1, 2, 3, 4)')
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
typedef float float4;
2+
3+
int main() {
4+
float4 f = 4.0f;
5+
// break here
6+
return a();
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
typedef float float4 __attribute__((ext_vector_type(4)));
2+
void stop() {}
3+
int a() {
4+
float4 f4 = {1, 2, 3, 4};
5+
// break here
6+
stop();
7+
return 0;
8+
}

0 commit comments

Comments
 (0)