Skip to content

Commit c51786b

Browse files
Revert "[lldb][dwarf] Compute fully qualified names on simplified template names with DWARFTypePrinter (#112811)"
This reverts commit 94d100f. Reverted because of greendragon failure on the incremental arm64 bot ******************** TEST 'lldb-shell :: SymbolFile/DWARF/x86/simplified-template-names.cpp' FAILED ******************** Exit Code: 1 RUN: at line 7: /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/bin/clang --driver-mode=g++ --target=specify-a-target-or-use-a-_host-substitution --target=x86_64-pc-linux -g -gsimple-template-names /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/test/Shell/SymbolFile/DWARF/x86/simplified-template-names.cpp -o /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/tools/lldb/test/Shell/SymbolFile/DWARF/x86/Output/simplified-template-names.cpp.tmp /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/bin/clang --driver-mode=g++ --target=specify-a-target-or-use-a-_host-substitution --target=x86_64-pc-linux -g -gsimple-template-names /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/test/Shell/SymbolFile/DWARF/x86/simplified-template-names.cpp -o /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/tools/lldb/test/Shell/SymbolFile/DWARF/x86/Output/simplified-template-names.cpp.tmp ld: warning: -m is obsolete ld: unknown option: --hash-style=gnu clang: error: linker command failed with exit code 1 (use -v to see invocation)
1 parent cfc574a commit c51786b

File tree

14 files changed

+70
-309
lines changed

14 files changed

+70
-309
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
#include "clang/AST/Type.h"
4646
#include "clang/Basic/Specifiers.h"
4747
#include "llvm/ADT/StringExtras.h"
48-
#include "llvm/DebugInfo/DWARF/DWARFTypePrinter.h"
4948
#include "llvm/Demangle/Demangle.h"
5049

5150
#include <map>
@@ -827,11 +826,11 @@ std::string DWARFASTParserClang::GetDIEClassTemplateParams(DWARFDIE die) {
827826
if (llvm::StringRef(die.GetName()).contains("<"))
828827
return {};
829828

830-
std::string name;
831-
llvm::raw_string_ostream os(name);
832-
llvm::DWARFTypePrinter<DWARFDIE> type_printer(os);
833-
type_printer.appendAndTerminateTemplateParameters(die);
834-
return name;
829+
TypeSystemClang::TemplateParameterInfos template_param_infos;
830+
if (ParseTemplateParameterInfos(die, template_param_infos))
831+
return m_ast.PrintTemplateParams(template_param_infos);
832+
833+
return {};
835834
}
836835

837836
void DWARFASTParserClang::MapDeclDIEToDefDIE(
@@ -1619,9 +1618,9 @@ void DWARFASTParserClang::GetUniqueTypeNameAndDeclaration(
16191618
case DW_TAG_structure_type:
16201619
case DW_TAG_union_type: {
16211620
if (const char *class_union_struct_name = parent_decl_ctx_die.GetName()) {
1621+
qualified_name.insert(
1622+
0, GetDIEClassTemplateParams(parent_decl_ctx_die));
16221623
qualified_name.insert(0, "::");
1623-
qualified_name.insert(0,
1624-
GetDIEClassTemplateParams(parent_decl_ctx_die));
16251624
qualified_name.insert(0, class_union_struct_name);
16261625
}
16271626
parent_decl_ctx_die = parent_decl_ctx_die.GetParentDeclContextDIE();
@@ -1674,12 +1673,6 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
16741673
if (attrs.name) {
16751674
GetUniqueTypeNameAndDeclaration(die, cu_language, unique_typename,
16761675
unique_decl);
1677-
if (log) {
1678-
dwarf->GetObjectFile()->GetModule()->LogMessage(
1679-
log, "SymbolFileDWARF({0:p}) - {1:x16}: {2} has unique name: {3} ",
1680-
static_cast<void *>(this), die.GetID(), DW_TAG_value_to_name(tag),
1681-
unique_typename.AsCString());
1682-
}
16831676
if (UniqueDWARFASTType *unique_ast_entry_type =
16841677
dwarf->GetUniqueDWARFASTTypeMap().Find(
16851678
unique_typename, die, unique_decl, byte_size,

lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ class DWARFUnit;
2424
class DWARFDebugInfoEntry;
2525
class DWARFDeclContext;
2626
class SymbolFileDWARF;
27-
class DWARFFormValue;
2827

2928
class DWARFBaseDIE {
3029
public:
31-
using DWARFFormValue = dwarf::DWARFFormValue;
3230
DWARFBaseDIE() = default;
3331

3432
DWARFBaseDIE(DWARFUnit *cu, DWARFDebugInfoEntry *die)
@@ -119,12 +117,6 @@ class DWARFBaseDIE {
119117
enum class Recurse : bool { no, yes };
120118
DWARFAttributes GetAttributes(Recurse recurse = Recurse::yes) const;
121119

122-
// The following methods use LLVM naming convension in order to be are used by
123-
// LLVM libraries.
124-
dw_tag_t getTag() const { return Tag(); }
125-
126-
const char *getShortName() const { return GetName(); }
127-
128120
protected:
129121
DWARFUnit *m_cu = nullptr;
130122
DWARFDebugInfoEntry *m_die = nullptr;

lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -572,43 +572,6 @@ bool DWARFDIE::GetDIENamesAndRanges(
572572
return false;
573573
}
574574

575-
// The following methods use LLVM naming convension in order to be are used by
576-
// LLVM libraries.
577575
llvm::iterator_range<DWARFDIE::child_iterator> DWARFDIE::children() const {
578576
return llvm::make_range(child_iterator(*this), child_iterator());
579577
}
580-
581-
DWARFDIE::child_iterator DWARFDIE::begin() const {
582-
return child_iterator(*this);
583-
}
584-
585-
DWARFDIE::child_iterator DWARFDIE::end() const { return child_iterator(); }
586-
587-
std::optional<DWARFFormValue> DWARFDIE::find(const dw_attr_t attr) const {
588-
DWARFFormValue form_value;
589-
if (m_die->GetAttributeValue(m_cu, attr, form_value, nullptr, false))
590-
return form_value;
591-
return std::nullopt;
592-
}
593-
594-
std::optional<uint64_t> DWARFDIE::getLanguage() const {
595-
if (IsValid())
596-
return m_cu->GetDWARFLanguageType();
597-
return std::nullopt;
598-
}
599-
600-
DWARFDIE DWARFDIE::resolveReferencedType(dw_attr_t attr) const {
601-
return GetReferencedDIE(attr);
602-
}
603-
604-
DWARFDIE DWARFDIE::resolveReferencedType(DWARFFormValue v) const {
605-
if (IsValid())
606-
return v.Reference();
607-
return {};
608-
}
609-
610-
DWARFDIE DWARFDIE::resolveTypeUnitReference() const {
611-
if (DWARFDIE reference = GetReferencedDIE(DW_AT_signature))
612-
return reference;
613-
return *this;
614-
}

lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,25 +103,8 @@ class DWARFDIE : public DWARFBaseDIE {
103103
std::optional<int> &call_line, std::optional<int> &call_column,
104104
DWARFExpressionList *frame_base) const;
105105

106-
// The following methods use LLVM naming convension in order to be are used by
107-
// LLVM libraries.
108-
std::optional<uint64_t> getLanguage() const;
109-
110-
DWARFDIE getParent() const { return GetParent(); }
111-
112-
DWARFDIE resolveReferencedType(dw_attr_t attr) const;
113-
114-
DWARFDIE resolveReferencedType(DWARFFormValue v) const;
115-
116-
DWARFDIE resolveTypeUnitReference() const;
117-
118-
std::optional<DWARFFormValue> find(const dw_attr_t attr) const;
119-
120106
/// The range of all the children of this DIE.
121107
llvm::iterator_range<child_iterator> children() const;
122-
123-
child_iterator begin() const;
124-
child_iterator end() const;
125108
};
126109

127110
class DWARFDIE::child_iterator

lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -574,31 +574,6 @@ uint64_t DWARFFormValue::Reference(dw_offset_t base_offset) const {
574574
}
575575
}
576576

577-
std::optional<uint64_t> DWARFFormValue::getAsUnsignedConstant() const {
578-
if ((!IsDataForm(m_form)) || m_form == lldb_private::dwarf::DW_FORM_sdata)
579-
return std::nullopt;
580-
return m_value.uval;
581-
}
582-
583-
std::optional<int64_t> DWARFFormValue::getAsSignedConstant() const {
584-
if ((!IsDataForm(m_form)) ||
585-
(m_form == lldb_private::dwarf::DW_FORM_udata &&
586-
uint64_t(std::numeric_limits<int64_t>::max()) < m_value.uval))
587-
return std::nullopt;
588-
switch (m_form) {
589-
case lldb_private::dwarf::DW_FORM_data4:
590-
return int32_t(m_value.uval);
591-
case lldb_private::dwarf::DW_FORM_data2:
592-
return int16_t(m_value.uval);
593-
case lldb_private::dwarf::DW_FORM_data1:
594-
return int8_t(m_value.uval);
595-
case lldb_private::dwarf::DW_FORM_sdata:
596-
case lldb_private::dwarf::DW_FORM_data8:
597-
default:
598-
return m_value.sval;
599-
}
600-
}
601-
602577
const uint8_t *DWARFFormValue::BlockData() const { return m_value.data; }
603578

604579
bool DWARFFormValue::IsBlockForm(const dw_form_t form) {

lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,6 @@ class DWARFFormValue {
7676
void Clear();
7777
static bool FormIsSupported(dw_form_t form);
7878

79-
// The following methods use LLVM naming convension in order to be are used by
80-
// LLVM libraries.
81-
std::optional<uint64_t> getAsUnsignedConstant() const;
82-
std::optional<int64_t> getAsSignedConstant() const;
83-
const char *getAsCString() const { return AsCString(); }
84-
8579
protected:
8680
// Compile unit where m_value was located.
8781
// It may be different from compile unit where m_value refers to.

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "SymbolFileDWARF.h"
1010

1111
#include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
12-
#include "llvm/DebugInfo/DWARF/DWARFTypePrinter.h"
1312
#include "llvm/Support/Casting.h"
1413
#include "llvm/Support/FileUtilities.h"
1514
#include "llvm/Support/Format.h"
@@ -2811,14 +2810,33 @@ void SymbolFileDWARF::FindTypes(const TypeQuery &query, TypeResults &results) {
28112810
return true; // Keep iterating over index types, language mismatch.
28122811
}
28132812

2814-
std::string qualified_name;
2815-
llvm::raw_string_ostream os(qualified_name);
2816-
llvm::DWARFTypePrinter<DWARFDIE> type_printer(os);
2817-
type_printer.appendQualifiedName(die);
2818-
TypeQuery die_query(qualified_name, e_exact_match);
2819-
if (query.ContextMatches(die_query.GetContextRef()))
2820-
if (Type *matching_type = ResolveType(die, true, true))
2821-
results.InsertUnique(matching_type->shared_from_this());
2813+
// Check the context matches
2814+
std::vector<lldb_private::CompilerContext> die_context;
2815+
if (query.GetModuleSearch())
2816+
die_context = die.GetDeclContext();
2817+
else
2818+
die_context = die.GetTypeLookupContext();
2819+
assert(!die_context.empty());
2820+
if (!query_simple.ContextMatches(die_context))
2821+
return true; // Keep iterating over index types, context mismatch.
2822+
2823+
// Try to resolve the type.
2824+
if (Type *matching_type = ResolveType(die, true, true)) {
2825+
ConstString name = matching_type->GetQualifiedName();
2826+
// We have found a type that still might not match due to template
2827+
// parameters. If we create a new TypeQuery that uses the new type's
2828+
// fully qualified name, we can find out if this type matches at all
2829+
// context levels. We can't use just the "match_simple" context
2830+
// because all template parameters were stripped off. The fully
2831+
// qualified name of the type will have the template parameters and
2832+
// will allow us to make sure it matches correctly.
2833+
TypeQuery die_query(name.GetStringRef(),
2834+
TypeQueryOptions::e_exact_match);
2835+
if (!query.ContextMatches(die_query.GetContextRef()))
2836+
return true; // Keep iterating over index types, context mismatch.
2837+
2838+
results.InsertUnique(matching_type->shared_from_this());
2839+
}
28222840
return !results.Done(query); // Keep iterating if we aren't done.
28232841
});
28242842
if (results.Done(query)) {

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,26 @@ static TemplateParameterList *CreateTemplateParameterList(
14031403
return template_param_list;
14041404
}
14051405

1406+
std::string TypeSystemClang::PrintTemplateParams(
1407+
const TemplateParameterInfos &template_param_infos) {
1408+
llvm::SmallVector<NamedDecl *, 8> ignore;
1409+
clang::TemplateParameterList *template_param_list =
1410+
CreateTemplateParameterList(getASTContext(), template_param_infos,
1411+
ignore);
1412+
llvm::SmallVector<clang::TemplateArgument, 2> args(
1413+
template_param_infos.GetArgs());
1414+
if (template_param_infos.hasParameterPack()) {
1415+
llvm::ArrayRef<TemplateArgument> pack_args =
1416+
template_param_infos.GetParameterPackArgs();
1417+
args.append(pack_args.begin(), pack_args.end());
1418+
}
1419+
std::string str;
1420+
llvm::raw_string_ostream os(str);
1421+
clang::printTemplateArgumentList(os, args, GetTypePrintingPolicy(),
1422+
template_param_list);
1423+
return str;
1424+
}
1425+
14061426
clang::FunctionTemplateDecl *TypeSystemClang::CreateFunctionTemplateDecl(
14071427
clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module,
14081428
clang::FunctionDecl *func_decl,

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,10 @@ class TypeSystemClang : public TypeSystem {
11481148

11491149
bool SetDeclIsForcefullyCompleted(const clang::TagDecl *td);
11501150

1151+
/// Return the template parameters (including surrounding <>) in string form.
1152+
std::string
1153+
PrintTemplateParams(const TemplateParameterInfos &template_param_infos);
1154+
11511155
private:
11521156
/// Returns the PrintingPolicy used when generating the internal type names.
11531157
/// These type names are mostly used for the formatter selection.

lldb/test/Shell/SymbolFile/DWARF/x86/simplified-template-names.cpp

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)