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