@@ -1718,13 +1718,7 @@ bool SwiftLanguage::GetFunctionDisplayName(
1718
1718
// No need to customize this.
1719
1719
return false ;
1720
1720
case Language::FunctionNameRepresentation::eNameWithNoArgs: {
1721
- if (!sc.function )
1722
- return false ;
1723
- if (sc.function ->GetLanguage () != eLanguageTypeSwift)
1724
- return false ;
1725
- std::string display_name = SwiftLanguageRuntime::DemangleSymbolAsString (
1726
- sc.function ->GetMangled ().GetMangledName ().GetStringRef (),
1727
- SwiftLanguageRuntime::eSimplified, &sc, exe_ctx);
1721
+ std::string display_name = GetDemangledFunctionName (sc, exe_ctx);
1728
1722
if (display_name.empty ())
1729
1723
return false ;
1730
1724
s << display_name;
@@ -1759,69 +1753,82 @@ bool SwiftLanguage::GetFunctionDisplayName(
1759
1753
variable_list_sp->AppendVariablesWithScope (eValueTypeVariableArgument,
1760
1754
args);
1761
1755
1756
+ s << GetFunctionTemplateArguments (sc, exe_ctx);
1762
1757
s << GetFunctionDisplayArgs (sc, args, exe_ctx);
1763
1758
return true ;
1764
1759
}
1765
1760
}
1766
1761
return false ;
1767
1762
}
1768
1763
1769
- std::string SwiftLanguage::GetFunctionName (const SymbolContext &sc,
1770
- const ExecutionContext *exe_ctx) {
1764
+ std::string
1765
+ SwiftLanguage::GetDemangledFunctionName (const SymbolContext &sc,
1766
+ const ExecutionContext *exe_ctx) {
1771
1767
if (!sc.function )
1772
1768
return {};
1773
1769
if (sc.function ->GetLanguage () != eLanguageTypeSwift)
1774
1770
return {};
1775
- std::string name = SwiftLanguageRuntime::DemangleSymbolAsString (
1771
+ return SwiftLanguageRuntime::DemangleSymbolAsString (
1776
1772
sc.GetPossiblyInlinedFunctionName ().GetMangledName (),
1777
1773
SwiftLanguageRuntime::eSimplified, &sc, exe_ctx);
1778
- if (name.empty ())
1774
+ }
1775
+
1776
+ std::string SwiftLanguage::GetFunctionName (const SymbolContext &sc,
1777
+ const ExecutionContext *exe_ctx) {
1778
+ std::string demangled_name = GetDemangledFunctionName (sc, exe_ctx);
1779
+ if (demangled_name.empty ())
1779
1780
return {};
1780
- size_t open_paren = name .find (' (' );
1781
- size_t generic = name .find (' <' );
1781
+ size_t open_paren = demangled_name .find (' (' );
1782
+ size_t generic = demangled_name .find (' <' );
1782
1783
size_t name_end = std::min (open_paren, generic);
1783
1784
if (name_end == std::string::npos)
1784
- return name;
1785
- return name.substr (0 , name_end);
1785
+ return demangled_name;
1786
+ return demangled_name.substr (0 , name_end);
1787
+ }
1788
+
1789
+ std::string
1790
+ SwiftLanguage::GetFunctionTemplateArguments (const SymbolContext &sc,
1791
+ const ExecutionContext *exe_ctx) {
1792
+ std::string demangled_name = GetDemangledFunctionName (sc, exe_ctx);
1793
+ if (demangled_name.empty ())
1794
+ return {};
1795
+ size_t open_paren = demangled_name.find (' (' );
1796
+ size_t generic_start = demangled_name.find (' <' );
1797
+ if (generic_start == std::string::npos || generic_start > open_paren)
1798
+ return {};
1799
+
1800
+ int generic_depth = 1 ;
1801
+ size_t generic_end = generic_start + 1 ;
1802
+
1803
+ while (generic_end < demangled_name.size () && generic_depth > 0 ) {
1804
+ if (demangled_name[generic_end] == ' <' ) {
1805
+ generic_depth++;
1806
+ } else if (demangled_name[generic_end] == ' >' ) {
1807
+ generic_depth--;
1808
+ }
1809
+ generic_end++;
1810
+ }
1811
+
1812
+ if (generic_depth != 0 )
1813
+ return {};
1814
+
1815
+ return demangled_name.substr (generic_start, generic_end - generic_start);
1786
1816
}
1787
1817
1788
1818
std::string SwiftLanguage::GetFunctionDisplayArgs (
1789
1819
const SymbolContext &sc, VariableList &args,
1790
1820
const lldb_private::ExecutionContext *exe_ctx) {
1791
1821
ExecutionContextScope *exe_scope =
1792
1822
exe_ctx ? exe_ctx->GetBestExecutionContextScope () : NULL ;
1793
- std::string name = SwiftLanguageRuntime::DemangleSymbolAsString (
1794
- sc.function ->GetMangled ().GetMangledName ().GetStringRef (),
1795
- SwiftLanguageRuntime::eSimplified, &sc, exe_ctx);
1823
+ std::string name = GetDemangledFunctionName (sc, exe_ctx);
1796
1824
lldb_private::StreamString s;
1797
1825
const char *cstr = name.data ();
1798
1826
const char *open_paren = strchr (cstr, ' (' );
1799
1827
const char *close_paren = nullptr ;
1800
- const char *generic = strchr (cstr, ' <' );
1801
- // If before the arguments list begins there is a template sign
1802
- // then scan to the end of the generic args before you try to find
1803
- // the arguments list.
1804
- const char *generic_start = generic;
1805
- if (generic && open_paren && generic < open_paren) {
1806
- int generic_depth = 1 ;
1807
- ++generic;
1808
- for (; *generic && generic_depth > 0 ; generic++) {
1809
- if (*generic == ' <' )
1810
- generic_depth++;
1811
- if (*generic == ' >' )
1812
- generic_depth--;
1813
- }
1814
- if (*generic)
1815
- open_paren = strchr (generic, ' (' );
1816
- else
1817
- open_paren = nullptr ;
1818
- }
1819
1828
if (open_paren) {
1820
1829
close_paren = strchr (open_paren, ' )' );
1821
1830
}
1822
1831
1823
- if (generic_start && generic_start < open_paren)
1824
- s.Write (generic_start, open_paren - generic_start);
1825
1832
s.PutChar (' (' );
1826
1833
1827
1834
const size_t num_args = args.GetSize ();
@@ -1945,6 +1952,23 @@ GetDemangledBasename(const SymbolContext &sc) {
1945
1952
info.BasenameRange .second );
1946
1953
}
1947
1954
1955
+ static llvm::Expected<llvm::StringRef>
1956
+ GetDemangledNameQualifiers (const SymbolContext &sc) {
1957
+ auto info_or_err = GetAndValidateInfo (sc);
1958
+ if (!info_or_err)
1959
+ return info_or_err.takeError ();
1960
+
1961
+ auto [demangled_name, info] = *info_or_err;
1962
+
1963
+ if (!info.hasPrefix ())
1964
+ return llvm::createStringError (
1965
+ " DemangledInfo for '%s does not have a name qualifiers range." ,
1966
+ demangled_name.data ());
1967
+
1968
+ return demangled_name.slice (info.NameQualifiersRange .first ,
1969
+ info.NameQualifiersRange .second );
1970
+ }
1971
+
1948
1972
static llvm::Expected<llvm::StringRef>
1949
1973
GetDemangledFunctionPrefix (const SymbolContext &sc) {
1950
1974
auto info_or_err = GetAndValidateInfo (sc);
@@ -1955,7 +1979,7 @@ GetDemangledFunctionPrefix(const SymbolContext &sc) {
1955
1979
1956
1980
if (!info.hasPrefix ())
1957
1981
return llvm::createStringError (
1958
- " DemangledInfo for '%s does not have suffix range." ,
1982
+ " DemangledInfo for '%s does not have a prefix range." ,
1959
1983
demangled_name.data ());
1960
1984
1961
1985
return demangled_name.slice (info.PrefixRange .first , info.PrefixRange .second );
@@ -1971,7 +1995,7 @@ GetDemangledFunctionSuffix(const SymbolContext &sc) {
1971
1995
1972
1996
if (!info.hasSuffix ())
1973
1997
return llvm::createStringError (
1974
- " DemangledInfo for '%s does not have suffix range." ,
1998
+ " DemangledInfo for '%s does not have a suffix range." ,
1975
1999
demangled_name.data ());
1976
2000
1977
2001
return demangled_name.slice (info.SuffixRange .first , info.SuffixRange .second );
@@ -2026,6 +2050,24 @@ bool SwiftLanguage::HandleFrameFormatVariable(const SymbolContext &sc,
2026
2050
2027
2051
return true ;
2028
2052
}
2053
+ case FormatEntity::Entry::Type::FunctionNameQualifiers: {
2054
+ auto qualifiers_or_err = GetDemangledNameQualifiers (sc);
2055
+ if (!qualifiers_or_err) {
2056
+ LLDB_LOG_ERROR (GetLog (LLDBLog::Language), qualifiers_or_err.takeError (),
2057
+ " Failed to handle ${{function.name-qualifiers}} "
2058
+ " frame-format variable: {0}" );
2059
+ return false ;
2060
+ }
2061
+
2062
+ s << *qualifiers_or_err;
2063
+
2064
+ return true ;
2065
+ }
2066
+ case FormatEntity::Entry::Type::FunctionTemplateArguments: {
2067
+ s << GetFunctionTemplateArguments (sc, exe_ctx);
2068
+
2069
+ return true ;
2070
+ }
2029
2071
case FormatEntity::Entry::Type::FunctionFormattedArguments: {
2030
2072
// This ensures we print the arguments even when no debug-info is available.
2031
2073
//
@@ -2034,9 +2076,7 @@ bool SwiftLanguage::HandleFrameFormatVariable(const SymbolContext &sc,
2034
2076
// once we have a "fallback operator" in the frame-format language.
2035
2077
if (!sc.function && sc.symbol )
2036
2078
return PrintDemangledArgumentList (s, sc);
2037
- std::string display_name = SwiftLanguageRuntime::DemangleSymbolAsString (
2038
- sc.function ->GetMangled ().GetMangledName ().GetStringRef (),
2039
- SwiftLanguageRuntime::eSimplified, &sc, exe_ctx);
2079
+ std::string display_name = GetDemangledFunctionName (sc, exe_ctx);
2040
2080
if (display_name.empty ())
2041
2081
return false ;
2042
2082
@@ -2076,7 +2116,6 @@ bool SwiftLanguage::HandleFrameFormatVariable(const SymbolContext &sc,
2076
2116
}
2077
2117
2078
2118
case FormatEntity::Entry::Type::FunctionScope:
2079
- case FormatEntity::Entry::Type::FunctionTemplateArguments:
2080
2119
case FormatEntity::Entry::Type::FunctionReturnRight:
2081
2120
case FormatEntity::Entry::Type::FunctionReturnLeft:
2082
2121
case FormatEntity::Entry::Type::FunctionQualifiers:
0 commit comments