Skip to content

Commit a93e6b3

Browse files
Merge pull request #6898 from apple/dl/lldb-improve-getobjectdescription-for-variables
[lldb] Improve GetObjectDescription for Swift variables
2 parents cee9300 + 33008ad commit a93e6b3

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
#include "lldb/Core/PluginManager.h"
2525
#include "lldb/Core/Progress.h"
2626
#include "lldb/Core/Section.h"
27+
#include "lldb/Core/ValueObject.h"
2728
#include "lldb/Core/ValueObjectCast.h"
2829
#include "lldb/Core/ValueObjectConstResult.h"
30+
#include "lldb/Core/ValueObjectVariable.h"
2931
#include "lldb/DataFormatters/StringPrinter.h"
3032
#include "lldb/Host/OptionParser.h"
3133
#include "lldb/Interpreter/CommandInterpreter.h"
@@ -1110,6 +1112,13 @@ SwiftLanguageRuntimeImpl::RunObjectDescriptionExpr(ValueObject &object,
11101112
}
11111113
}
11121114

1115+
static bool IsVariable(ValueObject &object) {
1116+
if (object.IsSynthetic())
1117+
return IsVariable(*object.GetNonSyntheticValue());
1118+
1119+
return bool(object.GetVariable());
1120+
}
1121+
11131122
static bool IsSwiftResultVariable(ConstString name) {
11141123
if (name) {
11151124
llvm::StringRef name_sr(name.GetStringRef());
@@ -1140,10 +1149,9 @@ bool SwiftLanguageRuntimeImpl::GetObjectDescription(Stream &str,
11401149
}
11411150

11421151
std::string expr_string;
1143-
1144-
if (::IsSwiftResultVariable(object.GetName())) {
1145-
// if this thing is a Swift expression result variable, it has two
1146-
// properties:
1152+
1153+
if (::IsVariable(object) || ::IsSwiftResultVariable(object.GetName())) {
1154+
// if the object is a Swift variable, it has two properties:
11471155
// a) its name is something we can refer to in expressions for free
11481156
// b) its type may be something we can't actually talk about in expressions
11491157
// so, just use the result variable's name in the expression and be done
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SWIFT_SOURCES := main.swift
2+
3+
include Makefile.rules
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
Test CFUUID object description.
3+
"""
4+
5+
import lldb
6+
from lldbsuite.test.lldbtest import *
7+
from lldbsuite.test.decorators import *
8+
import lldbsuite.test.lldbutil as lldbutil
9+
10+
11+
class TestCase(TestBase):
12+
@swiftTest
13+
@skipUnlessFoundation
14+
def test(self):
15+
"""Test CFUUID object description prints the UUID string."""
16+
self.build()
17+
lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.swift"))
18+
# Swift type validation fails in IsPossibleDynamicType rdar://109611675
19+
self.runCmd("settings set symbols.swift-validate-typesystem false")
20+
uuid = "68753A44-4D6F-1226-9C60-0050E4C00067"
21+
self.expect("frame variable -O uuid", substrs=[uuid])
22+
self.expect("dwim-print -O -- uuid", substrs=[uuid])
23+
self.expect("expression -O -- uuid", substrs=[uuid])
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import CoreFoundation
2+
import Foundation // Needed for `as CFString` cast
3+
4+
func main() {
5+
let uuid = CFUUIDCreateFromString(nil, "68753A44-4D6F-1226-9C60-0050E4C00067" as CFString)
6+
print("break here")
7+
}
8+
9+
main()

0 commit comments

Comments
 (0)