[Lldb-commits] [lldb] d0fb7a4 - [lldb] Support for DWARF-5 atomic types

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Mon Dec 9 01:47:04 PST 2019


Author: Raphael Isemann
Date: 2019-12-09T10:46:26+01:00
New Revision: d0fb7a478df19b78b58bf8778e9f046903115035

URL: https://github.com/llvm/llvm-project/commit/d0fb7a478df19b78b58bf8778e9f046903115035
DIFF: https://github.com/llvm/llvm-project/commit/d0fb7a478df19b78b58bf8778e9f046903115035.diff

LOG: [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

Added: 
    lldb/test/Shell/SymbolFile/DWARF/dwarf5-atomic.s

Modified: 
    lldb/include/lldb/Symbol/ClangASTContext.h
    lldb/include/lldb/Symbol/CompilerType.h
    lldb/include/lldb/Symbol/Type.h
    lldb/include/lldb/Symbol/TypeSystem.h
    lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
    lldb/source/Symbol/ClangASTContext.cpp
    lldb/source/Symbol/CompilerType.cpp
    lldb/source/Symbol/Type.cpp
    lldb/source/Symbol/TypeSystem.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Symbol/ClangASTContext.h b/lldb/include/lldb/Symbol/ClangASTContext.h
index b2c284282f11..f13567e0583c 100644
--- a/lldb/include/lldb/Symbol/ClangASTContext.h
+++ b/lldb/include/lldb/Symbol/ClangASTContext.h
@@ -644,6 +644,8 @@ class ClangASTContext : public TypeSystem {
   CompilerType
   GetRValueReferenceType(lldb::opaque_compiler_type_t type) override;
 
+  CompilerType GetAtomicType(lldb::opaque_compiler_type_t type) override;
+
   CompilerType AddConstModifier(lldb::opaque_compiler_type_t type) override;
 
   CompilerType AddVolatileModifier(lldb::opaque_compiler_type_t type) override;

diff  --git a/lldb/include/lldb/Symbol/CompilerType.h b/lldb/include/lldb/Symbol/CompilerType.h
index 91d9c5e48d20..ee87b53942b7 100644
--- a/lldb/include/lldb/Symbol/CompilerType.h
+++ b/lldb/include/lldb/Symbol/CompilerType.h
@@ -218,6 +218,11 @@ class CompilerType {
   // an invalid type.
   CompilerType AddVolatileModifier() const;
 
+  // Return a new CompilerType that is the atomic type of this type. If this
+  // type is not valid or the type system doesn't support atomic types, this
+  // returns an invalid type.
+  CompilerType GetAtomicType() const;
+
   // Return a new CompilerType adds a restrict modifier to this type if this
   // type is valid and the type system supports restrict modifiers, else return
   // an invalid type.

diff  --git a/lldb/include/lldb/Symbol/Type.h b/lldb/include/lldb/Symbol/Type.h
index ae61f99b4a4b..95a3bc497517 100644
--- a/lldb/include/lldb/Symbol/Type.h
+++ b/lldb/include/lldb/Symbol/Type.h
@@ -80,7 +80,9 @@ class Type : public std::enable_shared_from_this<Type>, public UserID {
     eEncodingIsLValueReferenceUID, ///< This type is L value reference to a type
                                    /// whose UID is m_encoding_uid
     eEncodingIsRValueReferenceUID, ///< This type is R value reference to a type
-                                   /// whose UID is m_encoding_uid
+                                   /// whose UID is m_encoding_uid,
+    eEncodingIsAtomicUID,          ///< This type is the type whose UID is
+                                   /// m_encoding_uid as an atomic type.
     eEncodingIsSyntheticUID
   };
 

diff  --git a/lldb/include/lldb/Symbol/TypeSystem.h b/lldb/include/lldb/Symbol/TypeSystem.h
index ea860647fdb1..5143a53674ab 100644
--- a/lldb/include/lldb/Symbol/TypeSystem.h
+++ b/lldb/include/lldb/Symbol/TypeSystem.h
@@ -228,6 +228,8 @@ class TypeSystem : public PluginInterface {
   virtual CompilerType
   GetRValueReferenceType(lldb::opaque_compiler_type_t type);
 
+  virtual CompilerType GetAtomicType(lldb::opaque_compiler_type_t type);
+
   virtual CompilerType AddConstModifier(lldb::opaque_compiler_type_t type);
 
   virtual CompilerType AddVolatileModifier(lldb::opaque_compiler_type_t type);

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 09f5b28449cb..002d373a5d99 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -474,6 +474,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
   case DW_TAG_const_type:
   case DW_TAG_restrict_type:
   case DW_TAG_volatile_type:
+  case DW_TAG_atomic_type:
   case DW_TAG_unspecified_type: {
     type_sp = ParseTypeModifier(sc, die, attrs);
     break;
@@ -618,6 +619,9 @@ DWARFASTParserClang::ParseTypeModifier(const SymbolContext &sc,
   case DW_TAG_volatile_type:
     encoding_data_type = Type::eEncodingIsVolatileUID;
     break;
+  case DW_TAG_atomic_type:
+    encoding_data_type = Type::eEncodingIsAtomicUID;
+    break;
   }
 
   if (!clang_type && (encoding_data_type == Type::eEncodingIsPointerUID ||

diff  --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp
index cf7f2caa51d2..b765dfb3df36 100644
--- a/lldb/source/Symbol/ClangASTContext.cpp
+++ b/lldb/source/Symbol/ClangASTContext.cpp
@@ -4066,6 +4066,11 @@ ClangASTContext::GetTypeInfo(lldb::opaque_compiler_type_t type,
                                   ->getUnderlyingType()
                                   .getAsOpaquePtr())
         .GetTypeInfo(pointee_or_element_clang_type);
+  case clang::Type::Atomic:
+    return CompilerType(this, llvm::cast<clang::AtomicType>(qual_type)
+                                  ->getValueType()
+                                  .getAsOpaquePtr())
+        .GetTypeInfo(pointee_or_element_clang_type);
   case clang::Type::UnresolvedUsing:
     return 0;
 
@@ -4760,6 +4765,13 @@ ClangASTContext::GetRValueReferenceType(lldb::opaque_compiler_type_t type) {
     return CompilerType();
 }
 
+CompilerType ClangASTContext::GetAtomicType(lldb::opaque_compiler_type_t type) {
+  if (!type)
+    return CompilerType();
+  return CompilerType(
+      this, getASTContext()->getAtomicType(GetQualType(type)).getAsOpaquePtr());
+}
+
 CompilerType
 ClangASTContext::AddConstModifier(lldb::opaque_compiler_type_t type) {
   if (type) {
@@ -5364,6 +5376,11 @@ lldb::Format ClangASTContext::GetFormat(lldb::opaque_compiler_type_t type) {
                                   ->getUnderlyingType()
                                   .getAsOpaquePtr())
         .GetFormat();
+  case clang::Type::Atomic:
+    return CompilerType(this, llvm::cast<clang::AtomicType>(qual_type)
+                                  ->getValueType()
+                                  .getAsOpaquePtr())
+        .GetFormat();
   case clang::Type::DependentSizedArray:
   case clang::Type::DependentSizedExtVector:
   case clang::Type::UnresolvedUsing:
@@ -5379,7 +5396,6 @@ lldb::Format ClangASTContext::GetFormat(lldb::opaque_compiler_type_t type) {
 
   case clang::Type::TemplateSpecialization:
   case clang::Type::DeducedTemplateSpecialization:
-  case clang::Type::Atomic:
   case clang::Type::Adjusted:
   case clang::Type::Pipe:
     break;

diff  --git a/lldb/source/Symbol/CompilerType.cpp b/lldb/source/Symbol/CompilerType.cpp
index d35213120b4d..ba924bf84c01 100644
--- a/lldb/source/Symbol/CompilerType.cpp
+++ b/lldb/source/Symbol/CompilerType.cpp
@@ -427,6 +427,12 @@ CompilerType CompilerType::GetRValueReferenceType() const {
     return CompilerType();
 }
 
+CompilerType CompilerType::GetAtomicType() const {
+  if (IsValid())
+    return m_type_system->GetAtomicType(m_type);
+  return CompilerType();
+}
+
 CompilerType CompilerType::AddConstModifier() const {
   if (IsValid())
     return m_type_system->AddConstModifier(m_type);

diff  --git a/lldb/source/Symbol/Type.cpp b/lldb/source/Symbol/Type.cpp
index 6465ce3dd156..aeca76f7d05f 100644
--- a/lldb/source/Symbol/Type.cpp
+++ b/lldb/source/Symbol/Type.cpp
@@ -213,6 +213,9 @@ void Type::GetDescription(Stream *s, lldb::DescriptionLevel level,
     case eEncodingIsVolatileUID:
       s->PutCString(" (unresolved volatile type)");
       break;
+    case eEncodingIsAtomicUID:
+      s->PutCString(" (unresolved atomic type)");
+      break;
     case eEncodingIsTypedefUID:
       s->PutCString(" (unresolved typedef)");
       break;
@@ -271,6 +274,9 @@ void Type::Dump(Stream *s, bool show_context) {
     case eEncodingIsVolatileUID:
       s->PutCString(" (unresolved volatile type)");
       break;
+    case eEncodingIsAtomicUID:
+      s->PutCString(" (unresolved atomic type)");
+      break;
     case eEncodingIsTypedefUID:
       s->PutCString(" (unresolved typedef)");
       break;
@@ -343,6 +349,7 @@ llvm::Optional<uint64_t> Type::GetByteSize() {
   case eEncodingIsConstUID:
   case eEncodingIsRestrictUID:
   case eEncodingIsVolatileUID:
+  case eEncodingIsAtomicUID:
   case eEncodingIsTypedefUID: {
     Type *encoding_type = GetEncodingType();
     if (encoding_type)
@@ -491,6 +498,11 @@ bool Type::ResolveClangType(ResolveState compiler_type_resolve_state) {
             encoding_type->GetForwardCompilerType().AddVolatileModifier();
         break;
 
+      case eEncodingIsAtomicUID:
+        m_compiler_type =
+            encoding_type->GetForwardCompilerType().GetAtomicType();
+        break;
+
       case eEncodingIsTypedefUID:
         m_compiler_type = encoding_type->GetForwardCompilerType().CreateTypedef(
             m_name.AsCString("__lldb_invalid_typedef_name"),
@@ -545,6 +557,10 @@ bool Type::ResolveClangType(ResolveState compiler_type_resolve_state) {
           m_compiler_type = void_compiler_type.AddVolatileModifier();
           break;
 
+        case eEncodingIsAtomicUID:
+          m_compiler_type = void_compiler_type.GetAtomicType();
+          break;
+
         case eEncodingIsTypedefUID:
           m_compiler_type = void_compiler_type.CreateTypedef(
               m_name.AsCString("__lldb_invalid_typedef_name"),

diff  --git a/lldb/source/Symbol/TypeSystem.cpp b/lldb/source/Symbol/TypeSystem.cpp
index 4e746bd18e1f..29a49a6fb1d4 100644
--- a/lldb/source/Symbol/TypeSystem.cpp
+++ b/lldb/source/Symbol/TypeSystem.cpp
@@ -89,6 +89,10 @@ TypeSystem::GetRValueReferenceType(lldb::opaque_compiler_type_t type) {
   return CompilerType();
 }
 
+CompilerType TypeSystem::GetAtomicType(lldb::opaque_compiler_type_t type) {
+  return CompilerType();
+}
+
 CompilerType TypeSystem::AddConstModifier(lldb::opaque_compiler_type_t type) {
   return CompilerType();
 }

diff  --git a/lldb/test/Shell/SymbolFile/DWARF/dwarf5-atomic.s b/lldb/test/Shell/SymbolFile/DWARF/dwarf5-atomic.s
new file mode 100644
index 000000000000..9d25956c0dfe
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/DWARF/dwarf5-atomic.s
@@ -0,0 +1,104 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -triple=x86_64-pc-linux -filetype=obj %s > %t
+# RUN: %lldb %t -o "target variable integer structure" -o exit | FileCheck %s
+
+# CHECK: (_Atomic(int)) integer = 14159
+# CHECK: (_Atomic(struct_type)) structure = {}
+
+        .data
+integer:
+        .long 14159
+structure:
+        .byte 0
+
+        .section        .debug_abbrev,"", at progbits
+        .byte   1                       # Abbreviation Code
+        .byte   17                      # DW_TAG_compile_unit
+        .byte   1                       # DW_CHILDREN_yes
+        .byte   37                      # DW_AT_producer
+        .byte   8                       # DW_FORM_string
+        .byte   19                      # DW_AT_language
+        .byte   5                       # DW_FORM_data2
+        .byte   0                       # EOM(1)
+        .byte   0                       # EOM(2)
+        .byte   2                       # Abbreviation Code
+        .byte   52                      # DW_TAG_variable
+        .byte   0                       # DW_CHILDREN_no
+        .byte   3                       # DW_AT_name
+        .byte   8                       # DW_FORM_string
+        .byte   73                      # DW_AT_type
+        .byte   19                      # DW_FORM_ref4
+        .byte   2                       # DW_AT_location
+        .byte   24                      # DW_FORM_exprloc
+        .byte   0                       # EOM(1)
+        .byte   0                       # EOM(2)
+        .byte   3                       # Abbreviation Code
+        .byte   71                      # DW_TAG_atomic_type
+        .byte   0                       # DW_CHILDREN_no
+        .byte   73                      # DW_AT_type
+        .byte   19                      # DW_FORM_ref4
+        .byte   0                       # EOM(1)
+        .byte   0                       # EOM(2)
+        .byte   4                       # Abbreviation Code
+        .byte   36                      # DW_TAG_base_type
+        .byte   0                       # DW_CHILDREN_no
+        .byte   3                       # DW_AT_name
+        .byte   8                       # DW_FORM_string
+        .byte   62                      # DW_AT_encoding
+        .byte   11                      # DW_FORM_data1
+        .byte   11                      # DW_AT_byte_size
+        .byte   11                      # DW_FORM_data1
+        .byte   0                       # EOM(1)
+        .byte   0                       # EOM(2)
+        .byte   5                       # Abbreviation Code
+        .byte   19                      # DW_TAG_structure_type
+        .byte   0                       # DW_CHILDREN_no
+        .byte   3                       # DW_AT_name
+        .byte   8                       # DW_FORM_string
+        .byte   11                      # DW_AT_byte_size
+        .byte   11                      # DW_FORM_data1
+        .byte   0                       # EOM(1)
+        .byte   0                       # EOM(2)
+        .byte   0                       # EOM(3)
+
+        .section        .debug_info,"", at progbits
+.Lcu_begin0:
+        .long   .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
+.Ldebug_info_start0:
+        .short  5                       # DWARF version number
+        .byte   1                       # DWARF Unit Type
+        .byte   8                       # Address Size (in bytes)
+        .long   .debug_abbrev           # Offset Into Abbrev. Section
+        .byte   1                       # Abbrev [1] 0xb:0x50 DW_TAG_compile_unit
+        .asciz  "Hand-written DWARF"    # DW_AT_producer
+        .short  12                      # DW_AT_language
+        .byte   2                       # Abbrev [2] DW_TAG_variable
+        .asciz  "integer"               # DW_AT_name
+        .long   .Latomic_int            # DW_AT_type
+        .byte   9                       # DW_AT_location
+        .byte   3
+        .quad   integer
+        .byte   2                       # Abbrev [2] DW_TAG_variable
+        .asciz  "structure"             # DW_AT_name
+        .long   .Latomic_struct         # DW_AT_type
+        .byte   9                       # DW_AT_location
+        .byte   3
+        .quad   structure
+.Latomic_int:
+        .byte   3                       # Abbrev [3] DW_TAG_atomic_type
+        .long   .Lint                   # DW_AT_type
+.Lint:
+        .byte   4                       # Abbrev [4] 0x53:0x7 DW_TAG_base_type
+        .asciz  "int"                   # DW_AT_name
+        .byte   5                       # DW_AT_encoding
+        .byte   4                       # DW_AT_byte_size
+.Latomic_struct:
+        .byte   3                       # Abbrev [3] DW_TAG_atomic_type
+        .long   .Lstruct                # DW_AT_type
+.Lstruct:
+        .byte   5                       # Abbrev [5] DW_TAG_structure_type
+        .asciz  "struct_type"           # DW_AT_name
+        .byte   0                       # DW_AT_byte_size
+        .byte   0                       # End Of Children Mark
+.Ldebug_info_end0:


        


More information about the lldb-commits mailing list