@@ -68,7 +68,7 @@ void SwiftLanguage::Initialize() {
68
68
static ConstString g_SwiftStringStorageClass (" _TtCs15__StringStorage" );
69
69
static ConstString g_NSArrayClass1 (" _TtCs22__SwiftDeferredNSArray" );
70
70
PluginManager::RegisterPlugin (GetPluginNameStatic (), " Swift Language" ,
71
- CreateInstance);
71
+ CreateInstance, &DebuggerInitialize );
72
72
73
73
lldb_private::formatters::NSString_Additionals::GetAdditionalSummaries ()
74
74
.emplace(
@@ -1894,6 +1894,144 @@ SwiftLanguage::GetDemangledFunctionNameWithoutArguments(Mangled mangled) const {
1894
1894
return mangled_name;
1895
1895
}
1896
1896
1897
+ static std::optional<llvm::StringRef>
1898
+ GetDemangledBasename (const SymbolContext &sc) {
1899
+ return std::nullopt;
1900
+ }
1901
+
1902
+ static std::optional<llvm::StringRef>
1903
+ GetDemangledFunctionPrefix (const SymbolContext &sc) {
1904
+ return std::nullopt;
1905
+ }
1906
+
1907
+ static std::optional<llvm::StringRef>
1908
+ GetDemangledFunctionSuffix (const SymbolContext &sc) {
1909
+ return std::nullopt;
1910
+ }
1911
+
1912
+ static bool PrintDemangledArgumentList (Stream &s, const SymbolContext &sc) {
1913
+ return false ;
1914
+ }
1915
+
1916
+ static VariableListSP GetFunctionVariableList (const SymbolContext &sc) {
1917
+ assert (sc.function );
1918
+
1919
+ if (sc.block )
1920
+ if (Block *inline_block = sc.block ->GetContainingInlinedBlock ())
1921
+ return inline_block->GetBlockVariableList (true );
1922
+
1923
+ return sc.function ->GetBlock (true ).GetBlockVariableList (true );
1924
+ }
1925
+
1926
+ bool SwiftLanguage::HandleFrameFormatVariable (const SymbolContext &sc,
1927
+ const ExecutionContext *exe_ctx,
1928
+ FormatEntity::Entry::Type type,
1929
+ Stream &s) {
1930
+ switch (type) {
1931
+ case FormatEntity::Entry::Type::FunctionBasename: {
1932
+ std::optional<llvm::StringRef> name = GetDemangledBasename (sc);
1933
+ if (!name)
1934
+ return false ;
1935
+
1936
+ s << *name;
1937
+
1938
+ return true ;
1939
+ }
1940
+ case FormatEntity::Entry::Type::FunctionFormattedArguments: {
1941
+ // This ensures we print the arguments even when no debug-info is available.
1942
+ //
1943
+ // FIXME: we should have a Entry::Type::FunctionArguments and
1944
+ // use it in the plugin.cplusplus.display.function-name-format
1945
+ // once we have a "fallback operator" in the frame-format language.
1946
+ if (!sc.function && sc.symbol )
1947
+ return PrintDemangledArgumentList (s, sc);
1948
+ std::string display_name = SwiftLanguageRuntime::DemangleSymbolAsString (
1949
+ sc.function ->GetMangled ().GetMangledName ().GetStringRef (),
1950
+ SwiftLanguageRuntime::eSimplified, &sc, exe_ctx);
1951
+ if (display_name.empty ())
1952
+ return false ;
1953
+
1954
+ VariableList args;
1955
+ if (auto variable_list_sp = GetFunctionVariableList (sc))
1956
+ variable_list_sp->AppendVariablesWithScope (eValueTypeVariableArgument,
1957
+ args);
1958
+
1959
+ s << GetFunctionDisplayArgs (sc, args, exe_ctx);
1960
+ return true ;
1961
+ }
1962
+ case FormatEntity::Entry::Type::FunctionPrefix: {
1963
+ std::optional<llvm::StringRef> prefix = GetDemangledFunctionPrefix (sc);
1964
+ if (!prefix)
1965
+ return false ;
1966
+
1967
+ s << *prefix;
1968
+
1969
+ return true ;
1970
+ }
1971
+ case FormatEntity::Entry::Type::FunctionSuffix: {
1972
+ std::optional<llvm::StringRef> suffix = GetDemangledFunctionSuffix (sc);
1973
+ if (!suffix)
1974
+ return false ;
1975
+
1976
+ s << *suffix;
1977
+
1978
+ return true ;
1979
+ }
1980
+
1981
+ case FormatEntity::Entry::Type::FunctionScope:
1982
+ case FormatEntity::Entry::Type::FunctionTemplateArguments:
1983
+ case FormatEntity::Entry::Type::FunctionReturnRight:
1984
+ case FormatEntity::Entry::Type::FunctionReturnLeft:
1985
+ case FormatEntity::Entry::Type::FunctionQualifiers:
1986
+ default :
1987
+ return true ;
1988
+ }
1989
+ }
1990
+
1991
+ #define LLDB_PROPERTIES_language_swift
1992
+ #include " LanguageSwiftProperties.inc"
1993
+
1994
+ enum {
1995
+ #define LLDB_PROPERTIES_language_swift
1996
+ #include " LanguageSwiftPropertiesEnum.inc"
1997
+ };
1998
+
1999
+ namespace {
2000
+ class PluginProperties : public Properties {
2001
+ public:
2002
+ static llvm::StringRef GetSettingName () { return " display" ; }
2003
+
2004
+ PluginProperties () {
2005
+ m_collection_sp = std::make_shared<OptionValueProperties>(GetSettingName ());
2006
+ m_collection_sp->Initialize (g_language_swift_properties);
2007
+ }
2008
+
2009
+ FormatEntity::Entry GetFunctionNameFormat () const {
2010
+ return GetPropertyAtIndexAs<const FormatEntity::Entry>(
2011
+ ePropertyFunctionNameFormat, {});
2012
+ }
2013
+ };
2014
+ } // namespace
2015
+
2016
+ static PluginProperties &GetGlobalPluginProperties () {
2017
+ static PluginProperties g_settings;
2018
+ return g_settings;
2019
+ }
2020
+
2021
+ FormatEntity::Entry SwiftLanguage::GetFunctionNameFormat () const {
2022
+ return GetGlobalPluginProperties ().GetFunctionNameFormat ();
2023
+ }
2024
+
2025
+ void SwiftLanguage::DebuggerInitialize (Debugger &debugger) {
2026
+ if (!PluginManager::GetSettingForSwiftLanguagePlugin (
2027
+ debugger, PluginProperties::GetSettingName ())) {
2028
+ PluginManager::CreateSettingForSwiftLanguagePlugin (
2029
+ debugger, GetGlobalPluginProperties ().GetValueProperties (),
2030
+ " Properties for the Swift language plug-in." ,
2031
+ /* is_global_property=*/ true );
2032
+ }
2033
+ }
2034
+
1897
2035
namespace {
1898
2036
using namespace swift ::Demangle;
1899
2037
struct AsyncInfo {
0 commit comments