Bug Summary

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