Skip to content

Commit 61d7c1a

Browse files
author
git apple-llvm automerger
committed
Merge commit 'a96b21200f3b' from swift/release/6.2 into stable/20240723
2 parents ed7f6af + a96b212 commit 61d7c1a

File tree

6 files changed

+71
-54
lines changed

6 files changed

+71
-54
lines changed

lldb/include/lldb/Symbol/SymbolFile.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,15 @@ class SymbolFile : public PluginInterface {
387387
/// for this module have been changed.
388388
virtual void SectionFileAddressesChanged() = 0;
389389

390+
/// Looks for the compile option specified by \p option, and sets \p value to
391+
/// it's value. For example, for a flag such as -foo=bar, looking up \p option
392+
/// "-foo" will set \p value to "bar". For a standalone flag such as -baz, \p
393+
/// value will be empty.
394+
///
395+
/// If \p cu is set, only that compile unit is searched. Otherwise, every
396+
/// compile unit is searched until the option is found or failure.
397+
///
398+
/// Returns true if the option is found.
390399
virtual bool GetCompileOption(const char *option, std::string &value,
391400
CompileUnit *cu = nullptr) {
392401
value.clear();

lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,12 @@ class LLDBExprNameLookup : public LLDBNameLookup {
358358
swift::Identifier getPreferredPrivateDiscriminator() override {
359359
if (m_sc.comp_unit) {
360360
if (lldb_private::Module *module = m_sc.module_sp.get()) {
361-
if (lldb_private::SymbolFile *symbol_file =
362-
module->GetSymbolFile()) {
361+
if (lldb_private::SymbolFile *symbol_file = module->GetSymbolFile()) {
363362
std::string private_discriminator_string;
364363
if (symbol_file->GetCompileOption("-private-discriminator",
365-
private_discriminator_string,
366-
m_sc.comp_unit)) {
364+
private_discriminator_string,
365+
m_sc.comp_unit) &&
366+
!private_discriminator_string.empty()) {
367367
return m_source_file.getASTContext().getIdentifier(
368368
private_discriminator_string);
369369
}

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3253,6 +3253,36 @@ SymbolFileDWARF::FindDefinitionDIE(const DWARFDIE &die) {
32533253
return result;
32543254
}
32553255

3256+
namespace {
3257+
const char *GetFlags(const char *option, DWARFUnit *dwarf_cu) {
3258+
if (!dwarf_cu)
3259+
return nullptr;
3260+
3261+
const DWARFBaseDIE die = dwarf_cu->GetUnitDIEOnly();
3262+
if (!die)
3263+
return nullptr;
3264+
3265+
const char *flags = die.GetAttributeValueAsString(DW_AT_APPLE_flags, NULL);
3266+
if (!flags)
3267+
return nullptr;
3268+
3269+
if (strstr(flags, option))
3270+
return flags;
3271+
3272+
return nullptr;
3273+
}
3274+
bool FindOptionInDWARFCU(const char *option, DWARFUnit *dwarf_cu,
3275+
std::string &value) {
3276+
const char *flags = GetFlags(option, dwarf_cu);
3277+
if (!flags)
3278+
return false;
3279+
3280+
Args compiler_args(flags);
3281+
OptionParsing::GetOptionValueAsString(compiler_args, option, value);
3282+
return true;
3283+
}
3284+
} // namespace
3285+
32563286
bool SymbolFileDWARF::GetCompileOption(const char *option, std::string &value,
32573287
CompileUnit *cu) {
32583288
value.clear();
@@ -3262,52 +3292,19 @@ bool SymbolFileDWARF::GetCompileOption(const char *option, std::string &value,
32623292
const uint32_t num_compile_units = GetNumCompileUnits();
32633293

32643294
if (cu) {
3265-
auto *dwarf_cu =
3266-
llvm::dyn_cast_or_null<DWARFCompileUnit>(GetDWARFCompileUnit(cu));
3267-
3268-
if (dwarf_cu) {
3295+
if (auto *dwarf_cu =
3296+
llvm::dyn_cast_or_null<DWARFCompileUnit>(GetDWARFCompileUnit(cu))) {
32693297
// GetDWARFCompileUnit() only looks up by CU#. Make sure that
32703298
// this is actually the correct SymbolFile by converting it
32713299
// back to a CompileUnit.
32723300
if (GetCompUnitForDWARFCompUnit(*dwarf_cu) != cu)
32733301
return false;
3274-
3275-
const DWARFBaseDIE die = dwarf_cu->GetUnitDIEOnly();
3276-
if (die) {
3277-
const char *flags =
3278-
die.GetAttributeValueAsString(DW_AT_APPLE_flags, NULL);
3279-
3280-
if (flags) {
3281-
if (strstr(flags, option)) {
3282-
Args compiler_args(flags);
3283-
3284-
return OptionParsing::GetOptionValueAsString(compiler_args,
3285-
option, value);
3286-
}
3287-
}
3288-
}
3302+
return FindOptionInDWARFCU(option, dwarf_cu, value);
32893303
}
32903304
} else {
3291-
for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) {
3292-
DWARFUnit *dwarf_cu = debug_info.GetUnitAtIndex(cu_idx);
3293-
3294-
if (dwarf_cu) {
3295-
const DWARFBaseDIE die = dwarf_cu->GetUnitDIEOnly();
3296-
if (die) {
3297-
const char *flags =
3298-
die.GetAttributeValueAsString(DW_AT_APPLE_flags, NULL);
3299-
3300-
if (flags) {
3301-
if (strstr(flags, option)) {
3302-
Args compiler_args(flags);
3303-
3304-
return OptionParsing::GetOptionValueAsString(compiler_args,
3305-
option, value);
3306-
}
3307-
}
3308-
}
3309-
}
3310-
}
3305+
for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
3306+
if (DWARFUnit *dwarf_cu = debug_info.GetUnitAtIndex(cu_idx))
3307+
return FindOptionInDWARFCU(option, dwarf_cu, value);
33113308
}
33123309

33133310
return false;

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h"
1717
#include "lldb/Core/PluginManager.h"
1818
#include "lldb/Symbol/CompileUnit.h"
19+
#include "lldb/Utility/LLDBLog.h"
1920
#include <lldb/lldb-enumerations.h>
2021
#include <llvm/ADT/StringRef.h>
2122

@@ -74,7 +75,7 @@ void TypeSystemSwift::Terminate() {
7475

7576
bool TypeSystemSwift::CheckFlagInCU(CompileUnit *cu, const char *flag) {
7677
AutoBool interop_enabled =
77-
ModuleList::GetGlobalModuleListProperties().GetSwiftEnableCxxInterop();
78+
ModuleList::GetGlobalModuleListProperties().GetSwiftEnableCxxInterop();
7879
switch (interop_enabled) {
7980
case AutoBool::True:
8081
return true;
@@ -89,18 +90,18 @@ bool TypeSystemSwift::CheckFlagInCU(CompileUnit *cu, const char *flag) {
8990
auto *sym_file = module->GetSymbolFile();
9091
if (!sym_file)
9192
return false;
92-
auto options = sym_file->GetCompileOptions();
93-
for (auto &[unit, args] : options) {
94-
if (unit.get() == cu) {
95-
if (cu->GetLanguage() == eLanguageTypeSwift)
96-
for (const char *arg : args.GetArgumentArrayRef())
97-
if (strcmp(arg, flag) == 0)
98-
return true;
99-
return false;
100-
}
93+
std::string value;
94+
if (sym_file->GetCompileOption(flag, value, cu)) {
95+
LLDB_LOGV(GetLog(LLDBLog::Types),
96+
"[CheckFlagInCU] Found flag {0} in CU: {1}", flag,
97+
cu->GetPrimaryFile().GetFilename().AsCString());
98+
return true;
10199
}
102100
}
103101
}
102+
LLDB_LOGV(GetLog(LLDBLog::Types),
103+
"[CheckFlagInCU] Did not find flag {0} in CU: {1}", flag,
104+
cu->GetPrimaryFile().GetFilename().AsCString());
104105
return false;
105106
}
106107

lldb/test/API/lang/swift/cxx_interop/forward/expressions/TestSwiftForwardInteropExpressions.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ def setup(self, bkpt_str):
1515
self, bkpt_str, lldb.SBFileSpec('main.swift'))
1616
return thread
1717

18-
@skipIf(bugnumber='rdar://152745034')
1918
@skipIfLinux # rdar://106871422"
2019
@skipIf(setting=('symbols.use-swift-clangimporter', 'false')) # rdar://106871275
2120
@swiftTest
2221
def test(self):
2322
self.setup('Break here')
2423

24+
types_log = self.getBuildArtifact('types.log')
25+
self.expect("log enable lldb types -v -f "+ types_log)
2526
# Check that we can call free functions.
2627
self.expect('expr returnsInt()', substrs=['Int32', '42'])
2728

@@ -54,6 +55,9 @@ def test(self):
5455
# Check that po prints the fields of a base class
5556
self.expect('po cxxClass', substrs=['CxxClass', 'a : 100', 'b : 101'])
5657

58+
self.filecheck('platform shell cat "%s"' % types_log, __file__)
59+
# CHECK: [CheckFlagInCU] Found flag -enable-experimental-cxx-interop in CU:
60+
5761
@expectedFailureAll(bugnumber="rdar://106216567")
5862
@swiftTest
5963
def test_po_subclass(self):

lldb/test/API/lang/swift/embedded/expr/TestSwiftEmbeddedExpression.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,10 @@ def test(self):
1414
self, "break here", lldb.SBFileSpec("main.swift")
1515
)
1616

17+
types_log = self.getBuildArtifact('types.log')
18+
self.expect("log enable lldb types -v -f "+ types_log)
19+
1720
self.expect("expr a.foo()", substrs=["(Int)", " = 16"])
21+
22+
self.filecheck('platform shell cat "%s"' % types_log, __file__)
23+
# CHECK: [CheckFlagInCU] Found flag -enable-embedded-swift in CU:

0 commit comments

Comments
 (0)