blob: 1991143b1f6dd42695d4e450b6270c6184d2bc78 [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
Greg Clayton62742b12010-11-11 01:09:45 +000069//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
Greg Claytonc93237c2010-10-01 20:48:32 +000070
71#ifdef ENABLE_DEBUG_PRINTF
72#include <stdio.h>
Ed Mastea0191d12013-10-17 20:42:56 +000073#define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__)
Greg Claytonc93237c2010-10-01 20:48:32 +000074#else
75#define DEBUG_PRINTF(fmt, ...)
76#endif
77
Greg Clayton594e5ed2010-09-27 21:07:38 +000078#define DIE_IS_BEING_PARSED ((lldb_private::Type*)1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000079
80using namespace lldb;
81using namespace lldb_private;
82
Greg Clayton219cf312012-03-30 00:51:13 +000083//static inline bool
84//child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag)
85//{
86// switch (tag)
87// {
88// default:
89// break;
90// case DW_TAG_subprogram:
91// case DW_TAG_inlined_subroutine:
92// case DW_TAG_class_type:
93// case DW_TAG_structure_type:
94// case DW_TAG_union_type:
95// return true;
96// }
97// return false;
98//}
99//
Sean Callananc7fbf732010-08-06 00:32:49 +0000100static AccessType
Greg Clayton8cf05932010-07-22 18:30:50 +0000101DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000102{
103 switch (dwarf_accessibility)
104 {
Sean Callananc7fbf732010-08-06 00:32:49 +0000105 case DW_ACCESS_public: return eAccessPublic;
106 case DW_ACCESS_private: return eAccessPrivate;
107 case DW_ACCESS_protected: return eAccessProtected;
Greg Clayton8cf05932010-07-22 18:30:50 +0000108 default: break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000109 }
Sean Callananc7fbf732010-08-06 00:32:49 +0000110 return eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000111}
112
Todd Fiala0a70a842014-05-28 16:43:26 +0000113#if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE)
Greg Clayton1fba87112012-02-09 20:03:49 +0000114
115class DIEStack
116{
117public:
118
119 void Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
120 {
121 m_dies.push_back (DIEInfo(cu, die));
122 }
123
124
125 void LogDIEs (Log *log, SymbolFileDWARF *dwarf)
126 {
127 StreamString log_strm;
128 const size_t n = m_dies.size();
Daniel Malead01b2952012-11-29 21:49:15 +0000129 log_strm.Printf("DIEStack[%" PRIu64 "]:\n", (uint64_t)n);
Greg Clayton1fba87112012-02-09 20:03:49 +0000130 for (size_t i=0; i<n; i++)
131 {
132 DWARFCompileUnit *cu = m_dies[i].cu;
133 const DWARFDebugInfoEntry *die = m_dies[i].die;
134 std::string qualified_name;
135 die->GetQualifiedName(dwarf, cu, qualified_name);
Daniel Malead01b2952012-11-29 21:49:15 +0000136 log_strm.Printf ("[%" PRIu64 "] 0x%8.8x: %s name='%s'\n",
Greg Clayton43e0af02012-09-18 18:04:04 +0000137 (uint64_t)i,
Greg Clayton1fba87112012-02-09 20:03:49 +0000138 die->GetOffset(),
139 DW_TAG_value_to_name(die->Tag()),
140 qualified_name.c_str());
141 }
142 log->PutCString(log_strm.GetData());
143 }
144 void Pop ()
145 {
146 m_dies.pop_back();
147 }
148
149 class ScopedPopper
150 {
151 public:
152 ScopedPopper (DIEStack &die_stack) :
153 m_die_stack (die_stack),
154 m_valid (false)
155 {
156 }
157
158 void
159 Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
160 {
161 m_valid = true;
162 m_die_stack.Push (cu, die);
163 }
164
165 ~ScopedPopper ()
166 {
167 if (m_valid)
168 m_die_stack.Pop();
169 }
170
171
172
173 protected:
174 DIEStack &m_die_stack;
175 bool m_valid;
176 };
177
178protected:
179 struct DIEInfo {
180 DIEInfo (DWARFCompileUnit *c, const DWARFDebugInfoEntry *d) :
181 cu(c),
182 die(d)
183 {
184 }
185 DWARFCompileUnit *cu;
186 const DWARFDebugInfoEntry *die;
187 };
188 typedef std::vector<DIEInfo> Stack;
189 Stack m_dies;
190};
191#endif
192
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000193void
194SymbolFileDWARF::Initialize()
195{
196 LogChannelDWARF::Initialize();
197 PluginManager::RegisterPlugin (GetPluginNameStatic(),
198 GetPluginDescriptionStatic(),
199 CreateInstance);
200}
201
202void
203SymbolFileDWARF::Terminate()
204{
205 PluginManager::UnregisterPlugin (CreateInstance);
206 LogChannelDWARF::Initialize();
207}
208
209
Greg Clayton57abc5d2013-05-10 21:47:16 +0000210lldb_private::ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000211SymbolFileDWARF::GetPluginNameStatic()
212{
Greg Clayton57abc5d2013-05-10 21:47:16 +0000213 static ConstString g_name("dwarf");
214 return g_name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000215}
216
217const char *
218SymbolFileDWARF::GetPluginDescriptionStatic()
219{
220 return "DWARF and DWARF3 debug symbol file reader.";
221}
222
223
224SymbolFile*
225SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
226{
227 return new SymbolFileDWARF(obj_file);
228}
229
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000230TypeList *
231SymbolFileDWARF::GetTypeList ()
232{
Greg Clayton1f746072012-08-29 21:13:06 +0000233 if (GetDebugMapSymfile ())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000234 return m_debug_map_symfile->GetTypeList();
235 return m_obj_file->GetModule()->GetTypeList();
236
237}
Greg Claytonf02500c2013-06-18 22:51:05 +0000238void
239SymbolFileDWARF::GetTypes (DWARFCompileUnit* cu,
240 const DWARFDebugInfoEntry *die,
241 dw_offset_t min_die_offset,
242 dw_offset_t max_die_offset,
243 uint32_t type_mask,
244 TypeSet &type_set)
245{
246 if (cu)
247 {
248 if (die)
249 {
250 const dw_offset_t die_offset = die->GetOffset();
251
252 if (die_offset >= max_die_offset)
253 return;
254
255 if (die_offset >= min_die_offset)
256 {
257 const dw_tag_t tag = die->Tag();
258
259 bool add_type = false;
260
261 switch (tag)
262 {
263 case DW_TAG_array_type: add_type = (type_mask & eTypeClassArray ) != 0; break;
264 case DW_TAG_unspecified_type:
265 case DW_TAG_base_type: add_type = (type_mask & eTypeClassBuiltin ) != 0; break;
266 case DW_TAG_class_type: add_type = (type_mask & eTypeClassClass ) != 0; break;
267 case DW_TAG_structure_type: add_type = (type_mask & eTypeClassStruct ) != 0; break;
268 case DW_TAG_union_type: add_type = (type_mask & eTypeClassUnion ) != 0; break;
269 case DW_TAG_enumeration_type: add_type = (type_mask & eTypeClassEnumeration ) != 0; break;
270 case DW_TAG_subroutine_type:
271 case DW_TAG_subprogram:
272 case DW_TAG_inlined_subroutine: add_type = (type_mask & eTypeClassFunction ) != 0; break;
273 case DW_TAG_pointer_type: add_type = (type_mask & eTypeClassPointer ) != 0; break;
274 case DW_TAG_rvalue_reference_type:
275 case DW_TAG_reference_type: add_type = (type_mask & eTypeClassReference ) != 0; break;
276 case DW_TAG_typedef: add_type = (type_mask & eTypeClassTypedef ) != 0; break;
277 case DW_TAG_ptr_to_member_type: add_type = (type_mask & eTypeClassMemberPointer ) != 0; break;
278 }
279
280 if (add_type)
281 {
282 const bool assert_not_being_parsed = true;
283 Type *type = ResolveTypeUID (cu, die, assert_not_being_parsed);
284 if (type)
285 {
286 if (type_set.find(type) == type_set.end())
287 type_set.insert(type);
288 }
289 }
290 }
291
292 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild();
293 child_die != NULL;
294 child_die = child_die->GetSibling())
295 {
296 GetTypes (cu, child_die, min_die_offset, max_die_offset, type_mask, type_set);
297 }
298 }
299 }
300}
301
302size_t
303SymbolFileDWARF::GetTypes (SymbolContextScope *sc_scope,
304 uint32_t type_mask,
305 TypeList &type_list)
306
307{
308 TypeSet type_set;
309
310 CompileUnit *comp_unit = NULL;
311 DWARFCompileUnit* dwarf_cu = NULL;
312 if (sc_scope)
313 comp_unit = sc_scope->CalculateSymbolContextCompileUnit();
314
315 if (comp_unit)
316 {
317 dwarf_cu = GetDWARFCompileUnit(comp_unit);
318 if (dwarf_cu == 0)
319 return 0;
320 GetTypes (dwarf_cu,
321 dwarf_cu->DIE(),
322 dwarf_cu->GetOffset(),
323 dwarf_cu->GetNextCompileUnitOffset(),
324 type_mask,
325 type_set);
326 }
327 else
328 {
329 DWARFDebugInfo* info = DebugInfo();
330 if (info)
331 {
332 const size_t num_cus = info->GetNumCompileUnits();
333 for (size_t cu_idx=0; cu_idx<num_cus; ++cu_idx)
334 {
335 dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
336 if (dwarf_cu)
337 {
338 GetTypes (dwarf_cu,
339 dwarf_cu->DIE(),
340 0,
341 UINT32_MAX,
342 type_mask,
343 type_set);
344 }
345 }
346 }
347 }
348// if (m_using_apple_tables)
349// {
350// DWARFMappedHash::MemoryTable *apple_types = m_apple_types_ap.get();
351// if (apple_types)
352// {
353// apple_types->ForEach([this, &type_set, apple_types, type_mask](const DWARFMappedHash::DIEInfoArray &die_info_array) -> bool {
354//
355// for (auto die_info: die_info_array)
356// {
357// bool add_type = TagMatchesTypeMask (type_mask, 0);
358// if (!add_type)
359// {
360// dw_tag_t tag = die_info.tag;
361// if (tag == 0)
362// {
363// const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_info.offset, NULL);
364// tag = die->Tag();
365// }
366// add_type = TagMatchesTypeMask (type_mask, tag);
367// }
368// if (add_type)
369// {
370// Type *type = ResolveTypeUID(die_info.offset);
371//
372// if (type_set.find(type) == type_set.end())
373// type_set.insert(type);
374// }
375// }
376// return true; // Keep iterating
377// });
378// }
379// }
380// else
381// {
382// if (!m_indexed)
383// Index ();
384//
385// m_type_index.ForEach([this, &type_set, type_mask](const char *name, uint32_t die_offset) -> bool {
386//
387// bool add_type = TagMatchesTypeMask (type_mask, 0);
388//
389// if (!add_type)
390// {
391// const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_offset, NULL);
392// if (die)
393// {
394// const dw_tag_t tag = die->Tag();
395// add_type = TagMatchesTypeMask (type_mask, tag);
396// }
397// }
398//
399// if (add_type)
400// {
401// Type *type = ResolveTypeUID(die_offset);
402//
403// if (type_set.find(type) == type_set.end())
404// type_set.insert(type);
405// }
406// return true; // Keep iterating
407// });
408// }
409
Greg Clayton57ee3062013-07-11 22:46:58 +0000410 std::set<ClangASTType> clang_type_set;
Greg Claytonf02500c2013-06-18 22:51:05 +0000411 size_t num_types_added = 0;
412 for (Type *type : type_set)
413 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000414 ClangASTType clang_type = type->GetClangForwardType();
Greg Clayton0fc4f312013-06-20 01:23:18 +0000415 if (clang_type_set.find(clang_type) == clang_type_set.end())
416 {
417 clang_type_set.insert(clang_type);
418 type_list.Insert (type->shared_from_this());
419 ++num_types_added;
420 }
Greg Claytonf02500c2013-06-18 22:51:05 +0000421 }
422 return num_types_added;
423}
424
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000425
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000426//----------------------------------------------------------------------
427// Gets the first parent that is a lexical block, function or inlined
428// subroutine, or compile unit.
429//----------------------------------------------------------------------
430static const DWARFDebugInfoEntry *
431GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
432{
433 const DWARFDebugInfoEntry *die;
434 for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
435 {
436 dw_tag_t tag = die->Tag();
437
438 switch (tag)
439 {
440 case DW_TAG_compile_unit:
441 case DW_TAG_subprogram:
442 case DW_TAG_inlined_subroutine:
443 case DW_TAG_lexical_block:
444 return die;
445 }
446 }
447 return NULL;
448}
449
450
Greg Clayton450e3f32010-10-12 02:24:53 +0000451SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
452 SymbolFile (objfile),
Greg Clayton81c22f62011-10-19 18:09:39 +0000453 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 +0000454 m_debug_map_module_wp (),
Greg Clayton450e3f32010-10-12 02:24:53 +0000455 m_debug_map_symfile (NULL),
Greg Clayton7a345282010-11-09 23:46:37 +0000456 m_clang_tu_decl (NULL),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000457 m_flags(),
Greg Claytond4a2b372011-09-12 23:21:58 +0000458 m_data_debug_abbrev (),
459 m_data_debug_aranges (),
460 m_data_debug_frame (),
461 m_data_debug_info (),
462 m_data_debug_line (),
463 m_data_debug_loc (),
464 m_data_debug_ranges (),
465 m_data_debug_str (),
Greg Clayton17674402011-09-28 17:06:40 +0000466 m_data_apple_names (),
467 m_data_apple_types (),
Greg Clayton7f995132011-10-04 22:41:51 +0000468 m_data_apple_namespaces (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000469 m_abbr(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000470 m_info(),
471 m_line(),
Greg Clayton7f995132011-10-04 22:41:51 +0000472 m_apple_names_ap (),
473 m_apple_types_ap (),
474 m_apple_namespaces_ap (),
Greg Clayton5009f9d2011-10-27 17:55:14 +0000475 m_apple_objc_ap (),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000476 m_function_basename_index(),
477 m_function_fullname_index(),
478 m_function_method_index(),
479 m_function_selector_index(),
Greg Clayton450e3f32010-10-12 02:24:53 +0000480 m_objc_class_selectors_index(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000481 m_global_index(),
Greg Clayton69b04882010-10-15 02:03:22 +0000482 m_type_index(),
483 m_namespace_index(),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000484 m_indexed (false),
485 m_is_external_ast_source (false),
Greg Clayton97fbc342011-10-20 22:30:33 +0000486 m_using_apple_tables (false),
Greg Claytonc7f03b62012-01-12 04:33:28 +0000487 m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +0000488 m_ranges(),
489 m_unique_ast_type_map ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000490{
491}
492
493SymbolFileDWARF::~SymbolFileDWARF()
494{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000495 if (m_is_external_ast_source)
Greg Claytone72dfb32012-02-24 01:59:29 +0000496 {
497 ModuleSP module_sp (m_obj_file->GetModule());
498 if (module_sp)
499 module_sp->GetClangASTContext().RemoveExternalSource ();
500 }
Greg Clayton6beaaa62011-01-17 03:46:26 +0000501}
502
503static const ConstString &
504GetDWARFMachOSegmentName ()
505{
506 static ConstString g_dwarf_section_name ("__DWARF");
507 return g_dwarf_section_name;
508}
509
Greg Claytone576ab22011-02-15 00:19:15 +0000510UniqueDWARFASTTypeMap &
511SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
512{
Greg Clayton1f746072012-08-29 21:13:06 +0000513 if (GetDebugMapSymfile ())
Greg Claytone576ab22011-02-15 00:19:15 +0000514 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
515 return m_unique_ast_type_map;
516}
517
Greg Clayton6beaaa62011-01-17 03:46:26 +0000518ClangASTContext &
519SymbolFileDWARF::GetClangASTContext ()
520{
Greg Clayton1f746072012-08-29 21:13:06 +0000521 if (GetDebugMapSymfile ())
Greg Clayton6beaaa62011-01-17 03:46:26 +0000522 return m_debug_map_symfile->GetClangASTContext ();
523
524 ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext();
525 if (!m_is_external_ast_source)
526 {
527 m_is_external_ast_source = true;
Todd Fiala955fe6f2014-02-27 17:18:23 +0000528 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source_ap (
Greg Clayton6beaaa62011-01-17 03:46:26 +0000529 new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl,
530 SymbolFileDWARF::CompleteObjCInterfaceDecl,
Greg Claytona2721472011-06-25 00:44:06 +0000531 SymbolFileDWARF::FindExternalVisibleDeclsByName,
Greg Claytoncaab74e2012-01-28 00:48:57 +0000532 SymbolFileDWARF::LayoutRecordType,
Greg Clayton6beaaa62011-01-17 03:46:26 +0000533 this));
Greg Clayton6beaaa62011-01-17 03:46:26 +0000534 ast.SetExternalSource (ast_source_ap);
535 }
536 return ast;
537}
538
539void
540SymbolFileDWARF::InitializeObject()
541{
542 // Install our external AST source callbacks so we can complete Clang types.
Greg Claytone72dfb32012-02-24 01:59:29 +0000543 ModuleSP module_sp (m_obj_file->GetModule());
544 if (module_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +0000545 {
Greg Clayton3046e662013-07-10 01:23:25 +0000546 const SectionList *section_list = module_sp->GetSectionList();
Greg Clayton6beaaa62011-01-17 03:46:26 +0000547
548 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
549
550 // Memory map the DWARF mach-o segment so we have everything mmap'ed
551 // to keep our heap memory usage down.
552 if (section)
Greg Claytonc9660542012-02-05 02:38:54 +0000553 m_obj_file->MemoryMapSectionData(section, m_dwarf_data);
Greg Clayton6beaaa62011-01-17 03:46:26 +0000554 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000555 get_apple_names_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000556 if (m_data_apple_names.GetByteSize() > 0)
557 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000558 m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names"));
559 if (m_apple_names_ap->IsValid())
560 m_using_apple_tables = true;
561 else
Greg Clayton7f995132011-10-04 22:41:51 +0000562 m_apple_names_ap.reset();
563 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000564 get_apple_types_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000565 if (m_data_apple_types.GetByteSize() > 0)
566 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000567 m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types"));
568 if (m_apple_types_ap->IsValid())
569 m_using_apple_tables = true;
570 else
Greg Clayton7f995132011-10-04 22:41:51 +0000571 m_apple_types_ap.reset();
572 }
573
574 get_apple_namespaces_data();
575 if (m_data_apple_namespaces.GetByteSize() > 0)
576 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000577 m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces"));
578 if (m_apple_namespaces_ap->IsValid())
579 m_using_apple_tables = true;
580 else
Greg Clayton7f995132011-10-04 22:41:51 +0000581 m_apple_namespaces_ap.reset();
582 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000583
Greg Clayton5009f9d2011-10-27 17:55:14 +0000584 get_apple_objc_data();
585 if (m_data_apple_objc.GetByteSize() > 0)
586 {
587 m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc"));
588 if (m_apple_objc_ap->IsValid())
589 m_using_apple_tables = true;
590 else
591 m_apple_objc_ap.reset();
592 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000593}
594
595bool
596SymbolFileDWARF::SupportedVersion(uint16_t version)
597{
Greg Claytonabcbfe52013-04-04 00:00:36 +0000598 return version == 2 || version == 3 || version == 4;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000599}
600
601uint32_t
Sean Callananbfaf54d2011-12-03 04:38:43 +0000602SymbolFileDWARF::CalculateAbilities ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000603{
604 uint32_t abilities = 0;
605 if (m_obj_file != NULL)
606 {
607 const Section* section = NULL;
608 const SectionList *section_list = m_obj_file->GetSectionList();
609 if (section_list == NULL)
610 return 0;
611
612 uint64_t debug_abbrev_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000613 uint64_t debug_info_file_size = 0;
614 uint64_t debug_line_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000615
Greg Clayton6beaaa62011-01-17 03:46:26 +0000616 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000617
618 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000619 section_list = &section->GetChildren ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000620
Greg Clayton4ceb9982010-07-21 22:54:26 +0000621 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000622 if (section != NULL)
623 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000624 debug_info_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000625
Greg Clayton4ceb9982010-07-21 22:54:26 +0000626 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000627 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000628 debug_abbrev_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000629 else
630 m_flags.Set (flagsGotDebugAbbrevData);
631
Greg Clayton4ceb9982010-07-21 22:54:26 +0000632 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000633 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000634 m_flags.Set (flagsGotDebugArangesData);
635
Greg Clayton4ceb9982010-07-21 22:54:26 +0000636 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000637 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000638 m_flags.Set (flagsGotDebugFrameData);
639
Greg Clayton4ceb9982010-07-21 22:54:26 +0000640 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000641 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000642 debug_line_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000643 else
644 m_flags.Set (flagsGotDebugLineData);
645
Greg Clayton4ceb9982010-07-21 22:54:26 +0000646 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000647 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000648 m_flags.Set (flagsGotDebugLocData);
649
Greg Clayton4ceb9982010-07-21 22:54:26 +0000650 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000651 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000652 m_flags.Set (flagsGotDebugMacInfoData);
653
Greg Clayton4ceb9982010-07-21 22:54:26 +0000654 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000655 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000656 m_flags.Set (flagsGotDebugPubNamesData);
657
Greg Clayton4ceb9982010-07-21 22:54:26 +0000658 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000659 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000660 m_flags.Set (flagsGotDebugPubTypesData);
661
Greg Clayton4ceb9982010-07-21 22:54:26 +0000662 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000663 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000664 m_flags.Set (flagsGotDebugRangesData);
665
Greg Clayton4ceb9982010-07-21 22:54:26 +0000666 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000667 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000668 m_flags.Set (flagsGotDebugStrData);
669 }
Greg Clayton6c596612012-05-18 21:47:20 +0000670 else
671 {
672 const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString();
673 if (symfile_dir_cstr)
674 {
675 if (strcasestr(symfile_dir_cstr, ".dsym"))
676 {
677 if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo)
678 {
679 // We have a dSYM file that didn't have a any debug info.
680 // If the string table has a size of 1, then it was made from
681 // an executable with no debug info, or from an executable that
682 // was stripped.
683 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
684 if (section && section->GetFileSize() == 1)
685 {
686 m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info.");
687 }
688 }
689 }
690 }
691 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000692
693 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
694 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
695
696 if (debug_line_file_size > 0)
697 abilities |= LineTables;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000698 }
699 return abilities;
700}
701
Ed Masteeeae7212013-10-24 20:43:47 +0000702const DWARFDataExtractor&
703SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DWARFDataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000704{
705 if (m_flags.IsClear (got_flag))
706 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000707 ModuleSP module_sp (m_obj_file->GetModule());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000708 m_flags.Set (got_flag);
Greg Clayton3046e662013-07-10 01:23:25 +0000709 const SectionList *section_list = module_sp->GetSectionList();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000710 if (section_list)
711 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000712 SectionSP section_sp (section_list->FindSectionByType(sect_type, true));
713 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000714 {
715 // See if we memory mapped the DWARF segment?
716 if (m_dwarf_data.GetByteSize())
717 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000718 data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000719 }
720 else
721 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000722 if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000723 data.Clear();
724 }
725 }
726 }
727 }
728 return data;
729}
730
Ed Masteeeae7212013-10-24 20:43:47 +0000731const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000732SymbolFileDWARF::get_debug_abbrev_data()
733{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000734 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000735}
736
Ed Masteeeae7212013-10-24 20:43:47 +0000737const DWARFDataExtractor&
Greg Claytond4a2b372011-09-12 23:21:58 +0000738SymbolFileDWARF::get_debug_aranges_data()
739{
740 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
741}
742
Ed Masteeeae7212013-10-24 20:43:47 +0000743const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000744SymbolFileDWARF::get_debug_frame_data()
745{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000746 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000747}
748
Ed Masteeeae7212013-10-24 20:43:47 +0000749const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000750SymbolFileDWARF::get_debug_info_data()
751{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000752 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000753}
754
Ed Masteeeae7212013-10-24 20:43:47 +0000755const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000756SymbolFileDWARF::get_debug_line_data()
757{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000758 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000759}
760
Ed Masteeeae7212013-10-24 20:43:47 +0000761const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000762SymbolFileDWARF::get_debug_loc_data()
763{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000764 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000765}
766
Ed Masteeeae7212013-10-24 20:43:47 +0000767const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000768SymbolFileDWARF::get_debug_ranges_data()
769{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000770 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000771}
772
Ed Masteeeae7212013-10-24 20:43:47 +0000773const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000774SymbolFileDWARF::get_debug_str_data()
775{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000776 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000777}
778
Ed Masteeeae7212013-10-24 20:43:47 +0000779const DWARFDataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000780SymbolFileDWARF::get_apple_names_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000781{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000782 return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names);
Greg Claytonf9eec202011-09-01 23:16:13 +0000783}
784
Ed Masteeeae7212013-10-24 20:43:47 +0000785const DWARFDataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000786SymbolFileDWARF::get_apple_types_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000787{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000788 return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types);
Greg Claytonf9eec202011-09-01 23:16:13 +0000789}
790
Ed Masteeeae7212013-10-24 20:43:47 +0000791const DWARFDataExtractor&
Greg Clayton7f995132011-10-04 22:41:51 +0000792SymbolFileDWARF::get_apple_namespaces_data()
793{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000794 return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
795}
796
Ed Masteeeae7212013-10-24 20:43:47 +0000797const DWARFDataExtractor&
Greg Clayton5009f9d2011-10-27 17:55:14 +0000798SymbolFileDWARF::get_apple_objc_data()
799{
800 return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc);
Greg Clayton7f995132011-10-04 22:41:51 +0000801}
802
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000803
804DWARFDebugAbbrev*
805SymbolFileDWARF::DebugAbbrev()
806{
807 if (m_abbr.get() == NULL)
808 {
Ed Masteeeae7212013-10-24 20:43:47 +0000809 const DWARFDataExtractor &debug_abbrev_data = get_debug_abbrev_data();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000810 if (debug_abbrev_data.GetByteSize() > 0)
811 {
812 m_abbr.reset(new DWARFDebugAbbrev());
813 if (m_abbr.get())
814 m_abbr->Parse(debug_abbrev_data);
815 }
816 }
817 return m_abbr.get();
818}
819
820const DWARFDebugAbbrev*
821SymbolFileDWARF::DebugAbbrev() const
822{
823 return m_abbr.get();
824}
825
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000826
827DWARFDebugInfo*
828SymbolFileDWARF::DebugInfo()
829{
830 if (m_info.get() == NULL)
831 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000832 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p",
833 __PRETTY_FUNCTION__, static_cast<void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000834 if (get_debug_info_data().GetByteSize() > 0)
835 {
836 m_info.reset(new DWARFDebugInfo());
837 if (m_info.get())
838 {
839 m_info->SetDwarfData(this);
840 }
841 }
842 }
843 return m_info.get();
844}
845
846const DWARFDebugInfo*
847SymbolFileDWARF::DebugInfo() const
848{
849 return m_info.get();
850}
851
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000852DWARFCompileUnit*
Greg Clayton1f746072012-08-29 21:13:06 +0000853SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000854{
855 DWARFDebugInfo* info = DebugInfo();
Greg Clayton1f746072012-08-29 21:13:06 +0000856 if (info)
857 {
858 if (GetDebugMapSymfile ())
859 {
860 // The debug map symbol file made the compile units for this DWARF
861 // file which is .o file with DWARF in it, and we should have
862 // only 1 compile unit which is at offset zero in the DWARF.
863 // TODO: modify to support LTO .o files where each .o file might
864 // have multiple DW_TAG_compile_unit tags.
865 return info->GetCompileUnit(0).get();
866 }
867 else
868 {
869 // Just a normal DWARF file whose user ID for the compile unit is
870 // the DWARF offset itself
871 return info->GetCompileUnit((dw_offset_t)comp_unit->GetID()).get();
872 }
873 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000874 return NULL;
875}
876
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000877
878DWARFDebugRanges*
879SymbolFileDWARF::DebugRanges()
880{
881 if (m_ranges.get() == NULL)
882 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000883 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p",
884 __PRETTY_FUNCTION__, static_cast<void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000885 if (get_debug_ranges_data().GetByteSize() > 0)
886 {
887 m_ranges.reset(new DWARFDebugRanges());
888 if (m_ranges.get())
889 m_ranges->Extract(this);
890 }
891 }
892 return m_ranges.get();
893}
894
895const DWARFDebugRanges*
896SymbolFileDWARF::DebugRanges() const
897{
898 return m_ranges.get();
899}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000900
Greg Clayton53eb1c22012-04-02 22:59:12 +0000901lldb::CompUnitSP
902SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000903{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000904 CompUnitSP cu_sp;
905 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000906 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000907 CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData();
908 if (comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000909 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000910 // We already parsed this compile unit, had out a shared pointer to it
911 cu_sp = comp_unit->shared_from_this();
912 }
913 else
914 {
Greg Clayton1f746072012-08-29 21:13:06 +0000915 if (GetDebugMapSymfile ())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000916 {
Greg Clayton1f746072012-08-29 21:13:06 +0000917 // Let the debug map create the compile unit
918 cu_sp = m_debug_map_symfile->GetCompileUnit(this);
919 dwarf_cu->SetUserData(cu_sp.get());
920 }
921 else
922 {
923 ModuleSP module_sp (m_obj_file->GetModule());
924 if (module_sp)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000925 {
Greg Clayton1f746072012-08-29 21:13:06 +0000926 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly ();
927 if (cu_die)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000928 {
Greg Clayton1f746072012-08-29 21:13:06 +0000929 const char * cu_die_name = cu_die->GetName(this, dwarf_cu);
930 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
931 LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
932 if (cu_die_name)
933 {
934 std::string ramapped_file;
935 FileSpec cu_file_spec;
Jim Ingham0909e5f2010-09-16 00:57:33 +0000936
Greg Clayton1f746072012-08-29 21:13:06 +0000937 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0')
Greg Clayton53eb1c22012-04-02 22:59:12 +0000938 {
Greg Clayton1f746072012-08-29 21:13:06 +0000939 // If we have a full path to the compile unit, we don't need to resolve
940 // the file. This can be expensive e.g. when the source files are NFS mounted.
941 if (module_sp->RemapSourceFile(cu_die_name, ramapped_file))
942 cu_file_spec.SetFile (ramapped_file.c_str(), false);
943 else
944 cu_file_spec.SetFile (cu_die_name, false);
Greg Clayton53eb1c22012-04-02 22:59:12 +0000945 }
946 else
947 {
Greg Clayton1f746072012-08-29 21:13:06 +0000948 std::string fullpath(cu_comp_dir);
949 if (*fullpath.rbegin() != '/')
950 fullpath += '/';
951 fullpath += cu_die_name;
952 if (module_sp->RemapSourceFile (fullpath.c_str(), ramapped_file))
953 cu_file_spec.SetFile (ramapped_file.c_str(), false);
954 else
955 cu_file_spec.SetFile (fullpath.c_str(), false);
956 }
957
958 cu_sp.reset(new CompileUnit (module_sp,
959 dwarf_cu,
960 cu_file_spec,
961 MakeUserID(dwarf_cu->GetOffset()),
962 cu_language));
963 if (cu_sp)
964 {
965 dwarf_cu->SetUserData(cu_sp.get());
966
Greg Clayton53eb1c22012-04-02 22:59:12 +0000967 // Figure out the compile unit index if we weren't given one
968 if (cu_idx == UINT32_MAX)
969 DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx);
970
971 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp);
972 }
973 }
974 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000975 }
976 }
977 }
978 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000979 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000980}
981
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000982uint32_t
983SymbolFileDWARF::GetNumCompileUnits()
984{
985 DWARFDebugInfo* info = DebugInfo();
986 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000987 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000988 return 0;
989}
990
991CompUnitSP
992SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
993{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000994 CompUnitSP cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000995 DWARFDebugInfo* info = DebugInfo();
996 if (info)
997 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000998 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
999 if (dwarf_cu)
1000 cu_sp = ParseCompileUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001001 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00001002 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001003}
1004
1005static void
Greg Claytonea3e7d52011-10-08 00:49:15 +00001006AddRangesToBlock (Block& block,
1007 DWARFDebugRanges::RangeList& ranges,
1008 addr_t block_base_addr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001009{
Greg Claytonea3e7d52011-10-08 00:49:15 +00001010 const size_t num_ranges = ranges.GetSize();
1011 for (size_t i = 0; i<num_ranges; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001012 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001013 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i);
1014 const addr_t range_base = range.GetRangeBase();
1015 assert (range_base >= block_base_addr);
1016 block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001017 }
Greg Claytonea3e7d52011-10-08 00:49:15 +00001018 block.FinalizeRanges ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001019}
1020
1021
1022Function *
Greg Clayton0fffff52010-09-24 05:15:53 +00001023SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001024{
1025 DWARFDebugRanges::RangeList func_ranges;
1026 const char *name = NULL;
1027 const char *mangled = NULL;
1028 int decl_file = 0;
1029 int decl_line = 0;
1030 int decl_column = 0;
1031 int call_file = 0;
1032 int call_line = 0;
1033 int call_column = 0;
1034 DWARFExpression frame_base;
1035
Greg Claytonc93237c2010-10-01 20:48:32 +00001036 assert (die->Tag() == DW_TAG_subprogram);
1037
1038 if (die->Tag() != DW_TAG_subprogram)
1039 return NULL;
1040
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001041 if (die->GetDIENamesAndRanges (this,
1042 dwarf_cu,
1043 name,
1044 mangled,
1045 func_ranges,
1046 decl_file,
1047 decl_line,
1048 decl_column,
1049 call_file,
1050 call_line,
1051 call_column,
1052 &frame_base))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001053 {
1054 // Union of all ranges in the function DIE (if the function is discontiguous)
1055 AddressRange func_range;
Greg Claytonea3e7d52011-10-08 00:49:15 +00001056 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0);
1057 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001058 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
1059 {
Michael Sartaina7499c92013-07-01 19:45:50 +00001060 ModuleSP module_sp (m_obj_file->GetModule());
Greg Clayton3046e662013-07-10 01:23:25 +00001061 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, module_sp->GetSectionList());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001062 if (func_range.GetBaseAddress().IsValid())
1063 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
1064 }
1065
1066 if (func_range.GetBaseAddress().IsValid())
1067 {
1068 Mangled func_name;
1069 if (mangled)
Greg Clayton037520e2012-07-18 23:18:10 +00001070 func_name.SetValue(ConstString(mangled), true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001071 else if (name)
Greg Clayton037520e2012-07-18 23:18:10 +00001072 func_name.SetValue(ConstString(name), false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001073
1074 FunctionSP func_sp;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001075 std::unique_ptr<Declaration> decl_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001076 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +00001077 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1078 decl_line,
1079 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001080
Greg Clayton0bd4e1b2011-09-30 20:52:25 +00001081 // Supply the type _only_ if it has already been parsed
Greg Clayton594e5ed2010-09-27 21:07:38 +00001082 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001083
1084 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
1085
Greg Clayton9422dd62013-03-04 21:46:16 +00001086 if (FixupAddress (func_range.GetBaseAddress()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001087 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001088 const user_id_t func_user_id = MakeUserID(die->GetOffset());
1089 func_sp.reset(new Function (sc.comp_unit,
1090 MakeUserID(func_user_id), // UserID is the DIE offset
1091 MakeUserID(func_user_id),
1092 func_name,
1093 func_type,
1094 func_range)); // first address range
1095
1096 if (func_sp.get() != NULL)
1097 {
1098 if (frame_base.IsValid())
1099 func_sp->GetFrameBaseExpression() = frame_base;
1100 sc.comp_unit->AddFunction(func_sp);
1101 return func_sp.get();
1102 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001103 }
1104 }
1105 }
1106 return NULL;
1107}
1108
Greg Clayton9422dd62013-03-04 21:46:16 +00001109bool
1110SymbolFileDWARF::FixupAddress (Address &addr)
1111{
1112 SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile ();
1113 if (debug_map_symfile)
1114 {
1115 return debug_map_symfile->LinkOSOAddress(addr);
1116 }
1117 // This is a normal DWARF file, no address fixups need to happen
1118 return true;
1119}
Greg Clayton1f746072012-08-29 21:13:06 +00001120lldb::LanguageType
1121SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc)
1122{
1123 assert (sc.comp_unit);
1124 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1125 if (dwarf_cu)
1126 {
1127 const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly();
Jim Ingham28eb5712012-10-12 17:34:26 +00001128 if (die)
1129 {
1130 const uint32_t language = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
1131 if (language)
1132 return (lldb::LanguageType)language;
1133 }
Greg Clayton1f746072012-08-29 21:13:06 +00001134 }
1135 return eLanguageTypeUnknown;
1136}
1137
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001138size_t
1139SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
1140{
1141 assert (sc.comp_unit);
1142 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00001143 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001144 if (dwarf_cu)
1145 {
1146 DWARFDIECollection function_dies;
Greg Clayton1f746072012-08-29 21:13:06 +00001147 const size_t num_functions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001148 size_t func_idx;
Greg Clayton1f746072012-08-29 21:13:06 +00001149 for (func_idx = 0; func_idx < num_functions; ++func_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001150 {
1151 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
Greg Clayton81c22f62011-10-19 18:09:39 +00001152 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001153 {
1154 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
1155 ++functions_added;
1156 }
1157 }
1158 //FixupTypes();
1159 }
1160 return functions_added;
1161}
1162
1163bool
1164SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
1165{
1166 assert (sc.comp_unit);
Greg Clayton1f746072012-08-29 21:13:06 +00001167 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Greg Claytonda2455b2012-11-01 17:28:37 +00001168 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001169 {
Greg Claytonda2455b2012-11-01 17:28:37 +00001170 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001171
Greg Claytonda2455b2012-11-01 17:28:37 +00001172 if (cu_die)
1173 {
1174 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
1175 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 +00001176
Greg Claytonda2455b2012-11-01 17:28:37 +00001177 // All file indexes in DWARF are one based and a file of index zero is
1178 // supposed to be the compile unit itself.
1179 support_files.Append (*sc.comp_unit);
1180
1181 return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
1182 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001183 }
1184 return false;
1185}
1186
1187struct ParseDWARFLineTableCallbackInfo
1188{
1189 LineTable* line_table;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001190 std::unique_ptr<LineSequence> sequence_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001191};
1192
1193//----------------------------------------------------------------------
1194// ParseStatementTableCallback
1195//----------------------------------------------------------------------
1196static void
1197ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
1198{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001199 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
1200 {
1201 // Just started parsing the line table
1202 }
1203 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
1204 {
1205 // Done parsing line table, nothing to do for the cleanup
1206 }
1207 else
1208 {
1209 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
Greg Clayton9422dd62013-03-04 21:46:16 +00001210 LineTable* line_table = info->line_table;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001211
Greg Clayton9422dd62013-03-04 21:46:16 +00001212 // If this is our first time here, we need to create a
1213 // sequence container.
1214 if (!info->sequence_ap.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001215 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001216 info->sequence_ap.reset(line_table->CreateLineSequenceContainer());
1217 assert(info->sequence_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001218 }
Greg Clayton9422dd62013-03-04 21:46:16 +00001219 line_table->AppendLineEntryToSequence (info->sequence_ap.get(),
1220 state.address,
1221 state.line,
1222 state.column,
1223 state.file,
1224 state.is_stmt,
1225 state.basic_block,
1226 state.prologue_end,
1227 state.epilogue_begin,
1228 state.end_sequence);
1229 if (state.end_sequence)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001230 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001231 // First, put the current sequence into the line table.
1232 line_table->InsertSequence(info->sequence_ap.get());
1233 // Then, empty it to prepare for the next sequence.
1234 info->sequence_ap->Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001235 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001236 }
1237}
1238
1239bool
1240SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1241{
1242 assert (sc.comp_unit);
1243 if (sc.comp_unit->GetLineTable() != NULL)
1244 return true;
1245
Greg Clayton1f746072012-08-29 21:13:06 +00001246 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001247 if (dwarf_cu)
1248 {
1249 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Greg Clayton129d12c2011-11-28 03:29:03 +00001250 if (dwarf_cu_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001251 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001252 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1253 if (cu_line_offset != DW_INVALID_OFFSET)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001254 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001255 std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
Greg Clayton129d12c2011-11-28 03:29:03 +00001256 if (line_table_ap.get())
1257 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001258 ParseDWARFLineTableCallbackInfo info;
1259 info.line_table = line_table_ap.get();
Greg Claytonc7bece562013-01-25 18:06:21 +00001260 lldb::offset_t offset = cu_line_offset;
Greg Clayton129d12c2011-11-28 03:29:03 +00001261 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
Greg Clayton9422dd62013-03-04 21:46:16 +00001262 if (m_debug_map_symfile)
1263 {
1264 // We have an object file that has a line table with addresses
1265 // that are not linked. We need to link the line table and convert
1266 // the addresses that are relative to the .o file into addresses
1267 // for the main executable.
1268 sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get()));
1269 }
1270 else
1271 {
1272 sc.comp_unit->SetLineTable(line_table_ap.release());
1273 return true;
1274 }
Greg Clayton129d12c2011-11-28 03:29:03 +00001275 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001276 }
1277 }
1278 }
1279 return false;
1280}
1281
1282size_t
1283SymbolFileDWARF::ParseFunctionBlocks
1284(
1285 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001286 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001287 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001288 const DWARFDebugInfoEntry *die,
1289 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001290 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001291)
1292{
1293 size_t blocks_added = 0;
1294 while (die != NULL)
1295 {
1296 dw_tag_t tag = die->Tag();
1297
1298 switch (tag)
1299 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001300 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001301 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001302 case DW_TAG_lexical_block:
1303 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001304 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001305 if (tag == DW_TAG_subprogram)
1306 {
1307 // Skip any DW_TAG_subprogram DIEs that are inside
1308 // of a normal or inlined functions. These will be
1309 // parsed on their own as separate entities.
1310
1311 if (depth > 0)
1312 break;
1313
1314 block = parent_block;
1315 }
1316 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001317 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001318 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001319 parent_block->AddChild(block_sp);
1320 block = block_sp.get();
1321 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001322 DWARFDebugRanges::RangeList ranges;
1323 const char *name = NULL;
1324 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001325
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001326 int decl_file = 0;
1327 int decl_line = 0;
1328 int decl_column = 0;
1329 int call_file = 0;
1330 int call_line = 0;
1331 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001332 if (die->GetDIENamesAndRanges (this,
1333 dwarf_cu,
1334 name,
1335 mangled_name,
1336 ranges,
1337 decl_file, decl_line, decl_column,
1338 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001339 {
1340 if (tag == DW_TAG_subprogram)
1341 {
1342 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001343 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001344 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001345 else if (tag == DW_TAG_inlined_subroutine)
1346 {
1347 // We get called here for inlined subroutines in two ways.
1348 // The first time is when we are making the Function object
1349 // for this inlined concrete instance. Since we're creating a top level block at
1350 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1351 // adjust the containing address.
1352 // The second time is when we are parsing the blocks inside the function that contains
1353 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1354 // function the offset will be for that function.
1355 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1356 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001357 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001358 }
1359 }
1360
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001361 AddRangesToBlock (*block, ranges, subprogram_low_pc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001362
1363 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1364 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001365 std::unique_ptr<Declaration> decl_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001366 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001367 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1368 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001369
Greg Clayton7b0992d2013-04-18 22:45:39 +00001370 std::unique_ptr<Declaration> call_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001371 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001372 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1373 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001374
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001375 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001376 }
1377
1378 ++blocks_added;
1379
Greg Claytondd7feaf2011-08-12 17:54:33 +00001380 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001381 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001382 blocks_added += ParseFunctionBlocks (sc,
1383 block,
1384 dwarf_cu,
1385 die->GetFirstChild(),
1386 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001387 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001388 }
1389 }
1390 }
1391 break;
1392 default:
1393 break;
1394 }
1395
Greg Claytondd7feaf2011-08-12 17:54:33 +00001396 // Only parse siblings of the block if we are not at depth zero. A depth
1397 // of zero indicates we are currently parsing the top level
1398 // DW_TAG_subprogram DIE
1399
1400 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001401 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001402 else
1403 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001404 }
1405 return blocks_added;
1406}
1407
Greg Claytonf0705c82011-10-22 03:33:13 +00001408bool
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001409SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu,
1410 const DWARFDebugInfoEntry *die,
1411 ClangASTContext::TemplateParameterInfos &template_param_infos)
1412{
1413 const dw_tag_t tag = die->Tag();
1414
1415 switch (tag)
1416 {
1417 case DW_TAG_template_type_parameter:
1418 case DW_TAG_template_value_parameter:
1419 {
1420 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
1421
1422 DWARFDebugInfoEntry::Attributes attributes;
1423 const size_t num_attributes = die->GetAttributes (this,
1424 dwarf_cu,
1425 fixed_form_sizes,
1426 attributes);
1427 const char *name = NULL;
1428 Type *lldb_type = NULL;
Greg Clayton57ee3062013-07-11 22:46:58 +00001429 ClangASTType clang_type;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001430 uint64_t uval64 = 0;
1431 bool uval64_valid = false;
1432 if (num_attributes > 0)
1433 {
1434 DWARFFormValue form_value;
1435 for (size_t i=0; i<num_attributes; ++i)
1436 {
1437 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1438
1439 switch (attr)
1440 {
1441 case DW_AT_name:
1442 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1443 name = form_value.AsCString(&get_debug_str_data());
1444 break;
1445
1446 case DW_AT_type:
1447 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1448 {
1449 const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu);
1450 lldb_type = ResolveTypeUID(type_die_offset);
1451 if (lldb_type)
1452 clang_type = lldb_type->GetClangForwardType();
1453 }
1454 break;
1455
1456 case DW_AT_const_value:
1457 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1458 {
1459 uval64_valid = true;
1460 uval64 = form_value.Unsigned();
1461 }
1462 break;
1463 default:
1464 break;
1465 }
1466 }
1467
Greg Clayton283b2652013-04-23 22:38:02 +00001468 clang::ASTContext *ast = GetClangASTContext().getASTContext();
1469 if (!clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00001470 clang_type = GetClangASTContext().GetBasicType(eBasicTypeVoid);
Greg Clayton283b2652013-04-23 22:38:02 +00001471
1472 if (clang_type)
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001473 {
1474 bool is_signed = false;
Greg Clayton283b2652013-04-23 22:38:02 +00001475 if (name && name[0])
1476 template_param_infos.names.push_back(name);
1477 else
1478 template_param_infos.names.push_back(NULL);
1479
Greg Clayton283b2652013-04-23 22:38:02 +00001480 if (tag == DW_TAG_template_value_parameter &&
1481 lldb_type != NULL &&
Greg Clayton57ee3062013-07-11 22:46:58 +00001482 clang_type.IsIntegerType (is_signed) &&
Greg Clayton283b2652013-04-23 22:38:02 +00001483 uval64_valid)
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001484 {
1485 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
Greg Clayton283b2652013-04-23 22:38:02 +00001486 template_param_infos.args.push_back (clang::TemplateArgument (*ast,
Sean Callanan3d654b32012-09-24 22:25:51 +00001487 llvm::APSInt(apint),
Greg Clayton57ee3062013-07-11 22:46:58 +00001488 clang_type.GetQualType()));
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001489 }
1490 else
1491 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001492 template_param_infos.args.push_back (clang::TemplateArgument (clang_type.GetQualType()));
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001493 }
1494 }
1495 else
1496 {
1497 return false;
1498 }
1499
1500 }
1501 }
1502 return true;
1503
1504 default:
1505 break;
1506 }
1507 return false;
1508}
1509
1510bool
Greg Claytonf0705c82011-10-22 03:33:13 +00001511SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1512 const DWARFDebugInfoEntry *parent_die,
1513 ClangASTContext::TemplateParameterInfos &template_param_infos)
1514{
1515
1516 if (parent_die == NULL)
Filipe Cabecinhas52008c62012-05-23 16:24:11 +00001517 return false;
Greg Claytonf0705c82011-10-22 03:33:13 +00001518
Greg Claytonf0705c82011-10-22 03:33:13 +00001519 Args template_parameter_names;
1520 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1521 die != NULL;
1522 die = die->GetSibling())
1523 {
1524 const dw_tag_t tag = die->Tag();
1525
1526 switch (tag)
1527 {
1528 case DW_TAG_template_type_parameter:
1529 case DW_TAG_template_value_parameter:
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001530 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Claytonf0705c82011-10-22 03:33:13 +00001531 break;
1532
1533 default:
1534 break;
1535 }
1536 }
1537 if (template_param_infos.args.empty())
1538 return false;
1539 return template_param_infos.args.size() == template_param_infos.names.size();
1540}
1541
1542clang::ClassTemplateDecl *
1543SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001544 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001545 const char *parent_name,
1546 int tag_decl_kind,
1547 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1548{
1549 if (template_param_infos.IsValid())
1550 {
1551 std::string template_basename(parent_name);
1552 template_basename.erase (template_basename.find('<'));
1553 ClangASTContext &ast = GetClangASTContext();
1554
1555 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001556 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001557 template_basename.c_str(),
1558 tag_decl_kind,
1559 template_param_infos);
1560 }
1561 return NULL;
1562}
1563
Sean Callanana0b80ab2012-06-04 22:28:05 +00001564class SymbolFileDWARF::DelayedAddObjCClassProperty
1565{
1566public:
1567 DelayedAddObjCClassProperty
1568 (
Greg Clayton57ee3062013-07-11 22:46:58 +00001569 const ClangASTType &class_opaque_type,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001570 const char *property_name,
Greg Clayton57ee3062013-07-11 22:46:58 +00001571 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 +00001572 clang::ObjCIvarDecl *ivar_decl,
1573 const char *property_setter_name,
1574 const char *property_getter_name,
1575 uint32_t property_attributes,
Greg Claytonc4ffd662013-03-08 01:37:30 +00001576 const ClangASTMetadata *metadata
Sean Callanana0b80ab2012-06-04 22:28:05 +00001577 ) :
Sean Callanana0b80ab2012-06-04 22:28:05 +00001578 m_class_opaque_type (class_opaque_type),
1579 m_property_name (property_name),
1580 m_property_opaque_type (property_opaque_type),
1581 m_ivar_decl (ivar_decl),
1582 m_property_setter_name (property_setter_name),
1583 m_property_getter_name (property_getter_name),
Jim Ingham379397632012-10-27 02:54:13 +00001584 m_property_attributes (property_attributes)
Sean Callanana0b80ab2012-06-04 22:28:05 +00001585 {
Jim Ingham379397632012-10-27 02:54:13 +00001586 if (metadata != NULL)
1587 {
1588 m_metadata_ap.reset(new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001589 *m_metadata_ap = *metadata;
Jim Ingham379397632012-10-27 02:54:13 +00001590 }
1591 }
1592
1593 DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs)
1594 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001595 *this = rhs;
Daniel Malead4c5be62012-11-12 21:02:14 +00001596 }
1597
1598 DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs)
1599 {
Jim Ingham379397632012-10-27 02:54:13 +00001600 m_class_opaque_type = rhs.m_class_opaque_type;
1601 m_property_name = rhs.m_property_name;
1602 m_property_opaque_type = rhs.m_property_opaque_type;
1603 m_ivar_decl = rhs.m_ivar_decl;
1604 m_property_setter_name = rhs.m_property_setter_name;
1605 m_property_getter_name = rhs.m_property_getter_name;
1606 m_property_attributes = rhs.m_property_attributes;
1607
1608 if (rhs.m_metadata_ap.get())
1609 {
1610 m_metadata_ap.reset (new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001611 *m_metadata_ap = *rhs.m_metadata_ap;
Jim Ingham379397632012-10-27 02:54:13 +00001612 }
Daniel Malead4c5be62012-11-12 21:02:14 +00001613 return *this;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001614 }
1615
Greg Clayton57ee3062013-07-11 22:46:58 +00001616 bool
1617 Finalize()
Sean Callanana0b80ab2012-06-04 22:28:05 +00001618 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001619 return m_class_opaque_type.AddObjCClassProperty (m_property_name,
1620 m_property_opaque_type,
1621 m_ivar_decl,
1622 m_property_setter_name,
1623 m_property_getter_name,
1624 m_property_attributes,
1625 m_metadata_ap.get());
Sean Callanana0b80ab2012-06-04 22:28:05 +00001626 }
1627private:
Greg Clayton57ee3062013-07-11 22:46:58 +00001628 ClangASTType m_class_opaque_type;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001629 const char *m_property_name;
Greg Clayton57ee3062013-07-11 22:46:58 +00001630 ClangASTType m_property_opaque_type;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001631 clang::ObjCIvarDecl *m_ivar_decl;
1632 const char *m_property_setter_name;
1633 const char *m_property_getter_name;
1634 uint32_t m_property_attributes;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001635 std::unique_ptr<ClangASTMetadata> m_metadata_ap;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001636};
1637
Sean Callananfaa0bb32012-12-05 23:37:14 +00001638struct BitfieldInfo
1639{
1640 uint64_t bit_size;
1641 uint64_t bit_offset;
1642
1643 BitfieldInfo () :
1644 bit_size (LLDB_INVALID_ADDRESS),
1645 bit_offset (LLDB_INVALID_ADDRESS)
1646 {
1647 }
1648
Greg Clayton78f4d952013-12-11 23:10:39 +00001649 void
1650 Clear()
1651 {
1652 bit_size = LLDB_INVALID_ADDRESS;
1653 bit_offset = LLDB_INVALID_ADDRESS;
1654 }
1655
Sean Callananfaa0bb32012-12-05 23:37:14 +00001656 bool IsValid ()
1657 {
1658 return (bit_size != LLDB_INVALID_ADDRESS) &&
1659 (bit_offset != LLDB_INVALID_ADDRESS);
1660 }
1661};
1662
Greg Claytonc4ffd662013-03-08 01:37:30 +00001663
1664bool
1665SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu,
1666 const DWARFDebugInfoEntry *parent_die)
1667{
1668 if (parent_die)
1669 {
1670 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1671 {
1672 dw_tag_t tag = die->Tag();
1673 bool check_virtuality = false;
1674 switch (tag)
1675 {
1676 case DW_TAG_inheritance:
1677 case DW_TAG_subprogram:
1678 check_virtuality = true;
1679 break;
1680 default:
1681 break;
1682 }
1683 if (check_virtuality)
1684 {
1685 if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0)
1686 return true;
1687 }
1688 }
1689 }
1690 return false;
1691}
1692
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001693size_t
1694SymbolFileDWARF::ParseChildMembers
1695(
1696 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001697 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001698 const DWARFDebugInfoEntry *parent_die,
Greg Clayton57ee3062013-07-11 22:46:58 +00001699 ClangASTType &class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001700 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001701 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1702 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001703 DWARFDIECollection& member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001704 DelayedPropertyList& delayed_properties,
Sean Callananc7fbf732010-08-06 00:32:49 +00001705 AccessType& default_accessibility,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001706 bool &is_a_class,
1707 LayoutInfo &layout_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001708)
1709{
1710 if (parent_die == NULL)
1711 return 0;
1712
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001713 size_t count = 0;
1714 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001715 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001716 uint32_t member_idx = 0;
Sean Callananfaa0bb32012-12-05 23:37:14 +00001717 BitfieldInfo last_field_info;
Richard Mitton0a558352013-10-17 21:14:00 +00001718 ModuleSP module = GetObjectFile()->GetModule();
Greg Claytond88d7592010-09-15 08:33:30 +00001719
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001720 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1721 {
1722 dw_tag_t tag = die->Tag();
1723
1724 switch (tag)
1725 {
1726 case DW_TAG_member:
Sean Callanan3d654b32012-09-24 22:25:51 +00001727 case DW_TAG_APPLE_property:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001728 {
1729 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001730 const size_t num_attributes = die->GetAttributes (this,
1731 dwarf_cu,
1732 fixed_form_sizes,
1733 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001734 if (num_attributes > 0)
1735 {
1736 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001737 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001738 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001739 const char *prop_name = NULL;
1740 const char *prop_getter_name = NULL;
1741 const char *prop_setter_name = NULL;
Greg Claytone528efd72013-02-26 23:45:18 +00001742 uint32_t prop_attributes = 0;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001743
1744
Greg Clayton24739922010-10-13 03:15:28 +00001745 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001746 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001747 AccessType accessibility = eAccessNone;
Greg Claytoncaab74e2012-01-28 00:48:57 +00001748 uint32_t member_byte_offset = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001749 size_t byte_size = 0;
1750 size_t bit_offset = 0;
1751 size_t bit_size = 0;
Greg Claytone528efd72013-02-26 23:45:18 +00001752 bool is_external = false; // On DW_TAG_members, this means the member is static
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001753 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001754 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001755 {
1756 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1757 DWARFFormValue form_value;
1758 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1759 {
1760 switch (attr)
1761 {
1762 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1763 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1764 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1765 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1766 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1767 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1768 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1769 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1770 case DW_AT_data_member_location:
Greg Claytoncaab74e2012-01-28 00:48:57 +00001771 if (form_value.BlockData())
1772 {
1773 Value initialValue(0);
1774 Value memberOffset(0);
Ed Masteeeae7212013-10-24 20:43:47 +00001775 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Claytoncaab74e2012-01-28 00:48:57 +00001776 uint32_t block_length = form_value.Unsigned();
1777 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1778 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
Greg Claytoncaab74e2012-01-28 00:48:57 +00001779 NULL, // ClangExpressionVariableList *
1780 NULL, // ClangExpressionDeclMap *
1781 NULL, // RegisterContext *
Richard Mitton0a558352013-10-17 21:14:00 +00001782 module,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001783 debug_info_data,
1784 block_offset,
1785 block_length,
1786 eRegisterKindDWARF,
1787 &initialValue,
1788 memberOffset,
1789 NULL))
1790 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001791 member_byte_offset = memberOffset.ResolveValue(NULL).UInt();
Greg Claytoncaab74e2012-01-28 00:48:57 +00001792 }
1793 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00001794 else
1795 {
1796 // With DWARF 3 and later, if the value is an integer constant,
1797 // this form value is the offset in bytes from the beginning
1798 // of the containing entity.
1799 member_byte_offset = form_value.Unsigned();
1800 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001801 break;
1802
Greg Clayton8cf05932010-07-22 18:30:50 +00001803 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00001804 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001805 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1806 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1807 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1808 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00001809 case DW_AT_external: is_external = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001810
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001811 default:
Greg Clayton1b02c172012-03-14 21:00:47 +00001812 case DW_AT_declaration:
1813 case DW_AT_description:
1814 case DW_AT_mutable:
1815 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001816 case DW_AT_sibling:
1817 break;
1818 }
1819 }
1820 }
Sean Callanana6582262012-04-05 00:12:52 +00001821
1822 if (prop_name)
Sean Callanan751aac62012-03-29 19:07:06 +00001823 {
Sean Callanana6582262012-04-05 00:12:52 +00001824 ConstString fixed_getter;
1825 ConstString fixed_setter;
1826
1827 // Check if the property getter/setter were provided as full
1828 // names. We want basenames, so we extract them.
1829
1830 if (prop_getter_name && prop_getter_name[0] == '-')
1831 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001832 ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true);
1833 prop_getter_name = prop_getter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001834 }
1835
1836 if (prop_setter_name && prop_setter_name[0] == '-')
1837 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001838 ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true);
1839 prop_setter_name = prop_setter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001840 }
1841
1842 // If the names haven't been provided, they need to be
1843 // filled in.
1844
1845 if (!prop_getter_name)
1846 {
1847 prop_getter_name = prop_name;
1848 }
1849 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly))
1850 {
1851 StreamString ss;
1852
1853 ss.Printf("set%c%s:",
1854 toupper(prop_name[0]),
1855 &prop_name[1]);
1856
1857 fixed_setter.SetCString(ss.GetData());
1858 prop_setter_name = fixed_setter.GetCString();
1859 }
Sean Callanan751aac62012-03-29 19:07:06 +00001860 }
1861
1862 // Clang has a DWARF generation bug where sometimes it
Greg Clayton44953932011-10-25 01:25:35 +00001863 // represents fields that are references with bad byte size
1864 // and bit size/offset information such as:
1865 //
1866 // DW_AT_byte_size( 0x00 )
1867 // DW_AT_bit_size( 0x40 )
1868 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1869 //
1870 // So check the bit offset to make sure it is sane, and if
1871 // the values are not sane, remove them. If we don't do this
1872 // then we will end up with a crash if we try to use this
1873 // type in an expression when clang becomes unhappy with its
1874 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001875
Greg Clayton44953932011-10-25 01:25:35 +00001876 if (bit_offset > 128)
1877 {
1878 bit_size = 0;
1879 bit_offset = 0;
1880 }
1881
1882 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00001883 if (class_language == eLanguageTypeObjC ||
1884 class_language == eLanguageTypeObjC_plus_plus)
1885 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001886
1887 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1888 {
1889 // Not all compilers will mark the vtable pointer
1890 // member as artificial (llvm-gcc). We can't have
1891 // the virtual members in our classes otherwise it
1892 // throws off all child offsets since we end up
1893 // having and extra pointer sized member in our
1894 // class layouts.
1895 is_artificial = true;
1896 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001897
Greg Clayton29659712013-07-12 20:08:35 +00001898 // Handle static members
Greg Claytone528efd72013-02-26 23:45:18 +00001899 if (is_external && member_byte_offset == UINT32_MAX)
Greg Clayton973b6c92013-04-11 16:57:51 +00001900 {
1901 Type *var_type = ResolveTypeUID(encoding_uid);
1902
1903 if (var_type)
1904 {
Greg Clayton29659712013-07-12 20:08:35 +00001905 if (accessibility == eAccessNone)
1906 accessibility = eAccessPublic;
Greg Clayton57ee3062013-07-11 22:46:58 +00001907 class_clang_type.AddVariableToRecordType (name,
1908 var_type->GetClangLayoutType(),
1909 accessibility);
Greg Clayton973b6c92013-04-11 16:57:51 +00001910 }
Greg Claytone528efd72013-02-26 23:45:18 +00001911 break;
Greg Clayton973b6c92013-04-11 16:57:51 +00001912 }
Greg Claytone528efd72013-02-26 23:45:18 +00001913
Greg Clayton24739922010-10-13 03:15:28 +00001914 if (is_artificial == false)
1915 {
1916 Type *member_type = ResolveTypeUID(encoding_uid);
Sean Callananfa3ab452012-12-14 00:54:13 +00001917
Jim Inghame3ae82a2011-11-12 01:36:43 +00001918 clang::FieldDecl *field_decl = NULL;
Sean Callanan751aac62012-03-29 19:07:06 +00001919 if (tag == DW_TAG_member)
Greg Claytond16e1e52011-07-12 17:06:17 +00001920 {
Sean Callanan751aac62012-03-29 19:07:06 +00001921 if (member_type)
1922 {
1923 if (accessibility == eAccessNone)
1924 accessibility = default_accessibility;
1925 member_accessibilities.push_back(accessibility);
Sean Callananfaa0bb32012-12-05 23:37:14 +00001926
Greg Clayton78f4d952013-12-11 23:10:39 +00001927 uint64_t field_bit_offset = (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
1928 if (bit_size > 0)
Greg Clayton88bc7f32012-11-06 00:20:41 +00001929 {
Greg Clayton78f4d952013-12-11 23:10:39 +00001930
1931 BitfieldInfo this_field_info;
1932 this_field_info.bit_offset = field_bit_offset;
1933 this_field_info.bit_size = bit_size;
1934
Sean Callananfaa0bb32012-12-05 23:37:14 +00001935 /////////////////////////////////////////////////////////////
1936 // How to locate a field given the DWARF debug information
1937 //
1938 // AT_byte_size indicates the size of the word in which the
1939 // bit offset must be interpreted.
1940 //
1941 // AT_data_member_location indicates the byte offset of the
1942 // word from the base address of the structure.
1943 //
1944 // AT_bit_offset indicates how many bits into the word
1945 // (according to the host endianness) the low-order bit of
1946 // the field starts. AT_bit_offset can be negative.
1947 //
1948 // AT_bit_size indicates the size of the field in bits.
1949 /////////////////////////////////////////////////////////////
1950
Greg Clayton78f4d952013-12-11 23:10:39 +00001951 if (byte_size == 0)
1952 byte_size = member_type->GetByteSize();
1953
Sean Callananfaa0bb32012-12-05 23:37:14 +00001954 if (GetObjectFile()->GetByteOrder() == eByteOrderLittle)
1955 {
1956 this_field_info.bit_offset += byte_size * 8;
1957 this_field_info.bit_offset -= (bit_offset + bit_size);
1958 }
1959 else
1960 {
1961 this_field_info.bit_offset += bit_offset;
1962 }
Greg Clayton78f4d952013-12-11 23:10:39 +00001963
1964 // Update the field bit offset we will report for layout
1965 field_bit_offset = this_field_info.bit_offset;
Sean Callananfaa0bb32012-12-05 23:37:14 +00001966
Greg Clayton78f4d952013-12-11 23:10:39 +00001967 // If the member to be emitted did not start on a character boundary and there is
1968 // empty space between the last field and this one, then we need to emit an
1969 // anonymous member filling up the space up to its start. There are three cases
1970 // here:
1971 //
1972 // 1 If the previous member ended on a character boundary, then we can emit an
1973 // anonymous member starting at the most recent character boundary.
1974 //
1975 // 2 If the previous member did not end on a character boundary and the distance
1976 // from the end of the previous member to the current member is less than a
1977 // word width, then we can emit an anonymous member starting right after the
1978 // previous member and right before this member.
1979 //
1980 // 3 If the previous member did not end on a character boundary and the distance
1981 // from the end of the previous member to the current member is greater than
1982 // or equal a word width, then we act as in Case 1.
1983
1984 const uint64_t character_width = 8;
1985 const uint64_t word_width = 32;
1986
Sean Callananfaa0bb32012-12-05 23:37:14 +00001987 // Objective-C has invalid DW_AT_bit_offset values in older versions
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +00001988 // of clang, so we have to be careful and only insert unnamed bitfields
Greg Clayton37c36e42012-11-27 00:59:26 +00001989 // if we have a new enough clang.
1990 bool detect_unnamed_bitfields = true;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001991
Greg Clayton37c36e42012-11-27 00:59:26 +00001992 if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus)
1993 detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields ();
1994
1995 if (detect_unnamed_bitfields)
Greg Clayton88bc7f32012-11-06 00:20:41 +00001996 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001997 BitfieldInfo anon_field_info;
1998
1999 if ((this_field_info.bit_offset % character_width) != 0) // not char aligned
Greg Clayton88bc7f32012-11-06 00:20:41 +00002000 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00002001 uint64_t last_field_end = 0;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002002
Sean Callananfaa0bb32012-12-05 23:37:14 +00002003 if (last_field_info.IsValid())
2004 last_field_end = last_field_info.bit_offset + last_field_info.bit_size;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002005
Sean Callananfaa0bb32012-12-05 23:37:14 +00002006 if (this_field_info.bit_offset != last_field_end)
2007 {
2008 if (((last_field_end % character_width) == 0) || // case 1
2009 (this_field_info.bit_offset - last_field_end >= word_width)) // case 3
2010 {
2011 anon_field_info.bit_size = this_field_info.bit_offset % character_width;
2012 anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size;
2013 }
2014 else // case 2
2015 {
2016 anon_field_info.bit_size = this_field_info.bit_offset - last_field_end;
2017 anon_field_info.bit_offset = last_field_end;
2018 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00002019 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00002020 }
2021
Sean Callananfaa0bb32012-12-05 23:37:14 +00002022 if (anon_field_info.IsValid())
Greg Clayton88bc7f32012-11-06 00:20:41 +00002023 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002024 clang::FieldDecl *unnamed_bitfield_decl = class_clang_type.AddFieldToRecordType (NULL,
2025 GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width),
2026 accessibility,
2027 anon_field_info.bit_size);
Greg Clayton88bc7f32012-11-06 00:20:41 +00002028
Sean Callananfaa0bb32012-12-05 23:37:14 +00002029 layout_info.field_offsets.insert(std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset));
Greg Clayton88bc7f32012-11-06 00:20:41 +00002030 }
2031 }
Greg Clayton78f4d952013-12-11 23:10:39 +00002032 last_field_info = this_field_info;
2033 }
2034 else
2035 {
2036 last_field_info.Clear();
Greg Clayton88bc7f32012-11-06 00:20:41 +00002037 }
Sean Callananfaa0bb32012-12-05 23:37:14 +00002038
Greg Clayton57ee3062013-07-11 22:46:58 +00002039 ClangASTType member_clang_type = member_type->GetClangLayoutType();
Sean Callananfa3ab452012-12-14 00:54:13 +00002040
2041 {
2042 // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>).
2043 // If the current field is at the end of the structure, then there is definitely no room for extra
2044 // elements and we override the type to array[0].
2045
Greg Clayton57ee3062013-07-11 22:46:58 +00002046 ClangASTType member_array_element_type;
Sean Callananfa3ab452012-12-14 00:54:13 +00002047 uint64_t member_array_size;
2048 bool member_array_is_incomplete;
2049
Greg Clayton57ee3062013-07-11 22:46:58 +00002050 if (member_clang_type.IsArrayType(&member_array_element_type,
2051 &member_array_size,
2052 &member_array_is_incomplete) &&
Sean Callananfa3ab452012-12-14 00:54:13 +00002053 !member_array_is_incomplete)
2054 {
2055 uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX);
2056
2057 if (member_byte_offset >= parent_byte_size)
2058 {
2059 if (member_array_size != 1)
2060 {
2061 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,
2062 MakeUserID(die->GetOffset()),
2063 name,
2064 encoding_uid,
2065 MakeUserID(parent_die->GetOffset()));
2066 }
2067
Greg Clayton1c8ef472013-04-05 23:27:21 +00002068 member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0, false);
Sean Callananfa3ab452012-12-14 00:54:13 +00002069 }
2070 }
2071 }
2072
Greg Clayton57ee3062013-07-11 22:46:58 +00002073 field_decl = class_clang_type.AddFieldToRecordType (name,
2074 member_clang_type,
2075 accessibility,
2076 bit_size);
Sean Callanan60217122012-04-13 00:10:03 +00002077
Greg Claytond0029442013-03-27 01:48:02 +00002078 GetClangASTContext().SetMetadataAsUserID (field_decl, MakeUserID(die->GetOffset()));
Sean Callananfaa0bb32012-12-05 23:37:14 +00002079
Greg Clayton78f4d952013-12-11 23:10:39 +00002080 layout_info.field_offsets.insert(std::make_pair(field_decl, field_bit_offset));
2081
Sean Callanan5b26f272012-02-04 08:49:35 +00002082 }
2083 else
2084 {
Sean Callanan751aac62012-03-29 19:07:06 +00002085 if (name)
Daniel Malead01b2952012-11-29 21:49:15 +00002086 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 +00002087 MakeUserID(die->GetOffset()),
2088 name,
2089 encoding_uid);
2090 else
Daniel Malead01b2952012-11-29 21:49:15 +00002091 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 +00002092 MakeUserID(die->GetOffset()),
2093 encoding_uid);
Sean Callanan5b26f272012-02-04 08:49:35 +00002094 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002095 }
Sean Callanan751aac62012-03-29 19:07:06 +00002096
Jim Inghame3ae82a2011-11-12 01:36:43 +00002097 if (prop_name != NULL)
2098 {
Sean Callanan751aac62012-03-29 19:07:06 +00002099 clang::ObjCIvarDecl *ivar_decl = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00002100
Sean Callanan751aac62012-03-29 19:07:06 +00002101 if (field_decl)
2102 {
2103 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
2104 assert (ivar_decl != NULL);
2105 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00002106
Jim Ingham379397632012-10-27 02:54:13 +00002107 ClangASTMetadata metadata;
2108 metadata.SetUserID (MakeUserID(die->GetOffset()));
Greg Clayton57ee3062013-07-11 22:46:58 +00002109 delayed_properties.push_back(DelayedAddObjCClassProperty(class_clang_type,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002110 prop_name,
2111 member_type->GetClangLayoutType(),
2112 ivar_decl,
2113 prop_setter_name,
2114 prop_getter_name,
2115 prop_attributes,
Jim Ingham379397632012-10-27 02:54:13 +00002116 &metadata));
Sean Callanan60217122012-04-13 00:10:03 +00002117
Sean Callananad880762012-04-18 01:06:17 +00002118 if (ivar_decl)
Greg Claytond0029442013-03-27 01:48:02 +00002119 GetClangASTContext().SetMetadataAsUserID (ivar_decl, MakeUserID(die->GetOffset()));
Jim Inghame3ae82a2011-11-12 01:36:43 +00002120 }
Greg Clayton24739922010-10-13 03:15:28 +00002121 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002122 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00002123 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002124 }
2125 break;
2126
2127 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00002128 // Let the type parsing code handle this one for us.
2129 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002130 break;
2131
2132 case DW_TAG_inheritance:
2133 {
2134 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00002135 if (default_accessibility == eAccessNone)
2136 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002137 // TODO: implement DW_TAG_inheritance type parsing
2138 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00002139 const size_t num_attributes = die->GetAttributes (this,
2140 dwarf_cu,
2141 fixed_form_sizes,
2142 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002143 if (num_attributes > 0)
2144 {
2145 Declaration decl;
2146 DWARFExpression location;
2147 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00002148 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002149 bool is_virtual = false;
2150 bool is_base_of_class = true;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002151 off_t member_byte_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002152 uint32_t i;
2153 for (i=0; i<num_attributes; ++i)
2154 {
2155 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2156 DWARFFormValue form_value;
2157 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2158 {
2159 switch (attr)
2160 {
2161 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2162 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2163 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2164 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002165 case DW_AT_data_member_location:
2166 if (form_value.BlockData())
2167 {
2168 Value initialValue(0);
2169 Value memberOffset(0);
Ed Masteeeae7212013-10-24 20:43:47 +00002170 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002171 uint32_t block_length = form_value.Unsigned();
2172 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
2173 if (DWARFExpression::Evaluate (NULL,
2174 NULL,
2175 NULL,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002176 NULL,
Richard Mitton0a558352013-10-17 21:14:00 +00002177 module,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002178 debug_info_data,
2179 block_offset,
2180 block_length,
2181 eRegisterKindDWARF,
2182 &initialValue,
2183 memberOffset,
2184 NULL))
2185 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002186 member_byte_offset = memberOffset.ResolveValue(NULL).UInt();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002187 }
2188 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002189 else
2190 {
2191 // With DWARF 3 and later, if the value is an integer constant,
2192 // this form value is the offset in bytes from the beginning
2193 // of the containing entity.
2194 member_byte_offset = form_value.Unsigned();
2195 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002196 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002197
2198 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00002199 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002200 break;
2201
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002202 case DW_AT_virtuality:
2203 is_virtual = form_value.Boolean();
2204 break;
2205
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002206 case DW_AT_sibling:
2207 break;
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002208
2209 default:
2210 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002211 }
2212 }
2213 }
2214
Greg Clayton526e5af2010-11-13 03:52:47 +00002215 Type *base_class_type = ResolveTypeUID(encoding_uid);
2216 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002217
Greg Clayton57ee3062013-07-11 22:46:58 +00002218 ClangASTType base_class_clang_type = base_class_type->GetClangFullType();
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002219 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002220 if (class_language == eLanguageTypeObjC)
2221 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002222 class_clang_type.SetObjCSuperClass(base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002223 }
2224 else
2225 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002226 base_classes.push_back (base_class_clang_type.CreateBaseClassSpecifier (accessibility,
Greg Claytonba2d22d2010-11-13 22:57:37 +00002227 is_virtual,
2228 is_base_of_class));
Greg Clayton2508b9b2012-11-01 23:20:02 +00002229
2230 if (is_virtual)
2231 {
Greg Clayton52694e32013-09-16 21:57:07 +00002232 // Do not specify any offset for virtual inheritance. The DWARF produced by clang doesn't
2233 // give us a constant offset, but gives us a DWARF expressions that requires an actual object
2234 // in memory. the DW_AT_data_member_location for a virtual base class looks like:
2235 // DW_AT_data_member_location( DW_OP_dup, DW_OP_deref, DW_OP_constu(0x00000018), DW_OP_minus, DW_OP_deref, DW_OP_plus )
2236 // Given this, there is really no valid response we can give to clang for virtual base
2237 // class offsets, and this should eventually be removed from LayoutRecordType() in the external
2238 // AST source in clang.
Greg Clayton2508b9b2012-11-01 23:20:02 +00002239 }
2240 else
2241 {
Greg Clayton57648732013-09-12 17:22:32 +00002242 layout_info.base_offsets.insert(std::make_pair(base_class_clang_type.GetAsCXXRecordDecl(),
Greg Clayton2508b9b2012-11-01 23:20:02 +00002243 clang::CharUnits::fromQuantity(member_byte_offset)));
2244 }
Greg Clayton9e409562010-07-28 02:04:09 +00002245 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002246 }
2247 }
2248 break;
2249
2250 default:
2251 break;
2252 }
2253 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002254
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002255 return count;
2256}
2257
2258
2259clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00002260SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002261{
2262 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00002263 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002264 {
2265 DWARFCompileUnitSP cu_sp;
2266 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
2267 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00002268 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00002269 }
2270 return NULL;
2271}
2272
2273clang::DeclContext*
2274SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
2275{
Greg Clayton81c22f62011-10-19 18:09:39 +00002276 if (UserIDMatches(type_uid))
2277 return GetClangDeclContextForDIEOffset (sc, type_uid);
2278 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002279}
2280
2281Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00002282SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002283{
Greg Clayton81c22f62011-10-19 18:09:39 +00002284 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002285 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002286 DWARFDebugInfo* debug_info = DebugInfo();
2287 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00002288 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002289 DWARFCompileUnitSP cu_sp;
2290 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00002291 const bool assert_not_being_parsed = true;
2292 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00002293 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002294 }
2295 return NULL;
2296}
2297
Greg Claytoncab36a32011-12-08 05:16:30 +00002298Type*
2299SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00002300{
Greg Claytoncab36a32011-12-08 05:16:30 +00002301 if (die != NULL)
2302 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002303 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00002304 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002305 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002306 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
2307 die->GetOffset(),
2308 DW_TAG_value_to_name(die->Tag()),
2309 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00002310
Greg Claytoncab36a32011-12-08 05:16:30 +00002311 // We might be coming in in the middle of a type tree (a class
2312 // withing a class, an enum within a class), so parse any needed
2313 // parent DIEs before we get to this one...
2314 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2315 switch (decl_ctx_die->Tag())
2316 {
2317 case DW_TAG_structure_type:
2318 case DW_TAG_union_type:
2319 case DW_TAG_class_type:
2320 {
2321 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00002322 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002323 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002324 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
2325 die->GetOffset(),
2326 DW_TAG_value_to_name(die->Tag()),
2327 die->GetName(this, cu),
2328 decl_ctx_die->GetOffset());
Greg Clayton219cf312012-03-30 00:51:13 +00002329//
2330// Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
2331// if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
2332// {
2333// if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002334// GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton219cf312012-03-30 00:51:13 +00002335// "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
2336// die->GetOffset(),
2337// DW_TAG_value_to_name(die->Tag()),
2338// die->GetName(this, cu),
2339// decl_ctx_die->GetOffset());
2340// // Ask the type to complete itself if it already hasn't since if we
2341// // want a function (method or static) from a class, the class must
2342// // create itself and add it's own methods and class functions.
2343// if (parent_type)
2344// parent_type->GetClangFullType();
2345// }
Greg Claytoncab36a32011-12-08 05:16:30 +00002346 }
2347 break;
2348
2349 default:
2350 break;
2351 }
2352 return ResolveType (cu, die);
2353 }
2354 return NULL;
2355}
2356
Greg Clayton6beaaa62011-01-17 03:46:26 +00002357// This function is used when SymbolFileDWARFDebugMap owns a bunch of
2358// SymbolFileDWARF objects to detect if this DWARF file is the one that
2359// can resolve a clang_type.
2360bool
Greg Clayton57ee3062013-07-11 22:46:58 +00002361SymbolFileDWARF::HasForwardDeclForClangType (const ClangASTType &clang_type)
Greg Clayton6beaaa62011-01-17 03:46:26 +00002362{
Greg Clayton57ee3062013-07-11 22:46:58 +00002363 ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers();
2364 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton6beaaa62011-01-17 03:46:26 +00002365 return die != NULL;
2366}
2367
2368
Greg Clayton57ee3062013-07-11 22:46:58 +00002369bool
2370SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (ClangASTType &clang_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00002371{
2372 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton57ee3062013-07-11 22:46:58 +00002373 ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers();
2374 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton1be10fc2010-09-29 01:12:09 +00002375 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00002376 {
2377 // We have already resolved this type...
Greg Clayton57ee3062013-07-11 22:46:58 +00002378 return true;
Greg Clayton73b472d2010-10-27 03:32:59 +00002379 }
2380 // Once we start resolving this type, remove it from the forward declaration
2381 // map in case anyone child members or other types require this type to get resolved.
2382 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
2383 // are done.
Greg Clayton57ee3062013-07-11 22:46:58 +00002384 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton1be10fc2010-09-29 01:12:09 +00002385
Greg Clayton85ae2e12011-10-18 23:36:41 +00002386 // Disable external storage for this type so we don't get anymore
2387 // clang::ExternalASTSource queries for this type.
Greg Clayton57ee3062013-07-11 22:46:58 +00002388 clang_type.SetHasExternalStorage (false);
Greg Clayton85ae2e12011-10-18 23:36:41 +00002389
Greg Clayton450e3f32010-10-12 02:24:53 +00002390 DWARFDebugInfo* debug_info = DebugInfo();
2391
Greg Clayton53eb1c22012-04-02 22:59:12 +00002392 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002393 Type *type = m_die_to_type.lookup (die);
2394
2395 const dw_tag_t tag = die->Tag();
2396
Greg Clayton5160ce52013-03-27 23:08:40 +00002397 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
Greg Clayton3bffb082011-12-10 02:15:28 +00002398 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002399 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002400 "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...",
Greg Claytond61c0fc2012-04-23 22:55:20 +00002401 MakeUserID(die->GetOffset()),
2402 DW_TAG_value_to_name(tag),
2403 type->GetName().AsCString());
Greg Clayton1be10fc2010-09-29 01:12:09 +00002404 assert (clang_type);
2405 DWARFDebugInfoEntry::Attributes attributes;
2406
Greg Clayton1be10fc2010-09-29 01:12:09 +00002407 switch (tag)
2408 {
2409 case DW_TAG_structure_type:
2410 case DW_TAG_union_type:
2411 case DW_TAG_class_type:
Greg Claytonc93237c2010-10-01 20:48:32 +00002412 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002413 LayoutInfo layout_info;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002414
Greg Clayton1be10fc2010-09-29 01:12:09 +00002415 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002416 if (die->HasChildren())
Greg Claytonc93237c2010-10-01 20:48:32 +00002417 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002418 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton57ee3062013-07-11 22:46:58 +00002419 if (clang_type.IsObjCObjectOrInterfaceType())
Greg Clayton219cf312012-03-30 00:51:13 +00002420 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002421 class_language = eLanguageTypeObjC;
Greg Clayton219cf312012-03-30 00:51:13 +00002422 // For objective C we don't start the definition when
2423 // the class is created.
Greg Clayton57ee3062013-07-11 22:46:58 +00002424 clang_type.StartTagDeclarationDefinition ();
Greg Clayton219cf312012-03-30 00:51:13 +00002425 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002426
Sean Callanan77a1fd32012-02-27 20:07:01 +00002427 int tag_decl_kind = -1;
2428 AccessType default_accessibility = eAccessNone;
2429 if (tag == DW_TAG_structure_type)
2430 {
2431 tag_decl_kind = clang::TTK_Struct;
2432 default_accessibility = eAccessPublic;
2433 }
2434 else if (tag == DW_TAG_union_type)
2435 {
2436 tag_decl_kind = clang::TTK_Union;
2437 default_accessibility = eAccessPublic;
2438 }
2439 else if (tag == DW_TAG_class_type)
2440 {
2441 tag_decl_kind = clang::TTK_Class;
2442 default_accessibility = eAccessPrivate;
2443 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002444
Greg Clayton53eb1c22012-04-02 22:59:12 +00002445 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002446 std::vector<clang::CXXBaseSpecifier *> base_classes;
2447 std::vector<int> member_accessibilities;
2448 bool is_a_class = false;
2449 // Parse members and base classes first
2450 DWARFDIECollection member_function_dies;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002451
Sean Callanana0b80ab2012-06-04 22:28:05 +00002452 DelayedPropertyList delayed_properties;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002453 ParseChildMembers (sc,
Greg Clayton53eb1c22012-04-02 22:59:12 +00002454 dwarf_cu,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002455 die,
2456 clang_type,
2457 class_language,
2458 base_classes,
2459 member_accessibilities,
2460 member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002461 delayed_properties,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002462 default_accessibility,
2463 is_a_class,
2464 layout_info);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002465
Sean Callanan77a1fd32012-02-27 20:07:01 +00002466 // Now parse any methods if there were any...
2467 size_t num_functions = member_function_dies.Size();
2468 if (num_functions > 0)
2469 {
2470 for (size_t i=0; i<num_functions; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002471 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002472 ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytoncaab74e2012-01-28 00:48:57 +00002473 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002474 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002475
Sean Callanan77a1fd32012-02-27 20:07:01 +00002476 if (class_language == eLanguageTypeObjC)
2477 {
Jim Inghamfb6fc0d2013-09-27 20:59:37 +00002478 ConstString class_name (clang_type.GetTypeName());
2479 if (class_name)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002480 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002481 DIEArray method_die_offsets;
2482 if (m_using_apple_tables)
Greg Clayton95d87902011-11-11 03:16:25 +00002483 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002484 if (m_apple_objc_ap.get())
Jim Inghamfb6fc0d2013-09-27 20:59:37 +00002485 m_apple_objc_ap->FindByName(class_name.GetCString(), method_die_offsets);
Sean Callanan77a1fd32012-02-27 20:07:01 +00002486 }
2487 else
2488 {
2489 if (!m_indexed)
2490 Index ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002491
Sean Callanan77a1fd32012-02-27 20:07:01 +00002492 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
2493 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002494
Sean Callanan77a1fd32012-02-27 20:07:01 +00002495 if (!method_die_offsets.empty())
2496 {
2497 DWARFDebugInfo* debug_info = DebugInfo();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002498
Sean Callanan77a1fd32012-02-27 20:07:01 +00002499 DWARFCompileUnit* method_cu = NULL;
2500 const size_t num_matches = method_die_offsets.size();
2501 for (size_t i=0; i<num_matches; ++i)
Greg Clayton95d87902011-11-11 03:16:25 +00002502 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002503 const dw_offset_t die_offset = method_die_offsets[i];
2504 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002505
Sean Callanan77a1fd32012-02-27 20:07:01 +00002506 if (method_die)
2507 ResolveType (method_cu, method_die);
2508 else
Greg Claytoncaab74e2012-01-28 00:48:57 +00002509 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002510 if (m_using_apple_tables)
2511 {
2512 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 +00002513 die_offset, class_name.GetCString());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002514 }
2515 }
2516 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002517 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002518
Greg Clayton57ee3062013-07-11 22:46:58 +00002519 for (DelayedPropertyList::iterator pi = delayed_properties.begin(), pe = delayed_properties.end();
Sean Callanana0b80ab2012-06-04 22:28:05 +00002520 pi != pe;
2521 ++pi)
2522 pi->Finalize();
Greg Clayton450e3f32010-10-12 02:24:53 +00002523 }
2524 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002525
Sean Callanan77a1fd32012-02-27 20:07:01 +00002526 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2527 // need to tell the clang type it is actually a class.
2528 if (class_language != eLanguageTypeObjC)
2529 {
2530 if (is_a_class && tag_decl_kind != clang::TTK_Class)
Greg Clayton57ee3062013-07-11 22:46:58 +00002531 clang_type.SetTagTypeKind (clang::TTK_Class);
Sean Callanan77a1fd32012-02-27 20:07:01 +00002532 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002533
Sean Callanan77a1fd32012-02-27 20:07:01 +00002534 // Since DW_TAG_structure_type gets used for both classes
2535 // and structures, we may need to set any DW_TAG_member
2536 // fields to have a "private" access if none was specified.
2537 // When we parsed the child members we tracked that actual
2538 // accessibility value for each DW_TAG_member in the
2539 // "member_accessibilities" array. If the value for the
2540 // member is zero, then it was set to the "default_accessibility"
2541 // which for structs was "public". Below we correct this
2542 // by setting any fields to "private" that weren't correctly
2543 // set.
2544 if (is_a_class && !member_accessibilities.empty())
2545 {
2546 // This is a class and all members that didn't have
2547 // their access specified are private.
Greg Clayton57ee3062013-07-11 22:46:58 +00002548 clang_type.SetDefaultAccessForRecordFields (eAccessPrivate,
2549 &member_accessibilities.front(),
2550 member_accessibilities.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002551 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002552
Sean Callanan77a1fd32012-02-27 20:07:01 +00002553 if (!base_classes.empty())
2554 {
Greg Clayton4705f8d2013-12-12 01:54:04 +00002555 // Make sure all base classes refer to complete types and not
2556 // forward declarations. If we don't do this, clang will crash
2557 // with an assertion in the call to clang_type.SetBaseClassesForClassType()
2558 bool base_class_error = false;
2559 for (auto &base_class : base_classes)
2560 {
2561 clang::TypeSourceInfo *type_source_info = base_class->getTypeSourceInfo();
2562 if (type_source_info)
2563 {
2564 ClangASTType base_class_type (GetClangASTContext().getASTContext(), type_source_info->getType());
2565 if (base_class_type.GetCompleteType() == false)
2566 {
2567 if (!base_class_error)
2568 {
2569 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",
2570 die->GetOffset(),
2571 die->GetName(this, dwarf_cu),
2572 base_class_type.GetTypeName().GetCString(),
2573 sc.comp_unit ? sc.comp_unit->GetPath().c_str() : "the source file");
2574 }
2575 // We have no choice other than to pretend that the base class
2576 // is complete. If we don't do this, clang will crash when we
2577 // call setBases() inside of "clang_type.SetBaseClassesForClassType()"
2578 // below. Since we provide layout assistance, all ivars in this
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00002579 // class and other classes will be fine, this is the best we can do
Greg Clayton4705f8d2013-12-12 01:54:04 +00002580 // short of crashing.
2581 base_class_type.StartTagDeclarationDefinition ();
2582 base_class_type.CompleteTagDeclarationDefinition ();
2583 }
2584 }
2585 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002586 clang_type.SetBaseClassesForClassType (&base_classes.front(),
2587 base_classes.size());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002588
Sean Callanan77a1fd32012-02-27 20:07:01 +00002589 // Clang will copy each CXXBaseSpecifier in "base_classes"
2590 // so we have to free them all.
Greg Clayton57ee3062013-07-11 22:46:58 +00002591 ClangASTType::DeleteBaseClassSpecifiers (&base_classes.front(),
2592 base_classes.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002593 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002594 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002595 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002596
Greg Clayton57ee3062013-07-11 22:46:58 +00002597 clang_type.BuildIndirectFields ();
2598 clang_type.CompleteTagDeclarationDefinition ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002599
Greg Clayton2508b9b2012-11-01 23:20:02 +00002600 if (!layout_info.field_offsets.empty() ||
2601 !layout_info.base_offsets.empty() ||
2602 !layout_info.vbase_offsets.empty() )
Greg Claytoncaab74e2012-01-28 00:48:57 +00002603 {
2604 if (type)
2605 layout_info.bit_size = type->GetByteSize() * 8;
2606 if (layout_info.bit_size == 0)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002607 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002608
Greg Clayton57ee3062013-07-11 22:46:58 +00002609 clang::CXXRecordDecl *record_decl = clang_type.GetAsCXXRecordDecl();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002610 if (record_decl)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002611 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002612 if (log)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002613 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002614 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002615 "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 +00002616 static_cast<void*>(clang_type.GetOpaqueQualType()),
2617 static_cast<void*>(record_decl),
Greg Claytoncaab74e2012-01-28 00:48:57 +00002618 layout_info.bit_size,
2619 layout_info.alignment,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002620 static_cast<uint32_t>(layout_info.field_offsets.size()),
2621 static_cast<uint32_t>(layout_info.base_offsets.size()),
2622 static_cast<uint32_t>(layout_info.vbase_offsets.size()));
2623
Greg Clayton2508b9b2012-11-01 23:20:02 +00002624 uint32_t idx;
2625 {
Greg Clayton821ac6d2012-01-28 02:22:27 +00002626 llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002627 for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002628 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002629 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002630 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = { bit_offset=%u, name='%s' }",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002631 static_cast<void*>(clang_type.GetOpaqueQualType()),
Greg Clayton2508b9b2012-11-01 23:20:02 +00002632 idx,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002633 static_cast<uint32_t>(pos->second),
Greg Clayton821ac6d2012-01-28 02:22:27 +00002634 pos->first->getNameAsString().c_str());
2635 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002636 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002637
Greg Clayton2508b9b2012-11-01 23:20:02 +00002638 {
2639 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos, base_end = layout_info.base_offsets.end();
2640 for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; ++base_pos, ++idx)
2641 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002642 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002643 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] = { byte_offset=%u, name='%s' }",
Greg Clayton57ee3062013-07-11 22:46:58 +00002644 clang_type.GetOpaqueQualType(),
Greg Clayton2508b9b2012-11-01 23:20:02 +00002645 idx,
2646 (uint32_t)base_pos->second.getQuantity(),
2647 base_pos->first->getNameAsString().c_str());
2648 }
2649 }
2650 {
2651 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos, vbase_end = layout_info.vbase_offsets.end();
2652 for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; ++vbase_pos, ++idx)
2653 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002654 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002655 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) vbase[%u] = { byte_offset=%u, name='%s' }",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002656 static_cast<void*>(clang_type.GetOpaqueQualType()),
Greg Clayton2508b9b2012-11-01 23:20:02 +00002657 idx,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002658 static_cast<uint32_t>(vbase_pos->second.getQuantity()),
Greg Clayton2508b9b2012-11-01 23:20:02 +00002659 vbase_pos->first->getNameAsString().c_str());
2660 }
2661 }
Greg Clayton821ac6d2012-01-28 02:22:27 +00002662 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002663 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2664 }
2665 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002666 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002667
Sean Callanan9076c0f2013-10-04 21:35:29 +00002668 return (bool)clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002669
2670 case DW_TAG_enumeration_type:
Greg Clayton57ee3062013-07-11 22:46:58 +00002671 clang_type.StartTagDeclarationDefinition ();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002672 if (die->HasChildren())
2673 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002674 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00002675 bool is_signed = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00002676 clang_type.IsIntegerType(is_signed);
Greg Clayton3e067532013-03-05 23:54:39 +00002677 ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002678 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002679 clang_type.CompleteTagDeclarationDefinition ();
Sean Callanan9076c0f2013-10-04 21:35:29 +00002680 return (bool)clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002681
2682 default:
2683 assert(false && "not a forward clang type decl!");
2684 break;
2685 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002686 return false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002687}
2688
Greg Claytonc685f8e2010-09-15 04:15:46 +00002689Type*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002690SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002691{
2692 if (type_die != NULL)
2693 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002694 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00002695
Greg Claytonc685f8e2010-09-15 04:15:46 +00002696 if (type == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002697 type = GetTypeForDIE (dwarf_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00002698
Greg Clayton24739922010-10-13 03:15:28 +00002699 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00002700 {
2701 if (type != DIE_IS_BEING_PARSED)
2702 return type;
2703
2704 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
Greg Clayton53eb1c22012-04-02 22:59:12 +00002705 type_die->GetOffset(),
2706 DW_TAG_value_to_name(type_die->Tag()),
2707 type_die->GetName(this, dwarf_cu));
Jim Inghamc3549282012-01-11 02:21:12 +00002708
2709 }
2710 else
2711 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002712 }
2713 return NULL;
2714}
2715
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002716CompileUnit*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002717SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002718{
2719 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002720 if (dwarf_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002721 {
2722 // The symbol vendor doesn't know about this compile unit, we
2723 // need to parse and add it to the symbol vendor object.
Greg Clayton53eb1c22012-04-02 22:59:12 +00002724 return ParseCompileUnit(dwarf_cu, cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002725 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00002726 return (CompileUnit*)dwarf_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002727}
2728
2729bool
Greg Clayton53eb1c22012-04-02 22:59:12 +00002730SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002731{
Greg Clayton72310352013-02-23 04:12:47 +00002732 sc.Clear(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002733 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002734 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002735
Greg Clayton81c22f62011-10-19 18:09:39 +00002736 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002737 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002738 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002739
2740 if (sc.function)
2741 {
Greg Claytone72dfb32012-02-24 01:59:29 +00002742 sc.module_sp = sc.function->CalculateSymbolContextModule();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002743 return true;
2744 }
2745
2746 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002747}
2748
2749uint32_t
2750SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2751{
2752 Timer scoped_timer(__PRETTY_FUNCTION__,
Daniel Malead01b2952012-11-29 21:49:15 +00002753 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002754 static_cast<void*>(so_addr.GetSection().get()),
2755 so_addr.GetOffset(), resolve_scope);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002756 uint32_t resolved = 0;
2757 if (resolve_scope & ( eSymbolContextCompUnit |
2758 eSymbolContextFunction |
2759 eSymbolContextBlock |
2760 eSymbolContextLineEntry))
2761 {
2762 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2763
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002764 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00002765 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002766 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002767 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002768 if (cu_offset != DW_INVALID_OFFSET)
2769 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002770 uint32_t cu_idx = DW_INVALID_INDEX;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002771 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
2772 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002773 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002774 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002775 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002776 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002777 resolved |= eSymbolContextCompUnit;
2778
Greg Clayton6ab80132012-12-12 17:30:52 +00002779 bool force_check_line_table = false;
Greg Clayton526a4ae2012-05-16 22:09:01 +00002780 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2781 {
2782 DWARFDebugInfoEntry *function_die = NULL;
2783 DWARFDebugInfoEntry *block_die = NULL;
2784 if (resolve_scope & eSymbolContextBlock)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002785 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002786 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
2787 }
2788 else
2789 {
2790 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL);
2791 }
2792
2793 if (function_die != NULL)
2794 {
2795 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2796 if (sc.function == NULL)
2797 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2798 }
2799 else
2800 {
2801 // We might have had a compile unit that had discontiguous
2802 // address ranges where the gaps are symbols that don't have
2803 // any debug info. Discontiguous compile unit address ranges
2804 // should only happen when there aren't other functions from
2805 // other compile units in these gaps. This helps keep the size
2806 // of the aranges down.
Greg Clayton6ab80132012-12-12 17:30:52 +00002807 force_check_line_table = true;
Greg Clayton526a4ae2012-05-16 22:09:01 +00002808 }
2809
2810 if (sc.function != NULL)
2811 {
2812 resolved |= eSymbolContextFunction;
2813
2814 if (resolve_scope & eSymbolContextBlock)
2815 {
2816 Block& block = sc.function->GetBlock (true);
2817
2818 if (block_die != NULL)
2819 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2820 else
2821 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2822 if (sc.block)
2823 resolved |= eSymbolContextBlock;
2824 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002825 }
2826 }
Greg Clayton6ab80132012-12-12 17:30:52 +00002827
2828 if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table)
2829 {
2830 LineTable *line_table = sc.comp_unit->GetLineTable();
2831 if (line_table != NULL)
2832 {
Greg Clayton9422dd62013-03-04 21:46:16 +00002833 // And address that makes it into this function should be in terms
2834 // of this debug file if there is no debug map, or it will be an
2835 // address in the .o file which needs to be fixed up to be in terms
2836 // of the debug map executable. Either way, calling FixupAddress()
2837 // will work for us.
2838 Address exe_so_addr (so_addr);
2839 if (FixupAddress(exe_so_addr))
Greg Clayton6ab80132012-12-12 17:30:52 +00002840 {
Greg Clayton9422dd62013-03-04 21:46:16 +00002841 if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry))
Greg Clayton6ab80132012-12-12 17:30:52 +00002842 {
2843 resolved |= eSymbolContextLineEntry;
2844 }
2845 }
Greg Clayton6ab80132012-12-12 17:30:52 +00002846 }
2847 }
2848
2849 if (force_check_line_table && !(resolved & eSymbolContextLineEntry))
2850 {
2851 // We might have had a compile unit that had discontiguous
2852 // address ranges where the gaps are symbols that don't have
2853 // any debug info. Discontiguous compile unit address ranges
2854 // should only happen when there aren't other functions from
2855 // other compile units in these gaps. This helps keep the size
2856 // of the aranges down.
2857 sc.comp_unit = NULL;
2858 resolved &= ~eSymbolContextCompUnit;
2859 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002860 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002861 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002862 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002863 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.",
2864 cu_offset,
2865 cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002866 }
2867 }
2868 }
2869 }
2870 }
2871 return resolved;
2872}
2873
2874
2875
2876uint32_t
2877SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
2878{
2879 const uint32_t prev_size = sc_list.GetSize();
2880 if (resolve_scope & eSymbolContextCompUnit)
2881 {
2882 DWARFDebugInfo* debug_info = DebugInfo();
2883 if (debug_info)
2884 {
2885 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002886 DWARFCompileUnit* dwarf_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002887
Greg Clayton53eb1c22012-04-02 22:59:12 +00002888 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002889 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002890 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Sean Callananddd7a2a2013-10-03 22:27:29 +00002891 const bool full_match = (bool)file_spec.GetDirectory();
Greg Clayton1f746072012-08-29 21:13:06 +00002892 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 +00002893 if (check_inlines || file_spec_matches_cu_file_spec)
2894 {
2895 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton53eb1c22012-04-02 22:59:12 +00002896 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002897 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002898 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002899 uint32_t file_idx = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002900
Greg Clayton526a4ae2012-05-16 22:09:01 +00002901 // If we are looking for inline functions only and we don't
2902 // find it in the support files, we are done.
2903 if (check_inlines)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002904 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002905 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
2906 if (file_idx == UINT32_MAX)
2907 continue;
2908 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002909
Greg Clayton526a4ae2012-05-16 22:09:01 +00002910 if (line != 0)
2911 {
2912 LineTable *line_table = sc.comp_unit->GetLineTable();
2913
2914 if (line_table != NULL && line != 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002915 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002916 // We will have already looked up the file index if
2917 // we are searching for inline entries.
2918 if (!check_inlines)
2919 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002920
Greg Clayton526a4ae2012-05-16 22:09:01 +00002921 if (file_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002922 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002923 uint32_t found_line;
2924 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
2925 found_line = sc.line_entry.line;
2926
2927 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002928 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002929 sc.function = NULL;
2930 sc.block = NULL;
2931 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002932 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002933 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
2934 if (file_vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002935 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002936 DWARFDebugInfoEntry *function_die = NULL;
2937 DWARFDebugInfoEntry *block_die = NULL;
2938 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002939
Greg Clayton526a4ae2012-05-16 22:09:01 +00002940 if (function_die != NULL)
2941 {
2942 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2943 if (sc.function == NULL)
2944 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2945 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002946
Greg Clayton526a4ae2012-05-16 22:09:01 +00002947 if (sc.function != NULL)
2948 {
2949 Block& block = sc.function->GetBlock (true);
2950
2951 if (block_die != NULL)
2952 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2953 else
2954 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2955 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002956 }
2957 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002958
Greg Clayton526a4ae2012-05-16 22:09:01 +00002959 sc_list.Append(sc);
2960 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2961 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002962 }
2963 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002964 else if (file_spec_matches_cu_file_spec && !check_inlines)
2965 {
2966 // only append the context if we aren't looking for inline call sites
2967 // by file and line and if the file spec matches that of the compile unit
2968 sc_list.Append(sc);
2969 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002970 }
2971 else if (file_spec_matches_cu_file_spec && !check_inlines)
2972 {
2973 // only append the context if we aren't looking for inline call sites
2974 // by file and line and if the file spec matches that of the compile unit
2975 sc_list.Append(sc);
2976 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002977
Greg Clayton526a4ae2012-05-16 22:09:01 +00002978 if (!check_inlines)
2979 break;
2980 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002981 }
2982 }
2983 }
2984 }
2985 return sc_list.GetSize() - prev_size;
2986}
2987
2988void
2989SymbolFileDWARF::Index ()
2990{
2991 if (m_indexed)
2992 return;
2993 m_indexed = true;
2994 Timer scoped_timer (__PRETTY_FUNCTION__,
2995 "SymbolFileDWARF::Index (%s)",
2996 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
2997
2998 DWARFDebugInfo* debug_info = DebugInfo();
2999 if (debug_info)
3000 {
3001 uint32_t cu_idx = 0;
3002 const uint32_t num_compile_units = GetNumCompileUnits();
3003 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
3004 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003005 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003006
Greg Clayton53eb1c22012-04-02 22:59:12 +00003007 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003008
Greg Clayton53eb1c22012-04-02 22:59:12 +00003009 dwarf_cu->Index (cu_idx,
3010 m_function_basename_index,
3011 m_function_fullname_index,
3012 m_function_method_index,
3013 m_function_selector_index,
3014 m_objc_class_selectors_index,
3015 m_global_index,
3016 m_type_index,
3017 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003018
3019 // Keep memory down by clearing DIEs if this generate function
3020 // caused them to be parsed
3021 if (clear_dies)
Greg Clayton53eb1c22012-04-02 22:59:12 +00003022 dwarf_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003023 }
3024
Greg Claytond4a2b372011-09-12 23:21:58 +00003025 m_function_basename_index.Finalize();
3026 m_function_fullname_index.Finalize();
3027 m_function_method_index.Finalize();
3028 m_function_selector_index.Finalize();
3029 m_objc_class_selectors_index.Finalize();
3030 m_global_index.Finalize();
3031 m_type_index.Finalize();
3032 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003033
Greg Clayton24739922010-10-13 03:15:28 +00003034#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00003035 StreamFile s(stdout, false);
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00003036 s.Printf ("DWARF index for '%s':",
3037 GetObjectFile()->GetFileSpec().GetPath().c_str());
Greg Claytonba2d22d2010-11-13 22:57:37 +00003038 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
3039 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
3040 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
3041 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
3042 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
3043 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00003044 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00003045 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00003046#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003047 }
3048}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003049
3050bool
3051SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
3052{
3053 if (namespace_decl == NULL)
3054 {
3055 // Invalid namespace decl which means we aren't matching only things
3056 // in this symbol file, so return true to indicate it matches this
3057 // symbol file.
3058 return true;
3059 }
3060
3061 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
3062
3063 if (namespace_ast == NULL)
3064 return true; // No AST in the "namespace_decl", return true since it
3065 // could then match any symbol file, including this one
3066
3067 if (namespace_ast == GetClangASTContext().getASTContext())
3068 return true; // The ASTs match, return true
3069
3070 // The namespace AST was valid, and it does not match...
Greg Clayton5160ce52013-03-27 23:08:40 +00003071 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Sean Callananc41e68b2011-10-13 21:08:11 +00003072
3073 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003074 GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00003075
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003076 return false;
3077}
3078
Greg Clayton2506a7a2011-10-12 23:34:26 +00003079bool
3080SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
3081 DWARFCompileUnit* cu,
3082 const DWARFDebugInfoEntry* die)
3083{
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +00003084 // No namespace specified, so the answer is
Greg Clayton2506a7a2011-10-12 23:34:26 +00003085 if (namespace_decl == NULL)
3086 return true;
Sean Callananebe60672011-10-13 21:50:33 +00003087
Greg Clayton5160ce52013-03-27 23:08:40 +00003088 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003089
Greg Clayton437a1352012-04-09 22:43:43 +00003090 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
3091 clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00003092 if (decl_ctx_die)
Greg Clayton437a1352012-04-09 22:43:43 +00003093 {
Greg Clayton2506a7a2011-10-12 23:34:26 +00003094 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
Greg Clayton437a1352012-04-09 22:43:43 +00003095
Greg Clayton2506a7a2011-10-12 23:34:26 +00003096 if (clang_namespace_decl)
3097 {
3098 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00003099 {
3100 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003101 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00003102 return false;
Sean Callananebe60672011-10-13 21:50:33 +00003103 }
3104
Greg Clayton437a1352012-04-09 22:43:43 +00003105 if (clang_namespace_decl == die_clang_decl_ctx)
3106 return true;
3107 else
Greg Clayton2506a7a2011-10-12 23:34:26 +00003108 return false;
Greg Clayton2506a7a2011-10-12 23:34:26 +00003109 }
3110 else
3111 {
3112 // We have a namespace_decl that was not NULL but it contained
3113 // a NULL "clang::NamespaceDecl", so this means the global namespace
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00003114 // So as long the contained decl context DIE isn't a namespace
Greg Clayton2506a7a2011-10-12 23:34:26 +00003115 // we should be ok.
3116 if (decl_ctx_die->Tag() != DW_TAG_namespace)
3117 return true;
3118 }
3119 }
Sean Callananebe60672011-10-13 21:50:33 +00003120
3121 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003122 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00003123
Greg Clayton2506a7a2011-10-12 23:34:26 +00003124 return false;
3125}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003126uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00003127SymbolFileDWARF::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 +00003128{
Greg Clayton5160ce52013-03-27 23:08:40 +00003129 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003130
3131 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003132 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003133 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
3134 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003135 static_cast<const void*>(namespace_decl),
3136 append, max_matches);
3137
Sean Callanan213fdb82011-10-13 01:49:10 +00003138 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00003139 return 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003140
Greg Claytonc685f8e2010-09-15 04:15:46 +00003141 DWARFDebugInfo* info = DebugInfo();
3142 if (info == NULL)
3143 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003144
3145 // If we aren't appending the results to this list, then clear the list
3146 if (!append)
3147 variables.Clear();
3148
3149 // Remember how many variables are in the list before we search in case
3150 // we are appending the results to a variable list.
3151 const uint32_t original_size = variables.GetSize();
3152
Greg Claytond4a2b372011-09-12 23:21:58 +00003153 DIEArray die_offsets;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003154
Greg Clayton97fbc342011-10-20 22:30:33 +00003155 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003156 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003157 if (m_apple_names_ap.get())
3158 {
3159 const char *name_cstr = name.GetCString();
3160 const char *base_name_start;
3161 const char *base_name_end = NULL;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003162
Greg Clayton97fbc342011-10-20 22:30:33 +00003163 if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end))
3164 base_name_start = name_cstr;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003165
Greg Clayton97fbc342011-10-20 22:30:33 +00003166 m_apple_names_ap->FindByName (base_name_start, die_offsets);
3167 }
Greg Clayton7f995132011-10-04 22:41:51 +00003168 }
3169 else
3170 {
3171 // Index the DWARF if we haven't already
3172 if (!m_indexed)
3173 Index ();
3174
3175 m_global_index.Find (name, die_offsets);
3176 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003177
Greg Clayton437a1352012-04-09 22:43:43 +00003178 const size_t num_die_matches = die_offsets.size();
3179 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003180 {
Greg Clayton7f995132011-10-04 22:41:51 +00003181 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003182 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00003183 assert (sc.module_sp);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003184
Greg Claytond4a2b372011-09-12 23:21:58 +00003185 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00003186 DWARFCompileUnit* dwarf_cu = NULL;
3187 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton437a1352012-04-09 22:43:43 +00003188 bool done = false;
3189 for (size_t i=0; i<num_die_matches && !done; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00003190 {
3191 const dw_offset_t die_offset = die_offsets[i];
3192 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003193
Greg Clayton95d87902011-11-11 03:16:25 +00003194 if (die)
3195 {
Greg Clayton437a1352012-04-09 22:43:43 +00003196 switch (die->Tag())
3197 {
3198 default:
3199 case DW_TAG_subprogram:
3200 case DW_TAG_inlined_subroutine:
3201 case DW_TAG_try_block:
3202 case DW_TAG_catch_block:
3203 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003204
Greg Clayton437a1352012-04-09 22:43:43 +00003205 case DW_TAG_variable:
3206 {
3207 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003208
Greg Clayton437a1352012-04-09 22:43:43 +00003209 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3210 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003211
Greg Clayton437a1352012-04-09 22:43:43 +00003212 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003213
Greg Clayton437a1352012-04-09 22:43:43 +00003214 if (variables.GetSize() - original_size >= max_matches)
3215 done = true;
3216 }
3217 break;
3218 }
Greg Clayton95d87902011-11-11 03:16:25 +00003219 }
3220 else
3221 {
3222 if (m_using_apple_tables)
3223 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003224 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
3225 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003226 }
3227 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003228 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003229 }
3230
3231 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003232 const uint32_t num_matches = variables.GetSize() - original_size;
3233 if (log && num_matches > 0)
3234 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003235 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003236 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003237 name.GetCString(),
3238 static_cast<const void*>(namespace_decl),
3239 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00003240 num_matches);
3241 }
3242 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003243}
3244
3245uint32_t
3246SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
3247{
Greg Clayton5160ce52013-03-27 23:08:40 +00003248 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003249
Greg Clayton21f2a492011-10-06 00:09:08 +00003250 if (log)
3251 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003252 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003253 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003254 regex.GetText(), append,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003255 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003256 }
3257
Greg Claytonc685f8e2010-09-15 04:15:46 +00003258 DWARFDebugInfo* info = DebugInfo();
3259 if (info == NULL)
3260 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003261
3262 // If we aren't appending the results to this list, then clear the list
3263 if (!append)
3264 variables.Clear();
3265
3266 // Remember how many variables are in the list before we search in case
3267 // we are appending the results to a variable list.
3268 const uint32_t original_size = variables.GetSize();
3269
Greg Clayton7f995132011-10-04 22:41:51 +00003270 DIEArray die_offsets;
3271
Greg Clayton97fbc342011-10-20 22:30:33 +00003272 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003273 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003274 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00003275 {
3276 DWARFMappedHash::DIEInfoArray hash_data_array;
3277 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
3278 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
3279 }
Greg Clayton7f995132011-10-04 22:41:51 +00003280 }
3281 else
3282 {
3283 // Index the DWARF if we haven't already
3284 if (!m_indexed)
3285 Index ();
3286
3287 m_global_index.Find (regex, die_offsets);
3288 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003289
Greg Claytonc685f8e2010-09-15 04:15:46 +00003290 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003291 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003292 assert (sc.module_sp);
3293
Greg Claytond4a2b372011-09-12 23:21:58 +00003294 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00003295 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003296 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003297 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003298 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003299 DWARFDebugInfo* debug_info = DebugInfo();
3300 for (size_t i=0; i<num_matches; ++i)
3301 {
3302 const dw_offset_t die_offset = die_offsets[i];
3303 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00003304
3305 if (die)
3306 {
3307 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003308
Greg Clayton95d87902011-11-11 03:16:25 +00003309 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003310
Greg Clayton95d87902011-11-11 03:16:25 +00003311 if (variables.GetSize() - original_size >= max_matches)
3312 break;
3313 }
3314 else
3315 {
3316 if (m_using_apple_tables)
3317 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003318 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
3319 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00003320 }
3321 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003322 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003323 }
3324
3325 // Return the number of variable that were appended to the list
3326 return variables.GetSize() - original_size;
3327}
3328
Greg Claytonaa044962011-10-13 00:59:38 +00003329
Jim Ingham4cda6e02011-10-07 22:23:45 +00003330bool
3331SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
3332 DWARFCompileUnit *&dwarf_cu,
3333 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00003334{
Greg Claytonaa044962011-10-13 00:59:38 +00003335 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3336 return ResolveFunction (dwarf_cu, die, sc_list);
3337}
3338
3339
3340bool
3341SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
3342 const DWARFDebugInfoEntry *die,
3343 SymbolContextList& sc_list)
3344{
Greg Clayton9e315582011-09-02 04:03:59 +00003345 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00003346
3347 if (die == NULL)
3348 return false;
3349
Jim Ingham4cda6e02011-10-07 22:23:45 +00003350 // If we were passed a die that is not a function, just return false...
3351 if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine)
3352 return false;
3353
3354 const DWARFDebugInfoEntry* inlined_die = NULL;
3355 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00003356 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003357 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00003358
Jim Ingham4cda6e02011-10-07 22:23:45 +00003359 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003360 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003361 if (die->Tag() == DW_TAG_subprogram)
3362 break;
Greg Clayton9e315582011-09-02 04:03:59 +00003363 }
3364 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003365 assert (die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00003366 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003367 {
3368 Address addr;
3369 // Parse all blocks if needed
3370 if (inlined_die)
3371 {
Greg Clayton81c22f62011-10-19 18:09:39 +00003372 sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset()));
Jim Ingham4cda6e02011-10-07 22:23:45 +00003373 assert (sc.block != NULL);
3374 if (sc.block->GetStartAddress (addr) == false)
3375 addr.Clear();
3376 }
3377 else
3378 {
3379 sc.block = NULL;
3380 addr = sc.function->GetAddressRange().GetBaseAddress();
3381 }
3382
3383 if (addr.IsValid())
3384 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003385 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00003386 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003387 }
3388 }
3389
Greg Claytonaa044962011-10-13 00:59:38 +00003390 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00003391}
3392
Greg Clayton7f995132011-10-04 22:41:51 +00003393void
3394SymbolFileDWARF::FindFunctions (const ConstString &name,
3395 const NameToDIE &name_to_die,
3396 SymbolContextList& sc_list)
3397{
Greg Claytond4a2b372011-09-12 23:21:58 +00003398 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003399 if (name_to_die.Find (name, die_offsets))
3400 {
3401 ParseFunctions (die_offsets, sc_list);
3402 }
3403}
3404
3405
3406void
3407SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3408 const NameToDIE &name_to_die,
3409 SymbolContextList& sc_list)
3410{
3411 DIEArray die_offsets;
3412 if (name_to_die.Find (regex, die_offsets))
3413 {
3414 ParseFunctions (die_offsets, sc_list);
3415 }
3416}
3417
3418
3419void
3420SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3421 const DWARFMappedHash::MemoryTable &memory_table,
3422 SymbolContextList& sc_list)
3423{
3424 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00003425 DWARFMappedHash::DIEInfoArray hash_data_array;
3426 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00003427 {
Greg Claytond1767f02011-12-08 02:13:16 +00003428 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Greg Clayton7f995132011-10-04 22:41:51 +00003429 ParseFunctions (die_offsets, sc_list);
3430 }
3431}
3432
3433void
3434SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
3435 SymbolContextList& sc_list)
3436{
3437 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003438 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00003439 {
Greg Clayton7f995132011-10-04 22:41:51 +00003440 SymbolContext sc;
Greg Clayton7f995132011-10-04 22:41:51 +00003441
3442 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003443 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00003444 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003445 const dw_offset_t die_offset = die_offsets[i];
Jim Ingham4cda6e02011-10-07 22:23:45 +00003446 ResolveFunction (die_offset, dwarf_cu, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003447 }
3448 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00003449}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003450
Jim Ingham4cda6e02011-10-07 22:23:45 +00003451bool
3452SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
3453 const DWARFCompileUnit *dwarf_cu,
3454 uint32_t name_type_mask,
3455 const char *partial_name,
3456 const char *base_name_start,
3457 const char *base_name_end)
3458{
Greg Claytonfbea0f62012-11-15 18:05:43 +00003459 // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes:
3460 if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003461 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003462 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
3463 if (!containing_decl_ctx)
3464 return false;
3465
3466 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
3467
Greg Claytonfbea0f62012-11-15 18:05:43 +00003468 if (name_type_mask == eFunctionNameTypeMethod)
3469 {
3470 if (is_cxx_method == false)
3471 return false;
3472 }
3473
3474 if (name_type_mask == eFunctionNameTypeBase)
3475 {
3476 if (is_cxx_method == true)
3477 return false;
3478 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003479 }
3480
3481 // Now we need to check whether the name we got back for this type matches the extra specifications
3482 // that were in the name we're looking up:
3483 if (base_name_start != partial_name || *base_name_end != '\0')
3484 {
3485 // First see if the stuff to the left matches the full name. To do that let's see if
3486 // we can pull out the mips linkage name attribute:
3487
3488 Mangled best_name;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003489 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonfbea0f62012-11-15 18:05:43 +00003490 DWARFFormValue form_value;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003491 die->GetAttributes(this, dwarf_cu, NULL, attributes);
3492 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
Greg Clayton71415542012-12-08 00:24:40 +00003493 if (idx == UINT32_MAX)
3494 idx = attributes.FindAttributeIndex(DW_AT_linkage_name);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003495 if (idx != UINT32_MAX)
3496 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003497 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
3498 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003499 const char *mangled_name = form_value.AsCString(&get_debug_str_data());
3500 if (mangled_name)
3501 best_name.SetValue (ConstString(mangled_name), true);
3502 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003503 }
Greg Claytonfbea0f62012-11-15 18:05:43 +00003504
3505 if (!best_name)
3506 {
3507 idx = attributes.FindAttributeIndex(DW_AT_name);
3508 if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value))
3509 {
3510 const char *name = form_value.AsCString(&get_debug_str_data());
3511 best_name.SetValue (ConstString(name), false);
3512 }
3513 }
3514
3515 if (best_name.GetDemangledName())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003516 {
3517 const char *demangled = best_name.GetDemangledName().GetCString();
3518 if (demangled)
3519 {
3520 std::string name_no_parens(partial_name, base_name_end - partial_name);
Jim Ingham85c13d72012-03-02 02:24:42 +00003521 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str());
3522 if (partial_in_demangled == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003523 return false;
Jim Ingham85c13d72012-03-02 02:24:42 +00003524 else
3525 {
3526 // Sort out the case where our name is something like "Process::Destroy" and the match is
3527 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on
3528 // namespace boundaries...
3529
3530 if (partial_name[0] == ':' && partial_name[1] == ':')
3531 {
3532 // The partial name was already on a namespace boundary so all matches are good.
3533 return true;
3534 }
3535 else if (partial_in_demangled == demangled)
3536 {
3537 // They both start the same, so this is an good match.
3538 return true;
3539 }
3540 else
3541 {
3542 if (partial_in_demangled - demangled == 1)
3543 {
3544 // Only one character difference, can't be a namespace boundary...
3545 return false;
3546 }
3547 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':')
3548 {
3549 // We are on a namespace boundary, so this is also good.
3550 return true;
3551 }
3552 else
3553 return false;
3554 }
3555 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003556 }
3557 }
3558 }
3559
3560 return true;
3561}
Greg Claytonc685f8e2010-09-15 04:15:46 +00003562
Greg Clayton0c5cd902010-06-28 21:30:43 +00003563uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00003564SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00003565 const lldb_private::ClangNamespaceDecl *namespace_decl,
Sean Callanan9df05fb2012-02-10 22:52:19 +00003566 uint32_t name_type_mask,
3567 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00003568 bool append,
3569 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00003570{
3571 Timer scoped_timer (__PRETTY_FUNCTION__,
3572 "SymbolFileDWARF::FindFunctions (name = '%s')",
3573 name.AsCString());
3574
Greg Clayton43fe2172013-04-03 02:00:15 +00003575 // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup()
3576 assert ((name_type_mask & eFunctionNameTypeAuto) == 0);
3577
Greg Clayton5160ce52013-03-27 23:08:40 +00003578 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003579
3580 if (log)
3581 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003582 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003583 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
3584 name.GetCString(),
3585 name_type_mask,
3586 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003587 }
3588
Greg Clayton0c5cd902010-06-28 21:30:43 +00003589 // If we aren't appending the results to this list, then clear the list
3590 if (!append)
3591 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003592
3593 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00003594 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003595
3596 // If name is empty then we won't find anything.
3597 if (name.IsEmpty())
3598 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00003599
3600 // Remember how many sc_list are in the list before we search in case
3601 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00003602
Jim Ingham4cda6e02011-10-07 22:23:45 +00003603 const char *name_cstr = name.GetCString();
Greg Clayton43fe2172013-04-03 02:00:15 +00003604
3605 const uint32_t original_size = sc_list.GetSize();
3606
Jim Ingham4cda6e02011-10-07 22:23:45 +00003607 DWARFDebugInfo* info = DebugInfo();
3608 if (info == NULL)
3609 return 0;
3610
Greg Claytonaa044962011-10-13 00:59:38 +00003611 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton43fe2172013-04-03 02:00:15 +00003612 std::set<const DWARFDebugInfoEntry *> resolved_dies;
Greg Clayton97fbc342011-10-20 22:30:33 +00003613 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00003614 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003615 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003616 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003617
3618 DIEArray die_offsets;
3619
3620 uint32_t num_matches = 0;
3621
Greg Clayton43fe2172013-04-03 02:00:15 +00003622 if (name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00003623 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003624 // If they asked for the full name, match what they typed. At some point we may
3625 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
3626 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00003627 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003628 for (uint32_t i = 0; i < num_matches; i++)
3629 {
Greg Clayton95d87902011-11-11 03:16:25 +00003630 const dw_offset_t die_offset = die_offsets[i];
3631 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00003632 if (die)
3633 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003634 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3635 continue;
3636
Sean Callanan9df05fb2012-02-10 22:52:19 +00003637 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3638 continue;
3639
Greg Clayton43fe2172013-04-03 02:00:15 +00003640 if (resolved_dies.find(die) == resolved_dies.end())
3641 {
3642 if (ResolveFunction (dwarf_cu, die, sc_list))
3643 resolved_dies.insert(die);
3644 }
Greg Claytonaa044962011-10-13 00:59:38 +00003645 }
Greg Clayton95d87902011-11-11 03:16:25 +00003646 else
3647 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003648 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3649 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003650 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003651 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003652 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003653
3654 if (name_type_mask & eFunctionNameTypeSelector)
3655 {
3656 if (namespace_decl && *namespace_decl)
3657 return 0; // no selectors in namespaces
Greg Clayton97fbc342011-10-20 22:30:33 +00003658
Greg Clayton43fe2172013-04-03 02:00:15 +00003659 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3660 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
3661 // and if it is an ObjC method name, we're good.
Greg Clayton97fbc342011-10-20 22:30:33 +00003662
Greg Clayton43fe2172013-04-03 02:00:15 +00003663 for (uint32_t i = 0; i < num_matches; i++)
Greg Clayton97fbc342011-10-20 22:30:33 +00003664 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003665 const dw_offset_t die_offset = die_offsets[i];
3666 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3667 if (die)
Greg Clayton97fbc342011-10-20 22:30:33 +00003668 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003669 const char *die_name = die->GetName(this, dwarf_cu);
3670 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
Greg Clayton97fbc342011-10-20 22:30:33 +00003671 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003672 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3673 continue;
3674
Greg Clayton43fe2172013-04-03 02:00:15 +00003675 if (resolved_dies.find(die) == resolved_dies.end())
3676 {
3677 if (ResolveFunction (dwarf_cu, die, sc_list))
3678 resolved_dies.insert(die);
3679 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003680 }
3681 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003682 else
3683 {
3684 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3685 die_offset, name_cstr);
3686 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003687 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003688 die_offsets.clear();
3689 }
3690
3691 if (((name_type_mask & eFunctionNameTypeMethod) && !namespace_decl) || name_type_mask & eFunctionNameTypeBase)
3692 {
3693 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
3694 // extract the base name, look that up, and if there is any other information in the name we were
3695 // passed in we have to post-filter based on that.
3696
3697 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
3698 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3699
3700 for (uint32_t i = 0; i < num_matches; i++)
3701 {
3702 const dw_offset_t die_offset = die_offsets[i];
3703 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3704 if (die)
3705 {
3706 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3707 continue;
3708
3709 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3710 continue;
3711
3712 // If we get to here, the die is good, and we should add it:
3713 if (resolved_dies.find(die) == resolved_dies.end())
3714 if (ResolveFunction (dwarf_cu, die, sc_list))
3715 {
3716 bool keep_die = true;
3717 if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod))
3718 {
3719 // We are looking for either basenames or methods, so we need to
3720 // trim out the ones we won't want by looking at the type
3721 SymbolContext sc;
3722 if (sc_list.GetLastContext(sc))
3723 {
3724 if (sc.block)
3725 {
3726 // We have an inlined function
3727 }
3728 else if (sc.function)
3729 {
3730 Type *type = sc.function->GetType();
3731
Sean Callananc370a8a2013-09-18 22:59:55 +00003732 if (type)
Greg Clayton43fe2172013-04-03 02:00:15 +00003733 {
Sean Callananc370a8a2013-09-18 22:59:55 +00003734 clang::DeclContext* decl_ctx = GetClangDeclContextContainingTypeUID (type->GetID());
3735 if (decl_ctx->isRecord())
Greg Clayton43fe2172013-04-03 02:00:15 +00003736 {
Sean Callananc370a8a2013-09-18 22:59:55 +00003737 if (name_type_mask & eFunctionNameTypeBase)
3738 {
3739 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3740 keep_die = false;
3741 }
3742 }
3743 else
3744 {
3745 if (name_type_mask & eFunctionNameTypeMethod)
3746 {
3747 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3748 keep_die = false;
3749 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003750 }
3751 }
3752 else
3753 {
Sean Callananc370a8a2013-09-18 22:59:55 +00003754 GetObjectFile()->GetModule()->ReportWarning ("function at die offset 0x%8.8x had no function type",
3755 die_offset);
Greg Clayton43fe2172013-04-03 02:00:15 +00003756 }
3757 }
3758 }
3759 }
3760 if (keep_die)
3761 resolved_dies.insert(die);
3762 }
3763 }
3764 else
3765 {
3766 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3767 die_offset, name_cstr);
3768 }
3769 }
3770 die_offsets.clear();
Jim Ingham4cda6e02011-10-07 22:23:45 +00003771 }
3772 }
Greg Clayton7f995132011-10-04 22:41:51 +00003773 }
3774 else
3775 {
3776
3777 // Index the DWARF if we haven't already
3778 if (!m_indexed)
3779 Index ();
3780
Greg Clayton7f995132011-10-04 22:41:51 +00003781 if (name_type_mask & eFunctionNameTypeFull)
Matt Kopecd6089962013-05-10 17:53:48 +00003782 {
Greg Clayton7f995132011-10-04 22:41:51 +00003783 FindFunctions (name, m_function_fullname_index, sc_list);
3784
Ed Mastefc7baa02013-09-09 18:00:45 +00003785 // FIXME Temporary workaround for global/anonymous namespace
3786 // functions on FreeBSD and Linux
3787#if defined (__FreeBSD__) || defined (__linux__)
Matt Kopecd6089962013-05-10 17:53:48 +00003788 // If we didn't find any functions in the global namespace try
3789 // looking in the basename index but ignore any returned
3790 // functions that have a namespace (ie. mangled names starting with
3791 // '_ZN') but keep functions which have an anonymous namespace
3792 if (sc_list.GetSize() == 0)
3793 {
3794 SymbolContextList temp_sc_list;
3795 FindFunctions (name, m_function_basename_index, temp_sc_list);
3796 if (!namespace_decl)
3797 {
3798 SymbolContext sc;
3799 for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++)
3800 {
3801 if (temp_sc_list.GetContextAtIndex(i, sc))
3802 {
Matt Kopeca189d492013-05-10 22:55:24 +00003803 ConstString mangled_name = sc.GetFunctionName(Mangled::ePreferMangled);
3804 ConstString demangled_name = sc.GetFunctionName(Mangled::ePreferDemangled);
Matt Kopec04e5d582013-05-14 19:00:41 +00003805 if (strncmp(mangled_name.GetCString(), "_ZN", 3) ||
3806 !strncmp(demangled_name.GetCString(), "(anonymous namespace)", 21))
Matt Kopecd6089962013-05-10 17:53:48 +00003807 {
3808 sc_list.Append(sc);
3809 }
3810 }
3811 }
3812 }
3813 }
3814#endif
3815 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003816 DIEArray die_offsets;
3817 DWARFCompileUnit *dwarf_cu = NULL;
3818
Greg Clayton43fe2172013-04-03 02:00:15 +00003819 if (name_type_mask & eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003820 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003821 uint32_t num_base = m_function_basename_index.Find(name, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00003822 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003823 {
Greg Claytonaa044962011-10-13 00:59:38 +00003824 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3825 if (die)
3826 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003827 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3828 continue;
3829
Sean Callanan213fdb82011-10-13 01:49:10 +00003830 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3831 continue;
3832
Greg Claytonaa044962011-10-13 00:59:38 +00003833 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00003834 if (resolved_dies.find(die) == resolved_dies.end())
3835 {
3836 if (ResolveFunction (dwarf_cu, die, sc_list))
3837 resolved_dies.insert(die);
3838 }
Greg Claytonaa044962011-10-13 00:59:38 +00003839 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003840 }
3841 die_offsets.clear();
3842 }
3843
Greg Clayton43fe2172013-04-03 02:00:15 +00003844 if (name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003845 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003846 if (namespace_decl && *namespace_decl)
3847 return 0; // no methods in namespaces
3848
Greg Clayton43fe2172013-04-03 02:00:15 +00003849 uint32_t num_base = m_function_method_index.Find(name, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003850 {
Greg Claytonaa044962011-10-13 00:59:38 +00003851 for (uint32_t i = 0; i < num_base; i++)
3852 {
3853 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3854 if (die)
3855 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003856 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3857 continue;
3858
Greg Claytonaa044962011-10-13 00:59:38 +00003859 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00003860 if (resolved_dies.find(die) == resolved_dies.end())
3861 {
3862 if (ResolveFunction (dwarf_cu, die, sc_list))
3863 resolved_dies.insert(die);
3864 }
Greg Claytonaa044962011-10-13 00:59:38 +00003865 }
3866 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003867 }
3868 die_offsets.clear();
3869 }
Greg Clayton7f995132011-10-04 22:41:51 +00003870
Greg Clayton43fe2172013-04-03 02:00:15 +00003871 if ((name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003872 {
Greg Clayton7f995132011-10-04 22:41:51 +00003873 FindFunctions (name, m_function_selector_index, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003874 }
3875
Greg Clayton4d01ace2011-09-29 16:58:15 +00003876 }
3877
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003878 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003879 const uint32_t num_matches = sc_list.GetSize() - original_size;
3880
3881 if (log && num_matches > 0)
3882 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003883 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003884 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list) => %u",
3885 name.GetCString(),
3886 name_type_mask,
3887 append,
3888 num_matches);
3889 }
3890 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003891}
3892
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003893uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00003894SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003895{
3896 Timer scoped_timer (__PRETTY_FUNCTION__,
3897 "SymbolFileDWARF::FindFunctions (regex = '%s')",
3898 regex.GetText());
3899
Greg Clayton5160ce52013-03-27 23:08:40 +00003900 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003901
3902 if (log)
3903 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003904 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003905 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
3906 regex.GetText(),
3907 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003908 }
3909
3910
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003911 // If we aren't appending the results to this list, then clear the list
3912 if (!append)
3913 sc_list.Clear();
3914
3915 // Remember how many sc_list are in the list before we search in case
3916 // we are appending the results to a variable list.
3917 uint32_t original_size = sc_list.GetSize();
3918
Greg Clayton97fbc342011-10-20 22:30:33 +00003919 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003920 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003921 if (m_apple_names_ap.get())
3922 FindFunctions (regex, *m_apple_names_ap, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003923 }
3924 else
3925 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003926 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00003927 if (!m_indexed)
3928 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003929
Greg Clayton7f995132011-10-04 22:41:51 +00003930 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003931
Greg Clayton7f995132011-10-04 22:41:51 +00003932 FindFunctions (regex, m_function_fullname_index, sc_list);
3933 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003934
3935 // Return the number of variable that were appended to the list
3936 return sc_list.GetSize() - original_size;
3937}
Jim Ingham318c9f22011-08-26 19:44:13 +00003938
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003939uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00003940SymbolFileDWARF::FindTypes (const SymbolContext& sc,
3941 const ConstString &name,
3942 const lldb_private::ClangNamespaceDecl *namespace_decl,
3943 bool append,
3944 uint32_t max_matches,
3945 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003946{
Greg Claytonc685f8e2010-09-15 04:15:46 +00003947 DWARFDebugInfo* info = DebugInfo();
3948 if (info == NULL)
3949 return 0;
3950
Greg Clayton5160ce52013-03-27 23:08:40 +00003951 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003952
Greg Clayton21f2a492011-10-06 00:09:08 +00003953 if (log)
3954 {
Greg Clayton437a1352012-04-09 22:43:43 +00003955 if (namespace_decl)
Greg Clayton5160ce52013-03-27 23:08:40 +00003956 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003957 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)",
3958 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003959 static_cast<void*>(namespace_decl->GetNamespaceDecl()),
Greg Clayton437a1352012-04-09 22:43:43 +00003960 namespace_decl->GetQualifiedName().c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003961 append, max_matches);
Greg Clayton437a1352012-04-09 22:43:43 +00003962 else
Greg Clayton5160ce52013-03-27 23:08:40 +00003963 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003964 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003965 name.GetCString(), append,
Greg Clayton437a1352012-04-09 22:43:43 +00003966 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003967 }
3968
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003969 // If we aren't appending the results to this list, then clear the list
3970 if (!append)
3971 types.Clear();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003972
Sean Callanan213fdb82011-10-13 01:49:10 +00003973 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00003974 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003975
Greg Claytond4a2b372011-09-12 23:21:58 +00003976 DIEArray die_offsets;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003977
Greg Clayton97fbc342011-10-20 22:30:33 +00003978 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003979 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003980 if (m_apple_types_ap.get())
3981 {
3982 const char *name_cstr = name.GetCString();
3983 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3984 }
Greg Clayton7f995132011-10-04 22:41:51 +00003985 }
3986 else
3987 {
3988 if (!m_indexed)
3989 Index ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003990
Greg Clayton7f995132011-10-04 22:41:51 +00003991 m_type_index.Find (name, die_offsets);
3992 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003993
Greg Clayton437a1352012-04-09 22:43:43 +00003994 const size_t num_die_matches = die_offsets.size();
Greg Clayton7f995132011-10-04 22:41:51 +00003995
Greg Clayton437a1352012-04-09 22:43:43 +00003996 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003997 {
Greg Clayton7f995132011-10-04 22:41:51 +00003998 const uint32_t initial_types_size = types.GetSize();
3999 DWARFCompileUnit* dwarf_cu = NULL;
4000 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00004001 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00004002 for (size_t i=0; i<num_die_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004003 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004004 const dw_offset_t die_offset = die_offsets[i];
4005 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
4006
Greg Clayton95d87902011-11-11 03:16:25 +00004007 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00004008 {
Greg Clayton95d87902011-11-11 03:16:25 +00004009 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
4010 continue;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004011
Greg Clayton95d87902011-11-11 03:16:25 +00004012 Type *matching_type = ResolveType (dwarf_cu, die);
4013 if (matching_type)
4014 {
4015 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00004016 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00004017 if (types.GetSize() >= max_matches)
4018 break;
4019 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00004020 }
Greg Clayton95d87902011-11-11 03:16:25 +00004021 else
4022 {
4023 if (m_using_apple_tables)
4024 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004025 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4026 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004027 }
4028 }
4029
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004030 }
Greg Clayton437a1352012-04-09 22:43:43 +00004031 const uint32_t num_matches = types.GetSize() - initial_types_size;
4032 if (log && num_matches)
4033 {
4034 if (namespace_decl)
4035 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004036 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004037 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u",
4038 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004039 static_cast<void*>(namespace_decl->GetNamespaceDecl()),
Greg Clayton437a1352012-04-09 22:43:43 +00004040 namespace_decl->GetQualifiedName().c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004041 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00004042 num_matches);
4043 }
4044 else
4045 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004046 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004047 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u",
4048 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004049 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00004050 num_matches);
4051 }
4052 }
4053 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004054 }
Greg Clayton7f995132011-10-04 22:41:51 +00004055 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004056}
4057
4058
Greg Clayton526e5af2010-11-13 03:52:47 +00004059ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00004060SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00004061 const ConstString &name,
4062 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004063{
Greg Clayton5160ce52013-03-27 23:08:40 +00004064 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00004065
4066 if (log)
4067 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004068 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00004069 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
4070 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00004071 }
Sean Callanan213fdb82011-10-13 01:49:10 +00004072
4073 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00004074 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00004075
Greg Clayton526e5af2010-11-13 03:52:47 +00004076 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004077 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00004078 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00004079 {
Greg Clayton7f995132011-10-04 22:41:51 +00004080 DIEArray die_offsets;
4081
Greg Clayton526e5af2010-11-13 03:52:47 +00004082 // Index if we already haven't to make sure the compile units
4083 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00004084 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004085 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004086 if (m_apple_namespaces_ap.get())
4087 {
4088 const char *name_cstr = name.GetCString();
4089 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
4090 }
Greg Clayton7f995132011-10-04 22:41:51 +00004091 }
4092 else
4093 {
4094 if (!m_indexed)
4095 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00004096
Greg Clayton7f995132011-10-04 22:41:51 +00004097 m_namespace_index.Find (name, die_offsets);
4098 }
Greg Claytond4a2b372011-09-12 23:21:58 +00004099
4100 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00004101 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00004102 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00004103 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00004104 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004105 DWARFDebugInfo* debug_info = DebugInfo();
4106 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00004107 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004108 const dw_offset_t die_offset = die_offsets[i];
4109 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00004110
Greg Clayton95d87902011-11-11 03:16:25 +00004111 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00004112 {
Greg Clayton95d87902011-11-11 03:16:25 +00004113 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
4114 continue;
4115
4116 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
4117 if (clang_namespace_decl)
4118 {
4119 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
4120 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
Greg Claytond1767f02011-12-08 02:13:16 +00004121 break;
Greg Clayton95d87902011-11-11 03:16:25 +00004122 }
Greg Claytond4a2b372011-09-12 23:21:58 +00004123 }
Greg Clayton95d87902011-11-11 03:16:25 +00004124 else
4125 {
4126 if (m_using_apple_tables)
4127 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004128 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
4129 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004130 }
4131 }
4132
Greg Clayton526e5af2010-11-13 03:52:47 +00004133 }
4134 }
Greg Clayton96d7d742010-11-10 23:42:09 +00004135 }
Greg Clayton437a1352012-04-09 22:43:43 +00004136 if (log && namespace_decl.GetNamespaceDecl())
4137 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004138 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004139 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"",
4140 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004141 static_cast<const void*>(namespace_decl.GetNamespaceDecl()),
Greg Clayton437a1352012-04-09 22:43:43 +00004142 namespace_decl.GetQualifiedName().c_str());
4143 }
4144
Greg Clayton526e5af2010-11-13 03:52:47 +00004145 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004146}
4147
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004148uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004149SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004150{
4151 // Remember how many sc_list are in the list before we search in case
4152 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004153 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004154
4155 const uint32_t num_die_offsets = die_offsets.size();
4156 // Parse all of the types we found from the pubtypes matches
4157 uint32_t i;
4158 uint32_t num_matches = 0;
4159 for (i = 0; i < num_die_offsets; ++i)
4160 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004161 Type *matching_type = ResolveTypeUID (die_offsets[i]);
4162 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004163 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004164 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00004165 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004166 ++num_matches;
4167 if (num_matches >= max_matches)
4168 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004169 }
4170 }
4171
4172 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004173 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004174}
4175
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004176
4177size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00004178SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
4179 clang::DeclContext *containing_decl_ctx,
Greg Clayton5113dc82011-08-12 06:47:54 +00004180 DWARFCompileUnit* dwarf_cu,
4181 const DWARFDebugInfoEntry *parent_die,
4182 bool skip_artificial,
4183 bool &is_static,
Greg Clayton03969752014-02-24 18:53:11 +00004184 bool &is_variadic,
Greg Clayton5113dc82011-08-12 06:47:54 +00004185 TypeList* type_list,
Greg Clayton57ee3062013-07-11 22:46:58 +00004186 std::vector<ClangASTType>& function_param_types,
Greg Clayton5113dc82011-08-12 06:47:54 +00004187 std::vector<clang::ParmVarDecl*>& function_param_decls,
Greg Claytond20deac2014-04-04 18:15:18 +00004188 unsigned &type_quals) // ,
4189 // ClangASTContext::TemplateParameterInfos &template_param_infos))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004190{
4191 if (parent_die == NULL)
4192 return 0;
4193
Greg Claytond88d7592010-09-15 08:33:30 +00004194 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
4195
Greg Clayton7fedea22010-11-16 02:10:54 +00004196 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004197 const DWARFDebugInfoEntry *die;
4198 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4199 {
4200 dw_tag_t tag = die->Tag();
4201 switch (tag)
4202 {
4203 case DW_TAG_formal_parameter:
4204 {
4205 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004206 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004207 if (num_attributes > 0)
4208 {
4209 const char *name = NULL;
4210 Declaration decl;
4211 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00004212 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004213 // one of None, Auto, Register, Extern, Static, PrivateExtern
4214
Sean Callanane2ef6e32010-09-23 03:01:22 +00004215 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004216 uint32_t i;
4217 for (i=0; i<num_attributes; ++i)
4218 {
4219 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4220 DWARFFormValue form_value;
4221 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4222 {
4223 switch (attr)
4224 {
4225 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4226 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4227 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4228 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
4229 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00004230 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004231 case DW_AT_location:
4232 // if (form_value.BlockData())
4233 // {
Ed Masteeeae7212013-10-24 20:43:47 +00004234 // const DWARFDataExtractor& debug_info_data = debug_info();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004235 // uint32_t block_length = form_value.Unsigned();
Ed Masteeeae7212013-10-24 20:43:47 +00004236 // DWARFDataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004237 // }
4238 // else
4239 // {
4240 // }
4241 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004242 case DW_AT_const_value:
4243 case DW_AT_default_value:
4244 case DW_AT_description:
4245 case DW_AT_endianity:
4246 case DW_AT_is_optional:
4247 case DW_AT_segment:
4248 case DW_AT_variable_parameter:
4249 default:
4250 case DW_AT_abstract_origin:
4251 case DW_AT_sibling:
4252 break;
4253 }
4254 }
4255 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00004256
Greg Clayton0fffff52010-09-24 05:15:53 +00004257 bool skip = false;
4258 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004259 {
Greg Clayton0fffff52010-09-24 05:15:53 +00004260 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00004261 {
4262 // In order to determine if a C++ member function is
4263 // "const" we have to look at the const-ness of "this"...
4264 // Ugly, but that
4265 if (arg_idx == 0)
4266 {
Greg Claytonf0705c82011-10-22 03:33:13 +00004267 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00004268 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004269 // Often times compilers omit the "this" name for the
4270 // specification DIEs, so we can't rely upon the name
4271 // being in the formal parameter DIE...
4272 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00004273 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004274 Type *this_type = ResolveTypeUID (param_type_die_offset);
4275 if (this_type)
4276 {
4277 uint32_t encoding_mask = this_type->GetEncodingMask();
4278 if (encoding_mask & Type::eEncodingIsPointerUID)
4279 {
4280 is_static = false;
4281
4282 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
4283 type_quals |= clang::Qualifiers::Const;
4284 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
4285 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00004286 }
4287 }
4288 }
4289 }
4290 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004291 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00004292 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004293 else
4294 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004295
Greg Clayton0fffff52010-09-24 05:15:53 +00004296 // HACK: Objective C formal parameters "self" and "_cmd"
4297 // are not marked as artificial in the DWARF...
Greg Clayton53eb1c22012-04-02 22:59:12 +00004298 CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
4299 if (comp_unit)
Greg Clayton0fffff52010-09-24 05:15:53 +00004300 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004301 switch (comp_unit->GetLanguage())
4302 {
4303 case eLanguageTypeObjC:
4304 case eLanguageTypeObjC_plus_plus:
4305 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
4306 skip = true;
4307 break;
4308 default:
4309 break;
4310 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004311 }
4312 }
4313 }
4314
4315 if (!skip)
4316 {
4317 Type *type = ResolveTypeUID(param_type_die_offset);
4318 if (type)
4319 {
Greg Claytonc93237c2010-10-01 20:48:32 +00004320 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00004321
Greg Clayton42ce2f32011-12-12 21:50:19 +00004322 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
4323 type->GetClangForwardType(),
4324 storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00004325 assert(param_var_decl);
4326 function_param_decls.push_back(param_var_decl);
Sean Callanan60217122012-04-13 00:10:03 +00004327
Greg Claytond0029442013-03-27 01:48:02 +00004328 GetClangASTContext().SetMetadataAsUserID (param_var_decl, MakeUserID(die->GetOffset()));
Greg Clayton0fffff52010-09-24 05:15:53 +00004329 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004330 }
4331 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004332 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004333 }
4334 break;
4335
Greg Clayton03969752014-02-24 18:53:11 +00004336 case DW_TAG_unspecified_parameters:
4337 is_variadic = true;
4338 break;
4339
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004340 case DW_TAG_template_type_parameter:
4341 case DW_TAG_template_value_parameter:
Greg Claytond20deac2014-04-04 18:15:18 +00004342 // The one caller of this was never using the template_param_infos,
4343 // and the local variable was taking up a large amount of stack space
4344 // in SymbolFileDWARF::ParseType() so this was removed. If we ever need
4345 // the template params back, we can add them back.
4346 // ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004347 break;
4348
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004349 default:
4350 break;
4351 }
4352 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004353 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004354}
4355
4356size_t
4357SymbolFileDWARF::ParseChildEnumerators
4358(
4359 const SymbolContext& sc,
Greg Clayton57ee3062013-07-11 22:46:58 +00004360 lldb_private::ClangASTType &clang_type,
Greg Clayton3e067532013-03-05 23:54:39 +00004361 bool is_signed,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004362 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00004363 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004364 const DWARFDebugInfoEntry *parent_die
4365)
4366{
4367 if (parent_die == NULL)
4368 return 0;
4369
4370 size_t enumerators_added = 0;
4371 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00004372 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
4373
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004374 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4375 {
4376 const dw_tag_t tag = die->Tag();
4377 if (tag == DW_TAG_enumerator)
4378 {
4379 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004380 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004381 if (num_child_attributes > 0)
4382 {
4383 const char *name = NULL;
4384 bool got_value = false;
4385 int64_t enum_value = 0;
4386 Declaration decl;
4387
4388 uint32_t i;
4389 for (i=0; i<num_child_attributes; ++i)
4390 {
4391 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4392 DWARFFormValue form_value;
4393 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4394 {
4395 switch (attr)
4396 {
4397 case DW_AT_const_value:
4398 got_value = true;
Greg Clayton3e067532013-03-05 23:54:39 +00004399 if (is_signed)
4400 enum_value = form_value.Signed();
4401 else
4402 enum_value = form_value.Unsigned();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004403 break;
4404
4405 case DW_AT_name:
4406 name = form_value.AsCString(&get_debug_str_data());
4407 break;
4408
4409 case DW_AT_description:
4410 default:
4411 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4412 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4413 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4414 case DW_AT_sibling:
4415 break;
4416 }
4417 }
4418 }
4419
4420 if (name && name[0] && got_value)
4421 {
Greg Clayton57ee3062013-07-11 22:46:58 +00004422 clang_type.AddEnumerationValueToEnumerationType (clang_type.GetEnumerationIntegerType(),
4423 decl,
4424 name,
4425 enum_value,
4426 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004427 ++enumerators_added;
4428 }
4429 }
4430 }
4431 }
4432 return enumerators_added;
4433}
4434
4435void
4436SymbolFileDWARF::ParseChildArrayInfo
4437(
4438 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004439 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004440 const DWARFDebugInfoEntry *parent_die,
4441 int64_t& first_index,
4442 std::vector<uint64_t>& element_orders,
4443 uint32_t& byte_stride,
4444 uint32_t& bit_stride
4445)
4446{
4447 if (parent_die == NULL)
4448 return;
4449
4450 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00004451 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004452 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4453 {
4454 const dw_tag_t tag = die->Tag();
4455 switch (tag)
4456 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004457 case DW_TAG_subrange_type:
4458 {
4459 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004460 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004461 if (num_child_attributes > 0)
4462 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004463 uint64_t num_elements = 0;
4464 uint64_t lower_bound = 0;
4465 uint64_t upper_bound = 0;
Greg Clayton4ef877f2012-12-06 02:33:54 +00004466 bool upper_bound_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004467 uint32_t i;
4468 for (i=0; i<num_child_attributes; ++i)
4469 {
4470 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4471 DWARFFormValue form_value;
4472 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4473 {
4474 switch (attr)
4475 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004476 case DW_AT_name:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004477 break;
4478
4479 case DW_AT_count:
4480 num_elements = form_value.Unsigned();
4481 break;
4482
4483 case DW_AT_bit_stride:
4484 bit_stride = form_value.Unsigned();
4485 break;
4486
4487 case DW_AT_byte_stride:
4488 byte_stride = form_value.Unsigned();
4489 break;
4490
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004491 case DW_AT_lower_bound:
4492 lower_bound = form_value.Unsigned();
4493 break;
4494
4495 case DW_AT_upper_bound:
Greg Clayton4ef877f2012-12-06 02:33:54 +00004496 upper_bound_valid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004497 upper_bound = form_value.Unsigned();
4498 break;
4499
4500 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004501 case DW_AT_abstract_origin:
4502 case DW_AT_accessibility:
4503 case DW_AT_allocated:
4504 case DW_AT_associated:
4505 case DW_AT_data_location:
4506 case DW_AT_declaration:
4507 case DW_AT_description:
4508 case DW_AT_sibling:
4509 case DW_AT_threads_scaled:
4510 case DW_AT_type:
4511 case DW_AT_visibility:
4512 break;
4513 }
4514 }
4515 }
4516
Greg Claytone6a07792012-12-05 21:59:39 +00004517 if (num_elements == 0)
4518 {
Greg Clayton4ef877f2012-12-06 02:33:54 +00004519 if (upper_bound_valid && upper_bound >= lower_bound)
Greg Claytone6a07792012-12-05 21:59:39 +00004520 num_elements = upper_bound - lower_bound + 1;
4521 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004522
Sean Callananec979ba2012-10-22 23:56:48 +00004523 element_orders.push_back (num_elements);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004524 }
4525 }
4526 break;
4527 }
4528 }
4529}
4530
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004531TypeSP
Greg Clayton53eb1c22012-04-02 22:59:12 +00004532SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004533{
4534 TypeSP type_sp;
4535 if (die != NULL)
4536 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004537 assert(dwarf_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00004538 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004539 if (type_ptr == NULL)
4540 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004541 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu);
Greg Claytonca512b32011-01-14 04:54:56 +00004542 assert (lldb_cu);
4543 SymbolContext sc(lldb_cu);
Greg Clayton53eb1c22012-04-02 22:59:12 +00004544 type_sp = ParseType(sc, dwarf_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004545 }
4546 else if (type_ptr != DIE_IS_BEING_PARSED)
4547 {
4548 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00004549 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004550 }
4551
4552 }
4553 return type_sp;
4554}
4555
4556clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00004557SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004558{
4559 if (die_offset != DW_INVALID_OFFSET)
4560 {
4561 DWARFCompileUnitSP cu_sp;
4562 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004563 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004564 }
4565 return NULL;
4566}
4567
Sean Callanan72e49402011-08-05 23:43:37 +00004568clang::DeclContext *
4569SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
4570{
4571 if (die_offset != DW_INVALID_OFFSET)
4572 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004573 DWARFDebugInfo* debug_info = DebugInfo();
4574 if (debug_info)
4575 {
4576 DWARFCompileUnitSP cu_sp;
4577 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
4578 if (die)
4579 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
4580 }
Sean Callanan72e49402011-08-05 23:43:37 +00004581 }
4582 return NULL;
4583}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004584
Greg Clayton96d7d742010-11-10 23:42:09 +00004585clang::NamespaceDecl *
Greg Clayton53eb1c22012-04-02 22:59:12 +00004586SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die)
Greg Clayton96d7d742010-11-10 23:42:09 +00004587{
Greg Clayton030a2042011-10-14 21:34:45 +00004588 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00004589 {
Greg Clayton030a2042011-10-14 21:34:45 +00004590 // See if we already parsed this namespace DIE and associated it with a
4591 // uniqued namespace declaration
4592 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
4593 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004594 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00004595 else
4596 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004597 const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL);
4598 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00004599 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
Greg Clayton5160ce52013-03-27 23:08:40 +00004600 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton9d3d6882011-10-31 23:51:19 +00004601 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00004602 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00004603 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00004604 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004605 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00004606 "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 +00004607 static_cast<void*>(GetClangASTContext().getASTContext()),
Greg Claytone38a5ed2012-01-05 03:57:59 +00004608 MakeUserID(die->GetOffset()),
4609 namespace_name,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004610 static_cast<void*>(namespace_decl),
4611 static_cast<void*>(namespace_decl->getOriginalNamespace()));
Greg Clayton030a2042011-10-14 21:34:45 +00004612 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004613 else
4614 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004615 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00004616 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004617 static_cast<void*>(GetClangASTContext().getASTContext()),
Greg Claytone38a5ed2012-01-05 03:57:59 +00004618 MakeUserID(die->GetOffset()),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004619 static_cast<void*>(namespace_decl),
4620 static_cast<void*>(namespace_decl->getOriginalNamespace()));
Greg Clayton9d3d6882011-10-31 23:51:19 +00004621 }
Greg Clayton030a2042011-10-14 21:34:45 +00004622 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004623
4624 if (namespace_decl)
4625 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
4626 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004627 }
4628 }
4629 return NULL;
4630}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004631
4632clang::DeclContext *
Greg Claytoncab36a32011-12-08 05:16:30 +00004633SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Sean Callanan72e49402011-08-05 23:43:37 +00004634{
Greg Clayton5cf58b92011-10-05 22:22:08 +00004635 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4636 if (clang_decl_ctx)
4637 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004638 // If this DIE has a specification, or an abstract origin, then trace to those.
4639
Greg Claytoncab36a32011-12-08 05:16:30 +00004640 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004641 if (die_offset != DW_INVALID_OFFSET)
4642 return GetClangDeclContextForDIEOffset (sc, die_offset);
4643
Greg Claytoncab36a32011-12-08 05:16:30 +00004644 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004645 if (die_offset != DW_INVALID_OFFSET)
4646 return GetClangDeclContextForDIEOffset (sc, die_offset);
4647
Greg Clayton5160ce52013-03-27 23:08:40 +00004648 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00004649 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004650 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 +00004651 // This is the DIE we want. Parse it, then query our map.
Greg Claytoncab36a32011-12-08 05:16:30 +00004652 bool assert_not_being_parsed = true;
4653 ResolveTypeUID (cu, die, assert_not_being_parsed);
4654
Greg Clayton5cf58b92011-10-05 22:22:08 +00004655 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4656
4657 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004658}
4659
4660clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00004661SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004662{
Greg Claytonca512b32011-01-14 04:54:56 +00004663 if (m_clang_tu_decl == NULL)
4664 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004665
Greg Clayton2bc22f82011-09-30 03:20:47 +00004666 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004667
4668 if (decl_ctx_die_copy)
4669 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00004670
4671 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004672 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00004673
Greg Clayton2bc22f82011-09-30 03:20:47 +00004674 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
4675 if (pos != m_die_to_decl_ctx.end())
4676 return pos->second;
4677
4678 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004679 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004680 case DW_TAG_compile_unit:
4681 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004682
Greg Clayton2bc22f82011-09-30 03:20:47 +00004683 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00004684 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00004685 break;
4686
4687 case DW_TAG_structure_type:
4688 case DW_TAG_union_type:
4689 case DW_TAG_class_type:
4690 {
4691 Type* type = ResolveType (cu, decl_ctx_die);
4692 if (type)
4693 {
Greg Clayton57ee3062013-07-11 22:46:58 +00004694 clang::DeclContext *decl_ctx = type->GetClangForwardType().GetDeclContextForType ();
Greg Clayton2bc22f82011-09-30 03:20:47 +00004695 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00004696 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004697 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
4698 if (decl_ctx)
4699 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00004700 }
4701 }
Greg Claytonca512b32011-01-14 04:54:56 +00004702 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00004703 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004704
Greg Clayton2bc22f82011-09-30 03:20:47 +00004705 default:
4706 break;
Greg Claytonca512b32011-01-14 04:54:56 +00004707 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004708 }
Greg Clayton7a345282010-11-09 23:46:37 +00004709 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004710}
4711
Greg Clayton2bc22f82011-09-30 03:20:47 +00004712
4713const DWARFDebugInfoEntry *
4714SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4715{
4716 if (cu && die)
4717 {
4718 const DWARFDebugInfoEntry * const decl_die = die;
4719
4720 while (die != NULL)
4721 {
4722 // If this is the original DIE that we are searching for a declaration
4723 // for, then don't look in the cache as we don't want our own decl
4724 // context to be our decl context...
4725 if (decl_die != die)
4726 {
4727 switch (die->Tag())
4728 {
4729 case DW_TAG_compile_unit:
4730 case DW_TAG_namespace:
4731 case DW_TAG_structure_type:
4732 case DW_TAG_union_type:
4733 case DW_TAG_class_type:
4734 return die;
4735
4736 default:
4737 break;
4738 }
4739 }
4740
4741 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4742 if (die_offset != DW_INVALID_OFFSET)
4743 {
4744 DWARFCompileUnit *spec_cu = cu;
4745 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
4746 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
4747 if (spec_die_decl_ctx_die)
4748 return spec_die_decl_ctx_die;
4749 }
4750
4751 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
4752 if (die_offset != DW_INVALID_OFFSET)
4753 {
4754 DWARFCompileUnit *abs_cu = cu;
4755 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
4756 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
4757 if (abs_die_decl_ctx_die)
4758 return abs_die_decl_ctx_die;
4759 }
4760
4761 die = die->GetParent();
4762 }
4763 }
4764 return NULL;
4765}
4766
4767
Greg Clayton901c5ca2011-12-03 04:40:03 +00004768Symbol *
4769SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
4770{
4771 Symbol *objc_class_symbol = NULL;
4772 if (m_obj_file)
4773 {
Greg Clayton3046e662013-07-10 01:23:25 +00004774 Symtab *symtab = m_obj_file->GetSymtab ();
Greg Clayton901c5ca2011-12-03 04:40:03 +00004775 if (symtab)
4776 {
4777 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
4778 eSymbolTypeObjCClass,
4779 Symtab::eDebugNo,
4780 Symtab::eVisibilityAny);
4781 }
4782 }
4783 return objc_class_symbol;
4784}
4785
Greg Claytonc7f03b62012-01-12 04:33:28 +00004786// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
4787// then we can end up looking through all class types for a complete type and never find
4788// the full definition. We need to know if this attribute is supported, so we determine
4789// this here and cache th result. We also need to worry about the debug map DWARF file
4790// if we are doing darwin DWARF in .o file debugging.
4791bool
4792SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
4793{
4794 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
4795 {
4796 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
4797 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
4798 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4799 else
4800 {
4801 DWARFDebugInfo* debug_info = DebugInfo();
4802 const uint32_t num_compile_units = GetNumCompileUnits();
4803 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
4804 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004805 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
4806 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004807 {
4808 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4809 break;
4810 }
4811 }
4812 }
Greg Clayton1f746072012-08-29 21:13:06 +00004813 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004814 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
4815 }
4816 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
4817}
Greg Clayton901c5ca2011-12-03 04:40:03 +00004818
4819// This function can be used when a DIE is found that is a forward declaration
4820// DIE and we want to try and find a type that has the complete definition.
4821TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00004822SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
4823 const ConstString &type_name,
4824 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00004825{
4826
4827 TypeSP type_sp;
4828
Greg Claytonc7f03b62012-01-12 04:33:28 +00004829 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00004830 return type_sp;
4831
4832 DIEArray die_offsets;
4833
4834 if (m_using_apple_tables)
4835 {
4836 if (m_apple_types_ap.get())
4837 {
4838 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00004839 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004840 }
4841 }
4842 else
4843 {
4844 if (!m_indexed)
4845 Index ();
4846
4847 m_type_index.Find (type_name, die_offsets);
4848 }
4849
Greg Clayton901c5ca2011-12-03 04:40:03 +00004850 const size_t num_matches = die_offsets.size();
4851
Greg Clayton901c5ca2011-12-03 04:40:03 +00004852 DWARFCompileUnit* type_cu = NULL;
4853 const DWARFDebugInfoEntry* type_die = NULL;
4854 if (num_matches)
4855 {
4856 DWARFDebugInfo* debug_info = DebugInfo();
4857 for (size_t i=0; i<num_matches; ++i)
4858 {
4859 const dw_offset_t die_offset = die_offsets[i];
4860 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4861
4862 if (type_die)
4863 {
4864 bool try_resolving_type = false;
4865
4866 // Don't try and resolve the DIE we are looking for with the DIE itself!
4867 if (type_die != die)
4868 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004869 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00004870 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004871 case DW_TAG_class_type:
4872 case DW_TAG_structure_type:
4873 try_resolving_type = true;
4874 break;
4875 default:
4876 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00004877 }
4878 }
4879
4880 if (try_resolving_type)
4881 {
Ed Maste4c24b122013-10-17 20:13:14 +00004882 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
4883 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004884
4885 if (try_resolving_type)
4886 {
4887 Type *resolved_type = ResolveType (type_cu, type_die, false);
4888 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4889 {
Ed Mastea0191d12013-10-17 20:42:56 +00004890 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 +00004891 MakeUserID(die->GetOffset()),
Greg Clayton901c5ca2011-12-03 04:40:03 +00004892 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4893 MakeUserID(type_die->GetOffset()),
4894 MakeUserID(type_cu->GetOffset()));
4895
Greg Claytonc7f03b62012-01-12 04:33:28 +00004896 if (die)
4897 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00004898 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00004899 break;
4900 }
4901 }
4902 }
4903 }
4904 else
4905 {
4906 if (m_using_apple_tables)
4907 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004908 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4909 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00004910 }
4911 }
4912
4913 }
4914 }
4915 return type_sp;
4916}
4917
Greg Claytona8022fa2012-04-24 21:22:41 +00004918
Greg Clayton80c26302012-02-05 06:12:47 +00004919//----------------------------------------------------------------------
4920// This function helps to ensure that the declaration contexts match for
4921// two different DIEs. Often times debug information will refer to a
4922// forward declaration of a type (the equivalent of "struct my_struct;".
4923// There will often be a declaration of that type elsewhere that has the
4924// full definition. When we go looking for the full type "my_struct", we
4925// will find one or more matches in the accelerator tables and we will
4926// then need to make sure the type was in the same declaration context
4927// as the original DIE. This function can efficiently compare two DIEs
4928// and will return true when the declaration context matches, and false
4929// when they don't.
4930//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00004931bool
4932SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
4933 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
4934{
Greg Claytona8022fa2012-04-24 21:22:41 +00004935 if (die1 == die2)
4936 return true;
4937
4938#if defined (LLDB_CONFIGURATION_DEBUG)
4939 // You can't and shouldn't call this function with a compile unit from
4940 // two different SymbolFileDWARF instances.
4941 assert (DebugInfo()->ContainsCompileUnit (cu1));
4942 assert (DebugInfo()->ContainsCompileUnit (cu2));
4943#endif
4944
Greg Clayton890ff562012-02-02 05:48:16 +00004945 DWARFDIECollection decl_ctx_1;
4946 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00004947 //The declaration DIE stack is a stack of the declaration context
4948 // DIEs all the way back to the compile unit. If a type "T" is
4949 // declared inside a class "B", and class "B" is declared inside
4950 // a class "A" and class "A" is in a namespace "lldb", and the
4951 // namespace is in a compile unit, there will be a stack of DIEs:
4952 //
4953 // [0] DW_TAG_class_type for "B"
4954 // [1] DW_TAG_class_type for "A"
4955 // [2] DW_TAG_namespace for "lldb"
4956 // [3] DW_TAG_compile_unit for the source file.
4957 //
4958 // We grab both contexts and make sure that everything matches
4959 // all the way back to the compiler unit.
4960
4961 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00004962 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004963 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00004964 // Make sure the context arrays have the same size, otherwise
4965 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00004966 const size_t count1 = decl_ctx_1.Size();
4967 const size_t count2 = decl_ctx_2.Size();
4968 if (count1 != count2)
4969 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00004970
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00004971 // Make sure the DW_TAG values match all the way back up the
Greg Clayton80c26302012-02-05 06:12:47 +00004972 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00004973 const DWARFDebugInfoEntry *decl_ctx_die1;
4974 const DWARFDebugInfoEntry *decl_ctx_die2;
4975 size_t i;
4976 for (i=0; i<count1; i++)
4977 {
4978 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4979 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4980 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
4981 return false;
4982 }
Greg Clayton890ff562012-02-02 05:48:16 +00004983#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00004984
4985 // Make sure the top item in the decl context die array is always
4986 // DW_TAG_compile_unit. If it isn't then something went wrong in
4987 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00004988 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00004989
Greg Clayton890ff562012-02-02 05:48:16 +00004990#endif
4991 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00004992 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00004993 for (i=0; i<count1 - 1; i++)
4994 {
4995 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4996 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4997 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004998 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00004999 // If the string was from a DW_FORM_strp, then the pointer will often
5000 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00005001 if (name1 == name2)
5002 continue;
5003
5004 // Name pointers are not equal, so only compare the strings
5005 // if both are not NULL.
5006 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00005007 {
Greg Clayton5569e642012-02-06 01:44:54 +00005008 // If the strings don't compare, we are done...
5009 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00005010 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00005011 }
5012 else
5013 {
5014 // One name was NULL while the other wasn't
5015 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00005016 }
5017 }
Greg Clayton80c26302012-02-05 06:12:47 +00005018 // We made it through all of the checks and the declaration contexts
5019 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00005020 return true;
5021}
Greg Clayton220a0072011-12-09 08:48:30 +00005022
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005023// This function can be used when a DIE is found that is a forward declaration
5024// DIE and we want to try and find a type that has the complete definition.
Greg Claytona8022fa2012-04-24 21:22:41 +00005025// "cu" and "die" must be from this SymbolFileDWARF
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005026TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00005027SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
Greg Clayton7f995132011-10-04 22:41:51 +00005028 const DWARFDebugInfoEntry *die,
5029 const ConstString &type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005030{
5031 TypeSP type_sp;
5032
Greg Claytona8022fa2012-04-24 21:22:41 +00005033#if defined (LLDB_CONFIGURATION_DEBUG)
5034 // You can't and shouldn't call this function with a compile unit from
5035 // another SymbolFileDWARF instance.
5036 assert (DebugInfo()->ContainsCompileUnit (cu));
5037#endif
5038
Greg Clayton1a65ae12011-01-25 23:55:37 +00005039 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005040 return type_sp;
5041
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005042 std::string qualified_name;
5043
Greg Clayton5160ce52013-03-27 23:08:40 +00005044 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005045 if (log)
5046 {
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005047 die->GetQualifiedName(this, cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00005048 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005049 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x (%s), name='%s')",
5050 die->GetOffset(),
5051 qualified_name.c_str(),
5052 type_name.GetCString());
5053 }
5054
Greg Clayton7f995132011-10-04 22:41:51 +00005055 DIEArray die_offsets;
5056
Greg Clayton97fbc342011-10-20 22:30:33 +00005057 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00005058 {
Greg Clayton97fbc342011-10-20 22:30:33 +00005059 if (m_apple_types_ap.get())
5060 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005061 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
5062 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
5063 if (has_tag && has_qualified_name_hash)
Greg Claytond1767f02011-12-08 02:13:16 +00005064 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005065 if (qualified_name.empty())
5066 die->GetQualifiedName(this, cu, qualified_name);
5067
5068 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name.c_str());
5069 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005070 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005071 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), die->Tag(), qualified_name_hash, die_offsets);
5072 }
Hafiz Abid Qadeer224746a42014-04-15 10:06:47 +00005073 else if (has_tag)
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005074 {
5075 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005076 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
Greg Claytonae920b62012-01-06 00:17:16 +00005077 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets);
Greg Claytond1767f02011-12-08 02:13:16 +00005078 }
5079 else
5080 {
5081 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
5082 }
Greg Clayton97fbc342011-10-20 22:30:33 +00005083 }
Greg Clayton7f995132011-10-04 22:41:51 +00005084 }
5085 else
5086 {
5087 if (!m_indexed)
5088 Index ();
5089
5090 m_type_index.Find (type_name, die_offsets);
5091 }
Greg Clayton7f995132011-10-04 22:41:51 +00005092
5093 const size_t num_matches = die_offsets.size();
Greg Clayton69974892010-12-03 21:42:06 +00005094
Greg Clayton934cb052011-12-03 00:27:05 +00005095 const dw_tag_t die_tag = die->Tag();
Greg Claytond4a2b372011-09-12 23:21:58 +00005096
5097 DWARFCompileUnit* type_cu = NULL;
5098 const DWARFDebugInfoEntry* type_die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00005099 if (num_matches)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005100 {
Greg Claytond4a2b372011-09-12 23:21:58 +00005101 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005102 for (size_t i=0; i<num_matches; ++i)
5103 {
Greg Claytond4a2b372011-09-12 23:21:58 +00005104 const dw_offset_t die_offset = die_offsets[i];
5105 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005106
Greg Clayton95d87902011-11-11 03:16:25 +00005107 if (type_die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005108 {
Greg Clayton934cb052011-12-03 00:27:05 +00005109 bool try_resolving_type = false;
5110
5111 // Don't try and resolve the DIE we are looking for with the DIE itself!
5112 if (type_die != die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005113 {
Greg Clayton934cb052011-12-03 00:27:05 +00005114 const dw_tag_t type_die_tag = type_die->Tag();
5115 // Make sure the tags match
5116 if (type_die_tag == die_tag)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005117 {
Greg Clayton934cb052011-12-03 00:27:05 +00005118 // The tags match, lets try resolving this type
5119 try_resolving_type = true;
5120 }
5121 else
5122 {
5123 // The tags don't match, but we need to watch our for a
5124 // forward declaration for a struct and ("struct foo")
5125 // ends up being a class ("class foo { ... };") or
5126 // vice versa.
5127 switch (type_die_tag)
Greg Clayton95d87902011-11-11 03:16:25 +00005128 {
Greg Clayton934cb052011-12-03 00:27:05 +00005129 case DW_TAG_class_type:
5130 // We had a "class foo", see if we ended up with a "struct foo { ... };"
5131 try_resolving_type = (die_tag == DW_TAG_structure_type);
5132 break;
5133 case DW_TAG_structure_type:
5134 // We had a "struct foo", see if we ended up with a "class foo { ... };"
5135 try_resolving_type = (die_tag == DW_TAG_class_type);
5136 break;
5137 default:
5138 // Tags don't match, don't event try to resolve
5139 // using this type whose name matches....
Greg Clayton95d87902011-11-11 03:16:25 +00005140 break;
5141 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005142 }
5143 }
Greg Clayton934cb052011-12-03 00:27:05 +00005144
5145 if (try_resolving_type)
5146 {
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005147 if (log)
5148 {
5149 std::string qualified_name;
5150 type_die->GetQualifiedName(this, cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00005151 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005152 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') trying die=0x%8.8x (%s)",
5153 die->GetOffset(),
5154 type_name.GetCString(),
5155 type_die->GetOffset(),
5156 qualified_name.c_str());
5157 }
5158
Greg Clayton890ff562012-02-02 05:48:16 +00005159 // Make sure the decl contexts match all the way up
5160 if (DIEDeclContextsMatch(cu, die, type_cu, type_die))
Greg Clayton934cb052011-12-03 00:27:05 +00005161 {
Greg Clayton890ff562012-02-02 05:48:16 +00005162 Type *resolved_type = ResolveType (type_cu, type_die, false);
5163 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5164 {
Daniel Malead01b2952012-11-29 21:49:15 +00005165 DEBUG_PRINTF ("resolved 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ") from %s to 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ")\n",
Greg Clayton890ff562012-02-02 05:48:16 +00005166 MakeUserID(die->GetOffset()),
Ed Mastea0191d12013-10-17 20:42:56 +00005167 MakeUserID(cu->GetOffset()),
Greg Clayton890ff562012-02-02 05:48:16 +00005168 m_obj_file->GetFileSpec().GetFilename().AsCString(),
5169 MakeUserID(type_die->GetOffset()),
5170 MakeUserID(type_cu->GetOffset()));
5171
5172 m_die_to_type[die] = resolved_type;
Greg Claytonff7692a2012-02-02 18:16:59 +00005173 type_sp = resolved_type->shared_from_this();
Greg Clayton890ff562012-02-02 05:48:16 +00005174 break;
5175 }
Greg Clayton934cb052011-12-03 00:27:05 +00005176 }
5177 }
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005178 else
5179 {
5180 if (log)
5181 {
5182 std::string qualified_name;
5183 type_die->GetQualifiedName(this, cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00005184 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005185 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') ignoring die=0x%8.8x (%s)",
5186 die->GetOffset(),
5187 type_name.GetCString(),
5188 type_die->GetOffset(),
5189 qualified_name.c_str());
5190 }
5191 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005192 }
Greg Clayton95d87902011-11-11 03:16:25 +00005193 else
5194 {
5195 if (m_using_apple_tables)
5196 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005197 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5198 die_offset, type_name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00005199 }
5200 }
5201
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005202 }
5203 }
5204 return type_sp;
5205}
5206
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005207TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00005208SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx)
5209{
5210 TypeSP type_sp;
5211
5212 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
5213 if (dwarf_decl_ctx_count > 0)
5214 {
5215 const ConstString type_name(dwarf_decl_ctx[0].name);
5216 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
5217
5218 if (type_name)
5219 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005220 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
Greg Claytona8022fa2012-04-24 21:22:41 +00005221 if (log)
5222 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005223 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005224 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')",
5225 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5226 dwarf_decl_ctx.GetQualifiedName());
5227 }
5228
5229 DIEArray die_offsets;
5230
5231 if (m_using_apple_tables)
5232 {
5233 if (m_apple_types_ap.get())
5234 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005235 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
5236 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
5237 if (has_tag && has_qualified_name_hash)
Greg Claytona8022fa2012-04-24 21:22:41 +00005238 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005239 const char *qualified_name = dwarf_decl_ctx.GetQualifiedName();
5240 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name);
5241 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005242 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005243 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets);
5244 }
5245 else if (has_tag)
5246 {
5247 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005248 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
Greg Claytona8022fa2012-04-24 21:22:41 +00005249 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets);
5250 }
5251 else
5252 {
5253 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
5254 }
5255 }
5256 }
5257 else
5258 {
5259 if (!m_indexed)
5260 Index ();
5261
5262 m_type_index.Find (type_name, die_offsets);
5263 }
5264
5265 const size_t num_matches = die_offsets.size();
5266
5267
5268 DWARFCompileUnit* type_cu = NULL;
5269 const DWARFDebugInfoEntry* type_die = NULL;
5270 if (num_matches)
5271 {
5272 DWARFDebugInfo* debug_info = DebugInfo();
5273 for (size_t i=0; i<num_matches; ++i)
5274 {
5275 const dw_offset_t die_offset = die_offsets[i];
5276 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
5277
5278 if (type_die)
5279 {
5280 bool try_resolving_type = false;
5281
5282 // Don't try and resolve the DIE we are looking for with the DIE itself!
5283 const dw_tag_t type_tag = type_die->Tag();
5284 // Make sure the tags match
5285 if (type_tag == tag)
5286 {
5287 // The tags match, lets try resolving this type
5288 try_resolving_type = true;
5289 }
5290 else
5291 {
5292 // The tags don't match, but we need to watch our for a
5293 // forward declaration for a struct and ("struct foo")
5294 // ends up being a class ("class foo { ... };") or
5295 // vice versa.
5296 switch (type_tag)
5297 {
5298 case DW_TAG_class_type:
5299 // We had a "class foo", see if we ended up with a "struct foo { ... };"
5300 try_resolving_type = (tag == DW_TAG_structure_type);
5301 break;
5302 case DW_TAG_structure_type:
5303 // We had a "struct foo", see if we ended up with a "class foo { ... };"
5304 try_resolving_type = (tag == DW_TAG_class_type);
5305 break;
5306 default:
5307 // Tags don't match, don't event try to resolve
5308 // using this type whose name matches....
5309 break;
5310 }
5311 }
5312
5313 if (try_resolving_type)
5314 {
5315 DWARFDeclContext type_dwarf_decl_ctx;
5316 type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx);
5317
5318 if (log)
5319 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005320 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005321 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)",
5322 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5323 dwarf_decl_ctx.GetQualifiedName(),
5324 type_die->GetOffset(),
5325 type_dwarf_decl_ctx.GetQualifiedName());
5326 }
5327
5328 // Make sure the decl contexts match all the way up
5329 if (dwarf_decl_ctx == type_dwarf_decl_ctx)
5330 {
5331 Type *resolved_type = ResolveType (type_cu, type_die, false);
5332 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5333 {
5334 type_sp = resolved_type->shared_from_this();
5335 break;
5336 }
5337 }
5338 }
5339 else
5340 {
5341 if (log)
5342 {
5343 std::string qualified_name;
5344 type_die->GetQualifiedName(this, type_cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00005345 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005346 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)",
5347 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5348 dwarf_decl_ctx.GetQualifiedName(),
5349 type_die->GetOffset(),
5350 qualified_name.c_str());
5351 }
5352 }
5353 }
5354 else
5355 {
5356 if (m_using_apple_tables)
5357 {
5358 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5359 die_offset, type_name.GetCString());
5360 }
5361 }
5362
5363 }
5364 }
5365 }
5366 }
5367 return type_sp;
5368}
5369
Greg Clayton4116e932012-05-15 02:33:01 +00005370bool
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005371SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005372 Type *class_type,
Greg Clayton4116e932012-05-15 02:33:01 +00005373 DWARFCompileUnit* src_cu,
5374 const DWARFDebugInfoEntry *src_class_die,
5375 DWARFCompileUnit* dst_cu,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005376 const DWARFDebugInfoEntry *dst_class_die,
Greg Claytond20deac2014-04-04 18:15:18 +00005377 DWARFDIECollection &failures)
Greg Clayton4116e932012-05-15 02:33:01 +00005378{
5379 if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die)
5380 return false;
5381 if (src_class_die->Tag() != dst_class_die->Tag())
5382 return false;
5383
5384 // We need to complete the class type so we can get all of the method types
5385 // parsed so we can then unique those types to their equivalent counterparts
5386 // in "dst_cu" and "dst_class_die"
5387 class_type->GetClangFullType();
5388
5389 const DWARFDebugInfoEntry *src_die;
5390 const DWARFDebugInfoEntry *dst_die;
5391 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die;
5392 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die;
Greg Clayton65ec1032012-11-12 21:27:20 +00005393 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial;
5394 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial;
Greg Clayton4116e932012-05-15 02:33:01 +00005395 for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling())
5396 {
5397 if (src_die->Tag() == DW_TAG_subprogram)
5398 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005399 // Make sure this is a declaration and not a concrete instance by looking
5400 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5401 // are placed inside the class definitions and shouldn't be included in
5402 // the list of things are are tracking here.
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005403 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_declaration, 0) == 1)
Greg Clayton84afacd2012-11-07 23:09:32 +00005404 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005405 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton84afacd2012-11-07 23:09:32 +00005406 if (src_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005407 {
5408 ConstString src_const_name(src_name);
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005409 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0))
Greg Clayton65ec1032012-11-12 21:27:20 +00005410 src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die);
5411 else
5412 src_name_to_die.Append(src_const_name.GetCString(), src_die);
5413 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005414 }
Greg Clayton4116e932012-05-15 02:33:01 +00005415 }
5416 }
5417 for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling())
5418 {
5419 if (dst_die->Tag() == DW_TAG_subprogram)
5420 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005421 // Make sure this is a declaration and not a concrete instance by looking
5422 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5423 // are placed inside the class definitions and shouldn't be included in
5424 // the list of things are are tracking here.
5425 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1)
5426 {
5427 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5428 if (dst_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005429 {
5430 ConstString dst_const_name(dst_name);
5431 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0))
5432 dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die);
5433 else
5434 dst_name_to_die.Append(dst_const_name.GetCString(), dst_die);
5435 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005436 }
Greg Clayton4116e932012-05-15 02:33:01 +00005437 }
5438 }
5439 const uint32_t src_size = src_name_to_die.GetSize ();
5440 const uint32_t dst_size = dst_name_to_die.GetSize ();
Greg Clayton5160ce52013-03-27 23:08:40 +00005441 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005442
5443 // Is everything kosher so we can go through the members at top speed?
5444 bool fast_path = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005445
Sean Callanan2367f8a2013-02-26 01:12:25 +00005446 if (src_size != dst_size)
Greg Clayton4116e932012-05-15 02:33:01 +00005447 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005448 if (src_size != 0 && dst_size != 0)
5449 {
5450 if (log)
5451 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)",
5452 src_class_die->GetOffset(),
5453 dst_class_die->GetOffset(),
5454 src_size,
5455 dst_size);
5456 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005457
Sean Callanan2367f8a2013-02-26 01:12:25 +00005458 fast_path = false;
5459 }
5460
5461 uint32_t idx;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005462
Sean Callanan2367f8a2013-02-26 01:12:25 +00005463 if (fast_path)
5464 {
Greg Clayton4116e932012-05-15 02:33:01 +00005465 for (idx = 0; idx < src_size; ++idx)
5466 {
5467 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5468 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5469
5470 if (src_die->Tag() != dst_die->Tag())
5471 {
5472 if (log)
5473 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)",
5474 src_class_die->GetOffset(),
5475 dst_class_die->GetOffset(),
5476 src_die->GetOffset(),
5477 DW_TAG_value_to_name(src_die->Tag()),
5478 dst_die->GetOffset(),
5479 DW_TAG_value_to_name(src_die->Tag()));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005480 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005481 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005482
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005483 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton4116e932012-05-15 02:33:01 +00005484 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005485
Greg Clayton4116e932012-05-15 02:33:01 +00005486 // Make sure the names match
5487 if (src_name == dst_name || (strcmp (src_name, dst_name) == 0))
5488 continue;
5489
5490 if (log)
5491 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)",
5492 src_class_die->GetOffset(),
5493 dst_class_die->GetOffset(),
5494 src_die->GetOffset(),
5495 src_name,
5496 dst_die->GetOffset(),
5497 dst_name);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005498
Sean Callanan2367f8a2013-02-26 01:12:25 +00005499 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005500 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005501 }
Greg Clayton4116e932012-05-15 02:33:01 +00005502
Sean Callanan2367f8a2013-02-26 01:12:25 +00005503 // Now do the work of linking the DeclContexts and Types.
5504 if (fast_path)
5505 {
5506 // We can do this quickly. Just run across the tables index-for-index since
5507 // we know each node has matching names and tags.
Greg Clayton4116e932012-05-15 02:33:01 +00005508 for (idx = 0; idx < src_size; ++idx)
5509 {
5510 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5511 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005512
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005513 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Greg Clayton4116e932012-05-15 02:33:01 +00005514 if (src_decl_ctx)
5515 {
5516 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005517 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
5518 static_cast<void*>(src_decl_ctx),
5519 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005520 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5521 }
5522 else
5523 {
5524 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005525 log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found",
5526 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005527 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005528
Greg Clayton4116e932012-05-15 02:33:01 +00005529 Type *src_child_type = m_die_to_type[src_die];
5530 if (src_child_type)
5531 {
5532 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005533 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
5534 static_cast<void*>(src_child_type),
5535 src_child_type->GetID(),
5536 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005537 m_die_to_type[dst_die] = src_child_type;
5538 }
5539 else
5540 {
5541 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005542 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());
5543 }
5544 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005545 }
5546 else
5547 {
5548 // We must do this slowly. For each member of the destination, look
5549 // up a member in the source with the same name, check its tag, and
5550 // unique them if everything matches up. Report failures.
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005551
Sean Callanan2367f8a2013-02-26 01:12:25 +00005552 if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty())
5553 {
5554 src_name_to_die.Sort();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005555
Sean Callanan2367f8a2013-02-26 01:12:25 +00005556 for (idx = 0; idx < dst_size; ++idx)
5557 {
5558 const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx);
5559 dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
5560 src_die = src_name_to_die.Find(dst_name, NULL);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005561
Sean Callanan2367f8a2013-02-26 01:12:25 +00005562 if (src_die && (src_die->Tag() == dst_die->Tag()))
5563 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005564 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Sean Callanan2367f8a2013-02-26 01:12:25 +00005565 if (src_decl_ctx)
5566 {
5567 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005568 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
5569 static_cast<void*>(src_decl_ctx),
5570 src_die->GetOffset(),
5571 dst_die->GetOffset());
Sean Callanan2367f8a2013-02-26 01:12:25 +00005572 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5573 }
5574 else
5575 {
5576 if (log)
5577 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());
5578 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005579
Sean Callanan2367f8a2013-02-26 01:12:25 +00005580 Type *src_child_type = m_die_to_type[src_die];
5581 if (src_child_type)
5582 {
5583 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005584 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
5585 static_cast<void*>(src_child_type),
5586 src_child_type->GetID(),
5587 src_die->GetOffset(),
5588 dst_die->GetOffset());
Sean Callanan2367f8a2013-02-26 01:12:25 +00005589 m_die_to_type[dst_die] = src_child_type;
5590 }
5591 else
5592 {
5593 if (log)
5594 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());
5595 }
5596 }
5597 else
5598 {
5599 if (log)
5600 log->Printf ("warning: couldn't find a match for 0x%8.8x", dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005601
Greg Claytond20deac2014-04-04 18:15:18 +00005602 failures.Append(dst_die);
Sean Callanan2367f8a2013-02-26 01:12:25 +00005603 }
5604 }
5605 }
5606 }
5607
5608 const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize ();
5609 const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize ();
5610
5611 UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src;
5612
5613 if (src_size_artificial && dst_size_artificial)
5614 {
5615 dst_name_to_die_artificial.Sort();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005616
Greg Clayton65ec1032012-11-12 21:27:20 +00005617 for (idx = 0; idx < src_size_artificial; ++idx)
5618 {
5619 const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx);
5620 src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5621 dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005622
Greg Clayton65ec1032012-11-12 21:27:20 +00005623 if (dst_die)
5624 {
Greg Clayton65ec1032012-11-12 21:27:20 +00005625 // Both classes have the artificial types, link them
5626 clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die];
5627 if (src_decl_ctx)
5628 {
5629 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005630 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
5631 static_cast<void*>(src_decl_ctx),
5632 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005633 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5634 }
5635 else
5636 {
5637 if (log)
5638 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());
5639 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005640
Greg Clayton65ec1032012-11-12 21:27:20 +00005641 Type *src_child_type = m_die_to_type[src_die];
5642 if (src_child_type)
5643 {
5644 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005645 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
5646 static_cast<void*>(src_child_type),
5647 src_child_type->GetID(),
5648 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005649 m_die_to_type[dst_die] = src_child_type;
5650 }
5651 else
5652 {
5653 if (log)
5654 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());
5655 }
5656 }
5657 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005658 }
Greg Clayton65ec1032012-11-12 21:27:20 +00005659
Sean Callanan2367f8a2013-02-26 01:12:25 +00005660 if (dst_size_artificial)
Greg Clayton4116e932012-05-15 02:33:01 +00005661 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005662 for (idx = 0; idx < dst_size_artificial; ++idx)
5663 {
5664 const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx);
5665 dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5666 if (log)
5667 log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial);
5668
Greg Claytond20deac2014-04-04 18:15:18 +00005669 failures.Append(dst_die);
Sean Callanan2367f8a2013-02-26 01:12:25 +00005670 }
Greg Clayton4116e932012-05-15 02:33:01 +00005671 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005672
Greg Claytond20deac2014-04-04 18:15:18 +00005673 return (failures.Size() != 0);
Greg Clayton4116e932012-05-15 02:33:01 +00005674}
Greg Claytona8022fa2012-04-24 21:22:41 +00005675
5676TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00005677SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005678{
5679 TypeSP type_sp;
5680
Greg Clayton1be10fc2010-09-29 01:12:09 +00005681 if (type_is_new_ptr)
5682 *type_is_new_ptr = false;
Greg Clayton1fba87112012-02-09 20:03:49 +00005683
Todd Fiala0a70a842014-05-28 16:43:26 +00005684#if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE)
Greg Clayton1fba87112012-02-09 20:03:49 +00005685 static DIEStack g_die_stack;
5686 DIEStack::ScopedPopper scoped_die_logger(g_die_stack);
5687#endif
Greg Clayton1be10fc2010-09-29 01:12:09 +00005688
Sean Callananc7fbf732010-08-06 00:32:49 +00005689 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005690 if (die != NULL)
5691 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005692 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005693 if (log)
Sean Callanan5b26f272012-02-04 08:49:35 +00005694 {
5695 const DWARFDebugInfoEntry *context_die;
5696 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005697
Greg Clayton5160ce52013-03-27 23:08:40 +00005698 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 +00005699 die->GetOffset(),
5700 static_cast<void*>(context),
5701 context_die->GetOffset(),
5702 DW_TAG_value_to_name(die->Tag()),
5703 die->GetName(this, dwarf_cu));
5704
Todd Fiala0a70a842014-05-28 16:43:26 +00005705#if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE)
Greg Clayton1fba87112012-02-09 20:03:49 +00005706 scoped_die_logger.Push (dwarf_cu, die);
Greg Clayton5160ce52013-03-27 23:08:40 +00005707 g_die_stack.LogDIEs(log, this);
Greg Clayton1fba87112012-02-09 20:03:49 +00005708#endif
Sean Callanan5b26f272012-02-04 08:49:35 +00005709 }
Greg Clayton3bffb082011-12-10 02:15:28 +00005710//
Greg Clayton5160ce52013-03-27 23:08:40 +00005711// Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005712// if (log && dwarf_cu)
5713// {
5714// StreamString s;
5715// die->DumpLocation (this, dwarf_cu, s);
Greg Clayton5160ce52013-03-27 23:08:40 +00005716// GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Greg Clayton3bffb082011-12-10 02:15:28 +00005717//
5718// }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005719
Greg Clayton594e5ed2010-09-27 21:07:38 +00005720 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005721 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00005722 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005723 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005724 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00005725 if (type_is_new_ptr)
5726 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005727
Greg Clayton594e5ed2010-09-27 21:07:38 +00005728 const dw_tag_t tag = die->Tag();
5729
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005730 bool is_forward_declaration = false;
5731 DWARFDebugInfoEntry::Attributes attributes;
5732 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00005733 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00005734 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
Greg Claytonfaac1112013-03-14 18:31:44 +00005735 uint64_t byte_size = 0;
Greg Clayton526e5af2010-11-13 03:52:47 +00005736 Declaration decl;
5737
Greg Clayton4957bf62010-09-30 21:49:03 +00005738 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton57ee3062013-07-11 22:46:58 +00005739 ClangASTType clang_type;
Greg Claytond20deac2014-04-04 18:15:18 +00005740 DWARFFormValue form_value;
5741
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005742 dw_attr_t attr;
5743
5744 switch (tag)
5745 {
5746 case DW_TAG_base_type:
5747 case DW_TAG_pointer_type:
5748 case DW_TAG_reference_type:
Sean Callanance8af862012-05-21 23:31:51 +00005749 case DW_TAG_rvalue_reference_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005750 case DW_TAG_typedef:
5751 case DW_TAG_const_type:
5752 case DW_TAG_restrict_type:
5753 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00005754 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005755 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005756 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005757 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005758
Greg Claytond88d7592010-09-15 08:33:30 +00005759 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005760 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005761 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
5762
5763 if (num_attributes > 0)
5764 {
5765 uint32_t i;
5766 for (i=0; i<num_attributes; ++i)
5767 {
5768 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005769 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5770 {
5771 switch (attr)
5772 {
5773 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5774 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5775 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5776 case DW_AT_name:
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005777
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005778 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00005779 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
5780 // include the "&"...
5781 if (tag == DW_TAG_reference_type)
5782 {
5783 if (strchr (type_name_cstr, '&') == NULL)
5784 type_name_cstr = NULL;
5785 }
5786 if (type_name_cstr)
5787 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005788 break;
Greg Clayton23f59502012-07-17 03:23:13 +00005789 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005790 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
5791 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
5792 default:
5793 case DW_AT_sibling:
5794 break;
5795 }
5796 }
5797 }
5798 }
5799
Ed Mastea0191d12013-10-17 20:42:56 +00005800 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 +00005801
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005802 switch (tag)
5803 {
5804 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00005805 break;
5806
Greg Claytond4436412011-10-28 21:00:00 +00005807 case DW_TAG_unspecified_type:
Greg Clayton7fba2632013-07-01 21:01:52 +00005808 if (strcmp(type_name_cstr, "nullptr_t") == 0 ||
5809 strcmp(type_name_cstr, "decltype(nullptr)") == 0 )
Greg Claytond4436412011-10-28 21:00:00 +00005810 {
5811 resolve_state = Type::eResolveStateFull;
Greg Clayton57ee3062013-07-11 22:46:58 +00005812 clang_type = ast.GetBasicType(eBasicTypeNullPtr);
Greg Claytond4436412011-10-28 21:00:00 +00005813 break;
5814 }
5815 // Fall through to base type below in case we can handle the type there...
5816
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005817 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00005818 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005819 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
5820 encoding,
5821 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005822 break;
5823
Sean Callanance8af862012-05-21 23:31:51 +00005824 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
5825 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
5826 case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break;
5827 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
5828 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
5829 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
5830 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005831 }
5832
Greg Clayton57ee3062013-07-11 22:46:58 +00005833 if (!clang_type && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID) && sc.comp_unit != NULL)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005834 {
Sean Callanan82587052013-01-03 00:05:56 +00005835 bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005836
Sean Callanan82587052013-01-03 00:05:56 +00005837 if (translation_unit_is_objc)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005838 {
Sean Callanan82587052013-01-03 00:05:56 +00005839 if (type_name_cstr != NULL)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005840 {
Sean Callanan82587052013-01-03 00:05:56 +00005841 static ConstString g_objc_type_name_id("id");
5842 static ConstString g_objc_type_name_Class("Class");
5843 static ConstString g_objc_type_name_selector("SEL");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005844
Sean Callanan82587052013-01-03 00:05:56 +00005845 if (type_name_const_str == g_objc_type_name_id)
5846 {
5847 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005848 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 +00005849 die->GetOffset(),
5850 DW_TAG_value_to_name(die->Tag()),
5851 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005852 clang_type = ast.GetBasicType(eBasicTypeObjCID);
Sean Callanan82587052013-01-03 00:05:56 +00005853 encoding_data_type = Type::eEncodingIsUID;
5854 encoding_uid = LLDB_INVALID_UID;
5855 resolve_state = Type::eResolveStateFull;
Greg Clayton526e5af2010-11-13 03:52:47 +00005856
Sean Callanan82587052013-01-03 00:05:56 +00005857 }
5858 else if (type_name_const_str == g_objc_type_name_Class)
5859 {
5860 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005861 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 +00005862 die->GetOffset(),
5863 DW_TAG_value_to_name(die->Tag()),
5864 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005865 clang_type = ast.GetBasicType(eBasicTypeObjCClass);
Sean Callanan82587052013-01-03 00:05:56 +00005866 encoding_data_type = Type::eEncodingIsUID;
5867 encoding_uid = LLDB_INVALID_UID;
5868 resolve_state = Type::eResolveStateFull;
5869 }
5870 else if (type_name_const_str == g_objc_type_name_selector)
5871 {
5872 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005873 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 +00005874 die->GetOffset(),
5875 DW_TAG_value_to_name(die->Tag()),
5876 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005877 clang_type = ast.GetBasicType(eBasicTypeObjCSel);
Sean Callanan82587052013-01-03 00:05:56 +00005878 encoding_data_type = Type::eEncodingIsUID;
5879 encoding_uid = LLDB_INVALID_UID;
5880 resolve_state = Type::eResolveStateFull;
5881 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005882 }
Sean Callanan82587052013-01-03 00:05:56 +00005883 else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005884 {
Sean Callanan82587052013-01-03 00:05:56 +00005885 // 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 +00005886
Sean Callanan82587052013-01-03 00:05:56 +00005887 DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005888
Sean Callanan82587052013-01-03 00:05:56 +00005889 if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005890 {
Sean Callanan82587052013-01-03 00:05:56 +00005891 if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL))
5892 {
5893 if (!strcmp(struct_name, "objc_object"))
5894 {
5895 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005896 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 +00005897 die->GetOffset(),
5898 DW_TAG_value_to_name(die->Tag()),
5899 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005900 clang_type = ast.GetBasicType(eBasicTypeObjCID);
Sean Callanan82587052013-01-03 00:05:56 +00005901 encoding_data_type = Type::eEncodingIsUID;
5902 encoding_uid = LLDB_INVALID_UID;
5903 resolve_state = Type::eResolveStateFull;
5904 }
5905 }
5906 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005907 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005908 }
5909 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005910
Greg Clayton81c22f62011-10-19 18:09:39 +00005911 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005912 this,
5913 type_name_const_str,
5914 byte_size,
5915 NULL,
5916 encoding_uid,
5917 encoding_data_type,
5918 &decl,
5919 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005920 resolve_state));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005921
Greg Clayton594e5ed2010-09-27 21:07:38 +00005922 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005923
5924// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
5925// if (encoding_type != NULL)
5926// {
5927// if (encoding_type != DIE_IS_BEING_PARSED)
5928// type_sp->SetEncodingType(encoding_type);
5929// else
5930// m_indirect_fixups.push_back(type_sp.get());
5931// }
5932 }
5933 break;
5934
5935 case DW_TAG_structure_type:
5936 case DW_TAG_union_type:
5937 case DW_TAG_class_type:
5938 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005939 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005940 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Greg Clayton23f59502012-07-17 03:23:13 +00005941 bool byte_size_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005942
Greg Clayton9e409562010-07-28 02:04:09 +00005943 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00005944 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005945 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00005946 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005947 if (num_attributes > 0)
5948 {
5949 uint32_t i;
5950 for (i=0; i<num_attributes; ++i)
5951 {
5952 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005953 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5954 {
5955 switch (attr)
5956 {
Greg Clayton9e409562010-07-28 02:04:09 +00005957 case DW_AT_decl_file:
Greg Claytonc7f03b62012-01-12 04:33:28 +00005958 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
Ed Maste4c24b122013-10-17 20:13:14 +00005959 {
5960 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
5961 // point to the compile unit file, so we clear this invalid value
5962 // so that we can still unique types efficiently.
Greg Claytonc7f03b62012-01-12 04:33:28 +00005963 decl.SetFile(FileSpec ("<invalid>", false));
Ed Maste4c24b122013-10-17 20:13:14 +00005964 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005965 else
5966 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
Greg Clayton9e409562010-07-28 02:04:09 +00005967 break;
5968
5969 case DW_AT_decl_line:
5970 decl.SetLine(form_value.Unsigned());
5971 break;
5972
5973 case DW_AT_decl_column:
5974 decl.SetColumn(form_value.Unsigned());
5975 break;
5976
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005977 case DW_AT_name:
5978 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005979 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005980 break;
Greg Clayton9e409562010-07-28 02:04:09 +00005981
5982 case DW_AT_byte_size:
5983 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00005984 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00005985 break;
5986
5987 case DW_AT_accessibility:
5988 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
5989 break;
5990
5991 case DW_AT_declaration:
Greg Clayton1c8ef472013-04-05 23:27:21 +00005992 is_forward_declaration = form_value.Boolean();
Greg Clayton9e409562010-07-28 02:04:09 +00005993 break;
5994
5995 case DW_AT_APPLE_runtime_class:
5996 class_language = (LanguageType)form_value.Signed();
5997 break;
5998
Greg Clayton18774842011-11-29 23:40:34 +00005999 case DW_AT_APPLE_objc_complete_type:
6000 is_complete_objc_class = form_value.Signed();
6001 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006002
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006003 case DW_AT_allocated:
6004 case DW_AT_associated:
6005 case DW_AT_data_location:
6006 case DW_AT_description:
6007 case DW_AT_start_scope:
6008 case DW_AT_visibility:
6009 default:
6010 case DW_AT_sibling:
6011 break;
6012 }
6013 }
6014 }
6015 }
Greg Claytond20deac2014-04-04 18:15:18 +00006016
6017 // UniqueDWARFASTType is large, so don't create a local variables on the
6018 // stack, put it on the heap. This function is often called recursively
6019 // and clang isn't good and sharing the stack space for variables in different blocks.
6020 std::unique_ptr<UniqueDWARFASTType> unique_ast_entry_ap(new UniqueDWARFASTType());
Sean Callanan8e8072d2012-02-07 21:13:38 +00006021
Greg Clayton123edca2012-03-02 00:07:15 +00006022 // Only try and unique the type if it has a name.
6023 if (type_name_const_str &&
6024 GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Sean Callanan8e8072d2012-02-07 21:13:38 +00006025 this,
6026 dwarf_cu,
6027 die,
6028 decl,
6029 byte_size_valid ? byte_size : -1,
Greg Claytond20deac2014-04-04 18:15:18 +00006030 *unique_ast_entry_ap))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006031 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00006032 // We have already parsed this type or from another
6033 // compile unit. GCC loves to use the "one definition
6034 // rule" which can result in multiple definitions
6035 // of the same class over and over in each compile
6036 // unit.
Greg Claytond20deac2014-04-04 18:15:18 +00006037 type_sp = unique_ast_entry_ap->m_type_sp;
Sean Callanan8e8072d2012-02-07 21:13:38 +00006038 if (type_sp)
Greg Claytonc615ce42010-11-09 04:42:43 +00006039 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00006040 m_die_to_type[die] = type_sp.get();
6041 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00006042 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006043 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006044
Daniel Malead01b2952012-11-29 21:49:15 +00006045 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 +00006046
6047 int tag_decl_kind = -1;
6048 AccessType default_accessibility = eAccessNone;
6049 if (tag == DW_TAG_structure_type)
6050 {
6051 tag_decl_kind = clang::TTK_Struct;
6052 default_accessibility = eAccessPublic;
6053 }
6054 else if (tag == DW_TAG_union_type)
6055 {
6056 tag_decl_kind = clang::TTK_Union;
6057 default_accessibility = eAccessPublic;
6058 }
6059 else if (tag == DW_TAG_class_type)
6060 {
6061 tag_decl_kind = clang::TTK_Class;
6062 default_accessibility = eAccessPrivate;
6063 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006064
Greg Clayton3a5f29a2011-11-30 02:48:28 +00006065 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
6066 die->HasChildren() == false &&
6067 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
6068 {
6069 // Work around an issue with clang at the moment where
6070 // forward declarations for objective C classes are emitted
6071 // as:
6072 // DW_TAG_structure_type [2]
6073 // DW_AT_name( "ForwardObjcClass" )
6074 // DW_AT_byte_size( 0x00 )
6075 // DW_AT_decl_file( "..." )
6076 // DW_AT_decl_line( 1 )
6077 //
6078 // Note that there is no DW_AT_declaration and there are
6079 // no children, and the byte size is zero.
6080 is_forward_declaration = true;
6081 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006082
Sean Callanan7457f8d2012-04-25 01:03:57 +00006083 if (class_language == eLanguageTypeObjC ||
6084 class_language == eLanguageTypeObjC_plus_plus)
Greg Clayton18774842011-11-29 23:40:34 +00006085 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00006086 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
Greg Clayton901c5ca2011-12-03 04:40:03 +00006087 {
6088 // We have a valid eSymbolTypeObjCClass class symbol whose
6089 // name matches the current objective C class that we
6090 // are trying to find and this DIE isn't the complete
6091 // definition (we checked is_complete_objc_class above and
6092 // know it is false), so the real definition is in here somewhere
Greg Claytonc7f03b62012-01-12 04:33:28 +00006093 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006094
Greg Clayton1f746072012-08-29 21:13:06 +00006095 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton901c5ca2011-12-03 04:40:03 +00006096 {
6097 // We weren't able to find a full declaration in
6098 // this DWARF, see if we have a declaration anywhere
6099 // else...
Greg Claytonc7f03b62012-01-12 04:33:28 +00006100 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00006101 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006102
Greg Clayton901c5ca2011-12-03 04:40:03 +00006103 if (type_sp)
6104 {
6105 if (log)
6106 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006107 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00006108 "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 +00006109 static_cast<void*>(this),
Greg Claytone38a5ed2012-01-05 03:57:59 +00006110 die->GetOffset(),
6111 DW_TAG_value_to_name(tag),
6112 type_name_cstr,
6113 type_sp->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00006114 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006115
Greg Clayton901c5ca2011-12-03 04:40:03 +00006116 // We found a real definition for this type elsewhere
6117 // so lets use it and cache the fact that we found
6118 // a complete type for this die
6119 m_die_to_type[die] = type_sp.get();
6120 return type_sp;
6121 }
6122 }
6123 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006124
Greg Clayton901c5ca2011-12-03 04:40:03 +00006125
6126 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006127 {
6128 // We have a forward declaration to a type and we need
6129 // to try and find a full declaration. We look in the
6130 // current type index just in case we have a forward
6131 // declaration followed by an actual declarations in the
6132 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00006133 if (log)
6134 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006135 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00006136 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006137 static_cast<void*>(this),
Greg Claytone38a5ed2012-01-05 03:57:59 +00006138 die->GetOffset(),
6139 DW_TAG_value_to_name(tag),
6140 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00006141 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006142
Greg Claytona8022fa2012-04-24 21:22:41 +00006143 DWARFDeclContext die_decl_ctx;
6144 die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx);
6145
6146 //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
6147 type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006148
Greg Clayton1f746072012-08-29 21:13:06 +00006149 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton4272cc72011-02-02 02:24:04 +00006150 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006151 // We weren't able to find a full declaration in
6152 // this DWARF, see if we have a declaration anywhere
6153 // else...
Greg Claytona8022fa2012-04-24 21:22:41 +00006154 type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton4272cc72011-02-02 02:24:04 +00006155 }
6156
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006157 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00006158 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00006159 if (log)
6160 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006161 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00006162 "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 +00006163 static_cast<void*>(this),
Greg Claytone38a5ed2012-01-05 03:57:59 +00006164 die->GetOffset(),
6165 DW_TAG_value_to_name(tag),
6166 type_name_cstr,
6167 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00006168 }
6169
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006170 // We found a real definition for this type elsewhere
6171 // so lets use it and cache the fact that we found
6172 // a complete type for this die
6173 m_die_to_type[die] = type_sp.get();
6174 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00006175 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006176 }
6177 assert (tag_decl_kind != -1);
6178 bool clang_type_was_created = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00006179 clang_type.SetClangType(ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die));
6180 if (!clang_type)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006181 {
Sean Callanan4d04c6a2012-02-09 22:54:11 +00006182 const DWARFDebugInfoEntry *decl_ctx_die;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006183
Sean Callanan4d04c6a2012-02-09 22:54:11 +00006184 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton55561e92011-10-26 03:31:36 +00006185 if (accessibility == eAccessNone && decl_ctx)
6186 {
6187 // Check the decl context that contains this class/struct/union.
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00006188 // If it is a class we must give it an accessibility.
Greg Clayton55561e92011-10-26 03:31:36 +00006189 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
6190 if (DeclKindIsCXXClass (containing_decl_kind))
6191 accessibility = default_accessibility;
6192 }
6193
Greg Claytonc4ffd662013-03-08 01:37:30 +00006194 ClangASTMetadata metadata;
6195 metadata.SetUserID(MakeUserID(die->GetOffset()));
6196 metadata.SetIsDynamicCXXType(ClassOrStructIsVirtual (dwarf_cu, die));
6197
Greg Claytonf0705c82011-10-22 03:33:13 +00006198 if (type_name_cstr && strchr (type_name_cstr, '<'))
6199 {
6200 ClangASTContext::TemplateParameterInfos template_param_infos;
6201 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
6202 {
6203 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00006204 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00006205 type_name_cstr,
6206 tag_decl_kind,
6207 template_param_infos);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006208
Greg Claytonf0705c82011-10-22 03:33:13 +00006209 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
6210 class_template_decl,
6211 tag_decl_kind,
6212 template_param_infos);
6213 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
6214 clang_type_was_created = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006215
Greg Claytond0029442013-03-27 01:48:02 +00006216 GetClangASTContext().SetMetadata (class_template_decl, metadata);
6217 GetClangASTContext().SetMetadata (class_specialization_decl, metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00006218 }
6219 }
6220
6221 if (!clang_type_was_created)
6222 {
6223 clang_type_was_created = true;
Greg Clayton55561e92011-10-26 03:31:36 +00006224 clang_type = ast.CreateRecordType (decl_ctx,
6225 accessibility,
6226 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00006227 tag_decl_kind,
Sean Callanan60217122012-04-13 00:10:03 +00006228 class_language,
Jim Ingham379397632012-10-27 02:54:13 +00006229 &metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00006230 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006231 }
6232
6233 // Store a forward declaration to this class type in case any
6234 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00006235 // types for function prototypes.
Greg Clayton57ee3062013-07-11 22:46:58 +00006236 LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00006237 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006238 this,
6239 type_name_const_str,
6240 byte_size,
6241 NULL,
6242 LLDB_INVALID_UID,
6243 Type::eEncodingIsUID,
6244 &decl,
6245 clang_type,
6246 Type::eResolveStateForward));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006247
Sean Callanan72772842012-02-22 23:57:45 +00006248 type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006249
6250
6251 // Add our type to the unique type map so we don't
6252 // end up creating many copies of the same type over
6253 // and over in the ASTContext for our module
Greg Claytond20deac2014-04-04 18:15:18 +00006254 unique_ast_entry_ap->m_type_sp = type_sp;
6255 unique_ast_entry_ap->m_symfile = this;
6256 unique_ast_entry_ap->m_cu = dwarf_cu;
6257 unique_ast_entry_ap->m_die = die;
6258 unique_ast_entry_ap->m_declaration = decl;
6259 unique_ast_entry_ap->m_byte_size = byte_size;
Greg Claytone576ab22011-02-15 00:19:15 +00006260 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
Greg Claytond20deac2014-04-04 18:15:18 +00006261 *unique_ast_entry_ap);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006262
Greg Clayton0ec71a02013-08-10 00:09:35 +00006263 if (is_forward_declaration && die->HasChildren())
6264 {
6265 // Check to see if the DIE actually has a definition, some version of GCC will
6266 // emit DIEs with DW_AT_declaration set to true, but yet still have subprogram,
6267 // members, or inheritance, so we can't trust it
6268 const DWARFDebugInfoEntry *child_die = die->GetFirstChild();
6269 while (child_die)
6270 {
6271 switch (child_die->Tag())
6272 {
6273 case DW_TAG_inheritance:
6274 case DW_TAG_subprogram:
6275 case DW_TAG_member:
6276 case DW_TAG_APPLE_property:
Greg Clayton4c484ec2014-02-07 19:21:56 +00006277 case DW_TAG_class_type:
6278 case DW_TAG_structure_type:
6279 case DW_TAG_enumeration_type:
6280 case DW_TAG_typedef:
6281 case DW_TAG_union_type:
Greg Clayton0ec71a02013-08-10 00:09:35 +00006282 child_die = NULL;
6283 is_forward_declaration = false;
6284 break;
6285 default:
6286 child_die = child_die->GetSibling();
6287 break;
6288 }
6289 }
6290 }
6291
Sean Callanan12014a02011-12-08 23:45:45 +00006292 if (!is_forward_declaration)
Greg Clayton219cf312012-03-30 00:51:13 +00006293 {
6294 // Always start the definition for a class type so that
6295 // if the class has child classes or types that require
6296 // the class to be created for use as their decl contexts
6297 // the class will be ready to accept these child definitions.
Sean Callanan12014a02011-12-08 23:45:45 +00006298 if (die->HasChildren() == false)
6299 {
6300 // No children for this struct/union/class, lets finish it
Greg Clayton57ee3062013-07-11 22:46:58 +00006301 clang_type.StartTagDeclarationDefinition ();
6302 clang_type.CompleteTagDeclarationDefinition ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006303
Sean Callanan433cd222012-10-19 01:37:25 +00006304 if (tag == DW_TAG_structure_type) // this only applies in C
6305 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006306 clang::RecordDecl *record_decl = clang_type.GetAsRecordDecl();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006307
Greg Clayton57ee3062013-07-11 22:46:58 +00006308 if (record_decl)
Greg Claytond20deac2014-04-04 18:15:18 +00006309 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, LayoutInfo()));
Sean Callanan433cd222012-10-19 01:37:25 +00006310 }
Sean Callanan12014a02011-12-08 23:45:45 +00006311 }
6312 else if (clang_type_was_created)
6313 {
Greg Clayton219cf312012-03-30 00:51:13 +00006314 // Start the definition if the class is not objective C since
6315 // the underlying decls respond to isCompleteDefinition(). Objective
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +00006316 // C decls don't respond to isCompleteDefinition() so we can't
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00006317 // start the declaration definition right away. For C++ class/union/structs
Greg Clayton219cf312012-03-30 00:51:13 +00006318 // we want to start the definition in case the class is needed as the
6319 // declaration context for a contained class or type without the need
6320 // to complete that type..
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006321
Sean Callanan7457f8d2012-04-25 01:03:57 +00006322 if (class_language != eLanguageTypeObjC &&
6323 class_language != eLanguageTypeObjC_plus_plus)
Greg Clayton57ee3062013-07-11 22:46:58 +00006324 clang_type.StartTagDeclarationDefinition ();
Greg Clayton219cf312012-03-30 00:51:13 +00006325
Sean Callanan12014a02011-12-08 23:45:45 +00006326 // Leave this as a forward declaration until we need
6327 // to know the details of the type. lldb_private::Type
6328 // will automatically call the SymbolFile virtual function
6329 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
6330 // When the definition needs to be defined.
Greg Clayton57ee3062013-07-11 22:46:58 +00006331 m_forward_decl_die_to_clang_type[die] = clang_type.GetOpaqueQualType();
6332 m_forward_decl_clang_type_to_die[clang_type.RemoveFastQualifiers().GetOpaqueQualType()] = die;
6333 clang_type.SetHasExternalStorage (true);
Sean Callanan12014a02011-12-08 23:45:45 +00006334 }
Greg Claytonc615ce42010-11-09 04:42:43 +00006335 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006336
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006337 }
6338 break;
6339
6340 case DW_TAG_enumeration_type:
6341 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006342 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006343 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006344
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006345 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006346
Greg Claytond88d7592010-09-15 08:33:30 +00006347 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006348 if (num_attributes > 0)
6349 {
6350 uint32_t i;
6351
6352 for (i=0; i<num_attributes; ++i)
6353 {
6354 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006355 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6356 {
6357 switch (attr)
6358 {
Greg Clayton7a345282010-11-09 23:46:37 +00006359 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6360 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6361 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006362 case DW_AT_name:
6363 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006364 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006365 break;
Greg Clayton7a345282010-11-09 23:46:37 +00006366 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006367 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
6368 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006369 case DW_AT_declaration: break; //is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006370 case DW_AT_allocated:
6371 case DW_AT_associated:
6372 case DW_AT_bit_stride:
6373 case DW_AT_byte_stride:
6374 case DW_AT_data_location:
6375 case DW_AT_description:
6376 case DW_AT_start_scope:
6377 case DW_AT_visibility:
6378 case DW_AT_specification:
6379 case DW_AT_abstract_origin:
6380 case DW_AT_sibling:
6381 break;
6382 }
6383 }
6384 }
6385
Daniel Malead01b2952012-11-29 21:49:15 +00006386 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 +00006387
Greg Clayton57ee3062013-07-11 22:46:58 +00006388 ClangASTType enumerator_clang_type;
6389 clang_type.SetClangType (ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die));
6390 if (!clang_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00006391 {
Greg Clayton5d14fc02013-03-06 06:23:54 +00006392 if (encoding_uid != DW_INVALID_OFFSET)
6393 {
6394 Type *enumerator_type = ResolveTypeUID(encoding_uid);
6395 if (enumerator_type)
6396 enumerator_clang_type = enumerator_type->GetClangFullType();
6397 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006398
Greg Clayton57ee3062013-07-11 22:46:58 +00006399 if (!enumerator_clang_type)
Greg Clayton5d14fc02013-03-06 06:23:54 +00006400 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
6401 DW_ATE_signed,
6402 byte_size * 8);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006403
Greg Claytonca512b32011-01-14 04:54:56 +00006404 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00006405 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00006406 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006407 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00006408 }
6409 else
6410 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006411 enumerator_clang_type = clang_type.GetEnumerationIntegerType ();
Greg Clayton1be10fc2010-09-29 01:12:09 +00006412 }
6413
Greg Clayton57ee3062013-07-11 22:46:58 +00006414 LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006415
Greg Clayton81c22f62011-10-19 18:09:39 +00006416 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006417 this,
6418 type_name_const_str,
6419 byte_size,
6420 NULL,
6421 encoding_uid,
6422 Type::eEncodingIsUID,
6423 &decl,
6424 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006425 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006426
Greg Clayton57ee3062013-07-11 22:46:58 +00006427 clang_type.StartTagDeclarationDefinition ();
Greg Clayton6beaaa62011-01-17 03:46:26 +00006428 if (die->HasChildren())
6429 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006430 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00006431 bool is_signed = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00006432 enumerator_clang_type.IsIntegerType(is_signed);
Greg Clayton3e067532013-03-05 23:54:39 +00006433 ParseChildEnumerators(cu_sc, clang_type, is_signed, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00006434 }
Greg Clayton57ee3062013-07-11 22:46:58 +00006435 clang_type.CompleteTagDeclarationDefinition ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006436 }
6437 }
6438 break;
6439
Jim Inghamb0be4422010-08-12 01:20:14 +00006440 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006441 case DW_TAG_subprogram:
6442 case DW_TAG_subroutine_type:
6443 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006444 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006445 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006446
Greg Clayton23f59502012-07-17 03:23:13 +00006447 //const char *mangled = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006448 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00006449 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006450 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00006451 bool is_static = false;
6452 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00006453 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00006454 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00006455 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
6456 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Jim Ingham379397632012-10-27 02:54:13 +00006457 dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00006458
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006459 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00006460 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006461
6462
Greg Claytond88d7592010-09-15 08:33:30 +00006463 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006464 if (num_attributes > 0)
6465 {
6466 uint32_t i;
6467 for (i=0; i<num_attributes; ++i)
6468 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006469 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006470 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6471 {
6472 switch (attr)
6473 {
6474 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6475 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6476 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6477 case DW_AT_name:
6478 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006479 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006480 break;
6481
Greg Clayton71415542012-12-08 00:24:40 +00006482 case DW_AT_linkage_name:
Greg Clayton23f59502012-07-17 03:23:13 +00006483 case DW_AT_MIPS_linkage_name: break; // mangled = form_value.AsCString(&get_debug_str_data()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006484 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00006485 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006486 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
6487 case DW_AT_inline: is_inline = form_value.Boolean(); break;
6488 case DW_AT_virtuality: is_virtual = form_value.Boolean(); break;
6489 case DW_AT_explicit: is_explicit = form_value.Boolean(); break;
6490 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006491
Greg Claytonf51de672010-10-01 02:31:07 +00006492
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006493 case DW_AT_external:
6494 if (form_value.Unsigned())
6495 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00006496 if (storage == clang::SC_None)
6497 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006498 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00006499 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006500 }
6501 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006502
Greg Clayton72da3972011-08-16 18:40:23 +00006503 case DW_AT_specification:
6504 specification_die_offset = form_value.Reference(dwarf_cu);
6505 break;
6506
6507 case DW_AT_abstract_origin:
6508 abstract_origin_die_offset = form_value.Reference(dwarf_cu);
6509 break;
6510
Jim Ingham379397632012-10-27 02:54:13 +00006511 case DW_AT_object_pointer:
6512 object_pointer_die_offset = form_value.Reference(dwarf_cu);
6513 break;
6514
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006515 case DW_AT_allocated:
6516 case DW_AT_associated:
6517 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006518 case DW_AT_calling_convention:
6519 case DW_AT_data_location:
6520 case DW_AT_elemental:
6521 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006522 case DW_AT_frame_base:
6523 case DW_AT_high_pc:
6524 case DW_AT_low_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006525 case DW_AT_prototyped:
6526 case DW_AT_pure:
6527 case DW_AT_ranges:
6528 case DW_AT_recursive:
6529 case DW_AT_return_addr:
6530 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006531 case DW_AT_start_scope:
6532 case DW_AT_static_link:
6533 case DW_AT_trampoline:
6534 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006535 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006536 case DW_AT_description:
6537 case DW_AT_sibling:
6538 break;
6539 }
6540 }
6541 }
Greg Clayton24739922010-10-13 03:15:28 +00006542 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006543
Jim Ingham379397632012-10-27 02:54:13 +00006544 std::string object_pointer_name;
6545 if (object_pointer_die_offset != DW_INVALID_OFFSET)
6546 {
6547 // Get the name from the object pointer die
6548 StreamString s;
6549 if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s))
6550 {
6551 object_pointer_name.assign(s.GetData());
6552 }
6553 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006554
Daniel Malead01b2952012-11-29 21:49:15 +00006555 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 +00006556
Greg Clayton57ee3062013-07-11 22:46:58 +00006557 ClangASTType return_clang_type;
Greg Clayton24739922010-10-13 03:15:28 +00006558 Type *func_type = NULL;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006559
Greg Clayton24739922010-10-13 03:15:28 +00006560 if (type_die_offset != DW_INVALID_OFFSET)
6561 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00006562
Greg Clayton24739922010-10-13 03:15:28 +00006563 if (func_type)
Greg Clayton42ce2f32011-12-12 21:50:19 +00006564 return_clang_type = func_type->GetClangForwardType();
Greg Clayton24739922010-10-13 03:15:28 +00006565 else
Greg Clayton57ee3062013-07-11 22:46:58 +00006566 return_clang_type = ast.GetBasicType(eBasicTypeVoid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006567
Greg Claytonf51de672010-10-01 02:31:07 +00006568
Greg Clayton57ee3062013-07-11 22:46:58 +00006569 std::vector<ClangASTType> function_param_types;
Greg Clayton24739922010-10-13 03:15:28 +00006570 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006571
Greg Clayton24739922010-10-13 03:15:28 +00006572 // Parse the function children for the parameters
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006573
Greg Claytoncb5860a2011-10-13 23:49:28 +00006574 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
6575 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00006576 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
6577
Greg Claytonf0705c82011-10-22 03:33:13 +00006578 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00006579 // Start off static. This will be set to false in ParseChildParameters(...)
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00006580 // if we find a "this" parameters as the first parameter
Greg Clayton5113dc82011-08-12 06:47:54 +00006581 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00006582 is_static = true;
Greg Claytond20deac2014-04-04 18:15:18 +00006583
Greg Clayton24739922010-10-13 03:15:28 +00006584 if (die->HasChildren())
6585 {
Greg Clayton0fffff52010-09-24 05:15:53 +00006586 bool skip_artificial = true;
Jim Ingham379397632012-10-27 02:54:13 +00006587 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00006588 containing_decl_ctx,
Jim Ingham379397632012-10-27 02:54:13 +00006589 dwarf_cu,
6590 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00006591 skip_artificial,
6592 is_static,
Greg Clayton03969752014-02-24 18:53:11 +00006593 is_variadic,
Jim Ingham379397632012-10-27 02:54:13 +00006594 type_list,
6595 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00006596 function_param_decls,
Greg Claytond20deac2014-04-04 18:15:18 +00006597 type_quals);
Greg Clayton24739922010-10-13 03:15:28 +00006598 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006599
Greg Clayton24739922010-10-13 03:15:28 +00006600 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006601 clang_type = ast.CreateFunctionType (return_clang_type,
Greg Clayton9cb25c42012-10-30 17:02:18 +00006602 function_param_types.data(),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006603 function_param_types.size(),
6604 is_variadic,
6605 type_quals);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006606
Sean Callanande9ce872013-05-09 23:13:13 +00006607 bool ignore_containing_context = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006608
Greg Clayton24739922010-10-13 03:15:28 +00006609 if (type_name_cstr)
6610 {
6611 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00006612 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006613 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00006614 ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true);
6615 if (objc_method.IsValid(true))
Greg Clayton0fffff52010-09-24 05:15:53 +00006616 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006617 ClangASTType class_opaque_type;
Greg Clayton1b3815c2013-01-30 00:18:29 +00006618 ConstString class_name(objc_method.GetClassName());
Greg Clayton7c810422012-01-18 23:40:49 +00006619 if (class_name)
Greg Clayton0fffff52010-09-24 05:15:53 +00006620 {
Greg Clayton278a16b2012-01-19 00:52:59 +00006621 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
Greg Claytonc7f03b62012-01-12 04:33:28 +00006622
6623 if (complete_objc_class_type_sp)
Greg Clayton0fffff52010-09-24 05:15:53 +00006624 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006625 ClangASTType type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
6626 if (type_clang_forward_type.IsObjCObjectOrInterfaceType ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00006627 class_opaque_type = type_clang_forward_type;
Greg Clayton0fffff52010-09-24 05:15:53 +00006628 }
Greg Clayton24739922010-10-13 03:15:28 +00006629 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006630
Greg Clayton24739922010-10-13 03:15:28 +00006631 if (class_opaque_type)
6632 {
6633 // If accessibility isn't set to anything valid, assume public for
6634 // now...
6635 if (accessibility == eAccessNone)
6636 accessibility = eAccessPublic;
6637
Greg Clayton57ee3062013-07-11 22:46:58 +00006638 clang::ObjCMethodDecl *objc_method_decl = class_opaque_type.AddMethodToObjCObjectType (type_name_cstr,
6639 clang_type,
6640 accessibility,
6641 is_artificial);
Greg Clayton24739922010-10-13 03:15:28 +00006642 type_handled = objc_method_decl != NULL;
Sean Callanan464a5b52012-10-04 22:06:29 +00006643 if (type_handled)
6644 {
6645 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Claytond0029442013-03-27 01:48:02 +00006646 GetClangASTContext().SetMetadataAsUserID (objc_method_decl, MakeUserID(die->GetOffset()));
Sean Callanan464a5b52012-10-04 22:06:29 +00006647 }
Sean Callananc3a1d562013-02-06 23:21:59 +00006648 else
6649 {
Jason Molendac1a65832013-03-07 22:44:42 +00006650 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 +00006651 die->GetOffset(),
6652 tag,
6653 DW_TAG_value_to_name(tag));
6654 }
Greg Clayton24739922010-10-13 03:15:28 +00006655 }
6656 }
Greg Clayton5113dc82011-08-12 06:47:54 +00006657 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00006658 {
6659 // Look at the parent of this DIE and see if is is
6660 // a class or struct and see if this is actually a
6661 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00006662 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00006663 if (class_type)
6664 {
Greg Clayton4116e932012-05-15 02:33:01 +00006665 if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset()))
6666 {
6667 // We uniqued the parent class of this function to another class
6668 // so we now need to associate all dies under "decl_ctx_die" to
6669 // DIEs in the DIE for "class_type"...
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006670 SymbolFileDWARF *class_symfile = NULL;
Greg Clayton4116e932012-05-15 02:33:01 +00006671 DWARFCompileUnitSP class_type_cu_sp;
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006672 const DWARFDebugInfoEntry *class_type_die = NULL;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006673
Sean Callanan2367f8a2013-02-26 01:12:25 +00006674 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
6675 if (debug_map_symfile)
6676 {
6677 class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID()));
6678 class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6679 }
6680 else
6681 {
6682 class_symfile = this;
6683 class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6684 }
Greg Clayton4116e932012-05-15 02:33:01 +00006685 if (class_type_die)
6686 {
Greg Claytond20deac2014-04-04 18:15:18 +00006687 DWARFDIECollection failures;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006688
Sean Callanan2367f8a2013-02-26 01:12:25 +00006689 CopyUniqueClassMethodTypes (class_symfile,
6690 class_type,
6691 class_type_cu_sp.get(),
6692 class_type_die,
6693 dwarf_cu,
6694 decl_ctx_die,
6695 failures);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006696
Sean Callanan2367f8a2013-02-26 01:12:25 +00006697 // FIXME do something with these failures that's smarter than
6698 // just dropping them on the ground. Unfortunately classes don't
6699 // like having stuff added to them after their definitions are
6700 // complete...
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006701
Sean Callanan2367f8a2013-02-26 01:12:25 +00006702 type_ptr = m_die_to_type[die];
6703 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton4116e932012-05-15 02:33:01 +00006704 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006705 type_sp = type_ptr->shared_from_this();
6706 break;
Greg Clayton4116e932012-05-15 02:33:01 +00006707 }
6708 }
6709 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006710
Greg Clayton72da3972011-08-16 18:40:23 +00006711 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00006712 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006713 // We have a specification which we are going to base our function
6714 // prototype off of, so we need this type to be completed so that the
6715 // m_die_to_decl_ctx for the method in the specification has a valid
6716 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006717 class_type->GetClangForwardType();
Greg Clayton72da3972011-08-16 18:40:23 +00006718 // If we have a specification, then the function type should have been
6719 // made with the specification and not with this die.
6720 DWARFCompileUnitSP spec_cu_sp;
6721 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006722 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006723 if (spec_clang_decl_ctx)
6724 {
6725 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
6726 }
6727 else
Jim Inghamc1663042011-09-29 22:12:35 +00006728 {
Daniel Malead01b2952012-11-29 21:49:15 +00006729 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8x) has no decl\n",
Greg Claytone38a5ed2012-01-05 03:57:59 +00006730 MakeUserID(die->GetOffset()),
6731 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006732 }
Greg Clayton72da3972011-08-16 18:40:23 +00006733 type_handled = true;
6734 }
6735 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
6736 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006737 // We have a specification which we are going to base our function
6738 // prototype off of, so we need this type to be completed so that the
6739 // m_die_to_decl_ctx for the method in the abstract origin has a valid
6740 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006741 class_type->GetClangForwardType();
Greg Clayton5cf58b92011-10-05 22:22:08 +00006742
Greg Clayton72da3972011-08-16 18:40:23 +00006743 DWARFCompileUnitSP abs_cu_sp;
6744 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006745 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006746 if (abs_clang_decl_ctx)
6747 {
6748 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
6749 }
6750 else
Jim Inghamc1663042011-09-29 22:12:35 +00006751 {
Daniel Malead01b2952012-11-29 21:49:15 +00006752 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 +00006753 MakeUserID(die->GetOffset()),
6754 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006755 }
Greg Clayton72da3972011-08-16 18:40:23 +00006756 type_handled = true;
6757 }
6758 else
6759 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006760 ClangASTType class_opaque_type = class_type->GetClangForwardType();
6761 if (class_opaque_type.IsCXXClassType ())
Greg Clayton931180e2011-01-27 06:44:37 +00006762 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006763 if (class_opaque_type.IsBeingDefined ())
Greg Clayton72da3972011-08-16 18:40:23 +00006764 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006765 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
6766 // in the DWARF for C++ methods... Default to public for now...
6767 if (accessibility == eAccessNone)
6768 accessibility = eAccessPublic;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006769
Greg Clayton20568dd2011-10-13 23:13:20 +00006770 if (!is_static && !die->HasChildren())
6771 {
6772 // We have a C++ member function with no children (this pointer!)
6773 // and clang will get mad if we try and make a function that isn't
6774 // well formed in the DWARF, so we will just skip it...
6775 type_handled = true;
6776 }
6777 else
6778 {
6779 clang::CXXMethodDecl *cxx_method_decl;
6780 // REMOVE THE CRASH DESCRIPTION BELOW
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00006781 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 +00006782 type_name_cstr,
6783 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00006784 MakeUserID(die->GetOffset()),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00006785 m_obj_file->GetFileSpec().GetPath().c_str());
Greg Clayton20568dd2011-10-13 23:13:20 +00006786
Sean Callananc1b732d2011-11-01 18:07:13 +00006787 const bool is_attr_used = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006788
Greg Clayton57ee3062013-07-11 22:46:58 +00006789 cxx_method_decl = class_opaque_type.AddMethodToCXXRecordType (type_name_cstr,
6790 clang_type,
6791 accessibility,
6792 is_virtual,
6793 is_static,
6794 is_inline,
6795 is_explicit,
6796 is_attr_used,
6797 is_artificial);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006798
Greg Clayton20568dd2011-10-13 23:13:20 +00006799 type_handled = cxx_method_decl != NULL;
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006800
6801 if (type_handled)
Jim Ingham379397632012-10-27 02:54:13 +00006802 {
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006803 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
6804
6805 Host::SetCrashDescription (NULL);
6806
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006807
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006808 ClangASTMetadata metadata;
6809 metadata.SetUserID(MakeUserID(die->GetOffset()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006810
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006811 if (!object_pointer_name.empty())
6812 {
6813 metadata.SetObjectPtrName(object_pointer_name.c_str());
6814 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006815 log->Printf ("Setting object pointer name: %s on method object %p.\n",
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006816 object_pointer_name.c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006817 static_cast<void*>(cxx_method_decl));
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006818 }
Greg Claytond0029442013-03-27 01:48:02 +00006819 GetClangASTContext().SetMetadata (cxx_method_decl, metadata);
Jim Ingham379397632012-10-27 02:54:13 +00006820 }
Sean Callananb0640dc2013-04-09 23:22:08 +00006821 else
6822 {
Sean Callanande9ce872013-05-09 23:13:13 +00006823 ignore_containing_context = true;
Sean Callananb0640dc2013-04-09 23:22:08 +00006824 }
Greg Clayton20568dd2011-10-13 23:13:20 +00006825 }
Greg Clayton72da3972011-08-16 18:40:23 +00006826 }
6827 else
6828 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006829 // We were asked to parse the type for a method in a class, yet the
6830 // class hasn't been asked to complete itself through the
6831 // clang::ExternalASTSource protocol, so we need to just have the
6832 // class complete itself and do things the right way, then our
6833 // DIE should then have an entry in the m_die_to_type map. First
6834 // we need to modify the m_die_to_type so it doesn't think we are
6835 // trying to parse this DIE anymore...
6836 m_die_to_type[die] = NULL;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006837
Greg Clayton20568dd2011-10-13 23:13:20 +00006838 // Now we get the full type to force our class type to complete itself
6839 // using the clang::ExternalASTSource protocol which will parse all
6840 // base classes and all methods (including the method for this DIE).
6841 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00006842
Greg Clayton20568dd2011-10-13 23:13:20 +00006843 // The type for this DIE should have been filled in the function call above
6844 type_ptr = m_die_to_type[die];
Greg Claytone5476db2012-06-01 20:32:35 +00006845 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton20568dd2011-10-13 23:13:20 +00006846 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006847 type_sp = type_ptr->shared_from_this();
Greg Clayton20568dd2011-10-13 23:13:20 +00006848 break;
6849 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006850
Sean Callanan02eee4d2012-04-12 23:10:00 +00006851 // FIXME This is fixing some even uglier behavior but we really need to
6852 // uniq the methods of each class as well as the class itself.
6853 // <rdar://problem/11240464>
6854 type_handled = true;
Greg Clayton72da3972011-08-16 18:40:23 +00006855 }
Greg Clayton931180e2011-01-27 06:44:37 +00006856 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006857 }
6858 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006859 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006860 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006861
Greg Clayton24739922010-10-13 03:15:28 +00006862 if (!type_handled)
6863 {
6864 // We just have a function that isn't part of a class
Sean Callanande9ce872013-05-09 23:13:13 +00006865 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (ignore_containing_context ? GetClangASTContext().GetTranslationUnitDecl() : containing_decl_ctx,
Greg Clayton147e1fa2011-10-14 22:47:18 +00006866 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006867 clang_type,
6868 storage,
6869 is_inline);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006870
6871// if (template_param_infos.GetSize() > 0)
6872// {
6873// clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
6874// function_decl,
6875// type_name_cstr,
6876// template_param_infos);
6877//
6878// ast.CreateFunctionTemplateSpecializationInfo (function_decl,
6879// func_template_decl,
6880// template_param_infos);
6881// }
Greg Clayton24739922010-10-13 03:15:28 +00006882 // Add the decl to our DIE to decl context map
6883 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00006884 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00006885 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006886 ast.SetFunctionParameters (function_decl,
6887 &function_param_decls.front(),
6888 function_param_decls.size());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006889
Jim Ingham379397632012-10-27 02:54:13 +00006890 ClangASTMetadata metadata;
6891 metadata.SetUserID(MakeUserID(die->GetOffset()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006892
Jim Ingham379397632012-10-27 02:54:13 +00006893 if (!object_pointer_name.empty())
6894 {
6895 metadata.SetObjectPtrName(object_pointer_name.c_str());
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006896 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006897 log->Printf ("Setting object pointer name: %s on function object %p.",
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006898 object_pointer_name.c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006899 static_cast<void*>(function_decl));
Jim Ingham379397632012-10-27 02:54:13 +00006900 }
Greg Claytond0029442013-03-27 01:48:02 +00006901 GetClangASTContext().SetMetadata (function_decl, metadata);
Greg Clayton24739922010-10-13 03:15:28 +00006902 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006903 }
Greg Clayton81c22f62011-10-19 18:09:39 +00006904 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006905 this,
6906 type_name_const_str,
6907 0,
6908 NULL,
6909 LLDB_INVALID_UID,
6910 Type::eEncodingIsUID,
6911 &decl,
6912 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006913 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00006914 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006915 }
6916 break;
6917
6918 case DW_TAG_array_type:
6919 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006920 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006921 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006922
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006923 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006924 int64_t first_index = 0;
6925 uint32_t byte_stride = 0;
6926 uint32_t bit_stride = 0;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006927 bool is_vector = false;
Greg Claytond88d7592010-09-15 08:33:30 +00006928 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006929
6930 if (num_attributes > 0)
6931 {
6932 uint32_t i;
6933 for (i=0; i<num_attributes; ++i)
6934 {
6935 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006936 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6937 {
6938 switch (attr)
6939 {
6940 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6941 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6942 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6943 case DW_AT_name:
6944 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006945 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006946 break;
6947
6948 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006949 case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006950 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
6951 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006952 case DW_AT_GNU_vector: is_vector = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006953 case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006954 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006955 case DW_AT_allocated:
6956 case DW_AT_associated:
6957 case DW_AT_data_location:
6958 case DW_AT_description:
6959 case DW_AT_ordering:
6960 case DW_AT_start_scope:
6961 case DW_AT_visibility:
6962 case DW_AT_specification:
6963 case DW_AT_abstract_origin:
6964 case DW_AT_sibling:
6965 break;
6966 }
6967 }
6968 }
6969
Daniel Malead01b2952012-11-29 21:49:15 +00006970 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 +00006971
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006972 Type *element_type = ResolveTypeUID(type_die_offset);
6973
6974 if (element_type)
6975 {
6976 std::vector<uint64_t> element_orders;
6977 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
6978 if (byte_stride == 0 && bit_stride == 0)
6979 byte_stride = element_type->GetByteSize();
Greg Clayton57ee3062013-07-11 22:46:58 +00006980 ClangASTType array_element_type = element_type->GetClangForwardType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006981 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
6982 uint64_t num_elements = 0;
6983 std::vector<uint64_t>::const_reverse_iterator pos;
6984 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
6985 for (pos = element_orders.rbegin(); pos != end; ++pos)
6986 {
6987 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006988 clang_type = ast.CreateArrayType (array_element_type,
Greg Clayton1c8ef472013-04-05 23:27:21 +00006989 num_elements,
6990 is_vector);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006991 array_element_type = clang_type;
Greg Clayton4ef877f2012-12-06 02:33:54 +00006992 array_element_bit_stride = num_elements ? array_element_bit_stride * num_elements : array_element_bit_stride;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006993 }
6994 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00006995 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006996 this,
6997 empty_name,
6998 array_element_bit_stride / 8,
6999 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00007000 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00007001 Type::eEncodingIsUID,
7002 &decl,
7003 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00007004 Type::eResolveStateFull));
7005 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007006 }
7007 }
7008 }
7009 break;
7010
Greg Clayton9b81a312010-06-12 01:20:30 +00007011 case DW_TAG_ptr_to_member_type:
7012 {
7013 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
7014 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
7015
Greg Claytond88d7592010-09-15 08:33:30 +00007016 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007017
Greg Clayton9b81a312010-06-12 01:20:30 +00007018 if (num_attributes > 0) {
7019 uint32_t i;
7020 for (i=0; i<num_attributes; ++i)
7021 {
7022 attr = attributes.AttributeAtIndex(i);
Greg Clayton9b81a312010-06-12 01:20:30 +00007023 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
7024 {
7025 switch (attr)
7026 {
7027 case DW_AT_type:
7028 type_die_offset = form_value.Reference(dwarf_cu); break;
7029 case DW_AT_containing_type:
7030 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
7031 }
7032 }
7033 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007034
Greg Clayton9b81a312010-06-12 01:20:30 +00007035 Type *pointee_type = ResolveTypeUID(type_die_offset);
7036 Type *class_type = ResolveTypeUID(containing_type_die_offset);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007037
Greg Clayton57ee3062013-07-11 22:46:58 +00007038 ClangASTType pointee_clang_type = pointee_type->GetClangForwardType();
7039 ClangASTType class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00007040
Greg Clayton57ee3062013-07-11 22:46:58 +00007041 clang_type = pointee_clang_type.CreateMemberPointerType(class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00007042
Greg Clayton57ee3062013-07-11 22:46:58 +00007043 byte_size = clang_type.GetByteSize();
Greg Clayton9b81a312010-06-12 01:20:30 +00007044
Greg Clayton81c22f62011-10-19 18:09:39 +00007045 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00007046 this,
7047 type_name_const_str,
7048 byte_size,
7049 NULL,
7050 LLDB_INVALID_UID,
7051 Type::eEncodingIsUID,
7052 NULL,
7053 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00007054 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00007055 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007056
Greg Clayton9b81a312010-06-12 01:20:30 +00007057 break;
7058 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007059 default:
Greg Clayton84afacd2012-11-07 23:09:32 +00007060 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",
7061 die->GetOffset(),
7062 tag,
7063 DW_TAG_value_to_name(tag));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007064 break;
7065 }
7066
7067 if (type_sp.get())
7068 {
7069 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7070 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7071
7072 SymbolContextScope * symbol_context_scope = NULL;
7073 if (sc_parent_tag == DW_TAG_compile_unit)
7074 {
7075 symbol_context_scope = sc.comp_unit;
7076 }
7077 else if (sc.function != NULL)
7078 {
Greg Clayton81c22f62011-10-19 18:09:39 +00007079 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007080 if (symbol_context_scope == NULL)
7081 symbol_context_scope = sc.function;
7082 }
7083
7084 if (symbol_context_scope != NULL)
7085 {
7086 type_sp->SetSymbolContextScope(symbol_context_scope);
7087 }
7088
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00007089 // We are ready to put this type into the uniqued list up at the module level
7090 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00007091
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00007092 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007093 }
7094 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00007095 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007096 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00007097 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007098 }
7099 }
7100 return type_sp;
7101}
7102
7103size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00007104SymbolFileDWARF::ParseTypes
7105(
7106 const SymbolContext& sc,
7107 DWARFCompileUnit* dwarf_cu,
7108 const DWARFDebugInfoEntry *die,
7109 bool parse_siblings,
7110 bool parse_children
7111)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007112{
7113 size_t types_added = 0;
7114 while (die != NULL)
7115 {
7116 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00007117 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007118 {
7119 if (type_is_new)
7120 ++types_added;
7121 }
7122
7123 if (parse_children && die->HasChildren())
7124 {
7125 if (die->Tag() == DW_TAG_subprogram)
7126 {
7127 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00007128 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007129 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
7130 }
7131 else
7132 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
7133 }
7134
7135 if (parse_siblings)
7136 die = die->GetSibling();
7137 else
7138 die = NULL;
7139 }
7140 return types_added;
7141}
7142
7143
7144size_t
7145SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
7146{
7147 assert(sc.comp_unit && sc.function);
7148 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00007149 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007150 if (dwarf_cu)
7151 {
7152 dw_offset_t function_die_offset = sc.function->GetID();
7153 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
7154 if (function_die)
7155 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00007156 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007157 }
7158 }
7159
7160 return functions_added;
7161}
7162
7163
7164size_t
7165SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
7166{
7167 // At least a compile unit must be valid
7168 assert(sc.comp_unit);
7169 size_t types_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00007170 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007171 if (dwarf_cu)
7172 {
7173 if (sc.function)
7174 {
7175 dw_offset_t function_die_offset = sc.function->GetID();
7176 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
7177 if (func_die && func_die->HasChildren())
7178 {
7179 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
7180 }
7181 }
7182 else
7183 {
7184 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
7185 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
7186 {
7187 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
7188 }
7189 }
7190 }
7191
7192 return types_added;
7193}
7194
7195size_t
7196SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
7197{
7198 if (sc.comp_unit != NULL)
7199 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00007200 DWARFDebugInfo* info = DebugInfo();
7201 if (info == NULL)
7202 return 0;
7203
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007204 if (sc.function)
7205 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007206 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get();
7207
7208 if (dwarf_cu == NULL)
7209 return 0;
7210
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007211 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00007212
Greg Claytonc7bece562013-01-25 18:06:21 +00007213 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
7214 if (func_lo_pc != LLDB_INVALID_ADDRESS)
Greg Claytone38a5ed2012-01-05 03:57:59 +00007215 {
7216 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00007217
Greg Claytone38a5ed2012-01-05 03:57:59 +00007218 // Let all blocks know they have parse all their variables
7219 sc.function->GetBlock (false).SetDidParseVariables (true, true);
7220 return num_variables;
7221 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007222 }
7223 else if (sc.comp_unit)
7224 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007225 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get();
7226
7227 if (dwarf_cu == NULL)
7228 return 0;
7229
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007230 uint32_t vars_added = 0;
7231 VariableListSP variables (sc.comp_unit->GetVariableList(false));
7232
7233 if (variables.get() == NULL)
7234 {
7235 variables.reset(new VariableList());
7236 sc.comp_unit->SetVariableList(variables);
7237
Greg Claytond4a2b372011-09-12 23:21:58 +00007238 DWARFCompileUnit* match_dwarf_cu = NULL;
7239 const DWARFDebugInfoEntry* die = NULL;
7240 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00007241 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00007242 {
Greg Clayton97fbc342011-10-20 22:30:33 +00007243 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00007244 {
7245 DWARFMappedHash::DIEInfoArray hash_data_array;
7246 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
7247 dwarf_cu->GetNextCompileUnitOffset(),
7248 hash_data_array))
7249 {
7250 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
7251 }
7252 }
Greg Clayton7f995132011-10-04 22:41:51 +00007253 }
7254 else
7255 {
7256 // Index if we already haven't to make sure the compile units
7257 // get indexed and make their global DIE index list
7258 if (!m_indexed)
7259 Index ();
7260
7261 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
7262 dwarf_cu->GetNextCompileUnitOffset(),
7263 die_offsets);
7264 }
7265
7266 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00007267 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007268 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007269 DWARFDebugInfo* debug_info = DebugInfo();
7270 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007271 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007272 const dw_offset_t die_offset = die_offsets[i];
7273 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00007274 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00007275 {
Greg Clayton95d87902011-11-11 03:16:25 +00007276 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
7277 if (var_sp)
7278 {
7279 variables->AddVariableIfUnique (var_sp);
7280 ++vars_added;
7281 }
Greg Claytond4a2b372011-09-12 23:21:58 +00007282 }
Greg Clayton95d87902011-11-11 03:16:25 +00007283 else
7284 {
7285 if (m_using_apple_tables)
7286 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00007287 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 +00007288 }
7289 }
7290
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007291 }
7292 }
7293 }
7294 return vars_added;
7295 }
7296 }
7297 return 0;
7298}
7299
7300
7301VariableSP
7302SymbolFileDWARF::ParseVariableDIE
7303(
7304 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007305 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007306 const DWARFDebugInfoEntry *die,
7307 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007308)
7309{
7310
Greg Clayton83c5cd92010-11-14 22:13:40 +00007311 VariableSP var_sp (m_die_to_variable_sp[die]);
7312 if (var_sp)
7313 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007314
7315 const dw_tag_t tag = die->Tag();
Richard Mitton0a558352013-10-17 21:14:00 +00007316 ModuleSP module = GetObjectFile()->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00007317
7318 if ((tag == DW_TAG_variable) ||
7319 (tag == DW_TAG_constant) ||
7320 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007321 {
Greg Clayton7f995132011-10-04 22:41:51 +00007322 DWARFDebugInfoEntry::Attributes attributes;
7323 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
7324 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007325 {
Greg Clayton7f995132011-10-04 22:41:51 +00007326 const char *name = NULL;
7327 const char *mangled = NULL;
7328 Declaration decl;
7329 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00007330 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00007331 DWARFExpression location;
7332 bool is_external = false;
7333 bool is_artificial = false;
7334 bool location_is_const_value_data = false;
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007335 bool has_explicit_location = false;
Enrico Granata4ec130d2014-08-11 19:16:35 +00007336 DWARFFormValue const_value;
Greg Clayton23f59502012-07-17 03:23:13 +00007337 //AccessType accessibility = eAccessNone;
Greg Clayton7f995132011-10-04 22:41:51 +00007338
7339 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007340 {
Greg Clayton7f995132011-10-04 22:41:51 +00007341 dw_attr_t attr = attributes.AttributeAtIndex(i);
7342 DWARFFormValue form_value;
7343 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007344 {
Greg Clayton7f995132011-10-04 22:41:51 +00007345 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007346 {
Greg Clayton7f995132011-10-04 22:41:51 +00007347 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
7348 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
7349 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
7350 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton71415542012-12-08 00:24:40 +00007351 case DW_AT_linkage_name:
Greg Clayton7f995132011-10-04 22:41:51 +00007352 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Claytond1767f02011-12-08 02:13:16 +00007353 case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00007354 case DW_AT_external: is_external = form_value.Boolean(); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007355 case DW_AT_const_value:
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007356 // If we have already found a DW_AT_location attribute, ignore this attribute.
7357 if (!has_explicit_location)
7358 {
7359 location_is_const_value_data = true;
7360 // The constant value will be either a block, a data value or a string.
Ed Masteeeae7212013-10-24 20:43:47 +00007361 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007362 if (DWARFFormValue::IsBlockForm(form_value.Form()))
7363 {
7364 // Retrieve the value as a block expression.
7365 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7366 uint32_t block_length = form_value.Unsigned();
Richard Mitton0a558352013-10-17 21:14:00 +00007367 location.CopyOpcodeData(module, debug_info_data, block_offset, block_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007368 }
7369 else if (DWARFFormValue::IsDataForm(form_value.Form()))
7370 {
7371 // Retrieve the value as a data expression.
7372 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
7373 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7374 uint32_t data_length = fixed_form_sizes[form_value.Form()];
Enrico Granata4ec130d2014-08-11 19:16:35 +00007375 if (data_length == 0)
7376 {
7377 const uint8_t *data_pointer = form_value.BlockData();
7378 if (data_pointer)
7379 {
7380 data_length = form_value.Unsigned();
7381 }
7382 else if (DWARFFormValue::IsDataForm(form_value.Form()))
7383 {
7384 // we need to get the byte size of the type later after we create the variable
7385 const_value = form_value;
7386 }
7387 }
7388 else
7389 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007390 }
7391 else
7392 {
7393 // Retrieve the value as a string expression.
7394 if (form_value.Form() == DW_FORM_strp)
7395 {
7396 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
7397 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7398 uint32_t data_length = fixed_form_sizes[form_value.Form()];
Richard Mitton0a558352013-10-17 21:14:00 +00007399 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007400 }
7401 else
7402 {
7403 const char *str = form_value.AsCString(&debug_info_data);
7404 uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart();
7405 uint32_t string_length = strlen(str) + 1;
Richard Mitton0a558352013-10-17 21:14:00 +00007406 location.CopyOpcodeData(module, debug_info_data, string_offset, string_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007407 }
7408 }
7409 }
7410 break;
Greg Clayton7f995132011-10-04 22:41:51 +00007411 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007412 {
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007413 location_is_const_value_data = false;
7414 has_explicit_location = true;
Greg Clayton7f995132011-10-04 22:41:51 +00007415 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007416 {
Ed Masteeeae7212013-10-24 20:43:47 +00007417 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Clayton7f995132011-10-04 22:41:51 +00007418
7419 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7420 uint32_t block_length = form_value.Unsigned();
Richard Mitton0a558352013-10-17 21:14:00 +00007421 location.CopyOpcodeData(module, get_debug_info_data(), block_offset, block_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007422 }
7423 else
7424 {
Ed Masteeeae7212013-10-24 20:43:47 +00007425 const DWARFDataExtractor& debug_loc_data = get_debug_loc_data();
Greg Clayton7f995132011-10-04 22:41:51 +00007426 const dw_offset_t debug_loc_offset = form_value.Unsigned();
7427
7428 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
7429 if (loc_list_length > 0)
7430 {
Richard Mitton0a558352013-10-17 21:14:00 +00007431 location.CopyOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007432 assert (func_low_pc != LLDB_INVALID_ADDRESS);
7433 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
7434 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007435 }
7436 }
Greg Clayton7f995132011-10-04 22:41:51 +00007437 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007438
Greg Clayton1c8ef472013-04-05 23:27:21 +00007439 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00007440 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007441 case DW_AT_declaration:
7442 case DW_AT_description:
7443 case DW_AT_endianity:
7444 case DW_AT_segment:
7445 case DW_AT_start_scope:
7446 case DW_AT_visibility:
7447 default:
7448 case DW_AT_abstract_origin:
7449 case DW_AT_sibling:
7450 case DW_AT_specification:
7451 break;
7452 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007453 }
7454 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007455
Greg Clayton9e9f2192013-05-17 00:55:28 +00007456 ValueType scope = eValueTypeInvalid;
7457
7458 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7459 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7460 SymbolContextScope * symbol_context_scope = NULL;
7461
7462 // DWARF doesn't specify if a DW_TAG_variable is a local, global
7463 // or static variable, so we have to do a little digging by
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00007464 // looking at the location of a variable to see if it contains
Greg Clayton9e9f2192013-05-17 00:55:28 +00007465 // a DW_OP_addr opcode _somewhere_ in the definition. I say
7466 // somewhere because clang likes to combine small global variables
7467 // into the same symbol and have locations like:
7468 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
7469 // So if we don't have a DW_TAG_formal_parameter, we can look at
7470 // the location to see if it contains a DW_OP_addr opcode, and
7471 // then we can correctly classify our variables.
7472 if (tag == DW_TAG_formal_parameter)
7473 scope = eValueTypeVariableArgument;
7474 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007475 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007476 bool op_error = false;
7477 // Check if the location has a DW_OP_addr with any address value...
7478 lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS;
7479 if (!location_is_const_value_data)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007480 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007481 location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error);
7482 if (op_error)
Greg Clayton96c09682012-01-04 22:56:43 +00007483 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007484 StreamString strm;
7485 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
7486 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 +00007487 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007488 }
Greg Claytond1767f02011-12-08 02:13:16 +00007489
Greg Clayton9e9f2192013-05-17 00:55:28 +00007490 if (location_DW_OP_addr != LLDB_INVALID_ADDRESS)
7491 {
7492 if (is_external)
7493 scope = eValueTypeVariableGlobal;
7494 else
7495 scope = eValueTypeVariableStatic;
7496
7497
7498 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile ();
7499
7500 if (debug_map_symfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007501 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007502 // When leaving the DWARF in the .o files on darwin,
7503 // when we have a global variable that wasn't initialized,
7504 // the .o file might not have allocated a virtual
7505 // address for the global variable. In this case it will
7506 // have created a symbol for the global variable
7507 // that is undefined/data and external and the value will
7508 // be the byte size of the variable. When we do the
7509 // address map in SymbolFileDWARFDebugMap we rely on
7510 // having an address, we need to do some magic here
7511 // so we can get the correct address for our global
7512 // variable. The address for all of these entries
7513 // will be zero, and there will be an undefined symbol
7514 // in this object file, and the executable will have
7515 // a matching symbol with a good address. So here we
7516 // dig up the correct address and replace it in the
7517 // location for the variable, and set the variable's
7518 // symbol context scope to be that of the main executable
7519 // so the file address will resolve correctly.
7520 bool linked_oso_file_addr = false;
7521 if (is_external && location_DW_OP_addr == 0)
Greg Clayton9422dd62013-03-04 21:46:16 +00007522 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007523 // we have a possible uninitialized extern global
7524 ConstString const_name(mangled ? mangled : name);
7525 ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile();
7526 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007527 {
Greg Clayton3046e662013-07-10 01:23:25 +00007528 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
Greg Clayton9e9f2192013-05-17 00:55:28 +00007529 if (debug_map_symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007530 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007531 Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
7532 eSymbolTypeData,
7533 Symtab::eDebugYes,
7534 Symtab::eVisibilityExtern);
7535 if (exe_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007536 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007537 if (exe_symbol->ValueIsAddress())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007538 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007539 const addr_t exe_file_addr = exe_symbol->GetAddress().GetFileAddress();
7540 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007541 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007542 if (location.Update_DW_OP_addr (exe_file_addr))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007543 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007544 linked_oso_file_addr = true;
7545 symbol_context_scope = exe_symbol;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007546 }
7547 }
7548 }
7549 }
7550 }
7551 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007552 }
Greg Clayton9422dd62013-03-04 21:46:16 +00007553
Greg Clayton9e9f2192013-05-17 00:55:28 +00007554 if (!linked_oso_file_addr)
7555 {
7556 // The DW_OP_addr is not zero, but it contains a .o file address which
7557 // needs to be linked up correctly.
7558 const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr);
7559 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton9422dd62013-03-04 21:46:16 +00007560 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007561 // Update the file address for this variable
7562 location.Update_DW_OP_addr (exe_file_addr);
7563 }
7564 else
7565 {
7566 // Variable didn't make it into the final executable
7567 return var_sp;
Greg Clayton9422dd62013-03-04 21:46:16 +00007568 }
Greg Claytond1767f02011-12-08 02:13:16 +00007569 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007570 }
Greg Clayton5cf58b92011-10-05 22:22:08 +00007571 }
7572 else
7573 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007574 scope = eValueTypeVariableLocal;
Greg Clayton5cf58b92011-10-05 22:22:08 +00007575 }
Greg Clayton7f995132011-10-04 22:41:51 +00007576 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007577
7578 if (symbol_context_scope == NULL)
7579 {
7580 switch (parent_tag)
7581 {
7582 case DW_TAG_subprogram:
7583 case DW_TAG_inlined_subroutine:
7584 case DW_TAG_lexical_block:
7585 if (sc.function)
7586 {
7587 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
7588 if (symbol_context_scope == NULL)
7589 symbol_context_scope = sc.function;
7590 }
7591 break;
7592
7593 default:
7594 symbol_context_scope = sc.comp_unit;
7595 break;
7596 }
7597 }
7598
7599 if (symbol_context_scope)
7600 {
Enrico Granata4ec130d2014-08-11 19:16:35 +00007601 SymbolFileTypeSP type_sp(new SymbolFileType(*this, type_uid));
7602
7603 if (const_value.Form() && type_sp && type_sp->GetType())
7604 location.CopyOpcodeData(const_value.Unsigned(), type_sp->GetType()->GetByteSize(), dwarf_cu->GetAddressByteSize());
7605
Greg Clayton9e9f2192013-05-17 00:55:28 +00007606 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
7607 name,
7608 mangled,
Enrico Granata4ec130d2014-08-11 19:16:35 +00007609 type_sp,
Greg Clayton9e9f2192013-05-17 00:55:28 +00007610 scope,
7611 symbol_context_scope,
7612 &decl,
7613 location,
7614 is_external,
7615 is_artificial));
7616
7617 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
7618 }
7619 else
7620 {
7621 // Not ready to parse this variable yet. It might be a global
7622 // or static variable that is in a function scope and the function
7623 // in the symbol context wasn't filled in yet
7624 return var_sp;
7625 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007626 }
Greg Clayton7f995132011-10-04 22:41:51 +00007627 // Cache var_sp even if NULL (the variable was just a specification or
7628 // was missing vital information to be able to be displayed in the debugger
7629 // (missing location due to optimization, etc)) so we don't re-parse
7630 // this DIE over and over later...
7631 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007632 }
7633 return var_sp;
7634}
7635
Greg Claytonc662ec82011-06-17 22:10:16 +00007636
7637const DWARFDebugInfoEntry *
7638SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
7639 dw_offset_t spec_block_die_offset,
7640 DWARFCompileUnit **result_die_cu_handle)
7641{
7642 // Give the concrete function die specified by "func_die_offset", find the
7643 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7644 // to "spec_block_die_offset"
7645 DWARFDebugInfo* info = DebugInfo();
7646
7647 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
7648 if (die)
7649 {
7650 assert (*result_die_cu_handle);
7651 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
7652 }
7653 return NULL;
7654}
7655
7656
7657const DWARFDebugInfoEntry *
7658SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
7659 const DWARFDebugInfoEntry *die,
7660 dw_offset_t spec_block_die_offset,
7661 DWARFCompileUnit **result_die_cu_handle)
7662{
7663 if (die)
7664 {
7665 switch (die->Tag())
7666 {
7667 case DW_TAG_subprogram:
7668 case DW_TAG_inlined_subroutine:
7669 case DW_TAG_lexical_block:
7670 {
7671 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
7672 {
7673 *result_die_cu_handle = dwarf_cu;
7674 return die;
7675 }
7676
7677 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
7678 {
7679 *result_die_cu_handle = dwarf_cu;
7680 return die;
7681 }
7682 }
7683 break;
7684 }
7685
7686 // Give the concrete function die specified by "func_die_offset", find the
7687 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7688 // to "spec_block_die_offset"
7689 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
7690 {
7691 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
7692 child_die,
7693 spec_block_die_offset,
7694 result_die_cu_handle);
7695 if (result_die)
7696 return result_die;
7697 }
7698 }
7699
7700 *result_die_cu_handle = NULL;
7701 return NULL;
7702}
7703
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007704size_t
7705SymbolFileDWARF::ParseVariables
7706(
7707 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007708 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007709 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007710 const DWARFDebugInfoEntry *orig_die,
7711 bool parse_siblings,
7712 bool parse_children,
7713 VariableList* cc_variable_list
7714)
7715{
7716 if (orig_die == NULL)
7717 return 0;
7718
Greg Claytonc662ec82011-06-17 22:10:16 +00007719 VariableListSP variable_list_sp;
7720
7721 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007722 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00007723 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007724 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007725 dw_tag_t tag = die->Tag();
7726
7727 // Check to see if we have already parsed this variable or constant?
7728 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007729 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007730 if (cc_variable_list)
7731 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007732 }
7733 else
7734 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007735 // We haven't already parsed it, lets do that now.
7736 if ((tag == DW_TAG_variable) ||
7737 (tag == DW_TAG_constant) ||
7738 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007739 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007740 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00007741 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007742 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
7743 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7744 switch (parent_tag)
7745 {
7746 case DW_TAG_compile_unit:
7747 if (sc.comp_unit != NULL)
7748 {
7749 variable_list_sp = sc.comp_unit->GetVariableList(false);
7750 if (variable_list_sp.get() == NULL)
7751 {
7752 variable_list_sp.reset(new VariableList());
7753 sc.comp_unit->SetVariableList(variable_list_sp);
7754 }
7755 }
7756 else
7757 {
Daniel Malead01b2952012-11-29 21:49:15 +00007758 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 +00007759 MakeUserID(sc_parent_die->GetOffset()),
7760 DW_TAG_value_to_name (parent_tag),
7761 MakeUserID(orig_die->GetOffset()),
7762 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007763 }
7764 break;
7765
7766 case DW_TAG_subprogram:
7767 case DW_TAG_inlined_subroutine:
7768 case DW_TAG_lexical_block:
7769 if (sc.function != NULL)
7770 {
7771 // Check to see if we already have parsed the variables for the given scope
7772
Greg Clayton81c22f62011-10-19 18:09:39 +00007773 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007774 if (block == NULL)
7775 {
7776 // This must be a specification or abstract origin with
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00007777 // a concrete block counterpart in the current function. We need
Greg Claytonc662ec82011-06-17 22:10:16 +00007778 // to find the concrete block so we can correctly add the
7779 // variable to it
7780 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
7781 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
7782 sc_parent_die->GetOffset(),
7783 &concrete_block_die_cu);
7784 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00007785 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007786 }
7787
7788 if (block != NULL)
7789 {
7790 const bool can_create = false;
7791 variable_list_sp = block->GetBlockVariableList (can_create);
7792 if (variable_list_sp.get() == NULL)
7793 {
7794 variable_list_sp.reset(new VariableList());
7795 block->SetVariableList(variable_list_sp);
7796 }
7797 }
7798 }
7799 break;
7800
7801 default:
Daniel Malead01b2952012-11-29 21:49:15 +00007802 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 +00007803 MakeUserID(orig_die->GetOffset()),
7804 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007805 break;
7806 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00007807 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007808
7809 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007810 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00007811 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
7812 if (var_sp)
7813 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007814 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00007815 if (cc_variable_list)
7816 cc_variable_list->AddVariableIfUnique (var_sp);
7817 ++vars_added;
7818 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007819 }
7820 }
7821 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007822
7823 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
7824
7825 if (!skip_children && parse_children && die->HasChildren())
7826 {
7827 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
7828 }
7829
7830 if (parse_siblings)
7831 die = die->GetSibling();
7832 else
7833 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007834 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007835 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007836}
7837
7838//------------------------------------------------------------------
7839// PluginInterface protocol
7840//------------------------------------------------------------------
Greg Clayton57abc5d2013-05-10 21:47:16 +00007841ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007842SymbolFileDWARF::GetPluginName()
7843{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007844 return GetPluginNameStatic();
7845}
7846
7847uint32_t
7848SymbolFileDWARF::GetPluginVersion()
7849{
7850 return 1;
7851}
7852
7853void
Greg Clayton6beaaa62011-01-17 03:46:26 +00007854SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
7855{
7856 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
Greg Clayton57ee3062013-07-11 22:46:58 +00007857 ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
Greg Clayton6beaaa62011-01-17 03:46:26 +00007858 if (clang_type)
7859 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7860}
7861
7862void
7863SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
7864{
7865 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
Greg Clayton57ee3062013-07-11 22:46:58 +00007866 ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
Greg Clayton6beaaa62011-01-17 03:46:26 +00007867 if (clang_type)
7868 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7869}
7870
Greg Claytona2721472011-06-25 00:44:06 +00007871void
Sean Callanancc427fa2011-07-30 02:42:06 +00007872SymbolFileDWARF::DumpIndexes ()
7873{
7874 StreamFile s(stdout, false);
7875
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00007876 s.Printf ("DWARF index for (%s) '%s':",
Sean Callanancc427fa2011-07-30 02:42:06 +00007877 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00007878 GetObjectFile()->GetFileSpec().GetPath().c_str());
Sean Callanancc427fa2011-07-30 02:42:06 +00007879 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
7880 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
7881 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
7882 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
7883 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
7884 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
7885 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
7886 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
7887}
7888
7889void
7890SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
7891 const char *name,
7892 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00007893{
Sean Callanancc427fa2011-07-30 02:42:06 +00007894 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00007895
7896 if (iter == m_decl_ctx_to_die.end())
7897 return;
7898
Greg Claytoncb5860a2011-10-13 23:49:28 +00007899 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00007900 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007901 const DWARFDebugInfoEntry *context_die = *pos;
7902
7903 if (!results)
7904 return;
7905
7906 DWARFDebugInfo* info = DebugInfo();
7907
7908 DIEArray die_offsets;
7909
7910 DWARFCompileUnit* dwarf_cu = NULL;
7911 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton220a0072011-12-09 08:48:30 +00007912
7913 if (m_using_apple_tables)
7914 {
7915 if (m_apple_types_ap.get())
7916 m_apple_types_ap->FindByName (name, die_offsets);
7917 }
7918 else
7919 {
7920 if (!m_indexed)
7921 Index ();
7922
7923 m_type_index.Find (ConstString(name), die_offsets);
7924 }
7925
Greg Clayton220a0072011-12-09 08:48:30 +00007926 const size_t num_matches = die_offsets.size();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007927
7928 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00007929 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007930 for (size_t i = 0; i < num_matches; ++i)
7931 {
7932 const dw_offset_t die_offset = die_offsets[i];
7933 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00007934
Greg Claytoncb5860a2011-10-13 23:49:28 +00007935 if (die->GetParent() != context_die)
7936 continue;
7937
7938 Type *matching_type = ResolveType (dwarf_cu, die);
7939
Greg Clayton57ee3062013-07-11 22:46:58 +00007940 clang::QualType qual_type = matching_type->GetClangForwardType().GetQualType();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007941
7942 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
7943 {
7944 clang::TagDecl *tag_decl = tag_type->getDecl();
7945 results->push_back(tag_decl);
7946 }
7947 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
7948 {
7949 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
7950 results->push_back(typedef_decl);
7951 }
Greg Claytona2721472011-06-25 00:44:06 +00007952 }
7953 }
7954 }
7955}
7956
7957void
7958SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00007959 const clang::DeclContext *decl_context,
7960 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00007961 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
7962{
Greg Clayton85ae2e12011-10-18 23:36:41 +00007963
7964 switch (decl_context->getDeclKind())
7965 {
7966 case clang::Decl::Namespace:
7967 case clang::Decl::TranslationUnit:
7968 {
7969 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7970 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
7971 }
7972 break;
7973 default:
7974 break;
7975 }
Greg Claytona2721472011-06-25 00:44:06 +00007976}
Greg Claytoncaab74e2012-01-28 00:48:57 +00007977
7978bool
7979SymbolFileDWARF::LayoutRecordType (void *baton,
7980 const clang::RecordDecl *record_decl,
7981 uint64_t &size,
7982 uint64_t &alignment,
7983 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7984 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7985 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7986{
7987 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7988 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
7989}
7990
7991
7992bool
7993SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl,
7994 uint64_t &bit_size,
7995 uint64_t &alignment,
7996 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7997 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7998 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7999{
Greg Clayton5160ce52013-03-27 23:08:40 +00008000 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Claytoncaab74e2012-01-28 00:48:57 +00008001 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
8002 bool success = false;
8003 base_offsets.clear();
8004 vbase_offsets.clear();
8005 if (pos != m_record_decl_to_layout_map.end())
8006 {
8007 bit_size = pos->second.bit_size;
8008 alignment = pos->second.alignment;
8009 field_offsets.swap(pos->second.field_offsets);
Greg Clayton2508b9b2012-11-01 23:20:02 +00008010 base_offsets.swap (pos->second.base_offsets);
8011 vbase_offsets.swap (pos->second.vbase_offsets);
Greg Claytoncaab74e2012-01-28 00:48:57 +00008012 m_record_decl_to_layout_map.erase(pos);
8013 success = true;
8014 }
8015 else
8016 {
8017 bit_size = 0;
8018 alignment = 0;
8019 field_offsets.clear();
8020 }
8021
8022 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00008023 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00008024 "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 +00008025 static_cast<const void*>(record_decl),
8026 bit_size, alignment,
8027 static_cast<uint32_t>(field_offsets.size()),
8028 static_cast<uint32_t>(base_offsets.size()),
8029 static_cast<uint32_t>(vbase_offsets.size()),
Greg Claytoncaab74e2012-01-28 00:48:57 +00008030 success);
8031 return success;
8032}
8033
8034
Greg Clayton1f746072012-08-29 21:13:06 +00008035SymbolFileDWARFDebugMap *
8036SymbolFileDWARF::GetDebugMapSymfile ()
8037{
8038 if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired())
8039 {
8040 lldb::ModuleSP module_sp (m_debug_map_module_wp.lock());
8041 if (module_sp)
8042 {
8043 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
8044 if (sym_vendor)
8045 m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile();
8046 }
8047 }
8048 return m_debug_map_symfile;
8049}
8050
Greg Claytoncaab74e2012-01-28 00:48:57 +00008051