blob: fa2d05819c42c1652b6b3e8825bbff136306c4ea [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>
73#define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
74#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 Clayton0fc4f312013-06-20 01:23:18 +0000410 std::set<clang_type_t> 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 Clayton0fc4f312013-06-20 01:23:18 +0000414 clang_type_t clang_type = type->GetClangForwardType();
415 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
702const DataExtractor&
Greg Clayton4ceb9982010-07-21 22:54:26 +0000703SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &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
731const DataExtractor&
732SymbolFileDWARF::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
737const DataExtractor&
Greg Claytond4a2b372011-09-12 23:21:58 +0000738SymbolFileDWARF::get_debug_aranges_data()
739{
740 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
741}
742
743const DataExtractor&
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
749const DataExtractor&
750SymbolFileDWARF::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
755const DataExtractor&
756SymbolFileDWARF::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
761const DataExtractor&
762SymbolFileDWARF::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
767const DataExtractor&
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
773const DataExtractor&
774SymbolFileDWARF::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
Greg Claytonf9eec202011-09-01 23:16:13 +0000779const DataExtractor&
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
785const DataExtractor&
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
Greg Clayton7f995132011-10-04 22:41:51 +0000791const DataExtractor&
792SymbolFileDWARF::get_apple_namespaces_data()
793{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000794 return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
795}
796
797const DataExtractor&
798SymbolFileDWARF::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 {
809 const DataExtractor &debug_abbrev_data = get_debug_abbrev_data();
810 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;
1427 clang_type_t clang_type = NULL;
1428 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)
1468 clang_type = ast->VoidTy.getAsOpaquePtr();
1469
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 Clayton3c2e3ae2012-02-06 06:42:51 +00001478 clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type));
Greg Clayton283b2652013-04-23 22:38:02 +00001479 if (tag == DW_TAG_template_value_parameter &&
1480 lldb_type != NULL &&
1481 ClangASTContext::IsIntegerType (clang_type, is_signed) &&
1482 uval64_valid)
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001483 {
1484 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
Greg Clayton283b2652013-04-23 22:38:02 +00001485 template_param_infos.args.push_back (clang::TemplateArgument (*ast,
Sean Callanan3d654b32012-09-24 22:25:51 +00001486 llvm::APSInt(apint),
1487 clang_qual_type));
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001488 }
1489 else
1490 {
1491 template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type));
1492 }
1493 }
1494 else
1495 {
1496 return false;
1497 }
1498
1499 }
1500 }
1501 return true;
1502
1503 default:
1504 break;
1505 }
1506 return false;
1507}
1508
1509bool
Greg Claytonf0705c82011-10-22 03:33:13 +00001510SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1511 const DWARFDebugInfoEntry *parent_die,
1512 ClangASTContext::TemplateParameterInfos &template_param_infos)
1513{
1514
1515 if (parent_die == NULL)
Filipe Cabecinhas52008c62012-05-23 16:24:11 +00001516 return false;
Greg Claytonf0705c82011-10-22 03:33:13 +00001517
Greg Claytonf0705c82011-10-22 03:33:13 +00001518 Args template_parameter_names;
1519 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1520 die != NULL;
1521 die = die->GetSibling())
1522 {
1523 const dw_tag_t tag = die->Tag();
1524
1525 switch (tag)
1526 {
1527 case DW_TAG_template_type_parameter:
1528 case DW_TAG_template_value_parameter:
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001529 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Claytonf0705c82011-10-22 03:33:13 +00001530 break;
1531
1532 default:
1533 break;
1534 }
1535 }
1536 if (template_param_infos.args.empty())
1537 return false;
1538 return template_param_infos.args.size() == template_param_infos.names.size();
1539}
1540
1541clang::ClassTemplateDecl *
1542SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001543 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001544 const char *parent_name,
1545 int tag_decl_kind,
1546 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1547{
1548 if (template_param_infos.IsValid())
1549 {
1550 std::string template_basename(parent_name);
1551 template_basename.erase (template_basename.find('<'));
1552 ClangASTContext &ast = GetClangASTContext();
1553
1554 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001555 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001556 template_basename.c_str(),
1557 tag_decl_kind,
1558 template_param_infos);
1559 }
1560 return NULL;
1561}
1562
Sean Callanana0b80ab2012-06-04 22:28:05 +00001563class SymbolFileDWARF::DelayedAddObjCClassProperty
1564{
1565public:
1566 DelayedAddObjCClassProperty
1567 (
1568 clang::ASTContext *ast,
1569 lldb::clang_type_t class_opaque_type,
1570 const char *property_name,
1571 lldb::clang_type_t property_opaque_type, // The property type is only required if you don't have an ivar decl
1572 clang::ObjCIvarDecl *ivar_decl,
1573 const char *property_setter_name,
1574 const char *property_getter_name,
1575 uint32_t property_attributes,
Greg Claytonc4ffd662013-03-08 01:37:30 +00001576 const ClangASTMetadata *metadata
Sean Callanana0b80ab2012-06-04 22:28:05 +00001577 ) :
1578 m_ast (ast),
1579 m_class_opaque_type (class_opaque_type),
1580 m_property_name (property_name),
1581 m_property_opaque_type (property_opaque_type),
1582 m_ivar_decl (ivar_decl),
1583 m_property_setter_name (property_setter_name),
1584 m_property_getter_name (property_getter_name),
Jim Ingham379397632012-10-27 02:54:13 +00001585 m_property_attributes (property_attributes)
Sean Callanana0b80ab2012-06-04 22:28:05 +00001586 {
Jim Ingham379397632012-10-27 02:54:13 +00001587 if (metadata != NULL)
1588 {
1589 m_metadata_ap.reset(new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001590 *m_metadata_ap = *metadata;
Jim Ingham379397632012-10-27 02:54:13 +00001591 }
1592 }
1593
1594 DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs)
1595 {
Daniel Malead4c5be62012-11-12 21:02:14 +00001596 *this = rhs;
1597 }
1598
1599 DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs)
1600 {
Jim Ingham379397632012-10-27 02:54:13 +00001601 m_ast = rhs.m_ast;
1602 m_class_opaque_type = rhs.m_class_opaque_type;
1603 m_property_name = rhs.m_property_name;
1604 m_property_opaque_type = rhs.m_property_opaque_type;
1605 m_ivar_decl = rhs.m_ivar_decl;
1606 m_property_setter_name = rhs.m_property_setter_name;
1607 m_property_getter_name = rhs.m_property_getter_name;
1608 m_property_attributes = rhs.m_property_attributes;
1609
1610 if (rhs.m_metadata_ap.get())
1611 {
1612 m_metadata_ap.reset (new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001613 *m_metadata_ap = *rhs.m_metadata_ap;
Jim Ingham379397632012-10-27 02:54:13 +00001614 }
Daniel Malead4c5be62012-11-12 21:02:14 +00001615 return *this;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001616 }
1617
1618 bool Finalize() const
1619 {
Greg Claytonc4ffd662013-03-08 01:37:30 +00001620 return ClangASTContext::AddObjCClassProperty (m_ast,
1621 m_class_opaque_type,
1622 m_property_name,
1623 m_property_opaque_type,
1624 m_ivar_decl,
1625 m_property_setter_name,
1626 m_property_getter_name,
1627 m_property_attributes,
1628 m_metadata_ap.get());
Sean Callanana0b80ab2012-06-04 22:28:05 +00001629 }
1630private:
1631 clang::ASTContext *m_ast;
1632 lldb::clang_type_t m_class_opaque_type;
1633 const char *m_property_name;
1634 lldb::clang_type_t m_property_opaque_type;
1635 clang::ObjCIvarDecl *m_ivar_decl;
1636 const char *m_property_setter_name;
1637 const char *m_property_getter_name;
1638 uint32_t m_property_attributes;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001639 std::unique_ptr<ClangASTMetadata> m_metadata_ap;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001640};
1641
Sean Callananfaa0bb32012-12-05 23:37:14 +00001642struct BitfieldInfo
1643{
1644 uint64_t bit_size;
1645 uint64_t bit_offset;
1646
1647 BitfieldInfo () :
1648 bit_size (LLDB_INVALID_ADDRESS),
1649 bit_offset (LLDB_INVALID_ADDRESS)
1650 {
1651 }
1652
1653 bool IsValid ()
1654 {
1655 return (bit_size != LLDB_INVALID_ADDRESS) &&
1656 (bit_offset != LLDB_INVALID_ADDRESS);
1657 }
1658};
1659
Greg Claytonc4ffd662013-03-08 01:37:30 +00001660
1661bool
1662SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu,
1663 const DWARFDebugInfoEntry *parent_die)
1664{
1665 if (parent_die)
1666 {
1667 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1668 {
1669 dw_tag_t tag = die->Tag();
1670 bool check_virtuality = false;
1671 switch (tag)
1672 {
1673 case DW_TAG_inheritance:
1674 case DW_TAG_subprogram:
1675 check_virtuality = true;
1676 break;
1677 default:
1678 break;
1679 }
1680 if (check_virtuality)
1681 {
1682 if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0)
1683 return true;
1684 }
1685 }
1686 }
1687 return false;
1688}
1689
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001690size_t
1691SymbolFileDWARF::ParseChildMembers
1692(
1693 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001694 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001695 const DWARFDebugInfoEntry *parent_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00001696 clang_type_t class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001697 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001698 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1699 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001700 DWARFDIECollection& member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001701 DelayedPropertyList& delayed_properties,
Sean Callananc7fbf732010-08-06 00:32:49 +00001702 AccessType& default_accessibility,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001703 bool &is_a_class,
1704 LayoutInfo &layout_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001705)
1706{
1707 if (parent_die == NULL)
1708 return 0;
1709
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001710 size_t count = 0;
1711 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001712 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001713 uint32_t member_idx = 0;
Sean Callananfaa0bb32012-12-05 23:37:14 +00001714 BitfieldInfo last_field_info;
Greg Claytond88d7592010-09-15 08:33:30 +00001715
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001716 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1717 {
1718 dw_tag_t tag = die->Tag();
1719
1720 switch (tag)
1721 {
1722 case DW_TAG_member:
Sean Callanan3d654b32012-09-24 22:25:51 +00001723 case DW_TAG_APPLE_property:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001724 {
1725 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001726 const size_t num_attributes = die->GetAttributes (this,
1727 dwarf_cu,
1728 fixed_form_sizes,
1729 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001730 if (num_attributes > 0)
1731 {
1732 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001733 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001734 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001735 const char *prop_name = NULL;
1736 const char *prop_getter_name = NULL;
1737 const char *prop_setter_name = NULL;
Greg Claytone528efd72013-02-26 23:45:18 +00001738 uint32_t prop_attributes = 0;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001739
1740
Greg Clayton24739922010-10-13 03:15:28 +00001741 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001742 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001743 AccessType accessibility = eAccessNone;
Greg Claytoncaab74e2012-01-28 00:48:57 +00001744 uint32_t member_byte_offset = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001745 size_t byte_size = 0;
1746 size_t bit_offset = 0;
1747 size_t bit_size = 0;
Greg Claytone528efd72013-02-26 23:45:18 +00001748 bool is_external = false; // On DW_TAG_members, this means the member is static
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001749 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001750 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001751 {
1752 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1753 DWARFFormValue form_value;
1754 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1755 {
1756 switch (attr)
1757 {
1758 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1759 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1760 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1761 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1762 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1763 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1764 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1765 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1766 case DW_AT_data_member_location:
Greg Claytoncaab74e2012-01-28 00:48:57 +00001767 if (form_value.BlockData())
1768 {
1769 Value initialValue(0);
1770 Value memberOffset(0);
1771 const DataExtractor& debug_info_data = get_debug_info_data();
1772 uint32_t block_length = form_value.Unsigned();
1773 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1774 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
1775 NULL, // clang::ASTContext *
1776 NULL, // ClangExpressionVariableList *
1777 NULL, // ClangExpressionDeclMap *
1778 NULL, // RegisterContext *
1779 debug_info_data,
1780 block_offset,
1781 block_length,
1782 eRegisterKindDWARF,
1783 &initialValue,
1784 memberOffset,
1785 NULL))
1786 {
1787 member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1788 }
1789 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001790 break;
1791
Greg Clayton8cf05932010-07-22 18:30:50 +00001792 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00001793 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001794 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1795 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1796 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1797 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00001798 case DW_AT_external: is_external = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001799
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001800 default:
Greg Clayton1b02c172012-03-14 21:00:47 +00001801 case DW_AT_declaration:
1802 case DW_AT_description:
1803 case DW_AT_mutable:
1804 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001805 case DW_AT_sibling:
1806 break;
1807 }
1808 }
1809 }
Sean Callanana6582262012-04-05 00:12:52 +00001810
1811 if (prop_name)
Sean Callanan751aac62012-03-29 19:07:06 +00001812 {
Sean Callanana6582262012-04-05 00:12:52 +00001813 ConstString fixed_getter;
1814 ConstString fixed_setter;
1815
1816 // Check if the property getter/setter were provided as full
1817 // names. We want basenames, so we extract them.
1818
1819 if (prop_getter_name && prop_getter_name[0] == '-')
1820 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001821 ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true);
1822 prop_getter_name = prop_getter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001823 }
1824
1825 if (prop_setter_name && prop_setter_name[0] == '-')
1826 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001827 ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true);
1828 prop_setter_name = prop_setter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001829 }
1830
1831 // If the names haven't been provided, they need to be
1832 // filled in.
1833
1834 if (!prop_getter_name)
1835 {
1836 prop_getter_name = prop_name;
1837 }
1838 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly))
1839 {
1840 StreamString ss;
1841
1842 ss.Printf("set%c%s:",
1843 toupper(prop_name[0]),
1844 &prop_name[1]);
1845
1846 fixed_setter.SetCString(ss.GetData());
1847 prop_setter_name = fixed_setter.GetCString();
1848 }
Sean Callanan751aac62012-03-29 19:07:06 +00001849 }
1850
1851 // Clang has a DWARF generation bug where sometimes it
Greg Clayton44953932011-10-25 01:25:35 +00001852 // represents fields that are references with bad byte size
1853 // and bit size/offset information such as:
1854 //
1855 // DW_AT_byte_size( 0x00 )
1856 // DW_AT_bit_size( 0x40 )
1857 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1858 //
1859 // So check the bit offset to make sure it is sane, and if
1860 // the values are not sane, remove them. If we don't do this
1861 // then we will end up with a crash if we try to use this
1862 // type in an expression when clang becomes unhappy with its
1863 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001864
Greg Clayton44953932011-10-25 01:25:35 +00001865 if (bit_offset > 128)
1866 {
1867 bit_size = 0;
1868 bit_offset = 0;
1869 }
1870
1871 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00001872 if (class_language == eLanguageTypeObjC ||
1873 class_language == eLanguageTypeObjC_plus_plus)
1874 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001875
1876 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1877 {
1878 // Not all compilers will mark the vtable pointer
1879 // member as artificial (llvm-gcc). We can't have
1880 // the virtual members in our classes otherwise it
1881 // throws off all child offsets since we end up
1882 // having and extra pointer sized member in our
1883 // class layouts.
1884 is_artificial = true;
1885 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001886
Greg Claytone528efd72013-02-26 23:45:18 +00001887 // Skip static members
1888 if (is_external && member_byte_offset == UINT32_MAX)
Greg Clayton973b6c92013-04-11 16:57:51 +00001889 {
1890 Type *var_type = ResolveTypeUID(encoding_uid);
1891
1892 if (var_type)
1893 {
1894 GetClangASTContext().AddVariableToRecordType (class_clang_type,
1895 name,
1896 var_type->GetClangLayoutType(),
1897 accessibility);
1898 }
Greg Claytone528efd72013-02-26 23:45:18 +00001899 break;
Greg Clayton973b6c92013-04-11 16:57:51 +00001900 }
Greg Claytone528efd72013-02-26 23:45:18 +00001901
Greg Clayton24739922010-10-13 03:15:28 +00001902 if (is_artificial == false)
1903 {
1904 Type *member_type = ResolveTypeUID(encoding_uid);
Sean Callananfa3ab452012-12-14 00:54:13 +00001905
Jim Inghame3ae82a2011-11-12 01:36:43 +00001906 clang::FieldDecl *field_decl = NULL;
Sean Callanan751aac62012-03-29 19:07:06 +00001907 if (tag == DW_TAG_member)
Greg Claytond16e1e52011-07-12 17:06:17 +00001908 {
Sean Callanan751aac62012-03-29 19:07:06 +00001909 if (member_type)
1910 {
1911 if (accessibility == eAccessNone)
1912 accessibility = default_accessibility;
1913 member_accessibilities.push_back(accessibility);
Sean Callananfaa0bb32012-12-05 23:37:14 +00001914
1915 BitfieldInfo this_field_info;
1916
1917 this_field_info.bit_size = bit_size;
1918
1919 if (member_byte_offset != UINT32_MAX || bit_size != 0)
Greg Clayton88bc7f32012-11-06 00:20:41 +00001920 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001921 /////////////////////////////////////////////////////////////
1922 // How to locate a field given the DWARF debug information
1923 //
1924 // AT_byte_size indicates the size of the word in which the
1925 // bit offset must be interpreted.
1926 //
1927 // AT_data_member_location indicates the byte offset of the
1928 // word from the base address of the structure.
1929 //
1930 // AT_bit_offset indicates how many bits into the word
1931 // (according to the host endianness) the low-order bit of
1932 // the field starts. AT_bit_offset can be negative.
1933 //
1934 // AT_bit_size indicates the size of the field in bits.
1935 /////////////////////////////////////////////////////////////
1936
1937 this_field_info.bit_offset = 0;
1938
1939 this_field_info.bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
1940
1941 if (GetObjectFile()->GetByteOrder() == eByteOrderLittle)
1942 {
1943 this_field_info.bit_offset += byte_size * 8;
1944 this_field_info.bit_offset -= (bit_offset + bit_size);
1945 }
1946 else
1947 {
1948 this_field_info.bit_offset += bit_offset;
1949 }
1950 }
1951
1952 // If the member to be emitted did not start on a character boundary and there is
1953 // empty space between the last field and this one, then we need to emit an
1954 // anonymous member filling up the space up to its start. There are three cases
1955 // here:
1956 //
1957 // 1 If the previous member ended on a character boundary, then we can emit an
1958 // anonymous member starting at the most recent character boundary.
1959 //
1960 // 2 If the previous member did not end on a character boundary and the distance
1961 // from the end of the previous member to the current member is less than a
1962 // word width, then we can emit an anonymous member starting right after the
1963 // previous member and right before this member.
1964 //
1965 // 3 If the previous member did not end on a character boundary and the distance
1966 // from the end of the previous member to the current member is greater than
1967 // or equal a word width, then we act as in Case 1.
1968
1969 const uint64_t character_width = 8;
1970 const uint64_t word_width = 32;
1971
1972 if (this_field_info.IsValid())
1973 {
1974 // Objective-C has invalid DW_AT_bit_offset values in older versions
1975 // of clang, so we have to be careful and only insert unnammed bitfields
Greg Clayton37c36e42012-11-27 00:59:26 +00001976 // if we have a new enough clang.
1977 bool detect_unnamed_bitfields = true;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001978
Greg Clayton37c36e42012-11-27 00:59:26 +00001979 if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus)
1980 detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields ();
1981
1982 if (detect_unnamed_bitfields)
Greg Clayton88bc7f32012-11-06 00:20:41 +00001983 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001984 BitfieldInfo anon_field_info;
1985
1986 if ((this_field_info.bit_offset % character_width) != 0) // not char aligned
Greg Clayton88bc7f32012-11-06 00:20:41 +00001987 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001988 uint64_t last_field_end = 0;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001989
Sean Callananfaa0bb32012-12-05 23:37:14 +00001990 if (last_field_info.IsValid())
1991 last_field_end = last_field_info.bit_offset + last_field_info.bit_size;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001992
Sean Callananfaa0bb32012-12-05 23:37:14 +00001993 if (this_field_info.bit_offset != last_field_end)
1994 {
1995 if (((last_field_end % character_width) == 0) || // case 1
1996 (this_field_info.bit_offset - last_field_end >= word_width)) // case 3
1997 {
1998 anon_field_info.bit_size = this_field_info.bit_offset % character_width;
1999 anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size;
2000 }
2001 else // case 2
2002 {
2003 anon_field_info.bit_size = this_field_info.bit_offset - last_field_end;
2004 anon_field_info.bit_offset = last_field_end;
2005 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00002006 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00002007 }
2008
Sean Callananfaa0bb32012-12-05 23:37:14 +00002009 if (anon_field_info.IsValid())
Greg Clayton88bc7f32012-11-06 00:20:41 +00002010 {
Greg Clayton88bc7f32012-11-06 00:20:41 +00002011 clang::FieldDecl *unnamed_bitfield_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
2012 NULL,
Sean Callananfaa0bb32012-12-05 23:37:14 +00002013 GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width),
Greg Clayton88bc7f32012-11-06 00:20:41 +00002014 accessibility,
Sean Callananfaa0bb32012-12-05 23:37:14 +00002015 anon_field_info.bit_size);
Greg Clayton88bc7f32012-11-06 00:20:41 +00002016
Sean Callananfaa0bb32012-12-05 23:37:14 +00002017 layout_info.field_offsets.insert(std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset));
Greg Clayton88bc7f32012-11-06 00:20:41 +00002018 }
2019 }
2020 }
Sean Callananfaa0bb32012-12-05 23:37:14 +00002021
Sean Callananfa3ab452012-12-14 00:54:13 +00002022 clang_type_t member_clang_type = member_type->GetClangLayoutType();
2023
2024 {
2025 // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>).
2026 // If the current field is at the end of the structure, then there is definitely no room for extra
2027 // elements and we override the type to array[0].
2028
2029 clang_type_t member_array_element_type;
2030 uint64_t member_array_size;
2031 bool member_array_is_incomplete;
2032
2033 if (GetClangASTContext().IsArrayType(member_clang_type,
2034 &member_array_element_type,
2035 &member_array_size,
2036 &member_array_is_incomplete) &&
2037 !member_array_is_incomplete)
2038 {
2039 uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX);
2040
2041 if (member_byte_offset >= parent_byte_size)
2042 {
2043 if (member_array_size != 1)
2044 {
2045 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,
2046 MakeUserID(die->GetOffset()),
2047 name,
2048 encoding_uid,
2049 MakeUserID(parent_die->GetOffset()));
2050 }
2051
Greg Clayton1c8ef472013-04-05 23:27:21 +00002052 member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0, false);
Sean Callananfa3ab452012-12-14 00:54:13 +00002053 }
2054 }
2055 }
2056
Greg Clayton88bc7f32012-11-06 00:20:41 +00002057 field_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
Sean Callanan751aac62012-03-29 19:07:06 +00002058 name,
Sean Callananfa3ab452012-12-14 00:54:13 +00002059 member_clang_type,
Sean Callanan751aac62012-03-29 19:07:06 +00002060 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()));
Sean Callanana0b80ab2012-06-04 22:28:05 +00002097 delayed_properties.push_back(DelayedAddObjCClassProperty(GetClangASTContext().getASTContext(),
2098 class_clang_type,
2099 prop_name,
2100 member_type->GetClangLayoutType(),
2101 ivar_decl,
2102 prop_setter_name,
2103 prop_getter_name,
2104 prop_attributes,
Jim Ingham379397632012-10-27 02:54:13 +00002105 &metadata));
Sean Callanan60217122012-04-13 00:10:03 +00002106
Sean Callananad880762012-04-18 01:06:17 +00002107 if (ivar_decl)
Greg Claytond0029442013-03-27 01:48:02 +00002108 GetClangASTContext().SetMetadataAsUserID (ivar_decl, MakeUserID(die->GetOffset()));
Jim Inghame3ae82a2011-11-12 01:36:43 +00002109 }
Greg Clayton24739922010-10-13 03:15:28 +00002110 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002111 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00002112 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002113 }
2114 break;
2115
2116 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00002117 // Let the type parsing code handle this one for us.
2118 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002119 break;
2120
2121 case DW_TAG_inheritance:
2122 {
2123 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00002124 if (default_accessibility == eAccessNone)
2125 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002126 // TODO: implement DW_TAG_inheritance type parsing
2127 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00002128 const size_t num_attributes = die->GetAttributes (this,
2129 dwarf_cu,
2130 fixed_form_sizes,
2131 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002132 if (num_attributes > 0)
2133 {
2134 Declaration decl;
2135 DWARFExpression location;
2136 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00002137 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002138 bool is_virtual = false;
2139 bool is_base_of_class = true;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002140 off_t member_byte_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002141 uint32_t i;
2142 for (i=0; i<num_attributes; ++i)
2143 {
2144 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2145 DWARFFormValue form_value;
2146 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2147 {
2148 switch (attr)
2149 {
2150 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2151 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2152 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2153 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002154 case DW_AT_data_member_location:
2155 if (form_value.BlockData())
2156 {
2157 Value initialValue(0);
2158 Value memberOffset(0);
2159 const DataExtractor& debug_info_data = get_debug_info_data();
2160 uint32_t block_length = form_value.Unsigned();
2161 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
2162 if (DWARFExpression::Evaluate (NULL,
2163 NULL,
2164 NULL,
2165 NULL,
2166 NULL,
2167 debug_info_data,
2168 block_offset,
2169 block_length,
2170 eRegisterKindDWARF,
2171 &initialValue,
2172 memberOffset,
2173 NULL))
2174 {
2175 member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
2176 }
2177 }
2178 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002179
2180 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00002181 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002182 break;
2183
Greg Clayton1c8ef472013-04-05 23:27:21 +00002184 case DW_AT_virtuality: is_virtual = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002185 default:
2186 case DW_AT_sibling:
2187 break;
2188 }
2189 }
2190 }
2191
Greg Clayton526e5af2010-11-13 03:52:47 +00002192 Type *base_class_type = ResolveTypeUID(encoding_uid);
2193 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002194
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002195 clang_type_t base_class_clang_type = base_class_type->GetClangFullType();
2196 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002197 if (class_language == eLanguageTypeObjC)
2198 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002199 GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002200 }
2201 else
2202 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002203 base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type,
Greg Claytonba2d22d2010-11-13 22:57:37 +00002204 accessibility,
2205 is_virtual,
2206 is_base_of_class));
Greg Clayton2508b9b2012-11-01 23:20:02 +00002207
2208 if (is_virtual)
2209 {
2210 layout_info.vbase_offsets.insert(std::make_pair(ClangASTType::GetAsCXXRecordDecl(class_clang_type),
2211 clang::CharUnits::fromQuantity(member_byte_offset)));
2212 }
2213 else
2214 {
2215 layout_info.base_offsets.insert(std::make_pair(ClangASTType::GetAsCXXRecordDecl(class_clang_type),
2216 clang::CharUnits::fromQuantity(member_byte_offset)));
2217 }
Greg Clayton9e409562010-07-28 02:04:09 +00002218 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002219 }
2220 }
2221 break;
2222
2223 default:
2224 break;
2225 }
2226 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002227
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002228 return count;
2229}
2230
2231
2232clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00002233SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002234{
2235 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00002236 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002237 {
2238 DWARFCompileUnitSP cu_sp;
2239 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
2240 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00002241 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00002242 }
2243 return NULL;
2244}
2245
2246clang::DeclContext*
2247SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
2248{
Greg Clayton81c22f62011-10-19 18:09:39 +00002249 if (UserIDMatches(type_uid))
2250 return GetClangDeclContextForDIEOffset (sc, type_uid);
2251 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002252}
2253
2254Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00002255SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002256{
Greg Clayton81c22f62011-10-19 18:09:39 +00002257 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002258 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002259 DWARFDebugInfo* debug_info = DebugInfo();
2260 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00002261 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002262 DWARFCompileUnitSP cu_sp;
2263 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00002264 const bool assert_not_being_parsed = true;
2265 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00002266 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002267 }
2268 return NULL;
2269}
2270
Greg Claytoncab36a32011-12-08 05:16:30 +00002271Type*
2272SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00002273{
Greg Claytoncab36a32011-12-08 05:16:30 +00002274 if (die != NULL)
2275 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002276 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00002277 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002278 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002279 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
2280 die->GetOffset(),
2281 DW_TAG_value_to_name(die->Tag()),
2282 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00002283
Greg Claytoncab36a32011-12-08 05:16:30 +00002284 // We might be coming in in the middle of a type tree (a class
2285 // withing a class, an enum within a class), so parse any needed
2286 // parent DIEs before we get to this one...
2287 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2288 switch (decl_ctx_die->Tag())
2289 {
2290 case DW_TAG_structure_type:
2291 case DW_TAG_union_type:
2292 case DW_TAG_class_type:
2293 {
2294 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00002295 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002296 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002297 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
2298 die->GetOffset(),
2299 DW_TAG_value_to_name(die->Tag()),
2300 die->GetName(this, cu),
2301 decl_ctx_die->GetOffset());
Greg Clayton219cf312012-03-30 00:51:13 +00002302//
2303// Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
2304// if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
2305// {
2306// if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002307// GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton219cf312012-03-30 00:51:13 +00002308// "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
2309// die->GetOffset(),
2310// DW_TAG_value_to_name(die->Tag()),
2311// die->GetName(this, cu),
2312// decl_ctx_die->GetOffset());
2313// // Ask the type to complete itself if it already hasn't since if we
2314// // want a function (method or static) from a class, the class must
2315// // create itself and add it's own methods and class functions.
2316// if (parent_type)
2317// parent_type->GetClangFullType();
2318// }
Greg Claytoncab36a32011-12-08 05:16:30 +00002319 }
2320 break;
2321
2322 default:
2323 break;
2324 }
2325 return ResolveType (cu, die);
2326 }
2327 return NULL;
2328}
2329
Greg Clayton6beaaa62011-01-17 03:46:26 +00002330// This function is used when SymbolFileDWARFDebugMap owns a bunch of
2331// SymbolFileDWARF objects to detect if this DWARF file is the one that
2332// can resolve a clang_type.
2333bool
2334SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type)
2335{
2336 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
2337 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
2338 return die != NULL;
2339}
2340
2341
Greg Clayton1be10fc2010-09-29 01:12:09 +00002342lldb::clang_type_t
2343SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
2344{
2345 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton6beaaa62011-01-17 03:46:26 +00002346 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
2347 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002348 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00002349 {
2350 // We have already resolved this type...
2351 return clang_type;
2352 }
2353 // Once we start resolving this type, remove it from the forward declaration
2354 // map in case anyone child members or other types require this type to get resolved.
2355 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
2356 // are done.
Greg Clayton6beaaa62011-01-17 03:46:26 +00002357 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers);
Greg Clayton73b472d2010-10-27 03:32:59 +00002358
Greg Clayton1be10fc2010-09-29 01:12:09 +00002359
Greg Clayton85ae2e12011-10-18 23:36:41 +00002360 // Disable external storage for this type so we don't get anymore
2361 // clang::ExternalASTSource queries for this type.
2362 ClangASTContext::SetHasExternalStorage (clang_type, false);
2363
Greg Clayton450e3f32010-10-12 02:24:53 +00002364 DWARFDebugInfo* debug_info = DebugInfo();
2365
Greg Clayton53eb1c22012-04-02 22:59:12 +00002366 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002367 Type *type = m_die_to_type.lookup (die);
2368
2369 const dw_tag_t tag = die->Tag();
2370
Greg Clayton5160ce52013-03-27 23:08:40 +00002371 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
Greg Clayton3bffb082011-12-10 02:15:28 +00002372 if (log)
Greg Claytonbaf95da2012-03-30 23:50:54 +00002373 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002374 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002375 "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...",
Greg Claytond61c0fc2012-04-23 22:55:20 +00002376 MakeUserID(die->GetOffset()),
2377 DW_TAG_value_to_name(tag),
2378 type->GetName().AsCString());
Greg Claytonbaf95da2012-03-30 23:50:54 +00002379
Greg Claytonbaf95da2012-03-30 23:50:54 +00002380 }
Greg Clayton1be10fc2010-09-29 01:12:09 +00002381 assert (clang_type);
2382 DWARFDebugInfoEntry::Attributes attributes;
2383
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002384 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002385
2386 switch (tag)
2387 {
2388 case DW_TAG_structure_type:
2389 case DW_TAG_union_type:
2390 case DW_TAG_class_type:
Greg Claytonc93237c2010-10-01 20:48:32 +00002391 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002392 LayoutInfo layout_info;
Sean Callanan77a1fd32012-02-27 20:07:01 +00002393
Greg Clayton1be10fc2010-09-29 01:12:09 +00002394 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002395 if (die->HasChildren())
Greg Claytonc93237c2010-10-01 20:48:32 +00002396 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002397
Sean Callanan77a1fd32012-02-27 20:07:01 +00002398 LanguageType class_language = eLanguageTypeUnknown;
2399 bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
2400 if (is_objc_class)
Greg Clayton219cf312012-03-30 00:51:13 +00002401 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002402 class_language = eLanguageTypeObjC;
Greg Clayton219cf312012-03-30 00:51:13 +00002403 // For objective C we don't start the definition when
2404 // the class is created.
2405 ast.StartTagDeclarationDefinition (clang_type);
2406 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002407
2408 int tag_decl_kind = -1;
2409 AccessType default_accessibility = eAccessNone;
2410 if (tag == DW_TAG_structure_type)
2411 {
2412 tag_decl_kind = clang::TTK_Struct;
2413 default_accessibility = eAccessPublic;
2414 }
2415 else if (tag == DW_TAG_union_type)
2416 {
2417 tag_decl_kind = clang::TTK_Union;
2418 default_accessibility = eAccessPublic;
2419 }
2420 else if (tag == DW_TAG_class_type)
2421 {
2422 tag_decl_kind = clang::TTK_Class;
2423 default_accessibility = eAccessPrivate;
2424 }
2425
Greg Clayton53eb1c22012-04-02 22:59:12 +00002426 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002427 std::vector<clang::CXXBaseSpecifier *> base_classes;
2428 std::vector<int> member_accessibilities;
2429 bool is_a_class = false;
2430 // Parse members and base classes first
2431 DWARFDIECollection member_function_dies;
Sean Callanana0b80ab2012-06-04 22:28:05 +00002432
2433 DelayedPropertyList delayed_properties;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002434 ParseChildMembers (sc,
Greg Clayton53eb1c22012-04-02 22:59:12 +00002435 dwarf_cu,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002436 die,
2437 clang_type,
2438 class_language,
2439 base_classes,
2440 member_accessibilities,
2441 member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002442 delayed_properties,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002443 default_accessibility,
2444 is_a_class,
2445 layout_info);
2446
2447 // Now parse any methods if there were any...
2448 size_t num_functions = member_function_dies.Size();
2449 if (num_functions > 0)
2450 {
2451 for (size_t i=0; i<num_functions; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002452 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002453 ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytoncaab74e2012-01-28 00:48:57 +00002454 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002455 }
2456
2457 if (class_language == eLanguageTypeObjC)
2458 {
Greg Clayton84db9102012-03-26 23:03:23 +00002459 std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(ast.getASTContext(), clang_type));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002460 if (!class_str.empty())
Greg Claytoncaab74e2012-01-28 00:48:57 +00002461 {
Greg Clayton450e3f32010-10-12 02:24:53 +00002462
Sean Callanan77a1fd32012-02-27 20:07:01 +00002463 DIEArray method_die_offsets;
2464 if (m_using_apple_tables)
Greg Clayton95d87902011-11-11 03:16:25 +00002465 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002466 if (m_apple_objc_ap.get())
2467 m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets);
2468 }
2469 else
2470 {
2471 if (!m_indexed)
2472 Index ();
Greg Claytoncaab74e2012-01-28 00:48:57 +00002473
Sean Callanan77a1fd32012-02-27 20:07:01 +00002474 ConstString class_name (class_str.c_str());
2475 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
2476 }
2477
2478 if (!method_die_offsets.empty())
2479 {
2480 DWARFDebugInfo* debug_info = DebugInfo();
2481
2482 DWARFCompileUnit* method_cu = NULL;
2483 const size_t num_matches = method_die_offsets.size();
2484 for (size_t i=0; i<num_matches; ++i)
Greg Clayton95d87902011-11-11 03:16:25 +00002485 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002486 const dw_offset_t die_offset = method_die_offsets[i];
2487 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
2488
2489 if (method_die)
2490 ResolveType (method_cu, method_die);
2491 else
Greg Claytoncaab74e2012-01-28 00:48:57 +00002492 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002493 if (m_using_apple_tables)
2494 {
2495 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n",
2496 die_offset, class_str.c_str());
2497 }
2498 }
2499 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002500 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002501
2502 for (DelayedPropertyList::const_iterator pi = delayed_properties.begin(), pe = delayed_properties.end();
2503 pi != pe;
2504 ++pi)
2505 pi->Finalize();
Greg Clayton450e3f32010-10-12 02:24:53 +00002506 }
2507 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002508
2509 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2510 // need to tell the clang type it is actually a class.
2511 if (class_language != eLanguageTypeObjC)
2512 {
2513 if (is_a_class && tag_decl_kind != clang::TTK_Class)
2514 ast.SetTagTypeKind (clang_type, clang::TTK_Class);
2515 }
2516
2517 // Since DW_TAG_structure_type gets used for both classes
2518 // and structures, we may need to set any DW_TAG_member
2519 // fields to have a "private" access if none was specified.
2520 // When we parsed the child members we tracked that actual
2521 // accessibility value for each DW_TAG_member in the
2522 // "member_accessibilities" array. If the value for the
2523 // member is zero, then it was set to the "default_accessibility"
2524 // which for structs was "public". Below we correct this
2525 // by setting any fields to "private" that weren't correctly
2526 // set.
2527 if (is_a_class && !member_accessibilities.empty())
2528 {
2529 // This is a class and all members that didn't have
2530 // their access specified are private.
2531 ast.SetDefaultAccessForRecordFields (clang_type,
2532 eAccessPrivate,
2533 &member_accessibilities.front(),
2534 member_accessibilities.size());
2535 }
2536
2537 if (!base_classes.empty())
2538 {
2539 ast.SetBaseClassesForClassType (clang_type,
2540 &base_classes.front(),
2541 base_classes.size());
2542
2543 // Clang will copy each CXXBaseSpecifier in "base_classes"
2544 // so we have to free them all.
2545 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
2546 base_classes.size());
2547 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002548 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002549 }
Sean Callanane8c0cfb2012-03-02 01:03:45 +00002550
2551 ast.BuildIndirectFields (clang_type);
2552
Sean Callanan77a1fd32012-02-27 20:07:01 +00002553 ast.CompleteTagDeclarationDefinition (clang_type);
Sean Callanan5b26f272012-02-04 08:49:35 +00002554
Greg Clayton2508b9b2012-11-01 23:20:02 +00002555 if (!layout_info.field_offsets.empty() ||
2556 !layout_info.base_offsets.empty() ||
2557 !layout_info.vbase_offsets.empty() )
Greg Claytoncaab74e2012-01-28 00:48:57 +00002558 {
2559 if (type)
2560 layout_info.bit_size = type->GetByteSize() * 8;
2561 if (layout_info.bit_size == 0)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002562 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002563
2564 clang::CXXRecordDecl *record_decl = ClangASTType::GetAsCXXRecordDecl(clang_type);
2565 if (record_decl)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002566 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002567 if (log)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002568 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002569 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002570 "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 Claytoncaab74e2012-01-28 00:48:57 +00002571 clang_type,
2572 record_decl,
2573 layout_info.bit_size,
2574 layout_info.alignment,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002575 (uint32_t)layout_info.field_offsets.size(),
2576 (uint32_t)layout_info.base_offsets.size(),
2577 (uint32_t)layout_info.vbase_offsets.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002578
Greg Clayton2508b9b2012-11-01 23:20:02 +00002579 uint32_t idx;
2580 {
Greg Clayton821ac6d2012-01-28 02:22:27 +00002581 llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002582 for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002583 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002584 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002585 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = { bit_offset=%u, name='%s' }",
Greg Clayton821ac6d2012-01-28 02:22:27 +00002586 clang_type,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002587 idx,
Greg Clayton821ac6d2012-01-28 02:22:27 +00002588 (uint32_t)pos->second,
2589 pos->first->getNameAsString().c_str());
2590 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002591 }
2592
2593 {
2594 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos, base_end = layout_info.base_offsets.end();
2595 for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; ++base_pos, ++idx)
2596 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002597 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002598 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] = { byte_offset=%u, name='%s' }",
2599 clang_type,
2600 idx,
2601 (uint32_t)base_pos->second.getQuantity(),
2602 base_pos->first->getNameAsString().c_str());
2603 }
2604 }
2605 {
2606 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos, vbase_end = layout_info.vbase_offsets.end();
2607 for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; ++vbase_pos, ++idx)
2608 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002609 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002610 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) vbase[%u] = { byte_offset=%u, name='%s' }",
2611 clang_type,
2612 idx,
2613 (uint32_t)vbase_pos->second.getQuantity(),
2614 vbase_pos->first->getNameAsString().c_str());
2615 }
2616 }
Greg Clayton821ac6d2012-01-28 02:22:27 +00002617 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002618 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2619 }
2620 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002621 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002622
Greg Claytonc93237c2010-10-01 20:48:32 +00002623 return clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002624
2625 case DW_TAG_enumeration_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002626 ast.StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002627 if (die->HasChildren())
2628 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002629 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00002630 bool is_signed = false;
2631 ast.IsIntegerType(clang_type, is_signed);
2632 ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002633 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002634 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002635 return clang_type;
2636
2637 default:
2638 assert(false && "not a forward clang type decl!");
2639 break;
2640 }
2641 return NULL;
2642}
2643
Greg Claytonc685f8e2010-09-15 04:15:46 +00002644Type*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002645SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002646{
2647 if (type_die != NULL)
2648 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002649 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00002650
Greg Claytonc685f8e2010-09-15 04:15:46 +00002651 if (type == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002652 type = GetTypeForDIE (dwarf_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00002653
Greg Clayton24739922010-10-13 03:15:28 +00002654 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00002655 {
2656 if (type != DIE_IS_BEING_PARSED)
2657 return type;
2658
2659 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
Greg Clayton53eb1c22012-04-02 22:59:12 +00002660 type_die->GetOffset(),
2661 DW_TAG_value_to_name(type_die->Tag()),
2662 type_die->GetName(this, dwarf_cu));
Jim Inghamc3549282012-01-11 02:21:12 +00002663
2664 }
2665 else
2666 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002667 }
2668 return NULL;
2669}
2670
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002671CompileUnit*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002672SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002673{
2674 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002675 if (dwarf_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002676 {
2677 // The symbol vendor doesn't know about this compile unit, we
2678 // need to parse and add it to the symbol vendor object.
Greg Clayton53eb1c22012-04-02 22:59:12 +00002679 return ParseCompileUnit(dwarf_cu, cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002680 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00002681 return (CompileUnit*)dwarf_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002682}
2683
2684bool
Greg Clayton53eb1c22012-04-02 22:59:12 +00002685SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002686{
Greg Clayton72310352013-02-23 04:12:47 +00002687 sc.Clear(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002688 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002689 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002690
Greg Clayton81c22f62011-10-19 18:09:39 +00002691 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002692 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002693 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002694
2695 if (sc.function)
2696 {
Greg Claytone72dfb32012-02-24 01:59:29 +00002697 sc.module_sp = sc.function->CalculateSymbolContextModule();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002698 return true;
2699 }
2700
2701 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002702}
2703
2704uint32_t
2705SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2706{
2707 Timer scoped_timer(__PRETTY_FUNCTION__,
Daniel Malead01b2952012-11-29 21:49:15 +00002708 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)",
Greg Claytone72dfb32012-02-24 01:59:29 +00002709 so_addr.GetSection().get(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002710 so_addr.GetOffset(),
2711 resolve_scope);
2712 uint32_t resolved = 0;
2713 if (resolve_scope & ( eSymbolContextCompUnit |
2714 eSymbolContextFunction |
2715 eSymbolContextBlock |
2716 eSymbolContextLineEntry))
2717 {
2718 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2719
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002720 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00002721 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002722 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002723 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002724 if (cu_offset != DW_INVALID_OFFSET)
2725 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002726 uint32_t cu_idx = DW_INVALID_INDEX;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002727 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
2728 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002729 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002730 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002731 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002732 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002733 resolved |= eSymbolContextCompUnit;
2734
Greg Clayton6ab80132012-12-12 17:30:52 +00002735 bool force_check_line_table = false;
Greg Clayton526a4ae2012-05-16 22:09:01 +00002736 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2737 {
2738 DWARFDebugInfoEntry *function_die = NULL;
2739 DWARFDebugInfoEntry *block_die = NULL;
2740 if (resolve_scope & eSymbolContextBlock)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002741 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002742 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
2743 }
2744 else
2745 {
2746 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL);
2747 }
2748
2749 if (function_die != NULL)
2750 {
2751 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2752 if (sc.function == NULL)
2753 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2754 }
2755 else
2756 {
2757 // We might have had a compile unit that had discontiguous
2758 // address ranges where the gaps are symbols that don't have
2759 // any debug info. Discontiguous compile unit address ranges
2760 // should only happen when there aren't other functions from
2761 // other compile units in these gaps. This helps keep the size
2762 // of the aranges down.
Greg Clayton6ab80132012-12-12 17:30:52 +00002763 force_check_line_table = true;
Greg Clayton526a4ae2012-05-16 22:09:01 +00002764 }
2765
2766 if (sc.function != NULL)
2767 {
2768 resolved |= eSymbolContextFunction;
2769
2770 if (resolve_scope & eSymbolContextBlock)
2771 {
2772 Block& block = sc.function->GetBlock (true);
2773
2774 if (block_die != NULL)
2775 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2776 else
2777 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2778 if (sc.block)
2779 resolved |= eSymbolContextBlock;
2780 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002781 }
2782 }
Greg Clayton6ab80132012-12-12 17:30:52 +00002783
2784 if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table)
2785 {
2786 LineTable *line_table = sc.comp_unit->GetLineTable();
2787 if (line_table != NULL)
2788 {
Greg Clayton9422dd62013-03-04 21:46:16 +00002789 // And address that makes it into this function should be in terms
2790 // of this debug file if there is no debug map, or it will be an
2791 // address in the .o file which needs to be fixed up to be in terms
2792 // of the debug map executable. Either way, calling FixupAddress()
2793 // will work for us.
2794 Address exe_so_addr (so_addr);
2795 if (FixupAddress(exe_so_addr))
Greg Clayton6ab80132012-12-12 17:30:52 +00002796 {
Greg Clayton9422dd62013-03-04 21:46:16 +00002797 if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry))
Greg Clayton6ab80132012-12-12 17:30:52 +00002798 {
2799 resolved |= eSymbolContextLineEntry;
2800 }
2801 }
Greg Clayton6ab80132012-12-12 17:30:52 +00002802 }
2803 }
2804
2805 if (force_check_line_table && !(resolved & eSymbolContextLineEntry))
2806 {
2807 // We might have had a compile unit that had discontiguous
2808 // address ranges where the gaps are symbols that don't have
2809 // any debug info. Discontiguous compile unit address ranges
2810 // should only happen when there aren't other functions from
2811 // other compile units in these gaps. This helps keep the size
2812 // of the aranges down.
2813 sc.comp_unit = NULL;
2814 resolved &= ~eSymbolContextCompUnit;
2815 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002816 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002817 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002818 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002819 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.",
2820 cu_offset,
2821 cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002822 }
2823 }
2824 }
2825 }
2826 }
2827 return resolved;
2828}
2829
2830
2831
2832uint32_t
2833SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
2834{
2835 const uint32_t prev_size = sc_list.GetSize();
2836 if (resolve_scope & eSymbolContextCompUnit)
2837 {
2838 DWARFDebugInfo* debug_info = DebugInfo();
2839 if (debug_info)
2840 {
2841 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002842 DWARFCompileUnit* dwarf_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002843
Greg Clayton53eb1c22012-04-02 22:59:12 +00002844 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002845 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002846 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton1f746072012-08-29 21:13:06 +00002847 const bool full_match = file_spec.GetDirectory();
2848 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 +00002849 if (check_inlines || file_spec_matches_cu_file_spec)
2850 {
2851 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton53eb1c22012-04-02 22:59:12 +00002852 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002853 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002854 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002855 uint32_t file_idx = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002856
Greg Clayton526a4ae2012-05-16 22:09:01 +00002857 // If we are looking for inline functions only and we don't
2858 // find it in the support files, we are done.
2859 if (check_inlines)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002860 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002861 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
2862 if (file_idx == UINT32_MAX)
2863 continue;
2864 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002865
Greg Clayton526a4ae2012-05-16 22:09:01 +00002866 if (line != 0)
2867 {
2868 LineTable *line_table = sc.comp_unit->GetLineTable();
2869
2870 if (line_table != NULL && line != 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002871 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002872 // We will have already looked up the file index if
2873 // we are searching for inline entries.
2874 if (!check_inlines)
2875 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002876
Greg Clayton526a4ae2012-05-16 22:09:01 +00002877 if (file_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002878 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002879 uint32_t found_line;
2880 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
2881 found_line = sc.line_entry.line;
2882
2883 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002884 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002885 sc.function = NULL;
2886 sc.block = NULL;
2887 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002888 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002889 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
2890 if (file_vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002891 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002892 DWARFDebugInfoEntry *function_die = NULL;
2893 DWARFDebugInfoEntry *block_die = NULL;
2894 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002895
Greg Clayton526a4ae2012-05-16 22:09:01 +00002896 if (function_die != NULL)
2897 {
2898 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2899 if (sc.function == NULL)
2900 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2901 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002902
Greg Clayton526a4ae2012-05-16 22:09:01 +00002903 if (sc.function != NULL)
2904 {
2905 Block& block = sc.function->GetBlock (true);
2906
2907 if (block_die != NULL)
2908 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2909 else
2910 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2911 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002912 }
2913 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002914
Greg Clayton526a4ae2012-05-16 22:09:01 +00002915 sc_list.Append(sc);
2916 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2917 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002918 }
2919 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002920 else if (file_spec_matches_cu_file_spec && !check_inlines)
2921 {
2922 // only append the context if we aren't looking for inline call sites
2923 // by file and line and if the file spec matches that of the compile unit
2924 sc_list.Append(sc);
2925 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002926 }
2927 else if (file_spec_matches_cu_file_spec && !check_inlines)
2928 {
2929 // only append the context if we aren't looking for inline call sites
2930 // by file and line and if the file spec matches that of the compile unit
2931 sc_list.Append(sc);
2932 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002933
Greg Clayton526a4ae2012-05-16 22:09:01 +00002934 if (!check_inlines)
2935 break;
2936 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002937 }
2938 }
2939 }
2940 }
2941 return sc_list.GetSize() - prev_size;
2942}
2943
2944void
2945SymbolFileDWARF::Index ()
2946{
2947 if (m_indexed)
2948 return;
2949 m_indexed = true;
2950 Timer scoped_timer (__PRETTY_FUNCTION__,
2951 "SymbolFileDWARF::Index (%s)",
2952 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
2953
2954 DWARFDebugInfo* debug_info = DebugInfo();
2955 if (debug_info)
2956 {
2957 uint32_t cu_idx = 0;
2958 const uint32_t num_compile_units = GetNumCompileUnits();
2959 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2960 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002961 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002962
Greg Clayton53eb1c22012-04-02 22:59:12 +00002963 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002964
Greg Clayton53eb1c22012-04-02 22:59:12 +00002965 dwarf_cu->Index (cu_idx,
2966 m_function_basename_index,
2967 m_function_fullname_index,
2968 m_function_method_index,
2969 m_function_selector_index,
2970 m_objc_class_selectors_index,
2971 m_global_index,
2972 m_type_index,
2973 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002974
2975 // Keep memory down by clearing DIEs if this generate function
2976 // caused them to be parsed
2977 if (clear_dies)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002978 dwarf_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002979 }
2980
Greg Claytond4a2b372011-09-12 23:21:58 +00002981 m_function_basename_index.Finalize();
2982 m_function_fullname_index.Finalize();
2983 m_function_method_index.Finalize();
2984 m_function_selector_index.Finalize();
2985 m_objc_class_selectors_index.Finalize();
2986 m_global_index.Finalize();
2987 m_type_index.Finalize();
2988 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002989
Greg Clayton24739922010-10-13 03:15:28 +00002990#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00002991 StreamFile s(stdout, false);
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00002992 s.Printf ("DWARF index for '%s':",
2993 GetObjectFile()->GetFileSpec().GetPath().c_str());
Greg Claytonba2d22d2010-11-13 22:57:37 +00002994 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
2995 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
2996 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
2997 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
2998 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
2999 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00003000 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00003001 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00003002#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003003 }
3004}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003005
3006bool
3007SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
3008{
3009 if (namespace_decl == NULL)
3010 {
3011 // Invalid namespace decl which means we aren't matching only things
3012 // in this symbol file, so return true to indicate it matches this
3013 // symbol file.
3014 return true;
3015 }
3016
3017 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
3018
3019 if (namespace_ast == NULL)
3020 return true; // No AST in the "namespace_decl", return true since it
3021 // could then match any symbol file, including this one
3022
3023 if (namespace_ast == GetClangASTContext().getASTContext())
3024 return true; // The ASTs match, return true
3025
3026 // The namespace AST was valid, and it does not match...
Greg Clayton5160ce52013-03-27 23:08:40 +00003027 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Sean Callananc41e68b2011-10-13 21:08:11 +00003028
3029 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003030 GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00003031
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003032 return false;
3033}
3034
Greg Clayton2506a7a2011-10-12 23:34:26 +00003035bool
3036SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
3037 DWARFCompileUnit* cu,
3038 const DWARFDebugInfoEntry* die)
3039{
3040 // No namespace specified, so the answesr i
3041 if (namespace_decl == NULL)
3042 return true;
Sean Callananebe60672011-10-13 21:50:33 +00003043
Greg Clayton5160ce52013-03-27 23:08:40 +00003044 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003045
Greg Clayton437a1352012-04-09 22:43:43 +00003046 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
3047 clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00003048 if (decl_ctx_die)
Greg Clayton437a1352012-04-09 22:43:43 +00003049 {
Greg Clayton2506a7a2011-10-12 23:34:26 +00003050 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
Greg Clayton437a1352012-04-09 22:43:43 +00003051
Greg Clayton2506a7a2011-10-12 23:34:26 +00003052 if (clang_namespace_decl)
3053 {
3054 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00003055 {
3056 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003057 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00003058 return false;
Sean Callananebe60672011-10-13 21:50:33 +00003059 }
3060
Greg Clayton437a1352012-04-09 22:43:43 +00003061 if (clang_namespace_decl == die_clang_decl_ctx)
3062 return true;
3063 else
Greg Clayton2506a7a2011-10-12 23:34:26 +00003064 return false;
Greg Clayton2506a7a2011-10-12 23:34:26 +00003065 }
3066 else
3067 {
3068 // We have a namespace_decl that was not NULL but it contained
3069 // a NULL "clang::NamespaceDecl", so this means the global namespace
3070 // So as long the the contained decl context DIE isn't a namespace
3071 // we should be ok.
3072 if (decl_ctx_die->Tag() != DW_TAG_namespace)
3073 return true;
3074 }
3075 }
Sean Callananebe60672011-10-13 21:50:33 +00003076
3077 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003078 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00003079
Greg Clayton2506a7a2011-10-12 23:34:26 +00003080 return false;
3081}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003082uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00003083SymbolFileDWARF::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 +00003084{
Greg Clayton5160ce52013-03-27 23:08:40 +00003085 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003086
3087 if (log)
3088 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003089 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003090 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
3091 name.GetCString(),
3092 namespace_decl,
3093 append,
3094 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003095 }
Sean Callanan213fdb82011-10-13 01:49:10 +00003096
3097 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3098 return 0;
3099
Greg Claytonc685f8e2010-09-15 04:15:46 +00003100 DWARFDebugInfo* info = DebugInfo();
3101 if (info == NULL)
3102 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003103
3104 // If we aren't appending the results to this list, then clear the list
3105 if (!append)
3106 variables.Clear();
3107
3108 // Remember how many variables are in the list before we search in case
3109 // we are appending the results to a variable list.
3110 const uint32_t original_size = variables.GetSize();
3111
Greg Claytond4a2b372011-09-12 23:21:58 +00003112 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003113
Greg Clayton97fbc342011-10-20 22:30:33 +00003114 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003115 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003116 if (m_apple_names_ap.get())
3117 {
3118 const char *name_cstr = name.GetCString();
3119 const char *base_name_start;
3120 const char *base_name_end = NULL;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003121
Greg Clayton97fbc342011-10-20 22:30:33 +00003122 if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end))
3123 base_name_start = name_cstr;
3124
3125 m_apple_names_ap->FindByName (base_name_start, die_offsets);
3126 }
Greg Clayton7f995132011-10-04 22:41:51 +00003127 }
3128 else
3129 {
3130 // Index the DWARF if we haven't already
3131 if (!m_indexed)
3132 Index ();
3133
3134 m_global_index.Find (name, die_offsets);
3135 }
3136
Greg Clayton437a1352012-04-09 22:43:43 +00003137 const size_t num_die_matches = die_offsets.size();
3138 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003139 {
Greg Clayton7f995132011-10-04 22:41:51 +00003140 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003141 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00003142 assert (sc.module_sp);
3143
Greg Claytond4a2b372011-09-12 23:21:58 +00003144 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00003145 DWARFCompileUnit* dwarf_cu = NULL;
3146 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton437a1352012-04-09 22:43:43 +00003147 bool done = false;
3148 for (size_t i=0; i<num_die_matches && !done; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00003149 {
3150 const dw_offset_t die_offset = die_offsets[i];
3151 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003152
Greg Clayton95d87902011-11-11 03:16:25 +00003153 if (die)
3154 {
Greg Clayton437a1352012-04-09 22:43:43 +00003155 switch (die->Tag())
3156 {
3157 default:
3158 case DW_TAG_subprogram:
3159 case DW_TAG_inlined_subroutine:
3160 case DW_TAG_try_block:
3161 case DW_TAG_catch_block:
3162 break;
3163
3164 case DW_TAG_variable:
3165 {
3166 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Greg Clayton437a1352012-04-09 22:43:43 +00003167
3168 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3169 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003170
Greg Clayton437a1352012-04-09 22:43:43 +00003171 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003172
Greg Clayton437a1352012-04-09 22:43:43 +00003173 if (variables.GetSize() - original_size >= max_matches)
3174 done = true;
3175 }
3176 break;
3177 }
Greg Clayton95d87902011-11-11 03:16:25 +00003178 }
3179 else
3180 {
3181 if (m_using_apple_tables)
3182 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003183 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
3184 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003185 }
3186 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003187 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003188 }
3189
3190 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003191 const uint32_t num_matches = variables.GetSize() - original_size;
3192 if (log && num_matches > 0)
3193 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003194 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003195 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u",
3196 name.GetCString(),
3197 namespace_decl,
3198 append,
3199 max_matches,
3200 num_matches);
3201 }
3202 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003203}
3204
3205uint32_t
3206SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
3207{
Greg Clayton5160ce52013-03-27 23:08:40 +00003208 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003209
3210 if (log)
3211 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003212 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003213 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
3214 regex.GetText(),
3215 append,
3216 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003217 }
3218
Greg Claytonc685f8e2010-09-15 04:15:46 +00003219 DWARFDebugInfo* info = DebugInfo();
3220 if (info == NULL)
3221 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003222
3223 // If we aren't appending the results to this list, then clear the list
3224 if (!append)
3225 variables.Clear();
3226
3227 // Remember how many variables are in the list before we search in case
3228 // we are appending the results to a variable list.
3229 const uint32_t original_size = variables.GetSize();
3230
Greg Clayton7f995132011-10-04 22:41:51 +00003231 DIEArray die_offsets;
3232
Greg Clayton97fbc342011-10-20 22:30:33 +00003233 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003234 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003235 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00003236 {
3237 DWARFMappedHash::DIEInfoArray hash_data_array;
3238 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
3239 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
3240 }
Greg Clayton7f995132011-10-04 22:41:51 +00003241 }
3242 else
3243 {
3244 // Index the DWARF if we haven't already
3245 if (!m_indexed)
3246 Index ();
3247
3248 m_global_index.Find (regex, die_offsets);
3249 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003250
Greg Claytonc685f8e2010-09-15 04:15:46 +00003251 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003252 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003253 assert (sc.module_sp);
3254
Greg Claytond4a2b372011-09-12 23:21:58 +00003255 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00003256 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003257 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003258 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003259 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003260 DWARFDebugInfo* debug_info = DebugInfo();
3261 for (size_t i=0; i<num_matches; ++i)
3262 {
3263 const dw_offset_t die_offset = die_offsets[i];
3264 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00003265
3266 if (die)
3267 {
3268 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003269
Greg Clayton95d87902011-11-11 03:16:25 +00003270 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003271
Greg Clayton95d87902011-11-11 03:16:25 +00003272 if (variables.GetSize() - original_size >= max_matches)
3273 break;
3274 }
3275 else
3276 {
3277 if (m_using_apple_tables)
3278 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003279 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
3280 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00003281 }
3282 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003283 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003284 }
3285
3286 // Return the number of variable that were appended to the list
3287 return variables.GetSize() - original_size;
3288}
3289
Greg Claytonaa044962011-10-13 00:59:38 +00003290
Jim Ingham4cda6e02011-10-07 22:23:45 +00003291bool
3292SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
3293 DWARFCompileUnit *&dwarf_cu,
3294 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00003295{
Greg Claytonaa044962011-10-13 00:59:38 +00003296 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3297 return ResolveFunction (dwarf_cu, die, sc_list);
3298}
3299
3300
3301bool
3302SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
3303 const DWARFDebugInfoEntry *die,
3304 SymbolContextList& sc_list)
3305{
Greg Clayton9e315582011-09-02 04:03:59 +00003306 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00003307
3308 if (die == NULL)
3309 return false;
3310
Jim Ingham4cda6e02011-10-07 22:23:45 +00003311 // If we were passed a die that is not a function, just return false...
3312 if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine)
3313 return false;
3314
3315 const DWARFDebugInfoEntry* inlined_die = NULL;
3316 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00003317 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003318 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00003319
Jim Ingham4cda6e02011-10-07 22:23:45 +00003320 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003321 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003322 if (die->Tag() == DW_TAG_subprogram)
3323 break;
Greg Clayton9e315582011-09-02 04:03:59 +00003324 }
3325 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003326 assert (die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00003327 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003328 {
3329 Address addr;
3330 // Parse all blocks if needed
3331 if (inlined_die)
3332 {
Greg Clayton81c22f62011-10-19 18:09:39 +00003333 sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset()));
Jim Ingham4cda6e02011-10-07 22:23:45 +00003334 assert (sc.block != NULL);
3335 if (sc.block->GetStartAddress (addr) == false)
3336 addr.Clear();
3337 }
3338 else
3339 {
3340 sc.block = NULL;
3341 addr = sc.function->GetAddressRange().GetBaseAddress();
3342 }
3343
3344 if (addr.IsValid())
3345 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003346 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00003347 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003348 }
3349 }
3350
Greg Claytonaa044962011-10-13 00:59:38 +00003351 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00003352}
3353
Greg Clayton7f995132011-10-04 22:41:51 +00003354void
3355SymbolFileDWARF::FindFunctions (const ConstString &name,
3356 const NameToDIE &name_to_die,
3357 SymbolContextList& sc_list)
3358{
Greg Claytond4a2b372011-09-12 23:21:58 +00003359 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003360 if (name_to_die.Find (name, die_offsets))
3361 {
3362 ParseFunctions (die_offsets, sc_list);
3363 }
3364}
3365
3366
3367void
3368SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3369 const NameToDIE &name_to_die,
3370 SymbolContextList& sc_list)
3371{
3372 DIEArray die_offsets;
3373 if (name_to_die.Find (regex, die_offsets))
3374 {
3375 ParseFunctions (die_offsets, sc_list);
3376 }
3377}
3378
3379
3380void
3381SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3382 const DWARFMappedHash::MemoryTable &memory_table,
3383 SymbolContextList& sc_list)
3384{
3385 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00003386 DWARFMappedHash::DIEInfoArray hash_data_array;
3387 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00003388 {
Greg Claytond1767f02011-12-08 02:13:16 +00003389 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Greg Clayton7f995132011-10-04 22:41:51 +00003390 ParseFunctions (die_offsets, sc_list);
3391 }
3392}
3393
3394void
3395SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
3396 SymbolContextList& sc_list)
3397{
3398 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003399 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00003400 {
Greg Clayton7f995132011-10-04 22:41:51 +00003401 SymbolContext sc;
Greg Clayton7f995132011-10-04 22:41:51 +00003402
3403 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003404 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00003405 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003406 const dw_offset_t die_offset = die_offsets[i];
Jim Ingham4cda6e02011-10-07 22:23:45 +00003407 ResolveFunction (die_offset, dwarf_cu, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003408 }
3409 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00003410}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003411
Jim Ingham4cda6e02011-10-07 22:23:45 +00003412bool
3413SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
3414 const DWARFCompileUnit *dwarf_cu,
3415 uint32_t name_type_mask,
3416 const char *partial_name,
3417 const char *base_name_start,
3418 const char *base_name_end)
3419{
Greg Claytonfbea0f62012-11-15 18:05:43 +00003420 // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes:
3421 if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003422 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003423 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
3424 if (!containing_decl_ctx)
3425 return false;
3426
3427 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
3428
Greg Claytonfbea0f62012-11-15 18:05:43 +00003429 if (name_type_mask == eFunctionNameTypeMethod)
3430 {
3431 if (is_cxx_method == false)
3432 return false;
3433 }
3434
3435 if (name_type_mask == eFunctionNameTypeBase)
3436 {
3437 if (is_cxx_method == true)
3438 return false;
3439 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003440 }
3441
3442 // Now we need to check whether the name we got back for this type matches the extra specifications
3443 // that were in the name we're looking up:
3444 if (base_name_start != partial_name || *base_name_end != '\0')
3445 {
3446 // First see if the stuff to the left matches the full name. To do that let's see if
3447 // we can pull out the mips linkage name attribute:
3448
3449 Mangled best_name;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003450 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonfbea0f62012-11-15 18:05:43 +00003451 DWARFFormValue form_value;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003452 die->GetAttributes(this, dwarf_cu, NULL, attributes);
3453 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
Greg Clayton71415542012-12-08 00:24:40 +00003454 if (idx == UINT32_MAX)
3455 idx = attributes.FindAttributeIndex(DW_AT_linkage_name);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003456 if (idx != UINT32_MAX)
3457 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003458 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
3459 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003460 const char *mangled_name = form_value.AsCString(&get_debug_str_data());
3461 if (mangled_name)
3462 best_name.SetValue (ConstString(mangled_name), true);
3463 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003464 }
Greg Claytonfbea0f62012-11-15 18:05:43 +00003465
3466 if (!best_name)
3467 {
3468 idx = attributes.FindAttributeIndex(DW_AT_name);
3469 if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value))
3470 {
3471 const char *name = form_value.AsCString(&get_debug_str_data());
3472 best_name.SetValue (ConstString(name), false);
3473 }
3474 }
3475
3476 if (best_name.GetDemangledName())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003477 {
3478 const char *demangled = best_name.GetDemangledName().GetCString();
3479 if (demangled)
3480 {
3481 std::string name_no_parens(partial_name, base_name_end - partial_name);
Jim Ingham85c13d72012-03-02 02:24:42 +00003482 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str());
3483 if (partial_in_demangled == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003484 return false;
Jim Ingham85c13d72012-03-02 02:24:42 +00003485 else
3486 {
3487 // Sort out the case where our name is something like "Process::Destroy" and the match is
3488 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on
3489 // namespace boundaries...
3490
3491 if (partial_name[0] == ':' && partial_name[1] == ':')
3492 {
3493 // The partial name was already on a namespace boundary so all matches are good.
3494 return true;
3495 }
3496 else if (partial_in_demangled == demangled)
3497 {
3498 // They both start the same, so this is an good match.
3499 return true;
3500 }
3501 else
3502 {
3503 if (partial_in_demangled - demangled == 1)
3504 {
3505 // Only one character difference, can't be a namespace boundary...
3506 return false;
3507 }
3508 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':')
3509 {
3510 // We are on a namespace boundary, so this is also good.
3511 return true;
3512 }
3513 else
3514 return false;
3515 }
3516 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003517 }
3518 }
3519 }
3520
3521 return true;
3522}
Greg Claytonc685f8e2010-09-15 04:15:46 +00003523
Greg Clayton0c5cd902010-06-28 21:30:43 +00003524uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00003525SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00003526 const lldb_private::ClangNamespaceDecl *namespace_decl,
Sean Callanan9df05fb2012-02-10 22:52:19 +00003527 uint32_t name_type_mask,
3528 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00003529 bool append,
3530 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00003531{
3532 Timer scoped_timer (__PRETTY_FUNCTION__,
3533 "SymbolFileDWARF::FindFunctions (name = '%s')",
3534 name.AsCString());
3535
Greg Clayton43fe2172013-04-03 02:00:15 +00003536 // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup()
3537 assert ((name_type_mask & eFunctionNameTypeAuto) == 0);
3538
Greg Clayton5160ce52013-03-27 23:08:40 +00003539 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003540
3541 if (log)
3542 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003543 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003544 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
3545 name.GetCString(),
3546 name_type_mask,
3547 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003548 }
3549
Greg Clayton0c5cd902010-06-28 21:30:43 +00003550 // If we aren't appending the results to this list, then clear the list
3551 if (!append)
3552 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003553
3554 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3555 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003556
3557 // If name is empty then we won't find anything.
3558 if (name.IsEmpty())
3559 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00003560
3561 // Remember how many sc_list are in the list before we search in case
3562 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00003563
Jim Ingham4cda6e02011-10-07 22:23:45 +00003564 const char *name_cstr = name.GetCString();
Greg Clayton43fe2172013-04-03 02:00:15 +00003565
3566 const uint32_t original_size = sc_list.GetSize();
3567
Jim Ingham4cda6e02011-10-07 22:23:45 +00003568 DWARFDebugInfo* info = DebugInfo();
3569 if (info == NULL)
3570 return 0;
3571
Greg Claytonaa044962011-10-13 00:59:38 +00003572 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton43fe2172013-04-03 02:00:15 +00003573 std::set<const DWARFDebugInfoEntry *> resolved_dies;
Greg Clayton97fbc342011-10-20 22:30:33 +00003574 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00003575 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003576 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003577 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003578
3579 DIEArray die_offsets;
3580
3581 uint32_t num_matches = 0;
3582
Greg Clayton43fe2172013-04-03 02:00:15 +00003583 if (name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00003584 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003585 // If they asked for the full name, match what they typed. At some point we may
3586 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
3587 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00003588 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003589 for (uint32_t i = 0; i < num_matches; i++)
3590 {
Greg Clayton95d87902011-11-11 03:16:25 +00003591 const dw_offset_t die_offset = die_offsets[i];
3592 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00003593 if (die)
3594 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003595 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3596 continue;
3597
Sean Callanan9df05fb2012-02-10 22:52:19 +00003598 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3599 continue;
3600
Greg Clayton43fe2172013-04-03 02:00:15 +00003601 if (resolved_dies.find(die) == resolved_dies.end())
3602 {
3603 if (ResolveFunction (dwarf_cu, die, sc_list))
3604 resolved_dies.insert(die);
3605 }
Greg Claytonaa044962011-10-13 00:59:38 +00003606 }
Greg Clayton95d87902011-11-11 03:16:25 +00003607 else
3608 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003609 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3610 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003611 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003612 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003613 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003614
3615 if (name_type_mask & eFunctionNameTypeSelector)
3616 {
3617 if (namespace_decl && *namespace_decl)
3618 return 0; // no selectors in namespaces
Greg Clayton97fbc342011-10-20 22:30:33 +00003619
Greg Clayton43fe2172013-04-03 02:00:15 +00003620 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3621 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
3622 // and if it is an ObjC method name, we're good.
Greg Clayton97fbc342011-10-20 22:30:33 +00003623
Greg Clayton43fe2172013-04-03 02:00:15 +00003624 for (uint32_t i = 0; i < num_matches; i++)
Greg Clayton97fbc342011-10-20 22:30:33 +00003625 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003626 const dw_offset_t die_offset = die_offsets[i];
3627 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3628 if (die)
Greg Clayton97fbc342011-10-20 22:30:33 +00003629 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003630 const char *die_name = die->GetName(this, dwarf_cu);
3631 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
Greg Clayton97fbc342011-10-20 22:30:33 +00003632 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003633 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3634 continue;
3635
Greg Clayton43fe2172013-04-03 02:00:15 +00003636 if (resolved_dies.find(die) == resolved_dies.end())
3637 {
3638 if (ResolveFunction (dwarf_cu, die, sc_list))
3639 resolved_dies.insert(die);
3640 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003641 }
3642 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003643 else
3644 {
3645 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3646 die_offset, name_cstr);
3647 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003648 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003649 die_offsets.clear();
3650 }
3651
3652 if (((name_type_mask & eFunctionNameTypeMethod) && !namespace_decl) || name_type_mask & eFunctionNameTypeBase)
3653 {
3654 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
3655 // extract the base name, look that up, and if there is any other information in the name we were
3656 // passed in we have to post-filter based on that.
3657
3658 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
3659 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3660
3661 for (uint32_t i = 0; i < num_matches; i++)
3662 {
3663 const dw_offset_t die_offset = die_offsets[i];
3664 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3665 if (die)
3666 {
3667 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3668 continue;
3669
3670 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3671 continue;
3672
3673 // If we get to here, the die is good, and we should add it:
3674 if (resolved_dies.find(die) == resolved_dies.end())
3675 if (ResolveFunction (dwarf_cu, die, sc_list))
3676 {
3677 bool keep_die = true;
3678 if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod))
3679 {
3680 // We are looking for either basenames or methods, so we need to
3681 // trim out the ones we won't want by looking at the type
3682 SymbolContext sc;
3683 if (sc_list.GetLastContext(sc))
3684 {
3685 if (sc.block)
3686 {
3687 // We have an inlined function
3688 }
3689 else if (sc.function)
3690 {
3691 Type *type = sc.function->GetType();
3692
3693 clang::DeclContext* decl_ctx = GetClangDeclContextContainingTypeUID (type->GetID());
3694 if (decl_ctx->isRecord())
3695 {
3696 if (name_type_mask & eFunctionNameTypeBase)
3697 {
3698 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3699 keep_die = false;
3700 }
3701 }
3702 else
3703 {
3704 if (name_type_mask & eFunctionNameTypeMethod)
3705 {
3706 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3707 keep_die = false;
3708 }
3709 }
3710 }
3711 }
3712 }
3713 if (keep_die)
3714 resolved_dies.insert(die);
3715 }
3716 }
3717 else
3718 {
3719 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3720 die_offset, name_cstr);
3721 }
3722 }
3723 die_offsets.clear();
Jim Ingham4cda6e02011-10-07 22:23:45 +00003724 }
3725 }
Greg Clayton7f995132011-10-04 22:41:51 +00003726 }
3727 else
3728 {
3729
3730 // Index the DWARF if we haven't already
3731 if (!m_indexed)
3732 Index ();
3733
Greg Clayton7f995132011-10-04 22:41:51 +00003734 if (name_type_mask & eFunctionNameTypeFull)
Matt Kopecd6089962013-05-10 17:53:48 +00003735 {
Greg Clayton7f995132011-10-04 22:41:51 +00003736 FindFunctions (name, m_function_fullname_index, sc_list);
3737
Matt Kopecd6089962013-05-10 17:53:48 +00003738 // Temporary workaround for global/anonymous namespace functions on linux
3739#if defined (__linux__)
3740 // If we didn't find any functions in the global namespace try
3741 // looking in the basename index but ignore any returned
3742 // functions that have a namespace (ie. mangled names starting with
3743 // '_ZN') but keep functions which have an anonymous namespace
3744 if (sc_list.GetSize() == 0)
3745 {
3746 SymbolContextList temp_sc_list;
3747 FindFunctions (name, m_function_basename_index, temp_sc_list);
3748 if (!namespace_decl)
3749 {
3750 SymbolContext sc;
3751 for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++)
3752 {
3753 if (temp_sc_list.GetContextAtIndex(i, sc))
3754 {
Matt Kopeca189d492013-05-10 22:55:24 +00003755 ConstString mangled_name = sc.GetFunctionName(Mangled::ePreferMangled);
3756 ConstString demangled_name = sc.GetFunctionName(Mangled::ePreferDemangled);
Matt Kopec04e5d582013-05-14 19:00:41 +00003757 if (strncmp(mangled_name.GetCString(), "_ZN", 3) ||
3758 !strncmp(demangled_name.GetCString(), "(anonymous namespace)", 21))
Matt Kopecd6089962013-05-10 17:53:48 +00003759 {
3760 sc_list.Append(sc);
3761 }
3762 }
3763 }
3764 }
3765 }
3766#endif
3767 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003768 DIEArray die_offsets;
3769 DWARFCompileUnit *dwarf_cu = NULL;
3770
Greg Clayton43fe2172013-04-03 02:00:15 +00003771 if (name_type_mask & eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003772 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003773 uint32_t num_base = m_function_basename_index.Find(name, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00003774 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003775 {
Greg Claytonaa044962011-10-13 00:59:38 +00003776 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3777 if (die)
3778 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003779 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3780 continue;
3781
Sean Callanan213fdb82011-10-13 01:49:10 +00003782 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3783 continue;
3784
Greg Claytonaa044962011-10-13 00:59:38 +00003785 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00003786 if (resolved_dies.find(die) == resolved_dies.end())
3787 {
3788 if (ResolveFunction (dwarf_cu, die, sc_list))
3789 resolved_dies.insert(die);
3790 }
Greg Claytonaa044962011-10-13 00:59:38 +00003791 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003792 }
3793 die_offsets.clear();
3794 }
3795
Greg Clayton43fe2172013-04-03 02:00:15 +00003796 if (name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003797 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003798 if (namespace_decl && *namespace_decl)
3799 return 0; // no methods in namespaces
3800
Greg Clayton43fe2172013-04-03 02:00:15 +00003801 uint32_t num_base = m_function_method_index.Find(name, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003802 {
Greg Claytonaa044962011-10-13 00:59:38 +00003803 for (uint32_t i = 0; i < num_base; i++)
3804 {
3805 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3806 if (die)
3807 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003808 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3809 continue;
3810
Greg Claytonaa044962011-10-13 00:59:38 +00003811 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00003812 if (resolved_dies.find(die) == resolved_dies.end())
3813 {
3814 if (ResolveFunction (dwarf_cu, die, sc_list))
3815 resolved_dies.insert(die);
3816 }
Greg Claytonaa044962011-10-13 00:59:38 +00003817 }
3818 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003819 }
3820 die_offsets.clear();
3821 }
Greg Clayton7f995132011-10-04 22:41:51 +00003822
Greg Clayton43fe2172013-04-03 02:00:15 +00003823 if ((name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003824 {
Greg Clayton7f995132011-10-04 22:41:51 +00003825 FindFunctions (name, m_function_selector_index, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003826 }
3827
Greg Clayton4d01ace2011-09-29 16:58:15 +00003828 }
3829
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003830 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003831 const uint32_t num_matches = sc_list.GetSize() - original_size;
3832
3833 if (log && num_matches > 0)
3834 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003835 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003836 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list) => %u",
3837 name.GetCString(),
3838 name_type_mask,
3839 append,
3840 num_matches);
3841 }
3842 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003843}
3844
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003845uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00003846SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003847{
3848 Timer scoped_timer (__PRETTY_FUNCTION__,
3849 "SymbolFileDWARF::FindFunctions (regex = '%s')",
3850 regex.GetText());
3851
Greg Clayton5160ce52013-03-27 23:08:40 +00003852 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003853
3854 if (log)
3855 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003856 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003857 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
3858 regex.GetText(),
3859 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003860 }
3861
3862
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003863 // If we aren't appending the results to this list, then clear the list
3864 if (!append)
3865 sc_list.Clear();
3866
3867 // Remember how many sc_list are in the list before we search in case
3868 // we are appending the results to a variable list.
3869 uint32_t original_size = sc_list.GetSize();
3870
Greg Clayton97fbc342011-10-20 22:30:33 +00003871 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003872 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003873 if (m_apple_names_ap.get())
3874 FindFunctions (regex, *m_apple_names_ap, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003875 }
3876 else
3877 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003878 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00003879 if (!m_indexed)
3880 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003881
Greg Clayton7f995132011-10-04 22:41:51 +00003882 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003883
Greg Clayton7f995132011-10-04 22:41:51 +00003884 FindFunctions (regex, m_function_fullname_index, sc_list);
3885 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003886
3887 // Return the number of variable that were appended to the list
3888 return sc_list.GetSize() - original_size;
3889}
Jim Ingham318c9f22011-08-26 19:44:13 +00003890
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003891uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00003892SymbolFileDWARF::FindTypes (const SymbolContext& sc,
3893 const ConstString &name,
3894 const lldb_private::ClangNamespaceDecl *namespace_decl,
3895 bool append,
3896 uint32_t max_matches,
3897 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003898{
Greg Claytonc685f8e2010-09-15 04:15:46 +00003899 DWARFDebugInfo* info = DebugInfo();
3900 if (info == NULL)
3901 return 0;
3902
Greg Clayton5160ce52013-03-27 23:08:40 +00003903 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003904
3905 if (log)
3906 {
Greg Clayton437a1352012-04-09 22:43:43 +00003907 if (namespace_decl)
3908 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003909 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003910 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)",
3911 name.GetCString(),
3912 namespace_decl->GetNamespaceDecl(),
3913 namespace_decl->GetQualifiedName().c_str(),
3914 append,
3915 max_matches);
3916 }
3917 else
3918 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003919 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003920 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)",
3921 name.GetCString(),
3922 append,
3923 max_matches);
3924 }
Greg Clayton21f2a492011-10-06 00:09:08 +00003925 }
3926
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003927 // If we aren't appending the results to this list, then clear the list
3928 if (!append)
3929 types.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003930
3931 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3932 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003933
Greg Claytond4a2b372011-09-12 23:21:58 +00003934 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003935
Greg Clayton97fbc342011-10-20 22:30:33 +00003936 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003937 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003938 if (m_apple_types_ap.get())
3939 {
3940 const char *name_cstr = name.GetCString();
3941 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3942 }
Greg Clayton7f995132011-10-04 22:41:51 +00003943 }
3944 else
3945 {
3946 if (!m_indexed)
3947 Index ();
3948
3949 m_type_index.Find (name, die_offsets);
3950 }
3951
Greg Clayton437a1352012-04-09 22:43:43 +00003952 const size_t num_die_matches = die_offsets.size();
Greg Clayton7f995132011-10-04 22:41:51 +00003953
Greg Clayton437a1352012-04-09 22:43:43 +00003954 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003955 {
Greg Clayton7f995132011-10-04 22:41:51 +00003956 const uint32_t initial_types_size = types.GetSize();
3957 DWARFCompileUnit* dwarf_cu = NULL;
3958 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003959 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00003960 for (size_t i=0; i<num_die_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003961 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003962 const dw_offset_t die_offset = die_offsets[i];
3963 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3964
Greg Clayton95d87902011-11-11 03:16:25 +00003965 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00003966 {
Greg Clayton95d87902011-11-11 03:16:25 +00003967 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3968 continue;
3969
3970 Type *matching_type = ResolveType (dwarf_cu, die);
3971 if (matching_type)
3972 {
3973 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003974 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00003975 if (types.GetSize() >= max_matches)
3976 break;
3977 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00003978 }
Greg Clayton95d87902011-11-11 03:16:25 +00003979 else
3980 {
3981 if (m_using_apple_tables)
3982 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003983 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
3984 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003985 }
3986 }
3987
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003988 }
Greg Clayton437a1352012-04-09 22:43:43 +00003989 const uint32_t num_matches = types.GetSize() - initial_types_size;
3990 if (log && num_matches)
3991 {
3992 if (namespace_decl)
3993 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003994 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003995 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u",
3996 name.GetCString(),
3997 namespace_decl->GetNamespaceDecl(),
3998 namespace_decl->GetQualifiedName().c_str(),
3999 append,
4000 max_matches,
4001 num_matches);
4002 }
4003 else
4004 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004005 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004006 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u",
4007 name.GetCString(),
4008 append,
4009 max_matches,
4010 num_matches);
4011 }
4012 }
4013 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004014 }
Greg Clayton7f995132011-10-04 22:41:51 +00004015 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004016}
4017
4018
Greg Clayton526e5af2010-11-13 03:52:47 +00004019ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00004020SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00004021 const ConstString &name,
4022 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004023{
Greg Clayton5160ce52013-03-27 23:08:40 +00004024 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00004025
4026 if (log)
4027 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004028 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00004029 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
4030 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00004031 }
Sean Callanan213fdb82011-10-13 01:49:10 +00004032
4033 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
4034 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00004035
Greg Clayton526e5af2010-11-13 03:52:47 +00004036 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004037 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00004038 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00004039 {
Greg Clayton7f995132011-10-04 22:41:51 +00004040 DIEArray die_offsets;
4041
Greg Clayton526e5af2010-11-13 03:52:47 +00004042 // Index if we already haven't to make sure the compile units
4043 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00004044 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004045 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004046 if (m_apple_namespaces_ap.get())
4047 {
4048 const char *name_cstr = name.GetCString();
4049 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
4050 }
Greg Clayton7f995132011-10-04 22:41:51 +00004051 }
4052 else
4053 {
4054 if (!m_indexed)
4055 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00004056
Greg Clayton7f995132011-10-04 22:41:51 +00004057 m_namespace_index.Find (name, die_offsets);
4058 }
Greg Claytond4a2b372011-09-12 23:21:58 +00004059
4060 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00004061 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00004062 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00004063 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00004064 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004065 DWARFDebugInfo* debug_info = DebugInfo();
4066 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00004067 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004068 const dw_offset_t die_offset = die_offsets[i];
4069 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00004070
Greg Clayton95d87902011-11-11 03:16:25 +00004071 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00004072 {
Greg Clayton95d87902011-11-11 03:16:25 +00004073 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
4074 continue;
4075
4076 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
4077 if (clang_namespace_decl)
4078 {
4079 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
4080 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
Greg Claytond1767f02011-12-08 02:13:16 +00004081 break;
Greg Clayton95d87902011-11-11 03:16:25 +00004082 }
Greg Claytond4a2b372011-09-12 23:21:58 +00004083 }
Greg Clayton95d87902011-11-11 03:16:25 +00004084 else
4085 {
4086 if (m_using_apple_tables)
4087 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004088 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
4089 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004090 }
4091 }
4092
Greg Clayton526e5af2010-11-13 03:52:47 +00004093 }
4094 }
Greg Clayton96d7d742010-11-10 23:42:09 +00004095 }
Greg Clayton437a1352012-04-09 22:43:43 +00004096 if (log && namespace_decl.GetNamespaceDecl())
4097 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004098 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004099 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"",
4100 name.GetCString(),
4101 namespace_decl.GetNamespaceDecl(),
4102 namespace_decl.GetQualifiedName().c_str());
4103 }
4104
Greg Clayton526e5af2010-11-13 03:52:47 +00004105 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004106}
4107
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004108uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004109SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004110{
4111 // Remember how many sc_list are in the list before we search in case
4112 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004113 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004114
4115 const uint32_t num_die_offsets = die_offsets.size();
4116 // Parse all of the types we found from the pubtypes matches
4117 uint32_t i;
4118 uint32_t num_matches = 0;
4119 for (i = 0; i < num_die_offsets; ++i)
4120 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004121 Type *matching_type = ResolveTypeUID (die_offsets[i]);
4122 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004123 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004124 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00004125 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004126 ++num_matches;
4127 if (num_matches >= max_matches)
4128 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004129 }
4130 }
4131
4132 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004133 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004134}
4135
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004136
4137size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00004138SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
4139 clang::DeclContext *containing_decl_ctx,
Greg Clayton5113dc82011-08-12 06:47:54 +00004140 DWARFCompileUnit* dwarf_cu,
4141 const DWARFDebugInfoEntry *parent_die,
4142 bool skip_artificial,
4143 bool &is_static,
4144 TypeList* type_list,
4145 std::vector<clang_type_t>& function_param_types,
4146 std::vector<clang::ParmVarDecl*>& function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004147 unsigned &type_quals,
4148 ClangASTContext::TemplateParameterInfos &template_param_infos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004149{
4150 if (parent_die == NULL)
4151 return 0;
4152
Greg Claytond88d7592010-09-15 08:33:30 +00004153 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
4154
Greg Clayton7fedea22010-11-16 02:10:54 +00004155 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004156 const DWARFDebugInfoEntry *die;
4157 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4158 {
4159 dw_tag_t tag = die->Tag();
4160 switch (tag)
4161 {
4162 case DW_TAG_formal_parameter:
4163 {
4164 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004165 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004166 if (num_attributes > 0)
4167 {
4168 const char *name = NULL;
4169 Declaration decl;
4170 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00004171 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004172 // one of None, Auto, Register, Extern, Static, PrivateExtern
4173
Sean Callanane2ef6e32010-09-23 03:01:22 +00004174 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004175 uint32_t i;
4176 for (i=0; i<num_attributes; ++i)
4177 {
4178 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4179 DWARFFormValue form_value;
4180 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4181 {
4182 switch (attr)
4183 {
4184 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4185 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4186 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4187 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
4188 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00004189 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004190 case DW_AT_location:
4191 // if (form_value.BlockData())
4192 // {
4193 // const DataExtractor& debug_info_data = debug_info();
4194 // uint32_t block_length = form_value.Unsigned();
4195 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
4196 // }
4197 // else
4198 // {
4199 // }
4200 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004201 case DW_AT_const_value:
4202 case DW_AT_default_value:
4203 case DW_AT_description:
4204 case DW_AT_endianity:
4205 case DW_AT_is_optional:
4206 case DW_AT_segment:
4207 case DW_AT_variable_parameter:
4208 default:
4209 case DW_AT_abstract_origin:
4210 case DW_AT_sibling:
4211 break;
4212 }
4213 }
4214 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00004215
Greg Clayton0fffff52010-09-24 05:15:53 +00004216 bool skip = false;
4217 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004218 {
Greg Clayton0fffff52010-09-24 05:15:53 +00004219 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00004220 {
4221 // In order to determine if a C++ member function is
4222 // "const" we have to look at the const-ness of "this"...
4223 // Ugly, but that
4224 if (arg_idx == 0)
4225 {
Greg Claytonf0705c82011-10-22 03:33:13 +00004226 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00004227 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004228 // Often times compilers omit the "this" name for the
4229 // specification DIEs, so we can't rely upon the name
4230 // being in the formal parameter DIE...
4231 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00004232 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004233 Type *this_type = ResolveTypeUID (param_type_die_offset);
4234 if (this_type)
4235 {
4236 uint32_t encoding_mask = this_type->GetEncodingMask();
4237 if (encoding_mask & Type::eEncodingIsPointerUID)
4238 {
4239 is_static = false;
4240
4241 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
4242 type_quals |= clang::Qualifiers::Const;
4243 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
4244 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00004245 }
4246 }
4247 }
4248 }
4249 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004250 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00004251 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004252 else
4253 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004254
Greg Clayton0fffff52010-09-24 05:15:53 +00004255 // HACK: Objective C formal parameters "self" and "_cmd"
4256 // are not marked as artificial in the DWARF...
Greg Clayton53eb1c22012-04-02 22:59:12 +00004257 CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
4258 if (comp_unit)
Greg Clayton0fffff52010-09-24 05:15:53 +00004259 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004260 switch (comp_unit->GetLanguage())
4261 {
4262 case eLanguageTypeObjC:
4263 case eLanguageTypeObjC_plus_plus:
4264 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
4265 skip = true;
4266 break;
4267 default:
4268 break;
4269 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004270 }
4271 }
4272 }
4273
4274 if (!skip)
4275 {
4276 Type *type = ResolveTypeUID(param_type_die_offset);
4277 if (type)
4278 {
Greg Claytonc93237c2010-10-01 20:48:32 +00004279 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00004280
Greg Clayton42ce2f32011-12-12 21:50:19 +00004281 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
4282 type->GetClangForwardType(),
4283 storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00004284 assert(param_var_decl);
4285 function_param_decls.push_back(param_var_decl);
Sean Callanan60217122012-04-13 00:10:03 +00004286
Greg Claytond0029442013-03-27 01:48:02 +00004287 GetClangASTContext().SetMetadataAsUserID (param_var_decl, MakeUserID(die->GetOffset()));
Greg Clayton0fffff52010-09-24 05:15:53 +00004288 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004289 }
4290 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004291 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004292 }
4293 break;
4294
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004295 case DW_TAG_template_type_parameter:
4296 case DW_TAG_template_value_parameter:
4297 ParseTemplateDIE (dwarf_cu, die,template_param_infos);
4298 break;
4299
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004300 default:
4301 break;
4302 }
4303 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004304 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004305}
4306
4307size_t
4308SymbolFileDWARF::ParseChildEnumerators
4309(
4310 const SymbolContext& sc,
Greg Clayton3e067532013-03-05 23:54:39 +00004311 clang_type_t enumerator_clang_type,
4312 bool is_signed,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004313 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00004314 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004315 const DWARFDebugInfoEntry *parent_die
4316)
4317{
4318 if (parent_die == NULL)
4319 return 0;
4320
4321 size_t enumerators_added = 0;
4322 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00004323 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
4324
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004325 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4326 {
4327 const dw_tag_t tag = die->Tag();
4328 if (tag == DW_TAG_enumerator)
4329 {
4330 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004331 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004332 if (num_child_attributes > 0)
4333 {
4334 const char *name = NULL;
4335 bool got_value = false;
4336 int64_t enum_value = 0;
4337 Declaration decl;
4338
4339 uint32_t i;
4340 for (i=0; i<num_child_attributes; ++i)
4341 {
4342 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4343 DWARFFormValue form_value;
4344 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4345 {
4346 switch (attr)
4347 {
4348 case DW_AT_const_value:
4349 got_value = true;
Greg Clayton3e067532013-03-05 23:54:39 +00004350 if (is_signed)
4351 enum_value = form_value.Signed();
4352 else
4353 enum_value = form_value.Unsigned();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004354 break;
4355
4356 case DW_AT_name:
4357 name = form_value.AsCString(&get_debug_str_data());
4358 break;
4359
4360 case DW_AT_description:
4361 default:
4362 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4363 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4364 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4365 case DW_AT_sibling:
4366 break;
4367 }
4368 }
4369 }
4370
4371 if (name && name[0] && got_value)
4372 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004373 GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
4374 enumerator_clang_type,
4375 decl,
4376 name,
4377 enum_value,
4378 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004379 ++enumerators_added;
4380 }
4381 }
4382 }
4383 }
4384 return enumerators_added;
4385}
4386
4387void
4388SymbolFileDWARF::ParseChildArrayInfo
4389(
4390 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004391 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004392 const DWARFDebugInfoEntry *parent_die,
4393 int64_t& first_index,
4394 std::vector<uint64_t>& element_orders,
4395 uint32_t& byte_stride,
4396 uint32_t& bit_stride
4397)
4398{
4399 if (parent_die == NULL)
4400 return;
4401
4402 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00004403 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004404 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4405 {
4406 const dw_tag_t tag = die->Tag();
4407 switch (tag)
4408 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004409 case DW_TAG_subrange_type:
4410 {
4411 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004412 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004413 if (num_child_attributes > 0)
4414 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004415 uint64_t num_elements = 0;
4416 uint64_t lower_bound = 0;
4417 uint64_t upper_bound = 0;
Greg Clayton4ef877f2012-12-06 02:33:54 +00004418 bool upper_bound_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004419 uint32_t i;
4420 for (i=0; i<num_child_attributes; ++i)
4421 {
4422 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4423 DWARFFormValue form_value;
4424 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4425 {
4426 switch (attr)
4427 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004428 case DW_AT_name:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004429 break;
4430
4431 case DW_AT_count:
4432 num_elements = form_value.Unsigned();
4433 break;
4434
4435 case DW_AT_bit_stride:
4436 bit_stride = form_value.Unsigned();
4437 break;
4438
4439 case DW_AT_byte_stride:
4440 byte_stride = form_value.Unsigned();
4441 break;
4442
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004443 case DW_AT_lower_bound:
4444 lower_bound = form_value.Unsigned();
4445 break;
4446
4447 case DW_AT_upper_bound:
Greg Clayton4ef877f2012-12-06 02:33:54 +00004448 upper_bound_valid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004449 upper_bound = form_value.Unsigned();
4450 break;
4451
4452 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004453 case DW_AT_abstract_origin:
4454 case DW_AT_accessibility:
4455 case DW_AT_allocated:
4456 case DW_AT_associated:
4457 case DW_AT_data_location:
4458 case DW_AT_declaration:
4459 case DW_AT_description:
4460 case DW_AT_sibling:
4461 case DW_AT_threads_scaled:
4462 case DW_AT_type:
4463 case DW_AT_visibility:
4464 break;
4465 }
4466 }
4467 }
4468
Greg Claytone6a07792012-12-05 21:59:39 +00004469 if (num_elements == 0)
4470 {
Greg Clayton4ef877f2012-12-06 02:33:54 +00004471 if (upper_bound_valid && upper_bound >= lower_bound)
Greg Claytone6a07792012-12-05 21:59:39 +00004472 num_elements = upper_bound - lower_bound + 1;
4473 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004474
Sean Callananec979ba2012-10-22 23:56:48 +00004475 element_orders.push_back (num_elements);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004476 }
4477 }
4478 break;
4479 }
4480 }
4481}
4482
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004483TypeSP
Greg Clayton53eb1c22012-04-02 22:59:12 +00004484SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004485{
4486 TypeSP type_sp;
4487 if (die != NULL)
4488 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004489 assert(dwarf_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00004490 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004491 if (type_ptr == NULL)
4492 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004493 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu);
Greg Claytonca512b32011-01-14 04:54:56 +00004494 assert (lldb_cu);
4495 SymbolContext sc(lldb_cu);
Greg Clayton53eb1c22012-04-02 22:59:12 +00004496 type_sp = ParseType(sc, dwarf_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004497 }
4498 else if (type_ptr != DIE_IS_BEING_PARSED)
4499 {
4500 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00004501 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004502 }
4503
4504 }
4505 return type_sp;
4506}
4507
4508clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00004509SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004510{
4511 if (die_offset != DW_INVALID_OFFSET)
4512 {
4513 DWARFCompileUnitSP cu_sp;
4514 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004515 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004516 }
4517 return NULL;
4518}
4519
Sean Callanan72e49402011-08-05 23:43:37 +00004520clang::DeclContext *
4521SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
4522{
4523 if (die_offset != DW_INVALID_OFFSET)
4524 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004525 DWARFDebugInfo* debug_info = DebugInfo();
4526 if (debug_info)
4527 {
4528 DWARFCompileUnitSP cu_sp;
4529 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
4530 if (die)
4531 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
4532 }
Sean Callanan72e49402011-08-05 23:43:37 +00004533 }
4534 return NULL;
4535}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004536
Greg Clayton96d7d742010-11-10 23:42:09 +00004537clang::NamespaceDecl *
Greg Clayton53eb1c22012-04-02 22:59:12 +00004538SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die)
Greg Clayton96d7d742010-11-10 23:42:09 +00004539{
Greg Clayton030a2042011-10-14 21:34:45 +00004540 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00004541 {
Greg Clayton030a2042011-10-14 21:34:45 +00004542 // See if we already parsed this namespace DIE and associated it with a
4543 // uniqued namespace declaration
4544 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
4545 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004546 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00004547 else
4548 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004549 const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL);
4550 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00004551 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
Greg Clayton5160ce52013-03-27 23:08:40 +00004552 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton9d3d6882011-10-31 23:51:19 +00004553 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00004554 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00004555 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00004556 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004557 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00004558 "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 +00004559 GetClangASTContext().getASTContext(),
4560 MakeUserID(die->GetOffset()),
4561 namespace_name,
4562 namespace_decl,
4563 namespace_decl->getOriginalNamespace());
Greg Clayton030a2042011-10-14 21:34:45 +00004564 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004565 else
4566 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004567 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00004568 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
Greg Claytone38a5ed2012-01-05 03:57:59 +00004569 GetClangASTContext().getASTContext(),
4570 MakeUserID(die->GetOffset()),
4571 namespace_decl,
4572 namespace_decl->getOriginalNamespace());
Greg Clayton9d3d6882011-10-31 23:51:19 +00004573 }
Greg Clayton030a2042011-10-14 21:34:45 +00004574 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004575
4576 if (namespace_decl)
4577 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
4578 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004579 }
4580 }
4581 return NULL;
4582}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004583
4584clang::DeclContext *
Greg Claytoncab36a32011-12-08 05:16:30 +00004585SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Sean Callanan72e49402011-08-05 23:43:37 +00004586{
Greg Clayton5cf58b92011-10-05 22:22:08 +00004587 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4588 if (clang_decl_ctx)
4589 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004590 // If this DIE has a specification, or an abstract origin, then trace to those.
4591
Greg Claytoncab36a32011-12-08 05:16:30 +00004592 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004593 if (die_offset != DW_INVALID_OFFSET)
4594 return GetClangDeclContextForDIEOffset (sc, die_offset);
4595
Greg Claytoncab36a32011-12-08 05:16:30 +00004596 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004597 if (die_offset != DW_INVALID_OFFSET)
4598 return GetClangDeclContextForDIEOffset (sc, die_offset);
4599
Greg Clayton5160ce52013-03-27 23:08:40 +00004600 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00004601 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004602 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 +00004603 // This is the DIE we want. Parse it, then query our map.
Greg Claytoncab36a32011-12-08 05:16:30 +00004604 bool assert_not_being_parsed = true;
4605 ResolveTypeUID (cu, die, assert_not_being_parsed);
4606
Greg Clayton5cf58b92011-10-05 22:22:08 +00004607 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4608
4609 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004610}
4611
4612clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00004613SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004614{
Greg Claytonca512b32011-01-14 04:54:56 +00004615 if (m_clang_tu_decl == NULL)
4616 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004617
Greg Clayton2bc22f82011-09-30 03:20:47 +00004618 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004619
4620 if (decl_ctx_die_copy)
4621 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00004622
4623 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004624 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00004625
Greg Clayton2bc22f82011-09-30 03:20:47 +00004626 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
4627 if (pos != m_die_to_decl_ctx.end())
4628 return pos->second;
4629
4630 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004631 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004632 case DW_TAG_compile_unit:
4633 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004634
Greg Clayton2bc22f82011-09-30 03:20:47 +00004635 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00004636 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00004637 break;
4638
4639 case DW_TAG_structure_type:
4640 case DW_TAG_union_type:
4641 case DW_TAG_class_type:
4642 {
4643 Type* type = ResolveType (cu, decl_ctx_die);
4644 if (type)
4645 {
4646 clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ());
4647 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00004648 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004649 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
4650 if (decl_ctx)
4651 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00004652 }
4653 }
Greg Claytonca512b32011-01-14 04:54:56 +00004654 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00004655 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004656
Greg Clayton2bc22f82011-09-30 03:20:47 +00004657 default:
4658 break;
Greg Claytonca512b32011-01-14 04:54:56 +00004659 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004660 }
Greg Clayton7a345282010-11-09 23:46:37 +00004661 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004662}
4663
Greg Clayton2bc22f82011-09-30 03:20:47 +00004664
4665const DWARFDebugInfoEntry *
4666SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4667{
4668 if (cu && die)
4669 {
4670 const DWARFDebugInfoEntry * const decl_die = die;
4671
4672 while (die != NULL)
4673 {
4674 // If this is the original DIE that we are searching for a declaration
4675 // for, then don't look in the cache as we don't want our own decl
4676 // context to be our decl context...
4677 if (decl_die != die)
4678 {
4679 switch (die->Tag())
4680 {
4681 case DW_TAG_compile_unit:
4682 case DW_TAG_namespace:
4683 case DW_TAG_structure_type:
4684 case DW_TAG_union_type:
4685 case DW_TAG_class_type:
4686 return die;
4687
4688 default:
4689 break;
4690 }
4691 }
4692
4693 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4694 if (die_offset != DW_INVALID_OFFSET)
4695 {
4696 DWARFCompileUnit *spec_cu = cu;
4697 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
4698 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
4699 if (spec_die_decl_ctx_die)
4700 return spec_die_decl_ctx_die;
4701 }
4702
4703 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
4704 if (die_offset != DW_INVALID_OFFSET)
4705 {
4706 DWARFCompileUnit *abs_cu = cu;
4707 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
4708 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
4709 if (abs_die_decl_ctx_die)
4710 return abs_die_decl_ctx_die;
4711 }
4712
4713 die = die->GetParent();
4714 }
4715 }
4716 return NULL;
4717}
4718
4719
Greg Clayton901c5ca2011-12-03 04:40:03 +00004720Symbol *
4721SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
4722{
4723 Symbol *objc_class_symbol = NULL;
4724 if (m_obj_file)
4725 {
Greg Clayton3046e662013-07-10 01:23:25 +00004726 Symtab *symtab = m_obj_file->GetSymtab ();
Greg Clayton901c5ca2011-12-03 04:40:03 +00004727 if (symtab)
4728 {
4729 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
4730 eSymbolTypeObjCClass,
4731 Symtab::eDebugNo,
4732 Symtab::eVisibilityAny);
4733 }
4734 }
4735 return objc_class_symbol;
4736}
4737
Greg Claytonc7f03b62012-01-12 04:33:28 +00004738// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
4739// then we can end up looking through all class types for a complete type and never find
4740// the full definition. We need to know if this attribute is supported, so we determine
4741// this here and cache th result. We also need to worry about the debug map DWARF file
4742// if we are doing darwin DWARF in .o file debugging.
4743bool
4744SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
4745{
4746 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
4747 {
4748 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
4749 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
4750 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4751 else
4752 {
4753 DWARFDebugInfo* debug_info = DebugInfo();
4754 const uint32_t num_compile_units = GetNumCompileUnits();
4755 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
4756 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004757 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
4758 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004759 {
4760 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4761 break;
4762 }
4763 }
4764 }
Greg Clayton1f746072012-08-29 21:13:06 +00004765 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004766 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
4767 }
4768 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
4769}
Greg Clayton901c5ca2011-12-03 04:40:03 +00004770
4771// This function can be used when a DIE is found that is a forward declaration
4772// DIE and we want to try and find a type that has the complete definition.
4773TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00004774SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
4775 const ConstString &type_name,
4776 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00004777{
4778
4779 TypeSP type_sp;
4780
Greg Claytonc7f03b62012-01-12 04:33:28 +00004781 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00004782 return type_sp;
4783
4784 DIEArray die_offsets;
4785
4786 if (m_using_apple_tables)
4787 {
4788 if (m_apple_types_ap.get())
4789 {
4790 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00004791 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004792 }
4793 }
4794 else
4795 {
4796 if (!m_indexed)
4797 Index ();
4798
4799 m_type_index.Find (type_name, die_offsets);
4800 }
4801
Greg Clayton901c5ca2011-12-03 04:40:03 +00004802 const size_t num_matches = die_offsets.size();
4803
Greg Clayton901c5ca2011-12-03 04:40:03 +00004804 DWARFCompileUnit* type_cu = NULL;
4805 const DWARFDebugInfoEntry* type_die = NULL;
4806 if (num_matches)
4807 {
4808 DWARFDebugInfo* debug_info = DebugInfo();
4809 for (size_t i=0; i<num_matches; ++i)
4810 {
4811 const dw_offset_t die_offset = die_offsets[i];
4812 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4813
4814 if (type_die)
4815 {
4816 bool try_resolving_type = false;
4817
4818 // Don't try and resolve the DIE we are looking for with the DIE itself!
4819 if (type_die != die)
4820 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004821 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00004822 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004823 case DW_TAG_class_type:
4824 case DW_TAG_structure_type:
4825 try_resolving_type = true;
4826 break;
4827 default:
4828 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00004829 }
4830 }
4831
4832 if (try_resolving_type)
4833 {
Sean Callanana9bc0652012-01-19 02:17:40 +00004834 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004835 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004836
4837 if (try_resolving_type)
4838 {
4839 Type *resolved_type = ResolveType (type_cu, type_die, false);
4840 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4841 {
Daniel Malead01b2952012-11-29 21:49:15 +00004842 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 Clayton901c5ca2011-12-03 04:40:03 +00004843 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00004844 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton901c5ca2011-12-03 04:40:03 +00004845 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4846 MakeUserID(type_die->GetOffset()),
4847 MakeUserID(type_cu->GetOffset()));
4848
Greg Claytonc7f03b62012-01-12 04:33:28 +00004849 if (die)
4850 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00004851 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00004852 break;
4853 }
4854 }
4855 }
4856 }
4857 else
4858 {
4859 if (m_using_apple_tables)
4860 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004861 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4862 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00004863 }
4864 }
4865
4866 }
4867 }
4868 return type_sp;
4869}
4870
Greg Claytona8022fa2012-04-24 21:22:41 +00004871
Greg Clayton80c26302012-02-05 06:12:47 +00004872//----------------------------------------------------------------------
4873// This function helps to ensure that the declaration contexts match for
4874// two different DIEs. Often times debug information will refer to a
4875// forward declaration of a type (the equivalent of "struct my_struct;".
4876// There will often be a declaration of that type elsewhere that has the
4877// full definition. When we go looking for the full type "my_struct", we
4878// will find one or more matches in the accelerator tables and we will
4879// then need to make sure the type was in the same declaration context
4880// as the original DIE. This function can efficiently compare two DIEs
4881// and will return true when the declaration context matches, and false
4882// when they don't.
4883//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00004884bool
4885SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
4886 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
4887{
Greg Claytona8022fa2012-04-24 21:22:41 +00004888 if (die1 == die2)
4889 return true;
4890
4891#if defined (LLDB_CONFIGURATION_DEBUG)
4892 // You can't and shouldn't call this function with a compile unit from
4893 // two different SymbolFileDWARF instances.
4894 assert (DebugInfo()->ContainsCompileUnit (cu1));
4895 assert (DebugInfo()->ContainsCompileUnit (cu2));
4896#endif
4897
Greg Clayton890ff562012-02-02 05:48:16 +00004898 DWARFDIECollection decl_ctx_1;
4899 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00004900 //The declaration DIE stack is a stack of the declaration context
4901 // DIEs all the way back to the compile unit. If a type "T" is
4902 // declared inside a class "B", and class "B" is declared inside
4903 // a class "A" and class "A" is in a namespace "lldb", and the
4904 // namespace is in a compile unit, there will be a stack of DIEs:
4905 //
4906 // [0] DW_TAG_class_type for "B"
4907 // [1] DW_TAG_class_type for "A"
4908 // [2] DW_TAG_namespace for "lldb"
4909 // [3] DW_TAG_compile_unit for the source file.
4910 //
4911 // We grab both contexts and make sure that everything matches
4912 // all the way back to the compiler unit.
4913
4914 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00004915 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004916 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00004917 // Make sure the context arrays have the same size, otherwise
4918 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00004919 const size_t count1 = decl_ctx_1.Size();
4920 const size_t count2 = decl_ctx_2.Size();
4921 if (count1 != count2)
4922 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00004923
4924 // Make sure the DW_TAG values match all the way back up the the
4925 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00004926 const DWARFDebugInfoEntry *decl_ctx_die1;
4927 const DWARFDebugInfoEntry *decl_ctx_die2;
4928 size_t i;
4929 for (i=0; i<count1; i++)
4930 {
4931 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4932 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4933 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
4934 return false;
4935 }
Greg Clayton890ff562012-02-02 05:48:16 +00004936#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00004937
4938 // Make sure the top item in the decl context die array is always
4939 // DW_TAG_compile_unit. If it isn't then something went wrong in
4940 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00004941 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00004942
Greg Clayton890ff562012-02-02 05:48:16 +00004943#endif
4944 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00004945 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00004946 for (i=0; i<count1 - 1; i++)
4947 {
4948 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4949 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4950 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004951 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00004952 // If the string was from a DW_FORM_strp, then the pointer will often
4953 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00004954 if (name1 == name2)
4955 continue;
4956
4957 // Name pointers are not equal, so only compare the strings
4958 // if both are not NULL.
4959 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00004960 {
Greg Clayton5569e642012-02-06 01:44:54 +00004961 // If the strings don't compare, we are done...
4962 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00004963 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00004964 }
4965 else
4966 {
4967 // One name was NULL while the other wasn't
4968 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00004969 }
4970 }
Greg Clayton80c26302012-02-05 06:12:47 +00004971 // We made it through all of the checks and the declaration contexts
4972 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00004973 return true;
4974}
Greg Clayton220a0072011-12-09 08:48:30 +00004975
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004976// This function can be used when a DIE is found that is a forward declaration
4977// DIE and we want to try and find a type that has the complete definition.
Greg Claytona8022fa2012-04-24 21:22:41 +00004978// "cu" and "die" must be from this SymbolFileDWARF
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004979TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00004980SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
Greg Clayton7f995132011-10-04 22:41:51 +00004981 const DWARFDebugInfoEntry *die,
4982 const ConstString &type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004983{
4984 TypeSP type_sp;
4985
Greg Claytona8022fa2012-04-24 21:22:41 +00004986#if defined (LLDB_CONFIGURATION_DEBUG)
4987 // You can't and shouldn't call this function with a compile unit from
4988 // another SymbolFileDWARF instance.
4989 assert (DebugInfo()->ContainsCompileUnit (cu));
4990#endif
4991
Greg Clayton1a65ae12011-01-25 23:55:37 +00004992 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004993 return type_sp;
4994
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004995 std::string qualified_name;
4996
Greg Clayton5160ce52013-03-27 23:08:40 +00004997 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004998 if (log)
4999 {
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005000 die->GetQualifiedName(this, cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00005001 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005002 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x (%s), name='%s')",
5003 die->GetOffset(),
5004 qualified_name.c_str(),
5005 type_name.GetCString());
5006 }
5007
Greg Clayton7f995132011-10-04 22:41:51 +00005008 DIEArray die_offsets;
5009
Greg Clayton97fbc342011-10-20 22:30:33 +00005010 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00005011 {
Greg Clayton97fbc342011-10-20 22:30:33 +00005012 if (m_apple_types_ap.get())
5013 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005014 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
5015 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
5016 if (has_tag && has_qualified_name_hash)
Greg Claytond1767f02011-12-08 02:13:16 +00005017 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005018 if (qualified_name.empty())
5019 die->GetQualifiedName(this, cu, qualified_name);
5020
5021 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name.c_str());
5022 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005023 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005024 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), die->Tag(), qualified_name_hash, die_offsets);
5025 }
5026 else if (has_tag > 1)
5027 {
5028 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005029 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
Greg Claytonae920b62012-01-06 00:17:16 +00005030 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets);
Greg Claytond1767f02011-12-08 02:13:16 +00005031 }
5032 else
5033 {
5034 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
5035 }
Greg Clayton97fbc342011-10-20 22:30:33 +00005036 }
Greg Clayton7f995132011-10-04 22:41:51 +00005037 }
5038 else
5039 {
5040 if (!m_indexed)
5041 Index ();
5042
5043 m_type_index.Find (type_name, die_offsets);
5044 }
Greg Clayton7f995132011-10-04 22:41:51 +00005045
5046 const size_t num_matches = die_offsets.size();
Greg Clayton69974892010-12-03 21:42:06 +00005047
Greg Clayton934cb052011-12-03 00:27:05 +00005048 const dw_tag_t die_tag = die->Tag();
Greg Claytond4a2b372011-09-12 23:21:58 +00005049
5050 DWARFCompileUnit* type_cu = NULL;
5051 const DWARFDebugInfoEntry* type_die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00005052 if (num_matches)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005053 {
Greg Claytond4a2b372011-09-12 23:21:58 +00005054 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005055 for (size_t i=0; i<num_matches; ++i)
5056 {
Greg Claytond4a2b372011-09-12 23:21:58 +00005057 const dw_offset_t die_offset = die_offsets[i];
5058 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005059
Greg Clayton95d87902011-11-11 03:16:25 +00005060 if (type_die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005061 {
Greg Clayton934cb052011-12-03 00:27:05 +00005062 bool try_resolving_type = false;
5063
5064 // Don't try and resolve the DIE we are looking for with the DIE itself!
5065 if (type_die != die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005066 {
Greg Clayton934cb052011-12-03 00:27:05 +00005067 const dw_tag_t type_die_tag = type_die->Tag();
5068 // Make sure the tags match
5069 if (type_die_tag == die_tag)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005070 {
Greg Clayton934cb052011-12-03 00:27:05 +00005071 // The tags match, lets try resolving this type
5072 try_resolving_type = true;
5073 }
5074 else
5075 {
5076 // The tags don't match, but we need to watch our for a
5077 // forward declaration for a struct and ("struct foo")
5078 // ends up being a class ("class foo { ... };") or
5079 // vice versa.
5080 switch (type_die_tag)
Greg Clayton95d87902011-11-11 03:16:25 +00005081 {
Greg Clayton934cb052011-12-03 00:27:05 +00005082 case DW_TAG_class_type:
5083 // We had a "class foo", see if we ended up with a "struct foo { ... };"
5084 try_resolving_type = (die_tag == DW_TAG_structure_type);
5085 break;
5086 case DW_TAG_structure_type:
5087 // We had a "struct foo", see if we ended up with a "class foo { ... };"
5088 try_resolving_type = (die_tag == DW_TAG_class_type);
5089 break;
5090 default:
5091 // Tags don't match, don't event try to resolve
5092 // using this type whose name matches....
Greg Clayton95d87902011-11-11 03:16:25 +00005093 break;
5094 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005095 }
5096 }
Greg Clayton934cb052011-12-03 00:27:05 +00005097
5098 if (try_resolving_type)
5099 {
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005100 if (log)
5101 {
5102 std::string qualified_name;
5103 type_die->GetQualifiedName(this, cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00005104 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005105 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') trying die=0x%8.8x (%s)",
5106 die->GetOffset(),
5107 type_name.GetCString(),
5108 type_die->GetOffset(),
5109 qualified_name.c_str());
5110 }
5111
Greg Clayton890ff562012-02-02 05:48:16 +00005112 // Make sure the decl contexts match all the way up
5113 if (DIEDeclContextsMatch(cu, die, type_cu, type_die))
Greg Clayton934cb052011-12-03 00:27:05 +00005114 {
Greg Clayton890ff562012-02-02 05:48:16 +00005115 Type *resolved_type = ResolveType (type_cu, type_die, false);
5116 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5117 {
Daniel Malead01b2952012-11-29 21:49:15 +00005118 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 +00005119 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00005120 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton890ff562012-02-02 05:48:16 +00005121 m_obj_file->GetFileSpec().GetFilename().AsCString(),
5122 MakeUserID(type_die->GetOffset()),
5123 MakeUserID(type_cu->GetOffset()));
5124
5125 m_die_to_type[die] = resolved_type;
Greg Claytonff7692a2012-02-02 18:16:59 +00005126 type_sp = resolved_type->shared_from_this();
Greg Clayton890ff562012-02-02 05:48:16 +00005127 break;
5128 }
Greg Clayton934cb052011-12-03 00:27:05 +00005129 }
5130 }
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005131 else
5132 {
5133 if (log)
5134 {
5135 std::string qualified_name;
5136 type_die->GetQualifiedName(this, cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00005137 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005138 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') ignoring die=0x%8.8x (%s)",
5139 die->GetOffset(),
5140 type_name.GetCString(),
5141 type_die->GetOffset(),
5142 qualified_name.c_str());
5143 }
5144 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005145 }
Greg Clayton95d87902011-11-11 03:16:25 +00005146 else
5147 {
5148 if (m_using_apple_tables)
5149 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005150 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5151 die_offset, type_name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00005152 }
5153 }
5154
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005155 }
5156 }
5157 return type_sp;
5158}
5159
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005160TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00005161SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx)
5162{
5163 TypeSP type_sp;
5164
5165 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
5166 if (dwarf_decl_ctx_count > 0)
5167 {
5168 const ConstString type_name(dwarf_decl_ctx[0].name);
5169 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
5170
5171 if (type_name)
5172 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005173 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
Greg Claytona8022fa2012-04-24 21:22:41 +00005174 if (log)
5175 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005176 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005177 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')",
5178 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5179 dwarf_decl_ctx.GetQualifiedName());
5180 }
5181
5182 DIEArray die_offsets;
5183
5184 if (m_using_apple_tables)
5185 {
5186 if (m_apple_types_ap.get())
5187 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005188 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
5189 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
5190 if (has_tag && has_qualified_name_hash)
Greg Claytona8022fa2012-04-24 21:22:41 +00005191 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005192 const char *qualified_name = dwarf_decl_ctx.GetQualifiedName();
5193 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name);
5194 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005195 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005196 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets);
5197 }
5198 else if (has_tag)
5199 {
5200 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005201 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
Greg Claytona8022fa2012-04-24 21:22:41 +00005202 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets);
5203 }
5204 else
5205 {
5206 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
5207 }
5208 }
5209 }
5210 else
5211 {
5212 if (!m_indexed)
5213 Index ();
5214
5215 m_type_index.Find (type_name, die_offsets);
5216 }
5217
5218 const size_t num_matches = die_offsets.size();
5219
5220
5221 DWARFCompileUnit* type_cu = NULL;
5222 const DWARFDebugInfoEntry* type_die = NULL;
5223 if (num_matches)
5224 {
5225 DWARFDebugInfo* debug_info = DebugInfo();
5226 for (size_t i=0; i<num_matches; ++i)
5227 {
5228 const dw_offset_t die_offset = die_offsets[i];
5229 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
5230
5231 if (type_die)
5232 {
5233 bool try_resolving_type = false;
5234
5235 // Don't try and resolve the DIE we are looking for with the DIE itself!
5236 const dw_tag_t type_tag = type_die->Tag();
5237 // Make sure the tags match
5238 if (type_tag == tag)
5239 {
5240 // The tags match, lets try resolving this type
5241 try_resolving_type = true;
5242 }
5243 else
5244 {
5245 // The tags don't match, but we need to watch our for a
5246 // forward declaration for a struct and ("struct foo")
5247 // ends up being a class ("class foo { ... };") or
5248 // vice versa.
5249 switch (type_tag)
5250 {
5251 case DW_TAG_class_type:
5252 // We had a "class foo", see if we ended up with a "struct foo { ... };"
5253 try_resolving_type = (tag == DW_TAG_structure_type);
5254 break;
5255 case DW_TAG_structure_type:
5256 // We had a "struct foo", see if we ended up with a "class foo { ... };"
5257 try_resolving_type = (tag == DW_TAG_class_type);
5258 break;
5259 default:
5260 // Tags don't match, don't event try to resolve
5261 // using this type whose name matches....
5262 break;
5263 }
5264 }
5265
5266 if (try_resolving_type)
5267 {
5268 DWARFDeclContext type_dwarf_decl_ctx;
5269 type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx);
5270
5271 if (log)
5272 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005273 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005274 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)",
5275 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5276 dwarf_decl_ctx.GetQualifiedName(),
5277 type_die->GetOffset(),
5278 type_dwarf_decl_ctx.GetQualifiedName());
5279 }
5280
5281 // Make sure the decl contexts match all the way up
5282 if (dwarf_decl_ctx == type_dwarf_decl_ctx)
5283 {
5284 Type *resolved_type = ResolveType (type_cu, type_die, false);
5285 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5286 {
5287 type_sp = resolved_type->shared_from_this();
5288 break;
5289 }
5290 }
5291 }
5292 else
5293 {
5294 if (log)
5295 {
5296 std::string qualified_name;
5297 type_die->GetQualifiedName(this, type_cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00005298 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005299 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)",
5300 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5301 dwarf_decl_ctx.GetQualifiedName(),
5302 type_die->GetOffset(),
5303 qualified_name.c_str());
5304 }
5305 }
5306 }
5307 else
5308 {
5309 if (m_using_apple_tables)
5310 {
5311 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5312 die_offset, type_name.GetCString());
5313 }
5314 }
5315
5316 }
5317 }
5318 }
5319 }
5320 return type_sp;
5321}
5322
Greg Clayton4116e932012-05-15 02:33:01 +00005323bool
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005324SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005325 Type *class_type,
Greg Clayton4116e932012-05-15 02:33:01 +00005326 DWARFCompileUnit* src_cu,
5327 const DWARFDebugInfoEntry *src_class_die,
5328 DWARFCompileUnit* dst_cu,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005329 const DWARFDebugInfoEntry *dst_class_die,
5330 llvm::SmallVectorImpl <const DWARFDebugInfoEntry *> &failures)
Greg Clayton4116e932012-05-15 02:33:01 +00005331{
5332 if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die)
5333 return false;
5334 if (src_class_die->Tag() != dst_class_die->Tag())
5335 return false;
5336
5337 // We need to complete the class type so we can get all of the method types
5338 // parsed so we can then unique those types to their equivalent counterparts
5339 // in "dst_cu" and "dst_class_die"
5340 class_type->GetClangFullType();
5341
5342 const DWARFDebugInfoEntry *src_die;
5343 const DWARFDebugInfoEntry *dst_die;
5344 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die;
5345 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die;
Greg Clayton65ec1032012-11-12 21:27:20 +00005346 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial;
5347 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial;
Greg Clayton4116e932012-05-15 02:33:01 +00005348 for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling())
5349 {
5350 if (src_die->Tag() == DW_TAG_subprogram)
5351 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005352 // Make sure this is a declaration and not a concrete instance by looking
5353 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5354 // are placed inside the class definitions and shouldn't be included in
5355 // the list of things are are tracking here.
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005356 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_declaration, 0) == 1)
Greg Clayton84afacd2012-11-07 23:09:32 +00005357 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005358 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton84afacd2012-11-07 23:09:32 +00005359 if (src_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005360 {
5361 ConstString src_const_name(src_name);
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005362 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0))
Greg Clayton65ec1032012-11-12 21:27:20 +00005363 src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die);
5364 else
5365 src_name_to_die.Append(src_const_name.GetCString(), src_die);
5366 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005367 }
Greg Clayton4116e932012-05-15 02:33:01 +00005368 }
5369 }
5370 for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling())
5371 {
5372 if (dst_die->Tag() == DW_TAG_subprogram)
5373 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005374 // Make sure this is a declaration and not a concrete instance by looking
5375 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5376 // are placed inside the class definitions and shouldn't be included in
5377 // the list of things are are tracking here.
5378 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1)
5379 {
5380 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5381 if (dst_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005382 {
5383 ConstString dst_const_name(dst_name);
5384 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0))
5385 dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die);
5386 else
5387 dst_name_to_die.Append(dst_const_name.GetCString(), dst_die);
5388 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005389 }
Greg Clayton4116e932012-05-15 02:33:01 +00005390 }
5391 }
5392 const uint32_t src_size = src_name_to_die.GetSize ();
5393 const uint32_t dst_size = dst_name_to_die.GetSize ();
Greg Clayton5160ce52013-03-27 23:08:40 +00005394 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005395
5396 // Is everything kosher so we can go through the members at top speed?
5397 bool fast_path = true;
5398
5399 if (src_size != dst_size)
Greg Clayton4116e932012-05-15 02:33:01 +00005400 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005401 if (src_size != 0 && dst_size != 0)
5402 {
5403 if (log)
5404 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)",
5405 src_class_die->GetOffset(),
5406 dst_class_die->GetOffset(),
5407 src_size,
5408 dst_size);
5409 }
5410
5411 fast_path = false;
5412 }
5413
5414 uint32_t idx;
5415
5416 if (fast_path)
5417 {
Greg Clayton4116e932012-05-15 02:33:01 +00005418 for (idx = 0; idx < src_size; ++idx)
5419 {
5420 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5421 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5422
5423 if (src_die->Tag() != dst_die->Tag())
5424 {
5425 if (log)
5426 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)",
5427 src_class_die->GetOffset(),
5428 dst_class_die->GetOffset(),
5429 src_die->GetOffset(),
5430 DW_TAG_value_to_name(src_die->Tag()),
5431 dst_die->GetOffset(),
5432 DW_TAG_value_to_name(src_die->Tag()));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005433 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005434 }
5435
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005436 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton4116e932012-05-15 02:33:01 +00005437 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5438
5439 // Make sure the names match
5440 if (src_name == dst_name || (strcmp (src_name, dst_name) == 0))
5441 continue;
5442
5443 if (log)
5444 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)",
5445 src_class_die->GetOffset(),
5446 dst_class_die->GetOffset(),
5447 src_die->GetOffset(),
5448 src_name,
5449 dst_die->GetOffset(),
5450 dst_name);
5451
Sean Callanan2367f8a2013-02-26 01:12:25 +00005452 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005453 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005454 }
Greg Clayton4116e932012-05-15 02:33:01 +00005455
Sean Callanan2367f8a2013-02-26 01:12:25 +00005456 // Now do the work of linking the DeclContexts and Types.
5457 if (fast_path)
5458 {
5459 // We can do this quickly. Just run across the tables index-for-index since
5460 // we know each node has matching names and tags.
Greg Clayton4116e932012-05-15 02:33:01 +00005461 for (idx = 0; idx < src_size; ++idx)
5462 {
5463 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5464 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5465
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005466 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Greg Clayton4116e932012-05-15 02:33:01 +00005467 if (src_decl_ctx)
5468 {
5469 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005470 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 +00005471 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5472 }
5473 else
5474 {
5475 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005476 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 +00005477 }
5478
5479 Type *src_child_type = m_die_to_type[src_die];
5480 if (src_child_type)
5481 {
5482 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00005483 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 +00005484 m_die_to_type[dst_die] = src_child_type;
5485 }
5486 else
5487 {
5488 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005489 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());
5490 }
5491 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005492 }
5493 else
5494 {
5495 // We must do this slowly. For each member of the destination, look
5496 // up a member in the source with the same name, check its tag, and
5497 // unique them if everything matches up. Report failures.
Greg Clayton65ec1032012-11-12 21:27:20 +00005498
Sean Callanan2367f8a2013-02-26 01:12:25 +00005499 if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty())
5500 {
5501 src_name_to_die.Sort();
Greg Clayton65ec1032012-11-12 21:27:20 +00005502
Sean Callanan2367f8a2013-02-26 01:12:25 +00005503 for (idx = 0; idx < dst_size; ++idx)
5504 {
5505 const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx);
5506 dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
5507 src_die = src_name_to_die.Find(dst_name, NULL);
5508
5509 if (src_die && (src_die->Tag() == dst_die->Tag()))
5510 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005511 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Sean Callanan2367f8a2013-02-26 01:12:25 +00005512 if (src_decl_ctx)
5513 {
5514 if (log)
5515 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
5516 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5517 }
5518 else
5519 {
5520 if (log)
5521 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());
5522 }
5523
5524 Type *src_child_type = m_die_to_type[src_die];
5525 if (src_child_type)
5526 {
5527 if (log)
5528 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());
5529 m_die_to_type[dst_die] = src_child_type;
5530 }
5531 else
5532 {
5533 if (log)
5534 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());
5535 }
5536 }
5537 else
5538 {
5539 if (log)
5540 log->Printf ("warning: couldn't find a match for 0x%8.8x", dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005541
Sean Callanan2367f8a2013-02-26 01:12:25 +00005542 failures.push_back(dst_die);
5543 }
5544 }
5545 }
5546 }
5547
5548 const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize ();
5549 const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize ();
5550
5551 UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src;
5552
5553 if (src_size_artificial && dst_size_artificial)
5554 {
5555 dst_name_to_die_artificial.Sort();
5556
Greg Clayton65ec1032012-11-12 21:27:20 +00005557 for (idx = 0; idx < src_size_artificial; ++idx)
5558 {
5559 const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx);
5560 src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5561 dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL);
5562
5563 if (dst_die)
5564 {
Greg Clayton65ec1032012-11-12 21:27:20 +00005565 // Both classes have the artificial types, link them
5566 clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die];
5567 if (src_decl_ctx)
5568 {
5569 if (log)
5570 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
5571 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5572 }
5573 else
5574 {
5575 if (log)
5576 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());
5577 }
5578
5579 Type *src_child_type = m_die_to_type[src_die];
5580 if (src_child_type)
5581 {
5582 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00005583 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 +00005584 m_die_to_type[dst_die] = src_child_type;
5585 }
5586 else
5587 {
5588 if (log)
5589 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());
5590 }
5591 }
5592 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005593 }
Greg Clayton65ec1032012-11-12 21:27:20 +00005594
Sean Callanan2367f8a2013-02-26 01:12:25 +00005595 if (dst_size_artificial)
Greg Clayton4116e932012-05-15 02:33:01 +00005596 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005597 for (idx = 0; idx < dst_size_artificial; ++idx)
5598 {
5599 const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx);
5600 dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5601 if (log)
5602 log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial);
5603
5604 failures.push_back(dst_die);
5605 }
Greg Clayton4116e932012-05-15 02:33:01 +00005606 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005607
5608 return (failures.size() != 0);
Greg Clayton4116e932012-05-15 02:33:01 +00005609}
Greg Claytona8022fa2012-04-24 21:22:41 +00005610
5611TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00005612SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005613{
5614 TypeSP type_sp;
5615
Greg Clayton1be10fc2010-09-29 01:12:09 +00005616 if (type_is_new_ptr)
5617 *type_is_new_ptr = false;
Greg Clayton1fba87112012-02-09 20:03:49 +00005618
5619#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5620 static DIEStack g_die_stack;
5621 DIEStack::ScopedPopper scoped_die_logger(g_die_stack);
5622#endif
Greg Clayton1be10fc2010-09-29 01:12:09 +00005623
Sean Callananc7fbf732010-08-06 00:32:49 +00005624 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005625 if (die != NULL)
5626 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005627 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005628 if (log)
Sean Callanan5b26f272012-02-04 08:49:35 +00005629 {
5630 const DWARFDebugInfoEntry *context_die;
5631 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
5632
Greg Clayton5160ce52013-03-27 23:08:40 +00005633 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 +00005634 die->GetOffset(),
5635 context,
5636 context_die->GetOffset(),
Greg Clayton3bffb082011-12-10 02:15:28 +00005637 DW_TAG_value_to_name(die->Tag()),
Greg Clayton1fba87112012-02-09 20:03:49 +00005638 die->GetName(this, dwarf_cu));
5639
5640#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5641 scoped_die_logger.Push (dwarf_cu, die);
Greg Clayton5160ce52013-03-27 23:08:40 +00005642 g_die_stack.LogDIEs(log, this);
Greg Clayton1fba87112012-02-09 20:03:49 +00005643#endif
Sean Callanan5b26f272012-02-04 08:49:35 +00005644 }
Greg Clayton3bffb082011-12-10 02:15:28 +00005645//
Greg Clayton5160ce52013-03-27 23:08:40 +00005646// Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005647// if (log && dwarf_cu)
5648// {
5649// StreamString s;
5650// die->DumpLocation (this, dwarf_cu, s);
Greg Clayton5160ce52013-03-27 23:08:40 +00005651// GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Greg Clayton3bffb082011-12-10 02:15:28 +00005652//
5653// }
Jim Ingham16746d12011-08-25 23:21:43 +00005654
Greg Clayton594e5ed2010-09-27 21:07:38 +00005655 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005656 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00005657 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005658 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005659 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00005660 if (type_is_new_ptr)
5661 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005662
Greg Clayton594e5ed2010-09-27 21:07:38 +00005663 const dw_tag_t tag = die->Tag();
5664
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005665 bool is_forward_declaration = false;
5666 DWARFDebugInfoEntry::Attributes attributes;
5667 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00005668 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00005669 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
Greg Claytonfaac1112013-03-14 18:31:44 +00005670 uint64_t byte_size = 0;
Greg Clayton526e5af2010-11-13 03:52:47 +00005671 Declaration decl;
5672
Greg Clayton4957bf62010-09-30 21:49:03 +00005673 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton1be10fc2010-09-29 01:12:09 +00005674 clang_type_t clang_type = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005675
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005676 dw_attr_t attr;
5677
5678 switch (tag)
5679 {
5680 case DW_TAG_base_type:
5681 case DW_TAG_pointer_type:
5682 case DW_TAG_reference_type:
Sean Callanance8af862012-05-21 23:31:51 +00005683 case DW_TAG_rvalue_reference_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005684 case DW_TAG_typedef:
5685 case DW_TAG_const_type:
5686 case DW_TAG_restrict_type:
5687 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00005688 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005689 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005690 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005691 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005692
Greg Claytond88d7592010-09-15 08:33:30 +00005693 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005694 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005695 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
5696
5697 if (num_attributes > 0)
5698 {
5699 uint32_t i;
5700 for (i=0; i<num_attributes; ++i)
5701 {
5702 attr = attributes.AttributeAtIndex(i);
5703 DWARFFormValue form_value;
5704 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5705 {
5706 switch (attr)
5707 {
5708 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5709 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5710 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5711 case DW_AT_name:
Jim Ingham337030f2011-04-15 23:41:23 +00005712
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005713 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00005714 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
5715 // include the "&"...
5716 if (tag == DW_TAG_reference_type)
5717 {
5718 if (strchr (type_name_cstr, '&') == NULL)
5719 type_name_cstr = NULL;
5720 }
5721 if (type_name_cstr)
5722 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005723 break;
Greg Clayton23f59502012-07-17 03:23:13 +00005724 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005725 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
5726 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
5727 default:
5728 case DW_AT_sibling:
5729 break;
5730 }
5731 }
5732 }
5733 }
5734
Daniel Malead01b2952012-11-29 21:49:15 +00005735 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\") type => 0x%8.8x\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr, encoding_uid);
Greg Claytonc93237c2010-10-01 20:48:32 +00005736
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005737 switch (tag)
5738 {
5739 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00005740 break;
5741
Greg Claytond4436412011-10-28 21:00:00 +00005742 case DW_TAG_unspecified_type:
Greg Clayton7fba2632013-07-01 21:01:52 +00005743 if (strcmp(type_name_cstr, "nullptr_t") == 0 ||
5744 strcmp(type_name_cstr, "decltype(nullptr)") == 0 )
Greg Claytond4436412011-10-28 21:00:00 +00005745 {
5746 resolve_state = Type::eResolveStateFull;
5747 clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr();
5748 break;
5749 }
5750 // Fall through to base type below in case we can handle the type there...
5751
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005752 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00005753 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005754 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
5755 encoding,
5756 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005757 break;
5758
Sean Callanance8af862012-05-21 23:31:51 +00005759 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
5760 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
5761 case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break;
5762 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
5763 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
5764 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
5765 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005766 }
5767
Sean Callanan82587052013-01-03 00:05:56 +00005768 if (clang_type == NULL && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID) && sc.comp_unit != NULL)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005769 {
Sean Callanan82587052013-01-03 00:05:56 +00005770 bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus);
5771
5772 if (translation_unit_is_objc)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005773 {
Sean Callanan82587052013-01-03 00:05:56 +00005774 if (type_name_cstr != NULL)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005775 {
Sean Callanan82587052013-01-03 00:05:56 +00005776 static ConstString g_objc_type_name_id("id");
5777 static ConstString g_objc_type_name_Class("Class");
5778 static ConstString g_objc_type_name_selector("SEL");
5779
5780 if (type_name_const_str == g_objc_type_name_id)
5781 {
5782 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005783 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 +00005784 die->GetOffset(),
5785 DW_TAG_value_to_name(die->Tag()),
5786 die->GetName(this, dwarf_cu));
5787 clang_type = ast.GetBuiltInType_objc_id();
5788 encoding_data_type = Type::eEncodingIsUID;
5789 encoding_uid = LLDB_INVALID_UID;
5790 resolve_state = Type::eResolveStateFull;
Greg Clayton526e5af2010-11-13 03:52:47 +00005791
Sean Callanan82587052013-01-03 00:05:56 +00005792 }
5793 else if (type_name_const_str == g_objc_type_name_Class)
5794 {
5795 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005796 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 +00005797 die->GetOffset(),
5798 DW_TAG_value_to_name(die->Tag()),
5799 die->GetName(this, dwarf_cu));
5800 clang_type = ast.GetBuiltInType_objc_Class();
5801 encoding_data_type = Type::eEncodingIsUID;
5802 encoding_uid = LLDB_INVALID_UID;
5803 resolve_state = Type::eResolveStateFull;
5804 }
5805 else if (type_name_const_str == g_objc_type_name_selector)
5806 {
5807 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005808 GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.",
Sean Callanan82587052013-01-03 00:05:56 +00005809 die->GetOffset(),
5810 DW_TAG_value_to_name(die->Tag()),
5811 die->GetName(this, dwarf_cu));
5812 clang_type = ast.GetBuiltInType_objc_selector();
5813 encoding_data_type = Type::eEncodingIsUID;
5814 encoding_uid = LLDB_INVALID_UID;
5815 resolve_state = Type::eResolveStateFull;
5816 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005817 }
Sean Callanan82587052013-01-03 00:05:56 +00005818 else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005819 {
Sean Callanan82587052013-01-03 00:05:56 +00005820 // Clang sometimes erroneously emits id as objc_object*. In that case we fix up the type to "id".
5821
5822 DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid);
5823
5824 if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type)
5825 {
5826 if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL))
5827 {
5828 if (!strcmp(struct_name, "objc_object"))
5829 {
5830 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005831 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 +00005832 die->GetOffset(),
5833 DW_TAG_value_to_name(die->Tag()),
5834 die->GetName(this, dwarf_cu));
5835 clang_type = ast.GetBuiltInType_objc_id();
5836 encoding_data_type = Type::eEncodingIsUID;
5837 encoding_uid = LLDB_INVALID_UID;
5838 resolve_state = Type::eResolveStateFull;
5839 }
5840 }
5841 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005842 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005843 }
5844 }
5845
Greg Clayton81c22f62011-10-19 18:09:39 +00005846 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005847 this,
5848 type_name_const_str,
5849 byte_size,
5850 NULL,
5851 encoding_uid,
5852 encoding_data_type,
5853 &decl,
5854 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005855 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005856
Greg Clayton594e5ed2010-09-27 21:07:38 +00005857 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005858
5859// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
5860// if (encoding_type != NULL)
5861// {
5862// if (encoding_type != DIE_IS_BEING_PARSED)
5863// type_sp->SetEncodingType(encoding_type);
5864// else
5865// m_indirect_fixups.push_back(type_sp.get());
5866// }
5867 }
5868 break;
5869
5870 case DW_TAG_structure_type:
5871 case DW_TAG_union_type:
5872 case DW_TAG_class_type:
5873 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005874 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005875 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Greg Clayton23f59502012-07-17 03:23:13 +00005876 bool byte_size_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005877
Greg Clayton9e409562010-07-28 02:04:09 +00005878 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00005879 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005880 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00005881 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005882 if (num_attributes > 0)
5883 {
5884 uint32_t i;
5885 for (i=0; i<num_attributes; ++i)
5886 {
5887 attr = attributes.AttributeAtIndex(i);
5888 DWARFFormValue form_value;
5889 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5890 {
5891 switch (attr)
5892 {
Greg Clayton9e409562010-07-28 02:04:09 +00005893 case DW_AT_decl_file:
Greg Claytonc7f03b62012-01-12 04:33:28 +00005894 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
5895 {
5896 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
5897 // point to the compile unit file, so we clear this invalid value
5898 // so that we can still unique types efficiently.
5899 decl.SetFile(FileSpec ("<invalid>", false));
5900 }
5901 else
5902 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
Greg Clayton9e409562010-07-28 02:04:09 +00005903 break;
5904
5905 case DW_AT_decl_line:
5906 decl.SetLine(form_value.Unsigned());
5907 break;
5908
5909 case DW_AT_decl_column:
5910 decl.SetColumn(form_value.Unsigned());
5911 break;
5912
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005913 case DW_AT_name:
5914 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005915 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005916 break;
Greg Clayton9e409562010-07-28 02:04:09 +00005917
5918 case DW_AT_byte_size:
5919 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00005920 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00005921 break;
5922
5923 case DW_AT_accessibility:
5924 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
5925 break;
5926
5927 case DW_AT_declaration:
Greg Clayton1c8ef472013-04-05 23:27:21 +00005928 is_forward_declaration = form_value.Boolean();
Greg Clayton9e409562010-07-28 02:04:09 +00005929 break;
5930
5931 case DW_AT_APPLE_runtime_class:
5932 class_language = (LanguageType)form_value.Signed();
5933 break;
5934
Greg Clayton18774842011-11-29 23:40:34 +00005935 case DW_AT_APPLE_objc_complete_type:
5936 is_complete_objc_class = form_value.Signed();
5937 break;
5938
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005939 case DW_AT_allocated:
5940 case DW_AT_associated:
5941 case DW_AT_data_location:
5942 case DW_AT_description:
5943 case DW_AT_start_scope:
5944 case DW_AT_visibility:
5945 default:
5946 case DW_AT_sibling:
5947 break;
5948 }
5949 }
5950 }
5951 }
5952
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005953 UniqueDWARFASTType unique_ast_entry;
Sean Callanan8e8072d2012-02-07 21:13:38 +00005954
Greg Clayton123edca2012-03-02 00:07:15 +00005955 // Only try and unique the type if it has a name.
5956 if (type_name_const_str &&
5957 GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Sean Callanan8e8072d2012-02-07 21:13:38 +00005958 this,
5959 dwarf_cu,
5960 die,
5961 decl,
5962 byte_size_valid ? byte_size : -1,
5963 unique_ast_entry))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005964 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005965 // We have already parsed this type or from another
5966 // compile unit. GCC loves to use the "one definition
5967 // rule" which can result in multiple definitions
5968 // of the same class over and over in each compile
5969 // unit.
5970 type_sp = unique_ast_entry.m_type_sp;
5971 if (type_sp)
Greg Claytonc615ce42010-11-09 04:42:43 +00005972 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005973 m_die_to_type[die] = type_sp.get();
5974 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005975 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005976 }
5977
Daniel Malead01b2952012-11-29 21:49:15 +00005978 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 +00005979
5980 int tag_decl_kind = -1;
5981 AccessType default_accessibility = eAccessNone;
5982 if (tag == DW_TAG_structure_type)
5983 {
5984 tag_decl_kind = clang::TTK_Struct;
5985 default_accessibility = eAccessPublic;
5986 }
5987 else if (tag == DW_TAG_union_type)
5988 {
5989 tag_decl_kind = clang::TTK_Union;
5990 default_accessibility = eAccessPublic;
5991 }
5992 else if (tag == DW_TAG_class_type)
5993 {
5994 tag_decl_kind = clang::TTK_Class;
5995 default_accessibility = eAccessPrivate;
5996 }
Greg Clayton3a5f29a2011-11-30 02:48:28 +00005997
5998 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
5999 die->HasChildren() == false &&
6000 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
6001 {
6002 // Work around an issue with clang at the moment where
6003 // forward declarations for objective C classes are emitted
6004 // as:
6005 // DW_TAG_structure_type [2]
6006 // DW_AT_name( "ForwardObjcClass" )
6007 // DW_AT_byte_size( 0x00 )
6008 // DW_AT_decl_file( "..." )
6009 // DW_AT_decl_line( 1 )
6010 //
6011 // Note that there is no DW_AT_declaration and there are
6012 // no children, and the byte size is zero.
6013 is_forward_declaration = true;
6014 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006015
Sean Callanan7457f8d2012-04-25 01:03:57 +00006016 if (class_language == eLanguageTypeObjC ||
6017 class_language == eLanguageTypeObjC_plus_plus)
Greg Clayton18774842011-11-29 23:40:34 +00006018 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00006019 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
Greg Clayton901c5ca2011-12-03 04:40:03 +00006020 {
6021 // We have a valid eSymbolTypeObjCClass class symbol whose
6022 // name matches the current objective C class that we
6023 // are trying to find and this DIE isn't the complete
6024 // definition (we checked is_complete_objc_class above and
6025 // know it is false), so the real definition is in here somewhere
Greg Claytonc7f03b62012-01-12 04:33:28 +00006026 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006027
Greg Clayton1f746072012-08-29 21:13:06 +00006028 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton901c5ca2011-12-03 04:40:03 +00006029 {
6030 // We weren't able to find a full declaration in
6031 // this DWARF, see if we have a declaration anywhere
6032 // else...
Greg Claytonc7f03b62012-01-12 04:33:28 +00006033 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00006034 }
6035
6036 if (type_sp)
6037 {
6038 if (log)
6039 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006040 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00006041 "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 +00006042 this,
6043 die->GetOffset(),
6044 DW_TAG_value_to_name(tag),
6045 type_name_cstr,
6046 type_sp->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00006047 }
6048
6049 // We found a real definition for this type elsewhere
6050 // so lets use it and cache the fact that we found
6051 // a complete type for this die
6052 m_die_to_type[die] = type_sp.get();
6053 return type_sp;
6054 }
6055 }
6056 }
6057
6058
6059 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006060 {
6061 // We have a forward declaration to a type and we need
6062 // to try and find a full declaration. We look in the
6063 // current type index just in case we have a forward
6064 // declaration followed by an actual declarations in the
6065 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00006066 if (log)
6067 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006068 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00006069 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
6070 this,
6071 die->GetOffset(),
6072 DW_TAG_value_to_name(tag),
6073 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00006074 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006075
Greg Claytona8022fa2012-04-24 21:22:41 +00006076 DWARFDeclContext die_decl_ctx;
6077 die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx);
6078
6079 //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
6080 type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006081
Greg Clayton1f746072012-08-29 21:13:06 +00006082 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton4272cc72011-02-02 02:24:04 +00006083 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006084 // We weren't able to find a full declaration in
6085 // this DWARF, see if we have a declaration anywhere
6086 // else...
Greg Claytona8022fa2012-04-24 21:22:41 +00006087 type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton4272cc72011-02-02 02:24:04 +00006088 }
6089
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006090 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00006091 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00006092 if (log)
6093 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006094 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00006095 "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 +00006096 this,
6097 die->GetOffset(),
6098 DW_TAG_value_to_name(tag),
6099 type_name_cstr,
6100 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00006101 }
6102
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006103 // We found a real definition for this type elsewhere
6104 // so lets use it and cache the fact that we found
6105 // a complete type for this die
6106 m_die_to_type[die] = type_sp.get();
6107 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00006108 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006109 }
6110 assert (tag_decl_kind != -1);
6111 bool clang_type_was_created = false;
6112 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
6113 if (clang_type == NULL)
6114 {
Sean Callanan4d04c6a2012-02-09 22:54:11 +00006115 const DWARFDebugInfoEntry *decl_ctx_die;
6116
6117 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton55561e92011-10-26 03:31:36 +00006118 if (accessibility == eAccessNone && decl_ctx)
6119 {
6120 // Check the decl context that contains this class/struct/union.
6121 // If it is a class we must give it an accessability.
6122 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
6123 if (DeclKindIsCXXClass (containing_decl_kind))
6124 accessibility = default_accessibility;
6125 }
6126
Greg Claytonc4ffd662013-03-08 01:37:30 +00006127 ClangASTMetadata metadata;
6128 metadata.SetUserID(MakeUserID(die->GetOffset()));
6129 metadata.SetIsDynamicCXXType(ClassOrStructIsVirtual (dwarf_cu, die));
6130
Greg Claytonf0705c82011-10-22 03:33:13 +00006131 if (type_name_cstr && strchr (type_name_cstr, '<'))
6132 {
6133 ClangASTContext::TemplateParameterInfos template_param_infos;
6134 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
6135 {
6136 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00006137 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00006138 type_name_cstr,
6139 tag_decl_kind,
6140 template_param_infos);
6141
6142 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
6143 class_template_decl,
6144 tag_decl_kind,
6145 template_param_infos);
6146 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
6147 clang_type_was_created = true;
Sean Callanan60217122012-04-13 00:10:03 +00006148
Greg Claytond0029442013-03-27 01:48:02 +00006149 GetClangASTContext().SetMetadata (class_template_decl, metadata);
6150 GetClangASTContext().SetMetadata (class_specialization_decl, metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00006151 }
6152 }
6153
6154 if (!clang_type_was_created)
6155 {
6156 clang_type_was_created = true;
Greg Clayton55561e92011-10-26 03:31:36 +00006157 clang_type = ast.CreateRecordType (decl_ctx,
6158 accessibility,
6159 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00006160 tag_decl_kind,
Sean Callanan60217122012-04-13 00:10:03 +00006161 class_language,
Jim Ingham379397632012-10-27 02:54:13 +00006162 &metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00006163 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006164 }
6165
6166 // Store a forward declaration to this class type in case any
6167 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00006168 // types for function prototypes.
6169 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00006170 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006171 this,
6172 type_name_const_str,
6173 byte_size,
6174 NULL,
6175 LLDB_INVALID_UID,
6176 Type::eEncodingIsUID,
6177 &decl,
6178 clang_type,
6179 Type::eResolveStateForward));
Sean Callanan72772842012-02-22 23:57:45 +00006180
6181 type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006182
6183
6184 // Add our type to the unique type map so we don't
6185 // end up creating many copies of the same type over
6186 // and over in the ASTContext for our module
6187 unique_ast_entry.m_type_sp = type_sp;
Greg Clayton36909642011-03-15 04:38:20 +00006188 unique_ast_entry.m_symfile = this;
6189 unique_ast_entry.m_cu = dwarf_cu;
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006190 unique_ast_entry.m_die = die;
6191 unique_ast_entry.m_declaration = decl;
Sean Callanan59700592012-02-13 22:30:16 +00006192 unique_ast_entry.m_byte_size = byte_size;
Greg Claytone576ab22011-02-15 00:19:15 +00006193 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
6194 unique_ast_entry);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006195
Sean Callanan12014a02011-12-08 23:45:45 +00006196 if (!is_forward_declaration)
Greg Clayton219cf312012-03-30 00:51:13 +00006197 {
6198 // Always start the definition for a class type so that
6199 // if the class has child classes or types that require
6200 // the class to be created for use as their decl contexts
6201 // the class will be ready to accept these child definitions.
Sean Callanan12014a02011-12-08 23:45:45 +00006202 if (die->HasChildren() == false)
6203 {
6204 // No children for this struct/union/class, lets finish it
6205 ast.StartTagDeclarationDefinition (clang_type);
6206 ast.CompleteTagDeclarationDefinition (clang_type);
Sean Callanan433cd222012-10-19 01:37:25 +00006207
6208 if (tag == DW_TAG_structure_type) // this only applies in C
6209 {
6210 clang::QualType qual_type = clang::QualType::getFromOpaquePtr (clang_type);
6211 const clang::RecordType *record_type = qual_type->getAs<clang::RecordType> ();
6212
6213 if (record_type)
6214 {
6215 clang::RecordDecl *record_decl = record_type->getDecl();
6216
6217 if (record_decl)
6218 {
6219 LayoutInfo layout_info;
6220
6221 layout_info.alignment = 0;
6222 layout_info.bit_size = 0;
6223
6224 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
6225 }
6226 }
6227 }
Sean Callanan12014a02011-12-08 23:45:45 +00006228 }
6229 else if (clang_type_was_created)
6230 {
Greg Clayton219cf312012-03-30 00:51:13 +00006231 // Start the definition if the class is not objective C since
6232 // the underlying decls respond to isCompleteDefinition(). Objective
6233 // C decls dont' respond to isCompleteDefinition() so we can't
6234 // start the declaration definition right away. For C++ classs/union/structs
6235 // we want to start the definition in case the class is needed as the
6236 // declaration context for a contained class or type without the need
6237 // to complete that type..
6238
Sean Callanan7457f8d2012-04-25 01:03:57 +00006239 if (class_language != eLanguageTypeObjC &&
6240 class_language != eLanguageTypeObjC_plus_plus)
Greg Clayton219cf312012-03-30 00:51:13 +00006241 ast.StartTagDeclarationDefinition (clang_type);
6242
Sean Callanan12014a02011-12-08 23:45:45 +00006243 // Leave this as a forward declaration until we need
6244 // to know the details of the type. lldb_private::Type
6245 // will automatically call the SymbolFile virtual function
6246 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
6247 // When the definition needs to be defined.
6248 m_forward_decl_die_to_clang_type[die] = clang_type;
6249 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
6250 ClangASTContext::SetHasExternalStorage (clang_type, true);
6251 }
Greg Claytonc615ce42010-11-09 04:42:43 +00006252 }
Greg Claytoncab36a32011-12-08 05:16:30 +00006253
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006254 }
6255 break;
6256
6257 case DW_TAG_enumeration_type:
6258 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006259 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006260 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006261
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006262 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006263
Greg Claytond88d7592010-09-15 08:33:30 +00006264 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006265 if (num_attributes > 0)
6266 {
6267 uint32_t i;
6268
6269 for (i=0; i<num_attributes; ++i)
6270 {
6271 attr = attributes.AttributeAtIndex(i);
6272 DWARFFormValue form_value;
6273 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6274 {
6275 switch (attr)
6276 {
Greg Clayton7a345282010-11-09 23:46:37 +00006277 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6278 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6279 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006280 case DW_AT_name:
6281 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006282 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006283 break;
Greg Clayton7a345282010-11-09 23:46:37 +00006284 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006285 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
6286 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006287 case DW_AT_declaration: break; //is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006288 case DW_AT_allocated:
6289 case DW_AT_associated:
6290 case DW_AT_bit_stride:
6291 case DW_AT_byte_stride:
6292 case DW_AT_data_location:
6293 case DW_AT_description:
6294 case DW_AT_start_scope:
6295 case DW_AT_visibility:
6296 case DW_AT_specification:
6297 case DW_AT_abstract_origin:
6298 case DW_AT_sibling:
6299 break;
6300 }
6301 }
6302 }
6303
Daniel Malead01b2952012-11-29 21:49:15 +00006304 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 +00006305
Greg Clayton1be10fc2010-09-29 01:12:09 +00006306 clang_type_t enumerator_clang_type = NULL;
6307 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
6308 if (clang_type == NULL)
6309 {
Greg Clayton5d14fc02013-03-06 06:23:54 +00006310 if (encoding_uid != DW_INVALID_OFFSET)
6311 {
6312 Type *enumerator_type = ResolveTypeUID(encoding_uid);
6313 if (enumerator_type)
6314 enumerator_clang_type = enumerator_type->GetClangFullType();
6315 }
6316
6317 if (enumerator_clang_type == NULL)
6318 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
6319 DW_ATE_signed,
6320 byte_size * 8);
6321
Greg Claytonca512b32011-01-14 04:54:56 +00006322 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00006323 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00006324 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006325 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00006326 }
6327 else
6328 {
6329 enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00006330 }
6331
Greg Claytona2721472011-06-25 00:44:06 +00006332 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
6333
Greg Clayton81c22f62011-10-19 18:09:39 +00006334 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006335 this,
6336 type_name_const_str,
6337 byte_size,
6338 NULL,
6339 encoding_uid,
6340 Type::eEncodingIsUID,
6341 &decl,
6342 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006343 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006344
Greg Clayton6beaaa62011-01-17 03:46:26 +00006345 ast.StartTagDeclarationDefinition (clang_type);
6346 if (die->HasChildren())
6347 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006348 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00006349 bool is_signed = false;
Greg Clayton5d14fc02013-03-06 06:23:54 +00006350 ast.IsIntegerType(enumerator_clang_type, is_signed);
Greg Clayton3e067532013-03-05 23:54:39 +00006351 ParseChildEnumerators(cu_sc, clang_type, is_signed, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00006352 }
6353 ast.CompleteTagDeclarationDefinition (clang_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006354 }
6355 }
6356 break;
6357
Jim Inghamb0be4422010-08-12 01:20:14 +00006358 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006359 case DW_TAG_subprogram:
6360 case DW_TAG_subroutine_type:
6361 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006362 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006363 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006364
Greg Clayton23f59502012-07-17 03:23:13 +00006365 //const char *mangled = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006366 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00006367 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006368 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00006369 bool is_static = false;
6370 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00006371 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00006372 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00006373 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
6374 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Jim Ingham379397632012-10-27 02:54:13 +00006375 dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00006376
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006377 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00006378 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006379
6380
Greg Claytond88d7592010-09-15 08:33:30 +00006381 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006382 if (num_attributes > 0)
6383 {
6384 uint32_t i;
6385 for (i=0; i<num_attributes; ++i)
6386 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006387 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006388 DWARFFormValue form_value;
6389 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6390 {
6391 switch (attr)
6392 {
6393 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6394 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6395 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6396 case DW_AT_name:
6397 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006398 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006399 break;
6400
Greg Clayton71415542012-12-08 00:24:40 +00006401 case DW_AT_linkage_name:
Greg Clayton23f59502012-07-17 03:23:13 +00006402 case DW_AT_MIPS_linkage_name: break; // mangled = form_value.AsCString(&get_debug_str_data()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006403 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00006404 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006405 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
6406 case DW_AT_inline: is_inline = form_value.Boolean(); break;
6407 case DW_AT_virtuality: is_virtual = form_value.Boolean(); break;
6408 case DW_AT_explicit: is_explicit = form_value.Boolean(); break;
6409 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Sean Callanandbb58392011-11-02 01:38:59 +00006410
Greg Claytonf51de672010-10-01 02:31:07 +00006411
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006412 case DW_AT_external:
6413 if (form_value.Unsigned())
6414 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00006415 if (storage == clang::SC_None)
6416 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006417 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00006418 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006419 }
6420 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006421
Greg Clayton72da3972011-08-16 18:40:23 +00006422 case DW_AT_specification:
6423 specification_die_offset = form_value.Reference(dwarf_cu);
6424 break;
6425
6426 case DW_AT_abstract_origin:
6427 abstract_origin_die_offset = form_value.Reference(dwarf_cu);
6428 break;
6429
Jim Ingham379397632012-10-27 02:54:13 +00006430 case DW_AT_object_pointer:
6431 object_pointer_die_offset = form_value.Reference(dwarf_cu);
6432 break;
6433
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006434 case DW_AT_allocated:
6435 case DW_AT_associated:
6436 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006437 case DW_AT_calling_convention:
6438 case DW_AT_data_location:
6439 case DW_AT_elemental:
6440 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006441 case DW_AT_frame_base:
6442 case DW_AT_high_pc:
6443 case DW_AT_low_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006444 case DW_AT_prototyped:
6445 case DW_AT_pure:
6446 case DW_AT_ranges:
6447 case DW_AT_recursive:
6448 case DW_AT_return_addr:
6449 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006450 case DW_AT_start_scope:
6451 case DW_AT_static_link:
6452 case DW_AT_trampoline:
6453 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006454 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006455 case DW_AT_description:
6456 case DW_AT_sibling:
6457 break;
6458 }
6459 }
6460 }
Greg Clayton24739922010-10-13 03:15:28 +00006461 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006462
Jim Ingham379397632012-10-27 02:54:13 +00006463 std::string object_pointer_name;
6464 if (object_pointer_die_offset != DW_INVALID_OFFSET)
6465 {
6466 // Get the name from the object pointer die
6467 StreamString s;
6468 if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s))
6469 {
6470 object_pointer_name.assign(s.GetData());
6471 }
6472 }
6473
Daniel Malead01b2952012-11-29 21:49:15 +00006474 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 +00006475
Greg Clayton24739922010-10-13 03:15:28 +00006476 clang_type_t return_clang_type = NULL;
6477 Type *func_type = NULL;
6478
6479 if (type_die_offset != DW_INVALID_OFFSET)
6480 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00006481
Greg Clayton24739922010-10-13 03:15:28 +00006482 if (func_type)
Greg Clayton42ce2f32011-12-12 21:50:19 +00006483 return_clang_type = func_type->GetClangForwardType();
Greg Clayton24739922010-10-13 03:15:28 +00006484 else
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006485 return_clang_type = ast.GetBuiltInType_void();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006486
Greg Claytonf51de672010-10-01 02:31:07 +00006487
Greg Clayton24739922010-10-13 03:15:28 +00006488 std::vector<clang_type_t> function_param_types;
6489 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006490
Greg Clayton24739922010-10-13 03:15:28 +00006491 // Parse the function children for the parameters
Sean Callanan763d72a2011-08-02 22:21:50 +00006492
Greg Claytoncb5860a2011-10-13 23:49:28 +00006493 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
6494 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00006495 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
6496
Greg Claytonf0705c82011-10-22 03:33:13 +00006497 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00006498 // Start off static. This will be set to false in ParseChildParameters(...)
6499 // if we find a "this" paramters as the first parameter
6500 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00006501 is_static = true;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006502 ClangASTContext::TemplateParameterInfos template_param_infos;
6503
Greg Clayton24739922010-10-13 03:15:28 +00006504 if (die->HasChildren())
6505 {
Greg Clayton0fffff52010-09-24 05:15:53 +00006506 bool skip_artificial = true;
Jim Ingham379397632012-10-27 02:54:13 +00006507 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00006508 containing_decl_ctx,
Jim Ingham379397632012-10-27 02:54:13 +00006509 dwarf_cu,
6510 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00006511 skip_artificial,
6512 is_static,
Jim Ingham379397632012-10-27 02:54:13 +00006513 type_list,
6514 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00006515 function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006516 type_quals,
6517 template_param_infos);
Greg Clayton24739922010-10-13 03:15:28 +00006518 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006519
Greg Clayton24739922010-10-13 03:15:28 +00006520 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006521 clang_type = ast.CreateFunctionType (return_clang_type,
Greg Clayton9cb25c42012-10-30 17:02:18 +00006522 function_param_types.data(),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006523 function_param_types.size(),
6524 is_variadic,
6525 type_quals);
6526
Sean Callanande9ce872013-05-09 23:13:13 +00006527 bool ignore_containing_context = false;
6528
Greg Clayton24739922010-10-13 03:15:28 +00006529 if (type_name_cstr)
6530 {
6531 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00006532 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006533 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00006534 ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true);
6535 if (objc_method.IsValid(true))
Greg Clayton0fffff52010-09-24 05:15:53 +00006536 {
Greg Clayton24739922010-10-13 03:15:28 +00006537 SymbolContext empty_sc;
6538 clang_type_t class_opaque_type = NULL;
Greg Clayton1b3815c2013-01-30 00:18:29 +00006539 ConstString class_name(objc_method.GetClassName());
Greg Clayton7c810422012-01-18 23:40:49 +00006540 if (class_name)
Greg Clayton0fffff52010-09-24 05:15:53 +00006541 {
Greg Clayton24739922010-10-13 03:15:28 +00006542 TypeList types;
Greg Clayton278a16b2012-01-19 00:52:59 +00006543 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
Greg Claytonc7f03b62012-01-12 04:33:28 +00006544
6545 if (complete_objc_class_type_sp)
Greg Clayton0fffff52010-09-24 05:15:53 +00006546 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00006547 clang_type_t type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
6548 if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
6549 class_opaque_type = type_clang_forward_type;
Greg Clayton0fffff52010-09-24 05:15:53 +00006550 }
Greg Clayton24739922010-10-13 03:15:28 +00006551 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006552
Greg Clayton24739922010-10-13 03:15:28 +00006553 if (class_opaque_type)
6554 {
6555 // If accessibility isn't set to anything valid, assume public for
6556 // now...
6557 if (accessibility == eAccessNone)
6558 accessibility = eAccessPublic;
6559
Sean Callanan464a5b52012-10-04 22:06:29 +00006560 clang::ObjCMethodDecl *objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
6561 type_name_cstr,
6562 clang_type,
Greg Clayton1bbcc032013-03-08 02:42:06 +00006563 accessibility,
6564 is_artificial);
Greg Clayton24739922010-10-13 03:15:28 +00006565 type_handled = objc_method_decl != NULL;
Sean Callanan464a5b52012-10-04 22:06:29 +00006566 if (type_handled)
6567 {
6568 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Claytond0029442013-03-27 01:48:02 +00006569 GetClangASTContext().SetMetadataAsUserID (objc_method_decl, MakeUserID(die->GetOffset()));
Sean Callanan464a5b52012-10-04 22:06:29 +00006570 }
Sean Callananc3a1d562013-02-06 23:21:59 +00006571 else
6572 {
Jason Molendac1a65832013-03-07 22:44:42 +00006573 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 +00006574 die->GetOffset(),
6575 tag,
6576 DW_TAG_value_to_name(tag));
6577 }
Greg Clayton24739922010-10-13 03:15:28 +00006578 }
6579 }
Greg Clayton5113dc82011-08-12 06:47:54 +00006580 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00006581 {
6582 // Look at the parent of this DIE and see if is is
6583 // a class or struct and see if this is actually a
6584 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00006585 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00006586 if (class_type)
6587 {
Greg Clayton4116e932012-05-15 02:33:01 +00006588 if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset()))
6589 {
6590 // We uniqued the parent class of this function to another class
6591 // so we now need to associate all dies under "decl_ctx_die" to
6592 // DIEs in the DIE for "class_type"...
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006593 SymbolFileDWARF *class_symfile = NULL;
Greg Clayton4116e932012-05-15 02:33:01 +00006594 DWARFCompileUnitSP class_type_cu_sp;
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006595 const DWARFDebugInfoEntry *class_type_die = NULL;
Sean Callanan2367f8a2013-02-26 01:12:25 +00006596
6597 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
6598 if (debug_map_symfile)
6599 {
6600 class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID()));
6601 class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6602 }
6603 else
6604 {
6605 class_symfile = this;
6606 class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6607 }
Greg Clayton4116e932012-05-15 02:33:01 +00006608 if (class_type_die)
6609 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006610 llvm::SmallVector<const DWARFDebugInfoEntry *, 0> failures;
6611
6612 CopyUniqueClassMethodTypes (class_symfile,
6613 class_type,
6614 class_type_cu_sp.get(),
6615 class_type_die,
6616 dwarf_cu,
6617 decl_ctx_die,
6618 failures);
6619
6620 // FIXME do something with these failures that's smarter than
6621 // just dropping them on the ground. Unfortunately classes don't
6622 // like having stuff added to them after their definitions are
6623 // complete...
6624
6625 type_ptr = m_die_to_type[die];
6626 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton4116e932012-05-15 02:33:01 +00006627 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006628 type_sp = type_ptr->shared_from_this();
6629 break;
Greg Clayton4116e932012-05-15 02:33:01 +00006630 }
6631 }
6632 }
6633
Greg Clayton72da3972011-08-16 18:40:23 +00006634 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00006635 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006636 // We have a specification which we are going to base our function
6637 // prototype off of, so we need this type to be completed so that the
6638 // m_die_to_decl_ctx for the method in the specification has a valid
6639 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006640 class_type->GetClangForwardType();
Greg Clayton72da3972011-08-16 18:40:23 +00006641 // If we have a specification, then the function type should have been
6642 // made with the specification and not with this die.
6643 DWARFCompileUnitSP spec_cu_sp;
6644 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006645 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006646 if (spec_clang_decl_ctx)
6647 {
6648 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
6649 }
6650 else
Jim Inghamc1663042011-09-29 22:12:35 +00006651 {
Daniel Malead01b2952012-11-29 21:49:15 +00006652 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8x) has no decl\n",
Greg Claytone38a5ed2012-01-05 03:57:59 +00006653 MakeUserID(die->GetOffset()),
6654 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006655 }
Greg Clayton72da3972011-08-16 18:40:23 +00006656 type_handled = true;
6657 }
6658 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
6659 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006660 // We have a specification which we are going to base our function
6661 // prototype off of, so we need this type to be completed so that the
6662 // m_die_to_decl_ctx for the method in the abstract origin has a valid
6663 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006664 class_type->GetClangForwardType();
Greg Clayton5cf58b92011-10-05 22:22:08 +00006665
Greg Clayton72da3972011-08-16 18:40:23 +00006666 DWARFCompileUnitSP abs_cu_sp;
6667 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006668 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006669 if (abs_clang_decl_ctx)
6670 {
6671 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
6672 }
6673 else
Jim Inghamc1663042011-09-29 22:12:35 +00006674 {
Daniel Malead01b2952012-11-29 21:49:15 +00006675 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 +00006676 MakeUserID(die->GetOffset()),
6677 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006678 }
Greg Clayton72da3972011-08-16 18:40:23 +00006679 type_handled = true;
6680 }
6681 else
6682 {
6683 clang_type_t class_opaque_type = class_type->GetClangForwardType();
6684 if (ClangASTContext::IsCXXClassType (class_opaque_type))
Greg Clayton931180e2011-01-27 06:44:37 +00006685 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006686 if (ClangASTContext::IsBeingDefined (class_opaque_type))
Greg Clayton72da3972011-08-16 18:40:23 +00006687 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006688 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
6689 // in the DWARF for C++ methods... Default to public for now...
6690 if (accessibility == eAccessNone)
6691 accessibility = eAccessPublic;
6692
6693 if (!is_static && !die->HasChildren())
6694 {
6695 // We have a C++ member function with no children (this pointer!)
6696 // and clang will get mad if we try and make a function that isn't
6697 // well formed in the DWARF, so we will just skip it...
6698 type_handled = true;
6699 }
6700 else
6701 {
6702 clang::CXXMethodDecl *cxx_method_decl;
6703 // REMOVE THE CRASH DESCRIPTION BELOW
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00006704 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 +00006705 type_name_cstr,
6706 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00006707 MakeUserID(die->GetOffset()),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00006708 m_obj_file->GetFileSpec().GetPath().c_str());
Greg Clayton20568dd2011-10-13 23:13:20 +00006709
Sean Callananc1b732d2011-11-01 18:07:13 +00006710 const bool is_attr_used = false;
6711
Greg Clayton20568dd2011-10-13 23:13:20 +00006712 cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type,
6713 type_name_cstr,
6714 clang_type,
6715 accessibility,
6716 is_virtual,
6717 is_static,
6718 is_inline,
Sean Callananc1b732d2011-11-01 18:07:13 +00006719 is_explicit,
Sean Callanandbb58392011-11-02 01:38:59 +00006720 is_attr_used,
6721 is_artificial);
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006722
Greg Clayton20568dd2011-10-13 23:13:20 +00006723 type_handled = cxx_method_decl != NULL;
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006724
6725 if (type_handled)
Jim Ingham379397632012-10-27 02:54:13 +00006726 {
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006727 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
6728
6729 Host::SetCrashDescription (NULL);
6730
6731
6732 ClangASTMetadata metadata;
6733 metadata.SetUserID(MakeUserID(die->GetOffset()));
6734
6735 if (!object_pointer_name.empty())
6736 {
6737 metadata.SetObjectPtrName(object_pointer_name.c_str());
6738 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006739 log->Printf ("Setting object pointer name: %s on method object %p.\n",
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006740 object_pointer_name.c_str(),
Greg Claytond0029442013-03-27 01:48:02 +00006741 cxx_method_decl);
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006742 }
Greg Claytond0029442013-03-27 01:48:02 +00006743 GetClangASTContext().SetMetadata (cxx_method_decl, metadata);
Jim Ingham379397632012-10-27 02:54:13 +00006744 }
Sean Callananb0640dc2013-04-09 23:22:08 +00006745 else
6746 {
Sean Callanande9ce872013-05-09 23:13:13 +00006747 ignore_containing_context = true;
Sean Callananb0640dc2013-04-09 23:22:08 +00006748 }
Greg Clayton20568dd2011-10-13 23:13:20 +00006749 }
Greg Clayton72da3972011-08-16 18:40:23 +00006750 }
6751 else
6752 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006753 // We were asked to parse the type for a method in a class, yet the
6754 // class hasn't been asked to complete itself through the
6755 // clang::ExternalASTSource protocol, so we need to just have the
6756 // class complete itself and do things the right way, then our
6757 // DIE should then have an entry in the m_die_to_type map. First
6758 // we need to modify the m_die_to_type so it doesn't think we are
6759 // trying to parse this DIE anymore...
6760 m_die_to_type[die] = NULL;
6761
6762 // Now we get the full type to force our class type to complete itself
6763 // using the clang::ExternalASTSource protocol which will parse all
6764 // base classes and all methods (including the method for this DIE).
6765 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00006766
Greg Clayton20568dd2011-10-13 23:13:20 +00006767 // The type for this DIE should have been filled in the function call above
6768 type_ptr = m_die_to_type[die];
Greg Claytone5476db2012-06-01 20:32:35 +00006769 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton20568dd2011-10-13 23:13:20 +00006770 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006771 type_sp = type_ptr->shared_from_this();
Greg Clayton20568dd2011-10-13 23:13:20 +00006772 break;
6773 }
Sean Callanan02eee4d2012-04-12 23:10:00 +00006774
6775 // FIXME This is fixing some even uglier behavior but we really need to
6776 // uniq the methods of each class as well as the class itself.
6777 // <rdar://problem/11240464>
6778 type_handled = true;
Greg Clayton72da3972011-08-16 18:40:23 +00006779 }
Greg Clayton931180e2011-01-27 06:44:37 +00006780 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006781 }
6782 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006783 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006784 }
Greg Clayton24739922010-10-13 03:15:28 +00006785
6786 if (!type_handled)
6787 {
6788 // We just have a function that isn't part of a class
Sean Callanande9ce872013-05-09 23:13:13 +00006789 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (ignore_containing_context ? GetClangASTContext().GetTranslationUnitDecl() : containing_decl_ctx,
Greg Clayton147e1fa2011-10-14 22:47:18 +00006790 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006791 clang_type,
6792 storage,
6793 is_inline);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006794
6795// if (template_param_infos.GetSize() > 0)
6796// {
6797// clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
6798// function_decl,
6799// type_name_cstr,
6800// template_param_infos);
6801//
6802// ast.CreateFunctionTemplateSpecializationInfo (function_decl,
6803// func_template_decl,
6804// template_param_infos);
6805// }
Greg Clayton24739922010-10-13 03:15:28 +00006806 // Add the decl to our DIE to decl context map
6807 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00006808 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00006809 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006810 ast.SetFunctionParameters (function_decl,
6811 &function_param_decls.front(),
6812 function_param_decls.size());
Sean Callanan60217122012-04-13 00:10:03 +00006813
Jim Ingham379397632012-10-27 02:54:13 +00006814 ClangASTMetadata metadata;
6815 metadata.SetUserID(MakeUserID(die->GetOffset()));
6816
6817 if (!object_pointer_name.empty())
6818 {
6819 metadata.SetObjectPtrName(object_pointer_name.c_str());
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006820 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006821 log->Printf ("Setting object pointer name: %s on function object %p.",
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006822 object_pointer_name.c_str(),
Greg Claytond0029442013-03-27 01:48:02 +00006823 function_decl);
Jim Ingham379397632012-10-27 02:54:13 +00006824 }
Greg Claytond0029442013-03-27 01:48:02 +00006825 GetClangASTContext().SetMetadata (function_decl, metadata);
Greg Clayton24739922010-10-13 03:15:28 +00006826 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006827 }
Greg Clayton81c22f62011-10-19 18:09:39 +00006828 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006829 this,
6830 type_name_const_str,
6831 0,
6832 NULL,
6833 LLDB_INVALID_UID,
6834 Type::eEncodingIsUID,
6835 &decl,
6836 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006837 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00006838 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006839 }
6840 break;
6841
6842 case DW_TAG_array_type:
6843 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006844 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006845 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006846
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006847 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006848 int64_t first_index = 0;
6849 uint32_t byte_stride = 0;
6850 uint32_t bit_stride = 0;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006851 bool is_vector = false;
Greg Claytond88d7592010-09-15 08:33:30 +00006852 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006853
6854 if (num_attributes > 0)
6855 {
6856 uint32_t i;
6857 for (i=0; i<num_attributes; ++i)
6858 {
6859 attr = attributes.AttributeAtIndex(i);
6860 DWARFFormValue form_value;
6861 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6862 {
6863 switch (attr)
6864 {
6865 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6866 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6867 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6868 case DW_AT_name:
6869 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006870 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006871 break;
6872
6873 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006874 case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006875 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
6876 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006877 case DW_AT_GNU_vector: is_vector = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006878 case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006879 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006880 case DW_AT_allocated:
6881 case DW_AT_associated:
6882 case DW_AT_data_location:
6883 case DW_AT_description:
6884 case DW_AT_ordering:
6885 case DW_AT_start_scope:
6886 case DW_AT_visibility:
6887 case DW_AT_specification:
6888 case DW_AT_abstract_origin:
6889 case DW_AT_sibling:
6890 break;
6891 }
6892 }
6893 }
6894
Daniel Malead01b2952012-11-29 21:49:15 +00006895 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 +00006896
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006897 Type *element_type = ResolveTypeUID(type_die_offset);
6898
6899 if (element_type)
6900 {
6901 std::vector<uint64_t> element_orders;
6902 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
6903 if (byte_stride == 0 && bit_stride == 0)
6904 byte_stride = element_type->GetByteSize();
Greg Clayton42ce2f32011-12-12 21:50:19 +00006905 clang_type_t array_element_type = element_type->GetClangForwardType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006906 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
6907 uint64_t num_elements = 0;
6908 std::vector<uint64_t>::const_reverse_iterator pos;
6909 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
6910 for (pos = element_orders.rbegin(); pos != end; ++pos)
6911 {
6912 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006913 clang_type = ast.CreateArrayType (array_element_type,
Greg Clayton1c8ef472013-04-05 23:27:21 +00006914 num_elements,
6915 is_vector);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006916 array_element_type = clang_type;
Greg Clayton4ef877f2012-12-06 02:33:54 +00006917 array_element_bit_stride = num_elements ? array_element_bit_stride * num_elements : array_element_bit_stride;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006918 }
6919 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00006920 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006921 this,
6922 empty_name,
6923 array_element_bit_stride / 8,
6924 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00006925 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006926 Type::eEncodingIsUID,
6927 &decl,
6928 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006929 Type::eResolveStateFull));
6930 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006931 }
6932 }
6933 }
6934 break;
6935
Greg Clayton9b81a312010-06-12 01:20:30 +00006936 case DW_TAG_ptr_to_member_type:
6937 {
6938 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
6939 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
6940
Greg Claytond88d7592010-09-15 08:33:30 +00006941 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00006942
6943 if (num_attributes > 0) {
6944 uint32_t i;
6945 for (i=0; i<num_attributes; ++i)
6946 {
6947 attr = attributes.AttributeAtIndex(i);
6948 DWARFFormValue form_value;
6949 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6950 {
6951 switch (attr)
6952 {
6953 case DW_AT_type:
6954 type_die_offset = form_value.Reference(dwarf_cu); break;
6955 case DW_AT_containing_type:
6956 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
6957 }
6958 }
6959 }
6960
6961 Type *pointee_type = ResolveTypeUID(type_die_offset);
6962 Type *class_type = ResolveTypeUID(containing_type_die_offset);
6963
Greg Clayton526e5af2010-11-13 03:52:47 +00006964 clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
6965 clang_type_t class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00006966
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006967 clang_type = ast.CreateMemberPointerType(pointee_clang_type,
6968 class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00006969
Greg Clayton526e5af2010-11-13 03:52:47 +00006970 byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(),
6971 clang_type) / 8;
Greg Clayton9b81a312010-06-12 01:20:30 +00006972
Greg Clayton81c22f62011-10-19 18:09:39 +00006973 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006974 this,
6975 type_name_const_str,
6976 byte_size,
6977 NULL,
6978 LLDB_INVALID_UID,
6979 Type::eEncodingIsUID,
6980 NULL,
6981 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006982 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00006983 }
6984
6985 break;
6986 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006987 default:
Greg Clayton84afacd2012-11-07 23:09:32 +00006988 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",
6989 die->GetOffset(),
6990 tag,
6991 DW_TAG_value_to_name(tag));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006992 break;
6993 }
6994
6995 if (type_sp.get())
6996 {
6997 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
6998 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
6999
7000 SymbolContextScope * symbol_context_scope = NULL;
7001 if (sc_parent_tag == DW_TAG_compile_unit)
7002 {
7003 symbol_context_scope = sc.comp_unit;
7004 }
7005 else if (sc.function != NULL)
7006 {
Greg Clayton81c22f62011-10-19 18:09:39 +00007007 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007008 if (symbol_context_scope == NULL)
7009 symbol_context_scope = sc.function;
7010 }
7011
7012 if (symbol_context_scope != NULL)
7013 {
7014 type_sp->SetSymbolContextScope(symbol_context_scope);
7015 }
7016
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00007017 // We are ready to put this type into the uniqued list up at the module level
7018 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00007019
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00007020 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007021 }
7022 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00007023 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007024 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00007025 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007026 }
7027 }
7028 return type_sp;
7029}
7030
7031size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00007032SymbolFileDWARF::ParseTypes
7033(
7034 const SymbolContext& sc,
7035 DWARFCompileUnit* dwarf_cu,
7036 const DWARFDebugInfoEntry *die,
7037 bool parse_siblings,
7038 bool parse_children
7039)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007040{
7041 size_t types_added = 0;
7042 while (die != NULL)
7043 {
7044 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00007045 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007046 {
7047 if (type_is_new)
7048 ++types_added;
7049 }
7050
7051 if (parse_children && die->HasChildren())
7052 {
7053 if (die->Tag() == DW_TAG_subprogram)
7054 {
7055 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00007056 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007057 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
7058 }
7059 else
7060 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
7061 }
7062
7063 if (parse_siblings)
7064 die = die->GetSibling();
7065 else
7066 die = NULL;
7067 }
7068 return types_added;
7069}
7070
7071
7072size_t
7073SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
7074{
7075 assert(sc.comp_unit && sc.function);
7076 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00007077 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007078 if (dwarf_cu)
7079 {
7080 dw_offset_t function_die_offset = sc.function->GetID();
7081 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
7082 if (function_die)
7083 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00007084 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007085 }
7086 }
7087
7088 return functions_added;
7089}
7090
7091
7092size_t
7093SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
7094{
7095 // At least a compile unit must be valid
7096 assert(sc.comp_unit);
7097 size_t types_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00007098 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007099 if (dwarf_cu)
7100 {
7101 if (sc.function)
7102 {
7103 dw_offset_t function_die_offset = sc.function->GetID();
7104 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
7105 if (func_die && func_die->HasChildren())
7106 {
7107 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
7108 }
7109 }
7110 else
7111 {
7112 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
7113 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
7114 {
7115 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
7116 }
7117 }
7118 }
7119
7120 return types_added;
7121}
7122
7123size_t
7124SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
7125{
7126 if (sc.comp_unit != NULL)
7127 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00007128 DWARFDebugInfo* info = DebugInfo();
7129 if (info == NULL)
7130 return 0;
7131
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007132 if (sc.function)
7133 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007134 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get();
7135
7136 if (dwarf_cu == NULL)
7137 return 0;
7138
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007139 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00007140
Greg Claytonc7bece562013-01-25 18:06:21 +00007141 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
7142 if (func_lo_pc != LLDB_INVALID_ADDRESS)
Greg Claytone38a5ed2012-01-05 03:57:59 +00007143 {
7144 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00007145
Greg Claytone38a5ed2012-01-05 03:57:59 +00007146 // Let all blocks know they have parse all their variables
7147 sc.function->GetBlock (false).SetDidParseVariables (true, true);
7148 return num_variables;
7149 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007150 }
7151 else if (sc.comp_unit)
7152 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007153 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get();
7154
7155 if (dwarf_cu == NULL)
7156 return 0;
7157
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007158 uint32_t vars_added = 0;
7159 VariableListSP variables (sc.comp_unit->GetVariableList(false));
7160
7161 if (variables.get() == NULL)
7162 {
7163 variables.reset(new VariableList());
7164 sc.comp_unit->SetVariableList(variables);
7165
Greg Claytond4a2b372011-09-12 23:21:58 +00007166 DWARFCompileUnit* match_dwarf_cu = NULL;
7167 const DWARFDebugInfoEntry* die = NULL;
7168 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00007169 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00007170 {
Greg Clayton97fbc342011-10-20 22:30:33 +00007171 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00007172 {
7173 DWARFMappedHash::DIEInfoArray hash_data_array;
7174 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
7175 dwarf_cu->GetNextCompileUnitOffset(),
7176 hash_data_array))
7177 {
7178 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
7179 }
7180 }
Greg Clayton7f995132011-10-04 22:41:51 +00007181 }
7182 else
7183 {
7184 // Index if we already haven't to make sure the compile units
7185 // get indexed and make their global DIE index list
7186 if (!m_indexed)
7187 Index ();
7188
7189 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
7190 dwarf_cu->GetNextCompileUnitOffset(),
7191 die_offsets);
7192 }
7193
7194 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00007195 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007196 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007197 DWARFDebugInfo* debug_info = DebugInfo();
7198 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007199 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007200 const dw_offset_t die_offset = die_offsets[i];
7201 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00007202 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00007203 {
Greg Clayton95d87902011-11-11 03:16:25 +00007204 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
7205 if (var_sp)
7206 {
7207 variables->AddVariableIfUnique (var_sp);
7208 ++vars_added;
7209 }
Greg Claytond4a2b372011-09-12 23:21:58 +00007210 }
Greg Clayton95d87902011-11-11 03:16:25 +00007211 else
7212 {
7213 if (m_using_apple_tables)
7214 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00007215 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 +00007216 }
7217 }
7218
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007219 }
7220 }
7221 }
7222 return vars_added;
7223 }
7224 }
7225 return 0;
7226}
7227
7228
7229VariableSP
7230SymbolFileDWARF::ParseVariableDIE
7231(
7232 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007233 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007234 const DWARFDebugInfoEntry *die,
7235 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007236)
7237{
7238
Greg Clayton83c5cd92010-11-14 22:13:40 +00007239 VariableSP var_sp (m_die_to_variable_sp[die]);
7240 if (var_sp)
7241 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007242
7243 const dw_tag_t tag = die->Tag();
Greg Clayton7f995132011-10-04 22:41:51 +00007244
7245 if ((tag == DW_TAG_variable) ||
7246 (tag == DW_TAG_constant) ||
7247 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007248 {
Greg Clayton7f995132011-10-04 22:41:51 +00007249 DWARFDebugInfoEntry::Attributes attributes;
7250 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
7251 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007252 {
Greg Clayton7f995132011-10-04 22:41:51 +00007253 const char *name = NULL;
7254 const char *mangled = NULL;
7255 Declaration decl;
7256 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00007257 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00007258 DWARFExpression location;
7259 bool is_external = false;
7260 bool is_artificial = false;
7261 bool location_is_const_value_data = false;
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007262 bool has_explicit_location = false;
Greg Clayton23f59502012-07-17 03:23:13 +00007263 //AccessType accessibility = eAccessNone;
Greg Clayton7f995132011-10-04 22:41:51 +00007264
7265 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007266 {
Greg Clayton7f995132011-10-04 22:41:51 +00007267 dw_attr_t attr = attributes.AttributeAtIndex(i);
7268 DWARFFormValue form_value;
7269 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007270 {
Greg Clayton7f995132011-10-04 22:41:51 +00007271 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007272 {
Greg Clayton7f995132011-10-04 22:41:51 +00007273 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
7274 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
7275 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
7276 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton71415542012-12-08 00:24:40 +00007277 case DW_AT_linkage_name:
Greg Clayton7f995132011-10-04 22:41:51 +00007278 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Claytond1767f02011-12-08 02:13:16 +00007279 case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00007280 case DW_AT_external: is_external = form_value.Boolean(); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007281 case DW_AT_const_value:
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007282 // If we have already found a DW_AT_location attribute, ignore this attribute.
7283 if (!has_explicit_location)
7284 {
7285 location_is_const_value_data = true;
7286 // The constant value will be either a block, a data value or a string.
7287 const DataExtractor& debug_info_data = get_debug_info_data();
7288 if (DWARFFormValue::IsBlockForm(form_value.Form()))
7289 {
7290 // Retrieve the value as a block expression.
7291 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7292 uint32_t block_length = form_value.Unsigned();
7293 location.CopyOpcodeData(debug_info_data, block_offset, block_length);
7294 }
7295 else if (DWARFFormValue::IsDataForm(form_value.Form()))
7296 {
7297 // Retrieve the value as a data expression.
7298 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
7299 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7300 uint32_t data_length = fixed_form_sizes[form_value.Form()];
7301 location.CopyOpcodeData(debug_info_data, data_offset, data_length);
7302 }
7303 else
7304 {
7305 // Retrieve the value as a string expression.
7306 if (form_value.Form() == DW_FORM_strp)
7307 {
7308 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
7309 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7310 uint32_t data_length = fixed_form_sizes[form_value.Form()];
7311 location.CopyOpcodeData(debug_info_data, data_offset, data_length);
7312 }
7313 else
7314 {
7315 const char *str = form_value.AsCString(&debug_info_data);
7316 uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart();
7317 uint32_t string_length = strlen(str) + 1;
7318 location.CopyOpcodeData(debug_info_data, string_offset, string_length);
7319 }
7320 }
7321 }
7322 break;
Greg Clayton7f995132011-10-04 22:41:51 +00007323 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007324 {
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007325 location_is_const_value_data = false;
7326 has_explicit_location = true;
Greg Clayton7f995132011-10-04 22:41:51 +00007327 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007328 {
Greg Clayton7f995132011-10-04 22:41:51 +00007329 const DataExtractor& debug_info_data = get_debug_info_data();
7330
7331 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7332 uint32_t block_length = form_value.Unsigned();
Greg Clayton7f4c7432012-08-11 00:49:14 +00007333 location.CopyOpcodeData(get_debug_info_data(), block_offset, block_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007334 }
7335 else
7336 {
7337 const DataExtractor& debug_loc_data = get_debug_loc_data();
7338 const dw_offset_t debug_loc_offset = form_value.Unsigned();
7339
7340 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
7341 if (loc_list_length > 0)
7342 {
Greg Clayton7f4c7432012-08-11 00:49:14 +00007343 location.CopyOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007344 assert (func_low_pc != LLDB_INVALID_ADDRESS);
7345 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
7346 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007347 }
7348 }
Greg Clayton7f995132011-10-04 22:41:51 +00007349 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007350
Greg Clayton1c8ef472013-04-05 23:27:21 +00007351 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00007352 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007353 case DW_AT_declaration:
7354 case DW_AT_description:
7355 case DW_AT_endianity:
7356 case DW_AT_segment:
7357 case DW_AT_start_scope:
7358 case DW_AT_visibility:
7359 default:
7360 case DW_AT_abstract_origin:
7361 case DW_AT_sibling:
7362 case DW_AT_specification:
7363 break;
7364 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007365 }
7366 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007367
Greg Clayton9e9f2192013-05-17 00:55:28 +00007368 ValueType scope = eValueTypeInvalid;
7369
7370 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7371 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7372 SymbolContextScope * symbol_context_scope = NULL;
7373
7374 // DWARF doesn't specify if a DW_TAG_variable is a local, global
7375 // or static variable, so we have to do a little digging by
7376 // looking at the location of a varaible to see if it contains
7377 // a DW_OP_addr opcode _somewhere_ in the definition. I say
7378 // somewhere because clang likes to combine small global variables
7379 // into the same symbol and have locations like:
7380 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
7381 // So if we don't have a DW_TAG_formal_parameter, we can look at
7382 // the location to see if it contains a DW_OP_addr opcode, and
7383 // then we can correctly classify our variables.
7384 if (tag == DW_TAG_formal_parameter)
7385 scope = eValueTypeVariableArgument;
7386 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007387 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007388 bool op_error = false;
7389 // Check if the location has a DW_OP_addr with any address value...
7390 lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS;
7391 if (!location_is_const_value_data)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007392 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007393 location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error);
7394 if (op_error)
Greg Clayton96c09682012-01-04 22:56:43 +00007395 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007396 StreamString strm;
7397 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
7398 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 +00007399 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007400 }
Greg Claytond1767f02011-12-08 02:13:16 +00007401
Greg Clayton9e9f2192013-05-17 00:55:28 +00007402 if (location_DW_OP_addr != LLDB_INVALID_ADDRESS)
7403 {
7404 if (is_external)
7405 scope = eValueTypeVariableGlobal;
7406 else
7407 scope = eValueTypeVariableStatic;
7408
7409
7410 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile ();
7411
7412 if (debug_map_symfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007413 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007414 // When leaving the DWARF in the .o files on darwin,
7415 // when we have a global variable that wasn't initialized,
7416 // the .o file might not have allocated a virtual
7417 // address for the global variable. In this case it will
7418 // have created a symbol for the global variable
7419 // that is undefined/data and external and the value will
7420 // be the byte size of the variable. When we do the
7421 // address map in SymbolFileDWARFDebugMap we rely on
7422 // having an address, we need to do some magic here
7423 // so we can get the correct address for our global
7424 // variable. The address for all of these entries
7425 // will be zero, and there will be an undefined symbol
7426 // in this object file, and the executable will have
7427 // a matching symbol with a good address. So here we
7428 // dig up the correct address and replace it in the
7429 // location for the variable, and set the variable's
7430 // symbol context scope to be that of the main executable
7431 // so the file address will resolve correctly.
7432 bool linked_oso_file_addr = false;
7433 if (is_external && location_DW_OP_addr == 0)
Greg Clayton9422dd62013-03-04 21:46:16 +00007434 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007435 // we have a possible uninitialized extern global
7436 ConstString const_name(mangled ? mangled : name);
7437 ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile();
7438 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007439 {
Greg Clayton3046e662013-07-10 01:23:25 +00007440 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
Greg Clayton9e9f2192013-05-17 00:55:28 +00007441 if (debug_map_symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007442 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007443 Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
7444 eSymbolTypeData,
7445 Symtab::eDebugYes,
7446 Symtab::eVisibilityExtern);
7447 if (exe_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007448 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007449 if (exe_symbol->ValueIsAddress())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007450 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007451 const addr_t exe_file_addr = exe_symbol->GetAddress().GetFileAddress();
7452 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007453 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007454 if (location.Update_DW_OP_addr (exe_file_addr))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007455 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007456 linked_oso_file_addr = true;
7457 symbol_context_scope = exe_symbol;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007458 }
7459 }
7460 }
7461 }
7462 }
7463 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007464 }
Greg Clayton9422dd62013-03-04 21:46:16 +00007465
Greg Clayton9e9f2192013-05-17 00:55:28 +00007466 if (!linked_oso_file_addr)
7467 {
7468 // The DW_OP_addr is not zero, but it contains a .o file address which
7469 // needs to be linked up correctly.
7470 const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr);
7471 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton9422dd62013-03-04 21:46:16 +00007472 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007473 // Update the file address for this variable
7474 location.Update_DW_OP_addr (exe_file_addr);
7475 }
7476 else
7477 {
7478 // Variable didn't make it into the final executable
7479 return var_sp;
Greg Clayton9422dd62013-03-04 21:46:16 +00007480 }
Greg Claytond1767f02011-12-08 02:13:16 +00007481 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007482 }
Greg Clayton5cf58b92011-10-05 22:22:08 +00007483 }
7484 else
7485 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007486 scope = eValueTypeVariableLocal;
Greg Clayton5cf58b92011-10-05 22:22:08 +00007487 }
Greg Clayton7f995132011-10-04 22:41:51 +00007488 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007489
7490 if (symbol_context_scope == NULL)
7491 {
7492 switch (parent_tag)
7493 {
7494 case DW_TAG_subprogram:
7495 case DW_TAG_inlined_subroutine:
7496 case DW_TAG_lexical_block:
7497 if (sc.function)
7498 {
7499 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
7500 if (symbol_context_scope == NULL)
7501 symbol_context_scope = sc.function;
7502 }
7503 break;
7504
7505 default:
7506 symbol_context_scope = sc.comp_unit;
7507 break;
7508 }
7509 }
7510
7511 if (symbol_context_scope)
7512 {
7513 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
7514 name,
7515 mangled,
7516 SymbolFileTypeSP (new SymbolFileType(*this, type_uid)),
7517 scope,
7518 symbol_context_scope,
7519 &decl,
7520 location,
7521 is_external,
7522 is_artificial));
7523
7524 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
7525 }
7526 else
7527 {
7528 // Not ready to parse this variable yet. It might be a global
7529 // or static variable that is in a function scope and the function
7530 // in the symbol context wasn't filled in yet
7531 return var_sp;
7532 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007533 }
Greg Clayton7f995132011-10-04 22:41:51 +00007534 // Cache var_sp even if NULL (the variable was just a specification or
7535 // was missing vital information to be able to be displayed in the debugger
7536 // (missing location due to optimization, etc)) so we don't re-parse
7537 // this DIE over and over later...
7538 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007539 }
7540 return var_sp;
7541}
7542
Greg Claytonc662ec82011-06-17 22:10:16 +00007543
7544const DWARFDebugInfoEntry *
7545SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
7546 dw_offset_t spec_block_die_offset,
7547 DWARFCompileUnit **result_die_cu_handle)
7548{
7549 // Give the concrete function die specified by "func_die_offset", find the
7550 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7551 // to "spec_block_die_offset"
7552 DWARFDebugInfo* info = DebugInfo();
7553
7554 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
7555 if (die)
7556 {
7557 assert (*result_die_cu_handle);
7558 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
7559 }
7560 return NULL;
7561}
7562
7563
7564const DWARFDebugInfoEntry *
7565SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
7566 const DWARFDebugInfoEntry *die,
7567 dw_offset_t spec_block_die_offset,
7568 DWARFCompileUnit **result_die_cu_handle)
7569{
7570 if (die)
7571 {
7572 switch (die->Tag())
7573 {
7574 case DW_TAG_subprogram:
7575 case DW_TAG_inlined_subroutine:
7576 case DW_TAG_lexical_block:
7577 {
7578 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
7579 {
7580 *result_die_cu_handle = dwarf_cu;
7581 return die;
7582 }
7583
7584 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
7585 {
7586 *result_die_cu_handle = dwarf_cu;
7587 return die;
7588 }
7589 }
7590 break;
7591 }
7592
7593 // Give the concrete function die specified by "func_die_offset", find the
7594 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7595 // to "spec_block_die_offset"
7596 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
7597 {
7598 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
7599 child_die,
7600 spec_block_die_offset,
7601 result_die_cu_handle);
7602 if (result_die)
7603 return result_die;
7604 }
7605 }
7606
7607 *result_die_cu_handle = NULL;
7608 return NULL;
7609}
7610
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007611size_t
7612SymbolFileDWARF::ParseVariables
7613(
7614 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007615 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007616 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007617 const DWARFDebugInfoEntry *orig_die,
7618 bool parse_siblings,
7619 bool parse_children,
7620 VariableList* cc_variable_list
7621)
7622{
7623 if (orig_die == NULL)
7624 return 0;
7625
Greg Claytonc662ec82011-06-17 22:10:16 +00007626 VariableListSP variable_list_sp;
7627
7628 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007629 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00007630 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007631 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007632 dw_tag_t tag = die->Tag();
7633
7634 // Check to see if we have already parsed this variable or constant?
7635 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007636 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007637 if (cc_variable_list)
7638 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007639 }
7640 else
7641 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007642 // We haven't already parsed it, lets do that now.
7643 if ((tag == DW_TAG_variable) ||
7644 (tag == DW_TAG_constant) ||
7645 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007646 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007647 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00007648 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007649 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
7650 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7651 switch (parent_tag)
7652 {
7653 case DW_TAG_compile_unit:
7654 if (sc.comp_unit != NULL)
7655 {
7656 variable_list_sp = sc.comp_unit->GetVariableList(false);
7657 if (variable_list_sp.get() == NULL)
7658 {
7659 variable_list_sp.reset(new VariableList());
7660 sc.comp_unit->SetVariableList(variable_list_sp);
7661 }
7662 }
7663 else
7664 {
Daniel Malead01b2952012-11-29 21:49:15 +00007665 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 +00007666 MakeUserID(sc_parent_die->GetOffset()),
7667 DW_TAG_value_to_name (parent_tag),
7668 MakeUserID(orig_die->GetOffset()),
7669 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007670 }
7671 break;
7672
7673 case DW_TAG_subprogram:
7674 case DW_TAG_inlined_subroutine:
7675 case DW_TAG_lexical_block:
7676 if (sc.function != NULL)
7677 {
7678 // Check to see if we already have parsed the variables for the given scope
7679
Greg Clayton81c22f62011-10-19 18:09:39 +00007680 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007681 if (block == NULL)
7682 {
7683 // This must be a specification or abstract origin with
7684 // a concrete block couterpart in the current function. We need
7685 // to find the concrete block so we can correctly add the
7686 // variable to it
7687 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
7688 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
7689 sc_parent_die->GetOffset(),
7690 &concrete_block_die_cu);
7691 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00007692 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007693 }
7694
7695 if (block != NULL)
7696 {
7697 const bool can_create = false;
7698 variable_list_sp = block->GetBlockVariableList (can_create);
7699 if (variable_list_sp.get() == NULL)
7700 {
7701 variable_list_sp.reset(new VariableList());
7702 block->SetVariableList(variable_list_sp);
7703 }
7704 }
7705 }
7706 break;
7707
7708 default:
Daniel Malead01b2952012-11-29 21:49:15 +00007709 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 +00007710 MakeUserID(orig_die->GetOffset()),
7711 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007712 break;
7713 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00007714 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007715
7716 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007717 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00007718 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
7719 if (var_sp)
7720 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007721 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00007722 if (cc_variable_list)
7723 cc_variable_list->AddVariableIfUnique (var_sp);
7724 ++vars_added;
7725 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007726 }
7727 }
7728 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007729
7730 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
7731
7732 if (!skip_children && parse_children && die->HasChildren())
7733 {
7734 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
7735 }
7736
7737 if (parse_siblings)
7738 die = die->GetSibling();
7739 else
7740 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007741 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007742 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007743}
7744
7745//------------------------------------------------------------------
7746// PluginInterface protocol
7747//------------------------------------------------------------------
Greg Clayton57abc5d2013-05-10 21:47:16 +00007748ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007749SymbolFileDWARF::GetPluginName()
7750{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007751 return GetPluginNameStatic();
7752}
7753
7754uint32_t
7755SymbolFileDWARF::GetPluginVersion()
7756{
7757 return 1;
7758}
7759
7760void
Greg Clayton6beaaa62011-01-17 03:46:26 +00007761SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
7762{
7763 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7764 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
7765 if (clang_type)
7766 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7767}
7768
7769void
7770SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
7771{
7772 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7773 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
7774 if (clang_type)
7775 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7776}
7777
Greg Claytona2721472011-06-25 00:44:06 +00007778void
Sean Callanancc427fa2011-07-30 02:42:06 +00007779SymbolFileDWARF::DumpIndexes ()
7780{
7781 StreamFile s(stdout, false);
7782
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00007783 s.Printf ("DWARF index for (%s) '%s':",
Sean Callanancc427fa2011-07-30 02:42:06 +00007784 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00007785 GetObjectFile()->GetFileSpec().GetPath().c_str());
Sean Callanancc427fa2011-07-30 02:42:06 +00007786 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
7787 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
7788 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
7789 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
7790 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
7791 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
7792 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
7793 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
7794}
7795
7796void
7797SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
7798 const char *name,
7799 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00007800{
Sean Callanancc427fa2011-07-30 02:42:06 +00007801 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00007802
7803 if (iter == m_decl_ctx_to_die.end())
7804 return;
7805
Greg Claytoncb5860a2011-10-13 23:49:28 +00007806 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00007807 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007808 const DWARFDebugInfoEntry *context_die = *pos;
7809
7810 if (!results)
7811 return;
7812
7813 DWARFDebugInfo* info = DebugInfo();
7814
7815 DIEArray die_offsets;
7816
7817 DWARFCompileUnit* dwarf_cu = NULL;
7818 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton220a0072011-12-09 08:48:30 +00007819
7820 if (m_using_apple_tables)
7821 {
7822 if (m_apple_types_ap.get())
7823 m_apple_types_ap->FindByName (name, die_offsets);
7824 }
7825 else
7826 {
7827 if (!m_indexed)
7828 Index ();
7829
7830 m_type_index.Find (ConstString(name), die_offsets);
7831 }
7832
Greg Clayton220a0072011-12-09 08:48:30 +00007833 const size_t num_matches = die_offsets.size();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007834
7835 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00007836 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007837 for (size_t i = 0; i < num_matches; ++i)
7838 {
7839 const dw_offset_t die_offset = die_offsets[i];
7840 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00007841
Greg Claytoncb5860a2011-10-13 23:49:28 +00007842 if (die->GetParent() != context_die)
7843 continue;
7844
7845 Type *matching_type = ResolveType (dwarf_cu, die);
7846
Greg Clayton42ce2f32011-12-12 21:50:19 +00007847 lldb::clang_type_t type = matching_type->GetClangForwardType();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007848 clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type);
7849
7850 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
7851 {
7852 clang::TagDecl *tag_decl = tag_type->getDecl();
7853 results->push_back(tag_decl);
7854 }
7855 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
7856 {
7857 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
7858 results->push_back(typedef_decl);
7859 }
Greg Claytona2721472011-06-25 00:44:06 +00007860 }
7861 }
7862 }
7863}
7864
7865void
7866SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00007867 const clang::DeclContext *decl_context,
7868 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00007869 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
7870{
Greg Clayton85ae2e12011-10-18 23:36:41 +00007871
7872 switch (decl_context->getDeclKind())
7873 {
7874 case clang::Decl::Namespace:
7875 case clang::Decl::TranslationUnit:
7876 {
7877 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7878 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
7879 }
7880 break;
7881 default:
7882 break;
7883 }
Greg Claytona2721472011-06-25 00:44:06 +00007884}
Greg Claytoncaab74e2012-01-28 00:48:57 +00007885
7886bool
7887SymbolFileDWARF::LayoutRecordType (void *baton,
7888 const clang::RecordDecl *record_decl,
7889 uint64_t &size,
7890 uint64_t &alignment,
7891 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7892 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7893 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7894{
7895 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7896 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
7897}
7898
7899
7900bool
7901SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl,
7902 uint64_t &bit_size,
7903 uint64_t &alignment,
7904 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7905 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7906 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7907{
Greg Clayton5160ce52013-03-27 23:08:40 +00007908 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Claytoncaab74e2012-01-28 00:48:57 +00007909 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
7910 bool success = false;
7911 base_offsets.clear();
7912 vbase_offsets.clear();
7913 if (pos != m_record_decl_to_layout_map.end())
7914 {
7915 bit_size = pos->second.bit_size;
7916 alignment = pos->second.alignment;
7917 field_offsets.swap(pos->second.field_offsets);
Greg Clayton2508b9b2012-11-01 23:20:02 +00007918 base_offsets.swap (pos->second.base_offsets);
7919 vbase_offsets.swap (pos->second.vbase_offsets);
Greg Claytoncaab74e2012-01-28 00:48:57 +00007920 m_record_decl_to_layout_map.erase(pos);
7921 success = true;
7922 }
7923 else
7924 {
7925 bit_size = 0;
7926 alignment = 0;
7927 field_offsets.clear();
7928 }
7929
7930 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00007931 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00007932 "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 +00007933 record_decl,
7934 bit_size,
7935 alignment,
7936 (uint32_t)field_offsets.size(),
7937 (uint32_t)base_offsets.size(),
7938 (uint32_t)vbase_offsets.size(),
7939 success);
7940 return success;
7941}
7942
7943
Greg Clayton1f746072012-08-29 21:13:06 +00007944SymbolFileDWARFDebugMap *
7945SymbolFileDWARF::GetDebugMapSymfile ()
7946{
7947 if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired())
7948 {
7949 lldb::ModuleSP module_sp (m_debug_map_module_wp.lock());
7950 if (module_sp)
7951 {
7952 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
7953 if (sym_vendor)
7954 m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile();
7955 }
7956 }
7957 return m_debug_map_symfile;
7958}
7959
Greg Claytoncaab74e2012-01-28 00:48:57 +00007960