Skip to content

Commit d0dfff1

Browse files
committed
[lldb] Fix that Swift uses the DisplayName in the FormatManager
In llvm.org the FormatManager currently has the bug that it uses only the TypeName when deciding which format to use. This bug is currently actually required to make it possible to support C++'s concept of display names where inline namespaces are hidden. To give some more context: The FormatManager prefers taking a summary provider for a type if the summary provider is *not* using a regex to match the type name. Upstream there is a non-regex summary provider for `std::string` and a regex summary provider for `std::__[num]::string`. The DisplayTypeName for libc++'s `std::__1::string` is `std::string`. As that matches the non-regex summary provider for `std::string`, the FormatManager will always prefer that summary provider over `std::__[num]::string`. However, `std::string` is a libstdc++ summary provider while `std::__[num]::string` is the correct libc++ provider. There is no way to tell LLDB that the libc++ summary provider is correct at the moment, so that's why llvm.org isn't using the DisplayTypeName in the format manager. Meanwhile in Swift, DisplayTypeName has to be used as some summary providers etc. match only the DisplayTypeName. That's why only using TypeName there is breaking tests. As using the DisplayTypeName breaks C++ and not using the DisplayTypeName breaks Swift, the current hack we came up with is to only add the DisplayTypeName to the list of strings the FormatManager searches if the type we are trying to format is Swift (or not a Clang type). Clearly this should be fixed upstream but I didn't get around to do that yet. This was originally fixed in the swift/master branch for stable/20200108 by commit dee0a4c which was just a merge commit for the actual patch that split up TypeName and DisplayTypeName in llvm.org. That's also why that patch escaped the usual detection mechanisms for these situations. Fixes rdar://64913211 (cherry picked from commit 766db68)
1 parent e4241f7 commit d0dfff1

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

lldb/source/DataFormatters/FormatManager.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
#include "lldb/Target/Language.h"
1919
#include "lldb/Utility/Log.h"
2020

21+
// BEGIN SWIFT
22+
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
23+
// END SWIFT
24+
2125
using namespace lldb;
2226
using namespace lldb_private;
2327
using namespace lldb_private::formatters;
@@ -192,14 +196,21 @@ void FormatManager::GetPossibleMatches(
192196
entries.push_back(
193197
{type_name, did_strip_ptr, did_strip_ref, did_strip_typedef});
194198

195-
const SymbolContext *sc = nullptr;
196-
if (valobj.GetFrameSP())
197-
sc = &valobj.GetFrameSP()->GetSymbolContext(eSymbolContextFunction);
198-
199-
ConstString display_type_name(compiler_type.GetTypeName());
200-
if (display_type_name != type_name)
201-
entries.push_back({display_type_name, did_strip_ptr,
202-
did_strip_ref, did_strip_typedef});
199+
// BEGIN SWIFT
200+
TypeSystem *ts = compiler_type.GetTypeSystem();
201+
if (ts && !llvm::isa<TypeSystemClang>(ts)) {
202+
// END SWIFT
203+
const SymbolContext *sc = nullptr;
204+
if (valobj.GetFrameSP())
205+
sc = &valobj.GetFrameSP()->GetSymbolContext(eSymbolContextFunction);
206+
207+
ConstString display_type_name(compiler_type.GetDisplayTypeName(sc));
208+
if (display_type_name != type_name)
209+
entries.push_back({display_type_name, reason, did_strip_ptr,
210+
did_strip_ref, did_strip_typedef});
211+
// BEGIN SWIFT
212+
}
213+
// END SWIFT
203214
}
204215

205216
for (bool is_rvalue_ref = true, j = true;

0 commit comments

Comments
 (0)