blob: d1d4c5d87916a373cfc63467037a5089a6856197 [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
Greg Clayton1fba87112012-02-09 20:03:49 +0000113#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
114
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;
528 llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap (
529 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 {
832 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
833 if (get_debug_info_data().GetByteSize() > 0)
834 {
835 m_info.reset(new DWARFDebugInfo());
836 if (m_info.get())
837 {
838 m_info->SetDwarfData(this);
839 }
840 }
841 }
842 return m_info.get();
843}
844
845const DWARFDebugInfo*
846SymbolFileDWARF::DebugInfo() const
847{
848 return m_info.get();
849}
850
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000851DWARFCompileUnit*
Greg Clayton1f746072012-08-29 21:13:06 +0000852SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000853{
854 DWARFDebugInfo* info = DebugInfo();
Greg Clayton1f746072012-08-29 21:13:06 +0000855 if (info)
856 {
857 if (GetDebugMapSymfile ())
858 {
859 // The debug map symbol file made the compile units for this DWARF
860 // file which is .o file with DWARF in it, and we should have
861 // only 1 compile unit which is at offset zero in the DWARF.
862 // TODO: modify to support LTO .o files where each .o file might
863 // have multiple DW_TAG_compile_unit tags.
864 return info->GetCompileUnit(0).get();
865 }
866 else
867 {
868 // Just a normal DWARF file whose user ID for the compile unit is
869 // the DWARF offset itself
870 return info->GetCompileUnit((dw_offset_t)comp_unit->GetID()).get();
871 }
872 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000873 return NULL;
874}
875
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000876
877DWARFDebugRanges*
878SymbolFileDWARF::DebugRanges()
879{
880 if (m_ranges.get() == NULL)
881 {
882 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
883 if (get_debug_ranges_data().GetByteSize() > 0)
884 {
885 m_ranges.reset(new DWARFDebugRanges());
886 if (m_ranges.get())
887 m_ranges->Extract(this);
888 }
889 }
890 return m_ranges.get();
891}
892
893const DWARFDebugRanges*
894SymbolFileDWARF::DebugRanges() const
895{
896 return m_ranges.get();
897}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000898
Greg Clayton53eb1c22012-04-02 22:59:12 +0000899lldb::CompUnitSP
900SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000901{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000902 CompUnitSP cu_sp;
903 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000904 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000905 CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData();
906 if (comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000907 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000908 // We already parsed this compile unit, had out a shared pointer to it
909 cu_sp = comp_unit->shared_from_this();
910 }
911 else
912 {
Greg Clayton1f746072012-08-29 21:13:06 +0000913 if (GetDebugMapSymfile ())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000914 {
Greg Clayton1f746072012-08-29 21:13:06 +0000915 // Let the debug map create the compile unit
916 cu_sp = m_debug_map_symfile->GetCompileUnit(this);
917 dwarf_cu->SetUserData(cu_sp.get());
918 }
919 else
920 {
921 ModuleSP module_sp (m_obj_file->GetModule());
922 if (module_sp)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000923 {
Greg Clayton1f746072012-08-29 21:13:06 +0000924 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly ();
925 if (cu_die)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000926 {
Greg Clayton1f746072012-08-29 21:13:06 +0000927 const char * cu_die_name = cu_die->GetName(this, dwarf_cu);
928 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
929 LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
930 if (cu_die_name)
931 {
932 std::string ramapped_file;
933 FileSpec cu_file_spec;
Jim Ingham0909e5f2010-09-16 00:57:33 +0000934
Greg Clayton1f746072012-08-29 21:13:06 +0000935 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0')
Greg Clayton53eb1c22012-04-02 22:59:12 +0000936 {
Greg Clayton1f746072012-08-29 21:13:06 +0000937 // If we have a full path to the compile unit, we don't need to resolve
938 // the file. This can be expensive e.g. when the source files are NFS mounted.
939 if (module_sp->RemapSourceFile(cu_die_name, ramapped_file))
940 cu_file_spec.SetFile (ramapped_file.c_str(), false);
941 else
942 cu_file_spec.SetFile (cu_die_name, false);
Greg Clayton53eb1c22012-04-02 22:59:12 +0000943 }
944 else
945 {
Greg Clayton1f746072012-08-29 21:13:06 +0000946 std::string fullpath(cu_comp_dir);
947 if (*fullpath.rbegin() != '/')
948 fullpath += '/';
949 fullpath += cu_die_name;
950 if (module_sp->RemapSourceFile (fullpath.c_str(), ramapped_file))
951 cu_file_spec.SetFile (ramapped_file.c_str(), false);
952 else
953 cu_file_spec.SetFile (fullpath.c_str(), false);
954 }
955
956 cu_sp.reset(new CompileUnit (module_sp,
957 dwarf_cu,
958 cu_file_spec,
959 MakeUserID(dwarf_cu->GetOffset()),
960 cu_language));
961 if (cu_sp)
962 {
963 dwarf_cu->SetUserData(cu_sp.get());
964
Greg Clayton53eb1c22012-04-02 22:59:12 +0000965 // Figure out the compile unit index if we weren't given one
966 if (cu_idx == UINT32_MAX)
967 DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx);
968
969 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp);
970 }
971 }
972 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000973 }
974 }
975 }
976 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000977 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000978}
979
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000980uint32_t
981SymbolFileDWARF::GetNumCompileUnits()
982{
983 DWARFDebugInfo* info = DebugInfo();
984 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000985 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000986 return 0;
987}
988
989CompUnitSP
990SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
991{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000992 CompUnitSP cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000993 DWARFDebugInfo* info = DebugInfo();
994 if (info)
995 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000996 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
997 if (dwarf_cu)
998 cu_sp = ParseCompileUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000999 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00001000 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001001}
1002
1003static void
Greg Claytonea3e7d52011-10-08 00:49:15 +00001004AddRangesToBlock (Block& block,
1005 DWARFDebugRanges::RangeList& ranges,
1006 addr_t block_base_addr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001007{
Greg Claytonea3e7d52011-10-08 00:49:15 +00001008 const size_t num_ranges = ranges.GetSize();
1009 for (size_t i = 0; i<num_ranges; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001010 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001011 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i);
1012 const addr_t range_base = range.GetRangeBase();
1013 assert (range_base >= block_base_addr);
1014 block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001015 }
Greg Claytonea3e7d52011-10-08 00:49:15 +00001016 block.FinalizeRanges ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001017}
1018
1019
1020Function *
Greg Clayton0fffff52010-09-24 05:15:53 +00001021SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001022{
1023 DWARFDebugRanges::RangeList func_ranges;
1024 const char *name = NULL;
1025 const char *mangled = NULL;
1026 int decl_file = 0;
1027 int decl_line = 0;
1028 int decl_column = 0;
1029 int call_file = 0;
1030 int call_line = 0;
1031 int call_column = 0;
1032 DWARFExpression frame_base;
1033
Greg Claytonc93237c2010-10-01 20:48:32 +00001034 assert (die->Tag() == DW_TAG_subprogram);
1035
1036 if (die->Tag() != DW_TAG_subprogram)
1037 return NULL;
1038
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001039 if (die->GetDIENamesAndRanges (this,
1040 dwarf_cu,
1041 name,
1042 mangled,
1043 func_ranges,
1044 decl_file,
1045 decl_line,
1046 decl_column,
1047 call_file,
1048 call_line,
1049 call_column,
1050 &frame_base))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001051 {
1052 // Union of all ranges in the function DIE (if the function is discontiguous)
1053 AddressRange func_range;
Greg Claytonea3e7d52011-10-08 00:49:15 +00001054 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0);
1055 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001056 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
1057 {
Michael Sartaina7499c92013-07-01 19:45:50 +00001058 ModuleSP module_sp (m_obj_file->GetModule());
Greg Clayton3046e662013-07-10 01:23:25 +00001059 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, module_sp->GetSectionList());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001060 if (func_range.GetBaseAddress().IsValid())
1061 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
1062 }
1063
1064 if (func_range.GetBaseAddress().IsValid())
1065 {
1066 Mangled func_name;
1067 if (mangled)
Greg Clayton037520e2012-07-18 23:18:10 +00001068 func_name.SetValue(ConstString(mangled), true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001069 else if (name)
Greg Clayton037520e2012-07-18 23:18:10 +00001070 func_name.SetValue(ConstString(name), false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001071
1072 FunctionSP func_sp;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001073 std::unique_ptr<Declaration> decl_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001074 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +00001075 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1076 decl_line,
1077 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001078
Greg Clayton0bd4e1b2011-09-30 20:52:25 +00001079 // Supply the type _only_ if it has already been parsed
Greg Clayton594e5ed2010-09-27 21:07:38 +00001080 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001081
1082 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
1083
Greg Clayton9422dd62013-03-04 21:46:16 +00001084 if (FixupAddress (func_range.GetBaseAddress()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001085 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001086 const user_id_t func_user_id = MakeUserID(die->GetOffset());
1087 func_sp.reset(new Function (sc.comp_unit,
1088 MakeUserID(func_user_id), // UserID is the DIE offset
1089 MakeUserID(func_user_id),
1090 func_name,
1091 func_type,
1092 func_range)); // first address range
1093
1094 if (func_sp.get() != NULL)
1095 {
1096 if (frame_base.IsValid())
1097 func_sp->GetFrameBaseExpression() = frame_base;
1098 sc.comp_unit->AddFunction(func_sp);
1099 return func_sp.get();
1100 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001101 }
1102 }
1103 }
1104 return NULL;
1105}
1106
Greg Clayton9422dd62013-03-04 21:46:16 +00001107bool
1108SymbolFileDWARF::FixupAddress (Address &addr)
1109{
1110 SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile ();
1111 if (debug_map_symfile)
1112 {
1113 return debug_map_symfile->LinkOSOAddress(addr);
1114 }
1115 // This is a normal DWARF file, no address fixups need to happen
1116 return true;
1117}
Greg Clayton1f746072012-08-29 21:13:06 +00001118lldb::LanguageType
1119SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc)
1120{
1121 assert (sc.comp_unit);
1122 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1123 if (dwarf_cu)
1124 {
1125 const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly();
Jim Ingham28eb5712012-10-12 17:34:26 +00001126 if (die)
1127 {
1128 const uint32_t language = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
1129 if (language)
1130 return (lldb::LanguageType)language;
1131 }
Greg Clayton1f746072012-08-29 21:13:06 +00001132 }
1133 return eLanguageTypeUnknown;
1134}
1135
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001136size_t
1137SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
1138{
1139 assert (sc.comp_unit);
1140 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00001141 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001142 if (dwarf_cu)
1143 {
1144 DWARFDIECollection function_dies;
Greg Clayton1f746072012-08-29 21:13:06 +00001145 const size_t num_functions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001146 size_t func_idx;
Greg Clayton1f746072012-08-29 21:13:06 +00001147 for (func_idx = 0; func_idx < num_functions; ++func_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001148 {
1149 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
Greg Clayton81c22f62011-10-19 18:09:39 +00001150 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001151 {
1152 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
1153 ++functions_added;
1154 }
1155 }
1156 //FixupTypes();
1157 }
1158 return functions_added;
1159}
1160
1161bool
1162SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
1163{
1164 assert (sc.comp_unit);
Greg Clayton1f746072012-08-29 21:13:06 +00001165 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Greg Claytonda2455b2012-11-01 17:28:37 +00001166 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001167 {
Greg Claytonda2455b2012-11-01 17:28:37 +00001168 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001169
Greg Claytonda2455b2012-11-01 17:28:37 +00001170 if (cu_die)
1171 {
1172 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
1173 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 +00001174
Greg Claytonda2455b2012-11-01 17:28:37 +00001175 // All file indexes in DWARF are one based and a file of index zero is
1176 // supposed to be the compile unit itself.
1177 support_files.Append (*sc.comp_unit);
1178
1179 return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
1180 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001181 }
1182 return false;
1183}
1184
1185struct ParseDWARFLineTableCallbackInfo
1186{
1187 LineTable* line_table;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001188 std::unique_ptr<LineSequence> sequence_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001189};
1190
1191//----------------------------------------------------------------------
1192// ParseStatementTableCallback
1193//----------------------------------------------------------------------
1194static void
1195ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
1196{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001197 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
1198 {
1199 // Just started parsing the line table
1200 }
1201 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
1202 {
1203 // Done parsing line table, nothing to do for the cleanup
1204 }
1205 else
1206 {
1207 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
Greg Clayton9422dd62013-03-04 21:46:16 +00001208 LineTable* line_table = info->line_table;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001209
Greg Clayton9422dd62013-03-04 21:46:16 +00001210 // If this is our first time here, we need to create a
1211 // sequence container.
1212 if (!info->sequence_ap.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001213 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001214 info->sequence_ap.reset(line_table->CreateLineSequenceContainer());
1215 assert(info->sequence_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001216 }
Greg Clayton9422dd62013-03-04 21:46:16 +00001217 line_table->AppendLineEntryToSequence (info->sequence_ap.get(),
1218 state.address,
1219 state.line,
1220 state.column,
1221 state.file,
1222 state.is_stmt,
1223 state.basic_block,
1224 state.prologue_end,
1225 state.epilogue_begin,
1226 state.end_sequence);
1227 if (state.end_sequence)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001228 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001229 // First, put the current sequence into the line table.
1230 line_table->InsertSequence(info->sequence_ap.get());
1231 // Then, empty it to prepare for the next sequence.
1232 info->sequence_ap->Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001233 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001234 }
1235}
1236
1237bool
1238SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1239{
1240 assert (sc.comp_unit);
1241 if (sc.comp_unit->GetLineTable() != NULL)
1242 return true;
1243
Greg Clayton1f746072012-08-29 21:13:06 +00001244 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001245 if (dwarf_cu)
1246 {
1247 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Greg Clayton129d12c2011-11-28 03:29:03 +00001248 if (dwarf_cu_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001249 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001250 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1251 if (cu_line_offset != DW_INVALID_OFFSET)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001252 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001253 std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
Greg Clayton129d12c2011-11-28 03:29:03 +00001254 if (line_table_ap.get())
1255 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001256 ParseDWARFLineTableCallbackInfo info;
1257 info.line_table = line_table_ap.get();
Greg Claytonc7bece562013-01-25 18:06:21 +00001258 lldb::offset_t offset = cu_line_offset;
Greg Clayton129d12c2011-11-28 03:29:03 +00001259 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
Greg Clayton9422dd62013-03-04 21:46:16 +00001260 if (m_debug_map_symfile)
1261 {
1262 // We have an object file that has a line table with addresses
1263 // that are not linked. We need to link the line table and convert
1264 // the addresses that are relative to the .o file into addresses
1265 // for the main executable.
1266 sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get()));
1267 }
1268 else
1269 {
1270 sc.comp_unit->SetLineTable(line_table_ap.release());
1271 return true;
1272 }
Greg Clayton129d12c2011-11-28 03:29:03 +00001273 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001274 }
1275 }
1276 }
1277 return false;
1278}
1279
1280size_t
1281SymbolFileDWARF::ParseFunctionBlocks
1282(
1283 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001284 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001285 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001286 const DWARFDebugInfoEntry *die,
1287 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001288 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001289)
1290{
1291 size_t blocks_added = 0;
1292 while (die != NULL)
1293 {
1294 dw_tag_t tag = die->Tag();
1295
1296 switch (tag)
1297 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001298 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001299 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001300 case DW_TAG_lexical_block:
1301 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001302 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001303 if (tag == DW_TAG_subprogram)
1304 {
1305 // Skip any DW_TAG_subprogram DIEs that are inside
1306 // of a normal or inlined functions. These will be
1307 // parsed on their own as separate entities.
1308
1309 if (depth > 0)
1310 break;
1311
1312 block = parent_block;
1313 }
1314 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001315 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001316 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001317 parent_block->AddChild(block_sp);
1318 block = block_sp.get();
1319 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001320 DWARFDebugRanges::RangeList ranges;
1321 const char *name = NULL;
1322 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001323
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001324 int decl_file = 0;
1325 int decl_line = 0;
1326 int decl_column = 0;
1327 int call_file = 0;
1328 int call_line = 0;
1329 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001330 if (die->GetDIENamesAndRanges (this,
1331 dwarf_cu,
1332 name,
1333 mangled_name,
1334 ranges,
1335 decl_file, decl_line, decl_column,
1336 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001337 {
1338 if (tag == DW_TAG_subprogram)
1339 {
1340 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001341 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001342 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001343 else if (tag == DW_TAG_inlined_subroutine)
1344 {
1345 // We get called here for inlined subroutines in two ways.
1346 // The first time is when we are making the Function object
1347 // for this inlined concrete instance. Since we're creating a top level block at
1348 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1349 // adjust the containing address.
1350 // The second time is when we are parsing the blocks inside the function that contains
1351 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1352 // function the offset will be for that function.
1353 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1354 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001355 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001356 }
1357 }
1358
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001359 AddRangesToBlock (*block, ranges, subprogram_low_pc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001360
1361 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1362 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001363 std::unique_ptr<Declaration> decl_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001364 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001365 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1366 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001367
Greg Clayton7b0992d2013-04-18 22:45:39 +00001368 std::unique_ptr<Declaration> call_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001369 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001370 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1371 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001372
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001373 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001374 }
1375
1376 ++blocks_added;
1377
Greg Claytondd7feaf2011-08-12 17:54:33 +00001378 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001379 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001380 blocks_added += ParseFunctionBlocks (sc,
1381 block,
1382 dwarf_cu,
1383 die->GetFirstChild(),
1384 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001385 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001386 }
1387 }
1388 }
1389 break;
1390 default:
1391 break;
1392 }
1393
Greg Claytondd7feaf2011-08-12 17:54:33 +00001394 // Only parse siblings of the block if we are not at depth zero. A depth
1395 // of zero indicates we are currently parsing the top level
1396 // DW_TAG_subprogram DIE
1397
1398 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001399 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001400 else
1401 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001402 }
1403 return blocks_added;
1404}
1405
Greg Claytonf0705c82011-10-22 03:33:13 +00001406bool
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001407SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu,
1408 const DWARFDebugInfoEntry *die,
1409 ClangASTContext::TemplateParameterInfos &template_param_infos)
1410{
1411 const dw_tag_t tag = die->Tag();
1412
1413 switch (tag)
1414 {
1415 case DW_TAG_template_type_parameter:
1416 case DW_TAG_template_value_parameter:
1417 {
1418 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
1419
1420 DWARFDebugInfoEntry::Attributes attributes;
1421 const size_t num_attributes = die->GetAttributes (this,
1422 dwarf_cu,
1423 fixed_form_sizes,
1424 attributes);
1425 const char *name = NULL;
1426 Type *lldb_type = NULL;
Greg Clayton57ee3062013-07-11 22:46:58 +00001427 ClangASTType clang_type;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001428 uint64_t uval64 = 0;
1429 bool uval64_valid = false;
1430 if (num_attributes > 0)
1431 {
1432 DWARFFormValue form_value;
1433 for (size_t i=0; i<num_attributes; ++i)
1434 {
1435 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1436
1437 switch (attr)
1438 {
1439 case DW_AT_name:
1440 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1441 name = form_value.AsCString(&get_debug_str_data());
1442 break;
1443
1444 case DW_AT_type:
1445 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1446 {
1447 const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu);
1448 lldb_type = ResolveTypeUID(type_die_offset);
1449 if (lldb_type)
1450 clang_type = lldb_type->GetClangForwardType();
1451 }
1452 break;
1453
1454 case DW_AT_const_value:
1455 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1456 {
1457 uval64_valid = true;
1458 uval64 = form_value.Unsigned();
1459 }
1460 break;
1461 default:
1462 break;
1463 }
1464 }
1465
Greg Clayton283b2652013-04-23 22:38:02 +00001466 clang::ASTContext *ast = GetClangASTContext().getASTContext();
1467 if (!clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00001468 clang_type = GetClangASTContext().GetBasicType(eBasicTypeVoid);
Greg Clayton283b2652013-04-23 22:38:02 +00001469
1470 if (clang_type)
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001471 {
1472 bool is_signed = false;
Greg Clayton283b2652013-04-23 22:38:02 +00001473 if (name && name[0])
1474 template_param_infos.names.push_back(name);
1475 else
1476 template_param_infos.names.push_back(NULL);
1477
Greg Clayton283b2652013-04-23 22:38:02 +00001478 if (tag == DW_TAG_template_value_parameter &&
1479 lldb_type != NULL &&
Greg Clayton57ee3062013-07-11 22:46:58 +00001480 clang_type.IsIntegerType (is_signed) &&
Greg Clayton283b2652013-04-23 22:38:02 +00001481 uval64_valid)
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001482 {
1483 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
Greg Clayton283b2652013-04-23 22:38:02 +00001484 template_param_infos.args.push_back (clang::TemplateArgument (*ast,
Sean Callanan3d654b32012-09-24 22:25:51 +00001485 llvm::APSInt(apint),
Greg Clayton57ee3062013-07-11 22:46:58 +00001486 clang_type.GetQualType()));
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001487 }
1488 else
1489 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001490 template_param_infos.args.push_back (clang::TemplateArgument (clang_type.GetQualType()));
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001491 }
1492 }
1493 else
1494 {
1495 return false;
1496 }
1497
1498 }
1499 }
1500 return true;
1501
1502 default:
1503 break;
1504 }
1505 return false;
1506}
1507
1508bool
Greg Claytonf0705c82011-10-22 03:33:13 +00001509SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1510 const DWARFDebugInfoEntry *parent_die,
1511 ClangASTContext::TemplateParameterInfos &template_param_infos)
1512{
1513
1514 if (parent_die == NULL)
Filipe Cabecinhas52008c62012-05-23 16:24:11 +00001515 return false;
Greg Claytonf0705c82011-10-22 03:33:13 +00001516
Greg Claytonf0705c82011-10-22 03:33:13 +00001517 Args template_parameter_names;
1518 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1519 die != NULL;
1520 die = die->GetSibling())
1521 {
1522 const dw_tag_t tag = die->Tag();
1523
1524 switch (tag)
1525 {
1526 case DW_TAG_template_type_parameter:
1527 case DW_TAG_template_value_parameter:
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001528 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Claytonf0705c82011-10-22 03:33:13 +00001529 break;
1530
1531 default:
1532 break;
1533 }
1534 }
1535 if (template_param_infos.args.empty())
1536 return false;
1537 return template_param_infos.args.size() == template_param_infos.names.size();
1538}
1539
1540clang::ClassTemplateDecl *
1541SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001542 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001543 const char *parent_name,
1544 int tag_decl_kind,
1545 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1546{
1547 if (template_param_infos.IsValid())
1548 {
1549 std::string template_basename(parent_name);
1550 template_basename.erase (template_basename.find('<'));
1551 ClangASTContext &ast = GetClangASTContext();
1552
1553 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001554 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001555 template_basename.c_str(),
1556 tag_decl_kind,
1557 template_param_infos);
1558 }
1559 return NULL;
1560}
1561
Sean Callanana0b80ab2012-06-04 22:28:05 +00001562class SymbolFileDWARF::DelayedAddObjCClassProperty
1563{
1564public:
1565 DelayedAddObjCClassProperty
1566 (
Greg Clayton57ee3062013-07-11 22:46:58 +00001567 const ClangASTType &class_opaque_type,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001568 const char *property_name,
Greg Clayton57ee3062013-07-11 22:46:58 +00001569 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 +00001570 clang::ObjCIvarDecl *ivar_decl,
1571 const char *property_setter_name,
1572 const char *property_getter_name,
1573 uint32_t property_attributes,
Greg Claytonc4ffd662013-03-08 01:37:30 +00001574 const ClangASTMetadata *metadata
Sean Callanana0b80ab2012-06-04 22:28:05 +00001575 ) :
Sean Callanana0b80ab2012-06-04 22:28:05 +00001576 m_class_opaque_type (class_opaque_type),
1577 m_property_name (property_name),
1578 m_property_opaque_type (property_opaque_type),
1579 m_ivar_decl (ivar_decl),
1580 m_property_setter_name (property_setter_name),
1581 m_property_getter_name (property_getter_name),
Jim Ingham379397632012-10-27 02:54:13 +00001582 m_property_attributes (property_attributes)
Sean Callanana0b80ab2012-06-04 22:28:05 +00001583 {
Jim Ingham379397632012-10-27 02:54:13 +00001584 if (metadata != NULL)
1585 {
1586 m_metadata_ap.reset(new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001587 *m_metadata_ap = *metadata;
Jim Ingham379397632012-10-27 02:54:13 +00001588 }
1589 }
1590
1591 DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs)
1592 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001593 *this = rhs;
Daniel Malead4c5be62012-11-12 21:02:14 +00001594 }
1595
1596 DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs)
1597 {
Jim Ingham379397632012-10-27 02:54:13 +00001598 m_class_opaque_type = rhs.m_class_opaque_type;
1599 m_property_name = rhs.m_property_name;
1600 m_property_opaque_type = rhs.m_property_opaque_type;
1601 m_ivar_decl = rhs.m_ivar_decl;
1602 m_property_setter_name = rhs.m_property_setter_name;
1603 m_property_getter_name = rhs.m_property_getter_name;
1604 m_property_attributes = rhs.m_property_attributes;
1605
1606 if (rhs.m_metadata_ap.get())
1607 {
1608 m_metadata_ap.reset (new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001609 *m_metadata_ap = *rhs.m_metadata_ap;
Jim Ingham379397632012-10-27 02:54:13 +00001610 }
Daniel Malead4c5be62012-11-12 21:02:14 +00001611 return *this;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001612 }
1613
Greg Clayton57ee3062013-07-11 22:46:58 +00001614 bool
1615 Finalize()
Sean Callanana0b80ab2012-06-04 22:28:05 +00001616 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001617 return m_class_opaque_type.AddObjCClassProperty (m_property_name,
1618 m_property_opaque_type,
1619 m_ivar_decl,
1620 m_property_setter_name,
1621 m_property_getter_name,
1622 m_property_attributes,
1623 m_metadata_ap.get());
Sean Callanana0b80ab2012-06-04 22:28:05 +00001624 }
1625private:
Greg Clayton57ee3062013-07-11 22:46:58 +00001626 ClangASTType m_class_opaque_type;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001627 const char *m_property_name;
Greg Clayton57ee3062013-07-11 22:46:58 +00001628 ClangASTType m_property_opaque_type;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001629 clang::ObjCIvarDecl *m_ivar_decl;
1630 const char *m_property_setter_name;
1631 const char *m_property_getter_name;
1632 uint32_t m_property_attributes;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001633 std::unique_ptr<ClangASTMetadata> m_metadata_ap;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001634};
1635
Sean Callananfaa0bb32012-12-05 23:37:14 +00001636struct BitfieldInfo
1637{
1638 uint64_t bit_size;
1639 uint64_t bit_offset;
1640
1641 BitfieldInfo () :
1642 bit_size (LLDB_INVALID_ADDRESS),
1643 bit_offset (LLDB_INVALID_ADDRESS)
1644 {
1645 }
1646
Greg Clayton78f4d952013-12-11 23:10:39 +00001647 void
1648 Clear()
1649 {
1650 bit_size = LLDB_INVALID_ADDRESS;
1651 bit_offset = LLDB_INVALID_ADDRESS;
1652 }
1653
Sean Callananfaa0bb32012-12-05 23:37:14 +00001654 bool IsValid ()
1655 {
1656 return (bit_size != LLDB_INVALID_ADDRESS) &&
1657 (bit_offset != LLDB_INVALID_ADDRESS);
1658 }
1659};
1660
Greg Claytonc4ffd662013-03-08 01:37:30 +00001661
1662bool
1663SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu,
1664 const DWARFDebugInfoEntry *parent_die)
1665{
1666 if (parent_die)
1667 {
1668 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1669 {
1670 dw_tag_t tag = die->Tag();
1671 bool check_virtuality = false;
1672 switch (tag)
1673 {
1674 case DW_TAG_inheritance:
1675 case DW_TAG_subprogram:
1676 check_virtuality = true;
1677 break;
1678 default:
1679 break;
1680 }
1681 if (check_virtuality)
1682 {
1683 if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0)
1684 return true;
1685 }
1686 }
1687 }
1688 return false;
1689}
1690
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001691size_t
1692SymbolFileDWARF::ParseChildMembers
1693(
1694 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001695 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001696 const DWARFDebugInfoEntry *parent_die,
Greg Clayton57ee3062013-07-11 22:46:58 +00001697 ClangASTType &class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001698 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001699 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1700 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001701 DWARFDIECollection& member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001702 DelayedPropertyList& delayed_properties,
Sean Callananc7fbf732010-08-06 00:32:49 +00001703 AccessType& default_accessibility,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001704 bool &is_a_class,
1705 LayoutInfo &layout_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001706)
1707{
1708 if (parent_die == NULL)
1709 return 0;
1710
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001711 size_t count = 0;
1712 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001713 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001714 uint32_t member_idx = 0;
Sean Callananfaa0bb32012-12-05 23:37:14 +00001715 BitfieldInfo last_field_info;
Richard Mitton0a558352013-10-17 21:14:00 +00001716 ModuleSP module = GetObjectFile()->GetModule();
Greg Claytond88d7592010-09-15 08:33:30 +00001717
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001718 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1719 {
1720 dw_tag_t tag = die->Tag();
1721
1722 switch (tag)
1723 {
1724 case DW_TAG_member:
Sean Callanan3d654b32012-09-24 22:25:51 +00001725 case DW_TAG_APPLE_property:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001726 {
1727 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001728 const size_t num_attributes = die->GetAttributes (this,
1729 dwarf_cu,
1730 fixed_form_sizes,
1731 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001732 if (num_attributes > 0)
1733 {
1734 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001735 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001736 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001737 const char *prop_name = NULL;
1738 const char *prop_getter_name = NULL;
1739 const char *prop_setter_name = NULL;
Greg Claytone528efd72013-02-26 23:45:18 +00001740 uint32_t prop_attributes = 0;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001741
1742
Greg Clayton24739922010-10-13 03:15:28 +00001743 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001744 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001745 AccessType accessibility = eAccessNone;
Greg Claytoncaab74e2012-01-28 00:48:57 +00001746 uint32_t member_byte_offset = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001747 size_t byte_size = 0;
1748 size_t bit_offset = 0;
1749 size_t bit_size = 0;
Greg Claytone528efd72013-02-26 23:45:18 +00001750 bool is_external = false; // On DW_TAG_members, this means the member is static
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001751 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001752 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001753 {
1754 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1755 DWARFFormValue form_value;
1756 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1757 {
1758 switch (attr)
1759 {
1760 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1761 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1762 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1763 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1764 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1765 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1766 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1767 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1768 case DW_AT_data_member_location:
Greg Claytoncaab74e2012-01-28 00:48:57 +00001769 if (form_value.BlockData())
1770 {
1771 Value initialValue(0);
1772 Value memberOffset(0);
Ed Masteeeae7212013-10-24 20:43:47 +00001773 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Claytoncaab74e2012-01-28 00:48:57 +00001774 uint32_t block_length = form_value.Unsigned();
1775 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1776 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
Greg Claytoncaab74e2012-01-28 00:48:57 +00001777 NULL, // ClangExpressionVariableList *
1778 NULL, // ClangExpressionDeclMap *
1779 NULL, // RegisterContext *
Richard Mitton0a558352013-10-17 21:14:00 +00001780 module,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001781 debug_info_data,
1782 block_offset,
1783 block_length,
1784 eRegisterKindDWARF,
1785 &initialValue,
1786 memberOffset,
1787 NULL))
1788 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001789 member_byte_offset = memberOffset.ResolveValue(NULL).UInt();
Greg Claytoncaab74e2012-01-28 00:48:57 +00001790 }
1791 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00001792 else
1793 {
1794 // With DWARF 3 and later, if the value is an integer constant,
1795 // this form value is the offset in bytes from the beginning
1796 // of the containing entity.
1797 member_byte_offset = form_value.Unsigned();
1798 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001799 break;
1800
Greg Clayton8cf05932010-07-22 18:30:50 +00001801 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00001802 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001803 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1804 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1805 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1806 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00001807 case DW_AT_external: is_external = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001808
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001809 default:
Greg Clayton1b02c172012-03-14 21:00:47 +00001810 case DW_AT_declaration:
1811 case DW_AT_description:
1812 case DW_AT_mutable:
1813 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001814 case DW_AT_sibling:
1815 break;
1816 }
1817 }
1818 }
Sean Callanana6582262012-04-05 00:12:52 +00001819
1820 if (prop_name)
Sean Callanan751aac62012-03-29 19:07:06 +00001821 {
Sean Callanana6582262012-04-05 00:12:52 +00001822 ConstString fixed_getter;
1823 ConstString fixed_setter;
1824
1825 // Check if the property getter/setter were provided as full
1826 // names. We want basenames, so we extract them.
1827
1828 if (prop_getter_name && prop_getter_name[0] == '-')
1829 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001830 ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true);
1831 prop_getter_name = prop_getter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001832 }
1833
1834 if (prop_setter_name && prop_setter_name[0] == '-')
1835 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001836 ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true);
1837 prop_setter_name = prop_setter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001838 }
1839
1840 // If the names haven't been provided, they need to be
1841 // filled in.
1842
1843 if (!prop_getter_name)
1844 {
1845 prop_getter_name = prop_name;
1846 }
1847 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly))
1848 {
1849 StreamString ss;
1850
1851 ss.Printf("set%c%s:",
1852 toupper(prop_name[0]),
1853 &prop_name[1]);
1854
1855 fixed_setter.SetCString(ss.GetData());
1856 prop_setter_name = fixed_setter.GetCString();
1857 }
Sean Callanan751aac62012-03-29 19:07:06 +00001858 }
1859
1860 // Clang has a DWARF generation bug where sometimes it
Greg Clayton44953932011-10-25 01:25:35 +00001861 // represents fields that are references with bad byte size
1862 // and bit size/offset information such as:
1863 //
1864 // DW_AT_byte_size( 0x00 )
1865 // DW_AT_bit_size( 0x40 )
1866 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1867 //
1868 // So check the bit offset to make sure it is sane, and if
1869 // the values are not sane, remove them. If we don't do this
1870 // then we will end up with a crash if we try to use this
1871 // type in an expression when clang becomes unhappy with its
1872 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001873
Greg Clayton44953932011-10-25 01:25:35 +00001874 if (bit_offset > 128)
1875 {
1876 bit_size = 0;
1877 bit_offset = 0;
1878 }
1879
1880 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00001881 if (class_language == eLanguageTypeObjC ||
1882 class_language == eLanguageTypeObjC_plus_plus)
1883 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001884
1885 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1886 {
1887 // Not all compilers will mark the vtable pointer
1888 // member as artificial (llvm-gcc). We can't have
1889 // the virtual members in our classes otherwise it
1890 // throws off all child offsets since we end up
1891 // having and extra pointer sized member in our
1892 // class layouts.
1893 is_artificial = true;
1894 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001895
Greg Clayton29659712013-07-12 20:08:35 +00001896 // Handle static members
Greg Claytone528efd72013-02-26 23:45:18 +00001897 if (is_external && member_byte_offset == UINT32_MAX)
Greg Clayton973b6c92013-04-11 16:57:51 +00001898 {
1899 Type *var_type = ResolveTypeUID(encoding_uid);
1900
1901 if (var_type)
1902 {
Greg Clayton29659712013-07-12 20:08:35 +00001903 if (accessibility == eAccessNone)
1904 accessibility = eAccessPublic;
Greg Clayton57ee3062013-07-11 22:46:58 +00001905 class_clang_type.AddVariableToRecordType (name,
1906 var_type->GetClangLayoutType(),
1907 accessibility);
Greg Clayton973b6c92013-04-11 16:57:51 +00001908 }
Greg Claytone528efd72013-02-26 23:45:18 +00001909 break;
Greg Clayton973b6c92013-04-11 16:57:51 +00001910 }
Greg Claytone528efd72013-02-26 23:45:18 +00001911
Greg Clayton24739922010-10-13 03:15:28 +00001912 if (is_artificial == false)
1913 {
1914 Type *member_type = ResolveTypeUID(encoding_uid);
Sean Callananfa3ab452012-12-14 00:54:13 +00001915
Jim Inghame3ae82a2011-11-12 01:36:43 +00001916 clang::FieldDecl *field_decl = NULL;
Sean Callanan751aac62012-03-29 19:07:06 +00001917 if (tag == DW_TAG_member)
Greg Claytond16e1e52011-07-12 17:06:17 +00001918 {
Sean Callanan751aac62012-03-29 19:07:06 +00001919 if (member_type)
1920 {
1921 if (accessibility == eAccessNone)
1922 accessibility = default_accessibility;
1923 member_accessibilities.push_back(accessibility);
Sean Callananfaa0bb32012-12-05 23:37:14 +00001924
Greg Clayton78f4d952013-12-11 23:10:39 +00001925 uint64_t field_bit_offset = (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
1926 if (bit_size > 0)
Greg Clayton88bc7f32012-11-06 00:20:41 +00001927 {
Greg Clayton78f4d952013-12-11 23:10:39 +00001928
1929 BitfieldInfo this_field_info;
1930 this_field_info.bit_offset = field_bit_offset;
1931 this_field_info.bit_size = bit_size;
1932
Sean Callananfaa0bb32012-12-05 23:37:14 +00001933 /////////////////////////////////////////////////////////////
1934 // How to locate a field given the DWARF debug information
1935 //
1936 // AT_byte_size indicates the size of the word in which the
1937 // bit offset must be interpreted.
1938 //
1939 // AT_data_member_location indicates the byte offset of the
1940 // word from the base address of the structure.
1941 //
1942 // AT_bit_offset indicates how many bits into the word
1943 // (according to the host endianness) the low-order bit of
1944 // the field starts. AT_bit_offset can be negative.
1945 //
1946 // AT_bit_size indicates the size of the field in bits.
1947 /////////////////////////////////////////////////////////////
1948
Greg Clayton78f4d952013-12-11 23:10:39 +00001949 if (byte_size == 0)
1950 byte_size = member_type->GetByteSize();
1951
Sean Callananfaa0bb32012-12-05 23:37:14 +00001952 if (GetObjectFile()->GetByteOrder() == eByteOrderLittle)
1953 {
1954 this_field_info.bit_offset += byte_size * 8;
1955 this_field_info.bit_offset -= (bit_offset + bit_size);
1956 }
1957 else
1958 {
1959 this_field_info.bit_offset += bit_offset;
1960 }
Greg Clayton78f4d952013-12-11 23:10:39 +00001961
1962 // Update the field bit offset we will report for layout
1963 field_bit_offset = this_field_info.bit_offset;
Sean Callananfaa0bb32012-12-05 23:37:14 +00001964
Greg Clayton78f4d952013-12-11 23:10:39 +00001965 // If the member to be emitted did not start on a character boundary and there is
1966 // empty space between the last field and this one, then we need to emit an
1967 // anonymous member filling up the space up to its start. There are three cases
1968 // here:
1969 //
1970 // 1 If the previous member ended on a character boundary, then we can emit an
1971 // anonymous member starting at the most recent character boundary.
1972 //
1973 // 2 If the previous member did not end on a character boundary and the distance
1974 // from the end of the previous member to the current member is less than a
1975 // word width, then we can emit an anonymous member starting right after the
1976 // previous member and right before this member.
1977 //
1978 // 3 If the previous member did not end on a character boundary and the distance
1979 // from the end of the previous member to the current member is greater than
1980 // or equal a word width, then we act as in Case 1.
1981
1982 const uint64_t character_width = 8;
1983 const uint64_t word_width = 32;
1984
Sean Callananfaa0bb32012-12-05 23:37:14 +00001985 // Objective-C has invalid DW_AT_bit_offset values in older versions
1986 // of clang, so we have to be careful and only insert unnammed bitfields
Greg Clayton37c36e42012-11-27 00:59:26 +00001987 // if we have a new enough clang.
1988 bool detect_unnamed_bitfields = true;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001989
Greg Clayton37c36e42012-11-27 00:59:26 +00001990 if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus)
1991 detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields ();
1992
1993 if (detect_unnamed_bitfields)
Greg Clayton88bc7f32012-11-06 00:20:41 +00001994 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001995 BitfieldInfo anon_field_info;
1996
1997 if ((this_field_info.bit_offset % character_width) != 0) // not char aligned
Greg Clayton88bc7f32012-11-06 00:20:41 +00001998 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001999 uint64_t last_field_end = 0;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002000
Sean Callananfaa0bb32012-12-05 23:37:14 +00002001 if (last_field_info.IsValid())
2002 last_field_end = last_field_info.bit_offset + last_field_info.bit_size;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002003
Sean Callananfaa0bb32012-12-05 23:37:14 +00002004 if (this_field_info.bit_offset != last_field_end)
2005 {
2006 if (((last_field_end % character_width) == 0) || // case 1
2007 (this_field_info.bit_offset - last_field_end >= word_width)) // case 3
2008 {
2009 anon_field_info.bit_size = this_field_info.bit_offset % character_width;
2010 anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size;
2011 }
2012 else // case 2
2013 {
2014 anon_field_info.bit_size = this_field_info.bit_offset - last_field_end;
2015 anon_field_info.bit_offset = last_field_end;
2016 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00002017 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00002018 }
2019
Sean Callananfaa0bb32012-12-05 23:37:14 +00002020 if (anon_field_info.IsValid())
Greg Clayton88bc7f32012-11-06 00:20:41 +00002021 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002022 clang::FieldDecl *unnamed_bitfield_decl = class_clang_type.AddFieldToRecordType (NULL,
2023 GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width),
2024 accessibility,
2025 anon_field_info.bit_size);
Greg Clayton88bc7f32012-11-06 00:20:41 +00002026
Sean Callananfaa0bb32012-12-05 23:37:14 +00002027 layout_info.field_offsets.insert(std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset));
Greg Clayton88bc7f32012-11-06 00:20:41 +00002028 }
2029 }
Greg Clayton78f4d952013-12-11 23:10:39 +00002030 last_field_info = this_field_info;
2031 }
2032 else
2033 {
2034 last_field_info.Clear();
Greg Clayton88bc7f32012-11-06 00:20:41 +00002035 }
Sean Callananfaa0bb32012-12-05 23:37:14 +00002036
Greg Clayton57ee3062013-07-11 22:46:58 +00002037 ClangASTType member_clang_type = member_type->GetClangLayoutType();
Sean Callananfa3ab452012-12-14 00:54:13 +00002038
2039 {
2040 // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>).
2041 // If the current field is at the end of the structure, then there is definitely no room for extra
2042 // elements and we override the type to array[0].
2043
Greg Clayton57ee3062013-07-11 22:46:58 +00002044 ClangASTType member_array_element_type;
Sean Callananfa3ab452012-12-14 00:54:13 +00002045 uint64_t member_array_size;
2046 bool member_array_is_incomplete;
2047
Greg Clayton57ee3062013-07-11 22:46:58 +00002048 if (member_clang_type.IsArrayType(&member_array_element_type,
2049 &member_array_size,
2050 &member_array_is_incomplete) &&
Sean Callananfa3ab452012-12-14 00:54:13 +00002051 !member_array_is_incomplete)
2052 {
2053 uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX);
2054
2055 if (member_byte_offset >= parent_byte_size)
2056 {
2057 if (member_array_size != 1)
2058 {
2059 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,
2060 MakeUserID(die->GetOffset()),
2061 name,
2062 encoding_uid,
2063 MakeUserID(parent_die->GetOffset()));
2064 }
2065
Greg Clayton1c8ef472013-04-05 23:27:21 +00002066 member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0, false);
Sean Callananfa3ab452012-12-14 00:54:13 +00002067 }
2068 }
2069 }
2070
Greg Clayton57ee3062013-07-11 22:46:58 +00002071 field_decl = class_clang_type.AddFieldToRecordType (name,
2072 member_clang_type,
2073 accessibility,
2074 bit_size);
Sean Callanan60217122012-04-13 00:10:03 +00002075
Greg Claytond0029442013-03-27 01:48:02 +00002076 GetClangASTContext().SetMetadataAsUserID (field_decl, MakeUserID(die->GetOffset()));
Sean Callananfaa0bb32012-12-05 23:37:14 +00002077
Greg Clayton78f4d952013-12-11 23:10:39 +00002078 layout_info.field_offsets.insert(std::make_pair(field_decl, field_bit_offset));
2079
Sean Callanan5b26f272012-02-04 08:49:35 +00002080 }
2081 else
2082 {
Sean Callanan751aac62012-03-29 19:07:06 +00002083 if (name)
Daniel Malead01b2952012-11-29 21:49:15 +00002084 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 +00002085 MakeUserID(die->GetOffset()),
2086 name,
2087 encoding_uid);
2088 else
Daniel Malead01b2952012-11-29 21:49:15 +00002089 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 +00002090 MakeUserID(die->GetOffset()),
2091 encoding_uid);
Sean Callanan5b26f272012-02-04 08:49:35 +00002092 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002093 }
Sean Callanan751aac62012-03-29 19:07:06 +00002094
Jim Inghame3ae82a2011-11-12 01:36:43 +00002095 if (prop_name != NULL)
2096 {
Sean Callanan751aac62012-03-29 19:07:06 +00002097 clang::ObjCIvarDecl *ivar_decl = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00002098
Sean Callanan751aac62012-03-29 19:07:06 +00002099 if (field_decl)
2100 {
2101 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
2102 assert (ivar_decl != NULL);
2103 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00002104
Jim Ingham379397632012-10-27 02:54:13 +00002105 ClangASTMetadata metadata;
2106 metadata.SetUserID (MakeUserID(die->GetOffset()));
Greg Clayton57ee3062013-07-11 22:46:58 +00002107 delayed_properties.push_back(DelayedAddObjCClassProperty(class_clang_type,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002108 prop_name,
2109 member_type->GetClangLayoutType(),
2110 ivar_decl,
2111 prop_setter_name,
2112 prop_getter_name,
2113 prop_attributes,
Jim Ingham379397632012-10-27 02:54:13 +00002114 &metadata));
Sean Callanan60217122012-04-13 00:10:03 +00002115
Sean Callananad880762012-04-18 01:06:17 +00002116 if (ivar_decl)
Greg Claytond0029442013-03-27 01:48:02 +00002117 GetClangASTContext().SetMetadataAsUserID (ivar_decl, MakeUserID(die->GetOffset()));
Jim Inghame3ae82a2011-11-12 01:36:43 +00002118 }
Greg Clayton24739922010-10-13 03:15:28 +00002119 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002120 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00002121 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002122 }
2123 break;
2124
2125 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00002126 // Let the type parsing code handle this one for us.
2127 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002128 break;
2129
2130 case DW_TAG_inheritance:
2131 {
2132 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00002133 if (default_accessibility == eAccessNone)
2134 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002135 // TODO: implement DW_TAG_inheritance type parsing
2136 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00002137 const size_t num_attributes = die->GetAttributes (this,
2138 dwarf_cu,
2139 fixed_form_sizes,
2140 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002141 if (num_attributes > 0)
2142 {
2143 Declaration decl;
2144 DWARFExpression location;
2145 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00002146 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002147 bool is_virtual = false;
2148 bool is_base_of_class = true;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002149 off_t member_byte_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002150 uint32_t i;
2151 for (i=0; i<num_attributes; ++i)
2152 {
2153 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2154 DWARFFormValue form_value;
2155 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2156 {
2157 switch (attr)
2158 {
2159 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2160 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2161 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2162 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002163 case DW_AT_data_member_location:
2164 if (form_value.BlockData())
2165 {
2166 Value initialValue(0);
2167 Value memberOffset(0);
Ed Masteeeae7212013-10-24 20:43:47 +00002168 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002169 uint32_t block_length = form_value.Unsigned();
2170 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
2171 if (DWARFExpression::Evaluate (NULL,
2172 NULL,
2173 NULL,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002174 NULL,
Richard Mitton0a558352013-10-17 21:14:00 +00002175 module,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002176 debug_info_data,
2177 block_offset,
2178 block_length,
2179 eRegisterKindDWARF,
2180 &initialValue,
2181 memberOffset,
2182 NULL))
2183 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002184 member_byte_offset = memberOffset.ResolveValue(NULL).UInt();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002185 }
2186 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002187 else
2188 {
2189 // With DWARF 3 and later, if the value is an integer constant,
2190 // this form value is the offset in bytes from the beginning
2191 // of the containing entity.
2192 member_byte_offset = form_value.Unsigned();
2193 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002194 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002195
2196 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00002197 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002198 break;
2199
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002200 case DW_AT_virtuality:
2201 is_virtual = form_value.Boolean();
2202 break;
2203
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002204 case DW_AT_sibling:
2205 break;
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002206
2207 default:
2208 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002209 }
2210 }
2211 }
2212
Greg Clayton526e5af2010-11-13 03:52:47 +00002213 Type *base_class_type = ResolveTypeUID(encoding_uid);
2214 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002215
Greg Clayton57ee3062013-07-11 22:46:58 +00002216 ClangASTType base_class_clang_type = base_class_type->GetClangFullType();
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002217 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002218 if (class_language == eLanguageTypeObjC)
2219 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002220 class_clang_type.SetObjCSuperClass(base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002221 }
2222 else
2223 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002224 base_classes.push_back (base_class_clang_type.CreateBaseClassSpecifier (accessibility,
Greg Claytonba2d22d2010-11-13 22:57:37 +00002225 is_virtual,
2226 is_base_of_class));
Greg Clayton2508b9b2012-11-01 23:20:02 +00002227
2228 if (is_virtual)
2229 {
Greg Clayton52694e32013-09-16 21:57:07 +00002230 // Do not specify any offset for virtual inheritance. The DWARF produced by clang doesn't
2231 // give us a constant offset, but gives us a DWARF expressions that requires an actual object
2232 // in memory. the DW_AT_data_member_location for a virtual base class looks like:
2233 // DW_AT_data_member_location( DW_OP_dup, DW_OP_deref, DW_OP_constu(0x00000018), DW_OP_minus, DW_OP_deref, DW_OP_plus )
2234 // Given this, there is really no valid response we can give to clang for virtual base
2235 // class offsets, and this should eventually be removed from LayoutRecordType() in the external
2236 // AST source in clang.
Greg Clayton2508b9b2012-11-01 23:20:02 +00002237 }
2238 else
2239 {
Greg Clayton57648732013-09-12 17:22:32 +00002240 layout_info.base_offsets.insert(std::make_pair(base_class_clang_type.GetAsCXXRecordDecl(),
Greg Clayton2508b9b2012-11-01 23:20:02 +00002241 clang::CharUnits::fromQuantity(member_byte_offset)));
2242 }
Greg Clayton9e409562010-07-28 02:04:09 +00002243 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002244 }
2245 }
2246 break;
2247
2248 default:
2249 break;
2250 }
2251 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002252
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002253 return count;
2254}
2255
2256
2257clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00002258SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002259{
2260 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00002261 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002262 {
2263 DWARFCompileUnitSP cu_sp;
2264 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
2265 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00002266 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00002267 }
2268 return NULL;
2269}
2270
2271clang::DeclContext*
2272SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
2273{
Greg Clayton81c22f62011-10-19 18:09:39 +00002274 if (UserIDMatches(type_uid))
2275 return GetClangDeclContextForDIEOffset (sc, type_uid);
2276 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002277}
2278
2279Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00002280SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002281{
Greg Clayton81c22f62011-10-19 18:09:39 +00002282 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002283 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002284 DWARFDebugInfo* debug_info = DebugInfo();
2285 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00002286 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002287 DWARFCompileUnitSP cu_sp;
2288 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00002289 const bool assert_not_being_parsed = true;
2290 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00002291 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002292 }
2293 return NULL;
2294}
2295
Greg Claytoncab36a32011-12-08 05:16:30 +00002296Type*
2297SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00002298{
Greg Claytoncab36a32011-12-08 05:16:30 +00002299 if (die != NULL)
2300 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002301 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00002302 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002303 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002304 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
2305 die->GetOffset(),
2306 DW_TAG_value_to_name(die->Tag()),
2307 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00002308
Greg Claytoncab36a32011-12-08 05:16:30 +00002309 // We might be coming in in the middle of a type tree (a class
2310 // withing a class, an enum within a class), so parse any needed
2311 // parent DIEs before we get to this one...
2312 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2313 switch (decl_ctx_die->Tag())
2314 {
2315 case DW_TAG_structure_type:
2316 case DW_TAG_union_type:
2317 case DW_TAG_class_type:
2318 {
2319 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00002320 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002321 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002322 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
2323 die->GetOffset(),
2324 DW_TAG_value_to_name(die->Tag()),
2325 die->GetName(this, cu),
2326 decl_ctx_die->GetOffset());
Greg Clayton219cf312012-03-30 00:51:13 +00002327//
2328// Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
2329// if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
2330// {
2331// if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002332// GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton219cf312012-03-30 00:51:13 +00002333// "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
2334// die->GetOffset(),
2335// DW_TAG_value_to_name(die->Tag()),
2336// die->GetName(this, cu),
2337// decl_ctx_die->GetOffset());
2338// // Ask the type to complete itself if it already hasn't since if we
2339// // want a function (method or static) from a class, the class must
2340// // create itself and add it's own methods and class functions.
2341// if (parent_type)
2342// parent_type->GetClangFullType();
2343// }
Greg Claytoncab36a32011-12-08 05:16:30 +00002344 }
2345 break;
2346
2347 default:
2348 break;
2349 }
2350 return ResolveType (cu, die);
2351 }
2352 return NULL;
2353}
2354
Greg Clayton6beaaa62011-01-17 03:46:26 +00002355// This function is used when SymbolFileDWARFDebugMap owns a bunch of
2356// SymbolFileDWARF objects to detect if this DWARF file is the one that
2357// can resolve a clang_type.
2358bool
Greg Clayton57ee3062013-07-11 22:46:58 +00002359SymbolFileDWARF::HasForwardDeclForClangType (const ClangASTType &clang_type)
Greg Clayton6beaaa62011-01-17 03:46:26 +00002360{
Greg Clayton57ee3062013-07-11 22:46:58 +00002361 ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers();
2362 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton6beaaa62011-01-17 03:46:26 +00002363 return die != NULL;
2364}
2365
2366
Greg Clayton57ee3062013-07-11 22:46:58 +00002367bool
2368SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (ClangASTType &clang_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00002369{
2370 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton57ee3062013-07-11 22:46:58 +00002371 ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers();
2372 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton1be10fc2010-09-29 01:12:09 +00002373 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00002374 {
2375 // We have already resolved this type...
Greg Clayton57ee3062013-07-11 22:46:58 +00002376 return true;
Greg Clayton73b472d2010-10-27 03:32:59 +00002377 }
2378 // Once we start resolving this type, remove it from the forward declaration
2379 // map in case anyone child members or other types require this type to get resolved.
2380 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
2381 // are done.
Greg Clayton57ee3062013-07-11 22:46:58 +00002382 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton73b472d2010-10-27 03:32:59 +00002383
Greg Clayton1be10fc2010-09-29 01:12:09 +00002384
Greg Clayton85ae2e12011-10-18 23:36:41 +00002385 // Disable external storage for this type so we don't get anymore
2386 // clang::ExternalASTSource queries for this type.
Greg Clayton57ee3062013-07-11 22:46:58 +00002387 clang_type.SetHasExternalStorage (false);
Greg Clayton85ae2e12011-10-18 23:36:41 +00002388
Greg Clayton450e3f32010-10-12 02:24:53 +00002389 DWARFDebugInfo* debug_info = DebugInfo();
2390
Greg Clayton53eb1c22012-04-02 22:59:12 +00002391 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002392 Type *type = m_die_to_type.lookup (die);
2393
2394 const dw_tag_t tag = die->Tag();
2395
Greg Clayton5160ce52013-03-27 23:08:40 +00002396 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
Greg Clayton3bffb082011-12-10 02:15:28 +00002397 if (log)
Greg Claytonbaf95da2012-03-30 23:50:54 +00002398 {
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 Claytonbaf95da2012-03-30 23:50:54 +00002404
Greg Claytonbaf95da2012-03-30 23:50:54 +00002405 }
Greg Clayton1be10fc2010-09-29 01:12:09 +00002406 assert (clang_type);
2407 DWARFDebugInfoEntry::Attributes attributes;
2408
Greg Clayton1be10fc2010-09-29 01:12:09 +00002409 switch (tag)
2410 {
2411 case DW_TAG_structure_type:
2412 case DW_TAG_union_type:
2413 case DW_TAG_class_type:
Greg Claytonc93237c2010-10-01 20:48:32 +00002414 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002415 LayoutInfo layout_info;
Sean Callanan77a1fd32012-02-27 20:07:01 +00002416
Greg Clayton1be10fc2010-09-29 01:12:09 +00002417 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002418 if (die->HasChildren())
Greg Claytonc93237c2010-10-01 20:48:32 +00002419 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002420
Sean Callanan77a1fd32012-02-27 20:07:01 +00002421 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton57ee3062013-07-11 22:46:58 +00002422 if (clang_type.IsObjCObjectOrInterfaceType())
Greg Clayton219cf312012-03-30 00:51:13 +00002423 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002424 class_language = eLanguageTypeObjC;
Greg Clayton219cf312012-03-30 00:51:13 +00002425 // For objective C we don't start the definition when
2426 // the class is created.
Greg Clayton57ee3062013-07-11 22:46:58 +00002427 clang_type.StartTagDeclarationDefinition ();
Greg Clayton219cf312012-03-30 00:51:13 +00002428 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002429
2430 int tag_decl_kind = -1;
2431 AccessType default_accessibility = eAccessNone;
2432 if (tag == DW_TAG_structure_type)
2433 {
2434 tag_decl_kind = clang::TTK_Struct;
2435 default_accessibility = eAccessPublic;
2436 }
2437 else if (tag == DW_TAG_union_type)
2438 {
2439 tag_decl_kind = clang::TTK_Union;
2440 default_accessibility = eAccessPublic;
2441 }
2442 else if (tag == DW_TAG_class_type)
2443 {
2444 tag_decl_kind = clang::TTK_Class;
2445 default_accessibility = eAccessPrivate;
2446 }
2447
Greg Clayton53eb1c22012-04-02 22:59:12 +00002448 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002449 std::vector<clang::CXXBaseSpecifier *> base_classes;
2450 std::vector<int> member_accessibilities;
2451 bool is_a_class = false;
2452 // Parse members and base classes first
2453 DWARFDIECollection member_function_dies;
Sean Callanana0b80ab2012-06-04 22:28:05 +00002454
2455 DelayedPropertyList delayed_properties;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002456 ParseChildMembers (sc,
Greg Clayton53eb1c22012-04-02 22:59:12 +00002457 dwarf_cu,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002458 die,
2459 clang_type,
2460 class_language,
2461 base_classes,
2462 member_accessibilities,
2463 member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002464 delayed_properties,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002465 default_accessibility,
2466 is_a_class,
2467 layout_info);
2468
2469 // Now parse any methods if there were any...
2470 size_t num_functions = member_function_dies.Size();
2471 if (num_functions > 0)
2472 {
2473 for (size_t i=0; i<num_functions; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002474 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002475 ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytoncaab74e2012-01-28 00:48:57 +00002476 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002477 }
2478
2479 if (class_language == eLanguageTypeObjC)
2480 {
Jim Inghamfb6fc0d2013-09-27 20:59:37 +00002481 ConstString class_name (clang_type.GetTypeName());
2482 if (class_name)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002483 {
Greg Clayton450e3f32010-10-12 02:24:53 +00002484
Sean Callanan77a1fd32012-02-27 20:07:01 +00002485 DIEArray method_die_offsets;
2486 if (m_using_apple_tables)
Greg Clayton95d87902011-11-11 03:16:25 +00002487 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002488 if (m_apple_objc_ap.get())
Jim Inghamfb6fc0d2013-09-27 20:59:37 +00002489 m_apple_objc_ap->FindByName(class_name.GetCString(), method_die_offsets);
Sean Callanan77a1fd32012-02-27 20:07:01 +00002490 }
2491 else
2492 {
2493 if (!m_indexed)
2494 Index ();
Greg Claytoncaab74e2012-01-28 00:48:57 +00002495
Sean Callanan77a1fd32012-02-27 20:07:01 +00002496 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
2497 }
2498
2499 if (!method_die_offsets.empty())
2500 {
2501 DWARFDebugInfo* debug_info = DebugInfo();
2502
2503 DWARFCompileUnit* method_cu = NULL;
2504 const size_t num_matches = method_die_offsets.size();
2505 for (size_t i=0; i<num_matches; ++i)
Greg Clayton95d87902011-11-11 03:16:25 +00002506 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002507 const dw_offset_t die_offset = method_die_offsets[i];
2508 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
2509
2510 if (method_die)
2511 ResolveType (method_cu, method_die);
2512 else
Greg Claytoncaab74e2012-01-28 00:48:57 +00002513 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002514 if (m_using_apple_tables)
2515 {
2516 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 +00002517 die_offset, class_name.GetCString());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002518 }
2519 }
2520 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002521 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002522
Greg Clayton57ee3062013-07-11 22:46:58 +00002523 for (DelayedPropertyList::iterator pi = delayed_properties.begin(), pe = delayed_properties.end();
Sean Callanana0b80ab2012-06-04 22:28:05 +00002524 pi != pe;
2525 ++pi)
2526 pi->Finalize();
Greg Clayton450e3f32010-10-12 02:24:53 +00002527 }
2528 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002529
2530 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2531 // need to tell the clang type it is actually a class.
2532 if (class_language != eLanguageTypeObjC)
2533 {
2534 if (is_a_class && tag_decl_kind != clang::TTK_Class)
Greg Clayton57ee3062013-07-11 22:46:58 +00002535 clang_type.SetTagTypeKind (clang::TTK_Class);
Sean Callanan77a1fd32012-02-27 20:07:01 +00002536 }
2537
2538 // Since DW_TAG_structure_type gets used for both classes
2539 // and structures, we may need to set any DW_TAG_member
2540 // fields to have a "private" access if none was specified.
2541 // When we parsed the child members we tracked that actual
2542 // accessibility value for each DW_TAG_member in the
2543 // "member_accessibilities" array. If the value for the
2544 // member is zero, then it was set to the "default_accessibility"
2545 // which for structs was "public". Below we correct this
2546 // by setting any fields to "private" that weren't correctly
2547 // set.
2548 if (is_a_class && !member_accessibilities.empty())
2549 {
2550 // This is a class and all members that didn't have
2551 // their access specified are private.
Greg Clayton57ee3062013-07-11 22:46:58 +00002552 clang_type.SetDefaultAccessForRecordFields (eAccessPrivate,
2553 &member_accessibilities.front(),
2554 member_accessibilities.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002555 }
2556
2557 if (!base_classes.empty())
2558 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002559 clang_type.SetBaseClassesForClassType (&base_classes.front(),
2560 base_classes.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002561
2562 // Clang will copy each CXXBaseSpecifier in "base_classes"
2563 // so we have to free them all.
Greg Clayton57ee3062013-07-11 22:46:58 +00002564 ClangASTType::DeleteBaseClassSpecifiers (&base_classes.front(),
2565 base_classes.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002566 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002567 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002568 }
Sean Callanane8c0cfb2012-03-02 01:03:45 +00002569
Greg Clayton57ee3062013-07-11 22:46:58 +00002570 clang_type.BuildIndirectFields ();
2571 clang_type.CompleteTagDeclarationDefinition ();
Sean Callanan5b26f272012-02-04 08:49:35 +00002572
Greg Clayton2508b9b2012-11-01 23:20:02 +00002573 if (!layout_info.field_offsets.empty() ||
2574 !layout_info.base_offsets.empty() ||
2575 !layout_info.vbase_offsets.empty() )
Greg Claytoncaab74e2012-01-28 00:48:57 +00002576 {
2577 if (type)
2578 layout_info.bit_size = type->GetByteSize() * 8;
2579 if (layout_info.bit_size == 0)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002580 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002581
Greg Clayton57ee3062013-07-11 22:46:58 +00002582 clang::CXXRecordDecl *record_decl = clang_type.GetAsCXXRecordDecl();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002583 if (record_decl)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002584 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002585 if (log)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002586 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002587 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002588 "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])",
Greg Clayton57ee3062013-07-11 22:46:58 +00002589 clang_type.GetOpaqueQualType(),
Greg Claytoncaab74e2012-01-28 00:48:57 +00002590 record_decl,
2591 layout_info.bit_size,
2592 layout_info.alignment,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002593 (uint32_t)layout_info.field_offsets.size(),
2594 (uint32_t)layout_info.base_offsets.size(),
2595 (uint32_t)layout_info.vbase_offsets.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002596
Greg Clayton2508b9b2012-11-01 23:20:02 +00002597 uint32_t idx;
2598 {
Greg Clayton821ac6d2012-01-28 02:22:27 +00002599 llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002600 for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002601 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002602 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002603 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = { bit_offset=%u, name='%s' }",
Greg Clayton57ee3062013-07-11 22:46:58 +00002604 clang_type.GetOpaqueQualType(),
Greg Clayton2508b9b2012-11-01 23:20:02 +00002605 idx,
Greg Clayton821ac6d2012-01-28 02:22:27 +00002606 (uint32_t)pos->second,
2607 pos->first->getNameAsString().c_str());
2608 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002609 }
2610
2611 {
2612 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos, base_end = layout_info.base_offsets.end();
2613 for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; ++base_pos, ++idx)
2614 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002615 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002616 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] = { byte_offset=%u, name='%s' }",
Greg Clayton57ee3062013-07-11 22:46:58 +00002617 clang_type.GetOpaqueQualType(),
Greg Clayton2508b9b2012-11-01 23:20:02 +00002618 idx,
2619 (uint32_t)base_pos->second.getQuantity(),
2620 base_pos->first->getNameAsString().c_str());
2621 }
2622 }
2623 {
2624 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos, vbase_end = layout_info.vbase_offsets.end();
2625 for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; ++vbase_pos, ++idx)
2626 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002627 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002628 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) vbase[%u] = { byte_offset=%u, name='%s' }",
Greg Clayton57ee3062013-07-11 22:46:58 +00002629 clang_type.GetOpaqueQualType(),
Greg Clayton2508b9b2012-11-01 23:20:02 +00002630 idx,
2631 (uint32_t)vbase_pos->second.getQuantity(),
2632 vbase_pos->first->getNameAsString().c_str());
2633 }
2634 }
Greg Clayton821ac6d2012-01-28 02:22:27 +00002635 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002636 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2637 }
2638 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002639 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002640
Sean Callanan9076c0f2013-10-04 21:35:29 +00002641 return (bool)clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002642
2643 case DW_TAG_enumeration_type:
Greg Clayton57ee3062013-07-11 22:46:58 +00002644 clang_type.StartTagDeclarationDefinition ();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002645 if (die->HasChildren())
2646 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002647 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00002648 bool is_signed = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00002649 clang_type.IsIntegerType(is_signed);
Greg Clayton3e067532013-03-05 23:54:39 +00002650 ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002651 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002652 clang_type.CompleteTagDeclarationDefinition ();
Sean Callanan9076c0f2013-10-04 21:35:29 +00002653 return (bool)clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002654
2655 default:
2656 assert(false && "not a forward clang type decl!");
2657 break;
2658 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002659 return false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002660}
2661
Greg Claytonc685f8e2010-09-15 04:15:46 +00002662Type*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002663SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002664{
2665 if (type_die != NULL)
2666 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002667 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00002668
Greg Claytonc685f8e2010-09-15 04:15:46 +00002669 if (type == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002670 type = GetTypeForDIE (dwarf_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00002671
Greg Clayton24739922010-10-13 03:15:28 +00002672 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00002673 {
2674 if (type != DIE_IS_BEING_PARSED)
2675 return type;
2676
2677 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
Greg Clayton53eb1c22012-04-02 22:59:12 +00002678 type_die->GetOffset(),
2679 DW_TAG_value_to_name(type_die->Tag()),
2680 type_die->GetName(this, dwarf_cu));
Jim Inghamc3549282012-01-11 02:21:12 +00002681
2682 }
2683 else
2684 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002685 }
2686 return NULL;
2687}
2688
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002689CompileUnit*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002690SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002691{
2692 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002693 if (dwarf_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002694 {
2695 // The symbol vendor doesn't know about this compile unit, we
2696 // need to parse and add it to the symbol vendor object.
Greg Clayton53eb1c22012-04-02 22:59:12 +00002697 return ParseCompileUnit(dwarf_cu, cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002698 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00002699 return (CompileUnit*)dwarf_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002700}
2701
2702bool
Greg Clayton53eb1c22012-04-02 22:59:12 +00002703SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002704{
Greg Clayton72310352013-02-23 04:12:47 +00002705 sc.Clear(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002706 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002707 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002708
Greg Clayton81c22f62011-10-19 18:09:39 +00002709 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002710 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002711 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002712
2713 if (sc.function)
2714 {
Greg Claytone72dfb32012-02-24 01:59:29 +00002715 sc.module_sp = sc.function->CalculateSymbolContextModule();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002716 return true;
2717 }
2718
2719 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002720}
2721
2722uint32_t
2723SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2724{
2725 Timer scoped_timer(__PRETTY_FUNCTION__,
Daniel Malead01b2952012-11-29 21:49:15 +00002726 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)",
Greg Claytone72dfb32012-02-24 01:59:29 +00002727 so_addr.GetSection().get(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002728 so_addr.GetOffset(),
2729 resolve_scope);
2730 uint32_t resolved = 0;
2731 if (resolve_scope & ( eSymbolContextCompUnit |
2732 eSymbolContextFunction |
2733 eSymbolContextBlock |
2734 eSymbolContextLineEntry))
2735 {
2736 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2737
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002738 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00002739 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002740 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002741 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002742 if (cu_offset != DW_INVALID_OFFSET)
2743 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002744 uint32_t cu_idx = DW_INVALID_INDEX;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002745 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
2746 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002747 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002748 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002749 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002750 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002751 resolved |= eSymbolContextCompUnit;
2752
Greg Clayton6ab80132012-12-12 17:30:52 +00002753 bool force_check_line_table = false;
Greg Clayton526a4ae2012-05-16 22:09:01 +00002754 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2755 {
2756 DWARFDebugInfoEntry *function_die = NULL;
2757 DWARFDebugInfoEntry *block_die = NULL;
2758 if (resolve_scope & eSymbolContextBlock)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002759 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002760 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
2761 }
2762 else
2763 {
2764 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL);
2765 }
2766
2767 if (function_die != NULL)
2768 {
2769 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2770 if (sc.function == NULL)
2771 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2772 }
2773 else
2774 {
2775 // We might have had a compile unit that had discontiguous
2776 // address ranges where the gaps are symbols that don't have
2777 // any debug info. Discontiguous compile unit address ranges
2778 // should only happen when there aren't other functions from
2779 // other compile units in these gaps. This helps keep the size
2780 // of the aranges down.
Greg Clayton6ab80132012-12-12 17:30:52 +00002781 force_check_line_table = true;
Greg Clayton526a4ae2012-05-16 22:09:01 +00002782 }
2783
2784 if (sc.function != NULL)
2785 {
2786 resolved |= eSymbolContextFunction;
2787
2788 if (resolve_scope & eSymbolContextBlock)
2789 {
2790 Block& block = sc.function->GetBlock (true);
2791
2792 if (block_die != NULL)
2793 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2794 else
2795 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2796 if (sc.block)
2797 resolved |= eSymbolContextBlock;
2798 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002799 }
2800 }
Greg Clayton6ab80132012-12-12 17:30:52 +00002801
2802 if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table)
2803 {
2804 LineTable *line_table = sc.comp_unit->GetLineTable();
2805 if (line_table != NULL)
2806 {
Greg Clayton9422dd62013-03-04 21:46:16 +00002807 // And address that makes it into this function should be in terms
2808 // of this debug file if there is no debug map, or it will be an
2809 // address in the .o file which needs to be fixed up to be in terms
2810 // of the debug map executable. Either way, calling FixupAddress()
2811 // will work for us.
2812 Address exe_so_addr (so_addr);
2813 if (FixupAddress(exe_so_addr))
Greg Clayton6ab80132012-12-12 17:30:52 +00002814 {
Greg Clayton9422dd62013-03-04 21:46:16 +00002815 if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry))
Greg Clayton6ab80132012-12-12 17:30:52 +00002816 {
2817 resolved |= eSymbolContextLineEntry;
2818 }
2819 }
Greg Clayton6ab80132012-12-12 17:30:52 +00002820 }
2821 }
2822
2823 if (force_check_line_table && !(resolved & eSymbolContextLineEntry))
2824 {
2825 // We might have had a compile unit that had discontiguous
2826 // address ranges where the gaps are symbols that don't have
2827 // any debug info. Discontiguous compile unit address ranges
2828 // should only happen when there aren't other functions from
2829 // other compile units in these gaps. This helps keep the size
2830 // of the aranges down.
2831 sc.comp_unit = NULL;
2832 resolved &= ~eSymbolContextCompUnit;
2833 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002834 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002835 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002836 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002837 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.",
2838 cu_offset,
2839 cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002840 }
2841 }
2842 }
2843 }
2844 }
2845 return resolved;
2846}
2847
2848
2849
2850uint32_t
2851SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
2852{
2853 const uint32_t prev_size = sc_list.GetSize();
2854 if (resolve_scope & eSymbolContextCompUnit)
2855 {
2856 DWARFDebugInfo* debug_info = DebugInfo();
2857 if (debug_info)
2858 {
2859 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002860 DWARFCompileUnit* dwarf_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002861
Greg Clayton53eb1c22012-04-02 22:59:12 +00002862 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002863 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002864 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Sean Callananddd7a2a2013-10-03 22:27:29 +00002865 const bool full_match = (bool)file_spec.GetDirectory();
Greg Clayton1f746072012-08-29 21:13:06 +00002866 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 +00002867 if (check_inlines || file_spec_matches_cu_file_spec)
2868 {
2869 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton53eb1c22012-04-02 22:59:12 +00002870 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002871 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002872 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002873 uint32_t file_idx = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002874
Greg Clayton526a4ae2012-05-16 22:09:01 +00002875 // If we are looking for inline functions only and we don't
2876 // find it in the support files, we are done.
2877 if (check_inlines)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002878 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002879 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
2880 if (file_idx == UINT32_MAX)
2881 continue;
2882 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002883
Greg Clayton526a4ae2012-05-16 22:09:01 +00002884 if (line != 0)
2885 {
2886 LineTable *line_table = sc.comp_unit->GetLineTable();
2887
2888 if (line_table != NULL && line != 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002889 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002890 // We will have already looked up the file index if
2891 // we are searching for inline entries.
2892 if (!check_inlines)
2893 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002894
Greg Clayton526a4ae2012-05-16 22:09:01 +00002895 if (file_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002896 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002897 uint32_t found_line;
2898 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
2899 found_line = sc.line_entry.line;
2900
2901 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002902 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002903 sc.function = NULL;
2904 sc.block = NULL;
2905 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002906 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002907 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
2908 if (file_vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002909 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002910 DWARFDebugInfoEntry *function_die = NULL;
2911 DWARFDebugInfoEntry *block_die = NULL;
2912 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002913
Greg Clayton526a4ae2012-05-16 22:09:01 +00002914 if (function_die != NULL)
2915 {
2916 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2917 if (sc.function == NULL)
2918 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2919 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002920
Greg Clayton526a4ae2012-05-16 22:09:01 +00002921 if (sc.function != NULL)
2922 {
2923 Block& block = sc.function->GetBlock (true);
2924
2925 if (block_die != NULL)
2926 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2927 else
2928 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2929 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002930 }
2931 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002932
Greg Clayton526a4ae2012-05-16 22:09:01 +00002933 sc_list.Append(sc);
2934 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2935 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002936 }
2937 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002938 else if (file_spec_matches_cu_file_spec && !check_inlines)
2939 {
2940 // only append the context if we aren't looking for inline call sites
2941 // by file and line and if the file spec matches that of the compile unit
2942 sc_list.Append(sc);
2943 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002944 }
2945 else if (file_spec_matches_cu_file_spec && !check_inlines)
2946 {
2947 // only append the context if we aren't looking for inline call sites
2948 // by file and line and if the file spec matches that of the compile unit
2949 sc_list.Append(sc);
2950 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002951
Greg Clayton526a4ae2012-05-16 22:09:01 +00002952 if (!check_inlines)
2953 break;
2954 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002955 }
2956 }
2957 }
2958 }
2959 return sc_list.GetSize() - prev_size;
2960}
2961
2962void
2963SymbolFileDWARF::Index ()
2964{
2965 if (m_indexed)
2966 return;
2967 m_indexed = true;
2968 Timer scoped_timer (__PRETTY_FUNCTION__,
2969 "SymbolFileDWARF::Index (%s)",
2970 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
2971
2972 DWARFDebugInfo* debug_info = DebugInfo();
2973 if (debug_info)
2974 {
2975 uint32_t cu_idx = 0;
2976 const uint32_t num_compile_units = GetNumCompileUnits();
2977 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2978 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002979 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002980
Greg Clayton53eb1c22012-04-02 22:59:12 +00002981 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002982
Greg Clayton53eb1c22012-04-02 22:59:12 +00002983 dwarf_cu->Index (cu_idx,
2984 m_function_basename_index,
2985 m_function_fullname_index,
2986 m_function_method_index,
2987 m_function_selector_index,
2988 m_objc_class_selectors_index,
2989 m_global_index,
2990 m_type_index,
2991 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002992
2993 // Keep memory down by clearing DIEs if this generate function
2994 // caused them to be parsed
2995 if (clear_dies)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002996 dwarf_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002997 }
2998
Greg Claytond4a2b372011-09-12 23:21:58 +00002999 m_function_basename_index.Finalize();
3000 m_function_fullname_index.Finalize();
3001 m_function_method_index.Finalize();
3002 m_function_selector_index.Finalize();
3003 m_objc_class_selectors_index.Finalize();
3004 m_global_index.Finalize();
3005 m_type_index.Finalize();
3006 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003007
Greg Clayton24739922010-10-13 03:15:28 +00003008#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00003009 StreamFile s(stdout, false);
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00003010 s.Printf ("DWARF index for '%s':",
3011 GetObjectFile()->GetFileSpec().GetPath().c_str());
Greg Claytonba2d22d2010-11-13 22:57:37 +00003012 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
3013 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
3014 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
3015 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
3016 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
3017 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00003018 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00003019 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00003020#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003021 }
3022}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003023
3024bool
3025SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
3026{
3027 if (namespace_decl == NULL)
3028 {
3029 // Invalid namespace decl which means we aren't matching only things
3030 // in this symbol file, so return true to indicate it matches this
3031 // symbol file.
3032 return true;
3033 }
3034
3035 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
3036
3037 if (namespace_ast == NULL)
3038 return true; // No AST in the "namespace_decl", return true since it
3039 // could then match any symbol file, including this one
3040
3041 if (namespace_ast == GetClangASTContext().getASTContext())
3042 return true; // The ASTs match, return true
3043
3044 // The namespace AST was valid, and it does not match...
Greg Clayton5160ce52013-03-27 23:08:40 +00003045 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Sean Callananc41e68b2011-10-13 21:08:11 +00003046
3047 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003048 GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00003049
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003050 return false;
3051}
3052
Greg Clayton2506a7a2011-10-12 23:34:26 +00003053bool
3054SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
3055 DWARFCompileUnit* cu,
3056 const DWARFDebugInfoEntry* die)
3057{
3058 // No namespace specified, so the answesr i
3059 if (namespace_decl == NULL)
3060 return true;
Sean Callananebe60672011-10-13 21:50:33 +00003061
Greg Clayton5160ce52013-03-27 23:08:40 +00003062 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003063
Greg Clayton437a1352012-04-09 22:43:43 +00003064 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
3065 clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00003066 if (decl_ctx_die)
Greg Clayton437a1352012-04-09 22:43:43 +00003067 {
Greg Clayton2506a7a2011-10-12 23:34:26 +00003068 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
Greg Clayton437a1352012-04-09 22:43:43 +00003069
Greg Clayton2506a7a2011-10-12 23:34:26 +00003070 if (clang_namespace_decl)
3071 {
3072 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00003073 {
3074 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003075 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00003076 return false;
Sean Callananebe60672011-10-13 21:50:33 +00003077 }
3078
Greg Clayton437a1352012-04-09 22:43:43 +00003079 if (clang_namespace_decl == die_clang_decl_ctx)
3080 return true;
3081 else
Greg Clayton2506a7a2011-10-12 23:34:26 +00003082 return false;
Greg Clayton2506a7a2011-10-12 23:34:26 +00003083 }
3084 else
3085 {
3086 // We have a namespace_decl that was not NULL but it contained
3087 // a NULL "clang::NamespaceDecl", so this means the global namespace
3088 // So as long the the contained decl context DIE isn't a namespace
3089 // we should be ok.
3090 if (decl_ctx_die->Tag() != DW_TAG_namespace)
3091 return true;
3092 }
3093 }
Sean Callananebe60672011-10-13 21:50:33 +00003094
3095 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003096 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00003097
Greg Clayton2506a7a2011-10-12 23:34:26 +00003098 return false;
3099}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003100uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00003101SymbolFileDWARF::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 +00003102{
Greg Clayton5160ce52013-03-27 23:08:40 +00003103 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003104
3105 if (log)
3106 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003107 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003108 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
3109 name.GetCString(),
3110 namespace_decl,
3111 append,
3112 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003113 }
Sean Callanan213fdb82011-10-13 01:49:10 +00003114
3115 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00003116 return 0;
Sean Callanan213fdb82011-10-13 01:49:10 +00003117
Greg Claytonc685f8e2010-09-15 04:15:46 +00003118 DWARFDebugInfo* info = DebugInfo();
3119 if (info == NULL)
3120 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003121
3122 // If we aren't appending the results to this list, then clear the list
3123 if (!append)
3124 variables.Clear();
3125
3126 // Remember how many variables are in the list before we search in case
3127 // we are appending the results to a variable list.
3128 const uint32_t original_size = variables.GetSize();
3129
Greg Claytond4a2b372011-09-12 23:21:58 +00003130 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003131
Greg Clayton97fbc342011-10-20 22:30:33 +00003132 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003133 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003134 if (m_apple_names_ap.get())
3135 {
3136 const char *name_cstr = name.GetCString();
3137 const char *base_name_start;
3138 const char *base_name_end = NULL;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003139
Greg Clayton97fbc342011-10-20 22:30:33 +00003140 if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end))
3141 base_name_start = name_cstr;
3142
3143 m_apple_names_ap->FindByName (base_name_start, die_offsets);
3144 }
Greg Clayton7f995132011-10-04 22:41:51 +00003145 }
3146 else
3147 {
3148 // Index the DWARF if we haven't already
3149 if (!m_indexed)
3150 Index ();
3151
3152 m_global_index.Find (name, die_offsets);
3153 }
3154
Greg Clayton437a1352012-04-09 22:43:43 +00003155 const size_t num_die_matches = die_offsets.size();
3156 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003157 {
Greg Clayton7f995132011-10-04 22:41:51 +00003158 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003159 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00003160 assert (sc.module_sp);
3161
Greg Claytond4a2b372011-09-12 23:21:58 +00003162 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00003163 DWARFCompileUnit* dwarf_cu = NULL;
3164 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton437a1352012-04-09 22:43:43 +00003165 bool done = false;
3166 for (size_t i=0; i<num_die_matches && !done; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00003167 {
3168 const dw_offset_t die_offset = die_offsets[i];
3169 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003170
Greg Clayton95d87902011-11-11 03:16:25 +00003171 if (die)
3172 {
Greg Clayton437a1352012-04-09 22:43:43 +00003173 switch (die->Tag())
3174 {
3175 default:
3176 case DW_TAG_subprogram:
3177 case DW_TAG_inlined_subroutine:
3178 case DW_TAG_try_block:
3179 case DW_TAG_catch_block:
3180 break;
3181
3182 case DW_TAG_variable:
3183 {
3184 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Greg Clayton437a1352012-04-09 22:43:43 +00003185
3186 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3187 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003188
Greg Clayton437a1352012-04-09 22:43:43 +00003189 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003190
Greg Clayton437a1352012-04-09 22:43:43 +00003191 if (variables.GetSize() - original_size >= max_matches)
3192 done = true;
3193 }
3194 break;
3195 }
Greg Clayton95d87902011-11-11 03:16:25 +00003196 }
3197 else
3198 {
3199 if (m_using_apple_tables)
3200 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003201 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
3202 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003203 }
3204 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003205 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003206 }
3207
3208 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003209 const uint32_t num_matches = variables.GetSize() - original_size;
3210 if (log && num_matches > 0)
3211 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003212 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003213 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u",
3214 name.GetCString(),
3215 namespace_decl,
3216 append,
3217 max_matches,
3218 num_matches);
3219 }
3220 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003221}
3222
3223uint32_t
3224SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
3225{
Greg Clayton5160ce52013-03-27 23:08:40 +00003226 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003227
3228 if (log)
3229 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003230 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003231 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
3232 regex.GetText(),
3233 append,
3234 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003235 }
3236
Greg Claytonc685f8e2010-09-15 04:15:46 +00003237 DWARFDebugInfo* info = DebugInfo();
3238 if (info == NULL)
3239 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003240
3241 // If we aren't appending the results to this list, then clear the list
3242 if (!append)
3243 variables.Clear();
3244
3245 // Remember how many variables are in the list before we search in case
3246 // we are appending the results to a variable list.
3247 const uint32_t original_size = variables.GetSize();
3248
Greg Clayton7f995132011-10-04 22:41:51 +00003249 DIEArray die_offsets;
3250
Greg Clayton97fbc342011-10-20 22:30:33 +00003251 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003252 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003253 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00003254 {
3255 DWARFMappedHash::DIEInfoArray hash_data_array;
3256 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
3257 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
3258 }
Greg Clayton7f995132011-10-04 22:41:51 +00003259 }
3260 else
3261 {
3262 // Index the DWARF if we haven't already
3263 if (!m_indexed)
3264 Index ();
3265
3266 m_global_index.Find (regex, die_offsets);
3267 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003268
Greg Claytonc685f8e2010-09-15 04:15:46 +00003269 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003270 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003271 assert (sc.module_sp);
3272
Greg Claytond4a2b372011-09-12 23:21:58 +00003273 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00003274 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003275 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003276 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003277 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003278 DWARFDebugInfo* debug_info = DebugInfo();
3279 for (size_t i=0; i<num_matches; ++i)
3280 {
3281 const dw_offset_t die_offset = die_offsets[i];
3282 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00003283
3284 if (die)
3285 {
3286 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003287
Greg Clayton95d87902011-11-11 03:16:25 +00003288 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003289
Greg Clayton95d87902011-11-11 03:16:25 +00003290 if (variables.GetSize() - original_size >= max_matches)
3291 break;
3292 }
3293 else
3294 {
3295 if (m_using_apple_tables)
3296 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003297 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
3298 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00003299 }
3300 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003301 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003302 }
3303
3304 // Return the number of variable that were appended to the list
3305 return variables.GetSize() - original_size;
3306}
3307
Greg Claytonaa044962011-10-13 00:59:38 +00003308
Jim Ingham4cda6e02011-10-07 22:23:45 +00003309bool
3310SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
3311 DWARFCompileUnit *&dwarf_cu,
3312 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00003313{
Greg Claytonaa044962011-10-13 00:59:38 +00003314 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3315 return ResolveFunction (dwarf_cu, die, sc_list);
3316}
3317
3318
3319bool
3320SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
3321 const DWARFDebugInfoEntry *die,
3322 SymbolContextList& sc_list)
3323{
Greg Clayton9e315582011-09-02 04:03:59 +00003324 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00003325
3326 if (die == NULL)
3327 return false;
3328
Jim Ingham4cda6e02011-10-07 22:23:45 +00003329 // If we were passed a die that is not a function, just return false...
3330 if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine)
3331 return false;
3332
3333 const DWARFDebugInfoEntry* inlined_die = NULL;
3334 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00003335 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003336 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00003337
Jim Ingham4cda6e02011-10-07 22:23:45 +00003338 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003339 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003340 if (die->Tag() == DW_TAG_subprogram)
3341 break;
Greg Clayton9e315582011-09-02 04:03:59 +00003342 }
3343 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003344 assert (die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00003345 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003346 {
3347 Address addr;
3348 // Parse all blocks if needed
3349 if (inlined_die)
3350 {
Greg Clayton81c22f62011-10-19 18:09:39 +00003351 sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset()));
Jim Ingham4cda6e02011-10-07 22:23:45 +00003352 assert (sc.block != NULL);
3353 if (sc.block->GetStartAddress (addr) == false)
3354 addr.Clear();
3355 }
3356 else
3357 {
3358 sc.block = NULL;
3359 addr = sc.function->GetAddressRange().GetBaseAddress();
3360 }
3361
3362 if (addr.IsValid())
3363 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003364 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00003365 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003366 }
3367 }
3368
Greg Claytonaa044962011-10-13 00:59:38 +00003369 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00003370}
3371
Greg Clayton7f995132011-10-04 22:41:51 +00003372void
3373SymbolFileDWARF::FindFunctions (const ConstString &name,
3374 const NameToDIE &name_to_die,
3375 SymbolContextList& sc_list)
3376{
Greg Claytond4a2b372011-09-12 23:21:58 +00003377 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003378 if (name_to_die.Find (name, die_offsets))
3379 {
3380 ParseFunctions (die_offsets, sc_list);
3381 }
3382}
3383
3384
3385void
3386SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3387 const NameToDIE &name_to_die,
3388 SymbolContextList& sc_list)
3389{
3390 DIEArray die_offsets;
3391 if (name_to_die.Find (regex, die_offsets))
3392 {
3393 ParseFunctions (die_offsets, sc_list);
3394 }
3395}
3396
3397
3398void
3399SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3400 const DWARFMappedHash::MemoryTable &memory_table,
3401 SymbolContextList& sc_list)
3402{
3403 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00003404 DWARFMappedHash::DIEInfoArray hash_data_array;
3405 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00003406 {
Greg Claytond1767f02011-12-08 02:13:16 +00003407 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Greg Clayton7f995132011-10-04 22:41:51 +00003408 ParseFunctions (die_offsets, sc_list);
3409 }
3410}
3411
3412void
3413SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
3414 SymbolContextList& sc_list)
3415{
3416 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003417 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00003418 {
Greg Clayton7f995132011-10-04 22:41:51 +00003419 SymbolContext sc;
Greg Clayton7f995132011-10-04 22:41:51 +00003420
3421 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003422 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00003423 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003424 const dw_offset_t die_offset = die_offsets[i];
Jim Ingham4cda6e02011-10-07 22:23:45 +00003425 ResolveFunction (die_offset, dwarf_cu, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003426 }
3427 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00003428}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003429
Jim Ingham4cda6e02011-10-07 22:23:45 +00003430bool
3431SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
3432 const DWARFCompileUnit *dwarf_cu,
3433 uint32_t name_type_mask,
3434 const char *partial_name,
3435 const char *base_name_start,
3436 const char *base_name_end)
3437{
Greg Claytonfbea0f62012-11-15 18:05:43 +00003438 // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes:
3439 if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003440 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003441 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
3442 if (!containing_decl_ctx)
3443 return false;
3444
3445 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
3446
Greg Claytonfbea0f62012-11-15 18:05:43 +00003447 if (name_type_mask == eFunctionNameTypeMethod)
3448 {
3449 if (is_cxx_method == false)
3450 return false;
3451 }
3452
3453 if (name_type_mask == eFunctionNameTypeBase)
3454 {
3455 if (is_cxx_method == true)
3456 return false;
3457 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003458 }
3459
3460 // Now we need to check whether the name we got back for this type matches the extra specifications
3461 // that were in the name we're looking up:
3462 if (base_name_start != partial_name || *base_name_end != '\0')
3463 {
3464 // First see if the stuff to the left matches the full name. To do that let's see if
3465 // we can pull out the mips linkage name attribute:
3466
3467 Mangled best_name;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003468 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonfbea0f62012-11-15 18:05:43 +00003469 DWARFFormValue form_value;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003470 die->GetAttributes(this, dwarf_cu, NULL, attributes);
3471 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
Greg Clayton71415542012-12-08 00:24:40 +00003472 if (idx == UINT32_MAX)
3473 idx = attributes.FindAttributeIndex(DW_AT_linkage_name);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003474 if (idx != UINT32_MAX)
3475 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003476 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
3477 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003478 const char *mangled_name = form_value.AsCString(&get_debug_str_data());
3479 if (mangled_name)
3480 best_name.SetValue (ConstString(mangled_name), true);
3481 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003482 }
Greg Claytonfbea0f62012-11-15 18:05:43 +00003483
3484 if (!best_name)
3485 {
3486 idx = attributes.FindAttributeIndex(DW_AT_name);
3487 if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value))
3488 {
3489 const char *name = form_value.AsCString(&get_debug_str_data());
3490 best_name.SetValue (ConstString(name), false);
3491 }
3492 }
3493
3494 if (best_name.GetDemangledName())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003495 {
3496 const char *demangled = best_name.GetDemangledName().GetCString();
3497 if (demangled)
3498 {
3499 std::string name_no_parens(partial_name, base_name_end - partial_name);
Jim Ingham85c13d72012-03-02 02:24:42 +00003500 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str());
3501 if (partial_in_demangled == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003502 return false;
Jim Ingham85c13d72012-03-02 02:24:42 +00003503 else
3504 {
3505 // Sort out the case where our name is something like "Process::Destroy" and the match is
3506 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on
3507 // namespace boundaries...
3508
3509 if (partial_name[0] == ':' && partial_name[1] == ':')
3510 {
3511 // The partial name was already on a namespace boundary so all matches are good.
3512 return true;
3513 }
3514 else if (partial_in_demangled == demangled)
3515 {
3516 // They both start the same, so this is an good match.
3517 return true;
3518 }
3519 else
3520 {
3521 if (partial_in_demangled - demangled == 1)
3522 {
3523 // Only one character difference, can't be a namespace boundary...
3524 return false;
3525 }
3526 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':')
3527 {
3528 // We are on a namespace boundary, so this is also good.
3529 return true;
3530 }
3531 else
3532 return false;
3533 }
3534 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003535 }
3536 }
3537 }
3538
3539 return true;
3540}
Greg Claytonc685f8e2010-09-15 04:15:46 +00003541
Greg Clayton0c5cd902010-06-28 21:30:43 +00003542uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00003543SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00003544 const lldb_private::ClangNamespaceDecl *namespace_decl,
Sean Callanan9df05fb2012-02-10 22:52:19 +00003545 uint32_t name_type_mask,
3546 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00003547 bool append,
3548 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00003549{
3550 Timer scoped_timer (__PRETTY_FUNCTION__,
3551 "SymbolFileDWARF::FindFunctions (name = '%s')",
3552 name.AsCString());
3553
Greg Clayton43fe2172013-04-03 02:00:15 +00003554 // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup()
3555 assert ((name_type_mask & eFunctionNameTypeAuto) == 0);
3556
Greg Clayton5160ce52013-03-27 23:08:40 +00003557 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003558
3559 if (log)
3560 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003561 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003562 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
3563 name.GetCString(),
3564 name_type_mask,
3565 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003566 }
3567
Greg Clayton0c5cd902010-06-28 21:30:43 +00003568 // If we aren't appending the results to this list, then clear the list
3569 if (!append)
3570 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003571
3572 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00003573 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003574
3575 // If name is empty then we won't find anything.
3576 if (name.IsEmpty())
3577 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00003578
3579 // Remember how many sc_list are in the list before we search in case
3580 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00003581
Jim Ingham4cda6e02011-10-07 22:23:45 +00003582 const char *name_cstr = name.GetCString();
Greg Clayton43fe2172013-04-03 02:00:15 +00003583
3584 const uint32_t original_size = sc_list.GetSize();
3585
Jim Ingham4cda6e02011-10-07 22:23:45 +00003586 DWARFDebugInfo* info = DebugInfo();
3587 if (info == NULL)
3588 return 0;
3589
Greg Claytonaa044962011-10-13 00:59:38 +00003590 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton43fe2172013-04-03 02:00:15 +00003591 std::set<const DWARFDebugInfoEntry *> resolved_dies;
Greg Clayton97fbc342011-10-20 22:30:33 +00003592 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00003593 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003594 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003595 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003596
3597 DIEArray die_offsets;
3598
3599 uint32_t num_matches = 0;
3600
Greg Clayton43fe2172013-04-03 02:00:15 +00003601 if (name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00003602 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003603 // If they asked for the full name, match what they typed. At some point we may
3604 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
3605 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00003606 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003607 for (uint32_t i = 0; i < num_matches; i++)
3608 {
Greg Clayton95d87902011-11-11 03:16:25 +00003609 const dw_offset_t die_offset = die_offsets[i];
3610 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00003611 if (die)
3612 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003613 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3614 continue;
3615
Sean Callanan9df05fb2012-02-10 22:52:19 +00003616 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3617 continue;
3618
Greg Clayton43fe2172013-04-03 02:00:15 +00003619 if (resolved_dies.find(die) == resolved_dies.end())
3620 {
3621 if (ResolveFunction (dwarf_cu, die, sc_list))
3622 resolved_dies.insert(die);
3623 }
Greg Claytonaa044962011-10-13 00:59:38 +00003624 }
Greg Clayton95d87902011-11-11 03:16:25 +00003625 else
3626 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003627 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3628 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003629 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003630 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003631 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003632
3633 if (name_type_mask & eFunctionNameTypeSelector)
3634 {
3635 if (namespace_decl && *namespace_decl)
3636 return 0; // no selectors in namespaces
Greg Clayton97fbc342011-10-20 22:30:33 +00003637
Greg Clayton43fe2172013-04-03 02:00:15 +00003638 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3639 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
3640 // and if it is an ObjC method name, we're good.
Greg Clayton97fbc342011-10-20 22:30:33 +00003641
Greg Clayton43fe2172013-04-03 02:00:15 +00003642 for (uint32_t i = 0; i < num_matches; i++)
Greg Clayton97fbc342011-10-20 22:30:33 +00003643 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003644 const dw_offset_t die_offset = die_offsets[i];
3645 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3646 if (die)
Greg Clayton97fbc342011-10-20 22:30:33 +00003647 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003648 const char *die_name = die->GetName(this, dwarf_cu);
3649 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
Greg Clayton97fbc342011-10-20 22:30:33 +00003650 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003651 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3652 continue;
3653
Greg Clayton43fe2172013-04-03 02:00:15 +00003654 if (resolved_dies.find(die) == resolved_dies.end())
3655 {
3656 if (ResolveFunction (dwarf_cu, die, sc_list))
3657 resolved_dies.insert(die);
3658 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003659 }
3660 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003661 else
3662 {
3663 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3664 die_offset, name_cstr);
3665 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003666 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003667 die_offsets.clear();
3668 }
3669
3670 if (((name_type_mask & eFunctionNameTypeMethod) && !namespace_decl) || name_type_mask & eFunctionNameTypeBase)
3671 {
3672 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
3673 // extract the base name, look that up, and if there is any other information in the name we were
3674 // passed in we have to post-filter based on that.
3675
3676 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
3677 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3678
3679 for (uint32_t i = 0; i < num_matches; i++)
3680 {
3681 const dw_offset_t die_offset = die_offsets[i];
3682 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3683 if (die)
3684 {
3685 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3686 continue;
3687
3688 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3689 continue;
3690
3691 // If we get to here, the die is good, and we should add it:
3692 if (resolved_dies.find(die) == resolved_dies.end())
3693 if (ResolveFunction (dwarf_cu, die, sc_list))
3694 {
3695 bool keep_die = true;
3696 if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod))
3697 {
3698 // We are looking for either basenames or methods, so we need to
3699 // trim out the ones we won't want by looking at the type
3700 SymbolContext sc;
3701 if (sc_list.GetLastContext(sc))
3702 {
3703 if (sc.block)
3704 {
3705 // We have an inlined function
3706 }
3707 else if (sc.function)
3708 {
3709 Type *type = sc.function->GetType();
3710
Sean Callananc370a8a2013-09-18 22:59:55 +00003711 if (type)
Greg Clayton43fe2172013-04-03 02:00:15 +00003712 {
Sean Callananc370a8a2013-09-18 22:59:55 +00003713 clang::DeclContext* decl_ctx = GetClangDeclContextContainingTypeUID (type->GetID());
3714 if (decl_ctx->isRecord())
Greg Clayton43fe2172013-04-03 02:00:15 +00003715 {
Sean Callananc370a8a2013-09-18 22:59:55 +00003716 if (name_type_mask & eFunctionNameTypeBase)
3717 {
3718 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3719 keep_die = false;
3720 }
3721 }
3722 else
3723 {
3724 if (name_type_mask & eFunctionNameTypeMethod)
3725 {
3726 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3727 keep_die = false;
3728 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003729 }
3730 }
3731 else
3732 {
Sean Callananc370a8a2013-09-18 22:59:55 +00003733 GetObjectFile()->GetModule()->ReportWarning ("function at die offset 0x%8.8x had no function type",
3734 die_offset);
Greg Clayton43fe2172013-04-03 02:00:15 +00003735 }
3736 }
3737 }
3738 }
3739 if (keep_die)
3740 resolved_dies.insert(die);
3741 }
3742 }
3743 else
3744 {
3745 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3746 die_offset, name_cstr);
3747 }
3748 }
3749 die_offsets.clear();
Jim Ingham4cda6e02011-10-07 22:23:45 +00003750 }
3751 }
Greg Clayton7f995132011-10-04 22:41:51 +00003752 }
3753 else
3754 {
3755
3756 // Index the DWARF if we haven't already
3757 if (!m_indexed)
3758 Index ();
3759
Greg Clayton7f995132011-10-04 22:41:51 +00003760 if (name_type_mask & eFunctionNameTypeFull)
Matt Kopecd6089962013-05-10 17:53:48 +00003761 {
Greg Clayton7f995132011-10-04 22:41:51 +00003762 FindFunctions (name, m_function_fullname_index, sc_list);
3763
Ed Mastefc7baa02013-09-09 18:00:45 +00003764 // FIXME Temporary workaround for global/anonymous namespace
3765 // functions on FreeBSD and Linux
3766#if defined (__FreeBSD__) || defined (__linux__)
Matt Kopecd6089962013-05-10 17:53:48 +00003767 // If we didn't find any functions in the global namespace try
3768 // looking in the basename index but ignore any returned
3769 // functions that have a namespace (ie. mangled names starting with
3770 // '_ZN') but keep functions which have an anonymous namespace
3771 if (sc_list.GetSize() == 0)
3772 {
3773 SymbolContextList temp_sc_list;
3774 FindFunctions (name, m_function_basename_index, temp_sc_list);
3775 if (!namespace_decl)
3776 {
3777 SymbolContext sc;
3778 for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++)
3779 {
3780 if (temp_sc_list.GetContextAtIndex(i, sc))
3781 {
Matt Kopeca189d492013-05-10 22:55:24 +00003782 ConstString mangled_name = sc.GetFunctionName(Mangled::ePreferMangled);
3783 ConstString demangled_name = sc.GetFunctionName(Mangled::ePreferDemangled);
Matt Kopec04e5d582013-05-14 19:00:41 +00003784 if (strncmp(mangled_name.GetCString(), "_ZN", 3) ||
3785 !strncmp(demangled_name.GetCString(), "(anonymous namespace)", 21))
Matt Kopecd6089962013-05-10 17:53:48 +00003786 {
3787 sc_list.Append(sc);
3788 }
3789 }
3790 }
3791 }
3792 }
3793#endif
3794 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003795 DIEArray die_offsets;
3796 DWARFCompileUnit *dwarf_cu = NULL;
3797
Greg Clayton43fe2172013-04-03 02:00:15 +00003798 if (name_type_mask & eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003799 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003800 uint32_t num_base = m_function_basename_index.Find(name, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00003801 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003802 {
Greg Claytonaa044962011-10-13 00:59:38 +00003803 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3804 if (die)
3805 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003806 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3807 continue;
3808
Sean Callanan213fdb82011-10-13 01:49:10 +00003809 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3810 continue;
3811
Greg Claytonaa044962011-10-13 00:59:38 +00003812 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00003813 if (resolved_dies.find(die) == resolved_dies.end())
3814 {
3815 if (ResolveFunction (dwarf_cu, die, sc_list))
3816 resolved_dies.insert(die);
3817 }
Greg Claytonaa044962011-10-13 00:59:38 +00003818 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003819 }
3820 die_offsets.clear();
3821 }
3822
Greg Clayton43fe2172013-04-03 02:00:15 +00003823 if (name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003824 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003825 if (namespace_decl && *namespace_decl)
3826 return 0; // no methods in namespaces
3827
Greg Clayton43fe2172013-04-03 02:00:15 +00003828 uint32_t num_base = m_function_method_index.Find(name, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003829 {
Greg Claytonaa044962011-10-13 00:59:38 +00003830 for (uint32_t i = 0; i < num_base; i++)
3831 {
3832 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3833 if (die)
3834 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003835 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3836 continue;
3837
Greg Claytonaa044962011-10-13 00:59:38 +00003838 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00003839 if (resolved_dies.find(die) == resolved_dies.end())
3840 {
3841 if (ResolveFunction (dwarf_cu, die, sc_list))
3842 resolved_dies.insert(die);
3843 }
Greg Claytonaa044962011-10-13 00:59:38 +00003844 }
3845 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003846 }
3847 die_offsets.clear();
3848 }
Greg Clayton7f995132011-10-04 22:41:51 +00003849
Greg Clayton43fe2172013-04-03 02:00:15 +00003850 if ((name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003851 {
Greg Clayton7f995132011-10-04 22:41:51 +00003852 FindFunctions (name, m_function_selector_index, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003853 }
3854
Greg Clayton4d01ace2011-09-29 16:58:15 +00003855 }
3856
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003857 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003858 const uint32_t num_matches = sc_list.GetSize() - original_size;
3859
3860 if (log && num_matches > 0)
3861 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003862 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003863 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list) => %u",
3864 name.GetCString(),
3865 name_type_mask,
3866 append,
3867 num_matches);
3868 }
3869 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003870}
3871
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003872uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00003873SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003874{
3875 Timer scoped_timer (__PRETTY_FUNCTION__,
3876 "SymbolFileDWARF::FindFunctions (regex = '%s')",
3877 regex.GetText());
3878
Greg Clayton5160ce52013-03-27 23:08:40 +00003879 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003880
3881 if (log)
3882 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003883 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003884 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
3885 regex.GetText(),
3886 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003887 }
3888
3889
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003890 // If we aren't appending the results to this list, then clear the list
3891 if (!append)
3892 sc_list.Clear();
3893
3894 // Remember how many sc_list are in the list before we search in case
3895 // we are appending the results to a variable list.
3896 uint32_t original_size = sc_list.GetSize();
3897
Greg Clayton97fbc342011-10-20 22:30:33 +00003898 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003899 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003900 if (m_apple_names_ap.get())
3901 FindFunctions (regex, *m_apple_names_ap, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003902 }
3903 else
3904 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003905 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00003906 if (!m_indexed)
3907 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003908
Greg Clayton7f995132011-10-04 22:41:51 +00003909 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003910
Greg Clayton7f995132011-10-04 22:41:51 +00003911 FindFunctions (regex, m_function_fullname_index, sc_list);
3912 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003913
3914 // Return the number of variable that were appended to the list
3915 return sc_list.GetSize() - original_size;
3916}
Jim Ingham318c9f22011-08-26 19:44:13 +00003917
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003918uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00003919SymbolFileDWARF::FindTypes (const SymbolContext& sc,
3920 const ConstString &name,
3921 const lldb_private::ClangNamespaceDecl *namespace_decl,
3922 bool append,
3923 uint32_t max_matches,
3924 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003925{
Greg Claytonc685f8e2010-09-15 04:15:46 +00003926 DWARFDebugInfo* info = DebugInfo();
3927 if (info == NULL)
3928 return 0;
3929
Greg Clayton5160ce52013-03-27 23:08:40 +00003930 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003931
3932 if (log)
3933 {
Greg Clayton437a1352012-04-09 22:43:43 +00003934 if (namespace_decl)
3935 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003936 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003937 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)",
3938 name.GetCString(),
3939 namespace_decl->GetNamespaceDecl(),
3940 namespace_decl->GetQualifiedName().c_str(),
3941 append,
3942 max_matches);
3943 }
3944 else
3945 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003946 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003947 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)",
3948 name.GetCString(),
3949 append,
3950 max_matches);
3951 }
Greg Clayton21f2a492011-10-06 00:09:08 +00003952 }
3953
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003954 // If we aren't appending the results to this list, then clear the list
3955 if (!append)
3956 types.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003957
3958 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00003959 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003960
Greg Claytond4a2b372011-09-12 23:21:58 +00003961 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003962
Greg Clayton97fbc342011-10-20 22:30:33 +00003963 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003964 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003965 if (m_apple_types_ap.get())
3966 {
3967 const char *name_cstr = name.GetCString();
3968 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3969 }
Greg Clayton7f995132011-10-04 22:41:51 +00003970 }
3971 else
3972 {
3973 if (!m_indexed)
3974 Index ();
3975
3976 m_type_index.Find (name, die_offsets);
3977 }
3978
Greg Clayton437a1352012-04-09 22:43:43 +00003979 const size_t num_die_matches = die_offsets.size();
Greg Clayton7f995132011-10-04 22:41:51 +00003980
Greg Clayton437a1352012-04-09 22:43:43 +00003981 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003982 {
Greg Clayton7f995132011-10-04 22:41:51 +00003983 const uint32_t initial_types_size = types.GetSize();
3984 DWARFCompileUnit* dwarf_cu = NULL;
3985 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003986 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00003987 for (size_t i=0; i<num_die_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003988 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003989 const dw_offset_t die_offset = die_offsets[i];
3990 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3991
Greg Clayton95d87902011-11-11 03:16:25 +00003992 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00003993 {
Greg Clayton95d87902011-11-11 03:16:25 +00003994 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3995 continue;
3996
3997 Type *matching_type = ResolveType (dwarf_cu, die);
3998 if (matching_type)
3999 {
4000 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00004001 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00004002 if (types.GetSize() >= max_matches)
4003 break;
4004 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00004005 }
Greg Clayton95d87902011-11-11 03:16:25 +00004006 else
4007 {
4008 if (m_using_apple_tables)
4009 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004010 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4011 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004012 }
4013 }
4014
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004015 }
Greg Clayton437a1352012-04-09 22:43:43 +00004016 const uint32_t num_matches = types.GetSize() - initial_types_size;
4017 if (log && num_matches)
4018 {
4019 if (namespace_decl)
4020 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004021 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004022 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u",
4023 name.GetCString(),
4024 namespace_decl->GetNamespaceDecl(),
4025 namespace_decl->GetQualifiedName().c_str(),
4026 append,
4027 max_matches,
4028 num_matches);
4029 }
4030 else
4031 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004032 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004033 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u",
4034 name.GetCString(),
4035 append,
4036 max_matches,
4037 num_matches);
4038 }
4039 }
4040 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004041 }
Greg Clayton7f995132011-10-04 22:41:51 +00004042 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004043}
4044
4045
Greg Clayton526e5af2010-11-13 03:52:47 +00004046ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00004047SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00004048 const ConstString &name,
4049 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004050{
Greg Clayton5160ce52013-03-27 23:08:40 +00004051 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00004052
4053 if (log)
4054 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004055 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00004056 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
4057 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00004058 }
Sean Callanan213fdb82011-10-13 01:49:10 +00004059
4060 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00004061 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00004062
Greg Clayton526e5af2010-11-13 03:52:47 +00004063 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004064 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00004065 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00004066 {
Greg Clayton7f995132011-10-04 22:41:51 +00004067 DIEArray die_offsets;
4068
Greg Clayton526e5af2010-11-13 03:52:47 +00004069 // Index if we already haven't to make sure the compile units
4070 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00004071 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004072 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004073 if (m_apple_namespaces_ap.get())
4074 {
4075 const char *name_cstr = name.GetCString();
4076 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
4077 }
Greg Clayton7f995132011-10-04 22:41:51 +00004078 }
4079 else
4080 {
4081 if (!m_indexed)
4082 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00004083
Greg Clayton7f995132011-10-04 22:41:51 +00004084 m_namespace_index.Find (name, die_offsets);
4085 }
Greg Claytond4a2b372011-09-12 23:21:58 +00004086
4087 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00004088 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00004089 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00004090 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00004091 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004092 DWARFDebugInfo* debug_info = DebugInfo();
4093 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00004094 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004095 const dw_offset_t die_offset = die_offsets[i];
4096 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00004097
Greg Clayton95d87902011-11-11 03:16:25 +00004098 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00004099 {
Greg Clayton95d87902011-11-11 03:16:25 +00004100 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
4101 continue;
4102
4103 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
4104 if (clang_namespace_decl)
4105 {
4106 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
4107 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
Greg Claytond1767f02011-12-08 02:13:16 +00004108 break;
Greg Clayton95d87902011-11-11 03:16:25 +00004109 }
Greg Claytond4a2b372011-09-12 23:21:58 +00004110 }
Greg Clayton95d87902011-11-11 03:16:25 +00004111 else
4112 {
4113 if (m_using_apple_tables)
4114 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004115 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
4116 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004117 }
4118 }
4119
Greg Clayton526e5af2010-11-13 03:52:47 +00004120 }
4121 }
Greg Clayton96d7d742010-11-10 23:42:09 +00004122 }
Greg Clayton437a1352012-04-09 22:43:43 +00004123 if (log && namespace_decl.GetNamespaceDecl())
4124 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004125 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004126 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"",
4127 name.GetCString(),
4128 namespace_decl.GetNamespaceDecl(),
4129 namespace_decl.GetQualifiedName().c_str());
4130 }
4131
Greg Clayton526e5af2010-11-13 03:52:47 +00004132 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004133}
4134
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004135uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004136SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004137{
4138 // Remember how many sc_list are in the list before we search in case
4139 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004140 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004141
4142 const uint32_t num_die_offsets = die_offsets.size();
4143 // Parse all of the types we found from the pubtypes matches
4144 uint32_t i;
4145 uint32_t num_matches = 0;
4146 for (i = 0; i < num_die_offsets; ++i)
4147 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004148 Type *matching_type = ResolveTypeUID (die_offsets[i]);
4149 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004150 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004151 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00004152 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004153 ++num_matches;
4154 if (num_matches >= max_matches)
4155 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004156 }
4157 }
4158
4159 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004160 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004161}
4162
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004163
4164size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00004165SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
4166 clang::DeclContext *containing_decl_ctx,
Greg Clayton5113dc82011-08-12 06:47:54 +00004167 DWARFCompileUnit* dwarf_cu,
4168 const DWARFDebugInfoEntry *parent_die,
4169 bool skip_artificial,
4170 bool &is_static,
4171 TypeList* type_list,
Greg Clayton57ee3062013-07-11 22:46:58 +00004172 std::vector<ClangASTType>& function_param_types,
Greg Clayton5113dc82011-08-12 06:47:54 +00004173 std::vector<clang::ParmVarDecl*>& function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004174 unsigned &type_quals,
4175 ClangASTContext::TemplateParameterInfos &template_param_infos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004176{
4177 if (parent_die == NULL)
4178 return 0;
4179
Greg Claytond88d7592010-09-15 08:33:30 +00004180 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
4181
Greg Clayton7fedea22010-11-16 02:10:54 +00004182 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004183 const DWARFDebugInfoEntry *die;
4184 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4185 {
4186 dw_tag_t tag = die->Tag();
4187 switch (tag)
4188 {
4189 case DW_TAG_formal_parameter:
4190 {
4191 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004192 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004193 if (num_attributes > 0)
4194 {
4195 const char *name = NULL;
4196 Declaration decl;
4197 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00004198 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004199 // one of None, Auto, Register, Extern, Static, PrivateExtern
4200
Sean Callanane2ef6e32010-09-23 03:01:22 +00004201 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004202 uint32_t i;
4203 for (i=0; i<num_attributes; ++i)
4204 {
4205 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4206 DWARFFormValue form_value;
4207 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4208 {
4209 switch (attr)
4210 {
4211 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4212 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4213 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4214 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
4215 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00004216 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004217 case DW_AT_location:
4218 // if (form_value.BlockData())
4219 // {
Ed Masteeeae7212013-10-24 20:43:47 +00004220 // const DWARFDataExtractor& debug_info_data = debug_info();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004221 // uint32_t block_length = form_value.Unsigned();
Ed Masteeeae7212013-10-24 20:43:47 +00004222 // DWARFDataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004223 // }
4224 // else
4225 // {
4226 // }
4227 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004228 case DW_AT_const_value:
4229 case DW_AT_default_value:
4230 case DW_AT_description:
4231 case DW_AT_endianity:
4232 case DW_AT_is_optional:
4233 case DW_AT_segment:
4234 case DW_AT_variable_parameter:
4235 default:
4236 case DW_AT_abstract_origin:
4237 case DW_AT_sibling:
4238 break;
4239 }
4240 }
4241 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00004242
Greg Clayton0fffff52010-09-24 05:15:53 +00004243 bool skip = false;
4244 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004245 {
Greg Clayton0fffff52010-09-24 05:15:53 +00004246 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00004247 {
4248 // In order to determine if a C++ member function is
4249 // "const" we have to look at the const-ness of "this"...
4250 // Ugly, but that
4251 if (arg_idx == 0)
4252 {
Greg Claytonf0705c82011-10-22 03:33:13 +00004253 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00004254 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004255 // Often times compilers omit the "this" name for the
4256 // specification DIEs, so we can't rely upon the name
4257 // being in the formal parameter DIE...
4258 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00004259 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004260 Type *this_type = ResolveTypeUID (param_type_die_offset);
4261 if (this_type)
4262 {
4263 uint32_t encoding_mask = this_type->GetEncodingMask();
4264 if (encoding_mask & Type::eEncodingIsPointerUID)
4265 {
4266 is_static = false;
4267
4268 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
4269 type_quals |= clang::Qualifiers::Const;
4270 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
4271 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00004272 }
4273 }
4274 }
4275 }
4276 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004277 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00004278 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004279 else
4280 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004281
Greg Clayton0fffff52010-09-24 05:15:53 +00004282 // HACK: Objective C formal parameters "self" and "_cmd"
4283 // are not marked as artificial in the DWARF...
Greg Clayton53eb1c22012-04-02 22:59:12 +00004284 CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
4285 if (comp_unit)
Greg Clayton0fffff52010-09-24 05:15:53 +00004286 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004287 switch (comp_unit->GetLanguage())
4288 {
4289 case eLanguageTypeObjC:
4290 case eLanguageTypeObjC_plus_plus:
4291 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
4292 skip = true;
4293 break;
4294 default:
4295 break;
4296 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004297 }
4298 }
4299 }
4300
4301 if (!skip)
4302 {
4303 Type *type = ResolveTypeUID(param_type_die_offset);
4304 if (type)
4305 {
Greg Claytonc93237c2010-10-01 20:48:32 +00004306 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00004307
Greg Clayton42ce2f32011-12-12 21:50:19 +00004308 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
4309 type->GetClangForwardType(),
4310 storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00004311 assert(param_var_decl);
4312 function_param_decls.push_back(param_var_decl);
Sean Callanan60217122012-04-13 00:10:03 +00004313
Greg Claytond0029442013-03-27 01:48:02 +00004314 GetClangASTContext().SetMetadataAsUserID (param_var_decl, MakeUserID(die->GetOffset()));
Greg Clayton0fffff52010-09-24 05:15:53 +00004315 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004316 }
4317 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004318 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004319 }
4320 break;
4321
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004322 case DW_TAG_template_type_parameter:
4323 case DW_TAG_template_value_parameter:
4324 ParseTemplateDIE (dwarf_cu, die,template_param_infos);
4325 break;
4326
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004327 default:
4328 break;
4329 }
4330 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004331 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004332}
4333
4334size_t
4335SymbolFileDWARF::ParseChildEnumerators
4336(
4337 const SymbolContext& sc,
Greg Clayton57ee3062013-07-11 22:46:58 +00004338 lldb_private::ClangASTType &clang_type,
Greg Clayton3e067532013-03-05 23:54:39 +00004339 bool is_signed,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004340 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00004341 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004342 const DWARFDebugInfoEntry *parent_die
4343)
4344{
4345 if (parent_die == NULL)
4346 return 0;
4347
4348 size_t enumerators_added = 0;
4349 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00004350 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
4351
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004352 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4353 {
4354 const dw_tag_t tag = die->Tag();
4355 if (tag == DW_TAG_enumerator)
4356 {
4357 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004358 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004359 if (num_child_attributes > 0)
4360 {
4361 const char *name = NULL;
4362 bool got_value = false;
4363 int64_t enum_value = 0;
4364 Declaration decl;
4365
4366 uint32_t i;
4367 for (i=0; i<num_child_attributes; ++i)
4368 {
4369 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4370 DWARFFormValue form_value;
4371 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4372 {
4373 switch (attr)
4374 {
4375 case DW_AT_const_value:
4376 got_value = true;
Greg Clayton3e067532013-03-05 23:54:39 +00004377 if (is_signed)
4378 enum_value = form_value.Signed();
4379 else
4380 enum_value = form_value.Unsigned();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004381 break;
4382
4383 case DW_AT_name:
4384 name = form_value.AsCString(&get_debug_str_data());
4385 break;
4386
4387 case DW_AT_description:
4388 default:
4389 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4390 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4391 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4392 case DW_AT_sibling:
4393 break;
4394 }
4395 }
4396 }
4397
4398 if (name && name[0] && got_value)
4399 {
Greg Clayton57ee3062013-07-11 22:46:58 +00004400 clang_type.AddEnumerationValueToEnumerationType (clang_type.GetEnumerationIntegerType(),
4401 decl,
4402 name,
4403 enum_value,
4404 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004405 ++enumerators_added;
4406 }
4407 }
4408 }
4409 }
4410 return enumerators_added;
4411}
4412
4413void
4414SymbolFileDWARF::ParseChildArrayInfo
4415(
4416 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004417 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004418 const DWARFDebugInfoEntry *parent_die,
4419 int64_t& first_index,
4420 std::vector<uint64_t>& element_orders,
4421 uint32_t& byte_stride,
4422 uint32_t& bit_stride
4423)
4424{
4425 if (parent_die == NULL)
4426 return;
4427
4428 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00004429 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004430 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4431 {
4432 const dw_tag_t tag = die->Tag();
4433 switch (tag)
4434 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004435 case DW_TAG_subrange_type:
4436 {
4437 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004438 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004439 if (num_child_attributes > 0)
4440 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004441 uint64_t num_elements = 0;
4442 uint64_t lower_bound = 0;
4443 uint64_t upper_bound = 0;
Greg Clayton4ef877f2012-12-06 02:33:54 +00004444 bool upper_bound_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004445 uint32_t i;
4446 for (i=0; i<num_child_attributes; ++i)
4447 {
4448 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4449 DWARFFormValue form_value;
4450 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4451 {
4452 switch (attr)
4453 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004454 case DW_AT_name:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004455 break;
4456
4457 case DW_AT_count:
4458 num_elements = form_value.Unsigned();
4459 break;
4460
4461 case DW_AT_bit_stride:
4462 bit_stride = form_value.Unsigned();
4463 break;
4464
4465 case DW_AT_byte_stride:
4466 byte_stride = form_value.Unsigned();
4467 break;
4468
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004469 case DW_AT_lower_bound:
4470 lower_bound = form_value.Unsigned();
4471 break;
4472
4473 case DW_AT_upper_bound:
Greg Clayton4ef877f2012-12-06 02:33:54 +00004474 upper_bound_valid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004475 upper_bound = form_value.Unsigned();
4476 break;
4477
4478 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004479 case DW_AT_abstract_origin:
4480 case DW_AT_accessibility:
4481 case DW_AT_allocated:
4482 case DW_AT_associated:
4483 case DW_AT_data_location:
4484 case DW_AT_declaration:
4485 case DW_AT_description:
4486 case DW_AT_sibling:
4487 case DW_AT_threads_scaled:
4488 case DW_AT_type:
4489 case DW_AT_visibility:
4490 break;
4491 }
4492 }
4493 }
4494
Greg Claytone6a07792012-12-05 21:59:39 +00004495 if (num_elements == 0)
4496 {
Greg Clayton4ef877f2012-12-06 02:33:54 +00004497 if (upper_bound_valid && upper_bound >= lower_bound)
Greg Claytone6a07792012-12-05 21:59:39 +00004498 num_elements = upper_bound - lower_bound + 1;
4499 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004500
Sean Callananec979ba2012-10-22 23:56:48 +00004501 element_orders.push_back (num_elements);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004502 }
4503 }
4504 break;
4505 }
4506 }
4507}
4508
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004509TypeSP
Greg Clayton53eb1c22012-04-02 22:59:12 +00004510SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004511{
4512 TypeSP type_sp;
4513 if (die != NULL)
4514 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004515 assert(dwarf_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00004516 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004517 if (type_ptr == NULL)
4518 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004519 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu);
Greg Claytonca512b32011-01-14 04:54:56 +00004520 assert (lldb_cu);
4521 SymbolContext sc(lldb_cu);
Greg Clayton53eb1c22012-04-02 22:59:12 +00004522 type_sp = ParseType(sc, dwarf_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004523 }
4524 else if (type_ptr != DIE_IS_BEING_PARSED)
4525 {
4526 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00004527 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004528 }
4529
4530 }
4531 return type_sp;
4532}
4533
4534clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00004535SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004536{
4537 if (die_offset != DW_INVALID_OFFSET)
4538 {
4539 DWARFCompileUnitSP cu_sp;
4540 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004541 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004542 }
4543 return NULL;
4544}
4545
Sean Callanan72e49402011-08-05 23:43:37 +00004546clang::DeclContext *
4547SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
4548{
4549 if (die_offset != DW_INVALID_OFFSET)
4550 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004551 DWARFDebugInfo* debug_info = DebugInfo();
4552 if (debug_info)
4553 {
4554 DWARFCompileUnitSP cu_sp;
4555 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
4556 if (die)
4557 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
4558 }
Sean Callanan72e49402011-08-05 23:43:37 +00004559 }
4560 return NULL;
4561}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004562
Greg Clayton96d7d742010-11-10 23:42:09 +00004563clang::NamespaceDecl *
Greg Clayton53eb1c22012-04-02 22:59:12 +00004564SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die)
Greg Clayton96d7d742010-11-10 23:42:09 +00004565{
Greg Clayton030a2042011-10-14 21:34:45 +00004566 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00004567 {
Greg Clayton030a2042011-10-14 21:34:45 +00004568 // See if we already parsed this namespace DIE and associated it with a
4569 // uniqued namespace declaration
4570 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
4571 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004572 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00004573 else
4574 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004575 const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL);
4576 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00004577 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
Greg Clayton5160ce52013-03-27 23:08:40 +00004578 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton9d3d6882011-10-31 23:51:19 +00004579 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00004580 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00004581 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00004582 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004583 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00004584 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)",
Greg Claytone38a5ed2012-01-05 03:57:59 +00004585 GetClangASTContext().getASTContext(),
4586 MakeUserID(die->GetOffset()),
4587 namespace_name,
4588 namespace_decl,
4589 namespace_decl->getOriginalNamespace());
Greg Clayton030a2042011-10-14 21:34:45 +00004590 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004591 else
4592 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004593 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00004594 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
Greg Claytone38a5ed2012-01-05 03:57:59 +00004595 GetClangASTContext().getASTContext(),
4596 MakeUserID(die->GetOffset()),
4597 namespace_decl,
4598 namespace_decl->getOriginalNamespace());
Greg Clayton9d3d6882011-10-31 23:51:19 +00004599 }
Greg Clayton030a2042011-10-14 21:34:45 +00004600 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004601
4602 if (namespace_decl)
4603 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
4604 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004605 }
4606 }
4607 return NULL;
4608}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004609
4610clang::DeclContext *
Greg Claytoncab36a32011-12-08 05:16:30 +00004611SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Sean Callanan72e49402011-08-05 23:43:37 +00004612{
Greg Clayton5cf58b92011-10-05 22:22:08 +00004613 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4614 if (clang_decl_ctx)
4615 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004616 // If this DIE has a specification, or an abstract origin, then trace to those.
4617
Greg Claytoncab36a32011-12-08 05:16:30 +00004618 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004619 if (die_offset != DW_INVALID_OFFSET)
4620 return GetClangDeclContextForDIEOffset (sc, die_offset);
4621
Greg Claytoncab36a32011-12-08 05:16:30 +00004622 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004623 if (die_offset != DW_INVALID_OFFSET)
4624 return GetClangDeclContextForDIEOffset (sc, die_offset);
4625
Greg Clayton5160ce52013-03-27 23:08:40 +00004626 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00004627 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004628 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 +00004629 // This is the DIE we want. Parse it, then query our map.
Greg Claytoncab36a32011-12-08 05:16:30 +00004630 bool assert_not_being_parsed = true;
4631 ResolveTypeUID (cu, die, assert_not_being_parsed);
4632
Greg Clayton5cf58b92011-10-05 22:22:08 +00004633 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4634
4635 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004636}
4637
4638clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00004639SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004640{
Greg Claytonca512b32011-01-14 04:54:56 +00004641 if (m_clang_tu_decl == NULL)
4642 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004643
Greg Clayton2bc22f82011-09-30 03:20:47 +00004644 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004645
4646 if (decl_ctx_die_copy)
4647 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00004648
4649 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004650 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00004651
Greg Clayton2bc22f82011-09-30 03:20:47 +00004652 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
4653 if (pos != m_die_to_decl_ctx.end())
4654 return pos->second;
4655
4656 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004657 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004658 case DW_TAG_compile_unit:
4659 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004660
Greg Clayton2bc22f82011-09-30 03:20:47 +00004661 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00004662 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00004663 break;
4664
4665 case DW_TAG_structure_type:
4666 case DW_TAG_union_type:
4667 case DW_TAG_class_type:
4668 {
4669 Type* type = ResolveType (cu, decl_ctx_die);
4670 if (type)
4671 {
Greg Clayton57ee3062013-07-11 22:46:58 +00004672 clang::DeclContext *decl_ctx = type->GetClangForwardType().GetDeclContextForType ();
Greg Clayton2bc22f82011-09-30 03:20:47 +00004673 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00004674 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004675 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
4676 if (decl_ctx)
4677 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00004678 }
4679 }
Greg Claytonca512b32011-01-14 04:54:56 +00004680 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00004681 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004682
Greg Clayton2bc22f82011-09-30 03:20:47 +00004683 default:
4684 break;
Greg Claytonca512b32011-01-14 04:54:56 +00004685 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004686 }
Greg Clayton7a345282010-11-09 23:46:37 +00004687 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004688}
4689
Greg Clayton2bc22f82011-09-30 03:20:47 +00004690
4691const DWARFDebugInfoEntry *
4692SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4693{
4694 if (cu && die)
4695 {
4696 const DWARFDebugInfoEntry * const decl_die = die;
4697
4698 while (die != NULL)
4699 {
4700 // If this is the original DIE that we are searching for a declaration
4701 // for, then don't look in the cache as we don't want our own decl
4702 // context to be our decl context...
4703 if (decl_die != die)
4704 {
4705 switch (die->Tag())
4706 {
4707 case DW_TAG_compile_unit:
4708 case DW_TAG_namespace:
4709 case DW_TAG_structure_type:
4710 case DW_TAG_union_type:
4711 case DW_TAG_class_type:
4712 return die;
4713
4714 default:
4715 break;
4716 }
4717 }
4718
4719 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4720 if (die_offset != DW_INVALID_OFFSET)
4721 {
4722 DWARFCompileUnit *spec_cu = cu;
4723 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
4724 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
4725 if (spec_die_decl_ctx_die)
4726 return spec_die_decl_ctx_die;
4727 }
4728
4729 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
4730 if (die_offset != DW_INVALID_OFFSET)
4731 {
4732 DWARFCompileUnit *abs_cu = cu;
4733 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
4734 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
4735 if (abs_die_decl_ctx_die)
4736 return abs_die_decl_ctx_die;
4737 }
4738
4739 die = die->GetParent();
4740 }
4741 }
4742 return NULL;
4743}
4744
4745
Greg Clayton901c5ca2011-12-03 04:40:03 +00004746Symbol *
4747SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
4748{
4749 Symbol *objc_class_symbol = NULL;
4750 if (m_obj_file)
4751 {
Greg Clayton3046e662013-07-10 01:23:25 +00004752 Symtab *symtab = m_obj_file->GetSymtab ();
Greg Clayton901c5ca2011-12-03 04:40:03 +00004753 if (symtab)
4754 {
4755 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
4756 eSymbolTypeObjCClass,
4757 Symtab::eDebugNo,
4758 Symtab::eVisibilityAny);
4759 }
4760 }
4761 return objc_class_symbol;
4762}
4763
Greg Claytonc7f03b62012-01-12 04:33:28 +00004764// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
4765// then we can end up looking through all class types for a complete type and never find
4766// the full definition. We need to know if this attribute is supported, so we determine
4767// this here and cache th result. We also need to worry about the debug map DWARF file
4768// if we are doing darwin DWARF in .o file debugging.
4769bool
4770SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
4771{
4772 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
4773 {
4774 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
4775 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
4776 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4777 else
4778 {
4779 DWARFDebugInfo* debug_info = DebugInfo();
4780 const uint32_t num_compile_units = GetNumCompileUnits();
4781 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
4782 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004783 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
4784 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004785 {
4786 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4787 break;
4788 }
4789 }
4790 }
Greg Clayton1f746072012-08-29 21:13:06 +00004791 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004792 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
4793 }
4794 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
4795}
Greg Clayton901c5ca2011-12-03 04:40:03 +00004796
4797// This function can be used when a DIE is found that is a forward declaration
4798// DIE and we want to try and find a type that has the complete definition.
4799TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00004800SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
4801 const ConstString &type_name,
4802 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00004803{
4804
4805 TypeSP type_sp;
4806
Greg Claytonc7f03b62012-01-12 04:33:28 +00004807 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00004808 return type_sp;
4809
4810 DIEArray die_offsets;
4811
4812 if (m_using_apple_tables)
4813 {
4814 if (m_apple_types_ap.get())
4815 {
4816 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00004817 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004818 }
4819 }
4820 else
4821 {
4822 if (!m_indexed)
4823 Index ();
4824
4825 m_type_index.Find (type_name, die_offsets);
4826 }
4827
Greg Clayton901c5ca2011-12-03 04:40:03 +00004828 const size_t num_matches = die_offsets.size();
4829
Greg Clayton901c5ca2011-12-03 04:40:03 +00004830 DWARFCompileUnit* type_cu = NULL;
4831 const DWARFDebugInfoEntry* type_die = NULL;
4832 if (num_matches)
4833 {
4834 DWARFDebugInfo* debug_info = DebugInfo();
4835 for (size_t i=0; i<num_matches; ++i)
4836 {
4837 const dw_offset_t die_offset = die_offsets[i];
4838 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4839
4840 if (type_die)
4841 {
4842 bool try_resolving_type = false;
4843
4844 // Don't try and resolve the DIE we are looking for with the DIE itself!
4845 if (type_die != die)
4846 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004847 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00004848 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004849 case DW_TAG_class_type:
4850 case DW_TAG_structure_type:
4851 try_resolving_type = true;
4852 break;
4853 default:
4854 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00004855 }
4856 }
4857
4858 if (try_resolving_type)
4859 {
Ed Maste4c24b122013-10-17 20:13:14 +00004860 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
4861 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004862
4863 if (try_resolving_type)
4864 {
4865 Type *resolved_type = ResolveType (type_cu, type_die, false);
4866 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4867 {
Ed Mastea0191d12013-10-17 20:42:56 +00004868 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 +00004869 MakeUserID(die->GetOffset()),
Greg Clayton901c5ca2011-12-03 04:40:03 +00004870 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4871 MakeUserID(type_die->GetOffset()),
4872 MakeUserID(type_cu->GetOffset()));
4873
Greg Claytonc7f03b62012-01-12 04:33:28 +00004874 if (die)
4875 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00004876 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00004877 break;
4878 }
4879 }
4880 }
4881 }
4882 else
4883 {
4884 if (m_using_apple_tables)
4885 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004886 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4887 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00004888 }
4889 }
4890
4891 }
4892 }
4893 return type_sp;
4894}
4895
Greg Claytona8022fa2012-04-24 21:22:41 +00004896
Greg Clayton80c26302012-02-05 06:12:47 +00004897//----------------------------------------------------------------------
4898// This function helps to ensure that the declaration contexts match for
4899// two different DIEs. Often times debug information will refer to a
4900// forward declaration of a type (the equivalent of "struct my_struct;".
4901// There will often be a declaration of that type elsewhere that has the
4902// full definition. When we go looking for the full type "my_struct", we
4903// will find one or more matches in the accelerator tables and we will
4904// then need to make sure the type was in the same declaration context
4905// as the original DIE. This function can efficiently compare two DIEs
4906// and will return true when the declaration context matches, and false
4907// when they don't.
4908//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00004909bool
4910SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
4911 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
4912{
Greg Claytona8022fa2012-04-24 21:22:41 +00004913 if (die1 == die2)
4914 return true;
4915
4916#if defined (LLDB_CONFIGURATION_DEBUG)
4917 // You can't and shouldn't call this function with a compile unit from
4918 // two different SymbolFileDWARF instances.
4919 assert (DebugInfo()->ContainsCompileUnit (cu1));
4920 assert (DebugInfo()->ContainsCompileUnit (cu2));
4921#endif
4922
Greg Clayton890ff562012-02-02 05:48:16 +00004923 DWARFDIECollection decl_ctx_1;
4924 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00004925 //The declaration DIE stack is a stack of the declaration context
4926 // DIEs all the way back to the compile unit. If a type "T" is
4927 // declared inside a class "B", and class "B" is declared inside
4928 // a class "A" and class "A" is in a namespace "lldb", and the
4929 // namespace is in a compile unit, there will be a stack of DIEs:
4930 //
4931 // [0] DW_TAG_class_type for "B"
4932 // [1] DW_TAG_class_type for "A"
4933 // [2] DW_TAG_namespace for "lldb"
4934 // [3] DW_TAG_compile_unit for the source file.
4935 //
4936 // We grab both contexts and make sure that everything matches
4937 // all the way back to the compiler unit.
4938
4939 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00004940 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004941 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00004942 // Make sure the context arrays have the same size, otherwise
4943 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00004944 const size_t count1 = decl_ctx_1.Size();
4945 const size_t count2 = decl_ctx_2.Size();
4946 if (count1 != count2)
4947 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00004948
4949 // Make sure the DW_TAG values match all the way back up the the
4950 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00004951 const DWARFDebugInfoEntry *decl_ctx_die1;
4952 const DWARFDebugInfoEntry *decl_ctx_die2;
4953 size_t i;
4954 for (i=0; i<count1; i++)
4955 {
4956 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4957 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4958 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
4959 return false;
4960 }
Greg Clayton890ff562012-02-02 05:48:16 +00004961#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00004962
4963 // Make sure the top item in the decl context die array is always
4964 // DW_TAG_compile_unit. If it isn't then something went wrong in
4965 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00004966 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00004967
Greg Clayton890ff562012-02-02 05:48:16 +00004968#endif
4969 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00004970 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00004971 for (i=0; i<count1 - 1; i++)
4972 {
4973 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4974 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4975 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004976 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00004977 // If the string was from a DW_FORM_strp, then the pointer will often
4978 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00004979 if (name1 == name2)
4980 continue;
4981
4982 // Name pointers are not equal, so only compare the strings
4983 // if both are not NULL.
4984 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00004985 {
Greg Clayton5569e642012-02-06 01:44:54 +00004986 // If the strings don't compare, we are done...
4987 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00004988 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00004989 }
4990 else
4991 {
4992 // One name was NULL while the other wasn't
4993 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00004994 }
4995 }
Greg Clayton80c26302012-02-05 06:12:47 +00004996 // We made it through all of the checks and the declaration contexts
4997 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00004998 return true;
4999}
Greg Clayton220a0072011-12-09 08:48:30 +00005000
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005001// This function can be used when a DIE is found that is a forward declaration
5002// DIE and we want to try and find a type that has the complete definition.
Greg Claytona8022fa2012-04-24 21:22:41 +00005003// "cu" and "die" must be from this SymbolFileDWARF
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005004TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00005005SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
Greg Clayton7f995132011-10-04 22:41:51 +00005006 const DWARFDebugInfoEntry *die,
5007 const ConstString &type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005008{
5009 TypeSP type_sp;
5010
Greg Claytona8022fa2012-04-24 21:22:41 +00005011#if defined (LLDB_CONFIGURATION_DEBUG)
5012 // You can't and shouldn't call this function with a compile unit from
5013 // another SymbolFileDWARF instance.
5014 assert (DebugInfo()->ContainsCompileUnit (cu));
5015#endif
5016
Greg Clayton1a65ae12011-01-25 23:55:37 +00005017 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005018 return type_sp;
5019
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005020 std::string qualified_name;
5021
Greg Clayton5160ce52013-03-27 23:08:40 +00005022 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005023 if (log)
5024 {
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005025 die->GetQualifiedName(this, cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00005026 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005027 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x (%s), name='%s')",
5028 die->GetOffset(),
5029 qualified_name.c_str(),
5030 type_name.GetCString());
5031 }
5032
Greg Clayton7f995132011-10-04 22:41:51 +00005033 DIEArray die_offsets;
5034
Greg Clayton97fbc342011-10-20 22:30:33 +00005035 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00005036 {
Greg Clayton97fbc342011-10-20 22:30:33 +00005037 if (m_apple_types_ap.get())
5038 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005039 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
5040 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
5041 if (has_tag && has_qualified_name_hash)
Greg Claytond1767f02011-12-08 02:13:16 +00005042 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005043 if (qualified_name.empty())
5044 die->GetQualifiedName(this, cu, qualified_name);
5045
5046 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name.c_str());
5047 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005048 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005049 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), die->Tag(), qualified_name_hash, die_offsets);
5050 }
5051 else if (has_tag > 1)
5052 {
5053 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005054 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
Greg Claytonae920b62012-01-06 00:17:16 +00005055 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets);
Greg Claytond1767f02011-12-08 02:13:16 +00005056 }
5057 else
5058 {
5059 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
5060 }
Greg Clayton97fbc342011-10-20 22:30:33 +00005061 }
Greg Clayton7f995132011-10-04 22:41:51 +00005062 }
5063 else
5064 {
5065 if (!m_indexed)
5066 Index ();
5067
5068 m_type_index.Find (type_name, die_offsets);
5069 }
Greg Clayton7f995132011-10-04 22:41:51 +00005070
5071 const size_t num_matches = die_offsets.size();
Greg Clayton69974892010-12-03 21:42:06 +00005072
Greg Clayton934cb052011-12-03 00:27:05 +00005073 const dw_tag_t die_tag = die->Tag();
Greg Claytond4a2b372011-09-12 23:21:58 +00005074
5075 DWARFCompileUnit* type_cu = NULL;
5076 const DWARFDebugInfoEntry* type_die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00005077 if (num_matches)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005078 {
Greg Claytond4a2b372011-09-12 23:21:58 +00005079 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005080 for (size_t i=0; i<num_matches; ++i)
5081 {
Greg Claytond4a2b372011-09-12 23:21:58 +00005082 const dw_offset_t die_offset = die_offsets[i];
5083 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005084
Greg Clayton95d87902011-11-11 03:16:25 +00005085 if (type_die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005086 {
Greg Clayton934cb052011-12-03 00:27:05 +00005087 bool try_resolving_type = false;
5088
5089 // Don't try and resolve the DIE we are looking for with the DIE itself!
5090 if (type_die != die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005091 {
Greg Clayton934cb052011-12-03 00:27:05 +00005092 const dw_tag_t type_die_tag = type_die->Tag();
5093 // Make sure the tags match
5094 if (type_die_tag == die_tag)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005095 {
Greg Clayton934cb052011-12-03 00:27:05 +00005096 // The tags match, lets try resolving this type
5097 try_resolving_type = true;
5098 }
5099 else
5100 {
5101 // The tags don't match, but we need to watch our for a
5102 // forward declaration for a struct and ("struct foo")
5103 // ends up being a class ("class foo { ... };") or
5104 // vice versa.
5105 switch (type_die_tag)
Greg Clayton95d87902011-11-11 03:16:25 +00005106 {
Greg Clayton934cb052011-12-03 00:27:05 +00005107 case DW_TAG_class_type:
5108 // We had a "class foo", see if we ended up with a "struct foo { ... };"
5109 try_resolving_type = (die_tag == DW_TAG_structure_type);
5110 break;
5111 case DW_TAG_structure_type:
5112 // We had a "struct foo", see if we ended up with a "class foo { ... };"
5113 try_resolving_type = (die_tag == DW_TAG_class_type);
5114 break;
5115 default:
5116 // Tags don't match, don't event try to resolve
5117 // using this type whose name matches....
Greg Clayton95d87902011-11-11 03:16:25 +00005118 break;
5119 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005120 }
5121 }
Greg Clayton934cb052011-12-03 00:27:05 +00005122
5123 if (try_resolving_type)
5124 {
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005125 if (log)
5126 {
5127 std::string qualified_name;
5128 type_die->GetQualifiedName(this, cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00005129 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005130 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') trying die=0x%8.8x (%s)",
5131 die->GetOffset(),
5132 type_name.GetCString(),
5133 type_die->GetOffset(),
5134 qualified_name.c_str());
5135 }
5136
Greg Clayton890ff562012-02-02 05:48:16 +00005137 // Make sure the decl contexts match all the way up
5138 if (DIEDeclContextsMatch(cu, die, type_cu, type_die))
Greg Clayton934cb052011-12-03 00:27:05 +00005139 {
Greg Clayton890ff562012-02-02 05:48:16 +00005140 Type *resolved_type = ResolveType (type_cu, type_die, false);
5141 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5142 {
Daniel Malead01b2952012-11-29 21:49:15 +00005143 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 +00005144 MakeUserID(die->GetOffset()),
Ed Mastea0191d12013-10-17 20:42:56 +00005145 MakeUserID(cu->GetOffset()),
Greg Clayton890ff562012-02-02 05:48:16 +00005146 m_obj_file->GetFileSpec().GetFilename().AsCString(),
5147 MakeUserID(type_die->GetOffset()),
5148 MakeUserID(type_cu->GetOffset()));
5149
5150 m_die_to_type[die] = resolved_type;
Greg Claytonff7692a2012-02-02 18:16:59 +00005151 type_sp = resolved_type->shared_from_this();
Greg Clayton890ff562012-02-02 05:48:16 +00005152 break;
5153 }
Greg Clayton934cb052011-12-03 00:27:05 +00005154 }
5155 }
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005156 else
5157 {
5158 if (log)
5159 {
5160 std::string qualified_name;
5161 type_die->GetQualifiedName(this, cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00005162 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005163 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') ignoring die=0x%8.8x (%s)",
5164 die->GetOffset(),
5165 type_name.GetCString(),
5166 type_die->GetOffset(),
5167 qualified_name.c_str());
5168 }
5169 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005170 }
Greg Clayton95d87902011-11-11 03:16:25 +00005171 else
5172 {
5173 if (m_using_apple_tables)
5174 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005175 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5176 die_offset, type_name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00005177 }
5178 }
5179
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005180 }
5181 }
5182 return type_sp;
5183}
5184
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005185TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00005186SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx)
5187{
5188 TypeSP type_sp;
5189
5190 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
5191 if (dwarf_decl_ctx_count > 0)
5192 {
5193 const ConstString type_name(dwarf_decl_ctx[0].name);
5194 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
5195
5196 if (type_name)
5197 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005198 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
Greg Claytona8022fa2012-04-24 21:22:41 +00005199 if (log)
5200 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005201 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005202 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')",
5203 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5204 dwarf_decl_ctx.GetQualifiedName());
5205 }
5206
5207 DIEArray die_offsets;
5208
5209 if (m_using_apple_tables)
5210 {
5211 if (m_apple_types_ap.get())
5212 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005213 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
5214 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
5215 if (has_tag && has_qualified_name_hash)
Greg Claytona8022fa2012-04-24 21:22:41 +00005216 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005217 const char *qualified_name = dwarf_decl_ctx.GetQualifiedName();
5218 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name);
5219 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005220 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005221 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets);
5222 }
5223 else if (has_tag)
5224 {
5225 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005226 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
Greg Claytona8022fa2012-04-24 21:22:41 +00005227 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets);
5228 }
5229 else
5230 {
5231 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
5232 }
5233 }
5234 }
5235 else
5236 {
5237 if (!m_indexed)
5238 Index ();
5239
5240 m_type_index.Find (type_name, die_offsets);
5241 }
5242
5243 const size_t num_matches = die_offsets.size();
5244
5245
5246 DWARFCompileUnit* type_cu = NULL;
5247 const DWARFDebugInfoEntry* type_die = NULL;
5248 if (num_matches)
5249 {
5250 DWARFDebugInfo* debug_info = DebugInfo();
5251 for (size_t i=0; i<num_matches; ++i)
5252 {
5253 const dw_offset_t die_offset = die_offsets[i];
5254 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
5255
5256 if (type_die)
5257 {
5258 bool try_resolving_type = false;
5259
5260 // Don't try and resolve the DIE we are looking for with the DIE itself!
5261 const dw_tag_t type_tag = type_die->Tag();
5262 // Make sure the tags match
5263 if (type_tag == tag)
5264 {
5265 // The tags match, lets try resolving this type
5266 try_resolving_type = true;
5267 }
5268 else
5269 {
5270 // The tags don't match, but we need to watch our for a
5271 // forward declaration for a struct and ("struct foo")
5272 // ends up being a class ("class foo { ... };") or
5273 // vice versa.
5274 switch (type_tag)
5275 {
5276 case DW_TAG_class_type:
5277 // We had a "class foo", see if we ended up with a "struct foo { ... };"
5278 try_resolving_type = (tag == DW_TAG_structure_type);
5279 break;
5280 case DW_TAG_structure_type:
5281 // We had a "struct foo", see if we ended up with a "class foo { ... };"
5282 try_resolving_type = (tag == DW_TAG_class_type);
5283 break;
5284 default:
5285 // Tags don't match, don't event try to resolve
5286 // using this type whose name matches....
5287 break;
5288 }
5289 }
5290
5291 if (try_resolving_type)
5292 {
5293 DWARFDeclContext type_dwarf_decl_ctx;
5294 type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx);
5295
5296 if (log)
5297 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005298 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005299 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)",
5300 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5301 dwarf_decl_ctx.GetQualifiedName(),
5302 type_die->GetOffset(),
5303 type_dwarf_decl_ctx.GetQualifiedName());
5304 }
5305
5306 // Make sure the decl contexts match all the way up
5307 if (dwarf_decl_ctx == type_dwarf_decl_ctx)
5308 {
5309 Type *resolved_type = ResolveType (type_cu, type_die, false);
5310 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5311 {
5312 type_sp = resolved_type->shared_from_this();
5313 break;
5314 }
5315 }
5316 }
5317 else
5318 {
5319 if (log)
5320 {
5321 std::string qualified_name;
5322 type_die->GetQualifiedName(this, type_cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00005323 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005324 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)",
5325 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5326 dwarf_decl_ctx.GetQualifiedName(),
5327 type_die->GetOffset(),
5328 qualified_name.c_str());
5329 }
5330 }
5331 }
5332 else
5333 {
5334 if (m_using_apple_tables)
5335 {
5336 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5337 die_offset, type_name.GetCString());
5338 }
5339 }
5340
5341 }
5342 }
5343 }
5344 }
5345 return type_sp;
5346}
5347
Greg Clayton4116e932012-05-15 02:33:01 +00005348bool
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005349SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005350 Type *class_type,
Greg Clayton4116e932012-05-15 02:33:01 +00005351 DWARFCompileUnit* src_cu,
5352 const DWARFDebugInfoEntry *src_class_die,
5353 DWARFCompileUnit* dst_cu,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005354 const DWARFDebugInfoEntry *dst_class_die,
5355 llvm::SmallVectorImpl <const DWARFDebugInfoEntry *> &failures)
Greg Clayton4116e932012-05-15 02:33:01 +00005356{
5357 if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die)
5358 return false;
5359 if (src_class_die->Tag() != dst_class_die->Tag())
5360 return false;
5361
5362 // We need to complete the class type so we can get all of the method types
5363 // parsed so we can then unique those types to their equivalent counterparts
5364 // in "dst_cu" and "dst_class_die"
5365 class_type->GetClangFullType();
5366
5367 const DWARFDebugInfoEntry *src_die;
5368 const DWARFDebugInfoEntry *dst_die;
5369 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die;
5370 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die;
Greg Clayton65ec1032012-11-12 21:27:20 +00005371 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial;
5372 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial;
Greg Clayton4116e932012-05-15 02:33:01 +00005373 for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling())
5374 {
5375 if (src_die->Tag() == DW_TAG_subprogram)
5376 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005377 // Make sure this is a declaration and not a concrete instance by looking
5378 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5379 // are placed inside the class definitions and shouldn't be included in
5380 // the list of things are are tracking here.
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005381 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_declaration, 0) == 1)
Greg Clayton84afacd2012-11-07 23:09:32 +00005382 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005383 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton84afacd2012-11-07 23:09:32 +00005384 if (src_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005385 {
5386 ConstString src_const_name(src_name);
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005387 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0))
Greg Clayton65ec1032012-11-12 21:27:20 +00005388 src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die);
5389 else
5390 src_name_to_die.Append(src_const_name.GetCString(), src_die);
5391 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005392 }
Greg Clayton4116e932012-05-15 02:33:01 +00005393 }
5394 }
5395 for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling())
5396 {
5397 if (dst_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.
5403 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1)
5404 {
5405 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5406 if (dst_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005407 {
5408 ConstString dst_const_name(dst_name);
5409 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0))
5410 dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die);
5411 else
5412 dst_name_to_die.Append(dst_const_name.GetCString(), dst_die);
5413 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005414 }
Greg Clayton4116e932012-05-15 02:33:01 +00005415 }
5416 }
5417 const uint32_t src_size = src_name_to_die.GetSize ();
5418 const uint32_t dst_size = dst_name_to_die.GetSize ();
Greg Clayton5160ce52013-03-27 23:08:40 +00005419 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005420
5421 // Is everything kosher so we can go through the members at top speed?
5422 bool fast_path = true;
5423
5424 if (src_size != dst_size)
Greg Clayton4116e932012-05-15 02:33:01 +00005425 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005426 if (src_size != 0 && dst_size != 0)
5427 {
5428 if (log)
5429 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)",
5430 src_class_die->GetOffset(),
5431 dst_class_die->GetOffset(),
5432 src_size,
5433 dst_size);
5434 }
5435
5436 fast_path = false;
5437 }
5438
5439 uint32_t idx;
5440
5441 if (fast_path)
5442 {
Greg Clayton4116e932012-05-15 02:33:01 +00005443 for (idx = 0; idx < src_size; ++idx)
5444 {
5445 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5446 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5447
5448 if (src_die->Tag() != dst_die->Tag())
5449 {
5450 if (log)
5451 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)",
5452 src_class_die->GetOffset(),
5453 dst_class_die->GetOffset(),
5454 src_die->GetOffset(),
5455 DW_TAG_value_to_name(src_die->Tag()),
5456 dst_die->GetOffset(),
5457 DW_TAG_value_to_name(src_die->Tag()));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005458 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005459 }
5460
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005461 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton4116e932012-05-15 02:33:01 +00005462 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5463
5464 // Make sure the names match
5465 if (src_name == dst_name || (strcmp (src_name, dst_name) == 0))
5466 continue;
5467
5468 if (log)
5469 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)",
5470 src_class_die->GetOffset(),
5471 dst_class_die->GetOffset(),
5472 src_die->GetOffset(),
5473 src_name,
5474 dst_die->GetOffset(),
5475 dst_name);
5476
Sean Callanan2367f8a2013-02-26 01:12:25 +00005477 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005478 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005479 }
Greg Clayton4116e932012-05-15 02:33:01 +00005480
Sean Callanan2367f8a2013-02-26 01:12:25 +00005481 // Now do the work of linking the DeclContexts and Types.
5482 if (fast_path)
5483 {
5484 // We can do this quickly. Just run across the tables index-for-index since
5485 // we know each node has matching names and tags.
Greg Clayton4116e932012-05-15 02:33:01 +00005486 for (idx = 0; idx < src_size; ++idx)
5487 {
5488 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5489 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5490
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005491 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Greg Clayton4116e932012-05-15 02:33:01 +00005492 if (src_decl_ctx)
5493 {
5494 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005495 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005496 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5497 }
5498 else
5499 {
5500 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005501 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());
Greg Clayton4116e932012-05-15 02:33:01 +00005502 }
5503
5504 Type *src_child_type = m_die_to_type[src_die];
5505 if (src_child_type)
5506 {
5507 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00005508 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", src_child_type, src_child_type->GetID(), src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005509 m_die_to_type[dst_die] = src_child_type;
5510 }
5511 else
5512 {
5513 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005514 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());
5515 }
5516 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005517 }
5518 else
5519 {
5520 // We must do this slowly. For each member of the destination, look
5521 // up a member in the source with the same name, check its tag, and
5522 // unique them if everything matches up. Report failures.
Greg Clayton65ec1032012-11-12 21:27:20 +00005523
Sean Callanan2367f8a2013-02-26 01:12:25 +00005524 if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty())
5525 {
5526 src_name_to_die.Sort();
Greg Clayton65ec1032012-11-12 21:27:20 +00005527
Sean Callanan2367f8a2013-02-26 01:12:25 +00005528 for (idx = 0; idx < dst_size; ++idx)
5529 {
5530 const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx);
5531 dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
5532 src_die = src_name_to_die.Find(dst_name, NULL);
5533
5534 if (src_die && (src_die->Tag() == dst_die->Tag()))
5535 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005536 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Sean Callanan2367f8a2013-02-26 01:12:25 +00005537 if (src_decl_ctx)
5538 {
5539 if (log)
5540 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
5541 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5542 }
5543 else
5544 {
5545 if (log)
5546 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());
5547 }
5548
5549 Type *src_child_type = m_die_to_type[src_die];
5550 if (src_child_type)
5551 {
5552 if (log)
5553 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", src_child_type, src_child_type->GetID(), src_die->GetOffset(), dst_die->GetOffset());
5554 m_die_to_type[dst_die] = src_child_type;
5555 }
5556 else
5557 {
5558 if (log)
5559 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());
5560 }
5561 }
5562 else
5563 {
5564 if (log)
5565 log->Printf ("warning: couldn't find a match for 0x%8.8x", dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005566
Sean Callanan2367f8a2013-02-26 01:12:25 +00005567 failures.push_back(dst_die);
5568 }
5569 }
5570 }
5571 }
5572
5573 const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize ();
5574 const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize ();
5575
5576 UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src;
5577
5578 if (src_size_artificial && dst_size_artificial)
5579 {
5580 dst_name_to_die_artificial.Sort();
5581
Greg Clayton65ec1032012-11-12 21:27:20 +00005582 for (idx = 0; idx < src_size_artificial; ++idx)
5583 {
5584 const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx);
5585 src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5586 dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL);
5587
5588 if (dst_die)
5589 {
Greg Clayton65ec1032012-11-12 21:27:20 +00005590 // Both classes have the artificial types, link them
5591 clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die];
5592 if (src_decl_ctx)
5593 {
5594 if (log)
5595 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
5596 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5597 }
5598 else
5599 {
5600 if (log)
5601 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());
5602 }
5603
5604 Type *src_child_type = m_die_to_type[src_die];
5605 if (src_child_type)
5606 {
5607 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00005608 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", src_child_type, src_child_type->GetID(), src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005609 m_die_to_type[dst_die] = src_child_type;
5610 }
5611 else
5612 {
5613 if (log)
5614 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());
5615 }
5616 }
5617 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005618 }
Greg Clayton65ec1032012-11-12 21:27:20 +00005619
Sean Callanan2367f8a2013-02-26 01:12:25 +00005620 if (dst_size_artificial)
Greg Clayton4116e932012-05-15 02:33:01 +00005621 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005622 for (idx = 0; idx < dst_size_artificial; ++idx)
5623 {
5624 const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx);
5625 dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5626 if (log)
5627 log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial);
5628
5629 failures.push_back(dst_die);
5630 }
Greg Clayton4116e932012-05-15 02:33:01 +00005631 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005632
5633 return (failures.size() != 0);
Greg Clayton4116e932012-05-15 02:33:01 +00005634}
Greg Claytona8022fa2012-04-24 21:22:41 +00005635
5636TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00005637SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005638{
5639 TypeSP type_sp;
5640
Greg Clayton1be10fc2010-09-29 01:12:09 +00005641 if (type_is_new_ptr)
5642 *type_is_new_ptr = false;
Greg Clayton1fba87112012-02-09 20:03:49 +00005643
5644#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5645 static DIEStack g_die_stack;
5646 DIEStack::ScopedPopper scoped_die_logger(g_die_stack);
5647#endif
Greg Clayton1be10fc2010-09-29 01:12:09 +00005648
Sean Callananc7fbf732010-08-06 00:32:49 +00005649 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005650 if (die != NULL)
5651 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005652 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005653 if (log)
Sean Callanan5b26f272012-02-04 08:49:35 +00005654 {
5655 const DWARFDebugInfoEntry *context_die;
5656 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
5657
Greg Clayton5160ce52013-03-27 23:08:40 +00005658 GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x, decl_ctx = %p (die 0x%8.8x)) %s name = '%s')",
Sean Callanan5b26f272012-02-04 08:49:35 +00005659 die->GetOffset(),
5660 context,
5661 context_die->GetOffset(),
Greg Clayton3bffb082011-12-10 02:15:28 +00005662 DW_TAG_value_to_name(die->Tag()),
Greg Clayton1fba87112012-02-09 20:03:49 +00005663 die->GetName(this, dwarf_cu));
5664
5665#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5666 scoped_die_logger.Push (dwarf_cu, die);
Greg Clayton5160ce52013-03-27 23:08:40 +00005667 g_die_stack.LogDIEs(log, this);
Greg Clayton1fba87112012-02-09 20:03:49 +00005668#endif
Sean Callanan5b26f272012-02-04 08:49:35 +00005669 }
Greg Clayton3bffb082011-12-10 02:15:28 +00005670//
Greg Clayton5160ce52013-03-27 23:08:40 +00005671// Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005672// if (log && dwarf_cu)
5673// {
5674// StreamString s;
5675// die->DumpLocation (this, dwarf_cu, s);
Greg Clayton5160ce52013-03-27 23:08:40 +00005676// GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Greg Clayton3bffb082011-12-10 02:15:28 +00005677//
5678// }
Jim Ingham16746d12011-08-25 23:21:43 +00005679
Greg Clayton594e5ed2010-09-27 21:07:38 +00005680 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005681 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00005682 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005683 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005684 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00005685 if (type_is_new_ptr)
5686 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005687
Greg Clayton594e5ed2010-09-27 21:07:38 +00005688 const dw_tag_t tag = die->Tag();
5689
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005690 bool is_forward_declaration = false;
5691 DWARFDebugInfoEntry::Attributes attributes;
5692 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00005693 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00005694 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
Greg Claytonfaac1112013-03-14 18:31:44 +00005695 uint64_t byte_size = 0;
Greg Clayton526e5af2010-11-13 03:52:47 +00005696 Declaration decl;
5697
Greg Clayton4957bf62010-09-30 21:49:03 +00005698 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton57ee3062013-07-11 22:46:58 +00005699 ClangASTType clang_type;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005700
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005701 dw_attr_t attr;
5702
5703 switch (tag)
5704 {
5705 case DW_TAG_base_type:
5706 case DW_TAG_pointer_type:
5707 case DW_TAG_reference_type:
Sean Callanance8af862012-05-21 23:31:51 +00005708 case DW_TAG_rvalue_reference_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005709 case DW_TAG_typedef:
5710 case DW_TAG_const_type:
5711 case DW_TAG_restrict_type:
5712 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00005713 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005714 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005715 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005716 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005717
Greg Claytond88d7592010-09-15 08:33:30 +00005718 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005719 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005720 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
5721
5722 if (num_attributes > 0)
5723 {
5724 uint32_t i;
5725 for (i=0; i<num_attributes; ++i)
5726 {
5727 attr = attributes.AttributeAtIndex(i);
5728 DWARFFormValue form_value;
5729 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5730 {
5731 switch (attr)
5732 {
5733 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5734 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5735 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5736 case DW_AT_name:
Jim Ingham337030f2011-04-15 23:41:23 +00005737
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005738 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00005739 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
5740 // include the "&"...
5741 if (tag == DW_TAG_reference_type)
5742 {
5743 if (strchr (type_name_cstr, '&') == NULL)
5744 type_name_cstr = NULL;
5745 }
5746 if (type_name_cstr)
5747 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005748 break;
Greg Clayton23f59502012-07-17 03:23:13 +00005749 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005750 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
5751 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
5752 default:
5753 case DW_AT_sibling:
5754 break;
5755 }
5756 }
5757 }
5758 }
5759
Ed Mastea0191d12013-10-17 20:42:56 +00005760 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 +00005761
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005762 switch (tag)
5763 {
5764 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00005765 break;
5766
Greg Claytond4436412011-10-28 21:00:00 +00005767 case DW_TAG_unspecified_type:
Greg Clayton7fba2632013-07-01 21:01:52 +00005768 if (strcmp(type_name_cstr, "nullptr_t") == 0 ||
5769 strcmp(type_name_cstr, "decltype(nullptr)") == 0 )
Greg Claytond4436412011-10-28 21:00:00 +00005770 {
5771 resolve_state = Type::eResolveStateFull;
Greg Clayton57ee3062013-07-11 22:46:58 +00005772 clang_type = ast.GetBasicType(eBasicTypeNullPtr);
Greg Claytond4436412011-10-28 21:00:00 +00005773 break;
5774 }
5775 // Fall through to base type below in case we can handle the type there...
5776
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005777 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00005778 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005779 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
5780 encoding,
5781 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005782 break;
5783
Sean Callanance8af862012-05-21 23:31:51 +00005784 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
5785 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
5786 case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break;
5787 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
5788 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
5789 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
5790 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005791 }
5792
Greg Clayton57ee3062013-07-11 22:46:58 +00005793 if (!clang_type && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID) && sc.comp_unit != NULL)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005794 {
Sean Callanan82587052013-01-03 00:05:56 +00005795 bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus);
5796
5797 if (translation_unit_is_objc)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005798 {
Sean Callanan82587052013-01-03 00:05:56 +00005799 if (type_name_cstr != NULL)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005800 {
Sean Callanan82587052013-01-03 00:05:56 +00005801 static ConstString g_objc_type_name_id("id");
5802 static ConstString g_objc_type_name_Class("Class");
5803 static ConstString g_objc_type_name_selector("SEL");
5804
5805 if (type_name_const_str == g_objc_type_name_id)
5806 {
5807 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005808 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 +00005809 die->GetOffset(),
5810 DW_TAG_value_to_name(die->Tag()),
5811 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005812 clang_type = ast.GetBasicType(eBasicTypeObjCID);
Sean Callanan82587052013-01-03 00:05:56 +00005813 encoding_data_type = Type::eEncodingIsUID;
5814 encoding_uid = LLDB_INVALID_UID;
5815 resolve_state = Type::eResolveStateFull;
Greg Clayton526e5af2010-11-13 03:52:47 +00005816
Sean Callanan82587052013-01-03 00:05:56 +00005817 }
5818 else if (type_name_const_str == g_objc_type_name_Class)
5819 {
5820 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005821 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 +00005822 die->GetOffset(),
5823 DW_TAG_value_to_name(die->Tag()),
5824 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005825 clang_type = ast.GetBasicType(eBasicTypeObjCClass);
Sean Callanan82587052013-01-03 00:05:56 +00005826 encoding_data_type = Type::eEncodingIsUID;
5827 encoding_uid = LLDB_INVALID_UID;
5828 resolve_state = Type::eResolveStateFull;
5829 }
5830 else if (type_name_const_str == g_objc_type_name_selector)
5831 {
5832 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005833 GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.",
Sean Callanan82587052013-01-03 00:05:56 +00005834 die->GetOffset(),
5835 DW_TAG_value_to_name(die->Tag()),
5836 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005837 clang_type = ast.GetBasicType(eBasicTypeObjCSel);
Sean Callanan82587052013-01-03 00:05:56 +00005838 encoding_data_type = Type::eEncodingIsUID;
5839 encoding_uid = LLDB_INVALID_UID;
5840 resolve_state = Type::eResolveStateFull;
5841 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005842 }
Sean Callanan82587052013-01-03 00:05:56 +00005843 else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005844 {
Sean Callanan82587052013-01-03 00:05:56 +00005845 // Clang sometimes erroneously emits id as objc_object*. In that case we fix up the type to "id".
5846
5847 DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid);
5848
5849 if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type)
5850 {
5851 if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL))
5852 {
5853 if (!strcmp(struct_name, "objc_object"))
5854 {
5855 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005856 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 +00005857 die->GetOffset(),
5858 DW_TAG_value_to_name(die->Tag()),
5859 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005860 clang_type = ast.GetBasicType(eBasicTypeObjCID);
Sean Callanan82587052013-01-03 00:05:56 +00005861 encoding_data_type = Type::eEncodingIsUID;
5862 encoding_uid = LLDB_INVALID_UID;
5863 resolve_state = Type::eResolveStateFull;
5864 }
5865 }
5866 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005867 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005868 }
5869 }
5870
Greg Clayton81c22f62011-10-19 18:09:39 +00005871 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005872 this,
5873 type_name_const_str,
5874 byte_size,
5875 NULL,
5876 encoding_uid,
5877 encoding_data_type,
5878 &decl,
5879 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005880 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005881
Greg Clayton594e5ed2010-09-27 21:07:38 +00005882 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005883
5884// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
5885// if (encoding_type != NULL)
5886// {
5887// if (encoding_type != DIE_IS_BEING_PARSED)
5888// type_sp->SetEncodingType(encoding_type);
5889// else
5890// m_indirect_fixups.push_back(type_sp.get());
5891// }
5892 }
5893 break;
5894
5895 case DW_TAG_structure_type:
5896 case DW_TAG_union_type:
5897 case DW_TAG_class_type:
5898 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005899 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005900 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Greg Clayton23f59502012-07-17 03:23:13 +00005901 bool byte_size_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005902
Greg Clayton9e409562010-07-28 02:04:09 +00005903 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00005904 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005905 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00005906 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005907 if (num_attributes > 0)
5908 {
5909 uint32_t i;
5910 for (i=0; i<num_attributes; ++i)
5911 {
5912 attr = attributes.AttributeAtIndex(i);
5913 DWARFFormValue form_value;
5914 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5915 {
5916 switch (attr)
5917 {
Greg Clayton9e409562010-07-28 02:04:09 +00005918 case DW_AT_decl_file:
Greg Claytonc7f03b62012-01-12 04:33:28 +00005919 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
Ed Maste4c24b122013-10-17 20:13:14 +00005920 {
5921 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
5922 // point to the compile unit file, so we clear this invalid value
5923 // so that we can still unique types efficiently.
Greg Claytonc7f03b62012-01-12 04:33:28 +00005924 decl.SetFile(FileSpec ("<invalid>", false));
Ed Maste4c24b122013-10-17 20:13:14 +00005925 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005926 else
5927 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
Greg Clayton9e409562010-07-28 02:04:09 +00005928 break;
5929
5930 case DW_AT_decl_line:
5931 decl.SetLine(form_value.Unsigned());
5932 break;
5933
5934 case DW_AT_decl_column:
5935 decl.SetColumn(form_value.Unsigned());
5936 break;
5937
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005938 case DW_AT_name:
5939 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005940 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005941 break;
Greg Clayton9e409562010-07-28 02:04:09 +00005942
5943 case DW_AT_byte_size:
5944 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00005945 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00005946 break;
5947
5948 case DW_AT_accessibility:
5949 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
5950 break;
5951
5952 case DW_AT_declaration:
Greg Clayton1c8ef472013-04-05 23:27:21 +00005953 is_forward_declaration = form_value.Boolean();
Greg Clayton9e409562010-07-28 02:04:09 +00005954 break;
5955
5956 case DW_AT_APPLE_runtime_class:
5957 class_language = (LanguageType)form_value.Signed();
5958 break;
5959
Greg Clayton18774842011-11-29 23:40:34 +00005960 case DW_AT_APPLE_objc_complete_type:
5961 is_complete_objc_class = form_value.Signed();
5962 break;
5963
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005964 case DW_AT_allocated:
5965 case DW_AT_associated:
5966 case DW_AT_data_location:
5967 case DW_AT_description:
5968 case DW_AT_start_scope:
5969 case DW_AT_visibility:
5970 default:
5971 case DW_AT_sibling:
5972 break;
5973 }
5974 }
5975 }
5976 }
5977
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005978 UniqueDWARFASTType unique_ast_entry;
Sean Callanan8e8072d2012-02-07 21:13:38 +00005979
Greg Clayton123edca2012-03-02 00:07:15 +00005980 // Only try and unique the type if it has a name.
5981 if (type_name_const_str &&
5982 GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Sean Callanan8e8072d2012-02-07 21:13:38 +00005983 this,
5984 dwarf_cu,
5985 die,
5986 decl,
5987 byte_size_valid ? byte_size : -1,
5988 unique_ast_entry))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005989 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005990 // We have already parsed this type or from another
5991 // compile unit. GCC loves to use the "one definition
5992 // rule" which can result in multiple definitions
5993 // of the same class over and over in each compile
5994 // unit.
5995 type_sp = unique_ast_entry.m_type_sp;
5996 if (type_sp)
Greg Claytonc615ce42010-11-09 04:42:43 +00005997 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005998 m_die_to_type[die] = type_sp.get();
5999 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00006000 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006001 }
6002
Daniel Malead01b2952012-11-29 21:49:15 +00006003 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 +00006004
6005 int tag_decl_kind = -1;
6006 AccessType default_accessibility = eAccessNone;
6007 if (tag == DW_TAG_structure_type)
6008 {
6009 tag_decl_kind = clang::TTK_Struct;
6010 default_accessibility = eAccessPublic;
6011 }
6012 else if (tag == DW_TAG_union_type)
6013 {
6014 tag_decl_kind = clang::TTK_Union;
6015 default_accessibility = eAccessPublic;
6016 }
6017 else if (tag == DW_TAG_class_type)
6018 {
6019 tag_decl_kind = clang::TTK_Class;
6020 default_accessibility = eAccessPrivate;
6021 }
Greg Clayton3a5f29a2011-11-30 02:48:28 +00006022
6023 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
6024 die->HasChildren() == false &&
6025 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
6026 {
6027 // Work around an issue with clang at the moment where
6028 // forward declarations for objective C classes are emitted
6029 // as:
6030 // DW_TAG_structure_type [2]
6031 // DW_AT_name( "ForwardObjcClass" )
6032 // DW_AT_byte_size( 0x00 )
6033 // DW_AT_decl_file( "..." )
6034 // DW_AT_decl_line( 1 )
6035 //
6036 // Note that there is no DW_AT_declaration and there are
6037 // no children, and the byte size is zero.
6038 is_forward_declaration = true;
6039 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006040
Sean Callanan7457f8d2012-04-25 01:03:57 +00006041 if (class_language == eLanguageTypeObjC ||
6042 class_language == eLanguageTypeObjC_plus_plus)
Greg Clayton18774842011-11-29 23:40:34 +00006043 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00006044 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
Greg Clayton901c5ca2011-12-03 04:40:03 +00006045 {
6046 // We have a valid eSymbolTypeObjCClass class symbol whose
6047 // name matches the current objective C class that we
6048 // are trying to find and this DIE isn't the complete
6049 // definition (we checked is_complete_objc_class above and
6050 // know it is false), so the real definition is in here somewhere
Greg Claytonc7f03b62012-01-12 04:33:28 +00006051 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006052
Greg Clayton1f746072012-08-29 21:13:06 +00006053 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton901c5ca2011-12-03 04:40:03 +00006054 {
6055 // We weren't able to find a full declaration in
6056 // this DWARF, see if we have a declaration anywhere
6057 // else...
Greg Claytonc7f03b62012-01-12 04:33:28 +00006058 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00006059 }
6060
6061 if (type_sp)
6062 {
6063 if (log)
6064 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006065 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00006066 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8" PRIx64,
Greg Claytone38a5ed2012-01-05 03:57:59 +00006067 this,
6068 die->GetOffset(),
6069 DW_TAG_value_to_name(tag),
6070 type_name_cstr,
6071 type_sp->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00006072 }
6073
6074 // We found a real definition for this type elsewhere
6075 // so lets use it and cache the fact that we found
6076 // a complete type for this die
6077 m_die_to_type[die] = type_sp.get();
6078 return type_sp;
6079 }
6080 }
6081 }
6082
6083
6084 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006085 {
6086 // We have a forward declaration to a type and we need
6087 // to try and find a full declaration. We look in the
6088 // current type index just in case we have a forward
6089 // declaration followed by an actual declarations in the
6090 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00006091 if (log)
6092 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006093 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00006094 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
6095 this,
6096 die->GetOffset(),
6097 DW_TAG_value_to_name(tag),
6098 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00006099 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006100
Greg Claytona8022fa2012-04-24 21:22:41 +00006101 DWARFDeclContext die_decl_ctx;
6102 die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx);
6103
6104 //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
6105 type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006106
Greg Clayton1f746072012-08-29 21:13:06 +00006107 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton4272cc72011-02-02 02:24:04 +00006108 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006109 // We weren't able to find a full declaration in
6110 // this DWARF, see if we have a declaration anywhere
6111 // else...
Greg Claytona8022fa2012-04-24 21:22:41 +00006112 type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton4272cc72011-02-02 02:24:04 +00006113 }
6114
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006115 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00006116 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00006117 if (log)
6118 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006119 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00006120 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8" PRIx64,
Greg Claytone38a5ed2012-01-05 03:57:59 +00006121 this,
6122 die->GetOffset(),
6123 DW_TAG_value_to_name(tag),
6124 type_name_cstr,
6125 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00006126 }
6127
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006128 // We found a real definition for this type elsewhere
6129 // so lets use it and cache the fact that we found
6130 // a complete type for this die
6131 m_die_to_type[die] = type_sp.get();
6132 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00006133 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006134 }
6135 assert (tag_decl_kind != -1);
6136 bool clang_type_was_created = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00006137 clang_type.SetClangType(ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die));
6138 if (!clang_type)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006139 {
Sean Callanan4d04c6a2012-02-09 22:54:11 +00006140 const DWARFDebugInfoEntry *decl_ctx_die;
6141
6142 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton55561e92011-10-26 03:31:36 +00006143 if (accessibility == eAccessNone && decl_ctx)
6144 {
6145 // Check the decl context that contains this class/struct/union.
6146 // If it is a class we must give it an accessability.
6147 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
6148 if (DeclKindIsCXXClass (containing_decl_kind))
6149 accessibility = default_accessibility;
6150 }
6151
Greg Claytonc4ffd662013-03-08 01:37:30 +00006152 ClangASTMetadata metadata;
6153 metadata.SetUserID(MakeUserID(die->GetOffset()));
6154 metadata.SetIsDynamicCXXType(ClassOrStructIsVirtual (dwarf_cu, die));
6155
Greg Claytonf0705c82011-10-22 03:33:13 +00006156 if (type_name_cstr && strchr (type_name_cstr, '<'))
6157 {
6158 ClangASTContext::TemplateParameterInfos template_param_infos;
6159 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
6160 {
6161 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00006162 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00006163 type_name_cstr,
6164 tag_decl_kind,
6165 template_param_infos);
6166
6167 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
6168 class_template_decl,
6169 tag_decl_kind,
6170 template_param_infos);
6171 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
6172 clang_type_was_created = true;
Sean Callanan60217122012-04-13 00:10:03 +00006173
Greg Claytond0029442013-03-27 01:48:02 +00006174 GetClangASTContext().SetMetadata (class_template_decl, metadata);
6175 GetClangASTContext().SetMetadata (class_specialization_decl, metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00006176 }
6177 }
6178
6179 if (!clang_type_was_created)
6180 {
6181 clang_type_was_created = true;
Greg Clayton55561e92011-10-26 03:31:36 +00006182 clang_type = ast.CreateRecordType (decl_ctx,
6183 accessibility,
6184 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00006185 tag_decl_kind,
Sean Callanan60217122012-04-13 00:10:03 +00006186 class_language,
Jim Ingham379397632012-10-27 02:54:13 +00006187 &metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00006188 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006189 }
6190
6191 // Store a forward declaration to this class type in case any
6192 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00006193 // types for function prototypes.
Greg Clayton57ee3062013-07-11 22:46:58 +00006194 LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00006195 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006196 this,
6197 type_name_const_str,
6198 byte_size,
6199 NULL,
6200 LLDB_INVALID_UID,
6201 Type::eEncodingIsUID,
6202 &decl,
6203 clang_type,
6204 Type::eResolveStateForward));
Sean Callanan72772842012-02-22 23:57:45 +00006205
6206 type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006207
6208
6209 // Add our type to the unique type map so we don't
6210 // end up creating many copies of the same type over
6211 // and over in the ASTContext for our module
6212 unique_ast_entry.m_type_sp = type_sp;
Greg Clayton36909642011-03-15 04:38:20 +00006213 unique_ast_entry.m_symfile = this;
6214 unique_ast_entry.m_cu = dwarf_cu;
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006215 unique_ast_entry.m_die = die;
6216 unique_ast_entry.m_declaration = decl;
Sean Callanan59700592012-02-13 22:30:16 +00006217 unique_ast_entry.m_byte_size = byte_size;
Greg Claytone576ab22011-02-15 00:19:15 +00006218 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
6219 unique_ast_entry);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006220
Greg Clayton0ec71a02013-08-10 00:09:35 +00006221 if (is_forward_declaration && die->HasChildren())
6222 {
6223 // Check to see if the DIE actually has a definition, some version of GCC will
6224 // emit DIEs with DW_AT_declaration set to true, but yet still have subprogram,
6225 // members, or inheritance, so we can't trust it
6226 const DWARFDebugInfoEntry *child_die = die->GetFirstChild();
6227 while (child_die)
6228 {
6229 switch (child_die->Tag())
6230 {
6231 case DW_TAG_inheritance:
6232 case DW_TAG_subprogram:
6233 case DW_TAG_member:
6234 case DW_TAG_APPLE_property:
6235 child_die = NULL;
6236 is_forward_declaration = false;
6237 break;
6238 default:
6239 child_die = child_die->GetSibling();
6240 break;
6241 }
6242 }
6243 }
6244
Sean Callanan12014a02011-12-08 23:45:45 +00006245 if (!is_forward_declaration)
Greg Clayton219cf312012-03-30 00:51:13 +00006246 {
6247 // Always start the definition for a class type so that
6248 // if the class has child classes or types that require
6249 // the class to be created for use as their decl contexts
6250 // the class will be ready to accept these child definitions.
Sean Callanan12014a02011-12-08 23:45:45 +00006251 if (die->HasChildren() == false)
6252 {
6253 // No children for this struct/union/class, lets finish it
Greg Clayton57ee3062013-07-11 22:46:58 +00006254 clang_type.StartTagDeclarationDefinition ();
6255 clang_type.CompleteTagDeclarationDefinition ();
Sean Callanan433cd222012-10-19 01:37:25 +00006256
6257 if (tag == DW_TAG_structure_type) // this only applies in C
6258 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006259 clang::RecordDecl *record_decl = clang_type.GetAsRecordDecl();
Sean Callanan433cd222012-10-19 01:37:25 +00006260
Greg Clayton57ee3062013-07-11 22:46:58 +00006261 if (record_decl)
Sean Callanan433cd222012-10-19 01:37:25 +00006262 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006263 LayoutInfo layout_info;
Sean Callanan433cd222012-10-19 01:37:25 +00006264
Greg Clayton57ee3062013-07-11 22:46:58 +00006265 layout_info.alignment = 0;
6266 layout_info.bit_size = 0;
6267
6268 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
Sean Callanan433cd222012-10-19 01:37:25 +00006269 }
6270 }
Sean Callanan12014a02011-12-08 23:45:45 +00006271 }
6272 else if (clang_type_was_created)
6273 {
Greg Clayton219cf312012-03-30 00:51:13 +00006274 // Start the definition if the class is not objective C since
6275 // the underlying decls respond to isCompleteDefinition(). Objective
6276 // C decls dont' respond to isCompleteDefinition() so we can't
6277 // start the declaration definition right away. For C++ classs/union/structs
6278 // we want to start the definition in case the class is needed as the
6279 // declaration context for a contained class or type without the need
6280 // to complete that type..
6281
Sean Callanan7457f8d2012-04-25 01:03:57 +00006282 if (class_language != eLanguageTypeObjC &&
6283 class_language != eLanguageTypeObjC_plus_plus)
Greg Clayton57ee3062013-07-11 22:46:58 +00006284 clang_type.StartTagDeclarationDefinition ();
Greg Clayton219cf312012-03-30 00:51:13 +00006285
Sean Callanan12014a02011-12-08 23:45:45 +00006286 // Leave this as a forward declaration until we need
6287 // to know the details of the type. lldb_private::Type
6288 // will automatically call the SymbolFile virtual function
6289 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
6290 // When the definition needs to be defined.
Greg Clayton57ee3062013-07-11 22:46:58 +00006291 m_forward_decl_die_to_clang_type[die] = clang_type.GetOpaqueQualType();
6292 m_forward_decl_clang_type_to_die[clang_type.RemoveFastQualifiers().GetOpaqueQualType()] = die;
6293 clang_type.SetHasExternalStorage (true);
Sean Callanan12014a02011-12-08 23:45:45 +00006294 }
Greg Claytonc615ce42010-11-09 04:42:43 +00006295 }
Greg Claytoncab36a32011-12-08 05:16:30 +00006296
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006297 }
6298 break;
6299
6300 case DW_TAG_enumeration_type:
6301 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006302 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006303 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006304
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006305 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006306
Greg Claytond88d7592010-09-15 08:33:30 +00006307 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006308 if (num_attributes > 0)
6309 {
6310 uint32_t i;
6311
6312 for (i=0; i<num_attributes; ++i)
6313 {
6314 attr = attributes.AttributeAtIndex(i);
6315 DWARFFormValue form_value;
6316 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6317 {
6318 switch (attr)
6319 {
Greg Clayton7a345282010-11-09 23:46:37 +00006320 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6321 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6322 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006323 case DW_AT_name:
6324 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006325 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006326 break;
Greg Clayton7a345282010-11-09 23:46:37 +00006327 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006328 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
6329 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006330 case DW_AT_declaration: break; //is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006331 case DW_AT_allocated:
6332 case DW_AT_associated:
6333 case DW_AT_bit_stride:
6334 case DW_AT_byte_stride:
6335 case DW_AT_data_location:
6336 case DW_AT_description:
6337 case DW_AT_start_scope:
6338 case DW_AT_visibility:
6339 case DW_AT_specification:
6340 case DW_AT_abstract_origin:
6341 case DW_AT_sibling:
6342 break;
6343 }
6344 }
6345 }
6346
Daniel Malead01b2952012-11-29 21:49:15 +00006347 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 +00006348
Greg Clayton57ee3062013-07-11 22:46:58 +00006349 ClangASTType enumerator_clang_type;
6350 clang_type.SetClangType (ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die));
6351 if (!clang_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00006352 {
Greg Clayton5d14fc02013-03-06 06:23:54 +00006353 if (encoding_uid != DW_INVALID_OFFSET)
6354 {
6355 Type *enumerator_type = ResolveTypeUID(encoding_uid);
6356 if (enumerator_type)
6357 enumerator_clang_type = enumerator_type->GetClangFullType();
6358 }
6359
Greg Clayton57ee3062013-07-11 22:46:58 +00006360 if (!enumerator_clang_type)
Greg Clayton5d14fc02013-03-06 06:23:54 +00006361 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
6362 DW_ATE_signed,
6363 byte_size * 8);
6364
Greg Claytonca512b32011-01-14 04:54:56 +00006365 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00006366 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00006367 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006368 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00006369 }
6370 else
6371 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006372 enumerator_clang_type = clang_type.GetEnumerationIntegerType ();
Greg Clayton1be10fc2010-09-29 01:12:09 +00006373 }
6374
Greg Clayton57ee3062013-07-11 22:46:58 +00006375 LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die);
Greg Claytona2721472011-06-25 00:44:06 +00006376
Greg Clayton81c22f62011-10-19 18:09:39 +00006377 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006378 this,
6379 type_name_const_str,
6380 byte_size,
6381 NULL,
6382 encoding_uid,
6383 Type::eEncodingIsUID,
6384 &decl,
6385 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006386 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006387
Greg Clayton57ee3062013-07-11 22:46:58 +00006388 clang_type.StartTagDeclarationDefinition ();
Greg Clayton6beaaa62011-01-17 03:46:26 +00006389 if (die->HasChildren())
6390 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006391 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00006392 bool is_signed = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00006393 enumerator_clang_type.IsIntegerType(is_signed);
Greg Clayton3e067532013-03-05 23:54:39 +00006394 ParseChildEnumerators(cu_sc, clang_type, is_signed, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00006395 }
Greg Clayton57ee3062013-07-11 22:46:58 +00006396 clang_type.CompleteTagDeclarationDefinition ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006397 }
6398 }
6399 break;
6400
Jim Inghamb0be4422010-08-12 01:20:14 +00006401 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006402 case DW_TAG_subprogram:
6403 case DW_TAG_subroutine_type:
6404 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006405 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006406 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006407
Greg Clayton23f59502012-07-17 03:23:13 +00006408 //const char *mangled = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006409 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00006410 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006411 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00006412 bool is_static = false;
6413 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00006414 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00006415 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00006416 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
6417 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Jim Ingham379397632012-10-27 02:54:13 +00006418 dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00006419
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006420 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00006421 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006422
6423
Greg Claytond88d7592010-09-15 08:33:30 +00006424 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006425 if (num_attributes > 0)
6426 {
6427 uint32_t i;
6428 for (i=0; i<num_attributes; ++i)
6429 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006430 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006431 DWARFFormValue form_value;
6432 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6433 {
6434 switch (attr)
6435 {
6436 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6437 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6438 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6439 case DW_AT_name:
6440 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006441 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006442 break;
6443
Greg Clayton71415542012-12-08 00:24:40 +00006444 case DW_AT_linkage_name:
Greg Clayton23f59502012-07-17 03:23:13 +00006445 case DW_AT_MIPS_linkage_name: break; // mangled = form_value.AsCString(&get_debug_str_data()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006446 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00006447 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006448 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
6449 case DW_AT_inline: is_inline = form_value.Boolean(); break;
6450 case DW_AT_virtuality: is_virtual = form_value.Boolean(); break;
6451 case DW_AT_explicit: is_explicit = form_value.Boolean(); break;
6452 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Sean Callanandbb58392011-11-02 01:38:59 +00006453
Greg Claytonf51de672010-10-01 02:31:07 +00006454
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006455 case DW_AT_external:
6456 if (form_value.Unsigned())
6457 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00006458 if (storage == clang::SC_None)
6459 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006460 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00006461 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006462 }
6463 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006464
Greg Clayton72da3972011-08-16 18:40:23 +00006465 case DW_AT_specification:
6466 specification_die_offset = form_value.Reference(dwarf_cu);
6467 break;
6468
6469 case DW_AT_abstract_origin:
6470 abstract_origin_die_offset = form_value.Reference(dwarf_cu);
6471 break;
6472
Jim Ingham379397632012-10-27 02:54:13 +00006473 case DW_AT_object_pointer:
6474 object_pointer_die_offset = form_value.Reference(dwarf_cu);
6475 break;
6476
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006477 case DW_AT_allocated:
6478 case DW_AT_associated:
6479 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006480 case DW_AT_calling_convention:
6481 case DW_AT_data_location:
6482 case DW_AT_elemental:
6483 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006484 case DW_AT_frame_base:
6485 case DW_AT_high_pc:
6486 case DW_AT_low_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006487 case DW_AT_prototyped:
6488 case DW_AT_pure:
6489 case DW_AT_ranges:
6490 case DW_AT_recursive:
6491 case DW_AT_return_addr:
6492 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006493 case DW_AT_start_scope:
6494 case DW_AT_static_link:
6495 case DW_AT_trampoline:
6496 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006497 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006498 case DW_AT_description:
6499 case DW_AT_sibling:
6500 break;
6501 }
6502 }
6503 }
Greg Clayton24739922010-10-13 03:15:28 +00006504 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006505
Jim Ingham379397632012-10-27 02:54:13 +00006506 std::string object_pointer_name;
6507 if (object_pointer_die_offset != DW_INVALID_OFFSET)
6508 {
6509 // Get the name from the object pointer die
6510 StreamString s;
6511 if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s))
6512 {
6513 object_pointer_name.assign(s.GetData());
6514 }
6515 }
6516
Daniel Malead01b2952012-11-29 21:49:15 +00006517 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 +00006518
Greg Clayton57ee3062013-07-11 22:46:58 +00006519 ClangASTType return_clang_type;
Greg Clayton24739922010-10-13 03:15:28 +00006520 Type *func_type = NULL;
6521
6522 if (type_die_offset != DW_INVALID_OFFSET)
6523 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00006524
Greg Clayton24739922010-10-13 03:15:28 +00006525 if (func_type)
Greg Clayton42ce2f32011-12-12 21:50:19 +00006526 return_clang_type = func_type->GetClangForwardType();
Greg Clayton24739922010-10-13 03:15:28 +00006527 else
Greg Clayton57ee3062013-07-11 22:46:58 +00006528 return_clang_type = ast.GetBasicType(eBasicTypeVoid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006529
Greg Claytonf51de672010-10-01 02:31:07 +00006530
Greg Clayton57ee3062013-07-11 22:46:58 +00006531 std::vector<ClangASTType> function_param_types;
Greg Clayton24739922010-10-13 03:15:28 +00006532 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006533
Greg Clayton24739922010-10-13 03:15:28 +00006534 // Parse the function children for the parameters
Sean Callanan763d72a2011-08-02 22:21:50 +00006535
Greg Claytoncb5860a2011-10-13 23:49:28 +00006536 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
6537 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00006538 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
6539
Greg Claytonf0705c82011-10-22 03:33:13 +00006540 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00006541 // Start off static. This will be set to false in ParseChildParameters(...)
6542 // if we find a "this" paramters as the first parameter
6543 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00006544 is_static = true;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006545 ClangASTContext::TemplateParameterInfos template_param_infos;
6546
Greg Clayton24739922010-10-13 03:15:28 +00006547 if (die->HasChildren())
6548 {
Greg Clayton0fffff52010-09-24 05:15:53 +00006549 bool skip_artificial = true;
Jim Ingham379397632012-10-27 02:54:13 +00006550 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00006551 containing_decl_ctx,
Jim Ingham379397632012-10-27 02:54:13 +00006552 dwarf_cu,
6553 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00006554 skip_artificial,
6555 is_static,
Jim Ingham379397632012-10-27 02:54:13 +00006556 type_list,
6557 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00006558 function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006559 type_quals,
6560 template_param_infos);
Greg Clayton24739922010-10-13 03:15:28 +00006561 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006562
Greg Clayton24739922010-10-13 03:15:28 +00006563 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006564 clang_type = ast.CreateFunctionType (return_clang_type,
Greg Clayton9cb25c42012-10-30 17:02:18 +00006565 function_param_types.data(),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006566 function_param_types.size(),
6567 is_variadic,
6568 type_quals);
6569
Sean Callanande9ce872013-05-09 23:13:13 +00006570 bool ignore_containing_context = false;
6571
Greg Clayton24739922010-10-13 03:15:28 +00006572 if (type_name_cstr)
6573 {
6574 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00006575 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006576 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00006577 ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true);
6578 if (objc_method.IsValid(true))
Greg Clayton0fffff52010-09-24 05:15:53 +00006579 {
Greg Clayton24739922010-10-13 03:15:28 +00006580 SymbolContext empty_sc;
Greg Clayton57ee3062013-07-11 22:46:58 +00006581 ClangASTType class_opaque_type;
Greg Clayton1b3815c2013-01-30 00:18:29 +00006582 ConstString class_name(objc_method.GetClassName());
Greg Clayton7c810422012-01-18 23:40:49 +00006583 if (class_name)
Greg Clayton0fffff52010-09-24 05:15:53 +00006584 {
Greg Clayton24739922010-10-13 03:15:28 +00006585 TypeList types;
Greg Clayton278a16b2012-01-19 00:52:59 +00006586 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
Greg Claytonc7f03b62012-01-12 04:33:28 +00006587
6588 if (complete_objc_class_type_sp)
Greg Clayton0fffff52010-09-24 05:15:53 +00006589 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006590 ClangASTType type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
6591 if (type_clang_forward_type.IsObjCObjectOrInterfaceType ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00006592 class_opaque_type = type_clang_forward_type;
Greg Clayton0fffff52010-09-24 05:15:53 +00006593 }
Greg Clayton24739922010-10-13 03:15:28 +00006594 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006595
Greg Clayton24739922010-10-13 03:15:28 +00006596 if (class_opaque_type)
6597 {
6598 // If accessibility isn't set to anything valid, assume public for
6599 // now...
6600 if (accessibility == eAccessNone)
6601 accessibility = eAccessPublic;
6602
Greg Clayton57ee3062013-07-11 22:46:58 +00006603 clang::ObjCMethodDecl *objc_method_decl = class_opaque_type.AddMethodToObjCObjectType (type_name_cstr,
6604 clang_type,
6605 accessibility,
6606 is_artificial);
Greg Clayton24739922010-10-13 03:15:28 +00006607 type_handled = objc_method_decl != NULL;
Sean Callanan464a5b52012-10-04 22:06:29 +00006608 if (type_handled)
6609 {
6610 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Claytond0029442013-03-27 01:48:02 +00006611 GetClangASTContext().SetMetadataAsUserID (objc_method_decl, MakeUserID(die->GetOffset()));
Sean Callanan464a5b52012-10-04 22:06:29 +00006612 }
Sean Callananc3a1d562013-02-06 23:21:59 +00006613 else
6614 {
Jason Molendac1a65832013-03-07 22:44:42 +00006615 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 +00006616 die->GetOffset(),
6617 tag,
6618 DW_TAG_value_to_name(tag));
6619 }
Greg Clayton24739922010-10-13 03:15:28 +00006620 }
6621 }
Greg Clayton5113dc82011-08-12 06:47:54 +00006622 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00006623 {
6624 // Look at the parent of this DIE and see if is is
6625 // a class or struct and see if this is actually a
6626 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00006627 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00006628 if (class_type)
6629 {
Greg Clayton4116e932012-05-15 02:33:01 +00006630 if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset()))
6631 {
6632 // We uniqued the parent class of this function to another class
6633 // so we now need to associate all dies under "decl_ctx_die" to
6634 // DIEs in the DIE for "class_type"...
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006635 SymbolFileDWARF *class_symfile = NULL;
Greg Clayton4116e932012-05-15 02:33:01 +00006636 DWARFCompileUnitSP class_type_cu_sp;
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006637 const DWARFDebugInfoEntry *class_type_die = NULL;
Sean Callanan2367f8a2013-02-26 01:12:25 +00006638
6639 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
6640 if (debug_map_symfile)
6641 {
6642 class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID()));
6643 class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6644 }
6645 else
6646 {
6647 class_symfile = this;
6648 class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6649 }
Greg Clayton4116e932012-05-15 02:33:01 +00006650 if (class_type_die)
6651 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006652 llvm::SmallVector<const DWARFDebugInfoEntry *, 0> failures;
6653
6654 CopyUniqueClassMethodTypes (class_symfile,
6655 class_type,
6656 class_type_cu_sp.get(),
6657 class_type_die,
6658 dwarf_cu,
6659 decl_ctx_die,
6660 failures);
6661
6662 // FIXME do something with these failures that's smarter than
6663 // just dropping them on the ground. Unfortunately classes don't
6664 // like having stuff added to them after their definitions are
6665 // complete...
6666
6667 type_ptr = m_die_to_type[die];
6668 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton4116e932012-05-15 02:33:01 +00006669 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006670 type_sp = type_ptr->shared_from_this();
6671 break;
Greg Clayton4116e932012-05-15 02:33:01 +00006672 }
6673 }
6674 }
6675
Greg Clayton72da3972011-08-16 18:40:23 +00006676 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00006677 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006678 // We have a specification which we are going to base our function
6679 // prototype off of, so we need this type to be completed so that the
6680 // m_die_to_decl_ctx for the method in the specification has a valid
6681 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006682 class_type->GetClangForwardType();
Greg Clayton72da3972011-08-16 18:40:23 +00006683 // If we have a specification, then the function type should have been
6684 // made with the specification and not with this die.
6685 DWARFCompileUnitSP spec_cu_sp;
6686 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006687 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006688 if (spec_clang_decl_ctx)
6689 {
6690 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
6691 }
6692 else
Jim Inghamc1663042011-09-29 22:12:35 +00006693 {
Daniel Malead01b2952012-11-29 21:49:15 +00006694 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8x) has no decl\n",
Greg Claytone38a5ed2012-01-05 03:57:59 +00006695 MakeUserID(die->GetOffset()),
6696 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006697 }
Greg Clayton72da3972011-08-16 18:40:23 +00006698 type_handled = true;
6699 }
6700 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
6701 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006702 // We have a specification which we are going to base our function
6703 // prototype off of, so we need this type to be completed so that the
6704 // m_die_to_decl_ctx for the method in the abstract origin has a valid
6705 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006706 class_type->GetClangForwardType();
Greg Clayton5cf58b92011-10-05 22:22:08 +00006707
Greg Clayton72da3972011-08-16 18:40:23 +00006708 DWARFCompileUnitSP abs_cu_sp;
6709 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006710 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006711 if (abs_clang_decl_ctx)
6712 {
6713 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
6714 }
6715 else
Jim Inghamc1663042011-09-29 22:12:35 +00006716 {
Daniel Malead01b2952012-11-29 21:49:15 +00006717 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 +00006718 MakeUserID(die->GetOffset()),
6719 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006720 }
Greg Clayton72da3972011-08-16 18:40:23 +00006721 type_handled = true;
6722 }
6723 else
6724 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006725 ClangASTType class_opaque_type = class_type->GetClangForwardType();
6726 if (class_opaque_type.IsCXXClassType ())
Greg Clayton931180e2011-01-27 06:44:37 +00006727 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006728 if (class_opaque_type.IsBeingDefined ())
Greg Clayton72da3972011-08-16 18:40:23 +00006729 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006730 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
6731 // in the DWARF for C++ methods... Default to public for now...
6732 if (accessibility == eAccessNone)
6733 accessibility = eAccessPublic;
6734
6735 if (!is_static && !die->HasChildren())
6736 {
6737 // We have a C++ member function with no children (this pointer!)
6738 // and clang will get mad if we try and make a function that isn't
6739 // well formed in the DWARF, so we will just skip it...
6740 type_handled = true;
6741 }
6742 else
6743 {
6744 clang::CXXMethodDecl *cxx_method_decl;
6745 // REMOVE THE CRASH DESCRIPTION BELOW
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00006746 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 +00006747 type_name_cstr,
6748 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00006749 MakeUserID(die->GetOffset()),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00006750 m_obj_file->GetFileSpec().GetPath().c_str());
Greg Clayton20568dd2011-10-13 23:13:20 +00006751
Sean Callananc1b732d2011-11-01 18:07:13 +00006752 const bool is_attr_used = false;
6753
Greg Clayton57ee3062013-07-11 22:46:58 +00006754 cxx_method_decl = class_opaque_type.AddMethodToCXXRecordType (type_name_cstr,
6755 clang_type,
6756 accessibility,
6757 is_virtual,
6758 is_static,
6759 is_inline,
6760 is_explicit,
6761 is_attr_used,
6762 is_artificial);
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006763
Greg Clayton20568dd2011-10-13 23:13:20 +00006764 type_handled = cxx_method_decl != NULL;
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006765
6766 if (type_handled)
Jim Ingham379397632012-10-27 02:54:13 +00006767 {
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006768 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
6769
6770 Host::SetCrashDescription (NULL);
6771
6772
6773 ClangASTMetadata metadata;
6774 metadata.SetUserID(MakeUserID(die->GetOffset()));
6775
6776 if (!object_pointer_name.empty())
6777 {
6778 metadata.SetObjectPtrName(object_pointer_name.c_str());
6779 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006780 log->Printf ("Setting object pointer name: %s on method object %p.\n",
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006781 object_pointer_name.c_str(),
Greg Claytond0029442013-03-27 01:48:02 +00006782 cxx_method_decl);
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006783 }
Greg Claytond0029442013-03-27 01:48:02 +00006784 GetClangASTContext().SetMetadata (cxx_method_decl, metadata);
Jim Ingham379397632012-10-27 02:54:13 +00006785 }
Sean Callananb0640dc2013-04-09 23:22:08 +00006786 else
6787 {
Sean Callanande9ce872013-05-09 23:13:13 +00006788 ignore_containing_context = true;
Sean Callananb0640dc2013-04-09 23:22:08 +00006789 }
Greg Clayton20568dd2011-10-13 23:13:20 +00006790 }
Greg Clayton72da3972011-08-16 18:40:23 +00006791 }
6792 else
6793 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006794 // We were asked to parse the type for a method in a class, yet the
6795 // class hasn't been asked to complete itself through the
6796 // clang::ExternalASTSource protocol, so we need to just have the
6797 // class complete itself and do things the right way, then our
6798 // DIE should then have an entry in the m_die_to_type map. First
6799 // we need to modify the m_die_to_type so it doesn't think we are
6800 // trying to parse this DIE anymore...
6801 m_die_to_type[die] = NULL;
6802
6803 // Now we get the full type to force our class type to complete itself
6804 // using the clang::ExternalASTSource protocol which will parse all
6805 // base classes and all methods (including the method for this DIE).
6806 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00006807
Greg Clayton20568dd2011-10-13 23:13:20 +00006808 // The type for this DIE should have been filled in the function call above
6809 type_ptr = m_die_to_type[die];
Greg Claytone5476db2012-06-01 20:32:35 +00006810 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton20568dd2011-10-13 23:13:20 +00006811 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006812 type_sp = type_ptr->shared_from_this();
Greg Clayton20568dd2011-10-13 23:13:20 +00006813 break;
6814 }
Sean Callanan02eee4d2012-04-12 23:10:00 +00006815
6816 // FIXME This is fixing some even uglier behavior but we really need to
6817 // uniq the methods of each class as well as the class itself.
6818 // <rdar://problem/11240464>
6819 type_handled = true;
Greg Clayton72da3972011-08-16 18:40:23 +00006820 }
Greg Clayton931180e2011-01-27 06:44:37 +00006821 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006822 }
6823 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006824 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006825 }
Greg Clayton24739922010-10-13 03:15:28 +00006826
6827 if (!type_handled)
6828 {
6829 // We just have a function that isn't part of a class
Sean Callanande9ce872013-05-09 23:13:13 +00006830 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (ignore_containing_context ? GetClangASTContext().GetTranslationUnitDecl() : containing_decl_ctx,
Greg Clayton147e1fa2011-10-14 22:47:18 +00006831 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006832 clang_type,
6833 storage,
6834 is_inline);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006835
6836// if (template_param_infos.GetSize() > 0)
6837// {
6838// clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
6839// function_decl,
6840// type_name_cstr,
6841// template_param_infos);
6842//
6843// ast.CreateFunctionTemplateSpecializationInfo (function_decl,
6844// func_template_decl,
6845// template_param_infos);
6846// }
Greg Clayton24739922010-10-13 03:15:28 +00006847 // Add the decl to our DIE to decl context map
6848 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00006849 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00006850 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006851 ast.SetFunctionParameters (function_decl,
6852 &function_param_decls.front(),
6853 function_param_decls.size());
Sean Callanan60217122012-04-13 00:10:03 +00006854
Jim Ingham379397632012-10-27 02:54:13 +00006855 ClangASTMetadata metadata;
6856 metadata.SetUserID(MakeUserID(die->GetOffset()));
6857
6858 if (!object_pointer_name.empty())
6859 {
6860 metadata.SetObjectPtrName(object_pointer_name.c_str());
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006861 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006862 log->Printf ("Setting object pointer name: %s on function object %p.",
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006863 object_pointer_name.c_str(),
Greg Claytond0029442013-03-27 01:48:02 +00006864 function_decl);
Jim Ingham379397632012-10-27 02:54:13 +00006865 }
Greg Claytond0029442013-03-27 01:48:02 +00006866 GetClangASTContext().SetMetadata (function_decl, metadata);
Greg Clayton24739922010-10-13 03:15:28 +00006867 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006868 }
Greg Clayton81c22f62011-10-19 18:09:39 +00006869 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006870 this,
6871 type_name_const_str,
6872 0,
6873 NULL,
6874 LLDB_INVALID_UID,
6875 Type::eEncodingIsUID,
6876 &decl,
6877 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006878 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00006879 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006880 }
6881 break;
6882
6883 case DW_TAG_array_type:
6884 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006885 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006886 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006887
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006888 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006889 int64_t first_index = 0;
6890 uint32_t byte_stride = 0;
6891 uint32_t bit_stride = 0;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006892 bool is_vector = false;
Greg Claytond88d7592010-09-15 08:33:30 +00006893 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006894
6895 if (num_attributes > 0)
6896 {
6897 uint32_t i;
6898 for (i=0; i<num_attributes; ++i)
6899 {
6900 attr = attributes.AttributeAtIndex(i);
6901 DWARFFormValue form_value;
6902 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6903 {
6904 switch (attr)
6905 {
6906 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6907 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6908 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6909 case DW_AT_name:
6910 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006911 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006912 break;
6913
6914 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006915 case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006916 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
6917 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006918 case DW_AT_GNU_vector: is_vector = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006919 case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006920 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006921 case DW_AT_allocated:
6922 case DW_AT_associated:
6923 case DW_AT_data_location:
6924 case DW_AT_description:
6925 case DW_AT_ordering:
6926 case DW_AT_start_scope:
6927 case DW_AT_visibility:
6928 case DW_AT_specification:
6929 case DW_AT_abstract_origin:
6930 case DW_AT_sibling:
6931 break;
6932 }
6933 }
6934 }
6935
Daniel Malead01b2952012-11-29 21:49:15 +00006936 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 +00006937
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006938 Type *element_type = ResolveTypeUID(type_die_offset);
6939
6940 if (element_type)
6941 {
6942 std::vector<uint64_t> element_orders;
6943 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
6944 if (byte_stride == 0 && bit_stride == 0)
6945 byte_stride = element_type->GetByteSize();
Greg Clayton57ee3062013-07-11 22:46:58 +00006946 ClangASTType array_element_type = element_type->GetClangForwardType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006947 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
6948 uint64_t num_elements = 0;
6949 std::vector<uint64_t>::const_reverse_iterator pos;
6950 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
6951 for (pos = element_orders.rbegin(); pos != end; ++pos)
6952 {
6953 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006954 clang_type = ast.CreateArrayType (array_element_type,
Greg Clayton1c8ef472013-04-05 23:27:21 +00006955 num_elements,
6956 is_vector);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006957 array_element_type = clang_type;
Greg Clayton4ef877f2012-12-06 02:33:54 +00006958 array_element_bit_stride = num_elements ? array_element_bit_stride * num_elements : array_element_bit_stride;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006959 }
6960 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00006961 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006962 this,
6963 empty_name,
6964 array_element_bit_stride / 8,
6965 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00006966 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006967 Type::eEncodingIsUID,
6968 &decl,
6969 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006970 Type::eResolveStateFull));
6971 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006972 }
6973 }
6974 }
6975 break;
6976
Greg Clayton9b81a312010-06-12 01:20:30 +00006977 case DW_TAG_ptr_to_member_type:
6978 {
6979 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
6980 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
6981
Greg Claytond88d7592010-09-15 08:33:30 +00006982 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00006983
6984 if (num_attributes > 0) {
6985 uint32_t i;
6986 for (i=0; i<num_attributes; ++i)
6987 {
6988 attr = attributes.AttributeAtIndex(i);
6989 DWARFFormValue form_value;
6990 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6991 {
6992 switch (attr)
6993 {
6994 case DW_AT_type:
6995 type_die_offset = form_value.Reference(dwarf_cu); break;
6996 case DW_AT_containing_type:
6997 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
6998 }
6999 }
7000 }
7001
7002 Type *pointee_type = ResolveTypeUID(type_die_offset);
7003 Type *class_type = ResolveTypeUID(containing_type_die_offset);
7004
Greg Clayton57ee3062013-07-11 22:46:58 +00007005 ClangASTType pointee_clang_type = pointee_type->GetClangForwardType();
7006 ClangASTType class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00007007
Greg Clayton57ee3062013-07-11 22:46:58 +00007008 clang_type = pointee_clang_type.CreateMemberPointerType(class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00007009
Greg Clayton57ee3062013-07-11 22:46:58 +00007010 byte_size = clang_type.GetByteSize();
Greg Clayton9b81a312010-06-12 01:20:30 +00007011
Greg Clayton81c22f62011-10-19 18:09:39 +00007012 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00007013 this,
7014 type_name_const_str,
7015 byte_size,
7016 NULL,
7017 LLDB_INVALID_UID,
7018 Type::eEncodingIsUID,
7019 NULL,
7020 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00007021 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00007022 }
7023
7024 break;
7025 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007026 default:
Greg Clayton84afacd2012-11-07 23:09:32 +00007027 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",
7028 die->GetOffset(),
7029 tag,
7030 DW_TAG_value_to_name(tag));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007031 break;
7032 }
7033
7034 if (type_sp.get())
7035 {
7036 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7037 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7038
7039 SymbolContextScope * symbol_context_scope = NULL;
7040 if (sc_parent_tag == DW_TAG_compile_unit)
7041 {
7042 symbol_context_scope = sc.comp_unit;
7043 }
7044 else if (sc.function != NULL)
7045 {
Greg Clayton81c22f62011-10-19 18:09:39 +00007046 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007047 if (symbol_context_scope == NULL)
7048 symbol_context_scope = sc.function;
7049 }
7050
7051 if (symbol_context_scope != NULL)
7052 {
7053 type_sp->SetSymbolContextScope(symbol_context_scope);
7054 }
7055
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00007056 // We are ready to put this type into the uniqued list up at the module level
7057 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00007058
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00007059 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007060 }
7061 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00007062 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007063 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00007064 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007065 }
7066 }
7067 return type_sp;
7068}
7069
7070size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00007071SymbolFileDWARF::ParseTypes
7072(
7073 const SymbolContext& sc,
7074 DWARFCompileUnit* dwarf_cu,
7075 const DWARFDebugInfoEntry *die,
7076 bool parse_siblings,
7077 bool parse_children
7078)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007079{
7080 size_t types_added = 0;
7081 while (die != NULL)
7082 {
7083 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00007084 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007085 {
7086 if (type_is_new)
7087 ++types_added;
7088 }
7089
7090 if (parse_children && die->HasChildren())
7091 {
7092 if (die->Tag() == DW_TAG_subprogram)
7093 {
7094 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00007095 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007096 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
7097 }
7098 else
7099 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
7100 }
7101
7102 if (parse_siblings)
7103 die = die->GetSibling();
7104 else
7105 die = NULL;
7106 }
7107 return types_added;
7108}
7109
7110
7111size_t
7112SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
7113{
7114 assert(sc.comp_unit && sc.function);
7115 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00007116 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007117 if (dwarf_cu)
7118 {
7119 dw_offset_t function_die_offset = sc.function->GetID();
7120 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
7121 if (function_die)
7122 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00007123 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007124 }
7125 }
7126
7127 return functions_added;
7128}
7129
7130
7131size_t
7132SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
7133{
7134 // At least a compile unit must be valid
7135 assert(sc.comp_unit);
7136 size_t types_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00007137 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007138 if (dwarf_cu)
7139 {
7140 if (sc.function)
7141 {
7142 dw_offset_t function_die_offset = sc.function->GetID();
7143 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
7144 if (func_die && func_die->HasChildren())
7145 {
7146 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
7147 }
7148 }
7149 else
7150 {
7151 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
7152 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
7153 {
7154 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
7155 }
7156 }
7157 }
7158
7159 return types_added;
7160}
7161
7162size_t
7163SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
7164{
7165 if (sc.comp_unit != NULL)
7166 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00007167 DWARFDebugInfo* info = DebugInfo();
7168 if (info == NULL)
7169 return 0;
7170
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007171 if (sc.function)
7172 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007173 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get();
7174
7175 if (dwarf_cu == NULL)
7176 return 0;
7177
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007178 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00007179
Greg Claytonc7bece562013-01-25 18:06:21 +00007180 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
7181 if (func_lo_pc != LLDB_INVALID_ADDRESS)
Greg Claytone38a5ed2012-01-05 03:57:59 +00007182 {
7183 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00007184
Greg Claytone38a5ed2012-01-05 03:57:59 +00007185 // Let all blocks know they have parse all their variables
7186 sc.function->GetBlock (false).SetDidParseVariables (true, true);
7187 return num_variables;
7188 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007189 }
7190 else if (sc.comp_unit)
7191 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007192 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get();
7193
7194 if (dwarf_cu == NULL)
7195 return 0;
7196
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007197 uint32_t vars_added = 0;
7198 VariableListSP variables (sc.comp_unit->GetVariableList(false));
7199
7200 if (variables.get() == NULL)
7201 {
7202 variables.reset(new VariableList());
7203 sc.comp_unit->SetVariableList(variables);
7204
Greg Claytond4a2b372011-09-12 23:21:58 +00007205 DWARFCompileUnit* match_dwarf_cu = NULL;
7206 const DWARFDebugInfoEntry* die = NULL;
7207 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00007208 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00007209 {
Greg Clayton97fbc342011-10-20 22:30:33 +00007210 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00007211 {
7212 DWARFMappedHash::DIEInfoArray hash_data_array;
7213 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
7214 dwarf_cu->GetNextCompileUnitOffset(),
7215 hash_data_array))
7216 {
7217 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
7218 }
7219 }
Greg Clayton7f995132011-10-04 22:41:51 +00007220 }
7221 else
7222 {
7223 // Index if we already haven't to make sure the compile units
7224 // get indexed and make their global DIE index list
7225 if (!m_indexed)
7226 Index ();
7227
7228 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
7229 dwarf_cu->GetNextCompileUnitOffset(),
7230 die_offsets);
7231 }
7232
7233 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00007234 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007235 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007236 DWARFDebugInfo* debug_info = DebugInfo();
7237 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007238 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007239 const dw_offset_t die_offset = die_offsets[i];
7240 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00007241 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00007242 {
Greg Clayton95d87902011-11-11 03:16:25 +00007243 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
7244 if (var_sp)
7245 {
7246 variables->AddVariableIfUnique (var_sp);
7247 ++vars_added;
7248 }
Greg Claytond4a2b372011-09-12 23:21:58 +00007249 }
Greg Clayton95d87902011-11-11 03:16:25 +00007250 else
7251 {
7252 if (m_using_apple_tables)
7253 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00007254 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 +00007255 }
7256 }
7257
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007258 }
7259 }
7260 }
7261 return vars_added;
7262 }
7263 }
7264 return 0;
7265}
7266
7267
7268VariableSP
7269SymbolFileDWARF::ParseVariableDIE
7270(
7271 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007272 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007273 const DWARFDebugInfoEntry *die,
7274 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007275)
7276{
7277
Greg Clayton83c5cd92010-11-14 22:13:40 +00007278 VariableSP var_sp (m_die_to_variable_sp[die]);
7279 if (var_sp)
7280 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007281
7282 const dw_tag_t tag = die->Tag();
Richard Mitton0a558352013-10-17 21:14:00 +00007283 ModuleSP module = GetObjectFile()->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00007284
7285 if ((tag == DW_TAG_variable) ||
7286 (tag == DW_TAG_constant) ||
7287 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007288 {
Greg Clayton7f995132011-10-04 22:41:51 +00007289 DWARFDebugInfoEntry::Attributes attributes;
7290 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
7291 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007292 {
Greg Clayton7f995132011-10-04 22:41:51 +00007293 const char *name = NULL;
7294 const char *mangled = NULL;
7295 Declaration decl;
7296 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00007297 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00007298 DWARFExpression location;
7299 bool is_external = false;
7300 bool is_artificial = false;
7301 bool location_is_const_value_data = false;
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007302 bool has_explicit_location = false;
Greg Clayton23f59502012-07-17 03:23:13 +00007303 //AccessType accessibility = eAccessNone;
Greg Clayton7f995132011-10-04 22:41:51 +00007304
7305 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007306 {
Greg Clayton7f995132011-10-04 22:41:51 +00007307 dw_attr_t attr = attributes.AttributeAtIndex(i);
7308 DWARFFormValue form_value;
7309 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007310 {
Greg Clayton7f995132011-10-04 22:41:51 +00007311 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007312 {
Greg Clayton7f995132011-10-04 22:41:51 +00007313 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
7314 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
7315 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
7316 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton71415542012-12-08 00:24:40 +00007317 case DW_AT_linkage_name:
Greg Clayton7f995132011-10-04 22:41:51 +00007318 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Claytond1767f02011-12-08 02:13:16 +00007319 case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00007320 case DW_AT_external: is_external = form_value.Boolean(); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007321 case DW_AT_const_value:
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007322 // If we have already found a DW_AT_location attribute, ignore this attribute.
7323 if (!has_explicit_location)
7324 {
7325 location_is_const_value_data = true;
7326 // The constant value will be either a block, a data value or a string.
Ed Masteeeae7212013-10-24 20:43:47 +00007327 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007328 if (DWARFFormValue::IsBlockForm(form_value.Form()))
7329 {
7330 // Retrieve the value as a block expression.
7331 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7332 uint32_t block_length = form_value.Unsigned();
Richard Mitton0a558352013-10-17 21:14:00 +00007333 location.CopyOpcodeData(module, debug_info_data, block_offset, block_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007334 }
7335 else if (DWARFFormValue::IsDataForm(form_value.Form()))
7336 {
7337 // Retrieve the value as a data expression.
7338 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
7339 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7340 uint32_t data_length = fixed_form_sizes[form_value.Form()];
Richard Mitton0a558352013-10-17 21:14:00 +00007341 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007342 }
7343 else
7344 {
7345 // Retrieve the value as a string expression.
7346 if (form_value.Form() == DW_FORM_strp)
7347 {
7348 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
7349 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7350 uint32_t data_length = fixed_form_sizes[form_value.Form()];
Richard Mitton0a558352013-10-17 21:14:00 +00007351 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007352 }
7353 else
7354 {
7355 const char *str = form_value.AsCString(&debug_info_data);
7356 uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart();
7357 uint32_t string_length = strlen(str) + 1;
Richard Mitton0a558352013-10-17 21:14:00 +00007358 location.CopyOpcodeData(module, debug_info_data, string_offset, string_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007359 }
7360 }
7361 }
7362 break;
Greg Clayton7f995132011-10-04 22:41:51 +00007363 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007364 {
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007365 location_is_const_value_data = false;
7366 has_explicit_location = true;
Greg Clayton7f995132011-10-04 22:41:51 +00007367 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007368 {
Ed Masteeeae7212013-10-24 20:43:47 +00007369 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Clayton7f995132011-10-04 22:41:51 +00007370
7371 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7372 uint32_t block_length = form_value.Unsigned();
Richard Mitton0a558352013-10-17 21:14:00 +00007373 location.CopyOpcodeData(module, get_debug_info_data(), block_offset, block_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007374 }
7375 else
7376 {
Ed Masteeeae7212013-10-24 20:43:47 +00007377 const DWARFDataExtractor& debug_loc_data = get_debug_loc_data();
Greg Clayton7f995132011-10-04 22:41:51 +00007378 const dw_offset_t debug_loc_offset = form_value.Unsigned();
7379
7380 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
7381 if (loc_list_length > 0)
7382 {
Richard Mitton0a558352013-10-17 21:14:00 +00007383 location.CopyOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007384 assert (func_low_pc != LLDB_INVALID_ADDRESS);
7385 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
7386 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007387 }
7388 }
Greg Clayton7f995132011-10-04 22:41:51 +00007389 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007390
Greg Clayton1c8ef472013-04-05 23:27:21 +00007391 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00007392 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007393 case DW_AT_declaration:
7394 case DW_AT_description:
7395 case DW_AT_endianity:
7396 case DW_AT_segment:
7397 case DW_AT_start_scope:
7398 case DW_AT_visibility:
7399 default:
7400 case DW_AT_abstract_origin:
7401 case DW_AT_sibling:
7402 case DW_AT_specification:
7403 break;
7404 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007405 }
7406 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007407
Greg Clayton9e9f2192013-05-17 00:55:28 +00007408 ValueType scope = eValueTypeInvalid;
7409
7410 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7411 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7412 SymbolContextScope * symbol_context_scope = NULL;
7413
7414 // DWARF doesn't specify if a DW_TAG_variable is a local, global
7415 // or static variable, so we have to do a little digging by
7416 // looking at the location of a varaible to see if it contains
7417 // a DW_OP_addr opcode _somewhere_ in the definition. I say
7418 // somewhere because clang likes to combine small global variables
7419 // into the same symbol and have locations like:
7420 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
7421 // So if we don't have a DW_TAG_formal_parameter, we can look at
7422 // the location to see if it contains a DW_OP_addr opcode, and
7423 // then we can correctly classify our variables.
7424 if (tag == DW_TAG_formal_parameter)
7425 scope = eValueTypeVariableArgument;
7426 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007427 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007428 bool op_error = false;
7429 // Check if the location has a DW_OP_addr with any address value...
7430 lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS;
7431 if (!location_is_const_value_data)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007432 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007433 location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error);
7434 if (op_error)
Greg Clayton96c09682012-01-04 22:56:43 +00007435 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007436 StreamString strm;
7437 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
7438 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 +00007439 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007440 }
Greg Claytond1767f02011-12-08 02:13:16 +00007441
Greg Clayton9e9f2192013-05-17 00:55:28 +00007442 if (location_DW_OP_addr != LLDB_INVALID_ADDRESS)
7443 {
7444 if (is_external)
7445 scope = eValueTypeVariableGlobal;
7446 else
7447 scope = eValueTypeVariableStatic;
7448
7449
7450 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile ();
7451
7452 if (debug_map_symfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007453 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007454 // When leaving the DWARF in the .o files on darwin,
7455 // when we have a global variable that wasn't initialized,
7456 // the .o file might not have allocated a virtual
7457 // address for the global variable. In this case it will
7458 // have created a symbol for the global variable
7459 // that is undefined/data and external and the value will
7460 // be the byte size of the variable. When we do the
7461 // address map in SymbolFileDWARFDebugMap we rely on
7462 // having an address, we need to do some magic here
7463 // so we can get the correct address for our global
7464 // variable. The address for all of these entries
7465 // will be zero, and there will be an undefined symbol
7466 // in this object file, and the executable will have
7467 // a matching symbol with a good address. So here we
7468 // dig up the correct address and replace it in the
7469 // location for the variable, and set the variable's
7470 // symbol context scope to be that of the main executable
7471 // so the file address will resolve correctly.
7472 bool linked_oso_file_addr = false;
7473 if (is_external && location_DW_OP_addr == 0)
Greg Clayton9422dd62013-03-04 21:46:16 +00007474 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007475 // we have a possible uninitialized extern global
7476 ConstString const_name(mangled ? mangled : name);
7477 ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile();
7478 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007479 {
Greg Clayton3046e662013-07-10 01:23:25 +00007480 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
Greg Clayton9e9f2192013-05-17 00:55:28 +00007481 if (debug_map_symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007482 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007483 Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
7484 eSymbolTypeData,
7485 Symtab::eDebugYes,
7486 Symtab::eVisibilityExtern);
7487 if (exe_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007488 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007489 if (exe_symbol->ValueIsAddress())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007490 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007491 const addr_t exe_file_addr = exe_symbol->GetAddress().GetFileAddress();
7492 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007493 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007494 if (location.Update_DW_OP_addr (exe_file_addr))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007495 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007496 linked_oso_file_addr = true;
7497 symbol_context_scope = exe_symbol;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007498 }
7499 }
7500 }
7501 }
7502 }
7503 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007504 }
Greg Clayton9422dd62013-03-04 21:46:16 +00007505
Greg Clayton9e9f2192013-05-17 00:55:28 +00007506 if (!linked_oso_file_addr)
7507 {
7508 // The DW_OP_addr is not zero, but it contains a .o file address which
7509 // needs to be linked up correctly.
7510 const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr);
7511 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton9422dd62013-03-04 21:46:16 +00007512 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007513 // Update the file address for this variable
7514 location.Update_DW_OP_addr (exe_file_addr);
7515 }
7516 else
7517 {
7518 // Variable didn't make it into the final executable
7519 return var_sp;
Greg Clayton9422dd62013-03-04 21:46:16 +00007520 }
Greg Claytond1767f02011-12-08 02:13:16 +00007521 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007522 }
Greg Clayton5cf58b92011-10-05 22:22:08 +00007523 }
7524 else
7525 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007526 scope = eValueTypeVariableLocal;
Greg Clayton5cf58b92011-10-05 22:22:08 +00007527 }
Greg Clayton7f995132011-10-04 22:41:51 +00007528 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007529
7530 if (symbol_context_scope == NULL)
7531 {
7532 switch (parent_tag)
7533 {
7534 case DW_TAG_subprogram:
7535 case DW_TAG_inlined_subroutine:
7536 case DW_TAG_lexical_block:
7537 if (sc.function)
7538 {
7539 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
7540 if (symbol_context_scope == NULL)
7541 symbol_context_scope = sc.function;
7542 }
7543 break;
7544
7545 default:
7546 symbol_context_scope = sc.comp_unit;
7547 break;
7548 }
7549 }
7550
7551 if (symbol_context_scope)
7552 {
7553 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
7554 name,
7555 mangled,
7556 SymbolFileTypeSP (new SymbolFileType(*this, type_uid)),
7557 scope,
7558 symbol_context_scope,
7559 &decl,
7560 location,
7561 is_external,
7562 is_artificial));
7563
7564 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
7565 }
7566 else
7567 {
7568 // Not ready to parse this variable yet. It might be a global
7569 // or static variable that is in a function scope and the function
7570 // in the symbol context wasn't filled in yet
7571 return var_sp;
7572 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007573 }
Greg Clayton7f995132011-10-04 22:41:51 +00007574 // Cache var_sp even if NULL (the variable was just a specification or
7575 // was missing vital information to be able to be displayed in the debugger
7576 // (missing location due to optimization, etc)) so we don't re-parse
7577 // this DIE over and over later...
7578 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007579 }
7580 return var_sp;
7581}
7582
Greg Claytonc662ec82011-06-17 22:10:16 +00007583
7584const DWARFDebugInfoEntry *
7585SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
7586 dw_offset_t spec_block_die_offset,
7587 DWARFCompileUnit **result_die_cu_handle)
7588{
7589 // Give the concrete function die specified by "func_die_offset", find the
7590 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7591 // to "spec_block_die_offset"
7592 DWARFDebugInfo* info = DebugInfo();
7593
7594 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
7595 if (die)
7596 {
7597 assert (*result_die_cu_handle);
7598 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
7599 }
7600 return NULL;
7601}
7602
7603
7604const DWARFDebugInfoEntry *
7605SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
7606 const DWARFDebugInfoEntry *die,
7607 dw_offset_t spec_block_die_offset,
7608 DWARFCompileUnit **result_die_cu_handle)
7609{
7610 if (die)
7611 {
7612 switch (die->Tag())
7613 {
7614 case DW_TAG_subprogram:
7615 case DW_TAG_inlined_subroutine:
7616 case DW_TAG_lexical_block:
7617 {
7618 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
7619 {
7620 *result_die_cu_handle = dwarf_cu;
7621 return die;
7622 }
7623
7624 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
7625 {
7626 *result_die_cu_handle = dwarf_cu;
7627 return die;
7628 }
7629 }
7630 break;
7631 }
7632
7633 // Give the concrete function die specified by "func_die_offset", find the
7634 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7635 // to "spec_block_die_offset"
7636 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
7637 {
7638 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
7639 child_die,
7640 spec_block_die_offset,
7641 result_die_cu_handle);
7642 if (result_die)
7643 return result_die;
7644 }
7645 }
7646
7647 *result_die_cu_handle = NULL;
7648 return NULL;
7649}
7650
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007651size_t
7652SymbolFileDWARF::ParseVariables
7653(
7654 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007655 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007656 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007657 const DWARFDebugInfoEntry *orig_die,
7658 bool parse_siblings,
7659 bool parse_children,
7660 VariableList* cc_variable_list
7661)
7662{
7663 if (orig_die == NULL)
7664 return 0;
7665
Greg Claytonc662ec82011-06-17 22:10:16 +00007666 VariableListSP variable_list_sp;
7667
7668 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007669 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00007670 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007671 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007672 dw_tag_t tag = die->Tag();
7673
7674 // Check to see if we have already parsed this variable or constant?
7675 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007676 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007677 if (cc_variable_list)
7678 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007679 }
7680 else
7681 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007682 // We haven't already parsed it, lets do that now.
7683 if ((tag == DW_TAG_variable) ||
7684 (tag == DW_TAG_constant) ||
7685 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007686 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007687 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00007688 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007689 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
7690 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7691 switch (parent_tag)
7692 {
7693 case DW_TAG_compile_unit:
7694 if (sc.comp_unit != NULL)
7695 {
7696 variable_list_sp = sc.comp_unit->GetVariableList(false);
7697 if (variable_list_sp.get() == NULL)
7698 {
7699 variable_list_sp.reset(new VariableList());
7700 sc.comp_unit->SetVariableList(variable_list_sp);
7701 }
7702 }
7703 else
7704 {
Daniel Malead01b2952012-11-29 21:49:15 +00007705 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 +00007706 MakeUserID(sc_parent_die->GetOffset()),
7707 DW_TAG_value_to_name (parent_tag),
7708 MakeUserID(orig_die->GetOffset()),
7709 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007710 }
7711 break;
7712
7713 case DW_TAG_subprogram:
7714 case DW_TAG_inlined_subroutine:
7715 case DW_TAG_lexical_block:
7716 if (sc.function != NULL)
7717 {
7718 // Check to see if we already have parsed the variables for the given scope
7719
Greg Clayton81c22f62011-10-19 18:09:39 +00007720 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007721 if (block == NULL)
7722 {
7723 // This must be a specification or abstract origin with
7724 // a concrete block couterpart in the current function. We need
7725 // to find the concrete block so we can correctly add the
7726 // variable to it
7727 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
7728 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
7729 sc_parent_die->GetOffset(),
7730 &concrete_block_die_cu);
7731 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00007732 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007733 }
7734
7735 if (block != NULL)
7736 {
7737 const bool can_create = false;
7738 variable_list_sp = block->GetBlockVariableList (can_create);
7739 if (variable_list_sp.get() == NULL)
7740 {
7741 variable_list_sp.reset(new VariableList());
7742 block->SetVariableList(variable_list_sp);
7743 }
7744 }
7745 }
7746 break;
7747
7748 default:
Daniel Malead01b2952012-11-29 21:49:15 +00007749 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 +00007750 MakeUserID(orig_die->GetOffset()),
7751 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007752 break;
7753 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00007754 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007755
7756 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007757 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00007758 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
7759 if (var_sp)
7760 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007761 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00007762 if (cc_variable_list)
7763 cc_variable_list->AddVariableIfUnique (var_sp);
7764 ++vars_added;
7765 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007766 }
7767 }
7768 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007769
7770 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
7771
7772 if (!skip_children && parse_children && die->HasChildren())
7773 {
7774 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
7775 }
7776
7777 if (parse_siblings)
7778 die = die->GetSibling();
7779 else
7780 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007781 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007782 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007783}
7784
7785//------------------------------------------------------------------
7786// PluginInterface protocol
7787//------------------------------------------------------------------
Greg Clayton57abc5d2013-05-10 21:47:16 +00007788ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007789SymbolFileDWARF::GetPluginName()
7790{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007791 return GetPluginNameStatic();
7792}
7793
7794uint32_t
7795SymbolFileDWARF::GetPluginVersion()
7796{
7797 return 1;
7798}
7799
7800void
Greg Clayton6beaaa62011-01-17 03:46:26 +00007801SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
7802{
7803 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
Greg Clayton57ee3062013-07-11 22:46:58 +00007804 ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
Greg Clayton6beaaa62011-01-17 03:46:26 +00007805 if (clang_type)
7806 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7807}
7808
7809void
7810SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
7811{
7812 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
Greg Clayton57ee3062013-07-11 22:46:58 +00007813 ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
Greg Clayton6beaaa62011-01-17 03:46:26 +00007814 if (clang_type)
7815 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7816}
7817
Greg Claytona2721472011-06-25 00:44:06 +00007818void
Sean Callanancc427fa2011-07-30 02:42:06 +00007819SymbolFileDWARF::DumpIndexes ()
7820{
7821 StreamFile s(stdout, false);
7822
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00007823 s.Printf ("DWARF index for (%s) '%s':",
Sean Callanancc427fa2011-07-30 02:42:06 +00007824 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00007825 GetObjectFile()->GetFileSpec().GetPath().c_str());
Sean Callanancc427fa2011-07-30 02:42:06 +00007826 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
7827 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
7828 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
7829 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
7830 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
7831 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
7832 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
7833 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
7834}
7835
7836void
7837SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
7838 const char *name,
7839 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00007840{
Sean Callanancc427fa2011-07-30 02:42:06 +00007841 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00007842
7843 if (iter == m_decl_ctx_to_die.end())
7844 return;
7845
Greg Claytoncb5860a2011-10-13 23:49:28 +00007846 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00007847 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007848 const DWARFDebugInfoEntry *context_die = *pos;
7849
7850 if (!results)
7851 return;
7852
7853 DWARFDebugInfo* info = DebugInfo();
7854
7855 DIEArray die_offsets;
7856
7857 DWARFCompileUnit* dwarf_cu = NULL;
7858 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton220a0072011-12-09 08:48:30 +00007859
7860 if (m_using_apple_tables)
7861 {
7862 if (m_apple_types_ap.get())
7863 m_apple_types_ap->FindByName (name, die_offsets);
7864 }
7865 else
7866 {
7867 if (!m_indexed)
7868 Index ();
7869
7870 m_type_index.Find (ConstString(name), die_offsets);
7871 }
7872
Greg Clayton220a0072011-12-09 08:48:30 +00007873 const size_t num_matches = die_offsets.size();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007874
7875 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00007876 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007877 for (size_t i = 0; i < num_matches; ++i)
7878 {
7879 const dw_offset_t die_offset = die_offsets[i];
7880 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00007881
Greg Claytoncb5860a2011-10-13 23:49:28 +00007882 if (die->GetParent() != context_die)
7883 continue;
7884
7885 Type *matching_type = ResolveType (dwarf_cu, die);
7886
Greg Clayton57ee3062013-07-11 22:46:58 +00007887 clang::QualType qual_type = matching_type->GetClangForwardType().GetQualType();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007888
7889 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
7890 {
7891 clang::TagDecl *tag_decl = tag_type->getDecl();
7892 results->push_back(tag_decl);
7893 }
7894 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
7895 {
7896 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
7897 results->push_back(typedef_decl);
7898 }
Greg Claytona2721472011-06-25 00:44:06 +00007899 }
7900 }
7901 }
7902}
7903
7904void
7905SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00007906 const clang::DeclContext *decl_context,
7907 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00007908 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
7909{
Greg Clayton85ae2e12011-10-18 23:36:41 +00007910
7911 switch (decl_context->getDeclKind())
7912 {
7913 case clang::Decl::Namespace:
7914 case clang::Decl::TranslationUnit:
7915 {
7916 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7917 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
7918 }
7919 break;
7920 default:
7921 break;
7922 }
Greg Claytona2721472011-06-25 00:44:06 +00007923}
Greg Claytoncaab74e2012-01-28 00:48:57 +00007924
7925bool
7926SymbolFileDWARF::LayoutRecordType (void *baton,
7927 const clang::RecordDecl *record_decl,
7928 uint64_t &size,
7929 uint64_t &alignment,
7930 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7931 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7932 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7933{
7934 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7935 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
7936}
7937
7938
7939bool
7940SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl,
7941 uint64_t &bit_size,
7942 uint64_t &alignment,
7943 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7944 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7945 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7946{
Greg Clayton5160ce52013-03-27 23:08:40 +00007947 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Claytoncaab74e2012-01-28 00:48:57 +00007948 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
7949 bool success = false;
7950 base_offsets.clear();
7951 vbase_offsets.clear();
7952 if (pos != m_record_decl_to_layout_map.end())
7953 {
7954 bit_size = pos->second.bit_size;
7955 alignment = pos->second.alignment;
7956 field_offsets.swap(pos->second.field_offsets);
Greg Clayton2508b9b2012-11-01 23:20:02 +00007957 base_offsets.swap (pos->second.base_offsets);
7958 vbase_offsets.swap (pos->second.vbase_offsets);
Greg Claytoncaab74e2012-01-28 00:48:57 +00007959 m_record_decl_to_layout_map.erase(pos);
7960 success = true;
7961 }
7962 else
7963 {
7964 bit_size = 0;
7965 alignment = 0;
7966 field_offsets.clear();
7967 }
7968
7969 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00007970 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00007971 "SymbolFileDWARF::LayoutRecordType (record_decl = %p, bit_size = %" PRIu64 ", alignment = %" PRIu64 ", field_offsets[%u],base_offsets[%u], vbase_offsets[%u]) success = %i",
Greg Claytoncaab74e2012-01-28 00:48:57 +00007972 record_decl,
7973 bit_size,
7974 alignment,
7975 (uint32_t)field_offsets.size(),
7976 (uint32_t)base_offsets.size(),
7977 (uint32_t)vbase_offsets.size(),
7978 success);
7979 return success;
7980}
7981
7982
Greg Clayton1f746072012-08-29 21:13:06 +00007983SymbolFileDWARFDebugMap *
7984SymbolFileDWARF::GetDebugMapSymfile ()
7985{
7986 if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired())
7987 {
7988 lldb::ModuleSP module_sp (m_debug_map_module_wp.lock());
7989 if (module_sp)
7990 {
7991 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
7992 if (sym_vendor)
7993 m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile();
7994 }
7995 }
7996 return m_debug_map_symfile;
7997}
7998
Greg Claytoncaab74e2012-01-28 00:48:57 +00007999