Skip to content

Commit 40063b6

Browse files
Merge pull request swiftlang#455 from adrian-prantl/57756763-master
Cherry-pick fix for rdar://57756763
2 parents 5d0b583 + d476af3 commit 40063b6

File tree

16 files changed

+294
-605
lines changed

16 files changed

+294
-605
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
@@ -221,14 +221,10 @@ class FormatManager : public IFormatChangeListener {
221221
ConstString m_vectortypes_category_name;
222222
ConstString m_runtime_synths_category_name;
223223

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

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

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
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+
}

lldb/packages/Python/lldbsuite/test/lang/swift/dwarfimporter/C/TestSwiftDWARFImporterC.py

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,56 @@ def test_dwarf_importer(self):
5151
lldbutil.check_variable(self,
5252
target.FindFirstGlobalVariable("point"),
5353
typename='__ObjC.Point', num_children=2)
54-
self.expect("ta v point", substrs=["x = 1", "y = 2"])
55-
self.expect("ta v enumerator", substrs=[".yellow"])
56-
self.expect("ta v pureSwiftStruct", substrs=["pure swift"])
57-
self.expect("ta v swiftStructCMember",
54+
self.expect("target variable point", substrs=["x = 1", "y = 2"])
55+
self.expect("target variable enumerator", substrs=[".yellow"])
56+
self.expect("target variable pureSwiftStruct", substrs=["pure swift"])
57+
self.expect("target variable swiftStructCMember",
5858
substrs=["point", "x = 3", "y = 4",
5959
"sub", "x = 1", "y = 2", "z = 3",
6060
"swift struct c member"])
61-
self.expect("ta v typedef", substrs=["x = 5", "y = 6"])
62-
self.expect("ta v union", substrs=["(DoubleLongUnion)", "long_val = 42"])
63-
self.expect("ta v fromSubmodule",
61+
self.expect("target variable typedef", substrs=["x = 5", "y = 6"])
62+
self.expect("target variable union",
63+
substrs=["(DoubleLongUnion)", "long_val = 42"])
64+
self.expect("target variable fromSubmodule",
6465
substrs=["(FromSubmodule)", "x = 1", "y = 2", "z = 3"])
6566
process.Clear()
6667
target.Clear()
6768
lldb.SBDebugger.MemoryPressureDetected()
6869

70+
@skipIf(archs=['ppc64le'], bugnumber='SR-10214')
71+
@swiftTest
72+
# This test needs a working Remote Mirrors implementation.
73+
@skipIf(oslist=['linux', 'windows'])
74+
def test_dwarf_importer_exprs(self):
75+
lldb.SBDebugger.MemoryPressureDetected()
76+
self.runCmd("settings set symbols.use-swift-dwarfimporter true")
77+
self.build()
78+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
79+
self, 'break here', lldb.SBFileSpec('main.swift'))
80+
lldbutil.check_variable(self,
81+
target.FindFirstGlobalVariable("pureSwift"),
82+
value="42")
83+
lldbutil.check_variable(self,
84+
target.FindFirstGlobalVariable("point"),
85+
typename='__ObjC.Point', num_children=2)
86+
self.expect("expr point", substrs=["x = 1", "y = 2"])
87+
self.expect("expr enumerator", substrs=[".yellow"])
88+
self.expect("expr pureSwiftStruct", substrs=["pure swift"])
89+
self.expect("expr swiftStructCMember",
90+
substrs=["point", "x = 3", "y = 4",
91+
"sub", "x = 1", "y = 2", "z = 3",
92+
"swift struct c member"])
93+
self.expect("expr typedef", substrs=["x = 5", "y = 6"])
94+
# FIXME: lookup fails for:
95+
# a.union.unsafeMutableAddressor : __C.DoubleLongUnion
96+
self.expect("expr union", error=True)
97+
#self.expect("expr union", substrs=["(DoubleLongUnion)", "long_val = 42"])
98+
self.expect("expr fromSubmodule",
99+
substrs=["(FromSubmodule)", "x = 1", "y = 2", "z = 3"])
100+
process.Clear()
101+
target.Clear()
102+
lldb.SBDebugger.MemoryPressureDetected()
103+
69104
@skipIf(archs=['ppc64le'], bugnumber='SR-10214')
70105
@swiftTest
71106
def test_negative(self):
@@ -81,7 +116,7 @@ def test_negative(self):
81116
target.FindFirstGlobalVariable("point"),
82117
typename="Point", num_children=2)
83118
# This works as a Clang type.
84-
self.expect("ta v point", substrs=["x = 1", "y = 2"])
119+
self.expect("target variable point", substrs=["x = 1", "y = 2"])
85120
# This can't be resolved.
86121
lldbutil.check_variable(self,
87122
target.FindFirstGlobalVariable("swiftStructCMember"),
@@ -97,4 +132,3 @@ def test_negative(self):
97132
process.Clear()
98133
target.Clear()
99134
lldb.SBDebugger.MemoryPressureDetected()
100-
self.runCmd("settings set symbols.use-swift-dwarfimporter true")

lldb/packages/Python/lldbsuite/test/lang/swift/dwarfimporter/Objective-C/TestSwiftDWARFImporterObjC.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def build(self):
3737

3838
@skipUnlessDarwin
3939
@swiftTest
40-
def test_dwarf_importer(self):
40+
def test(self):
4141
self.runCmd("settings set symbols.use-swift-dwarfimporter true")
4242

4343
self.build()
@@ -52,12 +52,32 @@ def test_dwarf_importer(self):
5252
num_children=0)
5353
self.expect("target var obj", substrs=["ObjCClass",
5454
"private_ivar", "42"])
55-
# FIXME: This triggers an assertion in ClangImporter:
56-
# "ObjC property without getter"
57-
#self.expect("target var swiftChild", substrs=["ObjCClass",
58-
# "private_ivar", "42"])
55+
56+
self.expect("target var swiftChild", substrs=["ObjCClass",
57+
"private_ivar", "42"])
5958
# This is a Clang type, since Clang doesn't generate DWARF for protocols.
6059
self.expect("target var -d no-dyn proto", substrs=["(id)", "proto"])
6160
# This is a Swift type.
6261
self.expect("target var -d run proto", substrs=["(ProtoImpl)", "proto"])
6362
self.expect("target var -O proto", substrs=["<ProtoImpl"])
63+
64+
@skipUnlessDarwin
65+
@swiftTest
66+
def test_expr(self):
67+
self.runCmd("settings set symbols.use-swift-dwarfimporter true")
68+
69+
self.build()
70+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
71+
self, 'break here', lldb.SBFileSpec('main.swift'))
72+
lldbutil.check_variable(self,
73+
target.FindFirstGlobalVariable("pureSwift"),
74+
value="42")
75+
lldbutil.check_variable(self,
76+
target.FindFirstGlobalVariable("obj"),
77+
typename="Swift.Optional<__ObjC.ObjCClass>",
78+
num_children=0)
79+
self.expect("expr obj", substrs=["ObjCClass",
80+
"private_ivar", "42"])
81+
# FIXME: Removing this makes the expression below fail!
82+
self.expect("target var swiftChild")
83+
self.expect("expr swiftChild!.number", substrs=["42"])

lldb/packages/Python/lldbsuite/test/lang/swift/variables/objc_optionals/TestSwiftObjCOptionals.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,20 @@ def do_check_visuals(self):
5656
def do_check_api(self):
5757
"""Check formatting for T? and T! when T is an ObjC type"""
5858
optColor_Some = self.frame().FindVariable("optColor_Some")
59+
60+
# SwiftOptionalSyntheticFrontEnd passes GetNumChildren
61+
# through to the .some object. NSColor has no children.
5962
lldbutil.check_variable(
6063
self,
6164
optColor_Some,
6265
use_dynamic=False,
63-
num_children=1)
66+
num_children=0)
6467
uoptColor_Some = self.frame().FindVariable("uoptColor_Some")
6568
lldbutil.check_variable(
6669
self,
6770
uoptColor_Some,
6871
use_dynamic=False,
69-
num_children=1)
72+
num_children=0)
7073

7174
if __name__ == '__main__':
7275
import atexit

0 commit comments

Comments
 (0)