| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1 | //===-- DWARFASTParserClang.cpp ---------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "DWARFASTParserClang.h" |
| 11 | #include "DWARFCompileUnit.h" |
| 12 | #include "DWARFDebugInfo.h" |
| 13 | #include "DWARFDeclContext.h" |
| 14 | #include "DWARFDefines.h" |
| 15 | #include "DWARFDIE.h" |
| 16 | #include "DWARFDIECollection.h" |
| 17 | #include "SymbolFileDWARF.h" |
| 18 | #include "SymbolFileDWARFDebugMap.h" |
| 19 | #include "UniqueDWARFASTType.h" |
| 20 | |
| Jim Ingham | aa816b8 | 2015-09-02 01:59:14 +0000 | [diff] [blame] | 21 | #include "lldb/Interpreter/Args.h" |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 22 | #include "lldb/Core/Log.h" |
| 23 | #include "lldb/Core/Module.h" |
| Jim Ingham | aa816b8 | 2015-09-02 01:59:14 +0000 | [diff] [blame] | 24 | #include "lldb/Core/StreamString.h" |
| 25 | #include "lldb/Core/Value.h" |
| 26 | #include "lldb/Host/Host.h" |
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 27 | #include "lldb/Symbol/ClangASTImporter.h" |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 28 | #include "lldb/Symbol/ClangExternalASTSourceCommon.h" |
| 29 | #include "lldb/Symbol/CompileUnit.h" |
| 30 | #include "lldb/Symbol/Function.h" |
| 31 | #include "lldb/Symbol/ObjectFile.h" |
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 32 | #include "lldb/Symbol/SymbolVendor.h" |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 33 | #include "lldb/Symbol/TypeList.h" |
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 34 | #include "lldb/Symbol/TypeMap.h" |
| Jim Ingham | 0e0984e | 2015-09-02 01:06:46 +0000 | [diff] [blame] | 35 | #include "lldb/Target/Language.h" |
| Jim Ingham | aa816b8 | 2015-09-02 01:59:14 +0000 | [diff] [blame] | 36 | #include "Plugins/Language/ObjC/ObjCLanguage.h" |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 37 | |
| 38 | #include "clang/AST/DeclCXX.h" |
| 39 | #include "clang/AST/DeclObjC.h" |
| 40 | |
| Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 41 | #include <map> |
| 42 | #include <vector> |
| 43 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 44 | //#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN |
| 45 | |
| 46 | #ifdef ENABLE_DEBUG_PRINTF |
| 47 | #include <stdio.h> |
| 48 | #define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__) |
| 49 | #else |
| 50 | #define DEBUG_PRINTF(fmt, ...) |
| 51 | #endif |
| 52 | |
| 53 | |
| 54 | using namespace lldb; |
| 55 | using namespace lldb_private; |
| 56 | DWARFASTParserClang::DWARFASTParserClang (ClangASTContext &ast) : |
| 57 | m_ast (ast), |
| 58 | m_die_to_decl_ctx (), |
| 59 | m_decl_ctx_to_die () |
| 60 | { |
| 61 | } |
| 62 | |
| 63 | DWARFASTParserClang::~DWARFASTParserClang () |
| 64 | { |
| 65 | } |
| 66 | |
| 67 | |
| 68 | static AccessType |
| 69 | DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility) |
| 70 | { |
| 71 | switch (dwarf_accessibility) |
| 72 | { |
| 73 | case DW_ACCESS_public: return eAccessPublic; |
| 74 | case DW_ACCESS_private: return eAccessPrivate; |
| 75 | case DW_ACCESS_protected: return eAccessProtected; |
| 76 | default: break; |
| 77 | } |
| 78 | return eAccessNone; |
| 79 | } |
| 80 | |
| 81 | static bool |
| 82 | DeclKindIsCXXClass (clang::Decl::Kind decl_kind) |
| 83 | { |
| 84 | switch (decl_kind) |
| 85 | { |
| 86 | case clang::Decl::CXXRecord: |
| 87 | case clang::Decl::ClassTemplateSpecialization: |
| 88 | return true; |
| 89 | default: |
| 90 | break; |
| 91 | } |
| 92 | return false; |
| 93 | } |
| 94 | |
| 95 | struct BitfieldInfo |
| 96 | { |
| 97 | uint64_t bit_size; |
| 98 | uint64_t bit_offset; |
| 99 | |
| 100 | BitfieldInfo () : |
| 101 | bit_size (LLDB_INVALID_ADDRESS), |
| 102 | bit_offset (LLDB_INVALID_ADDRESS) |
| 103 | { |
| 104 | } |
| 105 | |
| 106 | void |
| 107 | Clear() |
| 108 | { |
| 109 | bit_size = LLDB_INVALID_ADDRESS; |
| 110 | bit_offset = LLDB_INVALID_ADDRESS; |
| 111 | } |
| 112 | |
| 113 | bool IsValid () |
| 114 | { |
| 115 | return (bit_size != LLDB_INVALID_ADDRESS) && |
| 116 | (bit_offset != LLDB_INVALID_ADDRESS); |
| 117 | } |
| 118 | }; |
| 119 | |
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 120 | |
| 121 | ClangASTImporter & |
| 122 | DWARFASTParserClang::GetClangASTImporter() |
| 123 | { |
| 124 | if (!m_clang_ast_importer_ap) |
| 125 | { |
| 126 | m_clang_ast_importer_ap.reset (new ClangASTImporter); |
| 127 | } |
| 128 | return *m_clang_ast_importer_ap; |
| 129 | } |
| 130 | |
| 131 | |
| 132 | TypeSP |
| 133 | DWARFASTParserClang::ParseTypeFromDWO (const DWARFDIE &die, Log *log) |
| 134 | { |
| 135 | ModuleSP dwo_module_sp = die.GetContainingDWOModule(); |
| 136 | if (dwo_module_sp) |
| 137 | { |
| 138 | // This type comes from an external DWO module |
| 139 | std::vector<CompilerContext> dwo_context; |
| 140 | die.GetDWOContext(dwo_context); |
| 141 | TypeMap dwo_types; |
| 142 | if (dwo_module_sp->GetSymbolVendor()->FindTypes(dwo_context, true, dwo_types)) |
| 143 | { |
| 144 | const size_t num_dwo_types = dwo_types.GetSize(); |
| 145 | if (num_dwo_types == 1) |
| 146 | { |
| 147 | // We found a real definition for this type elsewhere |
| 148 | // so lets use it and cache the fact that we found |
| 149 | // a complete type for this die |
| 150 | TypeSP dwo_type_sp = dwo_types.GetTypeAtIndex(0); |
| 151 | if (dwo_type_sp) |
| 152 | { |
| 153 | lldb_private::CompilerType dwo_type = dwo_type_sp->GetForwardCompilerType(); |
| 154 | |
| 155 | lldb_private::CompilerType type = GetClangASTImporter().CopyType (m_ast, dwo_type); |
| 156 | |
| 157 | //printf ("copied_qual_type: ast = %p, clang_type = %p, name = '%s'\n", m_ast, copied_qual_type.getAsOpaquePtr(), external_type->GetName().GetCString()); |
| 158 | if (type) |
| 159 | { |
| 160 | SymbolFileDWARF *dwarf = die.GetDWARF(); |
| 161 | TypeSP type_sp (new Type (die.GetID(), |
| 162 | dwarf, |
| 163 | dwo_type_sp->GetName(), |
| 164 | dwo_type_sp->GetByteSize(), |
| 165 | NULL, |
| 166 | LLDB_INVALID_UID, |
| 167 | Type::eEncodingInvalid, |
| 168 | &dwo_type_sp->GetDeclaration(), |
| 169 | type, |
| 170 | Type::eResolveStateForward)); |
| 171 | |
| 172 | dwarf->GetTypeList()->Insert(type_sp); |
| 173 | dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); |
| 174 | clang::TagDecl *tag_decl = ClangASTContext::GetAsTagDecl(type); |
| 175 | if (tag_decl) |
| 176 | LinkDeclContextToDIE(tag_decl, die); |
| 177 | else |
| 178 | { |
| 179 | clang::DeclContext *defn_decl_ctx = GetCachedClangDeclContextForDIE(die); |
| 180 | if (defn_decl_ctx) |
| 181 | LinkDeclContextToDIE(defn_decl_ctx, die); |
| 182 | } |
| 183 | return type_sp; |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | return TypeSP(); |
| 190 | } |
| 191 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 192 | TypeSP |
| 193 | DWARFASTParserClang::ParseTypeFromDWARF (const SymbolContext& sc, |
| 194 | const DWARFDIE &die, |
| 195 | Log *log, |
| 196 | bool *type_is_new_ptr) |
| 197 | { |
| 198 | TypeSP type_sp; |
| 199 | |
| 200 | if (type_is_new_ptr) |
| 201 | *type_is_new_ptr = false; |
| 202 | |
| 203 | AccessType accessibility = eAccessNone; |
| 204 | if (die) |
| 205 | { |
| 206 | SymbolFileDWARF *dwarf = die.GetDWARF(); |
| 207 | if (log) |
| 208 | { |
| 209 | DWARFDIE context_die; |
| 210 | clang::DeclContext *context = GetClangDeclContextContainingDIE (die, &context_die); |
| 211 | |
| 212 | dwarf->GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x, decl_ctx = %p (die 0x%8.8x)) %s name = '%s')", |
| 213 | die.GetOffset(), |
| 214 | static_cast<void*>(context), |
| 215 | context_die.GetOffset(), |
| 216 | die.GetTagAsCString(), |
| 217 | die.GetName()); |
| 218 | |
| 219 | } |
| 220 | // |
| 221 | // Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 222 | // if (log && dwarf_cu) |
| 223 | // { |
| 224 | // StreamString s; |
| 225 | // die->DumpLocation (this, dwarf_cu, s); |
| 226 | // dwarf->GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData()); |
| 227 | // |
| 228 | // } |
| 229 | |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 230 | Type *type_ptr = dwarf->GetDIEToType().lookup (die.GetDIE()); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 231 | TypeList* type_list = dwarf->GetTypeList(); |
| 232 | if (type_ptr == NULL) |
| 233 | { |
| 234 | if (type_is_new_ptr) |
| 235 | *type_is_new_ptr = true; |
| 236 | |
| 237 | const dw_tag_t tag = die.Tag(); |
| 238 | |
| 239 | bool is_forward_declaration = false; |
| 240 | DWARFAttributes attributes; |
| 241 | const char *type_name_cstr = NULL; |
| 242 | ConstString type_name_const_str; |
| 243 | Type::ResolveState resolve_state = Type::eResolveStateUnresolved; |
| 244 | uint64_t byte_size = 0; |
| 245 | Declaration decl; |
| 246 | |
| 247 | Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID; |
| 248 | CompilerType clang_type; |
| 249 | DWARFFormValue form_value; |
| 250 | |
| 251 | dw_attr_t attr; |
| 252 | |
| 253 | switch (tag) |
| 254 | { |
| Greg Clayton | a5d1f62 | 2016-01-21 22:26:13 +0000 | [diff] [blame] | 255 | case DW_TAG_typedef: |
| 256 | // Try to parse a typedef from the DWO file first as modules |
| 257 | // can contain typedef'ed structures that have no names like: |
| 258 | // |
| 259 | // typedef struct { int a; } Foo; |
| 260 | // |
| 261 | // In this case we will have a structure with no name and a |
| 262 | // typedef named "Foo" that points to this unnamed structure. |
| 263 | // The name in the typedef is the only identifier for the struct, |
| 264 | // so always try to get typedefs from DWO files if possible. |
| 265 | // |
| 266 | // The type_sp returned will be empty if the typedef doesn't exist |
| 267 | // in a DWO file, so it is cheap to call this function just to check. |
| 268 | // |
| 269 | // If we don't do this we end up creating a TypeSP that says this |
| 270 | // is a typedef to type 0x123 (the DW_AT_type value would be 0x123 |
| 271 | // in the DW_TAG_typedef), and this is the unnamed structure type. |
| 272 | // We will have a hard time tracking down an unnammed structure |
| 273 | // type in the module DWO file, so we make sure we don't get into |
| 274 | // this situation by always resolving typedefs from the DWO file. |
| 275 | type_sp = ParseTypeFromDWO(die, log); |
| 276 | if (type_sp) |
| 277 | return type_sp; |
| 278 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 279 | case DW_TAG_base_type: |
| 280 | case DW_TAG_pointer_type: |
| 281 | case DW_TAG_reference_type: |
| 282 | case DW_TAG_rvalue_reference_type: |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 283 | case DW_TAG_const_type: |
| 284 | case DW_TAG_restrict_type: |
| 285 | case DW_TAG_volatile_type: |
| 286 | case DW_TAG_unspecified_type: |
| 287 | { |
| 288 | // Set a bit that lets us know that we are currently parsing this |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 289 | dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 290 | |
| 291 | const size_t num_attributes = die.GetAttributes (attributes); |
| 292 | uint32_t encoding = 0; |
| 293 | lldb::user_id_t encoding_uid = LLDB_INVALID_UID; |
| 294 | |
| 295 | if (num_attributes > 0) |
| 296 | { |
| 297 | uint32_t i; |
| 298 | for (i=0; i<num_attributes; ++i) |
| 299 | { |
| 300 | attr = attributes.AttributeAtIndex(i); |
| 301 | if (attributes.ExtractFormValueAtIndex(i, form_value)) |
| 302 | { |
| 303 | switch (attr) |
| 304 | { |
| 305 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 306 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 307 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 308 | case DW_AT_name: |
| 309 | |
| 310 | type_name_cstr = form_value.AsCString(); |
| 311 | // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't |
| 312 | // include the "&"... |
| 313 | if (tag == DW_TAG_reference_type) |
| 314 | { |
| 315 | if (strchr (type_name_cstr, '&') == NULL) |
| 316 | type_name_cstr = NULL; |
| 317 | } |
| 318 | if (type_name_cstr) |
| 319 | type_name_const_str.SetCString(type_name_cstr); |
| 320 | break; |
| 321 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; |
| 322 | case DW_AT_encoding: encoding = form_value.Unsigned(); break; |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 323 | case DW_AT_type: encoding_uid = DIERef(form_value).GetUID(); break; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 324 | default: |
| 325 | case DW_AT_sibling: |
| 326 | break; |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\") type => 0x%8.8lx\n", die.GetID(), DW_TAG_value_to_name(tag), type_name_cstr, encoding_uid); |
| 333 | |
| 334 | switch (tag) |
| 335 | { |
| 336 | default: |
| 337 | break; |
| 338 | |
| 339 | case DW_TAG_unspecified_type: |
| 340 | if (strcmp(type_name_cstr, "nullptr_t") == 0 || |
| 341 | strcmp(type_name_cstr, "decltype(nullptr)") == 0 ) |
| 342 | { |
| 343 | resolve_state = Type::eResolveStateFull; |
| 344 | clang_type = m_ast.GetBasicType(eBasicTypeNullPtr); |
| 345 | break; |
| 346 | } |
| 347 | // Fall through to base type below in case we can handle the type there... |
| 348 | |
| 349 | case DW_TAG_base_type: |
| 350 | resolve_state = Type::eResolveStateFull; |
| 351 | clang_type = m_ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr, |
| 352 | encoding, |
| 353 | byte_size * 8); |
| 354 | break; |
| 355 | |
| 356 | case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break; |
| 357 | case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break; |
| 358 | case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break; |
| 359 | case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break; |
| 360 | case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break; |
| 361 | case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break; |
| 362 | case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break; |
| 363 | } |
| 364 | |
| 365 | if (!clang_type && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID) && sc.comp_unit != NULL) |
| 366 | { |
| 367 | bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus); |
| 368 | |
| 369 | if (translation_unit_is_objc) |
| 370 | { |
| 371 | if (type_name_cstr != NULL) |
| 372 | { |
| 373 | static ConstString g_objc_type_name_id("id"); |
| 374 | static ConstString g_objc_type_name_Class("Class"); |
| 375 | static ConstString g_objc_type_name_selector("SEL"); |
| 376 | |
| 377 | if (type_name_const_str == g_objc_type_name_id) |
| 378 | { |
| 379 | if (log) |
| 380 | dwarf->GetObjectFile()->GetModule()->LogMessage (log, |
| 381 | "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'id' built-in type.", |
| 382 | die.GetOffset(), |
| 383 | die.GetTagAsCString(), |
| 384 | die.GetName()); |
| 385 | clang_type = m_ast.GetBasicType(eBasicTypeObjCID); |
| 386 | encoding_data_type = Type::eEncodingIsUID; |
| 387 | encoding_uid = LLDB_INVALID_UID; |
| 388 | resolve_state = Type::eResolveStateFull; |
| 389 | |
| 390 | } |
| 391 | else if (type_name_const_str == g_objc_type_name_Class) |
| 392 | { |
| 393 | if (log) |
| 394 | dwarf->GetObjectFile()->GetModule()->LogMessage (log, |
| 395 | "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'Class' built-in type.", |
| 396 | die.GetOffset(), |
| 397 | die.GetTagAsCString(), |
| 398 | die.GetName()); |
| 399 | clang_type = m_ast.GetBasicType(eBasicTypeObjCClass); |
| 400 | encoding_data_type = Type::eEncodingIsUID; |
| 401 | encoding_uid = LLDB_INVALID_UID; |
| 402 | resolve_state = Type::eResolveStateFull; |
| 403 | } |
| 404 | else if (type_name_const_str == g_objc_type_name_selector) |
| 405 | { |
| 406 | if (log) |
| 407 | dwarf->GetObjectFile()->GetModule()->LogMessage (log, |
| 408 | "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.", |
| 409 | die.GetOffset(), |
| 410 | die.GetTagAsCString(), |
| 411 | die.GetName()); |
| 412 | clang_type = m_ast.GetBasicType(eBasicTypeObjCSel); |
| 413 | encoding_data_type = Type::eEncodingIsUID; |
| 414 | encoding_uid = LLDB_INVALID_UID; |
| 415 | resolve_state = Type::eResolveStateFull; |
| 416 | } |
| 417 | } |
| 418 | else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID) |
| 419 | { |
| 420 | // Clang sometimes erroneously emits id as objc_object*. In that case we fix up the type to "id". |
| 421 | |
| 422 | const DWARFDIE encoding_die = die.GetDIE(encoding_uid); |
| 423 | |
| 424 | if (encoding_die && encoding_die.Tag() == DW_TAG_structure_type) |
| 425 | { |
| 426 | if (const char *struct_name = encoding_die.GetName()) |
| 427 | { |
| 428 | if (!strcmp(struct_name, "objc_object")) |
| 429 | { |
| 430 | if (log) |
| 431 | dwarf->GetObjectFile()->GetModule()->LogMessage (log, |
| 432 | "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is 'objc_object*', which we overrode to 'id'.", |
| 433 | die.GetOffset(), |
| 434 | die.GetTagAsCString(), |
| 435 | die.GetName()); |
| 436 | clang_type = m_ast.GetBasicType(eBasicTypeObjCID); |
| 437 | encoding_data_type = Type::eEncodingIsUID; |
| 438 | encoding_uid = LLDB_INVALID_UID; |
| 439 | resolve_state = Type::eResolveStateFull; |
| 440 | } |
| 441 | } |
| 442 | } |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | type_sp.reset( new Type (die.GetID(), |
| 448 | dwarf, |
| 449 | type_name_const_str, |
| 450 | byte_size, |
| 451 | NULL, |
| 452 | encoding_uid, |
| 453 | encoding_data_type, |
| 454 | &decl, |
| 455 | clang_type, |
| 456 | resolve_state)); |
| 457 | |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 458 | dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 459 | |
| 460 | // Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false); |
| 461 | // if (encoding_type != NULL) |
| 462 | // { |
| 463 | // if (encoding_type != DIE_IS_BEING_PARSED) |
| 464 | // type_sp->SetEncodingType(encoding_type); |
| 465 | // else |
| 466 | // m_indirect_fixups.push_back(type_sp.get()); |
| 467 | // } |
| 468 | } |
| 469 | break; |
| 470 | |
| 471 | case DW_TAG_structure_type: |
| 472 | case DW_TAG_union_type: |
| 473 | case DW_TAG_class_type: |
| 474 | { |
| 475 | // Set a bit that lets us know that we are currently parsing this |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 476 | dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 477 | bool byte_size_valid = false; |
| 478 | |
| 479 | LanguageType class_language = eLanguageTypeUnknown; |
| 480 | bool is_complete_objc_class = false; |
| 481 | //bool struct_is_class = false; |
| 482 | const size_t num_attributes = die.GetAttributes (attributes); |
| 483 | if (num_attributes > 0) |
| 484 | { |
| 485 | uint32_t i; |
| 486 | for (i=0; i<num_attributes; ++i) |
| 487 | { |
| 488 | attr = attributes.AttributeAtIndex(i); |
| 489 | if (attributes.ExtractFormValueAtIndex(i, form_value)) |
| 490 | { |
| 491 | switch (attr) |
| 492 | { |
| 493 | case DW_AT_decl_file: |
| 494 | if (die.GetCU()->DW_AT_decl_file_attributes_are_invalid()) |
| 495 | { |
| 496 | // llvm-gcc outputs invalid DW_AT_decl_file attributes that always |
| 497 | // point to the compile unit file, so we clear this invalid value |
| 498 | // so that we can still unique types efficiently. |
| 499 | decl.SetFile(FileSpec ("<invalid>", false)); |
| 500 | } |
| 501 | else |
| 502 | decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); |
| 503 | break; |
| 504 | |
| 505 | case DW_AT_decl_line: |
| 506 | decl.SetLine(form_value.Unsigned()); |
| 507 | break; |
| 508 | |
| 509 | case DW_AT_decl_column: |
| 510 | decl.SetColumn(form_value.Unsigned()); |
| 511 | break; |
| 512 | |
| 513 | case DW_AT_name: |
| 514 | type_name_cstr = form_value.AsCString(); |
| 515 | type_name_const_str.SetCString(type_name_cstr); |
| 516 | break; |
| 517 | |
| 518 | case DW_AT_byte_size: |
| 519 | byte_size = form_value.Unsigned(); |
| 520 | byte_size_valid = true; |
| 521 | break; |
| 522 | |
| 523 | case DW_AT_accessibility: |
| 524 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); |
| 525 | break; |
| 526 | |
| 527 | case DW_AT_declaration: |
| 528 | is_forward_declaration = form_value.Boolean(); |
| 529 | break; |
| 530 | |
| 531 | case DW_AT_APPLE_runtime_class: |
| 532 | class_language = (LanguageType)form_value.Signed(); |
| 533 | break; |
| 534 | |
| 535 | case DW_AT_APPLE_objc_complete_type: |
| 536 | is_complete_objc_class = form_value.Signed(); |
| 537 | break; |
| 538 | |
| 539 | case DW_AT_allocated: |
| 540 | case DW_AT_associated: |
| 541 | case DW_AT_data_location: |
| 542 | case DW_AT_description: |
| 543 | case DW_AT_start_scope: |
| 544 | case DW_AT_visibility: |
| 545 | default: |
| 546 | case DW_AT_sibling: |
| 547 | break; |
| 548 | } |
| 549 | } |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | // UniqueDWARFASTType is large, so don't create a local variables on the |
| 554 | // stack, put it on the heap. This function is often called recursively |
| 555 | // and clang isn't good and sharing the stack space for variables in different blocks. |
| 556 | std::unique_ptr<UniqueDWARFASTType> unique_ast_entry_ap(new UniqueDWARFASTType()); |
| 557 | |
| Greg Clayton | fb85e62 | 2016-02-09 22:36:24 +0000 | [diff] [blame^] | 558 | ConstString unique_typename(type_name_const_str); |
| 559 | Declaration unique_decl(decl); |
| 560 | |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 561 | if (type_name_const_str) |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 562 | { |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 563 | LanguageType die_language = die.GetLanguage(); |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 564 | if (Language::LanguageIsCPlusPlus(die_language)) |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 565 | { |
| Greg Clayton | fb85e62 | 2016-02-09 22:36:24 +0000 | [diff] [blame^] | 566 | // For C++, we rely solely upon the one definition rule that says only |
| 567 | // one thing can exist at a given decl context. We ignore the file and |
| 568 | // line that things are declared on. |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 569 | std::string qualified_name; |
| 570 | if (die.GetQualifiedName(qualified_name)) |
| Greg Clayton | fb85e62 | 2016-02-09 22:36:24 +0000 | [diff] [blame^] | 571 | unique_typename = ConstString(qualified_name); |
| 572 | unique_decl.Clear(); |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 573 | } |
| 574 | |
| Greg Clayton | fb85e62 | 2016-02-09 22:36:24 +0000 | [diff] [blame^] | 575 | if (dwarf->GetUniqueDWARFASTTypeMap().Find(unique_typename, die, unique_decl, |
| 576 | byte_size_valid ? byte_size : -1, |
| 577 | *unique_ast_entry_ap)) |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 578 | { |
| Greg Clayton | fb85e62 | 2016-02-09 22:36:24 +0000 | [diff] [blame^] | 579 | type_sp = unique_ast_entry_ap->m_type_sp; |
| 580 | if (type_sp) |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 581 | { |
| Greg Clayton | fb85e62 | 2016-02-09 22:36:24 +0000 | [diff] [blame^] | 582 | dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); |
| 583 | return type_sp; |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 584 | } |
| 585 | } |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(), DW_TAG_value_to_name(tag), type_name_cstr); |
| 589 | |
| 590 | int tag_decl_kind = -1; |
| 591 | AccessType default_accessibility = eAccessNone; |
| 592 | if (tag == DW_TAG_structure_type) |
| 593 | { |
| 594 | tag_decl_kind = clang::TTK_Struct; |
| 595 | default_accessibility = eAccessPublic; |
| 596 | } |
| 597 | else if (tag == DW_TAG_union_type) |
| 598 | { |
| 599 | tag_decl_kind = clang::TTK_Union; |
| 600 | default_accessibility = eAccessPublic; |
| 601 | } |
| 602 | else if (tag == DW_TAG_class_type) |
| 603 | { |
| 604 | tag_decl_kind = clang::TTK_Class; |
| 605 | default_accessibility = eAccessPrivate; |
| 606 | } |
| 607 | |
| 608 | if (byte_size_valid && byte_size == 0 && type_name_cstr && |
| 609 | die.HasChildren() == false && |
| 610 | sc.comp_unit->GetLanguage() == eLanguageTypeObjC) |
| 611 | { |
| 612 | // Work around an issue with clang at the moment where |
| 613 | // forward declarations for objective C classes are emitted |
| 614 | // as: |
| 615 | // DW_TAG_structure_type [2] |
| 616 | // DW_AT_name( "ForwardObjcClass" ) |
| 617 | // DW_AT_byte_size( 0x00 ) |
| 618 | // DW_AT_decl_file( "..." ) |
| 619 | // DW_AT_decl_line( 1 ) |
| 620 | // |
| 621 | // Note that there is no DW_AT_declaration and there are |
| 622 | // no children, and the byte size is zero. |
| 623 | is_forward_declaration = true; |
| 624 | } |
| 625 | |
| 626 | if (class_language == eLanguageTypeObjC || |
| 627 | class_language == eLanguageTypeObjC_plus_plus) |
| 628 | { |
| 629 | if (!is_complete_objc_class && die.Supports_DW_AT_APPLE_objc_complete_type()) |
| 630 | { |
| 631 | // We have a valid eSymbolTypeObjCClass class symbol whose |
| 632 | // name matches the current objective C class that we |
| 633 | // are trying to find and this DIE isn't the complete |
| 634 | // definition (we checked is_complete_objc_class above and |
| 635 | // know it is false), so the real definition is in here somewhere |
| 636 | type_sp = dwarf->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true); |
| 637 | |
| 638 | if (!type_sp) |
| 639 | { |
| 640 | SymbolFileDWARFDebugMap *debug_map_symfile = dwarf->GetDebugMapSymfile(); |
| 641 | if (debug_map_symfile) |
| 642 | { |
| 643 | // We weren't able to find a full declaration in |
| 644 | // this DWARF, see if we have a declaration anywhere |
| 645 | // else... |
| 646 | type_sp = debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true); |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | if (type_sp) |
| 651 | { |
| 652 | if (log) |
| 653 | { |
| 654 | dwarf->GetObjectFile()->GetModule()->LogMessage (log, |
| 655 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8" PRIx64, |
| 656 | static_cast<void*>(this), |
| 657 | die.GetOffset(), |
| 658 | DW_TAG_value_to_name(tag), |
| 659 | type_name_cstr, |
| 660 | type_sp->GetID()); |
| 661 | } |
| 662 | |
| 663 | // We found a real definition for this type elsewhere |
| 664 | // so lets use it and cache the fact that we found |
| 665 | // a complete type for this die |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 666 | dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 667 | return type_sp; |
| 668 | } |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | |
| 673 | if (is_forward_declaration) |
| 674 | { |
| 675 | // We have a forward declaration to a type and we need |
| 676 | // to try and find a full declaration. We look in the |
| 677 | // current type index just in case we have a forward |
| 678 | // declaration followed by an actual declarations in the |
| 679 | // DWARF. If this fails, we need to look elsewhere... |
| 680 | if (log) |
| 681 | { |
| 682 | dwarf->GetObjectFile()->GetModule()->LogMessage (log, |
| 683 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type", |
| 684 | static_cast<void*>(this), |
| 685 | die.GetOffset(), |
| 686 | DW_TAG_value_to_name(tag), |
| 687 | type_name_cstr); |
| 688 | } |
| 689 | |
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 690 | // See if the type comes from a DWO module and if so, track down that type. |
| 691 | type_sp = ParseTypeFromDWO(die, log); |
| 692 | if (type_sp) |
| 693 | return type_sp; |
| 694 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 695 | DWARFDeclContext die_decl_ctx; |
| 696 | die.GetDWARFDeclContext(die_decl_ctx); |
| 697 | |
| 698 | //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str); |
| 699 | type_sp = dwarf->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); |
| 700 | |
| 701 | if (!type_sp) |
| 702 | { |
| 703 | SymbolFileDWARFDebugMap *debug_map_symfile = dwarf->GetDebugMapSymfile(); |
| 704 | if (debug_map_symfile) |
| 705 | { |
| 706 | // We weren't able to find a full declaration in |
| 707 | // this DWARF, see if we have a declaration anywhere |
| 708 | // else... |
| 709 | type_sp = debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | if (type_sp) |
| 714 | { |
| 715 | if (log) |
| 716 | { |
| 717 | dwarf->GetObjectFile()->GetModule()->LogMessage (log, |
| 718 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8" PRIx64, |
| 719 | static_cast<void*>(this), |
| 720 | die.GetOffset(), |
| 721 | DW_TAG_value_to_name(tag), |
| 722 | type_name_cstr, |
| 723 | type_sp->GetID()); |
| 724 | } |
| 725 | |
| 726 | // We found a real definition for this type elsewhere |
| 727 | // so lets use it and cache the fact that we found |
| 728 | // a complete type for this die |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 729 | dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); |
| Siva Chandra | 27e33a8 | 2015-10-07 22:11:52 +0000 | [diff] [blame] | 730 | clang::DeclContext *defn_decl_ctx = GetCachedClangDeclContextForDIE( |
| 731 | dwarf->DebugInfo()->GetDIE(DIERef(type_sp->GetID()))); |
| 732 | if (defn_decl_ctx) |
| 733 | LinkDeclContextToDIE(defn_decl_ctx, die); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 734 | return type_sp; |
| 735 | } |
| 736 | } |
| 737 | assert (tag_decl_kind != -1); |
| 738 | bool clang_type_was_created = false; |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 739 | clang_type.SetCompilerType(&m_ast, dwarf->GetForwardDeclDieToClangType().lookup (die.GetDIE())); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 740 | if (!clang_type) |
| 741 | { |
| 742 | clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (die, nullptr); |
| 743 | if (accessibility == eAccessNone && decl_ctx) |
| 744 | { |
| 745 | // Check the decl context that contains this class/struct/union. |
| 746 | // If it is a class we must give it an accessibility. |
| 747 | const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind(); |
| 748 | if (DeclKindIsCXXClass (containing_decl_kind)) |
| 749 | accessibility = default_accessibility; |
| 750 | } |
| 751 | |
| 752 | ClangASTMetadata metadata; |
| 753 | metadata.SetUserID(die.GetID()); |
| 754 | metadata.SetIsDynamicCXXType(dwarf->ClassOrStructIsVirtual (die)); |
| 755 | |
| 756 | if (type_name_cstr && strchr (type_name_cstr, '<')) |
| 757 | { |
| 758 | ClangASTContext::TemplateParameterInfos template_param_infos; |
| 759 | if (ParseTemplateParameterInfos (die, template_param_infos)) |
| 760 | { |
| 761 | clang::ClassTemplateDecl *class_template_decl = m_ast.ParseClassTemplateDecl (decl_ctx, |
| 762 | accessibility, |
| 763 | type_name_cstr, |
| 764 | tag_decl_kind, |
| 765 | template_param_infos); |
| 766 | |
| 767 | clang::ClassTemplateSpecializationDecl *class_specialization_decl = m_ast.CreateClassTemplateSpecializationDecl (decl_ctx, |
| 768 | class_template_decl, |
| 769 | tag_decl_kind, |
| 770 | template_param_infos); |
| 771 | clang_type = m_ast.CreateClassTemplateSpecializationType (class_specialization_decl); |
| 772 | clang_type_was_created = true; |
| 773 | |
| 774 | m_ast.SetMetadata (class_template_decl, metadata); |
| 775 | m_ast.SetMetadata (class_specialization_decl, metadata); |
| 776 | } |
| 777 | } |
| 778 | |
| 779 | if (!clang_type_was_created) |
| 780 | { |
| 781 | clang_type_was_created = true; |
| 782 | clang_type = m_ast.CreateRecordType (decl_ctx, |
| 783 | accessibility, |
| 784 | type_name_cstr, |
| 785 | tag_decl_kind, |
| 786 | class_language, |
| 787 | &metadata); |
| 788 | } |
| 789 | } |
| 790 | |
| 791 | // Store a forward declaration to this class type in case any |
| 792 | // parameters in any class methods need it for the clang |
| 793 | // types for function prototypes. |
| 794 | LinkDeclContextToDIE(m_ast.GetDeclContextForType(clang_type), die); |
| 795 | type_sp.reset (new Type (die.GetID(), |
| 796 | dwarf, |
| 797 | type_name_const_str, |
| 798 | byte_size, |
| 799 | NULL, |
| 800 | LLDB_INVALID_UID, |
| 801 | Type::eEncodingIsUID, |
| 802 | &decl, |
| 803 | clang_type, |
| 804 | Type::eResolveStateForward)); |
| 805 | |
| 806 | type_sp->SetIsCompleteObjCClass(is_complete_objc_class); |
| 807 | |
| 808 | |
| 809 | // Add our type to the unique type map so we don't |
| 810 | // end up creating many copies of the same type over |
| 811 | // and over in the ASTContext for our module |
| 812 | unique_ast_entry_ap->m_type_sp = type_sp; |
| 813 | unique_ast_entry_ap->m_die = die; |
| Greg Clayton | fb85e62 | 2016-02-09 22:36:24 +0000 | [diff] [blame^] | 814 | unique_ast_entry_ap->m_declaration = unique_decl; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 815 | unique_ast_entry_ap->m_byte_size = byte_size; |
| Greg Clayton | fb85e62 | 2016-02-09 22:36:24 +0000 | [diff] [blame^] | 816 | dwarf->GetUniqueDWARFASTTypeMap().Insert (unique_typename, |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 817 | *unique_ast_entry_ap); |
| 818 | |
| 819 | if (is_forward_declaration && die.HasChildren()) |
| 820 | { |
| 821 | // Check to see if the DIE actually has a definition, some version of GCC will |
| 822 | // emit DIEs with DW_AT_declaration set to true, but yet still have subprogram, |
| 823 | // members, or inheritance, so we can't trust it |
| 824 | DWARFDIE child_die = die.GetFirstChild(); |
| 825 | while (child_die) |
| 826 | { |
| 827 | switch (child_die.Tag()) |
| 828 | { |
| 829 | case DW_TAG_inheritance: |
| 830 | case DW_TAG_subprogram: |
| 831 | case DW_TAG_member: |
| 832 | case DW_TAG_APPLE_property: |
| 833 | case DW_TAG_class_type: |
| 834 | case DW_TAG_structure_type: |
| 835 | case DW_TAG_enumeration_type: |
| 836 | case DW_TAG_typedef: |
| 837 | case DW_TAG_union_type: |
| 838 | child_die.Clear(); |
| 839 | is_forward_declaration = false; |
| 840 | break; |
| 841 | default: |
| 842 | child_die = child_die.GetSibling(); |
| 843 | break; |
| 844 | } |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | if (!is_forward_declaration) |
| 849 | { |
| 850 | // Always start the definition for a class type so that |
| 851 | // if the class has child classes or types that require |
| 852 | // the class to be created for use as their decl contexts |
| 853 | // the class will be ready to accept these child definitions. |
| 854 | if (die.HasChildren() == false) |
| 855 | { |
| 856 | // No children for this struct/union/class, lets finish it |
| 857 | ClangASTContext::StartTagDeclarationDefinition (clang_type); |
| 858 | ClangASTContext::CompleteTagDeclarationDefinition (clang_type); |
| 859 | |
| 860 | if (tag == DW_TAG_structure_type) // this only applies in C |
| 861 | { |
| 862 | clang::RecordDecl *record_decl = ClangASTContext::GetAsRecordDecl(clang_type); |
| 863 | |
| 864 | if (record_decl) |
| 865 | m_record_decl_to_layout_map.insert(std::make_pair(record_decl, LayoutInfo())); |
| 866 | } |
| 867 | } |
| 868 | else if (clang_type_was_created) |
| 869 | { |
| 870 | // Start the definition if the class is not objective C since |
| 871 | // the underlying decls respond to isCompleteDefinition(). Objective |
| 872 | // C decls don't respond to isCompleteDefinition() so we can't |
| 873 | // start the declaration definition right away. For C++ class/union/structs |
| 874 | // we want to start the definition in case the class is needed as the |
| 875 | // declaration context for a contained class or type without the need |
| 876 | // to complete that type.. |
| 877 | |
| 878 | if (class_language != eLanguageTypeObjC && |
| 879 | class_language != eLanguageTypeObjC_plus_plus) |
| 880 | ClangASTContext::StartTagDeclarationDefinition (clang_type); |
| 881 | |
| 882 | // Leave this as a forward declaration until we need |
| 883 | // to know the details of the type. lldb_private::Type |
| 884 | // will automatically call the SymbolFile virtual function |
| 885 | // "SymbolFileDWARF::CompleteType(Type *)" |
| 886 | // When the definition needs to be defined. |
| Tamas Berghammer | 69d0b33 | 2015-10-09 12:43:08 +0000 | [diff] [blame] | 887 | assert(!dwarf->GetForwardDeclClangTypeToDie().count(ClangASTContext::RemoveFastQualifiers(clang_type).GetOpaqueQualType()) && |
| 888 | "Type already in the forward declaration map!"); |
| 889 | assert(((SymbolFileDWARF*)m_ast.GetSymbolFile())->UserIDMatches(die.GetDIERef().GetUID()) && |
| 890 | "Adding incorrect type to forward declaration map"); |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 891 | dwarf->GetForwardDeclDieToClangType()[die.GetDIE()] = clang_type.GetOpaqueQualType(); |
| 892 | dwarf->GetForwardDeclClangTypeToDie()[ClangASTContext::RemoveFastQualifiers(clang_type).GetOpaqueQualType()] = die.GetDIERef(); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 893 | m_ast.SetHasExternalStorage (clang_type.GetOpaqueQualType(), true); |
| 894 | } |
| 895 | } |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 896 | } |
| 897 | break; |
| 898 | |
| 899 | case DW_TAG_enumeration_type: |
| 900 | { |
| 901 | // Set a bit that lets us know that we are currently parsing this |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 902 | dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 903 | |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 904 | DWARFFormValue encoding_form; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 905 | |
| 906 | const size_t num_attributes = die.GetAttributes (attributes); |
| 907 | if (num_attributes > 0) |
| 908 | { |
| 909 | uint32_t i; |
| 910 | |
| 911 | for (i=0; i<num_attributes; ++i) |
| 912 | { |
| 913 | attr = attributes.AttributeAtIndex(i); |
| 914 | if (attributes.ExtractFormValueAtIndex(i, form_value)) |
| 915 | { |
| 916 | switch (attr) |
| 917 | { |
| 918 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 919 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 920 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 921 | case DW_AT_name: |
| 922 | type_name_cstr = form_value.AsCString(); |
| 923 | type_name_const_str.SetCString(type_name_cstr); |
| 924 | break; |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 925 | case DW_AT_type: encoding_form = form_value; break; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 926 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; |
| 927 | case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 928 | case DW_AT_declaration: is_forward_declaration = form_value.Boolean(); break; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 929 | case DW_AT_allocated: |
| 930 | case DW_AT_associated: |
| 931 | case DW_AT_bit_stride: |
| 932 | case DW_AT_byte_stride: |
| 933 | case DW_AT_data_location: |
| 934 | case DW_AT_description: |
| 935 | case DW_AT_start_scope: |
| 936 | case DW_AT_visibility: |
| 937 | case DW_AT_specification: |
| 938 | case DW_AT_abstract_origin: |
| 939 | case DW_AT_sibling: |
| 940 | break; |
| 941 | } |
| 942 | } |
| 943 | } |
| 944 | |
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 945 | if (is_forward_declaration) |
| 946 | { |
| 947 | type_sp = ParseTypeFromDWO(die, log); |
| 948 | if (type_sp) |
| 949 | return type_sp; |
| 950 | |
| 951 | DWARFDeclContext die_decl_ctx; |
| 952 | die.GetDWARFDeclContext(die_decl_ctx); |
| 953 | |
| 954 | type_sp = dwarf->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); |
| 955 | |
| 956 | if (!type_sp) |
| 957 | { |
| 958 | SymbolFileDWARFDebugMap *debug_map_symfile = dwarf->GetDebugMapSymfile(); |
| 959 | if (debug_map_symfile) |
| 960 | { |
| 961 | // We weren't able to find a full declaration in |
| 962 | // this DWARF, see if we have a declaration anywhere |
| 963 | // else... |
| 964 | type_sp = debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); |
| 965 | } |
| 966 | } |
| 967 | |
| 968 | if (type_sp) |
| 969 | { |
| 970 | if (log) |
| 971 | { |
| 972 | dwarf->GetObjectFile()->GetModule()->LogMessage (log, |
| 973 | "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8" PRIx64, |
| 974 | static_cast<void*>(this), |
| 975 | die.GetOffset(), |
| 976 | DW_TAG_value_to_name(tag), |
| 977 | type_name_cstr, |
| 978 | type_sp->GetID()); |
| 979 | } |
| 980 | |
| 981 | // We found a real definition for this type elsewhere |
| 982 | // so lets use it and cache the fact that we found |
| 983 | // a complete type for this die |
| 984 | dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); |
| 985 | clang::DeclContext *defn_decl_ctx = GetCachedClangDeclContextForDIE( |
| 986 | dwarf->DebugInfo()->GetDIE(DIERef(type_sp->GetID()))); |
| 987 | if (defn_decl_ctx) |
| 988 | LinkDeclContextToDIE(defn_decl_ctx, die); |
| 989 | return type_sp; |
| 990 | } |
| 991 | |
| 992 | } |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 993 | DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(), DW_TAG_value_to_name(tag), type_name_cstr); |
| 994 | |
| 995 | CompilerType enumerator_clang_type; |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 996 | clang_type.SetCompilerType (&m_ast, dwarf->GetForwardDeclDieToClangType().lookup (die.GetDIE())); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 997 | if (!clang_type) |
| 998 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 999 | if (encoding_form.IsValid()) |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1000 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1001 | Type *enumerator_type = dwarf->ResolveTypeUID(DIERef(encoding_form).GetUID()); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1002 | if (enumerator_type) |
| 1003 | enumerator_clang_type = enumerator_type->GetFullCompilerType (); |
| 1004 | } |
| 1005 | |
| 1006 | if (!enumerator_clang_type) |
| 1007 | enumerator_clang_type = m_ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL, |
| 1008 | DW_ATE_signed, |
| 1009 | byte_size * 8); |
| 1010 | |
| 1011 | clang_type = m_ast.CreateEnumerationType (type_name_cstr, |
| 1012 | GetClangDeclContextContainingDIE (die, nullptr), |
| 1013 | decl, |
| 1014 | enumerator_clang_type); |
| 1015 | } |
| 1016 | else |
| 1017 | { |
| 1018 | enumerator_clang_type = m_ast.GetEnumerationIntegerType (clang_type.GetOpaqueQualType()); |
| 1019 | } |
| 1020 | |
| 1021 | LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die); |
| 1022 | |
| 1023 | type_sp.reset( new Type (die.GetID(), |
| 1024 | dwarf, |
| 1025 | type_name_const_str, |
| 1026 | byte_size, |
| 1027 | NULL, |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1028 | DIERef(encoding_form).GetUID(), |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1029 | Type::eEncodingIsUID, |
| 1030 | &decl, |
| 1031 | clang_type, |
| 1032 | Type::eResolveStateForward)); |
| 1033 | |
| 1034 | ClangASTContext::StartTagDeclarationDefinition (clang_type); |
| 1035 | if (die.HasChildren()) |
| 1036 | { |
| 1037 | SymbolContext cu_sc(die.GetLLDBCompileUnit()); |
| 1038 | bool is_signed = false; |
| 1039 | enumerator_clang_type.IsIntegerType(is_signed); |
| 1040 | ParseChildEnumerators(cu_sc, clang_type, is_signed, type_sp->GetByteSize(), die); |
| 1041 | } |
| 1042 | ClangASTContext::CompleteTagDeclarationDefinition (clang_type); |
| 1043 | } |
| 1044 | } |
| 1045 | break; |
| 1046 | |
| 1047 | case DW_TAG_inlined_subroutine: |
| 1048 | case DW_TAG_subprogram: |
| 1049 | case DW_TAG_subroutine_type: |
| 1050 | { |
| 1051 | // Set a bit that lets us know that we are currently parsing this |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1052 | dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1053 | |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1054 | DWARFFormValue type_die_form; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1055 | bool is_variadic = false; |
| 1056 | bool is_inline = false; |
| 1057 | bool is_static = false; |
| 1058 | bool is_virtual = false; |
| 1059 | bool is_explicit = false; |
| 1060 | bool is_artificial = false; |
| Greg Clayton | fb85e62 | 2016-02-09 22:36:24 +0000 | [diff] [blame^] | 1061 | bool has_template_params = false; |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1062 | DWARFFormValue specification_die_form; |
| 1063 | DWARFFormValue abstract_origin_die_form; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1064 | dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET; |
| 1065 | |
| 1066 | unsigned type_quals = 0; |
| 1067 | clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern |
| 1068 | |
| 1069 | |
| 1070 | const size_t num_attributes = die.GetAttributes (attributes); |
| 1071 | if (num_attributes > 0) |
| 1072 | { |
| 1073 | uint32_t i; |
| 1074 | for (i=0; i<num_attributes; ++i) |
| 1075 | { |
| 1076 | attr = attributes.AttributeAtIndex(i); |
| 1077 | if (attributes.ExtractFormValueAtIndex(i, form_value)) |
| 1078 | { |
| 1079 | switch (attr) |
| 1080 | { |
| 1081 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 1082 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 1083 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 1084 | case DW_AT_name: |
| 1085 | type_name_cstr = form_value.AsCString(); |
| 1086 | type_name_const_str.SetCString(type_name_cstr); |
| 1087 | break; |
| 1088 | |
| 1089 | case DW_AT_linkage_name: |
| 1090 | case DW_AT_MIPS_linkage_name: break; // mangled = form_value.AsCString(&dwarf->get_debug_str_data()); break; |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1091 | case DW_AT_type: type_die_form = form_value; break; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1092 | case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| 1093 | case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break; |
| 1094 | case DW_AT_inline: is_inline = form_value.Boolean(); break; |
| 1095 | case DW_AT_virtuality: is_virtual = form_value.Boolean(); break; |
| 1096 | case DW_AT_explicit: is_explicit = form_value.Boolean(); break; |
| 1097 | case DW_AT_artificial: is_artificial = form_value.Boolean(); break; |
| 1098 | |
| 1099 | |
| 1100 | case DW_AT_external: |
| 1101 | if (form_value.Unsigned()) |
| 1102 | { |
| 1103 | if (storage == clang::SC_None) |
| 1104 | storage = clang::SC_Extern; |
| 1105 | else |
| 1106 | storage = clang::SC_PrivateExtern; |
| 1107 | } |
| 1108 | break; |
| 1109 | |
| 1110 | case DW_AT_specification: |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1111 | specification_die_form = form_value; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1112 | break; |
| 1113 | |
| 1114 | case DW_AT_abstract_origin: |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1115 | abstract_origin_die_form = form_value; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1116 | break; |
| 1117 | |
| 1118 | case DW_AT_object_pointer: |
| 1119 | object_pointer_die_offset = form_value.Reference(); |
| 1120 | break; |
| 1121 | |
| 1122 | case DW_AT_allocated: |
| 1123 | case DW_AT_associated: |
| 1124 | case DW_AT_address_class: |
| 1125 | case DW_AT_calling_convention: |
| 1126 | case DW_AT_data_location: |
| 1127 | case DW_AT_elemental: |
| 1128 | case DW_AT_entry_pc: |
| 1129 | case DW_AT_frame_base: |
| 1130 | case DW_AT_high_pc: |
| 1131 | case DW_AT_low_pc: |
| 1132 | case DW_AT_prototyped: |
| 1133 | case DW_AT_pure: |
| 1134 | case DW_AT_ranges: |
| 1135 | case DW_AT_recursive: |
| 1136 | case DW_AT_return_addr: |
| 1137 | case DW_AT_segment: |
| 1138 | case DW_AT_start_scope: |
| 1139 | case DW_AT_static_link: |
| 1140 | case DW_AT_trampoline: |
| 1141 | case DW_AT_visibility: |
| 1142 | case DW_AT_vtable_elem_location: |
| 1143 | case DW_AT_description: |
| 1144 | case DW_AT_sibling: |
| 1145 | break; |
| 1146 | } |
| 1147 | } |
| 1148 | } |
| 1149 | } |
| 1150 | |
| 1151 | std::string object_pointer_name; |
| 1152 | if (object_pointer_die_offset != DW_INVALID_OFFSET) |
| 1153 | { |
| 1154 | DWARFDIE object_pointer_die = die.GetDIE (object_pointer_die_offset); |
| 1155 | if (object_pointer_die) |
| 1156 | { |
| 1157 | const char *object_pointer_name_cstr = object_pointer_die.GetName(); |
| 1158 | if (object_pointer_name_cstr) |
| 1159 | object_pointer_name = object_pointer_name_cstr; |
| 1160 | } |
| 1161 | } |
| 1162 | |
| 1163 | DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(), DW_TAG_value_to_name(tag), type_name_cstr); |
| 1164 | |
| 1165 | CompilerType return_clang_type; |
| 1166 | Type *func_type = NULL; |
| 1167 | |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1168 | if (type_die_form.IsValid()) |
| 1169 | func_type = dwarf->ResolveTypeUID(DIERef(type_die_form).GetUID()); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1170 | |
| 1171 | if (func_type) |
| 1172 | return_clang_type = func_type->GetForwardCompilerType (); |
| 1173 | else |
| 1174 | return_clang_type = m_ast.GetBasicType(eBasicTypeVoid); |
| 1175 | |
| 1176 | |
| 1177 | std::vector<CompilerType> function_param_types; |
| 1178 | std::vector<clang::ParmVarDecl*> function_param_decls; |
| 1179 | |
| 1180 | // Parse the function children for the parameters |
| 1181 | |
| 1182 | DWARFDIE decl_ctx_die; |
| 1183 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (die, &decl_ctx_die); |
| 1184 | const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind(); |
| 1185 | |
| Greg Clayton | fb85e62 | 2016-02-09 22:36:24 +0000 | [diff] [blame^] | 1186 | bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1187 | // Start off static. This will be set to false in ParseChildParameters(...) |
| 1188 | // if we find a "this" parameters as the first parameter |
| 1189 | if (is_cxx_method) |
| Greg Clayton | fb85e62 | 2016-02-09 22:36:24 +0000 | [diff] [blame^] | 1190 | { |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1191 | is_static = true; |
| Greg Clayton | fb85e62 | 2016-02-09 22:36:24 +0000 | [diff] [blame^] | 1192 | } |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1193 | |
| 1194 | if (die.HasChildren()) |
| 1195 | { |
| 1196 | bool skip_artificial = true; |
| 1197 | ParseChildParameters (sc, |
| 1198 | containing_decl_ctx, |
| 1199 | die, |
| 1200 | skip_artificial, |
| 1201 | is_static, |
| 1202 | is_variadic, |
| Greg Clayton | fb85e62 | 2016-02-09 22:36:24 +0000 | [diff] [blame^] | 1203 | has_template_params, |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1204 | function_param_types, |
| 1205 | function_param_decls, |
| 1206 | type_quals); |
| 1207 | } |
| 1208 | |
| Greg Clayton | fb85e62 | 2016-02-09 22:36:24 +0000 | [diff] [blame^] | 1209 | bool ignore_containing_context = false; |
| 1210 | // Check for templatized class member functions. If we had any DW_TAG_template_type_parameter |
| 1211 | // or DW_TAG_template_value_parameter the DW_TAG_subprogram DIE, then we can't let this become |
| 1212 | // a method in a class. Why? Because templatized functions are only emitted if one of the |
| 1213 | // templatized methods is used in the current compile unit and we will end up with classes |
| 1214 | // that may or may not include these member functions and this means one class won't match another |
| 1215 | // class definition and it affects our ability to use a class in the clang expression parser. So |
| 1216 | // for the greater good, we currently must not allow any template member functions in a class definition. |
| 1217 | // if (is_cxx_method && has_template_params) |
| 1218 | // { |
| 1219 | // ignore_containing_context = true; |
| 1220 | // is_cxx_method = false; |
| 1221 | // } |
| 1222 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1223 | // clang_type will get the function prototype clang type after this call |
| 1224 | clang_type = m_ast.CreateFunctionType (return_clang_type, |
| 1225 | function_param_types.data(), |
| 1226 | function_param_types.size(), |
| 1227 | is_variadic, |
| 1228 | type_quals); |
| 1229 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1230 | |
| 1231 | if (type_name_cstr) |
| 1232 | { |
| 1233 | bool type_handled = false; |
| 1234 | if (tag == DW_TAG_subprogram || |
| 1235 | tag == DW_TAG_inlined_subroutine) |
| 1236 | { |
| Jim Ingham | aa816b8 | 2015-09-02 01:59:14 +0000 | [diff] [blame] | 1237 | ObjCLanguage::MethodName objc_method (type_name_cstr, true); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1238 | if (objc_method.IsValid(true)) |
| 1239 | { |
| 1240 | CompilerType class_opaque_type; |
| 1241 | ConstString class_name(objc_method.GetClassName()); |
| 1242 | if (class_name) |
| 1243 | { |
| 1244 | TypeSP complete_objc_class_type_sp (dwarf->FindCompleteObjCDefinitionTypeForDIE (DWARFDIE(), class_name, false)); |
| 1245 | |
| 1246 | if (complete_objc_class_type_sp) |
| 1247 | { |
| 1248 | CompilerType type_clang_forward_type = complete_objc_class_type_sp->GetForwardCompilerType (); |
| 1249 | if (ClangASTContext::IsObjCObjectOrInterfaceType(type_clang_forward_type)) |
| 1250 | class_opaque_type = type_clang_forward_type; |
| 1251 | } |
| 1252 | } |
| 1253 | |
| 1254 | if (class_opaque_type) |
| 1255 | { |
| 1256 | // If accessibility isn't set to anything valid, assume public for |
| 1257 | // now... |
| 1258 | if (accessibility == eAccessNone) |
| 1259 | accessibility = eAccessPublic; |
| 1260 | |
| 1261 | clang::ObjCMethodDecl *objc_method_decl = m_ast.AddMethodToObjCObjectType (class_opaque_type, |
| 1262 | type_name_cstr, |
| 1263 | clang_type, |
| 1264 | accessibility, |
| 1265 | is_artificial); |
| 1266 | type_handled = objc_method_decl != NULL; |
| 1267 | if (type_handled) |
| 1268 | { |
| 1269 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die); |
| 1270 | m_ast.SetMetadataAsUserID (objc_method_decl, die.GetID()); |
| 1271 | } |
| 1272 | else |
| 1273 | { |
| 1274 | dwarf->GetObjectFile()->GetModule()->ReportError ("{0x%8.8x}: invalid Objective-C method 0x%4.4x (%s), please file a bug and attach the file at the start of this error message", |
| 1275 | die.GetOffset(), |
| 1276 | tag, |
| 1277 | DW_TAG_value_to_name(tag)); |
| 1278 | } |
| 1279 | } |
| 1280 | } |
| 1281 | else if (is_cxx_method) |
| 1282 | { |
| 1283 | // Look at the parent of this DIE and see if is is |
| 1284 | // a class or struct and see if this is actually a |
| 1285 | // C++ method |
| 1286 | Type *class_type = dwarf->ResolveType (decl_ctx_die); |
| 1287 | if (class_type) |
| 1288 | { |
| Siva Chandra | 27e33a8 | 2015-10-07 22:11:52 +0000 | [diff] [blame] | 1289 | bool alternate_defn = false; |
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 1290 | if (class_type->GetID() != decl_ctx_die.GetID() || decl_ctx_die.GetContainingDWOModuleDIE()) |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1291 | { |
| Siva Chandra | 27e33a8 | 2015-10-07 22:11:52 +0000 | [diff] [blame] | 1292 | alternate_defn = true; |
| 1293 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1294 | // We uniqued the parent class of this function to another class |
| 1295 | // so we now need to associate all dies under "decl_ctx_die" to |
| 1296 | // DIEs in the DIE for "class_type"... |
| 1297 | SymbolFileDWARF *class_symfile = NULL; |
| 1298 | DWARFDIE class_type_die; |
| 1299 | |
| 1300 | SymbolFileDWARFDebugMap *debug_map_symfile = dwarf->GetDebugMapSymfile(); |
| 1301 | if (debug_map_symfile) |
| 1302 | { |
| 1303 | class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID())); |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1304 | class_type_die = class_symfile->DebugInfo()->GetDIE (DIERef(class_type->GetID())); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1305 | } |
| 1306 | else |
| 1307 | { |
| 1308 | class_symfile = dwarf; |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1309 | class_type_die = dwarf->DebugInfo()->GetDIE (DIERef(class_type->GetID())); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1310 | } |
| 1311 | if (class_type_die) |
| 1312 | { |
| 1313 | DWARFDIECollection failures; |
| 1314 | |
| 1315 | CopyUniqueClassMethodTypes (decl_ctx_die, |
| 1316 | class_type_die, |
| 1317 | class_type, |
| 1318 | failures); |
| 1319 | |
| 1320 | // FIXME do something with these failures that's smarter than |
| 1321 | // just dropping them on the ground. Unfortunately classes don't |
| 1322 | // like having stuff added to them after their definitions are |
| 1323 | // complete... |
| 1324 | |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1325 | type_ptr = dwarf->GetDIEToType()[die.GetDIE()]; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1326 | if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) |
| 1327 | { |
| 1328 | type_sp = type_ptr->shared_from_this(); |
| 1329 | break; |
| 1330 | } |
| 1331 | } |
| 1332 | } |
| 1333 | |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1334 | if (specification_die_form.IsValid()) |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1335 | { |
| 1336 | // We have a specification which we are going to base our function |
| 1337 | // prototype off of, so we need this type to be completed so that the |
| 1338 | // m_die_to_decl_ctx for the method in the specification has a valid |
| 1339 | // clang decl context. |
| 1340 | class_type->GetForwardCompilerType (); |
| 1341 | // If we have a specification, then the function type should have been |
| 1342 | // made with the specification and not with this die. |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1343 | DWARFDIE spec_die = dwarf->DebugInfo()->GetDIE(DIERef(specification_die_form)); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1344 | clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (spec_die); |
| 1345 | if (spec_clang_decl_ctx) |
| 1346 | { |
| 1347 | LinkDeclContextToDIE(spec_clang_decl_ctx, die); |
| 1348 | } |
| 1349 | else |
| 1350 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1351 | dwarf->GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8" PRIx64 ") has no decl\n", |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1352 | die.GetID(), |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1353 | specification_die_form.Reference()); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1354 | } |
| 1355 | type_handled = true; |
| 1356 | } |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1357 | else if (abstract_origin_die_form.IsValid()) |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1358 | { |
| 1359 | // We have a specification which we are going to base our function |
| 1360 | // prototype off of, so we need this type to be completed so that the |
| 1361 | // m_die_to_decl_ctx for the method in the abstract origin has a valid |
| 1362 | // clang decl context. |
| 1363 | class_type->GetForwardCompilerType (); |
| 1364 | |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1365 | DWARFDIE abs_die = dwarf->DebugInfo()->GetDIE (DIERef(abstract_origin_die_form)); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1366 | clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (abs_die); |
| 1367 | if (abs_clang_decl_ctx) |
| 1368 | { |
| 1369 | LinkDeclContextToDIE (abs_clang_decl_ctx, die); |
| 1370 | } |
| 1371 | else |
| 1372 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1373 | dwarf->GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_abstract_origin(0x%8.8" PRIx64 ") has no decl\n", |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1374 | die.GetID(), |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1375 | abstract_origin_die_form.Reference()); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1376 | } |
| 1377 | type_handled = true; |
| 1378 | } |
| 1379 | else |
| 1380 | { |
| 1381 | CompilerType class_opaque_type = class_type->GetForwardCompilerType (); |
| 1382 | if (ClangASTContext::IsCXXClassType(class_opaque_type)) |
| 1383 | { |
| Siva Chandra | 27e33a8 | 2015-10-07 22:11:52 +0000 | [diff] [blame] | 1384 | if (class_opaque_type.IsBeingDefined () || alternate_defn) |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1385 | { |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1386 | if (!is_static && !die.HasChildren()) |
| 1387 | { |
| 1388 | // We have a C++ member function with no children (this pointer!) |
| 1389 | // and clang will get mad if we try and make a function that isn't |
| 1390 | // well formed in the DWARF, so we will just skip it... |
| 1391 | type_handled = true; |
| 1392 | } |
| 1393 | else |
| 1394 | { |
| Siva Chandra | 27e33a8 | 2015-10-07 22:11:52 +0000 | [diff] [blame] | 1395 | bool add_method = true; |
| 1396 | if (alternate_defn) |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1397 | { |
| Siva Chandra | 27e33a8 | 2015-10-07 22:11:52 +0000 | [diff] [blame] | 1398 | // If an alternate definition for the class exists, then add the method only if an |
| 1399 | // equivalent is not already present. |
| 1400 | clang::CXXRecordDecl *record_decl = m_ast.GetAsCXXRecordDecl(class_opaque_type.GetOpaqueQualType()); |
| 1401 | if (record_decl) |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1402 | { |
| Siva Chandra | 27e33a8 | 2015-10-07 22:11:52 +0000 | [diff] [blame] | 1403 | for (auto method_iter = record_decl->method_begin(); |
| 1404 | method_iter != record_decl->method_end(); |
| 1405 | method_iter++) |
| 1406 | { |
| 1407 | clang::CXXMethodDecl *method_decl = *method_iter; |
| 1408 | if (method_decl->getNameInfo().getAsString() == std::string(type_name_cstr)) |
| 1409 | { |
| 1410 | if (method_decl->getType() == ClangASTContext::GetQualType(clang_type)) |
| 1411 | { |
| 1412 | add_method = false; |
| 1413 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(method_decl), die); |
| 1414 | type_handled = true; |
| 1415 | |
| 1416 | break; |
| 1417 | } |
| 1418 | } |
| 1419 | } |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1420 | } |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1421 | } |
| Siva Chandra | 27e33a8 | 2015-10-07 22:11:52 +0000 | [diff] [blame] | 1422 | |
| 1423 | if (add_method) |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1424 | { |
| Siva Chandra | 27e33a8 | 2015-10-07 22:11:52 +0000 | [diff] [blame] | 1425 | // REMOVE THE CRASH DESCRIPTION BELOW |
| 1426 | Host::SetCrashDescriptionWithFormat ("SymbolFileDWARF::ParseType() is adding a method %s to class %s in DIE 0x%8.8" PRIx64 " from %s", |
| 1427 | type_name_cstr, |
| 1428 | class_type->GetName().GetCString(), |
| 1429 | die.GetID(), |
| 1430 | dwarf->GetObjectFile()->GetFileSpec().GetPath().c_str()); |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 1431 | |
| Siva Chandra | 27e33a8 | 2015-10-07 22:11:52 +0000 | [diff] [blame] | 1432 | const bool is_attr_used = false; |
| 1433 | // Neither GCC 4.2 nor clang++ currently set a valid accessibility |
| 1434 | // in the DWARF for C++ methods... Default to public for now... |
| 1435 | if (accessibility == eAccessNone) |
| 1436 | accessibility = eAccessPublic; |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 1437 | |
| Siva Chandra | 27e33a8 | 2015-10-07 22:11:52 +0000 | [diff] [blame] | 1438 | clang::CXXMethodDecl *cxx_method_decl; |
| 1439 | cxx_method_decl = m_ast.AddMethodToCXXRecordType (class_opaque_type.GetOpaqueQualType(), |
| 1440 | type_name_cstr, |
| 1441 | clang_type, |
| 1442 | accessibility, |
| 1443 | is_virtual, |
| 1444 | is_static, |
| 1445 | is_inline, |
| 1446 | is_explicit, |
| 1447 | is_attr_used, |
| 1448 | is_artificial); |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 1449 | |
| Siva Chandra | 27e33a8 | 2015-10-07 22:11:52 +0000 | [diff] [blame] | 1450 | type_handled = cxx_method_decl != NULL; |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 1451 | |
| Siva Chandra | 27e33a8 | 2015-10-07 22:11:52 +0000 | [diff] [blame] | 1452 | if (type_handled) |
| 1453 | { |
| 1454 | LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die); |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 1455 | |
| Siva Chandra | 27e33a8 | 2015-10-07 22:11:52 +0000 | [diff] [blame] | 1456 | Host::SetCrashDescription (NULL); |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 1457 | |
| Siva Chandra | 27e33a8 | 2015-10-07 22:11:52 +0000 | [diff] [blame] | 1458 | ClangASTMetadata metadata; |
| 1459 | metadata.SetUserID(die.GetID()); |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 1460 | |
| Siva Chandra | 27e33a8 | 2015-10-07 22:11:52 +0000 | [diff] [blame] | 1461 | if (!object_pointer_name.empty()) |
| 1462 | { |
| 1463 | metadata.SetObjectPtrName(object_pointer_name.c_str()); |
| 1464 | if (log) |
| 1465 | log->Printf ("Setting object pointer name: %s on method object %p.\n", |
| 1466 | object_pointer_name.c_str(), |
| 1467 | static_cast<void*>(cxx_method_decl)); |
| 1468 | } |
| 1469 | m_ast.SetMetadata (cxx_method_decl, metadata); |
| 1470 | } |
| 1471 | else |
| 1472 | { |
| 1473 | ignore_containing_context = true; |
| 1474 | } |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1475 | } |
| 1476 | } |
| 1477 | } |
| 1478 | else |
| 1479 | { |
| 1480 | // We were asked to parse the type for a method in a class, yet the |
| 1481 | // class hasn't been asked to complete itself through the |
| 1482 | // clang::ExternalASTSource protocol, so we need to just have the |
| 1483 | // class complete itself and do things the right way, then our |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1484 | // DIE should then have an entry in the dwarf->GetDIEToType() map. First |
| 1485 | // we need to modify the dwarf->GetDIEToType() so it doesn't think we are |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1486 | // trying to parse this DIE anymore... |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1487 | dwarf->GetDIEToType()[die.GetDIE()] = NULL; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1488 | |
| 1489 | // Now we get the full type to force our class type to complete itself |
| 1490 | // using the clang::ExternalASTSource protocol which will parse all |
| 1491 | // base classes and all methods (including the method for this DIE). |
| 1492 | class_type->GetFullCompilerType (); |
| 1493 | |
| 1494 | // The type for this DIE should have been filled in the function call above |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1495 | type_ptr = dwarf->GetDIEToType()[die.GetDIE()]; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1496 | if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) |
| 1497 | { |
| 1498 | type_sp = type_ptr->shared_from_this(); |
| 1499 | break; |
| 1500 | } |
| 1501 | |
| 1502 | // FIXME This is fixing some even uglier behavior but we really need to |
| 1503 | // uniq the methods of each class as well as the class itself. |
| 1504 | // <rdar://problem/11240464> |
| 1505 | type_handled = true; |
| 1506 | } |
| 1507 | } |
| 1508 | } |
| 1509 | } |
| 1510 | } |
| 1511 | } |
| 1512 | |
| 1513 | if (!type_handled) |
| 1514 | { |
| 1515 | // We just have a function that isn't part of a class |
| 1516 | clang::FunctionDecl *function_decl = m_ast.CreateFunctionDeclaration (ignore_containing_context ? m_ast.GetTranslationUnitDecl() : containing_decl_ctx, |
| 1517 | type_name_cstr, |
| 1518 | clang_type, |
| 1519 | storage, |
| 1520 | is_inline); |
| 1521 | |
| 1522 | // if (template_param_infos.GetSize() > 0) |
| 1523 | // { |
| 1524 | // clang::FunctionTemplateDecl *func_template_decl = CreateFunctionTemplateDecl (containing_decl_ctx, |
| 1525 | // function_decl, |
| 1526 | // type_name_cstr, |
| 1527 | // template_param_infos); |
| 1528 | // |
| 1529 | // CreateFunctionTemplateSpecializationInfo (function_decl, |
| 1530 | // func_template_decl, |
| 1531 | // template_param_infos); |
| 1532 | // } |
| 1533 | // Add the decl to our DIE to decl context map |
| 1534 | assert (function_decl); |
| 1535 | LinkDeclContextToDIE(function_decl, die); |
| 1536 | if (!function_param_decls.empty()) |
| 1537 | m_ast.SetFunctionParameters (function_decl, |
| 1538 | &function_param_decls.front(), |
| 1539 | function_param_decls.size()); |
| 1540 | |
| 1541 | ClangASTMetadata metadata; |
| 1542 | metadata.SetUserID(die.GetID()); |
| 1543 | |
| 1544 | if (!object_pointer_name.empty()) |
| 1545 | { |
| 1546 | metadata.SetObjectPtrName(object_pointer_name.c_str()); |
| 1547 | if (log) |
| 1548 | log->Printf ("Setting object pointer name: %s on function object %p.", |
| 1549 | object_pointer_name.c_str(), |
| 1550 | static_cast<void*>(function_decl)); |
| 1551 | } |
| 1552 | m_ast.SetMetadata (function_decl, metadata); |
| 1553 | } |
| 1554 | } |
| 1555 | type_sp.reset( new Type (die.GetID(), |
| 1556 | dwarf, |
| 1557 | type_name_const_str, |
| 1558 | 0, |
| 1559 | NULL, |
| 1560 | LLDB_INVALID_UID, |
| 1561 | Type::eEncodingIsUID, |
| 1562 | &decl, |
| 1563 | clang_type, |
| 1564 | Type::eResolveStateFull)); |
| 1565 | assert(type_sp.get()); |
| 1566 | } |
| 1567 | break; |
| 1568 | |
| 1569 | case DW_TAG_array_type: |
| 1570 | { |
| 1571 | // Set a bit that lets us know that we are currently parsing this |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1572 | dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1573 | |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1574 | DWARFFormValue type_die_form; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1575 | int64_t first_index = 0; |
| 1576 | uint32_t byte_stride = 0; |
| 1577 | uint32_t bit_stride = 0; |
| 1578 | bool is_vector = false; |
| 1579 | const size_t num_attributes = die.GetAttributes (attributes); |
| 1580 | |
| 1581 | if (num_attributes > 0) |
| 1582 | { |
| 1583 | uint32_t i; |
| 1584 | for (i=0; i<num_attributes; ++i) |
| 1585 | { |
| 1586 | attr = attributes.AttributeAtIndex(i); |
| 1587 | if (attributes.ExtractFormValueAtIndex(i, form_value)) |
| 1588 | { |
| 1589 | switch (attr) |
| 1590 | { |
| 1591 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 1592 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 1593 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 1594 | case DW_AT_name: |
| 1595 | type_name_cstr = form_value.AsCString(); |
| 1596 | type_name_const_str.SetCString(type_name_cstr); |
| 1597 | break; |
| 1598 | |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1599 | case DW_AT_type: type_die_form = form_value; break; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1600 | case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break; |
| 1601 | case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break; |
| 1602 | case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break; |
| 1603 | case DW_AT_GNU_vector: is_vector = form_value.Boolean(); break; |
| 1604 | case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| 1605 | case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break; |
| 1606 | case DW_AT_allocated: |
| 1607 | case DW_AT_associated: |
| 1608 | case DW_AT_data_location: |
| 1609 | case DW_AT_description: |
| 1610 | case DW_AT_ordering: |
| 1611 | case DW_AT_start_scope: |
| 1612 | case DW_AT_visibility: |
| 1613 | case DW_AT_specification: |
| 1614 | case DW_AT_abstract_origin: |
| 1615 | case DW_AT_sibling: |
| 1616 | break; |
| 1617 | } |
| 1618 | } |
| 1619 | } |
| 1620 | |
| 1621 | DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(), DW_TAG_value_to_name(tag), type_name_cstr); |
| 1622 | |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1623 | Type *element_type = dwarf->ResolveTypeUID(DIERef(type_die_form).GetUID()); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1624 | |
| 1625 | if (element_type) |
| 1626 | { |
| 1627 | std::vector<uint64_t> element_orders; |
| 1628 | ParseChildArrayInfo(sc, die, first_index, element_orders, byte_stride, bit_stride); |
| 1629 | if (byte_stride == 0 && bit_stride == 0) |
| 1630 | byte_stride = element_type->GetByteSize(); |
| 1631 | CompilerType array_element_type = element_type->GetForwardCompilerType (); |
| 1632 | uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride; |
| 1633 | if (element_orders.size() > 0) |
| 1634 | { |
| 1635 | uint64_t num_elements = 0; |
| 1636 | std::vector<uint64_t>::const_reverse_iterator pos; |
| 1637 | std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend(); |
| 1638 | for (pos = element_orders.rbegin(); pos != end; ++pos) |
| 1639 | { |
| 1640 | num_elements = *pos; |
| 1641 | clang_type = m_ast.CreateArrayType (array_element_type, |
| 1642 | num_elements, |
| 1643 | is_vector); |
| 1644 | array_element_type = clang_type; |
| 1645 | array_element_bit_stride = num_elements ? |
| 1646 | array_element_bit_stride * num_elements : |
| 1647 | array_element_bit_stride; |
| 1648 | } |
| 1649 | } |
| 1650 | else |
| 1651 | { |
| 1652 | clang_type = m_ast.CreateArrayType (array_element_type, 0, is_vector); |
| 1653 | } |
| 1654 | ConstString empty_name; |
| 1655 | type_sp.reset( new Type (die.GetID(), |
| 1656 | dwarf, |
| 1657 | empty_name, |
| 1658 | array_element_bit_stride / 8, |
| 1659 | NULL, |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1660 | DIERef(type_die_form).GetUID(), |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1661 | Type::eEncodingIsUID, |
| 1662 | &decl, |
| 1663 | clang_type, |
| 1664 | Type::eResolveStateFull)); |
| 1665 | type_sp->SetEncodingType (element_type); |
| 1666 | } |
| 1667 | } |
| 1668 | } |
| 1669 | break; |
| 1670 | |
| 1671 | case DW_TAG_ptr_to_member_type: |
| 1672 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1673 | DWARFFormValue type_die_form; |
| 1674 | DWARFFormValue containing_type_die_form; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1675 | |
| 1676 | const size_t num_attributes = die.GetAttributes (attributes); |
| 1677 | |
| 1678 | if (num_attributes > 0) { |
| 1679 | uint32_t i; |
| 1680 | for (i=0; i<num_attributes; ++i) |
| 1681 | { |
| 1682 | attr = attributes.AttributeAtIndex(i); |
| 1683 | if (attributes.ExtractFormValueAtIndex(i, form_value)) |
| 1684 | { |
| 1685 | switch (attr) |
| 1686 | { |
| 1687 | case DW_AT_type: |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1688 | type_die_form = form_value; break; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1689 | case DW_AT_containing_type: |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1690 | containing_type_die_form = form_value; break; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1691 | } |
| 1692 | } |
| 1693 | } |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 1694 | |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1695 | Type *pointee_type = dwarf->ResolveTypeUID(DIERef(type_die_form).GetUID()); |
| 1696 | Type *class_type = dwarf->ResolveTypeUID(DIERef(containing_type_die_form).GetUID()); |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 1697 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1698 | CompilerType pointee_clang_type = pointee_type->GetForwardCompilerType (); |
| 1699 | CompilerType class_clang_type = class_type->GetLayoutCompilerType (); |
| 1700 | |
| Tamas Berghammer | c9eb2fc | 2015-10-26 18:10:55 +0000 | [diff] [blame] | 1701 | clang_type = ClangASTContext::CreateMemberPointerType(class_clang_type, pointee_clang_type); |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 1702 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1703 | byte_size = clang_type.GetByteSize(nullptr); |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 1704 | |
| 1705 | type_sp.reset(new Type(die.GetID(), dwarf, type_name_const_str, byte_size, NULL, |
| 1706 | LLDB_INVALID_UID, Type::eEncodingIsUID, NULL, clang_type, |
| 1707 | Type::eResolveStateForward)); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1708 | } |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 1709 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1710 | break; |
| 1711 | } |
| 1712 | default: |
| 1713 | dwarf->GetObjectFile()->GetModule()->ReportError ("{0x%8.8x}: unhandled type tag 0x%4.4x (%s), please file a bug and attach the file at the start of this error message", |
| 1714 | die.GetOffset(), |
| 1715 | tag, |
| 1716 | DW_TAG_value_to_name(tag)); |
| 1717 | break; |
| 1718 | } |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 1719 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1720 | if (type_sp.get()) |
| 1721 | { |
| 1722 | DWARFDIE sc_parent_die = SymbolFileDWARF::GetParentSymbolContextDIE(die); |
| 1723 | dw_tag_t sc_parent_tag = sc_parent_die.Tag(); |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 1724 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1725 | SymbolContextScope * symbol_context_scope = NULL; |
| 1726 | if (sc_parent_tag == DW_TAG_compile_unit) |
| 1727 | { |
| 1728 | symbol_context_scope = sc.comp_unit; |
| 1729 | } |
| 1730 | else if (sc.function != NULL && sc_parent_die) |
| 1731 | { |
| 1732 | symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(sc_parent_die.GetID()); |
| 1733 | if (symbol_context_scope == NULL) |
| 1734 | symbol_context_scope = sc.function; |
| 1735 | } |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 1736 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1737 | if (symbol_context_scope != NULL) |
| 1738 | { |
| 1739 | type_sp->SetSymbolContextScope(symbol_context_scope); |
| 1740 | } |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 1741 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1742 | // We are ready to put this type into the uniqued list up at the module level |
| 1743 | type_list->Insert (type_sp); |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 1744 | |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1745 | dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1746 | } |
| 1747 | } |
| 1748 | else if (type_ptr != DIE_IS_BEING_PARSED) |
| 1749 | { |
| 1750 | type_sp = type_ptr->shared_from_this(); |
| 1751 | } |
| 1752 | } |
| 1753 | return type_sp; |
| 1754 | } |
| 1755 | |
| 1756 | // DWARF parsing functions |
| 1757 | |
| 1758 | class DWARFASTParserClang::DelayedAddObjCClassProperty |
| 1759 | { |
| 1760 | public: |
| 1761 | DelayedAddObjCClassProperty(const CompilerType &class_opaque_type, |
| 1762 | const char *property_name, |
| 1763 | const CompilerType &property_opaque_type, // The property type is only required if you don't have an ivar decl |
| 1764 | clang::ObjCIvarDecl *ivar_decl, |
| 1765 | const char *property_setter_name, |
| 1766 | const char *property_getter_name, |
| 1767 | uint32_t property_attributes, |
| 1768 | const ClangASTMetadata *metadata) : |
| 1769 | m_class_opaque_type (class_opaque_type), |
| 1770 | m_property_name (property_name), |
| 1771 | m_property_opaque_type (property_opaque_type), |
| 1772 | m_ivar_decl (ivar_decl), |
| 1773 | m_property_setter_name (property_setter_name), |
| 1774 | m_property_getter_name (property_getter_name), |
| 1775 | m_property_attributes (property_attributes) |
| 1776 | { |
| 1777 | if (metadata != NULL) |
| 1778 | { |
| 1779 | m_metadata_ap.reset(new ClangASTMetadata()); |
| 1780 | *m_metadata_ap = *metadata; |
| 1781 | } |
| 1782 | } |
| 1783 | |
| 1784 | DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs) |
| 1785 | { |
| 1786 | *this = rhs; |
| 1787 | } |
| 1788 | |
| 1789 | DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs) |
| 1790 | { |
| 1791 | m_class_opaque_type = rhs.m_class_opaque_type; |
| 1792 | m_property_name = rhs.m_property_name; |
| 1793 | m_property_opaque_type = rhs.m_property_opaque_type; |
| 1794 | m_ivar_decl = rhs.m_ivar_decl; |
| 1795 | m_property_setter_name = rhs.m_property_setter_name; |
| 1796 | m_property_getter_name = rhs.m_property_getter_name; |
| 1797 | m_property_attributes = rhs.m_property_attributes; |
| 1798 | |
| 1799 | if (rhs.m_metadata_ap.get()) |
| 1800 | { |
| 1801 | m_metadata_ap.reset (new ClangASTMetadata()); |
| 1802 | *m_metadata_ap = *rhs.m_metadata_ap; |
| 1803 | } |
| 1804 | return *this; |
| 1805 | } |
| 1806 | |
| 1807 | bool |
| 1808 | Finalize() |
| 1809 | { |
| Zachary Turner | 89a7938 | 2015-10-02 22:47:14 +0000 | [diff] [blame] | 1810 | return ClangASTContext::AddObjCClassProperty (m_class_opaque_type, |
| 1811 | m_property_name, |
| 1812 | m_property_opaque_type, |
| 1813 | m_ivar_decl, |
| 1814 | m_property_setter_name, |
| 1815 | m_property_getter_name, |
| 1816 | m_property_attributes, |
| 1817 | m_metadata_ap.get()); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1818 | } |
| 1819 | |
| 1820 | private: |
| 1821 | CompilerType m_class_opaque_type; |
| 1822 | const char *m_property_name; |
| 1823 | CompilerType m_property_opaque_type; |
| 1824 | clang::ObjCIvarDecl *m_ivar_decl; |
| 1825 | const char *m_property_setter_name; |
| 1826 | const char *m_property_getter_name; |
| 1827 | uint32_t m_property_attributes; |
| 1828 | std::unique_ptr<ClangASTMetadata> m_metadata_ap; |
| 1829 | }; |
| 1830 | |
| 1831 | bool |
| 1832 | DWARFASTParserClang::ParseTemplateDIE (const DWARFDIE &die, |
| 1833 | ClangASTContext::TemplateParameterInfos &template_param_infos) |
| 1834 | { |
| 1835 | const dw_tag_t tag = die.Tag(); |
| 1836 | |
| 1837 | switch (tag) |
| 1838 | { |
| 1839 | case DW_TAG_template_type_parameter: |
| 1840 | case DW_TAG_template_value_parameter: |
| 1841 | { |
| 1842 | DWARFAttributes attributes; |
| 1843 | const size_t num_attributes = die.GetAttributes (attributes); |
| 1844 | const char *name = NULL; |
| 1845 | Type *lldb_type = NULL; |
| 1846 | CompilerType clang_type; |
| 1847 | uint64_t uval64 = 0; |
| 1848 | bool uval64_valid = false; |
| 1849 | if (num_attributes > 0) |
| 1850 | { |
| 1851 | DWARFFormValue form_value; |
| 1852 | for (size_t i=0; i<num_attributes; ++i) |
| 1853 | { |
| 1854 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 1855 | |
| 1856 | switch (attr) |
| 1857 | { |
| 1858 | case DW_AT_name: |
| 1859 | if (attributes.ExtractFormValueAtIndex(i, form_value)) |
| 1860 | name = form_value.AsCString(); |
| 1861 | break; |
| 1862 | |
| 1863 | case DW_AT_type: |
| 1864 | if (attributes.ExtractFormValueAtIndex(i, form_value)) |
| 1865 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 1866 | lldb_type = die.ResolveTypeUID(DIERef(form_value).GetUID()); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1867 | if (lldb_type) |
| 1868 | clang_type = lldb_type->GetForwardCompilerType (); |
| 1869 | } |
| 1870 | break; |
| 1871 | |
| 1872 | case DW_AT_const_value: |
| 1873 | if (attributes.ExtractFormValueAtIndex(i, form_value)) |
| 1874 | { |
| 1875 | uval64_valid = true; |
| 1876 | uval64 = form_value.Unsigned(); |
| 1877 | } |
| 1878 | break; |
| 1879 | default: |
| 1880 | break; |
| 1881 | } |
| 1882 | } |
| 1883 | |
| 1884 | clang::ASTContext *ast = m_ast.getASTContext(); |
| 1885 | if (!clang_type) |
| 1886 | clang_type = m_ast.GetBasicType(eBasicTypeVoid); |
| 1887 | |
| 1888 | if (clang_type) |
| 1889 | { |
| 1890 | bool is_signed = false; |
| 1891 | if (name && name[0]) |
| 1892 | template_param_infos.names.push_back(name); |
| 1893 | else |
| 1894 | template_param_infos.names.push_back(NULL); |
| 1895 | |
| 1896 | if (tag == DW_TAG_template_value_parameter && |
| 1897 | lldb_type != NULL && |
| 1898 | clang_type.IsIntegerType (is_signed) && |
| 1899 | uval64_valid) |
| 1900 | { |
| 1901 | llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed); |
| 1902 | template_param_infos.args.push_back (clang::TemplateArgument (*ast, |
| 1903 | llvm::APSInt(apint), |
| 1904 | ClangASTContext::GetQualType(clang_type))); |
| 1905 | } |
| 1906 | else |
| 1907 | { |
| 1908 | template_param_infos.args.push_back (clang::TemplateArgument (ClangASTContext::GetQualType(clang_type))); |
| 1909 | } |
| 1910 | } |
| 1911 | else |
| 1912 | { |
| 1913 | return false; |
| 1914 | } |
| 1915 | |
| 1916 | } |
| 1917 | } |
| 1918 | return true; |
| 1919 | |
| 1920 | default: |
| 1921 | break; |
| 1922 | } |
| 1923 | return false; |
| 1924 | } |
| 1925 | |
| 1926 | bool |
| 1927 | DWARFASTParserClang::ParseTemplateParameterInfos (const DWARFDIE &parent_die, |
| 1928 | ClangASTContext::TemplateParameterInfos &template_param_infos) |
| 1929 | { |
| 1930 | |
| 1931 | if (!parent_die) |
| 1932 | return false; |
| 1933 | |
| 1934 | Args template_parameter_names; |
| 1935 | for (DWARFDIE die = parent_die.GetFirstChild(); |
| 1936 | die.IsValid(); |
| 1937 | die = die.GetSibling()) |
| 1938 | { |
| 1939 | const dw_tag_t tag = die.Tag(); |
| 1940 | |
| 1941 | switch (tag) |
| 1942 | { |
| 1943 | case DW_TAG_template_type_parameter: |
| 1944 | case DW_TAG_template_value_parameter: |
| 1945 | ParseTemplateDIE (die, template_param_infos); |
| 1946 | break; |
| 1947 | |
| 1948 | default: |
| 1949 | break; |
| 1950 | } |
| 1951 | } |
| 1952 | if (template_param_infos.args.empty()) |
| 1953 | return false; |
| 1954 | return template_param_infos.args.size() == template_param_infos.names.size(); |
| 1955 | } |
| 1956 | |
| 1957 | bool |
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 1958 | DWARFASTParserClang::CanCompleteType (const lldb_private::CompilerType &compiler_type) |
| 1959 | { |
| 1960 | if (m_clang_ast_importer_ap) |
| 1961 | return ClangASTContext::CanImport(compiler_type, GetClangASTImporter()); |
| 1962 | else |
| 1963 | return false; |
| 1964 | } |
| 1965 | |
| 1966 | bool |
| 1967 | DWARFASTParserClang::CompleteType (const lldb_private::CompilerType &compiler_type) |
| 1968 | { |
| 1969 | if (CanCompleteType(compiler_type)) |
| 1970 | { |
| 1971 | if (ClangASTContext::Import(compiler_type, GetClangASTImporter())) |
| 1972 | { |
| 1973 | ClangASTContext::CompleteTagDeclarationDefinition(compiler_type); |
| 1974 | return true; |
| 1975 | } |
| 1976 | else |
| 1977 | { |
| 1978 | ClangASTContext::SetHasExternalStorage (compiler_type.GetOpaqueQualType(), false); |
| 1979 | } |
| 1980 | } |
| 1981 | return false; |
| 1982 | } |
| 1983 | |
| 1984 | bool |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1985 | DWARFASTParserClang::CompleteTypeFromDWARF (const DWARFDIE &die, |
| 1986 | lldb_private::Type *type, |
| 1987 | CompilerType &clang_type) |
| 1988 | { |
| Greg Clayton | fb85e62 | 2016-02-09 22:36:24 +0000 | [diff] [blame^] | 1989 | SymbolFileDWARF *dwarf = die.GetDWARF(); |
| 1990 | |
| 1991 | lldb_private::Mutex::Locker locker(dwarf->GetObjectFile()->GetModule()->GetMutex()); |
| 1992 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 1993 | // Disable external storage for this type so we don't get anymore |
| 1994 | // clang::ExternalASTSource queries for this type. |
| 1995 | m_ast.SetHasExternalStorage (clang_type.GetOpaqueQualType(), false); |
| 1996 | |
| 1997 | if (!die) |
| 1998 | return false; |
| 1999 | |
| 2000 | const dw_tag_t tag = die.Tag(); |
| 2001 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2002 | Log *log = nullptr; // (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION)); |
| 2003 | if (log) |
| 2004 | dwarf->GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log, |
| 2005 | "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...", |
| 2006 | die.GetID(), |
| 2007 | die.GetTagAsCString(), |
| 2008 | type->GetName().AsCString()); |
| 2009 | assert (clang_type); |
| 2010 | DWARFAttributes attributes; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2011 | switch (tag) |
| 2012 | { |
| 2013 | case DW_TAG_structure_type: |
| 2014 | case DW_TAG_union_type: |
| 2015 | case DW_TAG_class_type: |
| 2016 | { |
| 2017 | LayoutInfo layout_info; |
| 2018 | |
| 2019 | { |
| 2020 | if (die.HasChildren()) |
| 2021 | { |
| 2022 | LanguageType class_language = eLanguageTypeUnknown; |
| 2023 | if (ClangASTContext::IsObjCObjectOrInterfaceType(clang_type)) |
| 2024 | { |
| 2025 | class_language = eLanguageTypeObjC; |
| 2026 | // For objective C we don't start the definition when |
| 2027 | // the class is created. |
| 2028 | ClangASTContext::StartTagDeclarationDefinition (clang_type); |
| 2029 | } |
| 2030 | |
| 2031 | int tag_decl_kind = -1; |
| 2032 | AccessType default_accessibility = eAccessNone; |
| 2033 | if (tag == DW_TAG_structure_type) |
| 2034 | { |
| 2035 | tag_decl_kind = clang::TTK_Struct; |
| 2036 | default_accessibility = eAccessPublic; |
| 2037 | } |
| 2038 | else if (tag == DW_TAG_union_type) |
| 2039 | { |
| 2040 | tag_decl_kind = clang::TTK_Union; |
| 2041 | default_accessibility = eAccessPublic; |
| 2042 | } |
| 2043 | else if (tag == DW_TAG_class_type) |
| 2044 | { |
| 2045 | tag_decl_kind = clang::TTK_Class; |
| 2046 | default_accessibility = eAccessPrivate; |
| 2047 | } |
| 2048 | |
| 2049 | SymbolContext sc(die.GetLLDBCompileUnit()); |
| 2050 | std::vector<clang::CXXBaseSpecifier *> base_classes; |
| 2051 | std::vector<int> member_accessibilities; |
| 2052 | bool is_a_class = false; |
| 2053 | // Parse members and base classes first |
| 2054 | DWARFDIECollection member_function_dies; |
| 2055 | |
| 2056 | DelayedPropertyList delayed_properties; |
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2057 | ParseChildMembers (sc, |
| 2058 | die, |
| 2059 | clang_type, |
| 2060 | class_language, |
| 2061 | base_classes, |
| 2062 | member_accessibilities, |
| 2063 | member_function_dies, |
| 2064 | delayed_properties, |
| 2065 | default_accessibility, |
| 2066 | is_a_class, |
| 2067 | layout_info); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2068 | |
| 2069 | // Now parse any methods if there were any... |
| 2070 | size_t num_functions = member_function_dies.Size(); |
| 2071 | if (num_functions > 0) |
| 2072 | { |
| 2073 | for (size_t i=0; i<num_functions; ++i) |
| 2074 | { |
| 2075 | dwarf->ResolveType(member_function_dies.GetDIEAtIndex(i)); |
| 2076 | } |
| 2077 | } |
| 2078 | |
| 2079 | if (class_language == eLanguageTypeObjC) |
| 2080 | { |
| 2081 | ConstString class_name (clang_type.GetTypeName()); |
| 2082 | if (class_name) |
| 2083 | { |
| 2084 | DIEArray method_die_offsets; |
| 2085 | dwarf->GetObjCMethodDIEOffsets(class_name, method_die_offsets); |
| 2086 | |
| 2087 | if (!method_die_offsets.empty()) |
| 2088 | { |
| 2089 | DWARFDebugInfo* debug_info = dwarf->DebugInfo(); |
| 2090 | |
| 2091 | const size_t num_matches = method_die_offsets.size(); |
| 2092 | for (size_t i=0; i<num_matches; ++i) |
| 2093 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 2094 | const DIERef& die_ref = method_die_offsets[i]; |
| 2095 | DWARFDIE method_die = debug_info->GetDIE (die_ref); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2096 | |
| 2097 | if (method_die) |
| 2098 | method_die.ResolveType (); |
| 2099 | } |
| 2100 | } |
| 2101 | |
| 2102 | for (DelayedPropertyList::iterator pi = delayed_properties.begin(), pe = delayed_properties.end(); |
| 2103 | pi != pe; |
| 2104 | ++pi) |
| 2105 | pi->Finalize(); |
| 2106 | } |
| 2107 | } |
| 2108 | |
| 2109 | // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we |
| 2110 | // need to tell the clang type it is actually a class. |
| 2111 | if (class_language != eLanguageTypeObjC) |
| 2112 | { |
| 2113 | if (is_a_class && tag_decl_kind != clang::TTK_Class) |
| 2114 | m_ast.SetTagTypeKind (ClangASTContext::GetQualType(clang_type), clang::TTK_Class); |
| 2115 | } |
| 2116 | |
| 2117 | // Since DW_TAG_structure_type gets used for both classes |
| 2118 | // and structures, we may need to set any DW_TAG_member |
| 2119 | // fields to have a "private" access if none was specified. |
| 2120 | // When we parsed the child members we tracked that actual |
| 2121 | // accessibility value for each DW_TAG_member in the |
| 2122 | // "member_accessibilities" array. If the value for the |
| 2123 | // member is zero, then it was set to the "default_accessibility" |
| 2124 | // which for structs was "public". Below we correct this |
| 2125 | // by setting any fields to "private" that weren't correctly |
| 2126 | // set. |
| 2127 | if (is_a_class && !member_accessibilities.empty()) |
| 2128 | { |
| 2129 | // This is a class and all members that didn't have |
| 2130 | // their access specified are private. |
| 2131 | m_ast.SetDefaultAccessForRecordFields (m_ast.GetAsRecordDecl(clang_type), |
| 2132 | eAccessPrivate, |
| 2133 | &member_accessibilities.front(), |
| 2134 | member_accessibilities.size()); |
| 2135 | } |
| 2136 | |
| 2137 | if (!base_classes.empty()) |
| 2138 | { |
| 2139 | // Make sure all base classes refer to complete types and not |
| 2140 | // forward declarations. If we don't do this, clang will crash |
| 2141 | // with an assertion in the call to clang_type.SetBaseClassesForClassType() |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2142 | for (auto &base_class : base_classes) |
| 2143 | { |
| 2144 | clang::TypeSourceInfo *type_source_info = base_class->getTypeSourceInfo(); |
| 2145 | if (type_source_info) |
| 2146 | { |
| 2147 | CompilerType base_class_type (&m_ast, type_source_info->getType().getAsOpaquePtr()); |
| 2148 | if (base_class_type.GetCompleteType() == false) |
| 2149 | { |
| Siva Chandra | cebabb9 | 2015-09-23 17:47:08 +0000 | [diff] [blame] | 2150 | auto module = dwarf->GetObjectFile()->GetModule(); |
| 2151 | module->ReportError ( |
| 2152 | ":: Class '%s' has a base class '%s' which does not have a complete definition.", |
| 2153 | die.GetName(), |
| 2154 | base_class_type.GetTypeName().GetCString()); |
| 2155 | if (die.GetCU()->GetProducer() == DWARFCompileUnit::eProducerClang) |
| 2156 | module->ReportError (":: Try compiling the source file with -fno-limit-debug-info."); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2157 | |
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2158 | // We have no choice other than to pretend that the base class |
| 2159 | // is complete. If we don't do this, clang will crash when we |
| 2160 | // call setBases() inside of "clang_type.SetBaseClassesForClassType()" |
| 2161 | // below. Since we provide layout assistance, all ivars in this |
| 2162 | // class and other classes will be fine, this is the best we can do |
| 2163 | // short of crashing. |
| 2164 | ClangASTContext::StartTagDeclarationDefinition (base_class_type); |
| 2165 | ClangASTContext::CompleteTagDeclarationDefinition (base_class_type); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2166 | } |
| 2167 | } |
| 2168 | } |
| 2169 | m_ast.SetBaseClassesForClassType (clang_type.GetOpaqueQualType(), |
| 2170 | &base_classes.front(), |
| 2171 | base_classes.size()); |
| 2172 | |
| 2173 | // Clang will copy each CXXBaseSpecifier in "base_classes" |
| 2174 | // so we have to free them all. |
| 2175 | ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(), |
| 2176 | base_classes.size()); |
| 2177 | } |
| 2178 | } |
| 2179 | } |
| 2180 | |
| 2181 | ClangASTContext::BuildIndirectFields (clang_type); |
| 2182 | ClangASTContext::CompleteTagDeclarationDefinition (clang_type); |
| 2183 | |
| 2184 | if (!layout_info.field_offsets.empty() || |
| 2185 | !layout_info.base_offsets.empty() || |
| 2186 | !layout_info.vbase_offsets.empty() ) |
| 2187 | { |
| 2188 | if (type) |
| 2189 | layout_info.bit_size = type->GetByteSize() * 8; |
| 2190 | if (layout_info.bit_size == 0) |
| 2191 | layout_info.bit_size = die.GetAttributeValueAsUnsigned(DW_AT_byte_size, 0) * 8; |
| 2192 | |
| 2193 | clang::CXXRecordDecl *record_decl = m_ast.GetAsCXXRecordDecl(clang_type.GetOpaqueQualType()); |
| 2194 | if (record_decl) |
| 2195 | { |
| 2196 | if (log) |
| 2197 | { |
| 2198 | ModuleSP module_sp = dwarf->GetObjectFile()->GetModule(); |
| 2199 | |
| 2200 | if (module_sp) |
| 2201 | { |
| 2202 | module_sp->LogMessage (log, |
| 2203 | "ClangASTContext::CompleteTypeFromDWARF (clang_type = %p) caching layout info for record_decl = %p, bit_size = %" PRIu64 ", alignment = %" PRIu64 ", field_offsets[%u], base_offsets[%u], vbase_offsets[%u])", |
| 2204 | static_cast<void*>(clang_type.GetOpaqueQualType()), |
| 2205 | static_cast<void*>(record_decl), |
| 2206 | layout_info.bit_size, |
| 2207 | layout_info.alignment, |
| 2208 | static_cast<uint32_t>(layout_info.field_offsets.size()), |
| 2209 | static_cast<uint32_t>(layout_info.base_offsets.size()), |
| 2210 | static_cast<uint32_t>(layout_info.vbase_offsets.size())); |
| 2211 | |
| 2212 | uint32_t idx; |
| 2213 | { |
| 2214 | llvm::DenseMap<const clang::FieldDecl *, uint64_t>::const_iterator pos, |
| 2215 | end = layout_info.field_offsets.end(); |
| 2216 | for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx) |
| 2217 | { |
| 2218 | module_sp->LogMessage(log, |
| 2219 | "ClangASTContext::CompleteTypeFromDWARF (clang_type = %p) field[%u] = { bit_offset=%u, name='%s' }", |
| 2220 | static_cast<void *>(clang_type.GetOpaqueQualType()), |
| 2221 | idx, |
| 2222 | static_cast<uint32_t>(pos->second), |
| 2223 | pos->first->getNameAsString().c_str()); |
| 2224 | } |
| 2225 | } |
| 2226 | |
| 2227 | { |
| 2228 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos, |
| 2229 | base_end = layout_info.base_offsets.end(); |
| 2230 | for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; ++base_pos, ++idx) |
| 2231 | { |
| 2232 | module_sp->LogMessage(log, |
| 2233 | "ClangASTContext::CompleteTypeFromDWARF (clang_type = %p) base[%u] = { byte_offset=%u, name='%s' }", |
| 2234 | clang_type.GetOpaqueQualType(), idx, (uint32_t)base_pos->second.getQuantity(), |
| 2235 | base_pos->first->getNameAsString().c_str()); |
| 2236 | } |
| 2237 | } |
| 2238 | { |
| 2239 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos, |
| 2240 | vbase_end = layout_info.vbase_offsets.end(); |
| 2241 | for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; ++vbase_pos, ++idx) |
| 2242 | { |
| 2243 | module_sp->LogMessage(log, |
| 2244 | "ClangASTContext::CompleteTypeFromDWARF (clang_type = %p) vbase[%u] = { byte_offset=%u, name='%s' }", |
| 2245 | static_cast<void *>(clang_type.GetOpaqueQualType()), idx, |
| 2246 | static_cast<uint32_t>(vbase_pos->second.getQuantity()), |
| 2247 | vbase_pos->first->getNameAsString().c_str()); |
| 2248 | } |
| 2249 | } |
| 2250 | |
| 2251 | } |
| 2252 | } |
| 2253 | m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info)); |
| 2254 | } |
| 2255 | } |
| 2256 | } |
| 2257 | |
| 2258 | return (bool)clang_type; |
| 2259 | |
| 2260 | case DW_TAG_enumeration_type: |
| 2261 | ClangASTContext::StartTagDeclarationDefinition (clang_type); |
| 2262 | if (die.HasChildren()) |
| 2263 | { |
| 2264 | SymbolContext sc(die.GetLLDBCompileUnit()); |
| 2265 | bool is_signed = false; |
| 2266 | clang_type.IsIntegerType(is_signed); |
| 2267 | ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), die); |
| 2268 | } |
| 2269 | ClangASTContext::CompleteTagDeclarationDefinition (clang_type); |
| 2270 | return (bool)clang_type; |
| 2271 | |
| 2272 | default: |
| 2273 | assert(false && "not a forward clang type decl!"); |
| 2274 | break; |
| 2275 | } |
| 2276 | |
| 2277 | return false; |
| 2278 | } |
| 2279 | |
| Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 2280 | std::vector<DWARFDIE> |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 2281 | DWARFASTParserClang::GetDIEForDeclContext(lldb_private::CompilerDeclContext decl_context) |
| Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 2282 | { |
| 2283 | std::vector<DWARFDIE> result; |
| 2284 | for (auto it = m_decl_ctx_to_die.find((clang::DeclContext *)decl_context.GetOpaqueDeclContext()); it != m_decl_ctx_to_die.end(); it++) |
| 2285 | result.push_back(it->second); |
| 2286 | return result; |
| 2287 | } |
| 2288 | |
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 2289 | CompilerDecl |
| 2290 | DWARFASTParserClang::GetDeclForUIDFromDWARF (const DWARFDIE &die) |
| 2291 | { |
| 2292 | clang::Decl *clang_decl = GetClangDeclForDIE(die); |
| 2293 | if (clang_decl != nullptr) |
| 2294 | return CompilerDecl(&m_ast, clang_decl); |
| 2295 | return CompilerDecl(); |
| 2296 | } |
| 2297 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2298 | CompilerDeclContext |
| 2299 | DWARFASTParserClang::GetDeclContextForUIDFromDWARF (const DWARFDIE &die) |
| 2300 | { |
| 2301 | clang::DeclContext *clang_decl_ctx = GetClangDeclContextForDIE (die); |
| 2302 | if (clang_decl_ctx) |
| 2303 | return CompilerDeclContext(&m_ast, clang_decl_ctx); |
| 2304 | return CompilerDeclContext(); |
| 2305 | } |
| 2306 | |
| 2307 | CompilerDeclContext |
| 2308 | DWARFASTParserClang::GetDeclContextContainingUIDFromDWARF (const DWARFDIE &die) |
| 2309 | { |
| 2310 | clang::DeclContext *clang_decl_ctx = GetClangDeclContextContainingDIE (die, nullptr); |
| 2311 | if (clang_decl_ctx) |
| 2312 | return CompilerDeclContext(&m_ast, clang_decl_ctx); |
| 2313 | return CompilerDeclContext(); |
| 2314 | } |
| 2315 | |
| 2316 | size_t |
| 2317 | DWARFASTParserClang::ParseChildEnumerators (const SymbolContext& sc, |
| 2318 | lldb_private::CompilerType &clang_type, |
| 2319 | bool is_signed, |
| 2320 | uint32_t enumerator_byte_size, |
| 2321 | const DWARFDIE &parent_die) |
| 2322 | { |
| 2323 | if (!parent_die) |
| 2324 | return 0; |
| 2325 | |
| 2326 | size_t enumerators_added = 0; |
| 2327 | |
| 2328 | for (DWARFDIE die = parent_die.GetFirstChild(); die.IsValid(); die = die.GetSibling()) |
| 2329 | { |
| 2330 | const dw_tag_t tag = die.Tag(); |
| 2331 | if (tag == DW_TAG_enumerator) |
| 2332 | { |
| 2333 | DWARFAttributes attributes; |
| 2334 | const size_t num_child_attributes = die.GetAttributes(attributes); |
| 2335 | if (num_child_attributes > 0) |
| 2336 | { |
| 2337 | const char *name = NULL; |
| 2338 | bool got_value = false; |
| 2339 | int64_t enum_value = 0; |
| 2340 | Declaration decl; |
| 2341 | |
| 2342 | uint32_t i; |
| 2343 | for (i=0; i<num_child_attributes; ++i) |
| 2344 | { |
| 2345 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 2346 | DWARFFormValue form_value; |
| 2347 | if (attributes.ExtractFormValueAtIndex(i, form_value)) |
| 2348 | { |
| 2349 | switch (attr) |
| 2350 | { |
| 2351 | case DW_AT_const_value: |
| 2352 | got_value = true; |
| 2353 | if (is_signed) |
| 2354 | enum_value = form_value.Signed(); |
| 2355 | else |
| 2356 | enum_value = form_value.Unsigned(); |
| 2357 | break; |
| 2358 | |
| 2359 | case DW_AT_name: |
| 2360 | name = form_value.AsCString(); |
| 2361 | break; |
| 2362 | |
| 2363 | case DW_AT_description: |
| 2364 | default: |
| 2365 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 2366 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 2367 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 2368 | case DW_AT_sibling: |
| 2369 | break; |
| 2370 | } |
| 2371 | } |
| 2372 | } |
| 2373 | |
| 2374 | if (name && name[0] && got_value) |
| 2375 | { |
| 2376 | m_ast.AddEnumerationValueToEnumerationType (clang_type.GetOpaqueQualType(), |
| 2377 | m_ast.GetEnumerationIntegerType(clang_type.GetOpaqueQualType()), |
| 2378 | decl, |
| 2379 | name, |
| 2380 | enum_value, |
| 2381 | enumerator_byte_size * 8); |
| 2382 | ++enumerators_added; |
| 2383 | } |
| 2384 | } |
| 2385 | } |
| 2386 | } |
| 2387 | return enumerators_added; |
| 2388 | } |
| 2389 | |
| 2390 | #if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE) |
| 2391 | |
| 2392 | class DIEStack |
| 2393 | { |
| 2394 | public: |
| 2395 | |
| 2396 | void Push (const DWARFDIE &die) |
| 2397 | { |
| 2398 | m_dies.push_back (die); |
| 2399 | } |
| 2400 | |
| 2401 | |
| 2402 | void LogDIEs (Log *log) |
| 2403 | { |
| 2404 | StreamString log_strm; |
| 2405 | const size_t n = m_dies.size(); |
| 2406 | log_strm.Printf("DIEStack[%" PRIu64 "]:\n", (uint64_t)n); |
| 2407 | for (size_t i=0; i<n; i++) |
| 2408 | { |
| 2409 | std::string qualified_name; |
| 2410 | const DWARFDIE &die = m_dies[i]; |
| 2411 | die.GetQualifiedName(qualified_name); |
| 2412 | log_strm.Printf ("[%" PRIu64 "] 0x%8.8x: %s name='%s'\n", |
| 2413 | (uint64_t)i, |
| 2414 | die.GetOffset(), |
| 2415 | die.GetTagAsCString(), |
| 2416 | qualified_name.c_str()); |
| 2417 | } |
| 2418 | log->PutCString(log_strm.GetData()); |
| 2419 | } |
| 2420 | void Pop () |
| 2421 | { |
| 2422 | m_dies.pop_back(); |
| 2423 | } |
| 2424 | |
| 2425 | class ScopedPopper |
| 2426 | { |
| 2427 | public: |
| 2428 | ScopedPopper (DIEStack &die_stack) : |
| 2429 | m_die_stack (die_stack), |
| 2430 | m_valid (false) |
| 2431 | { |
| 2432 | } |
| 2433 | |
| 2434 | void |
| 2435 | Push (const DWARFDIE &die) |
| 2436 | { |
| 2437 | m_valid = true; |
| 2438 | m_die_stack.Push (die); |
| 2439 | } |
| 2440 | |
| 2441 | ~ScopedPopper () |
| 2442 | { |
| 2443 | if (m_valid) |
| 2444 | m_die_stack.Pop(); |
| 2445 | } |
| 2446 | |
| 2447 | |
| 2448 | |
| 2449 | protected: |
| 2450 | DIEStack &m_die_stack; |
| 2451 | bool m_valid; |
| 2452 | }; |
| 2453 | |
| 2454 | protected: |
| 2455 | typedef std::vector<DWARFDIE> Stack; |
| 2456 | Stack m_dies; |
| 2457 | }; |
| 2458 | #endif |
| 2459 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2460 | Function * |
| 2461 | DWARFASTParserClang::ParseFunctionFromDWARF (const SymbolContext& sc, |
| 2462 | const DWARFDIE &die) |
| 2463 | { |
| 2464 | DWARFRangeList func_ranges; |
| 2465 | const char *name = NULL; |
| 2466 | const char *mangled = NULL; |
| 2467 | int decl_file = 0; |
| 2468 | int decl_line = 0; |
| 2469 | int decl_column = 0; |
| 2470 | int call_file = 0; |
| 2471 | int call_line = 0; |
| 2472 | int call_column = 0; |
| 2473 | DWARFExpression frame_base(die.GetCU()); |
| 2474 | |
| 2475 | const dw_tag_t tag = die.Tag(); |
| 2476 | |
| 2477 | if (tag != DW_TAG_subprogram) |
| 2478 | return NULL; |
| 2479 | |
| 2480 | if (die.GetDIENamesAndRanges (name, |
| 2481 | mangled, |
| 2482 | func_ranges, |
| 2483 | decl_file, |
| 2484 | decl_line, |
| 2485 | decl_column, |
| 2486 | call_file, |
| 2487 | call_line, |
| 2488 | call_column, |
| 2489 | &frame_base)) |
| 2490 | { |
| 2491 | |
| 2492 | // Union of all ranges in the function DIE (if the function is discontiguous) |
| 2493 | AddressRange func_range; |
| 2494 | lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0); |
| 2495 | lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0); |
| 2496 | if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr) |
| 2497 | { |
| 2498 | ModuleSP module_sp (die.GetModule()); |
| 2499 | func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, module_sp->GetSectionList()); |
| 2500 | if (func_range.GetBaseAddress().IsValid()) |
| 2501 | func_range.SetByteSize(highest_func_addr - lowest_func_addr); |
| 2502 | } |
| 2503 | |
| 2504 | if (func_range.GetBaseAddress().IsValid()) |
| 2505 | { |
| 2506 | Mangled func_name; |
| 2507 | if (mangled) |
| 2508 | func_name.SetValue(ConstString(mangled), true); |
| 2509 | else if (die.GetParent().Tag() == DW_TAG_compile_unit && |
| Jim Ingham | 0e0984e | 2015-09-02 01:06:46 +0000 | [diff] [blame] | 2510 | Language::LanguageIsCPlusPlus(die.GetLanguage()) && |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2511 | name && strcmp(name, "main") != 0) |
| 2512 | { |
| 2513 | // If the mangled name is not present in the DWARF, generate the demangled name |
| 2514 | // using the decl context. We skip if the function is "main" as its name is |
| 2515 | // never mangled. |
| 2516 | bool is_static = false; |
| 2517 | bool is_variadic = false; |
| Greg Clayton | fb85e62 | 2016-02-09 22:36:24 +0000 | [diff] [blame^] | 2518 | bool has_template_params = false; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2519 | unsigned type_quals = 0; |
| 2520 | std::vector<CompilerType> param_types; |
| 2521 | std::vector<clang::ParmVarDecl*> param_decls; |
| 2522 | DWARFDeclContext decl_ctx; |
| 2523 | StreamString sstr; |
| 2524 | |
| 2525 | die.GetDWARFDeclContext(decl_ctx); |
| 2526 | sstr << decl_ctx.GetQualifiedName(); |
| 2527 | |
| 2528 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE(die, nullptr); |
| 2529 | ParseChildParameters(sc, |
| 2530 | containing_decl_ctx, |
| 2531 | die, |
| 2532 | true, |
| 2533 | is_static, |
| 2534 | is_variadic, |
| Greg Clayton | fb85e62 | 2016-02-09 22:36:24 +0000 | [diff] [blame^] | 2535 | has_template_params, |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2536 | param_types, |
| 2537 | param_decls, |
| 2538 | type_quals); |
| 2539 | sstr << "("; |
| 2540 | for (size_t i = 0; i < param_types.size(); i++) |
| 2541 | { |
| 2542 | if (i > 0) |
| 2543 | sstr << ", "; |
| 2544 | sstr << param_types[i].GetTypeName(); |
| 2545 | } |
| 2546 | if (is_variadic) |
| 2547 | sstr << ", ..."; |
| 2548 | sstr << ")"; |
| 2549 | if (type_quals & clang::Qualifiers::Const) |
| 2550 | sstr << " const"; |
| 2551 | |
| 2552 | func_name.SetValue(ConstString(sstr.GetData()), false); |
| 2553 | } |
| 2554 | else |
| 2555 | func_name.SetValue(ConstString(name), false); |
| 2556 | |
| 2557 | FunctionSP func_sp; |
| 2558 | std::unique_ptr<Declaration> decl_ap; |
| 2559 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) |
| 2560 | decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), |
| 2561 | decl_line, |
| 2562 | decl_column)); |
| 2563 | |
| 2564 | SymbolFileDWARF *dwarf = die.GetDWARF(); |
| 2565 | // Supply the type _only_ if it has already been parsed |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 2566 | Type *func_type = dwarf->GetDIEToType().lookup (die.GetDIE()); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2567 | |
| 2568 | assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED); |
| 2569 | |
| 2570 | if (dwarf->FixupAddress (func_range.GetBaseAddress())) |
| 2571 | { |
| 2572 | const user_id_t func_user_id = die.GetID(); |
| 2573 | func_sp.reset(new Function (sc.comp_unit, |
| 2574 | func_user_id, // UserID is the DIE offset |
| 2575 | func_user_id, |
| 2576 | func_name, |
| 2577 | func_type, |
| 2578 | func_range)); // first address range |
| 2579 | |
| 2580 | if (func_sp.get() != NULL) |
| 2581 | { |
| 2582 | if (frame_base.IsValid()) |
| 2583 | func_sp->GetFrameBaseExpression() = frame_base; |
| 2584 | sc.comp_unit->AddFunction(func_sp); |
| 2585 | return func_sp.get(); |
| 2586 | } |
| 2587 | } |
| 2588 | } |
| 2589 | } |
| 2590 | return NULL; |
| 2591 | } |
| 2592 | |
| 2593 | |
| Siva Chandra | cebabb9 | 2015-09-23 17:47:08 +0000 | [diff] [blame] | 2594 | bool |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2595 | DWARFASTParserClang::ParseChildMembers (const SymbolContext& sc, |
| 2596 | const DWARFDIE &parent_die, |
| 2597 | CompilerType &class_clang_type, |
| 2598 | const LanguageType class_language, |
| 2599 | std::vector<clang::CXXBaseSpecifier *>& base_classes, |
| 2600 | std::vector<int>& member_accessibilities, |
| 2601 | DWARFDIECollection& member_function_dies, |
| 2602 | DelayedPropertyList& delayed_properties, |
| 2603 | AccessType& default_accessibility, |
| 2604 | bool &is_a_class, |
| 2605 | LayoutInfo &layout_info) |
| 2606 | { |
| 2607 | if (!parent_die) |
| 2608 | return 0; |
| 2609 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2610 | uint32_t member_idx = 0; |
| 2611 | BitfieldInfo last_field_info; |
| 2612 | |
| 2613 | ModuleSP module_sp = parent_die.GetDWARF()->GetObjectFile()->GetModule(); |
| Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 2614 | ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(class_clang_type.GetTypeSystem()); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2615 | if (ast == nullptr) |
| 2616 | return 0; |
| 2617 | |
| 2618 | for (DWARFDIE die = parent_die.GetFirstChild(); die.IsValid(); die = die.GetSibling()) |
| 2619 | { |
| 2620 | dw_tag_t tag = die.Tag(); |
| 2621 | |
| 2622 | switch (tag) |
| 2623 | { |
| 2624 | case DW_TAG_member: |
| 2625 | case DW_TAG_APPLE_property: |
| 2626 | { |
| 2627 | DWARFAttributes attributes; |
| 2628 | const size_t num_attributes = die.GetAttributes (attributes); |
| 2629 | if (num_attributes > 0) |
| 2630 | { |
| 2631 | Declaration decl; |
| 2632 | //DWARFExpression location; |
| 2633 | const char *name = NULL; |
| 2634 | const char *prop_name = NULL; |
| 2635 | const char *prop_getter_name = NULL; |
| 2636 | const char *prop_setter_name = NULL; |
| 2637 | uint32_t prop_attributes = 0; |
| 2638 | |
| 2639 | |
| 2640 | bool is_artificial = false; |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 2641 | DWARFFormValue encoding_form; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2642 | AccessType accessibility = eAccessNone; |
| 2643 | uint32_t member_byte_offset = UINT32_MAX; |
| 2644 | size_t byte_size = 0; |
| 2645 | size_t bit_offset = 0; |
| 2646 | size_t bit_size = 0; |
| 2647 | bool is_external = false; // On DW_TAG_members, this means the member is static |
| 2648 | uint32_t i; |
| 2649 | for (i=0; i<num_attributes && !is_artificial; ++i) |
| 2650 | { |
| 2651 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 2652 | DWARFFormValue form_value; |
| 2653 | if (attributes.ExtractFormValueAtIndex(i, form_value)) |
| 2654 | { |
| 2655 | switch (attr) |
| 2656 | { |
| 2657 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 2658 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 2659 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 2660 | case DW_AT_name: name = form_value.AsCString(); break; |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 2661 | case DW_AT_type: encoding_form = form_value; break; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2662 | case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break; |
| 2663 | case DW_AT_bit_size: bit_size = form_value.Unsigned(); break; |
| 2664 | case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; |
| 2665 | case DW_AT_data_member_location: |
| 2666 | if (form_value.BlockData()) |
| 2667 | { |
| 2668 | Value initialValue(0); |
| 2669 | Value memberOffset(0); |
| 2670 | const DWARFDataExtractor& debug_info_data = die.GetDWARF()->get_debug_info_data(); |
| 2671 | uint32_t block_length = form_value.Unsigned(); |
| 2672 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 2673 | if (DWARFExpression::Evaluate(NULL, // ExecutionContext * |
| 2674 | NULL, // ClangExpressionVariableList * |
| 2675 | NULL, // ClangExpressionDeclMap * |
| 2676 | NULL, // RegisterContext * |
| 2677 | module_sp, |
| 2678 | debug_info_data, |
| 2679 | die.GetCU(), |
| 2680 | block_offset, |
| 2681 | block_length, |
| 2682 | eRegisterKindDWARF, |
| 2683 | &initialValue, |
| 2684 | memberOffset, |
| 2685 | NULL)) |
| 2686 | { |
| 2687 | member_byte_offset = memberOffset.ResolveValue(NULL).UInt(); |
| 2688 | } |
| 2689 | } |
| 2690 | else |
| 2691 | { |
| 2692 | // With DWARF 3 and later, if the value is an integer constant, |
| 2693 | // this form value is the offset in bytes from the beginning |
| 2694 | // of the containing entity. |
| 2695 | member_byte_offset = form_value.Unsigned(); |
| 2696 | } |
| 2697 | break; |
| 2698 | |
| 2699 | case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break; |
| 2700 | case DW_AT_artificial: is_artificial = form_value.Boolean(); break; |
| 2701 | case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(); |
| 2702 | break; |
| 2703 | case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(); |
| 2704 | break; |
| 2705 | case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(); |
| 2706 | break; |
| 2707 | case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break; |
| 2708 | case DW_AT_external: is_external = form_value.Boolean(); break; |
| 2709 | |
| 2710 | default: |
| 2711 | case DW_AT_declaration: |
| 2712 | case DW_AT_description: |
| 2713 | case DW_AT_mutable: |
| 2714 | case DW_AT_visibility: |
| 2715 | case DW_AT_sibling: |
| 2716 | break; |
| 2717 | } |
| 2718 | } |
| 2719 | } |
| 2720 | |
| 2721 | if (prop_name) |
| 2722 | { |
| 2723 | ConstString fixed_getter; |
| 2724 | ConstString fixed_setter; |
| 2725 | |
| 2726 | // Check if the property getter/setter were provided as full |
| 2727 | // names. We want basenames, so we extract them. |
| 2728 | |
| 2729 | if (prop_getter_name && prop_getter_name[0] == '-') |
| 2730 | { |
| Jim Ingham | aa816b8 | 2015-09-02 01:59:14 +0000 | [diff] [blame] | 2731 | ObjCLanguage::MethodName prop_getter_method(prop_getter_name, true); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2732 | prop_getter_name = prop_getter_method.GetSelector().GetCString(); |
| 2733 | } |
| 2734 | |
| 2735 | if (prop_setter_name && prop_setter_name[0] == '-') |
| 2736 | { |
| Jim Ingham | aa816b8 | 2015-09-02 01:59:14 +0000 | [diff] [blame] | 2737 | ObjCLanguage::MethodName prop_setter_method(prop_setter_name, true); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2738 | prop_setter_name = prop_setter_method.GetSelector().GetCString(); |
| 2739 | } |
| 2740 | |
| 2741 | // If the names haven't been provided, they need to be |
| 2742 | // filled in. |
| 2743 | |
| 2744 | if (!prop_getter_name) |
| 2745 | { |
| 2746 | prop_getter_name = prop_name; |
| 2747 | } |
| 2748 | if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly)) |
| 2749 | { |
| 2750 | StreamString ss; |
| 2751 | |
| 2752 | ss.Printf("set%c%s:", |
| 2753 | toupper(prop_name[0]), |
| 2754 | &prop_name[1]); |
| 2755 | |
| 2756 | fixed_setter.SetCString(ss.GetData()); |
| 2757 | prop_setter_name = fixed_setter.GetCString(); |
| 2758 | } |
| 2759 | } |
| 2760 | |
| 2761 | // Clang has a DWARF generation bug where sometimes it |
| 2762 | // represents fields that are references with bad byte size |
| 2763 | // and bit size/offset information such as: |
| 2764 | // |
| 2765 | // DW_AT_byte_size( 0x00 ) |
| 2766 | // DW_AT_bit_size( 0x40 ) |
| 2767 | // DW_AT_bit_offset( 0xffffffffffffffc0 ) |
| 2768 | // |
| 2769 | // So check the bit offset to make sure it is sane, and if |
| 2770 | // the values are not sane, remove them. If we don't do this |
| 2771 | // then we will end up with a crash if we try to use this |
| 2772 | // type in an expression when clang becomes unhappy with its |
| 2773 | // recycled debug info. |
| 2774 | |
| 2775 | if (bit_offset > 128) |
| 2776 | { |
| 2777 | bit_size = 0; |
| 2778 | bit_offset = 0; |
| 2779 | } |
| 2780 | |
| 2781 | // FIXME: Make Clang ignore Objective-C accessibility for expressions |
| 2782 | if (class_language == eLanguageTypeObjC || |
| 2783 | class_language == eLanguageTypeObjC_plus_plus) |
| 2784 | accessibility = eAccessNone; |
| 2785 | |
| 2786 | if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name)) |
| 2787 | { |
| 2788 | // Not all compilers will mark the vtable pointer |
| 2789 | // member as artificial (llvm-gcc). We can't have |
| 2790 | // the virtual members in our classes otherwise it |
| 2791 | // throws off all child offsets since we end up |
| 2792 | // having and extra pointer sized member in our |
| 2793 | // class layouts. |
| 2794 | is_artificial = true; |
| 2795 | } |
| 2796 | |
| 2797 | // Handle static members |
| 2798 | if (is_external && member_byte_offset == UINT32_MAX) |
| 2799 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 2800 | Type *var_type = die.ResolveTypeUID(DIERef(encoding_form).GetUID()); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2801 | |
| 2802 | if (var_type) |
| 2803 | { |
| 2804 | if (accessibility == eAccessNone) |
| 2805 | accessibility = eAccessPublic; |
| 2806 | ClangASTContext::AddVariableToRecordType (class_clang_type, |
| 2807 | name, |
| 2808 | var_type->GetLayoutCompilerType (), |
| 2809 | accessibility); |
| 2810 | } |
| 2811 | break; |
| 2812 | } |
| 2813 | |
| 2814 | if (is_artificial == false) |
| 2815 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 2816 | Type *member_type = die.ResolveTypeUID(DIERef(encoding_form).GetUID()); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2817 | |
| 2818 | clang::FieldDecl *field_decl = NULL; |
| 2819 | if (tag == DW_TAG_member) |
| 2820 | { |
| 2821 | if (member_type) |
| 2822 | { |
| 2823 | if (accessibility == eAccessNone) |
| 2824 | accessibility = default_accessibility; |
| 2825 | member_accessibilities.push_back(accessibility); |
| 2826 | |
| 2827 | uint64_t field_bit_offset = (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8)); |
| 2828 | if (bit_size > 0) |
| 2829 | { |
| 2830 | |
| 2831 | BitfieldInfo this_field_info; |
| 2832 | this_field_info.bit_offset = field_bit_offset; |
| 2833 | this_field_info.bit_size = bit_size; |
| 2834 | |
| 2835 | ///////////////////////////////////////////////////////////// |
| 2836 | // How to locate a field given the DWARF debug information |
| 2837 | // |
| 2838 | // AT_byte_size indicates the size of the word in which the |
| 2839 | // bit offset must be interpreted. |
| 2840 | // |
| 2841 | // AT_data_member_location indicates the byte offset of the |
| 2842 | // word from the base address of the structure. |
| 2843 | // |
| 2844 | // AT_bit_offset indicates how many bits into the word |
| 2845 | // (according to the host endianness) the low-order bit of |
| 2846 | // the field starts. AT_bit_offset can be negative. |
| 2847 | // |
| 2848 | // AT_bit_size indicates the size of the field in bits. |
| 2849 | ///////////////////////////////////////////////////////////// |
| 2850 | |
| 2851 | if (byte_size == 0) |
| 2852 | byte_size = member_type->GetByteSize(); |
| 2853 | |
| 2854 | if (die.GetDWARF()->GetObjectFile()->GetByteOrder() == eByteOrderLittle) |
| 2855 | { |
| 2856 | this_field_info.bit_offset += byte_size * 8; |
| 2857 | this_field_info.bit_offset -= (bit_offset + bit_size); |
| 2858 | } |
| 2859 | else |
| 2860 | { |
| 2861 | this_field_info.bit_offset += bit_offset; |
| 2862 | } |
| 2863 | |
| 2864 | // Update the field bit offset we will report for layout |
| 2865 | field_bit_offset = this_field_info.bit_offset; |
| 2866 | |
| 2867 | // If the member to be emitted did not start on a character boundary and there is |
| 2868 | // empty space between the last field and this one, then we need to emit an |
| 2869 | // anonymous member filling up the space up to its start. There are three cases |
| 2870 | // here: |
| 2871 | // |
| 2872 | // 1 If the previous member ended on a character boundary, then we can emit an |
| 2873 | // anonymous member starting at the most recent character boundary. |
| 2874 | // |
| 2875 | // 2 If the previous member did not end on a character boundary and the distance |
| 2876 | // from the end of the previous member to the current member is less than a |
| 2877 | // word width, then we can emit an anonymous member starting right after the |
| 2878 | // previous member and right before this member. |
| 2879 | // |
| 2880 | // 3 If the previous member did not end on a character boundary and the distance |
| 2881 | // from the end of the previous member to the current member is greater than |
| 2882 | // or equal a word width, then we act as in Case 1. |
| 2883 | |
| 2884 | const uint64_t character_width = 8; |
| 2885 | const uint64_t word_width = 32; |
| 2886 | |
| 2887 | // Objective-C has invalid DW_AT_bit_offset values in older versions |
| 2888 | // of clang, so we have to be careful and only insert unnamed bitfields |
| 2889 | // if we have a new enough clang. |
| 2890 | bool detect_unnamed_bitfields = true; |
| 2891 | |
| 2892 | if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus) |
| 2893 | detect_unnamed_bitfields = die.GetCU()->Supports_unnamed_objc_bitfields (); |
| 2894 | |
| 2895 | if (detect_unnamed_bitfields) |
| 2896 | { |
| 2897 | BitfieldInfo anon_field_info; |
| 2898 | |
| 2899 | if ((this_field_info.bit_offset % character_width) != 0) // not char aligned |
| 2900 | { |
| 2901 | uint64_t last_field_end = 0; |
| 2902 | |
| 2903 | if (last_field_info.IsValid()) |
| 2904 | last_field_end = last_field_info.bit_offset + last_field_info.bit_size; |
| 2905 | |
| 2906 | if (this_field_info.bit_offset != last_field_end) |
| 2907 | { |
| 2908 | if (((last_field_end % character_width) == 0) || // case 1 |
| 2909 | (this_field_info.bit_offset - last_field_end >= word_width)) // case 3 |
| 2910 | { |
| 2911 | anon_field_info.bit_size = this_field_info.bit_offset % character_width; |
| 2912 | anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size; |
| 2913 | } |
| 2914 | else // case 2 |
| 2915 | { |
| 2916 | anon_field_info.bit_size = this_field_info.bit_offset - last_field_end; |
| 2917 | anon_field_info.bit_offset = last_field_end; |
| 2918 | } |
| 2919 | } |
| 2920 | } |
| 2921 | |
| 2922 | if (anon_field_info.IsValid()) |
| 2923 | { |
| 2924 | clang::FieldDecl *unnamed_bitfield_decl = |
| 2925 | ClangASTContext::AddFieldToRecordType (class_clang_type, |
| 2926 | NULL, |
| 2927 | m_ast.GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width), |
| 2928 | accessibility, |
| 2929 | anon_field_info.bit_size); |
| 2930 | |
| 2931 | layout_info.field_offsets.insert( |
| 2932 | std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset)); |
| 2933 | } |
| 2934 | } |
| 2935 | last_field_info = this_field_info; |
| 2936 | } |
| 2937 | else |
| 2938 | { |
| 2939 | last_field_info.Clear(); |
| 2940 | } |
| 2941 | |
| 2942 | CompilerType member_clang_type = member_type->GetLayoutCompilerType (); |
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2943 | if (!member_clang_type.IsCompleteType()) |
| 2944 | member_clang_type.GetCompleteType(); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2945 | |
| 2946 | { |
| 2947 | // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>). |
| 2948 | // If the current field is at the end of the structure, then there is definitely no room for extra |
| 2949 | // elements and we override the type to array[0]. |
| 2950 | |
| 2951 | CompilerType member_array_element_type; |
| 2952 | uint64_t member_array_size; |
| 2953 | bool member_array_is_incomplete; |
| 2954 | |
| 2955 | if (member_clang_type.IsArrayType(&member_array_element_type, |
| 2956 | &member_array_size, |
| 2957 | &member_array_is_incomplete) && |
| 2958 | !member_array_is_incomplete) |
| 2959 | { |
| 2960 | uint64_t parent_byte_size = parent_die.GetAttributeValueAsUnsigned(DW_AT_byte_size, UINT64_MAX); |
| 2961 | |
| 2962 | if (member_byte_offset >= parent_byte_size) |
| 2963 | { |
| Tamas Berghammer | 808ff18 | 2016-01-13 14:58:48 +0000 | [diff] [blame] | 2964 | if (member_array_size != 1 && (member_array_size != 0 || member_byte_offset > parent_byte_size)) |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2965 | { |
| 2966 | module_sp->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member '%s' refers to type 0x%8.8" PRIx64 " which extends beyond the bounds of 0x%8.8" PRIx64, |
| 2967 | die.GetID(), |
| 2968 | name, |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 2969 | encoding_form.Reference(), |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 2970 | parent_die.GetID()); |
| 2971 | } |
| 2972 | |
| 2973 | member_clang_type = m_ast.CreateArrayType(member_array_element_type, 0, false); |
| 2974 | } |
| 2975 | } |
| 2976 | } |
| 2977 | |
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2978 | if (ClangASTContext::IsCXXClassType(member_clang_type) && member_clang_type.GetCompleteType() == false) |
| 2979 | { |
| 2980 | if (die.GetCU()->GetProducer() == DWARFCompileUnit::eProducerClang) |
| 2981 | module_sp->ReportError ("DWARF DIE at 0x%8.8x (class %s) has a member variable 0x%8.8x (%s) whose type is a forward declaration, not a complete definition.\nTry compiling the source file with -fno-limit-debug-info", |
| 2982 | parent_die.GetOffset(), |
| 2983 | parent_die.GetName(), |
| 2984 | die.GetOffset(), |
| 2985 | name); |
| 2986 | else |
| 2987 | module_sp->ReportError ("DWARF DIE at 0x%8.8x (class %s) has a member variable 0x%8.8x (%s) whose type is a forward declaration, not a complete definition.\nPlease file a bug against the compiler and include the preprocessed output for %s", |
| 2988 | parent_die.GetOffset(), |
| 2989 | parent_die.GetName(), |
| 2990 | die.GetOffset(), |
| 2991 | name, |
| 2992 | sc.comp_unit ? sc.comp_unit->GetPath().c_str() : "the source file"); |
| 2993 | // We have no choice other than to pretend that the member class |
| 2994 | // is complete. If we don't do this, clang will crash when trying |
| 2995 | // to layout the class. Since we provide layout assistance, all |
| 2996 | // ivars in this class and other classes will be fine, this is |
| 2997 | // the best we can do short of crashing. |
| 2998 | ClangASTContext::StartTagDeclarationDefinition(member_clang_type); |
| 2999 | ClangASTContext::CompleteTagDeclarationDefinition(member_clang_type); |
| 3000 | } |
| 3001 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3002 | field_decl = ClangASTContext::AddFieldToRecordType (class_clang_type, |
| 3003 | name, |
| 3004 | member_clang_type, |
| 3005 | accessibility, |
| 3006 | bit_size); |
| 3007 | |
| 3008 | m_ast.SetMetadataAsUserID (field_decl, die.GetID()); |
| 3009 | |
| 3010 | layout_info.field_offsets.insert(std::make_pair(field_decl, field_bit_offset)); |
| 3011 | } |
| 3012 | else |
| 3013 | { |
| 3014 | if (name) |
| 3015 | module_sp->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member '%s' refers to type 0x%8.8" PRIx64 " which was unable to be parsed", |
| 3016 | die.GetID(), |
| 3017 | name, |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 3018 | encoding_form.Reference()); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3019 | else |
| 3020 | module_sp->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member refers to type 0x%8.8" PRIx64 " which was unable to be parsed", |
| 3021 | die.GetID(), |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 3022 | encoding_form.Reference()); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3023 | } |
| 3024 | } |
| 3025 | |
| 3026 | if (prop_name != NULL && member_type) |
| 3027 | { |
| 3028 | clang::ObjCIvarDecl *ivar_decl = NULL; |
| 3029 | |
| 3030 | if (field_decl) |
| 3031 | { |
| 3032 | ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl); |
| 3033 | assert (ivar_decl != NULL); |
| 3034 | } |
| 3035 | |
| 3036 | ClangASTMetadata metadata; |
| 3037 | metadata.SetUserID (die.GetID()); |
| 3038 | delayed_properties.push_back(DelayedAddObjCClassProperty(class_clang_type, |
| 3039 | prop_name, |
| 3040 | member_type->GetLayoutCompilerType (), |
| 3041 | ivar_decl, |
| 3042 | prop_setter_name, |
| 3043 | prop_getter_name, |
| 3044 | prop_attributes, |
| 3045 | &metadata)); |
| 3046 | |
| 3047 | if (ivar_decl) |
| 3048 | m_ast.SetMetadataAsUserID (ivar_decl, die.GetID()); |
| 3049 | } |
| 3050 | } |
| 3051 | } |
| 3052 | ++member_idx; |
| 3053 | } |
| 3054 | break; |
| 3055 | |
| 3056 | case DW_TAG_subprogram: |
| 3057 | // Let the type parsing code handle this one for us. |
| 3058 | member_function_dies.Append (die); |
| 3059 | break; |
| 3060 | |
| 3061 | case DW_TAG_inheritance: |
| 3062 | { |
| 3063 | is_a_class = true; |
| 3064 | if (default_accessibility == eAccessNone) |
| 3065 | default_accessibility = eAccessPrivate; |
| 3066 | // TODO: implement DW_TAG_inheritance type parsing |
| 3067 | DWARFAttributes attributes; |
| 3068 | const size_t num_attributes = die.GetAttributes (attributes); |
| 3069 | if (num_attributes > 0) |
| 3070 | { |
| 3071 | Declaration decl; |
| 3072 | DWARFExpression location(die.GetCU()); |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 3073 | DWARFFormValue encoding_form; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3074 | AccessType accessibility = default_accessibility; |
| 3075 | bool is_virtual = false; |
| 3076 | bool is_base_of_class = true; |
| 3077 | off_t member_byte_offset = 0; |
| 3078 | uint32_t i; |
| 3079 | for (i=0; i<num_attributes; ++i) |
| 3080 | { |
| 3081 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 3082 | DWARFFormValue form_value; |
| 3083 | if (attributes.ExtractFormValueAtIndex(i, form_value)) |
| 3084 | { |
| 3085 | switch (attr) |
| 3086 | { |
| 3087 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 3088 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 3089 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 3090 | case DW_AT_type: encoding_form = form_value; break; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3091 | case DW_AT_data_member_location: |
| 3092 | if (form_value.BlockData()) |
| 3093 | { |
| 3094 | Value initialValue(0); |
| 3095 | Value memberOffset(0); |
| 3096 | const DWARFDataExtractor& debug_info_data = die.GetDWARF()->get_debug_info_data(); |
| 3097 | uint32_t block_length = form_value.Unsigned(); |
| 3098 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 3099 | if (DWARFExpression::Evaluate (NULL, |
| 3100 | NULL, |
| 3101 | NULL, |
| 3102 | NULL, |
| 3103 | module_sp, |
| 3104 | debug_info_data, |
| 3105 | die.GetCU(), |
| 3106 | block_offset, |
| 3107 | block_length, |
| 3108 | eRegisterKindDWARF, |
| 3109 | &initialValue, |
| 3110 | memberOffset, |
| 3111 | NULL)) |
| 3112 | { |
| 3113 | member_byte_offset = memberOffset.ResolveValue(NULL).UInt(); |
| 3114 | } |
| 3115 | } |
| 3116 | else |
| 3117 | { |
| 3118 | // With DWARF 3 and later, if the value is an integer constant, |
| 3119 | // this form value is the offset in bytes from the beginning |
| 3120 | // of the containing entity. |
| 3121 | member_byte_offset = form_value.Unsigned(); |
| 3122 | } |
| 3123 | break; |
| 3124 | |
| 3125 | case DW_AT_accessibility: |
| 3126 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); |
| 3127 | break; |
| 3128 | |
| 3129 | case DW_AT_virtuality: |
| 3130 | is_virtual = form_value.Boolean(); |
| 3131 | break; |
| 3132 | |
| 3133 | case DW_AT_sibling: |
| 3134 | break; |
| 3135 | |
| 3136 | default: |
| 3137 | break; |
| 3138 | } |
| 3139 | } |
| 3140 | } |
| 3141 | |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 3142 | Type *base_class_type = die.ResolveTypeUID(DIERef(encoding_form).GetUID()); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3143 | if (base_class_type == NULL) |
| 3144 | { |
| 3145 | module_sp->ReportError("0x%8.8x: DW_TAG_inheritance failed to resolve the base class at 0x%8.8" PRIx64 " from enclosing type 0x%8.8x. \nPlease file a bug and attach the file at the start of this error message", |
| 3146 | die.GetOffset(), |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 3147 | encoding_form.Reference(), |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3148 | parent_die.GetOffset()); |
| 3149 | break; |
| 3150 | } |
| 3151 | |
| 3152 | CompilerType base_class_clang_type = base_class_type->GetFullCompilerType (); |
| 3153 | assert (base_class_clang_type); |
| 3154 | if (class_language == eLanguageTypeObjC) |
| 3155 | { |
| 3156 | ast->SetObjCSuperClass(class_clang_type, base_class_clang_type); |
| 3157 | } |
| 3158 | else |
| 3159 | { |
| 3160 | base_classes.push_back (ast->CreateBaseClassSpecifier (base_class_clang_type.GetOpaqueQualType(), |
| 3161 | accessibility, |
| 3162 | is_virtual, |
| 3163 | is_base_of_class)); |
| 3164 | |
| 3165 | if (is_virtual) |
| 3166 | { |
| 3167 | // Do not specify any offset for virtual inheritance. The DWARF produced by clang doesn't |
| 3168 | // give us a constant offset, but gives us a DWARF expressions that requires an actual object |
| 3169 | // in memory. the DW_AT_data_member_location for a virtual base class looks like: |
| 3170 | // DW_AT_data_member_location( DW_OP_dup, DW_OP_deref, DW_OP_constu(0x00000018), DW_OP_minus, DW_OP_deref, DW_OP_plus ) |
| 3171 | // Given this, there is really no valid response we can give to clang for virtual base |
| 3172 | // class offsets, and this should eventually be removed from LayoutRecordType() in the external |
| 3173 | // AST source in clang. |
| 3174 | } |
| 3175 | else |
| 3176 | { |
| 3177 | layout_info.base_offsets.insert( |
| 3178 | std::make_pair(ast->GetAsCXXRecordDecl(base_class_clang_type.GetOpaqueQualType()), |
| 3179 | clang::CharUnits::fromQuantity(member_byte_offset))); |
| 3180 | } |
| 3181 | } |
| 3182 | } |
| 3183 | } |
| 3184 | break; |
| 3185 | |
| 3186 | default: |
| 3187 | break; |
| 3188 | } |
| 3189 | } |
| 3190 | |
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 3191 | return true; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3192 | } |
| 3193 | |
| 3194 | |
| 3195 | size_t |
| 3196 | DWARFASTParserClang::ParseChildParameters (const SymbolContext& sc, |
| 3197 | clang::DeclContext *containing_decl_ctx, |
| 3198 | const DWARFDIE &parent_die, |
| 3199 | bool skip_artificial, |
| 3200 | bool &is_static, |
| 3201 | bool &is_variadic, |
| Greg Clayton | fb85e62 | 2016-02-09 22:36:24 +0000 | [diff] [blame^] | 3202 | bool &has_template_params, |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3203 | std::vector<CompilerType>& function_param_types, |
| 3204 | std::vector<clang::ParmVarDecl*>& function_param_decls, |
| 3205 | unsigned &type_quals) |
| 3206 | { |
| 3207 | if (!parent_die) |
| 3208 | return 0; |
| 3209 | |
| 3210 | size_t arg_idx = 0; |
| 3211 | for (DWARFDIE die = parent_die.GetFirstChild(); die.IsValid(); die = die.GetSibling()) |
| 3212 | { |
| 3213 | const dw_tag_t tag = die.Tag(); |
| 3214 | switch (tag) |
| 3215 | { |
| 3216 | case DW_TAG_formal_parameter: |
| 3217 | { |
| 3218 | DWARFAttributes attributes; |
| 3219 | const size_t num_attributes = die.GetAttributes(attributes); |
| 3220 | if (num_attributes > 0) |
| 3221 | { |
| 3222 | const char *name = NULL; |
| 3223 | Declaration decl; |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 3224 | DWARFFormValue param_type_die_form; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3225 | bool is_artificial = false; |
| 3226 | // one of None, Auto, Register, Extern, Static, PrivateExtern |
| 3227 | |
| 3228 | clang::StorageClass storage = clang::SC_None; |
| 3229 | uint32_t i; |
| 3230 | for (i=0; i<num_attributes; ++i) |
| 3231 | { |
| 3232 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 3233 | DWARFFormValue form_value; |
| 3234 | if (attributes.ExtractFormValueAtIndex(i, form_value)) |
| 3235 | { |
| 3236 | switch (attr) |
| 3237 | { |
| 3238 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 3239 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 3240 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 3241 | case DW_AT_name: name = form_value.AsCString(); |
| 3242 | break; |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 3243 | case DW_AT_type: param_type_die_form = form_value; break; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3244 | case DW_AT_artificial: is_artificial = form_value.Boolean(); break; |
| 3245 | case DW_AT_location: |
| 3246 | // if (form_value.BlockData()) |
| 3247 | // { |
| 3248 | // const DWARFDataExtractor& debug_info_data = debug_info(); |
| 3249 | // uint32_t block_length = form_value.Unsigned(); |
| 3250 | // DWARFDataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length); |
| 3251 | // } |
| 3252 | // else |
| 3253 | // { |
| 3254 | // } |
| 3255 | // break; |
| 3256 | case DW_AT_const_value: |
| 3257 | case DW_AT_default_value: |
| 3258 | case DW_AT_description: |
| 3259 | case DW_AT_endianity: |
| 3260 | case DW_AT_is_optional: |
| 3261 | case DW_AT_segment: |
| 3262 | case DW_AT_variable_parameter: |
| 3263 | default: |
| 3264 | case DW_AT_abstract_origin: |
| 3265 | case DW_AT_sibling: |
| 3266 | break; |
| 3267 | } |
| 3268 | } |
| 3269 | } |
| 3270 | |
| 3271 | bool skip = false; |
| 3272 | if (skip_artificial) |
| 3273 | { |
| 3274 | if (is_artificial) |
| 3275 | { |
| 3276 | // In order to determine if a C++ member function is |
| 3277 | // "const" we have to look at the const-ness of "this"... |
| 3278 | // Ugly, but that |
| 3279 | if (arg_idx == 0) |
| 3280 | { |
| 3281 | if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind())) |
| 3282 | { |
| 3283 | // Often times compilers omit the "this" name for the |
| 3284 | // specification DIEs, so we can't rely upon the name |
| 3285 | // being in the formal parameter DIE... |
| 3286 | if (name == NULL || ::strcmp(name, "this")==0) |
| 3287 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 3288 | Type *this_type = die.ResolveTypeUID (DIERef(param_type_die_form).GetUID()); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3289 | if (this_type) |
| 3290 | { |
| 3291 | uint32_t encoding_mask = this_type->GetEncodingMask(); |
| 3292 | if (encoding_mask & Type::eEncodingIsPointerUID) |
| 3293 | { |
| 3294 | is_static = false; |
| 3295 | |
| 3296 | if (encoding_mask & (1u << Type::eEncodingIsConstUID)) |
| 3297 | type_quals |= clang::Qualifiers::Const; |
| 3298 | if (encoding_mask & (1u << Type::eEncodingIsVolatileUID)) |
| 3299 | type_quals |= clang::Qualifiers::Volatile; |
| 3300 | } |
| 3301 | } |
| 3302 | } |
| 3303 | } |
| 3304 | } |
| 3305 | skip = true; |
| 3306 | } |
| 3307 | else |
| 3308 | { |
| 3309 | |
| 3310 | // HACK: Objective C formal parameters "self" and "_cmd" |
| 3311 | // are not marked as artificial in the DWARF... |
| 3312 | CompileUnit *comp_unit = die.GetLLDBCompileUnit(); |
| 3313 | if (comp_unit) |
| 3314 | { |
| 3315 | switch (comp_unit->GetLanguage()) |
| 3316 | { |
| 3317 | case eLanguageTypeObjC: |
| 3318 | case eLanguageTypeObjC_plus_plus: |
| 3319 | if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0)) |
| 3320 | skip = true; |
| 3321 | break; |
| 3322 | default: |
| 3323 | break; |
| 3324 | } |
| 3325 | } |
| 3326 | } |
| 3327 | } |
| 3328 | |
| 3329 | if (!skip) |
| 3330 | { |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 3331 | Type *type = die.ResolveTypeUID(DIERef(param_type_die_form).GetUID()); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3332 | if (type) |
| 3333 | { |
| 3334 | function_param_types.push_back (type->GetForwardCompilerType ()); |
| 3335 | |
| 3336 | clang::ParmVarDecl *param_var_decl = m_ast.CreateParameterDeclaration (name, |
| 3337 | type->GetForwardCompilerType (), |
| 3338 | storage); |
| 3339 | assert(param_var_decl); |
| 3340 | function_param_decls.push_back(param_var_decl); |
| 3341 | |
| 3342 | m_ast.SetMetadataAsUserID (param_var_decl, die.GetID()); |
| 3343 | } |
| 3344 | } |
| 3345 | } |
| 3346 | arg_idx++; |
| 3347 | } |
| 3348 | break; |
| 3349 | |
| 3350 | case DW_TAG_unspecified_parameters: |
| 3351 | is_variadic = true; |
| 3352 | break; |
| 3353 | |
| 3354 | case DW_TAG_template_type_parameter: |
| 3355 | case DW_TAG_template_value_parameter: |
| 3356 | // The one caller of this was never using the template_param_infos, |
| 3357 | // and the local variable was taking up a large amount of stack space |
| 3358 | // in SymbolFileDWARF::ParseType() so this was removed. If we ever need |
| 3359 | // the template params back, we can add them back. |
| 3360 | // ParseTemplateDIE (dwarf_cu, die, template_param_infos); |
| Greg Clayton | fb85e62 | 2016-02-09 22:36:24 +0000 | [diff] [blame^] | 3361 | has_template_params = true; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3362 | break; |
| 3363 | |
| 3364 | default: |
| 3365 | break; |
| 3366 | } |
| 3367 | } |
| 3368 | return arg_idx; |
| 3369 | } |
| 3370 | |
| 3371 | void |
| 3372 | DWARFASTParserClang::ParseChildArrayInfo (const SymbolContext& sc, |
| 3373 | const DWARFDIE &parent_die, |
| 3374 | int64_t& first_index, |
| 3375 | std::vector<uint64_t>& element_orders, |
| 3376 | uint32_t& byte_stride, |
| 3377 | uint32_t& bit_stride) |
| 3378 | { |
| 3379 | if (!parent_die) |
| 3380 | return; |
| 3381 | |
| 3382 | for (DWARFDIE die = parent_die.GetFirstChild(); die.IsValid(); die = die.GetSibling()) |
| 3383 | { |
| 3384 | const dw_tag_t tag = die.Tag(); |
| 3385 | switch (tag) |
| 3386 | { |
| 3387 | case DW_TAG_subrange_type: |
| 3388 | { |
| 3389 | DWARFAttributes attributes; |
| 3390 | const size_t num_child_attributes = die.GetAttributes(attributes); |
| 3391 | if (num_child_attributes > 0) |
| 3392 | { |
| 3393 | uint64_t num_elements = 0; |
| 3394 | uint64_t lower_bound = 0; |
| 3395 | uint64_t upper_bound = 0; |
| 3396 | bool upper_bound_valid = false; |
| 3397 | uint32_t i; |
| 3398 | for (i=0; i<num_child_attributes; ++i) |
| 3399 | { |
| 3400 | const dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 3401 | DWARFFormValue form_value; |
| 3402 | if (attributes.ExtractFormValueAtIndex(i, form_value)) |
| 3403 | { |
| 3404 | switch (attr) |
| 3405 | { |
| 3406 | case DW_AT_name: |
| 3407 | break; |
| 3408 | |
| 3409 | case DW_AT_count: |
| 3410 | num_elements = form_value.Unsigned(); |
| 3411 | break; |
| 3412 | |
| 3413 | case DW_AT_bit_stride: |
| 3414 | bit_stride = form_value.Unsigned(); |
| 3415 | break; |
| 3416 | |
| 3417 | case DW_AT_byte_stride: |
| 3418 | byte_stride = form_value.Unsigned(); |
| 3419 | break; |
| 3420 | |
| 3421 | case DW_AT_lower_bound: |
| 3422 | lower_bound = form_value.Unsigned(); |
| 3423 | break; |
| 3424 | |
| 3425 | case DW_AT_upper_bound: |
| 3426 | upper_bound_valid = true; |
| 3427 | upper_bound = form_value.Unsigned(); |
| 3428 | break; |
| 3429 | |
| 3430 | default: |
| 3431 | case DW_AT_abstract_origin: |
| 3432 | case DW_AT_accessibility: |
| 3433 | case DW_AT_allocated: |
| 3434 | case DW_AT_associated: |
| 3435 | case DW_AT_data_location: |
| 3436 | case DW_AT_declaration: |
| 3437 | case DW_AT_description: |
| 3438 | case DW_AT_sibling: |
| 3439 | case DW_AT_threads_scaled: |
| 3440 | case DW_AT_type: |
| 3441 | case DW_AT_visibility: |
| 3442 | break; |
| 3443 | } |
| 3444 | } |
| 3445 | } |
| 3446 | |
| 3447 | if (num_elements == 0) |
| 3448 | { |
| 3449 | if (upper_bound_valid && upper_bound >= lower_bound) |
| 3450 | num_elements = upper_bound - lower_bound + 1; |
| 3451 | } |
| 3452 | |
| 3453 | element_orders.push_back (num_elements); |
| 3454 | } |
| 3455 | } |
| 3456 | break; |
| 3457 | } |
| 3458 | } |
| 3459 | } |
| 3460 | |
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 3461 | Type * |
| 3462 | DWARFASTParserClang::GetTypeForDIE (const DWARFDIE &die) |
| 3463 | { |
| 3464 | if (die) |
| 3465 | { |
| 3466 | SymbolFileDWARF *dwarf = die.GetDWARF(); |
| 3467 | DWARFAttributes attributes; |
| 3468 | const size_t num_attributes = die.GetAttributes(attributes); |
| 3469 | if (num_attributes > 0) |
| 3470 | { |
| 3471 | DWARFFormValue type_die_form; |
| 3472 | for (size_t i = 0; i < num_attributes; ++i) |
| 3473 | { |
| 3474 | dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 3475 | DWARFFormValue form_value; |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 3476 | |
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 3477 | if (attr == DW_AT_type && attributes.ExtractFormValueAtIndex(i, form_value)) |
| 3478 | return dwarf->ResolveTypeUID(DIERef(form_value).GetUID()); |
| 3479 | } |
| 3480 | } |
| 3481 | } |
| 3482 | |
| 3483 | return nullptr; |
| 3484 | } |
| 3485 | |
| 3486 | clang::Decl * |
| 3487 | DWARFASTParserClang::GetClangDeclForDIE (const DWARFDIE &die) |
| 3488 | { |
| 3489 | if (!die) |
| 3490 | return nullptr; |
| 3491 | |
| Paul Herman | f6681b4 | 2015-09-17 19:32:02 +0000 | [diff] [blame] | 3492 | switch (die.Tag()) |
| 3493 | { |
| 3494 | case DW_TAG_variable: |
| 3495 | case DW_TAG_constant: |
| 3496 | case DW_TAG_formal_parameter: |
| 3497 | case DW_TAG_imported_declaration: |
| 3498 | case DW_TAG_imported_module: |
| 3499 | break; |
| 3500 | default: |
| 3501 | return nullptr; |
| 3502 | } |
| Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 3503 | |
| Paul Herman | f6681b4 | 2015-09-17 19:32:02 +0000 | [diff] [blame] | 3504 | DIEToDeclMap::iterator cache_pos = m_die_to_decl.find(die.GetDIE()); |
| 3505 | if (cache_pos != m_die_to_decl.end()) |
| 3506 | return cache_pos->second; |
| 3507 | |
| 3508 | if (DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification)) |
| 3509 | { |
| 3510 | clang::Decl *decl = GetClangDeclForDIE(spec_die); |
| 3511 | m_die_to_decl[die.GetDIE()] = decl; |
| 3512 | m_decl_to_die[decl].insert(die.GetDIE()); |
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 3513 | return decl; |
| Paul Herman | f6681b4 | 2015-09-17 19:32:02 +0000 | [diff] [blame] | 3514 | } |
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 3515 | |
| Paul Herman | f6681b4 | 2015-09-17 19:32:02 +0000 | [diff] [blame] | 3516 | clang::Decl *decl = nullptr; |
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 3517 | switch (die.Tag()) |
| 3518 | { |
| 3519 | case DW_TAG_variable: |
| 3520 | case DW_TAG_constant: |
| 3521 | case DW_TAG_formal_parameter: |
| 3522 | { |
| 3523 | SymbolFileDWARF *dwarf = die.GetDWARF(); |
| 3524 | Type *type = GetTypeForDIE(die); |
| 3525 | const char *name = die.GetName(); |
| 3526 | clang::DeclContext *decl_context = ClangASTContext::DeclContextGetAsDeclContext(dwarf->GetDeclContextContainingUID(die.GetID())); |
| 3527 | decl = m_ast.CreateVariableDeclaration( |
| 3528 | decl_context, |
| 3529 | name, |
| 3530 | ClangASTContext::GetQualType(type->GetForwardCompilerType())); |
| 3531 | break; |
| 3532 | } |
| 3533 | case DW_TAG_imported_declaration: |
| 3534 | { |
| 3535 | SymbolFileDWARF *dwarf = die.GetDWARF(); |
| 3536 | lldb::user_id_t imported_uid = die.GetAttributeValueAsReference(DW_AT_import, DW_INVALID_OFFSET); |
| 3537 | |
| 3538 | if (dwarf->UserIDMatches(imported_uid)) |
| 3539 | { |
| 3540 | CompilerDecl imported_decl = dwarf->GetDeclForUID(imported_uid); |
| 3541 | if (imported_decl) |
| 3542 | { |
| 3543 | clang::DeclContext *decl_context = ClangASTContext::DeclContextGetAsDeclContext(dwarf->GetDeclContextContainingUID(die.GetID())); |
| 3544 | if (clang::NamedDecl *clang_imported_decl = llvm::dyn_cast<clang::NamedDecl>((clang::Decl *)imported_decl.GetOpaqueDecl())) |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 3545 | decl = m_ast.CreateUsingDeclaration(decl_context, clang_imported_decl); |
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 3546 | } |
| 3547 | } |
| 3548 | break; |
| 3549 | } |
| 3550 | case DW_TAG_imported_module: |
| 3551 | { |
| 3552 | SymbolFileDWARF *dwarf = die.GetDWARF(); |
| 3553 | lldb::user_id_t imported_uid = die.GetAttributeValueAsReference(DW_AT_import, DW_INVALID_OFFSET); |
| 3554 | |
| 3555 | if (dwarf->UserIDMatches(imported_uid)) |
| 3556 | { |
| 3557 | CompilerDeclContext imported_decl = dwarf->GetDeclContextForUID(imported_uid); |
| 3558 | if (imported_decl) |
| 3559 | { |
| 3560 | clang::DeclContext *decl_context = ClangASTContext::DeclContextGetAsDeclContext(dwarf->GetDeclContextContainingUID(die.GetID())); |
| Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 3561 | if (clang::NamespaceDecl *ns_decl = ClangASTContext::DeclContextGetAsNamespaceDecl(imported_decl)) |
| 3562 | decl = m_ast.CreateUsingDirectiveDeclaration(decl_context, ns_decl); |
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 3563 | } |
| 3564 | } |
| 3565 | break; |
| 3566 | } |
| 3567 | default: |
| 3568 | break; |
| 3569 | } |
| 3570 | |
| 3571 | m_die_to_decl[die.GetDIE()] = decl; |
| 3572 | m_decl_to_die[decl].insert(die.GetDIE()); |
| 3573 | |
| 3574 | return decl; |
| 3575 | } |
| 3576 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3577 | clang::DeclContext * |
| 3578 | DWARFASTParserClang::GetClangDeclContextForDIE (const DWARFDIE &die) |
| 3579 | { |
| 3580 | if (die) |
| 3581 | { |
| 3582 | clang::DeclContext *decl_ctx = GetCachedClangDeclContextForDIE (die); |
| 3583 | if (decl_ctx) |
| 3584 | return decl_ctx; |
| 3585 | |
| 3586 | bool try_parsing_type = true; |
| 3587 | switch (die.Tag()) |
| 3588 | { |
| 3589 | case DW_TAG_compile_unit: |
| 3590 | decl_ctx = m_ast.GetTranslationUnitDecl(); |
| 3591 | try_parsing_type = false; |
| 3592 | break; |
| 3593 | |
| 3594 | case DW_TAG_namespace: |
| 3595 | decl_ctx = ResolveNamespaceDIE (die); |
| 3596 | try_parsing_type = false; |
| 3597 | break; |
| 3598 | |
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 3599 | case DW_TAG_lexical_block: |
| 3600 | decl_ctx = (clang::DeclContext *)ResolveBlockDIE(die); |
| 3601 | try_parsing_type = false; |
| 3602 | break; |
| 3603 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3604 | default: |
| 3605 | break; |
| 3606 | } |
| 3607 | |
| 3608 | if (decl_ctx == nullptr && try_parsing_type) |
| 3609 | { |
| 3610 | Type* type = die.GetDWARF()->ResolveType (die); |
| 3611 | if (type) |
| 3612 | decl_ctx = GetCachedClangDeclContextForDIE (die); |
| 3613 | } |
| 3614 | |
| 3615 | if (decl_ctx) |
| 3616 | { |
| 3617 | LinkDeclContextToDIE (decl_ctx, die); |
| 3618 | return decl_ctx; |
| 3619 | } |
| 3620 | } |
| 3621 | return nullptr; |
| 3622 | } |
| 3623 | |
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 3624 | clang::BlockDecl * |
| 3625 | DWARFASTParserClang::ResolveBlockDIE (const DWARFDIE &die) |
| 3626 | { |
| 3627 | if (die && die.Tag() == DW_TAG_lexical_block) |
| 3628 | { |
| 3629 | clang::BlockDecl *decl = llvm::cast_or_null<clang::BlockDecl>(m_die_to_decl_ctx[die.GetDIE()]); |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 3630 | |
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 3631 | if (!decl) |
| 3632 | { |
| 3633 | DWARFDIE decl_context_die; |
| 3634 | clang::DeclContext *decl_context = GetClangDeclContextContainingDIE(die, &decl_context_die); |
| 3635 | decl = m_ast.CreateBlockDeclaration(decl_context); |
| 3636 | |
| 3637 | if (decl) |
| 3638 | LinkDeclContextToDIE((clang::DeclContext *)decl, die); |
| 3639 | } |
| 3640 | |
| 3641 | return decl; |
| 3642 | } |
| 3643 | return nullptr; |
| 3644 | } |
| 3645 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3646 | clang::NamespaceDecl * |
| 3647 | DWARFASTParserClang::ResolveNamespaceDIE (const DWARFDIE &die) |
| 3648 | { |
| 3649 | if (die && die.Tag() == DW_TAG_namespace) |
| 3650 | { |
| 3651 | // See if we already parsed this namespace DIE and associated it with a |
| 3652 | // uniqued namespace declaration |
| 3653 | clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die.GetDIE()]); |
| 3654 | if (namespace_decl) |
| 3655 | return namespace_decl; |
| 3656 | else |
| 3657 | { |
| 3658 | const char *namespace_name = die.GetName(); |
| 3659 | clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (die, nullptr); |
| 3660 | namespace_decl = m_ast.GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx); |
| 3661 | Log *log = nullptr;// (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| 3662 | if (log) |
| 3663 | { |
| 3664 | SymbolFileDWARF *dwarf = die.GetDWARF(); |
| 3665 | if (namespace_name) |
| 3666 | { |
| 3667 | dwarf->GetObjectFile()->GetModule()->LogMessage (log, |
| 3668 | "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)", |
| 3669 | static_cast<void*>(m_ast.getASTContext()), |
| 3670 | die.GetID(), |
| 3671 | namespace_name, |
| 3672 | static_cast<void*>(namespace_decl), |
| 3673 | static_cast<void*>(namespace_decl->getOriginalNamespace())); |
| 3674 | } |
| 3675 | else |
| 3676 | { |
| 3677 | dwarf->GetObjectFile()->GetModule()->LogMessage (log, |
| 3678 | "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)", |
| 3679 | static_cast<void*>(m_ast.getASTContext()), |
| 3680 | die.GetID(), |
| 3681 | static_cast<void*>(namespace_decl), |
| 3682 | static_cast<void*>(namespace_decl->getOriginalNamespace())); |
| 3683 | } |
| 3684 | } |
| 3685 | |
| 3686 | if (namespace_decl) |
| 3687 | LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die); |
| 3688 | return namespace_decl; |
| 3689 | } |
| 3690 | } |
| 3691 | return nullptr; |
| 3692 | } |
| 3693 | |
| 3694 | clang::DeclContext * |
| 3695 | DWARFASTParserClang::GetClangDeclContextContainingDIE (const DWARFDIE &die, |
| 3696 | DWARFDIE *decl_ctx_die_copy) |
| 3697 | { |
| 3698 | SymbolFileDWARF *dwarf = die.GetDWARF(); |
| 3699 | |
| 3700 | DWARFDIE decl_ctx_die = dwarf->GetDeclContextDIEContainingDIE (die); |
| 3701 | |
| 3702 | if (decl_ctx_die_copy) |
| 3703 | *decl_ctx_die_copy = decl_ctx_die; |
| 3704 | |
| 3705 | if (decl_ctx_die) |
| 3706 | { |
| 3707 | clang::DeclContext *clang_decl_ctx = GetClangDeclContextForDIE (decl_ctx_die); |
| 3708 | if (clang_decl_ctx) |
| 3709 | return clang_decl_ctx; |
| 3710 | } |
| 3711 | return m_ast.GetTranslationUnitDecl(); |
| 3712 | } |
| 3713 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3714 | clang::DeclContext * |
| 3715 | DWARFASTParserClang::GetCachedClangDeclContextForDIE (const DWARFDIE &die) |
| 3716 | { |
| 3717 | if (die) |
| 3718 | { |
| 3719 | DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die.GetDIE()); |
| 3720 | if (pos != m_die_to_decl_ctx.end()) |
| 3721 | return pos->second; |
| 3722 | } |
| 3723 | return nullptr; |
| 3724 | } |
| 3725 | |
| 3726 | void |
| 3727 | DWARFASTParserClang::LinkDeclContextToDIE (clang::DeclContext *decl_ctx, const DWARFDIE &die) |
| 3728 | { |
| 3729 | m_die_to_decl_ctx[die.GetDIE()] = decl_ctx; |
| 3730 | // There can be many DIEs for a single decl context |
| Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 3731 | //m_decl_ctx_to_die[decl_ctx].insert(die.GetDIE()); |
| 3732 | m_decl_ctx_to_die.insert(std::make_pair(decl_ctx, die)); |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3733 | } |
| 3734 | |
| 3735 | bool |
| 3736 | DWARFASTParserClang::CopyUniqueClassMethodTypes (const DWARFDIE &src_class_die, |
| 3737 | const DWARFDIE &dst_class_die, |
| 3738 | lldb_private::Type *class_type, |
| 3739 | DWARFDIECollection &failures) |
| 3740 | { |
| 3741 | if (!class_type || !src_class_die || !dst_class_die) |
| 3742 | return false; |
| 3743 | if (src_class_die.Tag() != dst_class_die.Tag()) |
| 3744 | return false; |
| 3745 | |
| 3746 | // We need to complete the class type so we can get all of the method types |
| 3747 | // parsed so we can then unique those types to their equivalent counterparts |
| 3748 | // in "dst_cu" and "dst_class_die" |
| 3749 | class_type->GetFullCompilerType (); |
| 3750 | |
| 3751 | DWARFDIE src_die; |
| 3752 | DWARFDIE dst_die; |
| 3753 | UniqueCStringMap<DWARFDIE> src_name_to_die; |
| 3754 | UniqueCStringMap<DWARFDIE> dst_name_to_die; |
| 3755 | UniqueCStringMap<DWARFDIE> src_name_to_die_artificial; |
| 3756 | UniqueCStringMap<DWARFDIE> dst_name_to_die_artificial; |
| 3757 | for (src_die = src_class_die.GetFirstChild(); src_die.IsValid(); src_die = src_die.GetSibling()) |
| 3758 | { |
| 3759 | if (src_die.Tag() == DW_TAG_subprogram) |
| 3760 | { |
| 3761 | // Make sure this is a declaration and not a concrete instance by looking |
| 3762 | // for DW_AT_declaration set to 1. Sometimes concrete function instances |
| 3763 | // are placed inside the class definitions and shouldn't be included in |
| 3764 | // the list of things are are tracking here. |
| 3765 | if (src_die.GetAttributeValueAsUnsigned(DW_AT_declaration, 0) == 1) |
| 3766 | { |
| 3767 | const char *src_name = src_die.GetMangledName (); |
| 3768 | if (src_name) |
| 3769 | { |
| 3770 | ConstString src_const_name(src_name); |
| 3771 | if (src_die.GetAttributeValueAsUnsigned(DW_AT_artificial, 0)) |
| 3772 | src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die); |
| 3773 | else |
| 3774 | src_name_to_die.Append(src_const_name.GetCString(), src_die); |
| 3775 | } |
| 3776 | } |
| 3777 | } |
| 3778 | } |
| 3779 | for (dst_die = dst_class_die.GetFirstChild(); dst_die.IsValid(); dst_die = dst_die.GetSibling()) |
| 3780 | { |
| 3781 | if (dst_die.Tag() == DW_TAG_subprogram) |
| 3782 | { |
| 3783 | // Make sure this is a declaration and not a concrete instance by looking |
| 3784 | // for DW_AT_declaration set to 1. Sometimes concrete function instances |
| 3785 | // are placed inside the class definitions and shouldn't be included in |
| 3786 | // the list of things are are tracking here. |
| 3787 | if (dst_die.GetAttributeValueAsUnsigned(DW_AT_declaration, 0) == 1) |
| 3788 | { |
| 3789 | const char *dst_name = dst_die.GetMangledName (); |
| 3790 | if (dst_name) |
| 3791 | { |
| 3792 | ConstString dst_const_name(dst_name); |
| 3793 | if ( dst_die.GetAttributeValueAsUnsigned(DW_AT_artificial, 0)) |
| 3794 | dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die); |
| 3795 | else |
| 3796 | dst_name_to_die.Append(dst_const_name.GetCString(), dst_die); |
| 3797 | } |
| 3798 | } |
| 3799 | } |
| 3800 | } |
| 3801 | const uint32_t src_size = src_name_to_die.GetSize (); |
| 3802 | const uint32_t dst_size = dst_name_to_die.GetSize (); |
| 3803 | Log *log = nullptr; // (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION)); |
| 3804 | |
| 3805 | // Is everything kosher so we can go through the members at top speed? |
| 3806 | bool fast_path = true; |
| 3807 | |
| 3808 | if (src_size != dst_size) |
| 3809 | { |
| 3810 | if (src_size != 0 && dst_size != 0) |
| 3811 | { |
| 3812 | if (log) |
| 3813 | log->Printf("warning: trying to unique class DIE 0x%8.8x to 0x%8.8x, but they didn't have the same size (src=%d, dst=%d)", |
| 3814 | src_class_die.GetOffset(), |
| 3815 | dst_class_die.GetOffset(), |
| 3816 | src_size, |
| 3817 | dst_size); |
| 3818 | } |
| 3819 | |
| 3820 | fast_path = false; |
| 3821 | } |
| 3822 | |
| 3823 | uint32_t idx; |
| 3824 | |
| 3825 | if (fast_path) |
| 3826 | { |
| 3827 | for (idx = 0; idx < src_size; ++idx) |
| 3828 | { |
| 3829 | src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); |
| 3830 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); |
| 3831 | |
| 3832 | if (src_die.Tag() != dst_die.Tag()) |
| 3833 | { |
| 3834 | if (log) |
| 3835 | log->Printf("warning: tried to unique class DIE 0x%8.8x to 0x%8.8x, but 0x%8.8x (%s) tags didn't match 0x%8.8x (%s)", |
| 3836 | src_class_die.GetOffset(), |
| 3837 | dst_class_die.GetOffset(), |
| 3838 | src_die.GetOffset(), |
| 3839 | src_die.GetTagAsCString(), |
| 3840 | dst_die.GetOffset(), |
| 3841 | dst_die.GetTagAsCString()); |
| 3842 | fast_path = false; |
| 3843 | } |
| 3844 | |
| 3845 | const char *src_name = src_die.GetMangledName (); |
| 3846 | const char *dst_name = dst_die.GetMangledName (); |
| 3847 | |
| 3848 | // Make sure the names match |
| 3849 | if (src_name == dst_name || (strcmp (src_name, dst_name) == 0)) |
| 3850 | continue; |
| 3851 | |
| 3852 | if (log) |
| 3853 | log->Printf("warning: tried to unique class DIE 0x%8.8x to 0x%8.8x, but 0x%8.8x (%s) names didn't match 0x%8.8x (%s)", |
| 3854 | src_class_die.GetOffset(), |
| 3855 | dst_class_die.GetOffset(), |
| 3856 | src_die.GetOffset(), |
| 3857 | src_name, |
| 3858 | dst_die.GetOffset(), |
| 3859 | dst_name); |
| 3860 | |
| 3861 | fast_path = false; |
| 3862 | } |
| 3863 | } |
| 3864 | |
| 3865 | DWARFASTParserClang *src_dwarf_ast_parser = (DWARFASTParserClang *)src_die.GetDWARFParser(); |
| 3866 | DWARFASTParserClang *dst_dwarf_ast_parser = (DWARFASTParserClang *)dst_die.GetDWARFParser(); |
| 3867 | |
| 3868 | // Now do the work of linking the DeclContexts and Types. |
| 3869 | if (fast_path) |
| 3870 | { |
| 3871 | // We can do this quickly. Just run across the tables index-for-index since |
| 3872 | // we know each node has matching names and tags. |
| 3873 | for (idx = 0; idx < src_size; ++idx) |
| 3874 | { |
| 3875 | src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); |
| 3876 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); |
| 3877 | |
| 3878 | clang::DeclContext *src_decl_ctx = src_dwarf_ast_parser->m_die_to_decl_ctx[src_die.GetDIE()]; |
| 3879 | if (src_decl_ctx) |
| 3880 | { |
| 3881 | if (log) |
| 3882 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", |
| 3883 | static_cast<void*>(src_decl_ctx), |
| 3884 | src_die.GetOffset(), dst_die.GetOffset()); |
| 3885 | dst_dwarf_ast_parser->LinkDeclContextToDIE (src_decl_ctx, dst_die); |
| 3886 | } |
| 3887 | else |
| 3888 | { |
| 3889 | if (log) |
| 3890 | log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found", |
| 3891 | src_die.GetOffset(), dst_die.GetOffset()); |
| 3892 | } |
| 3893 | |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 3894 | Type *src_child_type = dst_die.GetDWARF()->GetDIEToType()[src_die.GetDIE()]; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3895 | if (src_child_type) |
| 3896 | { |
| 3897 | if (log) |
| 3898 | log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", |
| 3899 | static_cast<void*>(src_child_type), |
| 3900 | src_child_type->GetID(), |
| 3901 | src_die.GetOffset(), dst_die.GetOffset()); |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 3902 | dst_die.GetDWARF()->GetDIEToType()[dst_die.GetDIE()] = src_child_type; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3903 | } |
| 3904 | else |
| 3905 | { |
| 3906 | if (log) |
| 3907 | log->Printf ("warning: tried to unique lldb_private::Type from 0x%8.8x for 0x%8.8x, but none was found", src_die.GetOffset(), dst_die.GetOffset()); |
| 3908 | } |
| 3909 | } |
| 3910 | } |
| 3911 | else |
| 3912 | { |
| 3913 | // We must do this slowly. For each member of the destination, look |
| 3914 | // up a member in the source with the same name, check its tag, and |
| 3915 | // unique them if everything matches up. Report failures. |
| 3916 | |
| 3917 | if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty()) |
| 3918 | { |
| 3919 | src_name_to_die.Sort(); |
| 3920 | |
| 3921 | for (idx = 0; idx < dst_size; ++idx) |
| 3922 | { |
| 3923 | const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx); |
| 3924 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx); |
| 3925 | src_die = src_name_to_die.Find(dst_name, DWARFDIE()); |
| 3926 | |
| 3927 | if (src_die && (src_die.Tag() == dst_die.Tag())) |
| 3928 | { |
| 3929 | clang::DeclContext *src_decl_ctx = src_dwarf_ast_parser->m_die_to_decl_ctx[src_die.GetDIE()]; |
| 3930 | if (src_decl_ctx) |
| 3931 | { |
| 3932 | if (log) |
| 3933 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", |
| 3934 | static_cast<void*>(src_decl_ctx), |
| 3935 | src_die.GetOffset(), |
| 3936 | dst_die.GetOffset()); |
| 3937 | dst_dwarf_ast_parser->LinkDeclContextToDIE (src_decl_ctx, dst_die); |
| 3938 | } |
| 3939 | else |
| 3940 | { |
| 3941 | if (log) |
| 3942 | log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found", src_die.GetOffset(), dst_die.GetOffset()); |
| 3943 | } |
| 3944 | |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 3945 | Type *src_child_type = dst_die.GetDWARF()->GetDIEToType()[src_die.GetDIE()]; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3946 | if (src_child_type) |
| 3947 | { |
| 3948 | if (log) |
| 3949 | log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", |
| 3950 | static_cast<void*>(src_child_type), |
| 3951 | src_child_type->GetID(), |
| 3952 | src_die.GetOffset(), |
| 3953 | dst_die.GetOffset()); |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 3954 | dst_die.GetDWARF()->GetDIEToType()[dst_die.GetDIE()] = src_child_type; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3955 | } |
| 3956 | else |
| 3957 | { |
| 3958 | if (log) |
| 3959 | log->Printf ("warning: tried to unique lldb_private::Type from 0x%8.8x for 0x%8.8x, but none was found", src_die.GetOffset(), dst_die.GetOffset()); |
| 3960 | } |
| 3961 | } |
| 3962 | else |
| 3963 | { |
| 3964 | if (log) |
| 3965 | log->Printf ("warning: couldn't find a match for 0x%8.8x", dst_die.GetOffset()); |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 3966 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3967 | failures.Append(dst_die); |
| 3968 | } |
| 3969 | } |
| 3970 | } |
| 3971 | } |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 3972 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3973 | const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize (); |
| 3974 | const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize (); |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 3975 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3976 | if (src_size_artificial && dst_size_artificial) |
| 3977 | { |
| 3978 | dst_name_to_die_artificial.Sort(); |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 3979 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3980 | for (idx = 0; idx < src_size_artificial; ++idx) |
| 3981 | { |
| 3982 | const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx); |
| 3983 | src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx); |
| 3984 | dst_die = dst_name_to_die_artificial.Find(src_name_artificial, DWARFDIE()); |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 3985 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 3986 | if (dst_die) |
| 3987 | { |
| 3988 | // Both classes have the artificial types, link them |
| 3989 | clang::DeclContext *src_decl_ctx = src_dwarf_ast_parser->m_die_to_decl_ctx[src_die.GetDIE()]; |
| 3990 | if (src_decl_ctx) |
| 3991 | { |
| 3992 | if (log) |
| 3993 | log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", |
| 3994 | static_cast<void*>(src_decl_ctx), |
| 3995 | src_die.GetOffset(), dst_die.GetOffset()); |
| 3996 | dst_dwarf_ast_parser->LinkDeclContextToDIE (src_decl_ctx, dst_die); |
| 3997 | } |
| 3998 | else |
| 3999 | { |
| 4000 | if (log) |
| 4001 | log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found", src_die.GetOffset(), dst_die.GetOffset()); |
| 4002 | } |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 4003 | |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 4004 | Type *src_child_type = dst_die.GetDWARF()->GetDIEToType()[src_die.GetDIE()]; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 4005 | if (src_child_type) |
| 4006 | { |
| 4007 | if (log) |
| 4008 | log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", |
| 4009 | static_cast<void*>(src_child_type), |
| 4010 | src_child_type->GetID(), |
| 4011 | src_die.GetOffset(), dst_die.GetOffset()); |
| Tamas Berghammer | eb882fc | 2015-09-09 10:20:48 +0000 | [diff] [blame] | 4012 | dst_die.GetDWARF()->GetDIEToType()[dst_die.GetDIE()] = src_child_type; |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 4013 | } |
| 4014 | else |
| 4015 | { |
| 4016 | if (log) |
| 4017 | log->Printf ("warning: tried to unique lldb_private::Type from 0x%8.8x for 0x%8.8x, but none was found", src_die.GetOffset(), dst_die.GetOffset()); |
| 4018 | } |
| 4019 | } |
| 4020 | } |
| 4021 | } |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 4022 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 4023 | if (dst_size_artificial) |
| 4024 | { |
| 4025 | for (idx = 0; idx < dst_size_artificial; ++idx) |
| 4026 | { |
| 4027 | const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx); |
| 4028 | dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx); |
| 4029 | if (log) |
| 4030 | log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die.GetOffset(), dst_name_artificial); |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 4031 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 4032 | failures.Append(dst_die); |
| 4033 | } |
| 4034 | } |
| Ramkumar Ramachandra | 314b752 | 2015-11-12 14:44:24 +0000 | [diff] [blame] | 4035 | |
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 4036 | return (failures.Size() != 0); |
| 4037 | } |
| 4038 | |
| 4039 | |
| 4040 | bool |
| 4041 | DWARFASTParserClang::LayoutRecordType(const clang::RecordDecl *record_decl, |
| 4042 | uint64_t &bit_size, |
| 4043 | uint64_t &alignment, |
| 4044 | llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets, |
| 4045 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, |
| 4046 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) |
| 4047 | { |
| 4048 | RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl); |
| 4049 | bool success = false; |
| 4050 | base_offsets.clear(); |
| 4051 | vbase_offsets.clear(); |
| 4052 | if (pos != m_record_decl_to_layout_map.end()) |
| 4053 | { |
| 4054 | bit_size = pos->second.bit_size; |
| 4055 | alignment = pos->second.alignment; |
| 4056 | field_offsets.swap(pos->second.field_offsets); |
| 4057 | base_offsets.swap (pos->second.base_offsets); |
| 4058 | vbase_offsets.swap (pos->second.vbase_offsets); |
| 4059 | m_record_decl_to_layout_map.erase(pos); |
| 4060 | success = true; |
| 4061 | } |
| 4062 | else |
| 4063 | { |
| 4064 | bit_size = 0; |
| 4065 | alignment = 0; |
| 4066 | field_offsets.clear(); |
| 4067 | } |
| 4068 | return success; |
| 4069 | } |