Skip to content

Commit d0fb7a4

Browse files
committed
[lldb] Support for DWARF-5 atomic types
Summary: This patch adds support for atomic types (DW_TAG_atomic_type) to LLDB. It's mostly just filling out all the switch-statements that didn't implement Atomic case with the usual boilerplate. Thanks Pavel for writing the test case. Reviewers: labath, aprantl, shafik Reviewed By: labath Subscribers: jfb, abidh, JDevlieghere, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D71183
1 parent f369653 commit d0fb7a4

File tree

10 files changed

+163
-2
lines changed

10 files changed

+163
-2
lines changed

lldb/include/lldb/Symbol/ClangASTContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,8 @@ class ClangASTContext : public TypeSystem {
644644
CompilerType
645645
GetRValueReferenceType(lldb::opaque_compiler_type_t type) override;
646646

647+
CompilerType GetAtomicType(lldb::opaque_compiler_type_t type) override;
648+
647649
CompilerType AddConstModifier(lldb::opaque_compiler_type_t type) override;
648650

649651
CompilerType AddVolatileModifier(lldb::opaque_compiler_type_t type) override;

lldb/include/lldb/Symbol/CompilerType.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ class CompilerType {
218218
// an invalid type.
219219
CompilerType AddVolatileModifier() const;
220220

221+
// Return a new CompilerType that is the atomic type of this type. If this
222+
// type is not valid or the type system doesn't support atomic types, this
223+
// returns an invalid type.
224+
CompilerType GetAtomicType() const;
225+
221226
// Return a new CompilerType adds a restrict modifier to this type if this
222227
// type is valid and the type system supports restrict modifiers, else return
223228
// an invalid type.

lldb/include/lldb/Symbol/Type.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ class Type : public std::enable_shared_from_this<Type>, public UserID {
8080
eEncodingIsLValueReferenceUID, ///< This type is L value reference to a type
8181
/// whose UID is m_encoding_uid
8282
eEncodingIsRValueReferenceUID, ///< This type is R value reference to a type
83-
/// whose UID is m_encoding_uid
83+
/// whose UID is m_encoding_uid,
84+
eEncodingIsAtomicUID, ///< This type is the type whose UID is
85+
/// m_encoding_uid as an atomic type.
8486
eEncodingIsSyntheticUID
8587
};
8688

lldb/include/lldb/Symbol/TypeSystem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ class TypeSystem : public PluginInterface {
228228
virtual CompilerType
229229
GetRValueReferenceType(lldb::opaque_compiler_type_t type);
230230

231+
virtual CompilerType GetAtomicType(lldb::opaque_compiler_type_t type);
232+
231233
virtual CompilerType AddConstModifier(lldb::opaque_compiler_type_t type);
232234

233235
virtual CompilerType AddVolatileModifier(lldb::opaque_compiler_type_t type);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
474474
case DW_TAG_const_type:
475475
case DW_TAG_restrict_type:
476476
case DW_TAG_volatile_type:
477+
case DW_TAG_atomic_type:
477478
case DW_TAG_unspecified_type: {
478479
type_sp = ParseTypeModifier(sc, die, attrs);
479480
break;
@@ -618,6 +619,9 @@ DWARFASTParserClang::ParseTypeModifier(const SymbolContext &sc,
618619
case DW_TAG_volatile_type:
619620
encoding_data_type = Type::eEncodingIsVolatileUID;
620621
break;
622+
case DW_TAG_atomic_type:
623+
encoding_data_type = Type::eEncodingIsAtomicUID;
624+
break;
621625
}
622626

623627
if (!clang_type && (encoding_data_type == Type::eEncodingIsPointerUID ||

lldb/source/Symbol/ClangASTContext.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4066,6 +4066,11 @@ ClangASTContext::GetTypeInfo(lldb::opaque_compiler_type_t type,
40664066
->getUnderlyingType()
40674067
.getAsOpaquePtr())
40684068
.GetTypeInfo(pointee_or_element_clang_type);
4069+
case clang::Type::Atomic:
4070+
return CompilerType(this, llvm::cast<clang::AtomicType>(qual_type)
4071+
->getValueType()
4072+
.getAsOpaquePtr())
4073+
.GetTypeInfo(pointee_or_element_clang_type);
40694074
case clang::Type::UnresolvedUsing:
40704075
return 0;
40714076

@@ -4760,6 +4765,13 @@ ClangASTContext::GetRValueReferenceType(lldb::opaque_compiler_type_t type) {
47604765
return CompilerType();
47614766
}
47624767

4768+
CompilerType ClangASTContext::GetAtomicType(lldb::opaque_compiler_type_t type) {
4769+
if (!type)
4770+
return CompilerType();
4771+
return CompilerType(
4772+
this, getASTContext()->getAtomicType(GetQualType(type)).getAsOpaquePtr());
4773+
}
4774+
47634775
CompilerType
47644776
ClangASTContext::AddConstModifier(lldb::opaque_compiler_type_t type) {
47654777
if (type) {
@@ -5364,6 +5376,11 @@ lldb::Format ClangASTContext::GetFormat(lldb::opaque_compiler_type_t type) {
53645376
->getUnderlyingType()
53655377
.getAsOpaquePtr())
53665378
.GetFormat();
5379+
case clang::Type::Atomic:
5380+
return CompilerType(this, llvm::cast<clang::AtomicType>(qual_type)
5381+
->getValueType()
5382+
.getAsOpaquePtr())
5383+
.GetFormat();
53675384
case clang::Type::DependentSizedArray:
53685385
case clang::Type::DependentSizedExtVector:
53695386
case clang::Type::UnresolvedUsing:
@@ -5379,7 +5396,6 @@ lldb::Format ClangASTContext::GetFormat(lldb::opaque_compiler_type_t type) {
53795396

53805397
case clang::Type::TemplateSpecialization:
53815398
case clang::Type::DeducedTemplateSpecialization:
5382-
case clang::Type::Atomic:
53835399
case clang::Type::Adjusted:
53845400
case clang::Type::Pipe:
53855401
break;

lldb/source/Symbol/CompilerType.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,12 @@ CompilerType CompilerType::GetRValueReferenceType() const {
427427
return CompilerType();
428428
}
429429

430+
CompilerType CompilerType::GetAtomicType() const {
431+
if (IsValid())
432+
return m_type_system->GetAtomicType(m_type);
433+
return CompilerType();
434+
}
435+
430436
CompilerType CompilerType::AddConstModifier() const {
431437
if (IsValid())
432438
return m_type_system->AddConstModifier(m_type);

lldb/source/Symbol/Type.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ void Type::GetDescription(Stream *s, lldb::DescriptionLevel level,
213213
case eEncodingIsVolatileUID:
214214
s->PutCString(" (unresolved volatile type)");
215215
break;
216+
case eEncodingIsAtomicUID:
217+
s->PutCString(" (unresolved atomic type)");
218+
break;
216219
case eEncodingIsTypedefUID:
217220
s->PutCString(" (unresolved typedef)");
218221
break;
@@ -271,6 +274,9 @@ void Type::Dump(Stream *s, bool show_context) {
271274
case eEncodingIsVolatileUID:
272275
s->PutCString(" (unresolved volatile type)");
273276
break;
277+
case eEncodingIsAtomicUID:
278+
s->PutCString(" (unresolved atomic type)");
279+
break;
274280
case eEncodingIsTypedefUID:
275281
s->PutCString(" (unresolved typedef)");
276282
break;
@@ -343,6 +349,7 @@ llvm::Optional<uint64_t> Type::GetByteSize() {
343349
case eEncodingIsConstUID:
344350
case eEncodingIsRestrictUID:
345351
case eEncodingIsVolatileUID:
352+
case eEncodingIsAtomicUID:
346353
case eEncodingIsTypedefUID: {
347354
Type *encoding_type = GetEncodingType();
348355
if (encoding_type)
@@ -491,6 +498,11 @@ bool Type::ResolveClangType(ResolveState compiler_type_resolve_state) {
491498
encoding_type->GetForwardCompilerType().AddVolatileModifier();
492499
break;
493500

501+
case eEncodingIsAtomicUID:
502+
m_compiler_type =
503+
encoding_type->GetForwardCompilerType().GetAtomicType();
504+
break;
505+
494506
case eEncodingIsTypedefUID:
495507
m_compiler_type = encoding_type->GetForwardCompilerType().CreateTypedef(
496508
m_name.AsCString("__lldb_invalid_typedef_name"),
@@ -545,6 +557,10 @@ bool Type::ResolveClangType(ResolveState compiler_type_resolve_state) {
545557
m_compiler_type = void_compiler_type.AddVolatileModifier();
546558
break;
547559

560+
case eEncodingIsAtomicUID:
561+
m_compiler_type = void_compiler_type.GetAtomicType();
562+
break;
563+
548564
case eEncodingIsTypedefUID:
549565
m_compiler_type = void_compiler_type.CreateTypedef(
550566
m_name.AsCString("__lldb_invalid_typedef_name"),

lldb/source/Symbol/TypeSystem.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ TypeSystem::GetRValueReferenceType(lldb::opaque_compiler_type_t type) {
8989
return CompilerType();
9090
}
9191

92+
CompilerType TypeSystem::GetAtomicType(lldb::opaque_compiler_type_t type) {
93+
return CompilerType();
94+
}
95+
9296
CompilerType TypeSystem::AddConstModifier(lldb::opaque_compiler_type_t type) {
9397
return CompilerType();
9498
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# REQUIRES: x86
2+
3+
# RUN: llvm-mc -triple=x86_64-pc-linux -filetype=obj %s > %t
4+
# RUN: %lldb %t -o "target variable integer structure" -o exit | FileCheck %s
5+
6+
# CHECK: (_Atomic(int)) integer = 14159
7+
# CHECK: (_Atomic(struct_type)) structure = {}
8+
9+
.data
10+
integer:
11+
.long 14159
12+
structure:
13+
.byte 0
14+
15+
.section .debug_abbrev,"",@progbits
16+
.byte 1 # Abbreviation Code
17+
.byte 17 # DW_TAG_compile_unit
18+
.byte 1 # DW_CHILDREN_yes
19+
.byte 37 # DW_AT_producer
20+
.byte 8 # DW_FORM_string
21+
.byte 19 # DW_AT_language
22+
.byte 5 # DW_FORM_data2
23+
.byte 0 # EOM(1)
24+
.byte 0 # EOM(2)
25+
.byte 2 # Abbreviation Code
26+
.byte 52 # DW_TAG_variable
27+
.byte 0 # DW_CHILDREN_no
28+
.byte 3 # DW_AT_name
29+
.byte 8 # DW_FORM_string
30+
.byte 73 # DW_AT_type
31+
.byte 19 # DW_FORM_ref4
32+
.byte 2 # DW_AT_location
33+
.byte 24 # DW_FORM_exprloc
34+
.byte 0 # EOM(1)
35+
.byte 0 # EOM(2)
36+
.byte 3 # Abbreviation Code
37+
.byte 71 # DW_TAG_atomic_type
38+
.byte 0 # DW_CHILDREN_no
39+
.byte 73 # DW_AT_type
40+
.byte 19 # DW_FORM_ref4
41+
.byte 0 # EOM(1)
42+
.byte 0 # EOM(2)
43+
.byte 4 # Abbreviation Code
44+
.byte 36 # DW_TAG_base_type
45+
.byte 0 # DW_CHILDREN_no
46+
.byte 3 # DW_AT_name
47+
.byte 8 # DW_FORM_string
48+
.byte 62 # DW_AT_encoding
49+
.byte 11 # DW_FORM_data1
50+
.byte 11 # DW_AT_byte_size
51+
.byte 11 # DW_FORM_data1
52+
.byte 0 # EOM(1)
53+
.byte 0 # EOM(2)
54+
.byte 5 # Abbreviation Code
55+
.byte 19 # DW_TAG_structure_type
56+
.byte 0 # DW_CHILDREN_no
57+
.byte 3 # DW_AT_name
58+
.byte 8 # DW_FORM_string
59+
.byte 11 # DW_AT_byte_size
60+
.byte 11 # DW_FORM_data1
61+
.byte 0 # EOM(1)
62+
.byte 0 # EOM(2)
63+
.byte 0 # EOM(3)
64+
65+
.section .debug_info,"",@progbits
66+
.Lcu_begin0:
67+
.long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
68+
.Ldebug_info_start0:
69+
.short 5 # DWARF version number
70+
.byte 1 # DWARF Unit Type
71+
.byte 8 # Address Size (in bytes)
72+
.long .debug_abbrev # Offset Into Abbrev. Section
73+
.byte 1 # Abbrev [1] 0xb:0x50 DW_TAG_compile_unit
74+
.asciz "Hand-written DWARF" # DW_AT_producer
75+
.short 12 # DW_AT_language
76+
.byte 2 # Abbrev [2] DW_TAG_variable
77+
.asciz "integer" # DW_AT_name
78+
.long .Latomic_int # DW_AT_type
79+
.byte 9 # DW_AT_location
80+
.byte 3
81+
.quad integer
82+
.byte 2 # Abbrev [2] DW_TAG_variable
83+
.asciz "structure" # DW_AT_name
84+
.long .Latomic_struct # DW_AT_type
85+
.byte 9 # DW_AT_location
86+
.byte 3
87+
.quad structure
88+
.Latomic_int:
89+
.byte 3 # Abbrev [3] DW_TAG_atomic_type
90+
.long .Lint # DW_AT_type
91+
.Lint:
92+
.byte 4 # Abbrev [4] 0x53:0x7 DW_TAG_base_type
93+
.asciz "int" # DW_AT_name
94+
.byte 5 # DW_AT_encoding
95+
.byte 4 # DW_AT_byte_size
96+
.Latomic_struct:
97+
.byte 3 # Abbrev [3] DW_TAG_atomic_type
98+
.long .Lstruct # DW_AT_type
99+
.Lstruct:
100+
.byte 5 # Abbrev [5] DW_TAG_structure_type
101+
.asciz "struct_type" # DW_AT_name
102+
.byte 0 # DW_AT_byte_size
103+
.byte 0 # End Of Children Mark
104+
.Ldebug_info_end0:

0 commit comments

Comments
 (0)