Bug Summary

File:tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
Location:line 1151, column 45
Description:Value stored to 'class_symfile' is never read

Annotated Source Code

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