Skip to content

Commit 7442d8a

Browse files
committed
IRGen: Add another lldb resilience hack
When accessing global variables defined in the REPL, lldb does not consult debug info, so it does not see that the DW_OP_deref was emitted. So instead, set a special bit on globals defined in the REPL which bypasses resilience for them altogether. Part of the fix <rdar://problem/39722386>.
1 parent 23f70f7 commit 7442d8a

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

include/swift/AST/Decl.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ class alignas(1 << DeclAlignInBits) Decl {
328328
StorageKind : 4
329329
);
330330

331-
SWIFT_INLINE_BITFIELD(VarDecl, AbstractStorageDecl, 1+4+1+1+1,
331+
SWIFT_INLINE_BITFIELD(VarDecl, AbstractStorageDecl, 1+4+1+1+1+1,
332332
/// \brief Whether this property is a type property (currently unfortunately
333333
/// called 'static').
334334
IsStatic : 1,
@@ -347,7 +347,11 @@ class alignas(1 << DeclAlignInBits) Decl {
347347

348348
/// \brief Whether this is a property used in expressions in the debugger.
349349
/// It is up to the debugger to instruct SIL how to access this variable.
350-
IsDebuggerVar : 1
350+
IsDebuggerVar : 1,
351+
352+
/// \brief Whether this is a property defined in the debugger's REPL.
353+
/// FIXME: Remove this once LLDB has proper support for resilience.
354+
IsREPLVar : 1
351355
);
352356

353357
SWIFT_INLINE_BITFIELD(ParamDecl, VarDecl, 1 + NumDefaultArgumentKindBits,
@@ -4576,6 +4580,7 @@ class VarDecl : public AbstractStorageDecl {
45764580
Bits.VarDecl.Specifier = static_cast<unsigned>(Sp);
45774581
Bits.VarDecl.IsCaptureList = IsCaptureList;
45784582
Bits.VarDecl.IsDebuggerVar = false;
4583+
Bits.VarDecl.IsREPLVar = false;
45794584
Bits.VarDecl.HasNonPatternBindingInit = false;
45804585
setType(Ty);
45814586
}
@@ -4762,6 +4767,13 @@ class VarDecl : public AbstractStorageDecl {
47624767
void setDebuggerVar(bool IsDebuggerVar) {
47634768
Bits.VarDecl.IsDebuggerVar = IsDebuggerVar;
47644769
}
4770+
4771+
/// Is this a special debugger REPL variable?
4772+
/// FIXME: Remove this once LLDB has proper support for resilience.
4773+
bool isREPLVar() const { return Bits.VarDecl.IsREPLVar; }
4774+
void setREPLVar(bool IsREPLVar) {
4775+
Bits.VarDecl.IsREPLVar = IsREPLVar;
4776+
}
47654777

47664778
/// Return the Objective-C runtime name for this property.
47674779
Identifier getObjCPropertyName() const;

lib/IRGen/GenDecl.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2123,6 +2123,12 @@ Address IRGenModule::getAddrOfSILGlobalVariable(SILGlobalVariable *var,
21232123
bool inFixedBuffer = false;
21242124
bool indirectForDebugInfo = false;
21252125

2126+
// FIXME: Remove this once LLDB has proper support for resilience.
2127+
bool isREPLVar = false;
2128+
if (auto *decl = var->getDecl())
2129+
if (decl->isREPLVar())
2130+
isREPLVar = true;
2131+
21262132
if (var->isInitializedObject()) {
21272133
assert(ti.isFixedSize(expansion));
21282134
StructLayout *Layout = StaticObjectLayouts[var].get();
@@ -2142,7 +2148,7 @@ Address IRGenModule::getAddrOfSILGlobalVariable(SILGlobalVariable *var,
21422148
fixedSize = Layout->getSize();
21432149
fixedAlignment = Layout->getAlignment();
21442150
assert(fixedAlignment >= TargetInfo.HeapObjectAlignment);
2145-
} else if (ti.isFixedSize(expansion)) {
2151+
} else if (isREPLVar || ti.isFixedSize(expansion)) {
21462152
// Allocate static storage.
21472153
auto &fixedTI = cast<FixedTypeInfo>(ti);
21482154
storageType = fixedTI.getStorageType();

lib/IRGen/IRGenSIL.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,9 +1857,15 @@ void IRGenSILFunction::visitAllocGlobalInst(AllocGlobalInst *i) {
18571857

18581858
auto expansion = IGM.getResilienceExpansionForLayout(var);
18591859

1860+
// FIXME: Remove this once LLDB has proper support for resilience.
1861+
bool isREPLVar = false;
1862+
if (auto *decl = var->getDecl())
1863+
if (decl->isREPLVar())
1864+
isREPLVar = true;
1865+
18601866
// If the global is fixed-size in all resilience domains that can see it,
18611867
// we allocated storage for it statically, and there's nothing to do.
1862-
if (ti.isFixedSize(expansion))
1868+
if (isREPLVar || ti.isFixedSize(expansion))
18631869
return;
18641870

18651871
// Otherwise, the static storage for the global consists of a fixed-size
@@ -1887,9 +1893,15 @@ void IRGenSILFunction::visitGlobalAddrInst(GlobalAddrInst *i) {
18871893
Address addr = IGM.getAddrOfSILGlobalVariable(var, ti,
18881894
NotForDefinition);
18891895

1896+
// FIXME: Remove this once LLDB has proper support for resilience.
1897+
bool isREPLVar = false;
1898+
if (auto *decl = var->getDecl())
1899+
if (decl->isREPLVar())
1900+
isREPLVar = true;
1901+
18901902
// If the global is fixed-size in all resilience domains that can see it,
18911903
// we allocated storage for it statically, and there's nothing to do.
1892-
if (ti.isFixedSize(expansion)) {
1904+
if (isREPLVar || ti.isFixedSize(expansion)) {
18931905
setLoweredAddress(i, addr);
18941906
return;
18951907
}

0 commit comments

Comments
 (0)