Skip to content

Commit 715517d

Browse files
Merge pull request #8703 from adrian-prantl/65956239
Display generic function type parameters in backtraces.
2 parents bb2ca20 + d0fbe03 commit 715517d

File tree

11 files changed

+244
-227
lines changed

11 files changed

+244
-227
lines changed

lldb/include/lldb/Symbol/Function.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ class Function : public UserID, public SymbolContextScope {
537537

538538
ConstString GetNameNoArguments(const SymbolContext *sc = nullptr) const;
539539

540-
ConstString GetDisplayName(const SymbolContext *sc = nullptr) const;
540+
ConstString GetDisplayName() const;
541541

542542
const Mangled &GetMangled() const { return m_mangled; }
543543

lldb/source/Core/Mangled.cpp

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,6 @@ static inline bool cstring_is_mangled(llvm::StringRef s) {
4545
return Mangled::GetManglingScheme(s) != Mangled::eManglingSchemeNone;
4646
}
4747

48-
#ifdef LLDB_ENABLE_SWIFT
49-
#pragma mark DisplayDemangledNamesCache
50-
51-
// make the key type be a const char* because that gives us usable
52-
// DenseMapInfo for free making DenseMap work for ConstString requires
53-
// us to provide two "invalid" values: the empty key and the tombstone
54-
// key; but for ConstString, we really don't have any well-known
55-
// invalid value other than ConstString(nullptr) so, just use const
56-
// char* as the key as LLVM knows how to do proper DenseMapInfo for
57-
// pointers
58-
static ThreadSafeDenseMap<const char *, ConstString>&
59-
GetDisplayDemangledNamesCache() {
60-
static ThreadSafeDenseMap<const char *, ConstString> g_cache;
61-
return g_cache;
62-
}
63-
#endif // LLDB_ENABLE_SWIFT
64-
6548
#pragma mark Mangled
6649

6750
Mangled::ManglingScheme Mangled::GetManglingScheme(llvm::StringRef const name) {
@@ -346,39 +329,15 @@ ConstString Mangled::GetDemangledName(// BEGIN SWIFT
346329

347330
ConstString Mangled::GetDisplayDemangledName(
348331
// BEGIN SWIFT
349-
const SymbolContext *sc
350-
) const {
351-
ConstString demangled;
332+
const SymbolContext *sc) const {
352333
#ifdef LLDB_ENABLE_SWIFT
353-
if (m_mangled) {
354-
do {
355-
const char *mangled = m_mangled.GetCString();
356-
357-
if (mangled) {
358-
if (SwiftLanguageRuntime::IsSwiftMangledName(m_mangled.GetStringRef())) {
359-
auto& display_cache = ::GetDisplayDemangledNamesCache();
360-
if (display_cache.Lookup(mangled, demangled) &&
361-
demangled)
362-
break;
363-
364-
std::string demangled_std =
365-
SwiftLanguageRuntime::DemangleSymbolAsString(
366-
m_mangled.GetStringRef(), SwiftLanguageRuntime::eSimplified,
367-
sc);
368-
if (!demangled_std.empty()) {
369-
demangled.SetCString(demangled_std.c_str());
370-
display_cache.Insert(mangled, demangled);
371-
break;
372-
}
373-
}
374-
}
375-
} while (0);
376-
}
334+
if (m_mangled &&
335+
SwiftLanguageRuntime::IsSwiftMangledName(m_mangled.GetStringRef()))
336+
return ConstString(SwiftLanguageRuntime::DemangleSymbolAsString(
337+
m_mangled.GetStringRef(), SwiftLanguageRuntime::eSimplified, sc));
377338
#endif // LLDB_ENABLE_SWIFT
378-
if (!demangled)
379-
demangled = GetDemangledName();
380-
return demangled ? demangled : m_mangled;
381339
// END SWIFT
340+
return GetDemangledName();
382341
}
383342

384343
bool Mangled::NameMatches(const RegularExpression &regex) const {

lldb/source/Plugins/Language/Swift/SwiftLanguage.cpp

Lines changed: 140 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,8 @@ bool SwiftLanguage::IsSourceFile(llvm::StringRef file_path) const {
12071207
return file_path.endswith(".swift");
12081208
}
12091209

1210-
std::vector<FormattersMatchCandidate> SwiftLanguage::GetPossibleFormattersMatches(
1210+
std::vector<FormattersMatchCandidate>
1211+
SwiftLanguage::GetPossibleFormattersMatches(
12111212
ValueObject &valobj, lldb::DynamicValueType use_dynamic) {
12121213
std::vector<FormattersMatchCandidate> result;
12131214

@@ -1636,152 +1637,154 @@ bool SwiftLanguage::GetFunctionDisplayName(
16361637
SwiftScratchContextLock scratch_ctx_lock(exe_ctx);
16371638
switch (representation) {
16381639
case Language::FunctionNameRepresentation::eName:
1639-
break; // no need to customize this
1640+
// No need to customize this.
1641+
return false;
16401642
case Language::FunctionNameRepresentation::eNameWithNoArgs: {
1641-
if (sc->function) {
1642-
if (sc->function->GetLanguage() == eLanguageTypeSwift) {
1643-
if (ConstString cs = sc->function->GetDisplayName(sc)) {
1644-
s.Printf("%s", cs.AsCString());
1645-
return true;
1646-
}
1647-
}
1648-
}
1649-
break;
1643+
if (!sc->function)
1644+
return false;
1645+
if (sc->function->GetLanguage() != eLanguageTypeSwift)
1646+
return false;
1647+
std::string display_name = SwiftLanguageRuntime::DemangleSymbolAsString(
1648+
sc->function->GetMangled().GetMangledName().GetStringRef(),
1649+
SwiftLanguageRuntime::eSimplified, sc, exe_ctx);
1650+
if (display_name.empty())
1651+
return false;
1652+
s << display_name;
1653+
return true;
16501654
}
16511655
case Language::FunctionNameRepresentation::eNameWithArgs: {
1652-
if (sc->function) {
1653-
if (sc->function->GetLanguage() == eLanguageTypeSwift) {
1654-
if (const char *cstr = sc->function->GetDisplayName(sc).AsCString()) {
1655-
ExecutionContextScope *exe_scope =
1656-
exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL;
1657-
const InlineFunctionInfo *inline_info = NULL;
1658-
VariableListSP variable_list_sp;
1659-
bool get_function_vars = true;
1660-
if (sc->block) {
1661-
Block *inline_block = sc->block->GetContainingInlinedBlock();
1662-
1663-
if (inline_block) {
1664-
get_function_vars = false;
1665-
inline_info = sc->block->GetInlinedFunctionInfo();
1666-
if (inline_info)
1667-
variable_list_sp = inline_block->GetBlockVariableList(true);
1668-
}
1669-
}
1670-
1671-
if (get_function_vars) {
1672-
variable_list_sp =
1673-
sc->function->GetBlock(true).GetBlockVariableList(true);
1674-
}
1675-
1676-
if (inline_info) {
1677-
s.PutCString(cstr);
1678-
s.PutCString(" [inlined] ");
1679-
cstr = inline_info->GetName().GetCString();
1680-
}
1656+
if (!sc->function)
1657+
return false;
1658+
if (sc->function->GetLanguage() != eLanguageTypeSwift)
1659+
return false;
1660+
std::string display_name = SwiftLanguageRuntime::DemangleSymbolAsString(
1661+
sc->function->GetMangled().GetMangledName().GetStringRef(),
1662+
SwiftLanguageRuntime::eSimplified, sc, exe_ctx);
1663+
if (display_name.empty())
1664+
return false;
1665+
ExecutionContextScope *exe_scope =
1666+
exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL;
1667+
const InlineFunctionInfo *inline_info = NULL;
1668+
VariableListSP variable_list_sp;
1669+
bool get_function_vars = true;
1670+
if (sc->block) {
1671+
Block *inline_block = sc->block->GetContainingInlinedBlock();
1672+
1673+
if (inline_block) {
1674+
get_function_vars = false;
1675+
inline_info = sc->block->GetInlinedFunctionInfo();
1676+
if (inline_info)
1677+
variable_list_sp = inline_block->GetBlockVariableList(true);
1678+
}
1679+
}
16811680

1682-
VariableList args;
1683-
if (variable_list_sp)
1684-
variable_list_sp->AppendVariablesWithScope(
1685-
eValueTypeVariableArgument, args);
1686-
if (args.GetSize() > 0) {
1687-
const char *open_paren = strchr(cstr, '(');
1688-
const char *close_paren = nullptr;
1689-
const char *generic = strchr(cstr, '<');
1690-
// if before the arguments list begins there is a template sign
1691-
// then scan to the end of the generic args before you try to find
1692-
// the arguments list
1693-
if (generic && open_paren && generic < open_paren) {
1694-
int generic_depth = 1;
1695-
++generic;
1696-
for (; *generic && generic_depth > 0; generic++) {
1697-
if (*generic == '<')
1698-
generic_depth++;
1699-
if (*generic == '>')
1700-
generic_depth--;
1701-
}
1702-
if (*generic)
1703-
open_paren = strchr(generic, '(');
1704-
else
1705-
open_paren = nullptr;
1706-
}
1707-
if (open_paren) {
1708-
close_paren = strchr(open_paren, ')');
1709-
}
1681+
if (get_function_vars) {
1682+
variable_list_sp =
1683+
sc->function->GetBlock(true).GetBlockVariableList(true);
1684+
}
17101685

1711-
if (open_paren)
1712-
s.Write(cstr, open_paren - cstr + 1);
1713-
else {
1714-
s.PutCString(cstr);
1715-
s.PutChar('(');
1716-
}
1717-
const size_t num_args = args.GetSize();
1718-
for (size_t arg_idx = 0; arg_idx < num_args; ++arg_idx) {
1719-
std::string buffer;
1720-
1721-
VariableSP var_sp(args.GetVariableAtIndex(arg_idx));
1722-
ValueObjectSP var_value_sp(
1723-
ValueObjectVariable::Create(exe_scope, var_sp));
1724-
StreamString ss;
1725-
const char *var_representation = nullptr;
1726-
const char *var_name = var_value_sp->GetName().GetCString();
1727-
if (var_value_sp->GetCompilerType().IsValid()) {
1728-
if (var_value_sp && exe_scope->CalculateTarget())
1729-
var_value_sp =
1730-
var_value_sp->GetQualifiedRepresentationIfAvailable(
1731-
exe_scope->CalculateTarget()
1732-
->TargetProperties::GetPreferDynamicValue(),
1733-
exe_scope->CalculateTarget()
1734-
->TargetProperties::GetEnableSyntheticValue());
1735-
if (var_value_sp->GetCompilerType().IsAggregateType() &&
1736-
DataVisualization::ShouldPrintAsOneLiner(
1737-
*var_value_sp.get())) {
1738-
static StringSummaryFormat format(
1739-
TypeSummaryImpl::Flags()
1740-
.SetHideItemNames(false)
1741-
.SetShowMembersOneLiner(true),
1742-
"");
1743-
format.FormatObject(var_value_sp.get(), buffer,
1744-
TypeSummaryOptions());
1745-
var_representation = buffer.c_str();
1746-
} else
1747-
var_value_sp->DumpPrintableRepresentation(
1748-
ss,
1749-
ValueObject::ValueObjectRepresentationStyle::
1750-
eValueObjectRepresentationStyleSummary,
1751-
eFormatDefault,
1752-
ValueObject::PrintableRepresentationSpecialCases::eAllow,
1753-
false);
1754-
}
1755-
if (ss.GetData() && ss.GetSize())
1756-
var_representation = ss.GetData();
1757-
if (arg_idx > 0)
1758-
s.PutCString(", ");
1759-
if (var_value_sp->GetError().Success()) {
1760-
if (var_representation)
1761-
s.Printf("%s=%s", var_name, var_representation);
1762-
else
1763-
s.Printf("%s=%s at %s", var_name,
1764-
var_value_sp->GetTypeName().GetCString(),
1765-
var_value_sp->GetLocationAsCString());
1766-
} else
1767-
s.Printf("%s=<unavailable>", var_name);
1768-
}
1686+
if (inline_info) {
1687+
s << display_name;
1688+
s.PutCString(" [inlined] ");
1689+
display_name = inline_info->GetName();
1690+
}
17691691

1770-
if (close_paren)
1771-
s.PutCString(close_paren);
1772-
else
1773-
s.PutChar(')');
1692+
VariableList args;
1693+
if (variable_list_sp)
1694+
variable_list_sp->AppendVariablesWithScope(eValueTypeVariableArgument,
1695+
args);
1696+
if (args.GetSize() == 0) {
1697+
s << display_name;
1698+
return true;
1699+
}
1700+
const char *cstr = display_name.data();
1701+
const char *open_paren = strchr(cstr, '(');
1702+
const char *close_paren = nullptr;
1703+
const char *generic = strchr(cstr, '<');
1704+
// If before the arguments list begins there is a template sign
1705+
// then scan to the end of the generic args before you try to find
1706+
// the arguments list.
1707+
if (generic && open_paren && generic < open_paren) {
1708+
int generic_depth = 1;
1709+
++generic;
1710+
for (; *generic && generic_depth > 0; generic++) {
1711+
if (*generic == '<')
1712+
generic_depth++;
1713+
if (*generic == '>')
1714+
generic_depth--;
1715+
}
1716+
if (*generic)
1717+
open_paren = strchr(generic, '(');
1718+
else
1719+
open_paren = nullptr;
1720+
}
1721+
if (open_paren) {
1722+
close_paren = strchr(open_paren, ')');
1723+
}
17741724

1775-
} else {
1776-
s.PutCString(cstr);
1777-
}
1778-
return true;
1779-
}
1725+
if (open_paren)
1726+
s.Write(cstr, open_paren - cstr + 1);
1727+
else {
1728+
s << display_name;
1729+
s.PutChar('(');
1730+
}
1731+
const size_t num_args = args.GetSize();
1732+
for (size_t arg_idx = 0; arg_idx < num_args; ++arg_idx) {
1733+
std::string buffer;
1734+
1735+
VariableSP var_sp(args.GetVariableAtIndex(arg_idx));
1736+
ValueObjectSP var_value_sp(
1737+
ValueObjectVariable::Create(exe_scope, var_sp));
1738+
if (!var_sp || !var_value_sp || var_sp->IsArtificial())
1739+
continue;
1740+
StreamString ss;
1741+
const char *var_representation = nullptr;
1742+
const char *var_name = var_value_sp->GetName().GetCString();
1743+
if (var_value_sp->GetCompilerType().IsValid()) {
1744+
if (var_value_sp && exe_scope->CalculateTarget())
1745+
var_value_sp = var_value_sp->GetQualifiedRepresentationIfAvailable(
1746+
exe_scope->CalculateTarget()
1747+
->TargetProperties::GetPreferDynamicValue(),
1748+
exe_scope->CalculateTarget()
1749+
->TargetProperties::GetEnableSyntheticValue());
1750+
if (var_value_sp->GetCompilerType().IsAggregateType() &&
1751+
DataVisualization::ShouldPrintAsOneLiner(*var_value_sp.get())) {
1752+
static StringSummaryFormat format(TypeSummaryImpl::Flags()
1753+
.SetHideItemNames(false)
1754+
.SetShowMembersOneLiner(true),
1755+
"");
1756+
format.FormatObject(var_value_sp.get(), buffer, TypeSummaryOptions());
1757+
var_representation = buffer.c_str();
1758+
} else
1759+
var_value_sp->DumpPrintableRepresentation(
1760+
ss,
1761+
ValueObject::ValueObjectRepresentationStyle::
1762+
eValueObjectRepresentationStyleSummary,
1763+
eFormatDefault,
1764+
ValueObject::PrintableRepresentationSpecialCases::eAllow, false);
17801765
}
1766+
if (ss.GetData() && ss.GetSize())
1767+
var_representation = ss.GetData();
1768+
if (arg_idx > 0)
1769+
s.PutCString(", ");
1770+
if (var_value_sp->GetError().Success()) {
1771+
if (var_representation)
1772+
s.Printf("%s=%s", var_name, var_representation);
1773+
else
1774+
s.Printf("%s=%s at %s", var_name,
1775+
var_value_sp->GetTypeName().GetCString(),
1776+
var_value_sp->GetLocationAsCString());
1777+
} else
1778+
s.Printf("%s=<unavailable>", var_name);
17811779
}
1782-
}
1783-
}
17841780

1781+
if (close_paren)
1782+
s.PutCString(close_paren);
1783+
else
1784+
s.PutChar(')');
1785+
}
1786+
return true;
1787+
}
17851788
return false;
17861789
}
17871790

0 commit comments

Comments
 (0)