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