blob: 487438b1e1f9eaab8a68574d7152c2cb579e7cfc [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SymbolFileDWARF.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 "SymbolFileDWARF.h"
11
12// Other libraries and framework includes
13#include "clang/AST/ASTConsumer.h"
14#include "clang/AST/ASTContext.h"
15#include "clang/AST/Decl.h"
16#include "clang/AST/DeclGroup.h"
Jim Inghame3ae82a2011-11-12 01:36:43 +000017#include "clang/AST/DeclObjC.h"
Greg Clayton3c2e3ae2012-02-06 06:42:51 +000018#include "clang/AST/DeclTemplate.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "clang/Basic/Builtins.h"
20#include "clang/Basic/IdentifierTable.h"
21#include "clang/Basic/LangOptions.h"
22#include "clang/Basic/SourceManager.h"
23#include "clang/Basic/TargetInfo.h"
24#include "clang/Basic/Specifiers.h"
Greg Clayton7fedea22010-11-16 02:10:54 +000025#include "clang/Sema/DeclSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026
Sean Callanancc427fa2011-07-30 02:42:06 +000027#include "llvm/Support/Casting.h"
28
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Core/Module.h"
30#include "lldb/Core/PluginManager.h"
31#include "lldb/Core/RegularExpression.h"
32#include "lldb/Core/Scalar.h"
33#include "lldb/Core/Section.h"
Greg Claytonc685f8e2010-09-15 04:15:46 +000034#include "lldb/Core/StreamFile.h"
Jim Ingham318c9f22011-08-26 19:44:13 +000035#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000036#include "lldb/Core/Timer.h"
37#include "lldb/Core/Value.h"
38
Greg Clayton20568dd2011-10-13 23:13:20 +000039#include "lldb/Host/Host.h"
40
Chris Lattner30fdc8d2010-06-08 16:52:24 +000041#include "lldb/Symbol/Block.h"
Greg Clayton6beaaa62011-01-17 03:46:26 +000042#include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043#include "lldb/Symbol/CompileUnit.h"
44#include "lldb/Symbol/LineTable.h"
45#include "lldb/Symbol/ObjectFile.h"
46#include "lldb/Symbol/SymbolVendor.h"
47#include "lldb/Symbol/VariableList.h"
48
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000049#include "lldb/Target/ObjCLanguageRuntime.h"
Jim Ingham4cda6e02011-10-07 22:23:45 +000050#include "lldb/Target/CPPLanguageRuntime.h"
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000051
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052#include "DWARFCompileUnit.h"
53#include "DWARFDebugAbbrev.h"
54#include "DWARFDebugAranges.h"
55#include "DWARFDebugInfo.h"
56#include "DWARFDebugInfoEntry.h"
57#include "DWARFDebugLine.h"
58#include "DWARFDebugPubnames.h"
59#include "DWARFDebugRanges.h"
Greg Claytona8022fa2012-04-24 21:22:41 +000060#include "DWARFDeclContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061#include "DWARFDIECollection.h"
62#include "DWARFFormValue.h"
63#include "DWARFLocationList.h"
64#include "LogChannelDWARF.h"
Greg Clayton450e3f32010-10-12 02:24:53 +000065#include "SymbolFileDWARFDebugMap.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066
67#include <map>
68
Matthew Gardinere81df3b2014-08-26 06:57:23 +000069#include <ctype.h>
70#include <string.h>
71
Greg Clayton62742b12010-11-11 01:09:45 +000072//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
Greg Claytonc93237c2010-10-01 20:48:32 +000073
74#ifdef ENABLE_DEBUG_PRINTF
75#include <stdio.h>
Ed Mastea0191d12013-10-17 20:42:56 +000076#define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__)
Greg Claytonc93237c2010-10-01 20:48:32 +000077#else
78#define DEBUG_PRINTF(fmt, ...)
79#endif
80
Greg Clayton594e5ed2010-09-27 21:07:38 +000081#define DIE_IS_BEING_PARSED ((lldb_private::Type*)1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000082
83using namespace lldb;
84using namespace lldb_private;
85
Greg Clayton219cf312012-03-30 00:51:13 +000086//static inline bool
87//child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag)
88//{
89// switch (tag)
90// {
91// default:
92// break;
93// case DW_TAG_subprogram:
94// case DW_TAG_inlined_subroutine:
95// case DW_TAG_class_type:
96// case DW_TAG_structure_type:
97// case DW_TAG_union_type:
98// return true;
99// }
100// return false;
101//}
102//
Sean Callananc7fbf732010-08-06 00:32:49 +0000103static AccessType
Greg Clayton8cf05932010-07-22 18:30:50 +0000104DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000105{
106 switch (dwarf_accessibility)
107 {
Sean Callananc7fbf732010-08-06 00:32:49 +0000108 case DW_ACCESS_public: return eAccessPublic;
109 case DW_ACCESS_private: return eAccessPrivate;
110 case DW_ACCESS_protected: return eAccessProtected;
Greg Clayton8cf05932010-07-22 18:30:50 +0000111 default: break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000112 }
Sean Callananc7fbf732010-08-06 00:32:49 +0000113 return eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000114}
115
Matthew Gardinere81df3b2014-08-26 06:57:23 +0000116static const char*
117removeHostnameFromPathname(const char* path_from_dwarf)
118{
119 if (!path_from_dwarf || !path_from_dwarf[0])
120 {
121 return path_from_dwarf;
122 }
123
124 const char *colon_pos = strchr(path_from_dwarf, ':');
125 if (!colon_pos)
126 {
127 return path_from_dwarf;
128 }
129
130 // check whether we have a windows path, and so the first character
131 // is a drive-letter not a hostname.
132 if (
133 colon_pos == path_from_dwarf + 1 &&
134 isalpha(*path_from_dwarf) &&
135 strlen(path_from_dwarf) > 2 &&
136 '\\' == path_from_dwarf[2])
137 {
138 return path_from_dwarf;
139 }
140
141 return colon_pos + 1;
142}
143
Todd Fiala0a70a842014-05-28 16:43:26 +0000144#if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE)
Greg Clayton1fba87112012-02-09 20:03:49 +0000145
146class DIEStack
147{
148public:
149
150 void Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
151 {
152 m_dies.push_back (DIEInfo(cu, die));
153 }
154
155
156 void LogDIEs (Log *log, SymbolFileDWARF *dwarf)
157 {
158 StreamString log_strm;
159 const size_t n = m_dies.size();
Daniel Malead01b2952012-11-29 21:49:15 +0000160 log_strm.Printf("DIEStack[%" PRIu64 "]:\n", (uint64_t)n);
Greg Clayton1fba87112012-02-09 20:03:49 +0000161 for (size_t i=0; i<n; i++)
162 {
163 DWARFCompileUnit *cu = m_dies[i].cu;
164 const DWARFDebugInfoEntry *die = m_dies[i].die;
165 std::string qualified_name;
166 die->GetQualifiedName(dwarf, cu, qualified_name);
Daniel Malead01b2952012-11-29 21:49:15 +0000167 log_strm.Printf ("[%" PRIu64 "] 0x%8.8x: %s name='%s'\n",
Greg Clayton43e0af02012-09-18 18:04:04 +0000168 (uint64_t)i,
Greg Clayton1fba87112012-02-09 20:03:49 +0000169 die->GetOffset(),
170 DW_TAG_value_to_name(die->Tag()),
171 qualified_name.c_str());
172 }
173 log->PutCString(log_strm.GetData());
174 }
175 void Pop ()
176 {
177 m_dies.pop_back();
178 }
179
180 class ScopedPopper
181 {
182 public:
183 ScopedPopper (DIEStack &die_stack) :
184 m_die_stack (die_stack),
185 m_valid (false)
186 {
187 }
188
189 void
190 Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
191 {
192 m_valid = true;
193 m_die_stack.Push (cu, die);
194 }
195
196 ~ScopedPopper ()
197 {
198 if (m_valid)
199 m_die_stack.Pop();
200 }
201
202
203
204 protected:
205 DIEStack &m_die_stack;
206 bool m_valid;
207 };
208
209protected:
210 struct DIEInfo {
211 DIEInfo (DWARFCompileUnit *c, const DWARFDebugInfoEntry *d) :
212 cu(c),
213 die(d)
214 {
215 }
216 DWARFCompileUnit *cu;
217 const DWARFDebugInfoEntry *die;
218 };
219 typedef std::vector<DIEInfo> Stack;
220 Stack m_dies;
221};
222#endif
223
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000224void
225SymbolFileDWARF::Initialize()
226{
227 LogChannelDWARF::Initialize();
228 PluginManager::RegisterPlugin (GetPluginNameStatic(),
229 GetPluginDescriptionStatic(),
230 CreateInstance);
231}
232
233void
234SymbolFileDWARF::Terminate()
235{
236 PluginManager::UnregisterPlugin (CreateInstance);
237 LogChannelDWARF::Initialize();
238}
239
240
Greg Clayton57abc5d2013-05-10 21:47:16 +0000241lldb_private::ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000242SymbolFileDWARF::GetPluginNameStatic()
243{
Greg Clayton57abc5d2013-05-10 21:47:16 +0000244 static ConstString g_name("dwarf");
245 return g_name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000246}
247
248const char *
249SymbolFileDWARF::GetPluginDescriptionStatic()
250{
251 return "DWARF and DWARF3 debug symbol file reader.";
252}
253
254
255SymbolFile*
256SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
257{
258 return new SymbolFileDWARF(obj_file);
259}
260
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000261TypeList *
262SymbolFileDWARF::GetTypeList ()
263{
Greg Clayton1f746072012-08-29 21:13:06 +0000264 if (GetDebugMapSymfile ())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000265 return m_debug_map_symfile->GetTypeList();
266 return m_obj_file->GetModule()->GetTypeList();
267
268}
Greg Claytonf02500c2013-06-18 22:51:05 +0000269void
270SymbolFileDWARF::GetTypes (DWARFCompileUnit* cu,
271 const DWARFDebugInfoEntry *die,
272 dw_offset_t min_die_offset,
273 dw_offset_t max_die_offset,
274 uint32_t type_mask,
275 TypeSet &type_set)
276{
277 if (cu)
278 {
279 if (die)
280 {
281 const dw_offset_t die_offset = die->GetOffset();
282
283 if (die_offset >= max_die_offset)
284 return;
285
286 if (die_offset >= min_die_offset)
287 {
288 const dw_tag_t tag = die->Tag();
289
290 bool add_type = false;
291
292 switch (tag)
293 {
294 case DW_TAG_array_type: add_type = (type_mask & eTypeClassArray ) != 0; break;
295 case DW_TAG_unspecified_type:
296 case DW_TAG_base_type: add_type = (type_mask & eTypeClassBuiltin ) != 0; break;
297 case DW_TAG_class_type: add_type = (type_mask & eTypeClassClass ) != 0; break;
298 case DW_TAG_structure_type: add_type = (type_mask & eTypeClassStruct ) != 0; break;
299 case DW_TAG_union_type: add_type = (type_mask & eTypeClassUnion ) != 0; break;
300 case DW_TAG_enumeration_type: add_type = (type_mask & eTypeClassEnumeration ) != 0; break;
301 case DW_TAG_subroutine_type:
302 case DW_TAG_subprogram:
303 case DW_TAG_inlined_subroutine: add_type = (type_mask & eTypeClassFunction ) != 0; break;
304 case DW_TAG_pointer_type: add_type = (type_mask & eTypeClassPointer ) != 0; break;
305 case DW_TAG_rvalue_reference_type:
306 case DW_TAG_reference_type: add_type = (type_mask & eTypeClassReference ) != 0; break;
307 case DW_TAG_typedef: add_type = (type_mask & eTypeClassTypedef ) != 0; break;
308 case DW_TAG_ptr_to_member_type: add_type = (type_mask & eTypeClassMemberPointer ) != 0; break;
309 }
310
311 if (add_type)
312 {
313 const bool assert_not_being_parsed = true;
314 Type *type = ResolveTypeUID (cu, die, assert_not_being_parsed);
315 if (type)
316 {
317 if (type_set.find(type) == type_set.end())
318 type_set.insert(type);
319 }
320 }
321 }
322
323 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild();
324 child_die != NULL;
325 child_die = child_die->GetSibling())
326 {
327 GetTypes (cu, child_die, min_die_offset, max_die_offset, type_mask, type_set);
328 }
329 }
330 }
331}
332
333size_t
334SymbolFileDWARF::GetTypes (SymbolContextScope *sc_scope,
335 uint32_t type_mask,
336 TypeList &type_list)
337
338{
339 TypeSet type_set;
340
341 CompileUnit *comp_unit = NULL;
342 DWARFCompileUnit* dwarf_cu = NULL;
343 if (sc_scope)
344 comp_unit = sc_scope->CalculateSymbolContextCompileUnit();
345
346 if (comp_unit)
347 {
348 dwarf_cu = GetDWARFCompileUnit(comp_unit);
349 if (dwarf_cu == 0)
350 return 0;
351 GetTypes (dwarf_cu,
352 dwarf_cu->DIE(),
353 dwarf_cu->GetOffset(),
354 dwarf_cu->GetNextCompileUnitOffset(),
355 type_mask,
356 type_set);
357 }
358 else
359 {
360 DWARFDebugInfo* info = DebugInfo();
361 if (info)
362 {
363 const size_t num_cus = info->GetNumCompileUnits();
364 for (size_t cu_idx=0; cu_idx<num_cus; ++cu_idx)
365 {
366 dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
367 if (dwarf_cu)
368 {
369 GetTypes (dwarf_cu,
370 dwarf_cu->DIE(),
371 0,
372 UINT32_MAX,
373 type_mask,
374 type_set);
375 }
376 }
377 }
378 }
379// if (m_using_apple_tables)
380// {
381// DWARFMappedHash::MemoryTable *apple_types = m_apple_types_ap.get();
382// if (apple_types)
383// {
384// apple_types->ForEach([this, &type_set, apple_types, type_mask](const DWARFMappedHash::DIEInfoArray &die_info_array) -> bool {
385//
386// for (auto die_info: die_info_array)
387// {
388// bool add_type = TagMatchesTypeMask (type_mask, 0);
389// if (!add_type)
390// {
391// dw_tag_t tag = die_info.tag;
392// if (tag == 0)
393// {
394// const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_info.offset, NULL);
395// tag = die->Tag();
396// }
397// add_type = TagMatchesTypeMask (type_mask, tag);
398// }
399// if (add_type)
400// {
401// Type *type = ResolveTypeUID(die_info.offset);
402//
403// if (type_set.find(type) == type_set.end())
404// type_set.insert(type);
405// }
406// }
407// return true; // Keep iterating
408// });
409// }
410// }
411// else
412// {
413// if (!m_indexed)
414// Index ();
415//
416// m_type_index.ForEach([this, &type_set, type_mask](const char *name, uint32_t die_offset) -> bool {
417//
418// bool add_type = TagMatchesTypeMask (type_mask, 0);
419//
420// if (!add_type)
421// {
422// const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_offset, NULL);
423// if (die)
424// {
425// const dw_tag_t tag = die->Tag();
426// add_type = TagMatchesTypeMask (type_mask, tag);
427// }
428// }
429//
430// if (add_type)
431// {
432// Type *type = ResolveTypeUID(die_offset);
433//
434// if (type_set.find(type) == type_set.end())
435// type_set.insert(type);
436// }
437// return true; // Keep iterating
438// });
439// }
440
Greg Clayton57ee3062013-07-11 22:46:58 +0000441 std::set<ClangASTType> clang_type_set;
Greg Claytonf02500c2013-06-18 22:51:05 +0000442 size_t num_types_added = 0;
443 for (Type *type : type_set)
444 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000445 ClangASTType clang_type = type->GetClangForwardType();
Greg Clayton0fc4f312013-06-20 01:23:18 +0000446 if (clang_type_set.find(clang_type) == clang_type_set.end())
447 {
448 clang_type_set.insert(clang_type);
449 type_list.Insert (type->shared_from_this());
450 ++num_types_added;
451 }
Greg Claytonf02500c2013-06-18 22:51:05 +0000452 }
453 return num_types_added;
454}
455
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000456
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000457//----------------------------------------------------------------------
458// Gets the first parent that is a lexical block, function or inlined
459// subroutine, or compile unit.
460//----------------------------------------------------------------------
461static const DWARFDebugInfoEntry *
462GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
463{
464 const DWARFDebugInfoEntry *die;
465 for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
466 {
467 dw_tag_t tag = die->Tag();
468
469 switch (tag)
470 {
471 case DW_TAG_compile_unit:
472 case DW_TAG_subprogram:
473 case DW_TAG_inlined_subroutine:
474 case DW_TAG_lexical_block:
475 return die;
476 }
477 }
478 return NULL;
479}
480
481
Greg Clayton450e3f32010-10-12 02:24:53 +0000482SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
483 SymbolFile (objfile),
Greg Clayton81c22f62011-10-19 18:09:39 +0000484 UserID (0), // Used by SymbolFileDWARFDebugMap to when this class parses .o files to contain the .o file index/ID
Greg Clayton1f746072012-08-29 21:13:06 +0000485 m_debug_map_module_wp (),
Greg Clayton450e3f32010-10-12 02:24:53 +0000486 m_debug_map_symfile (NULL),
Greg Clayton7a345282010-11-09 23:46:37 +0000487 m_clang_tu_decl (NULL),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000488 m_flags(),
Greg Claytond4a2b372011-09-12 23:21:58 +0000489 m_data_debug_abbrev (),
490 m_data_debug_aranges (),
491 m_data_debug_frame (),
492 m_data_debug_info (),
493 m_data_debug_line (),
494 m_data_debug_loc (),
495 m_data_debug_ranges (),
496 m_data_debug_str (),
Greg Clayton17674402011-09-28 17:06:40 +0000497 m_data_apple_names (),
498 m_data_apple_types (),
Greg Clayton7f995132011-10-04 22:41:51 +0000499 m_data_apple_namespaces (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000500 m_abbr(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000501 m_info(),
502 m_line(),
Greg Clayton7f995132011-10-04 22:41:51 +0000503 m_apple_names_ap (),
504 m_apple_types_ap (),
505 m_apple_namespaces_ap (),
Greg Clayton5009f9d2011-10-27 17:55:14 +0000506 m_apple_objc_ap (),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000507 m_function_basename_index(),
508 m_function_fullname_index(),
509 m_function_method_index(),
510 m_function_selector_index(),
Greg Clayton450e3f32010-10-12 02:24:53 +0000511 m_objc_class_selectors_index(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000512 m_global_index(),
Greg Clayton69b04882010-10-15 02:03:22 +0000513 m_type_index(),
514 m_namespace_index(),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000515 m_indexed (false),
516 m_is_external_ast_source (false),
Greg Clayton97fbc342011-10-20 22:30:33 +0000517 m_using_apple_tables (false),
Greg Claytonc7f03b62012-01-12 04:33:28 +0000518 m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +0000519 m_ranges(),
520 m_unique_ast_type_map ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000521{
522}
523
524SymbolFileDWARF::~SymbolFileDWARF()
525{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000526 if (m_is_external_ast_source)
Greg Claytone72dfb32012-02-24 01:59:29 +0000527 {
528 ModuleSP module_sp (m_obj_file->GetModule());
529 if (module_sp)
530 module_sp->GetClangASTContext().RemoveExternalSource ();
531 }
Greg Clayton6beaaa62011-01-17 03:46:26 +0000532}
533
534static const ConstString &
535GetDWARFMachOSegmentName ()
536{
537 static ConstString g_dwarf_section_name ("__DWARF");
538 return g_dwarf_section_name;
539}
540
Greg Claytone576ab22011-02-15 00:19:15 +0000541UniqueDWARFASTTypeMap &
542SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
543{
Greg Clayton1f746072012-08-29 21:13:06 +0000544 if (GetDebugMapSymfile ())
Greg Claytone576ab22011-02-15 00:19:15 +0000545 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
546 return m_unique_ast_type_map;
547}
548
Greg Clayton6beaaa62011-01-17 03:46:26 +0000549ClangASTContext &
550SymbolFileDWARF::GetClangASTContext ()
551{
Greg Clayton1f746072012-08-29 21:13:06 +0000552 if (GetDebugMapSymfile ())
Greg Clayton6beaaa62011-01-17 03:46:26 +0000553 return m_debug_map_symfile->GetClangASTContext ();
554
555 ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext();
556 if (!m_is_external_ast_source)
557 {
558 m_is_external_ast_source = true;
Todd Fiala955fe6f2014-02-27 17:18:23 +0000559 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source_ap (
Greg Clayton6beaaa62011-01-17 03:46:26 +0000560 new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl,
561 SymbolFileDWARF::CompleteObjCInterfaceDecl,
Greg Claytona2721472011-06-25 00:44:06 +0000562 SymbolFileDWARF::FindExternalVisibleDeclsByName,
Greg Claytoncaab74e2012-01-28 00:48:57 +0000563 SymbolFileDWARF::LayoutRecordType,
Greg Clayton6beaaa62011-01-17 03:46:26 +0000564 this));
Greg Clayton6beaaa62011-01-17 03:46:26 +0000565 ast.SetExternalSource (ast_source_ap);
566 }
567 return ast;
568}
569
570void
571SymbolFileDWARF::InitializeObject()
572{
573 // Install our external AST source callbacks so we can complete Clang types.
Greg Claytone72dfb32012-02-24 01:59:29 +0000574 ModuleSP module_sp (m_obj_file->GetModule());
575 if (module_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +0000576 {
Greg Clayton3046e662013-07-10 01:23:25 +0000577 const SectionList *section_list = module_sp->GetSectionList();
Greg Clayton6beaaa62011-01-17 03:46:26 +0000578
579 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
580
581 // Memory map the DWARF mach-o segment so we have everything mmap'ed
582 // to keep our heap memory usage down.
583 if (section)
Greg Claytonc9660542012-02-05 02:38:54 +0000584 m_obj_file->MemoryMapSectionData(section, m_dwarf_data);
Greg Clayton6beaaa62011-01-17 03:46:26 +0000585 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000586 get_apple_names_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000587 if (m_data_apple_names.GetByteSize() > 0)
588 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000589 m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names"));
590 if (m_apple_names_ap->IsValid())
591 m_using_apple_tables = true;
592 else
Greg Clayton7f995132011-10-04 22:41:51 +0000593 m_apple_names_ap.reset();
594 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000595 get_apple_types_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000596 if (m_data_apple_types.GetByteSize() > 0)
597 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000598 m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types"));
599 if (m_apple_types_ap->IsValid())
600 m_using_apple_tables = true;
601 else
Greg Clayton7f995132011-10-04 22:41:51 +0000602 m_apple_types_ap.reset();
603 }
604
605 get_apple_namespaces_data();
606 if (m_data_apple_namespaces.GetByteSize() > 0)
607 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000608 m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces"));
609 if (m_apple_namespaces_ap->IsValid())
610 m_using_apple_tables = true;
611 else
Greg Clayton7f995132011-10-04 22:41:51 +0000612 m_apple_namespaces_ap.reset();
613 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000614
Greg Clayton5009f9d2011-10-27 17:55:14 +0000615 get_apple_objc_data();
616 if (m_data_apple_objc.GetByteSize() > 0)
617 {
618 m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc"));
619 if (m_apple_objc_ap->IsValid())
620 m_using_apple_tables = true;
621 else
622 m_apple_objc_ap.reset();
623 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000624}
625
626bool
627SymbolFileDWARF::SupportedVersion(uint16_t version)
628{
Greg Claytonabcbfe52013-04-04 00:00:36 +0000629 return version == 2 || version == 3 || version == 4;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000630}
631
632uint32_t
Sean Callananbfaf54d2011-12-03 04:38:43 +0000633SymbolFileDWARF::CalculateAbilities ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000634{
635 uint32_t abilities = 0;
636 if (m_obj_file != NULL)
637 {
638 const Section* section = NULL;
639 const SectionList *section_list = m_obj_file->GetSectionList();
640 if (section_list == NULL)
641 return 0;
642
643 uint64_t debug_abbrev_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000644 uint64_t debug_info_file_size = 0;
645 uint64_t debug_line_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000646
Greg Clayton6beaaa62011-01-17 03:46:26 +0000647 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000648
649 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000650 section_list = &section->GetChildren ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000651
Greg Clayton4ceb9982010-07-21 22:54:26 +0000652 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000653 if (section != NULL)
654 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000655 debug_info_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000656
Greg Clayton4ceb9982010-07-21 22:54:26 +0000657 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000658 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000659 debug_abbrev_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000660 else
661 m_flags.Set (flagsGotDebugAbbrevData);
662
Greg Clayton4ceb9982010-07-21 22:54:26 +0000663 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000664 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000665 m_flags.Set (flagsGotDebugArangesData);
666
Greg Clayton4ceb9982010-07-21 22:54:26 +0000667 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000668 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000669 m_flags.Set (flagsGotDebugFrameData);
670
Greg Clayton4ceb9982010-07-21 22:54:26 +0000671 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000672 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000673 debug_line_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000674 else
675 m_flags.Set (flagsGotDebugLineData);
676
Greg Clayton4ceb9982010-07-21 22:54:26 +0000677 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000678 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000679 m_flags.Set (flagsGotDebugLocData);
680
Greg Clayton4ceb9982010-07-21 22:54:26 +0000681 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000682 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000683 m_flags.Set (flagsGotDebugMacInfoData);
684
Greg Clayton4ceb9982010-07-21 22:54:26 +0000685 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000686 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000687 m_flags.Set (flagsGotDebugPubNamesData);
688
Greg Clayton4ceb9982010-07-21 22:54:26 +0000689 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000690 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000691 m_flags.Set (flagsGotDebugPubTypesData);
692
Greg Clayton4ceb9982010-07-21 22:54:26 +0000693 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000694 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000695 m_flags.Set (flagsGotDebugRangesData);
696
Greg Clayton4ceb9982010-07-21 22:54:26 +0000697 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000698 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000699 m_flags.Set (flagsGotDebugStrData);
700 }
Greg Clayton6c596612012-05-18 21:47:20 +0000701 else
702 {
703 const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString();
704 if (symfile_dir_cstr)
705 {
706 if (strcasestr(symfile_dir_cstr, ".dsym"))
707 {
708 if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo)
709 {
710 // We have a dSYM file that didn't have a any debug info.
711 // If the string table has a size of 1, then it was made from
712 // an executable with no debug info, or from an executable that
713 // was stripped.
714 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
715 if (section && section->GetFileSize() == 1)
716 {
717 m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info.");
718 }
719 }
720 }
721 }
722 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000723
724 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
725 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
726
727 if (debug_line_file_size > 0)
728 abilities |= LineTables;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000729 }
730 return abilities;
731}
732
Ed Masteeeae7212013-10-24 20:43:47 +0000733const DWARFDataExtractor&
734SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DWARFDataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000735{
736 if (m_flags.IsClear (got_flag))
737 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000738 ModuleSP module_sp (m_obj_file->GetModule());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000739 m_flags.Set (got_flag);
Greg Clayton3046e662013-07-10 01:23:25 +0000740 const SectionList *section_list = module_sp->GetSectionList();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000741 if (section_list)
742 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000743 SectionSP section_sp (section_list->FindSectionByType(sect_type, true));
744 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000745 {
746 // See if we memory mapped the DWARF segment?
747 if (m_dwarf_data.GetByteSize())
748 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000749 data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000750 }
751 else
752 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000753 if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000754 data.Clear();
755 }
756 }
757 }
758 }
759 return data;
760}
761
Ed Masteeeae7212013-10-24 20:43:47 +0000762const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000763SymbolFileDWARF::get_debug_abbrev_data()
764{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000765 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000766}
767
Ed Masteeeae7212013-10-24 20:43:47 +0000768const DWARFDataExtractor&
Greg Claytond4a2b372011-09-12 23:21:58 +0000769SymbolFileDWARF::get_debug_aranges_data()
770{
771 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
772}
773
Ed Masteeeae7212013-10-24 20:43:47 +0000774const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000775SymbolFileDWARF::get_debug_frame_data()
776{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000777 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000778}
779
Ed Masteeeae7212013-10-24 20:43:47 +0000780const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000781SymbolFileDWARF::get_debug_info_data()
782{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000783 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000784}
785
Ed Masteeeae7212013-10-24 20:43:47 +0000786const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000787SymbolFileDWARF::get_debug_line_data()
788{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000789 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000790}
791
Ed Masteeeae7212013-10-24 20:43:47 +0000792const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000793SymbolFileDWARF::get_debug_loc_data()
794{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000795 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000796}
797
Ed Masteeeae7212013-10-24 20:43:47 +0000798const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000799SymbolFileDWARF::get_debug_ranges_data()
800{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000801 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000802}
803
Ed Masteeeae7212013-10-24 20:43:47 +0000804const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000805SymbolFileDWARF::get_debug_str_data()
806{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000807 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000808}
809
Ed Masteeeae7212013-10-24 20:43:47 +0000810const DWARFDataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000811SymbolFileDWARF::get_apple_names_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000812{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000813 return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names);
Greg Claytonf9eec202011-09-01 23:16:13 +0000814}
815
Ed Masteeeae7212013-10-24 20:43:47 +0000816const DWARFDataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000817SymbolFileDWARF::get_apple_types_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000818{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000819 return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types);
Greg Claytonf9eec202011-09-01 23:16:13 +0000820}
821
Ed Masteeeae7212013-10-24 20:43:47 +0000822const DWARFDataExtractor&
Greg Clayton7f995132011-10-04 22:41:51 +0000823SymbolFileDWARF::get_apple_namespaces_data()
824{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000825 return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
826}
827
Ed Masteeeae7212013-10-24 20:43:47 +0000828const DWARFDataExtractor&
Greg Clayton5009f9d2011-10-27 17:55:14 +0000829SymbolFileDWARF::get_apple_objc_data()
830{
831 return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc);
Greg Clayton7f995132011-10-04 22:41:51 +0000832}
833
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000834
835DWARFDebugAbbrev*
836SymbolFileDWARF::DebugAbbrev()
837{
838 if (m_abbr.get() == NULL)
839 {
Ed Masteeeae7212013-10-24 20:43:47 +0000840 const DWARFDataExtractor &debug_abbrev_data = get_debug_abbrev_data();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000841 if (debug_abbrev_data.GetByteSize() > 0)
842 {
843 m_abbr.reset(new DWARFDebugAbbrev());
844 if (m_abbr.get())
845 m_abbr->Parse(debug_abbrev_data);
846 }
847 }
848 return m_abbr.get();
849}
850
851const DWARFDebugAbbrev*
852SymbolFileDWARF::DebugAbbrev() const
853{
854 return m_abbr.get();
855}
856
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000857
858DWARFDebugInfo*
859SymbolFileDWARF::DebugInfo()
860{
861 if (m_info.get() == NULL)
862 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000863 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p",
864 __PRETTY_FUNCTION__, static_cast<void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000865 if (get_debug_info_data().GetByteSize() > 0)
866 {
867 m_info.reset(new DWARFDebugInfo());
868 if (m_info.get())
869 {
870 m_info->SetDwarfData(this);
871 }
872 }
873 }
874 return m_info.get();
875}
876
877const DWARFDebugInfo*
878SymbolFileDWARF::DebugInfo() const
879{
880 return m_info.get();
881}
882
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000883DWARFCompileUnit*
Greg Clayton1f746072012-08-29 21:13:06 +0000884SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000885{
886 DWARFDebugInfo* info = DebugInfo();
Greg Clayton1f746072012-08-29 21:13:06 +0000887 if (info)
888 {
889 if (GetDebugMapSymfile ())
890 {
891 // The debug map symbol file made the compile units for this DWARF
892 // file which is .o file with DWARF in it, and we should have
893 // only 1 compile unit which is at offset zero in the DWARF.
894 // TODO: modify to support LTO .o files where each .o file might
895 // have multiple DW_TAG_compile_unit tags.
Greg Clayton68c00bd2015-02-05 02:10:29 +0000896
897 DWARFCompileUnit *dwarf_cu = info->GetCompileUnit(0).get();
898 if (dwarf_cu && dwarf_cu->GetUserData() == NULL)
899 dwarf_cu->SetUserData(comp_unit);
900 return dwarf_cu;
Greg Clayton1f746072012-08-29 21:13:06 +0000901 }
902 else
903 {
904 // Just a normal DWARF file whose user ID for the compile unit is
905 // the DWARF offset itself
Greg Clayton68c00bd2015-02-05 02:10:29 +0000906
907 DWARFCompileUnit *dwarf_cu = info->GetCompileUnit((dw_offset_t)comp_unit->GetID()).get();
908 if (dwarf_cu && dwarf_cu->GetUserData() == NULL)
909 dwarf_cu->SetUserData(comp_unit);
910 return dwarf_cu;
911
Greg Clayton1f746072012-08-29 21:13:06 +0000912 }
913 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000914 return NULL;
915}
916
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000917
918DWARFDebugRanges*
919SymbolFileDWARF::DebugRanges()
920{
921 if (m_ranges.get() == NULL)
922 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000923 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p",
924 __PRETTY_FUNCTION__, static_cast<void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000925 if (get_debug_ranges_data().GetByteSize() > 0)
926 {
927 m_ranges.reset(new DWARFDebugRanges());
928 if (m_ranges.get())
929 m_ranges->Extract(this);
930 }
931 }
932 return m_ranges.get();
933}
934
935const DWARFDebugRanges*
936SymbolFileDWARF::DebugRanges() const
937{
938 return m_ranges.get();
939}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000940
Greg Clayton53eb1c22012-04-02 22:59:12 +0000941lldb::CompUnitSP
942SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000943{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000944 CompUnitSP cu_sp;
945 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000946 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000947 CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData();
948 if (comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000949 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000950 // We already parsed this compile unit, had out a shared pointer to it
951 cu_sp = comp_unit->shared_from_this();
952 }
953 else
954 {
Greg Clayton1f746072012-08-29 21:13:06 +0000955 if (GetDebugMapSymfile ())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000956 {
Greg Clayton1f746072012-08-29 21:13:06 +0000957 // Let the debug map create the compile unit
958 cu_sp = m_debug_map_symfile->GetCompileUnit(this);
959 dwarf_cu->SetUserData(cu_sp.get());
960 }
961 else
962 {
963 ModuleSP module_sp (m_obj_file->GetModule());
964 if (module_sp)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000965 {
Greg Clayton1f746072012-08-29 21:13:06 +0000966 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly ();
967 if (cu_die)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000968 {
Greg Clayton1f746072012-08-29 21:13:06 +0000969 const char * cu_die_name = cu_die->GetName(this, dwarf_cu);
970 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
971 LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
972 if (cu_die_name)
973 {
974 std::string ramapped_file;
975 FileSpec cu_file_spec;
Jim Ingham0909e5f2010-09-16 00:57:33 +0000976
Greg Clayton1f746072012-08-29 21:13:06 +0000977 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0')
Greg Clayton53eb1c22012-04-02 22:59:12 +0000978 {
Greg Clayton1f746072012-08-29 21:13:06 +0000979 // If we have a full path to the compile unit, we don't need to resolve
980 // the file. This can be expensive e.g. when the source files are NFS mounted.
981 if (module_sp->RemapSourceFile(cu_die_name, ramapped_file))
982 cu_file_spec.SetFile (ramapped_file.c_str(), false);
983 else
984 cu_file_spec.SetFile (cu_die_name, false);
Greg Clayton53eb1c22012-04-02 22:59:12 +0000985 }
986 else
987 {
Matthew Gardinere81df3b2014-08-26 06:57:23 +0000988 // DWARF2/3 suggests the form hostname:pathname for compilation directory.
989 // Remove the host part if present.
990 cu_comp_dir = removeHostnameFromPathname(cu_comp_dir);
Greg Clayton1f746072012-08-29 21:13:06 +0000991 std::string fullpath(cu_comp_dir);
Matthew Gardinere81df3b2014-08-26 06:57:23 +0000992
Greg Clayton1f746072012-08-29 21:13:06 +0000993 if (*fullpath.rbegin() != '/')
994 fullpath += '/';
995 fullpath += cu_die_name;
996 if (module_sp->RemapSourceFile (fullpath.c_str(), ramapped_file))
997 cu_file_spec.SetFile (ramapped_file.c_str(), false);
998 else
999 cu_file_spec.SetFile (fullpath.c_str(), false);
1000 }
1001
1002 cu_sp.reset(new CompileUnit (module_sp,
1003 dwarf_cu,
1004 cu_file_spec,
1005 MakeUserID(dwarf_cu->GetOffset()),
1006 cu_language));
1007 if (cu_sp)
1008 {
1009 dwarf_cu->SetUserData(cu_sp.get());
1010
Greg Clayton53eb1c22012-04-02 22:59:12 +00001011 // Figure out the compile unit index if we weren't given one
1012 if (cu_idx == UINT32_MAX)
1013 DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx);
1014
1015 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp);
1016 }
1017 }
1018 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001019 }
1020 }
1021 }
1022 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00001023 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001024}
1025
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001026uint32_t
1027SymbolFileDWARF::GetNumCompileUnits()
1028{
1029 DWARFDebugInfo* info = DebugInfo();
1030 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001031 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001032 return 0;
1033}
1034
1035CompUnitSP
1036SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
1037{
Greg Clayton53eb1c22012-04-02 22:59:12 +00001038 CompUnitSP cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001039 DWARFDebugInfo* info = DebugInfo();
1040 if (info)
1041 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00001042 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
1043 if (dwarf_cu)
1044 cu_sp = ParseCompileUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001045 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00001046 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001047}
1048
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001049Function *
Greg Clayton0fffff52010-09-24 05:15:53 +00001050SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001051{
1052 DWARFDebugRanges::RangeList func_ranges;
1053 const char *name = NULL;
1054 const char *mangled = NULL;
1055 int decl_file = 0;
1056 int decl_line = 0;
1057 int decl_column = 0;
1058 int call_file = 0;
1059 int call_line = 0;
1060 int call_column = 0;
1061 DWARFExpression frame_base;
1062
Greg Claytonc93237c2010-10-01 20:48:32 +00001063 assert (die->Tag() == DW_TAG_subprogram);
1064
1065 if (die->Tag() != DW_TAG_subprogram)
1066 return NULL;
1067
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001068 if (die->GetDIENamesAndRanges (this,
1069 dwarf_cu,
1070 name,
1071 mangled,
1072 func_ranges,
1073 decl_file,
1074 decl_line,
1075 decl_column,
1076 call_file,
1077 call_line,
1078 call_column,
1079 &frame_base))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001080 {
1081 // Union of all ranges in the function DIE (if the function is discontiguous)
1082 AddressRange func_range;
Greg Claytonea3e7d52011-10-08 00:49:15 +00001083 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0);
1084 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001085 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
1086 {
Michael Sartaina7499c92013-07-01 19:45:50 +00001087 ModuleSP module_sp (m_obj_file->GetModule());
Greg Clayton3046e662013-07-10 01:23:25 +00001088 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, module_sp->GetSectionList());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001089 if (func_range.GetBaseAddress().IsValid())
1090 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
1091 }
1092
1093 if (func_range.GetBaseAddress().IsValid())
1094 {
1095 Mangled func_name;
1096 if (mangled)
Greg Clayton037520e2012-07-18 23:18:10 +00001097 func_name.SetValue(ConstString(mangled), true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001098 else if (name)
Greg Clayton037520e2012-07-18 23:18:10 +00001099 func_name.SetValue(ConstString(name), false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001100
1101 FunctionSP func_sp;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001102 std::unique_ptr<Declaration> decl_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001103 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +00001104 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1105 decl_line,
1106 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001107
Greg Clayton0bd4e1b2011-09-30 20:52:25 +00001108 // Supply the type _only_ if it has already been parsed
Greg Clayton594e5ed2010-09-27 21:07:38 +00001109 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001110
1111 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
1112
Greg Clayton9422dd62013-03-04 21:46:16 +00001113 if (FixupAddress (func_range.GetBaseAddress()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001114 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001115 const user_id_t func_user_id = MakeUserID(die->GetOffset());
1116 func_sp.reset(new Function (sc.comp_unit,
1117 MakeUserID(func_user_id), // UserID is the DIE offset
1118 MakeUserID(func_user_id),
1119 func_name,
1120 func_type,
1121 func_range)); // first address range
1122
1123 if (func_sp.get() != NULL)
1124 {
1125 if (frame_base.IsValid())
1126 func_sp->GetFrameBaseExpression() = frame_base;
1127 sc.comp_unit->AddFunction(func_sp);
1128 return func_sp.get();
1129 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001130 }
1131 }
1132 }
1133 return NULL;
1134}
1135
Greg Clayton9422dd62013-03-04 21:46:16 +00001136bool
1137SymbolFileDWARF::FixupAddress (Address &addr)
1138{
1139 SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile ();
1140 if (debug_map_symfile)
1141 {
1142 return debug_map_symfile->LinkOSOAddress(addr);
1143 }
1144 // This is a normal DWARF file, no address fixups need to happen
1145 return true;
1146}
Greg Clayton1f746072012-08-29 21:13:06 +00001147lldb::LanguageType
1148SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc)
1149{
1150 assert (sc.comp_unit);
1151 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1152 if (dwarf_cu)
1153 {
1154 const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly();
Jim Ingham28eb5712012-10-12 17:34:26 +00001155 if (die)
1156 {
1157 const uint32_t language = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
1158 if (language)
1159 return (lldb::LanguageType)language;
1160 }
Greg Clayton1f746072012-08-29 21:13:06 +00001161 }
1162 return eLanguageTypeUnknown;
1163}
1164
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001165size_t
1166SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
1167{
1168 assert (sc.comp_unit);
1169 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00001170 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001171 if (dwarf_cu)
1172 {
1173 DWARFDIECollection function_dies;
Greg Clayton1f746072012-08-29 21:13:06 +00001174 const size_t num_functions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001175 size_t func_idx;
Greg Clayton1f746072012-08-29 21:13:06 +00001176 for (func_idx = 0; func_idx < num_functions; ++func_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001177 {
1178 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
Greg Clayton81c22f62011-10-19 18:09:39 +00001179 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001180 {
1181 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
1182 ++functions_added;
1183 }
1184 }
1185 //FixupTypes();
1186 }
1187 return functions_added;
1188}
1189
1190bool
1191SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
1192{
1193 assert (sc.comp_unit);
Greg Clayton1f746072012-08-29 21:13:06 +00001194 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Greg Claytonda2455b2012-11-01 17:28:37 +00001195 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001196 {
Greg Claytonda2455b2012-11-01 17:28:37 +00001197 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001198
Greg Claytonda2455b2012-11-01 17:28:37 +00001199 if (cu_die)
1200 {
1201 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
Matthew Gardinere81df3b2014-08-26 06:57:23 +00001202
1203 // DWARF2/3 suggests the form hostname:pathname for compilation directory.
1204 // Remove the host part if present.
1205 cu_comp_dir = removeHostnameFromPathname(cu_comp_dir);
1206
Greg Claytonda2455b2012-11-01 17:28:37 +00001207 dw_offset_t stmt_list = cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001208
Greg Claytonda2455b2012-11-01 17:28:37 +00001209 // All file indexes in DWARF are one based and a file of index zero is
1210 // supposed to be the compile unit itself.
1211 support_files.Append (*sc.comp_unit);
1212
1213 return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
1214 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001215 }
1216 return false;
1217}
1218
1219struct ParseDWARFLineTableCallbackInfo
1220{
1221 LineTable* line_table;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001222 std::unique_ptr<LineSequence> sequence_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001223};
1224
1225//----------------------------------------------------------------------
1226// ParseStatementTableCallback
1227//----------------------------------------------------------------------
1228static void
1229ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
1230{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001231 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
1232 {
1233 // Just started parsing the line table
1234 }
1235 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
1236 {
1237 // Done parsing line table, nothing to do for the cleanup
1238 }
1239 else
1240 {
1241 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
Greg Clayton9422dd62013-03-04 21:46:16 +00001242 LineTable* line_table = info->line_table;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001243
Greg Clayton9422dd62013-03-04 21:46:16 +00001244 // If this is our first time here, we need to create a
1245 // sequence container.
1246 if (!info->sequence_ap.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001247 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001248 info->sequence_ap.reset(line_table->CreateLineSequenceContainer());
1249 assert(info->sequence_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001250 }
Greg Clayton9422dd62013-03-04 21:46:16 +00001251 line_table->AppendLineEntryToSequence (info->sequence_ap.get(),
1252 state.address,
1253 state.line,
1254 state.column,
1255 state.file,
1256 state.is_stmt,
1257 state.basic_block,
1258 state.prologue_end,
1259 state.epilogue_begin,
1260 state.end_sequence);
1261 if (state.end_sequence)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001262 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001263 // First, put the current sequence into the line table.
1264 line_table->InsertSequence(info->sequence_ap.get());
1265 // Then, empty it to prepare for the next sequence.
1266 info->sequence_ap->Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001267 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001268 }
1269}
1270
1271bool
1272SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1273{
1274 assert (sc.comp_unit);
1275 if (sc.comp_unit->GetLineTable() != NULL)
1276 return true;
1277
Greg Clayton1f746072012-08-29 21:13:06 +00001278 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001279 if (dwarf_cu)
1280 {
1281 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Greg Clayton129d12c2011-11-28 03:29:03 +00001282 if (dwarf_cu_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001283 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001284 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1285 if (cu_line_offset != DW_INVALID_OFFSET)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001286 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001287 std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
Greg Clayton129d12c2011-11-28 03:29:03 +00001288 if (line_table_ap.get())
1289 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001290 ParseDWARFLineTableCallbackInfo info;
1291 info.line_table = line_table_ap.get();
Greg Claytonc7bece562013-01-25 18:06:21 +00001292 lldb::offset_t offset = cu_line_offset;
Greg Clayton129d12c2011-11-28 03:29:03 +00001293 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
Greg Clayton9422dd62013-03-04 21:46:16 +00001294 if (m_debug_map_symfile)
1295 {
1296 // We have an object file that has a line table with addresses
1297 // that are not linked. We need to link the line table and convert
1298 // the addresses that are relative to the .o file into addresses
1299 // for the main executable.
1300 sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get()));
1301 }
1302 else
1303 {
1304 sc.comp_unit->SetLineTable(line_table_ap.release());
1305 return true;
1306 }
Greg Clayton129d12c2011-11-28 03:29:03 +00001307 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001308 }
1309 }
1310 }
1311 return false;
1312}
1313
1314size_t
1315SymbolFileDWARF::ParseFunctionBlocks
1316(
1317 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001318 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001319 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001320 const DWARFDebugInfoEntry *die,
1321 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001322 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001323)
1324{
1325 size_t blocks_added = 0;
1326 while (die != NULL)
1327 {
1328 dw_tag_t tag = die->Tag();
1329
1330 switch (tag)
1331 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001332 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001333 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001334 case DW_TAG_lexical_block:
1335 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001336 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001337 if (tag == DW_TAG_subprogram)
1338 {
1339 // Skip any DW_TAG_subprogram DIEs that are inside
1340 // of a normal or inlined functions. These will be
1341 // parsed on their own as separate entities.
1342
1343 if (depth > 0)
1344 break;
1345
1346 block = parent_block;
1347 }
1348 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001349 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001350 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001351 parent_block->AddChild(block_sp);
1352 block = block_sp.get();
1353 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001354 DWARFDebugRanges::RangeList ranges;
1355 const char *name = NULL;
1356 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001357
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001358 int decl_file = 0;
1359 int decl_line = 0;
1360 int decl_column = 0;
1361 int call_file = 0;
1362 int call_line = 0;
1363 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001364 if (die->GetDIENamesAndRanges (this,
1365 dwarf_cu,
1366 name,
1367 mangled_name,
1368 ranges,
1369 decl_file, decl_line, decl_column,
1370 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001371 {
1372 if (tag == DW_TAG_subprogram)
1373 {
1374 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001375 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001376 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001377 else if (tag == DW_TAG_inlined_subroutine)
1378 {
1379 // We get called here for inlined subroutines in two ways.
1380 // The first time is when we are making the Function object
1381 // for this inlined concrete instance. Since we're creating a top level block at
1382 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1383 // adjust the containing address.
1384 // The second time is when we are parsing the blocks inside the function that contains
1385 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1386 // function the offset will be for that function.
1387 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1388 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001389 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001390 }
1391 }
Greg Clayton103f3092015-01-15 03:04:37 +00001392
1393 const size_t num_ranges = ranges.GetSize();
1394 for (size_t i = 0; i<num_ranges; ++i)
1395 {
1396 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i);
1397 const addr_t range_base = range.GetRangeBase();
1398 if (range_base >= subprogram_low_pc)
1399 block->AddRange(Block::Range (range_base - subprogram_low_pc, range.GetByteSize()));
1400 else
1401 {
1402 GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": adding range [0x%" PRIx64 "-0x%" PRIx64 ") which has a base that is less than the function's low PC 0x%" PRIx64 ". Please file a bug and attach the file at the start of this error message",
1403 block->GetID(),
1404 range_base,
1405 range.GetRangeEnd(),
1406 subprogram_low_pc);
1407 }
1408 }
1409 block->FinalizeRanges ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001410
1411 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1412 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001413 std::unique_ptr<Declaration> decl_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001414 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001415 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1416 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001417
Greg Clayton7b0992d2013-04-18 22:45:39 +00001418 std::unique_ptr<Declaration> call_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001419 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001420 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1421 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001422
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001423 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001424 }
1425
1426 ++blocks_added;
1427
Greg Claytondd7feaf2011-08-12 17:54:33 +00001428 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001429 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001430 blocks_added += ParseFunctionBlocks (sc,
1431 block,
1432 dwarf_cu,
1433 die->GetFirstChild(),
1434 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001435 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001436 }
1437 }
1438 }
1439 break;
1440 default:
1441 break;
1442 }
1443
Greg Claytondd7feaf2011-08-12 17:54:33 +00001444 // Only parse siblings of the block if we are not at depth zero. A depth
1445 // of zero indicates we are currently parsing the top level
1446 // DW_TAG_subprogram DIE
1447
1448 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001449 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001450 else
1451 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001452 }
1453 return blocks_added;
1454}
1455
Greg Claytonf0705c82011-10-22 03:33:13 +00001456bool
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001457SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu,
1458 const DWARFDebugInfoEntry *die,
1459 ClangASTContext::TemplateParameterInfos &template_param_infos)
1460{
1461 const dw_tag_t tag = die->Tag();
1462
1463 switch (tag)
1464 {
1465 case DW_TAG_template_type_parameter:
1466 case DW_TAG_template_value_parameter:
1467 {
Todd Fialaee8bfc62014-09-11 17:29:12 +00001468 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001469
1470 DWARFDebugInfoEntry::Attributes attributes;
1471 const size_t num_attributes = die->GetAttributes (this,
1472 dwarf_cu,
1473 fixed_form_sizes,
1474 attributes);
1475 const char *name = NULL;
1476 Type *lldb_type = NULL;
Greg Clayton57ee3062013-07-11 22:46:58 +00001477 ClangASTType clang_type;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001478 uint64_t uval64 = 0;
1479 bool uval64_valid = false;
1480 if (num_attributes > 0)
1481 {
1482 DWARFFormValue form_value;
1483 for (size_t i=0; i<num_attributes; ++i)
1484 {
1485 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1486
1487 switch (attr)
1488 {
1489 case DW_AT_name:
1490 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1491 name = form_value.AsCString(&get_debug_str_data());
1492 break;
1493
1494 case DW_AT_type:
1495 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1496 {
Greg Clayton54166af2014-11-22 01:58:59 +00001497 const dw_offset_t type_die_offset = form_value.Reference();
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001498 lldb_type = ResolveTypeUID(type_die_offset);
1499 if (lldb_type)
1500 clang_type = lldb_type->GetClangForwardType();
1501 }
1502 break;
1503
1504 case DW_AT_const_value:
1505 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1506 {
1507 uval64_valid = true;
1508 uval64 = form_value.Unsigned();
1509 }
1510 break;
1511 default:
1512 break;
1513 }
1514 }
1515
Greg Clayton283b2652013-04-23 22:38:02 +00001516 clang::ASTContext *ast = GetClangASTContext().getASTContext();
1517 if (!clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00001518 clang_type = GetClangASTContext().GetBasicType(eBasicTypeVoid);
Greg Clayton283b2652013-04-23 22:38:02 +00001519
1520 if (clang_type)
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001521 {
1522 bool is_signed = false;
Greg Clayton283b2652013-04-23 22:38:02 +00001523 if (name && name[0])
1524 template_param_infos.names.push_back(name);
1525 else
1526 template_param_infos.names.push_back(NULL);
1527
Greg Clayton283b2652013-04-23 22:38:02 +00001528 if (tag == DW_TAG_template_value_parameter &&
1529 lldb_type != NULL &&
Greg Clayton57ee3062013-07-11 22:46:58 +00001530 clang_type.IsIntegerType (is_signed) &&
Greg Clayton283b2652013-04-23 22:38:02 +00001531 uval64_valid)
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001532 {
1533 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
Greg Clayton283b2652013-04-23 22:38:02 +00001534 template_param_infos.args.push_back (clang::TemplateArgument (*ast,
Sean Callanan3d654b32012-09-24 22:25:51 +00001535 llvm::APSInt(apint),
Greg Clayton57ee3062013-07-11 22:46:58 +00001536 clang_type.GetQualType()));
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001537 }
1538 else
1539 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001540 template_param_infos.args.push_back (clang::TemplateArgument (clang_type.GetQualType()));
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001541 }
1542 }
1543 else
1544 {
1545 return false;
1546 }
1547
1548 }
1549 }
1550 return true;
1551
1552 default:
1553 break;
1554 }
1555 return false;
1556}
1557
1558bool
Greg Claytonf0705c82011-10-22 03:33:13 +00001559SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1560 const DWARFDebugInfoEntry *parent_die,
1561 ClangASTContext::TemplateParameterInfos &template_param_infos)
1562{
1563
1564 if (parent_die == NULL)
Filipe Cabecinhas52008c62012-05-23 16:24:11 +00001565 return false;
Greg Claytonf0705c82011-10-22 03:33:13 +00001566
Greg Claytonf0705c82011-10-22 03:33:13 +00001567 Args template_parameter_names;
1568 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1569 die != NULL;
1570 die = die->GetSibling())
1571 {
1572 const dw_tag_t tag = die->Tag();
1573
1574 switch (tag)
1575 {
1576 case DW_TAG_template_type_parameter:
1577 case DW_TAG_template_value_parameter:
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001578 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Claytonf0705c82011-10-22 03:33:13 +00001579 break;
1580
1581 default:
1582 break;
1583 }
1584 }
1585 if (template_param_infos.args.empty())
1586 return false;
1587 return template_param_infos.args.size() == template_param_infos.names.size();
1588}
1589
1590clang::ClassTemplateDecl *
1591SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001592 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001593 const char *parent_name,
1594 int tag_decl_kind,
1595 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1596{
1597 if (template_param_infos.IsValid())
1598 {
1599 std::string template_basename(parent_name);
1600 template_basename.erase (template_basename.find('<'));
1601 ClangASTContext &ast = GetClangASTContext();
1602
1603 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001604 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001605 template_basename.c_str(),
1606 tag_decl_kind,
1607 template_param_infos);
1608 }
1609 return NULL;
1610}
1611
Sean Callanana0b80ab2012-06-04 22:28:05 +00001612class SymbolFileDWARF::DelayedAddObjCClassProperty
1613{
1614public:
1615 DelayedAddObjCClassProperty
1616 (
Greg Clayton57ee3062013-07-11 22:46:58 +00001617 const ClangASTType &class_opaque_type,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001618 const char *property_name,
Greg Clayton57ee3062013-07-11 22:46:58 +00001619 const ClangASTType &property_opaque_type, // The property type is only required if you don't have an ivar decl
Sean Callanana0b80ab2012-06-04 22:28:05 +00001620 clang::ObjCIvarDecl *ivar_decl,
1621 const char *property_setter_name,
1622 const char *property_getter_name,
1623 uint32_t property_attributes,
Greg Claytonc4ffd662013-03-08 01:37:30 +00001624 const ClangASTMetadata *metadata
Sean Callanana0b80ab2012-06-04 22:28:05 +00001625 ) :
Sean Callanana0b80ab2012-06-04 22:28:05 +00001626 m_class_opaque_type (class_opaque_type),
1627 m_property_name (property_name),
1628 m_property_opaque_type (property_opaque_type),
1629 m_ivar_decl (ivar_decl),
1630 m_property_setter_name (property_setter_name),
1631 m_property_getter_name (property_getter_name),
Jim Ingham379397632012-10-27 02:54:13 +00001632 m_property_attributes (property_attributes)
Sean Callanana0b80ab2012-06-04 22:28:05 +00001633 {
Jim Ingham379397632012-10-27 02:54:13 +00001634 if (metadata != NULL)
1635 {
1636 m_metadata_ap.reset(new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001637 *m_metadata_ap = *metadata;
Jim Ingham379397632012-10-27 02:54:13 +00001638 }
1639 }
1640
1641 DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs)
1642 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001643 *this = rhs;
Daniel Malead4c5be62012-11-12 21:02:14 +00001644 }
1645
1646 DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs)
1647 {
Jim Ingham379397632012-10-27 02:54:13 +00001648 m_class_opaque_type = rhs.m_class_opaque_type;
1649 m_property_name = rhs.m_property_name;
1650 m_property_opaque_type = rhs.m_property_opaque_type;
1651 m_ivar_decl = rhs.m_ivar_decl;
1652 m_property_setter_name = rhs.m_property_setter_name;
1653 m_property_getter_name = rhs.m_property_getter_name;
1654 m_property_attributes = rhs.m_property_attributes;
1655
1656 if (rhs.m_metadata_ap.get())
1657 {
1658 m_metadata_ap.reset (new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001659 *m_metadata_ap = *rhs.m_metadata_ap;
Jim Ingham379397632012-10-27 02:54:13 +00001660 }
Daniel Malead4c5be62012-11-12 21:02:14 +00001661 return *this;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001662 }
1663
Greg Clayton57ee3062013-07-11 22:46:58 +00001664 bool
1665 Finalize()
Sean Callanana0b80ab2012-06-04 22:28:05 +00001666 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001667 return m_class_opaque_type.AddObjCClassProperty (m_property_name,
1668 m_property_opaque_type,
1669 m_ivar_decl,
1670 m_property_setter_name,
1671 m_property_getter_name,
1672 m_property_attributes,
1673 m_metadata_ap.get());
Sean Callanana0b80ab2012-06-04 22:28:05 +00001674 }
1675private:
Greg Clayton57ee3062013-07-11 22:46:58 +00001676 ClangASTType m_class_opaque_type;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001677 const char *m_property_name;
Greg Clayton57ee3062013-07-11 22:46:58 +00001678 ClangASTType m_property_opaque_type;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001679 clang::ObjCIvarDecl *m_ivar_decl;
1680 const char *m_property_setter_name;
1681 const char *m_property_getter_name;
1682 uint32_t m_property_attributes;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001683 std::unique_ptr<ClangASTMetadata> m_metadata_ap;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001684};
1685
Sean Callananfaa0bb32012-12-05 23:37:14 +00001686struct BitfieldInfo
1687{
1688 uint64_t bit_size;
1689 uint64_t bit_offset;
1690
1691 BitfieldInfo () :
1692 bit_size (LLDB_INVALID_ADDRESS),
1693 bit_offset (LLDB_INVALID_ADDRESS)
1694 {
1695 }
1696
Greg Clayton78f4d952013-12-11 23:10:39 +00001697 void
1698 Clear()
1699 {
1700 bit_size = LLDB_INVALID_ADDRESS;
1701 bit_offset = LLDB_INVALID_ADDRESS;
1702 }
1703
Sean Callananfaa0bb32012-12-05 23:37:14 +00001704 bool IsValid ()
1705 {
1706 return (bit_size != LLDB_INVALID_ADDRESS) &&
1707 (bit_offset != LLDB_INVALID_ADDRESS);
1708 }
1709};
1710
Greg Claytonc4ffd662013-03-08 01:37:30 +00001711
1712bool
1713SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu,
1714 const DWARFDebugInfoEntry *parent_die)
1715{
1716 if (parent_die)
1717 {
1718 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1719 {
1720 dw_tag_t tag = die->Tag();
1721 bool check_virtuality = false;
1722 switch (tag)
1723 {
1724 case DW_TAG_inheritance:
1725 case DW_TAG_subprogram:
1726 check_virtuality = true;
1727 break;
1728 default:
1729 break;
1730 }
1731 if (check_virtuality)
1732 {
1733 if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0)
1734 return true;
1735 }
1736 }
1737 }
1738 return false;
1739}
1740
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001741size_t
1742SymbolFileDWARF::ParseChildMembers
1743(
1744 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001745 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001746 const DWARFDebugInfoEntry *parent_die,
Greg Clayton57ee3062013-07-11 22:46:58 +00001747 ClangASTType &class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001748 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001749 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1750 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001751 DWARFDIECollection& member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001752 DelayedPropertyList& delayed_properties,
Sean Callananc7fbf732010-08-06 00:32:49 +00001753 AccessType& default_accessibility,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001754 bool &is_a_class,
1755 LayoutInfo &layout_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001756)
1757{
1758 if (parent_die == NULL)
1759 return 0;
1760
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001761 size_t count = 0;
1762 const DWARFDebugInfoEntry *die;
Todd Fialaee8bfc62014-09-11 17:29:12 +00001763 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001764 uint32_t member_idx = 0;
Sean Callananfaa0bb32012-12-05 23:37:14 +00001765 BitfieldInfo last_field_info;
Richard Mitton0a558352013-10-17 21:14:00 +00001766 ModuleSP module = GetObjectFile()->GetModule();
Greg Claytond88d7592010-09-15 08:33:30 +00001767
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001768 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1769 {
1770 dw_tag_t tag = die->Tag();
1771
1772 switch (tag)
1773 {
1774 case DW_TAG_member:
Sean Callanan3d654b32012-09-24 22:25:51 +00001775 case DW_TAG_APPLE_property:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001776 {
1777 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001778 const size_t num_attributes = die->GetAttributes (this,
1779 dwarf_cu,
1780 fixed_form_sizes,
1781 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001782 if (num_attributes > 0)
1783 {
1784 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001785 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001786 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001787 const char *prop_name = NULL;
1788 const char *prop_getter_name = NULL;
1789 const char *prop_setter_name = NULL;
Greg Claytone528efd72013-02-26 23:45:18 +00001790 uint32_t prop_attributes = 0;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001791
1792
Greg Clayton24739922010-10-13 03:15:28 +00001793 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001794 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001795 AccessType accessibility = eAccessNone;
Greg Claytoncaab74e2012-01-28 00:48:57 +00001796 uint32_t member_byte_offset = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001797 size_t byte_size = 0;
1798 size_t bit_offset = 0;
1799 size_t bit_size = 0;
Greg Claytone528efd72013-02-26 23:45:18 +00001800 bool is_external = false; // On DW_TAG_members, this means the member is static
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001801 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001802 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001803 {
1804 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1805 DWARFFormValue form_value;
1806 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1807 {
1808 switch (attr)
1809 {
1810 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1811 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1812 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1813 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00001814 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001815 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1816 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1817 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1818 case DW_AT_data_member_location:
Greg Claytoncaab74e2012-01-28 00:48:57 +00001819 if (form_value.BlockData())
1820 {
1821 Value initialValue(0);
1822 Value memberOffset(0);
Ed Masteeeae7212013-10-24 20:43:47 +00001823 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Claytoncaab74e2012-01-28 00:48:57 +00001824 uint32_t block_length = form_value.Unsigned();
1825 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1826 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
Greg Claytoncaab74e2012-01-28 00:48:57 +00001827 NULL, // ClangExpressionVariableList *
1828 NULL, // ClangExpressionDeclMap *
1829 NULL, // RegisterContext *
Richard Mitton0a558352013-10-17 21:14:00 +00001830 module,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001831 debug_info_data,
1832 block_offset,
1833 block_length,
1834 eRegisterKindDWARF,
1835 &initialValue,
1836 memberOffset,
1837 NULL))
1838 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001839 member_byte_offset = memberOffset.ResolveValue(NULL).UInt();
Greg Claytoncaab74e2012-01-28 00:48:57 +00001840 }
1841 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00001842 else
1843 {
1844 // With DWARF 3 and later, if the value is an integer constant,
1845 // this form value is the offset in bytes from the beginning
1846 // of the containing entity.
1847 member_byte_offset = form_value.Unsigned();
1848 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001849 break;
1850
Greg Clayton8cf05932010-07-22 18:30:50 +00001851 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00001852 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001853 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1854 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1855 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1856 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00001857 case DW_AT_external: is_external = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001858
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001859 default:
Greg Clayton1b02c172012-03-14 21:00:47 +00001860 case DW_AT_declaration:
1861 case DW_AT_description:
1862 case DW_AT_mutable:
1863 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001864 case DW_AT_sibling:
1865 break;
1866 }
1867 }
1868 }
Sean Callanana6582262012-04-05 00:12:52 +00001869
1870 if (prop_name)
Sean Callanan751aac62012-03-29 19:07:06 +00001871 {
Sean Callanana6582262012-04-05 00:12:52 +00001872 ConstString fixed_getter;
1873 ConstString fixed_setter;
1874
1875 // Check if the property getter/setter were provided as full
1876 // names. We want basenames, so we extract them.
1877
1878 if (prop_getter_name && prop_getter_name[0] == '-')
1879 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001880 ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true);
1881 prop_getter_name = prop_getter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001882 }
1883
1884 if (prop_setter_name && prop_setter_name[0] == '-')
1885 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001886 ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true);
1887 prop_setter_name = prop_setter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001888 }
1889
1890 // If the names haven't been provided, they need to be
1891 // filled in.
1892
1893 if (!prop_getter_name)
1894 {
1895 prop_getter_name = prop_name;
1896 }
1897 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly))
1898 {
1899 StreamString ss;
1900
1901 ss.Printf("set%c%s:",
1902 toupper(prop_name[0]),
1903 &prop_name[1]);
1904
1905 fixed_setter.SetCString(ss.GetData());
1906 prop_setter_name = fixed_setter.GetCString();
1907 }
Sean Callanan751aac62012-03-29 19:07:06 +00001908 }
1909
1910 // Clang has a DWARF generation bug where sometimes it
Greg Clayton44953932011-10-25 01:25:35 +00001911 // represents fields that are references with bad byte size
1912 // and bit size/offset information such as:
1913 //
1914 // DW_AT_byte_size( 0x00 )
1915 // DW_AT_bit_size( 0x40 )
1916 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1917 //
1918 // So check the bit offset to make sure it is sane, and if
1919 // the values are not sane, remove them. If we don't do this
1920 // then we will end up with a crash if we try to use this
1921 // type in an expression when clang becomes unhappy with its
1922 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001923
Greg Clayton44953932011-10-25 01:25:35 +00001924 if (bit_offset > 128)
1925 {
1926 bit_size = 0;
1927 bit_offset = 0;
1928 }
1929
1930 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00001931 if (class_language == eLanguageTypeObjC ||
1932 class_language == eLanguageTypeObjC_plus_plus)
1933 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001934
1935 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1936 {
1937 // Not all compilers will mark the vtable pointer
1938 // member as artificial (llvm-gcc). We can't have
1939 // the virtual members in our classes otherwise it
1940 // throws off all child offsets since we end up
1941 // having and extra pointer sized member in our
1942 // class layouts.
1943 is_artificial = true;
1944 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001945
Greg Clayton29659712013-07-12 20:08:35 +00001946 // Handle static members
Greg Claytone528efd72013-02-26 23:45:18 +00001947 if (is_external && member_byte_offset == UINT32_MAX)
Greg Clayton973b6c92013-04-11 16:57:51 +00001948 {
1949 Type *var_type = ResolveTypeUID(encoding_uid);
1950
1951 if (var_type)
1952 {
Greg Clayton29659712013-07-12 20:08:35 +00001953 if (accessibility == eAccessNone)
1954 accessibility = eAccessPublic;
Greg Clayton57ee3062013-07-11 22:46:58 +00001955 class_clang_type.AddVariableToRecordType (name,
1956 var_type->GetClangLayoutType(),
1957 accessibility);
Greg Clayton973b6c92013-04-11 16:57:51 +00001958 }
Greg Claytone528efd72013-02-26 23:45:18 +00001959 break;
Greg Clayton973b6c92013-04-11 16:57:51 +00001960 }
Greg Claytone528efd72013-02-26 23:45:18 +00001961
Greg Clayton24739922010-10-13 03:15:28 +00001962 if (is_artificial == false)
1963 {
1964 Type *member_type = ResolveTypeUID(encoding_uid);
Sean Callananfa3ab452012-12-14 00:54:13 +00001965
Jim Inghame3ae82a2011-11-12 01:36:43 +00001966 clang::FieldDecl *field_decl = NULL;
Sean Callanan751aac62012-03-29 19:07:06 +00001967 if (tag == DW_TAG_member)
Greg Claytond16e1e52011-07-12 17:06:17 +00001968 {
Sean Callanan751aac62012-03-29 19:07:06 +00001969 if (member_type)
1970 {
1971 if (accessibility == eAccessNone)
1972 accessibility = default_accessibility;
1973 member_accessibilities.push_back(accessibility);
Sean Callananfaa0bb32012-12-05 23:37:14 +00001974
Greg Clayton78f4d952013-12-11 23:10:39 +00001975 uint64_t field_bit_offset = (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
1976 if (bit_size > 0)
Greg Clayton88bc7f32012-11-06 00:20:41 +00001977 {
Greg Clayton78f4d952013-12-11 23:10:39 +00001978
1979 BitfieldInfo this_field_info;
1980 this_field_info.bit_offset = field_bit_offset;
1981 this_field_info.bit_size = bit_size;
1982
Sean Callananfaa0bb32012-12-05 23:37:14 +00001983 /////////////////////////////////////////////////////////////
1984 // How to locate a field given the DWARF debug information
1985 //
1986 // AT_byte_size indicates the size of the word in which the
1987 // bit offset must be interpreted.
1988 //
1989 // AT_data_member_location indicates the byte offset of the
1990 // word from the base address of the structure.
1991 //
1992 // AT_bit_offset indicates how many bits into the word
1993 // (according to the host endianness) the low-order bit of
1994 // the field starts. AT_bit_offset can be negative.
1995 //
1996 // AT_bit_size indicates the size of the field in bits.
1997 /////////////////////////////////////////////////////////////
1998
Greg Clayton78f4d952013-12-11 23:10:39 +00001999 if (byte_size == 0)
2000 byte_size = member_type->GetByteSize();
2001
Sean Callananfaa0bb32012-12-05 23:37:14 +00002002 if (GetObjectFile()->GetByteOrder() == eByteOrderLittle)
2003 {
2004 this_field_info.bit_offset += byte_size * 8;
2005 this_field_info.bit_offset -= (bit_offset + bit_size);
2006 }
2007 else
2008 {
2009 this_field_info.bit_offset += bit_offset;
2010 }
Greg Clayton78f4d952013-12-11 23:10:39 +00002011
2012 // Update the field bit offset we will report for layout
2013 field_bit_offset = this_field_info.bit_offset;
Sean Callananfaa0bb32012-12-05 23:37:14 +00002014
Greg Clayton78f4d952013-12-11 23:10:39 +00002015 // If the member to be emitted did not start on a character boundary and there is
2016 // empty space between the last field and this one, then we need to emit an
2017 // anonymous member filling up the space up to its start. There are three cases
2018 // here:
2019 //
2020 // 1 If the previous member ended on a character boundary, then we can emit an
2021 // anonymous member starting at the most recent character boundary.
2022 //
2023 // 2 If the previous member did not end on a character boundary and the distance
2024 // from the end of the previous member to the current member is less than a
2025 // word width, then we can emit an anonymous member starting right after the
2026 // previous member and right before this member.
2027 //
2028 // 3 If the previous member did not end on a character boundary and the distance
2029 // from the end of the previous member to the current member is greater than
2030 // or equal a word width, then we act as in Case 1.
2031
2032 const uint64_t character_width = 8;
2033 const uint64_t word_width = 32;
2034
Sean Callananfaa0bb32012-12-05 23:37:14 +00002035 // Objective-C has invalid DW_AT_bit_offset values in older versions
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +00002036 // of clang, so we have to be careful and only insert unnamed bitfields
Greg Clayton37c36e42012-11-27 00:59:26 +00002037 // if we have a new enough clang.
2038 bool detect_unnamed_bitfields = true;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002039
Greg Clayton37c36e42012-11-27 00:59:26 +00002040 if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus)
2041 detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields ();
2042
2043 if (detect_unnamed_bitfields)
Greg Clayton88bc7f32012-11-06 00:20:41 +00002044 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00002045 BitfieldInfo anon_field_info;
2046
2047 if ((this_field_info.bit_offset % character_width) != 0) // not char aligned
Greg Clayton88bc7f32012-11-06 00:20:41 +00002048 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00002049 uint64_t last_field_end = 0;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002050
Sean Callananfaa0bb32012-12-05 23:37:14 +00002051 if (last_field_info.IsValid())
2052 last_field_end = last_field_info.bit_offset + last_field_info.bit_size;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002053
Sean Callananfaa0bb32012-12-05 23:37:14 +00002054 if (this_field_info.bit_offset != last_field_end)
2055 {
2056 if (((last_field_end % character_width) == 0) || // case 1
2057 (this_field_info.bit_offset - last_field_end >= word_width)) // case 3
2058 {
2059 anon_field_info.bit_size = this_field_info.bit_offset % character_width;
2060 anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size;
2061 }
2062 else // case 2
2063 {
2064 anon_field_info.bit_size = this_field_info.bit_offset - last_field_end;
2065 anon_field_info.bit_offset = last_field_end;
2066 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00002067 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00002068 }
2069
Sean Callananfaa0bb32012-12-05 23:37:14 +00002070 if (anon_field_info.IsValid())
Greg Clayton88bc7f32012-11-06 00:20:41 +00002071 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002072 clang::FieldDecl *unnamed_bitfield_decl = class_clang_type.AddFieldToRecordType (NULL,
2073 GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width),
2074 accessibility,
2075 anon_field_info.bit_size);
Zachary Turner504f38d2015-03-24 16:24:50 +00002076
Zachary Turnera98fac22015-03-24 18:56:08 +00002077 layout_info.field_offsets.insert(
Zachary Turner504f38d2015-03-24 16:24:50 +00002078 std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset));
Greg Clayton88bc7f32012-11-06 00:20:41 +00002079 }
2080 }
Greg Clayton78f4d952013-12-11 23:10:39 +00002081 last_field_info = this_field_info;
2082 }
2083 else
2084 {
2085 last_field_info.Clear();
Greg Clayton88bc7f32012-11-06 00:20:41 +00002086 }
Sean Callananfaa0bb32012-12-05 23:37:14 +00002087
Greg Clayton57ee3062013-07-11 22:46:58 +00002088 ClangASTType member_clang_type = member_type->GetClangLayoutType();
Sean Callananfa3ab452012-12-14 00:54:13 +00002089
2090 {
2091 // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>).
2092 // If the current field is at the end of the structure, then there is definitely no room for extra
2093 // elements and we override the type to array[0].
2094
Greg Clayton57ee3062013-07-11 22:46:58 +00002095 ClangASTType member_array_element_type;
Sean Callananfa3ab452012-12-14 00:54:13 +00002096 uint64_t member_array_size;
2097 bool member_array_is_incomplete;
2098
Greg Clayton57ee3062013-07-11 22:46:58 +00002099 if (member_clang_type.IsArrayType(&member_array_element_type,
2100 &member_array_size,
2101 &member_array_is_incomplete) &&
Sean Callananfa3ab452012-12-14 00:54:13 +00002102 !member_array_is_incomplete)
2103 {
2104 uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX);
2105
2106 if (member_byte_offset >= parent_byte_size)
2107 {
2108 if (member_array_size != 1)
2109 {
2110 GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member '%s' refers to type 0x%8.8" PRIx64 " which extends beyond the bounds of 0x%8.8" PRIx64,
2111 MakeUserID(die->GetOffset()),
2112 name,
2113 encoding_uid,
2114 MakeUserID(parent_die->GetOffset()));
2115 }
2116
Greg Clayton1c8ef472013-04-05 23:27:21 +00002117 member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0, false);
Sean Callananfa3ab452012-12-14 00:54:13 +00002118 }
2119 }
2120 }
2121
Greg Clayton57ee3062013-07-11 22:46:58 +00002122 field_decl = class_clang_type.AddFieldToRecordType (name,
2123 member_clang_type,
2124 accessibility,
2125 bit_size);
Sean Callanan60217122012-04-13 00:10:03 +00002126
Greg Claytond0029442013-03-27 01:48:02 +00002127 GetClangASTContext().SetMetadataAsUserID (field_decl, MakeUserID(die->GetOffset()));
Greg Clayton78f4d952013-12-11 23:10:39 +00002128
Zachary Turnera98fac22015-03-24 18:56:08 +00002129 layout_info.field_offsets.insert(std::make_pair(field_decl, field_bit_offset));
Sean Callanan5b26f272012-02-04 08:49:35 +00002130 }
2131 else
2132 {
Sean Callanan751aac62012-03-29 19:07:06 +00002133 if (name)
Daniel Malead01b2952012-11-29 21:49:15 +00002134 GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member '%s' refers to type 0x%8.8" PRIx64 " which was unable to be parsed",
Sean Callanan751aac62012-03-29 19:07:06 +00002135 MakeUserID(die->GetOffset()),
2136 name,
2137 encoding_uid);
2138 else
Daniel Malead01b2952012-11-29 21:49:15 +00002139 GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member refers to type 0x%8.8" PRIx64 " which was unable to be parsed",
Sean Callanan751aac62012-03-29 19:07:06 +00002140 MakeUserID(die->GetOffset()),
2141 encoding_uid);
Sean Callanan5b26f272012-02-04 08:49:35 +00002142 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002143 }
Sean Callanan751aac62012-03-29 19:07:06 +00002144
Jim Inghame3ae82a2011-11-12 01:36:43 +00002145 if (prop_name != NULL)
2146 {
Sean Callanan751aac62012-03-29 19:07:06 +00002147 clang::ObjCIvarDecl *ivar_decl = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00002148
Sean Callanan751aac62012-03-29 19:07:06 +00002149 if (field_decl)
2150 {
2151 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
2152 assert (ivar_decl != NULL);
2153 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00002154
Jim Ingham379397632012-10-27 02:54:13 +00002155 ClangASTMetadata metadata;
2156 metadata.SetUserID (MakeUserID(die->GetOffset()));
Greg Clayton57ee3062013-07-11 22:46:58 +00002157 delayed_properties.push_back(DelayedAddObjCClassProperty(class_clang_type,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002158 prop_name,
2159 member_type->GetClangLayoutType(),
2160 ivar_decl,
2161 prop_setter_name,
2162 prop_getter_name,
2163 prop_attributes,
Jim Ingham379397632012-10-27 02:54:13 +00002164 &metadata));
Sean Callanan60217122012-04-13 00:10:03 +00002165
Sean Callananad880762012-04-18 01:06:17 +00002166 if (ivar_decl)
Greg Claytond0029442013-03-27 01:48:02 +00002167 GetClangASTContext().SetMetadataAsUserID (ivar_decl, MakeUserID(die->GetOffset()));
Jim Inghame3ae82a2011-11-12 01:36:43 +00002168 }
Greg Clayton24739922010-10-13 03:15:28 +00002169 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002170 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00002171 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002172 }
2173 break;
2174
2175 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00002176 // Let the type parsing code handle this one for us.
2177 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002178 break;
2179
2180 case DW_TAG_inheritance:
2181 {
2182 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00002183 if (default_accessibility == eAccessNone)
2184 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002185 // TODO: implement DW_TAG_inheritance type parsing
2186 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00002187 const size_t num_attributes = die->GetAttributes (this,
2188 dwarf_cu,
2189 fixed_form_sizes,
2190 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002191 if (num_attributes > 0)
2192 {
2193 Declaration decl;
2194 DWARFExpression location;
2195 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00002196 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002197 bool is_virtual = false;
2198 bool is_base_of_class = true;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002199 off_t member_byte_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002200 uint32_t i;
2201 for (i=0; i<num_attributes; ++i)
2202 {
2203 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2204 DWARFFormValue form_value;
2205 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2206 {
2207 switch (attr)
2208 {
2209 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2210 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2211 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00002212 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002213 case DW_AT_data_member_location:
2214 if (form_value.BlockData())
2215 {
2216 Value initialValue(0);
2217 Value memberOffset(0);
Ed Masteeeae7212013-10-24 20:43:47 +00002218 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002219 uint32_t block_length = form_value.Unsigned();
2220 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
2221 if (DWARFExpression::Evaluate (NULL,
2222 NULL,
2223 NULL,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002224 NULL,
Richard Mitton0a558352013-10-17 21:14:00 +00002225 module,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002226 debug_info_data,
2227 block_offset,
2228 block_length,
2229 eRegisterKindDWARF,
2230 &initialValue,
2231 memberOffset,
2232 NULL))
2233 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002234 member_byte_offset = memberOffset.ResolveValue(NULL).UInt();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002235 }
2236 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002237 else
2238 {
2239 // With DWARF 3 and later, if the value is an integer constant,
2240 // this form value is the offset in bytes from the beginning
2241 // of the containing entity.
2242 member_byte_offset = form_value.Unsigned();
2243 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002244 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002245
2246 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00002247 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002248 break;
2249
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002250 case DW_AT_virtuality:
2251 is_virtual = form_value.Boolean();
2252 break;
2253
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002254 case DW_AT_sibling:
2255 break;
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002256
2257 default:
2258 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002259 }
2260 }
2261 }
2262
Greg Clayton526e5af2010-11-13 03:52:47 +00002263 Type *base_class_type = ResolveTypeUID(encoding_uid);
2264 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002265
Greg Clayton57ee3062013-07-11 22:46:58 +00002266 ClangASTType base_class_clang_type = base_class_type->GetClangFullType();
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002267 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002268 if (class_language == eLanguageTypeObjC)
2269 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002270 class_clang_type.SetObjCSuperClass(base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002271 }
2272 else
2273 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002274 base_classes.push_back (base_class_clang_type.CreateBaseClassSpecifier (accessibility,
Greg Claytonba2d22d2010-11-13 22:57:37 +00002275 is_virtual,
2276 is_base_of_class));
Greg Clayton2508b9b2012-11-01 23:20:02 +00002277
2278 if (is_virtual)
2279 {
Greg Clayton52694e32013-09-16 21:57:07 +00002280 // Do not specify any offset for virtual inheritance. The DWARF produced by clang doesn't
2281 // give us a constant offset, but gives us a DWARF expressions that requires an actual object
2282 // in memory. the DW_AT_data_member_location for a virtual base class looks like:
2283 // DW_AT_data_member_location( DW_OP_dup, DW_OP_deref, DW_OP_constu(0x00000018), DW_OP_minus, DW_OP_deref, DW_OP_plus )
2284 // Given this, there is really no valid response we can give to clang for virtual base
2285 // class offsets, and this should eventually be removed from LayoutRecordType() in the external
2286 // AST source in clang.
Greg Clayton2508b9b2012-11-01 23:20:02 +00002287 }
2288 else
2289 {
Zachary Turnera98fac22015-03-24 18:56:08 +00002290 layout_info.base_offsets.insert(
Zachary Turner504f38d2015-03-24 16:24:50 +00002291 std::make_pair(base_class_clang_type.GetAsCXXRecordDecl(),
2292 clang::CharUnits::fromQuantity(member_byte_offset)));
Greg Clayton2508b9b2012-11-01 23:20:02 +00002293 }
Greg Clayton9e409562010-07-28 02:04:09 +00002294 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002295 }
2296 }
2297 break;
2298
2299 default:
2300 break;
2301 }
2302 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002303
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002304 return count;
2305}
2306
2307
2308clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00002309SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002310{
2311 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00002312 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002313 {
2314 DWARFCompileUnitSP cu_sp;
2315 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
2316 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00002317 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00002318 }
2319 return NULL;
2320}
2321
2322clang::DeclContext*
2323SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
2324{
Greg Clayton81c22f62011-10-19 18:09:39 +00002325 if (UserIDMatches(type_uid))
2326 return GetClangDeclContextForDIEOffset (sc, type_uid);
2327 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002328}
2329
2330Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00002331SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002332{
Greg Clayton81c22f62011-10-19 18:09:39 +00002333 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002334 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002335 DWARFDebugInfo* debug_info = DebugInfo();
2336 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00002337 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002338 DWARFCompileUnitSP cu_sp;
2339 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00002340 const bool assert_not_being_parsed = true;
2341 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00002342 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002343 }
2344 return NULL;
2345}
2346
Greg Claytoncab36a32011-12-08 05:16:30 +00002347Type*
2348SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00002349{
Greg Claytoncab36a32011-12-08 05:16:30 +00002350 if (die != NULL)
2351 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002352 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00002353 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002354 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002355 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
2356 die->GetOffset(),
2357 DW_TAG_value_to_name(die->Tag()),
2358 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00002359
Greg Claytoncab36a32011-12-08 05:16:30 +00002360 // We might be coming in in the middle of a type tree (a class
2361 // withing a class, an enum within a class), so parse any needed
2362 // parent DIEs before we get to this one...
2363 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2364 switch (decl_ctx_die->Tag())
2365 {
2366 case DW_TAG_structure_type:
2367 case DW_TAG_union_type:
2368 case DW_TAG_class_type:
2369 {
2370 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00002371 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002372 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002373 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
2374 die->GetOffset(),
2375 DW_TAG_value_to_name(die->Tag()),
2376 die->GetName(this, cu),
2377 decl_ctx_die->GetOffset());
Greg Clayton219cf312012-03-30 00:51:13 +00002378//
2379// Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
2380// if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
2381// {
2382// if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002383// GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton219cf312012-03-30 00:51:13 +00002384// "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
2385// die->GetOffset(),
2386// DW_TAG_value_to_name(die->Tag()),
2387// die->GetName(this, cu),
2388// decl_ctx_die->GetOffset());
2389// // Ask the type to complete itself if it already hasn't since if we
2390// // want a function (method or static) from a class, the class must
2391// // create itself and add it's own methods and class functions.
2392// if (parent_type)
2393// parent_type->GetClangFullType();
2394// }
Greg Claytoncab36a32011-12-08 05:16:30 +00002395 }
2396 break;
2397
2398 default:
2399 break;
2400 }
2401 return ResolveType (cu, die);
2402 }
2403 return NULL;
2404}
2405
Greg Clayton6beaaa62011-01-17 03:46:26 +00002406// This function is used when SymbolFileDWARFDebugMap owns a bunch of
2407// SymbolFileDWARF objects to detect if this DWARF file is the one that
2408// can resolve a clang_type.
2409bool
Greg Clayton57ee3062013-07-11 22:46:58 +00002410SymbolFileDWARF::HasForwardDeclForClangType (const ClangASTType &clang_type)
Greg Clayton6beaaa62011-01-17 03:46:26 +00002411{
Greg Clayton57ee3062013-07-11 22:46:58 +00002412 ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers();
2413 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton6beaaa62011-01-17 03:46:26 +00002414 return die != NULL;
2415}
2416
2417
Greg Clayton57ee3062013-07-11 22:46:58 +00002418bool
2419SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (ClangASTType &clang_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00002420{
2421 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton57ee3062013-07-11 22:46:58 +00002422 ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers();
2423 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton1be10fc2010-09-29 01:12:09 +00002424 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00002425 {
2426 // We have already resolved this type...
Greg Clayton57ee3062013-07-11 22:46:58 +00002427 return true;
Greg Clayton73b472d2010-10-27 03:32:59 +00002428 }
2429 // Once we start resolving this type, remove it from the forward declaration
2430 // map in case anyone child members or other types require this type to get resolved.
2431 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
2432 // are done.
Greg Clayton57ee3062013-07-11 22:46:58 +00002433 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton1be10fc2010-09-29 01:12:09 +00002434
Greg Clayton85ae2e12011-10-18 23:36:41 +00002435 // Disable external storage for this type so we don't get anymore
2436 // clang::ExternalASTSource queries for this type.
Greg Clayton57ee3062013-07-11 22:46:58 +00002437 clang_type.SetHasExternalStorage (false);
Greg Clayton85ae2e12011-10-18 23:36:41 +00002438
Greg Clayton450e3f32010-10-12 02:24:53 +00002439 DWARFDebugInfo* debug_info = DebugInfo();
2440
Greg Clayton53eb1c22012-04-02 22:59:12 +00002441 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002442 Type *type = m_die_to_type.lookup (die);
2443
2444 const dw_tag_t tag = die->Tag();
2445
Greg Clayton5160ce52013-03-27 23:08:40 +00002446 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
Greg Clayton3bffb082011-12-10 02:15:28 +00002447 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002448 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002449 "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...",
Greg Claytond61c0fc2012-04-23 22:55:20 +00002450 MakeUserID(die->GetOffset()),
2451 DW_TAG_value_to_name(tag),
2452 type->GetName().AsCString());
Greg Clayton1be10fc2010-09-29 01:12:09 +00002453 assert (clang_type);
2454 DWARFDebugInfoEntry::Attributes attributes;
2455
Greg Clayton1be10fc2010-09-29 01:12:09 +00002456 switch (tag)
2457 {
2458 case DW_TAG_structure_type:
2459 case DW_TAG_union_type:
2460 case DW_TAG_class_type:
Greg Claytonc93237c2010-10-01 20:48:32 +00002461 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002462 LayoutInfo layout_info;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002463
Greg Clayton1be10fc2010-09-29 01:12:09 +00002464 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002465 if (die->HasChildren())
Greg Claytonc93237c2010-10-01 20:48:32 +00002466 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002467 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton57ee3062013-07-11 22:46:58 +00002468 if (clang_type.IsObjCObjectOrInterfaceType())
Greg Clayton219cf312012-03-30 00:51:13 +00002469 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002470 class_language = eLanguageTypeObjC;
Greg Clayton219cf312012-03-30 00:51:13 +00002471 // For objective C we don't start the definition when
2472 // the class is created.
Greg Clayton57ee3062013-07-11 22:46:58 +00002473 clang_type.StartTagDeclarationDefinition ();
Greg Clayton219cf312012-03-30 00:51:13 +00002474 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002475
Sean Callanan77a1fd32012-02-27 20:07:01 +00002476 int tag_decl_kind = -1;
2477 AccessType default_accessibility = eAccessNone;
2478 if (tag == DW_TAG_structure_type)
2479 {
2480 tag_decl_kind = clang::TTK_Struct;
2481 default_accessibility = eAccessPublic;
2482 }
2483 else if (tag == DW_TAG_union_type)
2484 {
2485 tag_decl_kind = clang::TTK_Union;
2486 default_accessibility = eAccessPublic;
2487 }
2488 else if (tag == DW_TAG_class_type)
2489 {
2490 tag_decl_kind = clang::TTK_Class;
2491 default_accessibility = eAccessPrivate;
2492 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002493
Greg Clayton53eb1c22012-04-02 22:59:12 +00002494 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002495 std::vector<clang::CXXBaseSpecifier *> base_classes;
2496 std::vector<int> member_accessibilities;
2497 bool is_a_class = false;
2498 // Parse members and base classes first
2499 DWARFDIECollection member_function_dies;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002500
Sean Callanana0b80ab2012-06-04 22:28:05 +00002501 DelayedPropertyList delayed_properties;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002502 ParseChildMembers (sc,
Greg Clayton53eb1c22012-04-02 22:59:12 +00002503 dwarf_cu,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002504 die,
2505 clang_type,
2506 class_language,
2507 base_classes,
2508 member_accessibilities,
2509 member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002510 delayed_properties,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002511 default_accessibility,
2512 is_a_class,
2513 layout_info);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002514
Sean Callanan77a1fd32012-02-27 20:07:01 +00002515 // Now parse any methods if there were any...
2516 size_t num_functions = member_function_dies.Size();
2517 if (num_functions > 0)
2518 {
2519 for (size_t i=0; i<num_functions; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002520 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002521 ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytoncaab74e2012-01-28 00:48:57 +00002522 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002523 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002524
Sean Callanan77a1fd32012-02-27 20:07:01 +00002525 if (class_language == eLanguageTypeObjC)
2526 {
Jim Inghamfb6fc0d2013-09-27 20:59:37 +00002527 ConstString class_name (clang_type.GetTypeName());
2528 if (class_name)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002529 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002530 DIEArray method_die_offsets;
2531 if (m_using_apple_tables)
Greg Clayton95d87902011-11-11 03:16:25 +00002532 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002533 if (m_apple_objc_ap.get())
Jim Inghamfb6fc0d2013-09-27 20:59:37 +00002534 m_apple_objc_ap->FindByName(class_name.GetCString(), method_die_offsets);
Sean Callanan77a1fd32012-02-27 20:07:01 +00002535 }
2536 else
2537 {
2538 if (!m_indexed)
2539 Index ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002540
Sean Callanan77a1fd32012-02-27 20:07:01 +00002541 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
2542 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002543
Sean Callanan77a1fd32012-02-27 20:07:01 +00002544 if (!method_die_offsets.empty())
2545 {
2546 DWARFDebugInfo* debug_info = DebugInfo();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002547
Sean Callanan77a1fd32012-02-27 20:07:01 +00002548 DWARFCompileUnit* method_cu = NULL;
2549 const size_t num_matches = method_die_offsets.size();
2550 for (size_t i=0; i<num_matches; ++i)
Greg Clayton95d87902011-11-11 03:16:25 +00002551 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002552 const dw_offset_t die_offset = method_die_offsets[i];
2553 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002554
Sean Callanan77a1fd32012-02-27 20:07:01 +00002555 if (method_die)
2556 ResolveType (method_cu, method_die);
2557 else
Greg Claytoncaab74e2012-01-28 00:48:57 +00002558 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002559 if (m_using_apple_tables)
2560 {
2561 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n",
Jim Inghamfb6fc0d2013-09-27 20:59:37 +00002562 die_offset, class_name.GetCString());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002563 }
2564 }
2565 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002566 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002567
Greg Clayton57ee3062013-07-11 22:46:58 +00002568 for (DelayedPropertyList::iterator pi = delayed_properties.begin(), pe = delayed_properties.end();
Sean Callanana0b80ab2012-06-04 22:28:05 +00002569 pi != pe;
2570 ++pi)
2571 pi->Finalize();
Greg Clayton450e3f32010-10-12 02:24:53 +00002572 }
2573 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002574
Sean Callanan77a1fd32012-02-27 20:07:01 +00002575 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2576 // need to tell the clang type it is actually a class.
2577 if (class_language != eLanguageTypeObjC)
2578 {
2579 if (is_a_class && tag_decl_kind != clang::TTK_Class)
Greg Clayton57ee3062013-07-11 22:46:58 +00002580 clang_type.SetTagTypeKind (clang::TTK_Class);
Sean Callanan77a1fd32012-02-27 20:07:01 +00002581 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002582
Sean Callanan77a1fd32012-02-27 20:07:01 +00002583 // Since DW_TAG_structure_type gets used for both classes
2584 // and structures, we may need to set any DW_TAG_member
2585 // fields to have a "private" access if none was specified.
2586 // When we parsed the child members we tracked that actual
2587 // accessibility value for each DW_TAG_member in the
2588 // "member_accessibilities" array. If the value for the
2589 // member is zero, then it was set to the "default_accessibility"
2590 // which for structs was "public". Below we correct this
2591 // by setting any fields to "private" that weren't correctly
2592 // set.
2593 if (is_a_class && !member_accessibilities.empty())
2594 {
2595 // This is a class and all members that didn't have
2596 // their access specified are private.
Greg Clayton57ee3062013-07-11 22:46:58 +00002597 clang_type.SetDefaultAccessForRecordFields (eAccessPrivate,
2598 &member_accessibilities.front(),
2599 member_accessibilities.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002600 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002601
Sean Callanan77a1fd32012-02-27 20:07:01 +00002602 if (!base_classes.empty())
2603 {
Greg Clayton4705f8d2013-12-12 01:54:04 +00002604 // Make sure all base classes refer to complete types and not
2605 // forward declarations. If we don't do this, clang will crash
2606 // with an assertion in the call to clang_type.SetBaseClassesForClassType()
2607 bool base_class_error = false;
2608 for (auto &base_class : base_classes)
2609 {
2610 clang::TypeSourceInfo *type_source_info = base_class->getTypeSourceInfo();
2611 if (type_source_info)
2612 {
2613 ClangASTType base_class_type (GetClangASTContext().getASTContext(), type_source_info->getType());
2614 if (base_class_type.GetCompleteType() == false)
2615 {
2616 if (!base_class_error)
2617 {
2618 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",
2619 die->GetOffset(),
2620 die->GetName(this, dwarf_cu),
2621 base_class_type.GetTypeName().GetCString(),
2622 sc.comp_unit ? sc.comp_unit->GetPath().c_str() : "the source file");
2623 }
2624 // We have no choice other than to pretend that the base class
2625 // is complete. If we don't do this, clang will crash when we
2626 // call setBases() inside of "clang_type.SetBaseClassesForClassType()"
2627 // below. Since we provide layout assistance, all ivars in this
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00002628 // class and other classes will be fine, this is the best we can do
Greg Clayton4705f8d2013-12-12 01:54:04 +00002629 // short of crashing.
2630 base_class_type.StartTagDeclarationDefinition ();
2631 base_class_type.CompleteTagDeclarationDefinition ();
2632 }
2633 }
2634 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002635 clang_type.SetBaseClassesForClassType (&base_classes.front(),
2636 base_classes.size());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002637
Sean Callanan77a1fd32012-02-27 20:07:01 +00002638 // Clang will copy each CXXBaseSpecifier in "base_classes"
2639 // so we have to free them all.
Greg Clayton57ee3062013-07-11 22:46:58 +00002640 ClangASTType::DeleteBaseClassSpecifiers (&base_classes.front(),
2641 base_classes.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002642 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002643 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002644 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002645
Greg Clayton57ee3062013-07-11 22:46:58 +00002646 clang_type.BuildIndirectFields ();
2647 clang_type.CompleteTagDeclarationDefinition ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002648
Greg Clayton2508b9b2012-11-01 23:20:02 +00002649 if (!layout_info.field_offsets.empty() ||
2650 !layout_info.base_offsets.empty() ||
2651 !layout_info.vbase_offsets.empty() )
Greg Claytoncaab74e2012-01-28 00:48:57 +00002652 {
2653 if (type)
2654 layout_info.bit_size = type->GetByteSize() * 8;
2655 if (layout_info.bit_size == 0)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002656 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002657
Greg Clayton57ee3062013-07-11 22:46:58 +00002658 clang::CXXRecordDecl *record_decl = clang_type.GetAsCXXRecordDecl();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002659 if (record_decl)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002660 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002661 if (log)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002662 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002663 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002664 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) caching layout info for record_decl = %p, bit_size = %" PRIu64 ", alignment = %" PRIu64 ", field_offsets[%u], base_offsets[%u], vbase_offsets[%u])",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002665 static_cast<void*>(clang_type.GetOpaqueQualType()),
2666 static_cast<void*>(record_decl),
Greg Claytoncaab74e2012-01-28 00:48:57 +00002667 layout_info.bit_size,
2668 layout_info.alignment,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002669 static_cast<uint32_t>(layout_info.field_offsets.size()),
2670 static_cast<uint32_t>(layout_info.base_offsets.size()),
2671 static_cast<uint32_t>(layout_info.vbase_offsets.size()));
2672
Zachary Turnera98fac22015-03-24 18:56:08 +00002673 uint32_t idx;
2674 {
2675 llvm::DenseMap<const clang::FieldDecl *, uint64_t>::const_iterator pos,
2676 end = layout_info.field_offsets.end();
2677 for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx)
Greg Clayton2508b9b2012-11-01 23:20:02 +00002678 {
Zachary Turner504f38d2015-03-24 16:24:50 +00002679 GetObjectFile()->GetModule()->LogMessage(
2680 log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = "
2681 "{ bit_offset=%u, name='%s' }",
Zachary Turner504f38d2015-03-24 16:24:50 +00002682 static_cast<void *>(clang_type.GetOpaqueQualType()), idx,
Zachary Turnera98fac22015-03-24 18:56:08 +00002683 static_cast<uint32_t>(pos->second), pos->first->getNameAsString().c_str());
2684 }
2685 }
2686
2687 {
2688 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos,
2689 base_end = layout_info.base_offsets.end();
2690 for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end;
2691 ++base_pos, ++idx)
2692 {
2693 GetObjectFile()->GetModule()->LogMessage(
2694 log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] "
2695 "= { byte_offset=%u, name='%s' }",
2696 clang_type.GetOpaqueQualType(), idx, (uint32_t)base_pos->second.getQuantity(),
2697 base_pos->first->getNameAsString().c_str());
2698 }
2699 }
2700 {
2701 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos,
2702 vbase_end = layout_info.vbase_offsets.end();
2703 for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end;
2704 ++vbase_pos, ++idx)
2705 {
2706 GetObjectFile()->GetModule()->LogMessage(
2707 log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) "
2708 "vbase[%u] = { byte_offset=%u, name='%s' }",
2709 static_cast<void *>(clang_type.GetOpaqueQualType()), idx,
2710 static_cast<uint32_t>(vbase_pos->second.getQuantity()),
2711 vbase_pos->first->getNameAsString().c_str());
2712 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002713 }
Greg Clayton821ac6d2012-01-28 02:22:27 +00002714 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002715 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2716 }
2717 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002718 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002719
Sean Callanan9076c0f2013-10-04 21:35:29 +00002720 return (bool)clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002721
2722 case DW_TAG_enumeration_type:
Greg Clayton57ee3062013-07-11 22:46:58 +00002723 clang_type.StartTagDeclarationDefinition ();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002724 if (die->HasChildren())
2725 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002726 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00002727 bool is_signed = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00002728 clang_type.IsIntegerType(is_signed);
Greg Clayton3e067532013-03-05 23:54:39 +00002729 ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002730 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002731 clang_type.CompleteTagDeclarationDefinition ();
Sean Callanan9076c0f2013-10-04 21:35:29 +00002732 return (bool)clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002733
2734 default:
2735 assert(false && "not a forward clang type decl!");
2736 break;
2737 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002738 return false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002739}
2740
Greg Claytonc685f8e2010-09-15 04:15:46 +00002741Type*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002742SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002743{
2744 if (type_die != NULL)
2745 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002746 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00002747
Greg Claytonc685f8e2010-09-15 04:15:46 +00002748 if (type == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002749 type = GetTypeForDIE (dwarf_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00002750
Greg Clayton24739922010-10-13 03:15:28 +00002751 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00002752 {
2753 if (type != DIE_IS_BEING_PARSED)
2754 return type;
2755
2756 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
Greg Clayton53eb1c22012-04-02 22:59:12 +00002757 type_die->GetOffset(),
2758 DW_TAG_value_to_name(type_die->Tag()),
2759 type_die->GetName(this, dwarf_cu));
Jim Inghamc3549282012-01-11 02:21:12 +00002760
2761 }
2762 else
2763 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002764 }
2765 return NULL;
2766}
2767
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002768CompileUnit*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002769SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002770{
2771 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002772 if (dwarf_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002773 {
2774 // The symbol vendor doesn't know about this compile unit, we
2775 // need to parse and add it to the symbol vendor object.
Greg Clayton53eb1c22012-04-02 22:59:12 +00002776 return ParseCompileUnit(dwarf_cu, cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002777 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00002778 return (CompileUnit*)dwarf_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002779}
2780
2781bool
Greg Clayton53eb1c22012-04-02 22:59:12 +00002782SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002783{
Greg Clayton72310352013-02-23 04:12:47 +00002784 sc.Clear(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002785 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002786 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002787
Greg Clayton81c22f62011-10-19 18:09:39 +00002788 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002789 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002790 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002791
2792 if (sc.function)
2793 {
Greg Claytone72dfb32012-02-24 01:59:29 +00002794 sc.module_sp = sc.function->CalculateSymbolContextModule();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002795 return true;
2796 }
2797
2798 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002799}
2800
Greg Clayton2501e5e2015-01-15 02:59:20 +00002801
2802
2803SymbolFileDWARF::GlobalVariableMap &
2804SymbolFileDWARF::GetGlobalAranges()
2805{
2806 if (!m_global_aranges_ap)
2807 {
2808 m_global_aranges_ap.reset (new GlobalVariableMap());
2809
2810 ModuleSP module_sp = GetObjectFile()->GetModule();
2811 if (module_sp)
2812 {
2813 const size_t num_cus = module_sp->GetNumCompileUnits();
2814 for (size_t i = 0; i < num_cus; ++i)
2815 {
2816 CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(i);
2817 if (cu_sp)
2818 {
2819 VariableListSP globals_sp = cu_sp->GetVariableList(true);
2820 if (globals_sp)
2821 {
2822 const size_t num_globals = globals_sp->GetSize();
2823 for (size_t g = 0; g < num_globals; ++g)
2824 {
2825 VariableSP var_sp = globals_sp->GetVariableAtIndex(g);
2826 if (var_sp && !var_sp->GetLocationIsConstantValueData())
2827 {
2828 const DWARFExpression &location = var_sp->LocationExpression();
2829 Value location_result;
2830 Error error;
2831 if (location.Evaluate(NULL, NULL, NULL, LLDB_INVALID_ADDRESS, NULL, location_result, &error))
2832 {
2833 if (location_result.GetValueType() == Value::eValueTypeFileAddress)
2834 {
2835 lldb::addr_t file_addr = location_result.GetScalar().ULongLong();
2836 lldb::addr_t byte_size = 1;
2837 if (var_sp->GetType())
2838 byte_size = var_sp->GetType()->GetByteSize();
2839 m_global_aranges_ap->Append(GlobalVariableMap::Entry(file_addr, byte_size, var_sp.get()));
2840 }
2841 }
2842 }
2843 }
2844 }
2845 }
2846 }
2847 }
2848 m_global_aranges_ap->Sort();
2849 }
2850 return *m_global_aranges_ap;
2851}
2852
2853
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002854uint32_t
2855SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2856{
2857 Timer scoped_timer(__PRETTY_FUNCTION__,
Daniel Malead01b2952012-11-29 21:49:15 +00002858 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002859 static_cast<void*>(so_addr.GetSection().get()),
2860 so_addr.GetOffset(), resolve_scope);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002861 uint32_t resolved = 0;
Greg Clayton2501e5e2015-01-15 02:59:20 +00002862 if (resolve_scope & ( eSymbolContextCompUnit |
2863 eSymbolContextFunction |
2864 eSymbolContextBlock |
2865 eSymbolContextLineEntry |
2866 eSymbolContextVariable ))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002867 {
2868 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2869
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002870 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00002871 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002872 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002873 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Greg Clayton2501e5e2015-01-15 02:59:20 +00002874 if (cu_offset == DW_INVALID_OFFSET)
2875 {
2876 // Global variables are not in the compile unit address ranges. The only way to
2877 // currently find global variables is to iterate over the .debug_pubnames or the
2878 // __apple_names table and find all items in there that point to DW_TAG_variable
2879 // DIEs and then find the address that matches.
2880 if (resolve_scope & eSymbolContextVariable)
2881 {
2882 GlobalVariableMap &map = GetGlobalAranges();
2883 const GlobalVariableMap::Entry *entry = map.FindEntryThatContains(file_vm_addr);
2884 if (entry && entry->data)
2885 {
2886 Variable *variable = entry->data;
2887 SymbolContextScope *scc = variable->GetSymbolContextScope();
2888 if (scc)
2889 {
2890 scc->CalculateSymbolContext(&sc);
2891 sc.variable = variable;
2892 }
2893 return sc.GetResolvedMask();
2894 }
2895 }
2896 }
2897 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002898 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002899 uint32_t cu_idx = DW_INVALID_INDEX;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002900 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
2901 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002902 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002903 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002904 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002905 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002906 resolved |= eSymbolContextCompUnit;
2907
Greg Clayton6ab80132012-12-12 17:30:52 +00002908 bool force_check_line_table = false;
Greg Clayton526a4ae2012-05-16 22:09:01 +00002909 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2910 {
2911 DWARFDebugInfoEntry *function_die = NULL;
2912 DWARFDebugInfoEntry *block_die = NULL;
2913 if (resolve_scope & eSymbolContextBlock)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002914 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002915 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
2916 }
2917 else
2918 {
2919 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL);
2920 }
2921
2922 if (function_die != NULL)
2923 {
2924 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2925 if (sc.function == NULL)
2926 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2927 }
2928 else
2929 {
2930 // We might have had a compile unit that had discontiguous
2931 // address ranges where the gaps are symbols that don't have
2932 // any debug info. Discontiguous compile unit address ranges
2933 // should only happen when there aren't other functions from
2934 // other compile units in these gaps. This helps keep the size
2935 // of the aranges down.
Greg Clayton6ab80132012-12-12 17:30:52 +00002936 force_check_line_table = true;
Greg Clayton526a4ae2012-05-16 22:09:01 +00002937 }
2938
2939 if (sc.function != NULL)
2940 {
2941 resolved |= eSymbolContextFunction;
2942
2943 if (resolve_scope & eSymbolContextBlock)
2944 {
2945 Block& block = sc.function->GetBlock (true);
2946
2947 if (block_die != NULL)
2948 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2949 else
2950 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2951 if (sc.block)
2952 resolved |= eSymbolContextBlock;
2953 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002954 }
2955 }
Greg Clayton6ab80132012-12-12 17:30:52 +00002956
2957 if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table)
2958 {
2959 LineTable *line_table = sc.comp_unit->GetLineTable();
2960 if (line_table != NULL)
2961 {
Greg Clayton9422dd62013-03-04 21:46:16 +00002962 // And address that makes it into this function should be in terms
2963 // of this debug file if there is no debug map, or it will be an
2964 // address in the .o file which needs to be fixed up to be in terms
2965 // of the debug map executable. Either way, calling FixupAddress()
2966 // will work for us.
2967 Address exe_so_addr (so_addr);
2968 if (FixupAddress(exe_so_addr))
Greg Clayton6ab80132012-12-12 17:30:52 +00002969 {
Greg Clayton9422dd62013-03-04 21:46:16 +00002970 if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry))
Greg Clayton6ab80132012-12-12 17:30:52 +00002971 {
2972 resolved |= eSymbolContextLineEntry;
2973 }
2974 }
Greg Clayton6ab80132012-12-12 17:30:52 +00002975 }
2976 }
2977
2978 if (force_check_line_table && !(resolved & eSymbolContextLineEntry))
2979 {
2980 // We might have had a compile unit that had discontiguous
2981 // address ranges where the gaps are symbols that don't have
2982 // any debug info. Discontiguous compile unit address ranges
2983 // should only happen when there aren't other functions from
2984 // other compile units in these gaps. This helps keep the size
2985 // of the aranges down.
2986 sc.comp_unit = NULL;
2987 resolved &= ~eSymbolContextCompUnit;
2988 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002989 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002990 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002991 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002992 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.",
2993 cu_offset,
2994 cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002995 }
2996 }
2997 }
2998 }
2999 }
3000 return resolved;
3001}
3002
3003
3004
3005uint32_t
3006SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
3007{
3008 const uint32_t prev_size = sc_list.GetSize();
3009 if (resolve_scope & eSymbolContextCompUnit)
3010 {
3011 DWARFDebugInfo* debug_info = DebugInfo();
3012 if (debug_info)
3013 {
3014 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00003015 DWARFCompileUnit* dwarf_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003016
Greg Clayton53eb1c22012-04-02 22:59:12 +00003017 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003018 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003019 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Sean Callananddd7a2a2013-10-03 22:27:29 +00003020 const bool full_match = (bool)file_spec.GetDirectory();
Greg Clayton1f746072012-08-29 21:13:06 +00003021 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Equal(file_spec, *dc_cu, full_match);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003022 if (check_inlines || file_spec_matches_cu_file_spec)
3023 {
3024 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton53eb1c22012-04-02 22:59:12 +00003025 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00003026 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003027 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003028 uint32_t file_idx = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003029
Greg Clayton526a4ae2012-05-16 22:09:01 +00003030 // If we are looking for inline functions only and we don't
3031 // find it in the support files, we are done.
3032 if (check_inlines)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003033 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003034 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
3035 if (file_idx == UINT32_MAX)
3036 continue;
3037 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003038
Greg Clayton526a4ae2012-05-16 22:09:01 +00003039 if (line != 0)
3040 {
3041 LineTable *line_table = sc.comp_unit->GetLineTable();
3042
3043 if (line_table != NULL && line != 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003044 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003045 // We will have already looked up the file index if
3046 // we are searching for inline entries.
3047 if (!check_inlines)
3048 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003049
Greg Clayton526a4ae2012-05-16 22:09:01 +00003050 if (file_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003051 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003052 uint32_t found_line;
3053 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
3054 found_line = sc.line_entry.line;
3055
3056 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003057 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003058 sc.function = NULL;
3059 sc.block = NULL;
3060 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003061 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003062 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
3063 if (file_vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003064 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003065 DWARFDebugInfoEntry *function_die = NULL;
3066 DWARFDebugInfoEntry *block_die = NULL;
3067 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003068
Greg Clayton526a4ae2012-05-16 22:09:01 +00003069 if (function_die != NULL)
3070 {
3071 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
3072 if (sc.function == NULL)
3073 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
3074 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003075
Greg Clayton526a4ae2012-05-16 22:09:01 +00003076 if (sc.function != NULL)
3077 {
3078 Block& block = sc.function->GetBlock (true);
3079
3080 if (block_die != NULL)
3081 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
Jason Molenda60db6e42014-10-16 01:40:16 +00003082 else if (function_die != NULL)
Greg Clayton526a4ae2012-05-16 22:09:01 +00003083 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
3084 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003085 }
3086 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003087
Greg Clayton526a4ae2012-05-16 22:09:01 +00003088 sc_list.Append(sc);
3089 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
3090 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003091 }
3092 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00003093 else if (file_spec_matches_cu_file_spec && !check_inlines)
3094 {
3095 // only append the context if we aren't looking for inline call sites
3096 // by file and line and if the file spec matches that of the compile unit
3097 sc_list.Append(sc);
3098 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003099 }
3100 else if (file_spec_matches_cu_file_spec && !check_inlines)
3101 {
3102 // only append the context if we aren't looking for inline call sites
3103 // by file and line and if the file spec matches that of the compile unit
3104 sc_list.Append(sc);
3105 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003106
Greg Clayton526a4ae2012-05-16 22:09:01 +00003107 if (!check_inlines)
3108 break;
3109 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003110 }
3111 }
3112 }
3113 }
3114 return sc_list.GetSize() - prev_size;
3115}
3116
3117void
3118SymbolFileDWARF::Index ()
3119{
3120 if (m_indexed)
3121 return;
3122 m_indexed = true;
3123 Timer scoped_timer (__PRETTY_FUNCTION__,
3124 "SymbolFileDWARF::Index (%s)",
Jim Ingham4af59612014-12-19 19:20:44 +00003125 GetObjectFile()->GetFileSpec().GetFilename().AsCString("<Unknown>"));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003126
3127 DWARFDebugInfo* debug_info = DebugInfo();
3128 if (debug_info)
3129 {
3130 uint32_t cu_idx = 0;
3131 const uint32_t num_compile_units = GetNumCompileUnits();
3132 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
3133 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003134 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003135
Greg Clayton53eb1c22012-04-02 22:59:12 +00003136 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003137
Greg Clayton53eb1c22012-04-02 22:59:12 +00003138 dwarf_cu->Index (cu_idx,
3139 m_function_basename_index,
3140 m_function_fullname_index,
3141 m_function_method_index,
3142 m_function_selector_index,
3143 m_objc_class_selectors_index,
3144 m_global_index,
3145 m_type_index,
3146 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003147
3148 // Keep memory down by clearing DIEs if this generate function
3149 // caused them to be parsed
3150 if (clear_dies)
Greg Clayton53eb1c22012-04-02 22:59:12 +00003151 dwarf_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003152 }
3153
Greg Claytond4a2b372011-09-12 23:21:58 +00003154 m_function_basename_index.Finalize();
3155 m_function_fullname_index.Finalize();
3156 m_function_method_index.Finalize();
3157 m_function_selector_index.Finalize();
3158 m_objc_class_selectors_index.Finalize();
3159 m_global_index.Finalize();
3160 m_type_index.Finalize();
3161 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003162
Greg Clayton24739922010-10-13 03:15:28 +00003163#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00003164 StreamFile s(stdout, false);
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00003165 s.Printf ("DWARF index for '%s':",
3166 GetObjectFile()->GetFileSpec().GetPath().c_str());
Greg Claytonba2d22d2010-11-13 22:57:37 +00003167 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
3168 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
3169 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
3170 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
3171 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
3172 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00003173 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00003174 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00003175#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003176 }
3177}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003178
3179bool
3180SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
3181{
3182 if (namespace_decl == NULL)
3183 {
3184 // Invalid namespace decl which means we aren't matching only things
3185 // in this symbol file, so return true to indicate it matches this
3186 // symbol file.
3187 return true;
3188 }
3189
3190 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
3191
3192 if (namespace_ast == NULL)
3193 return true; // No AST in the "namespace_decl", return true since it
3194 // could then match any symbol file, including this one
3195
3196 if (namespace_ast == GetClangASTContext().getASTContext())
3197 return true; // The ASTs match, return true
3198
3199 // The namespace AST was valid, and it does not match...
Greg Clayton5160ce52013-03-27 23:08:40 +00003200 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Sean Callananc41e68b2011-10-13 21:08:11 +00003201
3202 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003203 GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00003204
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003205 return false;
3206}
3207
Greg Clayton2506a7a2011-10-12 23:34:26 +00003208bool
3209SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
3210 DWARFCompileUnit* cu,
3211 const DWARFDebugInfoEntry* die)
3212{
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +00003213 // No namespace specified, so the answer is
Greg Clayton2506a7a2011-10-12 23:34:26 +00003214 if (namespace_decl == NULL)
3215 return true;
Sean Callananebe60672011-10-13 21:50:33 +00003216
Greg Clayton5160ce52013-03-27 23:08:40 +00003217 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003218
Greg Clayton437a1352012-04-09 22:43:43 +00003219 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
3220 clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00003221 if (decl_ctx_die)
Greg Clayton437a1352012-04-09 22:43:43 +00003222 {
Greg Clayton2506a7a2011-10-12 23:34:26 +00003223 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
Greg Clayton437a1352012-04-09 22:43:43 +00003224
Greg Clayton2506a7a2011-10-12 23:34:26 +00003225 if (clang_namespace_decl)
3226 {
3227 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00003228 {
3229 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003230 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00003231 return false;
Sean Callananebe60672011-10-13 21:50:33 +00003232 }
3233
Greg Clayton437a1352012-04-09 22:43:43 +00003234 if (clang_namespace_decl == die_clang_decl_ctx)
3235 return true;
3236 else
Greg Clayton2506a7a2011-10-12 23:34:26 +00003237 return false;
Greg Clayton2506a7a2011-10-12 23:34:26 +00003238 }
3239 else
3240 {
3241 // We have a namespace_decl that was not NULL but it contained
3242 // a NULL "clang::NamespaceDecl", so this means the global namespace
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00003243 // So as long the contained decl context DIE isn't a namespace
Greg Clayton2506a7a2011-10-12 23:34:26 +00003244 // we should be ok.
3245 if (decl_ctx_die->Tag() != DW_TAG_namespace)
3246 return true;
3247 }
3248 }
Sean Callananebe60672011-10-13 21:50:33 +00003249
3250 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003251 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00003252
Greg Clayton2506a7a2011-10-12 23:34:26 +00003253 return false;
3254}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003255uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00003256SymbolFileDWARF::FindGlobalVariables (const ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, VariableList& variables)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003257{
Greg Clayton5160ce52013-03-27 23:08:40 +00003258 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003259
3260 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003261 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003262 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
3263 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003264 static_cast<const void*>(namespace_decl),
3265 append, max_matches);
3266
Sean Callanan213fdb82011-10-13 01:49:10 +00003267 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00003268 return 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003269
Greg Claytonc685f8e2010-09-15 04:15:46 +00003270 DWARFDebugInfo* info = DebugInfo();
3271 if (info == NULL)
3272 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003273
3274 // If we aren't appending the results to this list, then clear the list
3275 if (!append)
3276 variables.Clear();
3277
3278 // Remember how many variables are in the list before we search in case
3279 // we are appending the results to a variable list.
3280 const uint32_t original_size = variables.GetSize();
3281
Greg Claytond4a2b372011-09-12 23:21:58 +00003282 DIEArray die_offsets;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003283
Greg Clayton97fbc342011-10-20 22:30:33 +00003284 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003285 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003286 if (m_apple_names_ap.get())
3287 {
3288 const char *name_cstr = name.GetCString();
Jim Inghamfa39bb42014-10-25 00:33:55 +00003289 llvm::StringRef basename;
3290 llvm::StringRef context;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003291
Jim Inghamfa39bb42014-10-25 00:33:55 +00003292 if (!CPPLanguageRuntime::ExtractContextAndIdentifier(name_cstr, context, basename))
3293 basename = name_cstr;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003294
Jim Inghamfa39bb42014-10-25 00:33:55 +00003295 m_apple_names_ap->FindByName (basename.data(), die_offsets);
Greg Clayton97fbc342011-10-20 22:30:33 +00003296 }
Greg Clayton7f995132011-10-04 22:41:51 +00003297 }
3298 else
3299 {
3300 // Index the DWARF if we haven't already
3301 if (!m_indexed)
3302 Index ();
3303
3304 m_global_index.Find (name, die_offsets);
3305 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003306
Greg Clayton437a1352012-04-09 22:43:43 +00003307 const size_t num_die_matches = die_offsets.size();
3308 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003309 {
Greg Clayton7f995132011-10-04 22:41:51 +00003310 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003311 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00003312 assert (sc.module_sp);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003313
Greg Claytond4a2b372011-09-12 23:21:58 +00003314 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00003315 DWARFCompileUnit* dwarf_cu = NULL;
3316 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton437a1352012-04-09 22:43:43 +00003317 bool done = false;
3318 for (size_t i=0; i<num_die_matches && !done; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00003319 {
3320 const dw_offset_t die_offset = die_offsets[i];
3321 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003322
Greg Clayton95d87902011-11-11 03:16:25 +00003323 if (die)
3324 {
Greg Clayton437a1352012-04-09 22:43:43 +00003325 switch (die->Tag())
3326 {
3327 default:
3328 case DW_TAG_subprogram:
3329 case DW_TAG_inlined_subroutine:
3330 case DW_TAG_try_block:
3331 case DW_TAG_catch_block:
3332 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003333
Greg Clayton437a1352012-04-09 22:43:43 +00003334 case DW_TAG_variable:
3335 {
3336 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003337
Greg Clayton437a1352012-04-09 22:43:43 +00003338 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3339 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003340
Greg Clayton437a1352012-04-09 22:43:43 +00003341 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003342
Greg Clayton437a1352012-04-09 22:43:43 +00003343 if (variables.GetSize() - original_size >= max_matches)
3344 done = true;
3345 }
3346 break;
3347 }
Greg Clayton95d87902011-11-11 03:16:25 +00003348 }
3349 else
3350 {
3351 if (m_using_apple_tables)
3352 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003353 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
3354 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003355 }
3356 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003357 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003358 }
3359
3360 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003361 const uint32_t num_matches = variables.GetSize() - original_size;
3362 if (log && num_matches > 0)
3363 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003364 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003365 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003366 name.GetCString(),
3367 static_cast<const void*>(namespace_decl),
3368 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00003369 num_matches);
3370 }
3371 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003372}
3373
3374uint32_t
3375SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
3376{
Greg Clayton5160ce52013-03-27 23:08:40 +00003377 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003378
Greg Clayton21f2a492011-10-06 00:09:08 +00003379 if (log)
3380 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003381 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003382 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003383 regex.GetText(), append,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003384 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003385 }
3386
Greg Claytonc685f8e2010-09-15 04:15:46 +00003387 DWARFDebugInfo* info = DebugInfo();
3388 if (info == NULL)
3389 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003390
3391 // If we aren't appending the results to this list, then clear the list
3392 if (!append)
3393 variables.Clear();
3394
3395 // Remember how many variables are in the list before we search in case
3396 // we are appending the results to a variable list.
3397 const uint32_t original_size = variables.GetSize();
3398
Greg Clayton7f995132011-10-04 22:41:51 +00003399 DIEArray die_offsets;
3400
Greg Clayton97fbc342011-10-20 22:30:33 +00003401 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003402 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003403 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00003404 {
3405 DWARFMappedHash::DIEInfoArray hash_data_array;
3406 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
3407 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
3408 }
Greg Clayton7f995132011-10-04 22:41:51 +00003409 }
3410 else
3411 {
3412 // Index the DWARF if we haven't already
3413 if (!m_indexed)
3414 Index ();
3415
3416 m_global_index.Find (regex, die_offsets);
3417 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003418
Greg Claytonc685f8e2010-09-15 04:15:46 +00003419 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003420 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003421 assert (sc.module_sp);
3422
Greg Claytond4a2b372011-09-12 23:21:58 +00003423 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00003424 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003425 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003426 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003427 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003428 DWARFDebugInfo* debug_info = DebugInfo();
3429 for (size_t i=0; i<num_matches; ++i)
3430 {
3431 const dw_offset_t die_offset = die_offsets[i];
3432 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00003433
3434 if (die)
3435 {
3436 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003437
Greg Clayton95d87902011-11-11 03:16:25 +00003438 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003439
Greg Clayton95d87902011-11-11 03:16:25 +00003440 if (variables.GetSize() - original_size >= max_matches)
3441 break;
3442 }
3443 else
3444 {
3445 if (m_using_apple_tables)
3446 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003447 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
3448 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00003449 }
3450 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003451 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003452 }
3453
3454 // Return the number of variable that were appended to the list
3455 return variables.GetSize() - original_size;
3456}
3457
Greg Claytonaa044962011-10-13 00:59:38 +00003458
Jim Ingham4cda6e02011-10-07 22:23:45 +00003459bool
3460SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
3461 DWARFCompileUnit *&dwarf_cu,
Pavel Labatha73d6572015-03-13 10:22:00 +00003462 bool include_inlines,
Jim Ingham4cda6e02011-10-07 22:23:45 +00003463 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00003464{
Greg Claytonaa044962011-10-13 00:59:38 +00003465 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Pavel Labatha73d6572015-03-13 10:22:00 +00003466 return ResolveFunction (dwarf_cu, die, include_inlines, sc_list);
Greg Claytonaa044962011-10-13 00:59:38 +00003467}
3468
3469
3470bool
3471SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
3472 const DWARFDebugInfoEntry *die,
Pavel Labatha73d6572015-03-13 10:22:00 +00003473 bool include_inlines,
Greg Claytonaa044962011-10-13 00:59:38 +00003474 SymbolContextList& sc_list)
3475{
Greg Clayton9e315582011-09-02 04:03:59 +00003476 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00003477
3478 if (die == NULL)
3479 return false;
3480
Jim Ingham4cda6e02011-10-07 22:23:45 +00003481 // If we were passed a die that is not a function, just return false...
Pavel Labatha73d6572015-03-13 10:22:00 +00003482 if (! (die->Tag() == DW_TAG_subprogram || (include_inlines && die->Tag() == DW_TAG_inlined_subroutine)))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003483 return false;
3484
3485 const DWARFDebugInfoEntry* inlined_die = NULL;
3486 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00003487 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003488 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00003489
Jim Ingham4cda6e02011-10-07 22:23:45 +00003490 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003491 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003492 if (die->Tag() == DW_TAG_subprogram)
3493 break;
Greg Clayton9e315582011-09-02 04:03:59 +00003494 }
3495 }
Jason Molenda60db6e42014-10-16 01:40:16 +00003496 assert (die && die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00003497 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003498 {
3499 Address addr;
3500 // Parse all blocks if needed
3501 if (inlined_die)
3502 {
Greg Claytonf7bb1fb2015-01-15 03:13:44 +00003503 Block &function_block = sc.function->GetBlock (true);
3504 sc.block = function_block.FindBlockByID (MakeUserID(inlined_die->GetOffset()));
3505 if (sc.block == NULL)
3506 sc.block = function_block.FindBlockByID (inlined_die->GetOffset());
3507 if (sc.block == NULL || sc.block->GetStartAddress (addr) == false)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003508 addr.Clear();
3509 }
3510 else
3511 {
3512 sc.block = NULL;
3513 addr = sc.function->GetAddressRange().GetBaseAddress();
3514 }
3515
3516 if (addr.IsValid())
3517 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003518 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00003519 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003520 }
3521 }
3522
Greg Claytonaa044962011-10-13 00:59:38 +00003523 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00003524}
3525
Greg Clayton7f995132011-10-04 22:41:51 +00003526void
3527SymbolFileDWARF::FindFunctions (const ConstString &name,
3528 const NameToDIE &name_to_die,
Pavel Labatha73d6572015-03-13 10:22:00 +00003529 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003530 SymbolContextList& sc_list)
3531{
Greg Claytond4a2b372011-09-12 23:21:58 +00003532 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003533 if (name_to_die.Find (name, die_offsets))
3534 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003535 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003536 }
3537}
3538
3539
3540void
3541SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3542 const NameToDIE &name_to_die,
Pavel Labatha73d6572015-03-13 10:22:00 +00003543 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003544 SymbolContextList& sc_list)
3545{
3546 DIEArray die_offsets;
3547 if (name_to_die.Find (regex, die_offsets))
3548 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003549 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003550 }
3551}
3552
3553
3554void
3555SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3556 const DWARFMappedHash::MemoryTable &memory_table,
Pavel Labatha73d6572015-03-13 10:22:00 +00003557 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003558 SymbolContextList& sc_list)
3559{
3560 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00003561 DWARFMappedHash::DIEInfoArray hash_data_array;
3562 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00003563 {
Greg Claytond1767f02011-12-08 02:13:16 +00003564 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Pavel Labatha73d6572015-03-13 10:22:00 +00003565 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003566 }
3567}
3568
3569void
3570SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
Pavel Labatha73d6572015-03-13 10:22:00 +00003571 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003572 SymbolContextList& sc_list)
3573{
3574 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003575 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00003576 {
Greg Clayton7f995132011-10-04 22:41:51 +00003577 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003578 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00003579 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003580 const dw_offset_t die_offset = die_offsets[i];
Pavel Labatha73d6572015-03-13 10:22:00 +00003581 ResolveFunction (die_offset, dwarf_cu, include_inlines, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003582 }
3583 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00003584}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003585
Jim Ingham4cda6e02011-10-07 22:23:45 +00003586bool
3587SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
3588 const DWARFCompileUnit *dwarf_cu,
3589 uint32_t name_type_mask,
3590 const char *partial_name,
3591 const char *base_name_start,
3592 const char *base_name_end)
3593{
Greg Claytonfbea0f62012-11-15 18:05:43 +00003594 // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes:
3595 if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003596 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003597 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
3598 if (!containing_decl_ctx)
3599 return false;
3600
3601 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
3602
Greg Claytonfbea0f62012-11-15 18:05:43 +00003603 if (name_type_mask == eFunctionNameTypeMethod)
3604 {
3605 if (is_cxx_method == false)
3606 return false;
3607 }
3608
3609 if (name_type_mask == eFunctionNameTypeBase)
3610 {
3611 if (is_cxx_method == true)
3612 return false;
3613 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003614 }
3615
3616 // Now we need to check whether the name we got back for this type matches the extra specifications
3617 // that were in the name we're looking up:
3618 if (base_name_start != partial_name || *base_name_end != '\0')
3619 {
3620 // First see if the stuff to the left matches the full name. To do that let's see if
3621 // we can pull out the mips linkage name attribute:
3622
3623 Mangled best_name;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003624 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonfbea0f62012-11-15 18:05:43 +00003625 DWARFFormValue form_value;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003626 die->GetAttributes(this, dwarf_cu, NULL, attributes);
3627 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
Greg Clayton71415542012-12-08 00:24:40 +00003628 if (idx == UINT32_MAX)
3629 idx = attributes.FindAttributeIndex(DW_AT_linkage_name);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003630 if (idx != UINT32_MAX)
3631 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003632 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
3633 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003634 const char *mangled_name = form_value.AsCString(&get_debug_str_data());
3635 if (mangled_name)
3636 best_name.SetValue (ConstString(mangled_name), true);
3637 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003638 }
Greg Claytonfbea0f62012-11-15 18:05:43 +00003639
3640 if (!best_name)
3641 {
3642 idx = attributes.FindAttributeIndex(DW_AT_name);
3643 if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value))
3644 {
3645 const char *name = form_value.AsCString(&get_debug_str_data());
3646 best_name.SetValue (ConstString(name), false);
3647 }
3648 }
3649
3650 if (best_name.GetDemangledName())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003651 {
3652 const char *demangled = best_name.GetDemangledName().GetCString();
3653 if (demangled)
3654 {
3655 std::string name_no_parens(partial_name, base_name_end - partial_name);
Jim Ingham85c13d72012-03-02 02:24:42 +00003656 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str());
3657 if (partial_in_demangled == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003658 return false;
Jim Ingham85c13d72012-03-02 02:24:42 +00003659 else
3660 {
3661 // Sort out the case where our name is something like "Process::Destroy" and the match is
3662 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on
3663 // namespace boundaries...
3664
3665 if (partial_name[0] == ':' && partial_name[1] == ':')
3666 {
3667 // The partial name was already on a namespace boundary so all matches are good.
3668 return true;
3669 }
3670 else if (partial_in_demangled == demangled)
3671 {
3672 // They both start the same, so this is an good match.
3673 return true;
3674 }
3675 else
3676 {
3677 if (partial_in_demangled - demangled == 1)
3678 {
3679 // Only one character difference, can't be a namespace boundary...
3680 return false;
3681 }
3682 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':')
3683 {
3684 // We are on a namespace boundary, so this is also good.
3685 return true;
3686 }
3687 else
3688 return false;
3689 }
3690 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003691 }
3692 }
3693 }
3694
3695 return true;
3696}
Greg Claytonc685f8e2010-09-15 04:15:46 +00003697
Greg Clayton0c5cd902010-06-28 21:30:43 +00003698uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00003699SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00003700 const lldb_private::ClangNamespaceDecl *namespace_decl,
Sean Callanan9df05fb2012-02-10 22:52:19 +00003701 uint32_t name_type_mask,
3702 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00003703 bool append,
3704 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00003705{
3706 Timer scoped_timer (__PRETTY_FUNCTION__,
3707 "SymbolFileDWARF::FindFunctions (name = '%s')",
3708 name.AsCString());
3709
Greg Clayton43fe2172013-04-03 02:00:15 +00003710 // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup()
3711 assert ((name_type_mask & eFunctionNameTypeAuto) == 0);
3712
Greg Clayton5160ce52013-03-27 23:08:40 +00003713 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003714
3715 if (log)
3716 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003717 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003718 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
3719 name.GetCString(),
3720 name_type_mask,
3721 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003722 }
3723
Greg Clayton0c5cd902010-06-28 21:30:43 +00003724 // If we aren't appending the results to this list, then clear the list
3725 if (!append)
3726 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003727
3728 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00003729 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003730
3731 // If name is empty then we won't find anything.
3732 if (name.IsEmpty())
3733 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00003734
3735 // Remember how many sc_list are in the list before we search in case
3736 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00003737
Jim Ingham4cda6e02011-10-07 22:23:45 +00003738 const char *name_cstr = name.GetCString();
Greg Clayton43fe2172013-04-03 02:00:15 +00003739
3740 const uint32_t original_size = sc_list.GetSize();
3741
Jim Ingham4cda6e02011-10-07 22:23:45 +00003742 DWARFDebugInfo* info = DebugInfo();
3743 if (info == NULL)
3744 return 0;
3745
Greg Claytonaa044962011-10-13 00:59:38 +00003746 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton43fe2172013-04-03 02:00:15 +00003747 std::set<const DWARFDebugInfoEntry *> resolved_dies;
Greg Clayton97fbc342011-10-20 22:30:33 +00003748 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00003749 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003750 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003751 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003752
3753 DIEArray die_offsets;
3754
3755 uint32_t num_matches = 0;
3756
Greg Clayton43fe2172013-04-03 02:00:15 +00003757 if (name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00003758 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003759 // If they asked for the full name, match what they typed. At some point we may
3760 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
3761 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00003762 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003763 for (uint32_t i = 0; i < num_matches; i++)
3764 {
Greg Clayton95d87902011-11-11 03:16:25 +00003765 const dw_offset_t die_offset = die_offsets[i];
3766 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00003767 if (die)
3768 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003769 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3770 continue;
3771
Greg Clayton43fe2172013-04-03 02:00:15 +00003772 if (resolved_dies.find(die) == resolved_dies.end())
3773 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003774 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00003775 resolved_dies.insert(die);
3776 }
Greg Claytonaa044962011-10-13 00:59:38 +00003777 }
Greg Clayton95d87902011-11-11 03:16:25 +00003778 else
3779 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003780 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3781 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003782 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003783 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003784 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003785
3786 if (name_type_mask & eFunctionNameTypeSelector)
3787 {
3788 if (namespace_decl && *namespace_decl)
3789 return 0; // no selectors in namespaces
Greg Clayton97fbc342011-10-20 22:30:33 +00003790
Greg Clayton43fe2172013-04-03 02:00:15 +00003791 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3792 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
3793 // and if it is an ObjC method name, we're good.
Greg Clayton97fbc342011-10-20 22:30:33 +00003794
Greg Clayton43fe2172013-04-03 02:00:15 +00003795 for (uint32_t i = 0; i < num_matches; i++)
Greg Clayton97fbc342011-10-20 22:30:33 +00003796 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003797 const dw_offset_t die_offset = die_offsets[i];
3798 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3799 if (die)
Greg Clayton97fbc342011-10-20 22:30:33 +00003800 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003801 const char *die_name = die->GetName(this, dwarf_cu);
3802 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
Greg Clayton97fbc342011-10-20 22:30:33 +00003803 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003804 if (resolved_dies.find(die) == resolved_dies.end())
3805 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003806 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00003807 resolved_dies.insert(die);
3808 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003809 }
3810 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003811 else
3812 {
3813 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3814 die_offset, name_cstr);
3815 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003816 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003817 die_offsets.clear();
3818 }
3819
3820 if (((name_type_mask & eFunctionNameTypeMethod) && !namespace_decl) || name_type_mask & eFunctionNameTypeBase)
3821 {
3822 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
3823 // extract the base name, look that up, and if there is any other information in the name we were
3824 // passed in we have to post-filter based on that.
3825
3826 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
3827 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3828
3829 for (uint32_t i = 0; i < num_matches; i++)
3830 {
3831 const dw_offset_t die_offset = die_offsets[i];
3832 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3833 if (die)
3834 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003835 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3836 continue;
3837
3838 // If we get to here, the die is good, and we should add it:
3839 if (resolved_dies.find(die) == resolved_dies.end())
Pavel Labatha73d6572015-03-13 10:22:00 +00003840 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00003841 {
3842 bool keep_die = true;
3843 if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod))
3844 {
3845 // We are looking for either basenames or methods, so we need to
3846 // trim out the ones we won't want by looking at the type
3847 SymbolContext sc;
3848 if (sc_list.GetLastContext(sc))
3849 {
3850 if (sc.block)
3851 {
3852 // We have an inlined function
3853 }
3854 else if (sc.function)
3855 {
3856 Type *type = sc.function->GetType();
3857
Sean Callananc370a8a2013-09-18 22:59:55 +00003858 if (type)
Greg Clayton43fe2172013-04-03 02:00:15 +00003859 {
Sean Callananc370a8a2013-09-18 22:59:55 +00003860 clang::DeclContext* decl_ctx = GetClangDeclContextContainingTypeUID (type->GetID());
3861 if (decl_ctx->isRecord())
Greg Clayton43fe2172013-04-03 02:00:15 +00003862 {
Sean Callananc370a8a2013-09-18 22:59:55 +00003863 if (name_type_mask & eFunctionNameTypeBase)
3864 {
3865 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3866 keep_die = false;
3867 }
3868 }
3869 else
3870 {
3871 if (name_type_mask & eFunctionNameTypeMethod)
3872 {
3873 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3874 keep_die = false;
3875 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003876 }
3877 }
3878 else
3879 {
Sean Callananc370a8a2013-09-18 22:59:55 +00003880 GetObjectFile()->GetModule()->ReportWarning ("function at die offset 0x%8.8x had no function type",
3881 die_offset);
Greg Clayton43fe2172013-04-03 02:00:15 +00003882 }
3883 }
3884 }
3885 }
3886 if (keep_die)
3887 resolved_dies.insert(die);
3888 }
3889 }
3890 else
3891 {
3892 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3893 die_offset, name_cstr);
3894 }
3895 }
3896 die_offsets.clear();
Jim Ingham4cda6e02011-10-07 22:23:45 +00003897 }
3898 }
Greg Clayton7f995132011-10-04 22:41:51 +00003899 }
3900 else
3901 {
3902
3903 // Index the DWARF if we haven't already
3904 if (!m_indexed)
3905 Index ();
3906
Greg Clayton7f995132011-10-04 22:41:51 +00003907 if (name_type_mask & eFunctionNameTypeFull)
Matt Kopecd6089962013-05-10 17:53:48 +00003908 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003909 FindFunctions (name, m_function_fullname_index, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003910
Ed Mastefc7baa02013-09-09 18:00:45 +00003911 // FIXME Temporary workaround for global/anonymous namespace
3912 // functions on FreeBSD and Linux
3913#if defined (__FreeBSD__) || defined (__linux__)
Matt Kopecd6089962013-05-10 17:53:48 +00003914 // If we didn't find any functions in the global namespace try
3915 // looking in the basename index but ignore any returned
3916 // functions that have a namespace (ie. mangled names starting with
3917 // '_ZN') but keep functions which have an anonymous namespace
3918 if (sc_list.GetSize() == 0)
3919 {
3920 SymbolContextList temp_sc_list;
Pavel Labatha73d6572015-03-13 10:22:00 +00003921 FindFunctions (name, m_function_basename_index, include_inlines, temp_sc_list);
Matt Kopecd6089962013-05-10 17:53:48 +00003922 if (!namespace_decl)
3923 {
3924 SymbolContext sc;
3925 for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++)
3926 {
3927 if (temp_sc_list.GetContextAtIndex(i, sc))
3928 {
Matt Kopeca189d492013-05-10 22:55:24 +00003929 ConstString mangled_name = sc.GetFunctionName(Mangled::ePreferMangled);
3930 ConstString demangled_name = sc.GetFunctionName(Mangled::ePreferDemangled);
Matt Kopec04e5d582013-05-14 19:00:41 +00003931 if (strncmp(mangled_name.GetCString(), "_ZN", 3) ||
3932 !strncmp(demangled_name.GetCString(), "(anonymous namespace)", 21))
Matt Kopecd6089962013-05-10 17:53:48 +00003933 {
3934 sc_list.Append(sc);
3935 }
3936 }
3937 }
3938 }
3939 }
3940#endif
3941 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003942 DIEArray die_offsets;
3943 DWARFCompileUnit *dwarf_cu = NULL;
3944
Greg Clayton43fe2172013-04-03 02:00:15 +00003945 if (name_type_mask & eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003946 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003947 uint32_t num_base = m_function_basename_index.Find(name, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00003948 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003949 {
Greg Claytonaa044962011-10-13 00:59:38 +00003950 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3951 if (die)
3952 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003953 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3954 continue;
3955
Greg Claytonaa044962011-10-13 00:59:38 +00003956 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00003957 if (resolved_dies.find(die) == resolved_dies.end())
3958 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003959 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00003960 resolved_dies.insert(die);
3961 }
Greg Claytonaa044962011-10-13 00:59:38 +00003962 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003963 }
3964 die_offsets.clear();
3965 }
3966
Greg Clayton43fe2172013-04-03 02:00:15 +00003967 if (name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003968 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003969 if (namespace_decl && *namespace_decl)
3970 return 0; // no methods in namespaces
3971
Greg Clayton43fe2172013-04-03 02:00:15 +00003972 uint32_t num_base = m_function_method_index.Find(name, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003973 {
Greg Claytonaa044962011-10-13 00:59:38 +00003974 for (uint32_t i = 0; i < num_base; i++)
3975 {
3976 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3977 if (die)
3978 {
Greg Claytonaa044962011-10-13 00:59:38 +00003979 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00003980 if (resolved_dies.find(die) == resolved_dies.end())
3981 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003982 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00003983 resolved_dies.insert(die);
3984 }
Greg Claytonaa044962011-10-13 00:59:38 +00003985 }
3986 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003987 }
3988 die_offsets.clear();
3989 }
Greg Clayton7f995132011-10-04 22:41:51 +00003990
Greg Clayton43fe2172013-04-03 02:00:15 +00003991 if ((name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003992 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003993 FindFunctions (name, m_function_selector_index, include_inlines, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003994 }
3995
Greg Clayton4d01ace2011-09-29 16:58:15 +00003996 }
3997
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003998 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003999 const uint32_t num_matches = sc_list.GetSize() - original_size;
4000
4001 if (log && num_matches > 0)
4002 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004003 GetObjectFile()->GetModule()->LogMessage (log,
Pavel Labatha73d6572015-03-13 10:22:00 +00004004 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, include_inlines=%d, append=%u, sc_list) => %u",
Greg Clayton437a1352012-04-09 22:43:43 +00004005 name.GetCString(),
4006 name_type_mask,
Pavel Labatha73d6572015-03-13 10:22:00 +00004007 include_inlines,
Greg Clayton437a1352012-04-09 22:43:43 +00004008 append,
4009 num_matches);
4010 }
4011 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004012}
4013
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004014uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00004015SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004016{
4017 Timer scoped_timer (__PRETTY_FUNCTION__,
4018 "SymbolFileDWARF::FindFunctions (regex = '%s')",
4019 regex.GetText());
4020
Greg Clayton5160ce52013-03-27 23:08:40 +00004021 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00004022
4023 if (log)
4024 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004025 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00004026 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
4027 regex.GetText(),
4028 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00004029 }
4030
4031
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004032 // If we aren't appending the results to this list, then clear the list
4033 if (!append)
4034 sc_list.Clear();
4035
4036 // Remember how many sc_list are in the list before we search in case
4037 // we are appending the results to a variable list.
4038 uint32_t original_size = sc_list.GetSize();
4039
Greg Clayton97fbc342011-10-20 22:30:33 +00004040 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004041 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004042 if (m_apple_names_ap.get())
Pavel Labatha73d6572015-03-13 10:22:00 +00004043 FindFunctions (regex, *m_apple_names_ap, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00004044 }
4045 else
4046 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00004047 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00004048 if (!m_indexed)
4049 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004050
Pavel Labatha73d6572015-03-13 10:22:00 +00004051 FindFunctions (regex, m_function_basename_index, include_inlines, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004052
Pavel Labatha73d6572015-03-13 10:22:00 +00004053 FindFunctions (regex, m_function_fullname_index, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00004054 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004055
4056 // Return the number of variable that were appended to the list
4057 return sc_list.GetSize() - original_size;
4058}
Jim Ingham318c9f22011-08-26 19:44:13 +00004059
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004060uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00004061SymbolFileDWARF::FindTypes (const SymbolContext& sc,
4062 const ConstString &name,
4063 const lldb_private::ClangNamespaceDecl *namespace_decl,
4064 bool append,
4065 uint32_t max_matches,
4066 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004067{
Greg Claytonc685f8e2010-09-15 04:15:46 +00004068 DWARFDebugInfo* info = DebugInfo();
4069 if (info == NULL)
4070 return 0;
4071
Greg Clayton5160ce52013-03-27 23:08:40 +00004072 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004073
Greg Clayton21f2a492011-10-06 00:09:08 +00004074 if (log)
4075 {
Greg Clayton437a1352012-04-09 22:43:43 +00004076 if (namespace_decl)
Greg Clayton5160ce52013-03-27 23:08:40 +00004077 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004078 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)",
4079 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004080 static_cast<void*>(namespace_decl->GetNamespaceDecl()),
Greg Clayton437a1352012-04-09 22:43:43 +00004081 namespace_decl->GetQualifiedName().c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004082 append, max_matches);
Greg Clayton437a1352012-04-09 22:43:43 +00004083 else
Greg Clayton5160ce52013-03-27 23:08:40 +00004084 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004085 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004086 name.GetCString(), append,
Greg Clayton437a1352012-04-09 22:43:43 +00004087 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00004088 }
4089
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004090 // If we aren't appending the results to this list, then clear the list
4091 if (!append)
4092 types.Clear();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004093
Sean Callanan213fdb82011-10-13 01:49:10 +00004094 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00004095 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004096
Greg Claytond4a2b372011-09-12 23:21:58 +00004097 DIEArray die_offsets;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004098
Greg Clayton97fbc342011-10-20 22:30:33 +00004099 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004100 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004101 if (m_apple_types_ap.get())
4102 {
4103 const char *name_cstr = name.GetCString();
4104 m_apple_types_ap->FindByName (name_cstr, die_offsets);
4105 }
Greg Clayton7f995132011-10-04 22:41:51 +00004106 }
4107 else
4108 {
4109 if (!m_indexed)
4110 Index ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004111
Greg Clayton7f995132011-10-04 22:41:51 +00004112 m_type_index.Find (name, die_offsets);
4113 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004114
Greg Clayton437a1352012-04-09 22:43:43 +00004115 const size_t num_die_matches = die_offsets.size();
Greg Clayton7f995132011-10-04 22:41:51 +00004116
Greg Clayton437a1352012-04-09 22:43:43 +00004117 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004118 {
Greg Clayton7f995132011-10-04 22:41:51 +00004119 const uint32_t initial_types_size = types.GetSize();
4120 DWARFCompileUnit* dwarf_cu = NULL;
4121 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00004122 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00004123 for (size_t i=0; i<num_die_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004124 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004125 const dw_offset_t die_offset = die_offsets[i];
4126 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
4127
Greg Clayton95d87902011-11-11 03:16:25 +00004128 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00004129 {
Greg Clayton95d87902011-11-11 03:16:25 +00004130 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
4131 continue;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004132
Greg Clayton95d87902011-11-11 03:16:25 +00004133 Type *matching_type = ResolveType (dwarf_cu, die);
4134 if (matching_type)
4135 {
4136 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00004137 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00004138 if (types.GetSize() >= max_matches)
4139 break;
4140 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00004141 }
Greg Clayton95d87902011-11-11 03:16:25 +00004142 else
4143 {
4144 if (m_using_apple_tables)
4145 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004146 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4147 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004148 }
4149 }
4150
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004151 }
Greg Clayton437a1352012-04-09 22:43:43 +00004152 const uint32_t num_matches = types.GetSize() - initial_types_size;
4153 if (log && num_matches)
4154 {
4155 if (namespace_decl)
4156 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004157 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004158 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u",
4159 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004160 static_cast<void*>(namespace_decl->GetNamespaceDecl()),
Greg Clayton437a1352012-04-09 22:43:43 +00004161 namespace_decl->GetQualifiedName().c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004162 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00004163 num_matches);
4164 }
4165 else
4166 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004167 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004168 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u",
4169 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004170 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00004171 num_matches);
4172 }
4173 }
4174 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004175 }
Greg Clayton7f995132011-10-04 22:41:51 +00004176 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004177}
4178
4179
Greg Clayton526e5af2010-11-13 03:52:47 +00004180ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00004181SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00004182 const ConstString &name,
4183 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004184{
Greg Clayton5160ce52013-03-27 23:08:40 +00004185 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00004186
4187 if (log)
4188 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004189 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00004190 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
4191 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00004192 }
Sean Callanan213fdb82011-10-13 01:49:10 +00004193
4194 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00004195 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00004196
Greg Clayton526e5af2010-11-13 03:52:47 +00004197 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004198 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00004199 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00004200 {
Greg Clayton7f995132011-10-04 22:41:51 +00004201 DIEArray die_offsets;
4202
Greg Clayton526e5af2010-11-13 03:52:47 +00004203 // Index if we already haven't to make sure the compile units
4204 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00004205 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004206 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004207 if (m_apple_namespaces_ap.get())
4208 {
4209 const char *name_cstr = name.GetCString();
4210 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
4211 }
Greg Clayton7f995132011-10-04 22:41:51 +00004212 }
4213 else
4214 {
4215 if (!m_indexed)
4216 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00004217
Greg Clayton7f995132011-10-04 22:41:51 +00004218 m_namespace_index.Find (name, die_offsets);
4219 }
Greg Claytond4a2b372011-09-12 23:21:58 +00004220
4221 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00004222 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00004223 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00004224 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00004225 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004226 DWARFDebugInfo* debug_info = DebugInfo();
4227 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00004228 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004229 const dw_offset_t die_offset = die_offsets[i];
4230 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00004231
Greg Clayton95d87902011-11-11 03:16:25 +00004232 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00004233 {
Greg Clayton95d87902011-11-11 03:16:25 +00004234 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
4235 continue;
4236
4237 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
4238 if (clang_namespace_decl)
4239 {
4240 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
4241 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
Greg Claytond1767f02011-12-08 02:13:16 +00004242 break;
Greg Clayton95d87902011-11-11 03:16:25 +00004243 }
Greg Claytond4a2b372011-09-12 23:21:58 +00004244 }
Greg Clayton95d87902011-11-11 03:16:25 +00004245 else
4246 {
4247 if (m_using_apple_tables)
4248 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004249 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
4250 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004251 }
4252 }
4253
Greg Clayton526e5af2010-11-13 03:52:47 +00004254 }
4255 }
Greg Clayton96d7d742010-11-10 23:42:09 +00004256 }
Greg Clayton437a1352012-04-09 22:43:43 +00004257 if (log && namespace_decl.GetNamespaceDecl())
4258 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004259 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004260 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"",
4261 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004262 static_cast<const void*>(namespace_decl.GetNamespaceDecl()),
Greg Clayton437a1352012-04-09 22:43:43 +00004263 namespace_decl.GetQualifiedName().c_str());
4264 }
4265
Greg Clayton526e5af2010-11-13 03:52:47 +00004266 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004267}
4268
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004269uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004270SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004271{
4272 // Remember how many sc_list are in the list before we search in case
4273 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004274 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004275
4276 const uint32_t num_die_offsets = die_offsets.size();
4277 // Parse all of the types we found from the pubtypes matches
4278 uint32_t i;
4279 uint32_t num_matches = 0;
4280 for (i = 0; i < num_die_offsets; ++i)
4281 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004282 Type *matching_type = ResolveTypeUID (die_offsets[i]);
4283 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004284 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004285 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00004286 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004287 ++num_matches;
4288 if (num_matches >= max_matches)
4289 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004290 }
4291 }
4292
4293 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004294 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004295}
4296
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004297
4298size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00004299SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
4300 clang::DeclContext *containing_decl_ctx,
Greg Clayton5113dc82011-08-12 06:47:54 +00004301 DWARFCompileUnit* dwarf_cu,
4302 const DWARFDebugInfoEntry *parent_die,
4303 bool skip_artificial,
4304 bool &is_static,
Greg Clayton03969752014-02-24 18:53:11 +00004305 bool &is_variadic,
Greg Clayton57ee3062013-07-11 22:46:58 +00004306 std::vector<ClangASTType>& function_param_types,
Greg Clayton5113dc82011-08-12 06:47:54 +00004307 std::vector<clang::ParmVarDecl*>& function_param_decls,
Greg Claytond20deac2014-04-04 18:15:18 +00004308 unsigned &type_quals) // ,
4309 // ClangASTContext::TemplateParameterInfos &template_param_infos))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004310{
4311 if (parent_die == NULL)
4312 return 0;
4313
Todd Fialaee8bfc62014-09-11 17:29:12 +00004314 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Claytond88d7592010-09-15 08:33:30 +00004315
Greg Clayton7fedea22010-11-16 02:10:54 +00004316 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004317 const DWARFDebugInfoEntry *die;
4318 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4319 {
4320 dw_tag_t tag = die->Tag();
4321 switch (tag)
4322 {
4323 case DW_TAG_formal_parameter:
4324 {
4325 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004326 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004327 if (num_attributes > 0)
4328 {
4329 const char *name = NULL;
4330 Declaration decl;
4331 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00004332 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004333 // one of None, Auto, Register, Extern, Static, PrivateExtern
4334
Sean Callanane2ef6e32010-09-23 03:01:22 +00004335 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004336 uint32_t i;
4337 for (i=0; i<num_attributes; ++i)
4338 {
4339 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4340 DWARFFormValue form_value;
4341 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4342 {
4343 switch (attr)
4344 {
4345 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4346 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4347 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4348 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00004349 case DW_AT_type: param_type_die_offset = form_value.Reference(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00004350 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004351 case DW_AT_location:
4352 // if (form_value.BlockData())
4353 // {
Ed Masteeeae7212013-10-24 20:43:47 +00004354 // const DWARFDataExtractor& debug_info_data = debug_info();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004355 // uint32_t block_length = form_value.Unsigned();
Ed Masteeeae7212013-10-24 20:43:47 +00004356 // DWARFDataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004357 // }
4358 // else
4359 // {
4360 // }
4361 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004362 case DW_AT_const_value:
4363 case DW_AT_default_value:
4364 case DW_AT_description:
4365 case DW_AT_endianity:
4366 case DW_AT_is_optional:
4367 case DW_AT_segment:
4368 case DW_AT_variable_parameter:
4369 default:
4370 case DW_AT_abstract_origin:
4371 case DW_AT_sibling:
4372 break;
4373 }
4374 }
4375 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00004376
Greg Clayton0fffff52010-09-24 05:15:53 +00004377 bool skip = false;
4378 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004379 {
Greg Clayton0fffff52010-09-24 05:15:53 +00004380 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00004381 {
4382 // In order to determine if a C++ member function is
4383 // "const" we have to look at the const-ness of "this"...
4384 // Ugly, but that
4385 if (arg_idx == 0)
4386 {
Greg Claytonf0705c82011-10-22 03:33:13 +00004387 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00004388 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004389 // Often times compilers omit the "this" name for the
4390 // specification DIEs, so we can't rely upon the name
4391 // being in the formal parameter DIE...
4392 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00004393 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004394 Type *this_type = ResolveTypeUID (param_type_die_offset);
4395 if (this_type)
4396 {
4397 uint32_t encoding_mask = this_type->GetEncodingMask();
4398 if (encoding_mask & Type::eEncodingIsPointerUID)
4399 {
4400 is_static = false;
4401
4402 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
4403 type_quals |= clang::Qualifiers::Const;
4404 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
4405 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00004406 }
4407 }
4408 }
4409 }
4410 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004411 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00004412 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004413 else
4414 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004415
Greg Clayton0fffff52010-09-24 05:15:53 +00004416 // HACK: Objective C formal parameters "self" and "_cmd"
4417 // are not marked as artificial in the DWARF...
Greg Clayton53eb1c22012-04-02 22:59:12 +00004418 CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
4419 if (comp_unit)
Greg Clayton0fffff52010-09-24 05:15:53 +00004420 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004421 switch (comp_unit->GetLanguage())
4422 {
4423 case eLanguageTypeObjC:
4424 case eLanguageTypeObjC_plus_plus:
4425 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
4426 skip = true;
4427 break;
4428 default:
4429 break;
4430 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004431 }
4432 }
4433 }
4434
4435 if (!skip)
4436 {
4437 Type *type = ResolveTypeUID(param_type_die_offset);
4438 if (type)
4439 {
Greg Claytonc93237c2010-10-01 20:48:32 +00004440 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00004441
Greg Clayton42ce2f32011-12-12 21:50:19 +00004442 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
4443 type->GetClangForwardType(),
4444 storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00004445 assert(param_var_decl);
4446 function_param_decls.push_back(param_var_decl);
Sean Callanan60217122012-04-13 00:10:03 +00004447
Greg Claytond0029442013-03-27 01:48:02 +00004448 GetClangASTContext().SetMetadataAsUserID (param_var_decl, MakeUserID(die->GetOffset()));
Greg Clayton0fffff52010-09-24 05:15:53 +00004449 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004450 }
4451 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004452 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004453 }
4454 break;
4455
Greg Clayton03969752014-02-24 18:53:11 +00004456 case DW_TAG_unspecified_parameters:
4457 is_variadic = true;
4458 break;
4459
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004460 case DW_TAG_template_type_parameter:
4461 case DW_TAG_template_value_parameter:
Greg Claytond20deac2014-04-04 18:15:18 +00004462 // The one caller of this was never using the template_param_infos,
4463 // and the local variable was taking up a large amount of stack space
4464 // in SymbolFileDWARF::ParseType() so this was removed. If we ever need
4465 // the template params back, we can add them back.
4466 // ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004467 break;
4468
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004469 default:
4470 break;
4471 }
4472 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004473 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004474}
4475
4476size_t
4477SymbolFileDWARF::ParseChildEnumerators
4478(
4479 const SymbolContext& sc,
Greg Clayton57ee3062013-07-11 22:46:58 +00004480 lldb_private::ClangASTType &clang_type,
Greg Clayton3e067532013-03-05 23:54:39 +00004481 bool is_signed,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004482 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00004483 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004484 const DWARFDebugInfoEntry *parent_die
4485)
4486{
4487 if (parent_die == NULL)
4488 return 0;
4489
4490 size_t enumerators_added = 0;
4491 const DWARFDebugInfoEntry *die;
Todd Fialaee8bfc62014-09-11 17:29:12 +00004492 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Claytond88d7592010-09-15 08:33:30 +00004493
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004494 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4495 {
4496 const dw_tag_t tag = die->Tag();
4497 if (tag == DW_TAG_enumerator)
4498 {
4499 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004500 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004501 if (num_child_attributes > 0)
4502 {
4503 const char *name = NULL;
4504 bool got_value = false;
4505 int64_t enum_value = 0;
4506 Declaration decl;
4507
4508 uint32_t i;
4509 for (i=0; i<num_child_attributes; ++i)
4510 {
4511 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4512 DWARFFormValue form_value;
4513 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4514 {
4515 switch (attr)
4516 {
4517 case DW_AT_const_value:
4518 got_value = true;
Greg Clayton3e067532013-03-05 23:54:39 +00004519 if (is_signed)
4520 enum_value = form_value.Signed();
4521 else
4522 enum_value = form_value.Unsigned();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004523 break;
4524
4525 case DW_AT_name:
4526 name = form_value.AsCString(&get_debug_str_data());
4527 break;
4528
4529 case DW_AT_description:
4530 default:
4531 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4532 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4533 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4534 case DW_AT_sibling:
4535 break;
4536 }
4537 }
4538 }
4539
4540 if (name && name[0] && got_value)
4541 {
Greg Clayton57ee3062013-07-11 22:46:58 +00004542 clang_type.AddEnumerationValueToEnumerationType (clang_type.GetEnumerationIntegerType(),
4543 decl,
4544 name,
4545 enum_value,
4546 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004547 ++enumerators_added;
4548 }
4549 }
4550 }
4551 }
4552 return enumerators_added;
4553}
4554
4555void
4556SymbolFileDWARF::ParseChildArrayInfo
4557(
4558 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004559 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004560 const DWARFDebugInfoEntry *parent_die,
4561 int64_t& first_index,
4562 std::vector<uint64_t>& element_orders,
4563 uint32_t& byte_stride,
4564 uint32_t& bit_stride
4565)
4566{
4567 if (parent_die == NULL)
4568 return;
4569
4570 const DWARFDebugInfoEntry *die;
Todd Fialaee8bfc62014-09-11 17:29:12 +00004571 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004572 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4573 {
4574 const dw_tag_t tag = die->Tag();
4575 switch (tag)
4576 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004577 case DW_TAG_subrange_type:
4578 {
4579 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004580 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004581 if (num_child_attributes > 0)
4582 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004583 uint64_t num_elements = 0;
4584 uint64_t lower_bound = 0;
4585 uint64_t upper_bound = 0;
Greg Clayton4ef877f2012-12-06 02:33:54 +00004586 bool upper_bound_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004587 uint32_t i;
4588 for (i=0; i<num_child_attributes; ++i)
4589 {
4590 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4591 DWARFFormValue form_value;
4592 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4593 {
4594 switch (attr)
4595 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004596 case DW_AT_name:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004597 break;
4598
4599 case DW_AT_count:
4600 num_elements = form_value.Unsigned();
4601 break;
4602
4603 case DW_AT_bit_stride:
4604 bit_stride = form_value.Unsigned();
4605 break;
4606
4607 case DW_AT_byte_stride:
4608 byte_stride = form_value.Unsigned();
4609 break;
4610
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004611 case DW_AT_lower_bound:
4612 lower_bound = form_value.Unsigned();
4613 break;
4614
4615 case DW_AT_upper_bound:
Greg Clayton4ef877f2012-12-06 02:33:54 +00004616 upper_bound_valid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004617 upper_bound = form_value.Unsigned();
4618 break;
4619
4620 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004621 case DW_AT_abstract_origin:
4622 case DW_AT_accessibility:
4623 case DW_AT_allocated:
4624 case DW_AT_associated:
4625 case DW_AT_data_location:
4626 case DW_AT_declaration:
4627 case DW_AT_description:
4628 case DW_AT_sibling:
4629 case DW_AT_threads_scaled:
4630 case DW_AT_type:
4631 case DW_AT_visibility:
4632 break;
4633 }
4634 }
4635 }
4636
Greg Claytone6a07792012-12-05 21:59:39 +00004637 if (num_elements == 0)
4638 {
Greg Clayton4ef877f2012-12-06 02:33:54 +00004639 if (upper_bound_valid && upper_bound >= lower_bound)
Greg Claytone6a07792012-12-05 21:59:39 +00004640 num_elements = upper_bound - lower_bound + 1;
4641 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004642
Sean Callananec979ba2012-10-22 23:56:48 +00004643 element_orders.push_back (num_elements);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004644 }
4645 }
4646 break;
4647 }
4648 }
4649}
4650
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004651TypeSP
Greg Clayton53eb1c22012-04-02 22:59:12 +00004652SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004653{
4654 TypeSP type_sp;
4655 if (die != NULL)
4656 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004657 assert(dwarf_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00004658 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004659 if (type_ptr == NULL)
4660 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004661 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu);
Greg Claytonca512b32011-01-14 04:54:56 +00004662 assert (lldb_cu);
4663 SymbolContext sc(lldb_cu);
Greg Clayton53eb1c22012-04-02 22:59:12 +00004664 type_sp = ParseType(sc, dwarf_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004665 }
4666 else if (type_ptr != DIE_IS_BEING_PARSED)
4667 {
4668 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00004669 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004670 }
4671
4672 }
4673 return type_sp;
4674}
4675
4676clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00004677SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004678{
4679 if (die_offset != DW_INVALID_OFFSET)
4680 {
4681 DWARFCompileUnitSP cu_sp;
4682 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004683 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004684 }
4685 return NULL;
4686}
4687
Sean Callanan72e49402011-08-05 23:43:37 +00004688clang::DeclContext *
4689SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
4690{
4691 if (die_offset != DW_INVALID_OFFSET)
4692 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004693 DWARFDebugInfo* debug_info = DebugInfo();
4694 if (debug_info)
4695 {
4696 DWARFCompileUnitSP cu_sp;
4697 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
4698 if (die)
4699 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
4700 }
Sean Callanan72e49402011-08-05 23:43:37 +00004701 }
4702 return NULL;
4703}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004704
Greg Clayton96d7d742010-11-10 23:42:09 +00004705clang::NamespaceDecl *
Greg Clayton53eb1c22012-04-02 22:59:12 +00004706SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die)
Greg Clayton96d7d742010-11-10 23:42:09 +00004707{
Greg Clayton030a2042011-10-14 21:34:45 +00004708 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00004709 {
Greg Clayton030a2042011-10-14 21:34:45 +00004710 // See if we already parsed this namespace DIE and associated it with a
4711 // uniqued namespace declaration
4712 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
4713 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004714 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00004715 else
4716 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004717 const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL);
4718 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00004719 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
Greg Clayton5160ce52013-03-27 23:08:40 +00004720 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton9d3d6882011-10-31 23:51:19 +00004721 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00004722 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00004723 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00004724 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004725 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00004726 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004727 static_cast<void*>(GetClangASTContext().getASTContext()),
Greg Claytone38a5ed2012-01-05 03:57:59 +00004728 MakeUserID(die->GetOffset()),
4729 namespace_name,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004730 static_cast<void*>(namespace_decl),
4731 static_cast<void*>(namespace_decl->getOriginalNamespace()));
Greg Clayton030a2042011-10-14 21:34:45 +00004732 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004733 else
4734 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004735 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00004736 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004737 static_cast<void*>(GetClangASTContext().getASTContext()),
Greg Claytone38a5ed2012-01-05 03:57:59 +00004738 MakeUserID(die->GetOffset()),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004739 static_cast<void*>(namespace_decl),
4740 static_cast<void*>(namespace_decl->getOriginalNamespace()));
Greg Clayton9d3d6882011-10-31 23:51:19 +00004741 }
Greg Clayton030a2042011-10-14 21:34:45 +00004742 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004743
4744 if (namespace_decl)
4745 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
4746 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004747 }
4748 }
4749 return NULL;
4750}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004751
4752clang::DeclContext *
Greg Claytoncab36a32011-12-08 05:16:30 +00004753SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Sean Callanan72e49402011-08-05 23:43:37 +00004754{
Greg Clayton5cf58b92011-10-05 22:22:08 +00004755 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4756 if (clang_decl_ctx)
4757 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004758 // If this DIE has a specification, or an abstract origin, then trace to those.
4759
Greg Claytoncab36a32011-12-08 05:16:30 +00004760 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004761 if (die_offset != DW_INVALID_OFFSET)
4762 return GetClangDeclContextForDIEOffset (sc, die_offset);
4763
Greg Claytoncab36a32011-12-08 05:16:30 +00004764 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004765 if (die_offset != DW_INVALID_OFFSET)
4766 return GetClangDeclContextForDIEOffset (sc, die_offset);
4767
Greg Clayton5160ce52013-03-27 23:08:40 +00004768 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00004769 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004770 GetObjectFile()->GetModule()->LogMessage(log, "SymbolFileDWARF::GetClangDeclContextForDIE (die = 0x%8.8x) %s '%s'", die->GetOffset(), DW_TAG_value_to_name(die->Tag()), die->GetName(this, cu));
Sean Callanan72e49402011-08-05 23:43:37 +00004771 // This is the DIE we want. Parse it, then query our map.
Greg Claytoncab36a32011-12-08 05:16:30 +00004772 bool assert_not_being_parsed = true;
4773 ResolveTypeUID (cu, die, assert_not_being_parsed);
4774
Greg Clayton5cf58b92011-10-05 22:22:08 +00004775 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4776
4777 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004778}
4779
4780clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00004781SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004782{
Greg Claytonca512b32011-01-14 04:54:56 +00004783 if (m_clang_tu_decl == NULL)
4784 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004785
Greg Clayton2bc22f82011-09-30 03:20:47 +00004786 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004787
4788 if (decl_ctx_die_copy)
4789 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00004790
4791 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004792 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00004793
Greg Clayton2bc22f82011-09-30 03:20:47 +00004794 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
4795 if (pos != m_die_to_decl_ctx.end())
4796 return pos->second;
4797
4798 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004799 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004800 case DW_TAG_compile_unit:
4801 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004802
Greg Clayton2bc22f82011-09-30 03:20:47 +00004803 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00004804 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00004805 break;
4806
4807 case DW_TAG_structure_type:
4808 case DW_TAG_union_type:
4809 case DW_TAG_class_type:
4810 {
4811 Type* type = ResolveType (cu, decl_ctx_die);
4812 if (type)
4813 {
Greg Clayton57ee3062013-07-11 22:46:58 +00004814 clang::DeclContext *decl_ctx = type->GetClangForwardType().GetDeclContextForType ();
Greg Clayton2bc22f82011-09-30 03:20:47 +00004815 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00004816 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004817 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
4818 if (decl_ctx)
4819 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00004820 }
4821 }
Greg Claytonca512b32011-01-14 04:54:56 +00004822 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00004823 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004824
Greg Clayton2bc22f82011-09-30 03:20:47 +00004825 default:
4826 break;
Greg Claytonca512b32011-01-14 04:54:56 +00004827 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004828 }
Greg Clayton7a345282010-11-09 23:46:37 +00004829 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004830}
4831
Greg Clayton2bc22f82011-09-30 03:20:47 +00004832
4833const DWARFDebugInfoEntry *
4834SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4835{
4836 if (cu && die)
4837 {
4838 const DWARFDebugInfoEntry * const decl_die = die;
4839
4840 while (die != NULL)
4841 {
4842 // If this is the original DIE that we are searching for a declaration
4843 // for, then don't look in the cache as we don't want our own decl
4844 // context to be our decl context...
4845 if (decl_die != die)
4846 {
4847 switch (die->Tag())
4848 {
4849 case DW_TAG_compile_unit:
4850 case DW_TAG_namespace:
4851 case DW_TAG_structure_type:
4852 case DW_TAG_union_type:
4853 case DW_TAG_class_type:
4854 return die;
4855
4856 default:
4857 break;
4858 }
4859 }
4860
4861 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4862 if (die_offset != DW_INVALID_OFFSET)
4863 {
4864 DWARFCompileUnit *spec_cu = cu;
4865 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
4866 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
4867 if (spec_die_decl_ctx_die)
4868 return spec_die_decl_ctx_die;
4869 }
4870
4871 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
4872 if (die_offset != DW_INVALID_OFFSET)
4873 {
4874 DWARFCompileUnit *abs_cu = cu;
4875 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
4876 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
4877 if (abs_die_decl_ctx_die)
4878 return abs_die_decl_ctx_die;
4879 }
4880
4881 die = die->GetParent();
4882 }
4883 }
4884 return NULL;
4885}
4886
4887
Greg Clayton901c5ca2011-12-03 04:40:03 +00004888Symbol *
4889SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
4890{
4891 Symbol *objc_class_symbol = NULL;
4892 if (m_obj_file)
4893 {
Greg Clayton3046e662013-07-10 01:23:25 +00004894 Symtab *symtab = m_obj_file->GetSymtab ();
Greg Clayton901c5ca2011-12-03 04:40:03 +00004895 if (symtab)
4896 {
4897 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
4898 eSymbolTypeObjCClass,
4899 Symtab::eDebugNo,
4900 Symtab::eVisibilityAny);
4901 }
4902 }
4903 return objc_class_symbol;
4904}
4905
Greg Claytonc7f03b62012-01-12 04:33:28 +00004906// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
4907// then we can end up looking through all class types for a complete type and never find
4908// the full definition. We need to know if this attribute is supported, so we determine
4909// this here and cache th result. We also need to worry about the debug map DWARF file
4910// if we are doing darwin DWARF in .o file debugging.
4911bool
4912SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
4913{
4914 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
4915 {
4916 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
4917 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
4918 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4919 else
4920 {
4921 DWARFDebugInfo* debug_info = DebugInfo();
4922 const uint32_t num_compile_units = GetNumCompileUnits();
4923 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
4924 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004925 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
4926 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004927 {
4928 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4929 break;
4930 }
4931 }
4932 }
Greg Clayton1f746072012-08-29 21:13:06 +00004933 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004934 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
4935 }
4936 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
4937}
Greg Clayton901c5ca2011-12-03 04:40:03 +00004938
4939// This function can be used when a DIE is found that is a forward declaration
4940// DIE and we want to try and find a type that has the complete definition.
4941TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00004942SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
4943 const ConstString &type_name,
4944 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00004945{
4946
4947 TypeSP type_sp;
4948
Greg Claytonc7f03b62012-01-12 04:33:28 +00004949 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00004950 return type_sp;
4951
4952 DIEArray die_offsets;
4953
4954 if (m_using_apple_tables)
4955 {
4956 if (m_apple_types_ap.get())
4957 {
4958 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00004959 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004960 }
4961 }
4962 else
4963 {
4964 if (!m_indexed)
4965 Index ();
4966
4967 m_type_index.Find (type_name, die_offsets);
4968 }
4969
Greg Clayton901c5ca2011-12-03 04:40:03 +00004970 const size_t num_matches = die_offsets.size();
4971
Greg Clayton901c5ca2011-12-03 04:40:03 +00004972 DWARFCompileUnit* type_cu = NULL;
4973 const DWARFDebugInfoEntry* type_die = NULL;
4974 if (num_matches)
4975 {
4976 DWARFDebugInfo* debug_info = DebugInfo();
4977 for (size_t i=0; i<num_matches; ++i)
4978 {
4979 const dw_offset_t die_offset = die_offsets[i];
4980 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4981
4982 if (type_die)
4983 {
4984 bool try_resolving_type = false;
4985
4986 // Don't try and resolve the DIE we are looking for with the DIE itself!
4987 if (type_die != die)
4988 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004989 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00004990 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004991 case DW_TAG_class_type:
4992 case DW_TAG_structure_type:
4993 try_resolving_type = true;
4994 break;
4995 default:
4996 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00004997 }
4998 }
4999
5000 if (try_resolving_type)
5001 {
Ed Maste4c24b122013-10-17 20:13:14 +00005002 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
5003 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00005004
5005 if (try_resolving_type)
5006 {
5007 Type *resolved_type = ResolveType (type_cu, type_die, false);
5008 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5009 {
Ed Mastea0191d12013-10-17 20:42:56 +00005010 DEBUG_PRINTF ("resolved 0x%8.8" PRIx64 " from %s to 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ")\n",
Greg Clayton901c5ca2011-12-03 04:40:03 +00005011 MakeUserID(die->GetOffset()),
Jim Ingham4af59612014-12-19 19:20:44 +00005012 m_obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>"),
Greg Clayton901c5ca2011-12-03 04:40:03 +00005013 MakeUserID(type_die->GetOffset()),
5014 MakeUserID(type_cu->GetOffset()));
5015
Greg Claytonc7f03b62012-01-12 04:33:28 +00005016 if (die)
5017 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00005018 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00005019 break;
5020 }
5021 }
5022 }
5023 }
5024 else
5025 {
5026 if (m_using_apple_tables)
5027 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005028 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5029 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00005030 }
5031 }
5032
5033 }
5034 }
5035 return type_sp;
5036}
5037
Greg Claytona8022fa2012-04-24 21:22:41 +00005038
Greg Clayton80c26302012-02-05 06:12:47 +00005039//----------------------------------------------------------------------
5040// This function helps to ensure that the declaration contexts match for
5041// two different DIEs. Often times debug information will refer to a
5042// forward declaration of a type (the equivalent of "struct my_struct;".
5043// There will often be a declaration of that type elsewhere that has the
5044// full definition. When we go looking for the full type "my_struct", we
5045// will find one or more matches in the accelerator tables and we will
5046// then need to make sure the type was in the same declaration context
5047// as the original DIE. This function can efficiently compare two DIEs
5048// and will return true when the declaration context matches, and false
5049// when they don't.
5050//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00005051bool
5052SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
5053 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
5054{
Greg Claytona8022fa2012-04-24 21:22:41 +00005055 if (die1 == die2)
5056 return true;
5057
5058#if defined (LLDB_CONFIGURATION_DEBUG)
5059 // You can't and shouldn't call this function with a compile unit from
5060 // two different SymbolFileDWARF instances.
5061 assert (DebugInfo()->ContainsCompileUnit (cu1));
5062 assert (DebugInfo()->ContainsCompileUnit (cu2));
5063#endif
5064
Greg Clayton890ff562012-02-02 05:48:16 +00005065 DWARFDIECollection decl_ctx_1;
5066 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00005067 //The declaration DIE stack is a stack of the declaration context
5068 // DIEs all the way back to the compile unit. If a type "T" is
5069 // declared inside a class "B", and class "B" is declared inside
5070 // a class "A" and class "A" is in a namespace "lldb", and the
5071 // namespace is in a compile unit, there will be a stack of DIEs:
5072 //
5073 // [0] DW_TAG_class_type for "B"
5074 // [1] DW_TAG_class_type for "A"
5075 // [2] DW_TAG_namespace for "lldb"
5076 // [3] DW_TAG_compile_unit for the source file.
5077 //
5078 // We grab both contexts and make sure that everything matches
5079 // all the way back to the compiler unit.
5080
5081 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00005082 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00005083 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00005084 // Make sure the context arrays have the same size, otherwise
5085 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00005086 const size_t count1 = decl_ctx_1.Size();
5087 const size_t count2 = decl_ctx_2.Size();
5088 if (count1 != count2)
5089 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00005090
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00005091 // Make sure the DW_TAG values match all the way back up the
Greg Clayton80c26302012-02-05 06:12:47 +00005092 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00005093 const DWARFDebugInfoEntry *decl_ctx_die1;
5094 const DWARFDebugInfoEntry *decl_ctx_die2;
5095 size_t i;
5096 for (i=0; i<count1; i++)
5097 {
5098 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
5099 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
5100 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
5101 return false;
5102 }
Greg Clayton890ff562012-02-02 05:48:16 +00005103#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00005104
5105 // Make sure the top item in the decl context die array is always
5106 // DW_TAG_compile_unit. If it isn't then something went wrong in
5107 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00005108 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00005109
Greg Clayton890ff562012-02-02 05:48:16 +00005110#endif
5111 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00005112 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00005113 for (i=0; i<count1 - 1; i++)
5114 {
5115 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
5116 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
5117 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00005118 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00005119 // If the string was from a DW_FORM_strp, then the pointer will often
5120 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00005121 if (name1 == name2)
5122 continue;
5123
5124 // Name pointers are not equal, so only compare the strings
5125 // if both are not NULL.
5126 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00005127 {
Greg Clayton5569e642012-02-06 01:44:54 +00005128 // If the strings don't compare, we are done...
5129 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00005130 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00005131 }
5132 else
5133 {
5134 // One name was NULL while the other wasn't
5135 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00005136 }
5137 }
Greg Clayton80c26302012-02-05 06:12:47 +00005138 // We made it through all of the checks and the declaration contexts
5139 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00005140 return true;
5141}
Greg Clayton220a0072011-12-09 08:48:30 +00005142
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005143
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005144TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00005145SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx)
5146{
5147 TypeSP type_sp;
5148
5149 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
5150 if (dwarf_decl_ctx_count > 0)
5151 {
5152 const ConstString type_name(dwarf_decl_ctx[0].name);
5153 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
5154
5155 if (type_name)
5156 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005157 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
Greg Claytona8022fa2012-04-24 21:22:41 +00005158 if (log)
5159 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005160 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005161 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')",
5162 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5163 dwarf_decl_ctx.GetQualifiedName());
5164 }
5165
5166 DIEArray die_offsets;
5167
5168 if (m_using_apple_tables)
5169 {
5170 if (m_apple_types_ap.get())
5171 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005172 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
5173 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
5174 if (has_tag && has_qualified_name_hash)
Greg Claytona8022fa2012-04-24 21:22:41 +00005175 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005176 const char *qualified_name = dwarf_decl_ctx.GetQualifiedName();
5177 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name);
5178 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005179 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005180 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets);
5181 }
5182 else if (has_tag)
5183 {
5184 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005185 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
Greg Claytona8022fa2012-04-24 21:22:41 +00005186 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets);
5187 }
5188 else
5189 {
5190 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
5191 }
5192 }
5193 }
5194 else
5195 {
5196 if (!m_indexed)
5197 Index ();
5198
5199 m_type_index.Find (type_name, die_offsets);
5200 }
5201
5202 const size_t num_matches = die_offsets.size();
5203
5204
5205 DWARFCompileUnit* type_cu = NULL;
5206 const DWARFDebugInfoEntry* type_die = NULL;
5207 if (num_matches)
5208 {
5209 DWARFDebugInfo* debug_info = DebugInfo();
5210 for (size_t i=0; i<num_matches; ++i)
5211 {
5212 const dw_offset_t die_offset = die_offsets[i];
5213 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
5214
5215 if (type_die)
5216 {
5217 bool try_resolving_type = false;
5218
5219 // Don't try and resolve the DIE we are looking for with the DIE itself!
5220 const dw_tag_t type_tag = type_die->Tag();
5221 // Make sure the tags match
5222 if (type_tag == tag)
5223 {
5224 // The tags match, lets try resolving this type
5225 try_resolving_type = true;
5226 }
5227 else
5228 {
5229 // The tags don't match, but we need to watch our for a
5230 // forward declaration for a struct and ("struct foo")
5231 // ends up being a class ("class foo { ... };") or
5232 // vice versa.
5233 switch (type_tag)
5234 {
5235 case DW_TAG_class_type:
5236 // We had a "class foo", see if we ended up with a "struct foo { ... };"
5237 try_resolving_type = (tag == DW_TAG_structure_type);
5238 break;
5239 case DW_TAG_structure_type:
5240 // We had a "struct foo", see if we ended up with a "class foo { ... };"
5241 try_resolving_type = (tag == DW_TAG_class_type);
5242 break;
5243 default:
5244 // Tags don't match, don't event try to resolve
5245 // using this type whose name matches....
5246 break;
5247 }
5248 }
5249
5250 if (try_resolving_type)
5251 {
5252 DWARFDeclContext type_dwarf_decl_ctx;
5253 type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx);
5254
5255 if (log)
5256 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005257 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005258 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)",
5259 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5260 dwarf_decl_ctx.GetQualifiedName(),
5261 type_die->GetOffset(),
5262 type_dwarf_decl_ctx.GetQualifiedName());
5263 }
5264
5265 // Make sure the decl contexts match all the way up
5266 if (dwarf_decl_ctx == type_dwarf_decl_ctx)
5267 {
5268 Type *resolved_type = ResolveType (type_cu, type_die, false);
5269 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5270 {
5271 type_sp = resolved_type->shared_from_this();
5272 break;
5273 }
5274 }
5275 }
5276 else
5277 {
5278 if (log)
5279 {
5280 std::string qualified_name;
5281 type_die->GetQualifiedName(this, type_cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00005282 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005283 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)",
5284 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5285 dwarf_decl_ctx.GetQualifiedName(),
5286 type_die->GetOffset(),
5287 qualified_name.c_str());
5288 }
5289 }
5290 }
5291 else
5292 {
5293 if (m_using_apple_tables)
5294 {
5295 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5296 die_offset, type_name.GetCString());
5297 }
5298 }
5299
5300 }
5301 }
5302 }
5303 }
5304 return type_sp;
5305}
5306
Greg Clayton4116e932012-05-15 02:33:01 +00005307bool
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005308SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005309 Type *class_type,
Greg Clayton4116e932012-05-15 02:33:01 +00005310 DWARFCompileUnit* src_cu,
5311 const DWARFDebugInfoEntry *src_class_die,
5312 DWARFCompileUnit* dst_cu,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005313 const DWARFDebugInfoEntry *dst_class_die,
Greg Claytond20deac2014-04-04 18:15:18 +00005314 DWARFDIECollection &failures)
Greg Clayton4116e932012-05-15 02:33:01 +00005315{
5316 if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die)
5317 return false;
5318 if (src_class_die->Tag() != dst_class_die->Tag())
5319 return false;
5320
5321 // We need to complete the class type so we can get all of the method types
5322 // parsed so we can then unique those types to their equivalent counterparts
5323 // in "dst_cu" and "dst_class_die"
5324 class_type->GetClangFullType();
5325
5326 const DWARFDebugInfoEntry *src_die;
5327 const DWARFDebugInfoEntry *dst_die;
5328 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die;
5329 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die;
Greg Clayton65ec1032012-11-12 21:27:20 +00005330 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial;
5331 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial;
Greg Clayton4116e932012-05-15 02:33:01 +00005332 for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling())
5333 {
5334 if (src_die->Tag() == DW_TAG_subprogram)
5335 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005336 // Make sure this is a declaration and not a concrete instance by looking
5337 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5338 // are placed inside the class definitions and shouldn't be included in
5339 // the list of things are are tracking here.
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005340 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_declaration, 0) == 1)
Greg Clayton84afacd2012-11-07 23:09:32 +00005341 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005342 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton84afacd2012-11-07 23:09:32 +00005343 if (src_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005344 {
5345 ConstString src_const_name(src_name);
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005346 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0))
Greg Clayton65ec1032012-11-12 21:27:20 +00005347 src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die);
5348 else
5349 src_name_to_die.Append(src_const_name.GetCString(), src_die);
5350 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005351 }
Greg Clayton4116e932012-05-15 02:33:01 +00005352 }
5353 }
5354 for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling())
5355 {
5356 if (dst_die->Tag() == DW_TAG_subprogram)
5357 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005358 // Make sure this is a declaration and not a concrete instance by looking
5359 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5360 // are placed inside the class definitions and shouldn't be included in
5361 // the list of things are are tracking here.
5362 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1)
5363 {
5364 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5365 if (dst_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005366 {
5367 ConstString dst_const_name(dst_name);
5368 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0))
5369 dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die);
5370 else
5371 dst_name_to_die.Append(dst_const_name.GetCString(), dst_die);
5372 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005373 }
Greg Clayton4116e932012-05-15 02:33:01 +00005374 }
5375 }
5376 const uint32_t src_size = src_name_to_die.GetSize ();
5377 const uint32_t dst_size = dst_name_to_die.GetSize ();
Greg Clayton5160ce52013-03-27 23:08:40 +00005378 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005379
5380 // Is everything kosher so we can go through the members at top speed?
5381 bool fast_path = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005382
Sean Callanan2367f8a2013-02-26 01:12:25 +00005383 if (src_size != dst_size)
Greg Clayton4116e932012-05-15 02:33:01 +00005384 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005385 if (src_size != 0 && dst_size != 0)
5386 {
5387 if (log)
5388 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)",
5389 src_class_die->GetOffset(),
5390 dst_class_die->GetOffset(),
5391 src_size,
5392 dst_size);
5393 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005394
Sean Callanan2367f8a2013-02-26 01:12:25 +00005395 fast_path = false;
5396 }
5397
5398 uint32_t idx;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005399
Sean Callanan2367f8a2013-02-26 01:12:25 +00005400 if (fast_path)
5401 {
Greg Clayton4116e932012-05-15 02:33:01 +00005402 for (idx = 0; idx < src_size; ++idx)
5403 {
5404 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5405 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5406
5407 if (src_die->Tag() != dst_die->Tag())
5408 {
5409 if (log)
5410 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)",
5411 src_class_die->GetOffset(),
5412 dst_class_die->GetOffset(),
5413 src_die->GetOffset(),
5414 DW_TAG_value_to_name(src_die->Tag()),
5415 dst_die->GetOffset(),
5416 DW_TAG_value_to_name(src_die->Tag()));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005417 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005418 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005419
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005420 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton4116e932012-05-15 02:33:01 +00005421 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005422
Greg Clayton4116e932012-05-15 02:33:01 +00005423 // Make sure the names match
5424 if (src_name == dst_name || (strcmp (src_name, dst_name) == 0))
5425 continue;
5426
5427 if (log)
5428 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)",
5429 src_class_die->GetOffset(),
5430 dst_class_die->GetOffset(),
5431 src_die->GetOffset(),
5432 src_name,
5433 dst_die->GetOffset(),
5434 dst_name);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005435
Sean Callanan2367f8a2013-02-26 01:12:25 +00005436 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005437 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005438 }
Greg Clayton4116e932012-05-15 02:33:01 +00005439
Sean Callanan2367f8a2013-02-26 01:12:25 +00005440 // Now do the work of linking the DeclContexts and Types.
5441 if (fast_path)
5442 {
5443 // We can do this quickly. Just run across the tables index-for-index since
5444 // we know each node has matching names and tags.
Greg Clayton4116e932012-05-15 02:33:01 +00005445 for (idx = 0; idx < src_size; ++idx)
5446 {
5447 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5448 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005449
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005450 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Greg Clayton4116e932012-05-15 02:33:01 +00005451 if (src_decl_ctx)
5452 {
5453 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005454 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
5455 static_cast<void*>(src_decl_ctx),
5456 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005457 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5458 }
5459 else
5460 {
5461 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005462 log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found",
5463 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005464 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005465
Greg Clayton4116e932012-05-15 02:33:01 +00005466 Type *src_child_type = m_die_to_type[src_die];
5467 if (src_child_type)
5468 {
5469 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005470 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
5471 static_cast<void*>(src_child_type),
5472 src_child_type->GetID(),
5473 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005474 m_die_to_type[dst_die] = src_child_type;
5475 }
5476 else
5477 {
5478 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005479 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());
5480 }
5481 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005482 }
5483 else
5484 {
5485 // We must do this slowly. For each member of the destination, look
5486 // up a member in the source with the same name, check its tag, and
5487 // unique them if everything matches up. Report failures.
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005488
Sean Callanan2367f8a2013-02-26 01:12:25 +00005489 if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty())
5490 {
5491 src_name_to_die.Sort();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005492
Sean Callanan2367f8a2013-02-26 01:12:25 +00005493 for (idx = 0; idx < dst_size; ++idx)
5494 {
5495 const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx);
5496 dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
5497 src_die = src_name_to_die.Find(dst_name, NULL);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005498
Sean Callanan2367f8a2013-02-26 01:12:25 +00005499 if (src_die && (src_die->Tag() == dst_die->Tag()))
5500 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005501 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Sean Callanan2367f8a2013-02-26 01:12:25 +00005502 if (src_decl_ctx)
5503 {
5504 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005505 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
5506 static_cast<void*>(src_decl_ctx),
5507 src_die->GetOffset(),
5508 dst_die->GetOffset());
Sean Callanan2367f8a2013-02-26 01:12:25 +00005509 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5510 }
5511 else
5512 {
5513 if (log)
5514 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());
5515 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005516
Sean Callanan2367f8a2013-02-26 01:12:25 +00005517 Type *src_child_type = m_die_to_type[src_die];
5518 if (src_child_type)
5519 {
5520 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005521 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
5522 static_cast<void*>(src_child_type),
5523 src_child_type->GetID(),
5524 src_die->GetOffset(),
5525 dst_die->GetOffset());
Sean Callanan2367f8a2013-02-26 01:12:25 +00005526 m_die_to_type[dst_die] = src_child_type;
5527 }
5528 else
5529 {
5530 if (log)
5531 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());
5532 }
5533 }
5534 else
5535 {
5536 if (log)
5537 log->Printf ("warning: couldn't find a match for 0x%8.8x", dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005538
Greg Claytond20deac2014-04-04 18:15:18 +00005539 failures.Append(dst_die);
Sean Callanan2367f8a2013-02-26 01:12:25 +00005540 }
5541 }
5542 }
5543 }
5544
5545 const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize ();
5546 const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize ();
5547
5548 UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src;
5549
5550 if (src_size_artificial && dst_size_artificial)
5551 {
5552 dst_name_to_die_artificial.Sort();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005553
Greg Clayton65ec1032012-11-12 21:27:20 +00005554 for (idx = 0; idx < src_size_artificial; ++idx)
5555 {
5556 const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx);
5557 src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5558 dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005559
Greg Clayton65ec1032012-11-12 21:27:20 +00005560 if (dst_die)
5561 {
Greg Clayton65ec1032012-11-12 21:27:20 +00005562 // Both classes have the artificial types, link them
5563 clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die];
5564 if (src_decl_ctx)
5565 {
5566 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005567 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
5568 static_cast<void*>(src_decl_ctx),
5569 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005570 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5571 }
5572 else
5573 {
5574 if (log)
5575 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());
5576 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005577
Greg Clayton65ec1032012-11-12 21:27:20 +00005578 Type *src_child_type = m_die_to_type[src_die];
5579 if (src_child_type)
5580 {
5581 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005582 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
5583 static_cast<void*>(src_child_type),
5584 src_child_type->GetID(),
5585 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005586 m_die_to_type[dst_die] = src_child_type;
5587 }
5588 else
5589 {
5590 if (log)
5591 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());
5592 }
5593 }
5594 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005595 }
Greg Clayton65ec1032012-11-12 21:27:20 +00005596
Sean Callanan2367f8a2013-02-26 01:12:25 +00005597 if (dst_size_artificial)
Greg Clayton4116e932012-05-15 02:33:01 +00005598 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005599 for (idx = 0; idx < dst_size_artificial; ++idx)
5600 {
5601 const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx);
5602 dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5603 if (log)
5604 log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial);
5605
Greg Claytond20deac2014-04-04 18:15:18 +00005606 failures.Append(dst_die);
Sean Callanan2367f8a2013-02-26 01:12:25 +00005607 }
Greg Clayton4116e932012-05-15 02:33:01 +00005608 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005609
Greg Claytond20deac2014-04-04 18:15:18 +00005610 return (failures.Size() != 0);
Greg Clayton4116e932012-05-15 02:33:01 +00005611}
Greg Claytona8022fa2012-04-24 21:22:41 +00005612
5613TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00005614SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005615{
5616 TypeSP type_sp;
5617
Greg Clayton1be10fc2010-09-29 01:12:09 +00005618 if (type_is_new_ptr)
5619 *type_is_new_ptr = false;
Greg Clayton1fba87112012-02-09 20:03:49 +00005620
Todd Fiala0a70a842014-05-28 16:43:26 +00005621#if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE)
Greg Clayton1fba87112012-02-09 20:03:49 +00005622 static DIEStack g_die_stack;
5623 DIEStack::ScopedPopper scoped_die_logger(g_die_stack);
5624#endif
Greg Clayton1be10fc2010-09-29 01:12:09 +00005625
Sean Callananc7fbf732010-08-06 00:32:49 +00005626 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005627 if (die != NULL)
5628 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005629 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005630 if (log)
Sean Callanan5b26f272012-02-04 08:49:35 +00005631 {
5632 const DWARFDebugInfoEntry *context_die;
5633 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005634
Greg Clayton5160ce52013-03-27 23:08:40 +00005635 GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x, decl_ctx = %p (die 0x%8.8x)) %s name = '%s')",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005636 die->GetOffset(),
5637 static_cast<void*>(context),
5638 context_die->GetOffset(),
5639 DW_TAG_value_to_name(die->Tag()),
5640 die->GetName(this, dwarf_cu));
5641
Todd Fiala0a70a842014-05-28 16:43:26 +00005642#if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE)
Greg Clayton1fba87112012-02-09 20:03:49 +00005643 scoped_die_logger.Push (dwarf_cu, die);
Greg Clayton5160ce52013-03-27 23:08:40 +00005644 g_die_stack.LogDIEs(log, this);
Greg Clayton1fba87112012-02-09 20:03:49 +00005645#endif
Sean Callanan5b26f272012-02-04 08:49:35 +00005646 }
Greg Clayton3bffb082011-12-10 02:15:28 +00005647//
Greg Clayton5160ce52013-03-27 23:08:40 +00005648// Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005649// if (log && dwarf_cu)
5650// {
5651// StreamString s;
5652// die->DumpLocation (this, dwarf_cu, s);
Greg Clayton5160ce52013-03-27 23:08:40 +00005653// GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Greg Clayton3bffb082011-12-10 02:15:28 +00005654//
5655// }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005656
Greg Clayton594e5ed2010-09-27 21:07:38 +00005657 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005658 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00005659 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005660 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005661 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00005662 if (type_is_new_ptr)
5663 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005664
Greg Clayton594e5ed2010-09-27 21:07:38 +00005665 const dw_tag_t tag = die->Tag();
5666
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005667 bool is_forward_declaration = false;
5668 DWARFDebugInfoEntry::Attributes attributes;
5669 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00005670 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00005671 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
Greg Claytonfaac1112013-03-14 18:31:44 +00005672 uint64_t byte_size = 0;
Greg Clayton526e5af2010-11-13 03:52:47 +00005673 Declaration decl;
5674
Greg Clayton4957bf62010-09-30 21:49:03 +00005675 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton57ee3062013-07-11 22:46:58 +00005676 ClangASTType clang_type;
Greg Claytond20deac2014-04-04 18:15:18 +00005677 DWARFFormValue form_value;
5678
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005679 dw_attr_t attr;
5680
5681 switch (tag)
5682 {
5683 case DW_TAG_base_type:
5684 case DW_TAG_pointer_type:
5685 case DW_TAG_reference_type:
Sean Callanance8af862012-05-21 23:31:51 +00005686 case DW_TAG_rvalue_reference_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005687 case DW_TAG_typedef:
5688 case DW_TAG_const_type:
5689 case DW_TAG_restrict_type:
5690 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00005691 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005692 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005693 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005694 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005695
Greg Claytond88d7592010-09-15 08:33:30 +00005696 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005697 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005698 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
5699
5700 if (num_attributes > 0)
5701 {
5702 uint32_t i;
5703 for (i=0; i<num_attributes; ++i)
5704 {
5705 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005706 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5707 {
5708 switch (attr)
5709 {
5710 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5711 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5712 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5713 case DW_AT_name:
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005714
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005715 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00005716 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
5717 // include the "&"...
5718 if (tag == DW_TAG_reference_type)
5719 {
5720 if (strchr (type_name_cstr, '&') == NULL)
5721 type_name_cstr = NULL;
5722 }
5723 if (type_name_cstr)
5724 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005725 break;
Greg Clayton23f59502012-07-17 03:23:13 +00005726 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005727 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
Greg Clayton54166af2014-11-22 01:58:59 +00005728 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005729 default:
5730 case DW_AT_sibling:
5731 break;
5732 }
5733 }
5734 }
5735 }
5736
Ed Mastea0191d12013-10-17 20:42:56 +00005737 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\") type => 0x%8.8lx\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr, encoding_uid);
Greg Claytonc93237c2010-10-01 20:48:32 +00005738
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005739 switch (tag)
5740 {
5741 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00005742 break;
5743
Greg Claytond4436412011-10-28 21:00:00 +00005744 case DW_TAG_unspecified_type:
Greg Clayton7fba2632013-07-01 21:01:52 +00005745 if (strcmp(type_name_cstr, "nullptr_t") == 0 ||
5746 strcmp(type_name_cstr, "decltype(nullptr)") == 0 )
Greg Claytond4436412011-10-28 21:00:00 +00005747 {
5748 resolve_state = Type::eResolveStateFull;
Greg Clayton57ee3062013-07-11 22:46:58 +00005749 clang_type = ast.GetBasicType(eBasicTypeNullPtr);
Greg Claytond4436412011-10-28 21:00:00 +00005750 break;
5751 }
5752 // Fall through to base type below in case we can handle the type there...
5753
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005754 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00005755 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005756 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
5757 encoding,
5758 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005759 break;
5760
Sean Callanance8af862012-05-21 23:31:51 +00005761 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
5762 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
5763 case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break;
5764 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
5765 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
5766 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
5767 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005768 }
5769
Greg Clayton57ee3062013-07-11 22:46:58 +00005770 if (!clang_type && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID) && sc.comp_unit != NULL)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005771 {
Sean Callanan82587052013-01-03 00:05:56 +00005772 bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005773
Sean Callanan82587052013-01-03 00:05:56 +00005774 if (translation_unit_is_objc)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005775 {
Sean Callanan82587052013-01-03 00:05:56 +00005776 if (type_name_cstr != NULL)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005777 {
Sean Callanan82587052013-01-03 00:05:56 +00005778 static ConstString g_objc_type_name_id("id");
5779 static ConstString g_objc_type_name_Class("Class");
5780 static ConstString g_objc_type_name_selector("SEL");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005781
Sean Callanan82587052013-01-03 00:05:56 +00005782 if (type_name_const_str == g_objc_type_name_id)
5783 {
5784 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005785 GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'id' built-in type.",
Sean Callanan82587052013-01-03 00:05:56 +00005786 die->GetOffset(),
5787 DW_TAG_value_to_name(die->Tag()),
5788 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005789 clang_type = ast.GetBasicType(eBasicTypeObjCID);
Sean Callanan82587052013-01-03 00:05:56 +00005790 encoding_data_type = Type::eEncodingIsUID;
5791 encoding_uid = LLDB_INVALID_UID;
5792 resolve_state = Type::eResolveStateFull;
Greg Clayton526e5af2010-11-13 03:52:47 +00005793
Sean Callanan82587052013-01-03 00:05:56 +00005794 }
5795 else if (type_name_const_str == g_objc_type_name_Class)
5796 {
5797 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005798 GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'Class' built-in type.",
Sean Callanan82587052013-01-03 00:05:56 +00005799 die->GetOffset(),
5800 DW_TAG_value_to_name(die->Tag()),
5801 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005802 clang_type = ast.GetBasicType(eBasicTypeObjCClass);
Sean Callanan82587052013-01-03 00:05:56 +00005803 encoding_data_type = Type::eEncodingIsUID;
5804 encoding_uid = LLDB_INVALID_UID;
5805 resolve_state = Type::eResolveStateFull;
5806 }
5807 else if (type_name_const_str == g_objc_type_name_selector)
5808 {
5809 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005810 GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.",
Sean Callanan82587052013-01-03 00:05:56 +00005811 die->GetOffset(),
5812 DW_TAG_value_to_name(die->Tag()),
5813 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005814 clang_type = ast.GetBasicType(eBasicTypeObjCSel);
Sean Callanan82587052013-01-03 00:05:56 +00005815 encoding_data_type = Type::eEncodingIsUID;
5816 encoding_uid = LLDB_INVALID_UID;
5817 resolve_state = Type::eResolveStateFull;
5818 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005819 }
Sean Callanan82587052013-01-03 00:05:56 +00005820 else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005821 {
Sean Callanan82587052013-01-03 00:05:56 +00005822 // Clang sometimes erroneously emits id as objc_object*. In that case we fix up the type to "id".
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005823
Sean Callanan82587052013-01-03 00:05:56 +00005824 DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005825
Sean Callanan82587052013-01-03 00:05:56 +00005826 if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005827 {
Sean Callanan82587052013-01-03 00:05:56 +00005828 if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL))
5829 {
5830 if (!strcmp(struct_name, "objc_object"))
5831 {
5832 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005833 GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is 'objc_object*', which we overrode to 'id'.",
Sean Callanan82587052013-01-03 00:05:56 +00005834 die->GetOffset(),
5835 DW_TAG_value_to_name(die->Tag()),
5836 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005837 clang_type = ast.GetBasicType(eBasicTypeObjCID);
Sean Callanan82587052013-01-03 00:05:56 +00005838 encoding_data_type = Type::eEncodingIsUID;
5839 encoding_uid = LLDB_INVALID_UID;
5840 resolve_state = Type::eResolveStateFull;
5841 }
5842 }
5843 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005844 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005845 }
5846 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005847
Greg Clayton81c22f62011-10-19 18:09:39 +00005848 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005849 this,
5850 type_name_const_str,
5851 byte_size,
5852 NULL,
5853 encoding_uid,
5854 encoding_data_type,
5855 &decl,
5856 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005857 resolve_state));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005858
Greg Clayton594e5ed2010-09-27 21:07:38 +00005859 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005860
5861// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
5862// if (encoding_type != NULL)
5863// {
5864// if (encoding_type != DIE_IS_BEING_PARSED)
5865// type_sp->SetEncodingType(encoding_type);
5866// else
5867// m_indirect_fixups.push_back(type_sp.get());
5868// }
5869 }
5870 break;
5871
5872 case DW_TAG_structure_type:
5873 case DW_TAG_union_type:
5874 case DW_TAG_class_type:
5875 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005876 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005877 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Greg Clayton23f59502012-07-17 03:23:13 +00005878 bool byte_size_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005879
Greg Clayton9e409562010-07-28 02:04:09 +00005880 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00005881 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005882 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00005883 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005884 if (num_attributes > 0)
5885 {
5886 uint32_t i;
5887 for (i=0; i<num_attributes; ++i)
5888 {
5889 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005890 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5891 {
5892 switch (attr)
5893 {
Greg Clayton9e409562010-07-28 02:04:09 +00005894 case DW_AT_decl_file:
Greg Claytonc7f03b62012-01-12 04:33:28 +00005895 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
Ed Maste4c24b122013-10-17 20:13:14 +00005896 {
5897 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
5898 // point to the compile unit file, so we clear this invalid value
5899 // so that we can still unique types efficiently.
Greg Claytonc7f03b62012-01-12 04:33:28 +00005900 decl.SetFile(FileSpec ("<invalid>", false));
Ed Maste4c24b122013-10-17 20:13:14 +00005901 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005902 else
5903 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
Greg Clayton9e409562010-07-28 02:04:09 +00005904 break;
5905
5906 case DW_AT_decl_line:
5907 decl.SetLine(form_value.Unsigned());
5908 break;
5909
5910 case DW_AT_decl_column:
5911 decl.SetColumn(form_value.Unsigned());
5912 break;
5913
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005914 case DW_AT_name:
5915 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005916 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005917 break;
Greg Clayton9e409562010-07-28 02:04:09 +00005918
5919 case DW_AT_byte_size:
5920 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00005921 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00005922 break;
5923
5924 case DW_AT_accessibility:
5925 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
5926 break;
5927
5928 case DW_AT_declaration:
Greg Clayton1c8ef472013-04-05 23:27:21 +00005929 is_forward_declaration = form_value.Boolean();
Greg Clayton9e409562010-07-28 02:04:09 +00005930 break;
5931
5932 case DW_AT_APPLE_runtime_class:
5933 class_language = (LanguageType)form_value.Signed();
5934 break;
5935
Greg Clayton18774842011-11-29 23:40:34 +00005936 case DW_AT_APPLE_objc_complete_type:
5937 is_complete_objc_class = form_value.Signed();
5938 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005939
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005940 case DW_AT_allocated:
5941 case DW_AT_associated:
5942 case DW_AT_data_location:
5943 case DW_AT_description:
5944 case DW_AT_start_scope:
5945 case DW_AT_visibility:
5946 default:
5947 case DW_AT_sibling:
5948 break;
5949 }
5950 }
5951 }
5952 }
Greg Claytond20deac2014-04-04 18:15:18 +00005953
5954 // UniqueDWARFASTType is large, so don't create a local variables on the
5955 // stack, put it on the heap. This function is often called recursively
5956 // and clang isn't good and sharing the stack space for variables in different blocks.
5957 std::unique_ptr<UniqueDWARFASTType> unique_ast_entry_ap(new UniqueDWARFASTType());
Sean Callanan8e8072d2012-02-07 21:13:38 +00005958
Greg Clayton123edca2012-03-02 00:07:15 +00005959 // Only try and unique the type if it has a name.
5960 if (type_name_const_str &&
5961 GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Sean Callanan8e8072d2012-02-07 21:13:38 +00005962 this,
5963 dwarf_cu,
5964 die,
5965 decl,
5966 byte_size_valid ? byte_size : -1,
Greg Claytond20deac2014-04-04 18:15:18 +00005967 *unique_ast_entry_ap))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005968 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005969 // We have already parsed this type or from another
5970 // compile unit. GCC loves to use the "one definition
5971 // rule" which can result in multiple definitions
5972 // of the same class over and over in each compile
5973 // unit.
Greg Claytond20deac2014-04-04 18:15:18 +00005974 type_sp = unique_ast_entry_ap->m_type_sp;
Sean Callanan8e8072d2012-02-07 21:13:38 +00005975 if (type_sp)
Greg Claytonc615ce42010-11-09 04:42:43 +00005976 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005977 m_die_to_type[die] = type_sp.get();
5978 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005979 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005980 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005981
Daniel Malead01b2952012-11-29 21:49:15 +00005982 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005983
5984 int tag_decl_kind = -1;
5985 AccessType default_accessibility = eAccessNone;
5986 if (tag == DW_TAG_structure_type)
5987 {
5988 tag_decl_kind = clang::TTK_Struct;
5989 default_accessibility = eAccessPublic;
5990 }
5991 else if (tag == DW_TAG_union_type)
5992 {
5993 tag_decl_kind = clang::TTK_Union;
5994 default_accessibility = eAccessPublic;
5995 }
5996 else if (tag == DW_TAG_class_type)
5997 {
5998 tag_decl_kind = clang::TTK_Class;
5999 default_accessibility = eAccessPrivate;
6000 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006001
Greg Clayton3a5f29a2011-11-30 02:48:28 +00006002 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
6003 die->HasChildren() == false &&
6004 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
6005 {
6006 // Work around an issue with clang at the moment where
6007 // forward declarations for objective C classes are emitted
6008 // as:
6009 // DW_TAG_structure_type [2]
6010 // DW_AT_name( "ForwardObjcClass" )
6011 // DW_AT_byte_size( 0x00 )
6012 // DW_AT_decl_file( "..." )
6013 // DW_AT_decl_line( 1 )
6014 //
6015 // Note that there is no DW_AT_declaration and there are
6016 // no children, and the byte size is zero.
6017 is_forward_declaration = true;
6018 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006019
Sean Callanan7457f8d2012-04-25 01:03:57 +00006020 if (class_language == eLanguageTypeObjC ||
6021 class_language == eLanguageTypeObjC_plus_plus)
Greg Clayton18774842011-11-29 23:40:34 +00006022 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00006023 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
Greg Clayton901c5ca2011-12-03 04:40:03 +00006024 {
6025 // We have a valid eSymbolTypeObjCClass class symbol whose
6026 // name matches the current objective C class that we
6027 // are trying to find and this DIE isn't the complete
6028 // definition (we checked is_complete_objc_class above and
6029 // know it is false), so the real definition is in here somewhere
Greg Claytonc7f03b62012-01-12 04:33:28 +00006030 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006031
Greg Clayton1f746072012-08-29 21:13:06 +00006032 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton901c5ca2011-12-03 04:40:03 +00006033 {
6034 // We weren't able to find a full declaration in
6035 // this DWARF, see if we have a declaration anywhere
6036 // else...
Greg Claytonc7f03b62012-01-12 04:33:28 +00006037 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00006038 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006039
Greg Clayton901c5ca2011-12-03 04:40:03 +00006040 if (type_sp)
6041 {
6042 if (log)
6043 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006044 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00006045 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8" PRIx64,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006046 static_cast<void*>(this),
Greg Claytone38a5ed2012-01-05 03:57:59 +00006047 die->GetOffset(),
6048 DW_TAG_value_to_name(tag),
6049 type_name_cstr,
6050 type_sp->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00006051 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006052
Greg Clayton901c5ca2011-12-03 04:40:03 +00006053 // We found a real definition for this type elsewhere
6054 // so lets use it and cache the fact that we found
6055 // a complete type for this die
6056 m_die_to_type[die] = type_sp.get();
6057 return type_sp;
6058 }
6059 }
6060 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006061
Greg Clayton901c5ca2011-12-03 04:40:03 +00006062
6063 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006064 {
6065 // We have a forward declaration to a type and we need
6066 // to try and find a full declaration. We look in the
6067 // current type index just in case we have a forward
6068 // declaration followed by an actual declarations in the
6069 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00006070 if (log)
6071 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006072 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00006073 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006074 static_cast<void*>(this),
Greg Claytone38a5ed2012-01-05 03:57:59 +00006075 die->GetOffset(),
6076 DW_TAG_value_to_name(tag),
6077 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00006078 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006079
Greg Claytona8022fa2012-04-24 21:22:41 +00006080 DWARFDeclContext die_decl_ctx;
6081 die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx);
6082
6083 //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
6084 type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006085
Greg Clayton1f746072012-08-29 21:13:06 +00006086 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton4272cc72011-02-02 02:24:04 +00006087 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006088 // We weren't able to find a full declaration in
6089 // this DWARF, see if we have a declaration anywhere
6090 // else...
Greg Claytona8022fa2012-04-24 21:22:41 +00006091 type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton4272cc72011-02-02 02:24:04 +00006092 }
6093
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006094 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00006095 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00006096 if (log)
6097 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006098 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00006099 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8" PRIx64,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006100 static_cast<void*>(this),
Greg Claytone38a5ed2012-01-05 03:57:59 +00006101 die->GetOffset(),
6102 DW_TAG_value_to_name(tag),
6103 type_name_cstr,
6104 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00006105 }
6106
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006107 // We found a real definition for this type elsewhere
6108 // so lets use it and cache the fact that we found
6109 // a complete type for this die
6110 m_die_to_type[die] = type_sp.get();
6111 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00006112 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006113 }
6114 assert (tag_decl_kind != -1);
6115 bool clang_type_was_created = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00006116 clang_type.SetClangType(ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die));
6117 if (!clang_type)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006118 {
Sean Callanan4d04c6a2012-02-09 22:54:11 +00006119 const DWARFDebugInfoEntry *decl_ctx_die;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006120
Sean Callanan4d04c6a2012-02-09 22:54:11 +00006121 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton55561e92011-10-26 03:31:36 +00006122 if (accessibility == eAccessNone && decl_ctx)
6123 {
6124 // Check the decl context that contains this class/struct/union.
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00006125 // If it is a class we must give it an accessibility.
Greg Clayton55561e92011-10-26 03:31:36 +00006126 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
6127 if (DeclKindIsCXXClass (containing_decl_kind))
6128 accessibility = default_accessibility;
6129 }
6130
Greg Claytonc4ffd662013-03-08 01:37:30 +00006131 ClangASTMetadata metadata;
6132 metadata.SetUserID(MakeUserID(die->GetOffset()));
6133 metadata.SetIsDynamicCXXType(ClassOrStructIsVirtual (dwarf_cu, die));
6134
Greg Claytonf0705c82011-10-22 03:33:13 +00006135 if (type_name_cstr && strchr (type_name_cstr, '<'))
6136 {
6137 ClangASTContext::TemplateParameterInfos template_param_infos;
6138 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
6139 {
6140 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00006141 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00006142 type_name_cstr,
6143 tag_decl_kind,
6144 template_param_infos);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006145
Greg Claytonf0705c82011-10-22 03:33:13 +00006146 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
6147 class_template_decl,
6148 tag_decl_kind,
6149 template_param_infos);
6150 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
6151 clang_type_was_created = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006152
Greg Claytond0029442013-03-27 01:48:02 +00006153 GetClangASTContext().SetMetadata (class_template_decl, metadata);
6154 GetClangASTContext().SetMetadata (class_specialization_decl, metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00006155 }
6156 }
6157
6158 if (!clang_type_was_created)
6159 {
6160 clang_type_was_created = true;
Greg Clayton55561e92011-10-26 03:31:36 +00006161 clang_type = ast.CreateRecordType (decl_ctx,
6162 accessibility,
6163 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00006164 tag_decl_kind,
Sean Callanan60217122012-04-13 00:10:03 +00006165 class_language,
Jim Ingham379397632012-10-27 02:54:13 +00006166 &metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00006167 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006168 }
6169
6170 // Store a forward declaration to this class type in case any
6171 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00006172 // types for function prototypes.
Greg Clayton57ee3062013-07-11 22:46:58 +00006173 LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00006174 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006175 this,
6176 type_name_const_str,
6177 byte_size,
6178 NULL,
6179 LLDB_INVALID_UID,
6180 Type::eEncodingIsUID,
6181 &decl,
6182 clang_type,
6183 Type::eResolveStateForward));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006184
Sean Callanan72772842012-02-22 23:57:45 +00006185 type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006186
6187
6188 // Add our type to the unique type map so we don't
6189 // end up creating many copies of the same type over
6190 // and over in the ASTContext for our module
Greg Claytond20deac2014-04-04 18:15:18 +00006191 unique_ast_entry_ap->m_type_sp = type_sp;
6192 unique_ast_entry_ap->m_symfile = this;
6193 unique_ast_entry_ap->m_cu = dwarf_cu;
6194 unique_ast_entry_ap->m_die = die;
6195 unique_ast_entry_ap->m_declaration = decl;
6196 unique_ast_entry_ap->m_byte_size = byte_size;
Greg Claytone576ab22011-02-15 00:19:15 +00006197 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
Greg Claytond20deac2014-04-04 18:15:18 +00006198 *unique_ast_entry_ap);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006199
Greg Clayton0ec71a02013-08-10 00:09:35 +00006200 if (is_forward_declaration && die->HasChildren())
6201 {
6202 // Check to see if the DIE actually has a definition, some version of GCC will
6203 // emit DIEs with DW_AT_declaration set to true, but yet still have subprogram,
6204 // members, or inheritance, so we can't trust it
6205 const DWARFDebugInfoEntry *child_die = die->GetFirstChild();
6206 while (child_die)
6207 {
6208 switch (child_die->Tag())
6209 {
6210 case DW_TAG_inheritance:
6211 case DW_TAG_subprogram:
6212 case DW_TAG_member:
6213 case DW_TAG_APPLE_property:
Greg Clayton4c484ec2014-02-07 19:21:56 +00006214 case DW_TAG_class_type:
6215 case DW_TAG_structure_type:
6216 case DW_TAG_enumeration_type:
6217 case DW_TAG_typedef:
6218 case DW_TAG_union_type:
Greg Clayton0ec71a02013-08-10 00:09:35 +00006219 child_die = NULL;
6220 is_forward_declaration = false;
6221 break;
6222 default:
6223 child_die = child_die->GetSibling();
6224 break;
6225 }
6226 }
6227 }
6228
Sean Callanan12014a02011-12-08 23:45:45 +00006229 if (!is_forward_declaration)
Greg Clayton219cf312012-03-30 00:51:13 +00006230 {
6231 // Always start the definition for a class type so that
6232 // if the class has child classes or types that require
6233 // the class to be created for use as their decl contexts
6234 // the class will be ready to accept these child definitions.
Sean Callanan12014a02011-12-08 23:45:45 +00006235 if (die->HasChildren() == false)
6236 {
6237 // No children for this struct/union/class, lets finish it
Greg Clayton57ee3062013-07-11 22:46:58 +00006238 clang_type.StartTagDeclarationDefinition ();
6239 clang_type.CompleteTagDeclarationDefinition ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006240
Sean Callanan433cd222012-10-19 01:37:25 +00006241 if (tag == DW_TAG_structure_type) // this only applies in C
6242 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006243 clang::RecordDecl *record_decl = clang_type.GetAsRecordDecl();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006244
Greg Clayton57ee3062013-07-11 22:46:58 +00006245 if (record_decl)
Greg Claytond20deac2014-04-04 18:15:18 +00006246 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, LayoutInfo()));
Sean Callanan433cd222012-10-19 01:37:25 +00006247 }
Sean Callanan12014a02011-12-08 23:45:45 +00006248 }
6249 else if (clang_type_was_created)
6250 {
Greg Clayton219cf312012-03-30 00:51:13 +00006251 // Start the definition if the class is not objective C since
6252 // the underlying decls respond to isCompleteDefinition(). Objective
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +00006253 // C decls don't respond to isCompleteDefinition() so we can't
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00006254 // start the declaration definition right away. For C++ class/union/structs
Greg Clayton219cf312012-03-30 00:51:13 +00006255 // we want to start the definition in case the class is needed as the
6256 // declaration context for a contained class or type without the need
6257 // to complete that type..
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006258
Sean Callanan7457f8d2012-04-25 01:03:57 +00006259 if (class_language != eLanguageTypeObjC &&
6260 class_language != eLanguageTypeObjC_plus_plus)
Greg Clayton57ee3062013-07-11 22:46:58 +00006261 clang_type.StartTagDeclarationDefinition ();
Greg Clayton219cf312012-03-30 00:51:13 +00006262
Sean Callanan12014a02011-12-08 23:45:45 +00006263 // Leave this as a forward declaration until we need
6264 // to know the details of the type. lldb_private::Type
6265 // will automatically call the SymbolFile virtual function
6266 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
6267 // When the definition needs to be defined.
Greg Clayton57ee3062013-07-11 22:46:58 +00006268 m_forward_decl_die_to_clang_type[die] = clang_type.GetOpaqueQualType();
6269 m_forward_decl_clang_type_to_die[clang_type.RemoveFastQualifiers().GetOpaqueQualType()] = die;
6270 clang_type.SetHasExternalStorage (true);
Sean Callanan12014a02011-12-08 23:45:45 +00006271 }
Greg Claytonc615ce42010-11-09 04:42:43 +00006272 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006273
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006274 }
6275 break;
6276
6277 case DW_TAG_enumeration_type:
6278 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006279 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006280 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006281
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006282 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006283
Greg Claytond88d7592010-09-15 08:33:30 +00006284 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006285 if (num_attributes > 0)
6286 {
6287 uint32_t i;
6288
6289 for (i=0; i<num_attributes; ++i)
6290 {
6291 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006292 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6293 {
6294 switch (attr)
6295 {
Greg Clayton7a345282010-11-09 23:46:37 +00006296 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6297 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6298 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006299 case DW_AT_name:
6300 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006301 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006302 break;
Greg Clayton54166af2014-11-22 01:58:59 +00006303 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006304 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
6305 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006306 case DW_AT_declaration: break; //is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006307 case DW_AT_allocated:
6308 case DW_AT_associated:
6309 case DW_AT_bit_stride:
6310 case DW_AT_byte_stride:
6311 case DW_AT_data_location:
6312 case DW_AT_description:
6313 case DW_AT_start_scope:
6314 case DW_AT_visibility:
6315 case DW_AT_specification:
6316 case DW_AT_abstract_origin:
6317 case DW_AT_sibling:
6318 break;
6319 }
6320 }
6321 }
6322
Daniel Malead01b2952012-11-29 21:49:15 +00006323 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
Greg Claytonc93237c2010-10-01 20:48:32 +00006324
Greg Clayton57ee3062013-07-11 22:46:58 +00006325 ClangASTType enumerator_clang_type;
6326 clang_type.SetClangType (ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die));
6327 if (!clang_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00006328 {
Greg Clayton5d14fc02013-03-06 06:23:54 +00006329 if (encoding_uid != DW_INVALID_OFFSET)
6330 {
6331 Type *enumerator_type = ResolveTypeUID(encoding_uid);
6332 if (enumerator_type)
6333 enumerator_clang_type = enumerator_type->GetClangFullType();
6334 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006335
Greg Clayton57ee3062013-07-11 22:46:58 +00006336 if (!enumerator_clang_type)
Greg Clayton5d14fc02013-03-06 06:23:54 +00006337 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
6338 DW_ATE_signed,
6339 byte_size * 8);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006340
Greg Claytonca512b32011-01-14 04:54:56 +00006341 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00006342 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00006343 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006344 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00006345 }
6346 else
6347 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006348 enumerator_clang_type = clang_type.GetEnumerationIntegerType ();
Greg Clayton1be10fc2010-09-29 01:12:09 +00006349 }
6350
Greg Clayton57ee3062013-07-11 22:46:58 +00006351 LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006352
Greg Clayton81c22f62011-10-19 18:09:39 +00006353 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006354 this,
6355 type_name_const_str,
6356 byte_size,
6357 NULL,
6358 encoding_uid,
6359 Type::eEncodingIsUID,
6360 &decl,
6361 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006362 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006363
Greg Clayton57ee3062013-07-11 22:46:58 +00006364 clang_type.StartTagDeclarationDefinition ();
Greg Clayton6beaaa62011-01-17 03:46:26 +00006365 if (die->HasChildren())
6366 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006367 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00006368 bool is_signed = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00006369 enumerator_clang_type.IsIntegerType(is_signed);
Greg Clayton3e067532013-03-05 23:54:39 +00006370 ParseChildEnumerators(cu_sc, clang_type, is_signed, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00006371 }
Greg Clayton57ee3062013-07-11 22:46:58 +00006372 clang_type.CompleteTagDeclarationDefinition ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006373 }
6374 }
6375 break;
6376
Jim Inghamb0be4422010-08-12 01:20:14 +00006377 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006378 case DW_TAG_subprogram:
6379 case DW_TAG_subroutine_type:
6380 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006381 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006382 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006383
Greg Clayton23f59502012-07-17 03:23:13 +00006384 //const char *mangled = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006385 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00006386 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006387 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00006388 bool is_static = false;
6389 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00006390 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00006391 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00006392 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
6393 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Jim Ingham379397632012-10-27 02:54:13 +00006394 dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00006395
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006396 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00006397 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006398
6399
Greg Claytond88d7592010-09-15 08:33:30 +00006400 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006401 if (num_attributes > 0)
6402 {
6403 uint32_t i;
6404 for (i=0; i<num_attributes; ++i)
6405 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006406 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006407 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6408 {
6409 switch (attr)
6410 {
6411 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6412 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6413 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6414 case DW_AT_name:
6415 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006416 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006417 break;
6418
Greg Clayton71415542012-12-08 00:24:40 +00006419 case DW_AT_linkage_name:
Greg Clayton23f59502012-07-17 03:23:13 +00006420 case DW_AT_MIPS_linkage_name: break; // mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00006421 case DW_AT_type: type_die_offset = form_value.Reference(); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00006422 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006423 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
6424 case DW_AT_inline: is_inline = form_value.Boolean(); break;
6425 case DW_AT_virtuality: is_virtual = form_value.Boolean(); break;
6426 case DW_AT_explicit: is_explicit = form_value.Boolean(); break;
6427 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006428
Greg Claytonf51de672010-10-01 02:31:07 +00006429
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006430 case DW_AT_external:
6431 if (form_value.Unsigned())
6432 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00006433 if (storage == clang::SC_None)
6434 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006435 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00006436 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006437 }
6438 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006439
Greg Clayton72da3972011-08-16 18:40:23 +00006440 case DW_AT_specification:
Greg Clayton54166af2014-11-22 01:58:59 +00006441 specification_die_offset = form_value.Reference();
Greg Clayton72da3972011-08-16 18:40:23 +00006442 break;
6443
6444 case DW_AT_abstract_origin:
Greg Clayton54166af2014-11-22 01:58:59 +00006445 abstract_origin_die_offset = form_value.Reference();
Greg Clayton72da3972011-08-16 18:40:23 +00006446 break;
6447
Jim Ingham379397632012-10-27 02:54:13 +00006448 case DW_AT_object_pointer:
Greg Clayton54166af2014-11-22 01:58:59 +00006449 object_pointer_die_offset = form_value.Reference();
Jim Ingham379397632012-10-27 02:54:13 +00006450 break;
6451
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006452 case DW_AT_allocated:
6453 case DW_AT_associated:
6454 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006455 case DW_AT_calling_convention:
6456 case DW_AT_data_location:
6457 case DW_AT_elemental:
6458 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006459 case DW_AT_frame_base:
6460 case DW_AT_high_pc:
6461 case DW_AT_low_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006462 case DW_AT_prototyped:
6463 case DW_AT_pure:
6464 case DW_AT_ranges:
6465 case DW_AT_recursive:
6466 case DW_AT_return_addr:
6467 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006468 case DW_AT_start_scope:
6469 case DW_AT_static_link:
6470 case DW_AT_trampoline:
6471 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006472 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006473 case DW_AT_description:
6474 case DW_AT_sibling:
6475 break;
6476 }
6477 }
6478 }
Greg Clayton24739922010-10-13 03:15:28 +00006479 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006480
Jim Ingham379397632012-10-27 02:54:13 +00006481 std::string object_pointer_name;
6482 if (object_pointer_die_offset != DW_INVALID_OFFSET)
6483 {
6484 // Get the name from the object pointer die
6485 StreamString s;
6486 if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s))
6487 {
6488 object_pointer_name.assign(s.GetData());
6489 }
6490 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006491
Daniel Malead01b2952012-11-29 21:49:15 +00006492 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
Greg Claytonc93237c2010-10-01 20:48:32 +00006493
Greg Clayton57ee3062013-07-11 22:46:58 +00006494 ClangASTType return_clang_type;
Greg Clayton24739922010-10-13 03:15:28 +00006495 Type *func_type = NULL;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006496
Greg Clayton24739922010-10-13 03:15:28 +00006497 if (type_die_offset != DW_INVALID_OFFSET)
6498 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00006499
Greg Clayton24739922010-10-13 03:15:28 +00006500 if (func_type)
Greg Clayton42ce2f32011-12-12 21:50:19 +00006501 return_clang_type = func_type->GetClangForwardType();
Greg Clayton24739922010-10-13 03:15:28 +00006502 else
Greg Clayton57ee3062013-07-11 22:46:58 +00006503 return_clang_type = ast.GetBasicType(eBasicTypeVoid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006504
Greg Claytonf51de672010-10-01 02:31:07 +00006505
Greg Clayton57ee3062013-07-11 22:46:58 +00006506 std::vector<ClangASTType> function_param_types;
Greg Clayton24739922010-10-13 03:15:28 +00006507 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006508
Greg Clayton24739922010-10-13 03:15:28 +00006509 // Parse the function children for the parameters
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006510
Greg Claytoncb5860a2011-10-13 23:49:28 +00006511 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
6512 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00006513 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
6514
Greg Claytonf0705c82011-10-22 03:33:13 +00006515 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00006516 // Start off static. This will be set to false in ParseChildParameters(...)
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00006517 // if we find a "this" parameters as the first parameter
Greg Clayton5113dc82011-08-12 06:47:54 +00006518 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00006519 is_static = true;
Greg Claytond20deac2014-04-04 18:15:18 +00006520
Greg Clayton24739922010-10-13 03:15:28 +00006521 if (die->HasChildren())
6522 {
Greg Clayton0fffff52010-09-24 05:15:53 +00006523 bool skip_artificial = true;
Jim Ingham379397632012-10-27 02:54:13 +00006524 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00006525 containing_decl_ctx,
Jim Ingham379397632012-10-27 02:54:13 +00006526 dwarf_cu,
6527 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00006528 skip_artificial,
6529 is_static,
Greg Clayton03969752014-02-24 18:53:11 +00006530 is_variadic,
Jim Ingham379397632012-10-27 02:54:13 +00006531 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00006532 function_param_decls,
Greg Claytond20deac2014-04-04 18:15:18 +00006533 type_quals);
Greg Clayton24739922010-10-13 03:15:28 +00006534 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006535
Greg Clayton24739922010-10-13 03:15:28 +00006536 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006537 clang_type = ast.CreateFunctionType (return_clang_type,
Greg Clayton9cb25c42012-10-30 17:02:18 +00006538 function_param_types.data(),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006539 function_param_types.size(),
6540 is_variadic,
6541 type_quals);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006542
Sean Callanande9ce872013-05-09 23:13:13 +00006543 bool ignore_containing_context = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006544
Greg Clayton24739922010-10-13 03:15:28 +00006545 if (type_name_cstr)
6546 {
6547 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00006548 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006549 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00006550 ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true);
6551 if (objc_method.IsValid(true))
Greg Clayton0fffff52010-09-24 05:15:53 +00006552 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006553 ClangASTType class_opaque_type;
Greg Clayton1b3815c2013-01-30 00:18:29 +00006554 ConstString class_name(objc_method.GetClassName());
Greg Clayton7c810422012-01-18 23:40:49 +00006555 if (class_name)
Greg Clayton0fffff52010-09-24 05:15:53 +00006556 {
Greg Clayton278a16b2012-01-19 00:52:59 +00006557 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
Greg Claytonc7f03b62012-01-12 04:33:28 +00006558
6559 if (complete_objc_class_type_sp)
Greg Clayton0fffff52010-09-24 05:15:53 +00006560 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006561 ClangASTType type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
6562 if (type_clang_forward_type.IsObjCObjectOrInterfaceType ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00006563 class_opaque_type = type_clang_forward_type;
Greg Clayton0fffff52010-09-24 05:15:53 +00006564 }
Greg Clayton24739922010-10-13 03:15:28 +00006565 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006566
Greg Clayton24739922010-10-13 03:15:28 +00006567 if (class_opaque_type)
6568 {
6569 // If accessibility isn't set to anything valid, assume public for
6570 // now...
6571 if (accessibility == eAccessNone)
6572 accessibility = eAccessPublic;
6573
Greg Clayton57ee3062013-07-11 22:46:58 +00006574 clang::ObjCMethodDecl *objc_method_decl = class_opaque_type.AddMethodToObjCObjectType (type_name_cstr,
6575 clang_type,
6576 accessibility,
6577 is_artificial);
Greg Clayton24739922010-10-13 03:15:28 +00006578 type_handled = objc_method_decl != NULL;
Sean Callanan464a5b52012-10-04 22:06:29 +00006579 if (type_handled)
6580 {
6581 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Claytond0029442013-03-27 01:48:02 +00006582 GetClangASTContext().SetMetadataAsUserID (objc_method_decl, MakeUserID(die->GetOffset()));
Sean Callanan464a5b52012-10-04 22:06:29 +00006583 }
Sean Callananc3a1d562013-02-06 23:21:59 +00006584 else
6585 {
Jason Molendac1a65832013-03-07 22:44:42 +00006586 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",
Sean Callananc3a1d562013-02-06 23:21:59 +00006587 die->GetOffset(),
6588 tag,
6589 DW_TAG_value_to_name(tag));
6590 }
Greg Clayton24739922010-10-13 03:15:28 +00006591 }
6592 }
Greg Clayton5113dc82011-08-12 06:47:54 +00006593 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00006594 {
6595 // Look at the parent of this DIE and see if is is
6596 // a class or struct and see if this is actually a
6597 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00006598 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00006599 if (class_type)
6600 {
Greg Clayton4116e932012-05-15 02:33:01 +00006601 if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset()))
6602 {
6603 // We uniqued the parent class of this function to another class
6604 // so we now need to associate all dies under "decl_ctx_die" to
6605 // DIEs in the DIE for "class_type"...
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006606 SymbolFileDWARF *class_symfile = NULL;
Greg Clayton4116e932012-05-15 02:33:01 +00006607 DWARFCompileUnitSP class_type_cu_sp;
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006608 const DWARFDebugInfoEntry *class_type_die = NULL;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006609
Sean Callanan2367f8a2013-02-26 01:12:25 +00006610 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
6611 if (debug_map_symfile)
6612 {
6613 class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID()));
6614 class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6615 }
6616 else
6617 {
6618 class_symfile = this;
6619 class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6620 }
Greg Clayton4116e932012-05-15 02:33:01 +00006621 if (class_type_die)
6622 {
Greg Claytond20deac2014-04-04 18:15:18 +00006623 DWARFDIECollection failures;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006624
Sean Callanan2367f8a2013-02-26 01:12:25 +00006625 CopyUniqueClassMethodTypes (class_symfile,
6626 class_type,
6627 class_type_cu_sp.get(),
6628 class_type_die,
6629 dwarf_cu,
6630 decl_ctx_die,
6631 failures);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006632
Sean Callanan2367f8a2013-02-26 01:12:25 +00006633 // FIXME do something with these failures that's smarter than
6634 // just dropping them on the ground. Unfortunately classes don't
6635 // like having stuff added to them after their definitions are
6636 // complete...
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006637
Sean Callanan2367f8a2013-02-26 01:12:25 +00006638 type_ptr = m_die_to_type[die];
6639 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton4116e932012-05-15 02:33:01 +00006640 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006641 type_sp = type_ptr->shared_from_this();
6642 break;
Greg Clayton4116e932012-05-15 02:33:01 +00006643 }
6644 }
6645 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006646
Greg Clayton72da3972011-08-16 18:40:23 +00006647 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00006648 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006649 // We have a specification which we are going to base our function
6650 // prototype off of, so we need this type to be completed so that the
6651 // m_die_to_decl_ctx for the method in the specification has a valid
6652 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006653 class_type->GetClangForwardType();
Greg Clayton72da3972011-08-16 18:40:23 +00006654 // If we have a specification, then the function type should have been
6655 // made with the specification and not with this die.
6656 DWARFCompileUnitSP spec_cu_sp;
6657 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006658 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006659 if (spec_clang_decl_ctx)
6660 {
6661 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
6662 }
6663 else
Jim Inghamc1663042011-09-29 22:12:35 +00006664 {
Daniel Malead01b2952012-11-29 21:49:15 +00006665 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8x) has no decl\n",
Greg Claytone38a5ed2012-01-05 03:57:59 +00006666 MakeUserID(die->GetOffset()),
6667 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006668 }
Greg Clayton72da3972011-08-16 18:40:23 +00006669 type_handled = true;
6670 }
6671 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
6672 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006673 // We have a specification which we are going to base our function
6674 // prototype off of, so we need this type to be completed so that the
6675 // m_die_to_decl_ctx for the method in the abstract origin has a valid
6676 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006677 class_type->GetClangForwardType();
Greg Clayton5cf58b92011-10-05 22:22:08 +00006678
Greg Clayton72da3972011-08-16 18:40:23 +00006679 DWARFCompileUnitSP abs_cu_sp;
6680 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006681 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006682 if (abs_clang_decl_ctx)
6683 {
6684 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
6685 }
6686 else
Jim Inghamc1663042011-09-29 22:12:35 +00006687 {
Daniel Malead01b2952012-11-29 21:49:15 +00006688 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_abstract_origin(0x%8.8x) has no decl\n",
Greg Claytone38a5ed2012-01-05 03:57:59 +00006689 MakeUserID(die->GetOffset()),
6690 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006691 }
Greg Clayton72da3972011-08-16 18:40:23 +00006692 type_handled = true;
6693 }
6694 else
6695 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006696 ClangASTType class_opaque_type = class_type->GetClangForwardType();
6697 if (class_opaque_type.IsCXXClassType ())
Greg Clayton931180e2011-01-27 06:44:37 +00006698 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006699 if (class_opaque_type.IsBeingDefined ())
Greg Clayton72da3972011-08-16 18:40:23 +00006700 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006701 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
6702 // in the DWARF for C++ methods... Default to public for now...
6703 if (accessibility == eAccessNone)
6704 accessibility = eAccessPublic;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006705
Greg Clayton20568dd2011-10-13 23:13:20 +00006706 if (!is_static && !die->HasChildren())
6707 {
6708 // We have a C++ member function with no children (this pointer!)
6709 // and clang will get mad if we try and make a function that isn't
6710 // well formed in the DWARF, so we will just skip it...
6711 type_handled = true;
6712 }
6713 else
6714 {
6715 clang::CXXMethodDecl *cxx_method_decl;
6716 // REMOVE THE CRASH DESCRIPTION BELOW
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00006717 Host::SetCrashDescriptionWithFormat ("SymbolFileDWARF::ParseType() is adding a method %s to class %s in DIE 0x%8.8" PRIx64 " from %s",
Greg Clayton20568dd2011-10-13 23:13:20 +00006718 type_name_cstr,
6719 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00006720 MakeUserID(die->GetOffset()),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00006721 m_obj_file->GetFileSpec().GetPath().c_str());
Greg Clayton20568dd2011-10-13 23:13:20 +00006722
Sean Callananc1b732d2011-11-01 18:07:13 +00006723 const bool is_attr_used = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006724
Greg Clayton57ee3062013-07-11 22:46:58 +00006725 cxx_method_decl = class_opaque_type.AddMethodToCXXRecordType (type_name_cstr,
6726 clang_type,
6727 accessibility,
6728 is_virtual,
6729 is_static,
6730 is_inline,
6731 is_explicit,
6732 is_attr_used,
6733 is_artificial);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006734
Greg Clayton20568dd2011-10-13 23:13:20 +00006735 type_handled = cxx_method_decl != NULL;
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006736
6737 if (type_handled)
Jim Ingham379397632012-10-27 02:54:13 +00006738 {
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006739 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
6740
6741 Host::SetCrashDescription (NULL);
6742
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006743
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006744 ClangASTMetadata metadata;
6745 metadata.SetUserID(MakeUserID(die->GetOffset()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006746
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006747 if (!object_pointer_name.empty())
6748 {
6749 metadata.SetObjectPtrName(object_pointer_name.c_str());
6750 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006751 log->Printf ("Setting object pointer name: %s on method object %p.\n",
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006752 object_pointer_name.c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006753 static_cast<void*>(cxx_method_decl));
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006754 }
Greg Claytond0029442013-03-27 01:48:02 +00006755 GetClangASTContext().SetMetadata (cxx_method_decl, metadata);
Jim Ingham379397632012-10-27 02:54:13 +00006756 }
Sean Callananb0640dc2013-04-09 23:22:08 +00006757 else
6758 {
Sean Callanande9ce872013-05-09 23:13:13 +00006759 ignore_containing_context = true;
Sean Callananb0640dc2013-04-09 23:22:08 +00006760 }
Greg Clayton20568dd2011-10-13 23:13:20 +00006761 }
Greg Clayton72da3972011-08-16 18:40:23 +00006762 }
6763 else
6764 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006765 // We were asked to parse the type for a method in a class, yet the
6766 // class hasn't been asked to complete itself through the
6767 // clang::ExternalASTSource protocol, so we need to just have the
6768 // class complete itself and do things the right way, then our
6769 // DIE should then have an entry in the m_die_to_type map. First
6770 // we need to modify the m_die_to_type so it doesn't think we are
6771 // trying to parse this DIE anymore...
6772 m_die_to_type[die] = NULL;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006773
Greg Clayton20568dd2011-10-13 23:13:20 +00006774 // Now we get the full type to force our class type to complete itself
6775 // using the clang::ExternalASTSource protocol which will parse all
6776 // base classes and all methods (including the method for this DIE).
6777 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00006778
Greg Clayton20568dd2011-10-13 23:13:20 +00006779 // The type for this DIE should have been filled in the function call above
6780 type_ptr = m_die_to_type[die];
Greg Claytone5476db2012-06-01 20:32:35 +00006781 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton20568dd2011-10-13 23:13:20 +00006782 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006783 type_sp = type_ptr->shared_from_this();
Greg Clayton20568dd2011-10-13 23:13:20 +00006784 break;
6785 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006786
Sean Callanan02eee4d2012-04-12 23:10:00 +00006787 // FIXME This is fixing some even uglier behavior but we really need to
6788 // uniq the methods of each class as well as the class itself.
6789 // <rdar://problem/11240464>
6790 type_handled = true;
Greg Clayton72da3972011-08-16 18:40:23 +00006791 }
Greg Clayton931180e2011-01-27 06:44:37 +00006792 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006793 }
6794 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006795 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006796 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006797
Greg Clayton24739922010-10-13 03:15:28 +00006798 if (!type_handled)
6799 {
6800 // We just have a function that isn't part of a class
Sean Callanande9ce872013-05-09 23:13:13 +00006801 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (ignore_containing_context ? GetClangASTContext().GetTranslationUnitDecl() : containing_decl_ctx,
Greg Clayton147e1fa2011-10-14 22:47:18 +00006802 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006803 clang_type,
6804 storage,
6805 is_inline);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006806
6807// if (template_param_infos.GetSize() > 0)
6808// {
6809// clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
6810// function_decl,
6811// type_name_cstr,
6812// template_param_infos);
6813//
6814// ast.CreateFunctionTemplateSpecializationInfo (function_decl,
6815// func_template_decl,
6816// template_param_infos);
6817// }
Greg Clayton24739922010-10-13 03:15:28 +00006818 // Add the decl to our DIE to decl context map
6819 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00006820 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00006821 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006822 ast.SetFunctionParameters (function_decl,
6823 &function_param_decls.front(),
6824 function_param_decls.size());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006825
Jim Ingham379397632012-10-27 02:54:13 +00006826 ClangASTMetadata metadata;
6827 metadata.SetUserID(MakeUserID(die->GetOffset()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006828
Jim Ingham379397632012-10-27 02:54:13 +00006829 if (!object_pointer_name.empty())
6830 {
6831 metadata.SetObjectPtrName(object_pointer_name.c_str());
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006832 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006833 log->Printf ("Setting object pointer name: %s on function object %p.",
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006834 object_pointer_name.c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006835 static_cast<void*>(function_decl));
Jim Ingham379397632012-10-27 02:54:13 +00006836 }
Greg Claytond0029442013-03-27 01:48:02 +00006837 GetClangASTContext().SetMetadata (function_decl, metadata);
Greg Clayton24739922010-10-13 03:15:28 +00006838 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006839 }
Greg Clayton81c22f62011-10-19 18:09:39 +00006840 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006841 this,
6842 type_name_const_str,
6843 0,
6844 NULL,
6845 LLDB_INVALID_UID,
6846 Type::eEncodingIsUID,
6847 &decl,
6848 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006849 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00006850 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006851 }
6852 break;
6853
6854 case DW_TAG_array_type:
6855 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006856 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006857 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006858
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006859 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006860 int64_t first_index = 0;
6861 uint32_t byte_stride = 0;
6862 uint32_t bit_stride = 0;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006863 bool is_vector = false;
Greg Claytond88d7592010-09-15 08:33:30 +00006864 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006865
6866 if (num_attributes > 0)
6867 {
6868 uint32_t i;
6869 for (i=0; i<num_attributes; ++i)
6870 {
6871 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006872 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6873 {
6874 switch (attr)
6875 {
6876 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6877 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6878 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6879 case DW_AT_name:
6880 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006881 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006882 break;
6883
Greg Clayton54166af2014-11-22 01:58:59 +00006884 case DW_AT_type: type_die_offset = form_value.Reference(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006885 case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006886 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
6887 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006888 case DW_AT_GNU_vector: is_vector = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006889 case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006890 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006891 case DW_AT_allocated:
6892 case DW_AT_associated:
6893 case DW_AT_data_location:
6894 case DW_AT_description:
6895 case DW_AT_ordering:
6896 case DW_AT_start_scope:
6897 case DW_AT_visibility:
6898 case DW_AT_specification:
6899 case DW_AT_abstract_origin:
6900 case DW_AT_sibling:
6901 break;
6902 }
6903 }
6904 }
6905
Daniel Malead01b2952012-11-29 21:49:15 +00006906 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
Greg Claytonc93237c2010-10-01 20:48:32 +00006907
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006908 Type *element_type = ResolveTypeUID(type_die_offset);
6909
6910 if (element_type)
6911 {
6912 std::vector<uint64_t> element_orders;
6913 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
6914 if (byte_stride == 0 && bit_stride == 0)
6915 byte_stride = element_type->GetByteSize();
Greg Clayton57ee3062013-07-11 22:46:58 +00006916 ClangASTType array_element_type = element_type->GetClangForwardType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006917 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
Siva Chandra89ce9552015-01-05 23:06:14 +00006918 if (element_orders.size() > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006919 {
Siva Chandra89ce9552015-01-05 23:06:14 +00006920 uint64_t num_elements = 0;
6921 std::vector<uint64_t>::const_reverse_iterator pos;
6922 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
6923 for (pos = element_orders.rbegin(); pos != end; ++pos)
6924 {
6925 num_elements = *pos;
6926 clang_type = ast.CreateArrayType (array_element_type,
6927 num_elements,
6928 is_vector);
6929 array_element_type = clang_type;
6930 array_element_bit_stride = num_elements ?
6931 array_element_bit_stride * num_elements :
6932 array_element_bit_stride;
6933 }
6934 }
6935 else
6936 {
6937 clang_type = ast.CreateArrayType (array_element_type, 0, is_vector);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006938 }
6939 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00006940 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006941 this,
6942 empty_name,
6943 array_element_bit_stride / 8,
6944 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00006945 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006946 Type::eEncodingIsUID,
6947 &decl,
6948 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006949 Type::eResolveStateFull));
6950 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006951 }
6952 }
6953 }
6954 break;
6955
Greg Clayton9b81a312010-06-12 01:20:30 +00006956 case DW_TAG_ptr_to_member_type:
6957 {
6958 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
6959 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
6960
Greg Claytond88d7592010-09-15 08:33:30 +00006961 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006962
Greg Clayton9b81a312010-06-12 01:20:30 +00006963 if (num_attributes > 0) {
6964 uint32_t i;
6965 for (i=0; i<num_attributes; ++i)
6966 {
6967 attr = attributes.AttributeAtIndex(i);
Greg Clayton9b81a312010-06-12 01:20:30 +00006968 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6969 {
6970 switch (attr)
6971 {
6972 case DW_AT_type:
Greg Clayton54166af2014-11-22 01:58:59 +00006973 type_die_offset = form_value.Reference(); break;
Greg Clayton9b81a312010-06-12 01:20:30 +00006974 case DW_AT_containing_type:
Greg Clayton54166af2014-11-22 01:58:59 +00006975 containing_type_die_offset = form_value.Reference(); break;
Greg Clayton9b81a312010-06-12 01:20:30 +00006976 }
6977 }
6978 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006979
Greg Clayton9b81a312010-06-12 01:20:30 +00006980 Type *pointee_type = ResolveTypeUID(type_die_offset);
6981 Type *class_type = ResolveTypeUID(containing_type_die_offset);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006982
Greg Clayton57ee3062013-07-11 22:46:58 +00006983 ClangASTType pointee_clang_type = pointee_type->GetClangForwardType();
6984 ClangASTType class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00006985
Greg Clayton57ee3062013-07-11 22:46:58 +00006986 clang_type = pointee_clang_type.CreateMemberPointerType(class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00006987
Enrico Granata1cd5e922015-01-28 00:07:51 +00006988 byte_size = clang_type.GetByteSize(nullptr);
Greg Clayton9b81a312010-06-12 01:20:30 +00006989
Greg Clayton81c22f62011-10-19 18:09:39 +00006990 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006991 this,
6992 type_name_const_str,
6993 byte_size,
6994 NULL,
6995 LLDB_INVALID_UID,
6996 Type::eEncodingIsUID,
6997 NULL,
6998 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006999 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00007000 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007001
Greg Clayton9b81a312010-06-12 01:20:30 +00007002 break;
7003 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007004 default:
Greg Clayton84afacd2012-11-07 23:09:32 +00007005 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",
7006 die->GetOffset(),
7007 tag,
7008 DW_TAG_value_to_name(tag));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007009 break;
7010 }
7011
7012 if (type_sp.get())
7013 {
7014 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7015 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7016
7017 SymbolContextScope * symbol_context_scope = NULL;
7018 if (sc_parent_tag == DW_TAG_compile_unit)
7019 {
7020 symbol_context_scope = sc.comp_unit;
7021 }
Jason Molenda60db6e42014-10-16 01:40:16 +00007022 else if (sc.function != NULL && sc_parent_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007023 {
Greg Clayton81c22f62011-10-19 18:09:39 +00007024 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007025 if (symbol_context_scope == NULL)
7026 symbol_context_scope = sc.function;
7027 }
7028
7029 if (symbol_context_scope != NULL)
7030 {
7031 type_sp->SetSymbolContextScope(symbol_context_scope);
7032 }
7033
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00007034 // We are ready to put this type into the uniqued list up at the module level
7035 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00007036
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00007037 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007038 }
7039 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00007040 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007041 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00007042 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007043 }
7044 }
7045 return type_sp;
7046}
7047
7048size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00007049SymbolFileDWARF::ParseTypes
7050(
7051 const SymbolContext& sc,
7052 DWARFCompileUnit* dwarf_cu,
7053 const DWARFDebugInfoEntry *die,
7054 bool parse_siblings,
7055 bool parse_children
7056)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007057{
7058 size_t types_added = 0;
7059 while (die != NULL)
7060 {
7061 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00007062 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007063 {
7064 if (type_is_new)
7065 ++types_added;
7066 }
7067
7068 if (parse_children && die->HasChildren())
7069 {
7070 if (die->Tag() == DW_TAG_subprogram)
7071 {
7072 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00007073 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007074 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
7075 }
7076 else
7077 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
7078 }
7079
7080 if (parse_siblings)
7081 die = die->GetSibling();
7082 else
7083 die = NULL;
7084 }
7085 return types_added;
7086}
7087
7088
7089size_t
7090SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
7091{
7092 assert(sc.comp_unit && sc.function);
7093 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00007094 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007095 if (dwarf_cu)
7096 {
7097 dw_offset_t function_die_offset = sc.function->GetID();
7098 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
7099 if (function_die)
7100 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00007101 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007102 }
7103 }
7104
7105 return functions_added;
7106}
7107
7108
7109size_t
7110SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
7111{
7112 // At least a compile unit must be valid
7113 assert(sc.comp_unit);
7114 size_t types_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00007115 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007116 if (dwarf_cu)
7117 {
7118 if (sc.function)
7119 {
7120 dw_offset_t function_die_offset = sc.function->GetID();
7121 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
7122 if (func_die && func_die->HasChildren())
7123 {
7124 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
7125 }
7126 }
7127 else
7128 {
7129 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
7130 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
7131 {
7132 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
7133 }
7134 }
7135 }
7136
7137 return types_added;
7138}
7139
7140size_t
7141SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
7142{
7143 if (sc.comp_unit != NULL)
7144 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00007145 DWARFDebugInfo* info = DebugInfo();
7146 if (info == NULL)
7147 return 0;
7148
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007149 if (sc.function)
7150 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007151 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get();
7152
7153 if (dwarf_cu == NULL)
7154 return 0;
7155
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007156 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00007157
Greg Claytonc7bece562013-01-25 18:06:21 +00007158 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
7159 if (func_lo_pc != LLDB_INVALID_ADDRESS)
Greg Claytone38a5ed2012-01-05 03:57:59 +00007160 {
7161 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00007162
Greg Claytone38a5ed2012-01-05 03:57:59 +00007163 // Let all blocks know they have parse all their variables
7164 sc.function->GetBlock (false).SetDidParseVariables (true, true);
7165 return num_variables;
7166 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007167 }
7168 else if (sc.comp_unit)
7169 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007170 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get();
7171
7172 if (dwarf_cu == NULL)
7173 return 0;
7174
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007175 uint32_t vars_added = 0;
7176 VariableListSP variables (sc.comp_unit->GetVariableList(false));
7177
7178 if (variables.get() == NULL)
7179 {
7180 variables.reset(new VariableList());
7181 sc.comp_unit->SetVariableList(variables);
7182
Greg Claytond4a2b372011-09-12 23:21:58 +00007183 DWARFCompileUnit* match_dwarf_cu = NULL;
7184 const DWARFDebugInfoEntry* die = NULL;
7185 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00007186 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00007187 {
Greg Clayton97fbc342011-10-20 22:30:33 +00007188 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00007189 {
7190 DWARFMappedHash::DIEInfoArray hash_data_array;
7191 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
7192 dwarf_cu->GetNextCompileUnitOffset(),
7193 hash_data_array))
7194 {
7195 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
7196 }
7197 }
Greg Clayton7f995132011-10-04 22:41:51 +00007198 }
7199 else
7200 {
7201 // Index if we already haven't to make sure the compile units
7202 // get indexed and make their global DIE index list
7203 if (!m_indexed)
7204 Index ();
7205
7206 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
7207 dwarf_cu->GetNextCompileUnitOffset(),
7208 die_offsets);
7209 }
7210
7211 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00007212 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007213 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007214 DWARFDebugInfo* debug_info = DebugInfo();
7215 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007216 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007217 const dw_offset_t die_offset = die_offsets[i];
7218 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00007219 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00007220 {
Greg Clayton95d87902011-11-11 03:16:25 +00007221 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
7222 if (var_sp)
7223 {
7224 variables->AddVariableIfUnique (var_sp);
7225 ++vars_added;
7226 }
Greg Claytond4a2b372011-09-12 23:21:58 +00007227 }
Greg Clayton95d87902011-11-11 03:16:25 +00007228 else
7229 {
7230 if (m_using_apple_tables)
7231 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00007232 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x)\n", die_offset);
Greg Clayton95d87902011-11-11 03:16:25 +00007233 }
7234 }
7235
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007236 }
7237 }
7238 }
7239 return vars_added;
7240 }
7241 }
7242 return 0;
7243}
7244
7245
7246VariableSP
7247SymbolFileDWARF::ParseVariableDIE
7248(
7249 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007250 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007251 const DWARFDebugInfoEntry *die,
7252 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007253)
7254{
Greg Clayton83c5cd92010-11-14 22:13:40 +00007255 VariableSP var_sp (m_die_to_variable_sp[die]);
7256 if (var_sp)
7257 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007258
7259 const dw_tag_t tag = die->Tag();
Richard Mitton0a558352013-10-17 21:14:00 +00007260 ModuleSP module = GetObjectFile()->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00007261
7262 if ((tag == DW_TAG_variable) ||
7263 (tag == DW_TAG_constant) ||
7264 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007265 {
Greg Clayton7f995132011-10-04 22:41:51 +00007266 DWARFDebugInfoEntry::Attributes attributes;
7267 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
7268 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007269 {
Greg Clayton7f995132011-10-04 22:41:51 +00007270 const char *name = NULL;
7271 const char *mangled = NULL;
7272 Declaration decl;
7273 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00007274 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00007275 DWARFExpression location;
7276 bool is_external = false;
7277 bool is_artificial = false;
7278 bool location_is_const_value_data = false;
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007279 bool has_explicit_location = false;
Enrico Granata4ec130d2014-08-11 19:16:35 +00007280 DWARFFormValue const_value;
Greg Clayton23f59502012-07-17 03:23:13 +00007281 //AccessType accessibility = eAccessNone;
Greg Clayton7f995132011-10-04 22:41:51 +00007282
7283 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007284 {
Greg Clayton7f995132011-10-04 22:41:51 +00007285 dw_attr_t attr = attributes.AttributeAtIndex(i);
7286 DWARFFormValue form_value;
Greg Clayton54166af2014-11-22 01:58:59 +00007287
Greg Clayton7f995132011-10-04 22:41:51 +00007288 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007289 {
Greg Clayton7f995132011-10-04 22:41:51 +00007290 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007291 {
Greg Clayton7f995132011-10-04 22:41:51 +00007292 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
7293 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
7294 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
7295 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton71415542012-12-08 00:24:40 +00007296 case DW_AT_linkage_name:
Greg Clayton7f995132011-10-04 22:41:51 +00007297 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00007298 case DW_AT_type: type_uid = form_value.Reference(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00007299 case DW_AT_external: is_external = form_value.Boolean(); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007300 case DW_AT_const_value:
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007301 // If we have already found a DW_AT_location attribute, ignore this attribute.
7302 if (!has_explicit_location)
7303 {
7304 location_is_const_value_data = true;
7305 // The constant value will be either a block, a data value or a string.
Ed Masteeeae7212013-10-24 20:43:47 +00007306 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007307 if (DWARFFormValue::IsBlockForm(form_value.Form()))
7308 {
7309 // Retrieve the value as a block expression.
7310 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7311 uint32_t block_length = form_value.Unsigned();
Richard Mitton0a558352013-10-17 21:14:00 +00007312 location.CopyOpcodeData(module, debug_info_data, block_offset, block_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007313 }
7314 else if (DWARFFormValue::IsDataForm(form_value.Form()))
7315 {
7316 // Retrieve the value as a data expression.
Greg Clayton54166af2014-11-22 01:58:59 +00007317 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (attributes.CompileUnitAtIndex(i)->GetAddressByteSize(), attributes.CompileUnitAtIndex(i)->IsDWARF64());
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007318 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7319 uint32_t data_length = fixed_form_sizes[form_value.Form()];
Enrico Granata4ec130d2014-08-11 19:16:35 +00007320 if (data_length == 0)
7321 {
7322 const uint8_t *data_pointer = form_value.BlockData();
7323 if (data_pointer)
7324 {
Jason Molenda18f5fd32014-10-16 07:52:17 +00007325 form_value.Unsigned();
Enrico Granata4ec130d2014-08-11 19:16:35 +00007326 }
7327 else if (DWARFFormValue::IsDataForm(form_value.Form()))
7328 {
7329 // we need to get the byte size of the type later after we create the variable
7330 const_value = form_value;
7331 }
7332 }
7333 else
7334 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007335 }
7336 else
7337 {
7338 // Retrieve the value as a string expression.
7339 if (form_value.Form() == DW_FORM_strp)
7340 {
Greg Clayton54166af2014-11-22 01:58:59 +00007341 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (attributes.CompileUnitAtIndex(i)->GetAddressByteSize(), attributes.CompileUnitAtIndex(i)->IsDWARF64());
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007342 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7343 uint32_t data_length = fixed_form_sizes[form_value.Form()];
Richard Mitton0a558352013-10-17 21:14:00 +00007344 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007345 }
7346 else
7347 {
7348 const char *str = form_value.AsCString(&debug_info_data);
7349 uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart();
7350 uint32_t string_length = strlen(str) + 1;
Richard Mitton0a558352013-10-17 21:14:00 +00007351 location.CopyOpcodeData(module, debug_info_data, string_offset, string_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007352 }
7353 }
7354 }
7355 break;
Greg Clayton7f995132011-10-04 22:41:51 +00007356 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007357 {
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007358 location_is_const_value_data = false;
7359 has_explicit_location = true;
Greg Clayton7f995132011-10-04 22:41:51 +00007360 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007361 {
Ed Masteeeae7212013-10-24 20:43:47 +00007362 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Clayton7f995132011-10-04 22:41:51 +00007363
7364 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7365 uint32_t block_length = form_value.Unsigned();
Richard Mitton0a558352013-10-17 21:14:00 +00007366 location.CopyOpcodeData(module, get_debug_info_data(), block_offset, block_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007367 }
7368 else
7369 {
Ed Masteeeae7212013-10-24 20:43:47 +00007370 const DWARFDataExtractor& debug_loc_data = get_debug_loc_data();
Greg Clayton7f995132011-10-04 22:41:51 +00007371 const dw_offset_t debug_loc_offset = form_value.Unsigned();
7372
7373 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
7374 if (loc_list_length > 0)
7375 {
Richard Mitton0a558352013-10-17 21:14:00 +00007376 location.CopyOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007377 assert (func_low_pc != LLDB_INVALID_ADDRESS);
Greg Clayton54166af2014-11-22 01:58:59 +00007378 location.SetLocationListSlide (func_low_pc - attributes.CompileUnitAtIndex(i)->GetBaseAddress());
Greg Clayton7f995132011-10-04 22:41:51 +00007379 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007380 }
7381 }
Greg Clayton7f995132011-10-04 22:41:51 +00007382 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007383
Greg Clayton1c8ef472013-04-05 23:27:21 +00007384 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00007385 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007386 case DW_AT_declaration:
7387 case DW_AT_description:
7388 case DW_AT_endianity:
7389 case DW_AT_segment:
7390 case DW_AT_start_scope:
7391 case DW_AT_visibility:
7392 default:
7393 case DW_AT_abstract_origin:
7394 case DW_AT_sibling:
7395 case DW_AT_specification:
7396 break;
7397 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007398 }
7399 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007400
Greg Clayton9e9f2192013-05-17 00:55:28 +00007401 ValueType scope = eValueTypeInvalid;
7402
7403 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7404 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7405 SymbolContextScope * symbol_context_scope = NULL;
7406
Siva Chandra0783ab92015-03-24 18:32:27 +00007407 if (!mangled)
7408 {
7409 // LLDB relies on the mangled name (DW_TAG_linkage_name or DW_AT_MIPS_linkage_name) to
7410 // generate fully qualified names of global variables with commands like "frame var j".
7411 // For example, if j were an int variable holding a value 4 and declared in a namespace
7412 // B which in turn is contained in a namespace A, the command "frame var j" returns
7413 // "(int) A::B::j = 4". If the compiler does not emit a linkage name, we should be able
7414 // to generate a fully qualified name from the declaration context.
7415 if (die->GetParent()->Tag() == DW_TAG_compile_unit &&
7416 LanguageRuntime::LanguageIsCPlusPlus(dwarf_cu->GetLanguageType()))
7417 {
7418 DWARFDeclContext decl_ctx;
7419
7420 die->GetDWARFDeclContext(this, dwarf_cu, decl_ctx);
7421 mangled = decl_ctx.GetQualifiedNameAsConstString().GetCString();
7422 }
7423 }
7424
Greg Clayton9e9f2192013-05-17 00:55:28 +00007425 // DWARF doesn't specify if a DW_TAG_variable is a local, global
7426 // or static variable, so we have to do a little digging by
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00007427 // looking at the location of a variable to see if it contains
Greg Clayton9e9f2192013-05-17 00:55:28 +00007428 // a DW_OP_addr opcode _somewhere_ in the definition. I say
7429 // somewhere because clang likes to combine small global variables
7430 // into the same symbol and have locations like:
7431 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
7432 // So if we don't have a DW_TAG_formal_parameter, we can look at
7433 // the location to see if it contains a DW_OP_addr opcode, and
7434 // then we can correctly classify our variables.
7435 if (tag == DW_TAG_formal_parameter)
7436 scope = eValueTypeVariableArgument;
7437 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007438 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007439 bool op_error = false;
7440 // Check if the location has a DW_OP_addr with any address value...
7441 lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS;
7442 if (!location_is_const_value_data)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007443 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007444 location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error);
7445 if (op_error)
Greg Clayton96c09682012-01-04 22:56:43 +00007446 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007447 StreamString strm;
7448 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
7449 GetObjectFile()->GetModule()->ReportError ("0x%8.8x: %s has an invalid location: %s", die->GetOffset(), DW_TAG_value_to_name(die->Tag()), strm.GetString().c_str());
Greg Clayton96c09682012-01-04 22:56:43 +00007450 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007451 }
Greg Claytond1767f02011-12-08 02:13:16 +00007452
Greg Clayton9e9f2192013-05-17 00:55:28 +00007453 if (location_DW_OP_addr != LLDB_INVALID_ADDRESS)
7454 {
7455 if (is_external)
7456 scope = eValueTypeVariableGlobal;
7457 else
7458 scope = eValueTypeVariableStatic;
7459
7460
7461 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile ();
7462
7463 if (debug_map_symfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007464 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007465 // When leaving the DWARF in the .o files on darwin,
7466 // when we have a global variable that wasn't initialized,
7467 // the .o file might not have allocated a virtual
7468 // address for the global variable. In this case it will
7469 // have created a symbol for the global variable
7470 // that is undefined/data and external and the value will
7471 // be the byte size of the variable. When we do the
7472 // address map in SymbolFileDWARFDebugMap we rely on
7473 // having an address, we need to do some magic here
7474 // so we can get the correct address for our global
7475 // variable. The address for all of these entries
7476 // will be zero, and there will be an undefined symbol
7477 // in this object file, and the executable will have
7478 // a matching symbol with a good address. So here we
7479 // dig up the correct address and replace it in the
7480 // location for the variable, and set the variable's
7481 // symbol context scope to be that of the main executable
7482 // so the file address will resolve correctly.
7483 bool linked_oso_file_addr = false;
7484 if (is_external && location_DW_OP_addr == 0)
Greg Clayton9422dd62013-03-04 21:46:16 +00007485 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007486 // we have a possible uninitialized extern global
7487 ConstString const_name(mangled ? mangled : name);
7488 ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile();
7489 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007490 {
Greg Clayton3046e662013-07-10 01:23:25 +00007491 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
Greg Clayton9e9f2192013-05-17 00:55:28 +00007492 if (debug_map_symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007493 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007494 Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
7495 eSymbolTypeData,
7496 Symtab::eDebugYes,
7497 Symtab::eVisibilityExtern);
7498 if (exe_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007499 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007500 if (exe_symbol->ValueIsAddress())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007501 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007502 const addr_t exe_file_addr = exe_symbol->GetAddress().GetFileAddress();
7503 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007504 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007505 if (location.Update_DW_OP_addr (exe_file_addr))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007506 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007507 linked_oso_file_addr = true;
7508 symbol_context_scope = exe_symbol;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007509 }
7510 }
7511 }
7512 }
7513 }
7514 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007515 }
Greg Clayton9422dd62013-03-04 21:46:16 +00007516
Greg Clayton9e9f2192013-05-17 00:55:28 +00007517 if (!linked_oso_file_addr)
7518 {
7519 // The DW_OP_addr is not zero, but it contains a .o file address which
7520 // needs to be linked up correctly.
7521 const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr);
7522 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton9422dd62013-03-04 21:46:16 +00007523 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007524 // Update the file address for this variable
7525 location.Update_DW_OP_addr (exe_file_addr);
7526 }
7527 else
7528 {
7529 // Variable didn't make it into the final executable
7530 return var_sp;
Greg Clayton9422dd62013-03-04 21:46:16 +00007531 }
Greg Claytond1767f02011-12-08 02:13:16 +00007532 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007533 }
Greg Clayton5cf58b92011-10-05 22:22:08 +00007534 }
7535 else
7536 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007537 scope = eValueTypeVariableLocal;
Greg Clayton5cf58b92011-10-05 22:22:08 +00007538 }
Greg Clayton7f995132011-10-04 22:41:51 +00007539 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007540
7541 if (symbol_context_scope == NULL)
7542 {
7543 switch (parent_tag)
7544 {
7545 case DW_TAG_subprogram:
7546 case DW_TAG_inlined_subroutine:
7547 case DW_TAG_lexical_block:
7548 if (sc.function)
7549 {
7550 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
7551 if (symbol_context_scope == NULL)
7552 symbol_context_scope = sc.function;
7553 }
7554 break;
7555
7556 default:
7557 symbol_context_scope = sc.comp_unit;
7558 break;
7559 }
7560 }
7561
7562 if (symbol_context_scope)
7563 {
Enrico Granata4ec130d2014-08-11 19:16:35 +00007564 SymbolFileTypeSP type_sp(new SymbolFileType(*this, type_uid));
7565
7566 if (const_value.Form() && type_sp && type_sp->GetType())
7567 location.CopyOpcodeData(const_value.Unsigned(), type_sp->GetType()->GetByteSize(), dwarf_cu->GetAddressByteSize());
7568
Greg Clayton9e9f2192013-05-17 00:55:28 +00007569 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
7570 name,
7571 mangled,
Enrico Granata4ec130d2014-08-11 19:16:35 +00007572 type_sp,
Greg Clayton9e9f2192013-05-17 00:55:28 +00007573 scope,
7574 symbol_context_scope,
7575 &decl,
7576 location,
7577 is_external,
7578 is_artificial));
7579
7580 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
7581 }
7582 else
7583 {
7584 // Not ready to parse this variable yet. It might be a global
7585 // or static variable that is in a function scope and the function
7586 // in the symbol context wasn't filled in yet
7587 return var_sp;
7588 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007589 }
Greg Clayton7f995132011-10-04 22:41:51 +00007590 // Cache var_sp even if NULL (the variable was just a specification or
7591 // was missing vital information to be able to be displayed in the debugger
7592 // (missing location due to optimization, etc)) so we don't re-parse
7593 // this DIE over and over later...
7594 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007595 }
7596 return var_sp;
7597}
7598
Greg Claytonc662ec82011-06-17 22:10:16 +00007599
7600const DWARFDebugInfoEntry *
7601SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
7602 dw_offset_t spec_block_die_offset,
7603 DWARFCompileUnit **result_die_cu_handle)
7604{
7605 // Give the concrete function die specified by "func_die_offset", find the
7606 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7607 // to "spec_block_die_offset"
7608 DWARFDebugInfo* info = DebugInfo();
7609
7610 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
7611 if (die)
7612 {
7613 assert (*result_die_cu_handle);
7614 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
7615 }
7616 return NULL;
7617}
7618
7619
7620const DWARFDebugInfoEntry *
7621SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
7622 const DWARFDebugInfoEntry *die,
7623 dw_offset_t spec_block_die_offset,
7624 DWARFCompileUnit **result_die_cu_handle)
7625{
7626 if (die)
7627 {
7628 switch (die->Tag())
7629 {
7630 case DW_TAG_subprogram:
7631 case DW_TAG_inlined_subroutine:
7632 case DW_TAG_lexical_block:
7633 {
7634 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
7635 {
7636 *result_die_cu_handle = dwarf_cu;
7637 return die;
7638 }
7639
7640 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
7641 {
7642 *result_die_cu_handle = dwarf_cu;
7643 return die;
7644 }
7645 }
7646 break;
7647 }
7648
7649 // Give the concrete function die specified by "func_die_offset", find the
7650 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7651 // to "spec_block_die_offset"
7652 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
7653 {
7654 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
7655 child_die,
7656 spec_block_die_offset,
7657 result_die_cu_handle);
7658 if (result_die)
7659 return result_die;
7660 }
7661 }
7662
7663 *result_die_cu_handle = NULL;
7664 return NULL;
7665}
7666
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007667size_t
7668SymbolFileDWARF::ParseVariables
7669(
7670 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007671 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007672 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007673 const DWARFDebugInfoEntry *orig_die,
7674 bool parse_siblings,
7675 bool parse_children,
7676 VariableList* cc_variable_list
7677)
7678{
7679 if (orig_die == NULL)
7680 return 0;
7681
Greg Claytonc662ec82011-06-17 22:10:16 +00007682 VariableListSP variable_list_sp;
7683
7684 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007685 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00007686 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007687 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007688 dw_tag_t tag = die->Tag();
7689
7690 // Check to see if we have already parsed this variable or constant?
7691 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007692 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007693 if (cc_variable_list)
7694 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007695 }
7696 else
7697 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007698 // We haven't already parsed it, lets do that now.
7699 if ((tag == DW_TAG_variable) ||
7700 (tag == DW_TAG_constant) ||
7701 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007702 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007703 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00007704 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007705 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
7706 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7707 switch (parent_tag)
7708 {
7709 case DW_TAG_compile_unit:
7710 if (sc.comp_unit != NULL)
7711 {
7712 variable_list_sp = sc.comp_unit->GetVariableList(false);
7713 if (variable_list_sp.get() == NULL)
7714 {
7715 variable_list_sp.reset(new VariableList());
7716 sc.comp_unit->SetVariableList(variable_list_sp);
7717 }
7718 }
7719 else
7720 {
Daniel Malead01b2952012-11-29 21:49:15 +00007721 GetObjectFile()->GetModule()->ReportError ("parent 0x%8.8" PRIx64 " %s with no valid compile unit in symbol context for 0x%8.8" PRIx64 " %s.\n",
Greg Claytone38a5ed2012-01-05 03:57:59 +00007722 MakeUserID(sc_parent_die->GetOffset()),
7723 DW_TAG_value_to_name (parent_tag),
7724 MakeUserID(orig_die->GetOffset()),
7725 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007726 }
7727 break;
7728
7729 case DW_TAG_subprogram:
7730 case DW_TAG_inlined_subroutine:
7731 case DW_TAG_lexical_block:
7732 if (sc.function != NULL)
7733 {
7734 // Check to see if we already have parsed the variables for the given scope
7735
Greg Clayton81c22f62011-10-19 18:09:39 +00007736 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007737 if (block == NULL)
7738 {
7739 // This must be a specification or abstract origin with
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00007740 // a concrete block counterpart in the current function. We need
Greg Claytonc662ec82011-06-17 22:10:16 +00007741 // to find the concrete block so we can correctly add the
7742 // variable to it
7743 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
7744 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
7745 sc_parent_die->GetOffset(),
7746 &concrete_block_die_cu);
7747 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00007748 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007749 }
7750
7751 if (block != NULL)
7752 {
7753 const bool can_create = false;
7754 variable_list_sp = block->GetBlockVariableList (can_create);
7755 if (variable_list_sp.get() == NULL)
7756 {
7757 variable_list_sp.reset(new VariableList());
7758 block->SetVariableList(variable_list_sp);
7759 }
7760 }
7761 }
7762 break;
7763
7764 default:
Daniel Malead01b2952012-11-29 21:49:15 +00007765 GetObjectFile()->GetModule()->ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8" PRIx64 " %s.\n",
Greg Claytone38a5ed2012-01-05 03:57:59 +00007766 MakeUserID(orig_die->GetOffset()),
7767 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007768 break;
7769 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00007770 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007771
7772 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007773 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00007774 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
7775 if (var_sp)
7776 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007777 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00007778 if (cc_variable_list)
7779 cc_variable_list->AddVariableIfUnique (var_sp);
7780 ++vars_added;
7781 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007782 }
7783 }
7784 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007785
7786 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
7787
7788 if (!skip_children && parse_children && die->HasChildren())
7789 {
7790 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
7791 }
7792
7793 if (parse_siblings)
7794 die = die->GetSibling();
7795 else
7796 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007797 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007798 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007799}
7800
7801//------------------------------------------------------------------
7802// PluginInterface protocol
7803//------------------------------------------------------------------
Greg Clayton57abc5d2013-05-10 21:47:16 +00007804ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007805SymbolFileDWARF::GetPluginName()
7806{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007807 return GetPluginNameStatic();
7808}
7809
7810uint32_t
7811SymbolFileDWARF::GetPluginVersion()
7812{
7813 return 1;
7814}
7815
7816void
Greg Clayton6beaaa62011-01-17 03:46:26 +00007817SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
7818{
7819 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
Greg Clayton57ee3062013-07-11 22:46:58 +00007820 ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
Greg Clayton6beaaa62011-01-17 03:46:26 +00007821 if (clang_type)
7822 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7823}
7824
7825void
7826SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
7827{
7828 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
Greg Clayton57ee3062013-07-11 22:46:58 +00007829 ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
Greg Clayton6beaaa62011-01-17 03:46:26 +00007830 if (clang_type)
7831 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7832}
7833
Greg Claytona2721472011-06-25 00:44:06 +00007834void
Sean Callanancc427fa2011-07-30 02:42:06 +00007835SymbolFileDWARF::DumpIndexes ()
7836{
7837 StreamFile s(stdout, false);
7838
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00007839 s.Printf ("DWARF index for (%s) '%s':",
Sean Callanancc427fa2011-07-30 02:42:06 +00007840 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00007841 GetObjectFile()->GetFileSpec().GetPath().c_str());
Sean Callanancc427fa2011-07-30 02:42:06 +00007842 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
7843 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
7844 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
7845 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
7846 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
7847 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
7848 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
7849 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
7850}
7851
7852void
7853SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
7854 const char *name,
7855 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00007856{
Sean Callanancc427fa2011-07-30 02:42:06 +00007857 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00007858
7859 if (iter == m_decl_ctx_to_die.end())
7860 return;
7861
Greg Claytoncb5860a2011-10-13 23:49:28 +00007862 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00007863 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007864 const DWARFDebugInfoEntry *context_die = *pos;
7865
7866 if (!results)
7867 return;
7868
7869 DWARFDebugInfo* info = DebugInfo();
7870
7871 DIEArray die_offsets;
7872
7873 DWARFCompileUnit* dwarf_cu = NULL;
7874 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton220a0072011-12-09 08:48:30 +00007875
7876 if (m_using_apple_tables)
7877 {
7878 if (m_apple_types_ap.get())
7879 m_apple_types_ap->FindByName (name, die_offsets);
7880 }
7881 else
7882 {
7883 if (!m_indexed)
7884 Index ();
7885
7886 m_type_index.Find (ConstString(name), die_offsets);
7887 }
7888
Greg Clayton220a0072011-12-09 08:48:30 +00007889 const size_t num_matches = die_offsets.size();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007890
7891 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00007892 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007893 for (size_t i = 0; i < num_matches; ++i)
7894 {
7895 const dw_offset_t die_offset = die_offsets[i];
7896 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00007897
Greg Claytoncb5860a2011-10-13 23:49:28 +00007898 if (die->GetParent() != context_die)
7899 continue;
7900
7901 Type *matching_type = ResolveType (dwarf_cu, die);
7902
Greg Clayton57ee3062013-07-11 22:46:58 +00007903 clang::QualType qual_type = matching_type->GetClangForwardType().GetQualType();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007904
7905 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
7906 {
7907 clang::TagDecl *tag_decl = tag_type->getDecl();
7908 results->push_back(tag_decl);
7909 }
7910 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
7911 {
7912 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
7913 results->push_back(typedef_decl);
7914 }
Greg Claytona2721472011-06-25 00:44:06 +00007915 }
7916 }
7917 }
7918}
7919
7920void
7921SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00007922 const clang::DeclContext *decl_context,
7923 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00007924 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
7925{
Greg Clayton85ae2e12011-10-18 23:36:41 +00007926
7927 switch (decl_context->getDeclKind())
7928 {
7929 case clang::Decl::Namespace:
7930 case clang::Decl::TranslationUnit:
7931 {
7932 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7933 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
7934 }
7935 break;
7936 default:
7937 break;
7938 }
Greg Claytona2721472011-06-25 00:44:06 +00007939}
Greg Claytoncaab74e2012-01-28 00:48:57 +00007940
Zachary Turner504f38d2015-03-24 16:24:50 +00007941bool
7942SymbolFileDWARF::LayoutRecordType(void *baton, const clang::RecordDecl *record_decl, uint64_t &size,
7943 uint64_t &alignment,
Zachary Turnera98fac22015-03-24 18:56:08 +00007944 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
7945 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7946 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
Greg Claytoncaab74e2012-01-28 00:48:57 +00007947{
7948 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7949 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
7950}
7951
Zachary Turner504f38d2015-03-24 16:24:50 +00007952bool
7953SymbolFileDWARF::LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &bit_size, uint64_t &alignment,
Zachary Turnera98fac22015-03-24 18:56:08 +00007954 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
7955 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7956 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
Greg Claytoncaab74e2012-01-28 00:48:57 +00007957{
Greg Clayton5160ce52013-03-27 23:08:40 +00007958 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Claytoncaab74e2012-01-28 00:48:57 +00007959 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
7960 bool success = false;
7961 base_offsets.clear();
7962 vbase_offsets.clear();
7963 if (pos != m_record_decl_to_layout_map.end())
7964 {
7965 bit_size = pos->second.bit_size;
7966 alignment = pos->second.alignment;
7967 field_offsets.swap(pos->second.field_offsets);
Greg Clayton2508b9b2012-11-01 23:20:02 +00007968 base_offsets.swap (pos->second.base_offsets);
7969 vbase_offsets.swap (pos->second.vbase_offsets);
Greg Claytoncaab74e2012-01-28 00:48:57 +00007970 m_record_decl_to_layout_map.erase(pos);
7971 success = true;
7972 }
7973 else
7974 {
7975 bit_size = 0;
7976 alignment = 0;
7977 field_offsets.clear();
7978 }
7979
7980 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00007981 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00007982 "SymbolFileDWARF::LayoutRecordType (record_decl = %p, bit_size = %" PRIu64 ", alignment = %" PRIu64 ", field_offsets[%u],base_offsets[%u], vbase_offsets[%u]) success = %i",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007983 static_cast<const void*>(record_decl),
7984 bit_size, alignment,
7985 static_cast<uint32_t>(field_offsets.size()),
7986 static_cast<uint32_t>(base_offsets.size()),
7987 static_cast<uint32_t>(vbase_offsets.size()),
Greg Claytoncaab74e2012-01-28 00:48:57 +00007988 success);
7989 return success;
7990}
7991
7992
Greg Clayton1f746072012-08-29 21:13:06 +00007993SymbolFileDWARFDebugMap *
7994SymbolFileDWARF::GetDebugMapSymfile ()
7995{
7996 if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired())
7997 {
7998 lldb::ModuleSP module_sp (m_debug_map_module_wp.lock());
7999 if (module_sp)
8000 {
8001 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
8002 if (sym_vendor)
8003 m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile();
8004 }
8005 }
8006 return m_debug_map_symfile;
8007}
8008
Greg Claytoncaab74e2012-01-28 00:48:57 +00008009