LLDB mainline
DWARFASTParserFortran.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file implements the DWARF AST parser for the Fortran language.
11///
12//===----------------------------------------------------------------------===//
13
15#include "DWARFDIE.h"
16#include "DWARFDebugInfo.h"
17#include "DWARFDeclContext.h"
18#include "DWARFDefines.h"
19#include "LogChannelDWARF.h"
20#include "SymbolFileDWARF.h"
22#include "UniqueDWARFASTType.h"
23
25#include "lldb/Utility/Log.h"
27
28using namespace lldb;
29using namespace lldb_private;
30using namespace lldb_private::plugin::dwarf;
31using namespace llvm::dwarf;
32
37
39
41 const SymbolContext &sc, const DWARFDIE &die, TypeSP type_sp) {
42 if (!type_sp)
43 return type_sp;
44
46 dw_tag_t sc_parent_tag = sc_parent_die.Tag();
47
48 SymbolContextScope *symbol_context_scope = nullptr;
49 if (sc_parent_tag == DW_TAG_compile_unit ||
50 sc_parent_tag == DW_TAG_partial_unit) {
51 symbol_context_scope = sc.comp_unit;
52 } else if (!sc.function && sc_parent_die) {
53 symbol_context_scope =
54 sc.function->GetBlock(true).FindBlockByID(sc_parent_die.GetID());
55 if (symbol_context_scope == nullptr)
56 symbol_context_scope = sc.function;
57 } else {
58 symbol_context_scope = sc.module_sp.get();
59 }
60
61 if (symbol_context_scope != nullptr)
62 type_sp->SetSymbolContextScope(symbol_context_scope);
63 return type_sp;
64}
65
68 const lldb_private::plugin::dwarf::DWARFDIE &die, bool *type_is_new_ptr) {
69 TypeSP type_sp;
70 if (type_is_new_ptr)
71 *type_is_new_ptr = false;
72
74
75 if (!die)
76 return type_sp;
78 if (log) {
79 dwarf->GetObjectFile()->GetModule()->LogMessage(
80 log,
81 "DWARFASTParserFortran::ParseTypeFromDWARF (die = 0x%8.8x) %s name"
82 "= "
83 "'%s')",
85 die.GetName());
86 }
87
88 Type *type_ptr = dwarf->GetDIEToType().lookup(die.GetDIE());
89
90 if (type_ptr) {
91 if (type_ptr != DIE_IS_BEING_PARSED)
92 return type_ptr->shared_from_this();
93 else
94 return TypeSP();
95 }
96
97 if (type_is_new_ptr)
98 *type_is_new_ptr = true;
99
100 ConstString type_name;
101 const char *type_name_cstr = nullptr;
102 CompilerType compiler_type;
103 DWARFAttributes attributes;
104 DWARFFormValue form_value;
105 Declaration decl;
106 // We use 0x00 as a sentinel value, it doesn't map to any DW_ATE attribute
107 llvm::dwarf::TypeKind encoding = static_cast<llvm::dwarf::TypeKind>(0x00);
108
109 switch (const dw_tag_t tag = die.Tag()) {
110 case DW_TAG_base_type: {
111 dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED;
112 attributes = die.GetAttributes();
113 uint64_t bit_size = 0;
114 for (size_t idx = 0; idx < attributes.Size(); idx++) {
115 if (attributes.ExtractFormValueAtIndex(idx, form_value)) {
116
117 switch (attributes.AttributeAtIndex(idx)) {
118 case DW_AT_name:
119 type_name_cstr = form_value.AsCString();
120
121 if (type_name_cstr && type_name_cstr[0] != '\0')
122 type_name.SetString(llvm::StringRef(type_name_cstr).upper());
123 else
124 type_name.SetCString("UNKNOWN_FORTRAN_TYPE");
125
126 break;
127 case DW_AT_encoding:
128 encoding = static_cast<llvm::dwarf::TypeKind>(form_value.Unsigned());
129 break;
130 case DW_AT_byte_size:
131 bit_size = form_value.Unsigned() * 8;
132 break;
133 case DW_AT_bit_size:
134 bit_size = form_value.Unsigned();
135 break;
136 default:
137 break;
138 }
139 }
140 }
141
142 compiler_type = m_ast.CreateBaseType(encoding, bit_size, type_name);
143 type_sp =
144 dwarf->MakeType(die.GetID(), type_name, llvm::divideCeil(bit_size, 8),
146 compiler_type, Type::ResolveState::Full);
147 break;
148 }
149
150 default:
151 if (log) {
152 dwarf->GetObjectFile()->GetModule()->LogMessage(
153 log, "[{0:x16}]: unhandled type tag {1:x4} ({2})", die.GetOffset(),
154 tag, DW_TAG_value_to_name(tag));
155 }
156
157 break;
158 }
159
160 UpdateSymbolContextScopeForType(sc, die, type_sp);
161 if (type_sp.get())
162 dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
163
164 return type_sp;
165}
166
173
This file defines the DWARF AST parser for the Fortran language.
#define DIE_IS_BEING_PARSED
bool CompleteTypeFromDWARF(const lldb_private::plugin::dwarf::DWARFDIE &die, lldb_private::Type *type, const lldb_private::CompilerType &compiler_type) override
lldb_private::Function * ParseFunctionFromDWARF(lldb_private::CompileUnit &comp_unit, const lldb_private::plugin::dwarf::DWARFDIE &die, lldb_private::AddressRanges ranges) override
DWARFASTParserFortran(lldb_private::TypeSystemFortran &m_ast)
lldb_private::TypeSystemFortran & m_ast
lldb::TypeSP UpdateSymbolContextScopeForType(const lldb_private::SymbolContext &sc, const lldb_private::plugin::dwarf::DWARFDIE &die, lldb::TypeSP type_sp)
If type_sp is valid, calculate and set its symbol context scope, and update the type list for its bac...
lldb::TypeSP ParseTypeFromDWARF(const lldb_private::SymbolContext &sc, const lldb_private::plugin::dwarf::DWARFDIE &die, bool *type_is_new_ptr) override
Block * FindBlockByID(lldb::user_id_t block_id)
Definition Block.cpp:113
A class that describes a compilation unit.
Definition CompileUnit.h:43
Generic representation of a type in a programming language.
A uniqued constant string class.
Definition ConstString.h:40
void SetCString(const char *cstr)
Set the C string value.
void SetString(llvm::StringRef s)
A class that describes the declaration location of a lldb object.
Definition Declaration.h:24
A class that describes a function.
Definition Function.h:386
Block & GetBlock(bool can_create)
Get accessor for the block list.
Definition Function.cpp:401
"lldb/Symbol/SymbolContextScope.h" Inherit from this if your object is part of a symbol context and c...
Defines a symbol context baton that can be handed other debug core functions.
Function * function
The Function for a given query.
lldb::ModuleSP module_sp
The Module for a given query.
CompileUnit * comp_unit
The CompileUnit for a given query.
@ eEncodingIsUID
This type is the type whose UID is m_encoding_uid.
dw_attr_t AttributeAtIndex(uint32_t i) const
bool ExtractFormValueAtIndex(uint32_t i, DWARFFormValue &form_value) const
DWARFAttributes GetAttributes(Recurse recurse=Recurse::yes) const
DWARFDIE GetDIE(dw_offset_t die_offset) const
Definition DWARFDIE.cpp:126
static DWARFDIE GetParentSymbolContextDIE(const DWARFDIE &die)
llvm::dwarf::Tag dw_tag_t
Definition dwarf.h:19
#define LLDB_INVALID_UID
llvm::StringRef DW_TAG_value_to_name(dw_tag_t tag)
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:338
std::shared_ptr< lldb_private::Type > TypeSP