blob: 28bfcb9cae99642d43d7df36d7efe20e417e3e19 [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);
Siva Chandra462722d2015-03-27 00:10:04 +00001098 else if (die->GetParent()->Tag() == DW_TAG_compile_unit &&
1099 LanguageRuntime::LanguageIsCPlusPlus(dwarf_cu->GetLanguageType()) &&
1100 strcmp(name, "main") != 0)
1101 {
1102 // If the mangled name is not present in the DWARF, generate the demangled name
1103 // using the decl context. We skip if the function is "main" as its name is
1104 // never mangled.
1105 bool is_static = false;
1106 bool is_variadic = false;
1107 unsigned type_quals = 0;
1108 std::vector<ClangASTType> param_types;
1109 std::vector<clang::ParmVarDecl*> param_decls;
1110 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
1111 DWARFDeclContext decl_ctx;
1112 StreamString sstr;
1113
1114 die->GetDWARFDeclContext(this, dwarf_cu, decl_ctx);
1115 sstr << decl_ctx.GetQualifiedName();
1116
1117 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE(dwarf_cu,
1118 die,
1119 &decl_ctx_die);
1120 ParseChildParameters(sc,
1121 containing_decl_ctx,
1122 dwarf_cu,
1123 die,
1124 true,
1125 is_static,
1126 is_variadic,
1127 param_types,
1128 param_decls,
1129 type_quals);
1130 sstr << "(";
1131 for (size_t i = 0; i < param_types.size(); i++)
1132 {
1133 if (i > 0)
1134 sstr << ", ";
1135 sstr << param_types[i].GetTypeName();
1136 }
1137 if (is_variadic)
1138 sstr << ", ...";
1139 sstr << ")";
1140 if (type_quals & clang::Qualifiers::Const)
1141 sstr << " const";
1142
1143 func_name.SetValue(ConstString(sstr.GetData()), false);
1144 }
1145 else
Greg Clayton037520e2012-07-18 23:18:10 +00001146 func_name.SetValue(ConstString(name), false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001147
1148 FunctionSP func_sp;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001149 std::unique_ptr<Declaration> decl_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001150 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +00001151 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1152 decl_line,
1153 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001154
Greg Clayton0bd4e1b2011-09-30 20:52:25 +00001155 // Supply the type _only_ if it has already been parsed
Greg Clayton594e5ed2010-09-27 21:07:38 +00001156 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001157
1158 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
1159
Greg Clayton9422dd62013-03-04 21:46:16 +00001160 if (FixupAddress (func_range.GetBaseAddress()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001161 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001162 const user_id_t func_user_id = MakeUserID(die->GetOffset());
1163 func_sp.reset(new Function (sc.comp_unit,
1164 MakeUserID(func_user_id), // UserID is the DIE offset
1165 MakeUserID(func_user_id),
1166 func_name,
1167 func_type,
1168 func_range)); // first address range
1169
1170 if (func_sp.get() != NULL)
1171 {
1172 if (frame_base.IsValid())
1173 func_sp->GetFrameBaseExpression() = frame_base;
1174 sc.comp_unit->AddFunction(func_sp);
1175 return func_sp.get();
1176 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001177 }
1178 }
1179 }
1180 return NULL;
1181}
1182
Greg Clayton9422dd62013-03-04 21:46:16 +00001183bool
1184SymbolFileDWARF::FixupAddress (Address &addr)
1185{
1186 SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile ();
1187 if (debug_map_symfile)
1188 {
1189 return debug_map_symfile->LinkOSOAddress(addr);
1190 }
1191 // This is a normal DWARF file, no address fixups need to happen
1192 return true;
1193}
Greg Clayton1f746072012-08-29 21:13:06 +00001194lldb::LanguageType
1195SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc)
1196{
1197 assert (sc.comp_unit);
1198 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1199 if (dwarf_cu)
1200 {
1201 const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly();
Jim Ingham28eb5712012-10-12 17:34:26 +00001202 if (die)
1203 {
1204 const uint32_t language = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
1205 if (language)
1206 return (lldb::LanguageType)language;
1207 }
Greg Clayton1f746072012-08-29 21:13:06 +00001208 }
1209 return eLanguageTypeUnknown;
1210}
1211
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001212size_t
1213SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
1214{
1215 assert (sc.comp_unit);
1216 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00001217 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001218 if (dwarf_cu)
1219 {
1220 DWARFDIECollection function_dies;
Greg Clayton1f746072012-08-29 21:13:06 +00001221 const size_t num_functions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001222 size_t func_idx;
Greg Clayton1f746072012-08-29 21:13:06 +00001223 for (func_idx = 0; func_idx < num_functions; ++func_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001224 {
1225 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
Greg Clayton81c22f62011-10-19 18:09:39 +00001226 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001227 {
1228 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
1229 ++functions_added;
1230 }
1231 }
1232 //FixupTypes();
1233 }
1234 return functions_added;
1235}
1236
1237bool
1238SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
1239{
1240 assert (sc.comp_unit);
Greg Clayton1f746072012-08-29 21:13:06 +00001241 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Greg Claytonda2455b2012-11-01 17:28:37 +00001242 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001243 {
Greg Claytonda2455b2012-11-01 17:28:37 +00001244 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001245
Greg Claytonda2455b2012-11-01 17:28:37 +00001246 if (cu_die)
1247 {
1248 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
Matthew Gardinere81df3b2014-08-26 06:57:23 +00001249
1250 // DWARF2/3 suggests the form hostname:pathname for compilation directory.
1251 // Remove the host part if present.
1252 cu_comp_dir = removeHostnameFromPathname(cu_comp_dir);
1253
Greg Claytonda2455b2012-11-01 17:28:37 +00001254 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 +00001255
Greg Claytonda2455b2012-11-01 17:28:37 +00001256 // All file indexes in DWARF are one based and a file of index zero is
1257 // supposed to be the compile unit itself.
1258 support_files.Append (*sc.comp_unit);
1259
1260 return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
1261 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001262 }
1263 return false;
1264}
1265
1266struct ParseDWARFLineTableCallbackInfo
1267{
1268 LineTable* line_table;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001269 std::unique_ptr<LineSequence> sequence_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001270};
1271
1272//----------------------------------------------------------------------
1273// ParseStatementTableCallback
1274//----------------------------------------------------------------------
1275static void
1276ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
1277{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001278 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
1279 {
1280 // Just started parsing the line table
1281 }
1282 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
1283 {
1284 // Done parsing line table, nothing to do for the cleanup
1285 }
1286 else
1287 {
1288 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
Greg Clayton9422dd62013-03-04 21:46:16 +00001289 LineTable* line_table = info->line_table;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001290
Greg Clayton9422dd62013-03-04 21:46:16 +00001291 // If this is our first time here, we need to create a
1292 // sequence container.
1293 if (!info->sequence_ap.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001294 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001295 info->sequence_ap.reset(line_table->CreateLineSequenceContainer());
1296 assert(info->sequence_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001297 }
Greg Clayton9422dd62013-03-04 21:46:16 +00001298 line_table->AppendLineEntryToSequence (info->sequence_ap.get(),
1299 state.address,
1300 state.line,
1301 state.column,
1302 state.file,
1303 state.is_stmt,
1304 state.basic_block,
1305 state.prologue_end,
1306 state.epilogue_begin,
1307 state.end_sequence);
1308 if (state.end_sequence)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001309 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001310 // First, put the current sequence into the line table.
1311 line_table->InsertSequence(info->sequence_ap.get());
1312 // Then, empty it to prepare for the next sequence.
1313 info->sequence_ap->Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001314 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001315 }
1316}
1317
1318bool
1319SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1320{
1321 assert (sc.comp_unit);
1322 if (sc.comp_unit->GetLineTable() != NULL)
1323 return true;
1324
Greg Clayton1f746072012-08-29 21:13:06 +00001325 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001326 if (dwarf_cu)
1327 {
1328 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Greg Clayton129d12c2011-11-28 03:29:03 +00001329 if (dwarf_cu_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001330 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001331 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1332 if (cu_line_offset != DW_INVALID_OFFSET)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001333 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001334 std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
Greg Clayton129d12c2011-11-28 03:29:03 +00001335 if (line_table_ap.get())
1336 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001337 ParseDWARFLineTableCallbackInfo info;
1338 info.line_table = line_table_ap.get();
Greg Claytonc7bece562013-01-25 18:06:21 +00001339 lldb::offset_t offset = cu_line_offset;
Greg Clayton129d12c2011-11-28 03:29:03 +00001340 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
Greg Clayton9422dd62013-03-04 21:46:16 +00001341 if (m_debug_map_symfile)
1342 {
1343 // We have an object file that has a line table with addresses
1344 // that are not linked. We need to link the line table and convert
1345 // the addresses that are relative to the .o file into addresses
1346 // for the main executable.
1347 sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get()));
1348 }
1349 else
1350 {
1351 sc.comp_unit->SetLineTable(line_table_ap.release());
1352 return true;
1353 }
Greg Clayton129d12c2011-11-28 03:29:03 +00001354 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001355 }
1356 }
1357 }
1358 return false;
1359}
1360
1361size_t
1362SymbolFileDWARF::ParseFunctionBlocks
1363(
1364 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001365 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001366 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001367 const DWARFDebugInfoEntry *die,
1368 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001369 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001370)
1371{
1372 size_t blocks_added = 0;
1373 while (die != NULL)
1374 {
1375 dw_tag_t tag = die->Tag();
1376
1377 switch (tag)
1378 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001379 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001380 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001381 case DW_TAG_lexical_block:
1382 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001383 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001384 if (tag == DW_TAG_subprogram)
1385 {
1386 // Skip any DW_TAG_subprogram DIEs that are inside
1387 // of a normal or inlined functions. These will be
1388 // parsed on their own as separate entities.
1389
1390 if (depth > 0)
1391 break;
1392
1393 block = parent_block;
1394 }
1395 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001396 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001397 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001398 parent_block->AddChild(block_sp);
1399 block = block_sp.get();
1400 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001401 DWARFDebugRanges::RangeList ranges;
1402 const char *name = NULL;
1403 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001404
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001405 int decl_file = 0;
1406 int decl_line = 0;
1407 int decl_column = 0;
1408 int call_file = 0;
1409 int call_line = 0;
1410 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001411 if (die->GetDIENamesAndRanges (this,
1412 dwarf_cu,
1413 name,
1414 mangled_name,
1415 ranges,
1416 decl_file, decl_line, decl_column,
1417 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001418 {
1419 if (tag == DW_TAG_subprogram)
1420 {
1421 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001422 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001423 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001424 else if (tag == DW_TAG_inlined_subroutine)
1425 {
1426 // We get called here for inlined subroutines in two ways.
1427 // The first time is when we are making the Function object
1428 // for this inlined concrete instance. Since we're creating a top level block at
1429 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1430 // adjust the containing address.
1431 // The second time is when we are parsing the blocks inside the function that contains
1432 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1433 // function the offset will be for that function.
1434 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1435 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001436 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001437 }
1438 }
Greg Clayton103f3092015-01-15 03:04:37 +00001439
1440 const size_t num_ranges = ranges.GetSize();
1441 for (size_t i = 0; i<num_ranges; ++i)
1442 {
1443 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i);
1444 const addr_t range_base = range.GetRangeBase();
1445 if (range_base >= subprogram_low_pc)
1446 block->AddRange(Block::Range (range_base - subprogram_low_pc, range.GetByteSize()));
1447 else
1448 {
1449 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",
1450 block->GetID(),
1451 range_base,
1452 range.GetRangeEnd(),
1453 subprogram_low_pc);
1454 }
1455 }
1456 block->FinalizeRanges ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001457
1458 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1459 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001460 std::unique_ptr<Declaration> decl_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001461 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001462 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1463 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001464
Greg Clayton7b0992d2013-04-18 22:45:39 +00001465 std::unique_ptr<Declaration> call_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001466 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001467 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1468 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001469
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001470 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001471 }
1472
1473 ++blocks_added;
1474
Greg Claytondd7feaf2011-08-12 17:54:33 +00001475 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001476 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001477 blocks_added += ParseFunctionBlocks (sc,
1478 block,
1479 dwarf_cu,
1480 die->GetFirstChild(),
1481 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001482 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001483 }
1484 }
1485 }
1486 break;
1487 default:
1488 break;
1489 }
1490
Greg Claytondd7feaf2011-08-12 17:54:33 +00001491 // Only parse siblings of the block if we are not at depth zero. A depth
1492 // of zero indicates we are currently parsing the top level
1493 // DW_TAG_subprogram DIE
1494
1495 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001496 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001497 else
1498 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001499 }
1500 return blocks_added;
1501}
1502
Greg Claytonf0705c82011-10-22 03:33:13 +00001503bool
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001504SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu,
1505 const DWARFDebugInfoEntry *die,
1506 ClangASTContext::TemplateParameterInfos &template_param_infos)
1507{
1508 const dw_tag_t tag = die->Tag();
1509
1510 switch (tag)
1511 {
1512 case DW_TAG_template_type_parameter:
1513 case DW_TAG_template_value_parameter:
1514 {
Todd Fialaee8bfc62014-09-11 17:29:12 +00001515 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001516
1517 DWARFDebugInfoEntry::Attributes attributes;
1518 const size_t num_attributes = die->GetAttributes (this,
1519 dwarf_cu,
1520 fixed_form_sizes,
1521 attributes);
1522 const char *name = NULL;
1523 Type *lldb_type = NULL;
Greg Clayton57ee3062013-07-11 22:46:58 +00001524 ClangASTType clang_type;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001525 uint64_t uval64 = 0;
1526 bool uval64_valid = false;
1527 if (num_attributes > 0)
1528 {
1529 DWARFFormValue form_value;
1530 for (size_t i=0; i<num_attributes; ++i)
1531 {
1532 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1533
1534 switch (attr)
1535 {
1536 case DW_AT_name:
1537 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1538 name = form_value.AsCString(&get_debug_str_data());
1539 break;
1540
1541 case DW_AT_type:
1542 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1543 {
Greg Clayton54166af2014-11-22 01:58:59 +00001544 const dw_offset_t type_die_offset = form_value.Reference();
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001545 lldb_type = ResolveTypeUID(type_die_offset);
1546 if (lldb_type)
1547 clang_type = lldb_type->GetClangForwardType();
1548 }
1549 break;
1550
1551 case DW_AT_const_value:
1552 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1553 {
1554 uval64_valid = true;
1555 uval64 = form_value.Unsigned();
1556 }
1557 break;
1558 default:
1559 break;
1560 }
1561 }
1562
Greg Clayton283b2652013-04-23 22:38:02 +00001563 clang::ASTContext *ast = GetClangASTContext().getASTContext();
1564 if (!clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00001565 clang_type = GetClangASTContext().GetBasicType(eBasicTypeVoid);
Greg Clayton283b2652013-04-23 22:38:02 +00001566
1567 if (clang_type)
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001568 {
1569 bool is_signed = false;
Greg Clayton283b2652013-04-23 22:38:02 +00001570 if (name && name[0])
1571 template_param_infos.names.push_back(name);
1572 else
1573 template_param_infos.names.push_back(NULL);
1574
Greg Clayton283b2652013-04-23 22:38:02 +00001575 if (tag == DW_TAG_template_value_parameter &&
1576 lldb_type != NULL &&
Greg Clayton57ee3062013-07-11 22:46:58 +00001577 clang_type.IsIntegerType (is_signed) &&
Greg Clayton283b2652013-04-23 22:38:02 +00001578 uval64_valid)
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001579 {
1580 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
Greg Clayton283b2652013-04-23 22:38:02 +00001581 template_param_infos.args.push_back (clang::TemplateArgument (*ast,
Sean Callanan3d654b32012-09-24 22:25:51 +00001582 llvm::APSInt(apint),
Greg Clayton57ee3062013-07-11 22:46:58 +00001583 clang_type.GetQualType()));
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001584 }
1585 else
1586 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001587 template_param_infos.args.push_back (clang::TemplateArgument (clang_type.GetQualType()));
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001588 }
1589 }
1590 else
1591 {
1592 return false;
1593 }
1594
1595 }
1596 }
1597 return true;
1598
1599 default:
1600 break;
1601 }
1602 return false;
1603}
1604
1605bool
Greg Claytonf0705c82011-10-22 03:33:13 +00001606SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1607 const DWARFDebugInfoEntry *parent_die,
1608 ClangASTContext::TemplateParameterInfos &template_param_infos)
1609{
1610
1611 if (parent_die == NULL)
Filipe Cabecinhas52008c62012-05-23 16:24:11 +00001612 return false;
Greg Claytonf0705c82011-10-22 03:33:13 +00001613
Greg Claytonf0705c82011-10-22 03:33:13 +00001614 Args template_parameter_names;
1615 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1616 die != NULL;
1617 die = die->GetSibling())
1618 {
1619 const dw_tag_t tag = die->Tag();
1620
1621 switch (tag)
1622 {
1623 case DW_TAG_template_type_parameter:
1624 case DW_TAG_template_value_parameter:
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001625 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Claytonf0705c82011-10-22 03:33:13 +00001626 break;
1627
1628 default:
1629 break;
1630 }
1631 }
1632 if (template_param_infos.args.empty())
1633 return false;
1634 return template_param_infos.args.size() == template_param_infos.names.size();
1635}
1636
1637clang::ClassTemplateDecl *
1638SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001639 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001640 const char *parent_name,
1641 int tag_decl_kind,
1642 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1643{
1644 if (template_param_infos.IsValid())
1645 {
1646 std::string template_basename(parent_name);
1647 template_basename.erase (template_basename.find('<'));
1648 ClangASTContext &ast = GetClangASTContext();
1649
1650 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001651 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001652 template_basename.c_str(),
1653 tag_decl_kind,
1654 template_param_infos);
1655 }
1656 return NULL;
1657}
1658
Sean Callanana0b80ab2012-06-04 22:28:05 +00001659class SymbolFileDWARF::DelayedAddObjCClassProperty
1660{
1661public:
1662 DelayedAddObjCClassProperty
1663 (
Greg Clayton57ee3062013-07-11 22:46:58 +00001664 const ClangASTType &class_opaque_type,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001665 const char *property_name,
Greg Clayton57ee3062013-07-11 22:46:58 +00001666 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 +00001667 clang::ObjCIvarDecl *ivar_decl,
1668 const char *property_setter_name,
1669 const char *property_getter_name,
1670 uint32_t property_attributes,
Greg Claytonc4ffd662013-03-08 01:37:30 +00001671 const ClangASTMetadata *metadata
Sean Callanana0b80ab2012-06-04 22:28:05 +00001672 ) :
Sean Callanana0b80ab2012-06-04 22:28:05 +00001673 m_class_opaque_type (class_opaque_type),
1674 m_property_name (property_name),
1675 m_property_opaque_type (property_opaque_type),
1676 m_ivar_decl (ivar_decl),
1677 m_property_setter_name (property_setter_name),
1678 m_property_getter_name (property_getter_name),
Jim Ingham379397632012-10-27 02:54:13 +00001679 m_property_attributes (property_attributes)
Sean Callanana0b80ab2012-06-04 22:28:05 +00001680 {
Jim Ingham379397632012-10-27 02:54:13 +00001681 if (metadata != NULL)
1682 {
1683 m_metadata_ap.reset(new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001684 *m_metadata_ap = *metadata;
Jim Ingham379397632012-10-27 02:54:13 +00001685 }
1686 }
1687
1688 DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs)
1689 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001690 *this = rhs;
Daniel Malead4c5be62012-11-12 21:02:14 +00001691 }
1692
1693 DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs)
1694 {
Jim Ingham379397632012-10-27 02:54:13 +00001695 m_class_opaque_type = rhs.m_class_opaque_type;
1696 m_property_name = rhs.m_property_name;
1697 m_property_opaque_type = rhs.m_property_opaque_type;
1698 m_ivar_decl = rhs.m_ivar_decl;
1699 m_property_setter_name = rhs.m_property_setter_name;
1700 m_property_getter_name = rhs.m_property_getter_name;
1701 m_property_attributes = rhs.m_property_attributes;
1702
1703 if (rhs.m_metadata_ap.get())
1704 {
1705 m_metadata_ap.reset (new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001706 *m_metadata_ap = *rhs.m_metadata_ap;
Jim Ingham379397632012-10-27 02:54:13 +00001707 }
Daniel Malead4c5be62012-11-12 21:02:14 +00001708 return *this;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001709 }
1710
Greg Clayton57ee3062013-07-11 22:46:58 +00001711 bool
1712 Finalize()
Sean Callanana0b80ab2012-06-04 22:28:05 +00001713 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001714 return m_class_opaque_type.AddObjCClassProperty (m_property_name,
1715 m_property_opaque_type,
1716 m_ivar_decl,
1717 m_property_setter_name,
1718 m_property_getter_name,
1719 m_property_attributes,
1720 m_metadata_ap.get());
Sean Callanana0b80ab2012-06-04 22:28:05 +00001721 }
1722private:
Greg Clayton57ee3062013-07-11 22:46:58 +00001723 ClangASTType m_class_opaque_type;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001724 const char *m_property_name;
Greg Clayton57ee3062013-07-11 22:46:58 +00001725 ClangASTType m_property_opaque_type;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001726 clang::ObjCIvarDecl *m_ivar_decl;
1727 const char *m_property_setter_name;
1728 const char *m_property_getter_name;
1729 uint32_t m_property_attributes;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001730 std::unique_ptr<ClangASTMetadata> m_metadata_ap;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001731};
1732
Sean Callananfaa0bb32012-12-05 23:37:14 +00001733struct BitfieldInfo
1734{
1735 uint64_t bit_size;
1736 uint64_t bit_offset;
1737
1738 BitfieldInfo () :
1739 bit_size (LLDB_INVALID_ADDRESS),
1740 bit_offset (LLDB_INVALID_ADDRESS)
1741 {
1742 }
1743
Greg Clayton78f4d952013-12-11 23:10:39 +00001744 void
1745 Clear()
1746 {
1747 bit_size = LLDB_INVALID_ADDRESS;
1748 bit_offset = LLDB_INVALID_ADDRESS;
1749 }
1750
Sean Callananfaa0bb32012-12-05 23:37:14 +00001751 bool IsValid ()
1752 {
1753 return (bit_size != LLDB_INVALID_ADDRESS) &&
1754 (bit_offset != LLDB_INVALID_ADDRESS);
1755 }
1756};
1757
Greg Claytonc4ffd662013-03-08 01:37:30 +00001758
1759bool
1760SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu,
1761 const DWARFDebugInfoEntry *parent_die)
1762{
1763 if (parent_die)
1764 {
1765 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1766 {
1767 dw_tag_t tag = die->Tag();
1768 bool check_virtuality = false;
1769 switch (tag)
1770 {
1771 case DW_TAG_inheritance:
1772 case DW_TAG_subprogram:
1773 check_virtuality = true;
1774 break;
1775 default:
1776 break;
1777 }
1778 if (check_virtuality)
1779 {
1780 if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0)
1781 return true;
1782 }
1783 }
1784 }
1785 return false;
1786}
1787
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001788size_t
1789SymbolFileDWARF::ParseChildMembers
1790(
1791 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001792 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001793 const DWARFDebugInfoEntry *parent_die,
Greg Clayton57ee3062013-07-11 22:46:58 +00001794 ClangASTType &class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001795 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001796 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1797 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001798 DWARFDIECollection& member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001799 DelayedPropertyList& delayed_properties,
Sean Callananc7fbf732010-08-06 00:32:49 +00001800 AccessType& default_accessibility,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001801 bool &is_a_class,
1802 LayoutInfo &layout_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001803)
1804{
1805 if (parent_die == NULL)
1806 return 0;
1807
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001808 size_t count = 0;
1809 const DWARFDebugInfoEntry *die;
Todd Fialaee8bfc62014-09-11 17:29:12 +00001810 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001811 uint32_t member_idx = 0;
Sean Callananfaa0bb32012-12-05 23:37:14 +00001812 BitfieldInfo last_field_info;
Richard Mitton0a558352013-10-17 21:14:00 +00001813 ModuleSP module = GetObjectFile()->GetModule();
Greg Claytond88d7592010-09-15 08:33:30 +00001814
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001815 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1816 {
1817 dw_tag_t tag = die->Tag();
1818
1819 switch (tag)
1820 {
1821 case DW_TAG_member:
Sean Callanan3d654b32012-09-24 22:25:51 +00001822 case DW_TAG_APPLE_property:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001823 {
1824 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001825 const size_t num_attributes = die->GetAttributes (this,
1826 dwarf_cu,
1827 fixed_form_sizes,
1828 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001829 if (num_attributes > 0)
1830 {
1831 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001832 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001833 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001834 const char *prop_name = NULL;
1835 const char *prop_getter_name = NULL;
1836 const char *prop_setter_name = NULL;
Greg Claytone528efd72013-02-26 23:45:18 +00001837 uint32_t prop_attributes = 0;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001838
1839
Greg Clayton24739922010-10-13 03:15:28 +00001840 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001841 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001842 AccessType accessibility = eAccessNone;
Greg Claytoncaab74e2012-01-28 00:48:57 +00001843 uint32_t member_byte_offset = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001844 size_t byte_size = 0;
1845 size_t bit_offset = 0;
1846 size_t bit_size = 0;
Greg Claytone528efd72013-02-26 23:45:18 +00001847 bool is_external = false; // On DW_TAG_members, this means the member is static
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001848 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001849 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001850 {
1851 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1852 DWARFFormValue form_value;
1853 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1854 {
1855 switch (attr)
1856 {
1857 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1858 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1859 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1860 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00001861 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001862 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1863 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1864 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1865 case DW_AT_data_member_location:
Greg Claytoncaab74e2012-01-28 00:48:57 +00001866 if (form_value.BlockData())
1867 {
1868 Value initialValue(0);
1869 Value memberOffset(0);
Ed Masteeeae7212013-10-24 20:43:47 +00001870 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Claytoncaab74e2012-01-28 00:48:57 +00001871 uint32_t block_length = form_value.Unsigned();
1872 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1873 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
Greg Claytoncaab74e2012-01-28 00:48:57 +00001874 NULL, // ClangExpressionVariableList *
1875 NULL, // ClangExpressionDeclMap *
1876 NULL, // RegisterContext *
Richard Mitton0a558352013-10-17 21:14:00 +00001877 module,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001878 debug_info_data,
1879 block_offset,
1880 block_length,
1881 eRegisterKindDWARF,
1882 &initialValue,
1883 memberOffset,
1884 NULL))
1885 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001886 member_byte_offset = memberOffset.ResolveValue(NULL).UInt();
Greg Claytoncaab74e2012-01-28 00:48:57 +00001887 }
1888 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00001889 else
1890 {
1891 // With DWARF 3 and later, if the value is an integer constant,
1892 // this form value is the offset in bytes from the beginning
1893 // of the containing entity.
1894 member_byte_offset = form_value.Unsigned();
1895 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001896 break;
1897
Greg Clayton8cf05932010-07-22 18:30:50 +00001898 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00001899 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001900 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1901 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1902 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1903 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00001904 case DW_AT_external: is_external = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001905
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001906 default:
Greg Clayton1b02c172012-03-14 21:00:47 +00001907 case DW_AT_declaration:
1908 case DW_AT_description:
1909 case DW_AT_mutable:
1910 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001911 case DW_AT_sibling:
1912 break;
1913 }
1914 }
1915 }
Sean Callanana6582262012-04-05 00:12:52 +00001916
1917 if (prop_name)
Sean Callanan751aac62012-03-29 19:07:06 +00001918 {
Sean Callanana6582262012-04-05 00:12:52 +00001919 ConstString fixed_getter;
1920 ConstString fixed_setter;
1921
1922 // Check if the property getter/setter were provided as full
1923 // names. We want basenames, so we extract them.
1924
1925 if (prop_getter_name && prop_getter_name[0] == '-')
1926 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001927 ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true);
1928 prop_getter_name = prop_getter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001929 }
1930
1931 if (prop_setter_name && prop_setter_name[0] == '-')
1932 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001933 ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true);
1934 prop_setter_name = prop_setter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001935 }
1936
1937 // If the names haven't been provided, they need to be
1938 // filled in.
1939
1940 if (!prop_getter_name)
1941 {
1942 prop_getter_name = prop_name;
1943 }
1944 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly))
1945 {
1946 StreamString ss;
1947
1948 ss.Printf("set%c%s:",
1949 toupper(prop_name[0]),
1950 &prop_name[1]);
1951
1952 fixed_setter.SetCString(ss.GetData());
1953 prop_setter_name = fixed_setter.GetCString();
1954 }
Sean Callanan751aac62012-03-29 19:07:06 +00001955 }
1956
1957 // Clang has a DWARF generation bug where sometimes it
Greg Clayton44953932011-10-25 01:25:35 +00001958 // represents fields that are references with bad byte size
1959 // and bit size/offset information such as:
1960 //
1961 // DW_AT_byte_size( 0x00 )
1962 // DW_AT_bit_size( 0x40 )
1963 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1964 //
1965 // So check the bit offset to make sure it is sane, and if
1966 // the values are not sane, remove them. If we don't do this
1967 // then we will end up with a crash if we try to use this
1968 // type in an expression when clang becomes unhappy with its
1969 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001970
Greg Clayton44953932011-10-25 01:25:35 +00001971 if (bit_offset > 128)
1972 {
1973 bit_size = 0;
1974 bit_offset = 0;
1975 }
1976
1977 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00001978 if (class_language == eLanguageTypeObjC ||
1979 class_language == eLanguageTypeObjC_plus_plus)
1980 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001981
1982 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1983 {
1984 // Not all compilers will mark the vtable pointer
1985 // member as artificial (llvm-gcc). We can't have
1986 // the virtual members in our classes otherwise it
1987 // throws off all child offsets since we end up
1988 // having and extra pointer sized member in our
1989 // class layouts.
1990 is_artificial = true;
1991 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001992
Greg Clayton29659712013-07-12 20:08:35 +00001993 // Handle static members
Greg Claytone528efd72013-02-26 23:45:18 +00001994 if (is_external && member_byte_offset == UINT32_MAX)
Greg Clayton973b6c92013-04-11 16:57:51 +00001995 {
1996 Type *var_type = ResolveTypeUID(encoding_uid);
1997
1998 if (var_type)
1999 {
Greg Clayton29659712013-07-12 20:08:35 +00002000 if (accessibility == eAccessNone)
2001 accessibility = eAccessPublic;
Greg Clayton57ee3062013-07-11 22:46:58 +00002002 class_clang_type.AddVariableToRecordType (name,
2003 var_type->GetClangLayoutType(),
2004 accessibility);
Greg Clayton973b6c92013-04-11 16:57:51 +00002005 }
Greg Claytone528efd72013-02-26 23:45:18 +00002006 break;
Greg Clayton973b6c92013-04-11 16:57:51 +00002007 }
Greg Claytone528efd72013-02-26 23:45:18 +00002008
Greg Clayton24739922010-10-13 03:15:28 +00002009 if (is_artificial == false)
2010 {
2011 Type *member_type = ResolveTypeUID(encoding_uid);
Sean Callananfa3ab452012-12-14 00:54:13 +00002012
Jim Inghame3ae82a2011-11-12 01:36:43 +00002013 clang::FieldDecl *field_decl = NULL;
Sean Callanan751aac62012-03-29 19:07:06 +00002014 if (tag == DW_TAG_member)
Greg Claytond16e1e52011-07-12 17:06:17 +00002015 {
Sean Callanan751aac62012-03-29 19:07:06 +00002016 if (member_type)
2017 {
2018 if (accessibility == eAccessNone)
2019 accessibility = default_accessibility;
2020 member_accessibilities.push_back(accessibility);
Sean Callananfaa0bb32012-12-05 23:37:14 +00002021
Greg Clayton78f4d952013-12-11 23:10:39 +00002022 uint64_t field_bit_offset = (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
2023 if (bit_size > 0)
Greg Clayton88bc7f32012-11-06 00:20:41 +00002024 {
Greg Clayton78f4d952013-12-11 23:10:39 +00002025
2026 BitfieldInfo this_field_info;
2027 this_field_info.bit_offset = field_bit_offset;
2028 this_field_info.bit_size = bit_size;
2029
Sean Callananfaa0bb32012-12-05 23:37:14 +00002030 /////////////////////////////////////////////////////////////
2031 // How to locate a field given the DWARF debug information
2032 //
2033 // AT_byte_size indicates the size of the word in which the
2034 // bit offset must be interpreted.
2035 //
2036 // AT_data_member_location indicates the byte offset of the
2037 // word from the base address of the structure.
2038 //
2039 // AT_bit_offset indicates how many bits into the word
2040 // (according to the host endianness) the low-order bit of
2041 // the field starts. AT_bit_offset can be negative.
2042 //
2043 // AT_bit_size indicates the size of the field in bits.
2044 /////////////////////////////////////////////////////////////
2045
Greg Clayton78f4d952013-12-11 23:10:39 +00002046 if (byte_size == 0)
2047 byte_size = member_type->GetByteSize();
2048
Sean Callananfaa0bb32012-12-05 23:37:14 +00002049 if (GetObjectFile()->GetByteOrder() == eByteOrderLittle)
2050 {
2051 this_field_info.bit_offset += byte_size * 8;
2052 this_field_info.bit_offset -= (bit_offset + bit_size);
2053 }
2054 else
2055 {
2056 this_field_info.bit_offset += bit_offset;
2057 }
Greg Clayton78f4d952013-12-11 23:10:39 +00002058
2059 // Update the field bit offset we will report for layout
2060 field_bit_offset = this_field_info.bit_offset;
Sean Callananfaa0bb32012-12-05 23:37:14 +00002061
Greg Clayton78f4d952013-12-11 23:10:39 +00002062 // If the member to be emitted did not start on a character boundary and there is
2063 // empty space between the last field and this one, then we need to emit an
2064 // anonymous member filling up the space up to its start. There are three cases
2065 // here:
2066 //
2067 // 1 If the previous member ended on a character boundary, then we can emit an
2068 // anonymous member starting at the most recent character boundary.
2069 //
2070 // 2 If the previous member did not end on a character boundary and the distance
2071 // from the end of the previous member to the current member is less than a
2072 // word width, then we can emit an anonymous member starting right after the
2073 // previous member and right before this member.
2074 //
2075 // 3 If the previous member did not end on a character boundary and the distance
2076 // from the end of the previous member to the current member is greater than
2077 // or equal a word width, then we act as in Case 1.
2078
2079 const uint64_t character_width = 8;
2080 const uint64_t word_width = 32;
2081
Sean Callananfaa0bb32012-12-05 23:37:14 +00002082 // Objective-C has invalid DW_AT_bit_offset values in older versions
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +00002083 // of clang, so we have to be careful and only insert unnamed bitfields
Greg Clayton37c36e42012-11-27 00:59:26 +00002084 // if we have a new enough clang.
2085 bool detect_unnamed_bitfields = true;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002086
Greg Clayton37c36e42012-11-27 00:59:26 +00002087 if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus)
2088 detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields ();
2089
2090 if (detect_unnamed_bitfields)
Greg Clayton88bc7f32012-11-06 00:20:41 +00002091 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00002092 BitfieldInfo anon_field_info;
2093
2094 if ((this_field_info.bit_offset % character_width) != 0) // not char aligned
Greg Clayton88bc7f32012-11-06 00:20:41 +00002095 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00002096 uint64_t last_field_end = 0;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002097
Sean Callananfaa0bb32012-12-05 23:37:14 +00002098 if (last_field_info.IsValid())
2099 last_field_end = last_field_info.bit_offset + last_field_info.bit_size;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002100
Sean Callananfaa0bb32012-12-05 23:37:14 +00002101 if (this_field_info.bit_offset != last_field_end)
2102 {
2103 if (((last_field_end % character_width) == 0) || // case 1
2104 (this_field_info.bit_offset - last_field_end >= word_width)) // case 3
2105 {
2106 anon_field_info.bit_size = this_field_info.bit_offset % character_width;
2107 anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size;
2108 }
2109 else // case 2
2110 {
2111 anon_field_info.bit_size = this_field_info.bit_offset - last_field_end;
2112 anon_field_info.bit_offset = last_field_end;
2113 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00002114 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00002115 }
2116
Sean Callananfaa0bb32012-12-05 23:37:14 +00002117 if (anon_field_info.IsValid())
Greg Clayton88bc7f32012-11-06 00:20:41 +00002118 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002119 clang::FieldDecl *unnamed_bitfield_decl = class_clang_type.AddFieldToRecordType (NULL,
2120 GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width),
2121 accessibility,
2122 anon_field_info.bit_size);
Zachary Turner504f38d2015-03-24 16:24:50 +00002123
Zachary Turnera98fac22015-03-24 18:56:08 +00002124 layout_info.field_offsets.insert(
Zachary Turner504f38d2015-03-24 16:24:50 +00002125 std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset));
Greg Clayton88bc7f32012-11-06 00:20:41 +00002126 }
2127 }
Greg Clayton78f4d952013-12-11 23:10:39 +00002128 last_field_info = this_field_info;
2129 }
2130 else
2131 {
2132 last_field_info.Clear();
Greg Clayton88bc7f32012-11-06 00:20:41 +00002133 }
Sean Callananfaa0bb32012-12-05 23:37:14 +00002134
Greg Clayton57ee3062013-07-11 22:46:58 +00002135 ClangASTType member_clang_type = member_type->GetClangLayoutType();
Sean Callananfa3ab452012-12-14 00:54:13 +00002136
2137 {
2138 // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>).
2139 // If the current field is at the end of the structure, then there is definitely no room for extra
2140 // elements and we override the type to array[0].
2141
Greg Clayton57ee3062013-07-11 22:46:58 +00002142 ClangASTType member_array_element_type;
Sean Callananfa3ab452012-12-14 00:54:13 +00002143 uint64_t member_array_size;
2144 bool member_array_is_incomplete;
2145
Greg Clayton57ee3062013-07-11 22:46:58 +00002146 if (member_clang_type.IsArrayType(&member_array_element_type,
2147 &member_array_size,
2148 &member_array_is_incomplete) &&
Sean Callananfa3ab452012-12-14 00:54:13 +00002149 !member_array_is_incomplete)
2150 {
2151 uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX);
2152
2153 if (member_byte_offset >= parent_byte_size)
2154 {
2155 if (member_array_size != 1)
2156 {
2157 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,
2158 MakeUserID(die->GetOffset()),
2159 name,
2160 encoding_uid,
2161 MakeUserID(parent_die->GetOffset()));
2162 }
2163
Greg Clayton1c8ef472013-04-05 23:27:21 +00002164 member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0, false);
Sean Callananfa3ab452012-12-14 00:54:13 +00002165 }
2166 }
2167 }
2168
Greg Clayton57ee3062013-07-11 22:46:58 +00002169 field_decl = class_clang_type.AddFieldToRecordType (name,
2170 member_clang_type,
2171 accessibility,
2172 bit_size);
Sean Callanan60217122012-04-13 00:10:03 +00002173
Greg Claytond0029442013-03-27 01:48:02 +00002174 GetClangASTContext().SetMetadataAsUserID (field_decl, MakeUserID(die->GetOffset()));
Greg Clayton78f4d952013-12-11 23:10:39 +00002175
Zachary Turnera98fac22015-03-24 18:56:08 +00002176 layout_info.field_offsets.insert(std::make_pair(field_decl, field_bit_offset));
Sean Callanan5b26f272012-02-04 08:49:35 +00002177 }
2178 else
2179 {
Sean Callanan751aac62012-03-29 19:07:06 +00002180 if (name)
Daniel Malead01b2952012-11-29 21:49:15 +00002181 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 +00002182 MakeUserID(die->GetOffset()),
2183 name,
2184 encoding_uid);
2185 else
Daniel Malead01b2952012-11-29 21:49:15 +00002186 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 +00002187 MakeUserID(die->GetOffset()),
2188 encoding_uid);
Sean Callanan5b26f272012-02-04 08:49:35 +00002189 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002190 }
Sean Callanan751aac62012-03-29 19:07:06 +00002191
Jim Inghame3ae82a2011-11-12 01:36:43 +00002192 if (prop_name != NULL)
2193 {
Sean Callanan751aac62012-03-29 19:07:06 +00002194 clang::ObjCIvarDecl *ivar_decl = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00002195
Sean Callanan751aac62012-03-29 19:07:06 +00002196 if (field_decl)
2197 {
2198 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
2199 assert (ivar_decl != NULL);
2200 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00002201
Jim Ingham379397632012-10-27 02:54:13 +00002202 ClangASTMetadata metadata;
2203 metadata.SetUserID (MakeUserID(die->GetOffset()));
Greg Clayton57ee3062013-07-11 22:46:58 +00002204 delayed_properties.push_back(DelayedAddObjCClassProperty(class_clang_type,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002205 prop_name,
2206 member_type->GetClangLayoutType(),
2207 ivar_decl,
2208 prop_setter_name,
2209 prop_getter_name,
2210 prop_attributes,
Jim Ingham379397632012-10-27 02:54:13 +00002211 &metadata));
Sean Callanan60217122012-04-13 00:10:03 +00002212
Sean Callananad880762012-04-18 01:06:17 +00002213 if (ivar_decl)
Greg Claytond0029442013-03-27 01:48:02 +00002214 GetClangASTContext().SetMetadataAsUserID (ivar_decl, MakeUserID(die->GetOffset()));
Jim Inghame3ae82a2011-11-12 01:36:43 +00002215 }
Greg Clayton24739922010-10-13 03:15:28 +00002216 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002217 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00002218 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002219 }
2220 break;
2221
2222 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00002223 // Let the type parsing code handle this one for us.
2224 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002225 break;
2226
2227 case DW_TAG_inheritance:
2228 {
2229 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00002230 if (default_accessibility == eAccessNone)
2231 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002232 // TODO: implement DW_TAG_inheritance type parsing
2233 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00002234 const size_t num_attributes = die->GetAttributes (this,
2235 dwarf_cu,
2236 fixed_form_sizes,
2237 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002238 if (num_attributes > 0)
2239 {
2240 Declaration decl;
2241 DWARFExpression location;
2242 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00002243 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002244 bool is_virtual = false;
2245 bool is_base_of_class = true;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002246 off_t member_byte_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002247 uint32_t i;
2248 for (i=0; i<num_attributes; ++i)
2249 {
2250 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2251 DWARFFormValue form_value;
2252 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2253 {
2254 switch (attr)
2255 {
2256 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2257 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2258 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00002259 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002260 case DW_AT_data_member_location:
2261 if (form_value.BlockData())
2262 {
2263 Value initialValue(0);
2264 Value memberOffset(0);
Ed Masteeeae7212013-10-24 20:43:47 +00002265 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002266 uint32_t block_length = form_value.Unsigned();
2267 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
2268 if (DWARFExpression::Evaluate (NULL,
2269 NULL,
2270 NULL,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002271 NULL,
Richard Mitton0a558352013-10-17 21:14:00 +00002272 module,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002273 debug_info_data,
2274 block_offset,
2275 block_length,
2276 eRegisterKindDWARF,
2277 &initialValue,
2278 memberOffset,
2279 NULL))
2280 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002281 member_byte_offset = memberOffset.ResolveValue(NULL).UInt();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002282 }
2283 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002284 else
2285 {
2286 // With DWARF 3 and later, if the value is an integer constant,
2287 // this form value is the offset in bytes from the beginning
2288 // of the containing entity.
2289 member_byte_offset = form_value.Unsigned();
2290 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002291 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002292
2293 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00002294 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002295 break;
2296
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002297 case DW_AT_virtuality:
2298 is_virtual = form_value.Boolean();
2299 break;
2300
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002301 case DW_AT_sibling:
2302 break;
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002303
2304 default:
2305 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002306 }
2307 }
2308 }
2309
Greg Clayton526e5af2010-11-13 03:52:47 +00002310 Type *base_class_type = ResolveTypeUID(encoding_uid);
2311 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002312
Greg Clayton57ee3062013-07-11 22:46:58 +00002313 ClangASTType base_class_clang_type = base_class_type->GetClangFullType();
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002314 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002315 if (class_language == eLanguageTypeObjC)
2316 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002317 class_clang_type.SetObjCSuperClass(base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002318 }
2319 else
2320 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002321 base_classes.push_back (base_class_clang_type.CreateBaseClassSpecifier (accessibility,
Greg Claytonba2d22d2010-11-13 22:57:37 +00002322 is_virtual,
2323 is_base_of_class));
Greg Clayton2508b9b2012-11-01 23:20:02 +00002324
2325 if (is_virtual)
2326 {
Greg Clayton52694e32013-09-16 21:57:07 +00002327 // Do not specify any offset for virtual inheritance. The DWARF produced by clang doesn't
2328 // give us a constant offset, but gives us a DWARF expressions that requires an actual object
2329 // in memory. the DW_AT_data_member_location for a virtual base class looks like:
2330 // DW_AT_data_member_location( DW_OP_dup, DW_OP_deref, DW_OP_constu(0x00000018), DW_OP_minus, DW_OP_deref, DW_OP_plus )
2331 // Given this, there is really no valid response we can give to clang for virtual base
2332 // class offsets, and this should eventually be removed from LayoutRecordType() in the external
2333 // AST source in clang.
Greg Clayton2508b9b2012-11-01 23:20:02 +00002334 }
2335 else
2336 {
Zachary Turnera98fac22015-03-24 18:56:08 +00002337 layout_info.base_offsets.insert(
Zachary Turner504f38d2015-03-24 16:24:50 +00002338 std::make_pair(base_class_clang_type.GetAsCXXRecordDecl(),
2339 clang::CharUnits::fromQuantity(member_byte_offset)));
Greg Clayton2508b9b2012-11-01 23:20:02 +00002340 }
Greg Clayton9e409562010-07-28 02:04:09 +00002341 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002342 }
2343 }
2344 break;
2345
2346 default:
2347 break;
2348 }
2349 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002350
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002351 return count;
2352}
2353
2354
2355clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00002356SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002357{
2358 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00002359 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002360 {
2361 DWARFCompileUnitSP cu_sp;
2362 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
2363 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00002364 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00002365 }
2366 return NULL;
2367}
2368
2369clang::DeclContext*
2370SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
2371{
Greg Clayton81c22f62011-10-19 18:09:39 +00002372 if (UserIDMatches(type_uid))
2373 return GetClangDeclContextForDIEOffset (sc, type_uid);
2374 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002375}
2376
2377Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00002378SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002379{
Greg Clayton81c22f62011-10-19 18:09:39 +00002380 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002381 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002382 DWARFDebugInfo* debug_info = DebugInfo();
2383 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00002384 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002385 DWARFCompileUnitSP cu_sp;
2386 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00002387 const bool assert_not_being_parsed = true;
2388 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00002389 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002390 }
2391 return NULL;
2392}
2393
Greg Claytoncab36a32011-12-08 05:16:30 +00002394Type*
2395SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00002396{
Greg Claytoncab36a32011-12-08 05:16:30 +00002397 if (die != NULL)
2398 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002399 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00002400 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002401 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002402 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
2403 die->GetOffset(),
2404 DW_TAG_value_to_name(die->Tag()),
2405 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00002406
Greg Claytoncab36a32011-12-08 05:16:30 +00002407 // We might be coming in in the middle of a type tree (a class
2408 // withing a class, an enum within a class), so parse any needed
2409 // parent DIEs before we get to this one...
2410 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2411 switch (decl_ctx_die->Tag())
2412 {
2413 case DW_TAG_structure_type:
2414 case DW_TAG_union_type:
2415 case DW_TAG_class_type:
2416 {
2417 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00002418 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002419 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002420 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
2421 die->GetOffset(),
2422 DW_TAG_value_to_name(die->Tag()),
2423 die->GetName(this, cu),
2424 decl_ctx_die->GetOffset());
Greg Clayton219cf312012-03-30 00:51:13 +00002425//
2426// Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
2427// if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
2428// {
2429// if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002430// GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton219cf312012-03-30 00:51:13 +00002431// "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
2432// die->GetOffset(),
2433// DW_TAG_value_to_name(die->Tag()),
2434// die->GetName(this, cu),
2435// decl_ctx_die->GetOffset());
2436// // Ask the type to complete itself if it already hasn't since if we
2437// // want a function (method or static) from a class, the class must
2438// // create itself and add it's own methods and class functions.
2439// if (parent_type)
2440// parent_type->GetClangFullType();
2441// }
Greg Claytoncab36a32011-12-08 05:16:30 +00002442 }
2443 break;
2444
2445 default:
2446 break;
2447 }
2448 return ResolveType (cu, die);
2449 }
2450 return NULL;
2451}
2452
Greg Clayton6beaaa62011-01-17 03:46:26 +00002453// This function is used when SymbolFileDWARFDebugMap owns a bunch of
2454// SymbolFileDWARF objects to detect if this DWARF file is the one that
2455// can resolve a clang_type.
2456bool
Greg Clayton57ee3062013-07-11 22:46:58 +00002457SymbolFileDWARF::HasForwardDeclForClangType (const ClangASTType &clang_type)
Greg Clayton6beaaa62011-01-17 03:46:26 +00002458{
Greg Clayton57ee3062013-07-11 22:46:58 +00002459 ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers();
2460 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton6beaaa62011-01-17 03:46:26 +00002461 return die != NULL;
2462}
2463
2464
Greg Clayton57ee3062013-07-11 22:46:58 +00002465bool
2466SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (ClangASTType &clang_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00002467{
2468 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton57ee3062013-07-11 22:46:58 +00002469 ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers();
2470 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton1be10fc2010-09-29 01:12:09 +00002471 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00002472 {
2473 // We have already resolved this type...
Greg Clayton57ee3062013-07-11 22:46:58 +00002474 return true;
Greg Clayton73b472d2010-10-27 03:32:59 +00002475 }
2476 // Once we start resolving this type, remove it from the forward declaration
2477 // map in case anyone child members or other types require this type to get resolved.
2478 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
2479 // are done.
Greg Clayton57ee3062013-07-11 22:46:58 +00002480 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton1be10fc2010-09-29 01:12:09 +00002481
Greg Clayton85ae2e12011-10-18 23:36:41 +00002482 // Disable external storage for this type so we don't get anymore
2483 // clang::ExternalASTSource queries for this type.
Greg Clayton57ee3062013-07-11 22:46:58 +00002484 clang_type.SetHasExternalStorage (false);
Greg Clayton85ae2e12011-10-18 23:36:41 +00002485
Greg Clayton450e3f32010-10-12 02:24:53 +00002486 DWARFDebugInfo* debug_info = DebugInfo();
2487
Greg Clayton53eb1c22012-04-02 22:59:12 +00002488 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002489 Type *type = m_die_to_type.lookup (die);
2490
2491 const dw_tag_t tag = die->Tag();
2492
Greg Clayton5160ce52013-03-27 23:08:40 +00002493 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
Greg Clayton3bffb082011-12-10 02:15:28 +00002494 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002495 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002496 "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...",
Greg Claytond61c0fc2012-04-23 22:55:20 +00002497 MakeUserID(die->GetOffset()),
2498 DW_TAG_value_to_name(tag),
2499 type->GetName().AsCString());
Greg Clayton1be10fc2010-09-29 01:12:09 +00002500 assert (clang_type);
2501 DWARFDebugInfoEntry::Attributes attributes;
2502
Greg Clayton1be10fc2010-09-29 01:12:09 +00002503 switch (tag)
2504 {
2505 case DW_TAG_structure_type:
2506 case DW_TAG_union_type:
2507 case DW_TAG_class_type:
Greg Claytonc93237c2010-10-01 20:48:32 +00002508 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002509 LayoutInfo layout_info;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002510
Greg Clayton1be10fc2010-09-29 01:12:09 +00002511 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002512 if (die->HasChildren())
Greg Claytonc93237c2010-10-01 20:48:32 +00002513 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002514 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton57ee3062013-07-11 22:46:58 +00002515 if (clang_type.IsObjCObjectOrInterfaceType())
Greg Clayton219cf312012-03-30 00:51:13 +00002516 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002517 class_language = eLanguageTypeObjC;
Greg Clayton219cf312012-03-30 00:51:13 +00002518 // For objective C we don't start the definition when
2519 // the class is created.
Greg Clayton57ee3062013-07-11 22:46:58 +00002520 clang_type.StartTagDeclarationDefinition ();
Greg Clayton219cf312012-03-30 00:51:13 +00002521 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002522
Sean Callanan77a1fd32012-02-27 20:07:01 +00002523 int tag_decl_kind = -1;
2524 AccessType default_accessibility = eAccessNone;
2525 if (tag == DW_TAG_structure_type)
2526 {
2527 tag_decl_kind = clang::TTK_Struct;
2528 default_accessibility = eAccessPublic;
2529 }
2530 else if (tag == DW_TAG_union_type)
2531 {
2532 tag_decl_kind = clang::TTK_Union;
2533 default_accessibility = eAccessPublic;
2534 }
2535 else if (tag == DW_TAG_class_type)
2536 {
2537 tag_decl_kind = clang::TTK_Class;
2538 default_accessibility = eAccessPrivate;
2539 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002540
Greg Clayton53eb1c22012-04-02 22:59:12 +00002541 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002542 std::vector<clang::CXXBaseSpecifier *> base_classes;
2543 std::vector<int> member_accessibilities;
2544 bool is_a_class = false;
2545 // Parse members and base classes first
2546 DWARFDIECollection member_function_dies;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002547
Sean Callanana0b80ab2012-06-04 22:28:05 +00002548 DelayedPropertyList delayed_properties;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002549 ParseChildMembers (sc,
Greg Clayton53eb1c22012-04-02 22:59:12 +00002550 dwarf_cu,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002551 die,
2552 clang_type,
2553 class_language,
2554 base_classes,
2555 member_accessibilities,
2556 member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002557 delayed_properties,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002558 default_accessibility,
2559 is_a_class,
2560 layout_info);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002561
Sean Callanan77a1fd32012-02-27 20:07:01 +00002562 // Now parse any methods if there were any...
2563 size_t num_functions = member_function_dies.Size();
2564 if (num_functions > 0)
2565 {
2566 for (size_t i=0; i<num_functions; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002567 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002568 ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytoncaab74e2012-01-28 00:48:57 +00002569 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002570 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002571
Sean Callanan77a1fd32012-02-27 20:07:01 +00002572 if (class_language == eLanguageTypeObjC)
2573 {
Jim Inghamfb6fc0d2013-09-27 20:59:37 +00002574 ConstString class_name (clang_type.GetTypeName());
2575 if (class_name)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002576 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002577 DIEArray method_die_offsets;
2578 if (m_using_apple_tables)
Greg Clayton95d87902011-11-11 03:16:25 +00002579 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002580 if (m_apple_objc_ap.get())
Jim Inghamfb6fc0d2013-09-27 20:59:37 +00002581 m_apple_objc_ap->FindByName(class_name.GetCString(), method_die_offsets);
Sean Callanan77a1fd32012-02-27 20:07:01 +00002582 }
2583 else
2584 {
2585 if (!m_indexed)
2586 Index ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002587
Sean Callanan77a1fd32012-02-27 20:07:01 +00002588 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
2589 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002590
Sean Callanan77a1fd32012-02-27 20:07:01 +00002591 if (!method_die_offsets.empty())
2592 {
2593 DWARFDebugInfo* debug_info = DebugInfo();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002594
Sean Callanan77a1fd32012-02-27 20:07:01 +00002595 DWARFCompileUnit* method_cu = NULL;
2596 const size_t num_matches = method_die_offsets.size();
2597 for (size_t i=0; i<num_matches; ++i)
Greg Clayton95d87902011-11-11 03:16:25 +00002598 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002599 const dw_offset_t die_offset = method_die_offsets[i];
2600 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002601
Sean Callanan77a1fd32012-02-27 20:07:01 +00002602 if (method_die)
2603 ResolveType (method_cu, method_die);
2604 else
Greg Claytoncaab74e2012-01-28 00:48:57 +00002605 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002606 if (m_using_apple_tables)
2607 {
2608 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 +00002609 die_offset, class_name.GetCString());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002610 }
2611 }
2612 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002613 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002614
Greg Clayton57ee3062013-07-11 22:46:58 +00002615 for (DelayedPropertyList::iterator pi = delayed_properties.begin(), pe = delayed_properties.end();
Sean Callanana0b80ab2012-06-04 22:28:05 +00002616 pi != pe;
2617 ++pi)
2618 pi->Finalize();
Greg Clayton450e3f32010-10-12 02:24:53 +00002619 }
2620 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002621
Sean Callanan77a1fd32012-02-27 20:07:01 +00002622 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2623 // need to tell the clang type it is actually a class.
2624 if (class_language != eLanguageTypeObjC)
2625 {
2626 if (is_a_class && tag_decl_kind != clang::TTK_Class)
Greg Clayton57ee3062013-07-11 22:46:58 +00002627 clang_type.SetTagTypeKind (clang::TTK_Class);
Sean Callanan77a1fd32012-02-27 20:07:01 +00002628 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002629
Sean Callanan77a1fd32012-02-27 20:07:01 +00002630 // Since DW_TAG_structure_type gets used for both classes
2631 // and structures, we may need to set any DW_TAG_member
2632 // fields to have a "private" access if none was specified.
2633 // When we parsed the child members we tracked that actual
2634 // accessibility value for each DW_TAG_member in the
2635 // "member_accessibilities" array. If the value for the
2636 // member is zero, then it was set to the "default_accessibility"
2637 // which for structs was "public". Below we correct this
2638 // by setting any fields to "private" that weren't correctly
2639 // set.
2640 if (is_a_class && !member_accessibilities.empty())
2641 {
2642 // This is a class and all members that didn't have
2643 // their access specified are private.
Greg Clayton57ee3062013-07-11 22:46:58 +00002644 clang_type.SetDefaultAccessForRecordFields (eAccessPrivate,
2645 &member_accessibilities.front(),
2646 member_accessibilities.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002647 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002648
Sean Callanan77a1fd32012-02-27 20:07:01 +00002649 if (!base_classes.empty())
2650 {
Greg Clayton4705f8d2013-12-12 01:54:04 +00002651 // Make sure all base classes refer to complete types and not
2652 // forward declarations. If we don't do this, clang will crash
2653 // with an assertion in the call to clang_type.SetBaseClassesForClassType()
2654 bool base_class_error = false;
2655 for (auto &base_class : base_classes)
2656 {
2657 clang::TypeSourceInfo *type_source_info = base_class->getTypeSourceInfo();
2658 if (type_source_info)
2659 {
2660 ClangASTType base_class_type (GetClangASTContext().getASTContext(), type_source_info->getType());
2661 if (base_class_type.GetCompleteType() == false)
2662 {
2663 if (!base_class_error)
2664 {
2665 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",
2666 die->GetOffset(),
2667 die->GetName(this, dwarf_cu),
2668 base_class_type.GetTypeName().GetCString(),
2669 sc.comp_unit ? sc.comp_unit->GetPath().c_str() : "the source file");
2670 }
2671 // We have no choice other than to pretend that the base class
2672 // is complete. If we don't do this, clang will crash when we
2673 // call setBases() inside of "clang_type.SetBaseClassesForClassType()"
2674 // below. Since we provide layout assistance, all ivars in this
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00002675 // class and other classes will be fine, this is the best we can do
Greg Clayton4705f8d2013-12-12 01:54:04 +00002676 // short of crashing.
2677 base_class_type.StartTagDeclarationDefinition ();
2678 base_class_type.CompleteTagDeclarationDefinition ();
2679 }
2680 }
2681 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002682 clang_type.SetBaseClassesForClassType (&base_classes.front(),
2683 base_classes.size());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002684
Sean Callanan77a1fd32012-02-27 20:07:01 +00002685 // Clang will copy each CXXBaseSpecifier in "base_classes"
2686 // so we have to free them all.
Greg Clayton57ee3062013-07-11 22:46:58 +00002687 ClangASTType::DeleteBaseClassSpecifiers (&base_classes.front(),
2688 base_classes.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002689 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002690 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002691 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002692
Greg Clayton57ee3062013-07-11 22:46:58 +00002693 clang_type.BuildIndirectFields ();
2694 clang_type.CompleteTagDeclarationDefinition ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002695
Greg Clayton2508b9b2012-11-01 23:20:02 +00002696 if (!layout_info.field_offsets.empty() ||
2697 !layout_info.base_offsets.empty() ||
2698 !layout_info.vbase_offsets.empty() )
Greg Claytoncaab74e2012-01-28 00:48:57 +00002699 {
2700 if (type)
2701 layout_info.bit_size = type->GetByteSize() * 8;
2702 if (layout_info.bit_size == 0)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002703 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002704
Greg Clayton57ee3062013-07-11 22:46:58 +00002705 clang::CXXRecordDecl *record_decl = clang_type.GetAsCXXRecordDecl();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002706 if (record_decl)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002707 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002708 if (log)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002709 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002710 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002711 "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 +00002712 static_cast<void*>(clang_type.GetOpaqueQualType()),
2713 static_cast<void*>(record_decl),
Greg Claytoncaab74e2012-01-28 00:48:57 +00002714 layout_info.bit_size,
2715 layout_info.alignment,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002716 static_cast<uint32_t>(layout_info.field_offsets.size()),
2717 static_cast<uint32_t>(layout_info.base_offsets.size()),
2718 static_cast<uint32_t>(layout_info.vbase_offsets.size()));
2719
Zachary Turnera98fac22015-03-24 18:56:08 +00002720 uint32_t idx;
2721 {
2722 llvm::DenseMap<const clang::FieldDecl *, uint64_t>::const_iterator pos,
2723 end = layout_info.field_offsets.end();
2724 for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx)
Greg Clayton2508b9b2012-11-01 23:20:02 +00002725 {
Zachary Turner504f38d2015-03-24 16:24:50 +00002726 GetObjectFile()->GetModule()->LogMessage(
2727 log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = "
2728 "{ bit_offset=%u, name='%s' }",
Zachary Turner504f38d2015-03-24 16:24:50 +00002729 static_cast<void *>(clang_type.GetOpaqueQualType()), idx,
Zachary Turnera98fac22015-03-24 18:56:08 +00002730 static_cast<uint32_t>(pos->second), pos->first->getNameAsString().c_str());
2731 }
2732 }
2733
2734 {
2735 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos,
2736 base_end = layout_info.base_offsets.end();
2737 for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end;
2738 ++base_pos, ++idx)
2739 {
2740 GetObjectFile()->GetModule()->LogMessage(
2741 log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] "
2742 "= { byte_offset=%u, name='%s' }",
2743 clang_type.GetOpaqueQualType(), idx, (uint32_t)base_pos->second.getQuantity(),
2744 base_pos->first->getNameAsString().c_str());
2745 }
2746 }
2747 {
2748 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos,
2749 vbase_end = layout_info.vbase_offsets.end();
2750 for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end;
2751 ++vbase_pos, ++idx)
2752 {
2753 GetObjectFile()->GetModule()->LogMessage(
2754 log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) "
2755 "vbase[%u] = { byte_offset=%u, name='%s' }",
2756 static_cast<void *>(clang_type.GetOpaqueQualType()), idx,
2757 static_cast<uint32_t>(vbase_pos->second.getQuantity()),
2758 vbase_pos->first->getNameAsString().c_str());
2759 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002760 }
Greg Clayton821ac6d2012-01-28 02:22:27 +00002761 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002762 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2763 }
2764 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002765 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002766
Sean Callanan9076c0f2013-10-04 21:35:29 +00002767 return (bool)clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002768
2769 case DW_TAG_enumeration_type:
Greg Clayton57ee3062013-07-11 22:46:58 +00002770 clang_type.StartTagDeclarationDefinition ();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002771 if (die->HasChildren())
2772 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002773 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00002774 bool is_signed = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00002775 clang_type.IsIntegerType(is_signed);
Greg Clayton3e067532013-03-05 23:54:39 +00002776 ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002777 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002778 clang_type.CompleteTagDeclarationDefinition ();
Sean Callanan9076c0f2013-10-04 21:35:29 +00002779 return (bool)clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002780
2781 default:
2782 assert(false && "not a forward clang type decl!");
2783 break;
2784 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002785 return false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002786}
2787
Greg Claytonc685f8e2010-09-15 04:15:46 +00002788Type*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002789SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002790{
2791 if (type_die != NULL)
2792 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002793 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00002794
Greg Claytonc685f8e2010-09-15 04:15:46 +00002795 if (type == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002796 type = GetTypeForDIE (dwarf_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00002797
Greg Clayton24739922010-10-13 03:15:28 +00002798 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00002799 {
2800 if (type != DIE_IS_BEING_PARSED)
2801 return type;
2802
2803 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
Greg Clayton53eb1c22012-04-02 22:59:12 +00002804 type_die->GetOffset(),
2805 DW_TAG_value_to_name(type_die->Tag()),
2806 type_die->GetName(this, dwarf_cu));
Jim Inghamc3549282012-01-11 02:21:12 +00002807
2808 }
2809 else
2810 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002811 }
2812 return NULL;
2813}
2814
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002815CompileUnit*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002816SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002817{
2818 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002819 if (dwarf_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002820 {
2821 // The symbol vendor doesn't know about this compile unit, we
2822 // need to parse and add it to the symbol vendor object.
Greg Clayton53eb1c22012-04-02 22:59:12 +00002823 return ParseCompileUnit(dwarf_cu, cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002824 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00002825 return (CompileUnit*)dwarf_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002826}
2827
2828bool
Greg Clayton53eb1c22012-04-02 22:59:12 +00002829SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002830{
Greg Clayton72310352013-02-23 04:12:47 +00002831 sc.Clear(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002832 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002833 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002834
Greg Clayton81c22f62011-10-19 18:09:39 +00002835 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002836 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002837 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002838
2839 if (sc.function)
2840 {
Greg Claytone72dfb32012-02-24 01:59:29 +00002841 sc.module_sp = sc.function->CalculateSymbolContextModule();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002842 return true;
2843 }
2844
2845 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002846}
2847
Greg Clayton2501e5e2015-01-15 02:59:20 +00002848
2849
2850SymbolFileDWARF::GlobalVariableMap &
2851SymbolFileDWARF::GetGlobalAranges()
2852{
2853 if (!m_global_aranges_ap)
2854 {
2855 m_global_aranges_ap.reset (new GlobalVariableMap());
2856
2857 ModuleSP module_sp = GetObjectFile()->GetModule();
2858 if (module_sp)
2859 {
2860 const size_t num_cus = module_sp->GetNumCompileUnits();
2861 for (size_t i = 0; i < num_cus; ++i)
2862 {
2863 CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(i);
2864 if (cu_sp)
2865 {
2866 VariableListSP globals_sp = cu_sp->GetVariableList(true);
2867 if (globals_sp)
2868 {
2869 const size_t num_globals = globals_sp->GetSize();
2870 for (size_t g = 0; g < num_globals; ++g)
2871 {
2872 VariableSP var_sp = globals_sp->GetVariableAtIndex(g);
2873 if (var_sp && !var_sp->GetLocationIsConstantValueData())
2874 {
2875 const DWARFExpression &location = var_sp->LocationExpression();
2876 Value location_result;
2877 Error error;
2878 if (location.Evaluate(NULL, NULL, NULL, LLDB_INVALID_ADDRESS, NULL, location_result, &error))
2879 {
2880 if (location_result.GetValueType() == Value::eValueTypeFileAddress)
2881 {
2882 lldb::addr_t file_addr = location_result.GetScalar().ULongLong();
2883 lldb::addr_t byte_size = 1;
2884 if (var_sp->GetType())
2885 byte_size = var_sp->GetType()->GetByteSize();
2886 m_global_aranges_ap->Append(GlobalVariableMap::Entry(file_addr, byte_size, var_sp.get()));
2887 }
2888 }
2889 }
2890 }
2891 }
2892 }
2893 }
2894 }
2895 m_global_aranges_ap->Sort();
2896 }
2897 return *m_global_aranges_ap;
2898}
2899
2900
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002901uint32_t
2902SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2903{
2904 Timer scoped_timer(__PRETTY_FUNCTION__,
Daniel Malead01b2952012-11-29 21:49:15 +00002905 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002906 static_cast<void*>(so_addr.GetSection().get()),
2907 so_addr.GetOffset(), resolve_scope);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002908 uint32_t resolved = 0;
Greg Clayton2501e5e2015-01-15 02:59:20 +00002909 if (resolve_scope & ( eSymbolContextCompUnit |
2910 eSymbolContextFunction |
2911 eSymbolContextBlock |
2912 eSymbolContextLineEntry |
2913 eSymbolContextVariable ))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002914 {
2915 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2916
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002917 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00002918 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002919 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002920 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Greg Clayton2501e5e2015-01-15 02:59:20 +00002921 if (cu_offset == DW_INVALID_OFFSET)
2922 {
2923 // Global variables are not in the compile unit address ranges. The only way to
2924 // currently find global variables is to iterate over the .debug_pubnames or the
2925 // __apple_names table and find all items in there that point to DW_TAG_variable
2926 // DIEs and then find the address that matches.
2927 if (resolve_scope & eSymbolContextVariable)
2928 {
2929 GlobalVariableMap &map = GetGlobalAranges();
2930 const GlobalVariableMap::Entry *entry = map.FindEntryThatContains(file_vm_addr);
2931 if (entry && entry->data)
2932 {
2933 Variable *variable = entry->data;
2934 SymbolContextScope *scc = variable->GetSymbolContextScope();
2935 if (scc)
2936 {
2937 scc->CalculateSymbolContext(&sc);
2938 sc.variable = variable;
2939 }
2940 return sc.GetResolvedMask();
2941 }
2942 }
2943 }
2944 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002945 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002946 uint32_t cu_idx = DW_INVALID_INDEX;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002947 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
2948 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002949 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002950 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002951 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002952 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002953 resolved |= eSymbolContextCompUnit;
2954
Greg Clayton6ab80132012-12-12 17:30:52 +00002955 bool force_check_line_table = false;
Greg Clayton526a4ae2012-05-16 22:09:01 +00002956 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2957 {
2958 DWARFDebugInfoEntry *function_die = NULL;
2959 DWARFDebugInfoEntry *block_die = NULL;
2960 if (resolve_scope & eSymbolContextBlock)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002961 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002962 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
2963 }
2964 else
2965 {
2966 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL);
2967 }
2968
2969 if (function_die != NULL)
2970 {
2971 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2972 if (sc.function == NULL)
2973 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2974 }
2975 else
2976 {
2977 // We might have had a compile unit that had discontiguous
2978 // address ranges where the gaps are symbols that don't have
2979 // any debug info. Discontiguous compile unit address ranges
2980 // should only happen when there aren't other functions from
2981 // other compile units in these gaps. This helps keep the size
2982 // of the aranges down.
Greg Clayton6ab80132012-12-12 17:30:52 +00002983 force_check_line_table = true;
Greg Clayton526a4ae2012-05-16 22:09:01 +00002984 }
2985
2986 if (sc.function != NULL)
2987 {
2988 resolved |= eSymbolContextFunction;
2989
2990 if (resolve_scope & eSymbolContextBlock)
2991 {
2992 Block& block = sc.function->GetBlock (true);
2993
2994 if (block_die != NULL)
2995 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2996 else
2997 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2998 if (sc.block)
2999 resolved |= eSymbolContextBlock;
3000 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003001 }
3002 }
Greg Clayton6ab80132012-12-12 17:30:52 +00003003
3004 if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table)
3005 {
3006 LineTable *line_table = sc.comp_unit->GetLineTable();
3007 if (line_table != NULL)
3008 {
Greg Clayton9422dd62013-03-04 21:46:16 +00003009 // And address that makes it into this function should be in terms
3010 // of this debug file if there is no debug map, or it will be an
3011 // address in the .o file which needs to be fixed up to be in terms
3012 // of the debug map executable. Either way, calling FixupAddress()
3013 // will work for us.
3014 Address exe_so_addr (so_addr);
3015 if (FixupAddress(exe_so_addr))
Greg Clayton6ab80132012-12-12 17:30:52 +00003016 {
Greg Clayton9422dd62013-03-04 21:46:16 +00003017 if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry))
Greg Clayton6ab80132012-12-12 17:30:52 +00003018 {
3019 resolved |= eSymbolContextLineEntry;
3020 }
3021 }
Greg Clayton6ab80132012-12-12 17:30:52 +00003022 }
3023 }
3024
3025 if (force_check_line_table && !(resolved & eSymbolContextLineEntry))
3026 {
3027 // We might have had a compile unit that had discontiguous
3028 // address ranges where the gaps are symbols that don't have
3029 // any debug info. Discontiguous compile unit address ranges
3030 // should only happen when there aren't other functions from
3031 // other compile units in these gaps. This helps keep the size
3032 // of the aranges down.
3033 sc.comp_unit = NULL;
3034 resolved &= ~eSymbolContextCompUnit;
3035 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003036 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00003037 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003038 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003039 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.",
3040 cu_offset,
3041 cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003042 }
3043 }
3044 }
3045 }
3046 }
3047 return resolved;
3048}
3049
3050
3051
3052uint32_t
3053SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
3054{
3055 const uint32_t prev_size = sc_list.GetSize();
3056 if (resolve_scope & eSymbolContextCompUnit)
3057 {
3058 DWARFDebugInfo* debug_info = DebugInfo();
3059 if (debug_info)
3060 {
3061 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00003062 DWARFCompileUnit* dwarf_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003063
Greg Clayton53eb1c22012-04-02 22:59:12 +00003064 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003065 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003066 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Sean Callananddd7a2a2013-10-03 22:27:29 +00003067 const bool full_match = (bool)file_spec.GetDirectory();
Greg Clayton1f746072012-08-29 21:13:06 +00003068 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 +00003069 if (check_inlines || file_spec_matches_cu_file_spec)
3070 {
3071 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton53eb1c22012-04-02 22:59:12 +00003072 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00003073 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003074 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003075 uint32_t file_idx = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003076
Greg Clayton526a4ae2012-05-16 22:09:01 +00003077 // If we are looking for inline functions only and we don't
3078 // find it in the support files, we are done.
3079 if (check_inlines)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003080 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003081 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
3082 if (file_idx == UINT32_MAX)
3083 continue;
3084 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003085
Greg Clayton526a4ae2012-05-16 22:09:01 +00003086 if (line != 0)
3087 {
3088 LineTable *line_table = sc.comp_unit->GetLineTable();
3089
3090 if (line_table != NULL && line != 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003091 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003092 // We will have already looked up the file index if
3093 // we are searching for inline entries.
3094 if (!check_inlines)
3095 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003096
Greg Clayton526a4ae2012-05-16 22:09:01 +00003097 if (file_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003098 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003099 uint32_t found_line;
3100 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
3101 found_line = sc.line_entry.line;
3102
3103 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003104 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003105 sc.function = NULL;
3106 sc.block = NULL;
3107 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003108 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003109 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
3110 if (file_vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003111 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003112 DWARFDebugInfoEntry *function_die = NULL;
3113 DWARFDebugInfoEntry *block_die = NULL;
3114 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003115
Greg Clayton526a4ae2012-05-16 22:09:01 +00003116 if (function_die != NULL)
3117 {
3118 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
3119 if (sc.function == NULL)
3120 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
3121 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003122
Greg Clayton526a4ae2012-05-16 22:09:01 +00003123 if (sc.function != NULL)
3124 {
3125 Block& block = sc.function->GetBlock (true);
3126
3127 if (block_die != NULL)
3128 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
Jason Molenda60db6e42014-10-16 01:40:16 +00003129 else if (function_die != NULL)
Greg Clayton526a4ae2012-05-16 22:09:01 +00003130 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
3131 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003132 }
3133 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003134
Greg Clayton526a4ae2012-05-16 22:09:01 +00003135 sc_list.Append(sc);
3136 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
3137 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003138 }
3139 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00003140 else if (file_spec_matches_cu_file_spec && !check_inlines)
3141 {
3142 // only append the context if we aren't looking for inline call sites
3143 // by file and line and if the file spec matches that of the compile unit
3144 sc_list.Append(sc);
3145 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003146 }
3147 else if (file_spec_matches_cu_file_spec && !check_inlines)
3148 {
3149 // only append the context if we aren't looking for inline call sites
3150 // by file and line and if the file spec matches that of the compile unit
3151 sc_list.Append(sc);
3152 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003153
Greg Clayton526a4ae2012-05-16 22:09:01 +00003154 if (!check_inlines)
3155 break;
3156 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003157 }
3158 }
3159 }
3160 }
3161 return sc_list.GetSize() - prev_size;
3162}
3163
3164void
3165SymbolFileDWARF::Index ()
3166{
3167 if (m_indexed)
3168 return;
3169 m_indexed = true;
3170 Timer scoped_timer (__PRETTY_FUNCTION__,
3171 "SymbolFileDWARF::Index (%s)",
Jim Ingham4af59612014-12-19 19:20:44 +00003172 GetObjectFile()->GetFileSpec().GetFilename().AsCString("<Unknown>"));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003173
3174 DWARFDebugInfo* debug_info = DebugInfo();
3175 if (debug_info)
3176 {
3177 uint32_t cu_idx = 0;
3178 const uint32_t num_compile_units = GetNumCompileUnits();
3179 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
3180 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003181 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003182
Greg Clayton53eb1c22012-04-02 22:59:12 +00003183 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003184
Greg Clayton53eb1c22012-04-02 22:59:12 +00003185 dwarf_cu->Index (cu_idx,
3186 m_function_basename_index,
3187 m_function_fullname_index,
3188 m_function_method_index,
3189 m_function_selector_index,
3190 m_objc_class_selectors_index,
3191 m_global_index,
3192 m_type_index,
3193 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003194
3195 // Keep memory down by clearing DIEs if this generate function
3196 // caused them to be parsed
3197 if (clear_dies)
Greg Clayton53eb1c22012-04-02 22:59:12 +00003198 dwarf_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003199 }
3200
Greg Claytond4a2b372011-09-12 23:21:58 +00003201 m_function_basename_index.Finalize();
3202 m_function_fullname_index.Finalize();
3203 m_function_method_index.Finalize();
3204 m_function_selector_index.Finalize();
3205 m_objc_class_selectors_index.Finalize();
3206 m_global_index.Finalize();
3207 m_type_index.Finalize();
3208 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003209
Greg Clayton24739922010-10-13 03:15:28 +00003210#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00003211 StreamFile s(stdout, false);
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00003212 s.Printf ("DWARF index for '%s':",
3213 GetObjectFile()->GetFileSpec().GetPath().c_str());
Greg Claytonba2d22d2010-11-13 22:57:37 +00003214 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
3215 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
3216 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
3217 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
3218 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
3219 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00003220 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00003221 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00003222#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003223 }
3224}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003225
3226bool
3227SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
3228{
3229 if (namespace_decl == NULL)
3230 {
3231 // Invalid namespace decl which means we aren't matching only things
3232 // in this symbol file, so return true to indicate it matches this
3233 // symbol file.
3234 return true;
3235 }
3236
3237 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
3238
3239 if (namespace_ast == NULL)
3240 return true; // No AST in the "namespace_decl", return true since it
3241 // could then match any symbol file, including this one
3242
3243 if (namespace_ast == GetClangASTContext().getASTContext())
3244 return true; // The ASTs match, return true
3245
3246 // The namespace AST was valid, and it does not match...
Greg Clayton5160ce52013-03-27 23:08:40 +00003247 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Sean Callananc41e68b2011-10-13 21:08:11 +00003248
3249 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003250 GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00003251
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003252 return false;
3253}
3254
Greg Clayton2506a7a2011-10-12 23:34:26 +00003255bool
3256SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
3257 DWARFCompileUnit* cu,
3258 const DWARFDebugInfoEntry* die)
3259{
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +00003260 // No namespace specified, so the answer is
Greg Clayton2506a7a2011-10-12 23:34:26 +00003261 if (namespace_decl == NULL)
3262 return true;
Sean Callananebe60672011-10-13 21:50:33 +00003263
Greg Clayton5160ce52013-03-27 23:08:40 +00003264 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003265
Greg Clayton437a1352012-04-09 22:43:43 +00003266 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
3267 clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00003268 if (decl_ctx_die)
Greg Clayton437a1352012-04-09 22:43:43 +00003269 {
Greg Clayton2506a7a2011-10-12 23:34:26 +00003270 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
Greg Clayton437a1352012-04-09 22:43:43 +00003271
Greg Clayton2506a7a2011-10-12 23:34:26 +00003272 if (clang_namespace_decl)
3273 {
3274 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00003275 {
3276 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003277 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00003278 return false;
Sean Callananebe60672011-10-13 21:50:33 +00003279 }
3280
Greg Clayton437a1352012-04-09 22:43:43 +00003281 if (clang_namespace_decl == die_clang_decl_ctx)
3282 return true;
3283 else
Greg Clayton2506a7a2011-10-12 23:34:26 +00003284 return false;
Greg Clayton2506a7a2011-10-12 23:34:26 +00003285 }
3286 else
3287 {
3288 // We have a namespace_decl that was not NULL but it contained
3289 // a NULL "clang::NamespaceDecl", so this means the global namespace
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00003290 // So as long the contained decl context DIE isn't a namespace
Greg Clayton2506a7a2011-10-12 23:34:26 +00003291 // we should be ok.
3292 if (decl_ctx_die->Tag() != DW_TAG_namespace)
3293 return true;
3294 }
3295 }
Sean Callananebe60672011-10-13 21:50:33 +00003296
3297 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003298 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00003299
Greg Clayton2506a7a2011-10-12 23:34:26 +00003300 return false;
3301}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003302uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00003303SymbolFileDWARF::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 +00003304{
Greg Clayton5160ce52013-03-27 23:08:40 +00003305 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003306
3307 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003308 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003309 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
3310 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003311 static_cast<const void*>(namespace_decl),
3312 append, max_matches);
3313
Sean Callanan213fdb82011-10-13 01:49:10 +00003314 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00003315 return 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003316
Greg Claytonc685f8e2010-09-15 04:15:46 +00003317 DWARFDebugInfo* info = DebugInfo();
3318 if (info == NULL)
3319 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003320
3321 // If we aren't appending the results to this list, then clear the list
3322 if (!append)
3323 variables.Clear();
3324
3325 // Remember how many variables are in the list before we search in case
3326 // we are appending the results to a variable list.
3327 const uint32_t original_size = variables.GetSize();
3328
Greg Claytond4a2b372011-09-12 23:21:58 +00003329 DIEArray die_offsets;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003330
Greg Clayton97fbc342011-10-20 22:30:33 +00003331 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003332 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003333 if (m_apple_names_ap.get())
3334 {
3335 const char *name_cstr = name.GetCString();
Jim Inghamfa39bb42014-10-25 00:33:55 +00003336 llvm::StringRef basename;
3337 llvm::StringRef context;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003338
Jim Inghamfa39bb42014-10-25 00:33:55 +00003339 if (!CPPLanguageRuntime::ExtractContextAndIdentifier(name_cstr, context, basename))
3340 basename = name_cstr;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003341
Jim Inghamfa39bb42014-10-25 00:33:55 +00003342 m_apple_names_ap->FindByName (basename.data(), die_offsets);
Greg Clayton97fbc342011-10-20 22:30:33 +00003343 }
Greg Clayton7f995132011-10-04 22:41:51 +00003344 }
3345 else
3346 {
3347 // Index the DWARF if we haven't already
3348 if (!m_indexed)
3349 Index ();
3350
3351 m_global_index.Find (name, die_offsets);
3352 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003353
Greg Clayton437a1352012-04-09 22:43:43 +00003354 const size_t num_die_matches = die_offsets.size();
3355 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003356 {
Greg Clayton7f995132011-10-04 22:41:51 +00003357 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003358 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00003359 assert (sc.module_sp);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003360
Greg Claytond4a2b372011-09-12 23:21:58 +00003361 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00003362 DWARFCompileUnit* dwarf_cu = NULL;
3363 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton437a1352012-04-09 22:43:43 +00003364 bool done = false;
3365 for (size_t i=0; i<num_die_matches && !done; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00003366 {
3367 const dw_offset_t die_offset = die_offsets[i];
3368 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003369
Greg Clayton95d87902011-11-11 03:16:25 +00003370 if (die)
3371 {
Greg Clayton437a1352012-04-09 22:43:43 +00003372 switch (die->Tag())
3373 {
3374 default:
3375 case DW_TAG_subprogram:
3376 case DW_TAG_inlined_subroutine:
3377 case DW_TAG_try_block:
3378 case DW_TAG_catch_block:
3379 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003380
Greg Clayton437a1352012-04-09 22:43:43 +00003381 case DW_TAG_variable:
3382 {
3383 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003384
Greg Clayton437a1352012-04-09 22:43:43 +00003385 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3386 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003387
Greg Clayton437a1352012-04-09 22:43:43 +00003388 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003389
Greg Clayton437a1352012-04-09 22:43:43 +00003390 if (variables.GetSize() - original_size >= max_matches)
3391 done = true;
3392 }
3393 break;
3394 }
Greg Clayton95d87902011-11-11 03:16:25 +00003395 }
3396 else
3397 {
3398 if (m_using_apple_tables)
3399 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003400 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
3401 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003402 }
3403 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003404 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003405 }
3406
3407 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003408 const uint32_t num_matches = variables.GetSize() - original_size;
3409 if (log && num_matches > 0)
3410 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003411 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003412 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003413 name.GetCString(),
3414 static_cast<const void*>(namespace_decl),
3415 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00003416 num_matches);
3417 }
3418 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003419}
3420
3421uint32_t
3422SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
3423{
Greg Clayton5160ce52013-03-27 23:08:40 +00003424 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003425
Greg Clayton21f2a492011-10-06 00:09:08 +00003426 if (log)
3427 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003428 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003429 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003430 regex.GetText(), append,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003431 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003432 }
3433
Greg Claytonc685f8e2010-09-15 04:15:46 +00003434 DWARFDebugInfo* info = DebugInfo();
3435 if (info == NULL)
3436 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003437
3438 // If we aren't appending the results to this list, then clear the list
3439 if (!append)
3440 variables.Clear();
3441
3442 // Remember how many variables are in the list before we search in case
3443 // we are appending the results to a variable list.
3444 const uint32_t original_size = variables.GetSize();
3445
Greg Clayton7f995132011-10-04 22:41:51 +00003446 DIEArray die_offsets;
3447
Greg Clayton97fbc342011-10-20 22:30:33 +00003448 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003449 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003450 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00003451 {
3452 DWARFMappedHash::DIEInfoArray hash_data_array;
3453 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
3454 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
3455 }
Greg Clayton7f995132011-10-04 22:41:51 +00003456 }
3457 else
3458 {
3459 // Index the DWARF if we haven't already
3460 if (!m_indexed)
3461 Index ();
3462
3463 m_global_index.Find (regex, die_offsets);
3464 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003465
Greg Claytonc685f8e2010-09-15 04:15:46 +00003466 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003467 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003468 assert (sc.module_sp);
3469
Greg Claytond4a2b372011-09-12 23:21:58 +00003470 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00003471 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003472 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003473 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003474 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003475 DWARFDebugInfo* debug_info = DebugInfo();
3476 for (size_t i=0; i<num_matches; ++i)
3477 {
3478 const dw_offset_t die_offset = die_offsets[i];
3479 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00003480
3481 if (die)
3482 {
3483 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003484
Greg Clayton95d87902011-11-11 03:16:25 +00003485 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003486
Greg Clayton95d87902011-11-11 03:16:25 +00003487 if (variables.GetSize() - original_size >= max_matches)
3488 break;
3489 }
3490 else
3491 {
3492 if (m_using_apple_tables)
3493 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003494 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
3495 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00003496 }
3497 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003498 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003499 }
3500
3501 // Return the number of variable that were appended to the list
3502 return variables.GetSize() - original_size;
3503}
3504
Greg Claytonaa044962011-10-13 00:59:38 +00003505
Jim Ingham4cda6e02011-10-07 22:23:45 +00003506bool
3507SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
3508 DWARFCompileUnit *&dwarf_cu,
Pavel Labatha73d6572015-03-13 10:22:00 +00003509 bool include_inlines,
Jim Ingham4cda6e02011-10-07 22:23:45 +00003510 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00003511{
Greg Claytonaa044962011-10-13 00:59:38 +00003512 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Pavel Labatha73d6572015-03-13 10:22:00 +00003513 return ResolveFunction (dwarf_cu, die, include_inlines, sc_list);
Greg Claytonaa044962011-10-13 00:59:38 +00003514}
3515
3516
3517bool
3518SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
3519 const DWARFDebugInfoEntry *die,
Pavel Labatha73d6572015-03-13 10:22:00 +00003520 bool include_inlines,
Greg Claytonaa044962011-10-13 00:59:38 +00003521 SymbolContextList& sc_list)
3522{
Greg Clayton9e315582011-09-02 04:03:59 +00003523 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00003524
3525 if (die == NULL)
3526 return false;
3527
Jim Ingham4cda6e02011-10-07 22:23:45 +00003528 // If we were passed a die that is not a function, just return false...
Pavel Labatha73d6572015-03-13 10:22:00 +00003529 if (! (die->Tag() == DW_TAG_subprogram || (include_inlines && die->Tag() == DW_TAG_inlined_subroutine)))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003530 return false;
3531
3532 const DWARFDebugInfoEntry* inlined_die = NULL;
3533 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00003534 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003535 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00003536
Jim Ingham4cda6e02011-10-07 22:23:45 +00003537 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003538 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003539 if (die->Tag() == DW_TAG_subprogram)
3540 break;
Greg Clayton9e315582011-09-02 04:03:59 +00003541 }
3542 }
Jason Molenda60db6e42014-10-16 01:40:16 +00003543 assert (die && die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00003544 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003545 {
3546 Address addr;
3547 // Parse all blocks if needed
3548 if (inlined_die)
3549 {
Greg Claytonf7bb1fb2015-01-15 03:13:44 +00003550 Block &function_block = sc.function->GetBlock (true);
3551 sc.block = function_block.FindBlockByID (MakeUserID(inlined_die->GetOffset()));
3552 if (sc.block == NULL)
3553 sc.block = function_block.FindBlockByID (inlined_die->GetOffset());
3554 if (sc.block == NULL || sc.block->GetStartAddress (addr) == false)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003555 addr.Clear();
3556 }
3557 else
3558 {
3559 sc.block = NULL;
3560 addr = sc.function->GetAddressRange().GetBaseAddress();
3561 }
3562
3563 if (addr.IsValid())
3564 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003565 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00003566 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003567 }
3568 }
3569
Greg Claytonaa044962011-10-13 00:59:38 +00003570 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00003571}
3572
Greg Clayton7f995132011-10-04 22:41:51 +00003573void
3574SymbolFileDWARF::FindFunctions (const ConstString &name,
3575 const NameToDIE &name_to_die,
Pavel Labatha73d6572015-03-13 10:22:00 +00003576 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003577 SymbolContextList& sc_list)
3578{
Greg Claytond4a2b372011-09-12 23:21:58 +00003579 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003580 if (name_to_die.Find (name, die_offsets))
3581 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003582 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003583 }
3584}
3585
3586
3587void
3588SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3589 const NameToDIE &name_to_die,
Pavel Labatha73d6572015-03-13 10:22:00 +00003590 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003591 SymbolContextList& sc_list)
3592{
3593 DIEArray die_offsets;
3594 if (name_to_die.Find (regex, die_offsets))
3595 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003596 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003597 }
3598}
3599
3600
3601void
3602SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3603 const DWARFMappedHash::MemoryTable &memory_table,
Pavel Labatha73d6572015-03-13 10:22:00 +00003604 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003605 SymbolContextList& sc_list)
3606{
3607 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00003608 DWARFMappedHash::DIEInfoArray hash_data_array;
3609 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00003610 {
Greg Claytond1767f02011-12-08 02:13:16 +00003611 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Pavel Labatha73d6572015-03-13 10:22:00 +00003612 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003613 }
3614}
3615
3616void
3617SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
Pavel Labatha73d6572015-03-13 10:22:00 +00003618 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003619 SymbolContextList& sc_list)
3620{
3621 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003622 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00003623 {
Greg Clayton7f995132011-10-04 22:41:51 +00003624 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003625 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00003626 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003627 const dw_offset_t die_offset = die_offsets[i];
Pavel Labatha73d6572015-03-13 10:22:00 +00003628 ResolveFunction (die_offset, dwarf_cu, include_inlines, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003629 }
3630 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00003631}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003632
Jim Ingham4cda6e02011-10-07 22:23:45 +00003633bool
3634SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
3635 const DWARFCompileUnit *dwarf_cu,
3636 uint32_t name_type_mask,
3637 const char *partial_name,
3638 const char *base_name_start,
3639 const char *base_name_end)
3640{
Greg Claytonfbea0f62012-11-15 18:05:43 +00003641 // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes:
3642 if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003643 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003644 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
3645 if (!containing_decl_ctx)
3646 return false;
3647
3648 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
3649
Greg Claytonfbea0f62012-11-15 18:05:43 +00003650 if (name_type_mask == eFunctionNameTypeMethod)
3651 {
3652 if (is_cxx_method == false)
3653 return false;
3654 }
3655
3656 if (name_type_mask == eFunctionNameTypeBase)
3657 {
3658 if (is_cxx_method == true)
3659 return false;
3660 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003661 }
3662
3663 // Now we need to check whether the name we got back for this type matches the extra specifications
3664 // that were in the name we're looking up:
3665 if (base_name_start != partial_name || *base_name_end != '\0')
3666 {
3667 // First see if the stuff to the left matches the full name. To do that let's see if
3668 // we can pull out the mips linkage name attribute:
3669
3670 Mangled best_name;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003671 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonfbea0f62012-11-15 18:05:43 +00003672 DWARFFormValue form_value;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003673 die->GetAttributes(this, dwarf_cu, NULL, attributes);
3674 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
Greg Clayton71415542012-12-08 00:24:40 +00003675 if (idx == UINT32_MAX)
3676 idx = attributes.FindAttributeIndex(DW_AT_linkage_name);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003677 if (idx != UINT32_MAX)
3678 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003679 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
3680 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003681 const char *mangled_name = form_value.AsCString(&get_debug_str_data());
3682 if (mangled_name)
3683 best_name.SetValue (ConstString(mangled_name), true);
3684 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003685 }
Greg Claytonfbea0f62012-11-15 18:05:43 +00003686
3687 if (!best_name)
3688 {
3689 idx = attributes.FindAttributeIndex(DW_AT_name);
3690 if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value))
3691 {
3692 const char *name = form_value.AsCString(&get_debug_str_data());
3693 best_name.SetValue (ConstString(name), false);
3694 }
3695 }
3696
3697 if (best_name.GetDemangledName())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003698 {
3699 const char *demangled = best_name.GetDemangledName().GetCString();
3700 if (demangled)
3701 {
3702 std::string name_no_parens(partial_name, base_name_end - partial_name);
Jim Ingham85c13d72012-03-02 02:24:42 +00003703 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str());
3704 if (partial_in_demangled == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003705 return false;
Jim Ingham85c13d72012-03-02 02:24:42 +00003706 else
3707 {
3708 // Sort out the case where our name is something like "Process::Destroy" and the match is
3709 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on
3710 // namespace boundaries...
3711
3712 if (partial_name[0] == ':' && partial_name[1] == ':')
3713 {
3714 // The partial name was already on a namespace boundary so all matches are good.
3715 return true;
3716 }
3717 else if (partial_in_demangled == demangled)
3718 {
3719 // They both start the same, so this is an good match.
3720 return true;
3721 }
3722 else
3723 {
3724 if (partial_in_demangled - demangled == 1)
3725 {
3726 // Only one character difference, can't be a namespace boundary...
3727 return false;
3728 }
3729 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':')
3730 {
3731 // We are on a namespace boundary, so this is also good.
3732 return true;
3733 }
3734 else
3735 return false;
3736 }
3737 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003738 }
3739 }
3740 }
3741
3742 return true;
3743}
Greg Claytonc685f8e2010-09-15 04:15:46 +00003744
Greg Clayton0c5cd902010-06-28 21:30:43 +00003745uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00003746SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00003747 const lldb_private::ClangNamespaceDecl *namespace_decl,
Sean Callanan9df05fb2012-02-10 22:52:19 +00003748 uint32_t name_type_mask,
3749 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00003750 bool append,
3751 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00003752{
3753 Timer scoped_timer (__PRETTY_FUNCTION__,
3754 "SymbolFileDWARF::FindFunctions (name = '%s')",
3755 name.AsCString());
3756
Greg Clayton43fe2172013-04-03 02:00:15 +00003757 // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup()
3758 assert ((name_type_mask & eFunctionNameTypeAuto) == 0);
3759
Greg Clayton5160ce52013-03-27 23:08:40 +00003760 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003761
3762 if (log)
3763 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003764 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003765 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
3766 name.GetCString(),
3767 name_type_mask,
3768 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003769 }
3770
Greg Clayton0c5cd902010-06-28 21:30:43 +00003771 // If we aren't appending the results to this list, then clear the list
3772 if (!append)
3773 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003774
3775 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00003776 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003777
3778 // If name is empty then we won't find anything.
3779 if (name.IsEmpty())
3780 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00003781
3782 // Remember how many sc_list are in the list before we search in case
3783 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00003784
Jim Ingham4cda6e02011-10-07 22:23:45 +00003785 const char *name_cstr = name.GetCString();
Greg Clayton43fe2172013-04-03 02:00:15 +00003786
3787 const uint32_t original_size = sc_list.GetSize();
3788
Jim Ingham4cda6e02011-10-07 22:23:45 +00003789 DWARFDebugInfo* info = DebugInfo();
3790 if (info == NULL)
3791 return 0;
3792
Greg Claytonaa044962011-10-13 00:59:38 +00003793 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton43fe2172013-04-03 02:00:15 +00003794 std::set<const DWARFDebugInfoEntry *> resolved_dies;
Greg Clayton97fbc342011-10-20 22:30:33 +00003795 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00003796 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003797 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003798 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003799
3800 DIEArray die_offsets;
3801
3802 uint32_t num_matches = 0;
3803
Greg Clayton43fe2172013-04-03 02:00:15 +00003804 if (name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00003805 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003806 // If they asked for the full name, match what they typed. At some point we may
3807 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
3808 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00003809 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003810 for (uint32_t i = 0; i < num_matches; i++)
3811 {
Greg Clayton95d87902011-11-11 03:16:25 +00003812 const dw_offset_t die_offset = die_offsets[i];
3813 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00003814 if (die)
3815 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003816 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3817 continue;
3818
Greg Clayton43fe2172013-04-03 02:00:15 +00003819 if (resolved_dies.find(die) == resolved_dies.end())
3820 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003821 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00003822 resolved_dies.insert(die);
3823 }
Greg Claytonaa044962011-10-13 00:59:38 +00003824 }
Greg Clayton95d87902011-11-11 03:16:25 +00003825 else
3826 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003827 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3828 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003829 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003830 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003831 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003832
3833 if (name_type_mask & eFunctionNameTypeSelector)
3834 {
3835 if (namespace_decl && *namespace_decl)
3836 return 0; // no selectors in namespaces
Greg Clayton97fbc342011-10-20 22:30:33 +00003837
Greg Clayton43fe2172013-04-03 02:00:15 +00003838 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3839 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
3840 // and if it is an ObjC method name, we're good.
Greg Clayton97fbc342011-10-20 22:30:33 +00003841
Greg Clayton43fe2172013-04-03 02:00:15 +00003842 for (uint32_t i = 0; i < num_matches; i++)
Greg Clayton97fbc342011-10-20 22:30:33 +00003843 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003844 const dw_offset_t die_offset = die_offsets[i];
3845 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3846 if (die)
Greg Clayton97fbc342011-10-20 22:30:33 +00003847 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003848 const char *die_name = die->GetName(this, dwarf_cu);
3849 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
Greg Clayton97fbc342011-10-20 22:30:33 +00003850 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003851 if (resolved_dies.find(die) == resolved_dies.end())
3852 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003853 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00003854 resolved_dies.insert(die);
3855 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003856 }
3857 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003858 else
3859 {
3860 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3861 die_offset, name_cstr);
3862 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003863 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003864 die_offsets.clear();
3865 }
3866
3867 if (((name_type_mask & eFunctionNameTypeMethod) && !namespace_decl) || name_type_mask & eFunctionNameTypeBase)
3868 {
3869 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
3870 // extract the base name, look that up, and if there is any other information in the name we were
3871 // passed in we have to post-filter based on that.
3872
3873 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
3874 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3875
3876 for (uint32_t i = 0; i < num_matches; i++)
3877 {
3878 const dw_offset_t die_offset = die_offsets[i];
3879 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3880 if (die)
3881 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003882 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3883 continue;
3884
3885 // If we get to here, the die is good, and we should add it:
3886 if (resolved_dies.find(die) == resolved_dies.end())
Pavel Labatha73d6572015-03-13 10:22:00 +00003887 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00003888 {
3889 bool keep_die = true;
3890 if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod))
3891 {
3892 // We are looking for either basenames or methods, so we need to
3893 // trim out the ones we won't want by looking at the type
3894 SymbolContext sc;
3895 if (sc_list.GetLastContext(sc))
3896 {
3897 if (sc.block)
3898 {
3899 // We have an inlined function
3900 }
3901 else if (sc.function)
3902 {
3903 Type *type = sc.function->GetType();
3904
Sean Callananc370a8a2013-09-18 22:59:55 +00003905 if (type)
Greg Clayton43fe2172013-04-03 02:00:15 +00003906 {
Sean Callananc370a8a2013-09-18 22:59:55 +00003907 clang::DeclContext* decl_ctx = GetClangDeclContextContainingTypeUID (type->GetID());
3908 if (decl_ctx->isRecord())
Greg Clayton43fe2172013-04-03 02:00:15 +00003909 {
Sean Callananc370a8a2013-09-18 22:59:55 +00003910 if (name_type_mask & eFunctionNameTypeBase)
3911 {
3912 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3913 keep_die = false;
3914 }
3915 }
3916 else
3917 {
3918 if (name_type_mask & eFunctionNameTypeMethod)
3919 {
3920 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3921 keep_die = false;
3922 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003923 }
3924 }
3925 else
3926 {
Sean Callananc370a8a2013-09-18 22:59:55 +00003927 GetObjectFile()->GetModule()->ReportWarning ("function at die offset 0x%8.8x had no function type",
3928 die_offset);
Greg Clayton43fe2172013-04-03 02:00:15 +00003929 }
3930 }
3931 }
3932 }
3933 if (keep_die)
3934 resolved_dies.insert(die);
3935 }
3936 }
3937 else
3938 {
3939 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3940 die_offset, name_cstr);
3941 }
3942 }
3943 die_offsets.clear();
Jim Ingham4cda6e02011-10-07 22:23:45 +00003944 }
3945 }
Greg Clayton7f995132011-10-04 22:41:51 +00003946 }
3947 else
3948 {
3949
3950 // Index the DWARF if we haven't already
3951 if (!m_indexed)
3952 Index ();
3953
Greg Clayton7f995132011-10-04 22:41:51 +00003954 if (name_type_mask & eFunctionNameTypeFull)
Matt Kopecd6089962013-05-10 17:53:48 +00003955 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003956 FindFunctions (name, m_function_fullname_index, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003957
Ed Mastefc7baa02013-09-09 18:00:45 +00003958 // FIXME Temporary workaround for global/anonymous namespace
3959 // functions on FreeBSD and Linux
3960#if defined (__FreeBSD__) || defined (__linux__)
Matt Kopecd6089962013-05-10 17:53:48 +00003961 // If we didn't find any functions in the global namespace try
3962 // looking in the basename index but ignore any returned
3963 // functions that have a namespace (ie. mangled names starting with
3964 // '_ZN') but keep functions which have an anonymous namespace
3965 if (sc_list.GetSize() == 0)
3966 {
3967 SymbolContextList temp_sc_list;
Pavel Labatha73d6572015-03-13 10:22:00 +00003968 FindFunctions (name, m_function_basename_index, include_inlines, temp_sc_list);
Matt Kopecd6089962013-05-10 17:53:48 +00003969 if (!namespace_decl)
3970 {
3971 SymbolContext sc;
3972 for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++)
3973 {
3974 if (temp_sc_list.GetContextAtIndex(i, sc))
3975 {
Matt Kopeca189d492013-05-10 22:55:24 +00003976 ConstString mangled_name = sc.GetFunctionName(Mangled::ePreferMangled);
3977 ConstString demangled_name = sc.GetFunctionName(Mangled::ePreferDemangled);
Matt Kopec04e5d582013-05-14 19:00:41 +00003978 if (strncmp(mangled_name.GetCString(), "_ZN", 3) ||
3979 !strncmp(demangled_name.GetCString(), "(anonymous namespace)", 21))
Matt Kopecd6089962013-05-10 17:53:48 +00003980 {
3981 sc_list.Append(sc);
3982 }
3983 }
3984 }
3985 }
3986 }
3987#endif
3988 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003989 DIEArray die_offsets;
3990 DWARFCompileUnit *dwarf_cu = NULL;
3991
Greg Clayton43fe2172013-04-03 02:00:15 +00003992 if (name_type_mask & eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003993 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003994 uint32_t num_base = m_function_basename_index.Find(name, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00003995 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003996 {
Greg Claytonaa044962011-10-13 00:59:38 +00003997 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3998 if (die)
3999 {
Sean Callanan213fdb82011-10-13 01:49:10 +00004000 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
4001 continue;
4002
Greg Claytonaa044962011-10-13 00:59:38 +00004003 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00004004 if (resolved_dies.find(die) == resolved_dies.end())
4005 {
Pavel Labatha73d6572015-03-13 10:22:00 +00004006 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00004007 resolved_dies.insert(die);
4008 }
Greg Claytonaa044962011-10-13 00:59:38 +00004009 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00004010 }
4011 die_offsets.clear();
4012 }
4013
Greg Clayton43fe2172013-04-03 02:00:15 +00004014 if (name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00004015 {
Sean Callanan213fdb82011-10-13 01:49:10 +00004016 if (namespace_decl && *namespace_decl)
4017 return 0; // no methods in namespaces
4018
Greg Clayton43fe2172013-04-03 02:00:15 +00004019 uint32_t num_base = m_function_method_index.Find(name, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00004020 {
Greg Claytonaa044962011-10-13 00:59:38 +00004021 for (uint32_t i = 0; i < num_base; i++)
4022 {
4023 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
4024 if (die)
4025 {
Greg Claytonaa044962011-10-13 00:59:38 +00004026 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00004027 if (resolved_dies.find(die) == resolved_dies.end())
4028 {
Pavel Labatha73d6572015-03-13 10:22:00 +00004029 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00004030 resolved_dies.insert(die);
4031 }
Greg Claytonaa044962011-10-13 00:59:38 +00004032 }
4033 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00004034 }
4035 die_offsets.clear();
4036 }
Greg Clayton7f995132011-10-04 22:41:51 +00004037
Greg Clayton43fe2172013-04-03 02:00:15 +00004038 if ((name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00004039 {
Pavel Labatha73d6572015-03-13 10:22:00 +00004040 FindFunctions (name, m_function_selector_index, include_inlines, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00004041 }
4042
Greg Clayton4d01ace2011-09-29 16:58:15 +00004043 }
4044
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004045 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00004046 const uint32_t num_matches = sc_list.GetSize() - original_size;
4047
4048 if (log && num_matches > 0)
4049 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004050 GetObjectFile()->GetModule()->LogMessage (log,
Pavel Labatha73d6572015-03-13 10:22:00 +00004051 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, include_inlines=%d, append=%u, sc_list) => %u",
Greg Clayton437a1352012-04-09 22:43:43 +00004052 name.GetCString(),
4053 name_type_mask,
Pavel Labatha73d6572015-03-13 10:22:00 +00004054 include_inlines,
Greg Clayton437a1352012-04-09 22:43:43 +00004055 append,
4056 num_matches);
4057 }
4058 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004059}
4060
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004061uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00004062SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004063{
4064 Timer scoped_timer (__PRETTY_FUNCTION__,
4065 "SymbolFileDWARF::FindFunctions (regex = '%s')",
4066 regex.GetText());
4067
Greg Clayton5160ce52013-03-27 23:08:40 +00004068 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00004069
4070 if (log)
4071 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004072 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00004073 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
4074 regex.GetText(),
4075 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00004076 }
4077
4078
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004079 // If we aren't appending the results to this list, then clear the list
4080 if (!append)
4081 sc_list.Clear();
4082
4083 // Remember how many sc_list are in the list before we search in case
4084 // we are appending the results to a variable list.
4085 uint32_t original_size = sc_list.GetSize();
4086
Greg Clayton97fbc342011-10-20 22:30:33 +00004087 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004088 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004089 if (m_apple_names_ap.get())
Pavel Labatha73d6572015-03-13 10:22:00 +00004090 FindFunctions (regex, *m_apple_names_ap, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00004091 }
4092 else
4093 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00004094 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00004095 if (!m_indexed)
4096 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004097
Pavel Labatha73d6572015-03-13 10:22:00 +00004098 FindFunctions (regex, m_function_basename_index, include_inlines, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004099
Pavel Labatha73d6572015-03-13 10:22:00 +00004100 FindFunctions (regex, m_function_fullname_index, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00004101 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004102
4103 // Return the number of variable that were appended to the list
4104 return sc_list.GetSize() - original_size;
4105}
Jim Ingham318c9f22011-08-26 19:44:13 +00004106
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004107uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00004108SymbolFileDWARF::FindTypes (const SymbolContext& sc,
4109 const ConstString &name,
4110 const lldb_private::ClangNamespaceDecl *namespace_decl,
4111 bool append,
4112 uint32_t max_matches,
4113 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004114{
Greg Claytonc685f8e2010-09-15 04:15:46 +00004115 DWARFDebugInfo* info = DebugInfo();
4116 if (info == NULL)
4117 return 0;
4118
Greg Clayton5160ce52013-03-27 23:08:40 +00004119 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004120
Greg Clayton21f2a492011-10-06 00:09:08 +00004121 if (log)
4122 {
Greg Clayton437a1352012-04-09 22:43:43 +00004123 if (namespace_decl)
Greg Clayton5160ce52013-03-27 23:08:40 +00004124 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004125 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)",
4126 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004127 static_cast<void*>(namespace_decl->GetNamespaceDecl()),
Greg Clayton437a1352012-04-09 22:43:43 +00004128 namespace_decl->GetQualifiedName().c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004129 append, max_matches);
Greg Clayton437a1352012-04-09 22:43:43 +00004130 else
Greg Clayton5160ce52013-03-27 23:08:40 +00004131 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004132 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004133 name.GetCString(), append,
Greg Clayton437a1352012-04-09 22:43:43 +00004134 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00004135 }
4136
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004137 // If we aren't appending the results to this list, then clear the list
4138 if (!append)
4139 types.Clear();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004140
Sean Callanan213fdb82011-10-13 01:49:10 +00004141 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00004142 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004143
Greg Claytond4a2b372011-09-12 23:21:58 +00004144 DIEArray die_offsets;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004145
Greg Clayton97fbc342011-10-20 22:30:33 +00004146 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004147 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004148 if (m_apple_types_ap.get())
4149 {
4150 const char *name_cstr = name.GetCString();
4151 m_apple_types_ap->FindByName (name_cstr, die_offsets);
4152 }
Greg Clayton7f995132011-10-04 22:41:51 +00004153 }
4154 else
4155 {
4156 if (!m_indexed)
4157 Index ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004158
Greg Clayton7f995132011-10-04 22:41:51 +00004159 m_type_index.Find (name, die_offsets);
4160 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004161
Greg Clayton437a1352012-04-09 22:43:43 +00004162 const size_t num_die_matches = die_offsets.size();
Greg Clayton7f995132011-10-04 22:41:51 +00004163
Greg Clayton437a1352012-04-09 22:43:43 +00004164 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004165 {
Greg Clayton7f995132011-10-04 22:41:51 +00004166 const uint32_t initial_types_size = types.GetSize();
4167 DWARFCompileUnit* dwarf_cu = NULL;
4168 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00004169 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00004170 for (size_t i=0; i<num_die_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004171 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004172 const dw_offset_t die_offset = die_offsets[i];
4173 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
4174
Greg Clayton95d87902011-11-11 03:16:25 +00004175 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00004176 {
Greg Clayton95d87902011-11-11 03:16:25 +00004177 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
4178 continue;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004179
Greg Clayton95d87902011-11-11 03:16:25 +00004180 Type *matching_type = ResolveType (dwarf_cu, die);
4181 if (matching_type)
4182 {
4183 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00004184 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00004185 if (types.GetSize() >= max_matches)
4186 break;
4187 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00004188 }
Greg Clayton95d87902011-11-11 03:16:25 +00004189 else
4190 {
4191 if (m_using_apple_tables)
4192 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004193 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4194 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004195 }
4196 }
4197
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004198 }
Greg Clayton437a1352012-04-09 22:43:43 +00004199 const uint32_t num_matches = types.GetSize() - initial_types_size;
4200 if (log && num_matches)
4201 {
4202 if (namespace_decl)
4203 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004204 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004205 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u",
4206 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004207 static_cast<void*>(namespace_decl->GetNamespaceDecl()),
Greg Clayton437a1352012-04-09 22:43:43 +00004208 namespace_decl->GetQualifiedName().c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004209 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00004210 num_matches);
4211 }
4212 else
4213 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004214 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004215 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u",
4216 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004217 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00004218 num_matches);
4219 }
4220 }
4221 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004222 }
Greg Clayton7f995132011-10-04 22:41:51 +00004223 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004224}
4225
4226
Greg Clayton526e5af2010-11-13 03:52:47 +00004227ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00004228SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00004229 const ConstString &name,
4230 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004231{
Greg Clayton5160ce52013-03-27 23:08:40 +00004232 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00004233
4234 if (log)
4235 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004236 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00004237 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
4238 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00004239 }
Sean Callanan213fdb82011-10-13 01:49:10 +00004240
4241 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00004242 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00004243
Greg Clayton526e5af2010-11-13 03:52:47 +00004244 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004245 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00004246 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00004247 {
Greg Clayton7f995132011-10-04 22:41:51 +00004248 DIEArray die_offsets;
4249
Greg Clayton526e5af2010-11-13 03:52:47 +00004250 // Index if we already haven't to make sure the compile units
4251 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00004252 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004253 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004254 if (m_apple_namespaces_ap.get())
4255 {
4256 const char *name_cstr = name.GetCString();
4257 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
4258 }
Greg Clayton7f995132011-10-04 22:41:51 +00004259 }
4260 else
4261 {
4262 if (!m_indexed)
4263 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00004264
Greg Clayton7f995132011-10-04 22:41:51 +00004265 m_namespace_index.Find (name, die_offsets);
4266 }
Greg Claytond4a2b372011-09-12 23:21:58 +00004267
4268 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00004269 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00004270 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00004271 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00004272 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004273 DWARFDebugInfo* debug_info = DebugInfo();
4274 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00004275 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004276 const dw_offset_t die_offset = die_offsets[i];
4277 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00004278
Greg Clayton95d87902011-11-11 03:16:25 +00004279 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00004280 {
Greg Clayton95d87902011-11-11 03:16:25 +00004281 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
4282 continue;
4283
4284 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
4285 if (clang_namespace_decl)
4286 {
4287 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
4288 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
Greg Claytond1767f02011-12-08 02:13:16 +00004289 break;
Greg Clayton95d87902011-11-11 03:16:25 +00004290 }
Greg Claytond4a2b372011-09-12 23:21:58 +00004291 }
Greg Clayton95d87902011-11-11 03:16:25 +00004292 else
4293 {
4294 if (m_using_apple_tables)
4295 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004296 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
4297 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004298 }
4299 }
4300
Greg Clayton526e5af2010-11-13 03:52:47 +00004301 }
4302 }
Greg Clayton96d7d742010-11-10 23:42:09 +00004303 }
Greg Clayton437a1352012-04-09 22:43:43 +00004304 if (log && namespace_decl.GetNamespaceDecl())
4305 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004306 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004307 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"",
4308 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004309 static_cast<const void*>(namespace_decl.GetNamespaceDecl()),
Greg Clayton437a1352012-04-09 22:43:43 +00004310 namespace_decl.GetQualifiedName().c_str());
4311 }
4312
Greg Clayton526e5af2010-11-13 03:52:47 +00004313 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004314}
4315
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004316uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004317SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004318{
4319 // Remember how many sc_list are in the list before we search in case
4320 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004321 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004322
4323 const uint32_t num_die_offsets = die_offsets.size();
4324 // Parse all of the types we found from the pubtypes matches
4325 uint32_t i;
4326 uint32_t num_matches = 0;
4327 for (i = 0; i < num_die_offsets; ++i)
4328 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004329 Type *matching_type = ResolveTypeUID (die_offsets[i]);
4330 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004331 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004332 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00004333 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004334 ++num_matches;
4335 if (num_matches >= max_matches)
4336 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004337 }
4338 }
4339
4340 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004341 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004342}
4343
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004344
4345size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00004346SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
4347 clang::DeclContext *containing_decl_ctx,
Greg Clayton5113dc82011-08-12 06:47:54 +00004348 DWARFCompileUnit* dwarf_cu,
4349 const DWARFDebugInfoEntry *parent_die,
4350 bool skip_artificial,
4351 bool &is_static,
Greg Clayton03969752014-02-24 18:53:11 +00004352 bool &is_variadic,
Greg Clayton57ee3062013-07-11 22:46:58 +00004353 std::vector<ClangASTType>& function_param_types,
Greg Clayton5113dc82011-08-12 06:47:54 +00004354 std::vector<clang::ParmVarDecl*>& function_param_decls,
Greg Claytond20deac2014-04-04 18:15:18 +00004355 unsigned &type_quals) // ,
4356 // ClangASTContext::TemplateParameterInfos &template_param_infos))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004357{
4358 if (parent_die == NULL)
4359 return 0;
4360
Todd Fialaee8bfc62014-09-11 17:29:12 +00004361 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Claytond88d7592010-09-15 08:33:30 +00004362
Greg Clayton7fedea22010-11-16 02:10:54 +00004363 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004364 const DWARFDebugInfoEntry *die;
4365 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4366 {
4367 dw_tag_t tag = die->Tag();
4368 switch (tag)
4369 {
4370 case DW_TAG_formal_parameter:
4371 {
4372 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004373 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004374 if (num_attributes > 0)
4375 {
4376 const char *name = NULL;
4377 Declaration decl;
4378 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00004379 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004380 // one of None, Auto, Register, Extern, Static, PrivateExtern
4381
Sean Callanane2ef6e32010-09-23 03:01:22 +00004382 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004383 uint32_t i;
4384 for (i=0; i<num_attributes; ++i)
4385 {
4386 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4387 DWARFFormValue form_value;
4388 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4389 {
4390 switch (attr)
4391 {
4392 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4393 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4394 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4395 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00004396 case DW_AT_type: param_type_die_offset = form_value.Reference(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00004397 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004398 case DW_AT_location:
4399 // if (form_value.BlockData())
4400 // {
Ed Masteeeae7212013-10-24 20:43:47 +00004401 // const DWARFDataExtractor& debug_info_data = debug_info();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004402 // uint32_t block_length = form_value.Unsigned();
Ed Masteeeae7212013-10-24 20:43:47 +00004403 // DWARFDataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004404 // }
4405 // else
4406 // {
4407 // }
4408 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004409 case DW_AT_const_value:
4410 case DW_AT_default_value:
4411 case DW_AT_description:
4412 case DW_AT_endianity:
4413 case DW_AT_is_optional:
4414 case DW_AT_segment:
4415 case DW_AT_variable_parameter:
4416 default:
4417 case DW_AT_abstract_origin:
4418 case DW_AT_sibling:
4419 break;
4420 }
4421 }
4422 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00004423
Greg Clayton0fffff52010-09-24 05:15:53 +00004424 bool skip = false;
4425 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004426 {
Greg Clayton0fffff52010-09-24 05:15:53 +00004427 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00004428 {
4429 // In order to determine if a C++ member function is
4430 // "const" we have to look at the const-ness of "this"...
4431 // Ugly, but that
4432 if (arg_idx == 0)
4433 {
Greg Claytonf0705c82011-10-22 03:33:13 +00004434 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00004435 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004436 // Often times compilers omit the "this" name for the
4437 // specification DIEs, so we can't rely upon the name
4438 // being in the formal parameter DIE...
4439 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00004440 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004441 Type *this_type = ResolveTypeUID (param_type_die_offset);
4442 if (this_type)
4443 {
4444 uint32_t encoding_mask = this_type->GetEncodingMask();
4445 if (encoding_mask & Type::eEncodingIsPointerUID)
4446 {
4447 is_static = false;
4448
4449 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
4450 type_quals |= clang::Qualifiers::Const;
4451 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
4452 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00004453 }
4454 }
4455 }
4456 }
4457 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004458 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00004459 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004460 else
4461 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004462
Greg Clayton0fffff52010-09-24 05:15:53 +00004463 // HACK: Objective C formal parameters "self" and "_cmd"
4464 // are not marked as artificial in the DWARF...
Greg Clayton53eb1c22012-04-02 22:59:12 +00004465 CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
4466 if (comp_unit)
Greg Clayton0fffff52010-09-24 05:15:53 +00004467 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004468 switch (comp_unit->GetLanguage())
4469 {
4470 case eLanguageTypeObjC:
4471 case eLanguageTypeObjC_plus_plus:
4472 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
4473 skip = true;
4474 break;
4475 default:
4476 break;
4477 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004478 }
4479 }
4480 }
4481
4482 if (!skip)
4483 {
4484 Type *type = ResolveTypeUID(param_type_die_offset);
4485 if (type)
4486 {
Greg Claytonc93237c2010-10-01 20:48:32 +00004487 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00004488
Greg Clayton42ce2f32011-12-12 21:50:19 +00004489 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
4490 type->GetClangForwardType(),
4491 storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00004492 assert(param_var_decl);
4493 function_param_decls.push_back(param_var_decl);
Sean Callanan60217122012-04-13 00:10:03 +00004494
Greg Claytond0029442013-03-27 01:48:02 +00004495 GetClangASTContext().SetMetadataAsUserID (param_var_decl, MakeUserID(die->GetOffset()));
Greg Clayton0fffff52010-09-24 05:15:53 +00004496 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004497 }
4498 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004499 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004500 }
4501 break;
4502
Greg Clayton03969752014-02-24 18:53:11 +00004503 case DW_TAG_unspecified_parameters:
4504 is_variadic = true;
4505 break;
4506
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004507 case DW_TAG_template_type_parameter:
4508 case DW_TAG_template_value_parameter:
Greg Claytond20deac2014-04-04 18:15:18 +00004509 // The one caller of this was never using the template_param_infos,
4510 // and the local variable was taking up a large amount of stack space
4511 // in SymbolFileDWARF::ParseType() so this was removed. If we ever need
4512 // the template params back, we can add them back.
4513 // ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004514 break;
4515
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004516 default:
4517 break;
4518 }
4519 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004520 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004521}
4522
4523size_t
4524SymbolFileDWARF::ParseChildEnumerators
4525(
4526 const SymbolContext& sc,
Greg Clayton57ee3062013-07-11 22:46:58 +00004527 lldb_private::ClangASTType &clang_type,
Greg Clayton3e067532013-03-05 23:54:39 +00004528 bool is_signed,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004529 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00004530 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004531 const DWARFDebugInfoEntry *parent_die
4532)
4533{
4534 if (parent_die == NULL)
4535 return 0;
4536
4537 size_t enumerators_added = 0;
4538 const DWARFDebugInfoEntry *die;
Todd Fialaee8bfc62014-09-11 17:29:12 +00004539 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Claytond88d7592010-09-15 08:33:30 +00004540
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004541 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4542 {
4543 const dw_tag_t tag = die->Tag();
4544 if (tag == DW_TAG_enumerator)
4545 {
4546 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004547 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004548 if (num_child_attributes > 0)
4549 {
4550 const char *name = NULL;
4551 bool got_value = false;
4552 int64_t enum_value = 0;
4553 Declaration decl;
4554
4555 uint32_t i;
4556 for (i=0; i<num_child_attributes; ++i)
4557 {
4558 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4559 DWARFFormValue form_value;
4560 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4561 {
4562 switch (attr)
4563 {
4564 case DW_AT_const_value:
4565 got_value = true;
Greg Clayton3e067532013-03-05 23:54:39 +00004566 if (is_signed)
4567 enum_value = form_value.Signed();
4568 else
4569 enum_value = form_value.Unsigned();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004570 break;
4571
4572 case DW_AT_name:
4573 name = form_value.AsCString(&get_debug_str_data());
4574 break;
4575
4576 case DW_AT_description:
4577 default:
4578 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4579 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4580 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4581 case DW_AT_sibling:
4582 break;
4583 }
4584 }
4585 }
4586
4587 if (name && name[0] && got_value)
4588 {
Greg Clayton57ee3062013-07-11 22:46:58 +00004589 clang_type.AddEnumerationValueToEnumerationType (clang_type.GetEnumerationIntegerType(),
4590 decl,
4591 name,
4592 enum_value,
4593 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004594 ++enumerators_added;
4595 }
4596 }
4597 }
4598 }
4599 return enumerators_added;
4600}
4601
4602void
4603SymbolFileDWARF::ParseChildArrayInfo
4604(
4605 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004606 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004607 const DWARFDebugInfoEntry *parent_die,
4608 int64_t& first_index,
4609 std::vector<uint64_t>& element_orders,
4610 uint32_t& byte_stride,
4611 uint32_t& bit_stride
4612)
4613{
4614 if (parent_die == NULL)
4615 return;
4616
4617 const DWARFDebugInfoEntry *die;
Todd Fialaee8bfc62014-09-11 17:29:12 +00004618 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004619 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4620 {
4621 const dw_tag_t tag = die->Tag();
4622 switch (tag)
4623 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004624 case DW_TAG_subrange_type:
4625 {
4626 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004627 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004628 if (num_child_attributes > 0)
4629 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004630 uint64_t num_elements = 0;
4631 uint64_t lower_bound = 0;
4632 uint64_t upper_bound = 0;
Greg Clayton4ef877f2012-12-06 02:33:54 +00004633 bool upper_bound_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004634 uint32_t i;
4635 for (i=0; i<num_child_attributes; ++i)
4636 {
4637 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4638 DWARFFormValue form_value;
4639 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4640 {
4641 switch (attr)
4642 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004643 case DW_AT_name:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004644 break;
4645
4646 case DW_AT_count:
4647 num_elements = form_value.Unsigned();
4648 break;
4649
4650 case DW_AT_bit_stride:
4651 bit_stride = form_value.Unsigned();
4652 break;
4653
4654 case DW_AT_byte_stride:
4655 byte_stride = form_value.Unsigned();
4656 break;
4657
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004658 case DW_AT_lower_bound:
4659 lower_bound = form_value.Unsigned();
4660 break;
4661
4662 case DW_AT_upper_bound:
Greg Clayton4ef877f2012-12-06 02:33:54 +00004663 upper_bound_valid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004664 upper_bound = form_value.Unsigned();
4665 break;
4666
4667 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004668 case DW_AT_abstract_origin:
4669 case DW_AT_accessibility:
4670 case DW_AT_allocated:
4671 case DW_AT_associated:
4672 case DW_AT_data_location:
4673 case DW_AT_declaration:
4674 case DW_AT_description:
4675 case DW_AT_sibling:
4676 case DW_AT_threads_scaled:
4677 case DW_AT_type:
4678 case DW_AT_visibility:
4679 break;
4680 }
4681 }
4682 }
4683
Greg Claytone6a07792012-12-05 21:59:39 +00004684 if (num_elements == 0)
4685 {
Greg Clayton4ef877f2012-12-06 02:33:54 +00004686 if (upper_bound_valid && upper_bound >= lower_bound)
Greg Claytone6a07792012-12-05 21:59:39 +00004687 num_elements = upper_bound - lower_bound + 1;
4688 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004689
Sean Callananec979ba2012-10-22 23:56:48 +00004690 element_orders.push_back (num_elements);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004691 }
4692 }
4693 break;
4694 }
4695 }
4696}
4697
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004698TypeSP
Greg Clayton53eb1c22012-04-02 22:59:12 +00004699SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004700{
4701 TypeSP type_sp;
4702 if (die != NULL)
4703 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004704 assert(dwarf_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00004705 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004706 if (type_ptr == NULL)
4707 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004708 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu);
Greg Claytonca512b32011-01-14 04:54:56 +00004709 assert (lldb_cu);
4710 SymbolContext sc(lldb_cu);
Greg Clayton53eb1c22012-04-02 22:59:12 +00004711 type_sp = ParseType(sc, dwarf_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004712 }
4713 else if (type_ptr != DIE_IS_BEING_PARSED)
4714 {
4715 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00004716 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004717 }
4718
4719 }
4720 return type_sp;
4721}
4722
4723clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00004724SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004725{
4726 if (die_offset != DW_INVALID_OFFSET)
4727 {
4728 DWARFCompileUnitSP cu_sp;
4729 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004730 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004731 }
4732 return NULL;
4733}
4734
Sean Callanan72e49402011-08-05 23:43:37 +00004735clang::DeclContext *
4736SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
4737{
4738 if (die_offset != DW_INVALID_OFFSET)
4739 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004740 DWARFDebugInfo* debug_info = DebugInfo();
4741 if (debug_info)
4742 {
4743 DWARFCompileUnitSP cu_sp;
4744 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
4745 if (die)
4746 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
4747 }
Sean Callanan72e49402011-08-05 23:43:37 +00004748 }
4749 return NULL;
4750}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004751
Greg Clayton96d7d742010-11-10 23:42:09 +00004752clang::NamespaceDecl *
Greg Clayton53eb1c22012-04-02 22:59:12 +00004753SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die)
Greg Clayton96d7d742010-11-10 23:42:09 +00004754{
Greg Clayton030a2042011-10-14 21:34:45 +00004755 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00004756 {
Greg Clayton030a2042011-10-14 21:34:45 +00004757 // See if we already parsed this namespace DIE and associated it with a
4758 // uniqued namespace declaration
4759 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
4760 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004761 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00004762 else
4763 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004764 const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL);
4765 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00004766 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
Greg Clayton5160ce52013-03-27 23:08:40 +00004767 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton9d3d6882011-10-31 23:51:19 +00004768 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00004769 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00004770 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00004771 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004772 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00004773 "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 +00004774 static_cast<void*>(GetClangASTContext().getASTContext()),
Greg Claytone38a5ed2012-01-05 03:57:59 +00004775 MakeUserID(die->GetOffset()),
4776 namespace_name,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004777 static_cast<void*>(namespace_decl),
4778 static_cast<void*>(namespace_decl->getOriginalNamespace()));
Greg Clayton030a2042011-10-14 21:34:45 +00004779 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004780 else
4781 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004782 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00004783 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004784 static_cast<void*>(GetClangASTContext().getASTContext()),
Greg Claytone38a5ed2012-01-05 03:57:59 +00004785 MakeUserID(die->GetOffset()),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004786 static_cast<void*>(namespace_decl),
4787 static_cast<void*>(namespace_decl->getOriginalNamespace()));
Greg Clayton9d3d6882011-10-31 23:51:19 +00004788 }
Greg Clayton030a2042011-10-14 21:34:45 +00004789 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004790
4791 if (namespace_decl)
4792 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
4793 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004794 }
4795 }
4796 return NULL;
4797}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004798
4799clang::DeclContext *
Greg Claytoncab36a32011-12-08 05:16:30 +00004800SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Sean Callanan72e49402011-08-05 23:43:37 +00004801{
Greg Clayton5cf58b92011-10-05 22:22:08 +00004802 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4803 if (clang_decl_ctx)
4804 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004805 // If this DIE has a specification, or an abstract origin, then trace to those.
4806
Greg Claytoncab36a32011-12-08 05:16:30 +00004807 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004808 if (die_offset != DW_INVALID_OFFSET)
4809 return GetClangDeclContextForDIEOffset (sc, die_offset);
4810
Greg Claytoncab36a32011-12-08 05:16:30 +00004811 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004812 if (die_offset != DW_INVALID_OFFSET)
4813 return GetClangDeclContextForDIEOffset (sc, die_offset);
4814
Greg Clayton5160ce52013-03-27 23:08:40 +00004815 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00004816 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004817 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 +00004818 // This is the DIE we want. Parse it, then query our map.
Greg Claytoncab36a32011-12-08 05:16:30 +00004819 bool assert_not_being_parsed = true;
4820 ResolveTypeUID (cu, die, assert_not_being_parsed);
4821
Greg Clayton5cf58b92011-10-05 22:22:08 +00004822 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4823
4824 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004825}
4826
4827clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00004828SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004829{
Greg Claytonca512b32011-01-14 04:54:56 +00004830 if (m_clang_tu_decl == NULL)
4831 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004832
Greg Clayton2bc22f82011-09-30 03:20:47 +00004833 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004834
4835 if (decl_ctx_die_copy)
4836 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00004837
4838 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004839 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00004840
Greg Clayton2bc22f82011-09-30 03:20:47 +00004841 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
4842 if (pos != m_die_to_decl_ctx.end())
4843 return pos->second;
4844
4845 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004846 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004847 case DW_TAG_compile_unit:
4848 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004849
Greg Clayton2bc22f82011-09-30 03:20:47 +00004850 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00004851 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00004852 break;
4853
4854 case DW_TAG_structure_type:
4855 case DW_TAG_union_type:
4856 case DW_TAG_class_type:
4857 {
4858 Type* type = ResolveType (cu, decl_ctx_die);
4859 if (type)
4860 {
Greg Clayton57ee3062013-07-11 22:46:58 +00004861 clang::DeclContext *decl_ctx = type->GetClangForwardType().GetDeclContextForType ();
Greg Clayton2bc22f82011-09-30 03:20:47 +00004862 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00004863 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004864 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
4865 if (decl_ctx)
4866 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00004867 }
4868 }
Greg Claytonca512b32011-01-14 04:54:56 +00004869 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00004870 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004871
Greg Clayton2bc22f82011-09-30 03:20:47 +00004872 default:
4873 break;
Greg Claytonca512b32011-01-14 04:54:56 +00004874 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004875 }
Greg Clayton7a345282010-11-09 23:46:37 +00004876 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004877}
4878
Greg Clayton2bc22f82011-09-30 03:20:47 +00004879
4880const DWARFDebugInfoEntry *
4881SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4882{
4883 if (cu && die)
4884 {
4885 const DWARFDebugInfoEntry * const decl_die = die;
4886
4887 while (die != NULL)
4888 {
4889 // If this is the original DIE that we are searching for a declaration
4890 // for, then don't look in the cache as we don't want our own decl
4891 // context to be our decl context...
4892 if (decl_die != die)
4893 {
4894 switch (die->Tag())
4895 {
4896 case DW_TAG_compile_unit:
4897 case DW_TAG_namespace:
4898 case DW_TAG_structure_type:
4899 case DW_TAG_union_type:
4900 case DW_TAG_class_type:
4901 return die;
4902
4903 default:
4904 break;
4905 }
4906 }
4907
4908 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4909 if (die_offset != DW_INVALID_OFFSET)
4910 {
4911 DWARFCompileUnit *spec_cu = cu;
4912 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
4913 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
4914 if (spec_die_decl_ctx_die)
4915 return spec_die_decl_ctx_die;
4916 }
4917
4918 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
4919 if (die_offset != DW_INVALID_OFFSET)
4920 {
4921 DWARFCompileUnit *abs_cu = cu;
4922 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
4923 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
4924 if (abs_die_decl_ctx_die)
4925 return abs_die_decl_ctx_die;
4926 }
4927
4928 die = die->GetParent();
4929 }
4930 }
4931 return NULL;
4932}
4933
4934
Greg Clayton901c5ca2011-12-03 04:40:03 +00004935Symbol *
4936SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
4937{
4938 Symbol *objc_class_symbol = NULL;
4939 if (m_obj_file)
4940 {
Greg Clayton3046e662013-07-10 01:23:25 +00004941 Symtab *symtab = m_obj_file->GetSymtab ();
Greg Clayton901c5ca2011-12-03 04:40:03 +00004942 if (symtab)
4943 {
4944 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
4945 eSymbolTypeObjCClass,
4946 Symtab::eDebugNo,
4947 Symtab::eVisibilityAny);
4948 }
4949 }
4950 return objc_class_symbol;
4951}
4952
Greg Claytonc7f03b62012-01-12 04:33:28 +00004953// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
4954// then we can end up looking through all class types for a complete type and never find
4955// the full definition. We need to know if this attribute is supported, so we determine
4956// this here and cache th result. We also need to worry about the debug map DWARF file
4957// if we are doing darwin DWARF in .o file debugging.
4958bool
4959SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
4960{
4961 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
4962 {
4963 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
4964 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
4965 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4966 else
4967 {
4968 DWARFDebugInfo* debug_info = DebugInfo();
4969 const uint32_t num_compile_units = GetNumCompileUnits();
4970 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
4971 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004972 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
4973 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004974 {
4975 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4976 break;
4977 }
4978 }
4979 }
Greg Clayton1f746072012-08-29 21:13:06 +00004980 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004981 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
4982 }
4983 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
4984}
Greg Clayton901c5ca2011-12-03 04:40:03 +00004985
4986// This function can be used when a DIE is found that is a forward declaration
4987// DIE and we want to try and find a type that has the complete definition.
4988TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00004989SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
4990 const ConstString &type_name,
4991 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00004992{
4993
4994 TypeSP type_sp;
4995
Greg Claytonc7f03b62012-01-12 04:33:28 +00004996 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00004997 return type_sp;
4998
4999 DIEArray die_offsets;
5000
5001 if (m_using_apple_tables)
5002 {
5003 if (m_apple_types_ap.get())
5004 {
5005 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00005006 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00005007 }
5008 }
5009 else
5010 {
5011 if (!m_indexed)
5012 Index ();
5013
5014 m_type_index.Find (type_name, die_offsets);
5015 }
5016
Greg Clayton901c5ca2011-12-03 04:40:03 +00005017 const size_t num_matches = die_offsets.size();
5018
Greg Clayton901c5ca2011-12-03 04:40:03 +00005019 DWARFCompileUnit* type_cu = NULL;
5020 const DWARFDebugInfoEntry* type_die = NULL;
5021 if (num_matches)
5022 {
5023 DWARFDebugInfo* debug_info = DebugInfo();
5024 for (size_t i=0; i<num_matches; ++i)
5025 {
5026 const dw_offset_t die_offset = die_offsets[i];
5027 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
5028
5029 if (type_die)
5030 {
5031 bool try_resolving_type = false;
5032
5033 // Don't try and resolve the DIE we are looking for with the DIE itself!
5034 if (type_die != die)
5035 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005036 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00005037 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005038 case DW_TAG_class_type:
5039 case DW_TAG_structure_type:
5040 try_resolving_type = true;
5041 break;
5042 default:
5043 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00005044 }
5045 }
5046
5047 if (try_resolving_type)
5048 {
Ed Maste4c24b122013-10-17 20:13:14 +00005049 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
5050 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00005051
5052 if (try_resolving_type)
5053 {
5054 Type *resolved_type = ResolveType (type_cu, type_die, false);
5055 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5056 {
Ed Mastea0191d12013-10-17 20:42:56 +00005057 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 +00005058 MakeUserID(die->GetOffset()),
Jim Ingham4af59612014-12-19 19:20:44 +00005059 m_obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>"),
Greg Clayton901c5ca2011-12-03 04:40:03 +00005060 MakeUserID(type_die->GetOffset()),
5061 MakeUserID(type_cu->GetOffset()));
5062
Greg Claytonc7f03b62012-01-12 04:33:28 +00005063 if (die)
5064 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00005065 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00005066 break;
5067 }
5068 }
5069 }
5070 }
5071 else
5072 {
5073 if (m_using_apple_tables)
5074 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005075 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5076 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00005077 }
5078 }
5079
5080 }
5081 }
5082 return type_sp;
5083}
5084
Greg Claytona8022fa2012-04-24 21:22:41 +00005085
Greg Clayton80c26302012-02-05 06:12:47 +00005086//----------------------------------------------------------------------
5087// This function helps to ensure that the declaration contexts match for
5088// two different DIEs. Often times debug information will refer to a
5089// forward declaration of a type (the equivalent of "struct my_struct;".
5090// There will often be a declaration of that type elsewhere that has the
5091// full definition. When we go looking for the full type "my_struct", we
5092// will find one or more matches in the accelerator tables and we will
5093// then need to make sure the type was in the same declaration context
5094// as the original DIE. This function can efficiently compare two DIEs
5095// and will return true when the declaration context matches, and false
5096// when they don't.
5097//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00005098bool
5099SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
5100 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
5101{
Greg Claytona8022fa2012-04-24 21:22:41 +00005102 if (die1 == die2)
5103 return true;
5104
5105#if defined (LLDB_CONFIGURATION_DEBUG)
5106 // You can't and shouldn't call this function with a compile unit from
5107 // two different SymbolFileDWARF instances.
5108 assert (DebugInfo()->ContainsCompileUnit (cu1));
5109 assert (DebugInfo()->ContainsCompileUnit (cu2));
5110#endif
5111
Greg Clayton890ff562012-02-02 05:48:16 +00005112 DWARFDIECollection decl_ctx_1;
5113 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00005114 //The declaration DIE stack is a stack of the declaration context
5115 // DIEs all the way back to the compile unit. If a type "T" is
5116 // declared inside a class "B", and class "B" is declared inside
5117 // a class "A" and class "A" is in a namespace "lldb", and the
5118 // namespace is in a compile unit, there will be a stack of DIEs:
5119 //
5120 // [0] DW_TAG_class_type for "B"
5121 // [1] DW_TAG_class_type for "A"
5122 // [2] DW_TAG_namespace for "lldb"
5123 // [3] DW_TAG_compile_unit for the source file.
5124 //
5125 // We grab both contexts and make sure that everything matches
5126 // all the way back to the compiler unit.
5127
5128 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00005129 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00005130 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00005131 // Make sure the context arrays have the same size, otherwise
5132 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00005133 const size_t count1 = decl_ctx_1.Size();
5134 const size_t count2 = decl_ctx_2.Size();
5135 if (count1 != count2)
5136 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00005137
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00005138 // Make sure the DW_TAG values match all the way back up the
Greg Clayton80c26302012-02-05 06:12:47 +00005139 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00005140 const DWARFDebugInfoEntry *decl_ctx_die1;
5141 const DWARFDebugInfoEntry *decl_ctx_die2;
5142 size_t i;
5143 for (i=0; i<count1; i++)
5144 {
5145 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
5146 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
5147 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
5148 return false;
5149 }
Greg Clayton890ff562012-02-02 05:48:16 +00005150#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00005151
5152 // Make sure the top item in the decl context die array is always
5153 // DW_TAG_compile_unit. If it isn't then something went wrong in
5154 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00005155 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00005156
Greg Clayton890ff562012-02-02 05:48:16 +00005157#endif
5158 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00005159 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00005160 for (i=0; i<count1 - 1; i++)
5161 {
5162 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
5163 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
5164 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00005165 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00005166 // If the string was from a DW_FORM_strp, then the pointer will often
5167 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00005168 if (name1 == name2)
5169 continue;
5170
5171 // Name pointers are not equal, so only compare the strings
5172 // if both are not NULL.
5173 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00005174 {
Greg Clayton5569e642012-02-06 01:44:54 +00005175 // If the strings don't compare, we are done...
5176 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00005177 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00005178 }
5179 else
5180 {
5181 // One name was NULL while the other wasn't
5182 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00005183 }
5184 }
Greg Clayton80c26302012-02-05 06:12:47 +00005185 // We made it through all of the checks and the declaration contexts
5186 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00005187 return true;
5188}
Greg Clayton220a0072011-12-09 08:48:30 +00005189
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005190
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005191TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00005192SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx)
5193{
5194 TypeSP type_sp;
5195
5196 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
5197 if (dwarf_decl_ctx_count > 0)
5198 {
5199 const ConstString type_name(dwarf_decl_ctx[0].name);
5200 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
5201
5202 if (type_name)
5203 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005204 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
Greg Claytona8022fa2012-04-24 21:22:41 +00005205 if (log)
5206 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005207 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005208 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')",
5209 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5210 dwarf_decl_ctx.GetQualifiedName());
5211 }
5212
5213 DIEArray die_offsets;
5214
5215 if (m_using_apple_tables)
5216 {
5217 if (m_apple_types_ap.get())
5218 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005219 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
5220 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
5221 if (has_tag && has_qualified_name_hash)
Greg Claytona8022fa2012-04-24 21:22:41 +00005222 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005223 const char *qualified_name = dwarf_decl_ctx.GetQualifiedName();
5224 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name);
5225 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005226 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005227 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets);
5228 }
5229 else if (has_tag)
5230 {
5231 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005232 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
Greg Claytona8022fa2012-04-24 21:22:41 +00005233 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets);
5234 }
5235 else
5236 {
5237 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
5238 }
5239 }
5240 }
5241 else
5242 {
5243 if (!m_indexed)
5244 Index ();
5245
5246 m_type_index.Find (type_name, die_offsets);
5247 }
5248
5249 const size_t num_matches = die_offsets.size();
5250
5251
5252 DWARFCompileUnit* type_cu = NULL;
5253 const DWARFDebugInfoEntry* type_die = NULL;
5254 if (num_matches)
5255 {
5256 DWARFDebugInfo* debug_info = DebugInfo();
5257 for (size_t i=0; i<num_matches; ++i)
5258 {
5259 const dw_offset_t die_offset = die_offsets[i];
5260 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
5261
5262 if (type_die)
5263 {
5264 bool try_resolving_type = false;
5265
5266 // Don't try and resolve the DIE we are looking for with the DIE itself!
5267 const dw_tag_t type_tag = type_die->Tag();
5268 // Make sure the tags match
5269 if (type_tag == tag)
5270 {
5271 // The tags match, lets try resolving this type
5272 try_resolving_type = true;
5273 }
5274 else
5275 {
5276 // The tags don't match, but we need to watch our for a
5277 // forward declaration for a struct and ("struct foo")
5278 // ends up being a class ("class foo { ... };") or
5279 // vice versa.
5280 switch (type_tag)
5281 {
5282 case DW_TAG_class_type:
5283 // We had a "class foo", see if we ended up with a "struct foo { ... };"
5284 try_resolving_type = (tag == DW_TAG_structure_type);
5285 break;
5286 case DW_TAG_structure_type:
5287 // We had a "struct foo", see if we ended up with a "class foo { ... };"
5288 try_resolving_type = (tag == DW_TAG_class_type);
5289 break;
5290 default:
5291 // Tags don't match, don't event try to resolve
5292 // using this type whose name matches....
5293 break;
5294 }
5295 }
5296
5297 if (try_resolving_type)
5298 {
5299 DWARFDeclContext type_dwarf_decl_ctx;
5300 type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx);
5301
5302 if (log)
5303 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005304 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005305 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)",
5306 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5307 dwarf_decl_ctx.GetQualifiedName(),
5308 type_die->GetOffset(),
5309 type_dwarf_decl_ctx.GetQualifiedName());
5310 }
5311
5312 // Make sure the decl contexts match all the way up
5313 if (dwarf_decl_ctx == type_dwarf_decl_ctx)
5314 {
5315 Type *resolved_type = ResolveType (type_cu, type_die, false);
5316 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5317 {
5318 type_sp = resolved_type->shared_from_this();
5319 break;
5320 }
5321 }
5322 }
5323 else
5324 {
5325 if (log)
5326 {
5327 std::string qualified_name;
5328 type_die->GetQualifiedName(this, type_cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00005329 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005330 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)",
5331 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5332 dwarf_decl_ctx.GetQualifiedName(),
5333 type_die->GetOffset(),
5334 qualified_name.c_str());
5335 }
5336 }
5337 }
5338 else
5339 {
5340 if (m_using_apple_tables)
5341 {
5342 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5343 die_offset, type_name.GetCString());
5344 }
5345 }
5346
5347 }
5348 }
5349 }
5350 }
5351 return type_sp;
5352}
5353
Greg Clayton4116e932012-05-15 02:33:01 +00005354bool
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005355SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005356 Type *class_type,
Greg Clayton4116e932012-05-15 02:33:01 +00005357 DWARFCompileUnit* src_cu,
5358 const DWARFDebugInfoEntry *src_class_die,
5359 DWARFCompileUnit* dst_cu,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005360 const DWARFDebugInfoEntry *dst_class_die,
Greg Claytond20deac2014-04-04 18:15:18 +00005361 DWARFDIECollection &failures)
Greg Clayton4116e932012-05-15 02:33:01 +00005362{
5363 if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die)
5364 return false;
5365 if (src_class_die->Tag() != dst_class_die->Tag())
5366 return false;
5367
5368 // We need to complete the class type so we can get all of the method types
5369 // parsed so we can then unique those types to their equivalent counterparts
5370 // in "dst_cu" and "dst_class_die"
5371 class_type->GetClangFullType();
5372
5373 const DWARFDebugInfoEntry *src_die;
5374 const DWARFDebugInfoEntry *dst_die;
5375 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die;
5376 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die;
Greg Clayton65ec1032012-11-12 21:27:20 +00005377 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial;
5378 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial;
Greg Clayton4116e932012-05-15 02:33:01 +00005379 for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling())
5380 {
5381 if (src_die->Tag() == DW_TAG_subprogram)
5382 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005383 // Make sure this is a declaration and not a concrete instance by looking
5384 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5385 // are placed inside the class definitions and shouldn't be included in
5386 // the list of things are are tracking here.
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005387 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_declaration, 0) == 1)
Greg Clayton84afacd2012-11-07 23:09:32 +00005388 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005389 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton84afacd2012-11-07 23:09:32 +00005390 if (src_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005391 {
5392 ConstString src_const_name(src_name);
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005393 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0))
Greg Clayton65ec1032012-11-12 21:27:20 +00005394 src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die);
5395 else
5396 src_name_to_die.Append(src_const_name.GetCString(), src_die);
5397 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005398 }
Greg Clayton4116e932012-05-15 02:33:01 +00005399 }
5400 }
5401 for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling())
5402 {
5403 if (dst_die->Tag() == DW_TAG_subprogram)
5404 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005405 // Make sure this is a declaration and not a concrete instance by looking
5406 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5407 // are placed inside the class definitions and shouldn't be included in
5408 // the list of things are are tracking here.
5409 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1)
5410 {
5411 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5412 if (dst_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005413 {
5414 ConstString dst_const_name(dst_name);
5415 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0))
5416 dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die);
5417 else
5418 dst_name_to_die.Append(dst_const_name.GetCString(), dst_die);
5419 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005420 }
Greg Clayton4116e932012-05-15 02:33:01 +00005421 }
5422 }
5423 const uint32_t src_size = src_name_to_die.GetSize ();
5424 const uint32_t dst_size = dst_name_to_die.GetSize ();
Greg Clayton5160ce52013-03-27 23:08:40 +00005425 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005426
5427 // Is everything kosher so we can go through the members at top speed?
5428 bool fast_path = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005429
Sean Callanan2367f8a2013-02-26 01:12:25 +00005430 if (src_size != dst_size)
Greg Clayton4116e932012-05-15 02:33:01 +00005431 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005432 if (src_size != 0 && dst_size != 0)
5433 {
5434 if (log)
5435 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)",
5436 src_class_die->GetOffset(),
5437 dst_class_die->GetOffset(),
5438 src_size,
5439 dst_size);
5440 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005441
Sean Callanan2367f8a2013-02-26 01:12:25 +00005442 fast_path = false;
5443 }
5444
5445 uint32_t idx;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005446
Sean Callanan2367f8a2013-02-26 01:12:25 +00005447 if (fast_path)
5448 {
Greg Clayton4116e932012-05-15 02:33:01 +00005449 for (idx = 0; idx < src_size; ++idx)
5450 {
5451 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5452 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5453
5454 if (src_die->Tag() != dst_die->Tag())
5455 {
5456 if (log)
5457 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)",
5458 src_class_die->GetOffset(),
5459 dst_class_die->GetOffset(),
5460 src_die->GetOffset(),
5461 DW_TAG_value_to_name(src_die->Tag()),
5462 dst_die->GetOffset(),
5463 DW_TAG_value_to_name(src_die->Tag()));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005464 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005465 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005466
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005467 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton4116e932012-05-15 02:33:01 +00005468 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005469
Greg Clayton4116e932012-05-15 02:33:01 +00005470 // Make sure the names match
5471 if (src_name == dst_name || (strcmp (src_name, dst_name) == 0))
5472 continue;
5473
5474 if (log)
5475 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)",
5476 src_class_die->GetOffset(),
5477 dst_class_die->GetOffset(),
5478 src_die->GetOffset(),
5479 src_name,
5480 dst_die->GetOffset(),
5481 dst_name);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005482
Sean Callanan2367f8a2013-02-26 01:12:25 +00005483 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005484 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005485 }
Greg Clayton4116e932012-05-15 02:33:01 +00005486
Sean Callanan2367f8a2013-02-26 01:12:25 +00005487 // Now do the work of linking the DeclContexts and Types.
5488 if (fast_path)
5489 {
5490 // We can do this quickly. Just run across the tables index-for-index since
5491 // we know each node has matching names and tags.
Greg Clayton4116e932012-05-15 02:33:01 +00005492 for (idx = 0; idx < src_size; ++idx)
5493 {
5494 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5495 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005496
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005497 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Greg Clayton4116e932012-05-15 02:33:01 +00005498 if (src_decl_ctx)
5499 {
5500 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005501 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
5502 static_cast<void*>(src_decl_ctx),
5503 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005504 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5505 }
5506 else
5507 {
5508 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005509 log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found",
5510 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005511 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005512
Greg Clayton4116e932012-05-15 02:33:01 +00005513 Type *src_child_type = m_die_to_type[src_die];
5514 if (src_child_type)
5515 {
5516 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005517 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
5518 static_cast<void*>(src_child_type),
5519 src_child_type->GetID(),
5520 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005521 m_die_to_type[dst_die] = src_child_type;
5522 }
5523 else
5524 {
5525 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005526 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());
5527 }
5528 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005529 }
5530 else
5531 {
5532 // We must do this slowly. For each member of the destination, look
5533 // up a member in the source with the same name, check its tag, and
5534 // unique them if everything matches up. Report failures.
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005535
Sean Callanan2367f8a2013-02-26 01:12:25 +00005536 if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty())
5537 {
5538 src_name_to_die.Sort();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005539
Sean Callanan2367f8a2013-02-26 01:12:25 +00005540 for (idx = 0; idx < dst_size; ++idx)
5541 {
5542 const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx);
5543 dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
5544 src_die = src_name_to_die.Find(dst_name, NULL);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005545
Sean Callanan2367f8a2013-02-26 01:12:25 +00005546 if (src_die && (src_die->Tag() == dst_die->Tag()))
5547 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005548 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Sean Callanan2367f8a2013-02-26 01:12:25 +00005549 if (src_decl_ctx)
5550 {
5551 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005552 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
5553 static_cast<void*>(src_decl_ctx),
5554 src_die->GetOffset(),
5555 dst_die->GetOffset());
Sean Callanan2367f8a2013-02-26 01:12:25 +00005556 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5557 }
5558 else
5559 {
5560 if (log)
5561 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());
5562 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005563
Sean Callanan2367f8a2013-02-26 01:12:25 +00005564 Type *src_child_type = m_die_to_type[src_die];
5565 if (src_child_type)
5566 {
5567 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005568 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
5569 static_cast<void*>(src_child_type),
5570 src_child_type->GetID(),
5571 src_die->GetOffset(),
5572 dst_die->GetOffset());
Sean Callanan2367f8a2013-02-26 01:12:25 +00005573 m_die_to_type[dst_die] = src_child_type;
5574 }
5575 else
5576 {
5577 if (log)
5578 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());
5579 }
5580 }
5581 else
5582 {
5583 if (log)
5584 log->Printf ("warning: couldn't find a match for 0x%8.8x", dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005585
Greg Claytond20deac2014-04-04 18:15:18 +00005586 failures.Append(dst_die);
Sean Callanan2367f8a2013-02-26 01:12:25 +00005587 }
5588 }
5589 }
5590 }
5591
5592 const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize ();
5593 const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize ();
5594
5595 UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src;
5596
5597 if (src_size_artificial && dst_size_artificial)
5598 {
5599 dst_name_to_die_artificial.Sort();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005600
Greg Clayton65ec1032012-11-12 21:27:20 +00005601 for (idx = 0; idx < src_size_artificial; ++idx)
5602 {
5603 const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx);
5604 src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5605 dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005606
Greg Clayton65ec1032012-11-12 21:27:20 +00005607 if (dst_die)
5608 {
Greg Clayton65ec1032012-11-12 21:27:20 +00005609 // Both classes have the artificial types, link them
5610 clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die];
5611 if (src_decl_ctx)
5612 {
5613 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005614 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
5615 static_cast<void*>(src_decl_ctx),
5616 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005617 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5618 }
5619 else
5620 {
5621 if (log)
5622 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());
5623 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005624
Greg Clayton65ec1032012-11-12 21:27:20 +00005625 Type *src_child_type = m_die_to_type[src_die];
5626 if (src_child_type)
5627 {
5628 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005629 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
5630 static_cast<void*>(src_child_type),
5631 src_child_type->GetID(),
5632 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005633 m_die_to_type[dst_die] = src_child_type;
5634 }
5635 else
5636 {
5637 if (log)
5638 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());
5639 }
5640 }
5641 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005642 }
Greg Clayton65ec1032012-11-12 21:27:20 +00005643
Sean Callanan2367f8a2013-02-26 01:12:25 +00005644 if (dst_size_artificial)
Greg Clayton4116e932012-05-15 02:33:01 +00005645 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005646 for (idx = 0; idx < dst_size_artificial; ++idx)
5647 {
5648 const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx);
5649 dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5650 if (log)
5651 log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial);
5652
Greg Claytond20deac2014-04-04 18:15:18 +00005653 failures.Append(dst_die);
Sean Callanan2367f8a2013-02-26 01:12:25 +00005654 }
Greg Clayton4116e932012-05-15 02:33:01 +00005655 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005656
Greg Claytond20deac2014-04-04 18:15:18 +00005657 return (failures.Size() != 0);
Greg Clayton4116e932012-05-15 02:33:01 +00005658}
Greg Claytona8022fa2012-04-24 21:22:41 +00005659
5660TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00005661SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005662{
5663 TypeSP type_sp;
5664
Greg Clayton1be10fc2010-09-29 01:12:09 +00005665 if (type_is_new_ptr)
5666 *type_is_new_ptr = false;
Greg Clayton1fba87112012-02-09 20:03:49 +00005667
Todd Fiala0a70a842014-05-28 16:43:26 +00005668#if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE)
Greg Clayton1fba87112012-02-09 20:03:49 +00005669 static DIEStack g_die_stack;
5670 DIEStack::ScopedPopper scoped_die_logger(g_die_stack);
5671#endif
Greg Clayton1be10fc2010-09-29 01:12:09 +00005672
Sean Callananc7fbf732010-08-06 00:32:49 +00005673 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005674 if (die != NULL)
5675 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005676 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005677 if (log)
Sean Callanan5b26f272012-02-04 08:49:35 +00005678 {
5679 const DWARFDebugInfoEntry *context_die;
5680 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005681
Greg Clayton5160ce52013-03-27 23:08:40 +00005682 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 +00005683 die->GetOffset(),
5684 static_cast<void*>(context),
5685 context_die->GetOffset(),
5686 DW_TAG_value_to_name(die->Tag()),
5687 die->GetName(this, dwarf_cu));
5688
Todd Fiala0a70a842014-05-28 16:43:26 +00005689#if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE)
Greg Clayton1fba87112012-02-09 20:03:49 +00005690 scoped_die_logger.Push (dwarf_cu, die);
Greg Clayton5160ce52013-03-27 23:08:40 +00005691 g_die_stack.LogDIEs(log, this);
Greg Clayton1fba87112012-02-09 20:03:49 +00005692#endif
Sean Callanan5b26f272012-02-04 08:49:35 +00005693 }
Greg Clayton3bffb082011-12-10 02:15:28 +00005694//
Greg Clayton5160ce52013-03-27 23:08:40 +00005695// Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005696// if (log && dwarf_cu)
5697// {
5698// StreamString s;
5699// die->DumpLocation (this, dwarf_cu, s);
Greg Clayton5160ce52013-03-27 23:08:40 +00005700// GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Greg Clayton3bffb082011-12-10 02:15:28 +00005701//
5702// }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005703
Greg Clayton594e5ed2010-09-27 21:07:38 +00005704 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005705 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00005706 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005707 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005708 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00005709 if (type_is_new_ptr)
5710 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005711
Greg Clayton594e5ed2010-09-27 21:07:38 +00005712 const dw_tag_t tag = die->Tag();
5713
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005714 bool is_forward_declaration = false;
5715 DWARFDebugInfoEntry::Attributes attributes;
5716 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00005717 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00005718 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
Greg Claytonfaac1112013-03-14 18:31:44 +00005719 uint64_t byte_size = 0;
Greg Clayton526e5af2010-11-13 03:52:47 +00005720 Declaration decl;
5721
Greg Clayton4957bf62010-09-30 21:49:03 +00005722 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton57ee3062013-07-11 22:46:58 +00005723 ClangASTType clang_type;
Greg Claytond20deac2014-04-04 18:15:18 +00005724 DWARFFormValue form_value;
5725
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005726 dw_attr_t attr;
5727
5728 switch (tag)
5729 {
5730 case DW_TAG_base_type:
5731 case DW_TAG_pointer_type:
5732 case DW_TAG_reference_type:
Sean Callanance8af862012-05-21 23:31:51 +00005733 case DW_TAG_rvalue_reference_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005734 case DW_TAG_typedef:
5735 case DW_TAG_const_type:
5736 case DW_TAG_restrict_type:
5737 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00005738 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005739 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005740 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005741 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005742
Greg Claytond88d7592010-09-15 08:33:30 +00005743 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005744 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005745 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
5746
5747 if (num_attributes > 0)
5748 {
5749 uint32_t i;
5750 for (i=0; i<num_attributes; ++i)
5751 {
5752 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005753 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5754 {
5755 switch (attr)
5756 {
5757 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5758 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5759 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5760 case DW_AT_name:
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005761
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005762 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00005763 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
5764 // include the "&"...
5765 if (tag == DW_TAG_reference_type)
5766 {
5767 if (strchr (type_name_cstr, '&') == NULL)
5768 type_name_cstr = NULL;
5769 }
5770 if (type_name_cstr)
5771 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005772 break;
Greg Clayton23f59502012-07-17 03:23:13 +00005773 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005774 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
Greg Clayton54166af2014-11-22 01:58:59 +00005775 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005776 default:
5777 case DW_AT_sibling:
5778 break;
5779 }
5780 }
5781 }
5782 }
5783
Ed Mastea0191d12013-10-17 20:42:56 +00005784 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 +00005785
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005786 switch (tag)
5787 {
5788 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00005789 break;
5790
Greg Claytond4436412011-10-28 21:00:00 +00005791 case DW_TAG_unspecified_type:
Greg Clayton7fba2632013-07-01 21:01:52 +00005792 if (strcmp(type_name_cstr, "nullptr_t") == 0 ||
5793 strcmp(type_name_cstr, "decltype(nullptr)") == 0 )
Greg Claytond4436412011-10-28 21:00:00 +00005794 {
5795 resolve_state = Type::eResolveStateFull;
Greg Clayton57ee3062013-07-11 22:46:58 +00005796 clang_type = ast.GetBasicType(eBasicTypeNullPtr);
Greg Claytond4436412011-10-28 21:00:00 +00005797 break;
5798 }
5799 // Fall through to base type below in case we can handle the type there...
5800
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005801 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00005802 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005803 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
5804 encoding,
5805 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005806 break;
5807
Sean Callanance8af862012-05-21 23:31:51 +00005808 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
5809 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
5810 case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break;
5811 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
5812 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
5813 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
5814 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005815 }
5816
Greg Clayton57ee3062013-07-11 22:46:58 +00005817 if (!clang_type && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID) && sc.comp_unit != NULL)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005818 {
Sean Callanan82587052013-01-03 00:05:56 +00005819 bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005820
Sean Callanan82587052013-01-03 00:05:56 +00005821 if (translation_unit_is_objc)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005822 {
Sean Callanan82587052013-01-03 00:05:56 +00005823 if (type_name_cstr != NULL)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005824 {
Sean Callanan82587052013-01-03 00:05:56 +00005825 static ConstString g_objc_type_name_id("id");
5826 static ConstString g_objc_type_name_Class("Class");
5827 static ConstString g_objc_type_name_selector("SEL");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005828
Sean Callanan82587052013-01-03 00:05:56 +00005829 if (type_name_const_str == g_objc_type_name_id)
5830 {
5831 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005832 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 +00005833 die->GetOffset(),
5834 DW_TAG_value_to_name(die->Tag()),
5835 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005836 clang_type = ast.GetBasicType(eBasicTypeObjCID);
Sean Callanan82587052013-01-03 00:05:56 +00005837 encoding_data_type = Type::eEncodingIsUID;
5838 encoding_uid = LLDB_INVALID_UID;
5839 resolve_state = Type::eResolveStateFull;
Greg Clayton526e5af2010-11-13 03:52:47 +00005840
Sean Callanan82587052013-01-03 00:05:56 +00005841 }
5842 else if (type_name_const_str == g_objc_type_name_Class)
5843 {
5844 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005845 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 +00005846 die->GetOffset(),
5847 DW_TAG_value_to_name(die->Tag()),
5848 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005849 clang_type = ast.GetBasicType(eBasicTypeObjCClass);
Sean Callanan82587052013-01-03 00:05:56 +00005850 encoding_data_type = Type::eEncodingIsUID;
5851 encoding_uid = LLDB_INVALID_UID;
5852 resolve_state = Type::eResolveStateFull;
5853 }
5854 else if (type_name_const_str == g_objc_type_name_selector)
5855 {
5856 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005857 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 +00005858 die->GetOffset(),
5859 DW_TAG_value_to_name(die->Tag()),
5860 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005861 clang_type = ast.GetBasicType(eBasicTypeObjCSel);
Sean Callanan82587052013-01-03 00:05:56 +00005862 encoding_data_type = Type::eEncodingIsUID;
5863 encoding_uid = LLDB_INVALID_UID;
5864 resolve_state = Type::eResolveStateFull;
5865 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005866 }
Sean Callanan82587052013-01-03 00:05:56 +00005867 else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005868 {
Sean Callanan82587052013-01-03 00:05:56 +00005869 // 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 +00005870
Sean Callanan82587052013-01-03 00:05:56 +00005871 DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005872
Sean Callanan82587052013-01-03 00:05:56 +00005873 if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005874 {
Sean Callanan82587052013-01-03 00:05:56 +00005875 if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL))
5876 {
5877 if (!strcmp(struct_name, "objc_object"))
5878 {
5879 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005880 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 +00005881 die->GetOffset(),
5882 DW_TAG_value_to_name(die->Tag()),
5883 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005884 clang_type = ast.GetBasicType(eBasicTypeObjCID);
Sean Callanan82587052013-01-03 00:05:56 +00005885 encoding_data_type = Type::eEncodingIsUID;
5886 encoding_uid = LLDB_INVALID_UID;
5887 resolve_state = Type::eResolveStateFull;
5888 }
5889 }
5890 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005891 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005892 }
5893 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005894
Greg Clayton81c22f62011-10-19 18:09:39 +00005895 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005896 this,
5897 type_name_const_str,
5898 byte_size,
5899 NULL,
5900 encoding_uid,
5901 encoding_data_type,
5902 &decl,
5903 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005904 resolve_state));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005905
Greg Clayton594e5ed2010-09-27 21:07:38 +00005906 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005907
5908// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
5909// if (encoding_type != NULL)
5910// {
5911// if (encoding_type != DIE_IS_BEING_PARSED)
5912// type_sp->SetEncodingType(encoding_type);
5913// else
5914// m_indirect_fixups.push_back(type_sp.get());
5915// }
5916 }
5917 break;
5918
5919 case DW_TAG_structure_type:
5920 case DW_TAG_union_type:
5921 case DW_TAG_class_type:
5922 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005923 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005924 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Greg Clayton23f59502012-07-17 03:23:13 +00005925 bool byte_size_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005926
Greg Clayton9e409562010-07-28 02:04:09 +00005927 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00005928 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005929 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00005930 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005931 if (num_attributes > 0)
5932 {
5933 uint32_t i;
5934 for (i=0; i<num_attributes; ++i)
5935 {
5936 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005937 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5938 {
5939 switch (attr)
5940 {
Greg Clayton9e409562010-07-28 02:04:09 +00005941 case DW_AT_decl_file:
Greg Claytonc7f03b62012-01-12 04:33:28 +00005942 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
Ed Maste4c24b122013-10-17 20:13:14 +00005943 {
5944 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
5945 // point to the compile unit file, so we clear this invalid value
5946 // so that we can still unique types efficiently.
Greg Claytonc7f03b62012-01-12 04:33:28 +00005947 decl.SetFile(FileSpec ("<invalid>", false));
Ed Maste4c24b122013-10-17 20:13:14 +00005948 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005949 else
5950 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
Greg Clayton9e409562010-07-28 02:04:09 +00005951 break;
5952
5953 case DW_AT_decl_line:
5954 decl.SetLine(form_value.Unsigned());
5955 break;
5956
5957 case DW_AT_decl_column:
5958 decl.SetColumn(form_value.Unsigned());
5959 break;
5960
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005961 case DW_AT_name:
5962 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005963 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005964 break;
Greg Clayton9e409562010-07-28 02:04:09 +00005965
5966 case DW_AT_byte_size:
5967 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00005968 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00005969 break;
5970
5971 case DW_AT_accessibility:
5972 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
5973 break;
5974
5975 case DW_AT_declaration:
Greg Clayton1c8ef472013-04-05 23:27:21 +00005976 is_forward_declaration = form_value.Boolean();
Greg Clayton9e409562010-07-28 02:04:09 +00005977 break;
5978
5979 case DW_AT_APPLE_runtime_class:
5980 class_language = (LanguageType)form_value.Signed();
5981 break;
5982
Greg Clayton18774842011-11-29 23:40:34 +00005983 case DW_AT_APPLE_objc_complete_type:
5984 is_complete_objc_class = form_value.Signed();
5985 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005986
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005987 case DW_AT_allocated:
5988 case DW_AT_associated:
5989 case DW_AT_data_location:
5990 case DW_AT_description:
5991 case DW_AT_start_scope:
5992 case DW_AT_visibility:
5993 default:
5994 case DW_AT_sibling:
5995 break;
5996 }
5997 }
5998 }
5999 }
Greg Claytond20deac2014-04-04 18:15:18 +00006000
6001 // UniqueDWARFASTType is large, so don't create a local variables on the
6002 // stack, put it on the heap. This function is often called recursively
6003 // and clang isn't good and sharing the stack space for variables in different blocks.
6004 std::unique_ptr<UniqueDWARFASTType> unique_ast_entry_ap(new UniqueDWARFASTType());
Sean Callanan8e8072d2012-02-07 21:13:38 +00006005
Greg Clayton123edca2012-03-02 00:07:15 +00006006 // Only try and unique the type if it has a name.
6007 if (type_name_const_str &&
6008 GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Sean Callanan8e8072d2012-02-07 21:13:38 +00006009 this,
6010 dwarf_cu,
6011 die,
6012 decl,
6013 byte_size_valid ? byte_size : -1,
Greg Claytond20deac2014-04-04 18:15:18 +00006014 *unique_ast_entry_ap))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006015 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00006016 // We have already parsed this type or from another
6017 // compile unit. GCC loves to use the "one definition
6018 // rule" which can result in multiple definitions
6019 // of the same class over and over in each compile
6020 // unit.
Greg Claytond20deac2014-04-04 18:15:18 +00006021 type_sp = unique_ast_entry_ap->m_type_sp;
Sean Callanan8e8072d2012-02-07 21:13:38 +00006022 if (type_sp)
Greg Claytonc615ce42010-11-09 04:42:43 +00006023 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00006024 m_die_to_type[die] = type_sp.get();
6025 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00006026 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006027 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006028
Daniel Malead01b2952012-11-29 21:49:15 +00006029 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 +00006030
6031 int tag_decl_kind = -1;
6032 AccessType default_accessibility = eAccessNone;
6033 if (tag == DW_TAG_structure_type)
6034 {
6035 tag_decl_kind = clang::TTK_Struct;
6036 default_accessibility = eAccessPublic;
6037 }
6038 else if (tag == DW_TAG_union_type)
6039 {
6040 tag_decl_kind = clang::TTK_Union;
6041 default_accessibility = eAccessPublic;
6042 }
6043 else if (tag == DW_TAG_class_type)
6044 {
6045 tag_decl_kind = clang::TTK_Class;
6046 default_accessibility = eAccessPrivate;
6047 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006048
Greg Clayton3a5f29a2011-11-30 02:48:28 +00006049 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
6050 die->HasChildren() == false &&
6051 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
6052 {
6053 // Work around an issue with clang at the moment where
6054 // forward declarations for objective C classes are emitted
6055 // as:
6056 // DW_TAG_structure_type [2]
6057 // DW_AT_name( "ForwardObjcClass" )
6058 // DW_AT_byte_size( 0x00 )
6059 // DW_AT_decl_file( "..." )
6060 // DW_AT_decl_line( 1 )
6061 //
6062 // Note that there is no DW_AT_declaration and there are
6063 // no children, and the byte size is zero.
6064 is_forward_declaration = true;
6065 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006066
Sean Callanan7457f8d2012-04-25 01:03:57 +00006067 if (class_language == eLanguageTypeObjC ||
6068 class_language == eLanguageTypeObjC_plus_plus)
Greg Clayton18774842011-11-29 23:40:34 +00006069 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00006070 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
Greg Clayton901c5ca2011-12-03 04:40:03 +00006071 {
6072 // We have a valid eSymbolTypeObjCClass class symbol whose
6073 // name matches the current objective C class that we
6074 // are trying to find and this DIE isn't the complete
6075 // definition (we checked is_complete_objc_class above and
6076 // know it is false), so the real definition is in here somewhere
Greg Claytonc7f03b62012-01-12 04:33:28 +00006077 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006078
Greg Clayton1f746072012-08-29 21:13:06 +00006079 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton901c5ca2011-12-03 04:40:03 +00006080 {
6081 // We weren't able to find a full declaration in
6082 // this DWARF, see if we have a declaration anywhere
6083 // else...
Greg Claytonc7f03b62012-01-12 04:33:28 +00006084 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00006085 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006086
Greg Clayton901c5ca2011-12-03 04:40:03 +00006087 if (type_sp)
6088 {
6089 if (log)
6090 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006091 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00006092 "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 +00006093 static_cast<void*>(this),
Greg Claytone38a5ed2012-01-05 03:57:59 +00006094 die->GetOffset(),
6095 DW_TAG_value_to_name(tag),
6096 type_name_cstr,
6097 type_sp->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00006098 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006099
Greg Clayton901c5ca2011-12-03 04:40:03 +00006100 // We found a real definition for this type elsewhere
6101 // so lets use it and cache the fact that we found
6102 // a complete type for this die
6103 m_die_to_type[die] = type_sp.get();
6104 return type_sp;
6105 }
6106 }
6107 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006108
Greg Clayton901c5ca2011-12-03 04:40:03 +00006109
6110 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006111 {
6112 // We have a forward declaration to a type and we need
6113 // to try and find a full declaration. We look in the
6114 // current type index just in case we have a forward
6115 // declaration followed by an actual declarations in the
6116 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00006117 if (log)
6118 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006119 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00006120 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006121 static_cast<void*>(this),
Greg Claytone38a5ed2012-01-05 03:57:59 +00006122 die->GetOffset(),
6123 DW_TAG_value_to_name(tag),
6124 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00006125 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006126
Greg Claytona8022fa2012-04-24 21:22:41 +00006127 DWARFDeclContext die_decl_ctx;
6128 die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx);
6129
6130 //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
6131 type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006132
Greg Clayton1f746072012-08-29 21:13:06 +00006133 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton4272cc72011-02-02 02:24:04 +00006134 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006135 // We weren't able to find a full declaration in
6136 // this DWARF, see if we have a declaration anywhere
6137 // else...
Greg Claytona8022fa2012-04-24 21:22:41 +00006138 type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton4272cc72011-02-02 02:24:04 +00006139 }
6140
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006141 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00006142 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00006143 if (log)
6144 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006145 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00006146 "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 +00006147 static_cast<void*>(this),
Greg Claytone38a5ed2012-01-05 03:57:59 +00006148 die->GetOffset(),
6149 DW_TAG_value_to_name(tag),
6150 type_name_cstr,
6151 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00006152 }
6153
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006154 // We found a real definition for this type elsewhere
6155 // so lets use it and cache the fact that we found
6156 // a complete type for this die
6157 m_die_to_type[die] = type_sp.get();
6158 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00006159 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006160 }
6161 assert (tag_decl_kind != -1);
6162 bool clang_type_was_created = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00006163 clang_type.SetClangType(ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die));
6164 if (!clang_type)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006165 {
Sean Callanan4d04c6a2012-02-09 22:54:11 +00006166 const DWARFDebugInfoEntry *decl_ctx_die;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006167
Sean Callanan4d04c6a2012-02-09 22:54:11 +00006168 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton55561e92011-10-26 03:31:36 +00006169 if (accessibility == eAccessNone && decl_ctx)
6170 {
6171 // Check the decl context that contains this class/struct/union.
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00006172 // If it is a class we must give it an accessibility.
Greg Clayton55561e92011-10-26 03:31:36 +00006173 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
6174 if (DeclKindIsCXXClass (containing_decl_kind))
6175 accessibility = default_accessibility;
6176 }
6177
Greg Claytonc4ffd662013-03-08 01:37:30 +00006178 ClangASTMetadata metadata;
6179 metadata.SetUserID(MakeUserID(die->GetOffset()));
6180 metadata.SetIsDynamicCXXType(ClassOrStructIsVirtual (dwarf_cu, die));
6181
Greg Claytonf0705c82011-10-22 03:33:13 +00006182 if (type_name_cstr && strchr (type_name_cstr, '<'))
6183 {
6184 ClangASTContext::TemplateParameterInfos template_param_infos;
6185 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
6186 {
6187 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00006188 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00006189 type_name_cstr,
6190 tag_decl_kind,
6191 template_param_infos);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006192
Greg Claytonf0705c82011-10-22 03:33:13 +00006193 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
6194 class_template_decl,
6195 tag_decl_kind,
6196 template_param_infos);
6197 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
6198 clang_type_was_created = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006199
Greg Claytond0029442013-03-27 01:48:02 +00006200 GetClangASTContext().SetMetadata (class_template_decl, metadata);
6201 GetClangASTContext().SetMetadata (class_specialization_decl, metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00006202 }
6203 }
6204
6205 if (!clang_type_was_created)
6206 {
6207 clang_type_was_created = true;
Greg Clayton55561e92011-10-26 03:31:36 +00006208 clang_type = ast.CreateRecordType (decl_ctx,
6209 accessibility,
6210 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00006211 tag_decl_kind,
Sean Callanan60217122012-04-13 00:10:03 +00006212 class_language,
Jim Ingham379397632012-10-27 02:54:13 +00006213 &metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00006214 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006215 }
6216
6217 // Store a forward declaration to this class type in case any
6218 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00006219 // types for function prototypes.
Greg Clayton57ee3062013-07-11 22:46:58 +00006220 LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00006221 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006222 this,
6223 type_name_const_str,
6224 byte_size,
6225 NULL,
6226 LLDB_INVALID_UID,
6227 Type::eEncodingIsUID,
6228 &decl,
6229 clang_type,
6230 Type::eResolveStateForward));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006231
Sean Callanan72772842012-02-22 23:57:45 +00006232 type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006233
6234
6235 // Add our type to the unique type map so we don't
6236 // end up creating many copies of the same type over
6237 // and over in the ASTContext for our module
Greg Claytond20deac2014-04-04 18:15:18 +00006238 unique_ast_entry_ap->m_type_sp = type_sp;
6239 unique_ast_entry_ap->m_symfile = this;
6240 unique_ast_entry_ap->m_cu = dwarf_cu;
6241 unique_ast_entry_ap->m_die = die;
6242 unique_ast_entry_ap->m_declaration = decl;
6243 unique_ast_entry_ap->m_byte_size = byte_size;
Greg Claytone576ab22011-02-15 00:19:15 +00006244 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
Greg Claytond20deac2014-04-04 18:15:18 +00006245 *unique_ast_entry_ap);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006246
Greg Clayton0ec71a02013-08-10 00:09:35 +00006247 if (is_forward_declaration && die->HasChildren())
6248 {
6249 // Check to see if the DIE actually has a definition, some version of GCC will
6250 // emit DIEs with DW_AT_declaration set to true, but yet still have subprogram,
6251 // members, or inheritance, so we can't trust it
6252 const DWARFDebugInfoEntry *child_die = die->GetFirstChild();
6253 while (child_die)
6254 {
6255 switch (child_die->Tag())
6256 {
6257 case DW_TAG_inheritance:
6258 case DW_TAG_subprogram:
6259 case DW_TAG_member:
6260 case DW_TAG_APPLE_property:
Greg Clayton4c484ec2014-02-07 19:21:56 +00006261 case DW_TAG_class_type:
6262 case DW_TAG_structure_type:
6263 case DW_TAG_enumeration_type:
6264 case DW_TAG_typedef:
6265 case DW_TAG_union_type:
Greg Clayton0ec71a02013-08-10 00:09:35 +00006266 child_die = NULL;
6267 is_forward_declaration = false;
6268 break;
6269 default:
6270 child_die = child_die->GetSibling();
6271 break;
6272 }
6273 }
6274 }
6275
Sean Callanan12014a02011-12-08 23:45:45 +00006276 if (!is_forward_declaration)
Greg Clayton219cf312012-03-30 00:51:13 +00006277 {
6278 // Always start the definition for a class type so that
6279 // if the class has child classes or types that require
6280 // the class to be created for use as their decl contexts
6281 // the class will be ready to accept these child definitions.
Sean Callanan12014a02011-12-08 23:45:45 +00006282 if (die->HasChildren() == false)
6283 {
6284 // No children for this struct/union/class, lets finish it
Greg Clayton57ee3062013-07-11 22:46:58 +00006285 clang_type.StartTagDeclarationDefinition ();
6286 clang_type.CompleteTagDeclarationDefinition ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006287
Sean Callanan433cd222012-10-19 01:37:25 +00006288 if (tag == DW_TAG_structure_type) // this only applies in C
6289 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006290 clang::RecordDecl *record_decl = clang_type.GetAsRecordDecl();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006291
Greg Clayton57ee3062013-07-11 22:46:58 +00006292 if (record_decl)
Greg Claytond20deac2014-04-04 18:15:18 +00006293 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, LayoutInfo()));
Sean Callanan433cd222012-10-19 01:37:25 +00006294 }
Sean Callanan12014a02011-12-08 23:45:45 +00006295 }
6296 else if (clang_type_was_created)
6297 {
Greg Clayton219cf312012-03-30 00:51:13 +00006298 // Start the definition if the class is not objective C since
6299 // the underlying decls respond to isCompleteDefinition(). Objective
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +00006300 // C decls don't respond to isCompleteDefinition() so we can't
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00006301 // start the declaration definition right away. For C++ class/union/structs
Greg Clayton219cf312012-03-30 00:51:13 +00006302 // we want to start the definition in case the class is needed as the
6303 // declaration context for a contained class or type without the need
6304 // to complete that type..
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006305
Sean Callanan7457f8d2012-04-25 01:03:57 +00006306 if (class_language != eLanguageTypeObjC &&
6307 class_language != eLanguageTypeObjC_plus_plus)
Greg Clayton57ee3062013-07-11 22:46:58 +00006308 clang_type.StartTagDeclarationDefinition ();
Greg Clayton219cf312012-03-30 00:51:13 +00006309
Sean Callanan12014a02011-12-08 23:45:45 +00006310 // Leave this as a forward declaration until we need
6311 // to know the details of the type. lldb_private::Type
6312 // will automatically call the SymbolFile virtual function
6313 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
6314 // When the definition needs to be defined.
Greg Clayton57ee3062013-07-11 22:46:58 +00006315 m_forward_decl_die_to_clang_type[die] = clang_type.GetOpaqueQualType();
6316 m_forward_decl_clang_type_to_die[clang_type.RemoveFastQualifiers().GetOpaqueQualType()] = die;
6317 clang_type.SetHasExternalStorage (true);
Sean Callanan12014a02011-12-08 23:45:45 +00006318 }
Greg Claytonc615ce42010-11-09 04:42:43 +00006319 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006320
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006321 }
6322 break;
6323
6324 case DW_TAG_enumeration_type:
6325 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006326 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006327 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006328
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006329 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006330
Greg Claytond88d7592010-09-15 08:33:30 +00006331 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006332 if (num_attributes > 0)
6333 {
6334 uint32_t i;
6335
6336 for (i=0; i<num_attributes; ++i)
6337 {
6338 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006339 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6340 {
6341 switch (attr)
6342 {
Greg Clayton7a345282010-11-09 23:46:37 +00006343 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6344 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6345 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006346 case DW_AT_name:
6347 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006348 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006349 break;
Greg Clayton54166af2014-11-22 01:58:59 +00006350 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006351 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
6352 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006353 case DW_AT_declaration: break; //is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006354 case DW_AT_allocated:
6355 case DW_AT_associated:
6356 case DW_AT_bit_stride:
6357 case DW_AT_byte_stride:
6358 case DW_AT_data_location:
6359 case DW_AT_description:
6360 case DW_AT_start_scope:
6361 case DW_AT_visibility:
6362 case DW_AT_specification:
6363 case DW_AT_abstract_origin:
6364 case DW_AT_sibling:
6365 break;
6366 }
6367 }
6368 }
6369
Daniel Malead01b2952012-11-29 21:49:15 +00006370 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 +00006371
Greg Clayton57ee3062013-07-11 22:46:58 +00006372 ClangASTType enumerator_clang_type;
6373 clang_type.SetClangType (ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die));
6374 if (!clang_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00006375 {
Greg Clayton5d14fc02013-03-06 06:23:54 +00006376 if (encoding_uid != DW_INVALID_OFFSET)
6377 {
6378 Type *enumerator_type = ResolveTypeUID(encoding_uid);
6379 if (enumerator_type)
6380 enumerator_clang_type = enumerator_type->GetClangFullType();
6381 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006382
Greg Clayton57ee3062013-07-11 22:46:58 +00006383 if (!enumerator_clang_type)
Greg Clayton5d14fc02013-03-06 06:23:54 +00006384 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
6385 DW_ATE_signed,
6386 byte_size * 8);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006387
Greg Claytonca512b32011-01-14 04:54:56 +00006388 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00006389 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00006390 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006391 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00006392 }
6393 else
6394 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006395 enumerator_clang_type = clang_type.GetEnumerationIntegerType ();
Greg Clayton1be10fc2010-09-29 01:12:09 +00006396 }
6397
Greg Clayton57ee3062013-07-11 22:46:58 +00006398 LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006399
Greg Clayton81c22f62011-10-19 18:09:39 +00006400 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006401 this,
6402 type_name_const_str,
6403 byte_size,
6404 NULL,
6405 encoding_uid,
6406 Type::eEncodingIsUID,
6407 &decl,
6408 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006409 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006410
Greg Clayton57ee3062013-07-11 22:46:58 +00006411 clang_type.StartTagDeclarationDefinition ();
Greg Clayton6beaaa62011-01-17 03:46:26 +00006412 if (die->HasChildren())
6413 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006414 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00006415 bool is_signed = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00006416 enumerator_clang_type.IsIntegerType(is_signed);
Greg Clayton3e067532013-03-05 23:54:39 +00006417 ParseChildEnumerators(cu_sc, clang_type, is_signed, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00006418 }
Greg Clayton57ee3062013-07-11 22:46:58 +00006419 clang_type.CompleteTagDeclarationDefinition ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006420 }
6421 }
6422 break;
6423
Jim Inghamb0be4422010-08-12 01:20:14 +00006424 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006425 case DW_TAG_subprogram:
6426 case DW_TAG_subroutine_type:
6427 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006428 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006429 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006430
Greg Clayton23f59502012-07-17 03:23:13 +00006431 //const char *mangled = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006432 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00006433 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006434 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00006435 bool is_static = false;
6436 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00006437 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00006438 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00006439 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
6440 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Jim Ingham379397632012-10-27 02:54:13 +00006441 dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00006442
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006443 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00006444 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006445
6446
Greg Claytond88d7592010-09-15 08:33:30 +00006447 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006448 if (num_attributes > 0)
6449 {
6450 uint32_t i;
6451 for (i=0; i<num_attributes; ++i)
6452 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006453 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006454 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6455 {
6456 switch (attr)
6457 {
6458 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6459 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6460 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6461 case DW_AT_name:
6462 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006463 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006464 break;
6465
Greg Clayton71415542012-12-08 00:24:40 +00006466 case DW_AT_linkage_name:
Greg Clayton23f59502012-07-17 03:23:13 +00006467 case DW_AT_MIPS_linkage_name: break; // mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00006468 case DW_AT_type: type_die_offset = form_value.Reference(); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00006469 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006470 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
6471 case DW_AT_inline: is_inline = form_value.Boolean(); break;
6472 case DW_AT_virtuality: is_virtual = form_value.Boolean(); break;
6473 case DW_AT_explicit: is_explicit = form_value.Boolean(); break;
6474 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006475
Greg Claytonf51de672010-10-01 02:31:07 +00006476
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006477 case DW_AT_external:
6478 if (form_value.Unsigned())
6479 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00006480 if (storage == clang::SC_None)
6481 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006482 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00006483 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006484 }
6485 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006486
Greg Clayton72da3972011-08-16 18:40:23 +00006487 case DW_AT_specification:
Greg Clayton54166af2014-11-22 01:58:59 +00006488 specification_die_offset = form_value.Reference();
Greg Clayton72da3972011-08-16 18:40:23 +00006489 break;
6490
6491 case DW_AT_abstract_origin:
Greg Clayton54166af2014-11-22 01:58:59 +00006492 abstract_origin_die_offset = form_value.Reference();
Greg Clayton72da3972011-08-16 18:40:23 +00006493 break;
6494
Jim Ingham379397632012-10-27 02:54:13 +00006495 case DW_AT_object_pointer:
Greg Clayton54166af2014-11-22 01:58:59 +00006496 object_pointer_die_offset = form_value.Reference();
Jim Ingham379397632012-10-27 02:54:13 +00006497 break;
6498
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006499 case DW_AT_allocated:
6500 case DW_AT_associated:
6501 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006502 case DW_AT_calling_convention:
6503 case DW_AT_data_location:
6504 case DW_AT_elemental:
6505 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006506 case DW_AT_frame_base:
6507 case DW_AT_high_pc:
6508 case DW_AT_low_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006509 case DW_AT_prototyped:
6510 case DW_AT_pure:
6511 case DW_AT_ranges:
6512 case DW_AT_recursive:
6513 case DW_AT_return_addr:
6514 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006515 case DW_AT_start_scope:
6516 case DW_AT_static_link:
6517 case DW_AT_trampoline:
6518 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006519 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006520 case DW_AT_description:
6521 case DW_AT_sibling:
6522 break;
6523 }
6524 }
6525 }
Greg Clayton24739922010-10-13 03:15:28 +00006526 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006527
Jim Ingham379397632012-10-27 02:54:13 +00006528 std::string object_pointer_name;
6529 if (object_pointer_die_offset != DW_INVALID_OFFSET)
6530 {
6531 // Get the name from the object pointer die
6532 StreamString s;
6533 if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s))
6534 {
6535 object_pointer_name.assign(s.GetData());
6536 }
6537 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006538
Daniel Malead01b2952012-11-29 21:49:15 +00006539 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 +00006540
Greg Clayton57ee3062013-07-11 22:46:58 +00006541 ClangASTType return_clang_type;
Greg Clayton24739922010-10-13 03:15:28 +00006542 Type *func_type = NULL;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006543
Greg Clayton24739922010-10-13 03:15:28 +00006544 if (type_die_offset != DW_INVALID_OFFSET)
6545 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00006546
Greg Clayton24739922010-10-13 03:15:28 +00006547 if (func_type)
Greg Clayton42ce2f32011-12-12 21:50:19 +00006548 return_clang_type = func_type->GetClangForwardType();
Greg Clayton24739922010-10-13 03:15:28 +00006549 else
Greg Clayton57ee3062013-07-11 22:46:58 +00006550 return_clang_type = ast.GetBasicType(eBasicTypeVoid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006551
Greg Claytonf51de672010-10-01 02:31:07 +00006552
Greg Clayton57ee3062013-07-11 22:46:58 +00006553 std::vector<ClangASTType> function_param_types;
Greg Clayton24739922010-10-13 03:15:28 +00006554 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006555
Greg Clayton24739922010-10-13 03:15:28 +00006556 // Parse the function children for the parameters
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006557
Greg Claytoncb5860a2011-10-13 23:49:28 +00006558 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
6559 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00006560 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
6561
Greg Claytonf0705c82011-10-22 03:33:13 +00006562 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00006563 // Start off static. This will be set to false in ParseChildParameters(...)
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00006564 // if we find a "this" parameters as the first parameter
Greg Clayton5113dc82011-08-12 06:47:54 +00006565 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00006566 is_static = true;
Greg Claytond20deac2014-04-04 18:15:18 +00006567
Greg Clayton24739922010-10-13 03:15:28 +00006568 if (die->HasChildren())
6569 {
Greg Clayton0fffff52010-09-24 05:15:53 +00006570 bool skip_artificial = true;
Jim Ingham379397632012-10-27 02:54:13 +00006571 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00006572 containing_decl_ctx,
Jim Ingham379397632012-10-27 02:54:13 +00006573 dwarf_cu,
6574 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00006575 skip_artificial,
6576 is_static,
Greg Clayton03969752014-02-24 18:53:11 +00006577 is_variadic,
Jim Ingham379397632012-10-27 02:54:13 +00006578 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00006579 function_param_decls,
Greg Claytond20deac2014-04-04 18:15:18 +00006580 type_quals);
Greg Clayton24739922010-10-13 03:15:28 +00006581 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006582
Greg Clayton24739922010-10-13 03:15:28 +00006583 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006584 clang_type = ast.CreateFunctionType (return_clang_type,
Greg Clayton9cb25c42012-10-30 17:02:18 +00006585 function_param_types.data(),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006586 function_param_types.size(),
6587 is_variadic,
6588 type_quals);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006589
Sean Callanande9ce872013-05-09 23:13:13 +00006590 bool ignore_containing_context = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006591
Greg Clayton24739922010-10-13 03:15:28 +00006592 if (type_name_cstr)
6593 {
6594 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00006595 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006596 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00006597 ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true);
6598 if (objc_method.IsValid(true))
Greg Clayton0fffff52010-09-24 05:15:53 +00006599 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006600 ClangASTType class_opaque_type;
Greg Clayton1b3815c2013-01-30 00:18:29 +00006601 ConstString class_name(objc_method.GetClassName());
Greg Clayton7c810422012-01-18 23:40:49 +00006602 if (class_name)
Greg Clayton0fffff52010-09-24 05:15:53 +00006603 {
Greg Clayton278a16b2012-01-19 00:52:59 +00006604 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
Greg Claytonc7f03b62012-01-12 04:33:28 +00006605
6606 if (complete_objc_class_type_sp)
Greg Clayton0fffff52010-09-24 05:15:53 +00006607 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006608 ClangASTType type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
6609 if (type_clang_forward_type.IsObjCObjectOrInterfaceType ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00006610 class_opaque_type = type_clang_forward_type;
Greg Clayton0fffff52010-09-24 05:15:53 +00006611 }
Greg Clayton24739922010-10-13 03:15:28 +00006612 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006613
Greg Clayton24739922010-10-13 03:15:28 +00006614 if (class_opaque_type)
6615 {
6616 // If accessibility isn't set to anything valid, assume public for
6617 // now...
6618 if (accessibility == eAccessNone)
6619 accessibility = eAccessPublic;
6620
Greg Clayton57ee3062013-07-11 22:46:58 +00006621 clang::ObjCMethodDecl *objc_method_decl = class_opaque_type.AddMethodToObjCObjectType (type_name_cstr,
6622 clang_type,
6623 accessibility,
6624 is_artificial);
Greg Clayton24739922010-10-13 03:15:28 +00006625 type_handled = objc_method_decl != NULL;
Sean Callanan464a5b52012-10-04 22:06:29 +00006626 if (type_handled)
6627 {
6628 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Claytond0029442013-03-27 01:48:02 +00006629 GetClangASTContext().SetMetadataAsUserID (objc_method_decl, MakeUserID(die->GetOffset()));
Sean Callanan464a5b52012-10-04 22:06:29 +00006630 }
Sean Callananc3a1d562013-02-06 23:21:59 +00006631 else
6632 {
Jason Molendac1a65832013-03-07 22:44:42 +00006633 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 +00006634 die->GetOffset(),
6635 tag,
6636 DW_TAG_value_to_name(tag));
6637 }
Greg Clayton24739922010-10-13 03:15:28 +00006638 }
6639 }
Greg Clayton5113dc82011-08-12 06:47:54 +00006640 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00006641 {
6642 // Look at the parent of this DIE and see if is is
6643 // a class or struct and see if this is actually a
6644 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00006645 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00006646 if (class_type)
6647 {
Greg Clayton4116e932012-05-15 02:33:01 +00006648 if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset()))
6649 {
6650 // We uniqued the parent class of this function to another class
6651 // so we now need to associate all dies under "decl_ctx_die" to
6652 // DIEs in the DIE for "class_type"...
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006653 SymbolFileDWARF *class_symfile = NULL;
Greg Clayton4116e932012-05-15 02:33:01 +00006654 DWARFCompileUnitSP class_type_cu_sp;
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006655 const DWARFDebugInfoEntry *class_type_die = NULL;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006656
Sean Callanan2367f8a2013-02-26 01:12:25 +00006657 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
6658 if (debug_map_symfile)
6659 {
6660 class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID()));
6661 class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6662 }
6663 else
6664 {
6665 class_symfile = this;
6666 class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6667 }
Greg Clayton4116e932012-05-15 02:33:01 +00006668 if (class_type_die)
6669 {
Greg Claytond20deac2014-04-04 18:15:18 +00006670 DWARFDIECollection failures;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006671
Sean Callanan2367f8a2013-02-26 01:12:25 +00006672 CopyUniqueClassMethodTypes (class_symfile,
6673 class_type,
6674 class_type_cu_sp.get(),
6675 class_type_die,
6676 dwarf_cu,
6677 decl_ctx_die,
6678 failures);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006679
Sean Callanan2367f8a2013-02-26 01:12:25 +00006680 // FIXME do something with these failures that's smarter than
6681 // just dropping them on the ground. Unfortunately classes don't
6682 // like having stuff added to them after their definitions are
6683 // complete...
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006684
Sean Callanan2367f8a2013-02-26 01:12:25 +00006685 type_ptr = m_die_to_type[die];
6686 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton4116e932012-05-15 02:33:01 +00006687 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006688 type_sp = type_ptr->shared_from_this();
6689 break;
Greg Clayton4116e932012-05-15 02:33:01 +00006690 }
6691 }
6692 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006693
Greg Clayton72da3972011-08-16 18:40:23 +00006694 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00006695 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006696 // We have a specification which we are going to base our function
6697 // prototype off of, so we need this type to be completed so that the
6698 // m_die_to_decl_ctx for the method in the specification has a valid
6699 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006700 class_type->GetClangForwardType();
Greg Clayton72da3972011-08-16 18:40:23 +00006701 // If we have a specification, then the function type should have been
6702 // made with the specification and not with this die.
6703 DWARFCompileUnitSP spec_cu_sp;
6704 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006705 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006706 if (spec_clang_decl_ctx)
6707 {
6708 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
6709 }
6710 else
Jim Inghamc1663042011-09-29 22:12:35 +00006711 {
Daniel Malead01b2952012-11-29 21:49:15 +00006712 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8x) has no decl\n",
Greg Claytone38a5ed2012-01-05 03:57:59 +00006713 MakeUserID(die->GetOffset()),
6714 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006715 }
Greg Clayton72da3972011-08-16 18:40:23 +00006716 type_handled = true;
6717 }
6718 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
6719 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006720 // We have a specification which we are going to base our function
6721 // prototype off of, so we need this type to be completed so that the
6722 // m_die_to_decl_ctx for the method in the abstract origin has a valid
6723 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006724 class_type->GetClangForwardType();
Greg Clayton5cf58b92011-10-05 22:22:08 +00006725
Greg Clayton72da3972011-08-16 18:40:23 +00006726 DWARFCompileUnitSP abs_cu_sp;
6727 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006728 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006729 if (abs_clang_decl_ctx)
6730 {
6731 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
6732 }
6733 else
Jim Inghamc1663042011-09-29 22:12:35 +00006734 {
Daniel Malead01b2952012-11-29 21:49:15 +00006735 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 +00006736 MakeUserID(die->GetOffset()),
6737 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006738 }
Greg Clayton72da3972011-08-16 18:40:23 +00006739 type_handled = true;
6740 }
6741 else
6742 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006743 ClangASTType class_opaque_type = class_type->GetClangForwardType();
6744 if (class_opaque_type.IsCXXClassType ())
Greg Clayton931180e2011-01-27 06:44:37 +00006745 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006746 if (class_opaque_type.IsBeingDefined ())
Greg Clayton72da3972011-08-16 18:40:23 +00006747 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006748 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
6749 // in the DWARF for C++ methods... Default to public for now...
6750 if (accessibility == eAccessNone)
6751 accessibility = eAccessPublic;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006752
Greg Clayton20568dd2011-10-13 23:13:20 +00006753 if (!is_static && !die->HasChildren())
6754 {
6755 // We have a C++ member function with no children (this pointer!)
6756 // and clang will get mad if we try and make a function that isn't
6757 // well formed in the DWARF, so we will just skip it...
6758 type_handled = true;
6759 }
6760 else
6761 {
6762 clang::CXXMethodDecl *cxx_method_decl;
6763 // REMOVE THE CRASH DESCRIPTION BELOW
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00006764 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 +00006765 type_name_cstr,
6766 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00006767 MakeUserID(die->GetOffset()),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00006768 m_obj_file->GetFileSpec().GetPath().c_str());
Greg Clayton20568dd2011-10-13 23:13:20 +00006769
Sean Callananc1b732d2011-11-01 18:07:13 +00006770 const bool is_attr_used = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006771
Greg Clayton57ee3062013-07-11 22:46:58 +00006772 cxx_method_decl = class_opaque_type.AddMethodToCXXRecordType (type_name_cstr,
6773 clang_type,
6774 accessibility,
6775 is_virtual,
6776 is_static,
6777 is_inline,
6778 is_explicit,
6779 is_attr_used,
6780 is_artificial);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006781
Greg Clayton20568dd2011-10-13 23:13:20 +00006782 type_handled = cxx_method_decl != NULL;
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006783
6784 if (type_handled)
Jim Ingham379397632012-10-27 02:54:13 +00006785 {
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006786 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
6787
6788 Host::SetCrashDescription (NULL);
6789
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006790
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006791 ClangASTMetadata metadata;
6792 metadata.SetUserID(MakeUserID(die->GetOffset()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006793
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006794 if (!object_pointer_name.empty())
6795 {
6796 metadata.SetObjectPtrName(object_pointer_name.c_str());
6797 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006798 log->Printf ("Setting object pointer name: %s on method object %p.\n",
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006799 object_pointer_name.c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006800 static_cast<void*>(cxx_method_decl));
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006801 }
Greg Claytond0029442013-03-27 01:48:02 +00006802 GetClangASTContext().SetMetadata (cxx_method_decl, metadata);
Jim Ingham379397632012-10-27 02:54:13 +00006803 }
Sean Callananb0640dc2013-04-09 23:22:08 +00006804 else
6805 {
Sean Callanande9ce872013-05-09 23:13:13 +00006806 ignore_containing_context = true;
Sean Callananb0640dc2013-04-09 23:22:08 +00006807 }
Greg Clayton20568dd2011-10-13 23:13:20 +00006808 }
Greg Clayton72da3972011-08-16 18:40:23 +00006809 }
6810 else
6811 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006812 // We were asked to parse the type for a method in a class, yet the
6813 // class hasn't been asked to complete itself through the
6814 // clang::ExternalASTSource protocol, so we need to just have the
6815 // class complete itself and do things the right way, then our
6816 // DIE should then have an entry in the m_die_to_type map. First
6817 // we need to modify the m_die_to_type so it doesn't think we are
6818 // trying to parse this DIE anymore...
6819 m_die_to_type[die] = NULL;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006820
Greg Clayton20568dd2011-10-13 23:13:20 +00006821 // Now we get the full type to force our class type to complete itself
6822 // using the clang::ExternalASTSource protocol which will parse all
6823 // base classes and all methods (including the method for this DIE).
6824 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00006825
Greg Clayton20568dd2011-10-13 23:13:20 +00006826 // The type for this DIE should have been filled in the function call above
6827 type_ptr = m_die_to_type[die];
Greg Claytone5476db2012-06-01 20:32:35 +00006828 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton20568dd2011-10-13 23:13:20 +00006829 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006830 type_sp = type_ptr->shared_from_this();
Greg Clayton20568dd2011-10-13 23:13:20 +00006831 break;
6832 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006833
Sean Callanan02eee4d2012-04-12 23:10:00 +00006834 // FIXME This is fixing some even uglier behavior but we really need to
6835 // uniq the methods of each class as well as the class itself.
6836 // <rdar://problem/11240464>
6837 type_handled = true;
Greg Clayton72da3972011-08-16 18:40:23 +00006838 }
Greg Clayton931180e2011-01-27 06:44:37 +00006839 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006840 }
6841 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006842 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006843 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006844
Greg Clayton24739922010-10-13 03:15:28 +00006845 if (!type_handled)
6846 {
6847 // We just have a function that isn't part of a class
Sean Callanande9ce872013-05-09 23:13:13 +00006848 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (ignore_containing_context ? GetClangASTContext().GetTranslationUnitDecl() : containing_decl_ctx,
Greg Clayton147e1fa2011-10-14 22:47:18 +00006849 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006850 clang_type,
6851 storage,
6852 is_inline);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006853
6854// if (template_param_infos.GetSize() > 0)
6855// {
6856// clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
6857// function_decl,
6858// type_name_cstr,
6859// template_param_infos);
6860//
6861// ast.CreateFunctionTemplateSpecializationInfo (function_decl,
6862// func_template_decl,
6863// template_param_infos);
6864// }
Greg Clayton24739922010-10-13 03:15:28 +00006865 // Add the decl to our DIE to decl context map
6866 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00006867 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00006868 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006869 ast.SetFunctionParameters (function_decl,
6870 &function_param_decls.front(),
6871 function_param_decls.size());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006872
Jim Ingham379397632012-10-27 02:54:13 +00006873 ClangASTMetadata metadata;
6874 metadata.SetUserID(MakeUserID(die->GetOffset()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006875
Jim Ingham379397632012-10-27 02:54:13 +00006876 if (!object_pointer_name.empty())
6877 {
6878 metadata.SetObjectPtrName(object_pointer_name.c_str());
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006879 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006880 log->Printf ("Setting object pointer name: %s on function object %p.",
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006881 object_pointer_name.c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006882 static_cast<void*>(function_decl));
Jim Ingham379397632012-10-27 02:54:13 +00006883 }
Greg Claytond0029442013-03-27 01:48:02 +00006884 GetClangASTContext().SetMetadata (function_decl, metadata);
Greg Clayton24739922010-10-13 03:15:28 +00006885 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006886 }
Greg Clayton81c22f62011-10-19 18:09:39 +00006887 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006888 this,
6889 type_name_const_str,
6890 0,
6891 NULL,
6892 LLDB_INVALID_UID,
6893 Type::eEncodingIsUID,
6894 &decl,
6895 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006896 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00006897 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006898 }
6899 break;
6900
6901 case DW_TAG_array_type:
6902 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006903 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006904 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006905
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006906 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006907 int64_t first_index = 0;
6908 uint32_t byte_stride = 0;
6909 uint32_t bit_stride = 0;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006910 bool is_vector = false;
Greg Claytond88d7592010-09-15 08:33:30 +00006911 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006912
6913 if (num_attributes > 0)
6914 {
6915 uint32_t i;
6916 for (i=0; i<num_attributes; ++i)
6917 {
6918 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006919 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6920 {
6921 switch (attr)
6922 {
6923 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6924 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6925 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6926 case DW_AT_name:
6927 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006928 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006929 break;
6930
Greg Clayton54166af2014-11-22 01:58:59 +00006931 case DW_AT_type: type_die_offset = form_value.Reference(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006932 case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006933 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
6934 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006935 case DW_AT_GNU_vector: is_vector = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006936 case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006937 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006938 case DW_AT_allocated:
6939 case DW_AT_associated:
6940 case DW_AT_data_location:
6941 case DW_AT_description:
6942 case DW_AT_ordering:
6943 case DW_AT_start_scope:
6944 case DW_AT_visibility:
6945 case DW_AT_specification:
6946 case DW_AT_abstract_origin:
6947 case DW_AT_sibling:
6948 break;
6949 }
6950 }
6951 }
6952
Daniel Malead01b2952012-11-29 21:49:15 +00006953 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 +00006954
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006955 Type *element_type = ResolveTypeUID(type_die_offset);
6956
6957 if (element_type)
6958 {
6959 std::vector<uint64_t> element_orders;
6960 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
6961 if (byte_stride == 0 && bit_stride == 0)
6962 byte_stride = element_type->GetByteSize();
Greg Clayton57ee3062013-07-11 22:46:58 +00006963 ClangASTType array_element_type = element_type->GetClangForwardType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006964 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
Siva Chandra89ce9552015-01-05 23:06:14 +00006965 if (element_orders.size() > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006966 {
Siva Chandra89ce9552015-01-05 23:06:14 +00006967 uint64_t num_elements = 0;
6968 std::vector<uint64_t>::const_reverse_iterator pos;
6969 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
6970 for (pos = element_orders.rbegin(); pos != end; ++pos)
6971 {
6972 num_elements = *pos;
6973 clang_type = ast.CreateArrayType (array_element_type,
6974 num_elements,
6975 is_vector);
6976 array_element_type = clang_type;
6977 array_element_bit_stride = num_elements ?
6978 array_element_bit_stride * num_elements :
6979 array_element_bit_stride;
6980 }
6981 }
6982 else
6983 {
6984 clang_type = ast.CreateArrayType (array_element_type, 0, is_vector);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006985 }
6986 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00006987 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006988 this,
6989 empty_name,
6990 array_element_bit_stride / 8,
6991 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00006992 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006993 Type::eEncodingIsUID,
6994 &decl,
6995 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006996 Type::eResolveStateFull));
6997 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006998 }
6999 }
7000 }
7001 break;
7002
Greg Clayton9b81a312010-06-12 01:20:30 +00007003 case DW_TAG_ptr_to_member_type:
7004 {
7005 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
7006 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
7007
Greg Claytond88d7592010-09-15 08:33:30 +00007008 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007009
Greg Clayton9b81a312010-06-12 01:20:30 +00007010 if (num_attributes > 0) {
7011 uint32_t i;
7012 for (i=0; i<num_attributes; ++i)
7013 {
7014 attr = attributes.AttributeAtIndex(i);
Greg Clayton9b81a312010-06-12 01:20:30 +00007015 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
7016 {
7017 switch (attr)
7018 {
7019 case DW_AT_type:
Greg Clayton54166af2014-11-22 01:58:59 +00007020 type_die_offset = form_value.Reference(); break;
Greg Clayton9b81a312010-06-12 01:20:30 +00007021 case DW_AT_containing_type:
Greg Clayton54166af2014-11-22 01:58:59 +00007022 containing_type_die_offset = form_value.Reference(); break;
Greg Clayton9b81a312010-06-12 01:20:30 +00007023 }
7024 }
7025 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007026
Greg Clayton9b81a312010-06-12 01:20:30 +00007027 Type *pointee_type = ResolveTypeUID(type_die_offset);
7028 Type *class_type = ResolveTypeUID(containing_type_die_offset);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007029
Greg Clayton57ee3062013-07-11 22:46:58 +00007030 ClangASTType pointee_clang_type = pointee_type->GetClangForwardType();
7031 ClangASTType class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00007032
Greg Clayton57ee3062013-07-11 22:46:58 +00007033 clang_type = pointee_clang_type.CreateMemberPointerType(class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00007034
Enrico Granata1cd5e922015-01-28 00:07:51 +00007035 byte_size = clang_type.GetByteSize(nullptr);
Greg Clayton9b81a312010-06-12 01:20:30 +00007036
Greg Clayton81c22f62011-10-19 18:09:39 +00007037 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00007038 this,
7039 type_name_const_str,
7040 byte_size,
7041 NULL,
7042 LLDB_INVALID_UID,
7043 Type::eEncodingIsUID,
7044 NULL,
7045 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00007046 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00007047 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007048
Greg Clayton9b81a312010-06-12 01:20:30 +00007049 break;
7050 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007051 default:
Greg Clayton84afacd2012-11-07 23:09:32 +00007052 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",
7053 die->GetOffset(),
7054 tag,
7055 DW_TAG_value_to_name(tag));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007056 break;
7057 }
7058
7059 if (type_sp.get())
7060 {
7061 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7062 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7063
7064 SymbolContextScope * symbol_context_scope = NULL;
7065 if (sc_parent_tag == DW_TAG_compile_unit)
7066 {
7067 symbol_context_scope = sc.comp_unit;
7068 }
Jason Molenda60db6e42014-10-16 01:40:16 +00007069 else if (sc.function != NULL && sc_parent_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007070 {
Greg Clayton81c22f62011-10-19 18:09:39 +00007071 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007072 if (symbol_context_scope == NULL)
7073 symbol_context_scope = sc.function;
7074 }
7075
7076 if (symbol_context_scope != NULL)
7077 {
7078 type_sp->SetSymbolContextScope(symbol_context_scope);
7079 }
7080
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00007081 // We are ready to put this type into the uniqued list up at the module level
7082 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00007083
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00007084 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007085 }
7086 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00007087 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007088 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00007089 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007090 }
7091 }
7092 return type_sp;
7093}
7094
7095size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00007096SymbolFileDWARF::ParseTypes
7097(
7098 const SymbolContext& sc,
7099 DWARFCompileUnit* dwarf_cu,
7100 const DWARFDebugInfoEntry *die,
7101 bool parse_siblings,
7102 bool parse_children
7103)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007104{
7105 size_t types_added = 0;
7106 while (die != NULL)
7107 {
7108 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00007109 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007110 {
7111 if (type_is_new)
7112 ++types_added;
7113 }
7114
7115 if (parse_children && die->HasChildren())
7116 {
7117 if (die->Tag() == DW_TAG_subprogram)
7118 {
7119 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00007120 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007121 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
7122 }
7123 else
7124 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
7125 }
7126
7127 if (parse_siblings)
7128 die = die->GetSibling();
7129 else
7130 die = NULL;
7131 }
7132 return types_added;
7133}
7134
7135
7136size_t
7137SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
7138{
7139 assert(sc.comp_unit && sc.function);
7140 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00007141 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007142 if (dwarf_cu)
7143 {
7144 dw_offset_t function_die_offset = sc.function->GetID();
7145 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
7146 if (function_die)
7147 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00007148 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007149 }
7150 }
7151
7152 return functions_added;
7153}
7154
7155
7156size_t
7157SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
7158{
7159 // At least a compile unit must be valid
7160 assert(sc.comp_unit);
7161 size_t types_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00007162 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007163 if (dwarf_cu)
7164 {
7165 if (sc.function)
7166 {
7167 dw_offset_t function_die_offset = sc.function->GetID();
7168 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
7169 if (func_die && func_die->HasChildren())
7170 {
7171 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
7172 }
7173 }
7174 else
7175 {
7176 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
7177 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
7178 {
7179 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
7180 }
7181 }
7182 }
7183
7184 return types_added;
7185}
7186
7187size_t
7188SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
7189{
7190 if (sc.comp_unit != NULL)
7191 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00007192 DWARFDebugInfo* info = DebugInfo();
7193 if (info == NULL)
7194 return 0;
7195
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007196 if (sc.function)
7197 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007198 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get();
7199
7200 if (dwarf_cu == NULL)
7201 return 0;
7202
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007203 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00007204
Greg Claytonc7bece562013-01-25 18:06:21 +00007205 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
7206 if (func_lo_pc != LLDB_INVALID_ADDRESS)
Greg Claytone38a5ed2012-01-05 03:57:59 +00007207 {
7208 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00007209
Greg Claytone38a5ed2012-01-05 03:57:59 +00007210 // Let all blocks know they have parse all their variables
7211 sc.function->GetBlock (false).SetDidParseVariables (true, true);
7212 return num_variables;
7213 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007214 }
7215 else if (sc.comp_unit)
7216 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007217 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get();
7218
7219 if (dwarf_cu == NULL)
7220 return 0;
7221
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007222 uint32_t vars_added = 0;
7223 VariableListSP variables (sc.comp_unit->GetVariableList(false));
7224
7225 if (variables.get() == NULL)
7226 {
7227 variables.reset(new VariableList());
7228 sc.comp_unit->SetVariableList(variables);
7229
Greg Claytond4a2b372011-09-12 23:21:58 +00007230 DWARFCompileUnit* match_dwarf_cu = NULL;
7231 const DWARFDebugInfoEntry* die = NULL;
7232 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00007233 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00007234 {
Greg Clayton97fbc342011-10-20 22:30:33 +00007235 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00007236 {
7237 DWARFMappedHash::DIEInfoArray hash_data_array;
7238 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
7239 dwarf_cu->GetNextCompileUnitOffset(),
7240 hash_data_array))
7241 {
7242 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
7243 }
7244 }
Greg Clayton7f995132011-10-04 22:41:51 +00007245 }
7246 else
7247 {
7248 // Index if we already haven't to make sure the compile units
7249 // get indexed and make their global DIE index list
7250 if (!m_indexed)
7251 Index ();
7252
7253 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
7254 dwarf_cu->GetNextCompileUnitOffset(),
7255 die_offsets);
7256 }
7257
7258 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00007259 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007260 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007261 DWARFDebugInfo* debug_info = DebugInfo();
7262 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007263 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007264 const dw_offset_t die_offset = die_offsets[i];
7265 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00007266 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00007267 {
Greg Clayton95d87902011-11-11 03:16:25 +00007268 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
7269 if (var_sp)
7270 {
7271 variables->AddVariableIfUnique (var_sp);
7272 ++vars_added;
7273 }
Greg Claytond4a2b372011-09-12 23:21:58 +00007274 }
Greg Clayton95d87902011-11-11 03:16:25 +00007275 else
7276 {
7277 if (m_using_apple_tables)
7278 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00007279 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 +00007280 }
7281 }
7282
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007283 }
7284 }
7285 }
7286 return vars_added;
7287 }
7288 }
7289 return 0;
7290}
7291
7292
7293VariableSP
7294SymbolFileDWARF::ParseVariableDIE
7295(
7296 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007297 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007298 const DWARFDebugInfoEntry *die,
7299 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007300)
7301{
Greg Clayton83c5cd92010-11-14 22:13:40 +00007302 VariableSP var_sp (m_die_to_variable_sp[die]);
7303 if (var_sp)
7304 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007305
7306 const dw_tag_t tag = die->Tag();
Richard Mitton0a558352013-10-17 21:14:00 +00007307 ModuleSP module = GetObjectFile()->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00007308
7309 if ((tag == DW_TAG_variable) ||
7310 (tag == DW_TAG_constant) ||
7311 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007312 {
Greg Clayton7f995132011-10-04 22:41:51 +00007313 DWARFDebugInfoEntry::Attributes attributes;
7314 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
7315 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007316 {
Greg Clayton7f995132011-10-04 22:41:51 +00007317 const char *name = NULL;
7318 const char *mangled = NULL;
7319 Declaration decl;
7320 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00007321 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00007322 DWARFExpression location;
7323 bool is_external = false;
7324 bool is_artificial = false;
7325 bool location_is_const_value_data = false;
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007326 bool has_explicit_location = false;
Enrico Granata4ec130d2014-08-11 19:16:35 +00007327 DWARFFormValue const_value;
Greg Clayton23f59502012-07-17 03:23:13 +00007328 //AccessType accessibility = eAccessNone;
Greg Clayton7f995132011-10-04 22:41:51 +00007329
7330 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007331 {
Greg Clayton7f995132011-10-04 22:41:51 +00007332 dw_attr_t attr = attributes.AttributeAtIndex(i);
7333 DWARFFormValue form_value;
Greg Clayton54166af2014-11-22 01:58:59 +00007334
Greg Clayton7f995132011-10-04 22:41:51 +00007335 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007336 {
Greg Clayton7f995132011-10-04 22:41:51 +00007337 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007338 {
Greg Clayton7f995132011-10-04 22:41:51 +00007339 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
7340 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
7341 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
7342 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton71415542012-12-08 00:24:40 +00007343 case DW_AT_linkage_name:
Greg Clayton7f995132011-10-04 22:41:51 +00007344 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00007345 case DW_AT_type: type_uid = form_value.Reference(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00007346 case DW_AT_external: is_external = form_value.Boolean(); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007347 case DW_AT_const_value:
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007348 // If we have already found a DW_AT_location attribute, ignore this attribute.
7349 if (!has_explicit_location)
7350 {
7351 location_is_const_value_data = true;
7352 // The constant value will be either a block, a data value or a string.
Ed Masteeeae7212013-10-24 20:43:47 +00007353 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007354 if (DWARFFormValue::IsBlockForm(form_value.Form()))
7355 {
7356 // Retrieve the value as a block expression.
7357 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7358 uint32_t block_length = form_value.Unsigned();
Richard Mitton0a558352013-10-17 21:14:00 +00007359 location.CopyOpcodeData(module, debug_info_data, block_offset, block_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007360 }
7361 else if (DWARFFormValue::IsDataForm(form_value.Form()))
7362 {
7363 // Retrieve the value as a data expression.
Greg Clayton54166af2014-11-22 01:58:59 +00007364 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (attributes.CompileUnitAtIndex(i)->GetAddressByteSize(), attributes.CompileUnitAtIndex(i)->IsDWARF64());
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007365 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7366 uint32_t data_length = fixed_form_sizes[form_value.Form()];
Enrico Granata4ec130d2014-08-11 19:16:35 +00007367 if (data_length == 0)
7368 {
7369 const uint8_t *data_pointer = form_value.BlockData();
7370 if (data_pointer)
7371 {
Jason Molenda18f5fd32014-10-16 07:52:17 +00007372 form_value.Unsigned();
Enrico Granata4ec130d2014-08-11 19:16:35 +00007373 }
7374 else if (DWARFFormValue::IsDataForm(form_value.Form()))
7375 {
7376 // we need to get the byte size of the type later after we create the variable
7377 const_value = form_value;
7378 }
7379 }
7380 else
7381 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007382 }
7383 else
7384 {
7385 // Retrieve the value as a string expression.
7386 if (form_value.Form() == DW_FORM_strp)
7387 {
Greg Clayton54166af2014-11-22 01:58:59 +00007388 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (attributes.CompileUnitAtIndex(i)->GetAddressByteSize(), attributes.CompileUnitAtIndex(i)->IsDWARF64());
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007389 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7390 uint32_t data_length = fixed_form_sizes[form_value.Form()];
Richard Mitton0a558352013-10-17 21:14:00 +00007391 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007392 }
7393 else
7394 {
7395 const char *str = form_value.AsCString(&debug_info_data);
7396 uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart();
7397 uint32_t string_length = strlen(str) + 1;
Richard Mitton0a558352013-10-17 21:14:00 +00007398 location.CopyOpcodeData(module, debug_info_data, string_offset, string_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007399 }
7400 }
7401 }
7402 break;
Greg Clayton7f995132011-10-04 22:41:51 +00007403 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007404 {
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007405 location_is_const_value_data = false;
7406 has_explicit_location = true;
Greg Clayton7f995132011-10-04 22:41:51 +00007407 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007408 {
Ed Masteeeae7212013-10-24 20:43:47 +00007409 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Clayton7f995132011-10-04 22:41:51 +00007410
7411 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7412 uint32_t block_length = form_value.Unsigned();
Richard Mitton0a558352013-10-17 21:14:00 +00007413 location.CopyOpcodeData(module, get_debug_info_data(), block_offset, block_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007414 }
7415 else
7416 {
Ed Masteeeae7212013-10-24 20:43:47 +00007417 const DWARFDataExtractor& debug_loc_data = get_debug_loc_data();
Greg Clayton7f995132011-10-04 22:41:51 +00007418 const dw_offset_t debug_loc_offset = form_value.Unsigned();
7419
7420 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
7421 if (loc_list_length > 0)
7422 {
Richard Mitton0a558352013-10-17 21:14:00 +00007423 location.CopyOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007424 assert (func_low_pc != LLDB_INVALID_ADDRESS);
Greg Clayton54166af2014-11-22 01:58:59 +00007425 location.SetLocationListSlide (func_low_pc - attributes.CompileUnitAtIndex(i)->GetBaseAddress());
Greg Clayton7f995132011-10-04 22:41:51 +00007426 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007427 }
7428 }
Greg Clayton7f995132011-10-04 22:41:51 +00007429 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007430
Greg Clayton1c8ef472013-04-05 23:27:21 +00007431 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00007432 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007433 case DW_AT_declaration:
7434 case DW_AT_description:
7435 case DW_AT_endianity:
7436 case DW_AT_segment:
7437 case DW_AT_start_scope:
7438 case DW_AT_visibility:
7439 default:
7440 case DW_AT_abstract_origin:
7441 case DW_AT_sibling:
7442 case DW_AT_specification:
7443 break;
7444 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007445 }
7446 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007447
Greg Clayton9e9f2192013-05-17 00:55:28 +00007448 ValueType scope = eValueTypeInvalid;
7449
7450 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7451 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7452 SymbolContextScope * symbol_context_scope = NULL;
7453
Siva Chandra0783ab92015-03-24 18:32:27 +00007454 if (!mangled)
7455 {
7456 // LLDB relies on the mangled name (DW_TAG_linkage_name or DW_AT_MIPS_linkage_name) to
7457 // generate fully qualified names of global variables with commands like "frame var j".
7458 // For example, if j were an int variable holding a value 4 and declared in a namespace
7459 // B which in turn is contained in a namespace A, the command "frame var j" returns
7460 // "(int) A::B::j = 4". If the compiler does not emit a linkage name, we should be able
7461 // to generate a fully qualified name from the declaration context.
7462 if (die->GetParent()->Tag() == DW_TAG_compile_unit &&
7463 LanguageRuntime::LanguageIsCPlusPlus(dwarf_cu->GetLanguageType()))
7464 {
7465 DWARFDeclContext decl_ctx;
7466
7467 die->GetDWARFDeclContext(this, dwarf_cu, decl_ctx);
7468 mangled = decl_ctx.GetQualifiedNameAsConstString().GetCString();
7469 }
7470 }
7471
Greg Clayton9e9f2192013-05-17 00:55:28 +00007472 // DWARF doesn't specify if a DW_TAG_variable is a local, global
7473 // or static variable, so we have to do a little digging by
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00007474 // looking at the location of a variable to see if it contains
Greg Clayton9e9f2192013-05-17 00:55:28 +00007475 // a DW_OP_addr opcode _somewhere_ in the definition. I say
7476 // somewhere because clang likes to combine small global variables
7477 // into the same symbol and have locations like:
7478 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
7479 // So if we don't have a DW_TAG_formal_parameter, we can look at
7480 // the location to see if it contains a DW_OP_addr opcode, and
7481 // then we can correctly classify our variables.
7482 if (tag == DW_TAG_formal_parameter)
7483 scope = eValueTypeVariableArgument;
7484 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007485 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007486 bool op_error = false;
7487 // Check if the location has a DW_OP_addr with any address value...
7488 lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS;
7489 if (!location_is_const_value_data)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007490 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007491 location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error);
7492 if (op_error)
Greg Clayton96c09682012-01-04 22:56:43 +00007493 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007494 StreamString strm;
7495 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
7496 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 +00007497 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007498 }
Greg Claytond1767f02011-12-08 02:13:16 +00007499
Greg Clayton9e9f2192013-05-17 00:55:28 +00007500 if (location_DW_OP_addr != LLDB_INVALID_ADDRESS)
7501 {
7502 if (is_external)
7503 scope = eValueTypeVariableGlobal;
7504 else
7505 scope = eValueTypeVariableStatic;
7506
7507
7508 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile ();
7509
7510 if (debug_map_symfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007511 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007512 // When leaving the DWARF in the .o files on darwin,
7513 // when we have a global variable that wasn't initialized,
7514 // the .o file might not have allocated a virtual
7515 // address for the global variable. In this case it will
7516 // have created a symbol for the global variable
7517 // that is undefined/data and external and the value will
7518 // be the byte size of the variable. When we do the
7519 // address map in SymbolFileDWARFDebugMap we rely on
7520 // having an address, we need to do some magic here
7521 // so we can get the correct address for our global
7522 // variable. The address for all of these entries
7523 // will be zero, and there will be an undefined symbol
7524 // in this object file, and the executable will have
7525 // a matching symbol with a good address. So here we
7526 // dig up the correct address and replace it in the
7527 // location for the variable, and set the variable's
7528 // symbol context scope to be that of the main executable
7529 // so the file address will resolve correctly.
7530 bool linked_oso_file_addr = false;
7531 if (is_external && location_DW_OP_addr == 0)
Greg Clayton9422dd62013-03-04 21:46:16 +00007532 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007533 // we have a possible uninitialized extern global
7534 ConstString const_name(mangled ? mangled : name);
7535 ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile();
7536 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007537 {
Greg Clayton3046e662013-07-10 01:23:25 +00007538 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
Greg Clayton9e9f2192013-05-17 00:55:28 +00007539 if (debug_map_symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007540 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007541 Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
7542 eSymbolTypeData,
7543 Symtab::eDebugYes,
7544 Symtab::eVisibilityExtern);
7545 if (exe_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007546 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007547 if (exe_symbol->ValueIsAddress())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007548 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007549 const addr_t exe_file_addr = exe_symbol->GetAddress().GetFileAddress();
7550 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007551 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007552 if (location.Update_DW_OP_addr (exe_file_addr))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007553 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007554 linked_oso_file_addr = true;
7555 symbol_context_scope = exe_symbol;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007556 }
7557 }
7558 }
7559 }
7560 }
7561 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007562 }
Greg Clayton9422dd62013-03-04 21:46:16 +00007563
Greg Clayton9e9f2192013-05-17 00:55:28 +00007564 if (!linked_oso_file_addr)
7565 {
7566 // The DW_OP_addr is not zero, but it contains a .o file address which
7567 // needs to be linked up correctly.
7568 const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr);
7569 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton9422dd62013-03-04 21:46:16 +00007570 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007571 // Update the file address for this variable
7572 location.Update_DW_OP_addr (exe_file_addr);
7573 }
7574 else
7575 {
7576 // Variable didn't make it into the final executable
7577 return var_sp;
Greg Clayton9422dd62013-03-04 21:46:16 +00007578 }
Greg Claytond1767f02011-12-08 02:13:16 +00007579 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007580 }
Greg Clayton5cf58b92011-10-05 22:22:08 +00007581 }
7582 else
7583 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007584 scope = eValueTypeVariableLocal;
Greg Clayton5cf58b92011-10-05 22:22:08 +00007585 }
Greg Clayton7f995132011-10-04 22:41:51 +00007586 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007587
7588 if (symbol_context_scope == NULL)
7589 {
7590 switch (parent_tag)
7591 {
7592 case DW_TAG_subprogram:
7593 case DW_TAG_inlined_subroutine:
7594 case DW_TAG_lexical_block:
7595 if (sc.function)
7596 {
7597 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
7598 if (symbol_context_scope == NULL)
7599 symbol_context_scope = sc.function;
7600 }
7601 break;
7602
7603 default:
7604 symbol_context_scope = sc.comp_unit;
7605 break;
7606 }
7607 }
7608
7609 if (symbol_context_scope)
7610 {
Enrico Granata4ec130d2014-08-11 19:16:35 +00007611 SymbolFileTypeSP type_sp(new SymbolFileType(*this, type_uid));
7612
7613 if (const_value.Form() && type_sp && type_sp->GetType())
7614 location.CopyOpcodeData(const_value.Unsigned(), type_sp->GetType()->GetByteSize(), dwarf_cu->GetAddressByteSize());
7615
Greg Clayton9e9f2192013-05-17 00:55:28 +00007616 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
7617 name,
7618 mangled,
Enrico Granata4ec130d2014-08-11 19:16:35 +00007619 type_sp,
Greg Clayton9e9f2192013-05-17 00:55:28 +00007620 scope,
7621 symbol_context_scope,
7622 &decl,
7623 location,
7624 is_external,
7625 is_artificial));
7626
7627 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
7628 }
7629 else
7630 {
7631 // Not ready to parse this variable yet. It might be a global
7632 // or static variable that is in a function scope and the function
7633 // in the symbol context wasn't filled in yet
7634 return var_sp;
7635 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007636 }
Greg Clayton7f995132011-10-04 22:41:51 +00007637 // Cache var_sp even if NULL (the variable was just a specification or
7638 // was missing vital information to be able to be displayed in the debugger
7639 // (missing location due to optimization, etc)) so we don't re-parse
7640 // this DIE over and over later...
7641 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007642 }
7643 return var_sp;
7644}
7645
Greg Claytonc662ec82011-06-17 22:10:16 +00007646
7647const DWARFDebugInfoEntry *
7648SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
7649 dw_offset_t spec_block_die_offset,
7650 DWARFCompileUnit **result_die_cu_handle)
7651{
7652 // Give the concrete function die specified by "func_die_offset", find the
7653 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7654 // to "spec_block_die_offset"
7655 DWARFDebugInfo* info = DebugInfo();
7656
7657 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
7658 if (die)
7659 {
7660 assert (*result_die_cu_handle);
7661 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
7662 }
7663 return NULL;
7664}
7665
7666
7667const DWARFDebugInfoEntry *
7668SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
7669 const DWARFDebugInfoEntry *die,
7670 dw_offset_t spec_block_die_offset,
7671 DWARFCompileUnit **result_die_cu_handle)
7672{
7673 if (die)
7674 {
7675 switch (die->Tag())
7676 {
7677 case DW_TAG_subprogram:
7678 case DW_TAG_inlined_subroutine:
7679 case DW_TAG_lexical_block:
7680 {
7681 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
7682 {
7683 *result_die_cu_handle = dwarf_cu;
7684 return die;
7685 }
7686
7687 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
7688 {
7689 *result_die_cu_handle = dwarf_cu;
7690 return die;
7691 }
7692 }
7693 break;
7694 }
7695
7696 // Give the concrete function die specified by "func_die_offset", find the
7697 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7698 // to "spec_block_die_offset"
7699 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
7700 {
7701 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
7702 child_die,
7703 spec_block_die_offset,
7704 result_die_cu_handle);
7705 if (result_die)
7706 return result_die;
7707 }
7708 }
7709
7710 *result_die_cu_handle = NULL;
7711 return NULL;
7712}
7713
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007714size_t
7715SymbolFileDWARF::ParseVariables
7716(
7717 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007718 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007719 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007720 const DWARFDebugInfoEntry *orig_die,
7721 bool parse_siblings,
7722 bool parse_children,
7723 VariableList* cc_variable_list
7724)
7725{
7726 if (orig_die == NULL)
7727 return 0;
7728
Greg Claytonc662ec82011-06-17 22:10:16 +00007729 VariableListSP variable_list_sp;
7730
7731 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007732 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00007733 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007734 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007735 dw_tag_t tag = die->Tag();
7736
7737 // Check to see if we have already parsed this variable or constant?
7738 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007739 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007740 if (cc_variable_list)
7741 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007742 }
7743 else
7744 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007745 // We haven't already parsed it, lets do that now.
7746 if ((tag == DW_TAG_variable) ||
7747 (tag == DW_TAG_constant) ||
7748 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007749 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007750 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00007751 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007752 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
7753 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7754 switch (parent_tag)
7755 {
7756 case DW_TAG_compile_unit:
7757 if (sc.comp_unit != NULL)
7758 {
7759 variable_list_sp = sc.comp_unit->GetVariableList(false);
7760 if (variable_list_sp.get() == NULL)
7761 {
7762 variable_list_sp.reset(new VariableList());
7763 sc.comp_unit->SetVariableList(variable_list_sp);
7764 }
7765 }
7766 else
7767 {
Daniel Malead01b2952012-11-29 21:49:15 +00007768 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 +00007769 MakeUserID(sc_parent_die->GetOffset()),
7770 DW_TAG_value_to_name (parent_tag),
7771 MakeUserID(orig_die->GetOffset()),
7772 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007773 }
7774 break;
7775
7776 case DW_TAG_subprogram:
7777 case DW_TAG_inlined_subroutine:
7778 case DW_TAG_lexical_block:
7779 if (sc.function != NULL)
7780 {
7781 // Check to see if we already have parsed the variables for the given scope
7782
Greg Clayton81c22f62011-10-19 18:09:39 +00007783 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007784 if (block == NULL)
7785 {
7786 // This must be a specification or abstract origin with
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00007787 // a concrete block counterpart in the current function. We need
Greg Claytonc662ec82011-06-17 22:10:16 +00007788 // to find the concrete block so we can correctly add the
7789 // variable to it
7790 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
7791 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
7792 sc_parent_die->GetOffset(),
7793 &concrete_block_die_cu);
7794 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00007795 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007796 }
7797
7798 if (block != NULL)
7799 {
7800 const bool can_create = false;
7801 variable_list_sp = block->GetBlockVariableList (can_create);
7802 if (variable_list_sp.get() == NULL)
7803 {
7804 variable_list_sp.reset(new VariableList());
7805 block->SetVariableList(variable_list_sp);
7806 }
7807 }
7808 }
7809 break;
7810
7811 default:
Daniel Malead01b2952012-11-29 21:49:15 +00007812 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 +00007813 MakeUserID(orig_die->GetOffset()),
7814 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007815 break;
7816 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00007817 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007818
7819 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007820 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00007821 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
7822 if (var_sp)
7823 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007824 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00007825 if (cc_variable_list)
7826 cc_variable_list->AddVariableIfUnique (var_sp);
7827 ++vars_added;
7828 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007829 }
7830 }
7831 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007832
7833 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
7834
7835 if (!skip_children && parse_children && die->HasChildren())
7836 {
7837 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
7838 }
7839
7840 if (parse_siblings)
7841 die = die->GetSibling();
7842 else
7843 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007844 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007845 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007846}
7847
7848//------------------------------------------------------------------
7849// PluginInterface protocol
7850//------------------------------------------------------------------
Greg Clayton57abc5d2013-05-10 21:47:16 +00007851ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007852SymbolFileDWARF::GetPluginName()
7853{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007854 return GetPluginNameStatic();
7855}
7856
7857uint32_t
7858SymbolFileDWARF::GetPluginVersion()
7859{
7860 return 1;
7861}
7862
7863void
Greg Clayton6beaaa62011-01-17 03:46:26 +00007864SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
7865{
7866 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
Greg Clayton57ee3062013-07-11 22:46:58 +00007867 ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
Greg Clayton6beaaa62011-01-17 03:46:26 +00007868 if (clang_type)
7869 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7870}
7871
7872void
7873SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
7874{
7875 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
Greg Clayton57ee3062013-07-11 22:46:58 +00007876 ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
Greg Clayton6beaaa62011-01-17 03:46:26 +00007877 if (clang_type)
7878 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7879}
7880
Greg Claytona2721472011-06-25 00:44:06 +00007881void
Sean Callanancc427fa2011-07-30 02:42:06 +00007882SymbolFileDWARF::DumpIndexes ()
7883{
7884 StreamFile s(stdout, false);
7885
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00007886 s.Printf ("DWARF index for (%s) '%s':",
Sean Callanancc427fa2011-07-30 02:42:06 +00007887 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00007888 GetObjectFile()->GetFileSpec().GetPath().c_str());
Sean Callanancc427fa2011-07-30 02:42:06 +00007889 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
7890 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
7891 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
7892 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
7893 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
7894 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
7895 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
7896 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
7897}
7898
7899void
7900SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
7901 const char *name,
7902 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00007903{
Sean Callanancc427fa2011-07-30 02:42:06 +00007904 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00007905
7906 if (iter == m_decl_ctx_to_die.end())
7907 return;
7908
Greg Claytoncb5860a2011-10-13 23:49:28 +00007909 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00007910 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007911 const DWARFDebugInfoEntry *context_die = *pos;
7912
7913 if (!results)
7914 return;
7915
7916 DWARFDebugInfo* info = DebugInfo();
7917
7918 DIEArray die_offsets;
7919
7920 DWARFCompileUnit* dwarf_cu = NULL;
7921 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton220a0072011-12-09 08:48:30 +00007922
7923 if (m_using_apple_tables)
7924 {
7925 if (m_apple_types_ap.get())
7926 m_apple_types_ap->FindByName (name, die_offsets);
7927 }
7928 else
7929 {
7930 if (!m_indexed)
7931 Index ();
7932
7933 m_type_index.Find (ConstString(name), die_offsets);
7934 }
7935
Greg Clayton220a0072011-12-09 08:48:30 +00007936 const size_t num_matches = die_offsets.size();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007937
7938 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00007939 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007940 for (size_t i = 0; i < num_matches; ++i)
7941 {
7942 const dw_offset_t die_offset = die_offsets[i];
7943 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00007944
Greg Claytoncb5860a2011-10-13 23:49:28 +00007945 if (die->GetParent() != context_die)
7946 continue;
7947
7948 Type *matching_type = ResolveType (dwarf_cu, die);
7949
Greg Clayton57ee3062013-07-11 22:46:58 +00007950 clang::QualType qual_type = matching_type->GetClangForwardType().GetQualType();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007951
7952 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
7953 {
7954 clang::TagDecl *tag_decl = tag_type->getDecl();
7955 results->push_back(tag_decl);
7956 }
7957 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
7958 {
7959 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
7960 results->push_back(typedef_decl);
7961 }
Greg Claytona2721472011-06-25 00:44:06 +00007962 }
7963 }
7964 }
7965}
7966
7967void
7968SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00007969 const clang::DeclContext *decl_context,
7970 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00007971 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
7972{
Greg Clayton85ae2e12011-10-18 23:36:41 +00007973
7974 switch (decl_context->getDeclKind())
7975 {
7976 case clang::Decl::Namespace:
7977 case clang::Decl::TranslationUnit:
7978 {
7979 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7980 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
7981 }
7982 break;
7983 default:
7984 break;
7985 }
Greg Claytona2721472011-06-25 00:44:06 +00007986}
Greg Claytoncaab74e2012-01-28 00:48:57 +00007987
Zachary Turner504f38d2015-03-24 16:24:50 +00007988bool
7989SymbolFileDWARF::LayoutRecordType(void *baton, const clang::RecordDecl *record_decl, uint64_t &size,
7990 uint64_t &alignment,
Zachary Turnera98fac22015-03-24 18:56:08 +00007991 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
7992 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7993 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
Greg Claytoncaab74e2012-01-28 00:48:57 +00007994{
7995 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7996 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
7997}
7998
Zachary Turner504f38d2015-03-24 16:24:50 +00007999bool
8000SymbolFileDWARF::LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &bit_size, uint64_t &alignment,
Zachary Turnera98fac22015-03-24 18:56:08 +00008001 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
8002 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
8003 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
Greg Claytoncaab74e2012-01-28 00:48:57 +00008004{
Greg Clayton5160ce52013-03-27 23:08:40 +00008005 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Claytoncaab74e2012-01-28 00:48:57 +00008006 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
8007 bool success = false;
8008 base_offsets.clear();
8009 vbase_offsets.clear();
8010 if (pos != m_record_decl_to_layout_map.end())
8011 {
8012 bit_size = pos->second.bit_size;
8013 alignment = pos->second.alignment;
8014 field_offsets.swap(pos->second.field_offsets);
Greg Clayton2508b9b2012-11-01 23:20:02 +00008015 base_offsets.swap (pos->second.base_offsets);
8016 vbase_offsets.swap (pos->second.vbase_offsets);
Greg Claytoncaab74e2012-01-28 00:48:57 +00008017 m_record_decl_to_layout_map.erase(pos);
8018 success = true;
8019 }
8020 else
8021 {
8022 bit_size = 0;
8023 alignment = 0;
8024 field_offsets.clear();
8025 }
8026
8027 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00008028 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00008029 "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 +00008030 static_cast<const void*>(record_decl),
8031 bit_size, alignment,
8032 static_cast<uint32_t>(field_offsets.size()),
8033 static_cast<uint32_t>(base_offsets.size()),
8034 static_cast<uint32_t>(vbase_offsets.size()),
Greg Claytoncaab74e2012-01-28 00:48:57 +00008035 success);
8036 return success;
8037}
8038
8039
Greg Clayton1f746072012-08-29 21:13:06 +00008040SymbolFileDWARFDebugMap *
8041SymbolFileDWARF::GetDebugMapSymfile ()
8042{
8043 if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired())
8044 {
8045 lldb::ModuleSP module_sp (m_debug_map_module_wp.lock());
8046 if (module_sp)
8047 {
8048 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
8049 if (sym_vendor)
8050 m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile();
8051 }
8052 }
8053 return m_debug_map_symfile;
8054}
8055
Greg Claytoncaab74e2012-01-28 00:48:57 +00008056