blob: 09b50531b8a9eed42eabea0f674437627a147eb6 [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
1647 bool IsValid ()
1648 {
1649 return (bit_size != LLDB_INVALID_ADDRESS) &&
1650 (bit_offset != LLDB_INVALID_ADDRESS);
1651 }
1652};
1653
Greg Claytonc4ffd662013-03-08 01:37:30 +00001654
1655bool
1656SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu,
1657 const DWARFDebugInfoEntry *parent_die)
1658{
1659 if (parent_die)
1660 {
1661 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1662 {
1663 dw_tag_t tag = die->Tag();
1664 bool check_virtuality = false;
1665 switch (tag)
1666 {
1667 case DW_TAG_inheritance:
1668 case DW_TAG_subprogram:
1669 check_virtuality = true;
1670 break;
1671 default:
1672 break;
1673 }
1674 if (check_virtuality)
1675 {
1676 if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0)
1677 return true;
1678 }
1679 }
1680 }
1681 return false;
1682}
1683
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001684size_t
1685SymbolFileDWARF::ParseChildMembers
1686(
1687 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001688 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001689 const DWARFDebugInfoEntry *parent_die,
Greg Clayton57ee3062013-07-11 22:46:58 +00001690 ClangASTType &class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001691 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001692 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1693 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001694 DWARFDIECollection& member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001695 DelayedPropertyList& delayed_properties,
Sean Callananc7fbf732010-08-06 00:32:49 +00001696 AccessType& default_accessibility,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001697 bool &is_a_class,
1698 LayoutInfo &layout_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001699)
1700{
1701 if (parent_die == NULL)
1702 return 0;
1703
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001704 size_t count = 0;
1705 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001706 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001707 uint32_t member_idx = 0;
Sean Callananfaa0bb32012-12-05 23:37:14 +00001708 BitfieldInfo last_field_info;
Richard Mitton0a558352013-10-17 21:14:00 +00001709 ModuleSP module = GetObjectFile()->GetModule();
Greg Claytond88d7592010-09-15 08:33:30 +00001710
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001711 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1712 {
1713 dw_tag_t tag = die->Tag();
1714
1715 switch (tag)
1716 {
1717 case DW_TAG_member:
Sean Callanan3d654b32012-09-24 22:25:51 +00001718 case DW_TAG_APPLE_property:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001719 {
1720 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001721 const size_t num_attributes = die->GetAttributes (this,
1722 dwarf_cu,
1723 fixed_form_sizes,
1724 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001725 if (num_attributes > 0)
1726 {
1727 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001728 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001729 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001730 const char *prop_name = NULL;
1731 const char *prop_getter_name = NULL;
1732 const char *prop_setter_name = NULL;
Greg Claytone528efd72013-02-26 23:45:18 +00001733 uint32_t prop_attributes = 0;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001734
1735
Greg Clayton24739922010-10-13 03:15:28 +00001736 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001737 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001738 AccessType accessibility = eAccessNone;
Greg Claytoncaab74e2012-01-28 00:48:57 +00001739 uint32_t member_byte_offset = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001740 size_t byte_size = 0;
1741 size_t bit_offset = 0;
1742 size_t bit_size = 0;
Greg Claytone528efd72013-02-26 23:45:18 +00001743 bool is_external = false; // On DW_TAG_members, this means the member is static
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001744 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001745 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001746 {
1747 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1748 DWARFFormValue form_value;
1749 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1750 {
1751 switch (attr)
1752 {
1753 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1754 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1755 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1756 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1757 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1758 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1759 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1760 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1761 case DW_AT_data_member_location:
Greg Claytoncaab74e2012-01-28 00:48:57 +00001762 if (form_value.BlockData())
1763 {
1764 Value initialValue(0);
1765 Value memberOffset(0);
Ed Masteeeae7212013-10-24 20:43:47 +00001766 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Claytoncaab74e2012-01-28 00:48:57 +00001767 uint32_t block_length = form_value.Unsigned();
1768 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1769 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
Greg Claytoncaab74e2012-01-28 00:48:57 +00001770 NULL, // ClangExpressionVariableList *
1771 NULL, // ClangExpressionDeclMap *
1772 NULL, // RegisterContext *
Richard Mitton0a558352013-10-17 21:14:00 +00001773 module,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001774 debug_info_data,
1775 block_offset,
1776 block_length,
1777 eRegisterKindDWARF,
1778 &initialValue,
1779 memberOffset,
1780 NULL))
1781 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001782 member_byte_offset = memberOffset.ResolveValue(NULL).UInt();
Greg Claytoncaab74e2012-01-28 00:48:57 +00001783 }
1784 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00001785 else
1786 {
1787 // With DWARF 3 and later, if the value is an integer constant,
1788 // this form value is the offset in bytes from the beginning
1789 // of the containing entity.
1790 member_byte_offset = form_value.Unsigned();
1791 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001792 break;
1793
Greg Clayton8cf05932010-07-22 18:30:50 +00001794 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00001795 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001796 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1797 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1798 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1799 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00001800 case DW_AT_external: is_external = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001801
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001802 default:
Greg Clayton1b02c172012-03-14 21:00:47 +00001803 case DW_AT_declaration:
1804 case DW_AT_description:
1805 case DW_AT_mutable:
1806 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001807 case DW_AT_sibling:
1808 break;
1809 }
1810 }
1811 }
Sean Callanana6582262012-04-05 00:12:52 +00001812
1813 if (prop_name)
Sean Callanan751aac62012-03-29 19:07:06 +00001814 {
Sean Callanana6582262012-04-05 00:12:52 +00001815 ConstString fixed_getter;
1816 ConstString fixed_setter;
1817
1818 // Check if the property getter/setter were provided as full
1819 // names. We want basenames, so we extract them.
1820
1821 if (prop_getter_name && prop_getter_name[0] == '-')
1822 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001823 ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true);
1824 prop_getter_name = prop_getter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001825 }
1826
1827 if (prop_setter_name && prop_setter_name[0] == '-')
1828 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001829 ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true);
1830 prop_setter_name = prop_setter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001831 }
1832
1833 // If the names haven't been provided, they need to be
1834 // filled in.
1835
1836 if (!prop_getter_name)
1837 {
1838 prop_getter_name = prop_name;
1839 }
1840 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly))
1841 {
1842 StreamString ss;
1843
1844 ss.Printf("set%c%s:",
1845 toupper(prop_name[0]),
1846 &prop_name[1]);
1847
1848 fixed_setter.SetCString(ss.GetData());
1849 prop_setter_name = fixed_setter.GetCString();
1850 }
Sean Callanan751aac62012-03-29 19:07:06 +00001851 }
1852
1853 // Clang has a DWARF generation bug where sometimes it
Greg Clayton44953932011-10-25 01:25:35 +00001854 // represents fields that are references with bad byte size
1855 // and bit size/offset information such as:
1856 //
1857 // DW_AT_byte_size( 0x00 )
1858 // DW_AT_bit_size( 0x40 )
1859 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1860 //
1861 // So check the bit offset to make sure it is sane, and if
1862 // the values are not sane, remove them. If we don't do this
1863 // then we will end up with a crash if we try to use this
1864 // type in an expression when clang becomes unhappy with its
1865 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001866
Greg Clayton44953932011-10-25 01:25:35 +00001867 if (bit_offset > 128)
1868 {
1869 bit_size = 0;
1870 bit_offset = 0;
1871 }
1872
1873 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00001874 if (class_language == eLanguageTypeObjC ||
1875 class_language == eLanguageTypeObjC_plus_plus)
1876 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001877
1878 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1879 {
1880 // Not all compilers will mark the vtable pointer
1881 // member as artificial (llvm-gcc). We can't have
1882 // the virtual members in our classes otherwise it
1883 // throws off all child offsets since we end up
1884 // having and extra pointer sized member in our
1885 // class layouts.
1886 is_artificial = true;
1887 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001888
Greg Clayton29659712013-07-12 20:08:35 +00001889 // Handle static members
Greg Claytone528efd72013-02-26 23:45:18 +00001890 if (is_external && member_byte_offset == UINT32_MAX)
Greg Clayton973b6c92013-04-11 16:57:51 +00001891 {
1892 Type *var_type = ResolveTypeUID(encoding_uid);
1893
1894 if (var_type)
1895 {
Greg Clayton29659712013-07-12 20:08:35 +00001896 if (accessibility == eAccessNone)
1897 accessibility = eAccessPublic;
Greg Clayton57ee3062013-07-11 22:46:58 +00001898 class_clang_type.AddVariableToRecordType (name,
1899 var_type->GetClangLayoutType(),
1900 accessibility);
Greg Clayton973b6c92013-04-11 16:57:51 +00001901 }
Greg Claytone528efd72013-02-26 23:45:18 +00001902 break;
Greg Clayton973b6c92013-04-11 16:57:51 +00001903 }
Greg Claytone528efd72013-02-26 23:45:18 +00001904
Greg Clayton24739922010-10-13 03:15:28 +00001905 if (is_artificial == false)
1906 {
1907 Type *member_type = ResolveTypeUID(encoding_uid);
Sean Callananfa3ab452012-12-14 00:54:13 +00001908
Jim Inghame3ae82a2011-11-12 01:36:43 +00001909 clang::FieldDecl *field_decl = NULL;
Sean Callanan751aac62012-03-29 19:07:06 +00001910 if (tag == DW_TAG_member)
Greg Claytond16e1e52011-07-12 17:06:17 +00001911 {
Sean Callanan751aac62012-03-29 19:07:06 +00001912 if (member_type)
1913 {
1914 if (accessibility == eAccessNone)
1915 accessibility = default_accessibility;
1916 member_accessibilities.push_back(accessibility);
Sean Callananfaa0bb32012-12-05 23:37:14 +00001917
1918 BitfieldInfo this_field_info;
1919
1920 this_field_info.bit_size = bit_size;
1921
1922 if (member_byte_offset != UINT32_MAX || bit_size != 0)
Greg Clayton88bc7f32012-11-06 00:20:41 +00001923 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001924 /////////////////////////////////////////////////////////////
1925 // How to locate a field given the DWARF debug information
1926 //
1927 // AT_byte_size indicates the size of the word in which the
1928 // bit offset must be interpreted.
1929 //
1930 // AT_data_member_location indicates the byte offset of the
1931 // word from the base address of the structure.
1932 //
1933 // AT_bit_offset indicates how many bits into the word
1934 // (according to the host endianness) the low-order bit of
1935 // the field starts. AT_bit_offset can be negative.
1936 //
1937 // AT_bit_size indicates the size of the field in bits.
1938 /////////////////////////////////////////////////////////////
1939
1940 this_field_info.bit_offset = 0;
1941
1942 this_field_info.bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
1943
1944 if (GetObjectFile()->GetByteOrder() == eByteOrderLittle)
1945 {
1946 this_field_info.bit_offset += byte_size * 8;
1947 this_field_info.bit_offset -= (bit_offset + bit_size);
1948 }
1949 else
1950 {
1951 this_field_info.bit_offset += bit_offset;
1952 }
1953 }
1954
1955 // If the member to be emitted did not start on a character boundary and there is
1956 // empty space between the last field and this one, then we need to emit an
1957 // anonymous member filling up the space up to its start. There are three cases
1958 // here:
1959 //
1960 // 1 If the previous member ended on a character boundary, then we can emit an
1961 // anonymous member starting at the most recent character boundary.
1962 //
1963 // 2 If the previous member did not end on a character boundary and the distance
1964 // from the end of the previous member to the current member is less than a
1965 // word width, then we can emit an anonymous member starting right after the
1966 // previous member and right before this member.
1967 //
1968 // 3 If the previous member did not end on a character boundary and the distance
1969 // from the end of the previous member to the current member is greater than
1970 // or equal a word width, then we act as in Case 1.
1971
1972 const uint64_t character_width = 8;
1973 const uint64_t word_width = 32;
1974
1975 if (this_field_info.IsValid())
1976 {
1977 // Objective-C has invalid DW_AT_bit_offset values in older versions
1978 // of clang, so we have to be careful and only insert unnammed bitfields
Greg Clayton37c36e42012-11-27 00:59:26 +00001979 // if we have a new enough clang.
1980 bool detect_unnamed_bitfields = true;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001981
Greg Clayton37c36e42012-11-27 00:59:26 +00001982 if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus)
1983 detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields ();
1984
1985 if (detect_unnamed_bitfields)
Greg Clayton88bc7f32012-11-06 00:20:41 +00001986 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001987 BitfieldInfo anon_field_info;
1988
1989 if ((this_field_info.bit_offset % character_width) != 0) // not char aligned
Greg Clayton88bc7f32012-11-06 00:20:41 +00001990 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001991 uint64_t last_field_end = 0;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001992
Sean Callananfaa0bb32012-12-05 23:37:14 +00001993 if (last_field_info.IsValid())
1994 last_field_end = last_field_info.bit_offset + last_field_info.bit_size;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001995
Sean Callananfaa0bb32012-12-05 23:37:14 +00001996 if (this_field_info.bit_offset != last_field_end)
1997 {
1998 if (((last_field_end % character_width) == 0) || // case 1
1999 (this_field_info.bit_offset - last_field_end >= word_width)) // case 3
2000 {
2001 anon_field_info.bit_size = this_field_info.bit_offset % character_width;
2002 anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size;
2003 }
2004 else // case 2
2005 {
2006 anon_field_info.bit_size = this_field_info.bit_offset - last_field_end;
2007 anon_field_info.bit_offset = last_field_end;
2008 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00002009 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00002010 }
2011
Sean Callananfaa0bb32012-12-05 23:37:14 +00002012 if (anon_field_info.IsValid())
Greg Clayton88bc7f32012-11-06 00:20:41 +00002013 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002014 clang::FieldDecl *unnamed_bitfield_decl = class_clang_type.AddFieldToRecordType (NULL,
2015 GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width),
2016 accessibility,
2017 anon_field_info.bit_size);
Greg Clayton88bc7f32012-11-06 00:20:41 +00002018
Sean Callananfaa0bb32012-12-05 23:37:14 +00002019 layout_info.field_offsets.insert(std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset));
Greg Clayton88bc7f32012-11-06 00:20:41 +00002020 }
2021 }
2022 }
Sean Callananfaa0bb32012-12-05 23:37:14 +00002023
Greg Clayton57ee3062013-07-11 22:46:58 +00002024 ClangASTType member_clang_type = member_type->GetClangLayoutType();
Sean Callananfa3ab452012-12-14 00:54:13 +00002025
2026 {
2027 // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>).
2028 // If the current field is at the end of the structure, then there is definitely no room for extra
2029 // elements and we override the type to array[0].
2030
Greg Clayton57ee3062013-07-11 22:46:58 +00002031 ClangASTType member_array_element_type;
Sean Callananfa3ab452012-12-14 00:54:13 +00002032 uint64_t member_array_size;
2033 bool member_array_is_incomplete;
2034
Greg Clayton57ee3062013-07-11 22:46:58 +00002035 if (member_clang_type.IsArrayType(&member_array_element_type,
2036 &member_array_size,
2037 &member_array_is_incomplete) &&
Sean Callananfa3ab452012-12-14 00:54:13 +00002038 !member_array_is_incomplete)
2039 {
2040 uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX);
2041
2042 if (member_byte_offset >= parent_byte_size)
2043 {
2044 if (member_array_size != 1)
2045 {
2046 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,
2047 MakeUserID(die->GetOffset()),
2048 name,
2049 encoding_uid,
2050 MakeUserID(parent_die->GetOffset()));
2051 }
2052
Greg Clayton1c8ef472013-04-05 23:27:21 +00002053 member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0, false);
Sean Callananfa3ab452012-12-14 00:54:13 +00002054 }
2055 }
2056 }
2057
Greg Clayton57ee3062013-07-11 22:46:58 +00002058 field_decl = class_clang_type.AddFieldToRecordType (name,
2059 member_clang_type,
2060 accessibility,
2061 bit_size);
Sean Callanan60217122012-04-13 00:10:03 +00002062
Greg Claytond0029442013-03-27 01:48:02 +00002063 GetClangASTContext().SetMetadataAsUserID (field_decl, MakeUserID(die->GetOffset()));
Sean Callananfaa0bb32012-12-05 23:37:14 +00002064
2065 if (this_field_info.IsValid())
2066 {
2067 layout_info.field_offsets.insert(std::make_pair(field_decl, this_field_info.bit_offset));
2068 last_field_info = this_field_info;
2069 }
Sean Callanan5b26f272012-02-04 08:49:35 +00002070 }
2071 else
2072 {
Sean Callanan751aac62012-03-29 19:07:06 +00002073 if (name)
Daniel Malead01b2952012-11-29 21:49:15 +00002074 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 +00002075 MakeUserID(die->GetOffset()),
2076 name,
2077 encoding_uid);
2078 else
Daniel Malead01b2952012-11-29 21:49:15 +00002079 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 +00002080 MakeUserID(die->GetOffset()),
2081 encoding_uid);
Sean Callanan5b26f272012-02-04 08:49:35 +00002082 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002083 }
Sean Callanan751aac62012-03-29 19:07:06 +00002084
Jim Inghame3ae82a2011-11-12 01:36:43 +00002085 if (prop_name != NULL)
2086 {
Sean Callanan751aac62012-03-29 19:07:06 +00002087 clang::ObjCIvarDecl *ivar_decl = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00002088
Sean Callanan751aac62012-03-29 19:07:06 +00002089 if (field_decl)
2090 {
2091 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
2092 assert (ivar_decl != NULL);
2093 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00002094
Jim Ingham379397632012-10-27 02:54:13 +00002095 ClangASTMetadata metadata;
2096 metadata.SetUserID (MakeUserID(die->GetOffset()));
Greg Clayton57ee3062013-07-11 22:46:58 +00002097 delayed_properties.push_back(DelayedAddObjCClassProperty(class_clang_type,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002098 prop_name,
2099 member_type->GetClangLayoutType(),
2100 ivar_decl,
2101 prop_setter_name,
2102 prop_getter_name,
2103 prop_attributes,
Jim Ingham379397632012-10-27 02:54:13 +00002104 &metadata));
Sean Callanan60217122012-04-13 00:10:03 +00002105
Sean Callananad880762012-04-18 01:06:17 +00002106 if (ivar_decl)
Greg Claytond0029442013-03-27 01:48:02 +00002107 GetClangASTContext().SetMetadataAsUserID (ivar_decl, MakeUserID(die->GetOffset()));
Jim Inghame3ae82a2011-11-12 01:36:43 +00002108 }
Greg Clayton24739922010-10-13 03:15:28 +00002109 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002110 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00002111 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002112 }
2113 break;
2114
2115 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00002116 // Let the type parsing code handle this one for us.
2117 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002118 break;
2119
2120 case DW_TAG_inheritance:
2121 {
2122 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00002123 if (default_accessibility == eAccessNone)
2124 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002125 // TODO: implement DW_TAG_inheritance type parsing
2126 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00002127 const size_t num_attributes = die->GetAttributes (this,
2128 dwarf_cu,
2129 fixed_form_sizes,
2130 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002131 if (num_attributes > 0)
2132 {
2133 Declaration decl;
2134 DWARFExpression location;
2135 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00002136 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002137 bool is_virtual = false;
2138 bool is_base_of_class = true;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002139 off_t member_byte_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002140 uint32_t i;
2141 for (i=0; i<num_attributes; ++i)
2142 {
2143 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2144 DWARFFormValue form_value;
2145 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2146 {
2147 switch (attr)
2148 {
2149 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2150 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2151 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2152 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002153 case DW_AT_data_member_location:
2154 if (form_value.BlockData())
2155 {
2156 Value initialValue(0);
2157 Value memberOffset(0);
Ed Masteeeae7212013-10-24 20:43:47 +00002158 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002159 uint32_t block_length = form_value.Unsigned();
2160 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
2161 if (DWARFExpression::Evaluate (NULL,
2162 NULL,
2163 NULL,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002164 NULL,
Richard Mitton0a558352013-10-17 21:14:00 +00002165 module,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002166 debug_info_data,
2167 block_offset,
2168 block_length,
2169 eRegisterKindDWARF,
2170 &initialValue,
2171 memberOffset,
2172 NULL))
2173 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002174 member_byte_offset = memberOffset.ResolveValue(NULL).UInt();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002175 }
2176 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002177 else
2178 {
2179 // With DWARF 3 and later, if the value is an integer constant,
2180 // this form value is the offset in bytes from the beginning
2181 // of the containing entity.
2182 member_byte_offset = form_value.Unsigned();
2183 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002184 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002185
2186 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00002187 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002188 break;
2189
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002190 case DW_AT_virtuality:
2191 is_virtual = form_value.Boolean();
2192 break;
2193
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002194 case DW_AT_sibling:
2195 break;
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002196
2197 default:
2198 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002199 }
2200 }
2201 }
2202
Greg Clayton526e5af2010-11-13 03:52:47 +00002203 Type *base_class_type = ResolveTypeUID(encoding_uid);
2204 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002205
Greg Clayton57ee3062013-07-11 22:46:58 +00002206 ClangASTType base_class_clang_type = base_class_type->GetClangFullType();
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002207 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002208 if (class_language == eLanguageTypeObjC)
2209 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002210 class_clang_type.SetObjCSuperClass(base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002211 }
2212 else
2213 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002214 base_classes.push_back (base_class_clang_type.CreateBaseClassSpecifier (accessibility,
Greg Claytonba2d22d2010-11-13 22:57:37 +00002215 is_virtual,
2216 is_base_of_class));
Greg Clayton2508b9b2012-11-01 23:20:02 +00002217
2218 if (is_virtual)
2219 {
Greg Clayton52694e32013-09-16 21:57:07 +00002220 // Do not specify any offset for virtual inheritance. The DWARF produced by clang doesn't
2221 // give us a constant offset, but gives us a DWARF expressions that requires an actual object
2222 // in memory. the DW_AT_data_member_location for a virtual base class looks like:
2223 // DW_AT_data_member_location( DW_OP_dup, DW_OP_deref, DW_OP_constu(0x00000018), DW_OP_minus, DW_OP_deref, DW_OP_plus )
2224 // Given this, there is really no valid response we can give to clang for virtual base
2225 // class offsets, and this should eventually be removed from LayoutRecordType() in the external
2226 // AST source in clang.
Greg Clayton2508b9b2012-11-01 23:20:02 +00002227 }
2228 else
2229 {
Greg Clayton57648732013-09-12 17:22:32 +00002230 layout_info.base_offsets.insert(std::make_pair(base_class_clang_type.GetAsCXXRecordDecl(),
Greg Clayton2508b9b2012-11-01 23:20:02 +00002231 clang::CharUnits::fromQuantity(member_byte_offset)));
2232 }
Greg Clayton9e409562010-07-28 02:04:09 +00002233 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002234 }
2235 }
2236 break;
2237
2238 default:
2239 break;
2240 }
2241 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002242
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002243 return count;
2244}
2245
2246
2247clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00002248SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002249{
2250 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00002251 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002252 {
2253 DWARFCompileUnitSP cu_sp;
2254 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
2255 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00002256 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00002257 }
2258 return NULL;
2259}
2260
2261clang::DeclContext*
2262SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
2263{
Greg Clayton81c22f62011-10-19 18:09:39 +00002264 if (UserIDMatches(type_uid))
2265 return GetClangDeclContextForDIEOffset (sc, type_uid);
2266 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002267}
2268
2269Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00002270SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002271{
Greg Clayton81c22f62011-10-19 18:09:39 +00002272 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002273 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002274 DWARFDebugInfo* debug_info = DebugInfo();
2275 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00002276 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002277 DWARFCompileUnitSP cu_sp;
2278 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00002279 const bool assert_not_being_parsed = true;
2280 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00002281 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002282 }
2283 return NULL;
2284}
2285
Greg Claytoncab36a32011-12-08 05:16:30 +00002286Type*
2287SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00002288{
Greg Claytoncab36a32011-12-08 05:16:30 +00002289 if (die != NULL)
2290 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002291 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00002292 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002293 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002294 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
2295 die->GetOffset(),
2296 DW_TAG_value_to_name(die->Tag()),
2297 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00002298
Greg Claytoncab36a32011-12-08 05:16:30 +00002299 // We might be coming in in the middle of a type tree (a class
2300 // withing a class, an enum within a class), so parse any needed
2301 // parent DIEs before we get to this one...
2302 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2303 switch (decl_ctx_die->Tag())
2304 {
2305 case DW_TAG_structure_type:
2306 case DW_TAG_union_type:
2307 case DW_TAG_class_type:
2308 {
2309 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00002310 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002311 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002312 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
2313 die->GetOffset(),
2314 DW_TAG_value_to_name(die->Tag()),
2315 die->GetName(this, cu),
2316 decl_ctx_die->GetOffset());
Greg Clayton219cf312012-03-30 00:51:13 +00002317//
2318// Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
2319// if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
2320// {
2321// if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002322// GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton219cf312012-03-30 00:51:13 +00002323// "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
2324// die->GetOffset(),
2325// DW_TAG_value_to_name(die->Tag()),
2326// die->GetName(this, cu),
2327// decl_ctx_die->GetOffset());
2328// // Ask the type to complete itself if it already hasn't since if we
2329// // want a function (method or static) from a class, the class must
2330// // create itself and add it's own methods and class functions.
2331// if (parent_type)
2332// parent_type->GetClangFullType();
2333// }
Greg Claytoncab36a32011-12-08 05:16:30 +00002334 }
2335 break;
2336
2337 default:
2338 break;
2339 }
2340 return ResolveType (cu, die);
2341 }
2342 return NULL;
2343}
2344
Greg Clayton6beaaa62011-01-17 03:46:26 +00002345// This function is used when SymbolFileDWARFDebugMap owns a bunch of
2346// SymbolFileDWARF objects to detect if this DWARF file is the one that
2347// can resolve a clang_type.
2348bool
Greg Clayton57ee3062013-07-11 22:46:58 +00002349SymbolFileDWARF::HasForwardDeclForClangType (const ClangASTType &clang_type)
Greg Clayton6beaaa62011-01-17 03:46:26 +00002350{
Greg Clayton57ee3062013-07-11 22:46:58 +00002351 ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers();
2352 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton6beaaa62011-01-17 03:46:26 +00002353 return die != NULL;
2354}
2355
2356
Greg Clayton57ee3062013-07-11 22:46:58 +00002357bool
2358SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (ClangASTType &clang_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00002359{
2360 // We have a struct/union/class/enum that needs to be fully resolved.
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 Clayton1be10fc2010-09-29 01:12:09 +00002363 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00002364 {
2365 // We have already resolved this type...
Greg Clayton57ee3062013-07-11 22:46:58 +00002366 return true;
Greg Clayton73b472d2010-10-27 03:32:59 +00002367 }
2368 // Once we start resolving this type, remove it from the forward declaration
2369 // map in case anyone child members or other types require this type to get resolved.
2370 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
2371 // are done.
Greg Clayton57ee3062013-07-11 22:46:58 +00002372 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton73b472d2010-10-27 03:32:59 +00002373
Greg Clayton1be10fc2010-09-29 01:12:09 +00002374
Greg Clayton85ae2e12011-10-18 23:36:41 +00002375 // Disable external storage for this type so we don't get anymore
2376 // clang::ExternalASTSource queries for this type.
Greg Clayton57ee3062013-07-11 22:46:58 +00002377 clang_type.SetHasExternalStorage (false);
Greg Clayton85ae2e12011-10-18 23:36:41 +00002378
Greg Clayton450e3f32010-10-12 02:24:53 +00002379 DWARFDebugInfo* debug_info = DebugInfo();
2380
Greg Clayton53eb1c22012-04-02 22:59:12 +00002381 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002382 Type *type = m_die_to_type.lookup (die);
2383
2384 const dw_tag_t tag = die->Tag();
2385
Greg Clayton5160ce52013-03-27 23:08:40 +00002386 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
Greg Clayton3bffb082011-12-10 02:15:28 +00002387 if (log)
Greg Claytonbaf95da2012-03-30 23:50:54 +00002388 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002389 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002390 "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...",
Greg Claytond61c0fc2012-04-23 22:55:20 +00002391 MakeUserID(die->GetOffset()),
2392 DW_TAG_value_to_name(tag),
2393 type->GetName().AsCString());
Greg Claytonbaf95da2012-03-30 23:50:54 +00002394
Greg Claytonbaf95da2012-03-30 23:50:54 +00002395 }
Greg Clayton1be10fc2010-09-29 01:12:09 +00002396 assert (clang_type);
2397 DWARFDebugInfoEntry::Attributes attributes;
2398
Greg Clayton1be10fc2010-09-29 01:12:09 +00002399 switch (tag)
2400 {
2401 case DW_TAG_structure_type:
2402 case DW_TAG_union_type:
2403 case DW_TAG_class_type:
Greg Claytonc93237c2010-10-01 20:48:32 +00002404 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002405 LayoutInfo layout_info;
Sean Callanan77a1fd32012-02-27 20:07:01 +00002406
Greg Clayton1be10fc2010-09-29 01:12:09 +00002407 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002408 if (die->HasChildren())
Greg Claytonc93237c2010-10-01 20:48:32 +00002409 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002410
Sean Callanan77a1fd32012-02-27 20:07:01 +00002411 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton57ee3062013-07-11 22:46:58 +00002412 if (clang_type.IsObjCObjectOrInterfaceType())
Greg Clayton219cf312012-03-30 00:51:13 +00002413 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002414 class_language = eLanguageTypeObjC;
Greg Clayton219cf312012-03-30 00:51:13 +00002415 // For objective C we don't start the definition when
2416 // the class is created.
Greg Clayton57ee3062013-07-11 22:46:58 +00002417 clang_type.StartTagDeclarationDefinition ();
Greg Clayton219cf312012-03-30 00:51:13 +00002418 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002419
2420 int tag_decl_kind = -1;
2421 AccessType default_accessibility = eAccessNone;
2422 if (tag == DW_TAG_structure_type)
2423 {
2424 tag_decl_kind = clang::TTK_Struct;
2425 default_accessibility = eAccessPublic;
2426 }
2427 else if (tag == DW_TAG_union_type)
2428 {
2429 tag_decl_kind = clang::TTK_Union;
2430 default_accessibility = eAccessPublic;
2431 }
2432 else if (tag == DW_TAG_class_type)
2433 {
2434 tag_decl_kind = clang::TTK_Class;
2435 default_accessibility = eAccessPrivate;
2436 }
2437
Greg Clayton53eb1c22012-04-02 22:59:12 +00002438 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002439 std::vector<clang::CXXBaseSpecifier *> base_classes;
2440 std::vector<int> member_accessibilities;
2441 bool is_a_class = false;
2442 // Parse members and base classes first
2443 DWARFDIECollection member_function_dies;
Sean Callanana0b80ab2012-06-04 22:28:05 +00002444
2445 DelayedPropertyList delayed_properties;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002446 ParseChildMembers (sc,
Greg Clayton53eb1c22012-04-02 22:59:12 +00002447 dwarf_cu,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002448 die,
2449 clang_type,
2450 class_language,
2451 base_classes,
2452 member_accessibilities,
2453 member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002454 delayed_properties,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002455 default_accessibility,
2456 is_a_class,
2457 layout_info);
2458
2459 // Now parse any methods if there were any...
2460 size_t num_functions = member_function_dies.Size();
2461 if (num_functions > 0)
2462 {
2463 for (size_t i=0; i<num_functions; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002464 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002465 ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytoncaab74e2012-01-28 00:48:57 +00002466 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002467 }
2468
2469 if (class_language == eLanguageTypeObjC)
2470 {
Jim Inghamfb6fc0d2013-09-27 20:59:37 +00002471 ConstString class_name (clang_type.GetTypeName());
2472 if (class_name)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002473 {
Greg Clayton450e3f32010-10-12 02:24:53 +00002474
Sean Callanan77a1fd32012-02-27 20:07:01 +00002475 DIEArray method_die_offsets;
2476 if (m_using_apple_tables)
Greg Clayton95d87902011-11-11 03:16:25 +00002477 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002478 if (m_apple_objc_ap.get())
Jim Inghamfb6fc0d2013-09-27 20:59:37 +00002479 m_apple_objc_ap->FindByName(class_name.GetCString(), method_die_offsets);
Sean Callanan77a1fd32012-02-27 20:07:01 +00002480 }
2481 else
2482 {
2483 if (!m_indexed)
2484 Index ();
Greg Claytoncaab74e2012-01-28 00:48:57 +00002485
Sean Callanan77a1fd32012-02-27 20:07:01 +00002486 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
2487 }
2488
2489 if (!method_die_offsets.empty())
2490 {
2491 DWARFDebugInfo* debug_info = DebugInfo();
2492
2493 DWARFCompileUnit* method_cu = NULL;
2494 const size_t num_matches = method_die_offsets.size();
2495 for (size_t i=0; i<num_matches; ++i)
Greg Clayton95d87902011-11-11 03:16:25 +00002496 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002497 const dw_offset_t die_offset = method_die_offsets[i];
2498 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
2499
2500 if (method_die)
2501 ResolveType (method_cu, method_die);
2502 else
Greg Claytoncaab74e2012-01-28 00:48:57 +00002503 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002504 if (m_using_apple_tables)
2505 {
2506 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 +00002507 die_offset, class_name.GetCString());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002508 }
2509 }
2510 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002511 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002512
Greg Clayton57ee3062013-07-11 22:46:58 +00002513 for (DelayedPropertyList::iterator pi = delayed_properties.begin(), pe = delayed_properties.end();
Sean Callanana0b80ab2012-06-04 22:28:05 +00002514 pi != pe;
2515 ++pi)
2516 pi->Finalize();
Greg Clayton450e3f32010-10-12 02:24:53 +00002517 }
2518 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002519
2520 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2521 // need to tell the clang type it is actually a class.
2522 if (class_language != eLanguageTypeObjC)
2523 {
2524 if (is_a_class && tag_decl_kind != clang::TTK_Class)
Greg Clayton57ee3062013-07-11 22:46:58 +00002525 clang_type.SetTagTypeKind (clang::TTK_Class);
Sean Callanan77a1fd32012-02-27 20:07:01 +00002526 }
2527
2528 // Since DW_TAG_structure_type gets used for both classes
2529 // and structures, we may need to set any DW_TAG_member
2530 // fields to have a "private" access if none was specified.
2531 // When we parsed the child members we tracked that actual
2532 // accessibility value for each DW_TAG_member in the
2533 // "member_accessibilities" array. If the value for the
2534 // member is zero, then it was set to the "default_accessibility"
2535 // which for structs was "public". Below we correct this
2536 // by setting any fields to "private" that weren't correctly
2537 // set.
2538 if (is_a_class && !member_accessibilities.empty())
2539 {
2540 // This is a class and all members that didn't have
2541 // their access specified are private.
Greg Clayton57ee3062013-07-11 22:46:58 +00002542 clang_type.SetDefaultAccessForRecordFields (eAccessPrivate,
2543 &member_accessibilities.front(),
2544 member_accessibilities.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002545 }
2546
2547 if (!base_classes.empty())
2548 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002549 clang_type.SetBaseClassesForClassType (&base_classes.front(),
2550 base_classes.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002551
2552 // Clang will copy each CXXBaseSpecifier in "base_classes"
2553 // so we have to free them all.
Greg Clayton57ee3062013-07-11 22:46:58 +00002554 ClangASTType::DeleteBaseClassSpecifiers (&base_classes.front(),
2555 base_classes.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002556 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002557 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002558 }
Sean Callanane8c0cfb2012-03-02 01:03:45 +00002559
Greg Clayton57ee3062013-07-11 22:46:58 +00002560 clang_type.BuildIndirectFields ();
2561 clang_type.CompleteTagDeclarationDefinition ();
Sean Callanan5b26f272012-02-04 08:49:35 +00002562
Greg Clayton2508b9b2012-11-01 23:20:02 +00002563 if (!layout_info.field_offsets.empty() ||
2564 !layout_info.base_offsets.empty() ||
2565 !layout_info.vbase_offsets.empty() )
Greg Claytoncaab74e2012-01-28 00:48:57 +00002566 {
2567 if (type)
2568 layout_info.bit_size = type->GetByteSize() * 8;
2569 if (layout_info.bit_size == 0)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002570 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002571
Greg Clayton57ee3062013-07-11 22:46:58 +00002572 clang::CXXRecordDecl *record_decl = clang_type.GetAsCXXRecordDecl();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002573 if (record_decl)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002574 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002575 if (log)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002576 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002577 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002578 "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 +00002579 clang_type.GetOpaqueQualType(),
Greg Claytoncaab74e2012-01-28 00:48:57 +00002580 record_decl,
2581 layout_info.bit_size,
2582 layout_info.alignment,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002583 (uint32_t)layout_info.field_offsets.size(),
2584 (uint32_t)layout_info.base_offsets.size(),
2585 (uint32_t)layout_info.vbase_offsets.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002586
Greg Clayton2508b9b2012-11-01 23:20:02 +00002587 uint32_t idx;
2588 {
Greg Clayton821ac6d2012-01-28 02:22:27 +00002589 llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002590 for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002591 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002592 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002593 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = { bit_offset=%u, name='%s' }",
Greg Clayton57ee3062013-07-11 22:46:58 +00002594 clang_type.GetOpaqueQualType(),
Greg Clayton2508b9b2012-11-01 23:20:02 +00002595 idx,
Greg Clayton821ac6d2012-01-28 02:22:27 +00002596 (uint32_t)pos->second,
2597 pos->first->getNameAsString().c_str());
2598 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002599 }
2600
2601 {
2602 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos, base_end = layout_info.base_offsets.end();
2603 for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; ++base_pos, ++idx)
2604 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002605 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002606 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] = { byte_offset=%u, name='%s' }",
Greg Clayton57ee3062013-07-11 22:46:58 +00002607 clang_type.GetOpaqueQualType(),
Greg Clayton2508b9b2012-11-01 23:20:02 +00002608 idx,
2609 (uint32_t)base_pos->second.getQuantity(),
2610 base_pos->first->getNameAsString().c_str());
2611 }
2612 }
2613 {
2614 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos, vbase_end = layout_info.vbase_offsets.end();
2615 for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; ++vbase_pos, ++idx)
2616 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002617 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002618 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) vbase[%u] = { byte_offset=%u, name='%s' }",
Greg Clayton57ee3062013-07-11 22:46:58 +00002619 clang_type.GetOpaqueQualType(),
Greg Clayton2508b9b2012-11-01 23:20:02 +00002620 idx,
2621 (uint32_t)vbase_pos->second.getQuantity(),
2622 vbase_pos->first->getNameAsString().c_str());
2623 }
2624 }
Greg Clayton821ac6d2012-01-28 02:22:27 +00002625 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002626 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2627 }
2628 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002629 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002630
Sean Callanan9076c0f2013-10-04 21:35:29 +00002631 return (bool)clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002632
2633 case DW_TAG_enumeration_type:
Greg Clayton57ee3062013-07-11 22:46:58 +00002634 clang_type.StartTagDeclarationDefinition ();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002635 if (die->HasChildren())
2636 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002637 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00002638 bool is_signed = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00002639 clang_type.IsIntegerType(is_signed);
Greg Clayton3e067532013-03-05 23:54:39 +00002640 ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002641 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002642 clang_type.CompleteTagDeclarationDefinition ();
Sean Callanan9076c0f2013-10-04 21:35:29 +00002643 return (bool)clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002644
2645 default:
2646 assert(false && "not a forward clang type decl!");
2647 break;
2648 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002649 return false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002650}
2651
Greg Claytonc685f8e2010-09-15 04:15:46 +00002652Type*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002653SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002654{
2655 if (type_die != NULL)
2656 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002657 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00002658
Greg Claytonc685f8e2010-09-15 04:15:46 +00002659 if (type == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002660 type = GetTypeForDIE (dwarf_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00002661
Greg Clayton24739922010-10-13 03:15:28 +00002662 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00002663 {
2664 if (type != DIE_IS_BEING_PARSED)
2665 return type;
2666
2667 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
Greg Clayton53eb1c22012-04-02 22:59:12 +00002668 type_die->GetOffset(),
2669 DW_TAG_value_to_name(type_die->Tag()),
2670 type_die->GetName(this, dwarf_cu));
Jim Inghamc3549282012-01-11 02:21:12 +00002671
2672 }
2673 else
2674 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002675 }
2676 return NULL;
2677}
2678
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002679CompileUnit*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002680SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002681{
2682 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002683 if (dwarf_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002684 {
2685 // The symbol vendor doesn't know about this compile unit, we
2686 // need to parse and add it to the symbol vendor object.
Greg Clayton53eb1c22012-04-02 22:59:12 +00002687 return ParseCompileUnit(dwarf_cu, cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002688 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00002689 return (CompileUnit*)dwarf_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002690}
2691
2692bool
Greg Clayton53eb1c22012-04-02 22:59:12 +00002693SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002694{
Greg Clayton72310352013-02-23 04:12:47 +00002695 sc.Clear(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002696 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002697 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002698
Greg Clayton81c22f62011-10-19 18:09:39 +00002699 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002700 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002701 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002702
2703 if (sc.function)
2704 {
Greg Claytone72dfb32012-02-24 01:59:29 +00002705 sc.module_sp = sc.function->CalculateSymbolContextModule();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002706 return true;
2707 }
2708
2709 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002710}
2711
2712uint32_t
2713SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2714{
2715 Timer scoped_timer(__PRETTY_FUNCTION__,
Daniel Malead01b2952012-11-29 21:49:15 +00002716 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)",
Greg Claytone72dfb32012-02-24 01:59:29 +00002717 so_addr.GetSection().get(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002718 so_addr.GetOffset(),
2719 resolve_scope);
2720 uint32_t resolved = 0;
2721 if (resolve_scope & ( eSymbolContextCompUnit |
2722 eSymbolContextFunction |
2723 eSymbolContextBlock |
2724 eSymbolContextLineEntry))
2725 {
2726 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2727
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002728 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00002729 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002730 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002731 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002732 if (cu_offset != DW_INVALID_OFFSET)
2733 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002734 uint32_t cu_idx = DW_INVALID_INDEX;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002735 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
2736 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002737 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002738 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002739 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002740 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002741 resolved |= eSymbolContextCompUnit;
2742
Greg Clayton6ab80132012-12-12 17:30:52 +00002743 bool force_check_line_table = false;
Greg Clayton526a4ae2012-05-16 22:09:01 +00002744 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2745 {
2746 DWARFDebugInfoEntry *function_die = NULL;
2747 DWARFDebugInfoEntry *block_die = NULL;
2748 if (resolve_scope & eSymbolContextBlock)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002749 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002750 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
2751 }
2752 else
2753 {
2754 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL);
2755 }
2756
2757 if (function_die != NULL)
2758 {
2759 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2760 if (sc.function == NULL)
2761 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2762 }
2763 else
2764 {
2765 // We might have had a compile unit that had discontiguous
2766 // address ranges where the gaps are symbols that don't have
2767 // any debug info. Discontiguous compile unit address ranges
2768 // should only happen when there aren't other functions from
2769 // other compile units in these gaps. This helps keep the size
2770 // of the aranges down.
Greg Clayton6ab80132012-12-12 17:30:52 +00002771 force_check_line_table = true;
Greg Clayton526a4ae2012-05-16 22:09:01 +00002772 }
2773
2774 if (sc.function != NULL)
2775 {
2776 resolved |= eSymbolContextFunction;
2777
2778 if (resolve_scope & eSymbolContextBlock)
2779 {
2780 Block& block = sc.function->GetBlock (true);
2781
2782 if (block_die != NULL)
2783 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2784 else
2785 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2786 if (sc.block)
2787 resolved |= eSymbolContextBlock;
2788 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002789 }
2790 }
Greg Clayton6ab80132012-12-12 17:30:52 +00002791
2792 if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table)
2793 {
2794 LineTable *line_table = sc.comp_unit->GetLineTable();
2795 if (line_table != NULL)
2796 {
Greg Clayton9422dd62013-03-04 21:46:16 +00002797 // And address that makes it into this function should be in terms
2798 // of this debug file if there is no debug map, or it will be an
2799 // address in the .o file which needs to be fixed up to be in terms
2800 // of the debug map executable. Either way, calling FixupAddress()
2801 // will work for us.
2802 Address exe_so_addr (so_addr);
2803 if (FixupAddress(exe_so_addr))
Greg Clayton6ab80132012-12-12 17:30:52 +00002804 {
Greg Clayton9422dd62013-03-04 21:46:16 +00002805 if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry))
Greg Clayton6ab80132012-12-12 17:30:52 +00002806 {
2807 resolved |= eSymbolContextLineEntry;
2808 }
2809 }
Greg Clayton6ab80132012-12-12 17:30:52 +00002810 }
2811 }
2812
2813 if (force_check_line_table && !(resolved & eSymbolContextLineEntry))
2814 {
2815 // We might have had a compile unit that had discontiguous
2816 // address ranges where the gaps are symbols that don't have
2817 // any debug info. Discontiguous compile unit address ranges
2818 // should only happen when there aren't other functions from
2819 // other compile units in these gaps. This helps keep the size
2820 // of the aranges down.
2821 sc.comp_unit = NULL;
2822 resolved &= ~eSymbolContextCompUnit;
2823 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002824 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002825 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002826 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002827 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.",
2828 cu_offset,
2829 cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002830 }
2831 }
2832 }
2833 }
2834 }
2835 return resolved;
2836}
2837
2838
2839
2840uint32_t
2841SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
2842{
2843 const uint32_t prev_size = sc_list.GetSize();
2844 if (resolve_scope & eSymbolContextCompUnit)
2845 {
2846 DWARFDebugInfo* debug_info = DebugInfo();
2847 if (debug_info)
2848 {
2849 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002850 DWARFCompileUnit* dwarf_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002851
Greg Clayton53eb1c22012-04-02 22:59:12 +00002852 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002853 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002854 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Sean Callananddd7a2a2013-10-03 22:27:29 +00002855 const bool full_match = (bool)file_spec.GetDirectory();
Greg Clayton1f746072012-08-29 21:13:06 +00002856 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 +00002857 if (check_inlines || file_spec_matches_cu_file_spec)
2858 {
2859 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton53eb1c22012-04-02 22:59:12 +00002860 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002861 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002862 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002863 uint32_t file_idx = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002864
Greg Clayton526a4ae2012-05-16 22:09:01 +00002865 // If we are looking for inline functions only and we don't
2866 // find it in the support files, we are done.
2867 if (check_inlines)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002868 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002869 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
2870 if (file_idx == UINT32_MAX)
2871 continue;
2872 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002873
Greg Clayton526a4ae2012-05-16 22:09:01 +00002874 if (line != 0)
2875 {
2876 LineTable *line_table = sc.comp_unit->GetLineTable();
2877
2878 if (line_table != NULL && line != 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002879 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002880 // We will have already looked up the file index if
2881 // we are searching for inline entries.
2882 if (!check_inlines)
2883 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002884
Greg Clayton526a4ae2012-05-16 22:09:01 +00002885 if (file_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002886 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002887 uint32_t found_line;
2888 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
2889 found_line = sc.line_entry.line;
2890
2891 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002892 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002893 sc.function = NULL;
2894 sc.block = NULL;
2895 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002896 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002897 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
2898 if (file_vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002899 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002900 DWARFDebugInfoEntry *function_die = NULL;
2901 DWARFDebugInfoEntry *block_die = NULL;
2902 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002903
Greg Clayton526a4ae2012-05-16 22:09:01 +00002904 if (function_die != NULL)
2905 {
2906 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2907 if (sc.function == NULL)
2908 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2909 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002910
Greg Clayton526a4ae2012-05-16 22:09:01 +00002911 if (sc.function != NULL)
2912 {
2913 Block& block = sc.function->GetBlock (true);
2914
2915 if (block_die != NULL)
2916 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2917 else
2918 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2919 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002920 }
2921 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002922
Greg Clayton526a4ae2012-05-16 22:09:01 +00002923 sc_list.Append(sc);
2924 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2925 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002926 }
2927 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002928 else if (file_spec_matches_cu_file_spec && !check_inlines)
2929 {
2930 // only append the context if we aren't looking for inline call sites
2931 // by file and line and if the file spec matches that of the compile unit
2932 sc_list.Append(sc);
2933 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002934 }
2935 else if (file_spec_matches_cu_file_spec && !check_inlines)
2936 {
2937 // only append the context if we aren't looking for inline call sites
2938 // by file and line and if the file spec matches that of the compile unit
2939 sc_list.Append(sc);
2940 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002941
Greg Clayton526a4ae2012-05-16 22:09:01 +00002942 if (!check_inlines)
2943 break;
2944 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002945 }
2946 }
2947 }
2948 }
2949 return sc_list.GetSize() - prev_size;
2950}
2951
2952void
2953SymbolFileDWARF::Index ()
2954{
2955 if (m_indexed)
2956 return;
2957 m_indexed = true;
2958 Timer scoped_timer (__PRETTY_FUNCTION__,
2959 "SymbolFileDWARF::Index (%s)",
2960 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
2961
2962 DWARFDebugInfo* debug_info = DebugInfo();
2963 if (debug_info)
2964 {
2965 uint32_t cu_idx = 0;
2966 const uint32_t num_compile_units = GetNumCompileUnits();
2967 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2968 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002969 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002970
Greg Clayton53eb1c22012-04-02 22:59:12 +00002971 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002972
Greg Clayton53eb1c22012-04-02 22:59:12 +00002973 dwarf_cu->Index (cu_idx,
2974 m_function_basename_index,
2975 m_function_fullname_index,
2976 m_function_method_index,
2977 m_function_selector_index,
2978 m_objc_class_selectors_index,
2979 m_global_index,
2980 m_type_index,
2981 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002982
2983 // Keep memory down by clearing DIEs if this generate function
2984 // caused them to be parsed
2985 if (clear_dies)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002986 dwarf_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002987 }
2988
Greg Claytond4a2b372011-09-12 23:21:58 +00002989 m_function_basename_index.Finalize();
2990 m_function_fullname_index.Finalize();
2991 m_function_method_index.Finalize();
2992 m_function_selector_index.Finalize();
2993 m_objc_class_selectors_index.Finalize();
2994 m_global_index.Finalize();
2995 m_type_index.Finalize();
2996 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002997
Greg Clayton24739922010-10-13 03:15:28 +00002998#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00002999 StreamFile s(stdout, false);
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00003000 s.Printf ("DWARF index for '%s':",
3001 GetObjectFile()->GetFileSpec().GetPath().c_str());
Greg Claytonba2d22d2010-11-13 22:57:37 +00003002 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
3003 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
3004 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
3005 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
3006 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
3007 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00003008 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00003009 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00003010#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003011 }
3012}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003013
3014bool
3015SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
3016{
3017 if (namespace_decl == NULL)
3018 {
3019 // Invalid namespace decl which means we aren't matching only things
3020 // in this symbol file, so return true to indicate it matches this
3021 // symbol file.
3022 return true;
3023 }
3024
3025 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
3026
3027 if (namespace_ast == NULL)
3028 return true; // No AST in the "namespace_decl", return true since it
3029 // could then match any symbol file, including this one
3030
3031 if (namespace_ast == GetClangASTContext().getASTContext())
3032 return true; // The ASTs match, return true
3033
3034 // The namespace AST was valid, and it does not match...
Greg Clayton5160ce52013-03-27 23:08:40 +00003035 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Sean Callananc41e68b2011-10-13 21:08:11 +00003036
3037 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003038 GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00003039
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003040 return false;
3041}
3042
Greg Clayton2506a7a2011-10-12 23:34:26 +00003043bool
3044SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
3045 DWARFCompileUnit* cu,
3046 const DWARFDebugInfoEntry* die)
3047{
3048 // No namespace specified, so the answesr i
3049 if (namespace_decl == NULL)
3050 return true;
Sean Callananebe60672011-10-13 21:50:33 +00003051
Greg Clayton5160ce52013-03-27 23:08:40 +00003052 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003053
Greg Clayton437a1352012-04-09 22:43:43 +00003054 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
3055 clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00003056 if (decl_ctx_die)
Greg Clayton437a1352012-04-09 22:43:43 +00003057 {
Greg Clayton2506a7a2011-10-12 23:34:26 +00003058 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
Greg Clayton437a1352012-04-09 22:43:43 +00003059
Greg Clayton2506a7a2011-10-12 23:34:26 +00003060 if (clang_namespace_decl)
3061 {
3062 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00003063 {
3064 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003065 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00003066 return false;
Sean Callananebe60672011-10-13 21:50:33 +00003067 }
3068
Greg Clayton437a1352012-04-09 22:43:43 +00003069 if (clang_namespace_decl == die_clang_decl_ctx)
3070 return true;
3071 else
Greg Clayton2506a7a2011-10-12 23:34:26 +00003072 return false;
Greg Clayton2506a7a2011-10-12 23:34:26 +00003073 }
3074 else
3075 {
3076 // We have a namespace_decl that was not NULL but it contained
3077 // a NULL "clang::NamespaceDecl", so this means the global namespace
3078 // So as long the the contained decl context DIE isn't a namespace
3079 // we should be ok.
3080 if (decl_ctx_die->Tag() != DW_TAG_namespace)
3081 return true;
3082 }
3083 }
Sean Callananebe60672011-10-13 21:50:33 +00003084
3085 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003086 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00003087
Greg Clayton2506a7a2011-10-12 23:34:26 +00003088 return false;
3089}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003090uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00003091SymbolFileDWARF::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 +00003092{
Greg Clayton5160ce52013-03-27 23:08:40 +00003093 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003094
3095 if (log)
3096 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003097 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003098 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
3099 name.GetCString(),
3100 namespace_decl,
3101 append,
3102 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003103 }
Sean Callanan213fdb82011-10-13 01:49:10 +00003104
3105 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00003106 return 0;
Sean Callanan213fdb82011-10-13 01:49:10 +00003107
Greg Claytonc685f8e2010-09-15 04:15:46 +00003108 DWARFDebugInfo* info = DebugInfo();
3109 if (info == NULL)
3110 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003111
3112 // If we aren't appending the results to this list, then clear the list
3113 if (!append)
3114 variables.Clear();
3115
3116 // Remember how many variables are in the list before we search in case
3117 // we are appending the results to a variable list.
3118 const uint32_t original_size = variables.GetSize();
3119
Greg Claytond4a2b372011-09-12 23:21:58 +00003120 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003121
Greg Clayton97fbc342011-10-20 22:30:33 +00003122 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003123 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003124 if (m_apple_names_ap.get())
3125 {
3126 const char *name_cstr = name.GetCString();
3127 const char *base_name_start;
3128 const char *base_name_end = NULL;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003129
Greg Clayton97fbc342011-10-20 22:30:33 +00003130 if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end))
3131 base_name_start = name_cstr;
3132
3133 m_apple_names_ap->FindByName (base_name_start, die_offsets);
3134 }
Greg Clayton7f995132011-10-04 22:41:51 +00003135 }
3136 else
3137 {
3138 // Index the DWARF if we haven't already
3139 if (!m_indexed)
3140 Index ();
3141
3142 m_global_index.Find (name, die_offsets);
3143 }
3144
Greg Clayton437a1352012-04-09 22:43:43 +00003145 const size_t num_die_matches = die_offsets.size();
3146 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003147 {
Greg Clayton7f995132011-10-04 22:41:51 +00003148 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003149 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00003150 assert (sc.module_sp);
3151
Greg Claytond4a2b372011-09-12 23:21:58 +00003152 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00003153 DWARFCompileUnit* dwarf_cu = NULL;
3154 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton437a1352012-04-09 22:43:43 +00003155 bool done = false;
3156 for (size_t i=0; i<num_die_matches && !done; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00003157 {
3158 const dw_offset_t die_offset = die_offsets[i];
3159 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003160
Greg Clayton95d87902011-11-11 03:16:25 +00003161 if (die)
3162 {
Greg Clayton437a1352012-04-09 22:43:43 +00003163 switch (die->Tag())
3164 {
3165 default:
3166 case DW_TAG_subprogram:
3167 case DW_TAG_inlined_subroutine:
3168 case DW_TAG_try_block:
3169 case DW_TAG_catch_block:
3170 break;
3171
3172 case DW_TAG_variable:
3173 {
3174 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Greg Clayton437a1352012-04-09 22:43:43 +00003175
3176 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3177 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003178
Greg Clayton437a1352012-04-09 22:43:43 +00003179 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003180
Greg Clayton437a1352012-04-09 22:43:43 +00003181 if (variables.GetSize() - original_size >= max_matches)
3182 done = true;
3183 }
3184 break;
3185 }
Greg Clayton95d87902011-11-11 03:16:25 +00003186 }
3187 else
3188 {
3189 if (m_using_apple_tables)
3190 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003191 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
3192 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003193 }
3194 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003195 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003196 }
3197
3198 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003199 const uint32_t num_matches = variables.GetSize() - original_size;
3200 if (log && num_matches > 0)
3201 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003202 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003203 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u",
3204 name.GetCString(),
3205 namespace_decl,
3206 append,
3207 max_matches,
3208 num_matches);
3209 }
3210 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003211}
3212
3213uint32_t
3214SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
3215{
Greg Clayton5160ce52013-03-27 23:08:40 +00003216 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003217
3218 if (log)
3219 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003220 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003221 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
3222 regex.GetText(),
3223 append,
3224 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003225 }
3226
Greg Claytonc685f8e2010-09-15 04:15:46 +00003227 DWARFDebugInfo* info = DebugInfo();
3228 if (info == NULL)
3229 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003230
3231 // If we aren't appending the results to this list, then clear the list
3232 if (!append)
3233 variables.Clear();
3234
3235 // Remember how many variables are in the list before we search in case
3236 // we are appending the results to a variable list.
3237 const uint32_t original_size = variables.GetSize();
3238
Greg Clayton7f995132011-10-04 22:41:51 +00003239 DIEArray die_offsets;
3240
Greg Clayton97fbc342011-10-20 22:30:33 +00003241 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003242 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003243 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00003244 {
3245 DWARFMappedHash::DIEInfoArray hash_data_array;
3246 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
3247 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
3248 }
Greg Clayton7f995132011-10-04 22:41:51 +00003249 }
3250 else
3251 {
3252 // Index the DWARF if we haven't already
3253 if (!m_indexed)
3254 Index ();
3255
3256 m_global_index.Find (regex, die_offsets);
3257 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003258
Greg Claytonc685f8e2010-09-15 04:15:46 +00003259 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003260 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003261 assert (sc.module_sp);
3262
Greg Claytond4a2b372011-09-12 23:21:58 +00003263 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00003264 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003265 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003266 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003267 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003268 DWARFDebugInfo* debug_info = DebugInfo();
3269 for (size_t i=0; i<num_matches; ++i)
3270 {
3271 const dw_offset_t die_offset = die_offsets[i];
3272 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00003273
3274 if (die)
3275 {
3276 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003277
Greg Clayton95d87902011-11-11 03:16:25 +00003278 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003279
Greg Clayton95d87902011-11-11 03:16:25 +00003280 if (variables.GetSize() - original_size >= max_matches)
3281 break;
3282 }
3283 else
3284 {
3285 if (m_using_apple_tables)
3286 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003287 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
3288 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00003289 }
3290 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003291 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003292 }
3293
3294 // Return the number of variable that were appended to the list
3295 return variables.GetSize() - original_size;
3296}
3297
Greg Claytonaa044962011-10-13 00:59:38 +00003298
Jim Ingham4cda6e02011-10-07 22:23:45 +00003299bool
3300SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
3301 DWARFCompileUnit *&dwarf_cu,
3302 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00003303{
Greg Claytonaa044962011-10-13 00:59:38 +00003304 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3305 return ResolveFunction (dwarf_cu, die, sc_list);
3306}
3307
3308
3309bool
3310SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
3311 const DWARFDebugInfoEntry *die,
3312 SymbolContextList& sc_list)
3313{
Greg Clayton9e315582011-09-02 04:03:59 +00003314 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00003315
3316 if (die == NULL)
3317 return false;
3318
Jim Ingham4cda6e02011-10-07 22:23:45 +00003319 // If we were passed a die that is not a function, just return false...
3320 if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine)
3321 return false;
3322
3323 const DWARFDebugInfoEntry* inlined_die = NULL;
3324 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00003325 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003326 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00003327
Jim Ingham4cda6e02011-10-07 22:23:45 +00003328 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003329 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003330 if (die->Tag() == DW_TAG_subprogram)
3331 break;
Greg Clayton9e315582011-09-02 04:03:59 +00003332 }
3333 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003334 assert (die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00003335 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003336 {
3337 Address addr;
3338 // Parse all blocks if needed
3339 if (inlined_die)
3340 {
Greg Clayton81c22f62011-10-19 18:09:39 +00003341 sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset()));
Jim Ingham4cda6e02011-10-07 22:23:45 +00003342 assert (sc.block != NULL);
3343 if (sc.block->GetStartAddress (addr) == false)
3344 addr.Clear();
3345 }
3346 else
3347 {
3348 sc.block = NULL;
3349 addr = sc.function->GetAddressRange().GetBaseAddress();
3350 }
3351
3352 if (addr.IsValid())
3353 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003354 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00003355 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003356 }
3357 }
3358
Greg Claytonaa044962011-10-13 00:59:38 +00003359 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00003360}
3361
Greg Clayton7f995132011-10-04 22:41:51 +00003362void
3363SymbolFileDWARF::FindFunctions (const ConstString &name,
3364 const NameToDIE &name_to_die,
3365 SymbolContextList& sc_list)
3366{
Greg Claytond4a2b372011-09-12 23:21:58 +00003367 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003368 if (name_to_die.Find (name, die_offsets))
3369 {
3370 ParseFunctions (die_offsets, sc_list);
3371 }
3372}
3373
3374
3375void
3376SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3377 const NameToDIE &name_to_die,
3378 SymbolContextList& sc_list)
3379{
3380 DIEArray die_offsets;
3381 if (name_to_die.Find (regex, die_offsets))
3382 {
3383 ParseFunctions (die_offsets, sc_list);
3384 }
3385}
3386
3387
3388void
3389SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3390 const DWARFMappedHash::MemoryTable &memory_table,
3391 SymbolContextList& sc_list)
3392{
3393 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00003394 DWARFMappedHash::DIEInfoArray hash_data_array;
3395 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00003396 {
Greg Claytond1767f02011-12-08 02:13:16 +00003397 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Greg Clayton7f995132011-10-04 22:41:51 +00003398 ParseFunctions (die_offsets, sc_list);
3399 }
3400}
3401
3402void
3403SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
3404 SymbolContextList& sc_list)
3405{
3406 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003407 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00003408 {
Greg Clayton7f995132011-10-04 22:41:51 +00003409 SymbolContext sc;
Greg Clayton7f995132011-10-04 22:41:51 +00003410
3411 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003412 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00003413 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003414 const dw_offset_t die_offset = die_offsets[i];
Jim Ingham4cda6e02011-10-07 22:23:45 +00003415 ResolveFunction (die_offset, dwarf_cu, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003416 }
3417 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00003418}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003419
Jim Ingham4cda6e02011-10-07 22:23:45 +00003420bool
3421SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
3422 const DWARFCompileUnit *dwarf_cu,
3423 uint32_t name_type_mask,
3424 const char *partial_name,
3425 const char *base_name_start,
3426 const char *base_name_end)
3427{
Greg Claytonfbea0f62012-11-15 18:05:43 +00003428 // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes:
3429 if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003430 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003431 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
3432 if (!containing_decl_ctx)
3433 return false;
3434
3435 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
3436
Greg Claytonfbea0f62012-11-15 18:05:43 +00003437 if (name_type_mask == eFunctionNameTypeMethod)
3438 {
3439 if (is_cxx_method == false)
3440 return false;
3441 }
3442
3443 if (name_type_mask == eFunctionNameTypeBase)
3444 {
3445 if (is_cxx_method == true)
3446 return false;
3447 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003448 }
3449
3450 // Now we need to check whether the name we got back for this type matches the extra specifications
3451 // that were in the name we're looking up:
3452 if (base_name_start != partial_name || *base_name_end != '\0')
3453 {
3454 // First see if the stuff to the left matches the full name. To do that let's see if
3455 // we can pull out the mips linkage name attribute:
3456
3457 Mangled best_name;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003458 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonfbea0f62012-11-15 18:05:43 +00003459 DWARFFormValue form_value;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003460 die->GetAttributes(this, dwarf_cu, NULL, attributes);
3461 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
Greg Clayton71415542012-12-08 00:24:40 +00003462 if (idx == UINT32_MAX)
3463 idx = attributes.FindAttributeIndex(DW_AT_linkage_name);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003464 if (idx != UINT32_MAX)
3465 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003466 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
3467 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003468 const char *mangled_name = form_value.AsCString(&get_debug_str_data());
3469 if (mangled_name)
3470 best_name.SetValue (ConstString(mangled_name), true);
3471 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003472 }
Greg Claytonfbea0f62012-11-15 18:05:43 +00003473
3474 if (!best_name)
3475 {
3476 idx = attributes.FindAttributeIndex(DW_AT_name);
3477 if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value))
3478 {
3479 const char *name = form_value.AsCString(&get_debug_str_data());
3480 best_name.SetValue (ConstString(name), false);
3481 }
3482 }
3483
3484 if (best_name.GetDemangledName())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003485 {
3486 const char *demangled = best_name.GetDemangledName().GetCString();
3487 if (demangled)
3488 {
3489 std::string name_no_parens(partial_name, base_name_end - partial_name);
Jim Ingham85c13d72012-03-02 02:24:42 +00003490 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str());
3491 if (partial_in_demangled == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003492 return false;
Jim Ingham85c13d72012-03-02 02:24:42 +00003493 else
3494 {
3495 // Sort out the case where our name is something like "Process::Destroy" and the match is
3496 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on
3497 // namespace boundaries...
3498
3499 if (partial_name[0] == ':' && partial_name[1] == ':')
3500 {
3501 // The partial name was already on a namespace boundary so all matches are good.
3502 return true;
3503 }
3504 else if (partial_in_demangled == demangled)
3505 {
3506 // They both start the same, so this is an good match.
3507 return true;
3508 }
3509 else
3510 {
3511 if (partial_in_demangled - demangled == 1)
3512 {
3513 // Only one character difference, can't be a namespace boundary...
3514 return false;
3515 }
3516 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':')
3517 {
3518 // We are on a namespace boundary, so this is also good.
3519 return true;
3520 }
3521 else
3522 return false;
3523 }
3524 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003525 }
3526 }
3527 }
3528
3529 return true;
3530}
Greg Claytonc685f8e2010-09-15 04:15:46 +00003531
Greg Clayton0c5cd902010-06-28 21:30:43 +00003532uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00003533SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00003534 const lldb_private::ClangNamespaceDecl *namespace_decl,
Sean Callanan9df05fb2012-02-10 22:52:19 +00003535 uint32_t name_type_mask,
3536 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00003537 bool append,
3538 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00003539{
3540 Timer scoped_timer (__PRETTY_FUNCTION__,
3541 "SymbolFileDWARF::FindFunctions (name = '%s')",
3542 name.AsCString());
3543
Greg Clayton43fe2172013-04-03 02:00:15 +00003544 // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup()
3545 assert ((name_type_mask & eFunctionNameTypeAuto) == 0);
3546
Greg Clayton5160ce52013-03-27 23:08:40 +00003547 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003548
3549 if (log)
3550 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003551 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003552 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
3553 name.GetCString(),
3554 name_type_mask,
3555 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003556 }
3557
Greg Clayton0c5cd902010-06-28 21:30:43 +00003558 // If we aren't appending the results to this list, then clear the list
3559 if (!append)
3560 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003561
3562 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00003563 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003564
3565 // If name is empty then we won't find anything.
3566 if (name.IsEmpty())
3567 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00003568
3569 // Remember how many sc_list are in the list before we search in case
3570 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00003571
Jim Ingham4cda6e02011-10-07 22:23:45 +00003572 const char *name_cstr = name.GetCString();
Greg Clayton43fe2172013-04-03 02:00:15 +00003573
3574 const uint32_t original_size = sc_list.GetSize();
3575
Jim Ingham4cda6e02011-10-07 22:23:45 +00003576 DWARFDebugInfo* info = DebugInfo();
3577 if (info == NULL)
3578 return 0;
3579
Greg Claytonaa044962011-10-13 00:59:38 +00003580 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton43fe2172013-04-03 02:00:15 +00003581 std::set<const DWARFDebugInfoEntry *> resolved_dies;
Greg Clayton97fbc342011-10-20 22:30:33 +00003582 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00003583 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003584 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003585 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003586
3587 DIEArray die_offsets;
3588
3589 uint32_t num_matches = 0;
3590
Greg Clayton43fe2172013-04-03 02:00:15 +00003591 if (name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00003592 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003593 // If they asked for the full name, match what they typed. At some point we may
3594 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
3595 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00003596 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003597 for (uint32_t i = 0; i < num_matches; i++)
3598 {
Greg Clayton95d87902011-11-11 03:16:25 +00003599 const dw_offset_t die_offset = die_offsets[i];
3600 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00003601 if (die)
3602 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003603 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3604 continue;
3605
Sean Callanan9df05fb2012-02-10 22:52:19 +00003606 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3607 continue;
3608
Greg Clayton43fe2172013-04-03 02:00:15 +00003609 if (resolved_dies.find(die) == resolved_dies.end())
3610 {
3611 if (ResolveFunction (dwarf_cu, die, sc_list))
3612 resolved_dies.insert(die);
3613 }
Greg Claytonaa044962011-10-13 00:59:38 +00003614 }
Greg Clayton95d87902011-11-11 03:16:25 +00003615 else
3616 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003617 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3618 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003619 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003620 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003621 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003622
3623 if (name_type_mask & eFunctionNameTypeSelector)
3624 {
3625 if (namespace_decl && *namespace_decl)
3626 return 0; // no selectors in namespaces
Greg Clayton97fbc342011-10-20 22:30:33 +00003627
Greg Clayton43fe2172013-04-03 02:00:15 +00003628 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3629 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
3630 // and if it is an ObjC method name, we're good.
Greg Clayton97fbc342011-10-20 22:30:33 +00003631
Greg Clayton43fe2172013-04-03 02:00:15 +00003632 for (uint32_t i = 0; i < num_matches; i++)
Greg Clayton97fbc342011-10-20 22:30:33 +00003633 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003634 const dw_offset_t die_offset = die_offsets[i];
3635 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3636 if (die)
Greg Clayton97fbc342011-10-20 22:30:33 +00003637 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003638 const char *die_name = die->GetName(this, dwarf_cu);
3639 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
Greg Clayton97fbc342011-10-20 22:30:33 +00003640 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003641 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3642 continue;
3643
Greg Clayton43fe2172013-04-03 02:00:15 +00003644 if (resolved_dies.find(die) == resolved_dies.end())
3645 {
3646 if (ResolveFunction (dwarf_cu, die, sc_list))
3647 resolved_dies.insert(die);
3648 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003649 }
3650 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003651 else
3652 {
3653 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3654 die_offset, name_cstr);
3655 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003656 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003657 die_offsets.clear();
3658 }
3659
3660 if (((name_type_mask & eFunctionNameTypeMethod) && !namespace_decl) || name_type_mask & eFunctionNameTypeBase)
3661 {
3662 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
3663 // extract the base name, look that up, and if there is any other information in the name we were
3664 // passed in we have to post-filter based on that.
3665
3666 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
3667 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3668
3669 for (uint32_t i = 0; i < num_matches; i++)
3670 {
3671 const dw_offset_t die_offset = die_offsets[i];
3672 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3673 if (die)
3674 {
3675 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3676 continue;
3677
3678 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3679 continue;
3680
3681 // If we get to here, the die is good, and we should add it:
3682 if (resolved_dies.find(die) == resolved_dies.end())
3683 if (ResolveFunction (dwarf_cu, die, sc_list))
3684 {
3685 bool keep_die = true;
3686 if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod))
3687 {
3688 // We are looking for either basenames or methods, so we need to
3689 // trim out the ones we won't want by looking at the type
3690 SymbolContext sc;
3691 if (sc_list.GetLastContext(sc))
3692 {
3693 if (sc.block)
3694 {
3695 // We have an inlined function
3696 }
3697 else if (sc.function)
3698 {
3699 Type *type = sc.function->GetType();
3700
Sean Callananc370a8a2013-09-18 22:59:55 +00003701 if (type)
Greg Clayton43fe2172013-04-03 02:00:15 +00003702 {
Sean Callananc370a8a2013-09-18 22:59:55 +00003703 clang::DeclContext* decl_ctx = GetClangDeclContextContainingTypeUID (type->GetID());
3704 if (decl_ctx->isRecord())
Greg Clayton43fe2172013-04-03 02:00:15 +00003705 {
Sean Callananc370a8a2013-09-18 22:59:55 +00003706 if (name_type_mask & eFunctionNameTypeBase)
3707 {
3708 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3709 keep_die = false;
3710 }
3711 }
3712 else
3713 {
3714 if (name_type_mask & eFunctionNameTypeMethod)
3715 {
3716 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3717 keep_die = false;
3718 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003719 }
3720 }
3721 else
3722 {
Sean Callananc370a8a2013-09-18 22:59:55 +00003723 GetObjectFile()->GetModule()->ReportWarning ("function at die offset 0x%8.8x had no function type",
3724 die_offset);
Greg Clayton43fe2172013-04-03 02:00:15 +00003725 }
3726 }
3727 }
3728 }
3729 if (keep_die)
3730 resolved_dies.insert(die);
3731 }
3732 }
3733 else
3734 {
3735 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3736 die_offset, name_cstr);
3737 }
3738 }
3739 die_offsets.clear();
Jim Ingham4cda6e02011-10-07 22:23:45 +00003740 }
3741 }
Greg Clayton7f995132011-10-04 22:41:51 +00003742 }
3743 else
3744 {
3745
3746 // Index the DWARF if we haven't already
3747 if (!m_indexed)
3748 Index ();
3749
Greg Clayton7f995132011-10-04 22:41:51 +00003750 if (name_type_mask & eFunctionNameTypeFull)
Matt Kopecd6089962013-05-10 17:53:48 +00003751 {
Greg Clayton7f995132011-10-04 22:41:51 +00003752 FindFunctions (name, m_function_fullname_index, sc_list);
3753
Ed Mastefc7baa02013-09-09 18:00:45 +00003754 // FIXME Temporary workaround for global/anonymous namespace
3755 // functions on FreeBSD and Linux
3756#if defined (__FreeBSD__) || defined (__linux__)
Matt Kopecd6089962013-05-10 17:53:48 +00003757 // If we didn't find any functions in the global namespace try
3758 // looking in the basename index but ignore any returned
3759 // functions that have a namespace (ie. mangled names starting with
3760 // '_ZN') but keep functions which have an anonymous namespace
3761 if (sc_list.GetSize() == 0)
3762 {
3763 SymbolContextList temp_sc_list;
3764 FindFunctions (name, m_function_basename_index, temp_sc_list);
3765 if (!namespace_decl)
3766 {
3767 SymbolContext sc;
3768 for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++)
3769 {
3770 if (temp_sc_list.GetContextAtIndex(i, sc))
3771 {
Matt Kopeca189d492013-05-10 22:55:24 +00003772 ConstString mangled_name = sc.GetFunctionName(Mangled::ePreferMangled);
3773 ConstString demangled_name = sc.GetFunctionName(Mangled::ePreferDemangled);
Matt Kopec04e5d582013-05-14 19:00:41 +00003774 if (strncmp(mangled_name.GetCString(), "_ZN", 3) ||
3775 !strncmp(demangled_name.GetCString(), "(anonymous namespace)", 21))
Matt Kopecd6089962013-05-10 17:53:48 +00003776 {
3777 sc_list.Append(sc);
3778 }
3779 }
3780 }
3781 }
3782 }
3783#endif
3784 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003785 DIEArray die_offsets;
3786 DWARFCompileUnit *dwarf_cu = NULL;
3787
Greg Clayton43fe2172013-04-03 02:00:15 +00003788 if (name_type_mask & eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003789 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003790 uint32_t num_base = m_function_basename_index.Find(name, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00003791 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003792 {
Greg Claytonaa044962011-10-13 00:59:38 +00003793 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3794 if (die)
3795 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003796 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3797 continue;
3798
Sean Callanan213fdb82011-10-13 01:49:10 +00003799 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3800 continue;
3801
Greg Claytonaa044962011-10-13 00:59:38 +00003802 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00003803 if (resolved_dies.find(die) == resolved_dies.end())
3804 {
3805 if (ResolveFunction (dwarf_cu, die, sc_list))
3806 resolved_dies.insert(die);
3807 }
Greg Claytonaa044962011-10-13 00:59:38 +00003808 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003809 }
3810 die_offsets.clear();
3811 }
3812
Greg Clayton43fe2172013-04-03 02:00:15 +00003813 if (name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003814 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003815 if (namespace_decl && *namespace_decl)
3816 return 0; // no methods in namespaces
3817
Greg Clayton43fe2172013-04-03 02:00:15 +00003818 uint32_t num_base = m_function_method_index.Find(name, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003819 {
Greg Claytonaa044962011-10-13 00:59:38 +00003820 for (uint32_t i = 0; i < num_base; i++)
3821 {
3822 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3823 if (die)
3824 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003825 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3826 continue;
3827
Greg Claytonaa044962011-10-13 00:59:38 +00003828 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00003829 if (resolved_dies.find(die) == resolved_dies.end())
3830 {
3831 if (ResolveFunction (dwarf_cu, die, sc_list))
3832 resolved_dies.insert(die);
3833 }
Greg Claytonaa044962011-10-13 00:59:38 +00003834 }
3835 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003836 }
3837 die_offsets.clear();
3838 }
Greg Clayton7f995132011-10-04 22:41:51 +00003839
Greg Clayton43fe2172013-04-03 02:00:15 +00003840 if ((name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003841 {
Greg Clayton7f995132011-10-04 22:41:51 +00003842 FindFunctions (name, m_function_selector_index, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003843 }
3844
Greg Clayton4d01ace2011-09-29 16:58:15 +00003845 }
3846
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003847 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003848 const uint32_t num_matches = sc_list.GetSize() - original_size;
3849
3850 if (log && num_matches > 0)
3851 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003852 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003853 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list) => %u",
3854 name.GetCString(),
3855 name_type_mask,
3856 append,
3857 num_matches);
3858 }
3859 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003860}
3861
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003862uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00003863SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003864{
3865 Timer scoped_timer (__PRETTY_FUNCTION__,
3866 "SymbolFileDWARF::FindFunctions (regex = '%s')",
3867 regex.GetText());
3868
Greg Clayton5160ce52013-03-27 23:08:40 +00003869 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003870
3871 if (log)
3872 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003873 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003874 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
3875 regex.GetText(),
3876 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003877 }
3878
3879
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003880 // If we aren't appending the results to this list, then clear the list
3881 if (!append)
3882 sc_list.Clear();
3883
3884 // Remember how many sc_list are in the list before we search in case
3885 // we are appending the results to a variable list.
3886 uint32_t original_size = sc_list.GetSize();
3887
Greg Clayton97fbc342011-10-20 22:30:33 +00003888 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003889 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003890 if (m_apple_names_ap.get())
3891 FindFunctions (regex, *m_apple_names_ap, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003892 }
3893 else
3894 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003895 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00003896 if (!m_indexed)
3897 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003898
Greg Clayton7f995132011-10-04 22:41:51 +00003899 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003900
Greg Clayton7f995132011-10-04 22:41:51 +00003901 FindFunctions (regex, m_function_fullname_index, sc_list);
3902 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003903
3904 // Return the number of variable that were appended to the list
3905 return sc_list.GetSize() - original_size;
3906}
Jim Ingham318c9f22011-08-26 19:44:13 +00003907
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003908uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00003909SymbolFileDWARF::FindTypes (const SymbolContext& sc,
3910 const ConstString &name,
3911 const lldb_private::ClangNamespaceDecl *namespace_decl,
3912 bool append,
3913 uint32_t max_matches,
3914 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003915{
Greg Claytonc685f8e2010-09-15 04:15:46 +00003916 DWARFDebugInfo* info = DebugInfo();
3917 if (info == NULL)
3918 return 0;
3919
Greg Clayton5160ce52013-03-27 23:08:40 +00003920 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003921
3922 if (log)
3923 {
Greg Clayton437a1352012-04-09 22:43:43 +00003924 if (namespace_decl)
3925 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003926 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003927 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)",
3928 name.GetCString(),
3929 namespace_decl->GetNamespaceDecl(),
3930 namespace_decl->GetQualifiedName().c_str(),
3931 append,
3932 max_matches);
3933 }
3934 else
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(NULL), append=%u, max_matches=%u, type_list)",
3938 name.GetCString(),
3939 append,
3940 max_matches);
3941 }
Greg Clayton21f2a492011-10-06 00:09:08 +00003942 }
3943
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003944 // If we aren't appending the results to this list, then clear the list
3945 if (!append)
3946 types.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003947
3948 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00003949 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003950
Greg Claytond4a2b372011-09-12 23:21:58 +00003951 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003952
Greg Clayton97fbc342011-10-20 22:30:33 +00003953 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003954 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003955 if (m_apple_types_ap.get())
3956 {
3957 const char *name_cstr = name.GetCString();
3958 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3959 }
Greg Clayton7f995132011-10-04 22:41:51 +00003960 }
3961 else
3962 {
3963 if (!m_indexed)
3964 Index ();
3965
3966 m_type_index.Find (name, die_offsets);
3967 }
3968
Greg Clayton437a1352012-04-09 22:43:43 +00003969 const size_t num_die_matches = die_offsets.size();
Greg Clayton7f995132011-10-04 22:41:51 +00003970
Greg Clayton437a1352012-04-09 22:43:43 +00003971 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003972 {
Greg Clayton7f995132011-10-04 22:41:51 +00003973 const uint32_t initial_types_size = types.GetSize();
3974 DWARFCompileUnit* dwarf_cu = NULL;
3975 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003976 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00003977 for (size_t i=0; i<num_die_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003978 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003979 const dw_offset_t die_offset = die_offsets[i];
3980 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3981
Greg Clayton95d87902011-11-11 03:16:25 +00003982 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00003983 {
Greg Clayton95d87902011-11-11 03:16:25 +00003984 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3985 continue;
3986
3987 Type *matching_type = ResolveType (dwarf_cu, die);
3988 if (matching_type)
3989 {
3990 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003991 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00003992 if (types.GetSize() >= max_matches)
3993 break;
3994 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00003995 }
Greg Clayton95d87902011-11-11 03:16:25 +00003996 else
3997 {
3998 if (m_using_apple_tables)
3999 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004000 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4001 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004002 }
4003 }
4004
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004005 }
Greg Clayton437a1352012-04-09 22:43:43 +00004006 const uint32_t num_matches = types.GetSize() - initial_types_size;
4007 if (log && num_matches)
4008 {
4009 if (namespace_decl)
4010 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004011 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004012 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u",
4013 name.GetCString(),
4014 namespace_decl->GetNamespaceDecl(),
4015 namespace_decl->GetQualifiedName().c_str(),
4016 append,
4017 max_matches,
4018 num_matches);
4019 }
4020 else
4021 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004022 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004023 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u",
4024 name.GetCString(),
4025 append,
4026 max_matches,
4027 num_matches);
4028 }
4029 }
4030 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004031 }
Greg Clayton7f995132011-10-04 22:41:51 +00004032 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004033}
4034
4035
Greg Clayton526e5af2010-11-13 03:52:47 +00004036ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00004037SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00004038 const ConstString &name,
4039 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004040{
Greg Clayton5160ce52013-03-27 23:08:40 +00004041 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00004042
4043 if (log)
4044 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004045 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00004046 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
4047 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00004048 }
Sean Callanan213fdb82011-10-13 01:49:10 +00004049
4050 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00004051 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00004052
Greg Clayton526e5af2010-11-13 03:52:47 +00004053 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004054 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00004055 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00004056 {
Greg Clayton7f995132011-10-04 22:41:51 +00004057 DIEArray die_offsets;
4058
Greg Clayton526e5af2010-11-13 03:52:47 +00004059 // Index if we already haven't to make sure the compile units
4060 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00004061 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004062 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004063 if (m_apple_namespaces_ap.get())
4064 {
4065 const char *name_cstr = name.GetCString();
4066 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
4067 }
Greg Clayton7f995132011-10-04 22:41:51 +00004068 }
4069 else
4070 {
4071 if (!m_indexed)
4072 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00004073
Greg Clayton7f995132011-10-04 22:41:51 +00004074 m_namespace_index.Find (name, die_offsets);
4075 }
Greg Claytond4a2b372011-09-12 23:21:58 +00004076
4077 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00004078 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00004079 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00004080 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00004081 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004082 DWARFDebugInfo* debug_info = DebugInfo();
4083 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00004084 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004085 const dw_offset_t die_offset = die_offsets[i];
4086 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00004087
Greg Clayton95d87902011-11-11 03:16:25 +00004088 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00004089 {
Greg Clayton95d87902011-11-11 03:16:25 +00004090 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
4091 continue;
4092
4093 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
4094 if (clang_namespace_decl)
4095 {
4096 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
4097 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
Greg Claytond1767f02011-12-08 02:13:16 +00004098 break;
Greg Clayton95d87902011-11-11 03:16:25 +00004099 }
Greg Claytond4a2b372011-09-12 23:21:58 +00004100 }
Greg Clayton95d87902011-11-11 03:16:25 +00004101 else
4102 {
4103 if (m_using_apple_tables)
4104 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004105 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
4106 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004107 }
4108 }
4109
Greg Clayton526e5af2010-11-13 03:52:47 +00004110 }
4111 }
Greg Clayton96d7d742010-11-10 23:42:09 +00004112 }
Greg Clayton437a1352012-04-09 22:43:43 +00004113 if (log && namespace_decl.GetNamespaceDecl())
4114 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004115 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004116 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"",
4117 name.GetCString(),
4118 namespace_decl.GetNamespaceDecl(),
4119 namespace_decl.GetQualifiedName().c_str());
4120 }
4121
Greg Clayton526e5af2010-11-13 03:52:47 +00004122 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004123}
4124
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004125uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004126SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004127{
4128 // Remember how many sc_list are in the list before we search in case
4129 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004130 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004131
4132 const uint32_t num_die_offsets = die_offsets.size();
4133 // Parse all of the types we found from the pubtypes matches
4134 uint32_t i;
4135 uint32_t num_matches = 0;
4136 for (i = 0; i < num_die_offsets; ++i)
4137 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004138 Type *matching_type = ResolveTypeUID (die_offsets[i]);
4139 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004140 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004141 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00004142 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004143 ++num_matches;
4144 if (num_matches >= max_matches)
4145 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004146 }
4147 }
4148
4149 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004150 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004151}
4152
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004153
4154size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00004155SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
4156 clang::DeclContext *containing_decl_ctx,
Greg Clayton5113dc82011-08-12 06:47:54 +00004157 DWARFCompileUnit* dwarf_cu,
4158 const DWARFDebugInfoEntry *parent_die,
4159 bool skip_artificial,
4160 bool &is_static,
4161 TypeList* type_list,
Greg Clayton57ee3062013-07-11 22:46:58 +00004162 std::vector<ClangASTType>& function_param_types,
Greg Clayton5113dc82011-08-12 06:47:54 +00004163 std::vector<clang::ParmVarDecl*>& function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004164 unsigned &type_quals,
4165 ClangASTContext::TemplateParameterInfos &template_param_infos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004166{
4167 if (parent_die == NULL)
4168 return 0;
4169
Greg Claytond88d7592010-09-15 08:33:30 +00004170 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
4171
Greg Clayton7fedea22010-11-16 02:10:54 +00004172 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004173 const DWARFDebugInfoEntry *die;
4174 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4175 {
4176 dw_tag_t tag = die->Tag();
4177 switch (tag)
4178 {
4179 case DW_TAG_formal_parameter:
4180 {
4181 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004182 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004183 if (num_attributes > 0)
4184 {
4185 const char *name = NULL;
4186 Declaration decl;
4187 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00004188 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004189 // one of None, Auto, Register, Extern, Static, PrivateExtern
4190
Sean Callanane2ef6e32010-09-23 03:01:22 +00004191 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004192 uint32_t i;
4193 for (i=0; i<num_attributes; ++i)
4194 {
4195 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4196 DWARFFormValue form_value;
4197 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4198 {
4199 switch (attr)
4200 {
4201 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4202 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4203 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4204 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
4205 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00004206 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004207 case DW_AT_location:
4208 // if (form_value.BlockData())
4209 // {
Ed Masteeeae7212013-10-24 20:43:47 +00004210 // const DWARFDataExtractor& debug_info_data = debug_info();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004211 // uint32_t block_length = form_value.Unsigned();
Ed Masteeeae7212013-10-24 20:43:47 +00004212 // DWARFDataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004213 // }
4214 // else
4215 // {
4216 // }
4217 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004218 case DW_AT_const_value:
4219 case DW_AT_default_value:
4220 case DW_AT_description:
4221 case DW_AT_endianity:
4222 case DW_AT_is_optional:
4223 case DW_AT_segment:
4224 case DW_AT_variable_parameter:
4225 default:
4226 case DW_AT_abstract_origin:
4227 case DW_AT_sibling:
4228 break;
4229 }
4230 }
4231 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00004232
Greg Clayton0fffff52010-09-24 05:15:53 +00004233 bool skip = false;
4234 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004235 {
Greg Clayton0fffff52010-09-24 05:15:53 +00004236 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00004237 {
4238 // In order to determine if a C++ member function is
4239 // "const" we have to look at the const-ness of "this"...
4240 // Ugly, but that
4241 if (arg_idx == 0)
4242 {
Greg Claytonf0705c82011-10-22 03:33:13 +00004243 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00004244 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004245 // Often times compilers omit the "this" name for the
4246 // specification DIEs, so we can't rely upon the name
4247 // being in the formal parameter DIE...
4248 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00004249 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004250 Type *this_type = ResolveTypeUID (param_type_die_offset);
4251 if (this_type)
4252 {
4253 uint32_t encoding_mask = this_type->GetEncodingMask();
4254 if (encoding_mask & Type::eEncodingIsPointerUID)
4255 {
4256 is_static = false;
4257
4258 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
4259 type_quals |= clang::Qualifiers::Const;
4260 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
4261 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00004262 }
4263 }
4264 }
4265 }
4266 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004267 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00004268 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004269 else
4270 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004271
Greg Clayton0fffff52010-09-24 05:15:53 +00004272 // HACK: Objective C formal parameters "self" and "_cmd"
4273 // are not marked as artificial in the DWARF...
Greg Clayton53eb1c22012-04-02 22:59:12 +00004274 CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
4275 if (comp_unit)
Greg Clayton0fffff52010-09-24 05:15:53 +00004276 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004277 switch (comp_unit->GetLanguage())
4278 {
4279 case eLanguageTypeObjC:
4280 case eLanguageTypeObjC_plus_plus:
4281 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
4282 skip = true;
4283 break;
4284 default:
4285 break;
4286 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004287 }
4288 }
4289 }
4290
4291 if (!skip)
4292 {
4293 Type *type = ResolveTypeUID(param_type_die_offset);
4294 if (type)
4295 {
Greg Claytonc93237c2010-10-01 20:48:32 +00004296 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00004297
Greg Clayton42ce2f32011-12-12 21:50:19 +00004298 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
4299 type->GetClangForwardType(),
4300 storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00004301 assert(param_var_decl);
4302 function_param_decls.push_back(param_var_decl);
Sean Callanan60217122012-04-13 00:10:03 +00004303
Greg Claytond0029442013-03-27 01:48:02 +00004304 GetClangASTContext().SetMetadataAsUserID (param_var_decl, MakeUserID(die->GetOffset()));
Greg Clayton0fffff52010-09-24 05:15:53 +00004305 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004306 }
4307 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004308 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004309 }
4310 break;
4311
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004312 case DW_TAG_template_type_parameter:
4313 case DW_TAG_template_value_parameter:
4314 ParseTemplateDIE (dwarf_cu, die,template_param_infos);
4315 break;
4316
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004317 default:
4318 break;
4319 }
4320 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004321 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004322}
4323
4324size_t
4325SymbolFileDWARF::ParseChildEnumerators
4326(
4327 const SymbolContext& sc,
Greg Clayton57ee3062013-07-11 22:46:58 +00004328 lldb_private::ClangASTType &clang_type,
Greg Clayton3e067532013-03-05 23:54:39 +00004329 bool is_signed,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004330 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00004331 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004332 const DWARFDebugInfoEntry *parent_die
4333)
4334{
4335 if (parent_die == NULL)
4336 return 0;
4337
4338 size_t enumerators_added = 0;
4339 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00004340 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
4341
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004342 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4343 {
4344 const dw_tag_t tag = die->Tag();
4345 if (tag == DW_TAG_enumerator)
4346 {
4347 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004348 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004349 if (num_child_attributes > 0)
4350 {
4351 const char *name = NULL;
4352 bool got_value = false;
4353 int64_t enum_value = 0;
4354 Declaration decl;
4355
4356 uint32_t i;
4357 for (i=0; i<num_child_attributes; ++i)
4358 {
4359 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4360 DWARFFormValue form_value;
4361 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4362 {
4363 switch (attr)
4364 {
4365 case DW_AT_const_value:
4366 got_value = true;
Greg Clayton3e067532013-03-05 23:54:39 +00004367 if (is_signed)
4368 enum_value = form_value.Signed();
4369 else
4370 enum_value = form_value.Unsigned();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004371 break;
4372
4373 case DW_AT_name:
4374 name = form_value.AsCString(&get_debug_str_data());
4375 break;
4376
4377 case DW_AT_description:
4378 default:
4379 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4380 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4381 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4382 case DW_AT_sibling:
4383 break;
4384 }
4385 }
4386 }
4387
4388 if (name && name[0] && got_value)
4389 {
Greg Clayton57ee3062013-07-11 22:46:58 +00004390 clang_type.AddEnumerationValueToEnumerationType (clang_type.GetEnumerationIntegerType(),
4391 decl,
4392 name,
4393 enum_value,
4394 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004395 ++enumerators_added;
4396 }
4397 }
4398 }
4399 }
4400 return enumerators_added;
4401}
4402
4403void
4404SymbolFileDWARF::ParseChildArrayInfo
4405(
4406 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004407 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004408 const DWARFDebugInfoEntry *parent_die,
4409 int64_t& first_index,
4410 std::vector<uint64_t>& element_orders,
4411 uint32_t& byte_stride,
4412 uint32_t& bit_stride
4413)
4414{
4415 if (parent_die == NULL)
4416 return;
4417
4418 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00004419 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004420 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4421 {
4422 const dw_tag_t tag = die->Tag();
4423 switch (tag)
4424 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004425 case DW_TAG_subrange_type:
4426 {
4427 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004428 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004429 if (num_child_attributes > 0)
4430 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004431 uint64_t num_elements = 0;
4432 uint64_t lower_bound = 0;
4433 uint64_t upper_bound = 0;
Greg Clayton4ef877f2012-12-06 02:33:54 +00004434 bool upper_bound_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004435 uint32_t i;
4436 for (i=0; i<num_child_attributes; ++i)
4437 {
4438 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4439 DWARFFormValue form_value;
4440 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4441 {
4442 switch (attr)
4443 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004444 case DW_AT_name:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004445 break;
4446
4447 case DW_AT_count:
4448 num_elements = form_value.Unsigned();
4449 break;
4450
4451 case DW_AT_bit_stride:
4452 bit_stride = form_value.Unsigned();
4453 break;
4454
4455 case DW_AT_byte_stride:
4456 byte_stride = form_value.Unsigned();
4457 break;
4458
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004459 case DW_AT_lower_bound:
4460 lower_bound = form_value.Unsigned();
4461 break;
4462
4463 case DW_AT_upper_bound:
Greg Clayton4ef877f2012-12-06 02:33:54 +00004464 upper_bound_valid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004465 upper_bound = form_value.Unsigned();
4466 break;
4467
4468 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004469 case DW_AT_abstract_origin:
4470 case DW_AT_accessibility:
4471 case DW_AT_allocated:
4472 case DW_AT_associated:
4473 case DW_AT_data_location:
4474 case DW_AT_declaration:
4475 case DW_AT_description:
4476 case DW_AT_sibling:
4477 case DW_AT_threads_scaled:
4478 case DW_AT_type:
4479 case DW_AT_visibility:
4480 break;
4481 }
4482 }
4483 }
4484
Greg Claytone6a07792012-12-05 21:59:39 +00004485 if (num_elements == 0)
4486 {
Greg Clayton4ef877f2012-12-06 02:33:54 +00004487 if (upper_bound_valid && upper_bound >= lower_bound)
Greg Claytone6a07792012-12-05 21:59:39 +00004488 num_elements = upper_bound - lower_bound + 1;
4489 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004490
Sean Callananec979ba2012-10-22 23:56:48 +00004491 element_orders.push_back (num_elements);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004492 }
4493 }
4494 break;
4495 }
4496 }
4497}
4498
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004499TypeSP
Greg Clayton53eb1c22012-04-02 22:59:12 +00004500SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004501{
4502 TypeSP type_sp;
4503 if (die != NULL)
4504 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004505 assert(dwarf_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00004506 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004507 if (type_ptr == NULL)
4508 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004509 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu);
Greg Claytonca512b32011-01-14 04:54:56 +00004510 assert (lldb_cu);
4511 SymbolContext sc(lldb_cu);
Greg Clayton53eb1c22012-04-02 22:59:12 +00004512 type_sp = ParseType(sc, dwarf_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004513 }
4514 else if (type_ptr != DIE_IS_BEING_PARSED)
4515 {
4516 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00004517 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004518 }
4519
4520 }
4521 return type_sp;
4522}
4523
4524clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00004525SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004526{
4527 if (die_offset != DW_INVALID_OFFSET)
4528 {
4529 DWARFCompileUnitSP cu_sp;
4530 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004531 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004532 }
4533 return NULL;
4534}
4535
Sean Callanan72e49402011-08-05 23:43:37 +00004536clang::DeclContext *
4537SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
4538{
4539 if (die_offset != DW_INVALID_OFFSET)
4540 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004541 DWARFDebugInfo* debug_info = DebugInfo();
4542 if (debug_info)
4543 {
4544 DWARFCompileUnitSP cu_sp;
4545 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
4546 if (die)
4547 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
4548 }
Sean Callanan72e49402011-08-05 23:43:37 +00004549 }
4550 return NULL;
4551}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004552
Greg Clayton96d7d742010-11-10 23:42:09 +00004553clang::NamespaceDecl *
Greg Clayton53eb1c22012-04-02 22:59:12 +00004554SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die)
Greg Clayton96d7d742010-11-10 23:42:09 +00004555{
Greg Clayton030a2042011-10-14 21:34:45 +00004556 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00004557 {
Greg Clayton030a2042011-10-14 21:34:45 +00004558 // See if we already parsed this namespace DIE and associated it with a
4559 // uniqued namespace declaration
4560 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
4561 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004562 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00004563 else
4564 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004565 const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL);
4566 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00004567 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
Greg Clayton5160ce52013-03-27 23:08:40 +00004568 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton9d3d6882011-10-31 23:51:19 +00004569 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00004570 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00004571 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00004572 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004573 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00004574 "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 +00004575 GetClangASTContext().getASTContext(),
4576 MakeUserID(die->GetOffset()),
4577 namespace_name,
4578 namespace_decl,
4579 namespace_decl->getOriginalNamespace());
Greg Clayton030a2042011-10-14 21:34:45 +00004580 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004581 else
4582 {
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 (anonymous) => clang::NamespaceDecl *%p (original = %p)",
Greg Claytone38a5ed2012-01-05 03:57:59 +00004585 GetClangASTContext().getASTContext(),
4586 MakeUserID(die->GetOffset()),
4587 namespace_decl,
4588 namespace_decl->getOriginalNamespace());
Greg Clayton9d3d6882011-10-31 23:51:19 +00004589 }
Greg Clayton030a2042011-10-14 21:34:45 +00004590 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004591
4592 if (namespace_decl)
4593 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
4594 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004595 }
4596 }
4597 return NULL;
4598}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004599
4600clang::DeclContext *
Greg Claytoncab36a32011-12-08 05:16:30 +00004601SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Sean Callanan72e49402011-08-05 23:43:37 +00004602{
Greg Clayton5cf58b92011-10-05 22:22:08 +00004603 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4604 if (clang_decl_ctx)
4605 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004606 // If this DIE has a specification, or an abstract origin, then trace to those.
4607
Greg Claytoncab36a32011-12-08 05:16:30 +00004608 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004609 if (die_offset != DW_INVALID_OFFSET)
4610 return GetClangDeclContextForDIEOffset (sc, die_offset);
4611
Greg Claytoncab36a32011-12-08 05:16:30 +00004612 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004613 if (die_offset != DW_INVALID_OFFSET)
4614 return GetClangDeclContextForDIEOffset (sc, die_offset);
4615
Greg Clayton5160ce52013-03-27 23:08:40 +00004616 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00004617 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004618 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 +00004619 // This is the DIE we want. Parse it, then query our map.
Greg Claytoncab36a32011-12-08 05:16:30 +00004620 bool assert_not_being_parsed = true;
4621 ResolveTypeUID (cu, die, assert_not_being_parsed);
4622
Greg Clayton5cf58b92011-10-05 22:22:08 +00004623 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4624
4625 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004626}
4627
4628clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00004629SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004630{
Greg Claytonca512b32011-01-14 04:54:56 +00004631 if (m_clang_tu_decl == NULL)
4632 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004633
Greg Clayton2bc22f82011-09-30 03:20:47 +00004634 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004635
4636 if (decl_ctx_die_copy)
4637 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00004638
4639 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004640 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00004641
Greg Clayton2bc22f82011-09-30 03:20:47 +00004642 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
4643 if (pos != m_die_to_decl_ctx.end())
4644 return pos->second;
4645
4646 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004647 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004648 case DW_TAG_compile_unit:
4649 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004650
Greg Clayton2bc22f82011-09-30 03:20:47 +00004651 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00004652 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00004653 break;
4654
4655 case DW_TAG_structure_type:
4656 case DW_TAG_union_type:
4657 case DW_TAG_class_type:
4658 {
4659 Type* type = ResolveType (cu, decl_ctx_die);
4660 if (type)
4661 {
Greg Clayton57ee3062013-07-11 22:46:58 +00004662 clang::DeclContext *decl_ctx = type->GetClangForwardType().GetDeclContextForType ();
Greg Clayton2bc22f82011-09-30 03:20:47 +00004663 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00004664 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004665 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
4666 if (decl_ctx)
4667 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00004668 }
4669 }
Greg Claytonca512b32011-01-14 04:54:56 +00004670 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00004671 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004672
Greg Clayton2bc22f82011-09-30 03:20:47 +00004673 default:
4674 break;
Greg Claytonca512b32011-01-14 04:54:56 +00004675 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004676 }
Greg Clayton7a345282010-11-09 23:46:37 +00004677 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004678}
4679
Greg Clayton2bc22f82011-09-30 03:20:47 +00004680
4681const DWARFDebugInfoEntry *
4682SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4683{
4684 if (cu && die)
4685 {
4686 const DWARFDebugInfoEntry * const decl_die = die;
4687
4688 while (die != NULL)
4689 {
4690 // If this is the original DIE that we are searching for a declaration
4691 // for, then don't look in the cache as we don't want our own decl
4692 // context to be our decl context...
4693 if (decl_die != die)
4694 {
4695 switch (die->Tag())
4696 {
4697 case DW_TAG_compile_unit:
4698 case DW_TAG_namespace:
4699 case DW_TAG_structure_type:
4700 case DW_TAG_union_type:
4701 case DW_TAG_class_type:
4702 return die;
4703
4704 default:
4705 break;
4706 }
4707 }
4708
4709 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4710 if (die_offset != DW_INVALID_OFFSET)
4711 {
4712 DWARFCompileUnit *spec_cu = cu;
4713 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
4714 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
4715 if (spec_die_decl_ctx_die)
4716 return spec_die_decl_ctx_die;
4717 }
4718
4719 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
4720 if (die_offset != DW_INVALID_OFFSET)
4721 {
4722 DWARFCompileUnit *abs_cu = cu;
4723 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
4724 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
4725 if (abs_die_decl_ctx_die)
4726 return abs_die_decl_ctx_die;
4727 }
4728
4729 die = die->GetParent();
4730 }
4731 }
4732 return NULL;
4733}
4734
4735
Greg Clayton901c5ca2011-12-03 04:40:03 +00004736Symbol *
4737SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
4738{
4739 Symbol *objc_class_symbol = NULL;
4740 if (m_obj_file)
4741 {
Greg Clayton3046e662013-07-10 01:23:25 +00004742 Symtab *symtab = m_obj_file->GetSymtab ();
Greg Clayton901c5ca2011-12-03 04:40:03 +00004743 if (symtab)
4744 {
4745 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
4746 eSymbolTypeObjCClass,
4747 Symtab::eDebugNo,
4748 Symtab::eVisibilityAny);
4749 }
4750 }
4751 return objc_class_symbol;
4752}
4753
Greg Claytonc7f03b62012-01-12 04:33:28 +00004754// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
4755// then we can end up looking through all class types for a complete type and never find
4756// the full definition. We need to know if this attribute is supported, so we determine
4757// this here and cache th result. We also need to worry about the debug map DWARF file
4758// if we are doing darwin DWARF in .o file debugging.
4759bool
4760SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
4761{
4762 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
4763 {
4764 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
4765 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
4766 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4767 else
4768 {
4769 DWARFDebugInfo* debug_info = DebugInfo();
4770 const uint32_t num_compile_units = GetNumCompileUnits();
4771 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
4772 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004773 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
4774 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004775 {
4776 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4777 break;
4778 }
4779 }
4780 }
Greg Clayton1f746072012-08-29 21:13:06 +00004781 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004782 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
4783 }
4784 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
4785}
Greg Clayton901c5ca2011-12-03 04:40:03 +00004786
4787// This function can be used when a DIE is found that is a forward declaration
4788// DIE and we want to try and find a type that has the complete definition.
4789TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00004790SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
4791 const ConstString &type_name,
4792 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00004793{
4794
4795 TypeSP type_sp;
4796
Greg Claytonc7f03b62012-01-12 04:33:28 +00004797 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00004798 return type_sp;
4799
4800 DIEArray die_offsets;
4801
4802 if (m_using_apple_tables)
4803 {
4804 if (m_apple_types_ap.get())
4805 {
4806 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00004807 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004808 }
4809 }
4810 else
4811 {
4812 if (!m_indexed)
4813 Index ();
4814
4815 m_type_index.Find (type_name, die_offsets);
4816 }
4817
Greg Clayton901c5ca2011-12-03 04:40:03 +00004818 const size_t num_matches = die_offsets.size();
4819
Greg Clayton901c5ca2011-12-03 04:40:03 +00004820 DWARFCompileUnit* type_cu = NULL;
4821 const DWARFDebugInfoEntry* type_die = NULL;
4822 if (num_matches)
4823 {
4824 DWARFDebugInfo* debug_info = DebugInfo();
4825 for (size_t i=0; i<num_matches; ++i)
4826 {
4827 const dw_offset_t die_offset = die_offsets[i];
4828 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4829
4830 if (type_die)
4831 {
4832 bool try_resolving_type = false;
4833
4834 // Don't try and resolve the DIE we are looking for with the DIE itself!
4835 if (type_die != die)
4836 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004837 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00004838 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004839 case DW_TAG_class_type:
4840 case DW_TAG_structure_type:
4841 try_resolving_type = true;
4842 break;
4843 default:
4844 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00004845 }
4846 }
4847
4848 if (try_resolving_type)
4849 {
Ed Maste4c24b122013-10-17 20:13:14 +00004850 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
4851 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004852
4853 if (try_resolving_type)
4854 {
4855 Type *resolved_type = ResolveType (type_cu, type_die, false);
4856 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4857 {
Ed Mastea0191d12013-10-17 20:42:56 +00004858 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 +00004859 MakeUserID(die->GetOffset()),
Greg Clayton901c5ca2011-12-03 04:40:03 +00004860 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4861 MakeUserID(type_die->GetOffset()),
4862 MakeUserID(type_cu->GetOffset()));
4863
Greg Claytonc7f03b62012-01-12 04:33:28 +00004864 if (die)
4865 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00004866 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00004867 break;
4868 }
4869 }
4870 }
4871 }
4872 else
4873 {
4874 if (m_using_apple_tables)
4875 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004876 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4877 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00004878 }
4879 }
4880
4881 }
4882 }
4883 return type_sp;
4884}
4885
Greg Claytona8022fa2012-04-24 21:22:41 +00004886
Greg Clayton80c26302012-02-05 06:12:47 +00004887//----------------------------------------------------------------------
4888// This function helps to ensure that the declaration contexts match for
4889// two different DIEs. Often times debug information will refer to a
4890// forward declaration of a type (the equivalent of "struct my_struct;".
4891// There will often be a declaration of that type elsewhere that has the
4892// full definition. When we go looking for the full type "my_struct", we
4893// will find one or more matches in the accelerator tables and we will
4894// then need to make sure the type was in the same declaration context
4895// as the original DIE. This function can efficiently compare two DIEs
4896// and will return true when the declaration context matches, and false
4897// when they don't.
4898//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00004899bool
4900SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
4901 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
4902{
Greg Claytona8022fa2012-04-24 21:22:41 +00004903 if (die1 == die2)
4904 return true;
4905
4906#if defined (LLDB_CONFIGURATION_DEBUG)
4907 // You can't and shouldn't call this function with a compile unit from
4908 // two different SymbolFileDWARF instances.
4909 assert (DebugInfo()->ContainsCompileUnit (cu1));
4910 assert (DebugInfo()->ContainsCompileUnit (cu2));
4911#endif
4912
Greg Clayton890ff562012-02-02 05:48:16 +00004913 DWARFDIECollection decl_ctx_1;
4914 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00004915 //The declaration DIE stack is a stack of the declaration context
4916 // DIEs all the way back to the compile unit. If a type "T" is
4917 // declared inside a class "B", and class "B" is declared inside
4918 // a class "A" and class "A" is in a namespace "lldb", and the
4919 // namespace is in a compile unit, there will be a stack of DIEs:
4920 //
4921 // [0] DW_TAG_class_type for "B"
4922 // [1] DW_TAG_class_type for "A"
4923 // [2] DW_TAG_namespace for "lldb"
4924 // [3] DW_TAG_compile_unit for the source file.
4925 //
4926 // We grab both contexts and make sure that everything matches
4927 // all the way back to the compiler unit.
4928
4929 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00004930 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004931 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00004932 // Make sure the context arrays have the same size, otherwise
4933 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00004934 const size_t count1 = decl_ctx_1.Size();
4935 const size_t count2 = decl_ctx_2.Size();
4936 if (count1 != count2)
4937 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00004938
4939 // Make sure the DW_TAG values match all the way back up the the
4940 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00004941 const DWARFDebugInfoEntry *decl_ctx_die1;
4942 const DWARFDebugInfoEntry *decl_ctx_die2;
4943 size_t i;
4944 for (i=0; i<count1; i++)
4945 {
4946 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4947 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4948 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
4949 return false;
4950 }
Greg Clayton890ff562012-02-02 05:48:16 +00004951#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00004952
4953 // Make sure the top item in the decl context die array is always
4954 // DW_TAG_compile_unit. If it isn't then something went wrong in
4955 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00004956 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00004957
Greg Clayton890ff562012-02-02 05:48:16 +00004958#endif
4959 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00004960 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00004961 for (i=0; i<count1 - 1; i++)
4962 {
4963 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4964 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4965 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004966 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00004967 // If the string was from a DW_FORM_strp, then the pointer will often
4968 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00004969 if (name1 == name2)
4970 continue;
4971
4972 // Name pointers are not equal, so only compare the strings
4973 // if both are not NULL.
4974 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00004975 {
Greg Clayton5569e642012-02-06 01:44:54 +00004976 // If the strings don't compare, we are done...
4977 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00004978 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00004979 }
4980 else
4981 {
4982 // One name was NULL while the other wasn't
4983 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00004984 }
4985 }
Greg Clayton80c26302012-02-05 06:12:47 +00004986 // We made it through all of the checks and the declaration contexts
4987 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00004988 return true;
4989}
Greg Clayton220a0072011-12-09 08:48:30 +00004990
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004991// This function can be used when a DIE is found that is a forward declaration
4992// DIE and we want to try and find a type that has the complete definition.
Greg Claytona8022fa2012-04-24 21:22:41 +00004993// "cu" and "die" must be from this SymbolFileDWARF
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004994TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00004995SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
Greg Clayton7f995132011-10-04 22:41:51 +00004996 const DWARFDebugInfoEntry *die,
4997 const ConstString &type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004998{
4999 TypeSP type_sp;
5000
Greg Claytona8022fa2012-04-24 21:22:41 +00005001#if defined (LLDB_CONFIGURATION_DEBUG)
5002 // You can't and shouldn't call this function with a compile unit from
5003 // another SymbolFileDWARF instance.
5004 assert (DebugInfo()->ContainsCompileUnit (cu));
5005#endif
5006
Greg Clayton1a65ae12011-01-25 23:55:37 +00005007 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005008 return type_sp;
5009
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005010 std::string qualified_name;
5011
Greg Clayton5160ce52013-03-27 23:08:40 +00005012 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005013 if (log)
5014 {
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005015 die->GetQualifiedName(this, cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00005016 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005017 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x (%s), name='%s')",
5018 die->GetOffset(),
5019 qualified_name.c_str(),
5020 type_name.GetCString());
5021 }
5022
Greg Clayton7f995132011-10-04 22:41:51 +00005023 DIEArray die_offsets;
5024
Greg Clayton97fbc342011-10-20 22:30:33 +00005025 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00005026 {
Greg Clayton97fbc342011-10-20 22:30:33 +00005027 if (m_apple_types_ap.get())
5028 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005029 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
5030 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
5031 if (has_tag && has_qualified_name_hash)
Greg Claytond1767f02011-12-08 02:13:16 +00005032 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005033 if (qualified_name.empty())
5034 die->GetQualifiedName(this, cu, qualified_name);
5035
5036 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name.c_str());
5037 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005038 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005039 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), die->Tag(), qualified_name_hash, die_offsets);
5040 }
5041 else if (has_tag > 1)
5042 {
5043 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005044 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
Greg Claytonae920b62012-01-06 00:17:16 +00005045 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets);
Greg Claytond1767f02011-12-08 02:13:16 +00005046 }
5047 else
5048 {
5049 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
5050 }
Greg Clayton97fbc342011-10-20 22:30:33 +00005051 }
Greg Clayton7f995132011-10-04 22:41:51 +00005052 }
5053 else
5054 {
5055 if (!m_indexed)
5056 Index ();
5057
5058 m_type_index.Find (type_name, die_offsets);
5059 }
Greg Clayton7f995132011-10-04 22:41:51 +00005060
5061 const size_t num_matches = die_offsets.size();
Greg Clayton69974892010-12-03 21:42:06 +00005062
Greg Clayton934cb052011-12-03 00:27:05 +00005063 const dw_tag_t die_tag = die->Tag();
Greg Claytond4a2b372011-09-12 23:21:58 +00005064
5065 DWARFCompileUnit* type_cu = NULL;
5066 const DWARFDebugInfoEntry* type_die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00005067 if (num_matches)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005068 {
Greg Claytond4a2b372011-09-12 23:21:58 +00005069 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005070 for (size_t i=0; i<num_matches; ++i)
5071 {
Greg Claytond4a2b372011-09-12 23:21:58 +00005072 const dw_offset_t die_offset = die_offsets[i];
5073 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005074
Greg Clayton95d87902011-11-11 03:16:25 +00005075 if (type_die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005076 {
Greg Clayton934cb052011-12-03 00:27:05 +00005077 bool try_resolving_type = false;
5078
5079 // Don't try and resolve the DIE we are looking for with the DIE itself!
5080 if (type_die != die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005081 {
Greg Clayton934cb052011-12-03 00:27:05 +00005082 const dw_tag_t type_die_tag = type_die->Tag();
5083 // Make sure the tags match
5084 if (type_die_tag == die_tag)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005085 {
Greg Clayton934cb052011-12-03 00:27:05 +00005086 // The tags match, lets try resolving this type
5087 try_resolving_type = true;
5088 }
5089 else
5090 {
5091 // The tags don't match, but we need to watch our for a
5092 // forward declaration for a struct and ("struct foo")
5093 // ends up being a class ("class foo { ... };") or
5094 // vice versa.
5095 switch (type_die_tag)
Greg Clayton95d87902011-11-11 03:16:25 +00005096 {
Greg Clayton934cb052011-12-03 00:27:05 +00005097 case DW_TAG_class_type:
5098 // We had a "class foo", see if we ended up with a "struct foo { ... };"
5099 try_resolving_type = (die_tag == DW_TAG_structure_type);
5100 break;
5101 case DW_TAG_structure_type:
5102 // We had a "struct foo", see if we ended up with a "class foo { ... };"
5103 try_resolving_type = (die_tag == DW_TAG_class_type);
5104 break;
5105 default:
5106 // Tags don't match, don't event try to resolve
5107 // using this type whose name matches....
Greg Clayton95d87902011-11-11 03:16:25 +00005108 break;
5109 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005110 }
5111 }
Greg Clayton934cb052011-12-03 00:27:05 +00005112
5113 if (try_resolving_type)
5114 {
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005115 if (log)
5116 {
5117 std::string qualified_name;
5118 type_die->GetQualifiedName(this, cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00005119 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005120 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') trying die=0x%8.8x (%s)",
5121 die->GetOffset(),
5122 type_name.GetCString(),
5123 type_die->GetOffset(),
5124 qualified_name.c_str());
5125 }
5126
Greg Clayton890ff562012-02-02 05:48:16 +00005127 // Make sure the decl contexts match all the way up
5128 if (DIEDeclContextsMatch(cu, die, type_cu, type_die))
Greg Clayton934cb052011-12-03 00:27:05 +00005129 {
Greg Clayton890ff562012-02-02 05:48:16 +00005130 Type *resolved_type = ResolveType (type_cu, type_die, false);
5131 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5132 {
Daniel Malead01b2952012-11-29 21:49:15 +00005133 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 +00005134 MakeUserID(die->GetOffset()),
Ed Mastea0191d12013-10-17 20:42:56 +00005135 MakeUserID(cu->GetOffset()),
Greg Clayton890ff562012-02-02 05:48:16 +00005136 m_obj_file->GetFileSpec().GetFilename().AsCString(),
5137 MakeUserID(type_die->GetOffset()),
5138 MakeUserID(type_cu->GetOffset()));
5139
5140 m_die_to_type[die] = resolved_type;
Greg Claytonff7692a2012-02-02 18:16:59 +00005141 type_sp = resolved_type->shared_from_this();
Greg Clayton890ff562012-02-02 05:48:16 +00005142 break;
5143 }
Greg Clayton934cb052011-12-03 00:27:05 +00005144 }
5145 }
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005146 else
5147 {
5148 if (log)
5149 {
5150 std::string qualified_name;
5151 type_die->GetQualifiedName(this, cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00005152 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005153 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') ignoring die=0x%8.8x (%s)",
5154 die->GetOffset(),
5155 type_name.GetCString(),
5156 type_die->GetOffset(),
5157 qualified_name.c_str());
5158 }
5159 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005160 }
Greg Clayton95d87902011-11-11 03:16:25 +00005161 else
5162 {
5163 if (m_using_apple_tables)
5164 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005165 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5166 die_offset, type_name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00005167 }
5168 }
5169
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005170 }
5171 }
5172 return type_sp;
5173}
5174
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005175TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00005176SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx)
5177{
5178 TypeSP type_sp;
5179
5180 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
5181 if (dwarf_decl_ctx_count > 0)
5182 {
5183 const ConstString type_name(dwarf_decl_ctx[0].name);
5184 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
5185
5186 if (type_name)
5187 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005188 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
Greg Claytona8022fa2012-04-24 21:22:41 +00005189 if (log)
5190 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005191 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005192 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')",
5193 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5194 dwarf_decl_ctx.GetQualifiedName());
5195 }
5196
5197 DIEArray die_offsets;
5198
5199 if (m_using_apple_tables)
5200 {
5201 if (m_apple_types_ap.get())
5202 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005203 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
5204 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
5205 if (has_tag && has_qualified_name_hash)
Greg Claytona8022fa2012-04-24 21:22:41 +00005206 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005207 const char *qualified_name = dwarf_decl_ctx.GetQualifiedName();
5208 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name);
5209 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005210 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005211 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets);
5212 }
5213 else if (has_tag)
5214 {
5215 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005216 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
Greg Claytona8022fa2012-04-24 21:22:41 +00005217 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets);
5218 }
5219 else
5220 {
5221 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
5222 }
5223 }
5224 }
5225 else
5226 {
5227 if (!m_indexed)
5228 Index ();
5229
5230 m_type_index.Find (type_name, die_offsets);
5231 }
5232
5233 const size_t num_matches = die_offsets.size();
5234
5235
5236 DWARFCompileUnit* type_cu = NULL;
5237 const DWARFDebugInfoEntry* type_die = NULL;
5238 if (num_matches)
5239 {
5240 DWARFDebugInfo* debug_info = DebugInfo();
5241 for (size_t i=0; i<num_matches; ++i)
5242 {
5243 const dw_offset_t die_offset = die_offsets[i];
5244 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
5245
5246 if (type_die)
5247 {
5248 bool try_resolving_type = false;
5249
5250 // Don't try and resolve the DIE we are looking for with the DIE itself!
5251 const dw_tag_t type_tag = type_die->Tag();
5252 // Make sure the tags match
5253 if (type_tag == tag)
5254 {
5255 // The tags match, lets try resolving this type
5256 try_resolving_type = true;
5257 }
5258 else
5259 {
5260 // The tags don't match, but we need to watch our for a
5261 // forward declaration for a struct and ("struct foo")
5262 // ends up being a class ("class foo { ... };") or
5263 // vice versa.
5264 switch (type_tag)
5265 {
5266 case DW_TAG_class_type:
5267 // We had a "class foo", see if we ended up with a "struct foo { ... };"
5268 try_resolving_type = (tag == DW_TAG_structure_type);
5269 break;
5270 case DW_TAG_structure_type:
5271 // We had a "struct foo", see if we ended up with a "class foo { ... };"
5272 try_resolving_type = (tag == DW_TAG_class_type);
5273 break;
5274 default:
5275 // Tags don't match, don't event try to resolve
5276 // using this type whose name matches....
5277 break;
5278 }
5279 }
5280
5281 if (try_resolving_type)
5282 {
5283 DWARFDeclContext type_dwarf_decl_ctx;
5284 type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx);
5285
5286 if (log)
5287 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005288 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005289 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)",
5290 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5291 dwarf_decl_ctx.GetQualifiedName(),
5292 type_die->GetOffset(),
5293 type_dwarf_decl_ctx.GetQualifiedName());
5294 }
5295
5296 // Make sure the decl contexts match all the way up
5297 if (dwarf_decl_ctx == type_dwarf_decl_ctx)
5298 {
5299 Type *resolved_type = ResolveType (type_cu, type_die, false);
5300 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5301 {
5302 type_sp = resolved_type->shared_from_this();
5303 break;
5304 }
5305 }
5306 }
5307 else
5308 {
5309 if (log)
5310 {
5311 std::string qualified_name;
5312 type_die->GetQualifiedName(this, type_cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00005313 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005314 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)",
5315 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5316 dwarf_decl_ctx.GetQualifiedName(),
5317 type_die->GetOffset(),
5318 qualified_name.c_str());
5319 }
5320 }
5321 }
5322 else
5323 {
5324 if (m_using_apple_tables)
5325 {
5326 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5327 die_offset, type_name.GetCString());
5328 }
5329 }
5330
5331 }
5332 }
5333 }
5334 }
5335 return type_sp;
5336}
5337
Greg Clayton4116e932012-05-15 02:33:01 +00005338bool
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005339SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005340 Type *class_type,
Greg Clayton4116e932012-05-15 02:33:01 +00005341 DWARFCompileUnit* src_cu,
5342 const DWARFDebugInfoEntry *src_class_die,
5343 DWARFCompileUnit* dst_cu,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005344 const DWARFDebugInfoEntry *dst_class_die,
5345 llvm::SmallVectorImpl <const DWARFDebugInfoEntry *> &failures)
Greg Clayton4116e932012-05-15 02:33:01 +00005346{
5347 if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die)
5348 return false;
5349 if (src_class_die->Tag() != dst_class_die->Tag())
5350 return false;
5351
5352 // We need to complete the class type so we can get all of the method types
5353 // parsed so we can then unique those types to their equivalent counterparts
5354 // in "dst_cu" and "dst_class_die"
5355 class_type->GetClangFullType();
5356
5357 const DWARFDebugInfoEntry *src_die;
5358 const DWARFDebugInfoEntry *dst_die;
5359 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die;
5360 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die;
Greg Clayton65ec1032012-11-12 21:27:20 +00005361 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial;
5362 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial;
Greg Clayton4116e932012-05-15 02:33:01 +00005363 for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling())
5364 {
5365 if (src_die->Tag() == DW_TAG_subprogram)
5366 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005367 // Make sure this is a declaration and not a concrete instance by looking
5368 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5369 // are placed inside the class definitions and shouldn't be included in
5370 // the list of things are are tracking here.
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005371 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_declaration, 0) == 1)
Greg Clayton84afacd2012-11-07 23:09:32 +00005372 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005373 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton84afacd2012-11-07 23:09:32 +00005374 if (src_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005375 {
5376 ConstString src_const_name(src_name);
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005377 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0))
Greg Clayton65ec1032012-11-12 21:27:20 +00005378 src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die);
5379 else
5380 src_name_to_die.Append(src_const_name.GetCString(), src_die);
5381 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005382 }
Greg Clayton4116e932012-05-15 02:33:01 +00005383 }
5384 }
5385 for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling())
5386 {
5387 if (dst_die->Tag() == DW_TAG_subprogram)
5388 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005389 // Make sure this is a declaration and not a concrete instance by looking
5390 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5391 // are placed inside the class definitions and shouldn't be included in
5392 // the list of things are are tracking here.
5393 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1)
5394 {
5395 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5396 if (dst_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005397 {
5398 ConstString dst_const_name(dst_name);
5399 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0))
5400 dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die);
5401 else
5402 dst_name_to_die.Append(dst_const_name.GetCString(), dst_die);
5403 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005404 }
Greg Clayton4116e932012-05-15 02:33:01 +00005405 }
5406 }
5407 const uint32_t src_size = src_name_to_die.GetSize ();
5408 const uint32_t dst_size = dst_name_to_die.GetSize ();
Greg Clayton5160ce52013-03-27 23:08:40 +00005409 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005410
5411 // Is everything kosher so we can go through the members at top speed?
5412 bool fast_path = true;
5413
5414 if (src_size != dst_size)
Greg Clayton4116e932012-05-15 02:33:01 +00005415 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005416 if (src_size != 0 && dst_size != 0)
5417 {
5418 if (log)
5419 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)",
5420 src_class_die->GetOffset(),
5421 dst_class_die->GetOffset(),
5422 src_size,
5423 dst_size);
5424 }
5425
5426 fast_path = false;
5427 }
5428
5429 uint32_t idx;
5430
5431 if (fast_path)
5432 {
Greg Clayton4116e932012-05-15 02:33:01 +00005433 for (idx = 0; idx < src_size; ++idx)
5434 {
5435 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5436 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5437
5438 if (src_die->Tag() != dst_die->Tag())
5439 {
5440 if (log)
5441 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)",
5442 src_class_die->GetOffset(),
5443 dst_class_die->GetOffset(),
5444 src_die->GetOffset(),
5445 DW_TAG_value_to_name(src_die->Tag()),
5446 dst_die->GetOffset(),
5447 DW_TAG_value_to_name(src_die->Tag()));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005448 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005449 }
5450
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005451 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton4116e932012-05-15 02:33:01 +00005452 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5453
5454 // Make sure the names match
5455 if (src_name == dst_name || (strcmp (src_name, dst_name) == 0))
5456 continue;
5457
5458 if (log)
5459 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)",
5460 src_class_die->GetOffset(),
5461 dst_class_die->GetOffset(),
5462 src_die->GetOffset(),
5463 src_name,
5464 dst_die->GetOffset(),
5465 dst_name);
5466
Sean Callanan2367f8a2013-02-26 01:12:25 +00005467 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005468 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005469 }
Greg Clayton4116e932012-05-15 02:33:01 +00005470
Sean Callanan2367f8a2013-02-26 01:12:25 +00005471 // Now do the work of linking the DeclContexts and Types.
5472 if (fast_path)
5473 {
5474 // We can do this quickly. Just run across the tables index-for-index since
5475 // we know each node has matching names and tags.
Greg Clayton4116e932012-05-15 02:33:01 +00005476 for (idx = 0; idx < src_size; ++idx)
5477 {
5478 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5479 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5480
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005481 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Greg Clayton4116e932012-05-15 02:33:01 +00005482 if (src_decl_ctx)
5483 {
5484 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005485 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 +00005486 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5487 }
5488 else
5489 {
5490 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005491 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 +00005492 }
5493
5494 Type *src_child_type = m_die_to_type[src_die];
5495 if (src_child_type)
5496 {
5497 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00005498 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 +00005499 m_die_to_type[dst_die] = src_child_type;
5500 }
5501 else
5502 {
5503 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005504 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());
5505 }
5506 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005507 }
5508 else
5509 {
5510 // We must do this slowly. For each member of the destination, look
5511 // up a member in the source with the same name, check its tag, and
5512 // unique them if everything matches up. Report failures.
Greg Clayton65ec1032012-11-12 21:27:20 +00005513
Sean Callanan2367f8a2013-02-26 01:12:25 +00005514 if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty())
5515 {
5516 src_name_to_die.Sort();
Greg Clayton65ec1032012-11-12 21:27:20 +00005517
Sean Callanan2367f8a2013-02-26 01:12:25 +00005518 for (idx = 0; idx < dst_size; ++idx)
5519 {
5520 const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx);
5521 dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
5522 src_die = src_name_to_die.Find(dst_name, NULL);
5523
5524 if (src_die && (src_die->Tag() == dst_die->Tag()))
5525 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005526 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Sean Callanan2367f8a2013-02-26 01:12:25 +00005527 if (src_decl_ctx)
5528 {
5529 if (log)
5530 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
5531 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5532 }
5533 else
5534 {
5535 if (log)
5536 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());
5537 }
5538
5539 Type *src_child_type = m_die_to_type[src_die];
5540 if (src_child_type)
5541 {
5542 if (log)
5543 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());
5544 m_die_to_type[dst_die] = src_child_type;
5545 }
5546 else
5547 {
5548 if (log)
5549 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());
5550 }
5551 }
5552 else
5553 {
5554 if (log)
5555 log->Printf ("warning: couldn't find a match for 0x%8.8x", dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005556
Sean Callanan2367f8a2013-02-26 01:12:25 +00005557 failures.push_back(dst_die);
5558 }
5559 }
5560 }
5561 }
5562
5563 const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize ();
5564 const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize ();
5565
5566 UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src;
5567
5568 if (src_size_artificial && dst_size_artificial)
5569 {
5570 dst_name_to_die_artificial.Sort();
5571
Greg Clayton65ec1032012-11-12 21:27:20 +00005572 for (idx = 0; idx < src_size_artificial; ++idx)
5573 {
5574 const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx);
5575 src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5576 dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL);
5577
5578 if (dst_die)
5579 {
Greg Clayton65ec1032012-11-12 21:27:20 +00005580 // Both classes have the artificial types, link them
5581 clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die];
5582 if (src_decl_ctx)
5583 {
5584 if (log)
5585 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
5586 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5587 }
5588 else
5589 {
5590 if (log)
5591 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());
5592 }
5593
5594 Type *src_child_type = m_die_to_type[src_die];
5595 if (src_child_type)
5596 {
5597 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00005598 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 +00005599 m_die_to_type[dst_die] = src_child_type;
5600 }
5601 else
5602 {
5603 if (log)
5604 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());
5605 }
5606 }
5607 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005608 }
Greg Clayton65ec1032012-11-12 21:27:20 +00005609
Sean Callanan2367f8a2013-02-26 01:12:25 +00005610 if (dst_size_artificial)
Greg Clayton4116e932012-05-15 02:33:01 +00005611 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005612 for (idx = 0; idx < dst_size_artificial; ++idx)
5613 {
5614 const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx);
5615 dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5616 if (log)
5617 log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial);
5618
5619 failures.push_back(dst_die);
5620 }
Greg Clayton4116e932012-05-15 02:33:01 +00005621 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005622
5623 return (failures.size() != 0);
Greg Clayton4116e932012-05-15 02:33:01 +00005624}
Greg Claytona8022fa2012-04-24 21:22:41 +00005625
5626TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00005627SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005628{
5629 TypeSP type_sp;
5630
Greg Clayton1be10fc2010-09-29 01:12:09 +00005631 if (type_is_new_ptr)
5632 *type_is_new_ptr = false;
Greg Clayton1fba87112012-02-09 20:03:49 +00005633
5634#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5635 static DIEStack g_die_stack;
5636 DIEStack::ScopedPopper scoped_die_logger(g_die_stack);
5637#endif
Greg Clayton1be10fc2010-09-29 01:12:09 +00005638
Sean Callananc7fbf732010-08-06 00:32:49 +00005639 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005640 if (die != NULL)
5641 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005642 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005643 if (log)
Sean Callanan5b26f272012-02-04 08:49:35 +00005644 {
5645 const DWARFDebugInfoEntry *context_die;
5646 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
5647
Greg Clayton5160ce52013-03-27 23:08:40 +00005648 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 +00005649 die->GetOffset(),
5650 context,
5651 context_die->GetOffset(),
Greg Clayton3bffb082011-12-10 02:15:28 +00005652 DW_TAG_value_to_name(die->Tag()),
Greg Clayton1fba87112012-02-09 20:03:49 +00005653 die->GetName(this, dwarf_cu));
5654
5655#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5656 scoped_die_logger.Push (dwarf_cu, die);
Greg Clayton5160ce52013-03-27 23:08:40 +00005657 g_die_stack.LogDIEs(log, this);
Greg Clayton1fba87112012-02-09 20:03:49 +00005658#endif
Sean Callanan5b26f272012-02-04 08:49:35 +00005659 }
Greg Clayton3bffb082011-12-10 02:15:28 +00005660//
Greg Clayton5160ce52013-03-27 23:08:40 +00005661// Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005662// if (log && dwarf_cu)
5663// {
5664// StreamString s;
5665// die->DumpLocation (this, dwarf_cu, s);
Greg Clayton5160ce52013-03-27 23:08:40 +00005666// GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Greg Clayton3bffb082011-12-10 02:15:28 +00005667//
5668// }
Jim Ingham16746d12011-08-25 23:21:43 +00005669
Greg Clayton594e5ed2010-09-27 21:07:38 +00005670 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005671 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00005672 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005673 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005674 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00005675 if (type_is_new_ptr)
5676 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005677
Greg Clayton594e5ed2010-09-27 21:07:38 +00005678 const dw_tag_t tag = die->Tag();
5679
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005680 bool is_forward_declaration = false;
5681 DWARFDebugInfoEntry::Attributes attributes;
5682 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00005683 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00005684 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
Greg Claytonfaac1112013-03-14 18:31:44 +00005685 uint64_t byte_size = 0;
Greg Clayton526e5af2010-11-13 03:52:47 +00005686 Declaration decl;
5687
Greg Clayton4957bf62010-09-30 21:49:03 +00005688 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton57ee3062013-07-11 22:46:58 +00005689 ClangASTType clang_type;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005690
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005691 dw_attr_t attr;
5692
5693 switch (tag)
5694 {
5695 case DW_TAG_base_type:
5696 case DW_TAG_pointer_type:
5697 case DW_TAG_reference_type:
Sean Callanance8af862012-05-21 23:31:51 +00005698 case DW_TAG_rvalue_reference_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005699 case DW_TAG_typedef:
5700 case DW_TAG_const_type:
5701 case DW_TAG_restrict_type:
5702 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00005703 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005704 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005705 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005706 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005707
Greg Claytond88d7592010-09-15 08:33:30 +00005708 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005709 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005710 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
5711
5712 if (num_attributes > 0)
5713 {
5714 uint32_t i;
5715 for (i=0; i<num_attributes; ++i)
5716 {
5717 attr = attributes.AttributeAtIndex(i);
5718 DWARFFormValue form_value;
5719 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5720 {
5721 switch (attr)
5722 {
5723 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5724 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5725 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5726 case DW_AT_name:
Jim Ingham337030f2011-04-15 23:41:23 +00005727
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005728 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00005729 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
5730 // include the "&"...
5731 if (tag == DW_TAG_reference_type)
5732 {
5733 if (strchr (type_name_cstr, '&') == NULL)
5734 type_name_cstr = NULL;
5735 }
5736 if (type_name_cstr)
5737 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005738 break;
Greg Clayton23f59502012-07-17 03:23:13 +00005739 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005740 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
5741 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
5742 default:
5743 case DW_AT_sibling:
5744 break;
5745 }
5746 }
5747 }
5748 }
5749
Ed Mastea0191d12013-10-17 20:42:56 +00005750 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 +00005751
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005752 switch (tag)
5753 {
5754 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00005755 break;
5756
Greg Claytond4436412011-10-28 21:00:00 +00005757 case DW_TAG_unspecified_type:
Greg Clayton7fba2632013-07-01 21:01:52 +00005758 if (strcmp(type_name_cstr, "nullptr_t") == 0 ||
5759 strcmp(type_name_cstr, "decltype(nullptr)") == 0 )
Greg Claytond4436412011-10-28 21:00:00 +00005760 {
5761 resolve_state = Type::eResolveStateFull;
Greg Clayton57ee3062013-07-11 22:46:58 +00005762 clang_type = ast.GetBasicType(eBasicTypeNullPtr);
Greg Claytond4436412011-10-28 21:00:00 +00005763 break;
5764 }
5765 // Fall through to base type below in case we can handle the type there...
5766
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005767 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00005768 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005769 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
5770 encoding,
5771 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005772 break;
5773
Sean Callanance8af862012-05-21 23:31:51 +00005774 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
5775 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
5776 case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break;
5777 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
5778 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
5779 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
5780 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005781 }
5782
Greg Clayton57ee3062013-07-11 22:46:58 +00005783 if (!clang_type && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID) && sc.comp_unit != NULL)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005784 {
Sean Callanan82587052013-01-03 00:05:56 +00005785 bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus);
5786
5787 if (translation_unit_is_objc)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005788 {
Sean Callanan82587052013-01-03 00:05:56 +00005789 if (type_name_cstr != NULL)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005790 {
Sean Callanan82587052013-01-03 00:05:56 +00005791 static ConstString g_objc_type_name_id("id");
5792 static ConstString g_objc_type_name_Class("Class");
5793 static ConstString g_objc_type_name_selector("SEL");
5794
5795 if (type_name_const_str == g_objc_type_name_id)
5796 {
5797 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005798 GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'id' built-in type.",
Sean Callanan82587052013-01-03 00:05:56 +00005799 die->GetOffset(),
5800 DW_TAG_value_to_name(die->Tag()),
5801 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005802 clang_type = ast.GetBasicType(eBasicTypeObjCID);
Sean Callanan82587052013-01-03 00:05:56 +00005803 encoding_data_type = Type::eEncodingIsUID;
5804 encoding_uid = LLDB_INVALID_UID;
5805 resolve_state = Type::eResolveStateFull;
Greg Clayton526e5af2010-11-13 03:52:47 +00005806
Sean Callanan82587052013-01-03 00:05:56 +00005807 }
5808 else if (type_name_const_str == g_objc_type_name_Class)
5809 {
5810 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005811 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 +00005812 die->GetOffset(),
5813 DW_TAG_value_to_name(die->Tag()),
5814 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005815 clang_type = ast.GetBasicType(eBasicTypeObjCClass);
Sean Callanan82587052013-01-03 00:05:56 +00005816 encoding_data_type = Type::eEncodingIsUID;
5817 encoding_uid = LLDB_INVALID_UID;
5818 resolve_state = Type::eResolveStateFull;
5819 }
5820 else if (type_name_const_str == g_objc_type_name_selector)
5821 {
5822 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005823 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 +00005824 die->GetOffset(),
5825 DW_TAG_value_to_name(die->Tag()),
5826 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005827 clang_type = ast.GetBasicType(eBasicTypeObjCSel);
Sean Callanan82587052013-01-03 00:05:56 +00005828 encoding_data_type = Type::eEncodingIsUID;
5829 encoding_uid = LLDB_INVALID_UID;
5830 resolve_state = Type::eResolveStateFull;
5831 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005832 }
Sean Callanan82587052013-01-03 00:05:56 +00005833 else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005834 {
Sean Callanan82587052013-01-03 00:05:56 +00005835 // Clang sometimes erroneously emits id as objc_object*. In that case we fix up the type to "id".
5836
5837 DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid);
5838
5839 if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type)
5840 {
5841 if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL))
5842 {
5843 if (!strcmp(struct_name, "objc_object"))
5844 {
5845 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005846 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 +00005847 die->GetOffset(),
5848 DW_TAG_value_to_name(die->Tag()),
5849 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005850 clang_type = ast.GetBasicType(eBasicTypeObjCID);
Sean Callanan82587052013-01-03 00:05:56 +00005851 encoding_data_type = Type::eEncodingIsUID;
5852 encoding_uid = LLDB_INVALID_UID;
5853 resolve_state = Type::eResolveStateFull;
5854 }
5855 }
5856 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005857 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005858 }
5859 }
5860
Greg Clayton81c22f62011-10-19 18:09:39 +00005861 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005862 this,
5863 type_name_const_str,
5864 byte_size,
5865 NULL,
5866 encoding_uid,
5867 encoding_data_type,
5868 &decl,
5869 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005870 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005871
Greg Clayton594e5ed2010-09-27 21:07:38 +00005872 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005873
5874// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
5875// if (encoding_type != NULL)
5876// {
5877// if (encoding_type != DIE_IS_BEING_PARSED)
5878// type_sp->SetEncodingType(encoding_type);
5879// else
5880// m_indirect_fixups.push_back(type_sp.get());
5881// }
5882 }
5883 break;
5884
5885 case DW_TAG_structure_type:
5886 case DW_TAG_union_type:
5887 case DW_TAG_class_type:
5888 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005889 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005890 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Greg Clayton23f59502012-07-17 03:23:13 +00005891 bool byte_size_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005892
Greg Clayton9e409562010-07-28 02:04:09 +00005893 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00005894 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005895 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00005896 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005897 if (num_attributes > 0)
5898 {
5899 uint32_t i;
5900 for (i=0; i<num_attributes; ++i)
5901 {
5902 attr = attributes.AttributeAtIndex(i);
5903 DWARFFormValue form_value;
5904 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5905 {
5906 switch (attr)
5907 {
Greg Clayton9e409562010-07-28 02:04:09 +00005908 case DW_AT_decl_file:
Greg Claytonc7f03b62012-01-12 04:33:28 +00005909 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
Ed Maste4c24b122013-10-17 20:13:14 +00005910 {
5911 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
5912 // point to the compile unit file, so we clear this invalid value
5913 // so that we can still unique types efficiently.
Greg Claytonc7f03b62012-01-12 04:33:28 +00005914 decl.SetFile(FileSpec ("<invalid>", false));
Ed Maste4c24b122013-10-17 20:13:14 +00005915 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005916 else
5917 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
Greg Clayton9e409562010-07-28 02:04:09 +00005918 break;
5919
5920 case DW_AT_decl_line:
5921 decl.SetLine(form_value.Unsigned());
5922 break;
5923
5924 case DW_AT_decl_column:
5925 decl.SetColumn(form_value.Unsigned());
5926 break;
5927
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005928 case DW_AT_name:
5929 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005930 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005931 break;
Greg Clayton9e409562010-07-28 02:04:09 +00005932
5933 case DW_AT_byte_size:
5934 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00005935 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00005936 break;
5937
5938 case DW_AT_accessibility:
5939 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
5940 break;
5941
5942 case DW_AT_declaration:
Greg Clayton1c8ef472013-04-05 23:27:21 +00005943 is_forward_declaration = form_value.Boolean();
Greg Clayton9e409562010-07-28 02:04:09 +00005944 break;
5945
5946 case DW_AT_APPLE_runtime_class:
5947 class_language = (LanguageType)form_value.Signed();
5948 break;
5949
Greg Clayton18774842011-11-29 23:40:34 +00005950 case DW_AT_APPLE_objc_complete_type:
5951 is_complete_objc_class = form_value.Signed();
5952 break;
5953
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005954 case DW_AT_allocated:
5955 case DW_AT_associated:
5956 case DW_AT_data_location:
5957 case DW_AT_description:
5958 case DW_AT_start_scope:
5959 case DW_AT_visibility:
5960 default:
5961 case DW_AT_sibling:
5962 break;
5963 }
5964 }
5965 }
5966 }
5967
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005968 UniqueDWARFASTType unique_ast_entry;
Sean Callanan8e8072d2012-02-07 21:13:38 +00005969
Greg Clayton123edca2012-03-02 00:07:15 +00005970 // Only try and unique the type if it has a name.
5971 if (type_name_const_str &&
5972 GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Sean Callanan8e8072d2012-02-07 21:13:38 +00005973 this,
5974 dwarf_cu,
5975 die,
5976 decl,
5977 byte_size_valid ? byte_size : -1,
5978 unique_ast_entry))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005979 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005980 // We have already parsed this type or from another
5981 // compile unit. GCC loves to use the "one definition
5982 // rule" which can result in multiple definitions
5983 // of the same class over and over in each compile
5984 // unit.
5985 type_sp = unique_ast_entry.m_type_sp;
5986 if (type_sp)
Greg Claytonc615ce42010-11-09 04:42:43 +00005987 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005988 m_die_to_type[die] = type_sp.get();
5989 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005990 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005991 }
5992
Daniel Malead01b2952012-11-29 21:49:15 +00005993 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 +00005994
5995 int tag_decl_kind = -1;
5996 AccessType default_accessibility = eAccessNone;
5997 if (tag == DW_TAG_structure_type)
5998 {
5999 tag_decl_kind = clang::TTK_Struct;
6000 default_accessibility = eAccessPublic;
6001 }
6002 else if (tag == DW_TAG_union_type)
6003 {
6004 tag_decl_kind = clang::TTK_Union;
6005 default_accessibility = eAccessPublic;
6006 }
6007 else if (tag == DW_TAG_class_type)
6008 {
6009 tag_decl_kind = clang::TTK_Class;
6010 default_accessibility = eAccessPrivate;
6011 }
Greg Clayton3a5f29a2011-11-30 02:48:28 +00006012
6013 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
6014 die->HasChildren() == false &&
6015 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
6016 {
6017 // Work around an issue with clang at the moment where
6018 // forward declarations for objective C classes are emitted
6019 // as:
6020 // DW_TAG_structure_type [2]
6021 // DW_AT_name( "ForwardObjcClass" )
6022 // DW_AT_byte_size( 0x00 )
6023 // DW_AT_decl_file( "..." )
6024 // DW_AT_decl_line( 1 )
6025 //
6026 // Note that there is no DW_AT_declaration and there are
6027 // no children, and the byte size is zero.
6028 is_forward_declaration = true;
6029 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006030
Sean Callanan7457f8d2012-04-25 01:03:57 +00006031 if (class_language == eLanguageTypeObjC ||
6032 class_language == eLanguageTypeObjC_plus_plus)
Greg Clayton18774842011-11-29 23:40:34 +00006033 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00006034 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
Greg Clayton901c5ca2011-12-03 04:40:03 +00006035 {
6036 // We have a valid eSymbolTypeObjCClass class symbol whose
6037 // name matches the current objective C class that we
6038 // are trying to find and this DIE isn't the complete
6039 // definition (we checked is_complete_objc_class above and
6040 // know it is false), so the real definition is in here somewhere
Greg Claytonc7f03b62012-01-12 04:33:28 +00006041 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006042
Greg Clayton1f746072012-08-29 21:13:06 +00006043 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton901c5ca2011-12-03 04:40:03 +00006044 {
6045 // We weren't able to find a full declaration in
6046 // this DWARF, see if we have a declaration anywhere
6047 // else...
Greg Claytonc7f03b62012-01-12 04:33:28 +00006048 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00006049 }
6050
6051 if (type_sp)
6052 {
6053 if (log)
6054 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006055 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00006056 "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 +00006057 this,
6058 die->GetOffset(),
6059 DW_TAG_value_to_name(tag),
6060 type_name_cstr,
6061 type_sp->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00006062 }
6063
6064 // We found a real definition for this type elsewhere
6065 // so lets use it and cache the fact that we found
6066 // a complete type for this die
6067 m_die_to_type[die] = type_sp.get();
6068 return type_sp;
6069 }
6070 }
6071 }
6072
6073
6074 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006075 {
6076 // We have a forward declaration to a type and we need
6077 // to try and find a full declaration. We look in the
6078 // current type index just in case we have a forward
6079 // declaration followed by an actual declarations in the
6080 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00006081 if (log)
6082 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006083 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00006084 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
6085 this,
6086 die->GetOffset(),
6087 DW_TAG_value_to_name(tag),
6088 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00006089 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006090
Greg Claytona8022fa2012-04-24 21:22:41 +00006091 DWARFDeclContext die_decl_ctx;
6092 die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx);
6093
6094 //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
6095 type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006096
Greg Clayton1f746072012-08-29 21:13:06 +00006097 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton4272cc72011-02-02 02:24:04 +00006098 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006099 // We weren't able to find a full declaration in
6100 // this DWARF, see if we have a declaration anywhere
6101 // else...
Greg Claytona8022fa2012-04-24 21:22:41 +00006102 type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton4272cc72011-02-02 02:24:04 +00006103 }
6104
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006105 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00006106 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00006107 if (log)
6108 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006109 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00006110 "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 +00006111 this,
6112 die->GetOffset(),
6113 DW_TAG_value_to_name(tag),
6114 type_name_cstr,
6115 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00006116 }
6117
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006118 // We found a real definition for this type elsewhere
6119 // so lets use it and cache the fact that we found
6120 // a complete type for this die
6121 m_die_to_type[die] = type_sp.get();
6122 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00006123 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006124 }
6125 assert (tag_decl_kind != -1);
6126 bool clang_type_was_created = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00006127 clang_type.SetClangType(ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die));
6128 if (!clang_type)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006129 {
Sean Callanan4d04c6a2012-02-09 22:54:11 +00006130 const DWARFDebugInfoEntry *decl_ctx_die;
6131
6132 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton55561e92011-10-26 03:31:36 +00006133 if (accessibility == eAccessNone && decl_ctx)
6134 {
6135 // Check the decl context that contains this class/struct/union.
6136 // If it is a class we must give it an accessability.
6137 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
6138 if (DeclKindIsCXXClass (containing_decl_kind))
6139 accessibility = default_accessibility;
6140 }
6141
Greg Claytonc4ffd662013-03-08 01:37:30 +00006142 ClangASTMetadata metadata;
6143 metadata.SetUserID(MakeUserID(die->GetOffset()));
6144 metadata.SetIsDynamicCXXType(ClassOrStructIsVirtual (dwarf_cu, die));
6145
Greg Claytonf0705c82011-10-22 03:33:13 +00006146 if (type_name_cstr && strchr (type_name_cstr, '<'))
6147 {
6148 ClangASTContext::TemplateParameterInfos template_param_infos;
6149 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
6150 {
6151 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00006152 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00006153 type_name_cstr,
6154 tag_decl_kind,
6155 template_param_infos);
6156
6157 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
6158 class_template_decl,
6159 tag_decl_kind,
6160 template_param_infos);
6161 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
6162 clang_type_was_created = true;
Sean Callanan60217122012-04-13 00:10:03 +00006163
Greg Claytond0029442013-03-27 01:48:02 +00006164 GetClangASTContext().SetMetadata (class_template_decl, metadata);
6165 GetClangASTContext().SetMetadata (class_specialization_decl, metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00006166 }
6167 }
6168
6169 if (!clang_type_was_created)
6170 {
6171 clang_type_was_created = true;
Greg Clayton55561e92011-10-26 03:31:36 +00006172 clang_type = ast.CreateRecordType (decl_ctx,
6173 accessibility,
6174 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00006175 tag_decl_kind,
Sean Callanan60217122012-04-13 00:10:03 +00006176 class_language,
Jim Ingham379397632012-10-27 02:54:13 +00006177 &metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00006178 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006179 }
6180
6181 // Store a forward declaration to this class type in case any
6182 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00006183 // types for function prototypes.
Greg Clayton57ee3062013-07-11 22:46:58 +00006184 LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00006185 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006186 this,
6187 type_name_const_str,
6188 byte_size,
6189 NULL,
6190 LLDB_INVALID_UID,
6191 Type::eEncodingIsUID,
6192 &decl,
6193 clang_type,
6194 Type::eResolveStateForward));
Sean Callanan72772842012-02-22 23:57:45 +00006195
6196 type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006197
6198
6199 // Add our type to the unique type map so we don't
6200 // end up creating many copies of the same type over
6201 // and over in the ASTContext for our module
6202 unique_ast_entry.m_type_sp = type_sp;
Greg Clayton36909642011-03-15 04:38:20 +00006203 unique_ast_entry.m_symfile = this;
6204 unique_ast_entry.m_cu = dwarf_cu;
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006205 unique_ast_entry.m_die = die;
6206 unique_ast_entry.m_declaration = decl;
Sean Callanan59700592012-02-13 22:30:16 +00006207 unique_ast_entry.m_byte_size = byte_size;
Greg Claytone576ab22011-02-15 00:19:15 +00006208 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
6209 unique_ast_entry);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006210
Greg Clayton0ec71a02013-08-10 00:09:35 +00006211 if (is_forward_declaration && die->HasChildren())
6212 {
6213 // Check to see if the DIE actually has a definition, some version of GCC will
6214 // emit DIEs with DW_AT_declaration set to true, but yet still have subprogram,
6215 // members, or inheritance, so we can't trust it
6216 const DWARFDebugInfoEntry *child_die = die->GetFirstChild();
6217 while (child_die)
6218 {
6219 switch (child_die->Tag())
6220 {
6221 case DW_TAG_inheritance:
6222 case DW_TAG_subprogram:
6223 case DW_TAG_member:
6224 case DW_TAG_APPLE_property:
6225 child_die = NULL;
6226 is_forward_declaration = false;
6227 break;
6228 default:
6229 child_die = child_die->GetSibling();
6230 break;
6231 }
6232 }
6233 }
6234
Sean Callanan12014a02011-12-08 23:45:45 +00006235 if (!is_forward_declaration)
Greg Clayton219cf312012-03-30 00:51:13 +00006236 {
6237 // Always start the definition for a class type so that
6238 // if the class has child classes or types that require
6239 // the class to be created for use as their decl contexts
6240 // the class will be ready to accept these child definitions.
Sean Callanan12014a02011-12-08 23:45:45 +00006241 if (die->HasChildren() == false)
6242 {
6243 // No children for this struct/union/class, lets finish it
Greg Clayton57ee3062013-07-11 22:46:58 +00006244 clang_type.StartTagDeclarationDefinition ();
6245 clang_type.CompleteTagDeclarationDefinition ();
Sean Callanan433cd222012-10-19 01:37:25 +00006246
6247 if (tag == DW_TAG_structure_type) // this only applies in C
6248 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006249 clang::RecordDecl *record_decl = clang_type.GetAsRecordDecl();
Sean Callanan433cd222012-10-19 01:37:25 +00006250
Greg Clayton57ee3062013-07-11 22:46:58 +00006251 if (record_decl)
Sean Callanan433cd222012-10-19 01:37:25 +00006252 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006253 LayoutInfo layout_info;
Sean Callanan433cd222012-10-19 01:37:25 +00006254
Greg Clayton57ee3062013-07-11 22:46:58 +00006255 layout_info.alignment = 0;
6256 layout_info.bit_size = 0;
6257
6258 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
Sean Callanan433cd222012-10-19 01:37:25 +00006259 }
6260 }
Sean Callanan12014a02011-12-08 23:45:45 +00006261 }
6262 else if (clang_type_was_created)
6263 {
Greg Clayton219cf312012-03-30 00:51:13 +00006264 // Start the definition if the class is not objective C since
6265 // the underlying decls respond to isCompleteDefinition(). Objective
6266 // C decls dont' respond to isCompleteDefinition() so we can't
6267 // start the declaration definition right away. For C++ classs/union/structs
6268 // we want to start the definition in case the class is needed as the
6269 // declaration context for a contained class or type without the need
6270 // to complete that type..
6271
Sean Callanan7457f8d2012-04-25 01:03:57 +00006272 if (class_language != eLanguageTypeObjC &&
6273 class_language != eLanguageTypeObjC_plus_plus)
Greg Clayton57ee3062013-07-11 22:46:58 +00006274 clang_type.StartTagDeclarationDefinition ();
Greg Clayton219cf312012-03-30 00:51:13 +00006275
Sean Callanan12014a02011-12-08 23:45:45 +00006276 // Leave this as a forward declaration until we need
6277 // to know the details of the type. lldb_private::Type
6278 // will automatically call the SymbolFile virtual function
6279 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
6280 // When the definition needs to be defined.
Greg Clayton57ee3062013-07-11 22:46:58 +00006281 m_forward_decl_die_to_clang_type[die] = clang_type.GetOpaqueQualType();
6282 m_forward_decl_clang_type_to_die[clang_type.RemoveFastQualifiers().GetOpaqueQualType()] = die;
6283 clang_type.SetHasExternalStorage (true);
Sean Callanan12014a02011-12-08 23:45:45 +00006284 }
Greg Claytonc615ce42010-11-09 04:42:43 +00006285 }
Greg Claytoncab36a32011-12-08 05:16:30 +00006286
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006287 }
6288 break;
6289
6290 case DW_TAG_enumeration_type:
6291 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006292 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006293 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006294
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006295 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006296
Greg Claytond88d7592010-09-15 08:33:30 +00006297 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006298 if (num_attributes > 0)
6299 {
6300 uint32_t i;
6301
6302 for (i=0; i<num_attributes; ++i)
6303 {
6304 attr = attributes.AttributeAtIndex(i);
6305 DWARFFormValue form_value;
6306 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6307 {
6308 switch (attr)
6309 {
Greg Clayton7a345282010-11-09 23:46:37 +00006310 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6311 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6312 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006313 case DW_AT_name:
6314 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006315 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006316 break;
Greg Clayton7a345282010-11-09 23:46:37 +00006317 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006318 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
6319 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006320 case DW_AT_declaration: break; //is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006321 case DW_AT_allocated:
6322 case DW_AT_associated:
6323 case DW_AT_bit_stride:
6324 case DW_AT_byte_stride:
6325 case DW_AT_data_location:
6326 case DW_AT_description:
6327 case DW_AT_start_scope:
6328 case DW_AT_visibility:
6329 case DW_AT_specification:
6330 case DW_AT_abstract_origin:
6331 case DW_AT_sibling:
6332 break;
6333 }
6334 }
6335 }
6336
Daniel Malead01b2952012-11-29 21:49:15 +00006337 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 +00006338
Greg Clayton57ee3062013-07-11 22:46:58 +00006339 ClangASTType enumerator_clang_type;
6340 clang_type.SetClangType (ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die));
6341 if (!clang_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00006342 {
Greg Clayton5d14fc02013-03-06 06:23:54 +00006343 if (encoding_uid != DW_INVALID_OFFSET)
6344 {
6345 Type *enumerator_type = ResolveTypeUID(encoding_uid);
6346 if (enumerator_type)
6347 enumerator_clang_type = enumerator_type->GetClangFullType();
6348 }
6349
Greg Clayton57ee3062013-07-11 22:46:58 +00006350 if (!enumerator_clang_type)
Greg Clayton5d14fc02013-03-06 06:23:54 +00006351 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
6352 DW_ATE_signed,
6353 byte_size * 8);
6354
Greg Claytonca512b32011-01-14 04:54:56 +00006355 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00006356 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00006357 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006358 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00006359 }
6360 else
6361 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006362 enumerator_clang_type = clang_type.GetEnumerationIntegerType ();
Greg Clayton1be10fc2010-09-29 01:12:09 +00006363 }
6364
Greg Clayton57ee3062013-07-11 22:46:58 +00006365 LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die);
Greg Claytona2721472011-06-25 00:44:06 +00006366
Greg Clayton81c22f62011-10-19 18:09:39 +00006367 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006368 this,
6369 type_name_const_str,
6370 byte_size,
6371 NULL,
6372 encoding_uid,
6373 Type::eEncodingIsUID,
6374 &decl,
6375 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006376 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006377
Greg Clayton57ee3062013-07-11 22:46:58 +00006378 clang_type.StartTagDeclarationDefinition ();
Greg Clayton6beaaa62011-01-17 03:46:26 +00006379 if (die->HasChildren())
6380 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006381 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00006382 bool is_signed = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00006383 enumerator_clang_type.IsIntegerType(is_signed);
Greg Clayton3e067532013-03-05 23:54:39 +00006384 ParseChildEnumerators(cu_sc, clang_type, is_signed, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00006385 }
Greg Clayton57ee3062013-07-11 22:46:58 +00006386 clang_type.CompleteTagDeclarationDefinition ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006387 }
6388 }
6389 break;
6390
Jim Inghamb0be4422010-08-12 01:20:14 +00006391 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006392 case DW_TAG_subprogram:
6393 case DW_TAG_subroutine_type:
6394 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006395 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006396 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006397
Greg Clayton23f59502012-07-17 03:23:13 +00006398 //const char *mangled = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006399 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00006400 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006401 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00006402 bool is_static = false;
6403 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00006404 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00006405 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00006406 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
6407 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Jim Ingham379397632012-10-27 02:54:13 +00006408 dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00006409
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006410 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00006411 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006412
6413
Greg Claytond88d7592010-09-15 08:33:30 +00006414 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006415 if (num_attributes > 0)
6416 {
6417 uint32_t i;
6418 for (i=0; i<num_attributes; ++i)
6419 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006420 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006421 DWARFFormValue form_value;
6422 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6423 {
6424 switch (attr)
6425 {
6426 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6427 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6428 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6429 case DW_AT_name:
6430 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006431 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006432 break;
6433
Greg Clayton71415542012-12-08 00:24:40 +00006434 case DW_AT_linkage_name:
Greg Clayton23f59502012-07-17 03:23:13 +00006435 case DW_AT_MIPS_linkage_name: break; // mangled = form_value.AsCString(&get_debug_str_data()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006436 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00006437 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006438 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
6439 case DW_AT_inline: is_inline = form_value.Boolean(); break;
6440 case DW_AT_virtuality: is_virtual = form_value.Boolean(); break;
6441 case DW_AT_explicit: is_explicit = form_value.Boolean(); break;
6442 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Sean Callanandbb58392011-11-02 01:38:59 +00006443
Greg Claytonf51de672010-10-01 02:31:07 +00006444
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006445 case DW_AT_external:
6446 if (form_value.Unsigned())
6447 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00006448 if (storage == clang::SC_None)
6449 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006450 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00006451 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006452 }
6453 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006454
Greg Clayton72da3972011-08-16 18:40:23 +00006455 case DW_AT_specification:
6456 specification_die_offset = form_value.Reference(dwarf_cu);
6457 break;
6458
6459 case DW_AT_abstract_origin:
6460 abstract_origin_die_offset = form_value.Reference(dwarf_cu);
6461 break;
6462
Jim Ingham379397632012-10-27 02:54:13 +00006463 case DW_AT_object_pointer:
6464 object_pointer_die_offset = form_value.Reference(dwarf_cu);
6465 break;
6466
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006467 case DW_AT_allocated:
6468 case DW_AT_associated:
6469 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006470 case DW_AT_calling_convention:
6471 case DW_AT_data_location:
6472 case DW_AT_elemental:
6473 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006474 case DW_AT_frame_base:
6475 case DW_AT_high_pc:
6476 case DW_AT_low_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006477 case DW_AT_prototyped:
6478 case DW_AT_pure:
6479 case DW_AT_ranges:
6480 case DW_AT_recursive:
6481 case DW_AT_return_addr:
6482 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006483 case DW_AT_start_scope:
6484 case DW_AT_static_link:
6485 case DW_AT_trampoline:
6486 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006487 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006488 case DW_AT_description:
6489 case DW_AT_sibling:
6490 break;
6491 }
6492 }
6493 }
Greg Clayton24739922010-10-13 03:15:28 +00006494 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006495
Jim Ingham379397632012-10-27 02:54:13 +00006496 std::string object_pointer_name;
6497 if (object_pointer_die_offset != DW_INVALID_OFFSET)
6498 {
6499 // Get the name from the object pointer die
6500 StreamString s;
6501 if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s))
6502 {
6503 object_pointer_name.assign(s.GetData());
6504 }
6505 }
6506
Daniel Malead01b2952012-11-29 21:49:15 +00006507 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 +00006508
Greg Clayton57ee3062013-07-11 22:46:58 +00006509 ClangASTType return_clang_type;
Greg Clayton24739922010-10-13 03:15:28 +00006510 Type *func_type = NULL;
6511
6512 if (type_die_offset != DW_INVALID_OFFSET)
6513 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00006514
Greg Clayton24739922010-10-13 03:15:28 +00006515 if (func_type)
Greg Clayton42ce2f32011-12-12 21:50:19 +00006516 return_clang_type = func_type->GetClangForwardType();
Greg Clayton24739922010-10-13 03:15:28 +00006517 else
Greg Clayton57ee3062013-07-11 22:46:58 +00006518 return_clang_type = ast.GetBasicType(eBasicTypeVoid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006519
Greg Claytonf51de672010-10-01 02:31:07 +00006520
Greg Clayton57ee3062013-07-11 22:46:58 +00006521 std::vector<ClangASTType> function_param_types;
Greg Clayton24739922010-10-13 03:15:28 +00006522 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006523
Greg Clayton24739922010-10-13 03:15:28 +00006524 // Parse the function children for the parameters
Sean Callanan763d72a2011-08-02 22:21:50 +00006525
Greg Claytoncb5860a2011-10-13 23:49:28 +00006526 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
6527 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00006528 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
6529
Greg Claytonf0705c82011-10-22 03:33:13 +00006530 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00006531 // Start off static. This will be set to false in ParseChildParameters(...)
6532 // if we find a "this" paramters as the first parameter
6533 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00006534 is_static = true;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006535 ClangASTContext::TemplateParameterInfos template_param_infos;
6536
Greg Clayton24739922010-10-13 03:15:28 +00006537 if (die->HasChildren())
6538 {
Greg Clayton0fffff52010-09-24 05:15:53 +00006539 bool skip_artificial = true;
Jim Ingham379397632012-10-27 02:54:13 +00006540 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00006541 containing_decl_ctx,
Jim Ingham379397632012-10-27 02:54:13 +00006542 dwarf_cu,
6543 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00006544 skip_artificial,
6545 is_static,
Jim Ingham379397632012-10-27 02:54:13 +00006546 type_list,
6547 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00006548 function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006549 type_quals,
6550 template_param_infos);
Greg Clayton24739922010-10-13 03:15:28 +00006551 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006552
Greg Clayton24739922010-10-13 03:15:28 +00006553 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006554 clang_type = ast.CreateFunctionType (return_clang_type,
Greg Clayton9cb25c42012-10-30 17:02:18 +00006555 function_param_types.data(),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006556 function_param_types.size(),
6557 is_variadic,
6558 type_quals);
6559
Sean Callanande9ce872013-05-09 23:13:13 +00006560 bool ignore_containing_context = false;
6561
Greg Clayton24739922010-10-13 03:15:28 +00006562 if (type_name_cstr)
6563 {
6564 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00006565 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006566 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00006567 ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true);
6568 if (objc_method.IsValid(true))
Greg Clayton0fffff52010-09-24 05:15:53 +00006569 {
Greg Clayton24739922010-10-13 03:15:28 +00006570 SymbolContext empty_sc;
Greg Clayton57ee3062013-07-11 22:46:58 +00006571 ClangASTType class_opaque_type;
Greg Clayton1b3815c2013-01-30 00:18:29 +00006572 ConstString class_name(objc_method.GetClassName());
Greg Clayton7c810422012-01-18 23:40:49 +00006573 if (class_name)
Greg Clayton0fffff52010-09-24 05:15:53 +00006574 {
Greg Clayton24739922010-10-13 03:15:28 +00006575 TypeList types;
Greg Clayton278a16b2012-01-19 00:52:59 +00006576 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
Greg Claytonc7f03b62012-01-12 04:33:28 +00006577
6578 if (complete_objc_class_type_sp)
Greg Clayton0fffff52010-09-24 05:15:53 +00006579 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006580 ClangASTType type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
6581 if (type_clang_forward_type.IsObjCObjectOrInterfaceType ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00006582 class_opaque_type = type_clang_forward_type;
Greg Clayton0fffff52010-09-24 05:15:53 +00006583 }
Greg Clayton24739922010-10-13 03:15:28 +00006584 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006585
Greg Clayton24739922010-10-13 03:15:28 +00006586 if (class_opaque_type)
6587 {
6588 // If accessibility isn't set to anything valid, assume public for
6589 // now...
6590 if (accessibility == eAccessNone)
6591 accessibility = eAccessPublic;
6592
Greg Clayton57ee3062013-07-11 22:46:58 +00006593 clang::ObjCMethodDecl *objc_method_decl = class_opaque_type.AddMethodToObjCObjectType (type_name_cstr,
6594 clang_type,
6595 accessibility,
6596 is_artificial);
Greg Clayton24739922010-10-13 03:15:28 +00006597 type_handled = objc_method_decl != NULL;
Sean Callanan464a5b52012-10-04 22:06:29 +00006598 if (type_handled)
6599 {
6600 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Claytond0029442013-03-27 01:48:02 +00006601 GetClangASTContext().SetMetadataAsUserID (objc_method_decl, MakeUserID(die->GetOffset()));
Sean Callanan464a5b52012-10-04 22:06:29 +00006602 }
Sean Callananc3a1d562013-02-06 23:21:59 +00006603 else
6604 {
Jason Molendac1a65832013-03-07 22:44:42 +00006605 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 +00006606 die->GetOffset(),
6607 tag,
6608 DW_TAG_value_to_name(tag));
6609 }
Greg Clayton24739922010-10-13 03:15:28 +00006610 }
6611 }
Greg Clayton5113dc82011-08-12 06:47:54 +00006612 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00006613 {
6614 // Look at the parent of this DIE and see if is is
6615 // a class or struct and see if this is actually a
6616 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00006617 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00006618 if (class_type)
6619 {
Greg Clayton4116e932012-05-15 02:33:01 +00006620 if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset()))
6621 {
6622 // We uniqued the parent class of this function to another class
6623 // so we now need to associate all dies under "decl_ctx_die" to
6624 // DIEs in the DIE for "class_type"...
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006625 SymbolFileDWARF *class_symfile = NULL;
Greg Clayton4116e932012-05-15 02:33:01 +00006626 DWARFCompileUnitSP class_type_cu_sp;
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006627 const DWARFDebugInfoEntry *class_type_die = NULL;
Sean Callanan2367f8a2013-02-26 01:12:25 +00006628
6629 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
6630 if (debug_map_symfile)
6631 {
6632 class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID()));
6633 class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6634 }
6635 else
6636 {
6637 class_symfile = this;
6638 class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6639 }
Greg Clayton4116e932012-05-15 02:33:01 +00006640 if (class_type_die)
6641 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006642 llvm::SmallVector<const DWARFDebugInfoEntry *, 0> failures;
6643
6644 CopyUniqueClassMethodTypes (class_symfile,
6645 class_type,
6646 class_type_cu_sp.get(),
6647 class_type_die,
6648 dwarf_cu,
6649 decl_ctx_die,
6650 failures);
6651
6652 // FIXME do something with these failures that's smarter than
6653 // just dropping them on the ground. Unfortunately classes don't
6654 // like having stuff added to them after their definitions are
6655 // complete...
6656
6657 type_ptr = m_die_to_type[die];
6658 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton4116e932012-05-15 02:33:01 +00006659 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006660 type_sp = type_ptr->shared_from_this();
6661 break;
Greg Clayton4116e932012-05-15 02:33:01 +00006662 }
6663 }
6664 }
6665
Greg Clayton72da3972011-08-16 18:40:23 +00006666 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00006667 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006668 // We have a specification which we are going to base our function
6669 // prototype off of, so we need this type to be completed so that the
6670 // m_die_to_decl_ctx for the method in the specification has a valid
6671 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006672 class_type->GetClangForwardType();
Greg Clayton72da3972011-08-16 18:40:23 +00006673 // If we have a specification, then the function type should have been
6674 // made with the specification and not with this die.
6675 DWARFCompileUnitSP spec_cu_sp;
6676 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006677 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006678 if (spec_clang_decl_ctx)
6679 {
6680 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
6681 }
6682 else
Jim Inghamc1663042011-09-29 22:12:35 +00006683 {
Daniel Malead01b2952012-11-29 21:49:15 +00006684 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8x) has no decl\n",
Greg Claytone38a5ed2012-01-05 03:57:59 +00006685 MakeUserID(die->GetOffset()),
6686 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006687 }
Greg Clayton72da3972011-08-16 18:40:23 +00006688 type_handled = true;
6689 }
6690 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
6691 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006692 // We have a specification which we are going to base our function
6693 // prototype off of, so we need this type to be completed so that the
6694 // m_die_to_decl_ctx for the method in the abstract origin has a valid
6695 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006696 class_type->GetClangForwardType();
Greg Clayton5cf58b92011-10-05 22:22:08 +00006697
Greg Clayton72da3972011-08-16 18:40:23 +00006698 DWARFCompileUnitSP abs_cu_sp;
6699 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006700 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006701 if (abs_clang_decl_ctx)
6702 {
6703 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
6704 }
6705 else
Jim Inghamc1663042011-09-29 22:12:35 +00006706 {
Daniel Malead01b2952012-11-29 21:49:15 +00006707 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 +00006708 MakeUserID(die->GetOffset()),
6709 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006710 }
Greg Clayton72da3972011-08-16 18:40:23 +00006711 type_handled = true;
6712 }
6713 else
6714 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006715 ClangASTType class_opaque_type = class_type->GetClangForwardType();
6716 if (class_opaque_type.IsCXXClassType ())
Greg Clayton931180e2011-01-27 06:44:37 +00006717 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006718 if (class_opaque_type.IsBeingDefined ())
Greg Clayton72da3972011-08-16 18:40:23 +00006719 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006720 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
6721 // in the DWARF for C++ methods... Default to public for now...
6722 if (accessibility == eAccessNone)
6723 accessibility = eAccessPublic;
6724
6725 if (!is_static && !die->HasChildren())
6726 {
6727 // We have a C++ member function with no children (this pointer!)
6728 // and clang will get mad if we try and make a function that isn't
6729 // well formed in the DWARF, so we will just skip it...
6730 type_handled = true;
6731 }
6732 else
6733 {
6734 clang::CXXMethodDecl *cxx_method_decl;
6735 // REMOVE THE CRASH DESCRIPTION BELOW
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00006736 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 +00006737 type_name_cstr,
6738 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00006739 MakeUserID(die->GetOffset()),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00006740 m_obj_file->GetFileSpec().GetPath().c_str());
Greg Clayton20568dd2011-10-13 23:13:20 +00006741
Sean Callananc1b732d2011-11-01 18:07:13 +00006742 const bool is_attr_used = false;
6743
Greg Clayton57ee3062013-07-11 22:46:58 +00006744 cxx_method_decl = class_opaque_type.AddMethodToCXXRecordType (type_name_cstr,
6745 clang_type,
6746 accessibility,
6747 is_virtual,
6748 is_static,
6749 is_inline,
6750 is_explicit,
6751 is_attr_used,
6752 is_artificial);
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006753
Greg Clayton20568dd2011-10-13 23:13:20 +00006754 type_handled = cxx_method_decl != NULL;
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006755
6756 if (type_handled)
Jim Ingham379397632012-10-27 02:54:13 +00006757 {
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006758 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
6759
6760 Host::SetCrashDescription (NULL);
6761
6762
6763 ClangASTMetadata metadata;
6764 metadata.SetUserID(MakeUserID(die->GetOffset()));
6765
6766 if (!object_pointer_name.empty())
6767 {
6768 metadata.SetObjectPtrName(object_pointer_name.c_str());
6769 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006770 log->Printf ("Setting object pointer name: %s on method object %p.\n",
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006771 object_pointer_name.c_str(),
Greg Claytond0029442013-03-27 01:48:02 +00006772 cxx_method_decl);
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006773 }
Greg Claytond0029442013-03-27 01:48:02 +00006774 GetClangASTContext().SetMetadata (cxx_method_decl, metadata);
Jim Ingham379397632012-10-27 02:54:13 +00006775 }
Sean Callananb0640dc2013-04-09 23:22:08 +00006776 else
6777 {
Sean Callanande9ce872013-05-09 23:13:13 +00006778 ignore_containing_context = true;
Sean Callananb0640dc2013-04-09 23:22:08 +00006779 }
Greg Clayton20568dd2011-10-13 23:13:20 +00006780 }
Greg Clayton72da3972011-08-16 18:40:23 +00006781 }
6782 else
6783 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006784 // We were asked to parse the type for a method in a class, yet the
6785 // class hasn't been asked to complete itself through the
6786 // clang::ExternalASTSource protocol, so we need to just have the
6787 // class complete itself and do things the right way, then our
6788 // DIE should then have an entry in the m_die_to_type map. First
6789 // we need to modify the m_die_to_type so it doesn't think we are
6790 // trying to parse this DIE anymore...
6791 m_die_to_type[die] = NULL;
6792
6793 // Now we get the full type to force our class type to complete itself
6794 // using the clang::ExternalASTSource protocol which will parse all
6795 // base classes and all methods (including the method for this DIE).
6796 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00006797
Greg Clayton20568dd2011-10-13 23:13:20 +00006798 // The type for this DIE should have been filled in the function call above
6799 type_ptr = m_die_to_type[die];
Greg Claytone5476db2012-06-01 20:32:35 +00006800 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton20568dd2011-10-13 23:13:20 +00006801 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006802 type_sp = type_ptr->shared_from_this();
Greg Clayton20568dd2011-10-13 23:13:20 +00006803 break;
6804 }
Sean Callanan02eee4d2012-04-12 23:10:00 +00006805
6806 // FIXME This is fixing some even uglier behavior but we really need to
6807 // uniq the methods of each class as well as the class itself.
6808 // <rdar://problem/11240464>
6809 type_handled = true;
Greg Clayton72da3972011-08-16 18:40:23 +00006810 }
Greg Clayton931180e2011-01-27 06:44:37 +00006811 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006812 }
6813 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006814 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006815 }
Greg Clayton24739922010-10-13 03:15:28 +00006816
6817 if (!type_handled)
6818 {
6819 // We just have a function that isn't part of a class
Sean Callanande9ce872013-05-09 23:13:13 +00006820 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (ignore_containing_context ? GetClangASTContext().GetTranslationUnitDecl() : containing_decl_ctx,
Greg Clayton147e1fa2011-10-14 22:47:18 +00006821 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006822 clang_type,
6823 storage,
6824 is_inline);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006825
6826// if (template_param_infos.GetSize() > 0)
6827// {
6828// clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
6829// function_decl,
6830// type_name_cstr,
6831// template_param_infos);
6832//
6833// ast.CreateFunctionTemplateSpecializationInfo (function_decl,
6834// func_template_decl,
6835// template_param_infos);
6836// }
Greg Clayton24739922010-10-13 03:15:28 +00006837 // Add the decl to our DIE to decl context map
6838 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00006839 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00006840 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006841 ast.SetFunctionParameters (function_decl,
6842 &function_param_decls.front(),
6843 function_param_decls.size());
Sean Callanan60217122012-04-13 00:10:03 +00006844
Jim Ingham379397632012-10-27 02:54:13 +00006845 ClangASTMetadata metadata;
6846 metadata.SetUserID(MakeUserID(die->GetOffset()));
6847
6848 if (!object_pointer_name.empty())
6849 {
6850 metadata.SetObjectPtrName(object_pointer_name.c_str());
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006851 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006852 log->Printf ("Setting object pointer name: %s on function object %p.",
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006853 object_pointer_name.c_str(),
Greg Claytond0029442013-03-27 01:48:02 +00006854 function_decl);
Jim Ingham379397632012-10-27 02:54:13 +00006855 }
Greg Claytond0029442013-03-27 01:48:02 +00006856 GetClangASTContext().SetMetadata (function_decl, metadata);
Greg Clayton24739922010-10-13 03:15:28 +00006857 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006858 }
Greg Clayton81c22f62011-10-19 18:09:39 +00006859 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006860 this,
6861 type_name_const_str,
6862 0,
6863 NULL,
6864 LLDB_INVALID_UID,
6865 Type::eEncodingIsUID,
6866 &decl,
6867 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006868 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00006869 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006870 }
6871 break;
6872
6873 case DW_TAG_array_type:
6874 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006875 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006876 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006877
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006878 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006879 int64_t first_index = 0;
6880 uint32_t byte_stride = 0;
6881 uint32_t bit_stride = 0;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006882 bool is_vector = false;
Greg Claytond88d7592010-09-15 08:33:30 +00006883 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006884
6885 if (num_attributes > 0)
6886 {
6887 uint32_t i;
6888 for (i=0; i<num_attributes; ++i)
6889 {
6890 attr = attributes.AttributeAtIndex(i);
6891 DWARFFormValue form_value;
6892 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6893 {
6894 switch (attr)
6895 {
6896 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6897 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6898 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6899 case DW_AT_name:
6900 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006901 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006902 break;
6903
6904 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006905 case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006906 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
6907 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006908 case DW_AT_GNU_vector: is_vector = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006909 case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006910 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006911 case DW_AT_allocated:
6912 case DW_AT_associated:
6913 case DW_AT_data_location:
6914 case DW_AT_description:
6915 case DW_AT_ordering:
6916 case DW_AT_start_scope:
6917 case DW_AT_visibility:
6918 case DW_AT_specification:
6919 case DW_AT_abstract_origin:
6920 case DW_AT_sibling:
6921 break;
6922 }
6923 }
6924 }
6925
Daniel Malead01b2952012-11-29 21:49:15 +00006926 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 +00006927
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006928 Type *element_type = ResolveTypeUID(type_die_offset);
6929
6930 if (element_type)
6931 {
6932 std::vector<uint64_t> element_orders;
6933 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
6934 if (byte_stride == 0 && bit_stride == 0)
6935 byte_stride = element_type->GetByteSize();
Greg Clayton57ee3062013-07-11 22:46:58 +00006936 ClangASTType array_element_type = element_type->GetClangForwardType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006937 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
6938 uint64_t num_elements = 0;
6939 std::vector<uint64_t>::const_reverse_iterator pos;
6940 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
6941 for (pos = element_orders.rbegin(); pos != end; ++pos)
6942 {
6943 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006944 clang_type = ast.CreateArrayType (array_element_type,
Greg Clayton1c8ef472013-04-05 23:27:21 +00006945 num_elements,
6946 is_vector);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006947 array_element_type = clang_type;
Greg Clayton4ef877f2012-12-06 02:33:54 +00006948 array_element_bit_stride = num_elements ? array_element_bit_stride * num_elements : array_element_bit_stride;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006949 }
6950 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00006951 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006952 this,
6953 empty_name,
6954 array_element_bit_stride / 8,
6955 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00006956 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006957 Type::eEncodingIsUID,
6958 &decl,
6959 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006960 Type::eResolveStateFull));
6961 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006962 }
6963 }
6964 }
6965 break;
6966
Greg Clayton9b81a312010-06-12 01:20:30 +00006967 case DW_TAG_ptr_to_member_type:
6968 {
6969 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
6970 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
6971
Greg Claytond88d7592010-09-15 08:33:30 +00006972 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00006973
6974 if (num_attributes > 0) {
6975 uint32_t i;
6976 for (i=0; i<num_attributes; ++i)
6977 {
6978 attr = attributes.AttributeAtIndex(i);
6979 DWARFFormValue form_value;
6980 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6981 {
6982 switch (attr)
6983 {
6984 case DW_AT_type:
6985 type_die_offset = form_value.Reference(dwarf_cu); break;
6986 case DW_AT_containing_type:
6987 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
6988 }
6989 }
6990 }
6991
6992 Type *pointee_type = ResolveTypeUID(type_die_offset);
6993 Type *class_type = ResolveTypeUID(containing_type_die_offset);
6994
Greg Clayton57ee3062013-07-11 22:46:58 +00006995 ClangASTType pointee_clang_type = pointee_type->GetClangForwardType();
6996 ClangASTType class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00006997
Greg Clayton57ee3062013-07-11 22:46:58 +00006998 clang_type = pointee_clang_type.CreateMemberPointerType(class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00006999
Greg Clayton57ee3062013-07-11 22:46:58 +00007000 byte_size = clang_type.GetByteSize();
Greg Clayton9b81a312010-06-12 01:20:30 +00007001
Greg Clayton81c22f62011-10-19 18:09:39 +00007002 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00007003 this,
7004 type_name_const_str,
7005 byte_size,
7006 NULL,
7007 LLDB_INVALID_UID,
7008 Type::eEncodingIsUID,
7009 NULL,
7010 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00007011 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00007012 }
7013
7014 break;
7015 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007016 default:
Greg Clayton84afacd2012-11-07 23:09:32 +00007017 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",
7018 die->GetOffset(),
7019 tag,
7020 DW_TAG_value_to_name(tag));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007021 break;
7022 }
7023
7024 if (type_sp.get())
7025 {
7026 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7027 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7028
7029 SymbolContextScope * symbol_context_scope = NULL;
7030 if (sc_parent_tag == DW_TAG_compile_unit)
7031 {
7032 symbol_context_scope = sc.comp_unit;
7033 }
7034 else if (sc.function != NULL)
7035 {
Greg Clayton81c22f62011-10-19 18:09:39 +00007036 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007037 if (symbol_context_scope == NULL)
7038 symbol_context_scope = sc.function;
7039 }
7040
7041 if (symbol_context_scope != NULL)
7042 {
7043 type_sp->SetSymbolContextScope(symbol_context_scope);
7044 }
7045
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00007046 // We are ready to put this type into the uniqued list up at the module level
7047 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00007048
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00007049 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007050 }
7051 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00007052 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007053 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00007054 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007055 }
7056 }
7057 return type_sp;
7058}
7059
7060size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00007061SymbolFileDWARF::ParseTypes
7062(
7063 const SymbolContext& sc,
7064 DWARFCompileUnit* dwarf_cu,
7065 const DWARFDebugInfoEntry *die,
7066 bool parse_siblings,
7067 bool parse_children
7068)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007069{
7070 size_t types_added = 0;
7071 while (die != NULL)
7072 {
7073 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00007074 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007075 {
7076 if (type_is_new)
7077 ++types_added;
7078 }
7079
7080 if (parse_children && die->HasChildren())
7081 {
7082 if (die->Tag() == DW_TAG_subprogram)
7083 {
7084 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00007085 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007086 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
7087 }
7088 else
7089 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
7090 }
7091
7092 if (parse_siblings)
7093 die = die->GetSibling();
7094 else
7095 die = NULL;
7096 }
7097 return types_added;
7098}
7099
7100
7101size_t
7102SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
7103{
7104 assert(sc.comp_unit && sc.function);
7105 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00007106 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007107 if (dwarf_cu)
7108 {
7109 dw_offset_t function_die_offset = sc.function->GetID();
7110 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
7111 if (function_die)
7112 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00007113 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007114 }
7115 }
7116
7117 return functions_added;
7118}
7119
7120
7121size_t
7122SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
7123{
7124 // At least a compile unit must be valid
7125 assert(sc.comp_unit);
7126 size_t types_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00007127 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007128 if (dwarf_cu)
7129 {
7130 if (sc.function)
7131 {
7132 dw_offset_t function_die_offset = sc.function->GetID();
7133 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
7134 if (func_die && func_die->HasChildren())
7135 {
7136 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
7137 }
7138 }
7139 else
7140 {
7141 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
7142 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
7143 {
7144 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
7145 }
7146 }
7147 }
7148
7149 return types_added;
7150}
7151
7152size_t
7153SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
7154{
7155 if (sc.comp_unit != NULL)
7156 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00007157 DWARFDebugInfo* info = DebugInfo();
7158 if (info == NULL)
7159 return 0;
7160
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007161 if (sc.function)
7162 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007163 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get();
7164
7165 if (dwarf_cu == NULL)
7166 return 0;
7167
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007168 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00007169
Greg Claytonc7bece562013-01-25 18:06:21 +00007170 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
7171 if (func_lo_pc != LLDB_INVALID_ADDRESS)
Greg Claytone38a5ed2012-01-05 03:57:59 +00007172 {
7173 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00007174
Greg Claytone38a5ed2012-01-05 03:57:59 +00007175 // Let all blocks know they have parse all their variables
7176 sc.function->GetBlock (false).SetDidParseVariables (true, true);
7177 return num_variables;
7178 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007179 }
7180 else if (sc.comp_unit)
7181 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007182 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get();
7183
7184 if (dwarf_cu == NULL)
7185 return 0;
7186
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007187 uint32_t vars_added = 0;
7188 VariableListSP variables (sc.comp_unit->GetVariableList(false));
7189
7190 if (variables.get() == NULL)
7191 {
7192 variables.reset(new VariableList());
7193 sc.comp_unit->SetVariableList(variables);
7194
Greg Claytond4a2b372011-09-12 23:21:58 +00007195 DWARFCompileUnit* match_dwarf_cu = NULL;
7196 const DWARFDebugInfoEntry* die = NULL;
7197 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00007198 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00007199 {
Greg Clayton97fbc342011-10-20 22:30:33 +00007200 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00007201 {
7202 DWARFMappedHash::DIEInfoArray hash_data_array;
7203 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
7204 dwarf_cu->GetNextCompileUnitOffset(),
7205 hash_data_array))
7206 {
7207 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
7208 }
7209 }
Greg Clayton7f995132011-10-04 22:41:51 +00007210 }
7211 else
7212 {
7213 // Index if we already haven't to make sure the compile units
7214 // get indexed and make their global DIE index list
7215 if (!m_indexed)
7216 Index ();
7217
7218 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
7219 dwarf_cu->GetNextCompileUnitOffset(),
7220 die_offsets);
7221 }
7222
7223 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00007224 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007225 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007226 DWARFDebugInfo* debug_info = DebugInfo();
7227 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007228 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007229 const dw_offset_t die_offset = die_offsets[i];
7230 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00007231 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00007232 {
Greg Clayton95d87902011-11-11 03:16:25 +00007233 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
7234 if (var_sp)
7235 {
7236 variables->AddVariableIfUnique (var_sp);
7237 ++vars_added;
7238 }
Greg Claytond4a2b372011-09-12 23:21:58 +00007239 }
Greg Clayton95d87902011-11-11 03:16:25 +00007240 else
7241 {
7242 if (m_using_apple_tables)
7243 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00007244 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 +00007245 }
7246 }
7247
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007248 }
7249 }
7250 }
7251 return vars_added;
7252 }
7253 }
7254 return 0;
7255}
7256
7257
7258VariableSP
7259SymbolFileDWARF::ParseVariableDIE
7260(
7261 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007262 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007263 const DWARFDebugInfoEntry *die,
7264 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007265)
7266{
7267
Greg Clayton83c5cd92010-11-14 22:13:40 +00007268 VariableSP var_sp (m_die_to_variable_sp[die]);
7269 if (var_sp)
7270 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007271
7272 const dw_tag_t tag = die->Tag();
Richard Mitton0a558352013-10-17 21:14:00 +00007273 ModuleSP module = GetObjectFile()->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00007274
7275 if ((tag == DW_TAG_variable) ||
7276 (tag == DW_TAG_constant) ||
7277 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007278 {
Greg Clayton7f995132011-10-04 22:41:51 +00007279 DWARFDebugInfoEntry::Attributes attributes;
7280 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
7281 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007282 {
Greg Clayton7f995132011-10-04 22:41:51 +00007283 const char *name = NULL;
7284 const char *mangled = NULL;
7285 Declaration decl;
7286 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00007287 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00007288 DWARFExpression location;
7289 bool is_external = false;
7290 bool is_artificial = false;
7291 bool location_is_const_value_data = false;
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007292 bool has_explicit_location = false;
Greg Clayton23f59502012-07-17 03:23:13 +00007293 //AccessType accessibility = eAccessNone;
Greg Clayton7f995132011-10-04 22:41:51 +00007294
7295 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007296 {
Greg Clayton7f995132011-10-04 22:41:51 +00007297 dw_attr_t attr = attributes.AttributeAtIndex(i);
7298 DWARFFormValue form_value;
7299 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007300 {
Greg Clayton7f995132011-10-04 22:41:51 +00007301 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007302 {
Greg Clayton7f995132011-10-04 22:41:51 +00007303 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
7304 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
7305 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
7306 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton71415542012-12-08 00:24:40 +00007307 case DW_AT_linkage_name:
Greg Clayton7f995132011-10-04 22:41:51 +00007308 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Claytond1767f02011-12-08 02:13:16 +00007309 case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00007310 case DW_AT_external: is_external = form_value.Boolean(); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007311 case DW_AT_const_value:
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007312 // If we have already found a DW_AT_location attribute, ignore this attribute.
7313 if (!has_explicit_location)
7314 {
7315 location_is_const_value_data = true;
7316 // The constant value will be either a block, a data value or a string.
Ed Masteeeae7212013-10-24 20:43:47 +00007317 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007318 if (DWARFFormValue::IsBlockForm(form_value.Form()))
7319 {
7320 // Retrieve the value as a block expression.
7321 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7322 uint32_t block_length = form_value.Unsigned();
Richard Mitton0a558352013-10-17 21:14:00 +00007323 location.CopyOpcodeData(module, debug_info_data, block_offset, block_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007324 }
7325 else if (DWARFFormValue::IsDataForm(form_value.Form()))
7326 {
7327 // Retrieve the value as a data expression.
7328 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
7329 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7330 uint32_t data_length = fixed_form_sizes[form_value.Form()];
Richard Mitton0a558352013-10-17 21:14:00 +00007331 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007332 }
7333 else
7334 {
7335 // Retrieve the value as a string expression.
7336 if (form_value.Form() == DW_FORM_strp)
7337 {
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 const char *str = form_value.AsCString(&debug_info_data);
7346 uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart();
7347 uint32_t string_length = strlen(str) + 1;
Richard Mitton0a558352013-10-17 21:14:00 +00007348 location.CopyOpcodeData(module, debug_info_data, string_offset, string_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007349 }
7350 }
7351 }
7352 break;
Greg Clayton7f995132011-10-04 22:41:51 +00007353 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007354 {
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007355 location_is_const_value_data = false;
7356 has_explicit_location = true;
Greg Clayton7f995132011-10-04 22:41:51 +00007357 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007358 {
Ed Masteeeae7212013-10-24 20:43:47 +00007359 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Clayton7f995132011-10-04 22:41:51 +00007360
7361 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7362 uint32_t block_length = form_value.Unsigned();
Richard Mitton0a558352013-10-17 21:14:00 +00007363 location.CopyOpcodeData(module, get_debug_info_data(), block_offset, block_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007364 }
7365 else
7366 {
Ed Masteeeae7212013-10-24 20:43:47 +00007367 const DWARFDataExtractor& debug_loc_data = get_debug_loc_data();
Greg Clayton7f995132011-10-04 22:41:51 +00007368 const dw_offset_t debug_loc_offset = form_value.Unsigned();
7369
7370 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
7371 if (loc_list_length > 0)
7372 {
Richard Mitton0a558352013-10-17 21:14:00 +00007373 location.CopyOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007374 assert (func_low_pc != LLDB_INVALID_ADDRESS);
7375 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
7376 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007377 }
7378 }
Greg Clayton7f995132011-10-04 22:41:51 +00007379 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007380
Greg Clayton1c8ef472013-04-05 23:27:21 +00007381 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00007382 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007383 case DW_AT_declaration:
7384 case DW_AT_description:
7385 case DW_AT_endianity:
7386 case DW_AT_segment:
7387 case DW_AT_start_scope:
7388 case DW_AT_visibility:
7389 default:
7390 case DW_AT_abstract_origin:
7391 case DW_AT_sibling:
7392 case DW_AT_specification:
7393 break;
7394 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007395 }
7396 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007397
Greg Clayton9e9f2192013-05-17 00:55:28 +00007398 ValueType scope = eValueTypeInvalid;
7399
7400 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7401 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7402 SymbolContextScope * symbol_context_scope = NULL;
7403
7404 // DWARF doesn't specify if a DW_TAG_variable is a local, global
7405 // or static variable, so we have to do a little digging by
7406 // looking at the location of a varaible to see if it contains
7407 // a DW_OP_addr opcode _somewhere_ in the definition. I say
7408 // somewhere because clang likes to combine small global variables
7409 // into the same symbol and have locations like:
7410 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
7411 // So if we don't have a DW_TAG_formal_parameter, we can look at
7412 // the location to see if it contains a DW_OP_addr opcode, and
7413 // then we can correctly classify our variables.
7414 if (tag == DW_TAG_formal_parameter)
7415 scope = eValueTypeVariableArgument;
7416 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007417 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007418 bool op_error = false;
7419 // Check if the location has a DW_OP_addr with any address value...
7420 lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS;
7421 if (!location_is_const_value_data)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007422 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007423 location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error);
7424 if (op_error)
Greg Clayton96c09682012-01-04 22:56:43 +00007425 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007426 StreamString strm;
7427 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
7428 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 +00007429 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007430 }
Greg Claytond1767f02011-12-08 02:13:16 +00007431
Greg Clayton9e9f2192013-05-17 00:55:28 +00007432 if (location_DW_OP_addr != LLDB_INVALID_ADDRESS)
7433 {
7434 if (is_external)
7435 scope = eValueTypeVariableGlobal;
7436 else
7437 scope = eValueTypeVariableStatic;
7438
7439
7440 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile ();
7441
7442 if (debug_map_symfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007443 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007444 // When leaving the DWARF in the .o files on darwin,
7445 // when we have a global variable that wasn't initialized,
7446 // the .o file might not have allocated a virtual
7447 // address for the global variable. In this case it will
7448 // have created a symbol for the global variable
7449 // that is undefined/data and external and the value will
7450 // be the byte size of the variable. When we do the
7451 // address map in SymbolFileDWARFDebugMap we rely on
7452 // having an address, we need to do some magic here
7453 // so we can get the correct address for our global
7454 // variable. The address for all of these entries
7455 // will be zero, and there will be an undefined symbol
7456 // in this object file, and the executable will have
7457 // a matching symbol with a good address. So here we
7458 // dig up the correct address and replace it in the
7459 // location for the variable, and set the variable's
7460 // symbol context scope to be that of the main executable
7461 // so the file address will resolve correctly.
7462 bool linked_oso_file_addr = false;
7463 if (is_external && location_DW_OP_addr == 0)
Greg Clayton9422dd62013-03-04 21:46:16 +00007464 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007465 // we have a possible uninitialized extern global
7466 ConstString const_name(mangled ? mangled : name);
7467 ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile();
7468 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007469 {
Greg Clayton3046e662013-07-10 01:23:25 +00007470 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
Greg Clayton9e9f2192013-05-17 00:55:28 +00007471 if (debug_map_symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007472 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007473 Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
7474 eSymbolTypeData,
7475 Symtab::eDebugYes,
7476 Symtab::eVisibilityExtern);
7477 if (exe_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007478 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007479 if (exe_symbol->ValueIsAddress())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007480 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007481 const addr_t exe_file_addr = exe_symbol->GetAddress().GetFileAddress();
7482 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007483 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007484 if (location.Update_DW_OP_addr (exe_file_addr))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007485 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007486 linked_oso_file_addr = true;
7487 symbol_context_scope = exe_symbol;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007488 }
7489 }
7490 }
7491 }
7492 }
7493 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007494 }
Greg Clayton9422dd62013-03-04 21:46:16 +00007495
Greg Clayton9e9f2192013-05-17 00:55:28 +00007496 if (!linked_oso_file_addr)
7497 {
7498 // The DW_OP_addr is not zero, but it contains a .o file address which
7499 // needs to be linked up correctly.
7500 const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr);
7501 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton9422dd62013-03-04 21:46:16 +00007502 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007503 // Update the file address for this variable
7504 location.Update_DW_OP_addr (exe_file_addr);
7505 }
7506 else
7507 {
7508 // Variable didn't make it into the final executable
7509 return var_sp;
Greg Clayton9422dd62013-03-04 21:46:16 +00007510 }
Greg Claytond1767f02011-12-08 02:13:16 +00007511 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007512 }
Greg Clayton5cf58b92011-10-05 22:22:08 +00007513 }
7514 else
7515 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007516 scope = eValueTypeVariableLocal;
Greg Clayton5cf58b92011-10-05 22:22:08 +00007517 }
Greg Clayton7f995132011-10-04 22:41:51 +00007518 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007519
7520 if (symbol_context_scope == NULL)
7521 {
7522 switch (parent_tag)
7523 {
7524 case DW_TAG_subprogram:
7525 case DW_TAG_inlined_subroutine:
7526 case DW_TAG_lexical_block:
7527 if (sc.function)
7528 {
7529 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
7530 if (symbol_context_scope == NULL)
7531 symbol_context_scope = sc.function;
7532 }
7533 break;
7534
7535 default:
7536 symbol_context_scope = sc.comp_unit;
7537 break;
7538 }
7539 }
7540
7541 if (symbol_context_scope)
7542 {
7543 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
7544 name,
7545 mangled,
7546 SymbolFileTypeSP (new SymbolFileType(*this, type_uid)),
7547 scope,
7548 symbol_context_scope,
7549 &decl,
7550 location,
7551 is_external,
7552 is_artificial));
7553
7554 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
7555 }
7556 else
7557 {
7558 // Not ready to parse this variable yet. It might be a global
7559 // or static variable that is in a function scope and the function
7560 // in the symbol context wasn't filled in yet
7561 return var_sp;
7562 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007563 }
Greg Clayton7f995132011-10-04 22:41:51 +00007564 // Cache var_sp even if NULL (the variable was just a specification or
7565 // was missing vital information to be able to be displayed in the debugger
7566 // (missing location due to optimization, etc)) so we don't re-parse
7567 // this DIE over and over later...
7568 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007569 }
7570 return var_sp;
7571}
7572
Greg Claytonc662ec82011-06-17 22:10:16 +00007573
7574const DWARFDebugInfoEntry *
7575SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
7576 dw_offset_t spec_block_die_offset,
7577 DWARFCompileUnit **result_die_cu_handle)
7578{
7579 // Give the concrete function die specified by "func_die_offset", find the
7580 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7581 // to "spec_block_die_offset"
7582 DWARFDebugInfo* info = DebugInfo();
7583
7584 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
7585 if (die)
7586 {
7587 assert (*result_die_cu_handle);
7588 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
7589 }
7590 return NULL;
7591}
7592
7593
7594const DWARFDebugInfoEntry *
7595SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
7596 const DWARFDebugInfoEntry *die,
7597 dw_offset_t spec_block_die_offset,
7598 DWARFCompileUnit **result_die_cu_handle)
7599{
7600 if (die)
7601 {
7602 switch (die->Tag())
7603 {
7604 case DW_TAG_subprogram:
7605 case DW_TAG_inlined_subroutine:
7606 case DW_TAG_lexical_block:
7607 {
7608 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
7609 {
7610 *result_die_cu_handle = dwarf_cu;
7611 return die;
7612 }
7613
7614 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
7615 {
7616 *result_die_cu_handle = dwarf_cu;
7617 return die;
7618 }
7619 }
7620 break;
7621 }
7622
7623 // Give the concrete function die specified by "func_die_offset", find the
7624 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7625 // to "spec_block_die_offset"
7626 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
7627 {
7628 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
7629 child_die,
7630 spec_block_die_offset,
7631 result_die_cu_handle);
7632 if (result_die)
7633 return result_die;
7634 }
7635 }
7636
7637 *result_die_cu_handle = NULL;
7638 return NULL;
7639}
7640
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007641size_t
7642SymbolFileDWARF::ParseVariables
7643(
7644 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007645 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007646 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007647 const DWARFDebugInfoEntry *orig_die,
7648 bool parse_siblings,
7649 bool parse_children,
7650 VariableList* cc_variable_list
7651)
7652{
7653 if (orig_die == NULL)
7654 return 0;
7655
Greg Claytonc662ec82011-06-17 22:10:16 +00007656 VariableListSP variable_list_sp;
7657
7658 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007659 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00007660 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007661 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007662 dw_tag_t tag = die->Tag();
7663
7664 // Check to see if we have already parsed this variable or constant?
7665 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007666 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007667 if (cc_variable_list)
7668 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007669 }
7670 else
7671 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007672 // We haven't already parsed it, lets do that now.
7673 if ((tag == DW_TAG_variable) ||
7674 (tag == DW_TAG_constant) ||
7675 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007676 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007677 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00007678 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007679 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
7680 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7681 switch (parent_tag)
7682 {
7683 case DW_TAG_compile_unit:
7684 if (sc.comp_unit != NULL)
7685 {
7686 variable_list_sp = sc.comp_unit->GetVariableList(false);
7687 if (variable_list_sp.get() == NULL)
7688 {
7689 variable_list_sp.reset(new VariableList());
7690 sc.comp_unit->SetVariableList(variable_list_sp);
7691 }
7692 }
7693 else
7694 {
Daniel Malead01b2952012-11-29 21:49:15 +00007695 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 +00007696 MakeUserID(sc_parent_die->GetOffset()),
7697 DW_TAG_value_to_name (parent_tag),
7698 MakeUserID(orig_die->GetOffset()),
7699 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007700 }
7701 break;
7702
7703 case DW_TAG_subprogram:
7704 case DW_TAG_inlined_subroutine:
7705 case DW_TAG_lexical_block:
7706 if (sc.function != NULL)
7707 {
7708 // Check to see if we already have parsed the variables for the given scope
7709
Greg Clayton81c22f62011-10-19 18:09:39 +00007710 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007711 if (block == NULL)
7712 {
7713 // This must be a specification or abstract origin with
7714 // a concrete block couterpart in the current function. We need
7715 // to find the concrete block so we can correctly add the
7716 // variable to it
7717 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
7718 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
7719 sc_parent_die->GetOffset(),
7720 &concrete_block_die_cu);
7721 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00007722 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007723 }
7724
7725 if (block != NULL)
7726 {
7727 const bool can_create = false;
7728 variable_list_sp = block->GetBlockVariableList (can_create);
7729 if (variable_list_sp.get() == NULL)
7730 {
7731 variable_list_sp.reset(new VariableList());
7732 block->SetVariableList(variable_list_sp);
7733 }
7734 }
7735 }
7736 break;
7737
7738 default:
Daniel Malead01b2952012-11-29 21:49:15 +00007739 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 +00007740 MakeUserID(orig_die->GetOffset()),
7741 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007742 break;
7743 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00007744 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007745
7746 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007747 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00007748 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
7749 if (var_sp)
7750 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007751 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00007752 if (cc_variable_list)
7753 cc_variable_list->AddVariableIfUnique (var_sp);
7754 ++vars_added;
7755 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007756 }
7757 }
7758 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007759
7760 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
7761
7762 if (!skip_children && parse_children && die->HasChildren())
7763 {
7764 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
7765 }
7766
7767 if (parse_siblings)
7768 die = die->GetSibling();
7769 else
7770 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007771 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007772 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007773}
7774
7775//------------------------------------------------------------------
7776// PluginInterface protocol
7777//------------------------------------------------------------------
Greg Clayton57abc5d2013-05-10 21:47:16 +00007778ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007779SymbolFileDWARF::GetPluginName()
7780{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007781 return GetPluginNameStatic();
7782}
7783
7784uint32_t
7785SymbolFileDWARF::GetPluginVersion()
7786{
7787 return 1;
7788}
7789
7790void
Greg Clayton6beaaa62011-01-17 03:46:26 +00007791SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
7792{
7793 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
Greg Clayton57ee3062013-07-11 22:46:58 +00007794 ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
Greg Clayton6beaaa62011-01-17 03:46:26 +00007795 if (clang_type)
7796 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7797}
7798
7799void
7800SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
7801{
7802 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
Greg Clayton57ee3062013-07-11 22:46:58 +00007803 ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
Greg Clayton6beaaa62011-01-17 03:46:26 +00007804 if (clang_type)
7805 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7806}
7807
Greg Claytona2721472011-06-25 00:44:06 +00007808void
Sean Callanancc427fa2011-07-30 02:42:06 +00007809SymbolFileDWARF::DumpIndexes ()
7810{
7811 StreamFile s(stdout, false);
7812
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00007813 s.Printf ("DWARF index for (%s) '%s':",
Sean Callanancc427fa2011-07-30 02:42:06 +00007814 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00007815 GetObjectFile()->GetFileSpec().GetPath().c_str());
Sean Callanancc427fa2011-07-30 02:42:06 +00007816 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
7817 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
7818 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
7819 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
7820 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
7821 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
7822 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
7823 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
7824}
7825
7826void
7827SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
7828 const char *name,
7829 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00007830{
Sean Callanancc427fa2011-07-30 02:42:06 +00007831 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00007832
7833 if (iter == m_decl_ctx_to_die.end())
7834 return;
7835
Greg Claytoncb5860a2011-10-13 23:49:28 +00007836 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00007837 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007838 const DWARFDebugInfoEntry *context_die = *pos;
7839
7840 if (!results)
7841 return;
7842
7843 DWARFDebugInfo* info = DebugInfo();
7844
7845 DIEArray die_offsets;
7846
7847 DWARFCompileUnit* dwarf_cu = NULL;
7848 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton220a0072011-12-09 08:48:30 +00007849
7850 if (m_using_apple_tables)
7851 {
7852 if (m_apple_types_ap.get())
7853 m_apple_types_ap->FindByName (name, die_offsets);
7854 }
7855 else
7856 {
7857 if (!m_indexed)
7858 Index ();
7859
7860 m_type_index.Find (ConstString(name), die_offsets);
7861 }
7862
Greg Clayton220a0072011-12-09 08:48:30 +00007863 const size_t num_matches = die_offsets.size();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007864
7865 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00007866 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007867 for (size_t i = 0; i < num_matches; ++i)
7868 {
7869 const dw_offset_t die_offset = die_offsets[i];
7870 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00007871
Greg Claytoncb5860a2011-10-13 23:49:28 +00007872 if (die->GetParent() != context_die)
7873 continue;
7874
7875 Type *matching_type = ResolveType (dwarf_cu, die);
7876
Greg Clayton57ee3062013-07-11 22:46:58 +00007877 clang::QualType qual_type = matching_type->GetClangForwardType().GetQualType();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007878
7879 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
7880 {
7881 clang::TagDecl *tag_decl = tag_type->getDecl();
7882 results->push_back(tag_decl);
7883 }
7884 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
7885 {
7886 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
7887 results->push_back(typedef_decl);
7888 }
Greg Claytona2721472011-06-25 00:44:06 +00007889 }
7890 }
7891 }
7892}
7893
7894void
7895SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00007896 const clang::DeclContext *decl_context,
7897 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00007898 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
7899{
Greg Clayton85ae2e12011-10-18 23:36:41 +00007900
7901 switch (decl_context->getDeclKind())
7902 {
7903 case clang::Decl::Namespace:
7904 case clang::Decl::TranslationUnit:
7905 {
7906 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7907 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
7908 }
7909 break;
7910 default:
7911 break;
7912 }
Greg Claytona2721472011-06-25 00:44:06 +00007913}
Greg Claytoncaab74e2012-01-28 00:48:57 +00007914
7915bool
7916SymbolFileDWARF::LayoutRecordType (void *baton,
7917 const clang::RecordDecl *record_decl,
7918 uint64_t &size,
7919 uint64_t &alignment,
7920 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7921 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7922 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7923{
7924 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7925 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
7926}
7927
7928
7929bool
7930SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl,
7931 uint64_t &bit_size,
7932 uint64_t &alignment,
7933 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7934 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7935 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7936{
Greg Clayton5160ce52013-03-27 23:08:40 +00007937 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Claytoncaab74e2012-01-28 00:48:57 +00007938 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
7939 bool success = false;
7940 base_offsets.clear();
7941 vbase_offsets.clear();
7942 if (pos != m_record_decl_to_layout_map.end())
7943 {
7944 bit_size = pos->second.bit_size;
7945 alignment = pos->second.alignment;
7946 field_offsets.swap(pos->second.field_offsets);
Greg Clayton2508b9b2012-11-01 23:20:02 +00007947 base_offsets.swap (pos->second.base_offsets);
7948 vbase_offsets.swap (pos->second.vbase_offsets);
Greg Claytoncaab74e2012-01-28 00:48:57 +00007949 m_record_decl_to_layout_map.erase(pos);
7950 success = true;
7951 }
7952 else
7953 {
7954 bit_size = 0;
7955 alignment = 0;
7956 field_offsets.clear();
7957 }
7958
7959 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00007960 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00007961 "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 +00007962 record_decl,
7963 bit_size,
7964 alignment,
7965 (uint32_t)field_offsets.size(),
7966 (uint32_t)base_offsets.size(),
7967 (uint32_t)vbase_offsets.size(),
7968 success);
7969 return success;
7970}
7971
7972
Greg Clayton1f746072012-08-29 21:13:06 +00007973SymbolFileDWARFDebugMap *
7974SymbolFileDWARF::GetDebugMapSymfile ()
7975{
7976 if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired())
7977 {
7978 lldb::ModuleSP module_sp (m_debug_map_module_wp.lock());
7979 if (module_sp)
7980 {
7981 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
7982 if (sym_vendor)
7983 m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile();
7984 }
7985 }
7986 return m_debug_map_symfile;
7987}
7988
Greg Claytoncaab74e2012-01-28 00:48:57 +00007989