@@ -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,82 @@ 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
+ }
1813
+ generic_end++;
1814
+ }
1815
+
1816
+ if (generic_depth != 0 )
1817
+ return {};
1818
+
1819
+ return demangled_name.substr (generic_start, generic_end - generic_start);
1790
1820
}
1791
1821
1792
1822
std::string SwiftLanguage::GetFunctionDisplayArgs (
1793
1823
const SymbolContext &sc, VariableList &args,
1794
1824
const lldb_private::ExecutionContext *exe_ctx) {
1795
1825
ExecutionContextScope *exe_scope =
1796
1826
exe_ctx ? exe_ctx->GetBestExecutionContextScope () : NULL ;
1797
- std::string name = SwiftLanguageRuntime::DemangleSymbolAsString (
1798
- sc.function ->GetMangled ().GetMangledName ().GetStringRef (),
1799
- SwiftLanguageRuntime::eSimplified, &sc, exe_ctx);
1827
+ std::string name = GetDemangledFunctionName (sc, exe_ctx);
1800
1828
lldb_private::StreamString s;
1801
1829
const char *cstr = name.data ();
1802
1830
const char *open_paren = strchr (cstr, ' (' );
1803
1831
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
1832
if (open_paren) {
1824
1833
close_paren = strchr (open_paren, ' )' );
1825
1834
}
1826
1835
1827
- if (generic_start && generic_start < open_paren)
1828
- s.Write (generic_start, open_paren - generic_start);
1829
1836
s.PutChar (' (' );
1830
1837
1831
1838
const size_t num_args = args.GetSize ();
@@ -1949,6 +1956,23 @@ GetDemangledBasename(const SymbolContext &sc) {
1949
1956
info.BasenameRange .second );
1950
1957
}
1951
1958
1959
+ static llvm::Expected<llvm::StringRef>
1960
+ GetDemangledNameQualifiers (const SymbolContext &sc) {
1961
+ auto info_or_err = GetAndValidateInfo (sc);
1962
+ if (!info_or_err)
1963
+ return info_or_err.takeError ();
1964
+
1965
+ auto [demangled_name, info] = *info_or_err;
1966
+
1967
+ if (!info.hasPrefix ())
1968
+ return llvm::createStringError (
1969
+ " DemangledInfo for '%s does not have a name qualifiers range." ,
1970
+ demangled_name.data ());
1971
+
1972
+ return demangled_name.slice (info.NameQualifiersRange .first ,
1973
+ info.NameQualifiersRange .second );
1974
+ }
1975
+
1952
1976
static llvm::Expected<llvm::StringRef>
1953
1977
GetDemangledFunctionPrefix (const SymbolContext &sc) {
1954
1978
auto info_or_err = GetAndValidateInfo (sc);
@@ -1959,7 +1983,7 @@ GetDemangledFunctionPrefix(const SymbolContext &sc) {
1959
1983
1960
1984
if (!info.hasPrefix ())
1961
1985
return llvm::createStringError (
1962
- " DemangledInfo for '%s does not have suffix range." ,
1986
+ " DemangledInfo for '%s does not have a prefix range." ,
1963
1987
demangled_name.data ());
1964
1988
1965
1989
return demangled_name.slice (info.PrefixRange .first , info.PrefixRange .second );
@@ -1975,7 +1999,7 @@ GetDemangledFunctionSuffix(const SymbolContext &sc) {
1975
1999
1976
2000
if (!info.hasSuffix ())
1977
2001
return llvm::createStringError (
1978
- " DemangledInfo for '%s does not have suffix range." ,
2002
+ " DemangledInfo for '%s does not have a suffix range." ,
1979
2003
demangled_name.data ());
1980
2004
1981
2005
return demangled_name.slice (info.SuffixRange .first , info.SuffixRange .second );
@@ -2030,6 +2054,24 @@ bool SwiftLanguage::HandleFrameFormatVariable(const SymbolContext &sc,
2030
2054
2031
2055
return true ;
2032
2056
}
2057
+ case FormatEntity::Entry::Type::FunctionNameQualifiers: {
2058
+ auto qualifiers_or_err = GetDemangledNameQualifiers (sc);
2059
+ if (!qualifiers_or_err) {
2060
+ LLDB_LOG_ERROR (GetLog (LLDBLog::Language), qualifiers_or_err.takeError (),
2061
+ " Failed to handle ${{function.name-qualifiers}} "
2062
+ " frame-format variable: {0}" );
2063
+ return false ;
2064
+ }
2065
+
2066
+ s << *qualifiers_or_err;
2067
+
2068
+ return true ;
2069
+ }
2070
+ case FormatEntity::Entry::Type::FunctionTemplateArguments: {
2071
+ s << GetFunctionTemplateArguments (sc, exe_ctx);
2072
+
2073
+ return true ;
2074
+ }
2033
2075
case FormatEntity::Entry::Type::FunctionFormattedArguments: {
2034
2076
// This ensures we print the arguments even when no debug-info is available.
2035
2077
//
@@ -2038,9 +2080,7 @@ bool SwiftLanguage::HandleFrameFormatVariable(const SymbolContext &sc,
2038
2080
// once we have a "fallback operator" in the frame-format language.
2039
2081
if (!sc.function && sc.symbol )
2040
2082
return PrintDemangledArgumentList (s, sc);
2041
- std::string display_name = SwiftLanguageRuntime::DemangleSymbolAsString (
2042
- sc.function ->GetMangled ().GetMangledName ().GetStringRef (),
2043
- SwiftLanguageRuntime::eSimplified, &sc, exe_ctx);
2083
+ std::string display_name = GetDemangledFunctionName (sc, exe_ctx);
2044
2084
if (display_name.empty ())
2045
2085
return false ;
2046
2086
@@ -2080,7 +2120,6 @@ bool SwiftLanguage::HandleFrameFormatVariable(const SymbolContext &sc,
2080
2120
}
2081
2121
2082
2122
case FormatEntity::Entry::Type::FunctionScope:
2083
- case FormatEntity::Entry::Type::FunctionTemplateArguments:
2084
2123
case FormatEntity::Entry::Type::FunctionReturnRight:
2085
2124
case FormatEntity::Entry::Type::FunctionReturnLeft:
2086
2125
case FormatEntity::Entry::Type::FunctionQualifiers:
0 commit comments