blob: 19faac42e1d0722245b53697345f0e3b75738cec [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"
Sean Callananf0c5aeb2015-04-20 16:31:29 +000030#include "lldb/Core/ModuleList.h"
31#include "lldb/Core/ModuleSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032#include "lldb/Core/PluginManager.h"
33#include "lldb/Core/RegularExpression.h"
34#include "lldb/Core/Scalar.h"
35#include "lldb/Core/Section.h"
Greg Claytonc685f8e2010-09-15 04:15:46 +000036#include "lldb/Core/StreamFile.h"
Jim Ingham318c9f22011-08-26 19:44:13 +000037#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000038#include "lldb/Core/Timer.h"
39#include "lldb/Core/Value.h"
40
Sean Callananf0c5aeb2015-04-20 16:31:29 +000041#include "lldb/Expression/ClangModulesDeclVendor.h"
42
Greg Clayton20568dd2011-10-13 23:13:20 +000043#include "lldb/Host/Host.h"
44
Chris Lattner30fdc8d2010-06-08 16:52:24 +000045#include "lldb/Symbol/Block.h"
Greg Clayton6beaaa62011-01-17 03:46:26 +000046#include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000047#include "lldb/Symbol/CompileUnit.h"
48#include "lldb/Symbol/LineTable.h"
49#include "lldb/Symbol/ObjectFile.h"
50#include "lldb/Symbol/SymbolVendor.h"
51#include "lldb/Symbol/VariableList.h"
52
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000053#include "lldb/Target/ObjCLanguageRuntime.h"
Jim Ingham4cda6e02011-10-07 22:23:45 +000054#include "lldb/Target/CPPLanguageRuntime.h"
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000055
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056#include "DWARFCompileUnit.h"
57#include "DWARFDebugAbbrev.h"
58#include "DWARFDebugAranges.h"
59#include "DWARFDebugInfo.h"
60#include "DWARFDebugInfoEntry.h"
61#include "DWARFDebugLine.h"
62#include "DWARFDebugPubnames.h"
63#include "DWARFDebugRanges.h"
Greg Claytona8022fa2012-04-24 21:22:41 +000064#include "DWARFDeclContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065#include "DWARFDIECollection.h"
66#include "DWARFFormValue.h"
67#include "DWARFLocationList.h"
68#include "LogChannelDWARF.h"
Greg Clayton450e3f32010-10-12 02:24:53 +000069#include "SymbolFileDWARFDebugMap.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000070
71#include <map>
72
Matthew Gardinere81df3b2014-08-26 06:57:23 +000073#include <ctype.h>
74#include <string.h>
75
Greg Clayton62742b12010-11-11 01:09:45 +000076//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
Greg Claytonc93237c2010-10-01 20:48:32 +000077
78#ifdef ENABLE_DEBUG_PRINTF
79#include <stdio.h>
Ed Mastea0191d12013-10-17 20:42:56 +000080#define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__)
Greg Claytonc93237c2010-10-01 20:48:32 +000081#else
82#define DEBUG_PRINTF(fmt, ...)
83#endif
84
Greg Clayton594e5ed2010-09-27 21:07:38 +000085#define DIE_IS_BEING_PARSED ((lldb_private::Type*)1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000086
87using namespace lldb;
88using namespace lldb_private;
89
Greg Clayton219cf312012-03-30 00:51:13 +000090//static inline bool
91//child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag)
92//{
93// switch (tag)
94// {
95// default:
96// break;
97// case DW_TAG_subprogram:
98// case DW_TAG_inlined_subroutine:
99// case DW_TAG_class_type:
100// case DW_TAG_structure_type:
101// case DW_TAG_union_type:
102// return true;
103// }
104// return false;
105//}
106//
Sean Callananc7fbf732010-08-06 00:32:49 +0000107static AccessType
Greg Clayton8cf05932010-07-22 18:30:50 +0000108DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000109{
110 switch (dwarf_accessibility)
111 {
Sean Callananc7fbf732010-08-06 00:32:49 +0000112 case DW_ACCESS_public: return eAccessPublic;
113 case DW_ACCESS_private: return eAccessPrivate;
114 case DW_ACCESS_protected: return eAccessProtected;
Greg Clayton8cf05932010-07-22 18:30:50 +0000115 default: break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000116 }
Sean Callananc7fbf732010-08-06 00:32:49 +0000117 return eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000118}
119
Matthew Gardinere81df3b2014-08-26 06:57:23 +0000120static const char*
121removeHostnameFromPathname(const char* path_from_dwarf)
122{
123 if (!path_from_dwarf || !path_from_dwarf[0])
124 {
125 return path_from_dwarf;
126 }
127
128 const char *colon_pos = strchr(path_from_dwarf, ':');
129 if (!colon_pos)
130 {
131 return path_from_dwarf;
132 }
133
134 // check whether we have a windows path, and so the first character
135 // is a drive-letter not a hostname.
136 if (
137 colon_pos == path_from_dwarf + 1 &&
138 isalpha(*path_from_dwarf) &&
139 strlen(path_from_dwarf) > 2 &&
140 '\\' == path_from_dwarf[2])
141 {
142 return path_from_dwarf;
143 }
144
145 return colon_pos + 1;
146}
147
Todd Fiala0a70a842014-05-28 16:43:26 +0000148#if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE)
Greg Clayton1fba87112012-02-09 20:03:49 +0000149
150class DIEStack
151{
152public:
153
154 void Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
155 {
156 m_dies.push_back (DIEInfo(cu, die));
157 }
158
159
160 void LogDIEs (Log *log, SymbolFileDWARF *dwarf)
161 {
162 StreamString log_strm;
163 const size_t n = m_dies.size();
Daniel Malead01b2952012-11-29 21:49:15 +0000164 log_strm.Printf("DIEStack[%" PRIu64 "]:\n", (uint64_t)n);
Greg Clayton1fba87112012-02-09 20:03:49 +0000165 for (size_t i=0; i<n; i++)
166 {
167 DWARFCompileUnit *cu = m_dies[i].cu;
168 const DWARFDebugInfoEntry *die = m_dies[i].die;
169 std::string qualified_name;
170 die->GetQualifiedName(dwarf, cu, qualified_name);
Daniel Malead01b2952012-11-29 21:49:15 +0000171 log_strm.Printf ("[%" PRIu64 "] 0x%8.8x: %s name='%s'\n",
Greg Clayton43e0af02012-09-18 18:04:04 +0000172 (uint64_t)i,
Greg Clayton1fba87112012-02-09 20:03:49 +0000173 die->GetOffset(),
174 DW_TAG_value_to_name(die->Tag()),
175 qualified_name.c_str());
176 }
177 log->PutCString(log_strm.GetData());
178 }
179 void Pop ()
180 {
181 m_dies.pop_back();
182 }
183
184 class ScopedPopper
185 {
186 public:
187 ScopedPopper (DIEStack &die_stack) :
188 m_die_stack (die_stack),
189 m_valid (false)
190 {
191 }
192
193 void
194 Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
195 {
196 m_valid = true;
197 m_die_stack.Push (cu, die);
198 }
199
200 ~ScopedPopper ()
201 {
202 if (m_valid)
203 m_die_stack.Pop();
204 }
205
206
207
208 protected:
209 DIEStack &m_die_stack;
210 bool m_valid;
211 };
212
213protected:
214 struct DIEInfo {
215 DIEInfo (DWARFCompileUnit *c, const DWARFDebugInfoEntry *d) :
216 cu(c),
217 die(d)
218 {
219 }
220 DWARFCompileUnit *cu;
221 const DWARFDebugInfoEntry *die;
222 };
223 typedef std::vector<DIEInfo> Stack;
224 Stack m_dies;
225};
226#endif
227
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000228void
229SymbolFileDWARF::Initialize()
230{
231 LogChannelDWARF::Initialize();
232 PluginManager::RegisterPlugin (GetPluginNameStatic(),
233 GetPluginDescriptionStatic(),
234 CreateInstance);
235}
236
237void
238SymbolFileDWARF::Terminate()
239{
240 PluginManager::UnregisterPlugin (CreateInstance);
241 LogChannelDWARF::Initialize();
242}
243
244
Greg Clayton57abc5d2013-05-10 21:47:16 +0000245lldb_private::ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000246SymbolFileDWARF::GetPluginNameStatic()
247{
Greg Clayton57abc5d2013-05-10 21:47:16 +0000248 static ConstString g_name("dwarf");
249 return g_name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000250}
251
252const char *
253SymbolFileDWARF::GetPluginDescriptionStatic()
254{
255 return "DWARF and DWARF3 debug symbol file reader.";
256}
257
258
259SymbolFile*
260SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
261{
262 return new SymbolFileDWARF(obj_file);
263}
264
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000265TypeList *
266SymbolFileDWARF::GetTypeList ()
267{
Greg Clayton1f746072012-08-29 21:13:06 +0000268 if (GetDebugMapSymfile ())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000269 return m_debug_map_symfile->GetTypeList();
270 return m_obj_file->GetModule()->GetTypeList();
271
272}
Greg Claytonf02500c2013-06-18 22:51:05 +0000273void
274SymbolFileDWARF::GetTypes (DWARFCompileUnit* cu,
275 const DWARFDebugInfoEntry *die,
276 dw_offset_t min_die_offset,
277 dw_offset_t max_die_offset,
278 uint32_t type_mask,
279 TypeSet &type_set)
280{
281 if (cu)
282 {
283 if (die)
284 {
285 const dw_offset_t die_offset = die->GetOffset();
286
287 if (die_offset >= max_die_offset)
288 return;
289
290 if (die_offset >= min_die_offset)
291 {
292 const dw_tag_t tag = die->Tag();
293
294 bool add_type = false;
295
296 switch (tag)
297 {
298 case DW_TAG_array_type: add_type = (type_mask & eTypeClassArray ) != 0; break;
299 case DW_TAG_unspecified_type:
300 case DW_TAG_base_type: add_type = (type_mask & eTypeClassBuiltin ) != 0; break;
301 case DW_TAG_class_type: add_type = (type_mask & eTypeClassClass ) != 0; break;
302 case DW_TAG_structure_type: add_type = (type_mask & eTypeClassStruct ) != 0; break;
303 case DW_TAG_union_type: add_type = (type_mask & eTypeClassUnion ) != 0; break;
304 case DW_TAG_enumeration_type: add_type = (type_mask & eTypeClassEnumeration ) != 0; break;
305 case DW_TAG_subroutine_type:
306 case DW_TAG_subprogram:
307 case DW_TAG_inlined_subroutine: add_type = (type_mask & eTypeClassFunction ) != 0; break;
308 case DW_TAG_pointer_type: add_type = (type_mask & eTypeClassPointer ) != 0; break;
309 case DW_TAG_rvalue_reference_type:
310 case DW_TAG_reference_type: add_type = (type_mask & eTypeClassReference ) != 0; break;
311 case DW_TAG_typedef: add_type = (type_mask & eTypeClassTypedef ) != 0; break;
312 case DW_TAG_ptr_to_member_type: add_type = (type_mask & eTypeClassMemberPointer ) != 0; break;
313 }
314
315 if (add_type)
316 {
317 const bool assert_not_being_parsed = true;
318 Type *type = ResolveTypeUID (cu, die, assert_not_being_parsed);
319 if (type)
320 {
321 if (type_set.find(type) == type_set.end())
322 type_set.insert(type);
323 }
324 }
325 }
326
327 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild();
328 child_die != NULL;
329 child_die = child_die->GetSibling())
330 {
331 GetTypes (cu, child_die, min_die_offset, max_die_offset, type_mask, type_set);
332 }
333 }
334 }
335}
336
337size_t
338SymbolFileDWARF::GetTypes (SymbolContextScope *sc_scope,
339 uint32_t type_mask,
340 TypeList &type_list)
341
342{
343 TypeSet type_set;
344
345 CompileUnit *comp_unit = NULL;
346 DWARFCompileUnit* dwarf_cu = NULL;
347 if (sc_scope)
348 comp_unit = sc_scope->CalculateSymbolContextCompileUnit();
349
350 if (comp_unit)
351 {
352 dwarf_cu = GetDWARFCompileUnit(comp_unit);
353 if (dwarf_cu == 0)
354 return 0;
355 GetTypes (dwarf_cu,
356 dwarf_cu->DIE(),
357 dwarf_cu->GetOffset(),
358 dwarf_cu->GetNextCompileUnitOffset(),
359 type_mask,
360 type_set);
361 }
362 else
363 {
364 DWARFDebugInfo* info = DebugInfo();
365 if (info)
366 {
367 const size_t num_cus = info->GetNumCompileUnits();
368 for (size_t cu_idx=0; cu_idx<num_cus; ++cu_idx)
369 {
370 dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
371 if (dwarf_cu)
372 {
373 GetTypes (dwarf_cu,
374 dwarf_cu->DIE(),
375 0,
376 UINT32_MAX,
377 type_mask,
378 type_set);
379 }
380 }
381 }
382 }
383// if (m_using_apple_tables)
384// {
385// DWARFMappedHash::MemoryTable *apple_types = m_apple_types_ap.get();
386// if (apple_types)
387// {
388// apple_types->ForEach([this, &type_set, apple_types, type_mask](const DWARFMappedHash::DIEInfoArray &die_info_array) -> bool {
389//
390// for (auto die_info: die_info_array)
391// {
392// bool add_type = TagMatchesTypeMask (type_mask, 0);
393// if (!add_type)
394// {
395// dw_tag_t tag = die_info.tag;
396// if (tag == 0)
397// {
398// const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_info.offset, NULL);
399// tag = die->Tag();
400// }
401// add_type = TagMatchesTypeMask (type_mask, tag);
402// }
403// if (add_type)
404// {
405// Type *type = ResolveTypeUID(die_info.offset);
406//
407// if (type_set.find(type) == type_set.end())
408// type_set.insert(type);
409// }
410// }
411// return true; // Keep iterating
412// });
413// }
414// }
415// else
416// {
417// if (!m_indexed)
418// Index ();
419//
420// m_type_index.ForEach([this, &type_set, type_mask](const char *name, uint32_t die_offset) -> bool {
421//
422// bool add_type = TagMatchesTypeMask (type_mask, 0);
423//
424// if (!add_type)
425// {
426// const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_offset, NULL);
427// if (die)
428// {
429// const dw_tag_t tag = die->Tag();
430// add_type = TagMatchesTypeMask (type_mask, tag);
431// }
432// }
433//
434// if (add_type)
435// {
436// Type *type = ResolveTypeUID(die_offset);
437//
438// if (type_set.find(type) == type_set.end())
439// type_set.insert(type);
440// }
441// return true; // Keep iterating
442// });
443// }
444
Greg Clayton57ee3062013-07-11 22:46:58 +0000445 std::set<ClangASTType> clang_type_set;
Greg Claytonf02500c2013-06-18 22:51:05 +0000446 size_t num_types_added = 0;
447 for (Type *type : type_set)
448 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000449 ClangASTType clang_type = type->GetClangForwardType();
Greg Clayton0fc4f312013-06-20 01:23:18 +0000450 if (clang_type_set.find(clang_type) == clang_type_set.end())
451 {
452 clang_type_set.insert(clang_type);
453 type_list.Insert (type->shared_from_this());
454 ++num_types_added;
455 }
Greg Claytonf02500c2013-06-18 22:51:05 +0000456 }
457 return num_types_added;
458}
459
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000460
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000461//----------------------------------------------------------------------
462// Gets the first parent that is a lexical block, function or inlined
463// subroutine, or compile unit.
464//----------------------------------------------------------------------
465static const DWARFDebugInfoEntry *
466GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
467{
468 const DWARFDebugInfoEntry *die;
469 for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
470 {
471 dw_tag_t tag = die->Tag();
472
473 switch (tag)
474 {
475 case DW_TAG_compile_unit:
476 case DW_TAG_subprogram:
477 case DW_TAG_inlined_subroutine:
478 case DW_TAG_lexical_block:
479 return die;
480 }
481 }
482 return NULL;
483}
484
485
Greg Clayton450e3f32010-10-12 02:24:53 +0000486SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
487 SymbolFile (objfile),
Greg Clayton81c22f62011-10-19 18:09:39 +0000488 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 +0000489 m_debug_map_module_wp (),
Greg Clayton450e3f32010-10-12 02:24:53 +0000490 m_debug_map_symfile (NULL),
Greg Clayton7a345282010-11-09 23:46:37 +0000491 m_clang_tu_decl (NULL),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000492 m_flags(),
Greg Claytond4a2b372011-09-12 23:21:58 +0000493 m_data_debug_abbrev (),
494 m_data_debug_aranges (),
495 m_data_debug_frame (),
496 m_data_debug_info (),
497 m_data_debug_line (),
498 m_data_debug_loc (),
499 m_data_debug_ranges (),
500 m_data_debug_str (),
Greg Clayton17674402011-09-28 17:06:40 +0000501 m_data_apple_names (),
502 m_data_apple_types (),
Greg Clayton7f995132011-10-04 22:41:51 +0000503 m_data_apple_namespaces (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000504 m_abbr(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000505 m_info(),
506 m_line(),
Greg Clayton7f995132011-10-04 22:41:51 +0000507 m_apple_names_ap (),
508 m_apple_types_ap (),
509 m_apple_namespaces_ap (),
Greg Clayton5009f9d2011-10-27 17:55:14 +0000510 m_apple_objc_ap (),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000511 m_function_basename_index(),
512 m_function_fullname_index(),
513 m_function_method_index(),
514 m_function_selector_index(),
Greg Clayton450e3f32010-10-12 02:24:53 +0000515 m_objc_class_selectors_index(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000516 m_global_index(),
Greg Clayton69b04882010-10-15 02:03:22 +0000517 m_type_index(),
518 m_namespace_index(),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000519 m_indexed (false),
520 m_is_external_ast_source (false),
Greg Clayton97fbc342011-10-20 22:30:33 +0000521 m_using_apple_tables (false),
Sean Callananf0c5aeb2015-04-20 16:31:29 +0000522 m_fetched_external_modules (false),
Greg Claytonc7f03b62012-01-12 04:33:28 +0000523 m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +0000524 m_ranges(),
525 m_unique_ast_type_map ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000526{
527}
528
529SymbolFileDWARF::~SymbolFileDWARF()
530{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000531 if (m_is_external_ast_source)
Greg Claytone72dfb32012-02-24 01:59:29 +0000532 {
533 ModuleSP module_sp (m_obj_file->GetModule());
534 if (module_sp)
535 module_sp->GetClangASTContext().RemoveExternalSource ();
536 }
Greg Clayton6beaaa62011-01-17 03:46:26 +0000537}
538
539static const ConstString &
540GetDWARFMachOSegmentName ()
541{
542 static ConstString g_dwarf_section_name ("__DWARF");
543 return g_dwarf_section_name;
544}
545
Greg Claytone576ab22011-02-15 00:19:15 +0000546UniqueDWARFASTTypeMap &
547SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
548{
Greg Clayton1f746072012-08-29 21:13:06 +0000549 if (GetDebugMapSymfile ())
Greg Claytone576ab22011-02-15 00:19:15 +0000550 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
551 return m_unique_ast_type_map;
552}
553
Greg Clayton6beaaa62011-01-17 03:46:26 +0000554ClangASTContext &
555SymbolFileDWARF::GetClangASTContext ()
556{
Greg Clayton1f746072012-08-29 21:13:06 +0000557 if (GetDebugMapSymfile ())
Greg Clayton6beaaa62011-01-17 03:46:26 +0000558 return m_debug_map_symfile->GetClangASTContext ();
559
560 ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext();
561 if (!m_is_external_ast_source)
562 {
563 m_is_external_ast_source = true;
Todd Fiala955fe6f2014-02-27 17:18:23 +0000564 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source_ap (
Greg Clayton6beaaa62011-01-17 03:46:26 +0000565 new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl,
566 SymbolFileDWARF::CompleteObjCInterfaceDecl,
Greg Claytona2721472011-06-25 00:44:06 +0000567 SymbolFileDWARF::FindExternalVisibleDeclsByName,
Greg Claytoncaab74e2012-01-28 00:48:57 +0000568 SymbolFileDWARF::LayoutRecordType,
Greg Clayton6beaaa62011-01-17 03:46:26 +0000569 this));
Greg Clayton6beaaa62011-01-17 03:46:26 +0000570 ast.SetExternalSource (ast_source_ap);
571 }
572 return ast;
573}
574
575void
576SymbolFileDWARF::InitializeObject()
577{
578 // Install our external AST source callbacks so we can complete Clang types.
Greg Claytone72dfb32012-02-24 01:59:29 +0000579 ModuleSP module_sp (m_obj_file->GetModule());
580 if (module_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +0000581 {
Greg Clayton3046e662013-07-10 01:23:25 +0000582 const SectionList *section_list = module_sp->GetSectionList();
Greg Clayton6beaaa62011-01-17 03:46:26 +0000583
584 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
585
586 // Memory map the DWARF mach-o segment so we have everything mmap'ed
587 // to keep our heap memory usage down.
588 if (section)
Greg Claytonc9660542012-02-05 02:38:54 +0000589 m_obj_file->MemoryMapSectionData(section, m_dwarf_data);
Greg Clayton6beaaa62011-01-17 03:46:26 +0000590 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000591 get_apple_names_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000592 if (m_data_apple_names.GetByteSize() > 0)
593 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000594 m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names"));
595 if (m_apple_names_ap->IsValid())
596 m_using_apple_tables = true;
597 else
Greg Clayton7f995132011-10-04 22:41:51 +0000598 m_apple_names_ap.reset();
599 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000600 get_apple_types_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000601 if (m_data_apple_types.GetByteSize() > 0)
602 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000603 m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types"));
604 if (m_apple_types_ap->IsValid())
605 m_using_apple_tables = true;
606 else
Greg Clayton7f995132011-10-04 22:41:51 +0000607 m_apple_types_ap.reset();
608 }
609
610 get_apple_namespaces_data();
611 if (m_data_apple_namespaces.GetByteSize() > 0)
612 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000613 m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces"));
614 if (m_apple_namespaces_ap->IsValid())
615 m_using_apple_tables = true;
616 else
Greg Clayton7f995132011-10-04 22:41:51 +0000617 m_apple_namespaces_ap.reset();
618 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000619
Greg Clayton5009f9d2011-10-27 17:55:14 +0000620 get_apple_objc_data();
621 if (m_data_apple_objc.GetByteSize() > 0)
622 {
623 m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc"));
624 if (m_apple_objc_ap->IsValid())
625 m_using_apple_tables = true;
626 else
627 m_apple_objc_ap.reset();
628 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000629}
630
631bool
632SymbolFileDWARF::SupportedVersion(uint16_t version)
633{
Greg Claytonabcbfe52013-04-04 00:00:36 +0000634 return version == 2 || version == 3 || version == 4;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000635}
636
637uint32_t
Sean Callananbfaf54d2011-12-03 04:38:43 +0000638SymbolFileDWARF::CalculateAbilities ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000639{
640 uint32_t abilities = 0;
641 if (m_obj_file != NULL)
642 {
643 const Section* section = NULL;
644 const SectionList *section_list = m_obj_file->GetSectionList();
645 if (section_list == NULL)
646 return 0;
647
648 uint64_t debug_abbrev_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000649 uint64_t debug_info_file_size = 0;
650 uint64_t debug_line_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000651
Greg Clayton6beaaa62011-01-17 03:46:26 +0000652 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000653
654 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000655 section_list = &section->GetChildren ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000656
Greg Clayton4ceb9982010-07-21 22:54:26 +0000657 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000658 if (section != NULL)
659 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000660 debug_info_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000661
Greg Clayton4ceb9982010-07-21 22:54:26 +0000662 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000663 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000664 debug_abbrev_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000665 else
666 m_flags.Set (flagsGotDebugAbbrevData);
667
Greg Clayton4ceb9982010-07-21 22:54:26 +0000668 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000669 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000670 m_flags.Set (flagsGotDebugArangesData);
671
Greg Clayton4ceb9982010-07-21 22:54:26 +0000672 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000673 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000674 m_flags.Set (flagsGotDebugFrameData);
675
Greg Clayton4ceb9982010-07-21 22:54:26 +0000676 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000677 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000678 debug_line_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000679 else
680 m_flags.Set (flagsGotDebugLineData);
681
Greg Clayton4ceb9982010-07-21 22:54:26 +0000682 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000683 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000684 m_flags.Set (flagsGotDebugLocData);
685
Greg Clayton4ceb9982010-07-21 22:54:26 +0000686 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000687 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000688 m_flags.Set (flagsGotDebugMacInfoData);
689
Greg Clayton4ceb9982010-07-21 22:54:26 +0000690 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000691 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000692 m_flags.Set (flagsGotDebugPubNamesData);
693
Greg Clayton4ceb9982010-07-21 22:54:26 +0000694 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000695 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000696 m_flags.Set (flagsGotDebugPubTypesData);
697
Greg Clayton4ceb9982010-07-21 22:54:26 +0000698 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000699 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000700 m_flags.Set (flagsGotDebugRangesData);
701
Greg Clayton4ceb9982010-07-21 22:54:26 +0000702 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000703 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000704 m_flags.Set (flagsGotDebugStrData);
705 }
Greg Clayton6c596612012-05-18 21:47:20 +0000706 else
707 {
708 const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString();
709 if (symfile_dir_cstr)
710 {
711 if (strcasestr(symfile_dir_cstr, ".dsym"))
712 {
713 if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo)
714 {
715 // We have a dSYM file that didn't have a any debug info.
716 // If the string table has a size of 1, then it was made from
717 // an executable with no debug info, or from an executable that
718 // was stripped.
719 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
720 if (section && section->GetFileSize() == 1)
721 {
722 m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info.");
723 }
724 }
725 }
726 }
727 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000728
729 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
730 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
731
732 if (debug_line_file_size > 0)
733 abilities |= LineTables;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000734 }
735 return abilities;
736}
737
Ed Masteeeae7212013-10-24 20:43:47 +0000738const DWARFDataExtractor&
739SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DWARFDataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000740{
741 if (m_flags.IsClear (got_flag))
742 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000743 ModuleSP module_sp (m_obj_file->GetModule());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000744 m_flags.Set (got_flag);
Greg Clayton3046e662013-07-10 01:23:25 +0000745 const SectionList *section_list = module_sp->GetSectionList();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000746 if (section_list)
747 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000748 SectionSP section_sp (section_list->FindSectionByType(sect_type, true));
749 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000750 {
751 // See if we memory mapped the DWARF segment?
752 if (m_dwarf_data.GetByteSize())
753 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000754 data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000755 }
756 else
757 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000758 if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000759 data.Clear();
760 }
761 }
762 }
763 }
764 return data;
765}
766
Ed Masteeeae7212013-10-24 20:43:47 +0000767const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000768SymbolFileDWARF::get_debug_abbrev_data()
769{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000770 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000771}
772
Ed Masteeeae7212013-10-24 20:43:47 +0000773const DWARFDataExtractor&
Greg Claytond4a2b372011-09-12 23:21:58 +0000774SymbolFileDWARF::get_debug_aranges_data()
775{
776 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
777}
778
Ed Masteeeae7212013-10-24 20:43:47 +0000779const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000780SymbolFileDWARF::get_debug_frame_data()
781{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000782 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000783}
784
Ed Masteeeae7212013-10-24 20:43:47 +0000785const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000786SymbolFileDWARF::get_debug_info_data()
787{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000788 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000789}
790
Ed Masteeeae7212013-10-24 20:43:47 +0000791const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000792SymbolFileDWARF::get_debug_line_data()
793{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000794 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000795}
796
Ed Masteeeae7212013-10-24 20:43:47 +0000797const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000798SymbolFileDWARF::get_debug_loc_data()
799{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000800 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000801}
802
Ed Masteeeae7212013-10-24 20:43:47 +0000803const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000804SymbolFileDWARF::get_debug_ranges_data()
805{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000806 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000807}
808
Ed Masteeeae7212013-10-24 20:43:47 +0000809const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000810SymbolFileDWARF::get_debug_str_data()
811{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000812 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000813}
814
Ed Masteeeae7212013-10-24 20:43:47 +0000815const DWARFDataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000816SymbolFileDWARF::get_apple_names_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000817{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000818 return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names);
Greg Claytonf9eec202011-09-01 23:16:13 +0000819}
820
Ed Masteeeae7212013-10-24 20:43:47 +0000821const DWARFDataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000822SymbolFileDWARF::get_apple_types_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000823{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000824 return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types);
Greg Claytonf9eec202011-09-01 23:16:13 +0000825}
826
Ed Masteeeae7212013-10-24 20:43:47 +0000827const DWARFDataExtractor&
Greg Clayton7f995132011-10-04 22:41:51 +0000828SymbolFileDWARF::get_apple_namespaces_data()
829{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000830 return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
831}
832
Ed Masteeeae7212013-10-24 20:43:47 +0000833const DWARFDataExtractor&
Greg Clayton5009f9d2011-10-27 17:55:14 +0000834SymbolFileDWARF::get_apple_objc_data()
835{
836 return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc);
Greg Clayton7f995132011-10-04 22:41:51 +0000837}
838
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000839
840DWARFDebugAbbrev*
841SymbolFileDWARF::DebugAbbrev()
842{
843 if (m_abbr.get() == NULL)
844 {
Ed Masteeeae7212013-10-24 20:43:47 +0000845 const DWARFDataExtractor &debug_abbrev_data = get_debug_abbrev_data();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000846 if (debug_abbrev_data.GetByteSize() > 0)
847 {
848 m_abbr.reset(new DWARFDebugAbbrev());
849 if (m_abbr.get())
850 m_abbr->Parse(debug_abbrev_data);
851 }
852 }
853 return m_abbr.get();
854}
855
856const DWARFDebugAbbrev*
857SymbolFileDWARF::DebugAbbrev() const
858{
859 return m_abbr.get();
860}
861
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000862
863DWARFDebugInfo*
864SymbolFileDWARF::DebugInfo()
865{
866 if (m_info.get() == NULL)
867 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000868 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p",
869 __PRETTY_FUNCTION__, static_cast<void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000870 if (get_debug_info_data().GetByteSize() > 0)
871 {
872 m_info.reset(new DWARFDebugInfo());
873 if (m_info.get())
874 {
875 m_info->SetDwarfData(this);
876 }
877 }
878 }
879 return m_info.get();
880}
881
882const DWARFDebugInfo*
883SymbolFileDWARF::DebugInfo() const
884{
885 return m_info.get();
886}
887
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000888DWARFCompileUnit*
Greg Clayton1f746072012-08-29 21:13:06 +0000889SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000890{
891 DWARFDebugInfo* info = DebugInfo();
Greg Clayton1f746072012-08-29 21:13:06 +0000892 if (info)
893 {
894 if (GetDebugMapSymfile ())
895 {
896 // The debug map symbol file made the compile units for this DWARF
897 // file which is .o file with DWARF in it, and we should have
898 // only 1 compile unit which is at offset zero in the DWARF.
899 // TODO: modify to support LTO .o files where each .o file might
900 // have multiple DW_TAG_compile_unit tags.
Greg Clayton68c00bd2015-02-05 02:10:29 +0000901
902 DWARFCompileUnit *dwarf_cu = info->GetCompileUnit(0).get();
903 if (dwarf_cu && dwarf_cu->GetUserData() == NULL)
904 dwarf_cu->SetUserData(comp_unit);
905 return dwarf_cu;
Greg Clayton1f746072012-08-29 21:13:06 +0000906 }
907 else
908 {
909 // Just a normal DWARF file whose user ID for the compile unit is
910 // the DWARF offset itself
Greg Clayton68c00bd2015-02-05 02:10:29 +0000911
912 DWARFCompileUnit *dwarf_cu = info->GetCompileUnit((dw_offset_t)comp_unit->GetID()).get();
913 if (dwarf_cu && dwarf_cu->GetUserData() == NULL)
914 dwarf_cu->SetUserData(comp_unit);
915 return dwarf_cu;
916
Greg Clayton1f746072012-08-29 21:13:06 +0000917 }
918 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000919 return NULL;
920}
921
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000922
923DWARFDebugRanges*
924SymbolFileDWARF::DebugRanges()
925{
926 if (m_ranges.get() == NULL)
927 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000928 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p",
929 __PRETTY_FUNCTION__, static_cast<void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000930 if (get_debug_ranges_data().GetByteSize() > 0)
931 {
932 m_ranges.reset(new DWARFDebugRanges());
933 if (m_ranges.get())
934 m_ranges->Extract(this);
935 }
936 }
937 return m_ranges.get();
938}
939
940const DWARFDebugRanges*
941SymbolFileDWARF::DebugRanges() const
942{
943 return m_ranges.get();
944}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000945
Greg Clayton53eb1c22012-04-02 22:59:12 +0000946lldb::CompUnitSP
947SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000948{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000949 CompUnitSP cu_sp;
950 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000951 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000952 CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData();
953 if (comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000954 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000955 // We already parsed this compile unit, had out a shared pointer to it
956 cu_sp = comp_unit->shared_from_this();
957 }
958 else
959 {
Greg Clayton1f746072012-08-29 21:13:06 +0000960 if (GetDebugMapSymfile ())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000961 {
Greg Clayton1f746072012-08-29 21:13:06 +0000962 // Let the debug map create the compile unit
963 cu_sp = m_debug_map_symfile->GetCompileUnit(this);
964 dwarf_cu->SetUserData(cu_sp.get());
965 }
966 else
967 {
968 ModuleSP module_sp (m_obj_file->GetModule());
969 if (module_sp)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000970 {
Greg Clayton1f746072012-08-29 21:13:06 +0000971 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly ();
972 if (cu_die)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000973 {
Greg Clayton1f746072012-08-29 21:13:06 +0000974 const char * cu_die_name = cu_die->GetName(this, dwarf_cu);
975 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
976 LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
977 if (cu_die_name)
978 {
979 std::string ramapped_file;
980 FileSpec cu_file_spec;
Jim Ingham0909e5f2010-09-16 00:57:33 +0000981
Greg Clayton1f746072012-08-29 21:13:06 +0000982 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0')
Greg Clayton53eb1c22012-04-02 22:59:12 +0000983 {
Greg Clayton1f746072012-08-29 21:13:06 +0000984 // If we have a full path to the compile unit, we don't need to resolve
985 // the file. This can be expensive e.g. when the source files are NFS mounted.
986 if (module_sp->RemapSourceFile(cu_die_name, ramapped_file))
987 cu_file_spec.SetFile (ramapped_file.c_str(), false);
988 else
989 cu_file_spec.SetFile (cu_die_name, false);
Greg Clayton53eb1c22012-04-02 22:59:12 +0000990 }
991 else
992 {
Matthew Gardinere81df3b2014-08-26 06:57:23 +0000993 // DWARF2/3 suggests the form hostname:pathname for compilation directory.
994 // Remove the host part if present.
995 cu_comp_dir = removeHostnameFromPathname(cu_comp_dir);
Greg Clayton1f746072012-08-29 21:13:06 +0000996 std::string fullpath(cu_comp_dir);
Matthew Gardinere81df3b2014-08-26 06:57:23 +0000997
Greg Clayton1f746072012-08-29 21:13:06 +0000998 if (*fullpath.rbegin() != '/')
999 fullpath += '/';
1000 fullpath += cu_die_name;
1001 if (module_sp->RemapSourceFile (fullpath.c_str(), ramapped_file))
1002 cu_file_spec.SetFile (ramapped_file.c_str(), false);
1003 else
1004 cu_file_spec.SetFile (fullpath.c_str(), false);
1005 }
1006
1007 cu_sp.reset(new CompileUnit (module_sp,
1008 dwarf_cu,
1009 cu_file_spec,
1010 MakeUserID(dwarf_cu->GetOffset()),
1011 cu_language));
1012 if (cu_sp)
1013 {
1014 dwarf_cu->SetUserData(cu_sp.get());
1015
Greg Clayton53eb1c22012-04-02 22:59:12 +00001016 // Figure out the compile unit index if we weren't given one
1017 if (cu_idx == UINT32_MAX)
1018 DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx);
1019
1020 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp);
1021 }
1022 }
1023 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001024 }
1025 }
1026 }
1027 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00001028 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001029}
1030
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001031uint32_t
1032SymbolFileDWARF::GetNumCompileUnits()
1033{
1034 DWARFDebugInfo* info = DebugInfo();
1035 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001036 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001037 return 0;
1038}
1039
1040CompUnitSP
1041SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
1042{
Greg Clayton53eb1c22012-04-02 22:59:12 +00001043 CompUnitSP cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001044 DWARFDebugInfo* info = DebugInfo();
1045 if (info)
1046 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00001047 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
1048 if (dwarf_cu)
1049 cu_sp = ParseCompileUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001050 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00001051 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001052}
1053
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001054Function *
Greg Clayton0fffff52010-09-24 05:15:53 +00001055SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001056{
1057 DWARFDebugRanges::RangeList func_ranges;
1058 const char *name = NULL;
1059 const char *mangled = NULL;
1060 int decl_file = 0;
1061 int decl_line = 0;
1062 int decl_column = 0;
1063 int call_file = 0;
1064 int call_line = 0;
1065 int call_column = 0;
1066 DWARFExpression frame_base;
1067
Greg Claytonc93237c2010-10-01 20:48:32 +00001068 assert (die->Tag() == DW_TAG_subprogram);
1069
1070 if (die->Tag() != DW_TAG_subprogram)
1071 return NULL;
1072
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001073 if (die->GetDIENamesAndRanges (this,
1074 dwarf_cu,
1075 name,
1076 mangled,
1077 func_ranges,
1078 decl_file,
1079 decl_line,
1080 decl_column,
1081 call_file,
1082 call_line,
1083 call_column,
1084 &frame_base))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001085 {
1086 // Union of all ranges in the function DIE (if the function is discontiguous)
1087 AddressRange func_range;
Greg Claytonea3e7d52011-10-08 00:49:15 +00001088 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0);
1089 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001090 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
1091 {
Michael Sartaina7499c92013-07-01 19:45:50 +00001092 ModuleSP module_sp (m_obj_file->GetModule());
Greg Clayton3046e662013-07-10 01:23:25 +00001093 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, module_sp->GetSectionList());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001094 if (func_range.GetBaseAddress().IsValid())
1095 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
1096 }
1097
1098 if (func_range.GetBaseAddress().IsValid())
1099 {
1100 Mangled func_name;
1101 if (mangled)
Greg Clayton037520e2012-07-18 23:18:10 +00001102 func_name.SetValue(ConstString(mangled), true);
Siva Chandra462722d2015-03-27 00:10:04 +00001103 else if (die->GetParent()->Tag() == DW_TAG_compile_unit &&
1104 LanguageRuntime::LanguageIsCPlusPlus(dwarf_cu->GetLanguageType()) &&
1105 strcmp(name, "main") != 0)
1106 {
1107 // If the mangled name is not present in the DWARF, generate the demangled name
1108 // using the decl context. We skip if the function is "main" as its name is
1109 // never mangled.
1110 bool is_static = false;
1111 bool is_variadic = false;
1112 unsigned type_quals = 0;
1113 std::vector<ClangASTType> param_types;
1114 std::vector<clang::ParmVarDecl*> param_decls;
1115 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
1116 DWARFDeclContext decl_ctx;
1117 StreamString sstr;
1118
1119 die->GetDWARFDeclContext(this, dwarf_cu, decl_ctx);
1120 sstr << decl_ctx.GetQualifiedName();
1121
1122 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE(dwarf_cu,
1123 die,
1124 &decl_ctx_die);
1125 ParseChildParameters(sc,
1126 containing_decl_ctx,
1127 dwarf_cu,
1128 die,
1129 true,
1130 is_static,
1131 is_variadic,
1132 param_types,
1133 param_decls,
1134 type_quals);
1135 sstr << "(";
1136 for (size_t i = 0; i < param_types.size(); i++)
1137 {
1138 if (i > 0)
1139 sstr << ", ";
1140 sstr << param_types[i].GetTypeName();
1141 }
1142 if (is_variadic)
1143 sstr << ", ...";
1144 sstr << ")";
1145 if (type_quals & clang::Qualifiers::Const)
1146 sstr << " const";
1147
1148 func_name.SetValue(ConstString(sstr.GetData()), false);
1149 }
1150 else
Greg Clayton037520e2012-07-18 23:18:10 +00001151 func_name.SetValue(ConstString(name), false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001152
1153 FunctionSP func_sp;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001154 std::unique_ptr<Declaration> decl_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001155 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +00001156 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1157 decl_line,
1158 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001159
Greg Clayton0bd4e1b2011-09-30 20:52:25 +00001160 // Supply the type _only_ if it has already been parsed
Greg Clayton594e5ed2010-09-27 21:07:38 +00001161 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001162
1163 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
1164
Greg Clayton9422dd62013-03-04 21:46:16 +00001165 if (FixupAddress (func_range.GetBaseAddress()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001166 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001167 const user_id_t func_user_id = MakeUserID(die->GetOffset());
1168 func_sp.reset(new Function (sc.comp_unit,
1169 MakeUserID(func_user_id), // UserID is the DIE offset
1170 MakeUserID(func_user_id),
1171 func_name,
1172 func_type,
1173 func_range)); // first address range
1174
1175 if (func_sp.get() != NULL)
1176 {
1177 if (frame_base.IsValid())
1178 func_sp->GetFrameBaseExpression() = frame_base;
1179 sc.comp_unit->AddFunction(func_sp);
1180 return func_sp.get();
1181 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001182 }
1183 }
1184 }
1185 return NULL;
1186}
1187
Greg Clayton9422dd62013-03-04 21:46:16 +00001188bool
1189SymbolFileDWARF::FixupAddress (Address &addr)
1190{
1191 SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile ();
1192 if (debug_map_symfile)
1193 {
1194 return debug_map_symfile->LinkOSOAddress(addr);
1195 }
1196 // This is a normal DWARF file, no address fixups need to happen
1197 return true;
1198}
Greg Clayton1f746072012-08-29 21:13:06 +00001199lldb::LanguageType
1200SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc)
1201{
1202 assert (sc.comp_unit);
1203 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1204 if (dwarf_cu)
1205 {
1206 const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly();
Jim Ingham28eb5712012-10-12 17:34:26 +00001207 if (die)
1208 {
1209 const uint32_t language = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
1210 if (language)
1211 return (lldb::LanguageType)language;
1212 }
Greg Clayton1f746072012-08-29 21:13:06 +00001213 }
1214 return eLanguageTypeUnknown;
1215}
1216
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001217size_t
1218SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
1219{
1220 assert (sc.comp_unit);
1221 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00001222 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001223 if (dwarf_cu)
1224 {
1225 DWARFDIECollection function_dies;
Greg Clayton1f746072012-08-29 21:13:06 +00001226 const size_t num_functions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001227 size_t func_idx;
Greg Clayton1f746072012-08-29 21:13:06 +00001228 for (func_idx = 0; func_idx < num_functions; ++func_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001229 {
1230 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
Greg Clayton81c22f62011-10-19 18:09:39 +00001231 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001232 {
1233 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
1234 ++functions_added;
1235 }
1236 }
1237 //FixupTypes();
1238 }
1239 return functions_added;
1240}
1241
1242bool
1243SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
1244{
1245 assert (sc.comp_unit);
Greg Clayton1f746072012-08-29 21:13:06 +00001246 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Greg Claytonda2455b2012-11-01 17:28:37 +00001247 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001248 {
Greg Claytonda2455b2012-11-01 17:28:37 +00001249 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001250
Greg Claytonda2455b2012-11-01 17:28:37 +00001251 if (cu_die)
1252 {
1253 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
Matthew Gardinere81df3b2014-08-26 06:57:23 +00001254
1255 // DWARF2/3 suggests the form hostname:pathname for compilation directory.
1256 // Remove the host part if present.
1257 cu_comp_dir = removeHostnameFromPathname(cu_comp_dir);
1258
Greg Claytonda2455b2012-11-01 17:28:37 +00001259 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 +00001260
Greg Claytonda2455b2012-11-01 17:28:37 +00001261 // All file indexes in DWARF are one based and a file of index zero is
1262 // supposed to be the compile unit itself.
1263 support_files.Append (*sc.comp_unit);
1264
1265 return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
1266 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001267 }
1268 return false;
1269}
1270
Sean Callananf0c5aeb2015-04-20 16:31:29 +00001271bool
1272SymbolFileDWARF::ParseImportedModules (const lldb_private::SymbolContext &sc, std::vector<lldb_private::ConstString> &imported_modules)
1273{
1274 assert (sc.comp_unit);
1275 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1276 if (dwarf_cu)
1277 {
1278 if (ClangModulesDeclVendor::LanguageSupportsClangModules(sc.comp_unit->GetLanguage()))
1279 {
1280 UpdateExternalModuleListIfNeeded();
1281 for (const std::pair<uint64_t, const ClangModuleInfo> &external_type_module : m_external_type_modules)
1282 {
1283 imported_modules.push_back(external_type_module.second.m_name);
1284 }
1285 }
1286 }
1287 return false;
1288}
1289
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001290struct ParseDWARFLineTableCallbackInfo
1291{
1292 LineTable* line_table;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001293 std::unique_ptr<LineSequence> sequence_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001294};
1295
1296//----------------------------------------------------------------------
1297// ParseStatementTableCallback
1298//----------------------------------------------------------------------
1299static void
1300ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
1301{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001302 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
1303 {
1304 // Just started parsing the line table
1305 }
1306 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
1307 {
1308 // Done parsing line table, nothing to do for the cleanup
1309 }
1310 else
1311 {
1312 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
Greg Clayton9422dd62013-03-04 21:46:16 +00001313 LineTable* line_table = info->line_table;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001314
Greg Clayton9422dd62013-03-04 21:46:16 +00001315 // If this is our first time here, we need to create a
1316 // sequence container.
1317 if (!info->sequence_ap.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001318 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001319 info->sequence_ap.reset(line_table->CreateLineSequenceContainer());
1320 assert(info->sequence_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001321 }
Greg Clayton9422dd62013-03-04 21:46:16 +00001322 line_table->AppendLineEntryToSequence (info->sequence_ap.get(),
1323 state.address,
1324 state.line,
1325 state.column,
1326 state.file,
1327 state.is_stmt,
1328 state.basic_block,
1329 state.prologue_end,
1330 state.epilogue_begin,
1331 state.end_sequence);
1332 if (state.end_sequence)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001333 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001334 // First, put the current sequence into the line table.
1335 line_table->InsertSequence(info->sequence_ap.get());
1336 // Then, empty it to prepare for the next sequence.
1337 info->sequence_ap->Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001338 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001339 }
1340}
1341
1342bool
1343SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1344{
1345 assert (sc.comp_unit);
1346 if (sc.comp_unit->GetLineTable() != NULL)
1347 return true;
1348
Greg Clayton1f746072012-08-29 21:13:06 +00001349 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001350 if (dwarf_cu)
1351 {
1352 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Greg Clayton129d12c2011-11-28 03:29:03 +00001353 if (dwarf_cu_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001354 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001355 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1356 if (cu_line_offset != DW_INVALID_OFFSET)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001357 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001358 std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
Greg Clayton129d12c2011-11-28 03:29:03 +00001359 if (line_table_ap.get())
1360 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001361 ParseDWARFLineTableCallbackInfo info;
1362 info.line_table = line_table_ap.get();
Greg Claytonc7bece562013-01-25 18:06:21 +00001363 lldb::offset_t offset = cu_line_offset;
Greg Clayton129d12c2011-11-28 03:29:03 +00001364 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
Greg Clayton9422dd62013-03-04 21:46:16 +00001365 if (m_debug_map_symfile)
1366 {
1367 // We have an object file that has a line table with addresses
1368 // that are not linked. We need to link the line table and convert
1369 // the addresses that are relative to the .o file into addresses
1370 // for the main executable.
1371 sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get()));
1372 }
1373 else
1374 {
1375 sc.comp_unit->SetLineTable(line_table_ap.release());
1376 return true;
1377 }
Greg Clayton129d12c2011-11-28 03:29:03 +00001378 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001379 }
1380 }
1381 }
1382 return false;
1383}
1384
1385size_t
1386SymbolFileDWARF::ParseFunctionBlocks
1387(
1388 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001389 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001390 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001391 const DWARFDebugInfoEntry *die,
1392 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001393 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001394)
1395{
1396 size_t blocks_added = 0;
1397 while (die != NULL)
1398 {
1399 dw_tag_t tag = die->Tag();
1400
1401 switch (tag)
1402 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001403 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001404 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001405 case DW_TAG_lexical_block:
1406 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001407 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001408 if (tag == DW_TAG_subprogram)
1409 {
1410 // Skip any DW_TAG_subprogram DIEs that are inside
1411 // of a normal or inlined functions. These will be
1412 // parsed on their own as separate entities.
1413
1414 if (depth > 0)
1415 break;
1416
1417 block = parent_block;
1418 }
1419 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001420 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001421 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001422 parent_block->AddChild(block_sp);
1423 block = block_sp.get();
1424 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001425 DWARFDebugRanges::RangeList ranges;
1426 const char *name = NULL;
1427 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001428
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001429 int decl_file = 0;
1430 int decl_line = 0;
1431 int decl_column = 0;
1432 int call_file = 0;
1433 int call_line = 0;
1434 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001435 if (die->GetDIENamesAndRanges (this,
1436 dwarf_cu,
1437 name,
1438 mangled_name,
1439 ranges,
1440 decl_file, decl_line, decl_column,
1441 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001442 {
1443 if (tag == DW_TAG_subprogram)
1444 {
1445 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001446 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001447 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001448 else if (tag == DW_TAG_inlined_subroutine)
1449 {
1450 // We get called here for inlined subroutines in two ways.
1451 // The first time is when we are making the Function object
1452 // for this inlined concrete instance. Since we're creating a top level block at
1453 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1454 // adjust the containing address.
1455 // The second time is when we are parsing the blocks inside the function that contains
1456 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1457 // function the offset will be for that function.
1458 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1459 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001460 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001461 }
1462 }
Greg Clayton103f3092015-01-15 03:04:37 +00001463
1464 const size_t num_ranges = ranges.GetSize();
1465 for (size_t i = 0; i<num_ranges; ++i)
1466 {
1467 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i);
1468 const addr_t range_base = range.GetRangeBase();
1469 if (range_base >= subprogram_low_pc)
1470 block->AddRange(Block::Range (range_base - subprogram_low_pc, range.GetByteSize()));
1471 else
1472 {
1473 GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": adding range [0x%" PRIx64 "-0x%" PRIx64 ") which has a base that is less than the function's low PC 0x%" PRIx64 ". Please file a bug and attach the file at the start of this error message",
1474 block->GetID(),
1475 range_base,
1476 range.GetRangeEnd(),
1477 subprogram_low_pc);
1478 }
1479 }
1480 block->FinalizeRanges ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001481
1482 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1483 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001484 std::unique_ptr<Declaration> decl_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001485 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001486 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1487 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001488
Greg Clayton7b0992d2013-04-18 22:45:39 +00001489 std::unique_ptr<Declaration> call_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001490 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001491 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1492 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001493
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001494 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001495 }
1496
1497 ++blocks_added;
1498
Greg Claytondd7feaf2011-08-12 17:54:33 +00001499 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001500 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001501 blocks_added += ParseFunctionBlocks (sc,
1502 block,
1503 dwarf_cu,
1504 die->GetFirstChild(),
1505 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001506 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001507 }
1508 }
1509 }
1510 break;
1511 default:
1512 break;
1513 }
1514
Greg Claytondd7feaf2011-08-12 17:54:33 +00001515 // Only parse siblings of the block if we are not at depth zero. A depth
1516 // of zero indicates we are currently parsing the top level
1517 // DW_TAG_subprogram DIE
1518
1519 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001520 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001521 else
1522 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001523 }
1524 return blocks_added;
1525}
1526
Greg Claytonf0705c82011-10-22 03:33:13 +00001527bool
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001528SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu,
1529 const DWARFDebugInfoEntry *die,
1530 ClangASTContext::TemplateParameterInfos &template_param_infos)
1531{
1532 const dw_tag_t tag = die->Tag();
1533
1534 switch (tag)
1535 {
1536 case DW_TAG_template_type_parameter:
1537 case DW_TAG_template_value_parameter:
1538 {
Todd Fialaee8bfc62014-09-11 17:29:12 +00001539 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001540
1541 DWARFDebugInfoEntry::Attributes attributes;
1542 const size_t num_attributes = die->GetAttributes (this,
1543 dwarf_cu,
1544 fixed_form_sizes,
1545 attributes);
1546 const char *name = NULL;
1547 Type *lldb_type = NULL;
Greg Clayton57ee3062013-07-11 22:46:58 +00001548 ClangASTType clang_type;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001549 uint64_t uval64 = 0;
1550 bool uval64_valid = false;
1551 if (num_attributes > 0)
1552 {
1553 DWARFFormValue form_value;
1554 for (size_t i=0; i<num_attributes; ++i)
1555 {
1556 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1557
1558 switch (attr)
1559 {
1560 case DW_AT_name:
1561 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1562 name = form_value.AsCString(&get_debug_str_data());
1563 break;
1564
1565 case DW_AT_type:
1566 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1567 {
Greg Clayton54166af2014-11-22 01:58:59 +00001568 const dw_offset_t type_die_offset = form_value.Reference();
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001569 lldb_type = ResolveTypeUID(type_die_offset);
1570 if (lldb_type)
1571 clang_type = lldb_type->GetClangForwardType();
1572 }
1573 break;
1574
1575 case DW_AT_const_value:
1576 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1577 {
1578 uval64_valid = true;
1579 uval64 = form_value.Unsigned();
1580 }
1581 break;
1582 default:
1583 break;
1584 }
1585 }
1586
Greg Clayton283b2652013-04-23 22:38:02 +00001587 clang::ASTContext *ast = GetClangASTContext().getASTContext();
1588 if (!clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00001589 clang_type = GetClangASTContext().GetBasicType(eBasicTypeVoid);
Greg Clayton283b2652013-04-23 22:38:02 +00001590
1591 if (clang_type)
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001592 {
1593 bool is_signed = false;
Greg Clayton283b2652013-04-23 22:38:02 +00001594 if (name && name[0])
1595 template_param_infos.names.push_back(name);
1596 else
1597 template_param_infos.names.push_back(NULL);
1598
Greg Clayton283b2652013-04-23 22:38:02 +00001599 if (tag == DW_TAG_template_value_parameter &&
1600 lldb_type != NULL &&
Greg Clayton57ee3062013-07-11 22:46:58 +00001601 clang_type.IsIntegerType (is_signed) &&
Greg Clayton283b2652013-04-23 22:38:02 +00001602 uval64_valid)
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001603 {
1604 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
Greg Clayton283b2652013-04-23 22:38:02 +00001605 template_param_infos.args.push_back (clang::TemplateArgument (*ast,
Sean Callanan3d654b32012-09-24 22:25:51 +00001606 llvm::APSInt(apint),
Greg Clayton57ee3062013-07-11 22:46:58 +00001607 clang_type.GetQualType()));
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001608 }
1609 else
1610 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001611 template_param_infos.args.push_back (clang::TemplateArgument (clang_type.GetQualType()));
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001612 }
1613 }
1614 else
1615 {
1616 return false;
1617 }
1618
1619 }
1620 }
1621 return true;
1622
1623 default:
1624 break;
1625 }
1626 return false;
1627}
1628
1629bool
Greg Claytonf0705c82011-10-22 03:33:13 +00001630SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1631 const DWARFDebugInfoEntry *parent_die,
1632 ClangASTContext::TemplateParameterInfos &template_param_infos)
1633{
1634
1635 if (parent_die == NULL)
Filipe Cabecinhas52008c62012-05-23 16:24:11 +00001636 return false;
Greg Claytonf0705c82011-10-22 03:33:13 +00001637
Greg Claytonf0705c82011-10-22 03:33:13 +00001638 Args template_parameter_names;
1639 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1640 die != NULL;
1641 die = die->GetSibling())
1642 {
1643 const dw_tag_t tag = die->Tag();
1644
1645 switch (tag)
1646 {
1647 case DW_TAG_template_type_parameter:
1648 case DW_TAG_template_value_parameter:
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001649 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Claytonf0705c82011-10-22 03:33:13 +00001650 break;
1651
1652 default:
1653 break;
1654 }
1655 }
1656 if (template_param_infos.args.empty())
1657 return false;
1658 return template_param_infos.args.size() == template_param_infos.names.size();
1659}
1660
1661clang::ClassTemplateDecl *
1662SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001663 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001664 const char *parent_name,
1665 int tag_decl_kind,
1666 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1667{
1668 if (template_param_infos.IsValid())
1669 {
1670 std::string template_basename(parent_name);
1671 template_basename.erase (template_basename.find('<'));
1672 ClangASTContext &ast = GetClangASTContext();
1673
1674 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001675 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001676 template_basename.c_str(),
1677 tag_decl_kind,
1678 template_param_infos);
1679 }
1680 return NULL;
1681}
1682
Sean Callanana0b80ab2012-06-04 22:28:05 +00001683class SymbolFileDWARF::DelayedAddObjCClassProperty
1684{
1685public:
1686 DelayedAddObjCClassProperty
1687 (
Greg Clayton57ee3062013-07-11 22:46:58 +00001688 const ClangASTType &class_opaque_type,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001689 const char *property_name,
Greg Clayton57ee3062013-07-11 22:46:58 +00001690 const ClangASTType &property_opaque_type, // The property type is only required if you don't have an ivar decl
Sean Callanana0b80ab2012-06-04 22:28:05 +00001691 clang::ObjCIvarDecl *ivar_decl,
1692 const char *property_setter_name,
1693 const char *property_getter_name,
1694 uint32_t property_attributes,
Greg Claytonc4ffd662013-03-08 01:37:30 +00001695 const ClangASTMetadata *metadata
Sean Callanana0b80ab2012-06-04 22:28:05 +00001696 ) :
Sean Callanana0b80ab2012-06-04 22:28:05 +00001697 m_class_opaque_type (class_opaque_type),
1698 m_property_name (property_name),
1699 m_property_opaque_type (property_opaque_type),
1700 m_ivar_decl (ivar_decl),
1701 m_property_setter_name (property_setter_name),
1702 m_property_getter_name (property_getter_name),
Jim Ingham379397632012-10-27 02:54:13 +00001703 m_property_attributes (property_attributes)
Sean Callanana0b80ab2012-06-04 22:28:05 +00001704 {
Jim Ingham379397632012-10-27 02:54:13 +00001705 if (metadata != NULL)
1706 {
1707 m_metadata_ap.reset(new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001708 *m_metadata_ap = *metadata;
Jim Ingham379397632012-10-27 02:54:13 +00001709 }
1710 }
1711
1712 DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs)
1713 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001714 *this = rhs;
Daniel Malead4c5be62012-11-12 21:02:14 +00001715 }
1716
1717 DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs)
1718 {
Jim Ingham379397632012-10-27 02:54:13 +00001719 m_class_opaque_type = rhs.m_class_opaque_type;
1720 m_property_name = rhs.m_property_name;
1721 m_property_opaque_type = rhs.m_property_opaque_type;
1722 m_ivar_decl = rhs.m_ivar_decl;
1723 m_property_setter_name = rhs.m_property_setter_name;
1724 m_property_getter_name = rhs.m_property_getter_name;
1725 m_property_attributes = rhs.m_property_attributes;
1726
1727 if (rhs.m_metadata_ap.get())
1728 {
1729 m_metadata_ap.reset (new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001730 *m_metadata_ap = *rhs.m_metadata_ap;
Jim Ingham379397632012-10-27 02:54:13 +00001731 }
Daniel Malead4c5be62012-11-12 21:02:14 +00001732 return *this;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001733 }
1734
Greg Clayton57ee3062013-07-11 22:46:58 +00001735 bool
1736 Finalize()
Sean Callanana0b80ab2012-06-04 22:28:05 +00001737 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001738 return m_class_opaque_type.AddObjCClassProperty (m_property_name,
1739 m_property_opaque_type,
1740 m_ivar_decl,
1741 m_property_setter_name,
1742 m_property_getter_name,
1743 m_property_attributes,
1744 m_metadata_ap.get());
Sean Callanana0b80ab2012-06-04 22:28:05 +00001745 }
1746private:
Greg Clayton57ee3062013-07-11 22:46:58 +00001747 ClangASTType m_class_opaque_type;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001748 const char *m_property_name;
Greg Clayton57ee3062013-07-11 22:46:58 +00001749 ClangASTType m_property_opaque_type;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001750 clang::ObjCIvarDecl *m_ivar_decl;
1751 const char *m_property_setter_name;
1752 const char *m_property_getter_name;
1753 uint32_t m_property_attributes;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001754 std::unique_ptr<ClangASTMetadata> m_metadata_ap;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001755};
1756
Sean Callananfaa0bb32012-12-05 23:37:14 +00001757struct BitfieldInfo
1758{
1759 uint64_t bit_size;
1760 uint64_t bit_offset;
1761
1762 BitfieldInfo () :
1763 bit_size (LLDB_INVALID_ADDRESS),
1764 bit_offset (LLDB_INVALID_ADDRESS)
1765 {
1766 }
1767
Greg Clayton78f4d952013-12-11 23:10:39 +00001768 void
1769 Clear()
1770 {
1771 bit_size = LLDB_INVALID_ADDRESS;
1772 bit_offset = LLDB_INVALID_ADDRESS;
1773 }
1774
Sean Callananfaa0bb32012-12-05 23:37:14 +00001775 bool IsValid ()
1776 {
1777 return (bit_size != LLDB_INVALID_ADDRESS) &&
1778 (bit_offset != LLDB_INVALID_ADDRESS);
1779 }
1780};
1781
Greg Claytonc4ffd662013-03-08 01:37:30 +00001782
1783bool
1784SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu,
1785 const DWARFDebugInfoEntry *parent_die)
1786{
1787 if (parent_die)
1788 {
1789 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1790 {
1791 dw_tag_t tag = die->Tag();
1792 bool check_virtuality = false;
1793 switch (tag)
1794 {
1795 case DW_TAG_inheritance:
1796 case DW_TAG_subprogram:
1797 check_virtuality = true;
1798 break;
1799 default:
1800 break;
1801 }
1802 if (check_virtuality)
1803 {
1804 if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0)
1805 return true;
1806 }
1807 }
1808 }
1809 return false;
1810}
1811
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001812size_t
1813SymbolFileDWARF::ParseChildMembers
1814(
1815 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001816 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001817 const DWARFDebugInfoEntry *parent_die,
Greg Clayton57ee3062013-07-11 22:46:58 +00001818 ClangASTType &class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001819 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001820 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1821 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001822 DWARFDIECollection& member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001823 DelayedPropertyList& delayed_properties,
Sean Callananc7fbf732010-08-06 00:32:49 +00001824 AccessType& default_accessibility,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001825 bool &is_a_class,
1826 LayoutInfo &layout_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001827)
1828{
1829 if (parent_die == NULL)
1830 return 0;
1831
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001832 size_t count = 0;
1833 const DWARFDebugInfoEntry *die;
Todd Fialaee8bfc62014-09-11 17:29:12 +00001834 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001835 uint32_t member_idx = 0;
Sean Callananfaa0bb32012-12-05 23:37:14 +00001836 BitfieldInfo last_field_info;
Richard Mitton0a558352013-10-17 21:14:00 +00001837 ModuleSP module = GetObjectFile()->GetModule();
Greg Claytond88d7592010-09-15 08:33:30 +00001838
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001839 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1840 {
1841 dw_tag_t tag = die->Tag();
1842
1843 switch (tag)
1844 {
1845 case DW_TAG_member:
Sean Callanan3d654b32012-09-24 22:25:51 +00001846 case DW_TAG_APPLE_property:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001847 {
1848 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001849 const size_t num_attributes = die->GetAttributes (this,
1850 dwarf_cu,
1851 fixed_form_sizes,
1852 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001853 if (num_attributes > 0)
1854 {
1855 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001856 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001857 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001858 const char *prop_name = NULL;
1859 const char *prop_getter_name = NULL;
1860 const char *prop_setter_name = NULL;
Greg Claytone528efd72013-02-26 23:45:18 +00001861 uint32_t prop_attributes = 0;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001862
1863
Greg Clayton24739922010-10-13 03:15:28 +00001864 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001865 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001866 AccessType accessibility = eAccessNone;
Greg Claytoncaab74e2012-01-28 00:48:57 +00001867 uint32_t member_byte_offset = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001868 size_t byte_size = 0;
1869 size_t bit_offset = 0;
1870 size_t bit_size = 0;
Greg Claytone528efd72013-02-26 23:45:18 +00001871 bool is_external = false; // On DW_TAG_members, this means the member is static
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001872 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001873 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001874 {
1875 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1876 DWARFFormValue form_value;
1877 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1878 {
1879 switch (attr)
1880 {
1881 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1882 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1883 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1884 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00001885 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001886 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1887 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1888 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1889 case DW_AT_data_member_location:
Greg Claytoncaab74e2012-01-28 00:48:57 +00001890 if (form_value.BlockData())
1891 {
1892 Value initialValue(0);
1893 Value memberOffset(0);
Ed Masteeeae7212013-10-24 20:43:47 +00001894 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Claytoncaab74e2012-01-28 00:48:57 +00001895 uint32_t block_length = form_value.Unsigned();
1896 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1897 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
Greg Claytoncaab74e2012-01-28 00:48:57 +00001898 NULL, // ClangExpressionVariableList *
1899 NULL, // ClangExpressionDeclMap *
1900 NULL, // RegisterContext *
Richard Mitton0a558352013-10-17 21:14:00 +00001901 module,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001902 debug_info_data,
1903 block_offset,
1904 block_length,
1905 eRegisterKindDWARF,
1906 &initialValue,
1907 memberOffset,
1908 NULL))
1909 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001910 member_byte_offset = memberOffset.ResolveValue(NULL).UInt();
Greg Claytoncaab74e2012-01-28 00:48:57 +00001911 }
1912 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00001913 else
1914 {
1915 // With DWARF 3 and later, if the value is an integer constant,
1916 // this form value is the offset in bytes from the beginning
1917 // of the containing entity.
1918 member_byte_offset = form_value.Unsigned();
1919 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001920 break;
1921
Greg Clayton8cf05932010-07-22 18:30:50 +00001922 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00001923 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001924 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1925 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1926 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1927 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00001928 case DW_AT_external: is_external = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001929
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001930 default:
Greg Clayton1b02c172012-03-14 21:00:47 +00001931 case DW_AT_declaration:
1932 case DW_AT_description:
1933 case DW_AT_mutable:
1934 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001935 case DW_AT_sibling:
1936 break;
1937 }
1938 }
1939 }
Sean Callanana6582262012-04-05 00:12:52 +00001940
1941 if (prop_name)
Sean Callanan751aac62012-03-29 19:07:06 +00001942 {
Sean Callanana6582262012-04-05 00:12:52 +00001943 ConstString fixed_getter;
1944 ConstString fixed_setter;
1945
1946 // Check if the property getter/setter were provided as full
1947 // names. We want basenames, so we extract them.
1948
1949 if (prop_getter_name && prop_getter_name[0] == '-')
1950 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001951 ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true);
1952 prop_getter_name = prop_getter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001953 }
1954
1955 if (prop_setter_name && prop_setter_name[0] == '-')
1956 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001957 ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true);
1958 prop_setter_name = prop_setter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001959 }
1960
1961 // If the names haven't been provided, they need to be
1962 // filled in.
1963
1964 if (!prop_getter_name)
1965 {
1966 prop_getter_name = prop_name;
1967 }
1968 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly))
1969 {
1970 StreamString ss;
1971
1972 ss.Printf("set%c%s:",
1973 toupper(prop_name[0]),
1974 &prop_name[1]);
1975
1976 fixed_setter.SetCString(ss.GetData());
1977 prop_setter_name = fixed_setter.GetCString();
1978 }
Sean Callanan751aac62012-03-29 19:07:06 +00001979 }
1980
1981 // Clang has a DWARF generation bug where sometimes it
Greg Clayton44953932011-10-25 01:25:35 +00001982 // represents fields that are references with bad byte size
1983 // and bit size/offset information such as:
1984 //
1985 // DW_AT_byte_size( 0x00 )
1986 // DW_AT_bit_size( 0x40 )
1987 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1988 //
1989 // So check the bit offset to make sure it is sane, and if
1990 // the values are not sane, remove them. If we don't do this
1991 // then we will end up with a crash if we try to use this
1992 // type in an expression when clang becomes unhappy with its
1993 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001994
Greg Clayton44953932011-10-25 01:25:35 +00001995 if (bit_offset > 128)
1996 {
1997 bit_size = 0;
1998 bit_offset = 0;
1999 }
2000
2001 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00002002 if (class_language == eLanguageTypeObjC ||
2003 class_language == eLanguageTypeObjC_plus_plus)
2004 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00002005
2006 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
2007 {
2008 // Not all compilers will mark the vtable pointer
2009 // member as artificial (llvm-gcc). We can't have
2010 // the virtual members in our classes otherwise it
2011 // throws off all child offsets since we end up
2012 // having and extra pointer sized member in our
2013 // class layouts.
2014 is_artificial = true;
2015 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002016
Greg Clayton29659712013-07-12 20:08:35 +00002017 // Handle static members
Greg Claytone528efd72013-02-26 23:45:18 +00002018 if (is_external && member_byte_offset == UINT32_MAX)
Greg Clayton973b6c92013-04-11 16:57:51 +00002019 {
2020 Type *var_type = ResolveTypeUID(encoding_uid);
2021
2022 if (var_type)
2023 {
Greg Clayton29659712013-07-12 20:08:35 +00002024 if (accessibility == eAccessNone)
2025 accessibility = eAccessPublic;
Greg Clayton57ee3062013-07-11 22:46:58 +00002026 class_clang_type.AddVariableToRecordType (name,
2027 var_type->GetClangLayoutType(),
2028 accessibility);
Greg Clayton973b6c92013-04-11 16:57:51 +00002029 }
Greg Claytone528efd72013-02-26 23:45:18 +00002030 break;
Greg Clayton973b6c92013-04-11 16:57:51 +00002031 }
Greg Claytone528efd72013-02-26 23:45:18 +00002032
Greg Clayton24739922010-10-13 03:15:28 +00002033 if (is_artificial == false)
2034 {
2035 Type *member_type = ResolveTypeUID(encoding_uid);
Sean Callananfa3ab452012-12-14 00:54:13 +00002036
Jim Inghame3ae82a2011-11-12 01:36:43 +00002037 clang::FieldDecl *field_decl = NULL;
Sean Callanan751aac62012-03-29 19:07:06 +00002038 if (tag == DW_TAG_member)
Greg Claytond16e1e52011-07-12 17:06:17 +00002039 {
Sean Callanan751aac62012-03-29 19:07:06 +00002040 if (member_type)
2041 {
2042 if (accessibility == eAccessNone)
2043 accessibility = default_accessibility;
2044 member_accessibilities.push_back(accessibility);
Sean Callananfaa0bb32012-12-05 23:37:14 +00002045
Greg Clayton78f4d952013-12-11 23:10:39 +00002046 uint64_t field_bit_offset = (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
2047 if (bit_size > 0)
Greg Clayton88bc7f32012-11-06 00:20:41 +00002048 {
Greg Clayton78f4d952013-12-11 23:10:39 +00002049
2050 BitfieldInfo this_field_info;
2051 this_field_info.bit_offset = field_bit_offset;
2052 this_field_info.bit_size = bit_size;
2053
Sean Callananfaa0bb32012-12-05 23:37:14 +00002054 /////////////////////////////////////////////////////////////
2055 // How to locate a field given the DWARF debug information
2056 //
2057 // AT_byte_size indicates the size of the word in which the
2058 // bit offset must be interpreted.
2059 //
2060 // AT_data_member_location indicates the byte offset of the
2061 // word from the base address of the structure.
2062 //
2063 // AT_bit_offset indicates how many bits into the word
2064 // (according to the host endianness) the low-order bit of
2065 // the field starts. AT_bit_offset can be negative.
2066 //
2067 // AT_bit_size indicates the size of the field in bits.
2068 /////////////////////////////////////////////////////////////
2069
Greg Clayton78f4d952013-12-11 23:10:39 +00002070 if (byte_size == 0)
2071 byte_size = member_type->GetByteSize();
2072
Sean Callananfaa0bb32012-12-05 23:37:14 +00002073 if (GetObjectFile()->GetByteOrder() == eByteOrderLittle)
2074 {
2075 this_field_info.bit_offset += byte_size * 8;
2076 this_field_info.bit_offset -= (bit_offset + bit_size);
2077 }
2078 else
2079 {
2080 this_field_info.bit_offset += bit_offset;
2081 }
Greg Clayton78f4d952013-12-11 23:10:39 +00002082
2083 // Update the field bit offset we will report for layout
2084 field_bit_offset = this_field_info.bit_offset;
Sean Callananfaa0bb32012-12-05 23:37:14 +00002085
Greg Clayton78f4d952013-12-11 23:10:39 +00002086 // If the member to be emitted did not start on a character boundary and there is
2087 // empty space between the last field and this one, then we need to emit an
2088 // anonymous member filling up the space up to its start. There are three cases
2089 // here:
2090 //
2091 // 1 If the previous member ended on a character boundary, then we can emit an
2092 // anonymous member starting at the most recent character boundary.
2093 //
2094 // 2 If the previous member did not end on a character boundary and the distance
2095 // from the end of the previous member to the current member is less than a
2096 // word width, then we can emit an anonymous member starting right after the
2097 // previous member and right before this member.
2098 //
2099 // 3 If the previous member did not end on a character boundary and the distance
2100 // from the end of the previous member to the current member is greater than
2101 // or equal a word width, then we act as in Case 1.
2102
2103 const uint64_t character_width = 8;
2104 const uint64_t word_width = 32;
2105
Sean Callananfaa0bb32012-12-05 23:37:14 +00002106 // Objective-C has invalid DW_AT_bit_offset values in older versions
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +00002107 // of clang, so we have to be careful and only insert unnamed bitfields
Greg Clayton37c36e42012-11-27 00:59:26 +00002108 // if we have a new enough clang.
2109 bool detect_unnamed_bitfields = true;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002110
Greg Clayton37c36e42012-11-27 00:59:26 +00002111 if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus)
2112 detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields ();
2113
2114 if (detect_unnamed_bitfields)
Greg Clayton88bc7f32012-11-06 00:20:41 +00002115 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00002116 BitfieldInfo anon_field_info;
2117
2118 if ((this_field_info.bit_offset % character_width) != 0) // not char aligned
Greg Clayton88bc7f32012-11-06 00:20:41 +00002119 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00002120 uint64_t last_field_end = 0;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002121
Sean Callananfaa0bb32012-12-05 23:37:14 +00002122 if (last_field_info.IsValid())
2123 last_field_end = last_field_info.bit_offset + last_field_info.bit_size;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002124
Sean Callananfaa0bb32012-12-05 23:37:14 +00002125 if (this_field_info.bit_offset != last_field_end)
2126 {
2127 if (((last_field_end % character_width) == 0) || // case 1
2128 (this_field_info.bit_offset - last_field_end >= word_width)) // case 3
2129 {
2130 anon_field_info.bit_size = this_field_info.bit_offset % character_width;
2131 anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size;
2132 }
2133 else // case 2
2134 {
2135 anon_field_info.bit_size = this_field_info.bit_offset - last_field_end;
2136 anon_field_info.bit_offset = last_field_end;
2137 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00002138 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00002139 }
2140
Sean Callananfaa0bb32012-12-05 23:37:14 +00002141 if (anon_field_info.IsValid())
Greg Clayton88bc7f32012-11-06 00:20:41 +00002142 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002143 clang::FieldDecl *unnamed_bitfield_decl = class_clang_type.AddFieldToRecordType (NULL,
2144 GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width),
2145 accessibility,
2146 anon_field_info.bit_size);
Zachary Turner504f38d2015-03-24 16:24:50 +00002147
Zachary Turnera98fac22015-03-24 18:56:08 +00002148 layout_info.field_offsets.insert(
Zachary Turner504f38d2015-03-24 16:24:50 +00002149 std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset));
Greg Clayton88bc7f32012-11-06 00:20:41 +00002150 }
2151 }
Greg Clayton78f4d952013-12-11 23:10:39 +00002152 last_field_info = this_field_info;
2153 }
2154 else
2155 {
2156 last_field_info.Clear();
Greg Clayton88bc7f32012-11-06 00:20:41 +00002157 }
Sean Callananfaa0bb32012-12-05 23:37:14 +00002158
Greg Clayton57ee3062013-07-11 22:46:58 +00002159 ClangASTType member_clang_type = member_type->GetClangLayoutType();
Sean Callananfa3ab452012-12-14 00:54:13 +00002160
2161 {
2162 // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>).
2163 // If the current field is at the end of the structure, then there is definitely no room for extra
2164 // elements and we override the type to array[0].
2165
Greg Clayton57ee3062013-07-11 22:46:58 +00002166 ClangASTType member_array_element_type;
Sean Callananfa3ab452012-12-14 00:54:13 +00002167 uint64_t member_array_size;
2168 bool member_array_is_incomplete;
2169
Greg Clayton57ee3062013-07-11 22:46:58 +00002170 if (member_clang_type.IsArrayType(&member_array_element_type,
2171 &member_array_size,
2172 &member_array_is_incomplete) &&
Sean Callananfa3ab452012-12-14 00:54:13 +00002173 !member_array_is_incomplete)
2174 {
2175 uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX);
2176
2177 if (member_byte_offset >= parent_byte_size)
2178 {
2179 if (member_array_size != 1)
2180 {
2181 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,
2182 MakeUserID(die->GetOffset()),
2183 name,
2184 encoding_uid,
2185 MakeUserID(parent_die->GetOffset()));
2186 }
2187
Greg Clayton1c8ef472013-04-05 23:27:21 +00002188 member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0, false);
Sean Callananfa3ab452012-12-14 00:54:13 +00002189 }
2190 }
2191 }
2192
Greg Clayton57ee3062013-07-11 22:46:58 +00002193 field_decl = class_clang_type.AddFieldToRecordType (name,
2194 member_clang_type,
2195 accessibility,
2196 bit_size);
Sean Callanan60217122012-04-13 00:10:03 +00002197
Greg Claytond0029442013-03-27 01:48:02 +00002198 GetClangASTContext().SetMetadataAsUserID (field_decl, MakeUserID(die->GetOffset()));
Greg Clayton78f4d952013-12-11 23:10:39 +00002199
Zachary Turnera98fac22015-03-24 18:56:08 +00002200 layout_info.field_offsets.insert(std::make_pair(field_decl, field_bit_offset));
Sean Callanan5b26f272012-02-04 08:49:35 +00002201 }
2202 else
2203 {
Sean Callanan751aac62012-03-29 19:07:06 +00002204 if (name)
Daniel Malead01b2952012-11-29 21:49:15 +00002205 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 +00002206 MakeUserID(die->GetOffset()),
2207 name,
2208 encoding_uid);
2209 else
Daniel Malead01b2952012-11-29 21:49:15 +00002210 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 +00002211 MakeUserID(die->GetOffset()),
2212 encoding_uid);
Sean Callanan5b26f272012-02-04 08:49:35 +00002213 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002214 }
Sean Callanan751aac62012-03-29 19:07:06 +00002215
Jim Inghame3ae82a2011-11-12 01:36:43 +00002216 if (prop_name != NULL)
2217 {
Sean Callanan751aac62012-03-29 19:07:06 +00002218 clang::ObjCIvarDecl *ivar_decl = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00002219
Sean Callanan751aac62012-03-29 19:07:06 +00002220 if (field_decl)
2221 {
2222 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
2223 assert (ivar_decl != NULL);
2224 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00002225
Jim Ingham379397632012-10-27 02:54:13 +00002226 ClangASTMetadata metadata;
2227 metadata.SetUserID (MakeUserID(die->GetOffset()));
Greg Clayton57ee3062013-07-11 22:46:58 +00002228 delayed_properties.push_back(DelayedAddObjCClassProperty(class_clang_type,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002229 prop_name,
2230 member_type->GetClangLayoutType(),
2231 ivar_decl,
2232 prop_setter_name,
2233 prop_getter_name,
2234 prop_attributes,
Jim Ingham379397632012-10-27 02:54:13 +00002235 &metadata));
Sean Callanan60217122012-04-13 00:10:03 +00002236
Sean Callananad880762012-04-18 01:06:17 +00002237 if (ivar_decl)
Greg Claytond0029442013-03-27 01:48:02 +00002238 GetClangASTContext().SetMetadataAsUserID (ivar_decl, MakeUserID(die->GetOffset()));
Jim Inghame3ae82a2011-11-12 01:36:43 +00002239 }
Greg Clayton24739922010-10-13 03:15:28 +00002240 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002241 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00002242 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002243 }
2244 break;
2245
2246 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00002247 // Let the type parsing code handle this one for us.
2248 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002249 break;
2250
2251 case DW_TAG_inheritance:
2252 {
2253 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00002254 if (default_accessibility == eAccessNone)
2255 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002256 // TODO: implement DW_TAG_inheritance type parsing
2257 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00002258 const size_t num_attributes = die->GetAttributes (this,
2259 dwarf_cu,
2260 fixed_form_sizes,
2261 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002262 if (num_attributes > 0)
2263 {
2264 Declaration decl;
2265 DWARFExpression location;
2266 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00002267 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002268 bool is_virtual = false;
2269 bool is_base_of_class = true;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002270 off_t member_byte_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002271 uint32_t i;
2272 for (i=0; i<num_attributes; ++i)
2273 {
2274 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2275 DWARFFormValue form_value;
2276 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2277 {
2278 switch (attr)
2279 {
2280 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2281 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2282 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00002283 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002284 case DW_AT_data_member_location:
2285 if (form_value.BlockData())
2286 {
2287 Value initialValue(0);
2288 Value memberOffset(0);
Ed Masteeeae7212013-10-24 20:43:47 +00002289 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002290 uint32_t block_length = form_value.Unsigned();
2291 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
2292 if (DWARFExpression::Evaluate (NULL,
2293 NULL,
2294 NULL,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002295 NULL,
Richard Mitton0a558352013-10-17 21:14:00 +00002296 module,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002297 debug_info_data,
2298 block_offset,
2299 block_length,
2300 eRegisterKindDWARF,
2301 &initialValue,
2302 memberOffset,
2303 NULL))
2304 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002305 member_byte_offset = memberOffset.ResolveValue(NULL).UInt();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002306 }
2307 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002308 else
2309 {
2310 // With DWARF 3 and later, if the value is an integer constant,
2311 // this form value is the offset in bytes from the beginning
2312 // of the containing entity.
2313 member_byte_offset = form_value.Unsigned();
2314 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002315 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002316
2317 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00002318 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002319 break;
2320
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002321 case DW_AT_virtuality:
2322 is_virtual = form_value.Boolean();
2323 break;
2324
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002325 case DW_AT_sibling:
2326 break;
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002327
2328 default:
2329 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002330 }
2331 }
2332 }
2333
Greg Clayton526e5af2010-11-13 03:52:47 +00002334 Type *base_class_type = ResolveTypeUID(encoding_uid);
2335 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002336
Greg Clayton57ee3062013-07-11 22:46:58 +00002337 ClangASTType base_class_clang_type = base_class_type->GetClangFullType();
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002338 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002339 if (class_language == eLanguageTypeObjC)
2340 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002341 class_clang_type.SetObjCSuperClass(base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002342 }
2343 else
2344 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002345 base_classes.push_back (base_class_clang_type.CreateBaseClassSpecifier (accessibility,
Greg Claytonba2d22d2010-11-13 22:57:37 +00002346 is_virtual,
2347 is_base_of_class));
Greg Clayton2508b9b2012-11-01 23:20:02 +00002348
2349 if (is_virtual)
2350 {
Greg Clayton52694e32013-09-16 21:57:07 +00002351 // Do not specify any offset for virtual inheritance. The DWARF produced by clang doesn't
2352 // give us a constant offset, but gives us a DWARF expressions that requires an actual object
2353 // in memory. the DW_AT_data_member_location for a virtual base class looks like:
2354 // DW_AT_data_member_location( DW_OP_dup, DW_OP_deref, DW_OP_constu(0x00000018), DW_OP_minus, DW_OP_deref, DW_OP_plus )
2355 // Given this, there is really no valid response we can give to clang for virtual base
2356 // class offsets, and this should eventually be removed from LayoutRecordType() in the external
2357 // AST source in clang.
Greg Clayton2508b9b2012-11-01 23:20:02 +00002358 }
2359 else
2360 {
Zachary Turnera98fac22015-03-24 18:56:08 +00002361 layout_info.base_offsets.insert(
Zachary Turner504f38d2015-03-24 16:24:50 +00002362 std::make_pair(base_class_clang_type.GetAsCXXRecordDecl(),
2363 clang::CharUnits::fromQuantity(member_byte_offset)));
Greg Clayton2508b9b2012-11-01 23:20:02 +00002364 }
Greg Clayton9e409562010-07-28 02:04:09 +00002365 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002366 }
2367 }
2368 break;
2369
2370 default:
2371 break;
2372 }
2373 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002374
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002375 return count;
2376}
2377
2378
2379clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00002380SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002381{
2382 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00002383 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002384 {
2385 DWARFCompileUnitSP cu_sp;
2386 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
2387 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00002388 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00002389 }
2390 return NULL;
2391}
2392
2393clang::DeclContext*
2394SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
2395{
Greg Clayton81c22f62011-10-19 18:09:39 +00002396 if (UserIDMatches(type_uid))
2397 return GetClangDeclContextForDIEOffset (sc, type_uid);
2398 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002399}
2400
2401Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00002402SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002403{
Greg Clayton81c22f62011-10-19 18:09:39 +00002404 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002405 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002406 DWARFDebugInfo* debug_info = DebugInfo();
2407 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00002408 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002409 DWARFCompileUnitSP cu_sp;
2410 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00002411 const bool assert_not_being_parsed = true;
2412 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00002413 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002414 }
2415 return NULL;
2416}
2417
Greg Claytoncab36a32011-12-08 05:16:30 +00002418Type*
2419SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00002420{
Greg Claytoncab36a32011-12-08 05:16:30 +00002421 if (die != NULL)
2422 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002423 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00002424 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002425 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002426 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
2427 die->GetOffset(),
2428 DW_TAG_value_to_name(die->Tag()),
2429 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00002430
Greg Claytoncab36a32011-12-08 05:16:30 +00002431 // We might be coming in in the middle of a type tree (a class
2432 // withing a class, an enum within a class), so parse any needed
2433 // parent DIEs before we get to this one...
2434 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2435 switch (decl_ctx_die->Tag())
2436 {
2437 case DW_TAG_structure_type:
2438 case DW_TAG_union_type:
2439 case DW_TAG_class_type:
2440 {
2441 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00002442 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002443 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002444 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
2445 die->GetOffset(),
2446 DW_TAG_value_to_name(die->Tag()),
2447 die->GetName(this, cu),
2448 decl_ctx_die->GetOffset());
Greg Clayton219cf312012-03-30 00:51:13 +00002449//
2450// Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
2451// if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
2452// {
2453// if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002454// GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton219cf312012-03-30 00:51:13 +00002455// "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
2456// die->GetOffset(),
2457// DW_TAG_value_to_name(die->Tag()),
2458// die->GetName(this, cu),
2459// decl_ctx_die->GetOffset());
2460// // Ask the type to complete itself if it already hasn't since if we
2461// // want a function (method or static) from a class, the class must
2462// // create itself and add it's own methods and class functions.
2463// if (parent_type)
2464// parent_type->GetClangFullType();
2465// }
Greg Claytoncab36a32011-12-08 05:16:30 +00002466 }
2467 break;
2468
2469 default:
2470 break;
2471 }
2472 return ResolveType (cu, die);
2473 }
2474 return NULL;
2475}
2476
Greg Clayton6beaaa62011-01-17 03:46:26 +00002477// This function is used when SymbolFileDWARFDebugMap owns a bunch of
2478// SymbolFileDWARF objects to detect if this DWARF file is the one that
2479// can resolve a clang_type.
2480bool
Greg Clayton57ee3062013-07-11 22:46:58 +00002481SymbolFileDWARF::HasForwardDeclForClangType (const ClangASTType &clang_type)
Greg Clayton6beaaa62011-01-17 03:46:26 +00002482{
Greg Clayton57ee3062013-07-11 22:46:58 +00002483 ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers();
2484 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton6beaaa62011-01-17 03:46:26 +00002485 return die != NULL;
2486}
2487
2488
Greg Clayton57ee3062013-07-11 22:46:58 +00002489bool
2490SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (ClangASTType &clang_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00002491{
2492 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton57ee3062013-07-11 22:46:58 +00002493 ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers();
2494 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton1be10fc2010-09-29 01:12:09 +00002495 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00002496 {
2497 // We have already resolved this type...
Greg Clayton57ee3062013-07-11 22:46:58 +00002498 return true;
Greg Clayton73b472d2010-10-27 03:32:59 +00002499 }
2500 // Once we start resolving this type, remove it from the forward declaration
2501 // map in case anyone child members or other types require this type to get resolved.
2502 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
2503 // are done.
Greg Clayton57ee3062013-07-11 22:46:58 +00002504 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton1be10fc2010-09-29 01:12:09 +00002505
Greg Clayton85ae2e12011-10-18 23:36:41 +00002506 // Disable external storage for this type so we don't get anymore
2507 // clang::ExternalASTSource queries for this type.
Greg Clayton57ee3062013-07-11 22:46:58 +00002508 clang_type.SetHasExternalStorage (false);
Greg Clayton85ae2e12011-10-18 23:36:41 +00002509
Greg Clayton450e3f32010-10-12 02:24:53 +00002510 DWARFDebugInfo* debug_info = DebugInfo();
2511
Greg Clayton53eb1c22012-04-02 22:59:12 +00002512 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002513 Type *type = m_die_to_type.lookup (die);
2514
2515 const dw_tag_t tag = die->Tag();
2516
Greg Clayton5160ce52013-03-27 23:08:40 +00002517 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
Greg Clayton3bffb082011-12-10 02:15:28 +00002518 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002519 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002520 "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...",
Greg Claytond61c0fc2012-04-23 22:55:20 +00002521 MakeUserID(die->GetOffset()),
2522 DW_TAG_value_to_name(tag),
2523 type->GetName().AsCString());
Greg Clayton1be10fc2010-09-29 01:12:09 +00002524 assert (clang_type);
2525 DWARFDebugInfoEntry::Attributes attributes;
2526
Greg Clayton1be10fc2010-09-29 01:12:09 +00002527 switch (tag)
2528 {
2529 case DW_TAG_structure_type:
2530 case DW_TAG_union_type:
2531 case DW_TAG_class_type:
Greg Claytonc93237c2010-10-01 20:48:32 +00002532 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002533 LayoutInfo layout_info;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002534
Greg Clayton1be10fc2010-09-29 01:12:09 +00002535 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002536 if (die->HasChildren())
Greg Claytonc93237c2010-10-01 20:48:32 +00002537 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002538 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton57ee3062013-07-11 22:46:58 +00002539 if (clang_type.IsObjCObjectOrInterfaceType())
Greg Clayton219cf312012-03-30 00:51:13 +00002540 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002541 class_language = eLanguageTypeObjC;
Greg Clayton219cf312012-03-30 00:51:13 +00002542 // For objective C we don't start the definition when
2543 // the class is created.
Greg Clayton57ee3062013-07-11 22:46:58 +00002544 clang_type.StartTagDeclarationDefinition ();
Greg Clayton219cf312012-03-30 00:51:13 +00002545 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002546
Sean Callanan77a1fd32012-02-27 20:07:01 +00002547 int tag_decl_kind = -1;
2548 AccessType default_accessibility = eAccessNone;
2549 if (tag == DW_TAG_structure_type)
2550 {
2551 tag_decl_kind = clang::TTK_Struct;
2552 default_accessibility = eAccessPublic;
2553 }
2554 else if (tag == DW_TAG_union_type)
2555 {
2556 tag_decl_kind = clang::TTK_Union;
2557 default_accessibility = eAccessPublic;
2558 }
2559 else if (tag == DW_TAG_class_type)
2560 {
2561 tag_decl_kind = clang::TTK_Class;
2562 default_accessibility = eAccessPrivate;
2563 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002564
Greg Clayton53eb1c22012-04-02 22:59:12 +00002565 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002566 std::vector<clang::CXXBaseSpecifier *> base_classes;
2567 std::vector<int> member_accessibilities;
2568 bool is_a_class = false;
2569 // Parse members and base classes first
2570 DWARFDIECollection member_function_dies;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002571
Sean Callanana0b80ab2012-06-04 22:28:05 +00002572 DelayedPropertyList delayed_properties;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002573 ParseChildMembers (sc,
Greg Clayton53eb1c22012-04-02 22:59:12 +00002574 dwarf_cu,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002575 die,
2576 clang_type,
2577 class_language,
2578 base_classes,
2579 member_accessibilities,
2580 member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002581 delayed_properties,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002582 default_accessibility,
2583 is_a_class,
2584 layout_info);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002585
Sean Callanan77a1fd32012-02-27 20:07:01 +00002586 // Now parse any methods if there were any...
2587 size_t num_functions = member_function_dies.Size();
2588 if (num_functions > 0)
2589 {
2590 for (size_t i=0; i<num_functions; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002591 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002592 ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytoncaab74e2012-01-28 00:48:57 +00002593 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002594 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002595
Sean Callanan77a1fd32012-02-27 20:07:01 +00002596 if (class_language == eLanguageTypeObjC)
2597 {
Jim Inghamfb6fc0d2013-09-27 20:59:37 +00002598 ConstString class_name (clang_type.GetTypeName());
2599 if (class_name)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002600 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002601 DIEArray method_die_offsets;
2602 if (m_using_apple_tables)
Greg Clayton95d87902011-11-11 03:16:25 +00002603 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002604 if (m_apple_objc_ap.get())
Jim Inghamfb6fc0d2013-09-27 20:59:37 +00002605 m_apple_objc_ap->FindByName(class_name.GetCString(), method_die_offsets);
Sean Callanan77a1fd32012-02-27 20:07:01 +00002606 }
2607 else
2608 {
2609 if (!m_indexed)
2610 Index ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002611
Sean Callanan77a1fd32012-02-27 20:07:01 +00002612 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
2613 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002614
Sean Callanan77a1fd32012-02-27 20:07:01 +00002615 if (!method_die_offsets.empty())
2616 {
2617 DWARFDebugInfo* debug_info = DebugInfo();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002618
Sean Callanan77a1fd32012-02-27 20:07:01 +00002619 DWARFCompileUnit* method_cu = NULL;
2620 const size_t num_matches = method_die_offsets.size();
2621 for (size_t i=0; i<num_matches; ++i)
Greg Clayton95d87902011-11-11 03:16:25 +00002622 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002623 const dw_offset_t die_offset = method_die_offsets[i];
2624 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002625
Sean Callanan77a1fd32012-02-27 20:07:01 +00002626 if (method_die)
2627 ResolveType (method_cu, method_die);
2628 else
Greg Claytoncaab74e2012-01-28 00:48:57 +00002629 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002630 if (m_using_apple_tables)
2631 {
2632 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n",
Jim Inghamfb6fc0d2013-09-27 20:59:37 +00002633 die_offset, class_name.GetCString());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002634 }
2635 }
2636 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002637 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002638
Greg Clayton57ee3062013-07-11 22:46:58 +00002639 for (DelayedPropertyList::iterator pi = delayed_properties.begin(), pe = delayed_properties.end();
Sean Callanana0b80ab2012-06-04 22:28:05 +00002640 pi != pe;
2641 ++pi)
2642 pi->Finalize();
Greg Clayton450e3f32010-10-12 02:24:53 +00002643 }
2644 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002645
Sean Callanan77a1fd32012-02-27 20:07:01 +00002646 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2647 // need to tell the clang type it is actually a class.
2648 if (class_language != eLanguageTypeObjC)
2649 {
2650 if (is_a_class && tag_decl_kind != clang::TTK_Class)
Greg Clayton57ee3062013-07-11 22:46:58 +00002651 clang_type.SetTagTypeKind (clang::TTK_Class);
Sean Callanan77a1fd32012-02-27 20:07:01 +00002652 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002653
Sean Callanan77a1fd32012-02-27 20:07:01 +00002654 // Since DW_TAG_structure_type gets used for both classes
2655 // and structures, we may need to set any DW_TAG_member
2656 // fields to have a "private" access if none was specified.
2657 // When we parsed the child members we tracked that actual
2658 // accessibility value for each DW_TAG_member in the
2659 // "member_accessibilities" array. If the value for the
2660 // member is zero, then it was set to the "default_accessibility"
2661 // which for structs was "public". Below we correct this
2662 // by setting any fields to "private" that weren't correctly
2663 // set.
2664 if (is_a_class && !member_accessibilities.empty())
2665 {
2666 // This is a class and all members that didn't have
2667 // their access specified are private.
Greg Clayton57ee3062013-07-11 22:46:58 +00002668 clang_type.SetDefaultAccessForRecordFields (eAccessPrivate,
2669 &member_accessibilities.front(),
2670 member_accessibilities.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002671 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002672
Sean Callanan77a1fd32012-02-27 20:07:01 +00002673 if (!base_classes.empty())
2674 {
Greg Clayton4705f8d2013-12-12 01:54:04 +00002675 // Make sure all base classes refer to complete types and not
2676 // forward declarations. If we don't do this, clang will crash
2677 // with an assertion in the call to clang_type.SetBaseClassesForClassType()
2678 bool base_class_error = false;
2679 for (auto &base_class : base_classes)
2680 {
2681 clang::TypeSourceInfo *type_source_info = base_class->getTypeSourceInfo();
2682 if (type_source_info)
2683 {
2684 ClangASTType base_class_type (GetClangASTContext().getASTContext(), type_source_info->getType());
2685 if (base_class_type.GetCompleteType() == false)
2686 {
2687 if (!base_class_error)
2688 {
2689 GetObjectFile()->GetModule()->ReportError ("DWARF DIE at 0x%8.8x for class '%s' has a base class '%s' that is a forward declaration, not a complete definition.\nPlease file a bug against the compiler and include the preprocessed output for %s",
2690 die->GetOffset(),
2691 die->GetName(this, dwarf_cu),
2692 base_class_type.GetTypeName().GetCString(),
2693 sc.comp_unit ? sc.comp_unit->GetPath().c_str() : "the source file");
2694 }
2695 // We have no choice other than to pretend that the base class
2696 // is complete. If we don't do this, clang will crash when we
2697 // call setBases() inside of "clang_type.SetBaseClassesForClassType()"
2698 // below. Since we provide layout assistance, all ivars in this
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00002699 // class and other classes will be fine, this is the best we can do
Greg Clayton4705f8d2013-12-12 01:54:04 +00002700 // short of crashing.
2701 base_class_type.StartTagDeclarationDefinition ();
2702 base_class_type.CompleteTagDeclarationDefinition ();
2703 }
2704 }
2705 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002706 clang_type.SetBaseClassesForClassType (&base_classes.front(),
2707 base_classes.size());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002708
Sean Callanan77a1fd32012-02-27 20:07:01 +00002709 // Clang will copy each CXXBaseSpecifier in "base_classes"
2710 // so we have to free them all.
Greg Clayton57ee3062013-07-11 22:46:58 +00002711 ClangASTType::DeleteBaseClassSpecifiers (&base_classes.front(),
2712 base_classes.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002713 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002714 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002715 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002716
Greg Clayton57ee3062013-07-11 22:46:58 +00002717 clang_type.BuildIndirectFields ();
2718 clang_type.CompleteTagDeclarationDefinition ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002719
Greg Clayton2508b9b2012-11-01 23:20:02 +00002720 if (!layout_info.field_offsets.empty() ||
2721 !layout_info.base_offsets.empty() ||
2722 !layout_info.vbase_offsets.empty() )
Greg Claytoncaab74e2012-01-28 00:48:57 +00002723 {
2724 if (type)
2725 layout_info.bit_size = type->GetByteSize() * 8;
2726 if (layout_info.bit_size == 0)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002727 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002728
Greg Clayton57ee3062013-07-11 22:46:58 +00002729 clang::CXXRecordDecl *record_decl = clang_type.GetAsCXXRecordDecl();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002730 if (record_decl)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002731 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002732 if (log)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002733 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002734 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002735 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) caching layout info for record_decl = %p, bit_size = %" PRIu64 ", alignment = %" PRIu64 ", field_offsets[%u], base_offsets[%u], vbase_offsets[%u])",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002736 static_cast<void*>(clang_type.GetOpaqueQualType()),
2737 static_cast<void*>(record_decl),
Greg Claytoncaab74e2012-01-28 00:48:57 +00002738 layout_info.bit_size,
2739 layout_info.alignment,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002740 static_cast<uint32_t>(layout_info.field_offsets.size()),
2741 static_cast<uint32_t>(layout_info.base_offsets.size()),
2742 static_cast<uint32_t>(layout_info.vbase_offsets.size()));
2743
Zachary Turnera98fac22015-03-24 18:56:08 +00002744 uint32_t idx;
2745 {
2746 llvm::DenseMap<const clang::FieldDecl *, uint64_t>::const_iterator pos,
2747 end = layout_info.field_offsets.end();
2748 for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx)
Greg Clayton2508b9b2012-11-01 23:20:02 +00002749 {
Zachary Turner504f38d2015-03-24 16:24:50 +00002750 GetObjectFile()->GetModule()->LogMessage(
2751 log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = "
2752 "{ bit_offset=%u, name='%s' }",
Zachary Turner504f38d2015-03-24 16:24:50 +00002753 static_cast<void *>(clang_type.GetOpaqueQualType()), idx,
Zachary Turnera98fac22015-03-24 18:56:08 +00002754 static_cast<uint32_t>(pos->second), pos->first->getNameAsString().c_str());
2755 }
2756 }
2757
2758 {
2759 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos,
2760 base_end = layout_info.base_offsets.end();
2761 for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end;
2762 ++base_pos, ++idx)
2763 {
2764 GetObjectFile()->GetModule()->LogMessage(
2765 log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] "
2766 "= { byte_offset=%u, name='%s' }",
2767 clang_type.GetOpaqueQualType(), idx, (uint32_t)base_pos->second.getQuantity(),
2768 base_pos->first->getNameAsString().c_str());
2769 }
2770 }
2771 {
2772 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos,
2773 vbase_end = layout_info.vbase_offsets.end();
2774 for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end;
2775 ++vbase_pos, ++idx)
2776 {
2777 GetObjectFile()->GetModule()->LogMessage(
2778 log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) "
2779 "vbase[%u] = { byte_offset=%u, name='%s' }",
2780 static_cast<void *>(clang_type.GetOpaqueQualType()), idx,
2781 static_cast<uint32_t>(vbase_pos->second.getQuantity()),
2782 vbase_pos->first->getNameAsString().c_str());
2783 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002784 }
Greg Clayton821ac6d2012-01-28 02:22:27 +00002785 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002786 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2787 }
2788 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002789 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002790
Sean Callanan9076c0f2013-10-04 21:35:29 +00002791 return (bool)clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002792
2793 case DW_TAG_enumeration_type:
Greg Clayton57ee3062013-07-11 22:46:58 +00002794 clang_type.StartTagDeclarationDefinition ();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002795 if (die->HasChildren())
2796 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002797 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00002798 bool is_signed = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00002799 clang_type.IsIntegerType(is_signed);
Greg Clayton3e067532013-03-05 23:54:39 +00002800 ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002801 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002802 clang_type.CompleteTagDeclarationDefinition ();
Sean Callanan9076c0f2013-10-04 21:35:29 +00002803 return (bool)clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002804
2805 default:
2806 assert(false && "not a forward clang type decl!");
2807 break;
2808 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002809 return false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002810}
2811
Greg Claytonc685f8e2010-09-15 04:15:46 +00002812Type*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002813SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002814{
2815 if (type_die != NULL)
2816 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002817 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00002818
Greg Claytonc685f8e2010-09-15 04:15:46 +00002819 if (type == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002820 type = GetTypeForDIE (dwarf_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00002821
Greg Clayton24739922010-10-13 03:15:28 +00002822 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00002823 {
2824 if (type != DIE_IS_BEING_PARSED)
2825 return type;
2826
2827 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
Greg Clayton53eb1c22012-04-02 22:59:12 +00002828 type_die->GetOffset(),
2829 DW_TAG_value_to_name(type_die->Tag()),
2830 type_die->GetName(this, dwarf_cu));
Jim Inghamc3549282012-01-11 02:21:12 +00002831
2832 }
2833 else
2834 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002835 }
2836 return NULL;
2837}
2838
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002839CompileUnit*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002840SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002841{
2842 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002843 if (dwarf_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002844 {
2845 // The symbol vendor doesn't know about this compile unit, we
2846 // need to parse and add it to the symbol vendor object.
Greg Clayton53eb1c22012-04-02 22:59:12 +00002847 return ParseCompileUnit(dwarf_cu, cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002848 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00002849 return (CompileUnit*)dwarf_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002850}
2851
2852bool
Greg Clayton53eb1c22012-04-02 22:59:12 +00002853SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002854{
Greg Clayton72310352013-02-23 04:12:47 +00002855 sc.Clear(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002856 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002857 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002858
Greg Clayton81c22f62011-10-19 18:09:39 +00002859 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002860 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002861 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002862
2863 if (sc.function)
2864 {
Greg Claytone72dfb32012-02-24 01:59:29 +00002865 sc.module_sp = sc.function->CalculateSymbolContextModule();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002866 return true;
2867 }
2868
2869 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002870}
2871
Sean Callananf0c5aeb2015-04-20 16:31:29 +00002872void
2873SymbolFileDWARF::UpdateExternalModuleListIfNeeded()
2874{
2875 if (m_fetched_external_modules)
2876 return;
2877 m_fetched_external_modules = true;
2878
2879 DWARFDebugInfo * debug_info = DebugInfo();
2880 debug_info->GetNumCompileUnits();
2881
2882 const uint32_t num_compile_units = GetNumCompileUnits();
2883 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2884 {
2885 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
2886
2887 const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly();
2888 if (die && die->HasChildren() == false)
2889 {
2890 const uint64_t name_strp = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_name, UINT64_MAX);
2891 const uint64_t dwo_path_strp = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_GNU_dwo_name, UINT64_MAX);
2892
2893 if (name_strp != UINT64_MAX)
2894 {
2895 if (m_external_type_modules.find(dwo_path_strp) == m_external_type_modules.end())
2896 {
2897 const char *name = get_debug_str_data().PeekCStr(name_strp);
2898 const char *dwo_path = get_debug_str_data().PeekCStr(dwo_path_strp);
2899 if (name || dwo_path)
2900 {
2901 ModuleSP module_sp;
2902 if (dwo_path)
2903 {
2904 ModuleSpec dwo_module_spec;
2905 dwo_module_spec.GetFileSpec().SetFile(dwo_path, false);
2906 dwo_module_spec.GetArchitecture() = m_obj_file->GetModule()->GetArchitecture();
2907 //printf ("Loading dwo = '%s'\n", dwo_path);
2908 Error error = ModuleList::GetSharedModule (dwo_module_spec, module_sp, NULL, NULL, NULL);
2909 }
2910
2911 if (dwo_path_strp != LLDB_INVALID_UID)
2912 {
2913 m_external_type_modules[dwo_path_strp] = ClangModuleInfo { ConstString(name), module_sp };
2914 }
2915 else
2916 {
2917 // This hack should be removed promptly once clang emits both.
2918 m_external_type_modules[name_strp] = ClangModuleInfo { ConstString(name), module_sp };
2919 }
2920 }
2921 }
2922 }
2923 }
2924 }
2925}
Greg Clayton2501e5e2015-01-15 02:59:20 +00002926
2927SymbolFileDWARF::GlobalVariableMap &
2928SymbolFileDWARF::GetGlobalAranges()
2929{
2930 if (!m_global_aranges_ap)
2931 {
2932 m_global_aranges_ap.reset (new GlobalVariableMap());
2933
2934 ModuleSP module_sp = GetObjectFile()->GetModule();
2935 if (module_sp)
2936 {
2937 const size_t num_cus = module_sp->GetNumCompileUnits();
2938 for (size_t i = 0; i < num_cus; ++i)
2939 {
2940 CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(i);
2941 if (cu_sp)
2942 {
2943 VariableListSP globals_sp = cu_sp->GetVariableList(true);
2944 if (globals_sp)
2945 {
2946 const size_t num_globals = globals_sp->GetSize();
2947 for (size_t g = 0; g < num_globals; ++g)
2948 {
2949 VariableSP var_sp = globals_sp->GetVariableAtIndex(g);
2950 if (var_sp && !var_sp->GetLocationIsConstantValueData())
2951 {
2952 const DWARFExpression &location = var_sp->LocationExpression();
2953 Value location_result;
2954 Error error;
2955 if (location.Evaluate(NULL, NULL, NULL, LLDB_INVALID_ADDRESS, NULL, location_result, &error))
2956 {
2957 if (location_result.GetValueType() == Value::eValueTypeFileAddress)
2958 {
2959 lldb::addr_t file_addr = location_result.GetScalar().ULongLong();
2960 lldb::addr_t byte_size = 1;
2961 if (var_sp->GetType())
2962 byte_size = var_sp->GetType()->GetByteSize();
2963 m_global_aranges_ap->Append(GlobalVariableMap::Entry(file_addr, byte_size, var_sp.get()));
2964 }
2965 }
2966 }
2967 }
2968 }
2969 }
2970 }
2971 }
2972 m_global_aranges_ap->Sort();
2973 }
2974 return *m_global_aranges_ap;
2975}
2976
2977
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002978uint32_t
2979SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2980{
2981 Timer scoped_timer(__PRETTY_FUNCTION__,
Daniel Malead01b2952012-11-29 21:49:15 +00002982 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002983 static_cast<void*>(so_addr.GetSection().get()),
2984 so_addr.GetOffset(), resolve_scope);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002985 uint32_t resolved = 0;
Greg Clayton2501e5e2015-01-15 02:59:20 +00002986 if (resolve_scope & ( eSymbolContextCompUnit |
2987 eSymbolContextFunction |
2988 eSymbolContextBlock |
2989 eSymbolContextLineEntry |
2990 eSymbolContextVariable ))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002991 {
2992 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2993
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002994 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00002995 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002996 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002997 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Greg Clayton2501e5e2015-01-15 02:59:20 +00002998 if (cu_offset == DW_INVALID_OFFSET)
2999 {
3000 // Global variables are not in the compile unit address ranges. The only way to
3001 // currently find global variables is to iterate over the .debug_pubnames or the
3002 // __apple_names table and find all items in there that point to DW_TAG_variable
3003 // DIEs and then find the address that matches.
3004 if (resolve_scope & eSymbolContextVariable)
3005 {
3006 GlobalVariableMap &map = GetGlobalAranges();
3007 const GlobalVariableMap::Entry *entry = map.FindEntryThatContains(file_vm_addr);
3008 if (entry && entry->data)
3009 {
3010 Variable *variable = entry->data;
3011 SymbolContextScope *scc = variable->GetSymbolContextScope();
3012 if (scc)
3013 {
3014 scc->CalculateSymbolContext(&sc);
3015 sc.variable = variable;
3016 }
3017 return sc.GetResolvedMask();
3018 }
3019 }
3020 }
3021 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003022 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003023 uint32_t cu_idx = DW_INVALID_INDEX;
Greg Clayton53eb1c22012-04-02 22:59:12 +00003024 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
3025 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003026 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003027 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00003028 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003029 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003030 resolved |= eSymbolContextCompUnit;
3031
Greg Clayton6ab80132012-12-12 17:30:52 +00003032 bool force_check_line_table = false;
Greg Clayton526a4ae2012-05-16 22:09:01 +00003033 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
3034 {
3035 DWARFDebugInfoEntry *function_die = NULL;
3036 DWARFDebugInfoEntry *block_die = NULL;
3037 if (resolve_scope & eSymbolContextBlock)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003038 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003039 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
3040 }
3041 else
3042 {
3043 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL);
3044 }
3045
3046 if (function_die != NULL)
3047 {
3048 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
3049 if (sc.function == NULL)
3050 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
3051 }
3052 else
3053 {
3054 // We might have had a compile unit that had discontiguous
3055 // address ranges where the gaps are symbols that don't have
3056 // any debug info. Discontiguous compile unit address ranges
3057 // should only happen when there aren't other functions from
3058 // other compile units in these gaps. This helps keep the size
3059 // of the aranges down.
Greg Clayton6ab80132012-12-12 17:30:52 +00003060 force_check_line_table = true;
Greg Clayton526a4ae2012-05-16 22:09:01 +00003061 }
3062
3063 if (sc.function != NULL)
3064 {
3065 resolved |= eSymbolContextFunction;
3066
3067 if (resolve_scope & eSymbolContextBlock)
3068 {
3069 Block& block = sc.function->GetBlock (true);
3070
3071 if (block_die != NULL)
3072 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
3073 else
3074 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
3075 if (sc.block)
3076 resolved |= eSymbolContextBlock;
3077 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003078 }
3079 }
Greg Clayton6ab80132012-12-12 17:30:52 +00003080
3081 if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table)
3082 {
3083 LineTable *line_table = sc.comp_unit->GetLineTable();
3084 if (line_table != NULL)
3085 {
Greg Clayton9422dd62013-03-04 21:46:16 +00003086 // And address that makes it into this function should be in terms
3087 // of this debug file if there is no debug map, or it will be an
3088 // address in the .o file which needs to be fixed up to be in terms
3089 // of the debug map executable. Either way, calling FixupAddress()
3090 // will work for us.
3091 Address exe_so_addr (so_addr);
3092 if (FixupAddress(exe_so_addr))
Greg Clayton6ab80132012-12-12 17:30:52 +00003093 {
Greg Clayton9422dd62013-03-04 21:46:16 +00003094 if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry))
Greg Clayton6ab80132012-12-12 17:30:52 +00003095 {
3096 resolved |= eSymbolContextLineEntry;
3097 }
3098 }
Greg Clayton6ab80132012-12-12 17:30:52 +00003099 }
3100 }
3101
3102 if (force_check_line_table && !(resolved & eSymbolContextLineEntry))
3103 {
3104 // We might have had a compile unit that had discontiguous
3105 // address ranges where the gaps are symbols that don't have
3106 // any debug info. Discontiguous compile unit address ranges
3107 // should only happen when there aren't other functions from
3108 // other compile units in these gaps. This helps keep the size
3109 // of the aranges down.
3110 sc.comp_unit = NULL;
3111 resolved &= ~eSymbolContextCompUnit;
3112 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003113 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00003114 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003115 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003116 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.",
3117 cu_offset,
3118 cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003119 }
3120 }
3121 }
3122 }
3123 }
3124 return resolved;
3125}
3126
3127
3128
3129uint32_t
3130SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
3131{
3132 const uint32_t prev_size = sc_list.GetSize();
3133 if (resolve_scope & eSymbolContextCompUnit)
3134 {
3135 DWARFDebugInfo* debug_info = DebugInfo();
3136 if (debug_info)
3137 {
3138 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00003139 DWARFCompileUnit* dwarf_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003140
Greg Clayton53eb1c22012-04-02 22:59:12 +00003141 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003142 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003143 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Sean Callananddd7a2a2013-10-03 22:27:29 +00003144 const bool full_match = (bool)file_spec.GetDirectory();
Greg Clayton1f746072012-08-29 21:13:06 +00003145 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 +00003146 if (check_inlines || file_spec_matches_cu_file_spec)
3147 {
3148 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton53eb1c22012-04-02 22:59:12 +00003149 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00003150 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003151 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003152 uint32_t file_idx = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003153
Greg Clayton526a4ae2012-05-16 22:09:01 +00003154 // If we are looking for inline functions only and we don't
3155 // find it in the support files, we are done.
3156 if (check_inlines)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003157 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003158 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
3159 if (file_idx == UINT32_MAX)
3160 continue;
3161 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003162
Greg Clayton526a4ae2012-05-16 22:09:01 +00003163 if (line != 0)
3164 {
3165 LineTable *line_table = sc.comp_unit->GetLineTable();
3166
3167 if (line_table != NULL && line != 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003168 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003169 // We will have already looked up the file index if
3170 // we are searching for inline entries.
3171 if (!check_inlines)
3172 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003173
Greg Clayton526a4ae2012-05-16 22:09:01 +00003174 if (file_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003175 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003176 uint32_t found_line;
3177 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
3178 found_line = sc.line_entry.line;
3179
3180 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003181 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003182 sc.function = NULL;
3183 sc.block = NULL;
3184 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003185 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003186 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
3187 if (file_vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003188 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003189 DWARFDebugInfoEntry *function_die = NULL;
3190 DWARFDebugInfoEntry *block_die = NULL;
3191 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003192
Greg Clayton526a4ae2012-05-16 22:09:01 +00003193 if (function_die != NULL)
3194 {
3195 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
3196 if (sc.function == NULL)
3197 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
3198 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003199
Greg Clayton526a4ae2012-05-16 22:09:01 +00003200 if (sc.function != NULL)
3201 {
3202 Block& block = sc.function->GetBlock (true);
3203
3204 if (block_die != NULL)
3205 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
Jason Molenda60db6e42014-10-16 01:40:16 +00003206 else if (function_die != NULL)
Greg Clayton526a4ae2012-05-16 22:09:01 +00003207 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
3208 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003209 }
3210 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003211
Greg Clayton526a4ae2012-05-16 22:09:01 +00003212 sc_list.Append(sc);
3213 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
3214 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003215 }
3216 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00003217 else if (file_spec_matches_cu_file_spec && !check_inlines)
3218 {
3219 // only append the context if we aren't looking for inline call sites
3220 // by file and line and if the file spec matches that of the compile unit
3221 sc_list.Append(sc);
3222 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003223 }
3224 else if (file_spec_matches_cu_file_spec && !check_inlines)
3225 {
3226 // only append the context if we aren't looking for inline call sites
3227 // by file and line and if the file spec matches that of the compile unit
3228 sc_list.Append(sc);
3229 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003230
Greg Clayton526a4ae2012-05-16 22:09:01 +00003231 if (!check_inlines)
3232 break;
3233 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003234 }
3235 }
3236 }
3237 }
3238 return sc_list.GetSize() - prev_size;
3239}
3240
3241void
3242SymbolFileDWARF::Index ()
3243{
3244 if (m_indexed)
3245 return;
3246 m_indexed = true;
3247 Timer scoped_timer (__PRETTY_FUNCTION__,
3248 "SymbolFileDWARF::Index (%s)",
Jim Ingham4af59612014-12-19 19:20:44 +00003249 GetObjectFile()->GetFileSpec().GetFilename().AsCString("<Unknown>"));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003250
3251 DWARFDebugInfo* debug_info = DebugInfo();
3252 if (debug_info)
3253 {
3254 uint32_t cu_idx = 0;
3255 const uint32_t num_compile_units = GetNumCompileUnits();
3256 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
3257 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003258 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003259
Greg Clayton53eb1c22012-04-02 22:59:12 +00003260 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003261
Greg Clayton53eb1c22012-04-02 22:59:12 +00003262 dwarf_cu->Index (cu_idx,
3263 m_function_basename_index,
3264 m_function_fullname_index,
3265 m_function_method_index,
3266 m_function_selector_index,
3267 m_objc_class_selectors_index,
3268 m_global_index,
3269 m_type_index,
3270 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003271
3272 // Keep memory down by clearing DIEs if this generate function
3273 // caused them to be parsed
3274 if (clear_dies)
Greg Clayton53eb1c22012-04-02 22:59:12 +00003275 dwarf_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003276 }
3277
Greg Claytond4a2b372011-09-12 23:21:58 +00003278 m_function_basename_index.Finalize();
3279 m_function_fullname_index.Finalize();
3280 m_function_method_index.Finalize();
3281 m_function_selector_index.Finalize();
3282 m_objc_class_selectors_index.Finalize();
3283 m_global_index.Finalize();
3284 m_type_index.Finalize();
3285 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003286
Greg Clayton24739922010-10-13 03:15:28 +00003287#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00003288 StreamFile s(stdout, false);
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00003289 s.Printf ("DWARF index for '%s':",
3290 GetObjectFile()->GetFileSpec().GetPath().c_str());
Greg Claytonba2d22d2010-11-13 22:57:37 +00003291 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
3292 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
3293 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
3294 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
3295 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
3296 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00003297 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00003298 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00003299#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003300 }
3301}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003302
3303bool
3304SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
3305{
3306 if (namespace_decl == NULL)
3307 {
3308 // Invalid namespace decl which means we aren't matching only things
3309 // in this symbol file, so return true to indicate it matches this
3310 // symbol file.
3311 return true;
3312 }
3313
3314 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
3315
3316 if (namespace_ast == NULL)
3317 return true; // No AST in the "namespace_decl", return true since it
3318 // could then match any symbol file, including this one
3319
3320 if (namespace_ast == GetClangASTContext().getASTContext())
3321 return true; // The ASTs match, return true
3322
3323 // The namespace AST was valid, and it does not match...
Greg Clayton5160ce52013-03-27 23:08:40 +00003324 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Sean Callananc41e68b2011-10-13 21:08:11 +00003325
3326 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003327 GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00003328
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003329 return false;
3330}
3331
Greg Clayton2506a7a2011-10-12 23:34:26 +00003332bool
3333SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
3334 DWARFCompileUnit* cu,
3335 const DWARFDebugInfoEntry* die)
3336{
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +00003337 // No namespace specified, so the answer is
Greg Clayton2506a7a2011-10-12 23:34:26 +00003338 if (namespace_decl == NULL)
3339 return true;
Sean Callananebe60672011-10-13 21:50:33 +00003340
Greg Clayton5160ce52013-03-27 23:08:40 +00003341 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003342
Greg Clayton437a1352012-04-09 22:43:43 +00003343 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
3344 clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00003345 if (decl_ctx_die)
Greg Clayton437a1352012-04-09 22:43:43 +00003346 {
Greg Clayton2506a7a2011-10-12 23:34:26 +00003347 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
Greg Clayton437a1352012-04-09 22:43:43 +00003348
Greg Clayton2506a7a2011-10-12 23:34:26 +00003349 if (clang_namespace_decl)
3350 {
3351 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00003352 {
3353 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003354 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00003355 return false;
Sean Callananebe60672011-10-13 21:50:33 +00003356 }
3357
Greg Clayton437a1352012-04-09 22:43:43 +00003358 if (clang_namespace_decl == die_clang_decl_ctx)
3359 return true;
3360 else
Greg Clayton2506a7a2011-10-12 23:34:26 +00003361 return false;
Greg Clayton2506a7a2011-10-12 23:34:26 +00003362 }
3363 else
3364 {
3365 // We have a namespace_decl that was not NULL but it contained
3366 // a NULL "clang::NamespaceDecl", so this means the global namespace
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00003367 // So as long the contained decl context DIE isn't a namespace
Greg Clayton2506a7a2011-10-12 23:34:26 +00003368 // we should be ok.
3369 if (decl_ctx_die->Tag() != DW_TAG_namespace)
3370 return true;
3371 }
3372 }
Sean Callananebe60672011-10-13 21:50:33 +00003373
3374 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003375 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00003376
Greg Clayton2506a7a2011-10-12 23:34:26 +00003377 return false;
3378}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003379uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00003380SymbolFileDWARF::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 +00003381{
Greg Clayton5160ce52013-03-27 23:08:40 +00003382 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003383
3384 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003385 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003386 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
3387 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003388 static_cast<const void*>(namespace_decl),
3389 append, max_matches);
3390
Sean Callanan213fdb82011-10-13 01:49:10 +00003391 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00003392 return 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003393
Greg Claytonc685f8e2010-09-15 04:15:46 +00003394 DWARFDebugInfo* info = DebugInfo();
3395 if (info == NULL)
3396 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003397
3398 // If we aren't appending the results to this list, then clear the list
3399 if (!append)
3400 variables.Clear();
3401
3402 // Remember how many variables are in the list before we search in case
3403 // we are appending the results to a variable list.
3404 const uint32_t original_size = variables.GetSize();
3405
Greg Claytond4a2b372011-09-12 23:21:58 +00003406 DIEArray die_offsets;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003407
Greg Clayton97fbc342011-10-20 22:30:33 +00003408 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003409 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003410 if (m_apple_names_ap.get())
3411 {
3412 const char *name_cstr = name.GetCString();
Jim Inghamfa39bb42014-10-25 00:33:55 +00003413 llvm::StringRef basename;
3414 llvm::StringRef context;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003415
Jim Inghamfa39bb42014-10-25 00:33:55 +00003416 if (!CPPLanguageRuntime::ExtractContextAndIdentifier(name_cstr, context, basename))
3417 basename = name_cstr;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003418
Jim Inghamfa39bb42014-10-25 00:33:55 +00003419 m_apple_names_ap->FindByName (basename.data(), die_offsets);
Greg Clayton97fbc342011-10-20 22:30:33 +00003420 }
Greg Clayton7f995132011-10-04 22:41:51 +00003421 }
3422 else
3423 {
3424 // Index the DWARF if we haven't already
3425 if (!m_indexed)
3426 Index ();
3427
3428 m_global_index.Find (name, die_offsets);
3429 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003430
Greg Clayton437a1352012-04-09 22:43:43 +00003431 const size_t num_die_matches = die_offsets.size();
3432 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003433 {
Greg Clayton7f995132011-10-04 22:41:51 +00003434 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003435 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00003436 assert (sc.module_sp);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003437
Greg Claytond4a2b372011-09-12 23:21:58 +00003438 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00003439 DWARFCompileUnit* dwarf_cu = NULL;
3440 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton437a1352012-04-09 22:43:43 +00003441 bool done = false;
3442 for (size_t i=0; i<num_die_matches && !done; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00003443 {
3444 const dw_offset_t die_offset = die_offsets[i];
3445 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003446
Greg Clayton95d87902011-11-11 03:16:25 +00003447 if (die)
3448 {
Greg Clayton437a1352012-04-09 22:43:43 +00003449 switch (die->Tag())
3450 {
3451 default:
3452 case DW_TAG_subprogram:
3453 case DW_TAG_inlined_subroutine:
3454 case DW_TAG_try_block:
3455 case DW_TAG_catch_block:
3456 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003457
Greg Clayton437a1352012-04-09 22:43:43 +00003458 case DW_TAG_variable:
3459 {
3460 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003461
Greg Clayton437a1352012-04-09 22:43:43 +00003462 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3463 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003464
Greg Clayton437a1352012-04-09 22:43:43 +00003465 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003466
Greg Clayton437a1352012-04-09 22:43:43 +00003467 if (variables.GetSize() - original_size >= max_matches)
3468 done = true;
3469 }
3470 break;
3471 }
Greg Clayton95d87902011-11-11 03:16:25 +00003472 }
3473 else
3474 {
3475 if (m_using_apple_tables)
3476 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003477 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
3478 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003479 }
3480 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003481 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003482 }
3483
3484 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003485 const uint32_t num_matches = variables.GetSize() - original_size;
3486 if (log && num_matches > 0)
3487 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003488 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003489 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003490 name.GetCString(),
3491 static_cast<const void*>(namespace_decl),
3492 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00003493 num_matches);
3494 }
3495 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003496}
3497
3498uint32_t
3499SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
3500{
Greg Clayton5160ce52013-03-27 23:08:40 +00003501 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003502
Greg Clayton21f2a492011-10-06 00:09:08 +00003503 if (log)
3504 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003505 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003506 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003507 regex.GetText(), append,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003508 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003509 }
3510
Greg Claytonc685f8e2010-09-15 04:15:46 +00003511 DWARFDebugInfo* info = DebugInfo();
3512 if (info == NULL)
3513 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003514
3515 // If we aren't appending the results to this list, then clear the list
3516 if (!append)
3517 variables.Clear();
3518
3519 // Remember how many variables are in the list before we search in case
3520 // we are appending the results to a variable list.
3521 const uint32_t original_size = variables.GetSize();
3522
Greg Clayton7f995132011-10-04 22:41:51 +00003523 DIEArray die_offsets;
3524
Greg Clayton97fbc342011-10-20 22:30:33 +00003525 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003526 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003527 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00003528 {
3529 DWARFMappedHash::DIEInfoArray hash_data_array;
3530 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
3531 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
3532 }
Greg Clayton7f995132011-10-04 22:41:51 +00003533 }
3534 else
3535 {
3536 // Index the DWARF if we haven't already
3537 if (!m_indexed)
3538 Index ();
3539
3540 m_global_index.Find (regex, die_offsets);
3541 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003542
Greg Claytonc685f8e2010-09-15 04:15:46 +00003543 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003544 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003545 assert (sc.module_sp);
3546
Greg Claytond4a2b372011-09-12 23:21:58 +00003547 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00003548 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003549 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003550 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003551 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003552 DWARFDebugInfo* debug_info = DebugInfo();
3553 for (size_t i=0; i<num_matches; ++i)
3554 {
3555 const dw_offset_t die_offset = die_offsets[i];
3556 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00003557
3558 if (die)
3559 {
3560 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003561
Greg Clayton95d87902011-11-11 03:16:25 +00003562 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003563
Greg Clayton95d87902011-11-11 03:16:25 +00003564 if (variables.GetSize() - original_size >= max_matches)
3565 break;
3566 }
3567 else
3568 {
3569 if (m_using_apple_tables)
3570 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003571 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
3572 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00003573 }
3574 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003575 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003576 }
3577
3578 // Return the number of variable that were appended to the list
3579 return variables.GetSize() - original_size;
3580}
3581
Greg Claytonaa044962011-10-13 00:59:38 +00003582
Jim Ingham4cda6e02011-10-07 22:23:45 +00003583bool
3584SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
3585 DWARFCompileUnit *&dwarf_cu,
Pavel Labatha73d6572015-03-13 10:22:00 +00003586 bool include_inlines,
Jim Ingham4cda6e02011-10-07 22:23:45 +00003587 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00003588{
Greg Claytonaa044962011-10-13 00:59:38 +00003589 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Pavel Labatha73d6572015-03-13 10:22:00 +00003590 return ResolveFunction (dwarf_cu, die, include_inlines, sc_list);
Greg Claytonaa044962011-10-13 00:59:38 +00003591}
3592
3593
3594bool
3595SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
3596 const DWARFDebugInfoEntry *die,
Pavel Labatha73d6572015-03-13 10:22:00 +00003597 bool include_inlines,
Greg Claytonaa044962011-10-13 00:59:38 +00003598 SymbolContextList& sc_list)
3599{
Greg Clayton9e315582011-09-02 04:03:59 +00003600 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00003601
3602 if (die == NULL)
3603 return false;
3604
Jim Ingham4cda6e02011-10-07 22:23:45 +00003605 // If we were passed a die that is not a function, just return false...
Pavel Labatha73d6572015-03-13 10:22:00 +00003606 if (! (die->Tag() == DW_TAG_subprogram || (include_inlines && die->Tag() == DW_TAG_inlined_subroutine)))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003607 return false;
3608
3609 const DWARFDebugInfoEntry* inlined_die = NULL;
3610 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00003611 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003612 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00003613
Jim Ingham4cda6e02011-10-07 22:23:45 +00003614 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003615 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003616 if (die->Tag() == DW_TAG_subprogram)
3617 break;
Greg Clayton9e315582011-09-02 04:03:59 +00003618 }
3619 }
Jason Molenda60db6e42014-10-16 01:40:16 +00003620 assert (die && die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00003621 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003622 {
3623 Address addr;
3624 // Parse all blocks if needed
3625 if (inlined_die)
3626 {
Greg Claytonf7bb1fb2015-01-15 03:13:44 +00003627 Block &function_block = sc.function->GetBlock (true);
3628 sc.block = function_block.FindBlockByID (MakeUserID(inlined_die->GetOffset()));
3629 if (sc.block == NULL)
3630 sc.block = function_block.FindBlockByID (inlined_die->GetOffset());
3631 if (sc.block == NULL || sc.block->GetStartAddress (addr) == false)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003632 addr.Clear();
3633 }
3634 else
3635 {
3636 sc.block = NULL;
3637 addr = sc.function->GetAddressRange().GetBaseAddress();
3638 }
3639
3640 if (addr.IsValid())
3641 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003642 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00003643 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003644 }
3645 }
3646
Greg Claytonaa044962011-10-13 00:59:38 +00003647 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00003648}
3649
Greg Clayton7f995132011-10-04 22:41:51 +00003650void
3651SymbolFileDWARF::FindFunctions (const ConstString &name,
3652 const NameToDIE &name_to_die,
Pavel Labatha73d6572015-03-13 10:22:00 +00003653 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003654 SymbolContextList& sc_list)
3655{
Greg Claytond4a2b372011-09-12 23:21:58 +00003656 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003657 if (name_to_die.Find (name, die_offsets))
3658 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003659 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003660 }
3661}
3662
3663
3664void
3665SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3666 const NameToDIE &name_to_die,
Pavel Labatha73d6572015-03-13 10:22:00 +00003667 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003668 SymbolContextList& sc_list)
3669{
3670 DIEArray die_offsets;
3671 if (name_to_die.Find (regex, die_offsets))
3672 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003673 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003674 }
3675}
3676
3677
3678void
3679SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3680 const DWARFMappedHash::MemoryTable &memory_table,
Pavel Labatha73d6572015-03-13 10:22:00 +00003681 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003682 SymbolContextList& sc_list)
3683{
3684 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00003685 DWARFMappedHash::DIEInfoArray hash_data_array;
3686 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00003687 {
Greg Claytond1767f02011-12-08 02:13:16 +00003688 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Pavel Labatha73d6572015-03-13 10:22:00 +00003689 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003690 }
3691}
3692
3693void
3694SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
Pavel Labatha73d6572015-03-13 10:22:00 +00003695 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003696 SymbolContextList& sc_list)
3697{
3698 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003699 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00003700 {
Greg Clayton7f995132011-10-04 22:41:51 +00003701 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003702 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00003703 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003704 const dw_offset_t die_offset = die_offsets[i];
Pavel Labatha73d6572015-03-13 10:22:00 +00003705 ResolveFunction (die_offset, dwarf_cu, include_inlines, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003706 }
3707 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00003708}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003709
Jim Ingham4cda6e02011-10-07 22:23:45 +00003710bool
3711SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
3712 const DWARFCompileUnit *dwarf_cu,
3713 uint32_t name_type_mask,
3714 const char *partial_name,
3715 const char *base_name_start,
3716 const char *base_name_end)
3717{
Greg Claytonfbea0f62012-11-15 18:05:43 +00003718 // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes:
3719 if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003720 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003721 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
3722 if (!containing_decl_ctx)
3723 return false;
3724
3725 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
3726
Greg Claytonfbea0f62012-11-15 18:05:43 +00003727 if (name_type_mask == eFunctionNameTypeMethod)
3728 {
3729 if (is_cxx_method == false)
3730 return false;
3731 }
3732
3733 if (name_type_mask == eFunctionNameTypeBase)
3734 {
3735 if (is_cxx_method == true)
3736 return false;
3737 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003738 }
3739
3740 // Now we need to check whether the name we got back for this type matches the extra specifications
3741 // that were in the name we're looking up:
3742 if (base_name_start != partial_name || *base_name_end != '\0')
3743 {
3744 // First see if the stuff to the left matches the full name. To do that let's see if
3745 // we can pull out the mips linkage name attribute:
3746
3747 Mangled best_name;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003748 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonfbea0f62012-11-15 18:05:43 +00003749 DWARFFormValue form_value;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003750 die->GetAttributes(this, dwarf_cu, NULL, attributes);
3751 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
Greg Clayton71415542012-12-08 00:24:40 +00003752 if (idx == UINT32_MAX)
3753 idx = attributes.FindAttributeIndex(DW_AT_linkage_name);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003754 if (idx != UINT32_MAX)
3755 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003756 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
3757 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003758 const char *mangled_name = form_value.AsCString(&get_debug_str_data());
3759 if (mangled_name)
3760 best_name.SetValue (ConstString(mangled_name), true);
3761 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003762 }
Greg Claytonfbea0f62012-11-15 18:05:43 +00003763
3764 if (!best_name)
3765 {
3766 idx = attributes.FindAttributeIndex(DW_AT_name);
3767 if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value))
3768 {
3769 const char *name = form_value.AsCString(&get_debug_str_data());
3770 best_name.SetValue (ConstString(name), false);
3771 }
3772 }
3773
3774 if (best_name.GetDemangledName())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003775 {
3776 const char *demangled = best_name.GetDemangledName().GetCString();
3777 if (demangled)
3778 {
3779 std::string name_no_parens(partial_name, base_name_end - partial_name);
Jim Ingham85c13d72012-03-02 02:24:42 +00003780 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str());
3781 if (partial_in_demangled == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003782 return false;
Jim Ingham85c13d72012-03-02 02:24:42 +00003783 else
3784 {
3785 // Sort out the case where our name is something like "Process::Destroy" and the match is
3786 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on
3787 // namespace boundaries...
3788
3789 if (partial_name[0] == ':' && partial_name[1] == ':')
3790 {
3791 // The partial name was already on a namespace boundary so all matches are good.
3792 return true;
3793 }
3794 else if (partial_in_demangled == demangled)
3795 {
3796 // They both start the same, so this is an good match.
3797 return true;
3798 }
3799 else
3800 {
3801 if (partial_in_demangled - demangled == 1)
3802 {
3803 // Only one character difference, can't be a namespace boundary...
3804 return false;
3805 }
3806 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':')
3807 {
3808 // We are on a namespace boundary, so this is also good.
3809 return true;
3810 }
3811 else
3812 return false;
3813 }
3814 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003815 }
3816 }
3817 }
3818
3819 return true;
3820}
Greg Claytonc685f8e2010-09-15 04:15:46 +00003821
Greg Clayton0c5cd902010-06-28 21:30:43 +00003822uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00003823SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00003824 const lldb_private::ClangNamespaceDecl *namespace_decl,
Sean Callanan9df05fb2012-02-10 22:52:19 +00003825 uint32_t name_type_mask,
3826 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00003827 bool append,
3828 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00003829{
3830 Timer scoped_timer (__PRETTY_FUNCTION__,
3831 "SymbolFileDWARF::FindFunctions (name = '%s')",
3832 name.AsCString());
3833
Greg Clayton43fe2172013-04-03 02:00:15 +00003834 // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup()
3835 assert ((name_type_mask & eFunctionNameTypeAuto) == 0);
3836
Greg Clayton5160ce52013-03-27 23:08:40 +00003837 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003838
3839 if (log)
3840 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003841 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003842 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
3843 name.GetCString(),
3844 name_type_mask,
3845 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003846 }
3847
Greg Clayton0c5cd902010-06-28 21:30:43 +00003848 // If we aren't appending the results to this list, then clear the list
3849 if (!append)
3850 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003851
3852 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00003853 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003854
3855 // If name is empty then we won't find anything.
3856 if (name.IsEmpty())
3857 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00003858
3859 // Remember how many sc_list are in the list before we search in case
3860 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00003861
Jim Ingham4cda6e02011-10-07 22:23:45 +00003862 const char *name_cstr = name.GetCString();
Greg Clayton43fe2172013-04-03 02:00:15 +00003863
3864 const uint32_t original_size = sc_list.GetSize();
3865
Jim Ingham4cda6e02011-10-07 22:23:45 +00003866 DWARFDebugInfo* info = DebugInfo();
3867 if (info == NULL)
3868 return 0;
3869
Greg Claytonaa044962011-10-13 00:59:38 +00003870 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton43fe2172013-04-03 02:00:15 +00003871 std::set<const DWARFDebugInfoEntry *> resolved_dies;
Greg Clayton97fbc342011-10-20 22:30:33 +00003872 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00003873 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003874 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003875 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003876
3877 DIEArray die_offsets;
3878
3879 uint32_t num_matches = 0;
3880
Greg Clayton43fe2172013-04-03 02:00:15 +00003881 if (name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00003882 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003883 // If they asked for the full name, match what they typed. At some point we may
3884 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
3885 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00003886 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003887 for (uint32_t i = 0; i < num_matches; i++)
3888 {
Greg Clayton95d87902011-11-11 03:16:25 +00003889 const dw_offset_t die_offset = die_offsets[i];
3890 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00003891 if (die)
3892 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003893 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3894 continue;
3895
Greg Clayton43fe2172013-04-03 02:00:15 +00003896 if (resolved_dies.find(die) == resolved_dies.end())
3897 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003898 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00003899 resolved_dies.insert(die);
3900 }
Greg Claytonaa044962011-10-13 00:59:38 +00003901 }
Greg Clayton95d87902011-11-11 03:16:25 +00003902 else
3903 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003904 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3905 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003906 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003907 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003908 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003909
3910 if (name_type_mask & eFunctionNameTypeSelector)
3911 {
3912 if (namespace_decl && *namespace_decl)
3913 return 0; // no selectors in namespaces
Greg Clayton97fbc342011-10-20 22:30:33 +00003914
Greg Clayton43fe2172013-04-03 02:00:15 +00003915 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3916 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
3917 // and if it is an ObjC method name, we're good.
Greg Clayton97fbc342011-10-20 22:30:33 +00003918
Greg Clayton43fe2172013-04-03 02:00:15 +00003919 for (uint32_t i = 0; i < num_matches; i++)
Greg Clayton97fbc342011-10-20 22:30:33 +00003920 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003921 const dw_offset_t die_offset = die_offsets[i];
3922 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3923 if (die)
Greg Clayton97fbc342011-10-20 22:30:33 +00003924 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003925 const char *die_name = die->GetName(this, dwarf_cu);
3926 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
Greg Clayton97fbc342011-10-20 22:30:33 +00003927 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003928 if (resolved_dies.find(die) == resolved_dies.end())
3929 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003930 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00003931 resolved_dies.insert(die);
3932 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003933 }
3934 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003935 else
3936 {
3937 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3938 die_offset, name_cstr);
3939 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003940 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003941 die_offsets.clear();
3942 }
3943
3944 if (((name_type_mask & eFunctionNameTypeMethod) && !namespace_decl) || name_type_mask & eFunctionNameTypeBase)
3945 {
3946 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
3947 // extract the base name, look that up, and if there is any other information in the name we were
3948 // passed in we have to post-filter based on that.
3949
3950 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
3951 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3952
3953 for (uint32_t i = 0; i < num_matches; i++)
3954 {
3955 const dw_offset_t die_offset = die_offsets[i];
3956 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3957 if (die)
3958 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003959 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3960 continue;
3961
3962 // If we get to here, the die is good, and we should add it:
3963 if (resolved_dies.find(die) == resolved_dies.end())
Pavel Labatha73d6572015-03-13 10:22:00 +00003964 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00003965 {
3966 bool keep_die = true;
3967 if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod))
3968 {
3969 // We are looking for either basenames or methods, so we need to
3970 // trim out the ones we won't want by looking at the type
3971 SymbolContext sc;
3972 if (sc_list.GetLastContext(sc))
3973 {
3974 if (sc.block)
3975 {
3976 // We have an inlined function
3977 }
3978 else if (sc.function)
3979 {
3980 Type *type = sc.function->GetType();
3981
Sean Callananc370a8a2013-09-18 22:59:55 +00003982 if (type)
Greg Clayton43fe2172013-04-03 02:00:15 +00003983 {
Sean Callananc370a8a2013-09-18 22:59:55 +00003984 clang::DeclContext* decl_ctx = GetClangDeclContextContainingTypeUID (type->GetID());
3985 if (decl_ctx->isRecord())
Greg Clayton43fe2172013-04-03 02:00:15 +00003986 {
Sean Callananc370a8a2013-09-18 22:59:55 +00003987 if (name_type_mask & eFunctionNameTypeBase)
3988 {
3989 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3990 keep_die = false;
3991 }
3992 }
3993 else
3994 {
3995 if (name_type_mask & eFunctionNameTypeMethod)
3996 {
3997 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3998 keep_die = false;
3999 }
Greg Clayton43fe2172013-04-03 02:00:15 +00004000 }
4001 }
4002 else
4003 {
Sean Callananc370a8a2013-09-18 22:59:55 +00004004 GetObjectFile()->GetModule()->ReportWarning ("function at die offset 0x%8.8x had no function type",
4005 die_offset);
Greg Clayton43fe2172013-04-03 02:00:15 +00004006 }
4007 }
4008 }
4009 }
4010 if (keep_die)
4011 resolved_dies.insert(die);
4012 }
4013 }
4014 else
4015 {
4016 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
4017 die_offset, name_cstr);
4018 }
4019 }
4020 die_offsets.clear();
Jim Ingham4cda6e02011-10-07 22:23:45 +00004021 }
4022 }
Greg Clayton7f995132011-10-04 22:41:51 +00004023 }
4024 else
4025 {
4026
4027 // Index the DWARF if we haven't already
4028 if (!m_indexed)
4029 Index ();
4030
Greg Clayton7f995132011-10-04 22:41:51 +00004031 if (name_type_mask & eFunctionNameTypeFull)
Matt Kopecd6089962013-05-10 17:53:48 +00004032 {
Pavel Labatha73d6572015-03-13 10:22:00 +00004033 FindFunctions (name, m_function_fullname_index, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00004034
Ed Mastefc7baa02013-09-09 18:00:45 +00004035 // FIXME Temporary workaround for global/anonymous namespace
4036 // functions on FreeBSD and Linux
4037#if defined (__FreeBSD__) || defined (__linux__)
Matt Kopecd6089962013-05-10 17:53:48 +00004038 // If we didn't find any functions in the global namespace try
4039 // looking in the basename index but ignore any returned
4040 // functions that have a namespace (ie. mangled names starting with
4041 // '_ZN') but keep functions which have an anonymous namespace
4042 if (sc_list.GetSize() == 0)
4043 {
4044 SymbolContextList temp_sc_list;
Pavel Labatha73d6572015-03-13 10:22:00 +00004045 FindFunctions (name, m_function_basename_index, include_inlines, temp_sc_list);
Matt Kopecd6089962013-05-10 17:53:48 +00004046 if (!namespace_decl)
4047 {
4048 SymbolContext sc;
4049 for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++)
4050 {
4051 if (temp_sc_list.GetContextAtIndex(i, sc))
4052 {
Matt Kopeca189d492013-05-10 22:55:24 +00004053 ConstString mangled_name = sc.GetFunctionName(Mangled::ePreferMangled);
4054 ConstString demangled_name = sc.GetFunctionName(Mangled::ePreferDemangled);
Matt Kopec04e5d582013-05-14 19:00:41 +00004055 if (strncmp(mangled_name.GetCString(), "_ZN", 3) ||
4056 !strncmp(demangled_name.GetCString(), "(anonymous namespace)", 21))
Matt Kopecd6089962013-05-10 17:53:48 +00004057 {
4058 sc_list.Append(sc);
4059 }
4060 }
4061 }
4062 }
4063 }
4064#endif
4065 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00004066 DIEArray die_offsets;
4067 DWARFCompileUnit *dwarf_cu = NULL;
4068
Greg Clayton43fe2172013-04-03 02:00:15 +00004069 if (name_type_mask & eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00004070 {
Greg Clayton43fe2172013-04-03 02:00:15 +00004071 uint32_t num_base = m_function_basename_index.Find(name, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00004072 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00004073 {
Greg Claytonaa044962011-10-13 00:59:38 +00004074 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
4075 if (die)
4076 {
Sean Callanan213fdb82011-10-13 01:49:10 +00004077 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
4078 continue;
4079
Greg Claytonaa044962011-10-13 00:59:38 +00004080 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00004081 if (resolved_dies.find(die) == resolved_dies.end())
4082 {
Pavel Labatha73d6572015-03-13 10:22:00 +00004083 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00004084 resolved_dies.insert(die);
4085 }
Greg Claytonaa044962011-10-13 00:59:38 +00004086 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00004087 }
4088 die_offsets.clear();
4089 }
4090
Greg Clayton43fe2172013-04-03 02:00:15 +00004091 if (name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00004092 {
Sean Callanan213fdb82011-10-13 01:49:10 +00004093 if (namespace_decl && *namespace_decl)
4094 return 0; // no methods in namespaces
4095
Greg Clayton43fe2172013-04-03 02:00:15 +00004096 uint32_t num_base = m_function_method_index.Find(name, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00004097 {
Greg Claytonaa044962011-10-13 00:59:38 +00004098 for (uint32_t i = 0; i < num_base; i++)
4099 {
4100 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
4101 if (die)
4102 {
Greg Claytonaa044962011-10-13 00:59:38 +00004103 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00004104 if (resolved_dies.find(die) == resolved_dies.end())
4105 {
Pavel Labatha73d6572015-03-13 10:22:00 +00004106 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00004107 resolved_dies.insert(die);
4108 }
Greg Claytonaa044962011-10-13 00:59:38 +00004109 }
4110 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00004111 }
4112 die_offsets.clear();
4113 }
Greg Clayton7f995132011-10-04 22:41:51 +00004114
Greg Clayton43fe2172013-04-03 02:00:15 +00004115 if ((name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00004116 {
Pavel Labatha73d6572015-03-13 10:22:00 +00004117 FindFunctions (name, m_function_selector_index, include_inlines, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00004118 }
4119
Greg Clayton4d01ace2011-09-29 16:58:15 +00004120 }
4121
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004122 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00004123 const uint32_t num_matches = sc_list.GetSize() - original_size;
4124
4125 if (log && num_matches > 0)
4126 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004127 GetObjectFile()->GetModule()->LogMessage (log,
Pavel Labatha73d6572015-03-13 10:22:00 +00004128 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, include_inlines=%d, append=%u, sc_list) => %u",
Greg Clayton437a1352012-04-09 22:43:43 +00004129 name.GetCString(),
4130 name_type_mask,
Pavel Labatha73d6572015-03-13 10:22:00 +00004131 include_inlines,
Greg Clayton437a1352012-04-09 22:43:43 +00004132 append,
4133 num_matches);
4134 }
4135 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004136}
4137
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004138uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00004139SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004140{
4141 Timer scoped_timer (__PRETTY_FUNCTION__,
4142 "SymbolFileDWARF::FindFunctions (regex = '%s')",
4143 regex.GetText());
4144
Greg Clayton5160ce52013-03-27 23:08:40 +00004145 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00004146
4147 if (log)
4148 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004149 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00004150 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
4151 regex.GetText(),
4152 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00004153 }
4154
4155
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004156 // If we aren't appending the results to this list, then clear the list
4157 if (!append)
4158 sc_list.Clear();
4159
4160 // Remember how many sc_list are in the list before we search in case
4161 // we are appending the results to a variable list.
4162 uint32_t original_size = sc_list.GetSize();
4163
Greg Clayton97fbc342011-10-20 22:30:33 +00004164 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004165 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004166 if (m_apple_names_ap.get())
Pavel Labatha73d6572015-03-13 10:22:00 +00004167 FindFunctions (regex, *m_apple_names_ap, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00004168 }
4169 else
4170 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00004171 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00004172 if (!m_indexed)
4173 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004174
Pavel Labatha73d6572015-03-13 10:22:00 +00004175 FindFunctions (regex, m_function_basename_index, include_inlines, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004176
Pavel Labatha73d6572015-03-13 10:22:00 +00004177 FindFunctions (regex, m_function_fullname_index, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00004178 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004179
4180 // Return the number of variable that were appended to the list
4181 return sc_list.GetSize() - original_size;
4182}
Jim Ingham318c9f22011-08-26 19:44:13 +00004183
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004184uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00004185SymbolFileDWARF::FindTypes (const SymbolContext& sc,
4186 const ConstString &name,
4187 const lldb_private::ClangNamespaceDecl *namespace_decl,
4188 bool append,
4189 uint32_t max_matches,
4190 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004191{
Greg Claytonc685f8e2010-09-15 04:15:46 +00004192 DWARFDebugInfo* info = DebugInfo();
4193 if (info == NULL)
4194 return 0;
4195
Greg Clayton5160ce52013-03-27 23:08:40 +00004196 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004197
Greg Clayton21f2a492011-10-06 00:09:08 +00004198 if (log)
4199 {
Greg Clayton437a1352012-04-09 22:43:43 +00004200 if (namespace_decl)
Greg Clayton5160ce52013-03-27 23:08:40 +00004201 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004202 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)",
4203 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004204 static_cast<void*>(namespace_decl->GetNamespaceDecl()),
Greg Clayton437a1352012-04-09 22:43:43 +00004205 namespace_decl->GetQualifiedName().c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004206 append, max_matches);
Greg Clayton437a1352012-04-09 22:43:43 +00004207 else
Greg Clayton5160ce52013-03-27 23:08:40 +00004208 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004209 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004210 name.GetCString(), append,
Greg Clayton437a1352012-04-09 22:43:43 +00004211 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00004212 }
4213
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004214 // If we aren't appending the results to this list, then clear the list
4215 if (!append)
4216 types.Clear();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004217
Sean Callanan213fdb82011-10-13 01:49:10 +00004218 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00004219 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004220
Greg Claytond4a2b372011-09-12 23:21:58 +00004221 DIEArray die_offsets;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004222
Greg Clayton97fbc342011-10-20 22:30:33 +00004223 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004224 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004225 if (m_apple_types_ap.get())
4226 {
4227 const char *name_cstr = name.GetCString();
4228 m_apple_types_ap->FindByName (name_cstr, die_offsets);
4229 }
Greg Clayton7f995132011-10-04 22:41:51 +00004230 }
4231 else
4232 {
4233 if (!m_indexed)
4234 Index ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004235
Greg Clayton7f995132011-10-04 22:41:51 +00004236 m_type_index.Find (name, die_offsets);
4237 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004238
Greg Clayton437a1352012-04-09 22:43:43 +00004239 const size_t num_die_matches = die_offsets.size();
Greg Clayton7f995132011-10-04 22:41:51 +00004240
Greg Clayton437a1352012-04-09 22:43:43 +00004241 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004242 {
Greg Clayton7f995132011-10-04 22:41:51 +00004243 const uint32_t initial_types_size = types.GetSize();
4244 DWARFCompileUnit* dwarf_cu = NULL;
4245 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00004246 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00004247 for (size_t i=0; i<num_die_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004248 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004249 const dw_offset_t die_offset = die_offsets[i];
4250 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
4251
Greg Clayton95d87902011-11-11 03:16:25 +00004252 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00004253 {
Greg Clayton95d87902011-11-11 03:16:25 +00004254 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
4255 continue;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004256
Greg Clayton95d87902011-11-11 03:16:25 +00004257 Type *matching_type = ResolveType (dwarf_cu, die);
4258 if (matching_type)
4259 {
4260 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00004261 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00004262 if (types.GetSize() >= max_matches)
4263 break;
4264 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00004265 }
Greg Clayton95d87902011-11-11 03:16:25 +00004266 else
4267 {
4268 if (m_using_apple_tables)
4269 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004270 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4271 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004272 }
4273 }
4274
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004275 }
Greg Clayton437a1352012-04-09 22:43:43 +00004276 const uint32_t num_matches = types.GetSize() - initial_types_size;
4277 if (log && num_matches)
4278 {
4279 if (namespace_decl)
4280 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004281 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004282 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u",
4283 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004284 static_cast<void*>(namespace_decl->GetNamespaceDecl()),
Greg Clayton437a1352012-04-09 22:43:43 +00004285 namespace_decl->GetQualifiedName().c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004286 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00004287 num_matches);
4288 }
4289 else
4290 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004291 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004292 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u",
4293 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004294 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00004295 num_matches);
4296 }
4297 }
4298 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004299 }
Greg Clayton7f995132011-10-04 22:41:51 +00004300 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004301}
4302
4303
Greg Clayton526e5af2010-11-13 03:52:47 +00004304ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00004305SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00004306 const ConstString &name,
4307 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004308{
Greg Clayton5160ce52013-03-27 23:08:40 +00004309 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00004310
4311 if (log)
4312 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004313 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00004314 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
4315 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00004316 }
Sean Callanan213fdb82011-10-13 01:49:10 +00004317
4318 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00004319 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00004320
Greg Clayton526e5af2010-11-13 03:52:47 +00004321 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004322 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00004323 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00004324 {
Greg Clayton7f995132011-10-04 22:41:51 +00004325 DIEArray die_offsets;
4326
Greg Clayton526e5af2010-11-13 03:52:47 +00004327 // Index if we already haven't to make sure the compile units
4328 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00004329 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004330 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004331 if (m_apple_namespaces_ap.get())
4332 {
4333 const char *name_cstr = name.GetCString();
4334 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
4335 }
Greg Clayton7f995132011-10-04 22:41:51 +00004336 }
4337 else
4338 {
4339 if (!m_indexed)
4340 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00004341
Greg Clayton7f995132011-10-04 22:41:51 +00004342 m_namespace_index.Find (name, die_offsets);
4343 }
Greg Claytond4a2b372011-09-12 23:21:58 +00004344
4345 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00004346 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00004347 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00004348 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00004349 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004350 DWARFDebugInfo* debug_info = DebugInfo();
4351 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00004352 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004353 const dw_offset_t die_offset = die_offsets[i];
4354 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00004355
Greg Clayton95d87902011-11-11 03:16:25 +00004356 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00004357 {
Greg Clayton95d87902011-11-11 03:16:25 +00004358 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
4359 continue;
4360
4361 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
4362 if (clang_namespace_decl)
4363 {
4364 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
4365 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
Greg Claytond1767f02011-12-08 02:13:16 +00004366 break;
Greg Clayton95d87902011-11-11 03:16:25 +00004367 }
Greg Claytond4a2b372011-09-12 23:21:58 +00004368 }
Greg Clayton95d87902011-11-11 03:16:25 +00004369 else
4370 {
4371 if (m_using_apple_tables)
4372 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004373 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
4374 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004375 }
4376 }
4377
Greg Clayton526e5af2010-11-13 03:52:47 +00004378 }
4379 }
Greg Clayton96d7d742010-11-10 23:42:09 +00004380 }
Greg Clayton437a1352012-04-09 22:43:43 +00004381 if (log && namespace_decl.GetNamespaceDecl())
4382 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004383 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004384 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"",
4385 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004386 static_cast<const void*>(namespace_decl.GetNamespaceDecl()),
Greg Clayton437a1352012-04-09 22:43:43 +00004387 namespace_decl.GetQualifiedName().c_str());
4388 }
4389
Greg Clayton526e5af2010-11-13 03:52:47 +00004390 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004391}
4392
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004393uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004394SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004395{
4396 // Remember how many sc_list are in the list before we search in case
4397 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004398 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004399
4400 const uint32_t num_die_offsets = die_offsets.size();
4401 // Parse all of the types we found from the pubtypes matches
4402 uint32_t i;
4403 uint32_t num_matches = 0;
4404 for (i = 0; i < num_die_offsets; ++i)
4405 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004406 Type *matching_type = ResolveTypeUID (die_offsets[i]);
4407 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004408 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004409 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00004410 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004411 ++num_matches;
4412 if (num_matches >= max_matches)
4413 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004414 }
4415 }
4416
4417 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004418 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004419}
4420
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004421
4422size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00004423SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
4424 clang::DeclContext *containing_decl_ctx,
Greg Clayton5113dc82011-08-12 06:47:54 +00004425 DWARFCompileUnit* dwarf_cu,
4426 const DWARFDebugInfoEntry *parent_die,
4427 bool skip_artificial,
4428 bool &is_static,
Greg Clayton03969752014-02-24 18:53:11 +00004429 bool &is_variadic,
Greg Clayton57ee3062013-07-11 22:46:58 +00004430 std::vector<ClangASTType>& function_param_types,
Greg Clayton5113dc82011-08-12 06:47:54 +00004431 std::vector<clang::ParmVarDecl*>& function_param_decls,
Greg Claytond20deac2014-04-04 18:15:18 +00004432 unsigned &type_quals) // ,
4433 // ClangASTContext::TemplateParameterInfos &template_param_infos))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004434{
4435 if (parent_die == NULL)
4436 return 0;
4437
Todd Fialaee8bfc62014-09-11 17:29:12 +00004438 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Claytond88d7592010-09-15 08:33:30 +00004439
Greg Clayton7fedea22010-11-16 02:10:54 +00004440 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004441 const DWARFDebugInfoEntry *die;
4442 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4443 {
4444 dw_tag_t tag = die->Tag();
4445 switch (tag)
4446 {
4447 case DW_TAG_formal_parameter:
4448 {
4449 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004450 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004451 if (num_attributes > 0)
4452 {
4453 const char *name = NULL;
4454 Declaration decl;
4455 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00004456 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004457 // one of None, Auto, Register, Extern, Static, PrivateExtern
4458
Sean Callanane2ef6e32010-09-23 03:01:22 +00004459 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004460 uint32_t i;
4461 for (i=0; i<num_attributes; ++i)
4462 {
4463 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4464 DWARFFormValue form_value;
4465 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4466 {
4467 switch (attr)
4468 {
4469 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4470 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4471 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4472 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00004473 case DW_AT_type: param_type_die_offset = form_value.Reference(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00004474 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004475 case DW_AT_location:
4476 // if (form_value.BlockData())
4477 // {
Ed Masteeeae7212013-10-24 20:43:47 +00004478 // const DWARFDataExtractor& debug_info_data = debug_info();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004479 // uint32_t block_length = form_value.Unsigned();
Ed Masteeeae7212013-10-24 20:43:47 +00004480 // DWARFDataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004481 // }
4482 // else
4483 // {
4484 // }
4485 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004486 case DW_AT_const_value:
4487 case DW_AT_default_value:
4488 case DW_AT_description:
4489 case DW_AT_endianity:
4490 case DW_AT_is_optional:
4491 case DW_AT_segment:
4492 case DW_AT_variable_parameter:
4493 default:
4494 case DW_AT_abstract_origin:
4495 case DW_AT_sibling:
4496 break;
4497 }
4498 }
4499 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00004500
Greg Clayton0fffff52010-09-24 05:15:53 +00004501 bool skip = false;
4502 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004503 {
Greg Clayton0fffff52010-09-24 05:15:53 +00004504 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00004505 {
4506 // In order to determine if a C++ member function is
4507 // "const" we have to look at the const-ness of "this"...
4508 // Ugly, but that
4509 if (arg_idx == 0)
4510 {
Greg Claytonf0705c82011-10-22 03:33:13 +00004511 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00004512 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004513 // Often times compilers omit the "this" name for the
4514 // specification DIEs, so we can't rely upon the name
4515 // being in the formal parameter DIE...
4516 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00004517 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004518 Type *this_type = ResolveTypeUID (param_type_die_offset);
4519 if (this_type)
4520 {
4521 uint32_t encoding_mask = this_type->GetEncodingMask();
4522 if (encoding_mask & Type::eEncodingIsPointerUID)
4523 {
4524 is_static = false;
4525
4526 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
4527 type_quals |= clang::Qualifiers::Const;
4528 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
4529 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00004530 }
4531 }
4532 }
4533 }
4534 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004535 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00004536 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004537 else
4538 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004539
Greg Clayton0fffff52010-09-24 05:15:53 +00004540 // HACK: Objective C formal parameters "self" and "_cmd"
4541 // are not marked as artificial in the DWARF...
Greg Clayton53eb1c22012-04-02 22:59:12 +00004542 CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
4543 if (comp_unit)
Greg Clayton0fffff52010-09-24 05:15:53 +00004544 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004545 switch (comp_unit->GetLanguage())
4546 {
4547 case eLanguageTypeObjC:
4548 case eLanguageTypeObjC_plus_plus:
4549 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
4550 skip = true;
4551 break;
4552 default:
4553 break;
4554 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004555 }
4556 }
4557 }
4558
4559 if (!skip)
4560 {
4561 Type *type = ResolveTypeUID(param_type_die_offset);
4562 if (type)
4563 {
Greg Claytonc93237c2010-10-01 20:48:32 +00004564 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00004565
Greg Clayton42ce2f32011-12-12 21:50:19 +00004566 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
4567 type->GetClangForwardType(),
4568 storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00004569 assert(param_var_decl);
4570 function_param_decls.push_back(param_var_decl);
Sean Callanan60217122012-04-13 00:10:03 +00004571
Greg Claytond0029442013-03-27 01:48:02 +00004572 GetClangASTContext().SetMetadataAsUserID (param_var_decl, MakeUserID(die->GetOffset()));
Greg Clayton0fffff52010-09-24 05:15:53 +00004573 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004574 }
4575 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004576 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004577 }
4578 break;
4579
Greg Clayton03969752014-02-24 18:53:11 +00004580 case DW_TAG_unspecified_parameters:
4581 is_variadic = true;
4582 break;
4583
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004584 case DW_TAG_template_type_parameter:
4585 case DW_TAG_template_value_parameter:
Greg Claytond20deac2014-04-04 18:15:18 +00004586 // The one caller of this was never using the template_param_infos,
4587 // and the local variable was taking up a large amount of stack space
4588 // in SymbolFileDWARF::ParseType() so this was removed. If we ever need
4589 // the template params back, we can add them back.
4590 // ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004591 break;
4592
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004593 default:
4594 break;
4595 }
4596 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004597 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004598}
4599
4600size_t
4601SymbolFileDWARF::ParseChildEnumerators
4602(
4603 const SymbolContext& sc,
Greg Clayton57ee3062013-07-11 22:46:58 +00004604 lldb_private::ClangASTType &clang_type,
Greg Clayton3e067532013-03-05 23:54:39 +00004605 bool is_signed,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004606 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00004607 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004608 const DWARFDebugInfoEntry *parent_die
4609)
4610{
4611 if (parent_die == NULL)
4612 return 0;
4613
4614 size_t enumerators_added = 0;
4615 const DWARFDebugInfoEntry *die;
Todd Fialaee8bfc62014-09-11 17:29:12 +00004616 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Claytond88d7592010-09-15 08:33:30 +00004617
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004618 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4619 {
4620 const dw_tag_t tag = die->Tag();
4621 if (tag == DW_TAG_enumerator)
4622 {
4623 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004624 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004625 if (num_child_attributes > 0)
4626 {
4627 const char *name = NULL;
4628 bool got_value = false;
4629 int64_t enum_value = 0;
4630 Declaration decl;
4631
4632 uint32_t i;
4633 for (i=0; i<num_child_attributes; ++i)
4634 {
4635 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4636 DWARFFormValue form_value;
4637 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4638 {
4639 switch (attr)
4640 {
4641 case DW_AT_const_value:
4642 got_value = true;
Greg Clayton3e067532013-03-05 23:54:39 +00004643 if (is_signed)
4644 enum_value = form_value.Signed();
4645 else
4646 enum_value = form_value.Unsigned();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004647 break;
4648
4649 case DW_AT_name:
4650 name = form_value.AsCString(&get_debug_str_data());
4651 break;
4652
4653 case DW_AT_description:
4654 default:
4655 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4656 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4657 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4658 case DW_AT_sibling:
4659 break;
4660 }
4661 }
4662 }
4663
4664 if (name && name[0] && got_value)
4665 {
Greg Clayton57ee3062013-07-11 22:46:58 +00004666 clang_type.AddEnumerationValueToEnumerationType (clang_type.GetEnumerationIntegerType(),
4667 decl,
4668 name,
4669 enum_value,
4670 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004671 ++enumerators_added;
4672 }
4673 }
4674 }
4675 }
4676 return enumerators_added;
4677}
4678
4679void
4680SymbolFileDWARF::ParseChildArrayInfo
4681(
4682 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004683 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004684 const DWARFDebugInfoEntry *parent_die,
4685 int64_t& first_index,
4686 std::vector<uint64_t>& element_orders,
4687 uint32_t& byte_stride,
4688 uint32_t& bit_stride
4689)
4690{
4691 if (parent_die == NULL)
4692 return;
4693
4694 const DWARFDebugInfoEntry *die;
Todd Fialaee8bfc62014-09-11 17:29:12 +00004695 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004696 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4697 {
4698 const dw_tag_t tag = die->Tag();
4699 switch (tag)
4700 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004701 case DW_TAG_subrange_type:
4702 {
4703 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004704 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004705 if (num_child_attributes > 0)
4706 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004707 uint64_t num_elements = 0;
4708 uint64_t lower_bound = 0;
4709 uint64_t upper_bound = 0;
Greg Clayton4ef877f2012-12-06 02:33:54 +00004710 bool upper_bound_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004711 uint32_t i;
4712 for (i=0; i<num_child_attributes; ++i)
4713 {
4714 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4715 DWARFFormValue form_value;
4716 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4717 {
4718 switch (attr)
4719 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004720 case DW_AT_name:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004721 break;
4722
4723 case DW_AT_count:
4724 num_elements = form_value.Unsigned();
4725 break;
4726
4727 case DW_AT_bit_stride:
4728 bit_stride = form_value.Unsigned();
4729 break;
4730
4731 case DW_AT_byte_stride:
4732 byte_stride = form_value.Unsigned();
4733 break;
4734
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004735 case DW_AT_lower_bound:
4736 lower_bound = form_value.Unsigned();
4737 break;
4738
4739 case DW_AT_upper_bound:
Greg Clayton4ef877f2012-12-06 02:33:54 +00004740 upper_bound_valid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004741 upper_bound = form_value.Unsigned();
4742 break;
4743
4744 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004745 case DW_AT_abstract_origin:
4746 case DW_AT_accessibility:
4747 case DW_AT_allocated:
4748 case DW_AT_associated:
4749 case DW_AT_data_location:
4750 case DW_AT_declaration:
4751 case DW_AT_description:
4752 case DW_AT_sibling:
4753 case DW_AT_threads_scaled:
4754 case DW_AT_type:
4755 case DW_AT_visibility:
4756 break;
4757 }
4758 }
4759 }
4760
Greg Claytone6a07792012-12-05 21:59:39 +00004761 if (num_elements == 0)
4762 {
Greg Clayton4ef877f2012-12-06 02:33:54 +00004763 if (upper_bound_valid && upper_bound >= lower_bound)
Greg Claytone6a07792012-12-05 21:59:39 +00004764 num_elements = upper_bound - lower_bound + 1;
4765 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004766
Sean Callananec979ba2012-10-22 23:56:48 +00004767 element_orders.push_back (num_elements);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004768 }
4769 }
4770 break;
4771 }
4772 }
4773}
4774
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004775TypeSP
Greg Clayton53eb1c22012-04-02 22:59:12 +00004776SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004777{
4778 TypeSP type_sp;
4779 if (die != NULL)
4780 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004781 assert(dwarf_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00004782 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004783 if (type_ptr == NULL)
4784 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004785 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu);
Greg Claytonca512b32011-01-14 04:54:56 +00004786 assert (lldb_cu);
4787 SymbolContext sc(lldb_cu);
Greg Clayton53eb1c22012-04-02 22:59:12 +00004788 type_sp = ParseType(sc, dwarf_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004789 }
4790 else if (type_ptr != DIE_IS_BEING_PARSED)
4791 {
4792 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00004793 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004794 }
4795
4796 }
4797 return type_sp;
4798}
4799
4800clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00004801SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004802{
4803 if (die_offset != DW_INVALID_OFFSET)
4804 {
4805 DWARFCompileUnitSP cu_sp;
4806 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004807 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004808 }
4809 return NULL;
4810}
4811
Sean Callanan72e49402011-08-05 23:43:37 +00004812clang::DeclContext *
4813SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
4814{
4815 if (die_offset != DW_INVALID_OFFSET)
4816 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004817 DWARFDebugInfo* debug_info = DebugInfo();
4818 if (debug_info)
4819 {
4820 DWARFCompileUnitSP cu_sp;
4821 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
4822 if (die)
4823 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
4824 }
Sean Callanan72e49402011-08-05 23:43:37 +00004825 }
4826 return NULL;
4827}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004828
Greg Clayton96d7d742010-11-10 23:42:09 +00004829clang::NamespaceDecl *
Greg Clayton53eb1c22012-04-02 22:59:12 +00004830SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die)
Greg Clayton96d7d742010-11-10 23:42:09 +00004831{
Greg Clayton030a2042011-10-14 21:34:45 +00004832 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00004833 {
Greg Clayton030a2042011-10-14 21:34:45 +00004834 // See if we already parsed this namespace DIE and associated it with a
4835 // uniqued namespace declaration
4836 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
4837 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004838 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00004839 else
4840 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004841 const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL);
4842 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00004843 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
Greg Clayton5160ce52013-03-27 23:08:40 +00004844 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton9d3d6882011-10-31 23:51:19 +00004845 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00004846 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00004847 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00004848 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004849 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00004850 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004851 static_cast<void*>(GetClangASTContext().getASTContext()),
Greg Claytone38a5ed2012-01-05 03:57:59 +00004852 MakeUserID(die->GetOffset()),
4853 namespace_name,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004854 static_cast<void*>(namespace_decl),
4855 static_cast<void*>(namespace_decl->getOriginalNamespace()));
Greg Clayton030a2042011-10-14 21:34:45 +00004856 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004857 else
4858 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004859 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00004860 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004861 static_cast<void*>(GetClangASTContext().getASTContext()),
Greg Claytone38a5ed2012-01-05 03:57:59 +00004862 MakeUserID(die->GetOffset()),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004863 static_cast<void*>(namespace_decl),
4864 static_cast<void*>(namespace_decl->getOriginalNamespace()));
Greg Clayton9d3d6882011-10-31 23:51:19 +00004865 }
Greg Clayton030a2042011-10-14 21:34:45 +00004866 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004867
4868 if (namespace_decl)
4869 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
4870 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004871 }
4872 }
4873 return NULL;
4874}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004875
4876clang::DeclContext *
Greg Claytoncab36a32011-12-08 05:16:30 +00004877SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Sean Callanan72e49402011-08-05 23:43:37 +00004878{
Greg Clayton5cf58b92011-10-05 22:22:08 +00004879 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4880 if (clang_decl_ctx)
4881 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004882 // If this DIE has a specification, or an abstract origin, then trace to those.
4883
Greg Claytoncab36a32011-12-08 05:16:30 +00004884 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004885 if (die_offset != DW_INVALID_OFFSET)
4886 return GetClangDeclContextForDIEOffset (sc, die_offset);
4887
Greg Claytoncab36a32011-12-08 05:16:30 +00004888 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004889 if (die_offset != DW_INVALID_OFFSET)
4890 return GetClangDeclContextForDIEOffset (sc, die_offset);
4891
Greg Clayton5160ce52013-03-27 23:08:40 +00004892 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00004893 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004894 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 +00004895 // This is the DIE we want. Parse it, then query our map.
Greg Claytoncab36a32011-12-08 05:16:30 +00004896 bool assert_not_being_parsed = true;
4897 ResolveTypeUID (cu, die, assert_not_being_parsed);
4898
Greg Clayton5cf58b92011-10-05 22:22:08 +00004899 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4900
4901 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004902}
4903
4904clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00004905SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004906{
Greg Claytonca512b32011-01-14 04:54:56 +00004907 if (m_clang_tu_decl == NULL)
4908 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004909
Greg Clayton2bc22f82011-09-30 03:20:47 +00004910 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004911
4912 if (decl_ctx_die_copy)
4913 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00004914
4915 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004916 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00004917
Greg Clayton2bc22f82011-09-30 03:20:47 +00004918 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
4919 if (pos != m_die_to_decl_ctx.end())
4920 return pos->second;
4921
4922 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004923 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004924 case DW_TAG_compile_unit:
4925 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004926
Greg Clayton2bc22f82011-09-30 03:20:47 +00004927 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00004928 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00004929 break;
4930
4931 case DW_TAG_structure_type:
4932 case DW_TAG_union_type:
4933 case DW_TAG_class_type:
4934 {
4935 Type* type = ResolveType (cu, decl_ctx_die);
4936 if (type)
4937 {
Greg Clayton57ee3062013-07-11 22:46:58 +00004938 clang::DeclContext *decl_ctx = type->GetClangForwardType().GetDeclContextForType ();
Greg Clayton2bc22f82011-09-30 03:20:47 +00004939 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00004940 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004941 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
4942 if (decl_ctx)
4943 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00004944 }
4945 }
Greg Claytonca512b32011-01-14 04:54:56 +00004946 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00004947 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004948
Greg Clayton2bc22f82011-09-30 03:20:47 +00004949 default:
4950 break;
Greg Claytonca512b32011-01-14 04:54:56 +00004951 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004952 }
Greg Clayton7a345282010-11-09 23:46:37 +00004953 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004954}
4955
Greg Clayton2bc22f82011-09-30 03:20:47 +00004956
4957const DWARFDebugInfoEntry *
4958SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4959{
4960 if (cu && die)
4961 {
4962 const DWARFDebugInfoEntry * const decl_die = die;
4963
4964 while (die != NULL)
4965 {
4966 // If this is the original DIE that we are searching for a declaration
4967 // for, then don't look in the cache as we don't want our own decl
4968 // context to be our decl context...
4969 if (decl_die != die)
4970 {
4971 switch (die->Tag())
4972 {
4973 case DW_TAG_compile_unit:
4974 case DW_TAG_namespace:
4975 case DW_TAG_structure_type:
4976 case DW_TAG_union_type:
4977 case DW_TAG_class_type:
4978 return die;
4979
4980 default:
4981 break;
4982 }
4983 }
4984
4985 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4986 if (die_offset != DW_INVALID_OFFSET)
4987 {
4988 DWARFCompileUnit *spec_cu = cu;
4989 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
4990 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
4991 if (spec_die_decl_ctx_die)
4992 return spec_die_decl_ctx_die;
4993 }
4994
4995 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
4996 if (die_offset != DW_INVALID_OFFSET)
4997 {
4998 DWARFCompileUnit *abs_cu = cu;
4999 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
5000 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
5001 if (abs_die_decl_ctx_die)
5002 return abs_die_decl_ctx_die;
5003 }
5004
5005 die = die->GetParent();
5006 }
5007 }
5008 return NULL;
5009}
5010
5011
Greg Clayton901c5ca2011-12-03 04:40:03 +00005012Symbol *
5013SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
5014{
5015 Symbol *objc_class_symbol = NULL;
5016 if (m_obj_file)
5017 {
Greg Clayton3046e662013-07-10 01:23:25 +00005018 Symtab *symtab = m_obj_file->GetSymtab ();
Greg Clayton901c5ca2011-12-03 04:40:03 +00005019 if (symtab)
5020 {
5021 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
5022 eSymbolTypeObjCClass,
5023 Symtab::eDebugNo,
5024 Symtab::eVisibilityAny);
5025 }
5026 }
5027 return objc_class_symbol;
5028}
5029
Greg Claytonc7f03b62012-01-12 04:33:28 +00005030// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
5031// then we can end up looking through all class types for a complete type and never find
5032// the full definition. We need to know if this attribute is supported, so we determine
5033// this here and cache th result. We also need to worry about the debug map DWARF file
5034// if we are doing darwin DWARF in .o file debugging.
5035bool
5036SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
5037{
5038 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
5039 {
5040 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
5041 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
5042 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
5043 else
5044 {
5045 DWARFDebugInfo* debug_info = DebugInfo();
5046 const uint32_t num_compile_units = GetNumCompileUnits();
5047 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
5048 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00005049 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
5050 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00005051 {
5052 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
5053 break;
5054 }
5055 }
5056 }
Greg Clayton1f746072012-08-29 21:13:06 +00005057 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00005058 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
5059 }
5060 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
5061}
Greg Clayton901c5ca2011-12-03 04:40:03 +00005062
5063// This function can be used when a DIE is found that is a forward declaration
5064// DIE and we want to try and find a type that has the complete definition.
5065TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00005066SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
5067 const ConstString &type_name,
5068 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00005069{
5070
5071 TypeSP type_sp;
5072
Greg Claytonc7f03b62012-01-12 04:33:28 +00005073 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00005074 return type_sp;
5075
5076 DIEArray die_offsets;
5077
5078 if (m_using_apple_tables)
5079 {
5080 if (m_apple_types_ap.get())
5081 {
5082 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00005083 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00005084 }
5085 }
5086 else
5087 {
5088 if (!m_indexed)
5089 Index ();
5090
5091 m_type_index.Find (type_name, die_offsets);
5092 }
5093
Greg Clayton901c5ca2011-12-03 04:40:03 +00005094 const size_t num_matches = die_offsets.size();
5095
Greg Clayton901c5ca2011-12-03 04:40:03 +00005096 DWARFCompileUnit* type_cu = NULL;
5097 const DWARFDebugInfoEntry* type_die = NULL;
5098 if (num_matches)
5099 {
5100 DWARFDebugInfo* debug_info = DebugInfo();
5101 for (size_t i=0; i<num_matches; ++i)
5102 {
5103 const dw_offset_t die_offset = die_offsets[i];
5104 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
5105
5106 if (type_die)
5107 {
5108 bool try_resolving_type = false;
5109
5110 // Don't try and resolve the DIE we are looking for with the DIE itself!
5111 if (type_die != die)
5112 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005113 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00005114 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005115 case DW_TAG_class_type:
5116 case DW_TAG_structure_type:
5117 try_resolving_type = true;
5118 break;
5119 default:
5120 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00005121 }
5122 }
5123
5124 if (try_resolving_type)
5125 {
Ed Maste4c24b122013-10-17 20:13:14 +00005126 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
5127 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00005128
5129 if (try_resolving_type)
5130 {
5131 Type *resolved_type = ResolveType (type_cu, type_die, false);
5132 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5133 {
Ed Mastea0191d12013-10-17 20:42:56 +00005134 DEBUG_PRINTF ("resolved 0x%8.8" PRIx64 " from %s to 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ")\n",
Greg Clayton901c5ca2011-12-03 04:40:03 +00005135 MakeUserID(die->GetOffset()),
Jim Ingham4af59612014-12-19 19:20:44 +00005136 m_obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>"),
Greg Clayton901c5ca2011-12-03 04:40:03 +00005137 MakeUserID(type_die->GetOffset()),
5138 MakeUserID(type_cu->GetOffset()));
5139
Greg Claytonc7f03b62012-01-12 04:33:28 +00005140 if (die)
5141 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00005142 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00005143 break;
5144 }
5145 }
5146 }
5147 }
5148 else
5149 {
5150 if (m_using_apple_tables)
5151 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005152 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5153 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00005154 }
5155 }
5156
5157 }
5158 }
5159 return type_sp;
5160}
5161
Greg Claytona8022fa2012-04-24 21:22:41 +00005162
Greg Clayton80c26302012-02-05 06:12:47 +00005163//----------------------------------------------------------------------
5164// This function helps to ensure that the declaration contexts match for
5165// two different DIEs. Often times debug information will refer to a
5166// forward declaration of a type (the equivalent of "struct my_struct;".
5167// There will often be a declaration of that type elsewhere that has the
5168// full definition. When we go looking for the full type "my_struct", we
5169// will find one or more matches in the accelerator tables and we will
5170// then need to make sure the type was in the same declaration context
5171// as the original DIE. This function can efficiently compare two DIEs
5172// and will return true when the declaration context matches, and false
5173// when they don't.
5174//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00005175bool
5176SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
5177 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
5178{
Greg Claytona8022fa2012-04-24 21:22:41 +00005179 if (die1 == die2)
5180 return true;
5181
5182#if defined (LLDB_CONFIGURATION_DEBUG)
5183 // You can't and shouldn't call this function with a compile unit from
5184 // two different SymbolFileDWARF instances.
5185 assert (DebugInfo()->ContainsCompileUnit (cu1));
5186 assert (DebugInfo()->ContainsCompileUnit (cu2));
5187#endif
5188
Greg Clayton890ff562012-02-02 05:48:16 +00005189 DWARFDIECollection decl_ctx_1;
5190 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00005191 //The declaration DIE stack is a stack of the declaration context
5192 // DIEs all the way back to the compile unit. If a type "T" is
5193 // declared inside a class "B", and class "B" is declared inside
5194 // a class "A" and class "A" is in a namespace "lldb", and the
5195 // namespace is in a compile unit, there will be a stack of DIEs:
5196 //
5197 // [0] DW_TAG_class_type for "B"
5198 // [1] DW_TAG_class_type for "A"
5199 // [2] DW_TAG_namespace for "lldb"
5200 // [3] DW_TAG_compile_unit for the source file.
5201 //
5202 // We grab both contexts and make sure that everything matches
5203 // all the way back to the compiler unit.
5204
5205 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00005206 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00005207 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00005208 // Make sure the context arrays have the same size, otherwise
5209 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00005210 const size_t count1 = decl_ctx_1.Size();
5211 const size_t count2 = decl_ctx_2.Size();
5212 if (count1 != count2)
5213 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00005214
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00005215 // Make sure the DW_TAG values match all the way back up the
Greg Clayton80c26302012-02-05 06:12:47 +00005216 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00005217 const DWARFDebugInfoEntry *decl_ctx_die1;
5218 const DWARFDebugInfoEntry *decl_ctx_die2;
5219 size_t i;
5220 for (i=0; i<count1; i++)
5221 {
5222 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
5223 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
5224 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
5225 return false;
5226 }
Greg Clayton890ff562012-02-02 05:48:16 +00005227#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00005228
5229 // Make sure the top item in the decl context die array is always
5230 // DW_TAG_compile_unit. If it isn't then something went wrong in
5231 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00005232 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00005233
Greg Clayton890ff562012-02-02 05:48:16 +00005234#endif
5235 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00005236 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00005237 for (i=0; i<count1 - 1; i++)
5238 {
5239 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
5240 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
5241 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00005242 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00005243 // If the string was from a DW_FORM_strp, then the pointer will often
5244 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00005245 if (name1 == name2)
5246 continue;
5247
5248 // Name pointers are not equal, so only compare the strings
5249 // if both are not NULL.
5250 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00005251 {
Greg Clayton5569e642012-02-06 01:44:54 +00005252 // If the strings don't compare, we are done...
5253 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00005254 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00005255 }
5256 else
5257 {
5258 // One name was NULL while the other wasn't
5259 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00005260 }
5261 }
Greg Clayton80c26302012-02-05 06:12:47 +00005262 // We made it through all of the checks and the declaration contexts
5263 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00005264 return true;
5265}
Greg Clayton220a0072011-12-09 08:48:30 +00005266
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005267
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005268TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00005269SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx)
5270{
5271 TypeSP type_sp;
5272
5273 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
5274 if (dwarf_decl_ctx_count > 0)
5275 {
5276 const ConstString type_name(dwarf_decl_ctx[0].name);
5277 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
5278
5279 if (type_name)
5280 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005281 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
Greg Claytona8022fa2012-04-24 21:22:41 +00005282 if (log)
5283 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005284 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005285 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')",
5286 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5287 dwarf_decl_ctx.GetQualifiedName());
5288 }
5289
5290 DIEArray die_offsets;
5291
5292 if (m_using_apple_tables)
5293 {
5294 if (m_apple_types_ap.get())
5295 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005296 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
5297 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
5298 if (has_tag && has_qualified_name_hash)
Greg Claytona8022fa2012-04-24 21:22:41 +00005299 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005300 const char *qualified_name = dwarf_decl_ctx.GetQualifiedName();
5301 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name);
5302 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005303 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005304 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets);
5305 }
5306 else if (has_tag)
5307 {
5308 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005309 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
Greg Claytona8022fa2012-04-24 21:22:41 +00005310 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets);
5311 }
5312 else
5313 {
5314 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
5315 }
5316 }
5317 }
5318 else
5319 {
5320 if (!m_indexed)
5321 Index ();
5322
5323 m_type_index.Find (type_name, die_offsets);
5324 }
5325
5326 const size_t num_matches = die_offsets.size();
5327
5328
5329 DWARFCompileUnit* type_cu = NULL;
5330 const DWARFDebugInfoEntry* type_die = NULL;
5331 if (num_matches)
5332 {
5333 DWARFDebugInfo* debug_info = DebugInfo();
5334 for (size_t i=0; i<num_matches; ++i)
5335 {
5336 const dw_offset_t die_offset = die_offsets[i];
5337 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
5338
5339 if (type_die)
5340 {
5341 bool try_resolving_type = false;
5342
5343 // Don't try and resolve the DIE we are looking for with the DIE itself!
5344 const dw_tag_t type_tag = type_die->Tag();
5345 // Make sure the tags match
5346 if (type_tag == tag)
5347 {
5348 // The tags match, lets try resolving this type
5349 try_resolving_type = true;
5350 }
5351 else
5352 {
5353 // The tags don't match, but we need to watch our for a
5354 // forward declaration for a struct and ("struct foo")
5355 // ends up being a class ("class foo { ... };") or
5356 // vice versa.
5357 switch (type_tag)
5358 {
5359 case DW_TAG_class_type:
5360 // We had a "class foo", see if we ended up with a "struct foo { ... };"
5361 try_resolving_type = (tag == DW_TAG_structure_type);
5362 break;
5363 case DW_TAG_structure_type:
5364 // We had a "struct foo", see if we ended up with a "class foo { ... };"
5365 try_resolving_type = (tag == DW_TAG_class_type);
5366 break;
5367 default:
5368 // Tags don't match, don't event try to resolve
5369 // using this type whose name matches....
5370 break;
5371 }
5372 }
5373
5374 if (try_resolving_type)
5375 {
5376 DWARFDeclContext type_dwarf_decl_ctx;
5377 type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx);
5378
5379 if (log)
5380 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005381 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005382 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)",
5383 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5384 dwarf_decl_ctx.GetQualifiedName(),
5385 type_die->GetOffset(),
5386 type_dwarf_decl_ctx.GetQualifiedName());
5387 }
5388
5389 // Make sure the decl contexts match all the way up
5390 if (dwarf_decl_ctx == type_dwarf_decl_ctx)
5391 {
5392 Type *resolved_type = ResolveType (type_cu, type_die, false);
5393 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5394 {
5395 type_sp = resolved_type->shared_from_this();
5396 break;
5397 }
5398 }
5399 }
5400 else
5401 {
5402 if (log)
5403 {
5404 std::string qualified_name;
5405 type_die->GetQualifiedName(this, type_cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00005406 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005407 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)",
5408 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5409 dwarf_decl_ctx.GetQualifiedName(),
5410 type_die->GetOffset(),
5411 qualified_name.c_str());
5412 }
5413 }
5414 }
5415 else
5416 {
5417 if (m_using_apple_tables)
5418 {
5419 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5420 die_offset, type_name.GetCString());
5421 }
5422 }
5423
5424 }
5425 }
5426 }
5427 }
5428 return type_sp;
5429}
5430
Greg Clayton4116e932012-05-15 02:33:01 +00005431bool
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005432SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005433 Type *class_type,
Greg Clayton4116e932012-05-15 02:33:01 +00005434 DWARFCompileUnit* src_cu,
5435 const DWARFDebugInfoEntry *src_class_die,
5436 DWARFCompileUnit* dst_cu,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005437 const DWARFDebugInfoEntry *dst_class_die,
Greg Claytond20deac2014-04-04 18:15:18 +00005438 DWARFDIECollection &failures)
Greg Clayton4116e932012-05-15 02:33:01 +00005439{
5440 if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die)
5441 return false;
5442 if (src_class_die->Tag() != dst_class_die->Tag())
5443 return false;
5444
5445 // We need to complete the class type so we can get all of the method types
5446 // parsed so we can then unique those types to their equivalent counterparts
5447 // in "dst_cu" and "dst_class_die"
5448 class_type->GetClangFullType();
5449
5450 const DWARFDebugInfoEntry *src_die;
5451 const DWARFDebugInfoEntry *dst_die;
5452 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die;
5453 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die;
Greg Clayton65ec1032012-11-12 21:27:20 +00005454 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial;
5455 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial;
Greg Clayton4116e932012-05-15 02:33:01 +00005456 for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling())
5457 {
5458 if (src_die->Tag() == DW_TAG_subprogram)
5459 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005460 // Make sure this is a declaration and not a concrete instance by looking
5461 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5462 // are placed inside the class definitions and shouldn't be included in
5463 // the list of things are are tracking here.
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005464 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_declaration, 0) == 1)
Greg Clayton84afacd2012-11-07 23:09:32 +00005465 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005466 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton84afacd2012-11-07 23:09:32 +00005467 if (src_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005468 {
5469 ConstString src_const_name(src_name);
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005470 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0))
Greg Clayton65ec1032012-11-12 21:27:20 +00005471 src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die);
5472 else
5473 src_name_to_die.Append(src_const_name.GetCString(), src_die);
5474 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005475 }
Greg Clayton4116e932012-05-15 02:33:01 +00005476 }
5477 }
5478 for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling())
5479 {
5480 if (dst_die->Tag() == DW_TAG_subprogram)
5481 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005482 // Make sure this is a declaration and not a concrete instance by looking
5483 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5484 // are placed inside the class definitions and shouldn't be included in
5485 // the list of things are are tracking here.
5486 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1)
5487 {
5488 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5489 if (dst_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005490 {
5491 ConstString dst_const_name(dst_name);
5492 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0))
5493 dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die);
5494 else
5495 dst_name_to_die.Append(dst_const_name.GetCString(), dst_die);
5496 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005497 }
Greg Clayton4116e932012-05-15 02:33:01 +00005498 }
5499 }
5500 const uint32_t src_size = src_name_to_die.GetSize ();
5501 const uint32_t dst_size = dst_name_to_die.GetSize ();
Greg Clayton5160ce52013-03-27 23:08:40 +00005502 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005503
5504 // Is everything kosher so we can go through the members at top speed?
5505 bool fast_path = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005506
Sean Callanan2367f8a2013-02-26 01:12:25 +00005507 if (src_size != dst_size)
Greg Clayton4116e932012-05-15 02:33:01 +00005508 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005509 if (src_size != 0 && dst_size != 0)
5510 {
5511 if (log)
5512 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)",
5513 src_class_die->GetOffset(),
5514 dst_class_die->GetOffset(),
5515 src_size,
5516 dst_size);
5517 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005518
Sean Callanan2367f8a2013-02-26 01:12:25 +00005519 fast_path = false;
5520 }
5521
5522 uint32_t idx;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005523
Sean Callanan2367f8a2013-02-26 01:12:25 +00005524 if (fast_path)
5525 {
Greg Clayton4116e932012-05-15 02:33:01 +00005526 for (idx = 0; idx < src_size; ++idx)
5527 {
5528 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5529 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5530
5531 if (src_die->Tag() != dst_die->Tag())
5532 {
5533 if (log)
5534 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)",
5535 src_class_die->GetOffset(),
5536 dst_class_die->GetOffset(),
5537 src_die->GetOffset(),
5538 DW_TAG_value_to_name(src_die->Tag()),
5539 dst_die->GetOffset(),
5540 DW_TAG_value_to_name(src_die->Tag()));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005541 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005542 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005543
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005544 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton4116e932012-05-15 02:33:01 +00005545 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005546
Greg Clayton4116e932012-05-15 02:33:01 +00005547 // Make sure the names match
5548 if (src_name == dst_name || (strcmp (src_name, dst_name) == 0))
5549 continue;
5550
5551 if (log)
5552 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)",
5553 src_class_die->GetOffset(),
5554 dst_class_die->GetOffset(),
5555 src_die->GetOffset(),
5556 src_name,
5557 dst_die->GetOffset(),
5558 dst_name);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005559
Sean Callanan2367f8a2013-02-26 01:12:25 +00005560 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005561 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005562 }
Greg Clayton4116e932012-05-15 02:33:01 +00005563
Sean Callanan2367f8a2013-02-26 01:12:25 +00005564 // Now do the work of linking the DeclContexts and Types.
5565 if (fast_path)
5566 {
5567 // We can do this quickly. Just run across the tables index-for-index since
5568 // we know each node has matching names and tags.
Greg Clayton4116e932012-05-15 02:33:01 +00005569 for (idx = 0; idx < src_size; ++idx)
5570 {
5571 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5572 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005573
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005574 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Greg Clayton4116e932012-05-15 02:33:01 +00005575 if (src_decl_ctx)
5576 {
5577 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005578 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
5579 static_cast<void*>(src_decl_ctx),
5580 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005581 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5582 }
5583 else
5584 {
5585 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005586 log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found",
5587 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005588 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005589
Greg Clayton4116e932012-05-15 02:33:01 +00005590 Type *src_child_type = m_die_to_type[src_die];
5591 if (src_child_type)
5592 {
5593 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005594 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
5595 static_cast<void*>(src_child_type),
5596 src_child_type->GetID(),
5597 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005598 m_die_to_type[dst_die] = src_child_type;
5599 }
5600 else
5601 {
5602 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005603 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());
5604 }
5605 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005606 }
5607 else
5608 {
5609 // We must do this slowly. For each member of the destination, look
5610 // up a member in the source with the same name, check its tag, and
5611 // unique them if everything matches up. Report failures.
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005612
Sean Callanan2367f8a2013-02-26 01:12:25 +00005613 if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty())
5614 {
5615 src_name_to_die.Sort();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005616
Sean Callanan2367f8a2013-02-26 01:12:25 +00005617 for (idx = 0; idx < dst_size; ++idx)
5618 {
5619 const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx);
5620 dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
5621 src_die = src_name_to_die.Find(dst_name, NULL);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005622
Sean Callanan2367f8a2013-02-26 01:12:25 +00005623 if (src_die && (src_die->Tag() == dst_die->Tag()))
5624 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005625 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Sean Callanan2367f8a2013-02-26 01:12:25 +00005626 if (src_decl_ctx)
5627 {
5628 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005629 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
5630 static_cast<void*>(src_decl_ctx),
5631 src_die->GetOffset(),
5632 dst_die->GetOffset());
Sean Callanan2367f8a2013-02-26 01:12:25 +00005633 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5634 }
5635 else
5636 {
5637 if (log)
5638 log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found", src_die->GetOffset(), dst_die->GetOffset());
5639 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005640
Sean Callanan2367f8a2013-02-26 01:12:25 +00005641 Type *src_child_type = m_die_to_type[src_die];
5642 if (src_child_type)
5643 {
5644 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005645 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
5646 static_cast<void*>(src_child_type),
5647 src_child_type->GetID(),
5648 src_die->GetOffset(),
5649 dst_die->GetOffset());
Sean Callanan2367f8a2013-02-26 01:12:25 +00005650 m_die_to_type[dst_die] = src_child_type;
5651 }
5652 else
5653 {
5654 if (log)
5655 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());
5656 }
5657 }
5658 else
5659 {
5660 if (log)
5661 log->Printf ("warning: couldn't find a match for 0x%8.8x", dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005662
Greg Claytond20deac2014-04-04 18:15:18 +00005663 failures.Append(dst_die);
Sean Callanan2367f8a2013-02-26 01:12:25 +00005664 }
5665 }
5666 }
5667 }
5668
5669 const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize ();
5670 const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize ();
5671
5672 UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src;
5673
5674 if (src_size_artificial && dst_size_artificial)
5675 {
5676 dst_name_to_die_artificial.Sort();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005677
Greg Clayton65ec1032012-11-12 21:27:20 +00005678 for (idx = 0; idx < src_size_artificial; ++idx)
5679 {
5680 const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx);
5681 src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5682 dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005683
Greg Clayton65ec1032012-11-12 21:27:20 +00005684 if (dst_die)
5685 {
Greg Clayton65ec1032012-11-12 21:27:20 +00005686 // Both classes have the artificial types, link them
5687 clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die];
5688 if (src_decl_ctx)
5689 {
5690 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005691 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
5692 static_cast<void*>(src_decl_ctx),
5693 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005694 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5695 }
5696 else
5697 {
5698 if (log)
5699 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());
5700 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005701
Greg Clayton65ec1032012-11-12 21:27:20 +00005702 Type *src_child_type = m_die_to_type[src_die];
5703 if (src_child_type)
5704 {
5705 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005706 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
5707 static_cast<void*>(src_child_type),
5708 src_child_type->GetID(),
5709 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005710 m_die_to_type[dst_die] = src_child_type;
5711 }
5712 else
5713 {
5714 if (log)
5715 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());
5716 }
5717 }
5718 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005719 }
Greg Clayton65ec1032012-11-12 21:27:20 +00005720
Sean Callanan2367f8a2013-02-26 01:12:25 +00005721 if (dst_size_artificial)
Greg Clayton4116e932012-05-15 02:33:01 +00005722 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005723 for (idx = 0; idx < dst_size_artificial; ++idx)
5724 {
5725 const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx);
5726 dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5727 if (log)
5728 log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial);
5729
Greg Claytond20deac2014-04-04 18:15:18 +00005730 failures.Append(dst_die);
Sean Callanan2367f8a2013-02-26 01:12:25 +00005731 }
Greg Clayton4116e932012-05-15 02:33:01 +00005732 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005733
Greg Claytond20deac2014-04-04 18:15:18 +00005734 return (failures.Size() != 0);
Greg Clayton4116e932012-05-15 02:33:01 +00005735}
Greg Claytona8022fa2012-04-24 21:22:41 +00005736
5737TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00005738SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005739{
5740 TypeSP type_sp;
5741
Greg Clayton1be10fc2010-09-29 01:12:09 +00005742 if (type_is_new_ptr)
5743 *type_is_new_ptr = false;
Greg Clayton1fba87112012-02-09 20:03:49 +00005744
Todd Fiala0a70a842014-05-28 16:43:26 +00005745#if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE)
Greg Clayton1fba87112012-02-09 20:03:49 +00005746 static DIEStack g_die_stack;
5747 DIEStack::ScopedPopper scoped_die_logger(g_die_stack);
5748#endif
Greg Clayton1be10fc2010-09-29 01:12:09 +00005749
Sean Callananc7fbf732010-08-06 00:32:49 +00005750 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005751 if (die != NULL)
5752 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005753 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005754 if (log)
Sean Callanan5b26f272012-02-04 08:49:35 +00005755 {
5756 const DWARFDebugInfoEntry *context_die;
5757 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005758
Greg Clayton5160ce52013-03-27 23:08:40 +00005759 GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x, decl_ctx = %p (die 0x%8.8x)) %s name = '%s')",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005760 die->GetOffset(),
5761 static_cast<void*>(context),
5762 context_die->GetOffset(),
5763 DW_TAG_value_to_name(die->Tag()),
5764 die->GetName(this, dwarf_cu));
5765
Todd Fiala0a70a842014-05-28 16:43:26 +00005766#if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE)
Greg Clayton1fba87112012-02-09 20:03:49 +00005767 scoped_die_logger.Push (dwarf_cu, die);
Greg Clayton5160ce52013-03-27 23:08:40 +00005768 g_die_stack.LogDIEs(log, this);
Greg Clayton1fba87112012-02-09 20:03:49 +00005769#endif
Sean Callanan5b26f272012-02-04 08:49:35 +00005770 }
Greg Clayton3bffb082011-12-10 02:15:28 +00005771//
Greg Clayton5160ce52013-03-27 23:08:40 +00005772// Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005773// if (log && dwarf_cu)
5774// {
5775// StreamString s;
5776// die->DumpLocation (this, dwarf_cu, s);
Greg Clayton5160ce52013-03-27 23:08:40 +00005777// GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Greg Clayton3bffb082011-12-10 02:15:28 +00005778//
5779// }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005780
Greg Clayton594e5ed2010-09-27 21:07:38 +00005781 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005782 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00005783 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005784 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005785 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00005786 if (type_is_new_ptr)
5787 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005788
Greg Clayton594e5ed2010-09-27 21:07:38 +00005789 const dw_tag_t tag = die->Tag();
5790
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005791 bool is_forward_declaration = false;
5792 DWARFDebugInfoEntry::Attributes attributes;
5793 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00005794 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00005795 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
Greg Claytonfaac1112013-03-14 18:31:44 +00005796 uint64_t byte_size = 0;
Greg Clayton526e5af2010-11-13 03:52:47 +00005797 Declaration decl;
5798
Greg Clayton4957bf62010-09-30 21:49:03 +00005799 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton57ee3062013-07-11 22:46:58 +00005800 ClangASTType clang_type;
Greg Claytond20deac2014-04-04 18:15:18 +00005801 DWARFFormValue form_value;
5802
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005803 dw_attr_t attr;
5804
5805 switch (tag)
5806 {
5807 case DW_TAG_base_type:
5808 case DW_TAG_pointer_type:
5809 case DW_TAG_reference_type:
Sean Callanance8af862012-05-21 23:31:51 +00005810 case DW_TAG_rvalue_reference_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005811 case DW_TAG_typedef:
5812 case DW_TAG_const_type:
5813 case DW_TAG_restrict_type:
5814 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00005815 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005816 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005817 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005818 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005819
Greg Claytond88d7592010-09-15 08:33:30 +00005820 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005821 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005822 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
5823
5824 if (num_attributes > 0)
5825 {
5826 uint32_t i;
5827 for (i=0; i<num_attributes; ++i)
5828 {
5829 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005830 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5831 {
5832 switch (attr)
5833 {
5834 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5835 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5836 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5837 case DW_AT_name:
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005838
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005839 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00005840 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
5841 // include the "&"...
5842 if (tag == DW_TAG_reference_type)
5843 {
5844 if (strchr (type_name_cstr, '&') == NULL)
5845 type_name_cstr = NULL;
5846 }
5847 if (type_name_cstr)
5848 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005849 break;
Greg Clayton23f59502012-07-17 03:23:13 +00005850 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005851 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
Greg Clayton54166af2014-11-22 01:58:59 +00005852 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005853 default:
5854 case DW_AT_sibling:
5855 break;
5856 }
5857 }
5858 }
5859 }
5860
Ed Mastea0191d12013-10-17 20:42:56 +00005861 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\") type => 0x%8.8lx\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr, encoding_uid);
Greg Claytonc93237c2010-10-01 20:48:32 +00005862
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005863 switch (tag)
5864 {
5865 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00005866 break;
5867
Greg Claytond4436412011-10-28 21:00:00 +00005868 case DW_TAG_unspecified_type:
Greg Clayton7fba2632013-07-01 21:01:52 +00005869 if (strcmp(type_name_cstr, "nullptr_t") == 0 ||
5870 strcmp(type_name_cstr, "decltype(nullptr)") == 0 )
Greg Claytond4436412011-10-28 21:00:00 +00005871 {
5872 resolve_state = Type::eResolveStateFull;
Greg Clayton57ee3062013-07-11 22:46:58 +00005873 clang_type = ast.GetBasicType(eBasicTypeNullPtr);
Greg Claytond4436412011-10-28 21:00:00 +00005874 break;
5875 }
5876 // Fall through to base type below in case we can handle the type there...
5877
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005878 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00005879 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005880 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
5881 encoding,
5882 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005883 break;
5884
Sean Callanance8af862012-05-21 23:31:51 +00005885 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
5886 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
5887 case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break;
5888 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
5889 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
5890 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
5891 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005892 }
5893
Greg Clayton57ee3062013-07-11 22:46:58 +00005894 if (!clang_type && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID) && sc.comp_unit != NULL)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005895 {
Sean Callanan82587052013-01-03 00:05:56 +00005896 bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005897
Sean Callanan82587052013-01-03 00:05:56 +00005898 if (translation_unit_is_objc)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005899 {
Sean Callanan82587052013-01-03 00:05:56 +00005900 if (type_name_cstr != NULL)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005901 {
Sean Callanan82587052013-01-03 00:05:56 +00005902 static ConstString g_objc_type_name_id("id");
5903 static ConstString g_objc_type_name_Class("Class");
5904 static ConstString g_objc_type_name_selector("SEL");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005905
Sean Callanan82587052013-01-03 00:05:56 +00005906 if (type_name_const_str == g_objc_type_name_id)
5907 {
5908 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005909 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 +00005910 die->GetOffset(),
5911 DW_TAG_value_to_name(die->Tag()),
5912 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005913 clang_type = ast.GetBasicType(eBasicTypeObjCID);
Sean Callanan82587052013-01-03 00:05:56 +00005914 encoding_data_type = Type::eEncodingIsUID;
5915 encoding_uid = LLDB_INVALID_UID;
5916 resolve_state = Type::eResolveStateFull;
Greg Clayton526e5af2010-11-13 03:52:47 +00005917
Sean Callanan82587052013-01-03 00:05:56 +00005918 }
5919 else if (type_name_const_str == g_objc_type_name_Class)
5920 {
5921 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005922 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 +00005923 die->GetOffset(),
5924 DW_TAG_value_to_name(die->Tag()),
5925 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005926 clang_type = ast.GetBasicType(eBasicTypeObjCClass);
Sean Callanan82587052013-01-03 00:05:56 +00005927 encoding_data_type = Type::eEncodingIsUID;
5928 encoding_uid = LLDB_INVALID_UID;
5929 resolve_state = Type::eResolveStateFull;
5930 }
5931 else if (type_name_const_str == g_objc_type_name_selector)
5932 {
5933 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005934 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 +00005935 die->GetOffset(),
5936 DW_TAG_value_to_name(die->Tag()),
5937 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005938 clang_type = ast.GetBasicType(eBasicTypeObjCSel);
Sean Callanan82587052013-01-03 00:05:56 +00005939 encoding_data_type = Type::eEncodingIsUID;
5940 encoding_uid = LLDB_INVALID_UID;
5941 resolve_state = Type::eResolveStateFull;
5942 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005943 }
Sean Callanan82587052013-01-03 00:05:56 +00005944 else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005945 {
Sean Callanan82587052013-01-03 00:05:56 +00005946 // Clang sometimes erroneously emits id as objc_object*. In that case we fix up the type to "id".
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005947
Sean Callanan82587052013-01-03 00:05:56 +00005948 DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005949
Sean Callanan82587052013-01-03 00:05:56 +00005950 if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005951 {
Sean Callanan82587052013-01-03 00:05:56 +00005952 if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL))
5953 {
5954 if (!strcmp(struct_name, "objc_object"))
5955 {
5956 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005957 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 +00005958 die->GetOffset(),
5959 DW_TAG_value_to_name(die->Tag()),
5960 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005961 clang_type = ast.GetBasicType(eBasicTypeObjCID);
Sean Callanan82587052013-01-03 00:05:56 +00005962 encoding_data_type = Type::eEncodingIsUID;
5963 encoding_uid = LLDB_INVALID_UID;
5964 resolve_state = Type::eResolveStateFull;
5965 }
5966 }
5967 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005968 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005969 }
5970 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005971
Greg Clayton81c22f62011-10-19 18:09:39 +00005972 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005973 this,
5974 type_name_const_str,
5975 byte_size,
5976 NULL,
5977 encoding_uid,
5978 encoding_data_type,
5979 &decl,
5980 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005981 resolve_state));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005982
Greg Clayton594e5ed2010-09-27 21:07:38 +00005983 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005984
5985// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
5986// if (encoding_type != NULL)
5987// {
5988// if (encoding_type != DIE_IS_BEING_PARSED)
5989// type_sp->SetEncodingType(encoding_type);
5990// else
5991// m_indirect_fixups.push_back(type_sp.get());
5992// }
5993 }
5994 break;
5995
5996 case DW_TAG_structure_type:
5997 case DW_TAG_union_type:
5998 case DW_TAG_class_type:
5999 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006000 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006001 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Greg Clayton23f59502012-07-17 03:23:13 +00006002 bool byte_size_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006003
Greg Clayton9e409562010-07-28 02:04:09 +00006004 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00006005 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006006 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00006007 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006008 if (num_attributes > 0)
6009 {
6010 uint32_t i;
6011 for (i=0; i<num_attributes; ++i)
6012 {
6013 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006014 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6015 {
6016 switch (attr)
6017 {
Greg Clayton9e409562010-07-28 02:04:09 +00006018 case DW_AT_decl_file:
Greg Claytonc7f03b62012-01-12 04:33:28 +00006019 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
Ed Maste4c24b122013-10-17 20:13:14 +00006020 {
6021 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
6022 // point to the compile unit file, so we clear this invalid value
6023 // so that we can still unique types efficiently.
Greg Claytonc7f03b62012-01-12 04:33:28 +00006024 decl.SetFile(FileSpec ("<invalid>", false));
Ed Maste4c24b122013-10-17 20:13:14 +00006025 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00006026 else
6027 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
Greg Clayton9e409562010-07-28 02:04:09 +00006028 break;
6029
6030 case DW_AT_decl_line:
6031 decl.SetLine(form_value.Unsigned());
6032 break;
6033
6034 case DW_AT_decl_column:
6035 decl.SetColumn(form_value.Unsigned());
6036 break;
6037
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006038 case DW_AT_name:
6039 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006040 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006041 break;
Greg Clayton9e409562010-07-28 02:04:09 +00006042
6043 case DW_AT_byte_size:
6044 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00006045 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00006046 break;
6047
6048 case DW_AT_accessibility:
6049 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
6050 break;
6051
6052 case DW_AT_declaration:
Greg Clayton1c8ef472013-04-05 23:27:21 +00006053 is_forward_declaration = form_value.Boolean();
Greg Clayton9e409562010-07-28 02:04:09 +00006054 break;
6055
6056 case DW_AT_APPLE_runtime_class:
6057 class_language = (LanguageType)form_value.Signed();
6058 break;
6059
Greg Clayton18774842011-11-29 23:40:34 +00006060 case DW_AT_APPLE_objc_complete_type:
6061 is_complete_objc_class = form_value.Signed();
6062 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006063
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006064 case DW_AT_allocated:
6065 case DW_AT_associated:
6066 case DW_AT_data_location:
6067 case DW_AT_description:
6068 case DW_AT_start_scope:
6069 case DW_AT_visibility:
6070 default:
6071 case DW_AT_sibling:
6072 break;
6073 }
6074 }
6075 }
6076 }
Greg Claytond20deac2014-04-04 18:15:18 +00006077
6078 // UniqueDWARFASTType is large, so don't create a local variables on the
6079 // stack, put it on the heap. This function is often called recursively
6080 // and clang isn't good and sharing the stack space for variables in different blocks.
6081 std::unique_ptr<UniqueDWARFASTType> unique_ast_entry_ap(new UniqueDWARFASTType());
Sean Callanan8e8072d2012-02-07 21:13:38 +00006082
Greg Clayton123edca2012-03-02 00:07:15 +00006083 // Only try and unique the type if it has a name.
6084 if (type_name_const_str &&
6085 GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Sean Callanan8e8072d2012-02-07 21:13:38 +00006086 this,
6087 dwarf_cu,
6088 die,
6089 decl,
6090 byte_size_valid ? byte_size : -1,
Greg Claytond20deac2014-04-04 18:15:18 +00006091 *unique_ast_entry_ap))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006092 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00006093 // We have already parsed this type or from another
6094 // compile unit. GCC loves to use the "one definition
6095 // rule" which can result in multiple definitions
6096 // of the same class over and over in each compile
6097 // unit.
Greg Claytond20deac2014-04-04 18:15:18 +00006098 type_sp = unique_ast_entry_ap->m_type_sp;
Sean Callanan8e8072d2012-02-07 21:13:38 +00006099 if (type_sp)
Greg Claytonc615ce42010-11-09 04:42:43 +00006100 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00006101 m_die_to_type[die] = type_sp.get();
6102 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00006103 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006104 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006105
Daniel Malead01b2952012-11-29 21:49:15 +00006106 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 +00006107
6108 int tag_decl_kind = -1;
6109 AccessType default_accessibility = eAccessNone;
6110 if (tag == DW_TAG_structure_type)
6111 {
6112 tag_decl_kind = clang::TTK_Struct;
6113 default_accessibility = eAccessPublic;
6114 }
6115 else if (tag == DW_TAG_union_type)
6116 {
6117 tag_decl_kind = clang::TTK_Union;
6118 default_accessibility = eAccessPublic;
6119 }
6120 else if (tag == DW_TAG_class_type)
6121 {
6122 tag_decl_kind = clang::TTK_Class;
6123 default_accessibility = eAccessPrivate;
6124 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006125
Greg Clayton3a5f29a2011-11-30 02:48:28 +00006126 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
6127 die->HasChildren() == false &&
6128 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
6129 {
6130 // Work around an issue with clang at the moment where
6131 // forward declarations for objective C classes are emitted
6132 // as:
6133 // DW_TAG_structure_type [2]
6134 // DW_AT_name( "ForwardObjcClass" )
6135 // DW_AT_byte_size( 0x00 )
6136 // DW_AT_decl_file( "..." )
6137 // DW_AT_decl_line( 1 )
6138 //
6139 // Note that there is no DW_AT_declaration and there are
6140 // no children, and the byte size is zero.
6141 is_forward_declaration = true;
6142 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006143
Sean Callanan7457f8d2012-04-25 01:03:57 +00006144 if (class_language == eLanguageTypeObjC ||
6145 class_language == eLanguageTypeObjC_plus_plus)
Greg Clayton18774842011-11-29 23:40:34 +00006146 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00006147 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
Greg Clayton901c5ca2011-12-03 04:40:03 +00006148 {
6149 // We have a valid eSymbolTypeObjCClass class symbol whose
6150 // name matches the current objective C class that we
6151 // are trying to find and this DIE isn't the complete
6152 // definition (we checked is_complete_objc_class above and
6153 // know it is false), so the real definition is in here somewhere
Greg Claytonc7f03b62012-01-12 04:33:28 +00006154 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006155
Greg Clayton1f746072012-08-29 21:13:06 +00006156 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton901c5ca2011-12-03 04:40:03 +00006157 {
6158 // We weren't able to find a full declaration in
6159 // this DWARF, see if we have a declaration anywhere
6160 // else...
Greg Claytonc7f03b62012-01-12 04:33:28 +00006161 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00006162 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006163
Greg Clayton901c5ca2011-12-03 04:40:03 +00006164 if (type_sp)
6165 {
6166 if (log)
6167 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006168 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00006169 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8" PRIx64,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006170 static_cast<void*>(this),
Greg Claytone38a5ed2012-01-05 03:57:59 +00006171 die->GetOffset(),
6172 DW_TAG_value_to_name(tag),
6173 type_name_cstr,
6174 type_sp->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00006175 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006176
Greg Clayton901c5ca2011-12-03 04:40:03 +00006177 // We found a real definition for this type elsewhere
6178 // so lets use it and cache the fact that we found
6179 // a complete type for this die
6180 m_die_to_type[die] = type_sp.get();
6181 return type_sp;
6182 }
6183 }
6184 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006185
Greg Clayton901c5ca2011-12-03 04:40:03 +00006186
6187 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006188 {
6189 // We have a forward declaration to a type and we need
6190 // to try and find a full declaration. We look in the
6191 // current type index just in case we have a forward
6192 // declaration followed by an actual declarations in the
6193 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00006194 if (log)
6195 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006196 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00006197 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006198 static_cast<void*>(this),
Greg Claytone38a5ed2012-01-05 03:57:59 +00006199 die->GetOffset(),
6200 DW_TAG_value_to_name(tag),
6201 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00006202 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006203
Greg Claytona8022fa2012-04-24 21:22:41 +00006204 DWARFDeclContext die_decl_ctx;
6205 die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx);
6206
6207 //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
6208 type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006209
Greg Clayton1f746072012-08-29 21:13:06 +00006210 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton4272cc72011-02-02 02:24:04 +00006211 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006212 // We weren't able to find a full declaration in
6213 // this DWARF, see if we have a declaration anywhere
6214 // else...
Greg Claytona8022fa2012-04-24 21:22:41 +00006215 type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton4272cc72011-02-02 02:24:04 +00006216 }
6217
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006218 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00006219 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00006220 if (log)
6221 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006222 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00006223 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8" PRIx64,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006224 static_cast<void*>(this),
Greg Claytone38a5ed2012-01-05 03:57:59 +00006225 die->GetOffset(),
6226 DW_TAG_value_to_name(tag),
6227 type_name_cstr,
6228 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00006229 }
6230
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006231 // We found a real definition for this type elsewhere
6232 // so lets use it and cache the fact that we found
6233 // a complete type for this die
6234 m_die_to_type[die] = type_sp.get();
6235 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00006236 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006237 }
6238 assert (tag_decl_kind != -1);
6239 bool clang_type_was_created = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00006240 clang_type.SetClangType(ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die));
6241 if (!clang_type)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006242 {
Sean Callanan4d04c6a2012-02-09 22:54:11 +00006243 const DWARFDebugInfoEntry *decl_ctx_die;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006244
Sean Callanan4d04c6a2012-02-09 22:54:11 +00006245 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton55561e92011-10-26 03:31:36 +00006246 if (accessibility == eAccessNone && decl_ctx)
6247 {
6248 // Check the decl context that contains this class/struct/union.
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00006249 // If it is a class we must give it an accessibility.
Greg Clayton55561e92011-10-26 03:31:36 +00006250 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
6251 if (DeclKindIsCXXClass (containing_decl_kind))
6252 accessibility = default_accessibility;
6253 }
6254
Greg Claytonc4ffd662013-03-08 01:37:30 +00006255 ClangASTMetadata metadata;
6256 metadata.SetUserID(MakeUserID(die->GetOffset()));
6257 metadata.SetIsDynamicCXXType(ClassOrStructIsVirtual (dwarf_cu, die));
6258
Greg Claytonf0705c82011-10-22 03:33:13 +00006259 if (type_name_cstr && strchr (type_name_cstr, '<'))
6260 {
6261 ClangASTContext::TemplateParameterInfos template_param_infos;
6262 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
6263 {
6264 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00006265 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00006266 type_name_cstr,
6267 tag_decl_kind,
6268 template_param_infos);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006269
Greg Claytonf0705c82011-10-22 03:33:13 +00006270 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
6271 class_template_decl,
6272 tag_decl_kind,
6273 template_param_infos);
6274 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
6275 clang_type_was_created = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006276
Greg Claytond0029442013-03-27 01:48:02 +00006277 GetClangASTContext().SetMetadata (class_template_decl, metadata);
6278 GetClangASTContext().SetMetadata (class_specialization_decl, metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00006279 }
6280 }
6281
6282 if (!clang_type_was_created)
6283 {
6284 clang_type_was_created = true;
Greg Clayton55561e92011-10-26 03:31:36 +00006285 clang_type = ast.CreateRecordType (decl_ctx,
6286 accessibility,
6287 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00006288 tag_decl_kind,
Sean Callanan60217122012-04-13 00:10:03 +00006289 class_language,
Jim Ingham379397632012-10-27 02:54:13 +00006290 &metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00006291 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006292 }
6293
6294 // Store a forward declaration to this class type in case any
6295 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00006296 // types for function prototypes.
Greg Clayton57ee3062013-07-11 22:46:58 +00006297 LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00006298 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006299 this,
6300 type_name_const_str,
6301 byte_size,
6302 NULL,
6303 LLDB_INVALID_UID,
6304 Type::eEncodingIsUID,
6305 &decl,
6306 clang_type,
6307 Type::eResolveStateForward));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006308
Sean Callanan72772842012-02-22 23:57:45 +00006309 type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006310
6311
6312 // Add our type to the unique type map so we don't
6313 // end up creating many copies of the same type over
6314 // and over in the ASTContext for our module
Greg Claytond20deac2014-04-04 18:15:18 +00006315 unique_ast_entry_ap->m_type_sp = type_sp;
6316 unique_ast_entry_ap->m_symfile = this;
6317 unique_ast_entry_ap->m_cu = dwarf_cu;
6318 unique_ast_entry_ap->m_die = die;
6319 unique_ast_entry_ap->m_declaration = decl;
6320 unique_ast_entry_ap->m_byte_size = byte_size;
Greg Claytone576ab22011-02-15 00:19:15 +00006321 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
Greg Claytond20deac2014-04-04 18:15:18 +00006322 *unique_ast_entry_ap);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006323
Greg Clayton0ec71a02013-08-10 00:09:35 +00006324 if (is_forward_declaration && die->HasChildren())
6325 {
6326 // Check to see if the DIE actually has a definition, some version of GCC will
6327 // emit DIEs with DW_AT_declaration set to true, but yet still have subprogram,
6328 // members, or inheritance, so we can't trust it
6329 const DWARFDebugInfoEntry *child_die = die->GetFirstChild();
6330 while (child_die)
6331 {
6332 switch (child_die->Tag())
6333 {
6334 case DW_TAG_inheritance:
6335 case DW_TAG_subprogram:
6336 case DW_TAG_member:
6337 case DW_TAG_APPLE_property:
Greg Clayton4c484ec2014-02-07 19:21:56 +00006338 case DW_TAG_class_type:
6339 case DW_TAG_structure_type:
6340 case DW_TAG_enumeration_type:
6341 case DW_TAG_typedef:
6342 case DW_TAG_union_type:
Greg Clayton0ec71a02013-08-10 00:09:35 +00006343 child_die = NULL;
6344 is_forward_declaration = false;
6345 break;
6346 default:
6347 child_die = child_die->GetSibling();
6348 break;
6349 }
6350 }
6351 }
6352
Sean Callanan12014a02011-12-08 23:45:45 +00006353 if (!is_forward_declaration)
Greg Clayton219cf312012-03-30 00:51:13 +00006354 {
6355 // Always start the definition for a class type so that
6356 // if the class has child classes or types that require
6357 // the class to be created for use as their decl contexts
6358 // the class will be ready to accept these child definitions.
Sean Callanan12014a02011-12-08 23:45:45 +00006359 if (die->HasChildren() == false)
6360 {
6361 // No children for this struct/union/class, lets finish it
Greg Clayton57ee3062013-07-11 22:46:58 +00006362 clang_type.StartTagDeclarationDefinition ();
6363 clang_type.CompleteTagDeclarationDefinition ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006364
Sean Callanan433cd222012-10-19 01:37:25 +00006365 if (tag == DW_TAG_structure_type) // this only applies in C
6366 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006367 clang::RecordDecl *record_decl = clang_type.GetAsRecordDecl();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006368
Greg Clayton57ee3062013-07-11 22:46:58 +00006369 if (record_decl)
Greg Claytond20deac2014-04-04 18:15:18 +00006370 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, LayoutInfo()));
Sean Callanan433cd222012-10-19 01:37:25 +00006371 }
Sean Callanan12014a02011-12-08 23:45:45 +00006372 }
6373 else if (clang_type_was_created)
6374 {
Greg Clayton219cf312012-03-30 00:51:13 +00006375 // Start the definition if the class is not objective C since
6376 // the underlying decls respond to isCompleteDefinition(). Objective
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +00006377 // C decls don't respond to isCompleteDefinition() so we can't
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00006378 // start the declaration definition right away. For C++ class/union/structs
Greg Clayton219cf312012-03-30 00:51:13 +00006379 // we want to start the definition in case the class is needed as the
6380 // declaration context for a contained class or type without the need
6381 // to complete that type..
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006382
Sean Callanan7457f8d2012-04-25 01:03:57 +00006383 if (class_language != eLanguageTypeObjC &&
6384 class_language != eLanguageTypeObjC_plus_plus)
Greg Clayton57ee3062013-07-11 22:46:58 +00006385 clang_type.StartTagDeclarationDefinition ();
Greg Clayton219cf312012-03-30 00:51:13 +00006386
Sean Callanan12014a02011-12-08 23:45:45 +00006387 // Leave this as a forward declaration until we need
6388 // to know the details of the type. lldb_private::Type
6389 // will automatically call the SymbolFile virtual function
6390 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
6391 // When the definition needs to be defined.
Greg Clayton57ee3062013-07-11 22:46:58 +00006392 m_forward_decl_die_to_clang_type[die] = clang_type.GetOpaqueQualType();
6393 m_forward_decl_clang_type_to_die[clang_type.RemoveFastQualifiers().GetOpaqueQualType()] = die;
6394 clang_type.SetHasExternalStorage (true);
Sean Callanan12014a02011-12-08 23:45:45 +00006395 }
Greg Claytonc615ce42010-11-09 04:42:43 +00006396 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006397
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006398 }
6399 break;
6400
6401 case DW_TAG_enumeration_type:
6402 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006403 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006404 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006405
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006406 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006407
Greg Claytond88d7592010-09-15 08:33:30 +00006408 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006409 if (num_attributes > 0)
6410 {
6411 uint32_t i;
6412
6413 for (i=0; i<num_attributes; ++i)
6414 {
6415 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006416 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6417 {
6418 switch (attr)
6419 {
Greg Clayton7a345282010-11-09 23:46:37 +00006420 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6421 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6422 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006423 case DW_AT_name:
6424 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006425 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006426 break;
Greg Clayton54166af2014-11-22 01:58:59 +00006427 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006428 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
6429 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006430 case DW_AT_declaration: break; //is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006431 case DW_AT_allocated:
6432 case DW_AT_associated:
6433 case DW_AT_bit_stride:
6434 case DW_AT_byte_stride:
6435 case DW_AT_data_location:
6436 case DW_AT_description:
6437 case DW_AT_start_scope:
6438 case DW_AT_visibility:
6439 case DW_AT_specification:
6440 case DW_AT_abstract_origin:
6441 case DW_AT_sibling:
6442 break;
6443 }
6444 }
6445 }
6446
Daniel Malead01b2952012-11-29 21:49:15 +00006447 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 +00006448
Greg Clayton57ee3062013-07-11 22:46:58 +00006449 ClangASTType enumerator_clang_type;
6450 clang_type.SetClangType (ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die));
6451 if (!clang_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00006452 {
Greg Clayton5d14fc02013-03-06 06:23:54 +00006453 if (encoding_uid != DW_INVALID_OFFSET)
6454 {
6455 Type *enumerator_type = ResolveTypeUID(encoding_uid);
6456 if (enumerator_type)
6457 enumerator_clang_type = enumerator_type->GetClangFullType();
6458 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006459
Greg Clayton57ee3062013-07-11 22:46:58 +00006460 if (!enumerator_clang_type)
Greg Clayton5d14fc02013-03-06 06:23:54 +00006461 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
6462 DW_ATE_signed,
6463 byte_size * 8);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006464
Greg Claytonca512b32011-01-14 04:54:56 +00006465 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00006466 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00006467 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006468 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00006469 }
6470 else
6471 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006472 enumerator_clang_type = clang_type.GetEnumerationIntegerType ();
Greg Clayton1be10fc2010-09-29 01:12:09 +00006473 }
6474
Greg Clayton57ee3062013-07-11 22:46:58 +00006475 LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006476
Greg Clayton81c22f62011-10-19 18:09:39 +00006477 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006478 this,
6479 type_name_const_str,
6480 byte_size,
6481 NULL,
6482 encoding_uid,
6483 Type::eEncodingIsUID,
6484 &decl,
6485 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006486 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006487
Greg Clayton57ee3062013-07-11 22:46:58 +00006488 clang_type.StartTagDeclarationDefinition ();
Greg Clayton6beaaa62011-01-17 03:46:26 +00006489 if (die->HasChildren())
6490 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006491 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00006492 bool is_signed = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00006493 enumerator_clang_type.IsIntegerType(is_signed);
Greg Clayton3e067532013-03-05 23:54:39 +00006494 ParseChildEnumerators(cu_sc, clang_type, is_signed, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00006495 }
Greg Clayton57ee3062013-07-11 22:46:58 +00006496 clang_type.CompleteTagDeclarationDefinition ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006497 }
6498 }
6499 break;
6500
Jim Inghamb0be4422010-08-12 01:20:14 +00006501 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006502 case DW_TAG_subprogram:
6503 case DW_TAG_subroutine_type:
6504 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006505 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006506 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006507
Greg Clayton23f59502012-07-17 03:23:13 +00006508 //const char *mangled = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006509 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00006510 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006511 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00006512 bool is_static = false;
6513 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00006514 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00006515 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00006516 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
6517 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Jim Ingham379397632012-10-27 02:54:13 +00006518 dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00006519
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006520 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00006521 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006522
6523
Greg Claytond88d7592010-09-15 08:33:30 +00006524 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006525 if (num_attributes > 0)
6526 {
6527 uint32_t i;
6528 for (i=0; i<num_attributes; ++i)
6529 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006530 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006531 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6532 {
6533 switch (attr)
6534 {
6535 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6536 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6537 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6538 case DW_AT_name:
6539 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006540 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006541 break;
6542
Greg Clayton71415542012-12-08 00:24:40 +00006543 case DW_AT_linkage_name:
Greg Clayton23f59502012-07-17 03:23:13 +00006544 case DW_AT_MIPS_linkage_name: break; // mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00006545 case DW_AT_type: type_die_offset = form_value.Reference(); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00006546 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006547 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
6548 case DW_AT_inline: is_inline = form_value.Boolean(); break;
6549 case DW_AT_virtuality: is_virtual = form_value.Boolean(); break;
6550 case DW_AT_explicit: is_explicit = form_value.Boolean(); break;
6551 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006552
Greg Claytonf51de672010-10-01 02:31:07 +00006553
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006554 case DW_AT_external:
6555 if (form_value.Unsigned())
6556 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00006557 if (storage == clang::SC_None)
6558 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006559 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00006560 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006561 }
6562 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006563
Greg Clayton72da3972011-08-16 18:40:23 +00006564 case DW_AT_specification:
Greg Clayton54166af2014-11-22 01:58:59 +00006565 specification_die_offset = form_value.Reference();
Greg Clayton72da3972011-08-16 18:40:23 +00006566 break;
6567
6568 case DW_AT_abstract_origin:
Greg Clayton54166af2014-11-22 01:58:59 +00006569 abstract_origin_die_offset = form_value.Reference();
Greg Clayton72da3972011-08-16 18:40:23 +00006570 break;
6571
Jim Ingham379397632012-10-27 02:54:13 +00006572 case DW_AT_object_pointer:
Greg Clayton54166af2014-11-22 01:58:59 +00006573 object_pointer_die_offset = form_value.Reference();
Jim Ingham379397632012-10-27 02:54:13 +00006574 break;
6575
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006576 case DW_AT_allocated:
6577 case DW_AT_associated:
6578 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006579 case DW_AT_calling_convention:
6580 case DW_AT_data_location:
6581 case DW_AT_elemental:
6582 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006583 case DW_AT_frame_base:
6584 case DW_AT_high_pc:
6585 case DW_AT_low_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006586 case DW_AT_prototyped:
6587 case DW_AT_pure:
6588 case DW_AT_ranges:
6589 case DW_AT_recursive:
6590 case DW_AT_return_addr:
6591 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006592 case DW_AT_start_scope:
6593 case DW_AT_static_link:
6594 case DW_AT_trampoline:
6595 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006596 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006597 case DW_AT_description:
6598 case DW_AT_sibling:
6599 break;
6600 }
6601 }
6602 }
Greg Clayton24739922010-10-13 03:15:28 +00006603 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006604
Jim Ingham379397632012-10-27 02:54:13 +00006605 std::string object_pointer_name;
6606 if (object_pointer_die_offset != DW_INVALID_OFFSET)
6607 {
6608 // Get the name from the object pointer die
6609 StreamString s;
6610 if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s))
6611 {
6612 object_pointer_name.assign(s.GetData());
6613 }
6614 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006615
Daniel Malead01b2952012-11-29 21:49:15 +00006616 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 +00006617
Greg Clayton57ee3062013-07-11 22:46:58 +00006618 ClangASTType return_clang_type;
Greg Clayton24739922010-10-13 03:15:28 +00006619 Type *func_type = NULL;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006620
Greg Clayton24739922010-10-13 03:15:28 +00006621 if (type_die_offset != DW_INVALID_OFFSET)
6622 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00006623
Greg Clayton24739922010-10-13 03:15:28 +00006624 if (func_type)
Greg Clayton42ce2f32011-12-12 21:50:19 +00006625 return_clang_type = func_type->GetClangForwardType();
Greg Clayton24739922010-10-13 03:15:28 +00006626 else
Greg Clayton57ee3062013-07-11 22:46:58 +00006627 return_clang_type = ast.GetBasicType(eBasicTypeVoid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006628
Greg Claytonf51de672010-10-01 02:31:07 +00006629
Greg Clayton57ee3062013-07-11 22:46:58 +00006630 std::vector<ClangASTType> function_param_types;
Greg Clayton24739922010-10-13 03:15:28 +00006631 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006632
Greg Clayton24739922010-10-13 03:15:28 +00006633 // Parse the function children for the parameters
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006634
Greg Claytoncb5860a2011-10-13 23:49:28 +00006635 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
6636 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00006637 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
6638
Greg Claytonf0705c82011-10-22 03:33:13 +00006639 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00006640 // Start off static. This will be set to false in ParseChildParameters(...)
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00006641 // if we find a "this" parameters as the first parameter
Greg Clayton5113dc82011-08-12 06:47:54 +00006642 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00006643 is_static = true;
Greg Claytond20deac2014-04-04 18:15:18 +00006644
Greg Clayton24739922010-10-13 03:15:28 +00006645 if (die->HasChildren())
6646 {
Greg Clayton0fffff52010-09-24 05:15:53 +00006647 bool skip_artificial = true;
Jim Ingham379397632012-10-27 02:54:13 +00006648 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00006649 containing_decl_ctx,
Jim Ingham379397632012-10-27 02:54:13 +00006650 dwarf_cu,
6651 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00006652 skip_artificial,
6653 is_static,
Greg Clayton03969752014-02-24 18:53:11 +00006654 is_variadic,
Jim Ingham379397632012-10-27 02:54:13 +00006655 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00006656 function_param_decls,
Greg Claytond20deac2014-04-04 18:15:18 +00006657 type_quals);
Greg Clayton24739922010-10-13 03:15:28 +00006658 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006659
Greg Clayton24739922010-10-13 03:15:28 +00006660 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006661 clang_type = ast.CreateFunctionType (return_clang_type,
Greg Clayton9cb25c42012-10-30 17:02:18 +00006662 function_param_types.data(),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006663 function_param_types.size(),
6664 is_variadic,
6665 type_quals);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006666
Sean Callanande9ce872013-05-09 23:13:13 +00006667 bool ignore_containing_context = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006668
Greg Clayton24739922010-10-13 03:15:28 +00006669 if (type_name_cstr)
6670 {
6671 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00006672 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006673 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00006674 ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true);
6675 if (objc_method.IsValid(true))
Greg Clayton0fffff52010-09-24 05:15:53 +00006676 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006677 ClangASTType class_opaque_type;
Greg Clayton1b3815c2013-01-30 00:18:29 +00006678 ConstString class_name(objc_method.GetClassName());
Greg Clayton7c810422012-01-18 23:40:49 +00006679 if (class_name)
Greg Clayton0fffff52010-09-24 05:15:53 +00006680 {
Greg Clayton278a16b2012-01-19 00:52:59 +00006681 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
Greg Claytonc7f03b62012-01-12 04:33:28 +00006682
6683 if (complete_objc_class_type_sp)
Greg Clayton0fffff52010-09-24 05:15:53 +00006684 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006685 ClangASTType type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
6686 if (type_clang_forward_type.IsObjCObjectOrInterfaceType ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00006687 class_opaque_type = type_clang_forward_type;
Greg Clayton0fffff52010-09-24 05:15:53 +00006688 }
Greg Clayton24739922010-10-13 03:15:28 +00006689 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006690
Greg Clayton24739922010-10-13 03:15:28 +00006691 if (class_opaque_type)
6692 {
6693 // If accessibility isn't set to anything valid, assume public for
6694 // now...
6695 if (accessibility == eAccessNone)
6696 accessibility = eAccessPublic;
6697
Greg Clayton57ee3062013-07-11 22:46:58 +00006698 clang::ObjCMethodDecl *objc_method_decl = class_opaque_type.AddMethodToObjCObjectType (type_name_cstr,
6699 clang_type,
6700 accessibility,
6701 is_artificial);
Greg Clayton24739922010-10-13 03:15:28 +00006702 type_handled = objc_method_decl != NULL;
Sean Callanan464a5b52012-10-04 22:06:29 +00006703 if (type_handled)
6704 {
6705 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Claytond0029442013-03-27 01:48:02 +00006706 GetClangASTContext().SetMetadataAsUserID (objc_method_decl, MakeUserID(die->GetOffset()));
Sean Callanan464a5b52012-10-04 22:06:29 +00006707 }
Sean Callananc3a1d562013-02-06 23:21:59 +00006708 else
6709 {
Jason Molendac1a65832013-03-07 22:44:42 +00006710 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 +00006711 die->GetOffset(),
6712 tag,
6713 DW_TAG_value_to_name(tag));
6714 }
Greg Clayton24739922010-10-13 03:15:28 +00006715 }
6716 }
Greg Clayton5113dc82011-08-12 06:47:54 +00006717 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00006718 {
6719 // Look at the parent of this DIE and see if is is
6720 // a class or struct and see if this is actually a
6721 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00006722 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00006723 if (class_type)
6724 {
Greg Clayton4116e932012-05-15 02:33:01 +00006725 if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset()))
6726 {
6727 // We uniqued the parent class of this function to another class
6728 // so we now need to associate all dies under "decl_ctx_die" to
6729 // DIEs in the DIE for "class_type"...
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006730 SymbolFileDWARF *class_symfile = NULL;
Greg Clayton4116e932012-05-15 02:33:01 +00006731 DWARFCompileUnitSP class_type_cu_sp;
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006732 const DWARFDebugInfoEntry *class_type_die = NULL;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006733
Sean Callanan2367f8a2013-02-26 01:12:25 +00006734 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
6735 if (debug_map_symfile)
6736 {
6737 class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID()));
6738 class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6739 }
6740 else
6741 {
6742 class_symfile = this;
6743 class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6744 }
Greg Clayton4116e932012-05-15 02:33:01 +00006745 if (class_type_die)
6746 {
Greg Claytond20deac2014-04-04 18:15:18 +00006747 DWARFDIECollection failures;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006748
Sean Callanan2367f8a2013-02-26 01:12:25 +00006749 CopyUniqueClassMethodTypes (class_symfile,
6750 class_type,
6751 class_type_cu_sp.get(),
6752 class_type_die,
6753 dwarf_cu,
6754 decl_ctx_die,
6755 failures);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006756
Sean Callanan2367f8a2013-02-26 01:12:25 +00006757 // FIXME do something with these failures that's smarter than
6758 // just dropping them on the ground. Unfortunately classes don't
6759 // like having stuff added to them after their definitions are
6760 // complete...
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006761
Sean Callanan2367f8a2013-02-26 01:12:25 +00006762 type_ptr = m_die_to_type[die];
6763 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton4116e932012-05-15 02:33:01 +00006764 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006765 type_sp = type_ptr->shared_from_this();
6766 break;
Greg Clayton4116e932012-05-15 02:33:01 +00006767 }
6768 }
6769 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006770
Greg Clayton72da3972011-08-16 18:40:23 +00006771 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00006772 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006773 // We have a specification which we are going to base our function
6774 // prototype off of, so we need this type to be completed so that the
6775 // m_die_to_decl_ctx for the method in the specification has a valid
6776 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006777 class_type->GetClangForwardType();
Greg Clayton72da3972011-08-16 18:40:23 +00006778 // If we have a specification, then the function type should have been
6779 // made with the specification and not with this die.
6780 DWARFCompileUnitSP spec_cu_sp;
6781 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006782 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006783 if (spec_clang_decl_ctx)
6784 {
6785 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
6786 }
6787 else
Jim Inghamc1663042011-09-29 22:12:35 +00006788 {
Daniel Malead01b2952012-11-29 21:49:15 +00006789 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8x) has no decl\n",
Greg Claytone38a5ed2012-01-05 03:57:59 +00006790 MakeUserID(die->GetOffset()),
6791 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006792 }
Greg Clayton72da3972011-08-16 18:40:23 +00006793 type_handled = true;
6794 }
6795 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
6796 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006797 // We have a specification which we are going to base our function
6798 // prototype off of, so we need this type to be completed so that the
6799 // m_die_to_decl_ctx for the method in the abstract origin has a valid
6800 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006801 class_type->GetClangForwardType();
Greg Clayton5cf58b92011-10-05 22:22:08 +00006802
Greg Clayton72da3972011-08-16 18:40:23 +00006803 DWARFCompileUnitSP abs_cu_sp;
6804 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006805 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006806 if (abs_clang_decl_ctx)
6807 {
6808 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
6809 }
6810 else
Jim Inghamc1663042011-09-29 22:12:35 +00006811 {
Daniel Malead01b2952012-11-29 21:49:15 +00006812 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 +00006813 MakeUserID(die->GetOffset()),
6814 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006815 }
Greg Clayton72da3972011-08-16 18:40:23 +00006816 type_handled = true;
6817 }
6818 else
6819 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006820 ClangASTType class_opaque_type = class_type->GetClangForwardType();
6821 if (class_opaque_type.IsCXXClassType ())
Greg Clayton931180e2011-01-27 06:44:37 +00006822 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006823 if (class_opaque_type.IsBeingDefined ())
Greg Clayton72da3972011-08-16 18:40:23 +00006824 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006825 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
6826 // in the DWARF for C++ methods... Default to public for now...
6827 if (accessibility == eAccessNone)
6828 accessibility = eAccessPublic;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006829
Greg Clayton20568dd2011-10-13 23:13:20 +00006830 if (!is_static && !die->HasChildren())
6831 {
6832 // We have a C++ member function with no children (this pointer!)
6833 // and clang will get mad if we try and make a function that isn't
6834 // well formed in the DWARF, so we will just skip it...
6835 type_handled = true;
6836 }
6837 else
6838 {
6839 clang::CXXMethodDecl *cxx_method_decl;
6840 // REMOVE THE CRASH DESCRIPTION BELOW
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00006841 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 +00006842 type_name_cstr,
6843 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00006844 MakeUserID(die->GetOffset()),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00006845 m_obj_file->GetFileSpec().GetPath().c_str());
Greg Clayton20568dd2011-10-13 23:13:20 +00006846
Sean Callananc1b732d2011-11-01 18:07:13 +00006847 const bool is_attr_used = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006848
Greg Clayton57ee3062013-07-11 22:46:58 +00006849 cxx_method_decl = class_opaque_type.AddMethodToCXXRecordType (type_name_cstr,
6850 clang_type,
6851 accessibility,
6852 is_virtual,
6853 is_static,
6854 is_inline,
6855 is_explicit,
6856 is_attr_used,
6857 is_artificial);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006858
Greg Clayton20568dd2011-10-13 23:13:20 +00006859 type_handled = cxx_method_decl != NULL;
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006860
6861 if (type_handled)
Jim Ingham379397632012-10-27 02:54:13 +00006862 {
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006863 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
6864
6865 Host::SetCrashDescription (NULL);
6866
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006867
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006868 ClangASTMetadata metadata;
6869 metadata.SetUserID(MakeUserID(die->GetOffset()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006870
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006871 if (!object_pointer_name.empty())
6872 {
6873 metadata.SetObjectPtrName(object_pointer_name.c_str());
6874 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006875 log->Printf ("Setting object pointer name: %s on method object %p.\n",
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006876 object_pointer_name.c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006877 static_cast<void*>(cxx_method_decl));
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006878 }
Greg Claytond0029442013-03-27 01:48:02 +00006879 GetClangASTContext().SetMetadata (cxx_method_decl, metadata);
Jim Ingham379397632012-10-27 02:54:13 +00006880 }
Sean Callananb0640dc2013-04-09 23:22:08 +00006881 else
6882 {
Sean Callanande9ce872013-05-09 23:13:13 +00006883 ignore_containing_context = true;
Sean Callananb0640dc2013-04-09 23:22:08 +00006884 }
Greg Clayton20568dd2011-10-13 23:13:20 +00006885 }
Greg Clayton72da3972011-08-16 18:40:23 +00006886 }
6887 else
6888 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006889 // We were asked to parse the type for a method in a class, yet the
6890 // class hasn't been asked to complete itself through the
6891 // clang::ExternalASTSource protocol, so we need to just have the
6892 // class complete itself and do things the right way, then our
6893 // DIE should then have an entry in the m_die_to_type map. First
6894 // we need to modify the m_die_to_type so it doesn't think we are
6895 // trying to parse this DIE anymore...
6896 m_die_to_type[die] = NULL;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006897
Greg Clayton20568dd2011-10-13 23:13:20 +00006898 // Now we get the full type to force our class type to complete itself
6899 // using the clang::ExternalASTSource protocol which will parse all
6900 // base classes and all methods (including the method for this DIE).
6901 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00006902
Greg Clayton20568dd2011-10-13 23:13:20 +00006903 // The type for this DIE should have been filled in the function call above
6904 type_ptr = m_die_to_type[die];
Greg Claytone5476db2012-06-01 20:32:35 +00006905 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton20568dd2011-10-13 23:13:20 +00006906 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006907 type_sp = type_ptr->shared_from_this();
Greg Clayton20568dd2011-10-13 23:13:20 +00006908 break;
6909 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006910
Sean Callanan02eee4d2012-04-12 23:10:00 +00006911 // FIXME This is fixing some even uglier behavior but we really need to
6912 // uniq the methods of each class as well as the class itself.
6913 // <rdar://problem/11240464>
6914 type_handled = true;
Greg Clayton72da3972011-08-16 18:40:23 +00006915 }
Greg Clayton931180e2011-01-27 06:44:37 +00006916 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006917 }
6918 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006919 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006920 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006921
Greg Clayton24739922010-10-13 03:15:28 +00006922 if (!type_handled)
6923 {
6924 // We just have a function that isn't part of a class
Sean Callanande9ce872013-05-09 23:13:13 +00006925 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (ignore_containing_context ? GetClangASTContext().GetTranslationUnitDecl() : containing_decl_ctx,
Greg Clayton147e1fa2011-10-14 22:47:18 +00006926 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006927 clang_type,
6928 storage,
6929 is_inline);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006930
6931// if (template_param_infos.GetSize() > 0)
6932// {
6933// clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
6934// function_decl,
6935// type_name_cstr,
6936// template_param_infos);
6937//
6938// ast.CreateFunctionTemplateSpecializationInfo (function_decl,
6939// func_template_decl,
6940// template_param_infos);
6941// }
Greg Clayton24739922010-10-13 03:15:28 +00006942 // Add the decl to our DIE to decl context map
6943 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00006944 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00006945 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006946 ast.SetFunctionParameters (function_decl,
6947 &function_param_decls.front(),
6948 function_param_decls.size());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006949
Jim Ingham379397632012-10-27 02:54:13 +00006950 ClangASTMetadata metadata;
6951 metadata.SetUserID(MakeUserID(die->GetOffset()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006952
Jim Ingham379397632012-10-27 02:54:13 +00006953 if (!object_pointer_name.empty())
6954 {
6955 metadata.SetObjectPtrName(object_pointer_name.c_str());
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006956 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006957 log->Printf ("Setting object pointer name: %s on function object %p.",
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006958 object_pointer_name.c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006959 static_cast<void*>(function_decl));
Jim Ingham379397632012-10-27 02:54:13 +00006960 }
Greg Claytond0029442013-03-27 01:48:02 +00006961 GetClangASTContext().SetMetadata (function_decl, metadata);
Greg Clayton24739922010-10-13 03:15:28 +00006962 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006963 }
Greg Clayton81c22f62011-10-19 18:09:39 +00006964 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006965 this,
6966 type_name_const_str,
6967 0,
6968 NULL,
6969 LLDB_INVALID_UID,
6970 Type::eEncodingIsUID,
6971 &decl,
6972 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006973 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00006974 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006975 }
6976 break;
6977
6978 case DW_TAG_array_type:
6979 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006980 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006981 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006982
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006983 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006984 int64_t first_index = 0;
6985 uint32_t byte_stride = 0;
6986 uint32_t bit_stride = 0;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006987 bool is_vector = false;
Greg Claytond88d7592010-09-15 08:33:30 +00006988 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006989
6990 if (num_attributes > 0)
6991 {
6992 uint32_t i;
6993 for (i=0; i<num_attributes; ++i)
6994 {
6995 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006996 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6997 {
6998 switch (attr)
6999 {
7000 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
7001 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
7002 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
7003 case DW_AT_name:
7004 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00007005 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007006 break;
7007
Greg Clayton54166af2014-11-22 01:58:59 +00007008 case DW_AT_type: type_die_offset = form_value.Reference(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00007009 case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007010 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
7011 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00007012 case DW_AT_GNU_vector: is_vector = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00007013 case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00007014 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007015 case DW_AT_allocated:
7016 case DW_AT_associated:
7017 case DW_AT_data_location:
7018 case DW_AT_description:
7019 case DW_AT_ordering:
7020 case DW_AT_start_scope:
7021 case DW_AT_visibility:
7022 case DW_AT_specification:
7023 case DW_AT_abstract_origin:
7024 case DW_AT_sibling:
7025 break;
7026 }
7027 }
7028 }
7029
Daniel Malead01b2952012-11-29 21:49:15 +00007030 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 +00007031
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007032 Type *element_type = ResolveTypeUID(type_die_offset);
7033
7034 if (element_type)
7035 {
7036 std::vector<uint64_t> element_orders;
7037 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
7038 if (byte_stride == 0 && bit_stride == 0)
7039 byte_stride = element_type->GetByteSize();
Greg Clayton57ee3062013-07-11 22:46:58 +00007040 ClangASTType array_element_type = element_type->GetClangForwardType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007041 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
Siva Chandra89ce9552015-01-05 23:06:14 +00007042 if (element_orders.size() > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007043 {
Siva Chandra89ce9552015-01-05 23:06:14 +00007044 uint64_t num_elements = 0;
7045 std::vector<uint64_t>::const_reverse_iterator pos;
7046 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
7047 for (pos = element_orders.rbegin(); pos != end; ++pos)
7048 {
7049 num_elements = *pos;
7050 clang_type = ast.CreateArrayType (array_element_type,
7051 num_elements,
7052 is_vector);
7053 array_element_type = clang_type;
7054 array_element_bit_stride = num_elements ?
7055 array_element_bit_stride * num_elements :
7056 array_element_bit_stride;
7057 }
7058 }
7059 else
7060 {
7061 clang_type = ast.CreateArrayType (array_element_type, 0, is_vector);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007062 }
7063 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00007064 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00007065 this,
7066 empty_name,
7067 array_element_bit_stride / 8,
7068 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00007069 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00007070 Type::eEncodingIsUID,
7071 &decl,
7072 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00007073 Type::eResolveStateFull));
7074 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007075 }
7076 }
7077 }
7078 break;
7079
Greg Clayton9b81a312010-06-12 01:20:30 +00007080 case DW_TAG_ptr_to_member_type:
7081 {
7082 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
7083 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
7084
Greg Claytond88d7592010-09-15 08:33:30 +00007085 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007086
Greg Clayton9b81a312010-06-12 01:20:30 +00007087 if (num_attributes > 0) {
7088 uint32_t i;
7089 for (i=0; i<num_attributes; ++i)
7090 {
7091 attr = attributes.AttributeAtIndex(i);
Greg Clayton9b81a312010-06-12 01:20:30 +00007092 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
7093 {
7094 switch (attr)
7095 {
7096 case DW_AT_type:
Greg Clayton54166af2014-11-22 01:58:59 +00007097 type_die_offset = form_value.Reference(); break;
Greg Clayton9b81a312010-06-12 01:20:30 +00007098 case DW_AT_containing_type:
Greg Clayton54166af2014-11-22 01:58:59 +00007099 containing_type_die_offset = form_value.Reference(); break;
Greg Clayton9b81a312010-06-12 01:20:30 +00007100 }
7101 }
7102 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007103
Greg Clayton9b81a312010-06-12 01:20:30 +00007104 Type *pointee_type = ResolveTypeUID(type_die_offset);
7105 Type *class_type = ResolveTypeUID(containing_type_die_offset);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007106
Greg Clayton57ee3062013-07-11 22:46:58 +00007107 ClangASTType pointee_clang_type = pointee_type->GetClangForwardType();
7108 ClangASTType class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00007109
Greg Clayton57ee3062013-07-11 22:46:58 +00007110 clang_type = pointee_clang_type.CreateMemberPointerType(class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00007111
Enrico Granata1cd5e922015-01-28 00:07:51 +00007112 byte_size = clang_type.GetByteSize(nullptr);
Greg Clayton9b81a312010-06-12 01:20:30 +00007113
Greg Clayton81c22f62011-10-19 18:09:39 +00007114 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00007115 this,
7116 type_name_const_str,
7117 byte_size,
7118 NULL,
7119 LLDB_INVALID_UID,
7120 Type::eEncodingIsUID,
7121 NULL,
7122 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00007123 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00007124 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007125
Greg Clayton9b81a312010-06-12 01:20:30 +00007126 break;
7127 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007128 default:
Greg Clayton84afacd2012-11-07 23:09:32 +00007129 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",
7130 die->GetOffset(),
7131 tag,
7132 DW_TAG_value_to_name(tag));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007133 break;
7134 }
7135
7136 if (type_sp.get())
7137 {
7138 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7139 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7140
7141 SymbolContextScope * symbol_context_scope = NULL;
7142 if (sc_parent_tag == DW_TAG_compile_unit)
7143 {
7144 symbol_context_scope = sc.comp_unit;
7145 }
Jason Molenda60db6e42014-10-16 01:40:16 +00007146 else if (sc.function != NULL && sc_parent_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007147 {
Greg Clayton81c22f62011-10-19 18:09:39 +00007148 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007149 if (symbol_context_scope == NULL)
7150 symbol_context_scope = sc.function;
7151 }
7152
7153 if (symbol_context_scope != NULL)
7154 {
7155 type_sp->SetSymbolContextScope(symbol_context_scope);
7156 }
7157
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00007158 // We are ready to put this type into the uniqued list up at the module level
7159 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00007160
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00007161 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007162 }
7163 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00007164 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007165 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00007166 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007167 }
7168 }
7169 return type_sp;
7170}
7171
7172size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00007173SymbolFileDWARF::ParseTypes
7174(
7175 const SymbolContext& sc,
7176 DWARFCompileUnit* dwarf_cu,
7177 const DWARFDebugInfoEntry *die,
7178 bool parse_siblings,
7179 bool parse_children
7180)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007181{
7182 size_t types_added = 0;
7183 while (die != NULL)
7184 {
7185 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00007186 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007187 {
7188 if (type_is_new)
7189 ++types_added;
7190 }
7191
7192 if (parse_children && die->HasChildren())
7193 {
7194 if (die->Tag() == DW_TAG_subprogram)
7195 {
7196 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00007197 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007198 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
7199 }
7200 else
7201 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
7202 }
7203
7204 if (parse_siblings)
7205 die = die->GetSibling();
7206 else
7207 die = NULL;
7208 }
7209 return types_added;
7210}
7211
7212
7213size_t
7214SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
7215{
7216 assert(sc.comp_unit && sc.function);
7217 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00007218 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007219 if (dwarf_cu)
7220 {
7221 dw_offset_t function_die_offset = sc.function->GetID();
7222 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
7223 if (function_die)
7224 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00007225 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007226 }
7227 }
7228
7229 return functions_added;
7230}
7231
7232
7233size_t
7234SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
7235{
7236 // At least a compile unit must be valid
7237 assert(sc.comp_unit);
7238 size_t types_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00007239 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007240 if (dwarf_cu)
7241 {
7242 if (sc.function)
7243 {
7244 dw_offset_t function_die_offset = sc.function->GetID();
7245 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
7246 if (func_die && func_die->HasChildren())
7247 {
7248 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
7249 }
7250 }
7251 else
7252 {
7253 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
7254 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
7255 {
7256 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
7257 }
7258 }
7259 }
7260
7261 return types_added;
7262}
7263
7264size_t
7265SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
7266{
7267 if (sc.comp_unit != NULL)
7268 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00007269 DWARFDebugInfo* info = DebugInfo();
7270 if (info == NULL)
7271 return 0;
7272
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007273 if (sc.function)
7274 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007275 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get();
7276
7277 if (dwarf_cu == NULL)
7278 return 0;
7279
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007280 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00007281
Greg Claytonc7bece562013-01-25 18:06:21 +00007282 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
7283 if (func_lo_pc != LLDB_INVALID_ADDRESS)
Greg Claytone38a5ed2012-01-05 03:57:59 +00007284 {
7285 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00007286
Greg Claytone38a5ed2012-01-05 03:57:59 +00007287 // Let all blocks know they have parse all their variables
7288 sc.function->GetBlock (false).SetDidParseVariables (true, true);
7289 return num_variables;
7290 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007291 }
7292 else if (sc.comp_unit)
7293 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007294 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get();
7295
7296 if (dwarf_cu == NULL)
7297 return 0;
7298
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007299 uint32_t vars_added = 0;
7300 VariableListSP variables (sc.comp_unit->GetVariableList(false));
7301
7302 if (variables.get() == NULL)
7303 {
7304 variables.reset(new VariableList());
7305 sc.comp_unit->SetVariableList(variables);
7306
Greg Claytond4a2b372011-09-12 23:21:58 +00007307 DWARFCompileUnit* match_dwarf_cu = NULL;
7308 const DWARFDebugInfoEntry* die = NULL;
7309 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00007310 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00007311 {
Greg Clayton97fbc342011-10-20 22:30:33 +00007312 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00007313 {
7314 DWARFMappedHash::DIEInfoArray hash_data_array;
7315 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
7316 dwarf_cu->GetNextCompileUnitOffset(),
7317 hash_data_array))
7318 {
7319 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
7320 }
7321 }
Greg Clayton7f995132011-10-04 22:41:51 +00007322 }
7323 else
7324 {
7325 // Index if we already haven't to make sure the compile units
7326 // get indexed and make their global DIE index list
7327 if (!m_indexed)
7328 Index ();
7329
7330 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
7331 dwarf_cu->GetNextCompileUnitOffset(),
7332 die_offsets);
7333 }
7334
7335 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00007336 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007337 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007338 DWARFDebugInfo* debug_info = DebugInfo();
7339 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007340 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007341 const dw_offset_t die_offset = die_offsets[i];
7342 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00007343 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00007344 {
Greg Clayton95d87902011-11-11 03:16:25 +00007345 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
7346 if (var_sp)
7347 {
7348 variables->AddVariableIfUnique (var_sp);
7349 ++vars_added;
7350 }
Greg Claytond4a2b372011-09-12 23:21:58 +00007351 }
Greg Clayton95d87902011-11-11 03:16:25 +00007352 else
7353 {
7354 if (m_using_apple_tables)
7355 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00007356 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 +00007357 }
7358 }
7359
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007360 }
7361 }
7362 }
7363 return vars_added;
7364 }
7365 }
7366 return 0;
7367}
7368
7369
7370VariableSP
7371SymbolFileDWARF::ParseVariableDIE
7372(
7373 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007374 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007375 const DWARFDebugInfoEntry *die,
7376 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007377)
7378{
Greg Clayton83c5cd92010-11-14 22:13:40 +00007379 VariableSP var_sp (m_die_to_variable_sp[die]);
7380 if (var_sp)
7381 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007382
7383 const dw_tag_t tag = die->Tag();
Richard Mitton0a558352013-10-17 21:14:00 +00007384 ModuleSP module = GetObjectFile()->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00007385
7386 if ((tag == DW_TAG_variable) ||
7387 (tag == DW_TAG_constant) ||
7388 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007389 {
Greg Clayton7f995132011-10-04 22:41:51 +00007390 DWARFDebugInfoEntry::Attributes attributes;
7391 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
7392 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007393 {
Greg Clayton7f995132011-10-04 22:41:51 +00007394 const char *name = NULL;
7395 const char *mangled = NULL;
7396 Declaration decl;
7397 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00007398 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00007399 DWARFExpression location;
7400 bool is_external = false;
7401 bool is_artificial = false;
7402 bool location_is_const_value_data = false;
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007403 bool has_explicit_location = false;
Enrico Granata4ec130d2014-08-11 19:16:35 +00007404 DWARFFormValue const_value;
Greg Clayton23f59502012-07-17 03:23:13 +00007405 //AccessType accessibility = eAccessNone;
Greg Clayton7f995132011-10-04 22:41:51 +00007406
7407 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007408 {
Greg Clayton7f995132011-10-04 22:41:51 +00007409 dw_attr_t attr = attributes.AttributeAtIndex(i);
7410 DWARFFormValue form_value;
Greg Clayton54166af2014-11-22 01:58:59 +00007411
Greg Clayton7f995132011-10-04 22:41:51 +00007412 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007413 {
Greg Clayton7f995132011-10-04 22:41:51 +00007414 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007415 {
Greg Clayton7f995132011-10-04 22:41:51 +00007416 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
7417 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
7418 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
7419 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton71415542012-12-08 00:24:40 +00007420 case DW_AT_linkage_name:
Greg Clayton7f995132011-10-04 22:41:51 +00007421 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00007422 case DW_AT_type: type_uid = form_value.Reference(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00007423 case DW_AT_external: is_external = form_value.Boolean(); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007424 case DW_AT_const_value:
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007425 // If we have already found a DW_AT_location attribute, ignore this attribute.
7426 if (!has_explicit_location)
7427 {
7428 location_is_const_value_data = true;
7429 // The constant value will be either a block, a data value or a string.
Ed Masteeeae7212013-10-24 20:43:47 +00007430 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007431 if (DWARFFormValue::IsBlockForm(form_value.Form()))
7432 {
7433 // Retrieve the value as a block expression.
7434 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7435 uint32_t block_length = form_value.Unsigned();
Richard Mitton0a558352013-10-17 21:14:00 +00007436 location.CopyOpcodeData(module, debug_info_data, block_offset, block_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007437 }
7438 else if (DWARFFormValue::IsDataForm(form_value.Form()))
7439 {
7440 // Retrieve the value as a data expression.
Greg Clayton54166af2014-11-22 01:58:59 +00007441 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (attributes.CompileUnitAtIndex(i)->GetAddressByteSize(), attributes.CompileUnitAtIndex(i)->IsDWARF64());
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007442 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7443 uint32_t data_length = fixed_form_sizes[form_value.Form()];
Enrico Granata4ec130d2014-08-11 19:16:35 +00007444 if (data_length == 0)
7445 {
7446 const uint8_t *data_pointer = form_value.BlockData();
7447 if (data_pointer)
7448 {
Jason Molenda18f5fd32014-10-16 07:52:17 +00007449 form_value.Unsigned();
Enrico Granata4ec130d2014-08-11 19:16:35 +00007450 }
7451 else if (DWARFFormValue::IsDataForm(form_value.Form()))
7452 {
7453 // we need to get the byte size of the type later after we create the variable
7454 const_value = form_value;
7455 }
7456 }
7457 else
7458 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007459 }
7460 else
7461 {
7462 // Retrieve the value as a string expression.
7463 if (form_value.Form() == DW_FORM_strp)
7464 {
Greg Clayton54166af2014-11-22 01:58:59 +00007465 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (attributes.CompileUnitAtIndex(i)->GetAddressByteSize(), attributes.CompileUnitAtIndex(i)->IsDWARF64());
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007466 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7467 uint32_t data_length = fixed_form_sizes[form_value.Form()];
Richard Mitton0a558352013-10-17 21:14:00 +00007468 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007469 }
7470 else
7471 {
7472 const char *str = form_value.AsCString(&debug_info_data);
7473 uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart();
7474 uint32_t string_length = strlen(str) + 1;
Richard Mitton0a558352013-10-17 21:14:00 +00007475 location.CopyOpcodeData(module, debug_info_data, string_offset, string_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007476 }
7477 }
7478 }
7479 break;
Greg Clayton7f995132011-10-04 22:41:51 +00007480 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007481 {
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007482 location_is_const_value_data = false;
7483 has_explicit_location = true;
Greg Clayton7f995132011-10-04 22:41:51 +00007484 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007485 {
Ed Masteeeae7212013-10-24 20:43:47 +00007486 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Clayton7f995132011-10-04 22:41:51 +00007487
7488 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7489 uint32_t block_length = form_value.Unsigned();
Richard Mitton0a558352013-10-17 21:14:00 +00007490 location.CopyOpcodeData(module, get_debug_info_data(), block_offset, block_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007491 }
7492 else
7493 {
Ed Masteeeae7212013-10-24 20:43:47 +00007494 const DWARFDataExtractor& debug_loc_data = get_debug_loc_data();
Greg Clayton7f995132011-10-04 22:41:51 +00007495 const dw_offset_t debug_loc_offset = form_value.Unsigned();
7496
7497 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
7498 if (loc_list_length > 0)
7499 {
Richard Mitton0a558352013-10-17 21:14:00 +00007500 location.CopyOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007501 assert (func_low_pc != LLDB_INVALID_ADDRESS);
Greg Clayton54166af2014-11-22 01:58:59 +00007502 location.SetLocationListSlide (func_low_pc - attributes.CompileUnitAtIndex(i)->GetBaseAddress());
Greg Clayton7f995132011-10-04 22:41:51 +00007503 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007504 }
7505 }
Greg Clayton7f995132011-10-04 22:41:51 +00007506 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007507
Greg Clayton1c8ef472013-04-05 23:27:21 +00007508 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00007509 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007510 case DW_AT_declaration:
7511 case DW_AT_description:
7512 case DW_AT_endianity:
7513 case DW_AT_segment:
7514 case DW_AT_start_scope:
7515 case DW_AT_visibility:
7516 default:
7517 case DW_AT_abstract_origin:
7518 case DW_AT_sibling:
7519 case DW_AT_specification:
7520 break;
7521 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007522 }
7523 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007524
Greg Clayton9e9f2192013-05-17 00:55:28 +00007525 ValueType scope = eValueTypeInvalid;
7526
7527 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7528 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7529 SymbolContextScope * symbol_context_scope = NULL;
7530
Siva Chandra0783ab92015-03-24 18:32:27 +00007531 if (!mangled)
7532 {
7533 // LLDB relies on the mangled name (DW_TAG_linkage_name or DW_AT_MIPS_linkage_name) to
7534 // generate fully qualified names of global variables with commands like "frame var j".
7535 // For example, if j were an int variable holding a value 4 and declared in a namespace
7536 // B which in turn is contained in a namespace A, the command "frame var j" returns
7537 // "(int) A::B::j = 4". If the compiler does not emit a linkage name, we should be able
7538 // to generate a fully qualified name from the declaration context.
7539 if (die->GetParent()->Tag() == DW_TAG_compile_unit &&
7540 LanguageRuntime::LanguageIsCPlusPlus(dwarf_cu->GetLanguageType()))
7541 {
7542 DWARFDeclContext decl_ctx;
7543
7544 die->GetDWARFDeclContext(this, dwarf_cu, decl_ctx);
7545 mangled = decl_ctx.GetQualifiedNameAsConstString().GetCString();
7546 }
7547 }
7548
Greg Clayton9e9f2192013-05-17 00:55:28 +00007549 // DWARF doesn't specify if a DW_TAG_variable is a local, global
7550 // or static variable, so we have to do a little digging by
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00007551 // looking at the location of a variable to see if it contains
Greg Clayton9e9f2192013-05-17 00:55:28 +00007552 // a DW_OP_addr opcode _somewhere_ in the definition. I say
7553 // somewhere because clang likes to combine small global variables
7554 // into the same symbol and have locations like:
7555 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
7556 // So if we don't have a DW_TAG_formal_parameter, we can look at
7557 // the location to see if it contains a DW_OP_addr opcode, and
7558 // then we can correctly classify our variables.
7559 if (tag == DW_TAG_formal_parameter)
7560 scope = eValueTypeVariableArgument;
7561 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007562 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007563 bool op_error = false;
7564 // Check if the location has a DW_OP_addr with any address value...
7565 lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS;
7566 if (!location_is_const_value_data)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007567 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007568 location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error);
7569 if (op_error)
Greg Clayton96c09682012-01-04 22:56:43 +00007570 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007571 StreamString strm;
7572 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
7573 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 +00007574 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007575 }
Greg Claytond1767f02011-12-08 02:13:16 +00007576
Greg Clayton9e9f2192013-05-17 00:55:28 +00007577 if (location_DW_OP_addr != LLDB_INVALID_ADDRESS)
7578 {
7579 if (is_external)
7580 scope = eValueTypeVariableGlobal;
7581 else
7582 scope = eValueTypeVariableStatic;
7583
7584
7585 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile ();
7586
7587 if (debug_map_symfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007588 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007589 // When leaving the DWARF in the .o files on darwin,
7590 // when we have a global variable that wasn't initialized,
7591 // the .o file might not have allocated a virtual
7592 // address for the global variable. In this case it will
7593 // have created a symbol for the global variable
7594 // that is undefined/data and external and the value will
7595 // be the byte size of the variable. When we do the
7596 // address map in SymbolFileDWARFDebugMap we rely on
7597 // having an address, we need to do some magic here
7598 // so we can get the correct address for our global
7599 // variable. The address for all of these entries
7600 // will be zero, and there will be an undefined symbol
7601 // in this object file, and the executable will have
7602 // a matching symbol with a good address. So here we
7603 // dig up the correct address and replace it in the
7604 // location for the variable, and set the variable's
7605 // symbol context scope to be that of the main executable
7606 // so the file address will resolve correctly.
7607 bool linked_oso_file_addr = false;
7608 if (is_external && location_DW_OP_addr == 0)
Greg Clayton9422dd62013-03-04 21:46:16 +00007609 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007610 // we have a possible uninitialized extern global
7611 ConstString const_name(mangled ? mangled : name);
7612 ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile();
7613 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007614 {
Greg Clayton3046e662013-07-10 01:23:25 +00007615 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
Greg Clayton9e9f2192013-05-17 00:55:28 +00007616 if (debug_map_symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007617 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007618 Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
7619 eSymbolTypeData,
7620 Symtab::eDebugYes,
7621 Symtab::eVisibilityExtern);
7622 if (exe_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007623 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007624 if (exe_symbol->ValueIsAddress())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007625 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007626 const addr_t exe_file_addr = exe_symbol->GetAddress().GetFileAddress();
7627 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007628 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007629 if (location.Update_DW_OP_addr (exe_file_addr))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007630 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007631 linked_oso_file_addr = true;
7632 symbol_context_scope = exe_symbol;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007633 }
7634 }
7635 }
7636 }
7637 }
7638 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007639 }
Greg Clayton9422dd62013-03-04 21:46:16 +00007640
Greg Clayton9e9f2192013-05-17 00:55:28 +00007641 if (!linked_oso_file_addr)
7642 {
7643 // The DW_OP_addr is not zero, but it contains a .o file address which
7644 // needs to be linked up correctly.
7645 const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr);
7646 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton9422dd62013-03-04 21:46:16 +00007647 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007648 // Update the file address for this variable
7649 location.Update_DW_OP_addr (exe_file_addr);
7650 }
7651 else
7652 {
7653 // Variable didn't make it into the final executable
7654 return var_sp;
Greg Clayton9422dd62013-03-04 21:46:16 +00007655 }
Greg Claytond1767f02011-12-08 02:13:16 +00007656 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007657 }
Greg Clayton5cf58b92011-10-05 22:22:08 +00007658 }
7659 else
7660 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007661 scope = eValueTypeVariableLocal;
Greg Clayton5cf58b92011-10-05 22:22:08 +00007662 }
Greg Clayton7f995132011-10-04 22:41:51 +00007663 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007664
7665 if (symbol_context_scope == NULL)
7666 {
7667 switch (parent_tag)
7668 {
7669 case DW_TAG_subprogram:
7670 case DW_TAG_inlined_subroutine:
7671 case DW_TAG_lexical_block:
7672 if (sc.function)
7673 {
7674 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
7675 if (symbol_context_scope == NULL)
7676 symbol_context_scope = sc.function;
7677 }
7678 break;
7679
7680 default:
7681 symbol_context_scope = sc.comp_unit;
7682 break;
7683 }
7684 }
7685
7686 if (symbol_context_scope)
7687 {
Enrico Granata4ec130d2014-08-11 19:16:35 +00007688 SymbolFileTypeSP type_sp(new SymbolFileType(*this, type_uid));
7689
7690 if (const_value.Form() && type_sp && type_sp->GetType())
7691 location.CopyOpcodeData(const_value.Unsigned(), type_sp->GetType()->GetByteSize(), dwarf_cu->GetAddressByteSize());
7692
Greg Clayton9e9f2192013-05-17 00:55:28 +00007693 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
7694 name,
7695 mangled,
Enrico Granata4ec130d2014-08-11 19:16:35 +00007696 type_sp,
Greg Clayton9e9f2192013-05-17 00:55:28 +00007697 scope,
7698 symbol_context_scope,
7699 &decl,
7700 location,
7701 is_external,
7702 is_artificial));
7703
7704 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
7705 }
7706 else
7707 {
7708 // Not ready to parse this variable yet. It might be a global
7709 // or static variable that is in a function scope and the function
7710 // in the symbol context wasn't filled in yet
7711 return var_sp;
7712 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007713 }
Greg Clayton7f995132011-10-04 22:41:51 +00007714 // Cache var_sp even if NULL (the variable was just a specification or
7715 // was missing vital information to be able to be displayed in the debugger
7716 // (missing location due to optimization, etc)) so we don't re-parse
7717 // this DIE over and over later...
7718 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007719 }
7720 return var_sp;
7721}
7722
Greg Claytonc662ec82011-06-17 22:10:16 +00007723
7724const DWARFDebugInfoEntry *
7725SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
7726 dw_offset_t spec_block_die_offset,
7727 DWARFCompileUnit **result_die_cu_handle)
7728{
7729 // Give the concrete function die specified by "func_die_offset", find the
7730 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7731 // to "spec_block_die_offset"
7732 DWARFDebugInfo* info = DebugInfo();
7733
7734 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
7735 if (die)
7736 {
7737 assert (*result_die_cu_handle);
7738 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
7739 }
7740 return NULL;
7741}
7742
7743
7744const DWARFDebugInfoEntry *
7745SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
7746 const DWARFDebugInfoEntry *die,
7747 dw_offset_t spec_block_die_offset,
7748 DWARFCompileUnit **result_die_cu_handle)
7749{
7750 if (die)
7751 {
7752 switch (die->Tag())
7753 {
7754 case DW_TAG_subprogram:
7755 case DW_TAG_inlined_subroutine:
7756 case DW_TAG_lexical_block:
7757 {
7758 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
7759 {
7760 *result_die_cu_handle = dwarf_cu;
7761 return die;
7762 }
7763
7764 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
7765 {
7766 *result_die_cu_handle = dwarf_cu;
7767 return die;
7768 }
7769 }
7770 break;
7771 }
7772
7773 // Give the concrete function die specified by "func_die_offset", find the
7774 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7775 // to "spec_block_die_offset"
7776 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
7777 {
7778 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
7779 child_die,
7780 spec_block_die_offset,
7781 result_die_cu_handle);
7782 if (result_die)
7783 return result_die;
7784 }
7785 }
7786
7787 *result_die_cu_handle = NULL;
7788 return NULL;
7789}
7790
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007791size_t
7792SymbolFileDWARF::ParseVariables
7793(
7794 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007795 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007796 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007797 const DWARFDebugInfoEntry *orig_die,
7798 bool parse_siblings,
7799 bool parse_children,
7800 VariableList* cc_variable_list
7801)
7802{
7803 if (orig_die == NULL)
7804 return 0;
7805
Greg Claytonc662ec82011-06-17 22:10:16 +00007806 VariableListSP variable_list_sp;
7807
7808 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007809 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00007810 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007811 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007812 dw_tag_t tag = die->Tag();
7813
7814 // Check to see if we have already parsed this variable or constant?
7815 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007816 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007817 if (cc_variable_list)
7818 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007819 }
7820 else
7821 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007822 // We haven't already parsed it, lets do that now.
7823 if ((tag == DW_TAG_variable) ||
7824 (tag == DW_TAG_constant) ||
7825 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007826 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007827 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00007828 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007829 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
7830 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7831 switch (parent_tag)
7832 {
7833 case DW_TAG_compile_unit:
7834 if (sc.comp_unit != NULL)
7835 {
7836 variable_list_sp = sc.comp_unit->GetVariableList(false);
7837 if (variable_list_sp.get() == NULL)
7838 {
7839 variable_list_sp.reset(new VariableList());
7840 sc.comp_unit->SetVariableList(variable_list_sp);
7841 }
7842 }
7843 else
7844 {
Daniel Malead01b2952012-11-29 21:49:15 +00007845 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 +00007846 MakeUserID(sc_parent_die->GetOffset()),
7847 DW_TAG_value_to_name (parent_tag),
7848 MakeUserID(orig_die->GetOffset()),
7849 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007850 }
7851 break;
7852
7853 case DW_TAG_subprogram:
7854 case DW_TAG_inlined_subroutine:
7855 case DW_TAG_lexical_block:
7856 if (sc.function != NULL)
7857 {
7858 // Check to see if we already have parsed the variables for the given scope
7859
Greg Clayton81c22f62011-10-19 18:09:39 +00007860 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007861 if (block == NULL)
7862 {
7863 // This must be a specification or abstract origin with
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00007864 // a concrete block counterpart in the current function. We need
Greg Claytonc662ec82011-06-17 22:10:16 +00007865 // to find the concrete block so we can correctly add the
7866 // variable to it
7867 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
7868 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
7869 sc_parent_die->GetOffset(),
7870 &concrete_block_die_cu);
7871 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00007872 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007873 }
7874
7875 if (block != NULL)
7876 {
7877 const bool can_create = false;
7878 variable_list_sp = block->GetBlockVariableList (can_create);
7879 if (variable_list_sp.get() == NULL)
7880 {
7881 variable_list_sp.reset(new VariableList());
7882 block->SetVariableList(variable_list_sp);
7883 }
7884 }
7885 }
7886 break;
7887
7888 default:
Daniel Malead01b2952012-11-29 21:49:15 +00007889 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 +00007890 MakeUserID(orig_die->GetOffset()),
7891 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007892 break;
7893 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00007894 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007895
7896 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007897 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00007898 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
7899 if (var_sp)
7900 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007901 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00007902 if (cc_variable_list)
7903 cc_variable_list->AddVariableIfUnique (var_sp);
7904 ++vars_added;
7905 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007906 }
7907 }
7908 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007909
7910 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
7911
7912 if (!skip_children && parse_children && die->HasChildren())
7913 {
7914 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
7915 }
7916
7917 if (parse_siblings)
7918 die = die->GetSibling();
7919 else
7920 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007921 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007922 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007923}
7924
7925//------------------------------------------------------------------
7926// PluginInterface protocol
7927//------------------------------------------------------------------
Greg Clayton57abc5d2013-05-10 21:47:16 +00007928ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007929SymbolFileDWARF::GetPluginName()
7930{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007931 return GetPluginNameStatic();
7932}
7933
7934uint32_t
7935SymbolFileDWARF::GetPluginVersion()
7936{
7937 return 1;
7938}
7939
7940void
Greg Clayton6beaaa62011-01-17 03:46:26 +00007941SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
7942{
7943 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
Greg Clayton57ee3062013-07-11 22:46:58 +00007944 ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
Greg Clayton6beaaa62011-01-17 03:46:26 +00007945 if (clang_type)
7946 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7947}
7948
7949void
7950SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
7951{
7952 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
Greg Clayton57ee3062013-07-11 22:46:58 +00007953 ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
Greg Clayton6beaaa62011-01-17 03:46:26 +00007954 if (clang_type)
7955 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7956}
7957
Greg Claytona2721472011-06-25 00:44:06 +00007958void
Sean Callanancc427fa2011-07-30 02:42:06 +00007959SymbolFileDWARF::DumpIndexes ()
7960{
7961 StreamFile s(stdout, false);
7962
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00007963 s.Printf ("DWARF index for (%s) '%s':",
Sean Callanancc427fa2011-07-30 02:42:06 +00007964 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00007965 GetObjectFile()->GetFileSpec().GetPath().c_str());
Sean Callanancc427fa2011-07-30 02:42:06 +00007966 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
7967 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
7968 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
7969 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
7970 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
7971 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
7972 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
7973 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
7974}
7975
7976void
7977SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
7978 const char *name,
7979 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00007980{
Sean Callanancc427fa2011-07-30 02:42:06 +00007981 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00007982
7983 if (iter == m_decl_ctx_to_die.end())
7984 return;
7985
Greg Claytoncb5860a2011-10-13 23:49:28 +00007986 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00007987 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007988 const DWARFDebugInfoEntry *context_die = *pos;
7989
7990 if (!results)
7991 return;
7992
7993 DWARFDebugInfo* info = DebugInfo();
7994
7995 DIEArray die_offsets;
7996
7997 DWARFCompileUnit* dwarf_cu = NULL;
7998 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton220a0072011-12-09 08:48:30 +00007999
8000 if (m_using_apple_tables)
8001 {
8002 if (m_apple_types_ap.get())
8003 m_apple_types_ap->FindByName (name, die_offsets);
8004 }
8005 else
8006 {
8007 if (!m_indexed)
8008 Index ();
8009
8010 m_type_index.Find (ConstString(name), die_offsets);
8011 }
8012
Greg Clayton220a0072011-12-09 08:48:30 +00008013 const size_t num_matches = die_offsets.size();
Greg Claytoncb5860a2011-10-13 23:49:28 +00008014
8015 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00008016 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00008017 for (size_t i = 0; i < num_matches; ++i)
8018 {
8019 const dw_offset_t die_offset = die_offsets[i];
8020 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00008021
Greg Claytoncb5860a2011-10-13 23:49:28 +00008022 if (die->GetParent() != context_die)
8023 continue;
8024
8025 Type *matching_type = ResolveType (dwarf_cu, die);
8026
Greg Clayton57ee3062013-07-11 22:46:58 +00008027 clang::QualType qual_type = matching_type->GetClangForwardType().GetQualType();
Greg Claytoncb5860a2011-10-13 23:49:28 +00008028
8029 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
8030 {
8031 clang::TagDecl *tag_decl = tag_type->getDecl();
8032 results->push_back(tag_decl);
8033 }
8034 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
8035 {
8036 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
8037 results->push_back(typedef_decl);
8038 }
Greg Claytona2721472011-06-25 00:44:06 +00008039 }
8040 }
8041 }
8042}
8043
8044void
8045SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00008046 const clang::DeclContext *decl_context,
8047 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00008048 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
8049{
Greg Clayton85ae2e12011-10-18 23:36:41 +00008050
8051 switch (decl_context->getDeclKind())
8052 {
8053 case clang::Decl::Namespace:
8054 case clang::Decl::TranslationUnit:
8055 {
8056 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
8057 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
8058 }
8059 break;
8060 default:
8061 break;
8062 }
Greg Claytona2721472011-06-25 00:44:06 +00008063}
Greg Claytoncaab74e2012-01-28 00:48:57 +00008064
Zachary Turner504f38d2015-03-24 16:24:50 +00008065bool
8066SymbolFileDWARF::LayoutRecordType(void *baton, const clang::RecordDecl *record_decl, uint64_t &size,
8067 uint64_t &alignment,
Zachary Turnera98fac22015-03-24 18:56:08 +00008068 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
8069 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
8070 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
Greg Claytoncaab74e2012-01-28 00:48:57 +00008071{
8072 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
8073 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
8074}
8075
Zachary Turner504f38d2015-03-24 16:24:50 +00008076bool
8077SymbolFileDWARF::LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &bit_size, uint64_t &alignment,
Zachary Turnera98fac22015-03-24 18:56:08 +00008078 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
8079 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
8080 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
Greg Claytoncaab74e2012-01-28 00:48:57 +00008081{
Greg Clayton5160ce52013-03-27 23:08:40 +00008082 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Claytoncaab74e2012-01-28 00:48:57 +00008083 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
8084 bool success = false;
8085 base_offsets.clear();
8086 vbase_offsets.clear();
8087 if (pos != m_record_decl_to_layout_map.end())
8088 {
8089 bit_size = pos->second.bit_size;
8090 alignment = pos->second.alignment;
8091 field_offsets.swap(pos->second.field_offsets);
Greg Clayton2508b9b2012-11-01 23:20:02 +00008092 base_offsets.swap (pos->second.base_offsets);
8093 vbase_offsets.swap (pos->second.vbase_offsets);
Greg Claytoncaab74e2012-01-28 00:48:57 +00008094 m_record_decl_to_layout_map.erase(pos);
8095 success = true;
8096 }
8097 else
8098 {
8099 bit_size = 0;
8100 alignment = 0;
8101 field_offsets.clear();
8102 }
8103
8104 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00008105 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00008106 "SymbolFileDWARF::LayoutRecordType (record_decl = %p, bit_size = %" PRIu64 ", alignment = %" PRIu64 ", field_offsets[%u],base_offsets[%u], vbase_offsets[%u]) success = %i",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00008107 static_cast<const void*>(record_decl),
8108 bit_size, alignment,
8109 static_cast<uint32_t>(field_offsets.size()),
8110 static_cast<uint32_t>(base_offsets.size()),
8111 static_cast<uint32_t>(vbase_offsets.size()),
Greg Claytoncaab74e2012-01-28 00:48:57 +00008112 success);
8113 return success;
8114}
8115
8116
Greg Clayton1f746072012-08-29 21:13:06 +00008117SymbolFileDWARFDebugMap *
8118SymbolFileDWARF::GetDebugMapSymfile ()
8119{
8120 if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired())
8121 {
8122 lldb::ModuleSP module_sp (m_debug_map_module_wp.lock());
8123 if (module_sp)
8124 {
8125 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
8126 if (sym_vendor)
8127 m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile();
8128 }
8129 }
8130 return m_debug_map_symfile;
8131}
8132
Greg Claytoncaab74e2012-01-28 00:48:57 +00008133