blob: dafd389449a2bee2bf6cdafdd6f18eef0160fed7 [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
Robert Flackeb83fab2015-05-15 18:59:59 +000029#include "lldb/Core/ArchSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030#include "lldb/Core/Module.h"
Sean Callananf0c5aeb2015-04-20 16:31:29 +000031#include "lldb/Core/ModuleList.h"
32#include "lldb/Core/ModuleSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033#include "lldb/Core/PluginManager.h"
34#include "lldb/Core/RegularExpression.h"
35#include "lldb/Core/Scalar.h"
36#include "lldb/Core/Section.h"
Greg Claytonc685f8e2010-09-15 04:15:46 +000037#include "lldb/Core/StreamFile.h"
Jim Ingham318c9f22011-08-26 19:44:13 +000038#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039#include "lldb/Core/Timer.h"
40#include "lldb/Core/Value.h"
41
Sean Callananf0c5aeb2015-04-20 16:31:29 +000042#include "lldb/Expression/ClangModulesDeclVendor.h"
43
Greg Clayton20568dd2011-10-13 23:13:20 +000044#include "lldb/Host/Host.h"
45
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046#include "lldb/Symbol/Block.h"
Greg Clayton6beaaa62011-01-17 03:46:26 +000047#include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000048#include "lldb/Symbol/CompileUnit.h"
49#include "lldb/Symbol/LineTable.h"
50#include "lldb/Symbol/ObjectFile.h"
51#include "lldb/Symbol/SymbolVendor.h"
52#include "lldb/Symbol/VariableList.h"
53
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000054#include "lldb/Target/ObjCLanguageRuntime.h"
Jim Ingham4cda6e02011-10-07 22:23:45 +000055#include "lldb/Target/CPPLanguageRuntime.h"
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000056
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057#include "DWARFCompileUnit.h"
58#include "DWARFDebugAbbrev.h"
59#include "DWARFDebugAranges.h"
60#include "DWARFDebugInfo.h"
61#include "DWARFDebugInfoEntry.h"
62#include "DWARFDebugLine.h"
63#include "DWARFDebugPubnames.h"
64#include "DWARFDebugRanges.h"
Greg Claytona8022fa2012-04-24 21:22:41 +000065#include "DWARFDeclContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066#include "DWARFDIECollection.h"
67#include "DWARFFormValue.h"
68#include "DWARFLocationList.h"
69#include "LogChannelDWARF.h"
Greg Clayton450e3f32010-10-12 02:24:53 +000070#include "SymbolFileDWARFDebugMap.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000071
72#include <map>
73
Matthew Gardinere81df3b2014-08-26 06:57:23 +000074#include <ctype.h>
75#include <string.h>
76
Greg Clayton62742b12010-11-11 01:09:45 +000077//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
Greg Claytonc93237c2010-10-01 20:48:32 +000078
79#ifdef ENABLE_DEBUG_PRINTF
80#include <stdio.h>
Ed Mastea0191d12013-10-17 20:42:56 +000081#define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__)
Greg Claytonc93237c2010-10-01 20:48:32 +000082#else
83#define DEBUG_PRINTF(fmt, ...)
84#endif
85
Greg Clayton594e5ed2010-09-27 21:07:38 +000086#define DIE_IS_BEING_PARSED ((lldb_private::Type*)1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000087
88using namespace lldb;
89using namespace lldb_private;
90
Greg Clayton219cf312012-03-30 00:51:13 +000091//static inline bool
92//child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag)
93//{
94// switch (tag)
95// {
96// default:
97// break;
98// case DW_TAG_subprogram:
99// case DW_TAG_inlined_subroutine:
100// case DW_TAG_class_type:
101// case DW_TAG_structure_type:
102// case DW_TAG_union_type:
103// return true;
104// }
105// return false;
106//}
107//
Sean Callananc7fbf732010-08-06 00:32:49 +0000108static AccessType
Greg Clayton8cf05932010-07-22 18:30:50 +0000109DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000110{
111 switch (dwarf_accessibility)
112 {
Sean Callananc7fbf732010-08-06 00:32:49 +0000113 case DW_ACCESS_public: return eAccessPublic;
114 case DW_ACCESS_private: return eAccessPrivate;
115 case DW_ACCESS_protected: return eAccessProtected;
Greg Clayton8cf05932010-07-22 18:30:50 +0000116 default: break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000117 }
Sean Callananc7fbf732010-08-06 00:32:49 +0000118 return eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000119}
120
Matthew Gardinere81df3b2014-08-26 06:57:23 +0000121static const char*
122removeHostnameFromPathname(const char* path_from_dwarf)
123{
124 if (!path_from_dwarf || !path_from_dwarf[0])
125 {
126 return path_from_dwarf;
127 }
128
129 const char *colon_pos = strchr(path_from_dwarf, ':');
130 if (!colon_pos)
131 {
132 return path_from_dwarf;
133 }
134
135 // check whether we have a windows path, and so the first character
136 // is a drive-letter not a hostname.
137 if (
138 colon_pos == path_from_dwarf + 1 &&
139 isalpha(*path_from_dwarf) &&
140 strlen(path_from_dwarf) > 2 &&
141 '\\' == path_from_dwarf[2])
142 {
143 return path_from_dwarf;
144 }
145
146 return colon_pos + 1;
147}
148
Todd Fiala0a70a842014-05-28 16:43:26 +0000149#if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE)
Greg Clayton1fba87112012-02-09 20:03:49 +0000150
151class DIEStack
152{
153public:
154
155 void Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
156 {
157 m_dies.push_back (DIEInfo(cu, die));
158 }
159
160
161 void LogDIEs (Log *log, SymbolFileDWARF *dwarf)
162 {
163 StreamString log_strm;
164 const size_t n = m_dies.size();
Daniel Malead01b2952012-11-29 21:49:15 +0000165 log_strm.Printf("DIEStack[%" PRIu64 "]:\n", (uint64_t)n);
Greg Clayton1fba87112012-02-09 20:03:49 +0000166 for (size_t i=0; i<n; i++)
167 {
168 DWARFCompileUnit *cu = m_dies[i].cu;
169 const DWARFDebugInfoEntry *die = m_dies[i].die;
170 std::string qualified_name;
171 die->GetQualifiedName(dwarf, cu, qualified_name);
Daniel Malead01b2952012-11-29 21:49:15 +0000172 log_strm.Printf ("[%" PRIu64 "] 0x%8.8x: %s name='%s'\n",
Greg Clayton43e0af02012-09-18 18:04:04 +0000173 (uint64_t)i,
Greg Clayton1fba87112012-02-09 20:03:49 +0000174 die->GetOffset(),
175 DW_TAG_value_to_name(die->Tag()),
176 qualified_name.c_str());
177 }
178 log->PutCString(log_strm.GetData());
179 }
180 void Pop ()
181 {
182 m_dies.pop_back();
183 }
184
185 class ScopedPopper
186 {
187 public:
188 ScopedPopper (DIEStack &die_stack) :
189 m_die_stack (die_stack),
190 m_valid (false)
191 {
192 }
193
194 void
195 Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
196 {
197 m_valid = true;
198 m_die_stack.Push (cu, die);
199 }
200
201 ~ScopedPopper ()
202 {
203 if (m_valid)
204 m_die_stack.Pop();
205 }
206
207
208
209 protected:
210 DIEStack &m_die_stack;
211 bool m_valid;
212 };
213
214protected:
215 struct DIEInfo {
216 DIEInfo (DWARFCompileUnit *c, const DWARFDebugInfoEntry *d) :
217 cu(c),
218 die(d)
219 {
220 }
221 DWARFCompileUnit *cu;
222 const DWARFDebugInfoEntry *die;
223 };
224 typedef std::vector<DIEInfo> Stack;
225 Stack m_dies;
226};
227#endif
228
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000229void
230SymbolFileDWARF::Initialize()
231{
232 LogChannelDWARF::Initialize();
233 PluginManager::RegisterPlugin (GetPluginNameStatic(),
234 GetPluginDescriptionStatic(),
235 CreateInstance);
236}
237
238void
239SymbolFileDWARF::Terminate()
240{
241 PluginManager::UnregisterPlugin (CreateInstance);
242 LogChannelDWARF::Initialize();
243}
244
245
Greg Clayton57abc5d2013-05-10 21:47:16 +0000246lldb_private::ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000247SymbolFileDWARF::GetPluginNameStatic()
248{
Greg Clayton57abc5d2013-05-10 21:47:16 +0000249 static ConstString g_name("dwarf");
250 return g_name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000251}
252
253const char *
254SymbolFileDWARF::GetPluginDescriptionStatic()
255{
256 return "DWARF and DWARF3 debug symbol file reader.";
257}
258
259
260SymbolFile*
261SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
262{
263 return new SymbolFileDWARF(obj_file);
264}
265
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000266TypeList *
267SymbolFileDWARF::GetTypeList ()
268{
Greg Clayton1f746072012-08-29 21:13:06 +0000269 if (GetDebugMapSymfile ())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000270 return m_debug_map_symfile->GetTypeList();
271 return m_obj_file->GetModule()->GetTypeList();
272
273}
Greg Claytonf02500c2013-06-18 22:51:05 +0000274void
275SymbolFileDWARF::GetTypes (DWARFCompileUnit* cu,
276 const DWARFDebugInfoEntry *die,
277 dw_offset_t min_die_offset,
278 dw_offset_t max_die_offset,
279 uint32_t type_mask,
280 TypeSet &type_set)
281{
282 if (cu)
283 {
284 if (die)
285 {
286 const dw_offset_t die_offset = die->GetOffset();
287
288 if (die_offset >= max_die_offset)
289 return;
290
291 if (die_offset >= min_die_offset)
292 {
293 const dw_tag_t tag = die->Tag();
294
295 bool add_type = false;
296
297 switch (tag)
298 {
299 case DW_TAG_array_type: add_type = (type_mask & eTypeClassArray ) != 0; break;
300 case DW_TAG_unspecified_type:
301 case DW_TAG_base_type: add_type = (type_mask & eTypeClassBuiltin ) != 0; break;
302 case DW_TAG_class_type: add_type = (type_mask & eTypeClassClass ) != 0; break;
303 case DW_TAG_structure_type: add_type = (type_mask & eTypeClassStruct ) != 0; break;
304 case DW_TAG_union_type: add_type = (type_mask & eTypeClassUnion ) != 0; break;
305 case DW_TAG_enumeration_type: add_type = (type_mask & eTypeClassEnumeration ) != 0; break;
306 case DW_TAG_subroutine_type:
307 case DW_TAG_subprogram:
308 case DW_TAG_inlined_subroutine: add_type = (type_mask & eTypeClassFunction ) != 0; break;
309 case DW_TAG_pointer_type: add_type = (type_mask & eTypeClassPointer ) != 0; break;
310 case DW_TAG_rvalue_reference_type:
311 case DW_TAG_reference_type: add_type = (type_mask & eTypeClassReference ) != 0; break;
312 case DW_TAG_typedef: add_type = (type_mask & eTypeClassTypedef ) != 0; break;
313 case DW_TAG_ptr_to_member_type: add_type = (type_mask & eTypeClassMemberPointer ) != 0; break;
314 }
315
316 if (add_type)
317 {
318 const bool assert_not_being_parsed = true;
319 Type *type = ResolveTypeUID (cu, die, assert_not_being_parsed);
320 if (type)
321 {
322 if (type_set.find(type) == type_set.end())
323 type_set.insert(type);
324 }
325 }
326 }
327
328 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild();
329 child_die != NULL;
330 child_die = child_die->GetSibling())
331 {
332 GetTypes (cu, child_die, min_die_offset, max_die_offset, type_mask, type_set);
333 }
334 }
335 }
336}
337
338size_t
339SymbolFileDWARF::GetTypes (SymbolContextScope *sc_scope,
340 uint32_t type_mask,
341 TypeList &type_list)
342
343{
344 TypeSet type_set;
345
346 CompileUnit *comp_unit = NULL;
347 DWARFCompileUnit* dwarf_cu = NULL;
348 if (sc_scope)
349 comp_unit = sc_scope->CalculateSymbolContextCompileUnit();
350
351 if (comp_unit)
352 {
353 dwarf_cu = GetDWARFCompileUnit(comp_unit);
354 if (dwarf_cu == 0)
355 return 0;
356 GetTypes (dwarf_cu,
357 dwarf_cu->DIE(),
358 dwarf_cu->GetOffset(),
359 dwarf_cu->GetNextCompileUnitOffset(),
360 type_mask,
361 type_set);
362 }
363 else
364 {
365 DWARFDebugInfo* info = DebugInfo();
366 if (info)
367 {
368 const size_t num_cus = info->GetNumCompileUnits();
369 for (size_t cu_idx=0; cu_idx<num_cus; ++cu_idx)
370 {
371 dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
372 if (dwarf_cu)
373 {
374 GetTypes (dwarf_cu,
375 dwarf_cu->DIE(),
376 0,
377 UINT32_MAX,
378 type_mask,
379 type_set);
380 }
381 }
382 }
383 }
384// if (m_using_apple_tables)
385// {
386// DWARFMappedHash::MemoryTable *apple_types = m_apple_types_ap.get();
387// if (apple_types)
388// {
389// apple_types->ForEach([this, &type_set, apple_types, type_mask](const DWARFMappedHash::DIEInfoArray &die_info_array) -> bool {
390//
391// for (auto die_info: die_info_array)
392// {
393// bool add_type = TagMatchesTypeMask (type_mask, 0);
394// if (!add_type)
395// {
396// dw_tag_t tag = die_info.tag;
397// if (tag == 0)
398// {
399// const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_info.offset, NULL);
400// tag = die->Tag();
401// }
402// add_type = TagMatchesTypeMask (type_mask, tag);
403// }
404// if (add_type)
405// {
406// Type *type = ResolveTypeUID(die_info.offset);
407//
408// if (type_set.find(type) == type_set.end())
409// type_set.insert(type);
410// }
411// }
412// return true; // Keep iterating
413// });
414// }
415// }
416// else
417// {
418// if (!m_indexed)
419// Index ();
420//
421// m_type_index.ForEach([this, &type_set, type_mask](const char *name, uint32_t die_offset) -> bool {
422//
423// bool add_type = TagMatchesTypeMask (type_mask, 0);
424//
425// if (!add_type)
426// {
427// const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_offset, NULL);
428// if (die)
429// {
430// const dw_tag_t tag = die->Tag();
431// add_type = TagMatchesTypeMask (type_mask, tag);
432// }
433// }
434//
435// if (add_type)
436// {
437// Type *type = ResolveTypeUID(die_offset);
438//
439// if (type_set.find(type) == type_set.end())
440// type_set.insert(type);
441// }
442// return true; // Keep iterating
443// });
444// }
445
Greg Clayton57ee3062013-07-11 22:46:58 +0000446 std::set<ClangASTType> clang_type_set;
Greg Claytonf02500c2013-06-18 22:51:05 +0000447 size_t num_types_added = 0;
448 for (Type *type : type_set)
449 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000450 ClangASTType clang_type = type->GetClangForwardType();
Greg Clayton0fc4f312013-06-20 01:23:18 +0000451 if (clang_type_set.find(clang_type) == clang_type_set.end())
452 {
453 clang_type_set.insert(clang_type);
454 type_list.Insert (type->shared_from_this());
455 ++num_types_added;
456 }
Greg Claytonf02500c2013-06-18 22:51:05 +0000457 }
458 return num_types_added;
459}
460
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000461
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000462//----------------------------------------------------------------------
463// Gets the first parent that is a lexical block, function or inlined
464// subroutine, or compile unit.
465//----------------------------------------------------------------------
466static const DWARFDebugInfoEntry *
467GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
468{
469 const DWARFDebugInfoEntry *die;
470 for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
471 {
472 dw_tag_t tag = die->Tag();
473
474 switch (tag)
475 {
476 case DW_TAG_compile_unit:
477 case DW_TAG_subprogram:
478 case DW_TAG_inlined_subroutine:
479 case DW_TAG_lexical_block:
480 return die;
481 }
482 }
483 return NULL;
484}
485
486
Greg Clayton450e3f32010-10-12 02:24:53 +0000487SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
488 SymbolFile (objfile),
Greg Clayton81c22f62011-10-19 18:09:39 +0000489 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 +0000490 m_debug_map_module_wp (),
Greg Clayton450e3f32010-10-12 02:24:53 +0000491 m_debug_map_symfile (NULL),
Greg Clayton7a345282010-11-09 23:46:37 +0000492 m_clang_tu_decl (NULL),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000493 m_flags(),
Greg Claytond4a2b372011-09-12 23:21:58 +0000494 m_data_debug_abbrev (),
495 m_data_debug_aranges (),
496 m_data_debug_frame (),
497 m_data_debug_info (),
498 m_data_debug_line (),
499 m_data_debug_loc (),
500 m_data_debug_ranges (),
501 m_data_debug_str (),
Greg Clayton17674402011-09-28 17:06:40 +0000502 m_data_apple_names (),
503 m_data_apple_types (),
Greg Clayton7f995132011-10-04 22:41:51 +0000504 m_data_apple_namespaces (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000505 m_abbr(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000506 m_info(),
507 m_line(),
Greg Clayton7f995132011-10-04 22:41:51 +0000508 m_apple_names_ap (),
509 m_apple_types_ap (),
510 m_apple_namespaces_ap (),
Greg Clayton5009f9d2011-10-27 17:55:14 +0000511 m_apple_objc_ap (),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000512 m_function_basename_index(),
513 m_function_fullname_index(),
514 m_function_method_index(),
515 m_function_selector_index(),
Greg Clayton450e3f32010-10-12 02:24:53 +0000516 m_objc_class_selectors_index(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000517 m_global_index(),
Greg Clayton69b04882010-10-15 02:03:22 +0000518 m_type_index(),
519 m_namespace_index(),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000520 m_indexed (false),
521 m_is_external_ast_source (false),
Greg Clayton97fbc342011-10-20 22:30:33 +0000522 m_using_apple_tables (false),
Sean Callananf0c5aeb2015-04-20 16:31:29 +0000523 m_fetched_external_modules (false),
Greg Claytonc7f03b62012-01-12 04:33:28 +0000524 m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +0000525 m_ranges(),
526 m_unique_ast_type_map ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000527{
528}
529
530SymbolFileDWARF::~SymbolFileDWARF()
531{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000532 if (m_is_external_ast_source)
Greg Claytone72dfb32012-02-24 01:59:29 +0000533 {
534 ModuleSP module_sp (m_obj_file->GetModule());
535 if (module_sp)
536 module_sp->GetClangASTContext().RemoveExternalSource ();
537 }
Greg Clayton6beaaa62011-01-17 03:46:26 +0000538}
539
540static const ConstString &
541GetDWARFMachOSegmentName ()
542{
543 static ConstString g_dwarf_section_name ("__DWARF");
544 return g_dwarf_section_name;
545}
546
Greg Claytone576ab22011-02-15 00:19:15 +0000547UniqueDWARFASTTypeMap &
548SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
549{
Greg Clayton1f746072012-08-29 21:13:06 +0000550 if (GetDebugMapSymfile ())
Greg Claytone576ab22011-02-15 00:19:15 +0000551 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
552 return m_unique_ast_type_map;
553}
554
Greg Clayton6beaaa62011-01-17 03:46:26 +0000555ClangASTContext &
556SymbolFileDWARF::GetClangASTContext ()
557{
Greg Clayton1f746072012-08-29 21:13:06 +0000558 if (GetDebugMapSymfile ())
Greg Clayton6beaaa62011-01-17 03:46:26 +0000559 return m_debug_map_symfile->GetClangASTContext ();
560
561 ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext();
562 if (!m_is_external_ast_source)
563 {
564 m_is_external_ast_source = true;
Todd Fiala955fe6f2014-02-27 17:18:23 +0000565 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source_ap (
Greg Clayton6beaaa62011-01-17 03:46:26 +0000566 new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl,
567 SymbolFileDWARF::CompleteObjCInterfaceDecl,
Greg Claytona2721472011-06-25 00:44:06 +0000568 SymbolFileDWARF::FindExternalVisibleDeclsByName,
Greg Claytoncaab74e2012-01-28 00:48:57 +0000569 SymbolFileDWARF::LayoutRecordType,
Greg Clayton6beaaa62011-01-17 03:46:26 +0000570 this));
Greg Clayton6beaaa62011-01-17 03:46:26 +0000571 ast.SetExternalSource (ast_source_ap);
572 }
573 return ast;
574}
575
576void
577SymbolFileDWARF::InitializeObject()
578{
579 // Install our external AST source callbacks so we can complete Clang types.
Greg Claytone72dfb32012-02-24 01:59:29 +0000580 ModuleSP module_sp (m_obj_file->GetModule());
581 if (module_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +0000582 {
Greg Clayton3046e662013-07-10 01:23:25 +0000583 const SectionList *section_list = module_sp->GetSectionList();
Greg Clayton6beaaa62011-01-17 03:46:26 +0000584
585 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
586
587 // Memory map the DWARF mach-o segment so we have everything mmap'ed
588 // to keep our heap memory usage down.
589 if (section)
Greg Claytonc9660542012-02-05 02:38:54 +0000590 m_obj_file->MemoryMapSectionData(section, m_dwarf_data);
Greg Clayton6beaaa62011-01-17 03:46:26 +0000591 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000592 get_apple_names_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000593 if (m_data_apple_names.GetByteSize() > 0)
594 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000595 m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names"));
596 if (m_apple_names_ap->IsValid())
597 m_using_apple_tables = true;
598 else
Greg Clayton7f995132011-10-04 22:41:51 +0000599 m_apple_names_ap.reset();
600 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000601 get_apple_types_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000602 if (m_data_apple_types.GetByteSize() > 0)
603 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000604 m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types"));
605 if (m_apple_types_ap->IsValid())
606 m_using_apple_tables = true;
607 else
Greg Clayton7f995132011-10-04 22:41:51 +0000608 m_apple_types_ap.reset();
609 }
610
611 get_apple_namespaces_data();
612 if (m_data_apple_namespaces.GetByteSize() > 0)
613 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000614 m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces"));
615 if (m_apple_namespaces_ap->IsValid())
616 m_using_apple_tables = true;
617 else
Greg Clayton7f995132011-10-04 22:41:51 +0000618 m_apple_namespaces_ap.reset();
619 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000620
Greg Clayton5009f9d2011-10-27 17:55:14 +0000621 get_apple_objc_data();
622 if (m_data_apple_objc.GetByteSize() > 0)
623 {
624 m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc"));
625 if (m_apple_objc_ap->IsValid())
626 m_using_apple_tables = true;
627 else
628 m_apple_objc_ap.reset();
629 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000630}
631
632bool
633SymbolFileDWARF::SupportedVersion(uint16_t version)
634{
Greg Claytonabcbfe52013-04-04 00:00:36 +0000635 return version == 2 || version == 3 || version == 4;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000636}
637
638uint32_t
Sean Callananbfaf54d2011-12-03 04:38:43 +0000639SymbolFileDWARF::CalculateAbilities ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000640{
641 uint32_t abilities = 0;
642 if (m_obj_file != NULL)
643 {
644 const Section* section = NULL;
645 const SectionList *section_list = m_obj_file->GetSectionList();
646 if (section_list == NULL)
647 return 0;
648
649 uint64_t debug_abbrev_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000650 uint64_t debug_info_file_size = 0;
651 uint64_t debug_line_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000652
Greg Clayton6beaaa62011-01-17 03:46:26 +0000653 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000654
655 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000656 section_list = &section->GetChildren ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000657
Greg Clayton4ceb9982010-07-21 22:54:26 +0000658 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000659 if (section != NULL)
660 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000661 debug_info_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000662
Greg Clayton4ceb9982010-07-21 22:54:26 +0000663 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000664 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000665 debug_abbrev_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000666 else
667 m_flags.Set (flagsGotDebugAbbrevData);
668
Greg Clayton4ceb9982010-07-21 22:54:26 +0000669 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000670 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000671 m_flags.Set (flagsGotDebugArangesData);
672
Greg Clayton4ceb9982010-07-21 22:54:26 +0000673 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000674 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000675 m_flags.Set (flagsGotDebugFrameData);
676
Greg Clayton4ceb9982010-07-21 22:54:26 +0000677 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000678 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000679 debug_line_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000680 else
681 m_flags.Set (flagsGotDebugLineData);
682
Greg Clayton4ceb9982010-07-21 22:54:26 +0000683 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000684 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000685 m_flags.Set (flagsGotDebugLocData);
686
Greg Clayton4ceb9982010-07-21 22:54:26 +0000687 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000688 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000689 m_flags.Set (flagsGotDebugMacInfoData);
690
Greg Clayton4ceb9982010-07-21 22:54:26 +0000691 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000692 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000693 m_flags.Set (flagsGotDebugPubNamesData);
694
Greg Clayton4ceb9982010-07-21 22:54:26 +0000695 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000696 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000697 m_flags.Set (flagsGotDebugPubTypesData);
698
Greg Clayton4ceb9982010-07-21 22:54:26 +0000699 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000700 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000701 m_flags.Set (flagsGotDebugRangesData);
702
Greg Clayton4ceb9982010-07-21 22:54:26 +0000703 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000704 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000705 m_flags.Set (flagsGotDebugStrData);
706 }
Greg Clayton6c596612012-05-18 21:47:20 +0000707 else
708 {
709 const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString();
710 if (symfile_dir_cstr)
711 {
712 if (strcasestr(symfile_dir_cstr, ".dsym"))
713 {
714 if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo)
715 {
716 // We have a dSYM file that didn't have a any debug info.
717 // If the string table has a size of 1, then it was made from
718 // an executable with no debug info, or from an executable that
719 // was stripped.
720 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
721 if (section && section->GetFileSize() == 1)
722 {
723 m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info.");
724 }
725 }
726 }
727 }
728 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000729
730 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
731 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
732
733 if (debug_line_file_size > 0)
734 abilities |= LineTables;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000735 }
736 return abilities;
737}
738
Ed Masteeeae7212013-10-24 20:43:47 +0000739const DWARFDataExtractor&
740SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DWARFDataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000741{
742 if (m_flags.IsClear (got_flag))
743 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000744 ModuleSP module_sp (m_obj_file->GetModule());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000745 m_flags.Set (got_flag);
Greg Clayton3046e662013-07-10 01:23:25 +0000746 const SectionList *section_list = module_sp->GetSectionList();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000747 if (section_list)
748 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000749 SectionSP section_sp (section_list->FindSectionByType(sect_type, true));
750 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000751 {
752 // See if we memory mapped the DWARF segment?
753 if (m_dwarf_data.GetByteSize())
754 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000755 data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000756 }
757 else
758 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000759 if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000760 data.Clear();
761 }
762 }
763 }
764 }
765 return data;
766}
767
Ed Masteeeae7212013-10-24 20:43:47 +0000768const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000769SymbolFileDWARF::get_debug_abbrev_data()
770{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000771 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000772}
773
Ed Masteeeae7212013-10-24 20:43:47 +0000774const DWARFDataExtractor&
Greg Claytond4a2b372011-09-12 23:21:58 +0000775SymbolFileDWARF::get_debug_aranges_data()
776{
777 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
778}
779
Ed Masteeeae7212013-10-24 20:43:47 +0000780const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000781SymbolFileDWARF::get_debug_frame_data()
782{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000783 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000784}
785
Ed Masteeeae7212013-10-24 20:43:47 +0000786const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000787SymbolFileDWARF::get_debug_info_data()
788{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000789 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000790}
791
Ed Masteeeae7212013-10-24 20:43:47 +0000792const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000793SymbolFileDWARF::get_debug_line_data()
794{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000795 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000796}
797
Ed Masteeeae7212013-10-24 20:43:47 +0000798const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000799SymbolFileDWARF::get_debug_loc_data()
800{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000801 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000802}
803
Ed Masteeeae7212013-10-24 20:43:47 +0000804const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000805SymbolFileDWARF::get_debug_ranges_data()
806{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000807 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000808}
809
Ed Masteeeae7212013-10-24 20:43:47 +0000810const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000811SymbolFileDWARF::get_debug_str_data()
812{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000813 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000814}
815
Ed Masteeeae7212013-10-24 20:43:47 +0000816const DWARFDataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000817SymbolFileDWARF::get_apple_names_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000818{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000819 return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names);
Greg Claytonf9eec202011-09-01 23:16:13 +0000820}
821
Ed Masteeeae7212013-10-24 20:43:47 +0000822const DWARFDataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000823SymbolFileDWARF::get_apple_types_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000824{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000825 return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types);
Greg Claytonf9eec202011-09-01 23:16:13 +0000826}
827
Ed Masteeeae7212013-10-24 20:43:47 +0000828const DWARFDataExtractor&
Greg Clayton7f995132011-10-04 22:41:51 +0000829SymbolFileDWARF::get_apple_namespaces_data()
830{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000831 return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
832}
833
Ed Masteeeae7212013-10-24 20:43:47 +0000834const DWARFDataExtractor&
Greg Clayton5009f9d2011-10-27 17:55:14 +0000835SymbolFileDWARF::get_apple_objc_data()
836{
837 return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc);
Greg Clayton7f995132011-10-04 22:41:51 +0000838}
839
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000840
841DWARFDebugAbbrev*
842SymbolFileDWARF::DebugAbbrev()
843{
844 if (m_abbr.get() == NULL)
845 {
Ed Masteeeae7212013-10-24 20:43:47 +0000846 const DWARFDataExtractor &debug_abbrev_data = get_debug_abbrev_data();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000847 if (debug_abbrev_data.GetByteSize() > 0)
848 {
849 m_abbr.reset(new DWARFDebugAbbrev());
850 if (m_abbr.get())
851 m_abbr->Parse(debug_abbrev_data);
852 }
853 }
854 return m_abbr.get();
855}
856
857const DWARFDebugAbbrev*
858SymbolFileDWARF::DebugAbbrev() const
859{
860 return m_abbr.get();
861}
862
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000863
864DWARFDebugInfo*
865SymbolFileDWARF::DebugInfo()
866{
867 if (m_info.get() == NULL)
868 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000869 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p",
870 __PRETTY_FUNCTION__, static_cast<void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000871 if (get_debug_info_data().GetByteSize() > 0)
872 {
873 m_info.reset(new DWARFDebugInfo());
874 if (m_info.get())
875 {
876 m_info->SetDwarfData(this);
877 }
878 }
879 }
880 return m_info.get();
881}
882
883const DWARFDebugInfo*
884SymbolFileDWARF::DebugInfo() const
885{
886 return m_info.get();
887}
888
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000889DWARFCompileUnit*
Greg Clayton1f746072012-08-29 21:13:06 +0000890SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000891{
892 DWARFDebugInfo* info = DebugInfo();
Greg Clayton1f746072012-08-29 21:13:06 +0000893 if (info)
894 {
895 if (GetDebugMapSymfile ())
896 {
897 // The debug map symbol file made the compile units for this DWARF
898 // file which is .o file with DWARF in it, and we should have
899 // only 1 compile unit which is at offset zero in the DWARF.
900 // TODO: modify to support LTO .o files where each .o file might
901 // have multiple DW_TAG_compile_unit tags.
Greg Clayton68c00bd2015-02-05 02:10:29 +0000902
903 DWARFCompileUnit *dwarf_cu = info->GetCompileUnit(0).get();
904 if (dwarf_cu && dwarf_cu->GetUserData() == NULL)
905 dwarf_cu->SetUserData(comp_unit);
906 return dwarf_cu;
Greg Clayton1f746072012-08-29 21:13:06 +0000907 }
908 else
909 {
910 // Just a normal DWARF file whose user ID for the compile unit is
911 // the DWARF offset itself
Greg Clayton68c00bd2015-02-05 02:10:29 +0000912
913 DWARFCompileUnit *dwarf_cu = info->GetCompileUnit((dw_offset_t)comp_unit->GetID()).get();
914 if (dwarf_cu && dwarf_cu->GetUserData() == NULL)
915 dwarf_cu->SetUserData(comp_unit);
916 return dwarf_cu;
917
Greg Clayton1f746072012-08-29 21:13:06 +0000918 }
919 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000920 return NULL;
921}
922
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000923
924DWARFDebugRanges*
925SymbolFileDWARF::DebugRanges()
926{
927 if (m_ranges.get() == NULL)
928 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000929 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p",
930 __PRETTY_FUNCTION__, static_cast<void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000931 if (get_debug_ranges_data().GetByteSize() > 0)
932 {
933 m_ranges.reset(new DWARFDebugRanges());
934 if (m_ranges.get())
935 m_ranges->Extract(this);
936 }
937 }
938 return m_ranges.get();
939}
940
941const DWARFDebugRanges*
942SymbolFileDWARF::DebugRanges() const
943{
944 return m_ranges.get();
945}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000946
Greg Clayton53eb1c22012-04-02 22:59:12 +0000947lldb::CompUnitSP
948SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000949{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000950 CompUnitSP cu_sp;
951 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000952 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000953 CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData();
954 if (comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000955 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000956 // We already parsed this compile unit, had out a shared pointer to it
957 cu_sp = comp_unit->shared_from_this();
958 }
959 else
960 {
Greg Clayton1f746072012-08-29 21:13:06 +0000961 if (GetDebugMapSymfile ())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000962 {
Greg Clayton1f746072012-08-29 21:13:06 +0000963 // Let the debug map create the compile unit
964 cu_sp = m_debug_map_symfile->GetCompileUnit(this);
965 dwarf_cu->SetUserData(cu_sp.get());
966 }
967 else
968 {
969 ModuleSP module_sp (m_obj_file->GetModule());
970 if (module_sp)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000971 {
Greg Clayton1f746072012-08-29 21:13:06 +0000972 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly ();
973 if (cu_die)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000974 {
Chaoren Lin0c5a9c12015-06-05 00:28:06 +0000975 FileSpec cu_file_spec{cu_die->GetName(this, dwarf_cu), false};
976 if (cu_file_spec)
Greg Clayton1f746072012-08-29 21:13:06 +0000977 {
Chaoren Lin0c5a9c12015-06-05 00:28:06 +0000978 // If we have a full path to the compile unit, we don't need to resolve
979 // the file. This can be expensive e.g. when the source files are NFS mounted.
Chaoren Lin372e9062015-06-09 17:54:27 +0000980 if (cu_file_spec.IsRelative())
Greg Clayton53eb1c22012-04-02 22:59:12 +0000981 {
Matthew Gardinere81df3b2014-08-26 06:57:23 +0000982 // DWARF2/3 suggests the form hostname:pathname for compilation directory.
983 // Remove the host part if present.
Chaoren Lin0c5a9c12015-06-05 00:28:06 +0000984 const char *cu_comp_dir{cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, nullptr)};
985 cu_file_spec.PrependPathComponent(removeHostnameFromPathname(cu_comp_dir));
Greg Clayton1f746072012-08-29 21:13:06 +0000986 }
987
Chaoren Lin0c5a9c12015-06-05 00:28:06 +0000988 std::string remapped_file;
989 if (module_sp->RemapSourceFile(cu_file_spec.GetCString(), remapped_file))
990 cu_file_spec.SetFile(remapped_file, false);
991
Dawn Perchikd0e87eb2015-06-17 22:30:24 +0000992 LanguageType cu_language = DWARFCompileUnit::LanguageTypeFromDWARF(cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0));
Chaoren Lin0c5a9c12015-06-05 00:28:06 +0000993
Greg Clayton1f746072012-08-29 21:13:06 +0000994 cu_sp.reset(new CompileUnit (module_sp,
995 dwarf_cu,
996 cu_file_spec,
997 MakeUserID(dwarf_cu->GetOffset()),
998 cu_language));
999 if (cu_sp)
1000 {
1001 dwarf_cu->SetUserData(cu_sp.get());
1002
Greg Clayton53eb1c22012-04-02 22:59:12 +00001003 // Figure out the compile unit index if we weren't given one
1004 if (cu_idx == UINT32_MAX)
1005 DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx);
1006
1007 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp);
1008 }
1009 }
1010 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001011 }
1012 }
1013 }
1014 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00001015 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001016}
1017
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001018uint32_t
1019SymbolFileDWARF::GetNumCompileUnits()
1020{
1021 DWARFDebugInfo* info = DebugInfo();
1022 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001023 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001024 return 0;
1025}
1026
1027CompUnitSP
1028SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
1029{
Greg Clayton53eb1c22012-04-02 22:59:12 +00001030 CompUnitSP cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001031 DWARFDebugInfo* info = DebugInfo();
1032 if (info)
1033 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00001034 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
1035 if (dwarf_cu)
1036 cu_sp = ParseCompileUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001037 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00001038 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001039}
1040
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001041Function *
Greg Clayton0fffff52010-09-24 05:15:53 +00001042SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001043{
1044 DWARFDebugRanges::RangeList func_ranges;
1045 const char *name = NULL;
1046 const char *mangled = NULL;
1047 int decl_file = 0;
1048 int decl_line = 0;
1049 int decl_column = 0;
1050 int call_file = 0;
1051 int call_line = 0;
1052 int call_column = 0;
1053 DWARFExpression frame_base;
1054
Greg Claytonc93237c2010-10-01 20:48:32 +00001055 assert (die->Tag() == DW_TAG_subprogram);
1056
1057 if (die->Tag() != DW_TAG_subprogram)
1058 return NULL;
1059
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001060 if (die->GetDIENamesAndRanges (this,
1061 dwarf_cu,
1062 name,
1063 mangled,
1064 func_ranges,
1065 decl_file,
1066 decl_line,
1067 decl_column,
1068 call_file,
1069 call_line,
1070 call_column,
1071 &frame_base))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001072 {
1073 // Union of all ranges in the function DIE (if the function is discontiguous)
1074 AddressRange func_range;
Greg Claytonea3e7d52011-10-08 00:49:15 +00001075 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0);
1076 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001077 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
1078 {
Michael Sartaina7499c92013-07-01 19:45:50 +00001079 ModuleSP module_sp (m_obj_file->GetModule());
Greg Clayton3046e662013-07-10 01:23:25 +00001080 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, module_sp->GetSectionList());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001081 if (func_range.GetBaseAddress().IsValid())
1082 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
1083 }
1084
1085 if (func_range.GetBaseAddress().IsValid())
1086 {
1087 Mangled func_name;
1088 if (mangled)
Greg Clayton037520e2012-07-18 23:18:10 +00001089 func_name.SetValue(ConstString(mangled), true);
Siva Chandra462722d2015-03-27 00:10:04 +00001090 else if (die->GetParent()->Tag() == DW_TAG_compile_unit &&
1091 LanguageRuntime::LanguageIsCPlusPlus(dwarf_cu->GetLanguageType()) &&
Greg Clayton94380562015-05-15 22:20:29 +00001092 name && strcmp(name, "main") != 0)
Siva Chandra462722d2015-03-27 00:10:04 +00001093 {
1094 // If the mangled name is not present in the DWARF, generate the demangled name
1095 // using the decl context. We skip if the function is "main" as its name is
1096 // never mangled.
1097 bool is_static = false;
1098 bool is_variadic = false;
1099 unsigned type_quals = 0;
1100 std::vector<ClangASTType> param_types;
1101 std::vector<clang::ParmVarDecl*> param_decls;
1102 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
1103 DWARFDeclContext decl_ctx;
1104 StreamString sstr;
1105
1106 die->GetDWARFDeclContext(this, dwarf_cu, decl_ctx);
1107 sstr << decl_ctx.GetQualifiedName();
1108
1109 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE(dwarf_cu,
1110 die,
1111 &decl_ctx_die);
1112 ParseChildParameters(sc,
1113 containing_decl_ctx,
1114 dwarf_cu,
1115 die,
1116 true,
1117 is_static,
1118 is_variadic,
1119 param_types,
1120 param_decls,
1121 type_quals);
1122 sstr << "(";
1123 for (size_t i = 0; i < param_types.size(); i++)
1124 {
1125 if (i > 0)
1126 sstr << ", ";
1127 sstr << param_types[i].GetTypeName();
1128 }
1129 if (is_variadic)
1130 sstr << ", ...";
1131 sstr << ")";
1132 if (type_quals & clang::Qualifiers::Const)
1133 sstr << " const";
1134
1135 func_name.SetValue(ConstString(sstr.GetData()), false);
1136 }
1137 else
Greg Clayton037520e2012-07-18 23:18:10 +00001138 func_name.SetValue(ConstString(name), false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001139
1140 FunctionSP func_sp;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001141 std::unique_ptr<Declaration> decl_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001142 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +00001143 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1144 decl_line,
1145 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001146
Greg Clayton0bd4e1b2011-09-30 20:52:25 +00001147 // Supply the type _only_ if it has already been parsed
Greg Clayton594e5ed2010-09-27 21:07:38 +00001148 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001149
1150 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
1151
Greg Clayton9422dd62013-03-04 21:46:16 +00001152 if (FixupAddress (func_range.GetBaseAddress()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001153 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001154 const user_id_t func_user_id = MakeUserID(die->GetOffset());
1155 func_sp.reset(new Function (sc.comp_unit,
1156 MakeUserID(func_user_id), // UserID is the DIE offset
1157 MakeUserID(func_user_id),
1158 func_name,
1159 func_type,
1160 func_range)); // first address range
1161
1162 if (func_sp.get() != NULL)
1163 {
1164 if (frame_base.IsValid())
1165 func_sp->GetFrameBaseExpression() = frame_base;
1166 sc.comp_unit->AddFunction(func_sp);
1167 return func_sp.get();
1168 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001169 }
1170 }
1171 }
1172 return NULL;
1173}
1174
Greg Clayton9422dd62013-03-04 21:46:16 +00001175bool
1176SymbolFileDWARF::FixupAddress (Address &addr)
1177{
1178 SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile ();
1179 if (debug_map_symfile)
1180 {
1181 return debug_map_symfile->LinkOSOAddress(addr);
1182 }
1183 // This is a normal DWARF file, no address fixups need to happen
1184 return true;
1185}
Greg Clayton1f746072012-08-29 21:13:06 +00001186lldb::LanguageType
1187SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc)
1188{
1189 assert (sc.comp_unit);
1190 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1191 if (dwarf_cu)
1192 {
1193 const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly();
Jim Ingham28eb5712012-10-12 17:34:26 +00001194 if (die)
Dawn Perchikd0e87eb2015-06-17 22:30:24 +00001195 return DWARFCompileUnit::LanguageTypeFromDWARF(die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0));
Greg Clayton1f746072012-08-29 21:13:06 +00001196 }
1197 return eLanguageTypeUnknown;
1198}
1199
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001200size_t
1201SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
1202{
1203 assert (sc.comp_unit);
1204 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00001205 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001206 if (dwarf_cu)
1207 {
1208 DWARFDIECollection function_dies;
Greg Clayton1f746072012-08-29 21:13:06 +00001209 const size_t num_functions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001210 size_t func_idx;
Greg Clayton1f746072012-08-29 21:13:06 +00001211 for (func_idx = 0; func_idx < num_functions; ++func_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001212 {
1213 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
Greg Clayton81c22f62011-10-19 18:09:39 +00001214 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001215 {
1216 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
1217 ++functions_added;
1218 }
1219 }
1220 //FixupTypes();
1221 }
1222 return functions_added;
1223}
1224
1225bool
1226SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
1227{
1228 assert (sc.comp_unit);
Greg Clayton1f746072012-08-29 21:13:06 +00001229 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Greg Claytonda2455b2012-11-01 17:28:37 +00001230 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001231 {
Greg Claytonda2455b2012-11-01 17:28:37 +00001232 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001233
Greg Claytonda2455b2012-11-01 17:28:37 +00001234 if (cu_die)
1235 {
1236 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
Matthew Gardinere81df3b2014-08-26 06:57:23 +00001237
1238 // DWARF2/3 suggests the form hostname:pathname for compilation directory.
1239 // Remove the host part if present.
1240 cu_comp_dir = removeHostnameFromPathname(cu_comp_dir);
1241
Greg Claytonda2455b2012-11-01 17:28:37 +00001242 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 +00001243
Greg Claytonda2455b2012-11-01 17:28:37 +00001244 // All file indexes in DWARF are one based and a file of index zero is
1245 // supposed to be the compile unit itself.
1246 support_files.Append (*sc.comp_unit);
1247
1248 return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
1249 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001250 }
1251 return false;
1252}
1253
Sean Callananf0c5aeb2015-04-20 16:31:29 +00001254bool
1255SymbolFileDWARF::ParseImportedModules (const lldb_private::SymbolContext &sc, std::vector<lldb_private::ConstString> &imported_modules)
1256{
1257 assert (sc.comp_unit);
1258 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1259 if (dwarf_cu)
1260 {
1261 if (ClangModulesDeclVendor::LanguageSupportsClangModules(sc.comp_unit->GetLanguage()))
1262 {
1263 UpdateExternalModuleListIfNeeded();
1264 for (const std::pair<uint64_t, const ClangModuleInfo> &external_type_module : m_external_type_modules)
1265 {
1266 imported_modules.push_back(external_type_module.second.m_name);
1267 }
1268 }
1269 }
1270 return false;
1271}
1272
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001273struct ParseDWARFLineTableCallbackInfo
1274{
1275 LineTable* line_table;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001276 std::unique_ptr<LineSequence> sequence_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001277};
1278
1279//----------------------------------------------------------------------
1280// ParseStatementTableCallback
1281//----------------------------------------------------------------------
1282static void
1283ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
1284{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001285 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
1286 {
1287 // Just started parsing the line table
1288 }
1289 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
1290 {
1291 // Done parsing line table, nothing to do for the cleanup
1292 }
1293 else
1294 {
1295 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
Greg Clayton9422dd62013-03-04 21:46:16 +00001296 LineTable* line_table = info->line_table;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001297
Greg Clayton9422dd62013-03-04 21:46:16 +00001298 // If this is our first time here, we need to create a
1299 // sequence container.
1300 if (!info->sequence_ap.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001301 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001302 info->sequence_ap.reset(line_table->CreateLineSequenceContainer());
1303 assert(info->sequence_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001304 }
Greg Clayton9422dd62013-03-04 21:46:16 +00001305 line_table->AppendLineEntryToSequence (info->sequence_ap.get(),
1306 state.address,
1307 state.line,
1308 state.column,
1309 state.file,
1310 state.is_stmt,
1311 state.basic_block,
1312 state.prologue_end,
1313 state.epilogue_begin,
1314 state.end_sequence);
1315 if (state.end_sequence)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001316 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001317 // First, put the current sequence into the line table.
1318 line_table->InsertSequence(info->sequence_ap.get());
1319 // Then, empty it to prepare for the next sequence.
1320 info->sequence_ap->Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001321 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001322 }
1323}
1324
1325bool
1326SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1327{
1328 assert (sc.comp_unit);
1329 if (sc.comp_unit->GetLineTable() != NULL)
1330 return true;
1331
Greg Clayton1f746072012-08-29 21:13:06 +00001332 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001333 if (dwarf_cu)
1334 {
1335 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Greg Clayton129d12c2011-11-28 03:29:03 +00001336 if (dwarf_cu_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001337 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001338 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1339 if (cu_line_offset != DW_INVALID_OFFSET)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001340 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001341 std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
Greg Clayton129d12c2011-11-28 03:29:03 +00001342 if (line_table_ap.get())
1343 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001344 ParseDWARFLineTableCallbackInfo info;
1345 info.line_table = line_table_ap.get();
Greg Claytonc7bece562013-01-25 18:06:21 +00001346 lldb::offset_t offset = cu_line_offset;
Greg Clayton129d12c2011-11-28 03:29:03 +00001347 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
Greg Clayton9422dd62013-03-04 21:46:16 +00001348 if (m_debug_map_symfile)
1349 {
1350 // We have an object file that has a line table with addresses
1351 // that are not linked. We need to link the line table and convert
1352 // the addresses that are relative to the .o file into addresses
1353 // for the main executable.
1354 sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get()));
1355 }
1356 else
1357 {
1358 sc.comp_unit->SetLineTable(line_table_ap.release());
1359 return true;
1360 }
Greg Clayton129d12c2011-11-28 03:29:03 +00001361 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001362 }
1363 }
1364 }
1365 return false;
1366}
1367
1368size_t
1369SymbolFileDWARF::ParseFunctionBlocks
1370(
1371 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001372 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001373 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001374 const DWARFDebugInfoEntry *die,
1375 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001376 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001377)
1378{
1379 size_t blocks_added = 0;
1380 while (die != NULL)
1381 {
1382 dw_tag_t tag = die->Tag();
1383
1384 switch (tag)
1385 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001386 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001387 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001388 case DW_TAG_lexical_block:
1389 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001390 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001391 if (tag == DW_TAG_subprogram)
1392 {
1393 // Skip any DW_TAG_subprogram DIEs that are inside
1394 // of a normal or inlined functions. These will be
1395 // parsed on their own as separate entities.
1396
1397 if (depth > 0)
1398 break;
1399
1400 block = parent_block;
1401 }
1402 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001403 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001404 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001405 parent_block->AddChild(block_sp);
1406 block = block_sp.get();
1407 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001408 DWARFDebugRanges::RangeList ranges;
1409 const char *name = NULL;
1410 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001411
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001412 int decl_file = 0;
1413 int decl_line = 0;
1414 int decl_column = 0;
1415 int call_file = 0;
1416 int call_line = 0;
1417 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001418 if (die->GetDIENamesAndRanges (this,
1419 dwarf_cu,
1420 name,
1421 mangled_name,
1422 ranges,
1423 decl_file, decl_line, decl_column,
1424 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001425 {
1426 if (tag == DW_TAG_subprogram)
1427 {
1428 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001429 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001430 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001431 else if (tag == DW_TAG_inlined_subroutine)
1432 {
1433 // We get called here for inlined subroutines in two ways.
1434 // The first time is when we are making the Function object
1435 // for this inlined concrete instance. Since we're creating a top level block at
1436 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1437 // adjust the containing address.
1438 // The second time is when we are parsing the blocks inside the function that contains
1439 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1440 // function the offset will be for that function.
1441 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1442 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001443 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001444 }
1445 }
Greg Clayton103f3092015-01-15 03:04:37 +00001446
1447 const size_t num_ranges = ranges.GetSize();
1448 for (size_t i = 0; i<num_ranges; ++i)
1449 {
1450 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i);
1451 const addr_t range_base = range.GetRangeBase();
1452 if (range_base >= subprogram_low_pc)
1453 block->AddRange(Block::Range (range_base - subprogram_low_pc, range.GetByteSize()));
1454 else
1455 {
1456 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",
1457 block->GetID(),
1458 range_base,
1459 range.GetRangeEnd(),
1460 subprogram_low_pc);
1461 }
1462 }
1463 block->FinalizeRanges ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001464
1465 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1466 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001467 std::unique_ptr<Declaration> decl_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001468 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001469 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1470 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001471
Greg Clayton7b0992d2013-04-18 22:45:39 +00001472 std::unique_ptr<Declaration> call_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001473 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001474 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1475 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001476
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001477 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001478 }
1479
1480 ++blocks_added;
1481
Greg Claytondd7feaf2011-08-12 17:54:33 +00001482 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001483 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001484 blocks_added += ParseFunctionBlocks (sc,
1485 block,
1486 dwarf_cu,
1487 die->GetFirstChild(),
1488 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001489 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001490 }
1491 }
1492 }
1493 break;
1494 default:
1495 break;
1496 }
1497
Greg Claytondd7feaf2011-08-12 17:54:33 +00001498 // Only parse siblings of the block if we are not at depth zero. A depth
1499 // of zero indicates we are currently parsing the top level
1500 // DW_TAG_subprogram DIE
1501
1502 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001503 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001504 else
1505 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001506 }
1507 return blocks_added;
1508}
1509
Greg Claytonf0705c82011-10-22 03:33:13 +00001510bool
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001511SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu,
1512 const DWARFDebugInfoEntry *die,
1513 ClangASTContext::TemplateParameterInfos &template_param_infos)
1514{
1515 const dw_tag_t tag = die->Tag();
1516
1517 switch (tag)
1518 {
1519 case DW_TAG_template_type_parameter:
1520 case DW_TAG_template_value_parameter:
1521 {
Todd Fialaee8bfc62014-09-11 17:29:12 +00001522 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001523
1524 DWARFDebugInfoEntry::Attributes attributes;
1525 const size_t num_attributes = die->GetAttributes (this,
1526 dwarf_cu,
1527 fixed_form_sizes,
1528 attributes);
1529 const char *name = NULL;
1530 Type *lldb_type = NULL;
Greg Clayton57ee3062013-07-11 22:46:58 +00001531 ClangASTType clang_type;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001532 uint64_t uval64 = 0;
1533 bool uval64_valid = false;
1534 if (num_attributes > 0)
1535 {
1536 DWARFFormValue form_value;
1537 for (size_t i=0; i<num_attributes; ++i)
1538 {
1539 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1540
1541 switch (attr)
1542 {
1543 case DW_AT_name:
1544 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1545 name = form_value.AsCString(&get_debug_str_data());
1546 break;
1547
1548 case DW_AT_type:
1549 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1550 {
Greg Clayton54166af2014-11-22 01:58:59 +00001551 const dw_offset_t type_die_offset = form_value.Reference();
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001552 lldb_type = ResolveTypeUID(type_die_offset);
1553 if (lldb_type)
1554 clang_type = lldb_type->GetClangForwardType();
1555 }
1556 break;
1557
1558 case DW_AT_const_value:
1559 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1560 {
1561 uval64_valid = true;
1562 uval64 = form_value.Unsigned();
1563 }
1564 break;
1565 default:
1566 break;
1567 }
1568 }
1569
Greg Clayton283b2652013-04-23 22:38:02 +00001570 clang::ASTContext *ast = GetClangASTContext().getASTContext();
1571 if (!clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00001572 clang_type = GetClangASTContext().GetBasicType(eBasicTypeVoid);
Greg Clayton283b2652013-04-23 22:38:02 +00001573
1574 if (clang_type)
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001575 {
1576 bool is_signed = false;
Greg Clayton283b2652013-04-23 22:38:02 +00001577 if (name && name[0])
1578 template_param_infos.names.push_back(name);
1579 else
1580 template_param_infos.names.push_back(NULL);
1581
Greg Clayton283b2652013-04-23 22:38:02 +00001582 if (tag == DW_TAG_template_value_parameter &&
1583 lldb_type != NULL &&
Greg Clayton57ee3062013-07-11 22:46:58 +00001584 clang_type.IsIntegerType (is_signed) &&
Greg Clayton283b2652013-04-23 22:38:02 +00001585 uval64_valid)
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001586 {
1587 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
Greg Clayton283b2652013-04-23 22:38:02 +00001588 template_param_infos.args.push_back (clang::TemplateArgument (*ast,
Sean Callanan3d654b32012-09-24 22:25:51 +00001589 llvm::APSInt(apint),
Pavel Labathc7c30eb2015-06-08 23:38:06 +00001590 clang_type.GetQualType()));
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001591 }
1592 else
1593 {
Pavel Labathc7c30eb2015-06-08 23:38:06 +00001594 template_param_infos.args.push_back (clang::TemplateArgument (clang_type.GetQualType()));
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001595 }
1596 }
1597 else
1598 {
1599 return false;
1600 }
1601
1602 }
1603 }
1604 return true;
1605
1606 default:
1607 break;
1608 }
1609 return false;
1610}
1611
1612bool
Greg Claytonf0705c82011-10-22 03:33:13 +00001613SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1614 const DWARFDebugInfoEntry *parent_die,
1615 ClangASTContext::TemplateParameterInfos &template_param_infos)
1616{
1617
1618 if (parent_die == NULL)
Filipe Cabecinhas52008c62012-05-23 16:24:11 +00001619 return false;
Greg Claytonf0705c82011-10-22 03:33:13 +00001620
Greg Claytonf0705c82011-10-22 03:33:13 +00001621 Args template_parameter_names;
1622 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1623 die != NULL;
1624 die = die->GetSibling())
1625 {
1626 const dw_tag_t tag = die->Tag();
1627
1628 switch (tag)
1629 {
1630 case DW_TAG_template_type_parameter:
1631 case DW_TAG_template_value_parameter:
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001632 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Claytonf0705c82011-10-22 03:33:13 +00001633 break;
1634
1635 default:
1636 break;
1637 }
1638 }
1639 if (template_param_infos.args.empty())
1640 return false;
1641 return template_param_infos.args.size() == template_param_infos.names.size();
1642}
1643
1644clang::ClassTemplateDecl *
1645SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001646 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001647 const char *parent_name,
1648 int tag_decl_kind,
1649 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1650{
1651 if (template_param_infos.IsValid())
1652 {
1653 std::string template_basename(parent_name);
1654 template_basename.erase (template_basename.find('<'));
1655 ClangASTContext &ast = GetClangASTContext();
1656
1657 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001658 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001659 template_basename.c_str(),
1660 tag_decl_kind,
1661 template_param_infos);
1662 }
1663 return NULL;
1664}
1665
Sean Callanana0b80ab2012-06-04 22:28:05 +00001666class SymbolFileDWARF::DelayedAddObjCClassProperty
1667{
1668public:
1669 DelayedAddObjCClassProperty
1670 (
Greg Clayton57ee3062013-07-11 22:46:58 +00001671 const ClangASTType &class_opaque_type,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001672 const char *property_name,
Greg Clayton57ee3062013-07-11 22:46:58 +00001673 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 +00001674 clang::ObjCIvarDecl *ivar_decl,
1675 const char *property_setter_name,
1676 const char *property_getter_name,
1677 uint32_t property_attributes,
Greg Claytonc4ffd662013-03-08 01:37:30 +00001678 const ClangASTMetadata *metadata
Sean Callanana0b80ab2012-06-04 22:28:05 +00001679 ) :
Sean Callanana0b80ab2012-06-04 22:28:05 +00001680 m_class_opaque_type (class_opaque_type),
1681 m_property_name (property_name),
1682 m_property_opaque_type (property_opaque_type),
1683 m_ivar_decl (ivar_decl),
1684 m_property_setter_name (property_setter_name),
1685 m_property_getter_name (property_getter_name),
Jim Ingham379397632012-10-27 02:54:13 +00001686 m_property_attributes (property_attributes)
Sean Callanana0b80ab2012-06-04 22:28:05 +00001687 {
Jim Ingham379397632012-10-27 02:54:13 +00001688 if (metadata != NULL)
1689 {
1690 m_metadata_ap.reset(new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001691 *m_metadata_ap = *metadata;
Jim Ingham379397632012-10-27 02:54:13 +00001692 }
1693 }
1694
1695 DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs)
1696 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001697 *this = rhs;
Daniel Malead4c5be62012-11-12 21:02:14 +00001698 }
1699
1700 DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs)
1701 {
Jim Ingham379397632012-10-27 02:54:13 +00001702 m_class_opaque_type = rhs.m_class_opaque_type;
1703 m_property_name = rhs.m_property_name;
1704 m_property_opaque_type = rhs.m_property_opaque_type;
1705 m_ivar_decl = rhs.m_ivar_decl;
1706 m_property_setter_name = rhs.m_property_setter_name;
1707 m_property_getter_name = rhs.m_property_getter_name;
1708 m_property_attributes = rhs.m_property_attributes;
1709
1710 if (rhs.m_metadata_ap.get())
1711 {
1712 m_metadata_ap.reset (new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001713 *m_metadata_ap = *rhs.m_metadata_ap;
Jim Ingham379397632012-10-27 02:54:13 +00001714 }
Daniel Malead4c5be62012-11-12 21:02:14 +00001715 return *this;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001716 }
1717
Greg Clayton57ee3062013-07-11 22:46:58 +00001718 bool
1719 Finalize()
Sean Callanana0b80ab2012-06-04 22:28:05 +00001720 {
Pavel Labathc7c30eb2015-06-08 23:38:06 +00001721 return m_class_opaque_type.AddObjCClassProperty (m_property_name,
1722 m_property_opaque_type,
1723 m_ivar_decl,
1724 m_property_setter_name,
1725 m_property_getter_name,
1726 m_property_attributes,
1727 m_metadata_ap.get());
Sean Callanana0b80ab2012-06-04 22:28:05 +00001728 }
1729private:
Greg Clayton57ee3062013-07-11 22:46:58 +00001730 ClangASTType m_class_opaque_type;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001731 const char *m_property_name;
Greg Clayton57ee3062013-07-11 22:46:58 +00001732 ClangASTType m_property_opaque_type;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001733 clang::ObjCIvarDecl *m_ivar_decl;
1734 const char *m_property_setter_name;
1735 const char *m_property_getter_name;
1736 uint32_t m_property_attributes;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001737 std::unique_ptr<ClangASTMetadata> m_metadata_ap;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001738};
1739
Sean Callananfaa0bb32012-12-05 23:37:14 +00001740struct BitfieldInfo
1741{
1742 uint64_t bit_size;
1743 uint64_t bit_offset;
1744
1745 BitfieldInfo () :
1746 bit_size (LLDB_INVALID_ADDRESS),
1747 bit_offset (LLDB_INVALID_ADDRESS)
1748 {
1749 }
1750
Greg Clayton78f4d952013-12-11 23:10:39 +00001751 void
1752 Clear()
1753 {
1754 bit_size = LLDB_INVALID_ADDRESS;
1755 bit_offset = LLDB_INVALID_ADDRESS;
1756 }
1757
Sean Callananfaa0bb32012-12-05 23:37:14 +00001758 bool IsValid ()
1759 {
1760 return (bit_size != LLDB_INVALID_ADDRESS) &&
1761 (bit_offset != LLDB_INVALID_ADDRESS);
1762 }
1763};
1764
Greg Claytonc4ffd662013-03-08 01:37:30 +00001765
1766bool
1767SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu,
1768 const DWARFDebugInfoEntry *parent_die)
1769{
1770 if (parent_die)
1771 {
1772 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1773 {
1774 dw_tag_t tag = die->Tag();
1775 bool check_virtuality = false;
1776 switch (tag)
1777 {
1778 case DW_TAG_inheritance:
1779 case DW_TAG_subprogram:
1780 check_virtuality = true;
1781 break;
1782 default:
1783 break;
1784 }
1785 if (check_virtuality)
1786 {
1787 if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0)
1788 return true;
1789 }
1790 }
1791 }
1792 return false;
1793}
1794
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001795size_t
1796SymbolFileDWARF::ParseChildMembers
1797(
1798 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001799 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001800 const DWARFDebugInfoEntry *parent_die,
Greg Clayton57ee3062013-07-11 22:46:58 +00001801 ClangASTType &class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001802 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001803 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1804 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001805 DWARFDIECollection& member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001806 DelayedPropertyList& delayed_properties,
Sean Callananc7fbf732010-08-06 00:32:49 +00001807 AccessType& default_accessibility,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001808 bool &is_a_class,
1809 LayoutInfo &layout_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001810)
1811{
1812 if (parent_die == NULL)
1813 return 0;
1814
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001815 size_t count = 0;
1816 const DWARFDebugInfoEntry *die;
Todd Fialaee8bfc62014-09-11 17:29:12 +00001817 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001818 uint32_t member_idx = 0;
Sean Callananfaa0bb32012-12-05 23:37:14 +00001819 BitfieldInfo last_field_info;
Richard Mitton0a558352013-10-17 21:14:00 +00001820 ModuleSP module = GetObjectFile()->GetModule();
Greg Claytond88d7592010-09-15 08:33:30 +00001821
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001822 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1823 {
1824 dw_tag_t tag = die->Tag();
1825
1826 switch (tag)
1827 {
1828 case DW_TAG_member:
Sean Callanan3d654b32012-09-24 22:25:51 +00001829 case DW_TAG_APPLE_property:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001830 {
1831 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001832 const size_t num_attributes = die->GetAttributes (this,
1833 dwarf_cu,
1834 fixed_form_sizes,
1835 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001836 if (num_attributes > 0)
1837 {
1838 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001839 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001840 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001841 const char *prop_name = NULL;
1842 const char *prop_getter_name = NULL;
1843 const char *prop_setter_name = NULL;
Greg Claytone528efd72013-02-26 23:45:18 +00001844 uint32_t prop_attributes = 0;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001845
1846
Greg Clayton24739922010-10-13 03:15:28 +00001847 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001848 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001849 AccessType accessibility = eAccessNone;
Greg Claytoncaab74e2012-01-28 00:48:57 +00001850 uint32_t member_byte_offset = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001851 size_t byte_size = 0;
1852 size_t bit_offset = 0;
1853 size_t bit_size = 0;
Greg Claytone528efd72013-02-26 23:45:18 +00001854 bool is_external = false; // On DW_TAG_members, this means the member is static
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001855 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001856 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001857 {
1858 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1859 DWARFFormValue form_value;
1860 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1861 {
1862 switch (attr)
1863 {
1864 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1865 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1866 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1867 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00001868 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001869 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1870 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1871 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1872 case DW_AT_data_member_location:
Greg Claytoncaab74e2012-01-28 00:48:57 +00001873 if (form_value.BlockData())
1874 {
1875 Value initialValue(0);
1876 Value memberOffset(0);
Ed Masteeeae7212013-10-24 20:43:47 +00001877 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Claytoncaab74e2012-01-28 00:48:57 +00001878 uint32_t block_length = form_value.Unsigned();
1879 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1880 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
Greg Claytoncaab74e2012-01-28 00:48:57 +00001881 NULL, // ClangExpressionVariableList *
1882 NULL, // ClangExpressionDeclMap *
1883 NULL, // RegisterContext *
Richard Mitton0a558352013-10-17 21:14:00 +00001884 module,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001885 debug_info_data,
1886 block_offset,
1887 block_length,
1888 eRegisterKindDWARF,
1889 &initialValue,
1890 memberOffset,
1891 NULL))
1892 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001893 member_byte_offset = memberOffset.ResolveValue(NULL).UInt();
Greg Claytoncaab74e2012-01-28 00:48:57 +00001894 }
1895 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00001896 else
1897 {
1898 // With DWARF 3 and later, if the value is an integer constant,
1899 // this form value is the offset in bytes from the beginning
1900 // of the containing entity.
1901 member_byte_offset = form_value.Unsigned();
1902 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001903 break;
1904
Greg Clayton8cf05932010-07-22 18:30:50 +00001905 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00001906 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001907 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1908 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1909 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1910 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00001911 case DW_AT_external: is_external = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001912
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001913 default:
Greg Clayton1b02c172012-03-14 21:00:47 +00001914 case DW_AT_declaration:
1915 case DW_AT_description:
1916 case DW_AT_mutable:
1917 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001918 case DW_AT_sibling:
1919 break;
1920 }
1921 }
1922 }
Sean Callanana6582262012-04-05 00:12:52 +00001923
1924 if (prop_name)
Sean Callanan751aac62012-03-29 19:07:06 +00001925 {
Sean Callanana6582262012-04-05 00:12:52 +00001926 ConstString fixed_getter;
1927 ConstString fixed_setter;
1928
1929 // Check if the property getter/setter were provided as full
1930 // names. We want basenames, so we extract them.
1931
1932 if (prop_getter_name && prop_getter_name[0] == '-')
1933 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001934 ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true);
1935 prop_getter_name = prop_getter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001936 }
1937
1938 if (prop_setter_name && prop_setter_name[0] == '-')
1939 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001940 ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true);
1941 prop_setter_name = prop_setter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001942 }
1943
1944 // If the names haven't been provided, they need to be
1945 // filled in.
1946
1947 if (!prop_getter_name)
1948 {
1949 prop_getter_name = prop_name;
1950 }
1951 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly))
1952 {
1953 StreamString ss;
1954
1955 ss.Printf("set%c%s:",
1956 toupper(prop_name[0]),
1957 &prop_name[1]);
1958
1959 fixed_setter.SetCString(ss.GetData());
1960 prop_setter_name = fixed_setter.GetCString();
1961 }
Sean Callanan751aac62012-03-29 19:07:06 +00001962 }
1963
1964 // Clang has a DWARF generation bug where sometimes it
Greg Clayton44953932011-10-25 01:25:35 +00001965 // represents fields that are references with bad byte size
1966 // and bit size/offset information such as:
1967 //
1968 // DW_AT_byte_size( 0x00 )
1969 // DW_AT_bit_size( 0x40 )
1970 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1971 //
1972 // So check the bit offset to make sure it is sane, and if
1973 // the values are not sane, remove them. If we don't do this
1974 // then we will end up with a crash if we try to use this
1975 // type in an expression when clang becomes unhappy with its
1976 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001977
Greg Clayton44953932011-10-25 01:25:35 +00001978 if (bit_offset > 128)
1979 {
1980 bit_size = 0;
1981 bit_offset = 0;
1982 }
1983
1984 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00001985 if (class_language == eLanguageTypeObjC ||
1986 class_language == eLanguageTypeObjC_plus_plus)
1987 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001988
1989 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1990 {
1991 // Not all compilers will mark the vtable pointer
1992 // member as artificial (llvm-gcc). We can't have
1993 // the virtual members in our classes otherwise it
1994 // throws off all child offsets since we end up
1995 // having and extra pointer sized member in our
1996 // class layouts.
1997 is_artificial = true;
1998 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001999
Greg Clayton29659712013-07-12 20:08:35 +00002000 // Handle static members
Greg Claytone528efd72013-02-26 23:45:18 +00002001 if (is_external && member_byte_offset == UINT32_MAX)
Greg Clayton973b6c92013-04-11 16:57:51 +00002002 {
2003 Type *var_type = ResolveTypeUID(encoding_uid);
2004
2005 if (var_type)
2006 {
Greg Clayton29659712013-07-12 20:08:35 +00002007 if (accessibility == eAccessNone)
2008 accessibility = eAccessPublic;
Pavel Labathc7c30eb2015-06-08 23:38:06 +00002009 class_clang_type.AddVariableToRecordType (name,
Greg Clayton57ee3062013-07-11 22:46:58 +00002010 var_type->GetClangLayoutType(),
2011 accessibility);
Greg Clayton973b6c92013-04-11 16:57:51 +00002012 }
Greg Claytone528efd72013-02-26 23:45:18 +00002013 break;
Greg Clayton973b6c92013-04-11 16:57:51 +00002014 }
Greg Claytone528efd72013-02-26 23:45:18 +00002015
Greg Clayton24739922010-10-13 03:15:28 +00002016 if (is_artificial == false)
2017 {
2018 Type *member_type = ResolveTypeUID(encoding_uid);
Sean Callananfa3ab452012-12-14 00:54:13 +00002019
Jim Inghame3ae82a2011-11-12 01:36:43 +00002020 clang::FieldDecl *field_decl = NULL;
Sean Callanan751aac62012-03-29 19:07:06 +00002021 if (tag == DW_TAG_member)
Greg Claytond16e1e52011-07-12 17:06:17 +00002022 {
Sean Callanan751aac62012-03-29 19:07:06 +00002023 if (member_type)
2024 {
2025 if (accessibility == eAccessNone)
2026 accessibility = default_accessibility;
2027 member_accessibilities.push_back(accessibility);
Sean Callananfaa0bb32012-12-05 23:37:14 +00002028
Greg Clayton78f4d952013-12-11 23:10:39 +00002029 uint64_t field_bit_offset = (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
2030 if (bit_size > 0)
Greg Clayton88bc7f32012-11-06 00:20:41 +00002031 {
Greg Clayton78f4d952013-12-11 23:10:39 +00002032
2033 BitfieldInfo this_field_info;
2034 this_field_info.bit_offset = field_bit_offset;
2035 this_field_info.bit_size = bit_size;
2036
Sean Callananfaa0bb32012-12-05 23:37:14 +00002037 /////////////////////////////////////////////////////////////
2038 // How to locate a field given the DWARF debug information
2039 //
2040 // AT_byte_size indicates the size of the word in which the
2041 // bit offset must be interpreted.
2042 //
2043 // AT_data_member_location indicates the byte offset of the
2044 // word from the base address of the structure.
2045 //
2046 // AT_bit_offset indicates how many bits into the word
2047 // (according to the host endianness) the low-order bit of
2048 // the field starts. AT_bit_offset can be negative.
2049 //
2050 // AT_bit_size indicates the size of the field in bits.
2051 /////////////////////////////////////////////////////////////
2052
Greg Clayton78f4d952013-12-11 23:10:39 +00002053 if (byte_size == 0)
2054 byte_size = member_type->GetByteSize();
2055
Sean Callananfaa0bb32012-12-05 23:37:14 +00002056 if (GetObjectFile()->GetByteOrder() == eByteOrderLittle)
2057 {
2058 this_field_info.bit_offset += byte_size * 8;
2059 this_field_info.bit_offset -= (bit_offset + bit_size);
2060 }
2061 else
2062 {
2063 this_field_info.bit_offset += bit_offset;
2064 }
Greg Clayton78f4d952013-12-11 23:10:39 +00002065
2066 // Update the field bit offset we will report for layout
2067 field_bit_offset = this_field_info.bit_offset;
Sean Callananfaa0bb32012-12-05 23:37:14 +00002068
Greg Clayton78f4d952013-12-11 23:10:39 +00002069 // If the member to be emitted did not start on a character boundary and there is
2070 // empty space between the last field and this one, then we need to emit an
2071 // anonymous member filling up the space up to its start. There are three cases
2072 // here:
2073 //
2074 // 1 If the previous member ended on a character boundary, then we can emit an
2075 // anonymous member starting at the most recent character boundary.
2076 //
2077 // 2 If the previous member did not end on a character boundary and the distance
2078 // from the end of the previous member to the current member is less than a
2079 // word width, then we can emit an anonymous member starting right after the
2080 // previous member and right before this member.
2081 //
2082 // 3 If the previous member did not end on a character boundary and the distance
2083 // from the end of the previous member to the current member is greater than
2084 // or equal a word width, then we act as in Case 1.
2085
2086 const uint64_t character_width = 8;
2087 const uint64_t word_width = 32;
2088
Sean Callananfaa0bb32012-12-05 23:37:14 +00002089 // Objective-C has invalid DW_AT_bit_offset values in older versions
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +00002090 // of clang, so we have to be careful and only insert unnamed bitfields
Greg Clayton37c36e42012-11-27 00:59:26 +00002091 // if we have a new enough clang.
2092 bool detect_unnamed_bitfields = true;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002093
Greg Clayton37c36e42012-11-27 00:59:26 +00002094 if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus)
2095 detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields ();
2096
2097 if (detect_unnamed_bitfields)
Greg Clayton88bc7f32012-11-06 00:20:41 +00002098 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00002099 BitfieldInfo anon_field_info;
2100
2101 if ((this_field_info.bit_offset % character_width) != 0) // not char aligned
Greg Clayton88bc7f32012-11-06 00:20:41 +00002102 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00002103 uint64_t last_field_end = 0;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002104
Sean Callananfaa0bb32012-12-05 23:37:14 +00002105 if (last_field_info.IsValid())
2106 last_field_end = last_field_info.bit_offset + last_field_info.bit_size;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002107
Sean Callananfaa0bb32012-12-05 23:37:14 +00002108 if (this_field_info.bit_offset != last_field_end)
2109 {
2110 if (((last_field_end % character_width) == 0) || // case 1
2111 (this_field_info.bit_offset - last_field_end >= word_width)) // case 3
2112 {
2113 anon_field_info.bit_size = this_field_info.bit_offset % character_width;
2114 anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size;
2115 }
2116 else // case 2
2117 {
2118 anon_field_info.bit_size = this_field_info.bit_offset - last_field_end;
2119 anon_field_info.bit_offset = last_field_end;
2120 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00002121 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00002122 }
2123
Sean Callananfaa0bb32012-12-05 23:37:14 +00002124 if (anon_field_info.IsValid())
Greg Clayton88bc7f32012-11-06 00:20:41 +00002125 {
Pavel Labathc7c30eb2015-06-08 23:38:06 +00002126 clang::FieldDecl *unnamed_bitfield_decl = class_clang_type.AddFieldToRecordType (NULL,
2127 GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width),
2128 accessibility,
2129 anon_field_info.bit_size);
Zachary Turner504f38d2015-03-24 16:24:50 +00002130
Zachary Turnera98fac22015-03-24 18:56:08 +00002131 layout_info.field_offsets.insert(
Zachary Turner504f38d2015-03-24 16:24:50 +00002132 std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset));
Greg Clayton88bc7f32012-11-06 00:20:41 +00002133 }
2134 }
Greg Clayton78f4d952013-12-11 23:10:39 +00002135 last_field_info = this_field_info;
2136 }
2137 else
2138 {
2139 last_field_info.Clear();
Greg Clayton88bc7f32012-11-06 00:20:41 +00002140 }
Sean Callananfaa0bb32012-12-05 23:37:14 +00002141
Greg Clayton57ee3062013-07-11 22:46:58 +00002142 ClangASTType member_clang_type = member_type->GetClangLayoutType();
Sean Callananfa3ab452012-12-14 00:54:13 +00002143
2144 {
2145 // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>).
2146 // If the current field is at the end of the structure, then there is definitely no room for extra
2147 // elements and we override the type to array[0].
2148
Greg Clayton57ee3062013-07-11 22:46:58 +00002149 ClangASTType member_array_element_type;
Sean Callananfa3ab452012-12-14 00:54:13 +00002150 uint64_t member_array_size;
2151 bool member_array_is_incomplete;
2152
Greg Clayton57ee3062013-07-11 22:46:58 +00002153 if (member_clang_type.IsArrayType(&member_array_element_type,
2154 &member_array_size,
2155 &member_array_is_incomplete) &&
Sean Callananfa3ab452012-12-14 00:54:13 +00002156 !member_array_is_incomplete)
2157 {
2158 uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX);
2159
2160 if (member_byte_offset >= parent_byte_size)
2161 {
2162 if (member_array_size != 1)
2163 {
2164 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,
2165 MakeUserID(die->GetOffset()),
2166 name,
2167 encoding_uid,
2168 MakeUserID(parent_die->GetOffset()));
2169 }
2170
Greg Clayton1c8ef472013-04-05 23:27:21 +00002171 member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0, false);
Sean Callananfa3ab452012-12-14 00:54:13 +00002172 }
2173 }
2174 }
2175
Pavel Labathc7c30eb2015-06-08 23:38:06 +00002176 field_decl = class_clang_type.AddFieldToRecordType (name,
Greg Clayton57ee3062013-07-11 22:46:58 +00002177 member_clang_type,
2178 accessibility,
2179 bit_size);
Sean Callanan60217122012-04-13 00:10:03 +00002180
Greg Claytond0029442013-03-27 01:48:02 +00002181 GetClangASTContext().SetMetadataAsUserID (field_decl, MakeUserID(die->GetOffset()));
Greg Clayton78f4d952013-12-11 23:10:39 +00002182
Zachary Turnera98fac22015-03-24 18:56:08 +00002183 layout_info.field_offsets.insert(std::make_pair(field_decl, field_bit_offset));
Sean Callanan5b26f272012-02-04 08:49:35 +00002184 }
2185 else
2186 {
Sean Callanan751aac62012-03-29 19:07:06 +00002187 if (name)
Daniel Malead01b2952012-11-29 21:49:15 +00002188 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 +00002189 MakeUserID(die->GetOffset()),
2190 name,
2191 encoding_uid);
2192 else
Daniel Malead01b2952012-11-29 21:49:15 +00002193 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 +00002194 MakeUserID(die->GetOffset()),
2195 encoding_uid);
Sean Callanan5b26f272012-02-04 08:49:35 +00002196 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002197 }
Sean Callanan751aac62012-03-29 19:07:06 +00002198
Jim Inghame3ae82a2011-11-12 01:36:43 +00002199 if (prop_name != NULL)
2200 {
Sean Callanan751aac62012-03-29 19:07:06 +00002201 clang::ObjCIvarDecl *ivar_decl = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00002202
Sean Callanan751aac62012-03-29 19:07:06 +00002203 if (field_decl)
2204 {
2205 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
2206 assert (ivar_decl != NULL);
2207 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00002208
Jim Ingham379397632012-10-27 02:54:13 +00002209 ClangASTMetadata metadata;
2210 metadata.SetUserID (MakeUserID(die->GetOffset()));
Greg Clayton57ee3062013-07-11 22:46:58 +00002211 delayed_properties.push_back(DelayedAddObjCClassProperty(class_clang_type,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002212 prop_name,
2213 member_type->GetClangLayoutType(),
2214 ivar_decl,
2215 prop_setter_name,
2216 prop_getter_name,
2217 prop_attributes,
Jim Ingham379397632012-10-27 02:54:13 +00002218 &metadata));
Sean Callanan60217122012-04-13 00:10:03 +00002219
Sean Callananad880762012-04-18 01:06:17 +00002220 if (ivar_decl)
Greg Claytond0029442013-03-27 01:48:02 +00002221 GetClangASTContext().SetMetadataAsUserID (ivar_decl, MakeUserID(die->GetOffset()));
Jim Inghame3ae82a2011-11-12 01:36:43 +00002222 }
Greg Clayton24739922010-10-13 03:15:28 +00002223 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002224 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00002225 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002226 }
2227 break;
2228
2229 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00002230 // Let the type parsing code handle this one for us.
2231 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002232 break;
2233
2234 case DW_TAG_inheritance:
2235 {
2236 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00002237 if (default_accessibility == eAccessNone)
2238 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002239 // TODO: implement DW_TAG_inheritance type parsing
2240 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00002241 const size_t num_attributes = die->GetAttributes (this,
2242 dwarf_cu,
2243 fixed_form_sizes,
2244 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002245 if (num_attributes > 0)
2246 {
2247 Declaration decl;
2248 DWARFExpression location;
2249 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00002250 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002251 bool is_virtual = false;
2252 bool is_base_of_class = true;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002253 off_t member_byte_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002254 uint32_t i;
2255 for (i=0; i<num_attributes; ++i)
2256 {
2257 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2258 DWARFFormValue form_value;
2259 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2260 {
2261 switch (attr)
2262 {
2263 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2264 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2265 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00002266 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002267 case DW_AT_data_member_location:
2268 if (form_value.BlockData())
2269 {
2270 Value initialValue(0);
2271 Value memberOffset(0);
Ed Masteeeae7212013-10-24 20:43:47 +00002272 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002273 uint32_t block_length = form_value.Unsigned();
2274 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
2275 if (DWARFExpression::Evaluate (NULL,
2276 NULL,
2277 NULL,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002278 NULL,
Richard Mitton0a558352013-10-17 21:14:00 +00002279 module,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002280 debug_info_data,
2281 block_offset,
2282 block_length,
2283 eRegisterKindDWARF,
2284 &initialValue,
2285 memberOffset,
2286 NULL))
2287 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002288 member_byte_offset = memberOffset.ResolveValue(NULL).UInt();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002289 }
2290 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002291 else
2292 {
2293 // With DWARF 3 and later, if the value is an integer constant,
2294 // this form value is the offset in bytes from the beginning
2295 // of the containing entity.
2296 member_byte_offset = form_value.Unsigned();
2297 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002298 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002299
2300 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00002301 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002302 break;
2303
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002304 case DW_AT_virtuality:
2305 is_virtual = form_value.Boolean();
2306 break;
2307
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002308 case DW_AT_sibling:
2309 break;
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002310
2311 default:
2312 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002313 }
2314 }
2315 }
2316
Greg Clayton526e5af2010-11-13 03:52:47 +00002317 Type *base_class_type = ResolveTypeUID(encoding_uid);
Greg Clayton898c1b22015-05-15 22:31:18 +00002318 if (base_class_type == NULL)
2319 {
Bruce Mitchener58ef3912015-06-18 05:27:05 +00002320 GetObjectFile()->GetModule()->ReportError("0x%8.8x: DW_TAG_inheritance failed to resolve the base class at 0x%8.8" PRIx64 " from enclosing type 0x%8.8x. \nPlease file a bug and attach the file at the start of this error message",
Greg Clayton898c1b22015-05-15 22:31:18 +00002321 die->GetOffset(),
2322 encoding_uid,
2323 parent_die->GetOffset());
2324 break;
2325 }
2326
Greg Clayton57ee3062013-07-11 22:46:58 +00002327 ClangASTType base_class_clang_type = base_class_type->GetClangFullType();
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002328 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002329 if (class_language == eLanguageTypeObjC)
2330 {
Pavel Labathc7c30eb2015-06-08 23:38:06 +00002331 class_clang_type.SetObjCSuperClass(base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002332 }
2333 else
2334 {
Pavel Labathc7c30eb2015-06-08 23:38:06 +00002335 base_classes.push_back (base_class_clang_type.CreateBaseClassSpecifier (accessibility,
2336 is_virtual,
2337 is_base_of_class));
Greg Clayton2508b9b2012-11-01 23:20:02 +00002338
2339 if (is_virtual)
2340 {
Greg Clayton52694e32013-09-16 21:57:07 +00002341 // Do not specify any offset for virtual inheritance. The DWARF produced by clang doesn't
2342 // give us a constant offset, but gives us a DWARF expressions that requires an actual object
2343 // in memory. the DW_AT_data_member_location for a virtual base class looks like:
2344 // DW_AT_data_member_location( DW_OP_dup, DW_OP_deref, DW_OP_constu(0x00000018), DW_OP_minus, DW_OP_deref, DW_OP_plus )
2345 // Given this, there is really no valid response we can give to clang for virtual base
2346 // class offsets, and this should eventually be removed from LayoutRecordType() in the external
2347 // AST source in clang.
Greg Clayton2508b9b2012-11-01 23:20:02 +00002348 }
2349 else
2350 {
Zachary Turnera98fac22015-03-24 18:56:08 +00002351 layout_info.base_offsets.insert(
Pavel Labathc7c30eb2015-06-08 23:38:06 +00002352 std::make_pair(base_class_clang_type.GetAsCXXRecordDecl(),
Zachary Turner504f38d2015-03-24 16:24:50 +00002353 clang::CharUnits::fromQuantity(member_byte_offset)));
Greg Clayton2508b9b2012-11-01 23:20:02 +00002354 }
Greg Clayton9e409562010-07-28 02:04:09 +00002355 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002356 }
2357 }
2358 break;
2359
2360 default:
2361 break;
2362 }
2363 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002364
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002365 return count;
2366}
2367
2368
2369clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00002370SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002371{
2372 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00002373 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002374 {
2375 DWARFCompileUnitSP cu_sp;
2376 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
2377 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00002378 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00002379 }
2380 return NULL;
2381}
2382
2383clang::DeclContext*
2384SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
2385{
Greg Clayton81c22f62011-10-19 18:09:39 +00002386 if (UserIDMatches(type_uid))
2387 return GetClangDeclContextForDIEOffset (sc, type_uid);
2388 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002389}
2390
2391Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00002392SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002393{
Greg Clayton81c22f62011-10-19 18:09:39 +00002394 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002395 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002396 DWARFDebugInfo* debug_info = DebugInfo();
2397 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00002398 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002399 DWARFCompileUnitSP cu_sp;
2400 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00002401 const bool assert_not_being_parsed = true;
2402 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00002403 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002404 }
2405 return NULL;
2406}
2407
Greg Claytoncab36a32011-12-08 05:16:30 +00002408Type*
2409SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00002410{
Greg Claytoncab36a32011-12-08 05:16:30 +00002411 if (die != NULL)
2412 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002413 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00002414 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002415 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002416 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
2417 die->GetOffset(),
2418 DW_TAG_value_to_name(die->Tag()),
2419 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00002420
Greg Claytoncab36a32011-12-08 05:16:30 +00002421 // We might be coming in in the middle of a type tree (a class
2422 // withing a class, an enum within a class), so parse any needed
2423 // parent DIEs before we get to this one...
2424 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2425 switch (decl_ctx_die->Tag())
2426 {
2427 case DW_TAG_structure_type:
2428 case DW_TAG_union_type:
2429 case DW_TAG_class_type:
2430 {
2431 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00002432 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002433 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002434 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
2435 die->GetOffset(),
2436 DW_TAG_value_to_name(die->Tag()),
2437 die->GetName(this, cu),
2438 decl_ctx_die->GetOffset());
Greg Clayton219cf312012-03-30 00:51:13 +00002439//
2440// Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
2441// if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
2442// {
2443// if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002444// GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton219cf312012-03-30 00:51:13 +00002445// "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
2446// die->GetOffset(),
2447// DW_TAG_value_to_name(die->Tag()),
2448// die->GetName(this, cu),
2449// decl_ctx_die->GetOffset());
2450// // Ask the type to complete itself if it already hasn't since if we
2451// // want a function (method or static) from a class, the class must
2452// // create itself and add it's own methods and class functions.
2453// if (parent_type)
2454// parent_type->GetClangFullType();
2455// }
Greg Claytoncab36a32011-12-08 05:16:30 +00002456 }
2457 break;
2458
2459 default:
2460 break;
2461 }
2462 return ResolveType (cu, die);
2463 }
2464 return NULL;
2465}
2466
Greg Clayton6beaaa62011-01-17 03:46:26 +00002467// This function is used when SymbolFileDWARFDebugMap owns a bunch of
2468// SymbolFileDWARF objects to detect if this DWARF file is the one that
2469// can resolve a clang_type.
2470bool
Greg Clayton57ee3062013-07-11 22:46:58 +00002471SymbolFileDWARF::HasForwardDeclForClangType (const ClangASTType &clang_type)
Greg Clayton6beaaa62011-01-17 03:46:26 +00002472{
Pavel Labathc7c30eb2015-06-08 23:38:06 +00002473 ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers();
Greg Clayton57ee3062013-07-11 22:46:58 +00002474 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton6beaaa62011-01-17 03:46:26 +00002475 return die != NULL;
2476}
2477
2478
Greg Clayton57ee3062013-07-11 22:46:58 +00002479bool
2480SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (ClangASTType &clang_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00002481{
2482 // We have a struct/union/class/enum that needs to be fully resolved.
Pavel Labathc7c30eb2015-06-08 23:38:06 +00002483 ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers();
Greg Clayton57ee3062013-07-11 22:46:58 +00002484 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton1be10fc2010-09-29 01:12:09 +00002485 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00002486 {
2487 // We have already resolved this type...
Greg Clayton57ee3062013-07-11 22:46:58 +00002488 return true;
Greg Clayton73b472d2010-10-27 03:32:59 +00002489 }
2490 // Once we start resolving this type, remove it from the forward declaration
2491 // map in case anyone child members or other types require this type to get resolved.
2492 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
2493 // are done.
Greg Clayton57ee3062013-07-11 22:46:58 +00002494 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton1be10fc2010-09-29 01:12:09 +00002495
Greg Clayton85ae2e12011-10-18 23:36:41 +00002496 // Disable external storage for this type so we don't get anymore
2497 // clang::ExternalASTSource queries for this type.
Pavel Labathc7c30eb2015-06-08 23:38:06 +00002498 clang_type.SetHasExternalStorage (false);
Greg Clayton85ae2e12011-10-18 23:36:41 +00002499
Greg Clayton450e3f32010-10-12 02:24:53 +00002500 DWARFDebugInfo* debug_info = DebugInfo();
2501
Greg Clayton53eb1c22012-04-02 22:59:12 +00002502 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002503 Type *type = m_die_to_type.lookup (die);
2504
2505 const dw_tag_t tag = die->Tag();
2506
Greg Clayton5160ce52013-03-27 23:08:40 +00002507 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
Greg Clayton3bffb082011-12-10 02:15:28 +00002508 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002509 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002510 "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...",
Greg Claytond61c0fc2012-04-23 22:55:20 +00002511 MakeUserID(die->GetOffset()),
2512 DW_TAG_value_to_name(tag),
2513 type->GetName().AsCString());
Greg Clayton1be10fc2010-09-29 01:12:09 +00002514 assert (clang_type);
2515 DWARFDebugInfoEntry::Attributes attributes;
2516
Greg Clayton1be10fc2010-09-29 01:12:09 +00002517 switch (tag)
2518 {
2519 case DW_TAG_structure_type:
2520 case DW_TAG_union_type:
2521 case DW_TAG_class_type:
Greg Claytonc93237c2010-10-01 20:48:32 +00002522 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002523 LayoutInfo layout_info;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002524
Greg Clayton1be10fc2010-09-29 01:12:09 +00002525 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002526 if (die->HasChildren())
Greg Claytonc93237c2010-10-01 20:48:32 +00002527 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002528 LanguageType class_language = eLanguageTypeUnknown;
Pavel Labathc7c30eb2015-06-08 23:38:06 +00002529 if (clang_type.IsObjCObjectOrInterfaceType())
Greg Clayton219cf312012-03-30 00:51:13 +00002530 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002531 class_language = eLanguageTypeObjC;
Greg Clayton219cf312012-03-30 00:51:13 +00002532 // For objective C we don't start the definition when
2533 // the class is created.
Pavel Labathc7c30eb2015-06-08 23:38:06 +00002534 clang_type.StartTagDeclarationDefinition ();
Greg Clayton219cf312012-03-30 00:51:13 +00002535 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002536
Sean Callanan77a1fd32012-02-27 20:07:01 +00002537 int tag_decl_kind = -1;
2538 AccessType default_accessibility = eAccessNone;
2539 if (tag == DW_TAG_structure_type)
2540 {
2541 tag_decl_kind = clang::TTK_Struct;
2542 default_accessibility = eAccessPublic;
2543 }
2544 else if (tag == DW_TAG_union_type)
2545 {
2546 tag_decl_kind = clang::TTK_Union;
2547 default_accessibility = eAccessPublic;
2548 }
2549 else if (tag == DW_TAG_class_type)
2550 {
2551 tag_decl_kind = clang::TTK_Class;
2552 default_accessibility = eAccessPrivate;
2553 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002554
Greg Clayton53eb1c22012-04-02 22:59:12 +00002555 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002556 std::vector<clang::CXXBaseSpecifier *> base_classes;
2557 std::vector<int> member_accessibilities;
2558 bool is_a_class = false;
2559 // Parse members and base classes first
2560 DWARFDIECollection member_function_dies;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002561
Sean Callanana0b80ab2012-06-04 22:28:05 +00002562 DelayedPropertyList delayed_properties;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002563 ParseChildMembers (sc,
Greg Clayton53eb1c22012-04-02 22:59:12 +00002564 dwarf_cu,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002565 die,
2566 clang_type,
2567 class_language,
2568 base_classes,
2569 member_accessibilities,
2570 member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002571 delayed_properties,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002572 default_accessibility,
2573 is_a_class,
2574 layout_info);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002575
Sean Callanan77a1fd32012-02-27 20:07:01 +00002576 // Now parse any methods if there were any...
2577 size_t num_functions = member_function_dies.Size();
2578 if (num_functions > 0)
2579 {
2580 for (size_t i=0; i<num_functions; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002581 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002582 ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytoncaab74e2012-01-28 00:48:57 +00002583 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002584 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002585
Sean Callanan77a1fd32012-02-27 20:07:01 +00002586 if (class_language == eLanguageTypeObjC)
2587 {
Jim Inghamfb6fc0d2013-09-27 20:59:37 +00002588 ConstString class_name (clang_type.GetTypeName());
2589 if (class_name)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002590 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002591 DIEArray method_die_offsets;
2592 if (m_using_apple_tables)
Greg Clayton95d87902011-11-11 03:16:25 +00002593 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002594 if (m_apple_objc_ap.get())
Jim Inghamfb6fc0d2013-09-27 20:59:37 +00002595 m_apple_objc_ap->FindByName(class_name.GetCString(), method_die_offsets);
Sean Callanan77a1fd32012-02-27 20:07:01 +00002596 }
2597 else
2598 {
2599 if (!m_indexed)
2600 Index ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002601
Sean Callanan77a1fd32012-02-27 20:07:01 +00002602 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
2603 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002604
Sean Callanan77a1fd32012-02-27 20:07:01 +00002605 if (!method_die_offsets.empty())
2606 {
2607 DWARFDebugInfo* debug_info = DebugInfo();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002608
Sean Callanan77a1fd32012-02-27 20:07:01 +00002609 DWARFCompileUnit* method_cu = NULL;
2610 const size_t num_matches = method_die_offsets.size();
2611 for (size_t i=0; i<num_matches; ++i)
Greg Clayton95d87902011-11-11 03:16:25 +00002612 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002613 const dw_offset_t die_offset = method_die_offsets[i];
2614 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002615
Sean Callanan77a1fd32012-02-27 20:07:01 +00002616 if (method_die)
2617 ResolveType (method_cu, method_die);
2618 else
Greg Claytoncaab74e2012-01-28 00:48:57 +00002619 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002620 if (m_using_apple_tables)
2621 {
2622 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 +00002623 die_offset, class_name.GetCString());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002624 }
2625 }
2626 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002627 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002628
Greg Clayton57ee3062013-07-11 22:46:58 +00002629 for (DelayedPropertyList::iterator pi = delayed_properties.begin(), pe = delayed_properties.end();
Sean Callanana0b80ab2012-06-04 22:28:05 +00002630 pi != pe;
2631 ++pi)
2632 pi->Finalize();
Greg Clayton450e3f32010-10-12 02:24:53 +00002633 }
2634 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002635
Sean Callanan77a1fd32012-02-27 20:07:01 +00002636 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2637 // need to tell the clang type it is actually a class.
2638 if (class_language != eLanguageTypeObjC)
2639 {
2640 if (is_a_class && tag_decl_kind != clang::TTK_Class)
Pavel Labathc7c30eb2015-06-08 23:38:06 +00002641 clang_type.SetTagTypeKind (clang::TTK_Class);
Sean Callanan77a1fd32012-02-27 20:07:01 +00002642 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002643
Sean Callanan77a1fd32012-02-27 20:07:01 +00002644 // Since DW_TAG_structure_type gets used for both classes
2645 // and structures, we may need to set any DW_TAG_member
2646 // fields to have a "private" access if none was specified.
2647 // When we parsed the child members we tracked that actual
2648 // accessibility value for each DW_TAG_member in the
2649 // "member_accessibilities" array. If the value for the
2650 // member is zero, then it was set to the "default_accessibility"
2651 // which for structs was "public". Below we correct this
2652 // by setting any fields to "private" that weren't correctly
2653 // set.
2654 if (is_a_class && !member_accessibilities.empty())
2655 {
2656 // This is a class and all members that didn't have
2657 // their access specified are private.
Pavel Labathc7c30eb2015-06-08 23:38:06 +00002658 clang_type.SetDefaultAccessForRecordFields (eAccessPrivate,
2659 &member_accessibilities.front(),
2660 member_accessibilities.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002661 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002662
Sean Callanan77a1fd32012-02-27 20:07:01 +00002663 if (!base_classes.empty())
2664 {
Greg Clayton4705f8d2013-12-12 01:54:04 +00002665 // Make sure all base classes refer to complete types and not
2666 // forward declarations. If we don't do this, clang will crash
2667 // with an assertion in the call to clang_type.SetBaseClassesForClassType()
2668 bool base_class_error = false;
2669 for (auto &base_class : base_classes)
2670 {
2671 clang::TypeSourceInfo *type_source_info = base_class->getTypeSourceInfo();
2672 if (type_source_info)
2673 {
2674 ClangASTType base_class_type (GetClangASTContext().getASTContext(), type_source_info->getType());
2675 if (base_class_type.GetCompleteType() == false)
2676 {
2677 if (!base_class_error)
2678 {
2679 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",
2680 die->GetOffset(),
2681 die->GetName(this, dwarf_cu),
2682 base_class_type.GetTypeName().GetCString(),
2683 sc.comp_unit ? sc.comp_unit->GetPath().c_str() : "the source file");
2684 }
2685 // We have no choice other than to pretend that the base class
2686 // is complete. If we don't do this, clang will crash when we
2687 // call setBases() inside of "clang_type.SetBaseClassesForClassType()"
2688 // below. Since we provide layout assistance, all ivars in this
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00002689 // class and other classes will be fine, this is the best we can do
Greg Clayton4705f8d2013-12-12 01:54:04 +00002690 // short of crashing.
Pavel Labathc7c30eb2015-06-08 23:38:06 +00002691 base_class_type.StartTagDeclarationDefinition ();
2692 base_class_type.CompleteTagDeclarationDefinition ();
Greg Clayton4705f8d2013-12-12 01:54:04 +00002693 }
2694 }
2695 }
Pavel Labathc7c30eb2015-06-08 23:38:06 +00002696 clang_type.SetBaseClassesForClassType (&base_classes.front(),
2697 base_classes.size());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002698
Sean Callanan77a1fd32012-02-27 20:07:01 +00002699 // Clang will copy each CXXBaseSpecifier in "base_classes"
2700 // so we have to free them all.
Pavel Labathc7c30eb2015-06-08 23:38:06 +00002701 ClangASTType::DeleteBaseClassSpecifiers (&base_classes.front(),
2702 base_classes.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002703 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002704 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002705 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002706
Pavel Labathc7c30eb2015-06-08 23:38:06 +00002707 clang_type.BuildIndirectFields ();
2708 clang_type.CompleteTagDeclarationDefinition ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002709
Greg Clayton2508b9b2012-11-01 23:20:02 +00002710 if (!layout_info.field_offsets.empty() ||
2711 !layout_info.base_offsets.empty() ||
2712 !layout_info.vbase_offsets.empty() )
Greg Claytoncaab74e2012-01-28 00:48:57 +00002713 {
2714 if (type)
2715 layout_info.bit_size = type->GetByteSize() * 8;
2716 if (layout_info.bit_size == 0)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002717 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002718
Pavel Labathc7c30eb2015-06-08 23:38:06 +00002719 clang::CXXRecordDecl *record_decl = clang_type.GetAsCXXRecordDecl();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002720 if (record_decl)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002721 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002722 if (log)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002723 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002724 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002725 "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 +00002726 static_cast<void*>(clang_type.GetOpaqueQualType()),
2727 static_cast<void*>(record_decl),
Greg Claytoncaab74e2012-01-28 00:48:57 +00002728 layout_info.bit_size,
2729 layout_info.alignment,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002730 static_cast<uint32_t>(layout_info.field_offsets.size()),
2731 static_cast<uint32_t>(layout_info.base_offsets.size()),
2732 static_cast<uint32_t>(layout_info.vbase_offsets.size()));
2733
Zachary Turnera98fac22015-03-24 18:56:08 +00002734 uint32_t idx;
2735 {
2736 llvm::DenseMap<const clang::FieldDecl *, uint64_t>::const_iterator pos,
2737 end = layout_info.field_offsets.end();
2738 for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx)
Greg Clayton2508b9b2012-11-01 23:20:02 +00002739 {
Zachary Turner504f38d2015-03-24 16:24:50 +00002740 GetObjectFile()->GetModule()->LogMessage(
2741 log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = "
2742 "{ bit_offset=%u, name='%s' }",
Zachary Turner504f38d2015-03-24 16:24:50 +00002743 static_cast<void *>(clang_type.GetOpaqueQualType()), idx,
Zachary Turnera98fac22015-03-24 18:56:08 +00002744 static_cast<uint32_t>(pos->second), pos->first->getNameAsString().c_str());
2745 }
2746 }
2747
2748 {
2749 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos,
2750 base_end = layout_info.base_offsets.end();
2751 for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end;
2752 ++base_pos, ++idx)
2753 {
2754 GetObjectFile()->GetModule()->LogMessage(
2755 log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] "
2756 "= { byte_offset=%u, name='%s' }",
2757 clang_type.GetOpaqueQualType(), idx, (uint32_t)base_pos->second.getQuantity(),
2758 base_pos->first->getNameAsString().c_str());
2759 }
2760 }
2761 {
2762 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos,
2763 vbase_end = layout_info.vbase_offsets.end();
2764 for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end;
2765 ++vbase_pos, ++idx)
2766 {
2767 GetObjectFile()->GetModule()->LogMessage(
2768 log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) "
2769 "vbase[%u] = { byte_offset=%u, name='%s' }",
2770 static_cast<void *>(clang_type.GetOpaqueQualType()), idx,
2771 static_cast<uint32_t>(vbase_pos->second.getQuantity()),
2772 vbase_pos->first->getNameAsString().c_str());
2773 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002774 }
Greg Clayton821ac6d2012-01-28 02:22:27 +00002775 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002776 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2777 }
2778 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002779 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002780
Sean Callanan9076c0f2013-10-04 21:35:29 +00002781 return (bool)clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002782
2783 case DW_TAG_enumeration_type:
Pavel Labathc7c30eb2015-06-08 23:38:06 +00002784 clang_type.StartTagDeclarationDefinition ();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002785 if (die->HasChildren())
2786 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002787 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00002788 bool is_signed = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00002789 clang_type.IsIntegerType(is_signed);
Greg Clayton3e067532013-03-05 23:54:39 +00002790 ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002791 }
Pavel Labathc7c30eb2015-06-08 23:38:06 +00002792 clang_type.CompleteTagDeclarationDefinition ();
Sean Callanan9076c0f2013-10-04 21:35:29 +00002793 return (bool)clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002794
2795 default:
2796 assert(false && "not a forward clang type decl!");
2797 break;
2798 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002799 return false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002800}
2801
Greg Claytonc685f8e2010-09-15 04:15:46 +00002802Type*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002803SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002804{
2805 if (type_die != NULL)
2806 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002807 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00002808
Greg Claytonc685f8e2010-09-15 04:15:46 +00002809 if (type == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002810 type = GetTypeForDIE (dwarf_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00002811
Greg Clayton24739922010-10-13 03:15:28 +00002812 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00002813 {
2814 if (type != DIE_IS_BEING_PARSED)
2815 return type;
2816
2817 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
Greg Clayton53eb1c22012-04-02 22:59:12 +00002818 type_die->GetOffset(),
2819 DW_TAG_value_to_name(type_die->Tag()),
2820 type_die->GetName(this, dwarf_cu));
Jim Inghamc3549282012-01-11 02:21:12 +00002821
2822 }
2823 else
2824 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002825 }
2826 return NULL;
2827}
2828
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002829CompileUnit*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002830SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002831{
2832 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002833 if (dwarf_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002834 {
2835 // The symbol vendor doesn't know about this compile unit, we
2836 // need to parse and add it to the symbol vendor object.
Greg Clayton53eb1c22012-04-02 22:59:12 +00002837 return ParseCompileUnit(dwarf_cu, cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002838 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00002839 return (CompileUnit*)dwarf_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002840}
2841
2842bool
Greg Clayton53eb1c22012-04-02 22:59:12 +00002843SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002844{
Greg Clayton72310352013-02-23 04:12:47 +00002845 sc.Clear(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002846 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002847 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002848
Greg Clayton81c22f62011-10-19 18:09:39 +00002849 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002850 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002851 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002852
2853 if (sc.function)
2854 {
Greg Claytone72dfb32012-02-24 01:59:29 +00002855 sc.module_sp = sc.function->CalculateSymbolContextModule();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002856 return true;
2857 }
2858
2859 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002860}
2861
Sean Callananf0c5aeb2015-04-20 16:31:29 +00002862void
2863SymbolFileDWARF::UpdateExternalModuleListIfNeeded()
2864{
2865 if (m_fetched_external_modules)
2866 return;
2867 m_fetched_external_modules = true;
2868
2869 DWARFDebugInfo * debug_info = DebugInfo();
2870 debug_info->GetNumCompileUnits();
2871
2872 const uint32_t num_compile_units = GetNumCompileUnits();
2873 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2874 {
2875 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
2876
2877 const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly();
2878 if (die && die->HasChildren() == false)
2879 {
2880 const uint64_t name_strp = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_name, UINT64_MAX);
2881 const uint64_t dwo_path_strp = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_GNU_dwo_name, UINT64_MAX);
2882
2883 if (name_strp != UINT64_MAX)
2884 {
2885 if (m_external_type_modules.find(dwo_path_strp) == m_external_type_modules.end())
2886 {
2887 const char *name = get_debug_str_data().PeekCStr(name_strp);
2888 const char *dwo_path = get_debug_str_data().PeekCStr(dwo_path_strp);
2889 if (name || dwo_path)
2890 {
2891 ModuleSP module_sp;
2892 if (dwo_path)
2893 {
2894 ModuleSpec dwo_module_spec;
2895 dwo_module_spec.GetFileSpec().SetFile(dwo_path, false);
2896 dwo_module_spec.GetArchitecture() = m_obj_file->GetModule()->GetArchitecture();
2897 //printf ("Loading dwo = '%s'\n", dwo_path);
2898 Error error = ModuleList::GetSharedModule (dwo_module_spec, module_sp, NULL, NULL, NULL);
2899 }
2900
2901 if (dwo_path_strp != LLDB_INVALID_UID)
2902 {
2903 m_external_type_modules[dwo_path_strp] = ClangModuleInfo { ConstString(name), module_sp };
2904 }
2905 else
2906 {
2907 // This hack should be removed promptly once clang emits both.
2908 m_external_type_modules[name_strp] = ClangModuleInfo { ConstString(name), module_sp };
2909 }
2910 }
2911 }
2912 }
2913 }
2914 }
2915}
Greg Clayton2501e5e2015-01-15 02:59:20 +00002916
2917SymbolFileDWARF::GlobalVariableMap &
2918SymbolFileDWARF::GetGlobalAranges()
2919{
2920 if (!m_global_aranges_ap)
2921 {
2922 m_global_aranges_ap.reset (new GlobalVariableMap());
2923
2924 ModuleSP module_sp = GetObjectFile()->GetModule();
2925 if (module_sp)
2926 {
2927 const size_t num_cus = module_sp->GetNumCompileUnits();
2928 for (size_t i = 0; i < num_cus; ++i)
2929 {
2930 CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(i);
2931 if (cu_sp)
2932 {
2933 VariableListSP globals_sp = cu_sp->GetVariableList(true);
2934 if (globals_sp)
2935 {
2936 const size_t num_globals = globals_sp->GetSize();
2937 for (size_t g = 0; g < num_globals; ++g)
2938 {
2939 VariableSP var_sp = globals_sp->GetVariableAtIndex(g);
2940 if (var_sp && !var_sp->GetLocationIsConstantValueData())
2941 {
2942 const DWARFExpression &location = var_sp->LocationExpression();
2943 Value location_result;
2944 Error error;
2945 if (location.Evaluate(NULL, NULL, NULL, LLDB_INVALID_ADDRESS, NULL, location_result, &error))
2946 {
2947 if (location_result.GetValueType() == Value::eValueTypeFileAddress)
2948 {
2949 lldb::addr_t file_addr = location_result.GetScalar().ULongLong();
2950 lldb::addr_t byte_size = 1;
2951 if (var_sp->GetType())
2952 byte_size = var_sp->GetType()->GetByteSize();
2953 m_global_aranges_ap->Append(GlobalVariableMap::Entry(file_addr, byte_size, var_sp.get()));
2954 }
2955 }
2956 }
2957 }
2958 }
2959 }
2960 }
2961 }
2962 m_global_aranges_ap->Sort();
2963 }
2964 return *m_global_aranges_ap;
2965}
2966
2967
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002968uint32_t
2969SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2970{
2971 Timer scoped_timer(__PRETTY_FUNCTION__,
Daniel Malead01b2952012-11-29 21:49:15 +00002972 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002973 static_cast<void*>(so_addr.GetSection().get()),
2974 so_addr.GetOffset(), resolve_scope);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002975 uint32_t resolved = 0;
Greg Clayton2501e5e2015-01-15 02:59:20 +00002976 if (resolve_scope & ( eSymbolContextCompUnit |
2977 eSymbolContextFunction |
2978 eSymbolContextBlock |
2979 eSymbolContextLineEntry |
2980 eSymbolContextVariable ))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002981 {
2982 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2983
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002984 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00002985 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002986 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002987 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Greg Clayton2501e5e2015-01-15 02:59:20 +00002988 if (cu_offset == DW_INVALID_OFFSET)
2989 {
2990 // Global variables are not in the compile unit address ranges. The only way to
2991 // currently find global variables is to iterate over the .debug_pubnames or the
2992 // __apple_names table and find all items in there that point to DW_TAG_variable
2993 // DIEs and then find the address that matches.
2994 if (resolve_scope & eSymbolContextVariable)
2995 {
2996 GlobalVariableMap &map = GetGlobalAranges();
2997 const GlobalVariableMap::Entry *entry = map.FindEntryThatContains(file_vm_addr);
2998 if (entry && entry->data)
2999 {
3000 Variable *variable = entry->data;
3001 SymbolContextScope *scc = variable->GetSymbolContextScope();
3002 if (scc)
3003 {
3004 scc->CalculateSymbolContext(&sc);
3005 sc.variable = variable;
3006 }
3007 return sc.GetResolvedMask();
3008 }
3009 }
3010 }
3011 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003012 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003013 uint32_t cu_idx = DW_INVALID_INDEX;
Greg Clayton53eb1c22012-04-02 22:59:12 +00003014 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
3015 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003016 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003017 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00003018 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003019 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003020 resolved |= eSymbolContextCompUnit;
3021
Greg Clayton6ab80132012-12-12 17:30:52 +00003022 bool force_check_line_table = false;
Greg Clayton526a4ae2012-05-16 22:09:01 +00003023 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
3024 {
3025 DWARFDebugInfoEntry *function_die = NULL;
3026 DWARFDebugInfoEntry *block_die = NULL;
3027 if (resolve_scope & eSymbolContextBlock)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003028 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003029 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
3030 }
3031 else
3032 {
3033 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL);
3034 }
3035
3036 if (function_die != NULL)
3037 {
3038 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
3039 if (sc.function == NULL)
3040 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
3041 }
3042 else
3043 {
3044 // We might have had a compile unit that had discontiguous
3045 // address ranges where the gaps are symbols that don't have
3046 // any debug info. Discontiguous compile unit address ranges
3047 // should only happen when there aren't other functions from
3048 // other compile units in these gaps. This helps keep the size
3049 // of the aranges down.
Greg Clayton6ab80132012-12-12 17:30:52 +00003050 force_check_line_table = true;
Greg Clayton526a4ae2012-05-16 22:09:01 +00003051 }
3052
3053 if (sc.function != NULL)
3054 {
3055 resolved |= eSymbolContextFunction;
3056
3057 if (resolve_scope & eSymbolContextBlock)
3058 {
3059 Block& block = sc.function->GetBlock (true);
3060
3061 if (block_die != NULL)
3062 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
3063 else
3064 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
3065 if (sc.block)
3066 resolved |= eSymbolContextBlock;
3067 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003068 }
3069 }
Greg Clayton6ab80132012-12-12 17:30:52 +00003070
3071 if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table)
3072 {
3073 LineTable *line_table = sc.comp_unit->GetLineTable();
3074 if (line_table != NULL)
3075 {
Greg Clayton9422dd62013-03-04 21:46:16 +00003076 // And address that makes it into this function should be in terms
3077 // of this debug file if there is no debug map, or it will be an
3078 // address in the .o file which needs to be fixed up to be in terms
3079 // of the debug map executable. Either way, calling FixupAddress()
3080 // will work for us.
3081 Address exe_so_addr (so_addr);
3082 if (FixupAddress(exe_so_addr))
Greg Clayton6ab80132012-12-12 17:30:52 +00003083 {
Greg Clayton9422dd62013-03-04 21:46:16 +00003084 if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry))
Greg Clayton6ab80132012-12-12 17:30:52 +00003085 {
3086 resolved |= eSymbolContextLineEntry;
3087 }
3088 }
Greg Clayton6ab80132012-12-12 17:30:52 +00003089 }
3090 }
3091
3092 if (force_check_line_table && !(resolved & eSymbolContextLineEntry))
3093 {
3094 // We might have had a compile unit that had discontiguous
3095 // address ranges where the gaps are symbols that don't have
3096 // any debug info. Discontiguous compile unit address ranges
3097 // should only happen when there aren't other functions from
3098 // other compile units in these gaps. This helps keep the size
3099 // of the aranges down.
3100 sc.comp_unit = NULL;
3101 resolved &= ~eSymbolContextCompUnit;
3102 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003103 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00003104 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003105 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003106 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.",
3107 cu_offset,
3108 cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003109 }
3110 }
3111 }
3112 }
3113 }
3114 return resolved;
3115}
3116
3117
3118
3119uint32_t
3120SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
3121{
3122 const uint32_t prev_size = sc_list.GetSize();
3123 if (resolve_scope & eSymbolContextCompUnit)
3124 {
3125 DWARFDebugInfo* debug_info = DebugInfo();
3126 if (debug_info)
3127 {
3128 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00003129 DWARFCompileUnit* dwarf_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003130
Greg Clayton53eb1c22012-04-02 22:59:12 +00003131 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003132 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003133 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Sean Callananddd7a2a2013-10-03 22:27:29 +00003134 const bool full_match = (bool)file_spec.GetDirectory();
Greg Clayton1f746072012-08-29 21:13:06 +00003135 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 +00003136 if (check_inlines || file_spec_matches_cu_file_spec)
3137 {
3138 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton53eb1c22012-04-02 22:59:12 +00003139 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00003140 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003141 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003142 uint32_t file_idx = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003143
Greg Clayton526a4ae2012-05-16 22:09:01 +00003144 // If we are looking for inline functions only and we don't
3145 // find it in the support files, we are done.
3146 if (check_inlines)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003147 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003148 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
3149 if (file_idx == UINT32_MAX)
3150 continue;
3151 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003152
Greg Clayton526a4ae2012-05-16 22:09:01 +00003153 if (line != 0)
3154 {
3155 LineTable *line_table = sc.comp_unit->GetLineTable();
3156
3157 if (line_table != NULL && line != 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003158 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003159 // We will have already looked up the file index if
3160 // we are searching for inline entries.
3161 if (!check_inlines)
3162 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003163
Greg Clayton526a4ae2012-05-16 22:09:01 +00003164 if (file_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003165 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003166 uint32_t found_line;
3167 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
3168 found_line = sc.line_entry.line;
3169
3170 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003171 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003172 sc.function = NULL;
3173 sc.block = NULL;
3174 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003175 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003176 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
3177 if (file_vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003178 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003179 DWARFDebugInfoEntry *function_die = NULL;
3180 DWARFDebugInfoEntry *block_die = NULL;
3181 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003182
Greg Clayton526a4ae2012-05-16 22:09:01 +00003183 if (function_die != NULL)
3184 {
3185 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
3186 if (sc.function == NULL)
3187 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
3188 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003189
Greg Clayton526a4ae2012-05-16 22:09:01 +00003190 if (sc.function != NULL)
3191 {
3192 Block& block = sc.function->GetBlock (true);
3193
3194 if (block_die != NULL)
3195 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
Jason Molenda60db6e42014-10-16 01:40:16 +00003196 else if (function_die != NULL)
Greg Clayton526a4ae2012-05-16 22:09:01 +00003197 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
3198 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003199 }
3200 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003201
Greg Clayton526a4ae2012-05-16 22:09:01 +00003202 sc_list.Append(sc);
3203 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
3204 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003205 }
3206 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00003207 else if (file_spec_matches_cu_file_spec && !check_inlines)
3208 {
3209 // only append the context if we aren't looking for inline call sites
3210 // by file and line and if the file spec matches that of the compile unit
3211 sc_list.Append(sc);
3212 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003213 }
3214 else if (file_spec_matches_cu_file_spec && !check_inlines)
3215 {
3216 // only append the context if we aren't looking for inline call sites
3217 // by file and line and if the file spec matches that of the compile unit
3218 sc_list.Append(sc);
3219 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003220
Greg Clayton526a4ae2012-05-16 22:09:01 +00003221 if (!check_inlines)
3222 break;
3223 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003224 }
3225 }
3226 }
3227 }
3228 return sc_list.GetSize() - prev_size;
3229}
3230
3231void
3232SymbolFileDWARF::Index ()
3233{
3234 if (m_indexed)
3235 return;
3236 m_indexed = true;
3237 Timer scoped_timer (__PRETTY_FUNCTION__,
3238 "SymbolFileDWARF::Index (%s)",
Jim Ingham4af59612014-12-19 19:20:44 +00003239 GetObjectFile()->GetFileSpec().GetFilename().AsCString("<Unknown>"));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003240
3241 DWARFDebugInfo* debug_info = DebugInfo();
3242 if (debug_info)
3243 {
3244 uint32_t cu_idx = 0;
3245 const uint32_t num_compile_units = GetNumCompileUnits();
3246 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
3247 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003248 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003249
Greg Clayton53eb1c22012-04-02 22:59:12 +00003250 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003251
Greg Clayton53eb1c22012-04-02 22:59:12 +00003252 dwarf_cu->Index (cu_idx,
3253 m_function_basename_index,
3254 m_function_fullname_index,
3255 m_function_method_index,
3256 m_function_selector_index,
3257 m_objc_class_selectors_index,
3258 m_global_index,
3259 m_type_index,
3260 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003261
3262 // Keep memory down by clearing DIEs if this generate function
3263 // caused them to be parsed
3264 if (clear_dies)
Greg Clayton53eb1c22012-04-02 22:59:12 +00003265 dwarf_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003266 }
3267
Greg Claytond4a2b372011-09-12 23:21:58 +00003268 m_function_basename_index.Finalize();
3269 m_function_fullname_index.Finalize();
3270 m_function_method_index.Finalize();
3271 m_function_selector_index.Finalize();
3272 m_objc_class_selectors_index.Finalize();
3273 m_global_index.Finalize();
3274 m_type_index.Finalize();
3275 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003276
Greg Clayton24739922010-10-13 03:15:28 +00003277#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00003278 StreamFile s(stdout, false);
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00003279 s.Printf ("DWARF index for '%s':",
3280 GetObjectFile()->GetFileSpec().GetPath().c_str());
Greg Claytonba2d22d2010-11-13 22:57:37 +00003281 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
3282 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
3283 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
3284 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
3285 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
3286 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00003287 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00003288 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00003289#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003290 }
3291}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003292
3293bool
3294SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
3295{
3296 if (namespace_decl == NULL)
3297 {
3298 // Invalid namespace decl which means we aren't matching only things
3299 // in this symbol file, so return true to indicate it matches this
3300 // symbol file.
3301 return true;
3302 }
3303
3304 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
3305
3306 if (namespace_ast == NULL)
3307 return true; // No AST in the "namespace_decl", return true since it
3308 // could then match any symbol file, including this one
3309
3310 if (namespace_ast == GetClangASTContext().getASTContext())
3311 return true; // The ASTs match, return true
3312
3313 // The namespace AST was valid, and it does not match...
Greg Clayton5160ce52013-03-27 23:08:40 +00003314 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Sean Callananc41e68b2011-10-13 21:08:11 +00003315
3316 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003317 GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00003318
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003319 return false;
3320}
3321
Greg Clayton2506a7a2011-10-12 23:34:26 +00003322bool
3323SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
3324 DWARFCompileUnit* cu,
3325 const DWARFDebugInfoEntry* die)
3326{
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +00003327 // No namespace specified, so the answer is
Greg Clayton2506a7a2011-10-12 23:34:26 +00003328 if (namespace_decl == NULL)
3329 return true;
Sean Callananebe60672011-10-13 21:50:33 +00003330
Greg Clayton5160ce52013-03-27 23:08:40 +00003331 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003332
Greg Clayton437a1352012-04-09 22:43:43 +00003333 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
3334 clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00003335 if (decl_ctx_die)
Greg Clayton437a1352012-04-09 22:43:43 +00003336 {
Greg Clayton2506a7a2011-10-12 23:34:26 +00003337 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
Greg Clayton437a1352012-04-09 22:43:43 +00003338
Greg Clayton2506a7a2011-10-12 23:34:26 +00003339 if (clang_namespace_decl)
3340 {
3341 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00003342 {
3343 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003344 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00003345 return false;
Sean Callananebe60672011-10-13 21:50:33 +00003346 }
3347
Greg Clayton437a1352012-04-09 22:43:43 +00003348 if (clang_namespace_decl == die_clang_decl_ctx)
3349 return true;
3350 else
Greg Clayton2506a7a2011-10-12 23:34:26 +00003351 return false;
Greg Clayton2506a7a2011-10-12 23:34:26 +00003352 }
3353 else
3354 {
3355 // We have a namespace_decl that was not NULL but it contained
3356 // a NULL "clang::NamespaceDecl", so this means the global namespace
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00003357 // So as long the contained decl context DIE isn't a namespace
Greg Clayton2506a7a2011-10-12 23:34:26 +00003358 // we should be ok.
3359 if (decl_ctx_die->Tag() != DW_TAG_namespace)
3360 return true;
3361 }
3362 }
Sean Callananebe60672011-10-13 21:50:33 +00003363
3364 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003365 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00003366
Greg Clayton2506a7a2011-10-12 23:34:26 +00003367 return false;
3368}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003369uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00003370SymbolFileDWARF::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 +00003371{
Greg Clayton5160ce52013-03-27 23:08:40 +00003372 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003373
3374 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003375 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003376 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
3377 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003378 static_cast<const void*>(namespace_decl),
3379 append, max_matches);
3380
Sean Callanan213fdb82011-10-13 01:49:10 +00003381 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00003382 return 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003383
Greg Claytonc685f8e2010-09-15 04:15:46 +00003384 DWARFDebugInfo* info = DebugInfo();
3385 if (info == NULL)
3386 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003387
3388 // If we aren't appending the results to this list, then clear the list
3389 if (!append)
3390 variables.Clear();
3391
3392 // Remember how many variables are in the list before we search in case
3393 // we are appending the results to a variable list.
3394 const uint32_t original_size = variables.GetSize();
3395
Greg Claytond4a2b372011-09-12 23:21:58 +00003396 DIEArray die_offsets;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003397
Greg Clayton97fbc342011-10-20 22:30:33 +00003398 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003399 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003400 if (m_apple_names_ap.get())
3401 {
3402 const char *name_cstr = name.GetCString();
Jim Inghamfa39bb42014-10-25 00:33:55 +00003403 llvm::StringRef basename;
3404 llvm::StringRef context;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003405
Jim Inghamfa39bb42014-10-25 00:33:55 +00003406 if (!CPPLanguageRuntime::ExtractContextAndIdentifier(name_cstr, context, basename))
3407 basename = name_cstr;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003408
Jim Inghamfa39bb42014-10-25 00:33:55 +00003409 m_apple_names_ap->FindByName (basename.data(), die_offsets);
Greg Clayton97fbc342011-10-20 22:30:33 +00003410 }
Greg Clayton7f995132011-10-04 22:41:51 +00003411 }
3412 else
3413 {
3414 // Index the DWARF if we haven't already
3415 if (!m_indexed)
3416 Index ();
3417
3418 m_global_index.Find (name, die_offsets);
3419 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003420
Greg Clayton437a1352012-04-09 22:43:43 +00003421 const size_t num_die_matches = die_offsets.size();
3422 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003423 {
Greg Clayton7f995132011-10-04 22:41:51 +00003424 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003425 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00003426 assert (sc.module_sp);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003427
Greg Claytond4a2b372011-09-12 23:21:58 +00003428 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00003429 DWARFCompileUnit* dwarf_cu = NULL;
3430 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton437a1352012-04-09 22:43:43 +00003431 bool done = false;
3432 for (size_t i=0; i<num_die_matches && !done; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00003433 {
3434 const dw_offset_t die_offset = die_offsets[i];
3435 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003436
Greg Clayton95d87902011-11-11 03:16:25 +00003437 if (die)
3438 {
Greg Clayton437a1352012-04-09 22:43:43 +00003439 switch (die->Tag())
3440 {
3441 default:
3442 case DW_TAG_subprogram:
3443 case DW_TAG_inlined_subroutine:
3444 case DW_TAG_try_block:
3445 case DW_TAG_catch_block:
3446 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003447
Greg Clayton437a1352012-04-09 22:43:43 +00003448 case DW_TAG_variable:
3449 {
3450 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003451
Greg Clayton437a1352012-04-09 22:43:43 +00003452 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3453 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003454
Greg Clayton437a1352012-04-09 22:43:43 +00003455 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003456
Greg Clayton437a1352012-04-09 22:43:43 +00003457 if (variables.GetSize() - original_size >= max_matches)
3458 done = true;
3459 }
3460 break;
3461 }
Greg Clayton95d87902011-11-11 03:16:25 +00003462 }
3463 else
3464 {
3465 if (m_using_apple_tables)
3466 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003467 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
3468 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003469 }
3470 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003471 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003472 }
3473
3474 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003475 const uint32_t num_matches = variables.GetSize() - original_size;
3476 if (log && num_matches > 0)
3477 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003478 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003479 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003480 name.GetCString(),
3481 static_cast<const void*>(namespace_decl),
3482 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00003483 num_matches);
3484 }
3485 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003486}
3487
3488uint32_t
3489SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
3490{
Greg Clayton5160ce52013-03-27 23:08:40 +00003491 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003492
Greg Clayton21f2a492011-10-06 00:09:08 +00003493 if (log)
3494 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003495 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003496 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003497 regex.GetText(), append,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003498 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003499 }
3500
Greg Claytonc685f8e2010-09-15 04:15:46 +00003501 DWARFDebugInfo* info = DebugInfo();
3502 if (info == NULL)
3503 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003504
3505 // If we aren't appending the results to this list, then clear the list
3506 if (!append)
3507 variables.Clear();
3508
3509 // Remember how many variables are in the list before we search in case
3510 // we are appending the results to a variable list.
3511 const uint32_t original_size = variables.GetSize();
3512
Greg Clayton7f995132011-10-04 22:41:51 +00003513 DIEArray die_offsets;
3514
Greg Clayton97fbc342011-10-20 22:30:33 +00003515 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003516 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003517 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00003518 {
3519 DWARFMappedHash::DIEInfoArray hash_data_array;
3520 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
3521 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
3522 }
Greg Clayton7f995132011-10-04 22:41:51 +00003523 }
3524 else
3525 {
3526 // Index the DWARF if we haven't already
3527 if (!m_indexed)
3528 Index ();
3529
3530 m_global_index.Find (regex, die_offsets);
3531 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003532
Greg Claytonc685f8e2010-09-15 04:15:46 +00003533 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003534 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003535 assert (sc.module_sp);
3536
Greg Claytond4a2b372011-09-12 23:21:58 +00003537 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00003538 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003539 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003540 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003541 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003542 DWARFDebugInfo* debug_info = DebugInfo();
3543 for (size_t i=0; i<num_matches; ++i)
3544 {
3545 const dw_offset_t die_offset = die_offsets[i];
3546 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00003547
3548 if (die)
3549 {
3550 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003551
Greg Clayton95d87902011-11-11 03:16:25 +00003552 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003553
Greg Clayton95d87902011-11-11 03:16:25 +00003554 if (variables.GetSize() - original_size >= max_matches)
3555 break;
3556 }
3557 else
3558 {
3559 if (m_using_apple_tables)
3560 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003561 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
3562 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00003563 }
3564 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003565 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003566 }
3567
3568 // Return the number of variable that were appended to the list
3569 return variables.GetSize() - original_size;
3570}
3571
Greg Claytonaa044962011-10-13 00:59:38 +00003572
Jim Ingham4cda6e02011-10-07 22:23:45 +00003573bool
3574SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
3575 DWARFCompileUnit *&dwarf_cu,
Pavel Labatha73d6572015-03-13 10:22:00 +00003576 bool include_inlines,
Jim Ingham4cda6e02011-10-07 22:23:45 +00003577 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00003578{
Greg Claytonaa044962011-10-13 00:59:38 +00003579 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Pavel Labatha73d6572015-03-13 10:22:00 +00003580 return ResolveFunction (dwarf_cu, die, include_inlines, sc_list);
Greg Claytonaa044962011-10-13 00:59:38 +00003581}
3582
3583
3584bool
3585SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
3586 const DWARFDebugInfoEntry *die,
Pavel Labatha73d6572015-03-13 10:22:00 +00003587 bool include_inlines,
Greg Claytonaa044962011-10-13 00:59:38 +00003588 SymbolContextList& sc_list)
3589{
Greg Clayton9e315582011-09-02 04:03:59 +00003590 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00003591
3592 if (die == NULL)
3593 return false;
3594
Jim Ingham4cda6e02011-10-07 22:23:45 +00003595 // If we were passed a die that is not a function, just return false...
Pavel Labatha73d6572015-03-13 10:22:00 +00003596 if (! (die->Tag() == DW_TAG_subprogram || (include_inlines && die->Tag() == DW_TAG_inlined_subroutine)))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003597 return false;
3598
3599 const DWARFDebugInfoEntry* inlined_die = NULL;
3600 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00003601 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003602 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00003603
Jim Ingham4cda6e02011-10-07 22:23:45 +00003604 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003605 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003606 if (die->Tag() == DW_TAG_subprogram)
3607 break;
Greg Clayton9e315582011-09-02 04:03:59 +00003608 }
3609 }
Jason Molenda60db6e42014-10-16 01:40:16 +00003610 assert (die && die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00003611 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003612 {
3613 Address addr;
3614 // Parse all blocks if needed
3615 if (inlined_die)
3616 {
Greg Claytonf7bb1fb2015-01-15 03:13:44 +00003617 Block &function_block = sc.function->GetBlock (true);
3618 sc.block = function_block.FindBlockByID (MakeUserID(inlined_die->GetOffset()));
3619 if (sc.block == NULL)
3620 sc.block = function_block.FindBlockByID (inlined_die->GetOffset());
3621 if (sc.block == NULL || sc.block->GetStartAddress (addr) == false)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003622 addr.Clear();
3623 }
3624 else
3625 {
3626 sc.block = NULL;
3627 addr = sc.function->GetAddressRange().GetBaseAddress();
3628 }
3629
3630 if (addr.IsValid())
3631 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003632 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00003633 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003634 }
3635 }
3636
Greg Claytonaa044962011-10-13 00:59:38 +00003637 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00003638}
3639
Greg Clayton7f995132011-10-04 22:41:51 +00003640void
3641SymbolFileDWARF::FindFunctions (const ConstString &name,
3642 const NameToDIE &name_to_die,
Pavel Labatha73d6572015-03-13 10:22:00 +00003643 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003644 SymbolContextList& sc_list)
3645{
Greg Claytond4a2b372011-09-12 23:21:58 +00003646 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003647 if (name_to_die.Find (name, die_offsets))
3648 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003649 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003650 }
3651}
3652
3653
3654void
3655SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3656 const NameToDIE &name_to_die,
Pavel Labatha73d6572015-03-13 10:22:00 +00003657 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003658 SymbolContextList& sc_list)
3659{
3660 DIEArray die_offsets;
3661 if (name_to_die.Find (regex, die_offsets))
3662 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003663 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003664 }
3665}
3666
3667
3668void
3669SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3670 const DWARFMappedHash::MemoryTable &memory_table,
Pavel Labatha73d6572015-03-13 10:22:00 +00003671 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003672 SymbolContextList& sc_list)
3673{
3674 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00003675 DWARFMappedHash::DIEInfoArray hash_data_array;
3676 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00003677 {
Greg Claytond1767f02011-12-08 02:13:16 +00003678 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Pavel Labatha73d6572015-03-13 10:22:00 +00003679 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003680 }
3681}
3682
3683void
3684SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
Pavel Labatha73d6572015-03-13 10:22:00 +00003685 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003686 SymbolContextList& sc_list)
3687{
3688 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003689 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00003690 {
Greg Clayton7f995132011-10-04 22:41:51 +00003691 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003692 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00003693 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003694 const dw_offset_t die_offset = die_offsets[i];
Pavel Labatha73d6572015-03-13 10:22:00 +00003695 ResolveFunction (die_offset, dwarf_cu, include_inlines, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003696 }
3697 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00003698}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003699
Jim Ingham4cda6e02011-10-07 22:23:45 +00003700bool
3701SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
3702 const DWARFCompileUnit *dwarf_cu,
3703 uint32_t name_type_mask,
3704 const char *partial_name,
3705 const char *base_name_start,
3706 const char *base_name_end)
3707{
Greg Claytonfbea0f62012-11-15 18:05:43 +00003708 // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes:
3709 if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003710 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003711 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
3712 if (!containing_decl_ctx)
3713 return false;
3714
3715 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
3716
Greg Claytonfbea0f62012-11-15 18:05:43 +00003717 if (name_type_mask == eFunctionNameTypeMethod)
3718 {
3719 if (is_cxx_method == false)
3720 return false;
3721 }
3722
3723 if (name_type_mask == eFunctionNameTypeBase)
3724 {
3725 if (is_cxx_method == true)
3726 return false;
3727 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003728 }
3729
3730 // Now we need to check whether the name we got back for this type matches the extra specifications
3731 // that were in the name we're looking up:
3732 if (base_name_start != partial_name || *base_name_end != '\0')
3733 {
3734 // First see if the stuff to the left matches the full name. To do that let's see if
3735 // we can pull out the mips linkage name attribute:
3736
3737 Mangled best_name;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003738 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonfbea0f62012-11-15 18:05:43 +00003739 DWARFFormValue form_value;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003740 die->GetAttributes(this, dwarf_cu, NULL, attributes);
3741 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
Greg Clayton71415542012-12-08 00:24:40 +00003742 if (idx == UINT32_MAX)
3743 idx = attributes.FindAttributeIndex(DW_AT_linkage_name);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003744 if (idx != UINT32_MAX)
3745 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003746 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
3747 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003748 const char *mangled_name = form_value.AsCString(&get_debug_str_data());
3749 if (mangled_name)
3750 best_name.SetValue (ConstString(mangled_name), true);
3751 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003752 }
Greg Claytonfbea0f62012-11-15 18:05:43 +00003753
3754 if (!best_name)
3755 {
3756 idx = attributes.FindAttributeIndex(DW_AT_name);
3757 if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value))
3758 {
3759 const char *name = form_value.AsCString(&get_debug_str_data());
3760 best_name.SetValue (ConstString(name), false);
3761 }
3762 }
3763
3764 if (best_name.GetDemangledName())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003765 {
3766 const char *demangled = best_name.GetDemangledName().GetCString();
3767 if (demangled)
3768 {
3769 std::string name_no_parens(partial_name, base_name_end - partial_name);
Jim Ingham85c13d72012-03-02 02:24:42 +00003770 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str());
3771 if (partial_in_demangled == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003772 return false;
Jim Ingham85c13d72012-03-02 02:24:42 +00003773 else
3774 {
3775 // Sort out the case where our name is something like "Process::Destroy" and the match is
3776 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on
3777 // namespace boundaries...
3778
3779 if (partial_name[0] == ':' && partial_name[1] == ':')
3780 {
3781 // The partial name was already on a namespace boundary so all matches are good.
3782 return true;
3783 }
3784 else if (partial_in_demangled == demangled)
3785 {
3786 // They both start the same, so this is an good match.
3787 return true;
3788 }
3789 else
3790 {
3791 if (partial_in_demangled - demangled == 1)
3792 {
3793 // Only one character difference, can't be a namespace boundary...
3794 return false;
3795 }
3796 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':')
3797 {
3798 // We are on a namespace boundary, so this is also good.
3799 return true;
3800 }
3801 else
3802 return false;
3803 }
3804 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003805 }
3806 }
3807 }
3808
3809 return true;
3810}
Greg Claytonc685f8e2010-09-15 04:15:46 +00003811
Greg Clayton0c5cd902010-06-28 21:30:43 +00003812uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00003813SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00003814 const lldb_private::ClangNamespaceDecl *namespace_decl,
Sean Callanan9df05fb2012-02-10 22:52:19 +00003815 uint32_t name_type_mask,
3816 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00003817 bool append,
3818 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00003819{
3820 Timer scoped_timer (__PRETTY_FUNCTION__,
3821 "SymbolFileDWARF::FindFunctions (name = '%s')",
3822 name.AsCString());
3823
Greg Clayton43fe2172013-04-03 02:00:15 +00003824 // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup()
3825 assert ((name_type_mask & eFunctionNameTypeAuto) == 0);
3826
Greg Clayton5160ce52013-03-27 23:08:40 +00003827 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003828
3829 if (log)
3830 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003831 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003832 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
3833 name.GetCString(),
3834 name_type_mask,
3835 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003836 }
3837
Greg Clayton0c5cd902010-06-28 21:30:43 +00003838 // If we aren't appending the results to this list, then clear the list
3839 if (!append)
3840 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003841
3842 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00003843 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003844
3845 // If name is empty then we won't find anything.
3846 if (name.IsEmpty())
3847 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00003848
3849 // Remember how many sc_list are in the list before we search in case
3850 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00003851
Jim Ingham4cda6e02011-10-07 22:23:45 +00003852 const char *name_cstr = name.GetCString();
Greg Clayton43fe2172013-04-03 02:00:15 +00003853
3854 const uint32_t original_size = sc_list.GetSize();
3855
Jim Ingham4cda6e02011-10-07 22:23:45 +00003856 DWARFDebugInfo* info = DebugInfo();
3857 if (info == NULL)
3858 return 0;
3859
Greg Claytonaa044962011-10-13 00:59:38 +00003860 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton43fe2172013-04-03 02:00:15 +00003861 std::set<const DWARFDebugInfoEntry *> resolved_dies;
Greg Clayton97fbc342011-10-20 22:30:33 +00003862 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00003863 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003864 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003865 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003866
3867 DIEArray die_offsets;
3868
3869 uint32_t num_matches = 0;
3870
Greg Clayton43fe2172013-04-03 02:00:15 +00003871 if (name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00003872 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003873 // If they asked for the full name, match what they typed. At some point we may
3874 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
3875 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00003876 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003877 for (uint32_t i = 0; i < num_matches; i++)
3878 {
Greg Clayton95d87902011-11-11 03:16:25 +00003879 const dw_offset_t die_offset = die_offsets[i];
3880 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00003881 if (die)
3882 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003883 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3884 continue;
3885
Greg Clayton43fe2172013-04-03 02:00:15 +00003886 if (resolved_dies.find(die) == resolved_dies.end())
3887 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003888 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00003889 resolved_dies.insert(die);
3890 }
Greg Claytonaa044962011-10-13 00:59:38 +00003891 }
Greg Clayton95d87902011-11-11 03:16:25 +00003892 else
3893 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003894 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3895 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003896 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003897 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003898 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003899
3900 if (name_type_mask & eFunctionNameTypeSelector)
3901 {
3902 if (namespace_decl && *namespace_decl)
3903 return 0; // no selectors in namespaces
Greg Clayton97fbc342011-10-20 22:30:33 +00003904
Greg Clayton43fe2172013-04-03 02:00:15 +00003905 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3906 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
3907 // and if it is an ObjC method name, we're good.
Greg Clayton97fbc342011-10-20 22:30:33 +00003908
Greg Clayton43fe2172013-04-03 02:00:15 +00003909 for (uint32_t i = 0; i < num_matches; i++)
Greg Clayton97fbc342011-10-20 22:30:33 +00003910 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003911 const dw_offset_t die_offset = die_offsets[i];
3912 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3913 if (die)
Greg Clayton97fbc342011-10-20 22:30:33 +00003914 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003915 const char *die_name = die->GetName(this, dwarf_cu);
3916 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
Greg Clayton97fbc342011-10-20 22:30:33 +00003917 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003918 if (resolved_dies.find(die) == resolved_dies.end())
3919 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003920 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00003921 resolved_dies.insert(die);
3922 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003923 }
3924 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003925 else
3926 {
3927 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3928 die_offset, name_cstr);
3929 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003930 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003931 die_offsets.clear();
3932 }
3933
3934 if (((name_type_mask & eFunctionNameTypeMethod) && !namespace_decl) || name_type_mask & eFunctionNameTypeBase)
3935 {
3936 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
3937 // extract the base name, look that up, and if there is any other information in the name we were
3938 // passed in we have to post-filter based on that.
3939
3940 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
3941 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3942
3943 for (uint32_t i = 0; i < num_matches; i++)
3944 {
3945 const dw_offset_t die_offset = die_offsets[i];
3946 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3947 if (die)
3948 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003949 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3950 continue;
3951
3952 // If we get to here, the die is good, and we should add it:
3953 if (resolved_dies.find(die) == resolved_dies.end())
Pavel Labatha73d6572015-03-13 10:22:00 +00003954 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00003955 {
3956 bool keep_die = true;
3957 if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod))
3958 {
3959 // We are looking for either basenames or methods, so we need to
3960 // trim out the ones we won't want by looking at the type
3961 SymbolContext sc;
3962 if (sc_list.GetLastContext(sc))
3963 {
3964 if (sc.block)
3965 {
3966 // We have an inlined function
3967 }
3968 else if (sc.function)
3969 {
3970 Type *type = sc.function->GetType();
3971
Sean Callananc370a8a2013-09-18 22:59:55 +00003972 if (type)
Greg Clayton43fe2172013-04-03 02:00:15 +00003973 {
Sean Callananc370a8a2013-09-18 22:59:55 +00003974 clang::DeclContext* decl_ctx = GetClangDeclContextContainingTypeUID (type->GetID());
3975 if (decl_ctx->isRecord())
Greg Clayton43fe2172013-04-03 02:00:15 +00003976 {
Sean Callananc370a8a2013-09-18 22:59:55 +00003977 if (name_type_mask & eFunctionNameTypeBase)
3978 {
3979 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3980 keep_die = false;
3981 }
3982 }
3983 else
3984 {
3985 if (name_type_mask & eFunctionNameTypeMethod)
3986 {
3987 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3988 keep_die = false;
3989 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003990 }
3991 }
3992 else
3993 {
Sean Callananc370a8a2013-09-18 22:59:55 +00003994 GetObjectFile()->GetModule()->ReportWarning ("function at die offset 0x%8.8x had no function type",
3995 die_offset);
Greg Clayton43fe2172013-04-03 02:00:15 +00003996 }
3997 }
3998 }
3999 }
4000 if (keep_die)
4001 resolved_dies.insert(die);
4002 }
4003 }
4004 else
4005 {
4006 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
4007 die_offset, name_cstr);
4008 }
4009 }
4010 die_offsets.clear();
Jim Ingham4cda6e02011-10-07 22:23:45 +00004011 }
4012 }
Greg Clayton7f995132011-10-04 22:41:51 +00004013 }
4014 else
4015 {
4016
4017 // Index the DWARF if we haven't already
4018 if (!m_indexed)
4019 Index ();
4020
Greg Clayton7f995132011-10-04 22:41:51 +00004021 if (name_type_mask & eFunctionNameTypeFull)
Matt Kopecd6089962013-05-10 17:53:48 +00004022 {
Pavel Labatha73d6572015-03-13 10:22:00 +00004023 FindFunctions (name, m_function_fullname_index, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00004024
Ed Mastefc7baa02013-09-09 18:00:45 +00004025 // FIXME Temporary workaround for global/anonymous namespace
Robert Flack5cbd3bf2015-05-13 18:20:02 +00004026 // functions debugging FreeBSD and Linux binaries.
Matt Kopecd6089962013-05-10 17:53:48 +00004027 // If we didn't find any functions in the global namespace try
4028 // looking in the basename index but ignore any returned
Robert Flackeb83fab2015-05-15 18:59:59 +00004029 // functions that have a namespace but keep functions which
4030 // have an anonymous namespace
4031 // TODO: The arch in the object file isn't correct for MSVC
4032 // binaries on windows, we should find a way to make it
4033 // correct and handle those symbols as well.
Matt Kopecd6089962013-05-10 17:53:48 +00004034 if (sc_list.GetSize() == 0)
4035 {
Robert Flackeb83fab2015-05-15 18:59:59 +00004036 ArchSpec arch;
4037 if (!namespace_decl &&
4038 GetObjectFile()->GetArchitecture(arch) &&
4039 (arch.GetTriple().isOSFreeBSD() || arch.GetTriple().isOSLinux() ||
4040 arch.GetMachine() == llvm::Triple::hexagon))
Matt Kopecd6089962013-05-10 17:53:48 +00004041 {
Robert Flackeb83fab2015-05-15 18:59:59 +00004042 SymbolContextList temp_sc_list;
4043 FindFunctions (name, m_function_basename_index, include_inlines, temp_sc_list);
Matt Kopecd6089962013-05-10 17:53:48 +00004044 SymbolContext sc;
4045 for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++)
4046 {
4047 if (temp_sc_list.GetContextAtIndex(i, sc))
4048 {
Matt Kopeca189d492013-05-10 22:55:24 +00004049 ConstString mangled_name = sc.GetFunctionName(Mangled::ePreferMangled);
4050 ConstString demangled_name = sc.GetFunctionName(Mangled::ePreferDemangled);
Robert Flackeb83fab2015-05-15 18:59:59 +00004051 // Mangled names on Linux and FreeBSD are of the form:
4052 // _ZN18function_namespace13function_nameEv.
Matt Kopec04e5d582013-05-14 19:00:41 +00004053 if (strncmp(mangled_name.GetCString(), "_ZN", 3) ||
4054 !strncmp(demangled_name.GetCString(), "(anonymous namespace)", 21))
Matt Kopecd6089962013-05-10 17:53:48 +00004055 {
4056 sc_list.Append(sc);
4057 }
4058 }
4059 }
4060 }
4061 }
Matt Kopecd6089962013-05-10 17:53:48 +00004062 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00004063 DIEArray die_offsets;
4064 DWARFCompileUnit *dwarf_cu = NULL;
4065
Greg Clayton43fe2172013-04-03 02:00:15 +00004066 if (name_type_mask & eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00004067 {
Greg Clayton43fe2172013-04-03 02:00:15 +00004068 uint32_t num_base = m_function_basename_index.Find(name, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00004069 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00004070 {
Greg Claytonaa044962011-10-13 00:59:38 +00004071 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
4072 if (die)
4073 {
Sean Callanan213fdb82011-10-13 01:49:10 +00004074 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
4075 continue;
4076
Greg Claytonaa044962011-10-13 00:59:38 +00004077 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00004078 if (resolved_dies.find(die) == resolved_dies.end())
4079 {
Pavel Labatha73d6572015-03-13 10:22:00 +00004080 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00004081 resolved_dies.insert(die);
4082 }
Greg Claytonaa044962011-10-13 00:59:38 +00004083 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00004084 }
4085 die_offsets.clear();
4086 }
4087
Greg Clayton43fe2172013-04-03 02:00:15 +00004088 if (name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00004089 {
Sean Callanan213fdb82011-10-13 01:49:10 +00004090 if (namespace_decl && *namespace_decl)
4091 return 0; // no methods in namespaces
4092
Greg Clayton43fe2172013-04-03 02:00:15 +00004093 uint32_t num_base = m_function_method_index.Find(name, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00004094 {
Greg Claytonaa044962011-10-13 00:59:38 +00004095 for (uint32_t i = 0; i < num_base; i++)
4096 {
4097 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
4098 if (die)
4099 {
Greg Claytonaa044962011-10-13 00:59:38 +00004100 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00004101 if (resolved_dies.find(die) == resolved_dies.end())
4102 {
Pavel Labatha73d6572015-03-13 10:22:00 +00004103 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00004104 resolved_dies.insert(die);
4105 }
Greg Claytonaa044962011-10-13 00:59:38 +00004106 }
4107 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00004108 }
4109 die_offsets.clear();
4110 }
Greg Clayton7f995132011-10-04 22:41:51 +00004111
Greg Clayton43fe2172013-04-03 02:00:15 +00004112 if ((name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00004113 {
Pavel Labatha73d6572015-03-13 10:22:00 +00004114 FindFunctions (name, m_function_selector_index, include_inlines, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00004115 }
4116
Greg Clayton4d01ace2011-09-29 16:58:15 +00004117 }
4118
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004119 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00004120 const uint32_t num_matches = sc_list.GetSize() - original_size;
4121
4122 if (log && num_matches > 0)
4123 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004124 GetObjectFile()->GetModule()->LogMessage (log,
Pavel Labatha73d6572015-03-13 10:22:00 +00004125 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, include_inlines=%d, append=%u, sc_list) => %u",
Greg Clayton437a1352012-04-09 22:43:43 +00004126 name.GetCString(),
4127 name_type_mask,
Pavel Labatha73d6572015-03-13 10:22:00 +00004128 include_inlines,
Greg Clayton437a1352012-04-09 22:43:43 +00004129 append,
4130 num_matches);
4131 }
4132 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004133}
4134
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004135uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00004136SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004137{
4138 Timer scoped_timer (__PRETTY_FUNCTION__,
4139 "SymbolFileDWARF::FindFunctions (regex = '%s')",
4140 regex.GetText());
4141
Greg Clayton5160ce52013-03-27 23:08:40 +00004142 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00004143
4144 if (log)
4145 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004146 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00004147 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
4148 regex.GetText(),
4149 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00004150 }
4151
4152
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004153 // If we aren't appending the results to this list, then clear the list
4154 if (!append)
4155 sc_list.Clear();
4156
4157 // Remember how many sc_list are in the list before we search in case
4158 // we are appending the results to a variable list.
4159 uint32_t original_size = sc_list.GetSize();
4160
Greg Clayton97fbc342011-10-20 22:30:33 +00004161 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004162 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004163 if (m_apple_names_ap.get())
Pavel Labatha73d6572015-03-13 10:22:00 +00004164 FindFunctions (regex, *m_apple_names_ap, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00004165 }
4166 else
4167 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00004168 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00004169 if (!m_indexed)
4170 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004171
Pavel Labatha73d6572015-03-13 10:22:00 +00004172 FindFunctions (regex, m_function_basename_index, include_inlines, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004173
Pavel Labatha73d6572015-03-13 10:22:00 +00004174 FindFunctions (regex, m_function_fullname_index, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00004175 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004176
4177 // Return the number of variable that were appended to the list
4178 return sc_list.GetSize() - original_size;
4179}
Jim Ingham318c9f22011-08-26 19:44:13 +00004180
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004181uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00004182SymbolFileDWARF::FindTypes (const SymbolContext& sc,
4183 const ConstString &name,
4184 const lldb_private::ClangNamespaceDecl *namespace_decl,
4185 bool append,
4186 uint32_t max_matches,
4187 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004188{
Greg Claytonc685f8e2010-09-15 04:15:46 +00004189 DWARFDebugInfo* info = DebugInfo();
4190 if (info == NULL)
4191 return 0;
4192
Greg Clayton5160ce52013-03-27 23:08:40 +00004193 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004194
Greg Clayton21f2a492011-10-06 00:09:08 +00004195 if (log)
4196 {
Greg Clayton437a1352012-04-09 22:43:43 +00004197 if (namespace_decl)
Greg Clayton5160ce52013-03-27 23:08:40 +00004198 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004199 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)",
4200 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004201 static_cast<void*>(namespace_decl->GetNamespaceDecl()),
Greg Clayton437a1352012-04-09 22:43:43 +00004202 namespace_decl->GetQualifiedName().c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004203 append, max_matches);
Greg Clayton437a1352012-04-09 22:43:43 +00004204 else
Greg Clayton5160ce52013-03-27 23:08:40 +00004205 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004206 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004207 name.GetCString(), append,
Greg Clayton437a1352012-04-09 22:43:43 +00004208 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00004209 }
4210
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004211 // If we aren't appending the results to this list, then clear the list
4212 if (!append)
4213 types.Clear();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004214
Sean Callanan213fdb82011-10-13 01:49:10 +00004215 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00004216 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004217
Greg Claytond4a2b372011-09-12 23:21:58 +00004218 DIEArray die_offsets;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004219
Greg Clayton97fbc342011-10-20 22:30:33 +00004220 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004221 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004222 if (m_apple_types_ap.get())
4223 {
4224 const char *name_cstr = name.GetCString();
4225 m_apple_types_ap->FindByName (name_cstr, die_offsets);
4226 }
Greg Clayton7f995132011-10-04 22:41:51 +00004227 }
4228 else
4229 {
4230 if (!m_indexed)
4231 Index ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004232
Greg Clayton7f995132011-10-04 22:41:51 +00004233 m_type_index.Find (name, die_offsets);
4234 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004235
Greg Clayton437a1352012-04-09 22:43:43 +00004236 const size_t num_die_matches = die_offsets.size();
Greg Clayton7f995132011-10-04 22:41:51 +00004237
Greg Clayton437a1352012-04-09 22:43:43 +00004238 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004239 {
Greg Clayton7f995132011-10-04 22:41:51 +00004240 const uint32_t initial_types_size = types.GetSize();
4241 DWARFCompileUnit* dwarf_cu = NULL;
4242 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00004243 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00004244 for (size_t i=0; i<num_die_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004245 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004246 const dw_offset_t die_offset = die_offsets[i];
4247 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
4248
Greg Clayton95d87902011-11-11 03:16:25 +00004249 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00004250 {
Greg Clayton95d87902011-11-11 03:16:25 +00004251 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
4252 continue;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004253
Greg Clayton95d87902011-11-11 03:16:25 +00004254 Type *matching_type = ResolveType (dwarf_cu, die);
4255 if (matching_type)
4256 {
4257 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00004258 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00004259 if (types.GetSize() >= max_matches)
4260 break;
4261 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00004262 }
Greg Clayton95d87902011-11-11 03:16:25 +00004263 else
4264 {
4265 if (m_using_apple_tables)
4266 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004267 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4268 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004269 }
4270 }
4271
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004272 }
Greg Clayton437a1352012-04-09 22:43:43 +00004273 const uint32_t num_matches = types.GetSize() - initial_types_size;
4274 if (log && num_matches)
4275 {
4276 if (namespace_decl)
4277 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004278 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004279 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u",
4280 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004281 static_cast<void*>(namespace_decl->GetNamespaceDecl()),
Greg Clayton437a1352012-04-09 22:43:43 +00004282 namespace_decl->GetQualifiedName().c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004283 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00004284 num_matches);
4285 }
4286 else
4287 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004288 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004289 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u",
4290 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004291 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00004292 num_matches);
4293 }
4294 }
4295 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004296 }
Greg Clayton7f995132011-10-04 22:41:51 +00004297 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004298}
4299
4300
Greg Clayton526e5af2010-11-13 03:52:47 +00004301ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00004302SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00004303 const ConstString &name,
4304 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004305{
Greg Clayton5160ce52013-03-27 23:08:40 +00004306 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00004307
4308 if (log)
4309 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004310 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00004311 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
4312 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00004313 }
Sean Callanan213fdb82011-10-13 01:49:10 +00004314
4315 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00004316 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00004317
Greg Clayton526e5af2010-11-13 03:52:47 +00004318 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004319 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00004320 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00004321 {
Greg Clayton7f995132011-10-04 22:41:51 +00004322 DIEArray die_offsets;
4323
Greg Clayton526e5af2010-11-13 03:52:47 +00004324 // Index if we already haven't to make sure the compile units
4325 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00004326 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004327 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004328 if (m_apple_namespaces_ap.get())
4329 {
4330 const char *name_cstr = name.GetCString();
4331 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
4332 }
Greg Clayton7f995132011-10-04 22:41:51 +00004333 }
4334 else
4335 {
4336 if (!m_indexed)
4337 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00004338
Greg Clayton7f995132011-10-04 22:41:51 +00004339 m_namespace_index.Find (name, die_offsets);
4340 }
Greg Claytond4a2b372011-09-12 23:21:58 +00004341
4342 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00004343 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00004344 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00004345 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00004346 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004347 DWARFDebugInfo* debug_info = DebugInfo();
4348 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00004349 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004350 const dw_offset_t die_offset = die_offsets[i];
4351 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00004352
Greg Clayton95d87902011-11-11 03:16:25 +00004353 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00004354 {
Greg Clayton95d87902011-11-11 03:16:25 +00004355 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
4356 continue;
4357
4358 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
4359 if (clang_namespace_decl)
4360 {
4361 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
4362 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
Greg Claytond1767f02011-12-08 02:13:16 +00004363 break;
Greg Clayton95d87902011-11-11 03:16:25 +00004364 }
Greg Claytond4a2b372011-09-12 23:21:58 +00004365 }
Greg Clayton95d87902011-11-11 03:16:25 +00004366 else
4367 {
4368 if (m_using_apple_tables)
4369 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004370 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
4371 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004372 }
4373 }
4374
Greg Clayton526e5af2010-11-13 03:52:47 +00004375 }
4376 }
Greg Clayton96d7d742010-11-10 23:42:09 +00004377 }
Greg Clayton437a1352012-04-09 22:43:43 +00004378 if (log && namespace_decl.GetNamespaceDecl())
4379 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004380 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004381 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"",
4382 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004383 static_cast<const void*>(namespace_decl.GetNamespaceDecl()),
Greg Clayton437a1352012-04-09 22:43:43 +00004384 namespace_decl.GetQualifiedName().c_str());
4385 }
4386
Greg Clayton526e5af2010-11-13 03:52:47 +00004387 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004388}
4389
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004390uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004391SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004392{
4393 // Remember how many sc_list are in the list before we search in case
4394 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004395 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004396
4397 const uint32_t num_die_offsets = die_offsets.size();
4398 // Parse all of the types we found from the pubtypes matches
4399 uint32_t i;
4400 uint32_t num_matches = 0;
4401 for (i = 0; i < num_die_offsets; ++i)
4402 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004403 Type *matching_type = ResolveTypeUID (die_offsets[i]);
4404 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004405 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004406 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00004407 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004408 ++num_matches;
4409 if (num_matches >= max_matches)
4410 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004411 }
4412 }
4413
4414 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004415 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004416}
4417
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004418
4419size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00004420SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
4421 clang::DeclContext *containing_decl_ctx,
Greg Clayton5113dc82011-08-12 06:47:54 +00004422 DWARFCompileUnit* dwarf_cu,
4423 const DWARFDebugInfoEntry *parent_die,
4424 bool skip_artificial,
4425 bool &is_static,
Greg Clayton03969752014-02-24 18:53:11 +00004426 bool &is_variadic,
Greg Clayton57ee3062013-07-11 22:46:58 +00004427 std::vector<ClangASTType>& function_param_types,
Greg Clayton5113dc82011-08-12 06:47:54 +00004428 std::vector<clang::ParmVarDecl*>& function_param_decls,
Greg Claytond20deac2014-04-04 18:15:18 +00004429 unsigned &type_quals) // ,
4430 // ClangASTContext::TemplateParameterInfos &template_param_infos))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004431{
4432 if (parent_die == NULL)
4433 return 0;
4434
Todd Fialaee8bfc62014-09-11 17:29:12 +00004435 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Claytond88d7592010-09-15 08:33:30 +00004436
Greg Clayton7fedea22010-11-16 02:10:54 +00004437 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004438 const DWARFDebugInfoEntry *die;
4439 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4440 {
4441 dw_tag_t tag = die->Tag();
4442 switch (tag)
4443 {
4444 case DW_TAG_formal_parameter:
4445 {
4446 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004447 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004448 if (num_attributes > 0)
4449 {
4450 const char *name = NULL;
4451 Declaration decl;
4452 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00004453 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004454 // one of None, Auto, Register, Extern, Static, PrivateExtern
4455
Sean Callanane2ef6e32010-09-23 03:01:22 +00004456 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004457 uint32_t i;
4458 for (i=0; i<num_attributes; ++i)
4459 {
4460 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4461 DWARFFormValue form_value;
4462 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4463 {
4464 switch (attr)
4465 {
4466 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4467 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4468 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4469 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00004470 case DW_AT_type: param_type_die_offset = form_value.Reference(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00004471 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004472 case DW_AT_location:
4473 // if (form_value.BlockData())
4474 // {
Ed Masteeeae7212013-10-24 20:43:47 +00004475 // const DWARFDataExtractor& debug_info_data = debug_info();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004476 // uint32_t block_length = form_value.Unsigned();
Ed Masteeeae7212013-10-24 20:43:47 +00004477 // DWARFDataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004478 // }
4479 // else
4480 // {
4481 // }
4482 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004483 case DW_AT_const_value:
4484 case DW_AT_default_value:
4485 case DW_AT_description:
4486 case DW_AT_endianity:
4487 case DW_AT_is_optional:
4488 case DW_AT_segment:
4489 case DW_AT_variable_parameter:
4490 default:
4491 case DW_AT_abstract_origin:
4492 case DW_AT_sibling:
4493 break;
4494 }
4495 }
4496 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00004497
Greg Clayton0fffff52010-09-24 05:15:53 +00004498 bool skip = false;
4499 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004500 {
Greg Clayton0fffff52010-09-24 05:15:53 +00004501 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00004502 {
4503 // In order to determine if a C++ member function is
4504 // "const" we have to look at the const-ness of "this"...
4505 // Ugly, but that
4506 if (arg_idx == 0)
4507 {
Greg Claytonf0705c82011-10-22 03:33:13 +00004508 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00004509 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004510 // Often times compilers omit the "this" name for the
4511 // specification DIEs, so we can't rely upon the name
4512 // being in the formal parameter DIE...
4513 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00004514 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004515 Type *this_type = ResolveTypeUID (param_type_die_offset);
4516 if (this_type)
4517 {
4518 uint32_t encoding_mask = this_type->GetEncodingMask();
4519 if (encoding_mask & Type::eEncodingIsPointerUID)
4520 {
4521 is_static = false;
4522
4523 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
4524 type_quals |= clang::Qualifiers::Const;
4525 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
4526 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00004527 }
4528 }
4529 }
4530 }
4531 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004532 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00004533 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004534 else
4535 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004536
Greg Clayton0fffff52010-09-24 05:15:53 +00004537 // HACK: Objective C formal parameters "self" and "_cmd"
4538 // are not marked as artificial in the DWARF...
Greg Clayton53eb1c22012-04-02 22:59:12 +00004539 CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
4540 if (comp_unit)
Greg Clayton0fffff52010-09-24 05:15:53 +00004541 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004542 switch (comp_unit->GetLanguage())
4543 {
4544 case eLanguageTypeObjC:
4545 case eLanguageTypeObjC_plus_plus:
4546 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
4547 skip = true;
4548 break;
4549 default:
4550 break;
4551 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004552 }
4553 }
4554 }
4555
4556 if (!skip)
4557 {
4558 Type *type = ResolveTypeUID(param_type_die_offset);
4559 if (type)
4560 {
Greg Claytonc93237c2010-10-01 20:48:32 +00004561 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00004562
Greg Clayton42ce2f32011-12-12 21:50:19 +00004563 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
4564 type->GetClangForwardType(),
4565 storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00004566 assert(param_var_decl);
4567 function_param_decls.push_back(param_var_decl);
Sean Callanan60217122012-04-13 00:10:03 +00004568
Greg Claytond0029442013-03-27 01:48:02 +00004569 GetClangASTContext().SetMetadataAsUserID (param_var_decl, MakeUserID(die->GetOffset()));
Greg Clayton0fffff52010-09-24 05:15:53 +00004570 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004571 }
4572 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004573 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004574 }
4575 break;
4576
Greg Clayton03969752014-02-24 18:53:11 +00004577 case DW_TAG_unspecified_parameters:
4578 is_variadic = true;
4579 break;
4580
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004581 case DW_TAG_template_type_parameter:
4582 case DW_TAG_template_value_parameter:
Greg Claytond20deac2014-04-04 18:15:18 +00004583 // The one caller of this was never using the template_param_infos,
4584 // and the local variable was taking up a large amount of stack space
4585 // in SymbolFileDWARF::ParseType() so this was removed. If we ever need
4586 // the template params back, we can add them back.
4587 // ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004588 break;
4589
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004590 default:
4591 break;
4592 }
4593 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004594 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004595}
4596
4597size_t
4598SymbolFileDWARF::ParseChildEnumerators
4599(
4600 const SymbolContext& sc,
Greg Clayton57ee3062013-07-11 22:46:58 +00004601 lldb_private::ClangASTType &clang_type,
Greg Clayton3e067532013-03-05 23:54:39 +00004602 bool is_signed,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004603 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00004604 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004605 const DWARFDebugInfoEntry *parent_die
4606)
4607{
4608 if (parent_die == NULL)
4609 return 0;
4610
4611 size_t enumerators_added = 0;
4612 const DWARFDebugInfoEntry *die;
Todd Fialaee8bfc62014-09-11 17:29:12 +00004613 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Claytond88d7592010-09-15 08:33:30 +00004614
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004615 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4616 {
4617 const dw_tag_t tag = die->Tag();
4618 if (tag == DW_TAG_enumerator)
4619 {
4620 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004621 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004622 if (num_child_attributes > 0)
4623 {
4624 const char *name = NULL;
4625 bool got_value = false;
4626 int64_t enum_value = 0;
4627 Declaration decl;
4628
4629 uint32_t i;
4630 for (i=0; i<num_child_attributes; ++i)
4631 {
4632 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4633 DWARFFormValue form_value;
4634 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4635 {
4636 switch (attr)
4637 {
4638 case DW_AT_const_value:
4639 got_value = true;
Greg Clayton3e067532013-03-05 23:54:39 +00004640 if (is_signed)
4641 enum_value = form_value.Signed();
4642 else
4643 enum_value = form_value.Unsigned();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004644 break;
4645
4646 case DW_AT_name:
4647 name = form_value.AsCString(&get_debug_str_data());
4648 break;
4649
4650 case DW_AT_description:
4651 default:
4652 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4653 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4654 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4655 case DW_AT_sibling:
4656 break;
4657 }
4658 }
4659 }
4660
4661 if (name && name[0] && got_value)
4662 {
Pavel Labathc7c30eb2015-06-08 23:38:06 +00004663 clang_type.AddEnumerationValueToEnumerationType (clang_type.GetEnumerationIntegerType(),
4664 decl,
4665 name,
4666 enum_value,
4667 enumerator_byte_size * 8);
4668 ++enumerators_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004669 }
4670 }
4671 }
4672 }
4673 return enumerators_added;
4674}
4675
4676void
4677SymbolFileDWARF::ParseChildArrayInfo
4678(
4679 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004680 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004681 const DWARFDebugInfoEntry *parent_die,
4682 int64_t& first_index,
4683 std::vector<uint64_t>& element_orders,
4684 uint32_t& byte_stride,
4685 uint32_t& bit_stride
4686)
4687{
4688 if (parent_die == NULL)
4689 return;
4690
4691 const DWARFDebugInfoEntry *die;
Todd Fialaee8bfc62014-09-11 17:29:12 +00004692 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004693 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4694 {
4695 const dw_tag_t tag = die->Tag();
4696 switch (tag)
4697 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004698 case DW_TAG_subrange_type:
4699 {
4700 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004701 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004702 if (num_child_attributes > 0)
4703 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004704 uint64_t num_elements = 0;
4705 uint64_t lower_bound = 0;
4706 uint64_t upper_bound = 0;
Greg Clayton4ef877f2012-12-06 02:33:54 +00004707 bool upper_bound_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004708 uint32_t i;
4709 for (i=0; i<num_child_attributes; ++i)
4710 {
4711 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4712 DWARFFormValue form_value;
4713 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4714 {
4715 switch (attr)
4716 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004717 case DW_AT_name:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004718 break;
4719
4720 case DW_AT_count:
4721 num_elements = form_value.Unsigned();
4722 break;
4723
4724 case DW_AT_bit_stride:
4725 bit_stride = form_value.Unsigned();
4726 break;
4727
4728 case DW_AT_byte_stride:
4729 byte_stride = form_value.Unsigned();
4730 break;
4731
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004732 case DW_AT_lower_bound:
4733 lower_bound = form_value.Unsigned();
4734 break;
4735
4736 case DW_AT_upper_bound:
Greg Clayton4ef877f2012-12-06 02:33:54 +00004737 upper_bound_valid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004738 upper_bound = form_value.Unsigned();
4739 break;
4740
4741 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004742 case DW_AT_abstract_origin:
4743 case DW_AT_accessibility:
4744 case DW_AT_allocated:
4745 case DW_AT_associated:
4746 case DW_AT_data_location:
4747 case DW_AT_declaration:
4748 case DW_AT_description:
4749 case DW_AT_sibling:
4750 case DW_AT_threads_scaled:
4751 case DW_AT_type:
4752 case DW_AT_visibility:
4753 break;
4754 }
4755 }
4756 }
4757
Greg Claytone6a07792012-12-05 21:59:39 +00004758 if (num_elements == 0)
4759 {
Greg Clayton4ef877f2012-12-06 02:33:54 +00004760 if (upper_bound_valid && upper_bound >= lower_bound)
Greg Claytone6a07792012-12-05 21:59:39 +00004761 num_elements = upper_bound - lower_bound + 1;
4762 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004763
Sean Callananec979ba2012-10-22 23:56:48 +00004764 element_orders.push_back (num_elements);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004765 }
4766 }
4767 break;
4768 }
4769 }
4770}
4771
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004772TypeSP
Greg Clayton53eb1c22012-04-02 22:59:12 +00004773SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004774{
4775 TypeSP type_sp;
4776 if (die != NULL)
4777 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004778 assert(dwarf_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00004779 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004780 if (type_ptr == NULL)
4781 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004782 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu);
Greg Claytonca512b32011-01-14 04:54:56 +00004783 assert (lldb_cu);
4784 SymbolContext sc(lldb_cu);
Greg Clayton53eb1c22012-04-02 22:59:12 +00004785 type_sp = ParseType(sc, dwarf_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004786 }
4787 else if (type_ptr != DIE_IS_BEING_PARSED)
4788 {
4789 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00004790 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004791 }
4792
4793 }
4794 return type_sp;
4795}
4796
4797clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00004798SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004799{
4800 if (die_offset != DW_INVALID_OFFSET)
4801 {
4802 DWARFCompileUnitSP cu_sp;
4803 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004804 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004805 }
4806 return NULL;
4807}
4808
Sean Callanan72e49402011-08-05 23:43:37 +00004809clang::DeclContext *
4810SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
4811{
4812 if (die_offset != DW_INVALID_OFFSET)
4813 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004814 DWARFDebugInfo* debug_info = DebugInfo();
4815 if (debug_info)
4816 {
4817 DWARFCompileUnitSP cu_sp;
4818 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
4819 if (die)
4820 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
4821 }
Sean Callanan72e49402011-08-05 23:43:37 +00004822 }
4823 return NULL;
4824}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004825
Greg Clayton96d7d742010-11-10 23:42:09 +00004826clang::NamespaceDecl *
Greg Clayton53eb1c22012-04-02 22:59:12 +00004827SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die)
Greg Clayton96d7d742010-11-10 23:42:09 +00004828{
Greg Clayton030a2042011-10-14 21:34:45 +00004829 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00004830 {
Greg Clayton030a2042011-10-14 21:34:45 +00004831 // See if we already parsed this namespace DIE and associated it with a
4832 // uniqued namespace declaration
4833 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
4834 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004835 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00004836 else
4837 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004838 const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL);
4839 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00004840 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
Greg Clayton5160ce52013-03-27 23:08:40 +00004841 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton9d3d6882011-10-31 23:51:19 +00004842 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00004843 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00004844 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00004845 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004846 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00004847 "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 +00004848 static_cast<void*>(GetClangASTContext().getASTContext()),
Greg Claytone38a5ed2012-01-05 03:57:59 +00004849 MakeUserID(die->GetOffset()),
4850 namespace_name,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004851 static_cast<void*>(namespace_decl),
4852 static_cast<void*>(namespace_decl->getOriginalNamespace()));
Greg Clayton030a2042011-10-14 21:34:45 +00004853 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004854 else
4855 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004856 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00004857 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004858 static_cast<void*>(GetClangASTContext().getASTContext()),
Greg Claytone38a5ed2012-01-05 03:57:59 +00004859 MakeUserID(die->GetOffset()),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004860 static_cast<void*>(namespace_decl),
4861 static_cast<void*>(namespace_decl->getOriginalNamespace()));
Greg Clayton9d3d6882011-10-31 23:51:19 +00004862 }
Greg Clayton030a2042011-10-14 21:34:45 +00004863 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004864
4865 if (namespace_decl)
4866 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
4867 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004868 }
4869 }
4870 return NULL;
4871}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004872
4873clang::DeclContext *
Greg Claytoncab36a32011-12-08 05:16:30 +00004874SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Sean Callanan72e49402011-08-05 23:43:37 +00004875{
Greg Clayton5cf58b92011-10-05 22:22:08 +00004876 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4877 if (clang_decl_ctx)
4878 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004879 // If this DIE has a specification, or an abstract origin, then trace to those.
4880
Greg Claytoncab36a32011-12-08 05:16:30 +00004881 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004882 if (die_offset != DW_INVALID_OFFSET)
4883 return GetClangDeclContextForDIEOffset (sc, die_offset);
4884
Greg Claytoncab36a32011-12-08 05:16:30 +00004885 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004886 if (die_offset != DW_INVALID_OFFSET)
4887 return GetClangDeclContextForDIEOffset (sc, die_offset);
4888
Greg Clayton5160ce52013-03-27 23:08:40 +00004889 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00004890 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004891 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 +00004892 // This is the DIE we want. Parse it, then query our map.
Greg Claytoncab36a32011-12-08 05:16:30 +00004893 bool assert_not_being_parsed = true;
4894 ResolveTypeUID (cu, die, assert_not_being_parsed);
4895
Greg Clayton5cf58b92011-10-05 22:22:08 +00004896 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4897
4898 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004899}
4900
4901clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00004902SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004903{
Greg Claytonca512b32011-01-14 04:54:56 +00004904 if (m_clang_tu_decl == NULL)
4905 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004906
Greg Clayton2bc22f82011-09-30 03:20:47 +00004907 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004908
4909 if (decl_ctx_die_copy)
4910 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00004911
4912 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004913 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00004914
Greg Clayton2bc22f82011-09-30 03:20:47 +00004915 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
4916 if (pos != m_die_to_decl_ctx.end())
4917 return pos->second;
4918
4919 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004920 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004921 case DW_TAG_compile_unit:
4922 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004923
Greg Clayton2bc22f82011-09-30 03:20:47 +00004924 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00004925 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00004926 break;
4927
4928 case DW_TAG_structure_type:
4929 case DW_TAG_union_type:
4930 case DW_TAG_class_type:
4931 {
4932 Type* type = ResolveType (cu, decl_ctx_die);
4933 if (type)
4934 {
Pavel Labathc7c30eb2015-06-08 23:38:06 +00004935 clang::DeclContext *decl_ctx = type->GetClangForwardType().GetDeclContextForType ();
Greg Clayton2bc22f82011-09-30 03:20:47 +00004936 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00004937 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004938 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
4939 if (decl_ctx)
4940 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00004941 }
4942 }
Greg Claytonca512b32011-01-14 04:54:56 +00004943 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00004944 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004945
Greg Clayton2bc22f82011-09-30 03:20:47 +00004946 default:
4947 break;
Greg Claytonca512b32011-01-14 04:54:56 +00004948 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004949 }
Greg Clayton7a345282010-11-09 23:46:37 +00004950 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004951}
4952
Greg Clayton2bc22f82011-09-30 03:20:47 +00004953
4954const DWARFDebugInfoEntry *
4955SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4956{
4957 if (cu && die)
4958 {
4959 const DWARFDebugInfoEntry * const decl_die = die;
4960
4961 while (die != NULL)
4962 {
4963 // If this is the original DIE that we are searching for a declaration
4964 // for, then don't look in the cache as we don't want our own decl
4965 // context to be our decl context...
4966 if (decl_die != die)
4967 {
4968 switch (die->Tag())
4969 {
4970 case DW_TAG_compile_unit:
4971 case DW_TAG_namespace:
4972 case DW_TAG_structure_type:
4973 case DW_TAG_union_type:
4974 case DW_TAG_class_type:
4975 return die;
4976
4977 default:
4978 break;
4979 }
4980 }
4981
4982 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4983 if (die_offset != DW_INVALID_OFFSET)
4984 {
4985 DWARFCompileUnit *spec_cu = cu;
4986 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
4987 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
4988 if (spec_die_decl_ctx_die)
4989 return spec_die_decl_ctx_die;
4990 }
4991
4992 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
4993 if (die_offset != DW_INVALID_OFFSET)
4994 {
4995 DWARFCompileUnit *abs_cu = cu;
4996 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
4997 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
4998 if (abs_die_decl_ctx_die)
4999 return abs_die_decl_ctx_die;
5000 }
5001
5002 die = die->GetParent();
5003 }
5004 }
5005 return NULL;
5006}
5007
5008
Greg Clayton901c5ca2011-12-03 04:40:03 +00005009Symbol *
5010SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
5011{
5012 Symbol *objc_class_symbol = NULL;
5013 if (m_obj_file)
5014 {
Greg Clayton3046e662013-07-10 01:23:25 +00005015 Symtab *symtab = m_obj_file->GetSymtab ();
Greg Clayton901c5ca2011-12-03 04:40:03 +00005016 if (symtab)
5017 {
5018 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
5019 eSymbolTypeObjCClass,
5020 Symtab::eDebugNo,
5021 Symtab::eVisibilityAny);
5022 }
5023 }
5024 return objc_class_symbol;
5025}
5026
Greg Claytonc7f03b62012-01-12 04:33:28 +00005027// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
5028// then we can end up looking through all class types for a complete type and never find
5029// the full definition. We need to know if this attribute is supported, so we determine
5030// this here and cache th result. We also need to worry about the debug map DWARF file
5031// if we are doing darwin DWARF in .o file debugging.
5032bool
5033SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
5034{
5035 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
5036 {
5037 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
5038 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
5039 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
5040 else
5041 {
5042 DWARFDebugInfo* debug_info = DebugInfo();
5043 const uint32_t num_compile_units = GetNumCompileUnits();
5044 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
5045 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00005046 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
5047 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00005048 {
5049 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
5050 break;
5051 }
5052 }
5053 }
Greg Clayton1f746072012-08-29 21:13:06 +00005054 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00005055 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
5056 }
5057 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
5058}
Greg Clayton901c5ca2011-12-03 04:40:03 +00005059
5060// This function can be used when a DIE is found that is a forward declaration
5061// DIE and we want to try and find a type that has the complete definition.
5062TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00005063SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
5064 const ConstString &type_name,
5065 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00005066{
5067
5068 TypeSP type_sp;
5069
Greg Claytonc7f03b62012-01-12 04:33:28 +00005070 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00005071 return type_sp;
5072
5073 DIEArray die_offsets;
5074
5075 if (m_using_apple_tables)
5076 {
5077 if (m_apple_types_ap.get())
5078 {
5079 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00005080 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00005081 }
5082 }
5083 else
5084 {
5085 if (!m_indexed)
5086 Index ();
5087
5088 m_type_index.Find (type_name, die_offsets);
5089 }
5090
Greg Clayton901c5ca2011-12-03 04:40:03 +00005091 const size_t num_matches = die_offsets.size();
5092
Greg Clayton901c5ca2011-12-03 04:40:03 +00005093 DWARFCompileUnit* type_cu = NULL;
5094 const DWARFDebugInfoEntry* type_die = NULL;
5095 if (num_matches)
5096 {
5097 DWARFDebugInfo* debug_info = DebugInfo();
5098 for (size_t i=0; i<num_matches; ++i)
5099 {
5100 const dw_offset_t die_offset = die_offsets[i];
5101 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
5102
5103 if (type_die)
5104 {
5105 bool try_resolving_type = false;
5106
5107 // Don't try and resolve the DIE we are looking for with the DIE itself!
5108 if (type_die != die)
5109 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005110 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00005111 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005112 case DW_TAG_class_type:
5113 case DW_TAG_structure_type:
5114 try_resolving_type = true;
5115 break;
5116 default:
5117 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00005118 }
5119 }
5120
5121 if (try_resolving_type)
5122 {
Ed Maste4c24b122013-10-17 20:13:14 +00005123 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
5124 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00005125
5126 if (try_resolving_type)
5127 {
5128 Type *resolved_type = ResolveType (type_cu, type_die, false);
5129 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5130 {
Ed Mastea0191d12013-10-17 20:42:56 +00005131 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 +00005132 MakeUserID(die->GetOffset()),
Jim Ingham4af59612014-12-19 19:20:44 +00005133 m_obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>"),
Greg Clayton901c5ca2011-12-03 04:40:03 +00005134 MakeUserID(type_die->GetOffset()),
5135 MakeUserID(type_cu->GetOffset()));
5136
Greg Claytonc7f03b62012-01-12 04:33:28 +00005137 if (die)
5138 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00005139 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00005140 break;
5141 }
5142 }
5143 }
5144 }
5145 else
5146 {
5147 if (m_using_apple_tables)
5148 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005149 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5150 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00005151 }
5152 }
5153
5154 }
5155 }
5156 return type_sp;
5157}
5158
Greg Claytona8022fa2012-04-24 21:22:41 +00005159
Greg Clayton80c26302012-02-05 06:12:47 +00005160//----------------------------------------------------------------------
5161// This function helps to ensure that the declaration contexts match for
5162// two different DIEs. Often times debug information will refer to a
5163// forward declaration of a type (the equivalent of "struct my_struct;".
5164// There will often be a declaration of that type elsewhere that has the
5165// full definition. When we go looking for the full type "my_struct", we
5166// will find one or more matches in the accelerator tables and we will
5167// then need to make sure the type was in the same declaration context
5168// as the original DIE. This function can efficiently compare two DIEs
5169// and will return true when the declaration context matches, and false
5170// when they don't.
5171//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00005172bool
5173SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
5174 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
5175{
Greg Claytona8022fa2012-04-24 21:22:41 +00005176 if (die1 == die2)
5177 return true;
5178
5179#if defined (LLDB_CONFIGURATION_DEBUG)
5180 // You can't and shouldn't call this function with a compile unit from
5181 // two different SymbolFileDWARF instances.
5182 assert (DebugInfo()->ContainsCompileUnit (cu1));
5183 assert (DebugInfo()->ContainsCompileUnit (cu2));
5184#endif
5185
Greg Clayton890ff562012-02-02 05:48:16 +00005186 DWARFDIECollection decl_ctx_1;
5187 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00005188 //The declaration DIE stack is a stack of the declaration context
5189 // DIEs all the way back to the compile unit. If a type "T" is
5190 // declared inside a class "B", and class "B" is declared inside
5191 // a class "A" and class "A" is in a namespace "lldb", and the
5192 // namespace is in a compile unit, there will be a stack of DIEs:
5193 //
5194 // [0] DW_TAG_class_type for "B"
5195 // [1] DW_TAG_class_type for "A"
5196 // [2] DW_TAG_namespace for "lldb"
5197 // [3] DW_TAG_compile_unit for the source file.
5198 //
5199 // We grab both contexts and make sure that everything matches
5200 // all the way back to the compiler unit.
5201
5202 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00005203 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00005204 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00005205 // Make sure the context arrays have the same size, otherwise
5206 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00005207 const size_t count1 = decl_ctx_1.Size();
5208 const size_t count2 = decl_ctx_2.Size();
5209 if (count1 != count2)
5210 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00005211
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00005212 // Make sure the DW_TAG values match all the way back up the
Greg Clayton80c26302012-02-05 06:12:47 +00005213 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00005214 const DWARFDebugInfoEntry *decl_ctx_die1;
5215 const DWARFDebugInfoEntry *decl_ctx_die2;
5216 size_t i;
5217 for (i=0; i<count1; i++)
5218 {
5219 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
5220 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
5221 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
5222 return false;
5223 }
Greg Clayton890ff562012-02-02 05:48:16 +00005224#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00005225
5226 // Make sure the top item in the decl context die array is always
5227 // DW_TAG_compile_unit. If it isn't then something went wrong in
5228 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00005229 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00005230
Greg Clayton890ff562012-02-02 05:48:16 +00005231#endif
5232 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00005233 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00005234 for (i=0; i<count1 - 1; i++)
5235 {
5236 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
5237 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
5238 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00005239 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00005240 // If the string was from a DW_FORM_strp, then the pointer will often
5241 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00005242 if (name1 == name2)
5243 continue;
5244
5245 // Name pointers are not equal, so only compare the strings
5246 // if both are not NULL.
5247 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00005248 {
Greg Clayton5569e642012-02-06 01:44:54 +00005249 // If the strings don't compare, we are done...
5250 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00005251 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00005252 }
5253 else
5254 {
5255 // One name was NULL while the other wasn't
5256 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00005257 }
5258 }
Greg Clayton80c26302012-02-05 06:12:47 +00005259 // We made it through all of the checks and the declaration contexts
5260 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00005261 return true;
5262}
Greg Clayton220a0072011-12-09 08:48:30 +00005263
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005264
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005265TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00005266SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx)
5267{
5268 TypeSP type_sp;
5269
5270 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
5271 if (dwarf_decl_ctx_count > 0)
5272 {
5273 const ConstString type_name(dwarf_decl_ctx[0].name);
5274 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
5275
5276 if (type_name)
5277 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005278 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
Greg Claytona8022fa2012-04-24 21:22:41 +00005279 if (log)
5280 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005281 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005282 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')",
5283 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5284 dwarf_decl_ctx.GetQualifiedName());
5285 }
5286
5287 DIEArray die_offsets;
5288
5289 if (m_using_apple_tables)
5290 {
5291 if (m_apple_types_ap.get())
5292 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005293 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
5294 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
5295 if (has_tag && has_qualified_name_hash)
Greg Claytona8022fa2012-04-24 21:22:41 +00005296 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005297 const char *qualified_name = dwarf_decl_ctx.GetQualifiedName();
5298 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name);
5299 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005300 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005301 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets);
5302 }
5303 else if (has_tag)
5304 {
5305 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005306 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
Greg Claytona8022fa2012-04-24 21:22:41 +00005307 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets);
5308 }
5309 else
5310 {
5311 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
5312 }
5313 }
5314 }
5315 else
5316 {
5317 if (!m_indexed)
5318 Index ();
5319
5320 m_type_index.Find (type_name, die_offsets);
5321 }
5322
5323 const size_t num_matches = die_offsets.size();
5324
5325
5326 DWARFCompileUnit* type_cu = NULL;
5327 const DWARFDebugInfoEntry* type_die = NULL;
5328 if (num_matches)
5329 {
5330 DWARFDebugInfo* debug_info = DebugInfo();
5331 for (size_t i=0; i<num_matches; ++i)
5332 {
5333 const dw_offset_t die_offset = die_offsets[i];
5334 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
5335
5336 if (type_die)
5337 {
5338 bool try_resolving_type = false;
5339
5340 // Don't try and resolve the DIE we are looking for with the DIE itself!
5341 const dw_tag_t type_tag = type_die->Tag();
5342 // Make sure the tags match
5343 if (type_tag == tag)
5344 {
5345 // The tags match, lets try resolving this type
5346 try_resolving_type = true;
5347 }
5348 else
5349 {
5350 // The tags don't match, but we need to watch our for a
5351 // forward declaration for a struct and ("struct foo")
5352 // ends up being a class ("class foo { ... };") or
5353 // vice versa.
5354 switch (type_tag)
5355 {
5356 case DW_TAG_class_type:
5357 // We had a "class foo", see if we ended up with a "struct foo { ... };"
5358 try_resolving_type = (tag == DW_TAG_structure_type);
5359 break;
5360 case DW_TAG_structure_type:
5361 // We had a "struct foo", see if we ended up with a "class foo { ... };"
5362 try_resolving_type = (tag == DW_TAG_class_type);
5363 break;
5364 default:
5365 // Tags don't match, don't event try to resolve
5366 // using this type whose name matches....
5367 break;
5368 }
5369 }
5370
5371 if (try_resolving_type)
5372 {
5373 DWARFDeclContext type_dwarf_decl_ctx;
5374 type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx);
5375
5376 if (log)
5377 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005378 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005379 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)",
5380 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5381 dwarf_decl_ctx.GetQualifiedName(),
5382 type_die->GetOffset(),
5383 type_dwarf_decl_ctx.GetQualifiedName());
5384 }
5385
5386 // Make sure the decl contexts match all the way up
5387 if (dwarf_decl_ctx == type_dwarf_decl_ctx)
5388 {
5389 Type *resolved_type = ResolveType (type_cu, type_die, false);
5390 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5391 {
5392 type_sp = resolved_type->shared_from_this();
5393 break;
5394 }
5395 }
5396 }
5397 else
5398 {
5399 if (log)
5400 {
5401 std::string qualified_name;
5402 type_die->GetQualifiedName(this, type_cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00005403 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005404 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)",
5405 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5406 dwarf_decl_ctx.GetQualifiedName(),
5407 type_die->GetOffset(),
5408 qualified_name.c_str());
5409 }
5410 }
5411 }
5412 else
5413 {
5414 if (m_using_apple_tables)
5415 {
5416 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5417 die_offset, type_name.GetCString());
5418 }
5419 }
5420
5421 }
5422 }
5423 }
5424 }
5425 return type_sp;
5426}
5427
Greg Clayton4116e932012-05-15 02:33:01 +00005428bool
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005429SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005430 Type *class_type,
Greg Clayton4116e932012-05-15 02:33:01 +00005431 DWARFCompileUnit* src_cu,
5432 const DWARFDebugInfoEntry *src_class_die,
5433 DWARFCompileUnit* dst_cu,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005434 const DWARFDebugInfoEntry *dst_class_die,
Greg Claytond20deac2014-04-04 18:15:18 +00005435 DWARFDIECollection &failures)
Greg Clayton4116e932012-05-15 02:33:01 +00005436{
5437 if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die)
5438 return false;
5439 if (src_class_die->Tag() != dst_class_die->Tag())
5440 return false;
5441
5442 // We need to complete the class type so we can get all of the method types
5443 // parsed so we can then unique those types to their equivalent counterparts
5444 // in "dst_cu" and "dst_class_die"
5445 class_type->GetClangFullType();
5446
5447 const DWARFDebugInfoEntry *src_die;
5448 const DWARFDebugInfoEntry *dst_die;
5449 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die;
5450 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die;
Greg Clayton65ec1032012-11-12 21:27:20 +00005451 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial;
5452 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial;
Greg Clayton4116e932012-05-15 02:33:01 +00005453 for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling())
5454 {
5455 if (src_die->Tag() == DW_TAG_subprogram)
5456 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005457 // Make sure this is a declaration and not a concrete instance by looking
5458 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5459 // are placed inside the class definitions and shouldn't be included in
5460 // the list of things are are tracking here.
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005461 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_declaration, 0) == 1)
Greg Clayton84afacd2012-11-07 23:09:32 +00005462 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005463 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton84afacd2012-11-07 23:09:32 +00005464 if (src_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005465 {
5466 ConstString src_const_name(src_name);
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005467 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0))
Greg Clayton65ec1032012-11-12 21:27:20 +00005468 src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die);
5469 else
5470 src_name_to_die.Append(src_const_name.GetCString(), src_die);
5471 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005472 }
Greg Clayton4116e932012-05-15 02:33:01 +00005473 }
5474 }
5475 for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling())
5476 {
5477 if (dst_die->Tag() == DW_TAG_subprogram)
5478 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005479 // Make sure this is a declaration and not a concrete instance by looking
5480 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5481 // are placed inside the class definitions and shouldn't be included in
5482 // the list of things are are tracking here.
5483 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1)
5484 {
5485 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5486 if (dst_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005487 {
5488 ConstString dst_const_name(dst_name);
5489 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0))
5490 dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die);
5491 else
5492 dst_name_to_die.Append(dst_const_name.GetCString(), dst_die);
5493 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005494 }
Greg Clayton4116e932012-05-15 02:33:01 +00005495 }
5496 }
5497 const uint32_t src_size = src_name_to_die.GetSize ();
5498 const uint32_t dst_size = dst_name_to_die.GetSize ();
Greg Clayton5160ce52013-03-27 23:08:40 +00005499 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005500
5501 // Is everything kosher so we can go through the members at top speed?
5502 bool fast_path = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005503
Sean Callanan2367f8a2013-02-26 01:12:25 +00005504 if (src_size != dst_size)
Greg Clayton4116e932012-05-15 02:33:01 +00005505 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005506 if (src_size != 0 && dst_size != 0)
5507 {
5508 if (log)
5509 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)",
5510 src_class_die->GetOffset(),
5511 dst_class_die->GetOffset(),
5512 src_size,
5513 dst_size);
5514 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005515
Sean Callanan2367f8a2013-02-26 01:12:25 +00005516 fast_path = false;
5517 }
5518
5519 uint32_t idx;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005520
Sean Callanan2367f8a2013-02-26 01:12:25 +00005521 if (fast_path)
5522 {
Greg Clayton4116e932012-05-15 02:33:01 +00005523 for (idx = 0; idx < src_size; ++idx)
5524 {
5525 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5526 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5527
5528 if (src_die->Tag() != dst_die->Tag())
5529 {
5530 if (log)
5531 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)",
5532 src_class_die->GetOffset(),
5533 dst_class_die->GetOffset(),
5534 src_die->GetOffset(),
5535 DW_TAG_value_to_name(src_die->Tag()),
5536 dst_die->GetOffset(),
5537 DW_TAG_value_to_name(src_die->Tag()));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005538 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005539 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005540
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005541 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton4116e932012-05-15 02:33:01 +00005542 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005543
Greg Clayton4116e932012-05-15 02:33:01 +00005544 // Make sure the names match
5545 if (src_name == dst_name || (strcmp (src_name, dst_name) == 0))
5546 continue;
5547
5548 if (log)
5549 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)",
5550 src_class_die->GetOffset(),
5551 dst_class_die->GetOffset(),
5552 src_die->GetOffset(),
5553 src_name,
5554 dst_die->GetOffset(),
5555 dst_name);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005556
Sean Callanan2367f8a2013-02-26 01:12:25 +00005557 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005558 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005559 }
Greg Clayton4116e932012-05-15 02:33:01 +00005560
Sean Callanan2367f8a2013-02-26 01:12:25 +00005561 // Now do the work of linking the DeclContexts and Types.
5562 if (fast_path)
5563 {
5564 // We can do this quickly. Just run across the tables index-for-index since
5565 // we know each node has matching names and tags.
Greg Clayton4116e932012-05-15 02:33:01 +00005566 for (idx = 0; idx < src_size; ++idx)
5567 {
5568 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5569 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005570
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005571 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Greg Clayton4116e932012-05-15 02:33:01 +00005572 if (src_decl_ctx)
5573 {
5574 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005575 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
5576 static_cast<void*>(src_decl_ctx),
5577 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005578 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5579 }
5580 else
5581 {
5582 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005583 log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found",
5584 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005585 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005586
Greg Clayton4116e932012-05-15 02:33:01 +00005587 Type *src_child_type = m_die_to_type[src_die];
5588 if (src_child_type)
5589 {
5590 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005591 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
5592 static_cast<void*>(src_child_type),
5593 src_child_type->GetID(),
5594 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005595 m_die_to_type[dst_die] = src_child_type;
5596 }
5597 else
5598 {
5599 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005600 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());
5601 }
5602 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005603 }
5604 else
5605 {
5606 // We must do this slowly. For each member of the destination, look
5607 // up a member in the source with the same name, check its tag, and
5608 // unique them if everything matches up. Report failures.
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005609
Sean Callanan2367f8a2013-02-26 01:12:25 +00005610 if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty())
5611 {
5612 src_name_to_die.Sort();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005613
Sean Callanan2367f8a2013-02-26 01:12:25 +00005614 for (idx = 0; idx < dst_size; ++idx)
5615 {
5616 const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx);
5617 dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
5618 src_die = src_name_to_die.Find(dst_name, NULL);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005619
Sean Callanan2367f8a2013-02-26 01:12:25 +00005620 if (src_die && (src_die->Tag() == dst_die->Tag()))
5621 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005622 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Sean Callanan2367f8a2013-02-26 01:12:25 +00005623 if (src_decl_ctx)
5624 {
5625 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005626 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
5627 static_cast<void*>(src_decl_ctx),
5628 src_die->GetOffset(),
5629 dst_die->GetOffset());
Sean Callanan2367f8a2013-02-26 01:12:25 +00005630 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5631 }
5632 else
5633 {
5634 if (log)
5635 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());
5636 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005637
Sean Callanan2367f8a2013-02-26 01:12:25 +00005638 Type *src_child_type = m_die_to_type[src_die];
5639 if (src_child_type)
5640 {
5641 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005642 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
5643 static_cast<void*>(src_child_type),
5644 src_child_type->GetID(),
5645 src_die->GetOffset(),
5646 dst_die->GetOffset());
Sean Callanan2367f8a2013-02-26 01:12:25 +00005647 m_die_to_type[dst_die] = src_child_type;
5648 }
5649 else
5650 {
5651 if (log)
5652 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());
5653 }
5654 }
5655 else
5656 {
5657 if (log)
5658 log->Printf ("warning: couldn't find a match for 0x%8.8x", dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005659
Greg Claytond20deac2014-04-04 18:15:18 +00005660 failures.Append(dst_die);
Sean Callanan2367f8a2013-02-26 01:12:25 +00005661 }
5662 }
5663 }
5664 }
5665
5666 const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize ();
5667 const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize ();
5668
5669 UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src;
5670
5671 if (src_size_artificial && dst_size_artificial)
5672 {
5673 dst_name_to_die_artificial.Sort();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005674
Greg Clayton65ec1032012-11-12 21:27:20 +00005675 for (idx = 0; idx < src_size_artificial; ++idx)
5676 {
5677 const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx);
5678 src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5679 dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005680
Greg Clayton65ec1032012-11-12 21:27:20 +00005681 if (dst_die)
5682 {
Greg Clayton65ec1032012-11-12 21:27:20 +00005683 // Both classes have the artificial types, link them
5684 clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die];
5685 if (src_decl_ctx)
5686 {
5687 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005688 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
5689 static_cast<void*>(src_decl_ctx),
5690 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005691 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5692 }
5693 else
5694 {
5695 if (log)
5696 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());
5697 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005698
Greg Clayton65ec1032012-11-12 21:27:20 +00005699 Type *src_child_type = m_die_to_type[src_die];
5700 if (src_child_type)
5701 {
5702 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005703 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
5704 static_cast<void*>(src_child_type),
5705 src_child_type->GetID(),
5706 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005707 m_die_to_type[dst_die] = src_child_type;
5708 }
5709 else
5710 {
5711 if (log)
5712 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());
5713 }
5714 }
5715 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005716 }
Greg Clayton65ec1032012-11-12 21:27:20 +00005717
Sean Callanan2367f8a2013-02-26 01:12:25 +00005718 if (dst_size_artificial)
Greg Clayton4116e932012-05-15 02:33:01 +00005719 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005720 for (idx = 0; idx < dst_size_artificial; ++idx)
5721 {
5722 const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx);
5723 dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5724 if (log)
5725 log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial);
5726
Greg Claytond20deac2014-04-04 18:15:18 +00005727 failures.Append(dst_die);
Sean Callanan2367f8a2013-02-26 01:12:25 +00005728 }
Greg Clayton4116e932012-05-15 02:33:01 +00005729 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005730
Greg Claytond20deac2014-04-04 18:15:18 +00005731 return (failures.Size() != 0);
Greg Clayton4116e932012-05-15 02:33:01 +00005732}
Greg Claytona8022fa2012-04-24 21:22:41 +00005733
5734TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00005735SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005736{
5737 TypeSP type_sp;
5738
Greg Clayton1be10fc2010-09-29 01:12:09 +00005739 if (type_is_new_ptr)
5740 *type_is_new_ptr = false;
Greg Clayton1fba87112012-02-09 20:03:49 +00005741
Todd Fiala0a70a842014-05-28 16:43:26 +00005742#if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE)
Greg Clayton1fba87112012-02-09 20:03:49 +00005743 static DIEStack g_die_stack;
5744 DIEStack::ScopedPopper scoped_die_logger(g_die_stack);
5745#endif
Greg Clayton1be10fc2010-09-29 01:12:09 +00005746
Sean Callananc7fbf732010-08-06 00:32:49 +00005747 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005748 if (die != NULL)
5749 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005750 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005751 if (log)
Sean Callanan5b26f272012-02-04 08:49:35 +00005752 {
5753 const DWARFDebugInfoEntry *context_die;
5754 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005755
Greg Clayton5160ce52013-03-27 23:08:40 +00005756 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 +00005757 die->GetOffset(),
5758 static_cast<void*>(context),
5759 context_die->GetOffset(),
5760 DW_TAG_value_to_name(die->Tag()),
5761 die->GetName(this, dwarf_cu));
5762
Todd Fiala0a70a842014-05-28 16:43:26 +00005763#if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE)
Greg Clayton1fba87112012-02-09 20:03:49 +00005764 scoped_die_logger.Push (dwarf_cu, die);
Greg Clayton5160ce52013-03-27 23:08:40 +00005765 g_die_stack.LogDIEs(log, this);
Greg Clayton1fba87112012-02-09 20:03:49 +00005766#endif
Sean Callanan5b26f272012-02-04 08:49:35 +00005767 }
Greg Clayton3bffb082011-12-10 02:15:28 +00005768//
Greg Clayton5160ce52013-03-27 23:08:40 +00005769// Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005770// if (log && dwarf_cu)
5771// {
5772// StreamString s;
5773// die->DumpLocation (this, dwarf_cu, s);
Greg Clayton5160ce52013-03-27 23:08:40 +00005774// GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Greg Clayton3bffb082011-12-10 02:15:28 +00005775//
5776// }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005777
Greg Clayton594e5ed2010-09-27 21:07:38 +00005778 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005779 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00005780 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005781 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005782 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00005783 if (type_is_new_ptr)
5784 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005785
Greg Clayton594e5ed2010-09-27 21:07:38 +00005786 const dw_tag_t tag = die->Tag();
5787
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005788 bool is_forward_declaration = false;
5789 DWARFDebugInfoEntry::Attributes attributes;
5790 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00005791 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00005792 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
Greg Claytonfaac1112013-03-14 18:31:44 +00005793 uint64_t byte_size = 0;
Greg Clayton526e5af2010-11-13 03:52:47 +00005794 Declaration decl;
5795
Greg Clayton4957bf62010-09-30 21:49:03 +00005796 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton57ee3062013-07-11 22:46:58 +00005797 ClangASTType clang_type;
Greg Claytond20deac2014-04-04 18:15:18 +00005798 DWARFFormValue form_value;
5799
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005800 dw_attr_t attr;
5801
5802 switch (tag)
5803 {
5804 case DW_TAG_base_type:
5805 case DW_TAG_pointer_type:
5806 case DW_TAG_reference_type:
Sean Callanance8af862012-05-21 23:31:51 +00005807 case DW_TAG_rvalue_reference_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005808 case DW_TAG_typedef:
5809 case DW_TAG_const_type:
5810 case DW_TAG_restrict_type:
5811 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00005812 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005813 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005814 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005815 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005816
Greg Claytond88d7592010-09-15 08:33:30 +00005817 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005818 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005819 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
5820
5821 if (num_attributes > 0)
5822 {
5823 uint32_t i;
5824 for (i=0; i<num_attributes; ++i)
5825 {
5826 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005827 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5828 {
5829 switch (attr)
5830 {
5831 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5832 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5833 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5834 case DW_AT_name:
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005835
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005836 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00005837 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
5838 // include the "&"...
5839 if (tag == DW_TAG_reference_type)
5840 {
5841 if (strchr (type_name_cstr, '&') == NULL)
5842 type_name_cstr = NULL;
5843 }
5844 if (type_name_cstr)
5845 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005846 break;
Greg Clayton23f59502012-07-17 03:23:13 +00005847 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005848 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
Greg Clayton54166af2014-11-22 01:58:59 +00005849 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005850 default:
5851 case DW_AT_sibling:
5852 break;
5853 }
5854 }
5855 }
5856 }
5857
Ed Mastea0191d12013-10-17 20:42:56 +00005858 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 +00005859
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005860 switch (tag)
5861 {
5862 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00005863 break;
5864
Greg Claytond4436412011-10-28 21:00:00 +00005865 case DW_TAG_unspecified_type:
Greg Clayton7fba2632013-07-01 21:01:52 +00005866 if (strcmp(type_name_cstr, "nullptr_t") == 0 ||
5867 strcmp(type_name_cstr, "decltype(nullptr)") == 0 )
Greg Claytond4436412011-10-28 21:00:00 +00005868 {
5869 resolve_state = Type::eResolveStateFull;
Greg Clayton57ee3062013-07-11 22:46:58 +00005870 clang_type = ast.GetBasicType(eBasicTypeNullPtr);
Greg Claytond4436412011-10-28 21:00:00 +00005871 break;
5872 }
5873 // Fall through to base type below in case we can handle the type there...
5874
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005875 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00005876 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005877 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
5878 encoding,
5879 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005880 break;
5881
Sean Callanance8af862012-05-21 23:31:51 +00005882 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
5883 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
5884 case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break;
5885 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
5886 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
5887 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
5888 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005889 }
5890
Greg Clayton57ee3062013-07-11 22:46:58 +00005891 if (!clang_type && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID) && sc.comp_unit != NULL)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005892 {
Sean Callanan82587052013-01-03 00:05:56 +00005893 bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005894
Sean Callanan82587052013-01-03 00:05:56 +00005895 if (translation_unit_is_objc)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005896 {
Sean Callanan82587052013-01-03 00:05:56 +00005897 if (type_name_cstr != NULL)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005898 {
Sean Callanan82587052013-01-03 00:05:56 +00005899 static ConstString g_objc_type_name_id("id");
5900 static ConstString g_objc_type_name_Class("Class");
5901 static ConstString g_objc_type_name_selector("SEL");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005902
Sean Callanan82587052013-01-03 00:05:56 +00005903 if (type_name_const_str == g_objc_type_name_id)
5904 {
5905 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005906 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 +00005907 die->GetOffset(),
5908 DW_TAG_value_to_name(die->Tag()),
5909 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005910 clang_type = ast.GetBasicType(eBasicTypeObjCID);
Sean Callanan82587052013-01-03 00:05:56 +00005911 encoding_data_type = Type::eEncodingIsUID;
5912 encoding_uid = LLDB_INVALID_UID;
5913 resolve_state = Type::eResolveStateFull;
Greg Clayton526e5af2010-11-13 03:52:47 +00005914
Sean Callanan82587052013-01-03 00:05:56 +00005915 }
5916 else if (type_name_const_str == g_objc_type_name_Class)
5917 {
5918 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005919 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 +00005920 die->GetOffset(),
5921 DW_TAG_value_to_name(die->Tag()),
5922 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005923 clang_type = ast.GetBasicType(eBasicTypeObjCClass);
Sean Callanan82587052013-01-03 00:05:56 +00005924 encoding_data_type = Type::eEncodingIsUID;
5925 encoding_uid = LLDB_INVALID_UID;
5926 resolve_state = Type::eResolveStateFull;
5927 }
5928 else if (type_name_const_str == g_objc_type_name_selector)
5929 {
5930 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005931 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 +00005932 die->GetOffset(),
5933 DW_TAG_value_to_name(die->Tag()),
5934 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005935 clang_type = ast.GetBasicType(eBasicTypeObjCSel);
Sean Callanan82587052013-01-03 00:05:56 +00005936 encoding_data_type = Type::eEncodingIsUID;
5937 encoding_uid = LLDB_INVALID_UID;
5938 resolve_state = Type::eResolveStateFull;
5939 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005940 }
Sean Callanan82587052013-01-03 00:05:56 +00005941 else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005942 {
Sean Callanan82587052013-01-03 00:05:56 +00005943 // 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 +00005944
Sean Callanan82587052013-01-03 00:05:56 +00005945 DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005946
Sean Callanan82587052013-01-03 00:05:56 +00005947 if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005948 {
Sean Callanan82587052013-01-03 00:05:56 +00005949 if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL))
5950 {
5951 if (!strcmp(struct_name, "objc_object"))
5952 {
5953 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005954 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 +00005955 die->GetOffset(),
5956 DW_TAG_value_to_name(die->Tag()),
5957 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005958 clang_type = ast.GetBasicType(eBasicTypeObjCID);
Sean Callanan82587052013-01-03 00:05:56 +00005959 encoding_data_type = Type::eEncodingIsUID;
5960 encoding_uid = LLDB_INVALID_UID;
5961 resolve_state = Type::eResolveStateFull;
5962 }
5963 }
5964 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005965 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005966 }
5967 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005968
Greg Clayton81c22f62011-10-19 18:09:39 +00005969 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005970 this,
5971 type_name_const_str,
5972 byte_size,
5973 NULL,
5974 encoding_uid,
5975 encoding_data_type,
5976 &decl,
5977 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005978 resolve_state));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005979
Greg Clayton594e5ed2010-09-27 21:07:38 +00005980 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005981
5982// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
5983// if (encoding_type != NULL)
5984// {
5985// if (encoding_type != DIE_IS_BEING_PARSED)
5986// type_sp->SetEncodingType(encoding_type);
5987// else
5988// m_indirect_fixups.push_back(type_sp.get());
5989// }
5990 }
5991 break;
5992
5993 case DW_TAG_structure_type:
5994 case DW_TAG_union_type:
5995 case DW_TAG_class_type:
5996 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005997 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005998 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Greg Clayton23f59502012-07-17 03:23:13 +00005999 bool byte_size_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006000
Greg Clayton9e409562010-07-28 02:04:09 +00006001 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00006002 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006003 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00006004 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006005 if (num_attributes > 0)
6006 {
6007 uint32_t i;
6008 for (i=0; i<num_attributes; ++i)
6009 {
6010 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006011 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6012 {
6013 switch (attr)
6014 {
Greg Clayton9e409562010-07-28 02:04:09 +00006015 case DW_AT_decl_file:
Greg Claytonc7f03b62012-01-12 04:33:28 +00006016 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
Ed Maste4c24b122013-10-17 20:13:14 +00006017 {
6018 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
6019 // point to the compile unit file, so we clear this invalid value
6020 // so that we can still unique types efficiently.
Greg Claytonc7f03b62012-01-12 04:33:28 +00006021 decl.SetFile(FileSpec ("<invalid>", false));
Ed Maste4c24b122013-10-17 20:13:14 +00006022 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00006023 else
6024 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
Greg Clayton9e409562010-07-28 02:04:09 +00006025 break;
6026
6027 case DW_AT_decl_line:
6028 decl.SetLine(form_value.Unsigned());
6029 break;
6030
6031 case DW_AT_decl_column:
6032 decl.SetColumn(form_value.Unsigned());
6033 break;
6034
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006035 case DW_AT_name:
6036 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006037 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006038 break;
Greg Clayton9e409562010-07-28 02:04:09 +00006039
6040 case DW_AT_byte_size:
6041 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00006042 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00006043 break;
6044
6045 case DW_AT_accessibility:
6046 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
6047 break;
6048
6049 case DW_AT_declaration:
Greg Clayton1c8ef472013-04-05 23:27:21 +00006050 is_forward_declaration = form_value.Boolean();
Greg Clayton9e409562010-07-28 02:04:09 +00006051 break;
6052
6053 case DW_AT_APPLE_runtime_class:
6054 class_language = (LanguageType)form_value.Signed();
6055 break;
6056
Greg Clayton18774842011-11-29 23:40:34 +00006057 case DW_AT_APPLE_objc_complete_type:
6058 is_complete_objc_class = form_value.Signed();
6059 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006060
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006061 case DW_AT_allocated:
6062 case DW_AT_associated:
6063 case DW_AT_data_location:
6064 case DW_AT_description:
6065 case DW_AT_start_scope:
6066 case DW_AT_visibility:
6067 default:
6068 case DW_AT_sibling:
6069 break;
6070 }
6071 }
6072 }
6073 }
Greg Claytond20deac2014-04-04 18:15:18 +00006074
6075 // UniqueDWARFASTType is large, so don't create a local variables on the
6076 // stack, put it on the heap. This function is often called recursively
6077 // and clang isn't good and sharing the stack space for variables in different blocks.
6078 std::unique_ptr<UniqueDWARFASTType> unique_ast_entry_ap(new UniqueDWARFASTType());
Sean Callanan8e8072d2012-02-07 21:13:38 +00006079
Greg Clayton123edca2012-03-02 00:07:15 +00006080 // Only try and unique the type if it has a name.
6081 if (type_name_const_str &&
6082 GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Sean Callanan8e8072d2012-02-07 21:13:38 +00006083 this,
6084 dwarf_cu,
6085 die,
6086 decl,
6087 byte_size_valid ? byte_size : -1,
Greg Claytond20deac2014-04-04 18:15:18 +00006088 *unique_ast_entry_ap))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006089 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00006090 // We have already parsed this type or from another
6091 // compile unit. GCC loves to use the "one definition
6092 // rule" which can result in multiple definitions
6093 // of the same class over and over in each compile
6094 // unit.
Greg Claytond20deac2014-04-04 18:15:18 +00006095 type_sp = unique_ast_entry_ap->m_type_sp;
Sean Callanan8e8072d2012-02-07 21:13:38 +00006096 if (type_sp)
Greg Claytonc615ce42010-11-09 04:42:43 +00006097 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00006098 m_die_to_type[die] = type_sp.get();
6099 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00006100 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006101 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006102
Daniel Malead01b2952012-11-29 21:49:15 +00006103 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 +00006104
6105 int tag_decl_kind = -1;
6106 AccessType default_accessibility = eAccessNone;
6107 if (tag == DW_TAG_structure_type)
6108 {
6109 tag_decl_kind = clang::TTK_Struct;
6110 default_accessibility = eAccessPublic;
6111 }
6112 else if (tag == DW_TAG_union_type)
6113 {
6114 tag_decl_kind = clang::TTK_Union;
6115 default_accessibility = eAccessPublic;
6116 }
6117 else if (tag == DW_TAG_class_type)
6118 {
6119 tag_decl_kind = clang::TTK_Class;
6120 default_accessibility = eAccessPrivate;
6121 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006122
Greg Clayton3a5f29a2011-11-30 02:48:28 +00006123 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
6124 die->HasChildren() == false &&
6125 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
6126 {
6127 // Work around an issue with clang at the moment where
6128 // forward declarations for objective C classes are emitted
6129 // as:
6130 // DW_TAG_structure_type [2]
6131 // DW_AT_name( "ForwardObjcClass" )
6132 // DW_AT_byte_size( 0x00 )
6133 // DW_AT_decl_file( "..." )
6134 // DW_AT_decl_line( 1 )
6135 //
6136 // Note that there is no DW_AT_declaration and there are
6137 // no children, and the byte size is zero.
6138 is_forward_declaration = true;
6139 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006140
Sean Callanan7457f8d2012-04-25 01:03:57 +00006141 if (class_language == eLanguageTypeObjC ||
6142 class_language == eLanguageTypeObjC_plus_plus)
Greg Clayton18774842011-11-29 23:40:34 +00006143 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00006144 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
Greg Clayton901c5ca2011-12-03 04:40:03 +00006145 {
6146 // We have a valid eSymbolTypeObjCClass class symbol whose
6147 // name matches the current objective C class that we
6148 // are trying to find and this DIE isn't the complete
6149 // definition (we checked is_complete_objc_class above and
6150 // know it is false), so the real definition is in here somewhere
Greg Claytonc7f03b62012-01-12 04:33:28 +00006151 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006152
Greg Clayton1f746072012-08-29 21:13:06 +00006153 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton901c5ca2011-12-03 04:40:03 +00006154 {
6155 // We weren't able to find a full declaration in
6156 // this DWARF, see if we have a declaration anywhere
6157 // else...
Greg Claytonc7f03b62012-01-12 04:33:28 +00006158 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00006159 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006160
Greg Clayton901c5ca2011-12-03 04:40:03 +00006161 if (type_sp)
6162 {
6163 if (log)
6164 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006165 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00006166 "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 +00006167 static_cast<void*>(this),
Greg Claytone38a5ed2012-01-05 03:57:59 +00006168 die->GetOffset(),
6169 DW_TAG_value_to_name(tag),
6170 type_name_cstr,
6171 type_sp->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00006172 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006173
Greg Clayton901c5ca2011-12-03 04:40:03 +00006174 // We found a real definition for this type elsewhere
6175 // so lets use it and cache the fact that we found
6176 // a complete type for this die
6177 m_die_to_type[die] = type_sp.get();
6178 return type_sp;
6179 }
6180 }
6181 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006182
Greg Clayton901c5ca2011-12-03 04:40:03 +00006183
6184 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006185 {
6186 // We have a forward declaration to a type and we need
6187 // to try and find a full declaration. We look in the
6188 // current type index just in case we have a forward
6189 // declaration followed by an actual declarations in the
6190 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00006191 if (log)
6192 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006193 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00006194 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006195 static_cast<void*>(this),
Greg Claytone38a5ed2012-01-05 03:57:59 +00006196 die->GetOffset(),
6197 DW_TAG_value_to_name(tag),
6198 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00006199 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006200
Greg Claytona8022fa2012-04-24 21:22:41 +00006201 DWARFDeclContext die_decl_ctx;
6202 die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx);
6203
6204 //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
6205 type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006206
Greg Clayton1f746072012-08-29 21:13:06 +00006207 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton4272cc72011-02-02 02:24:04 +00006208 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006209 // We weren't able to find a full declaration in
6210 // this DWARF, see if we have a declaration anywhere
6211 // else...
Greg Claytona8022fa2012-04-24 21:22:41 +00006212 type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton4272cc72011-02-02 02:24:04 +00006213 }
6214
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006215 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00006216 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00006217 if (log)
6218 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006219 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00006220 "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 +00006221 static_cast<void*>(this),
Greg Claytone38a5ed2012-01-05 03:57:59 +00006222 die->GetOffset(),
6223 DW_TAG_value_to_name(tag),
6224 type_name_cstr,
6225 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00006226 }
6227
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006228 // We found a real definition for this type elsewhere
6229 // so lets use it and cache the fact that we found
6230 // a complete type for this die
6231 m_die_to_type[die] = type_sp.get();
6232 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00006233 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006234 }
6235 assert (tag_decl_kind != -1);
6236 bool clang_type_was_created = false;
Pavel Labathc7c30eb2015-06-08 23:38:06 +00006237 clang_type.SetClangType(ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die));
Greg Clayton57ee3062013-07-11 22:46:58 +00006238 if (!clang_type)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006239 {
Sean Callanan4d04c6a2012-02-09 22:54:11 +00006240 const DWARFDebugInfoEntry *decl_ctx_die;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006241
Sean Callanan4d04c6a2012-02-09 22:54:11 +00006242 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton55561e92011-10-26 03:31:36 +00006243 if (accessibility == eAccessNone && decl_ctx)
6244 {
6245 // Check the decl context that contains this class/struct/union.
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00006246 // If it is a class we must give it an accessibility.
Greg Clayton55561e92011-10-26 03:31:36 +00006247 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
6248 if (DeclKindIsCXXClass (containing_decl_kind))
6249 accessibility = default_accessibility;
6250 }
6251
Greg Claytonc4ffd662013-03-08 01:37:30 +00006252 ClangASTMetadata metadata;
6253 metadata.SetUserID(MakeUserID(die->GetOffset()));
6254 metadata.SetIsDynamicCXXType(ClassOrStructIsVirtual (dwarf_cu, die));
6255
Greg Claytonf0705c82011-10-22 03:33:13 +00006256 if (type_name_cstr && strchr (type_name_cstr, '<'))
6257 {
6258 ClangASTContext::TemplateParameterInfos template_param_infos;
6259 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
6260 {
6261 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00006262 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00006263 type_name_cstr,
6264 tag_decl_kind,
6265 template_param_infos);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006266
Greg Claytonf0705c82011-10-22 03:33:13 +00006267 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
6268 class_template_decl,
6269 tag_decl_kind,
6270 template_param_infos);
6271 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
6272 clang_type_was_created = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006273
Greg Claytond0029442013-03-27 01:48:02 +00006274 GetClangASTContext().SetMetadata (class_template_decl, metadata);
6275 GetClangASTContext().SetMetadata (class_specialization_decl, metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00006276 }
6277 }
6278
6279 if (!clang_type_was_created)
6280 {
6281 clang_type_was_created = true;
Greg Clayton55561e92011-10-26 03:31:36 +00006282 clang_type = ast.CreateRecordType (decl_ctx,
6283 accessibility,
6284 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00006285 tag_decl_kind,
Sean Callanan60217122012-04-13 00:10:03 +00006286 class_language,
Jim Ingham379397632012-10-27 02:54:13 +00006287 &metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00006288 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006289 }
6290
6291 // Store a forward declaration to this class type in case any
6292 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00006293 // types for function prototypes.
Pavel Labathc7c30eb2015-06-08 23:38:06 +00006294 LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00006295 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006296 this,
6297 type_name_const_str,
6298 byte_size,
6299 NULL,
6300 LLDB_INVALID_UID,
6301 Type::eEncodingIsUID,
6302 &decl,
6303 clang_type,
6304 Type::eResolveStateForward));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006305
Sean Callanan72772842012-02-22 23:57:45 +00006306 type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006307
6308
6309 // Add our type to the unique type map so we don't
6310 // end up creating many copies of the same type over
6311 // and over in the ASTContext for our module
Greg Claytond20deac2014-04-04 18:15:18 +00006312 unique_ast_entry_ap->m_type_sp = type_sp;
6313 unique_ast_entry_ap->m_symfile = this;
6314 unique_ast_entry_ap->m_cu = dwarf_cu;
6315 unique_ast_entry_ap->m_die = die;
6316 unique_ast_entry_ap->m_declaration = decl;
6317 unique_ast_entry_ap->m_byte_size = byte_size;
Greg Claytone576ab22011-02-15 00:19:15 +00006318 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
Greg Claytond20deac2014-04-04 18:15:18 +00006319 *unique_ast_entry_ap);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006320
Greg Clayton0ec71a02013-08-10 00:09:35 +00006321 if (is_forward_declaration && die->HasChildren())
6322 {
6323 // Check to see if the DIE actually has a definition, some version of GCC will
6324 // emit DIEs with DW_AT_declaration set to true, but yet still have subprogram,
6325 // members, or inheritance, so we can't trust it
6326 const DWARFDebugInfoEntry *child_die = die->GetFirstChild();
6327 while (child_die)
6328 {
6329 switch (child_die->Tag())
6330 {
6331 case DW_TAG_inheritance:
6332 case DW_TAG_subprogram:
6333 case DW_TAG_member:
6334 case DW_TAG_APPLE_property:
Greg Clayton4c484ec2014-02-07 19:21:56 +00006335 case DW_TAG_class_type:
6336 case DW_TAG_structure_type:
6337 case DW_TAG_enumeration_type:
6338 case DW_TAG_typedef:
6339 case DW_TAG_union_type:
Greg Clayton0ec71a02013-08-10 00:09:35 +00006340 child_die = NULL;
6341 is_forward_declaration = false;
6342 break;
6343 default:
6344 child_die = child_die->GetSibling();
6345 break;
6346 }
6347 }
6348 }
6349
Sean Callanan12014a02011-12-08 23:45:45 +00006350 if (!is_forward_declaration)
Greg Clayton219cf312012-03-30 00:51:13 +00006351 {
6352 // Always start the definition for a class type so that
6353 // if the class has child classes or types that require
6354 // the class to be created for use as their decl contexts
6355 // the class will be ready to accept these child definitions.
Sean Callanan12014a02011-12-08 23:45:45 +00006356 if (die->HasChildren() == false)
6357 {
6358 // No children for this struct/union/class, lets finish it
Pavel Labathc7c30eb2015-06-08 23:38:06 +00006359 clang_type.StartTagDeclarationDefinition ();
6360 clang_type.CompleteTagDeclarationDefinition ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006361
Sean Callanan433cd222012-10-19 01:37:25 +00006362 if (tag == DW_TAG_structure_type) // this only applies in C
6363 {
Pavel Labathc7c30eb2015-06-08 23:38:06 +00006364 clang::RecordDecl *record_decl = clang_type.GetAsRecordDecl();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006365
Greg Clayton57ee3062013-07-11 22:46:58 +00006366 if (record_decl)
Greg Claytond20deac2014-04-04 18:15:18 +00006367 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, LayoutInfo()));
Sean Callanan433cd222012-10-19 01:37:25 +00006368 }
Sean Callanan12014a02011-12-08 23:45:45 +00006369 }
6370 else if (clang_type_was_created)
6371 {
Greg Clayton219cf312012-03-30 00:51:13 +00006372 // Start the definition if the class is not objective C since
6373 // the underlying decls respond to isCompleteDefinition(). Objective
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +00006374 // C decls don't respond to isCompleteDefinition() so we can't
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00006375 // start the declaration definition right away. For C++ class/union/structs
Greg Clayton219cf312012-03-30 00:51:13 +00006376 // we want to start the definition in case the class is needed as the
6377 // declaration context for a contained class or type without the need
6378 // to complete that type..
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006379
Sean Callanan7457f8d2012-04-25 01:03:57 +00006380 if (class_language != eLanguageTypeObjC &&
6381 class_language != eLanguageTypeObjC_plus_plus)
Pavel Labathc7c30eb2015-06-08 23:38:06 +00006382 clang_type.StartTagDeclarationDefinition ();
Greg Clayton219cf312012-03-30 00:51:13 +00006383
Sean Callanan12014a02011-12-08 23:45:45 +00006384 // Leave this as a forward declaration until we need
6385 // to know the details of the type. lldb_private::Type
6386 // will automatically call the SymbolFile virtual function
6387 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
6388 // When the definition needs to be defined.
Greg Clayton57ee3062013-07-11 22:46:58 +00006389 m_forward_decl_die_to_clang_type[die] = clang_type.GetOpaqueQualType();
Pavel Labathc7c30eb2015-06-08 23:38:06 +00006390 m_forward_decl_clang_type_to_die[clang_type.RemoveFastQualifiers().GetOpaqueQualType()] = die;
6391 clang_type.SetHasExternalStorage (true);
Sean Callanan12014a02011-12-08 23:45:45 +00006392 }
Greg Claytonc615ce42010-11-09 04:42:43 +00006393 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006394
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006395 }
6396 break;
6397
6398 case DW_TAG_enumeration_type:
6399 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006400 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006401 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006402
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006403 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006404
Greg Claytond88d7592010-09-15 08:33:30 +00006405 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006406 if (num_attributes > 0)
6407 {
6408 uint32_t i;
6409
6410 for (i=0; i<num_attributes; ++i)
6411 {
6412 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006413 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6414 {
6415 switch (attr)
6416 {
Greg Clayton7a345282010-11-09 23:46:37 +00006417 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6418 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6419 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006420 case DW_AT_name:
6421 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006422 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006423 break;
Greg Clayton54166af2014-11-22 01:58:59 +00006424 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006425 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
6426 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006427 case DW_AT_declaration: break; //is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006428 case DW_AT_allocated:
6429 case DW_AT_associated:
6430 case DW_AT_bit_stride:
6431 case DW_AT_byte_stride:
6432 case DW_AT_data_location:
6433 case DW_AT_description:
6434 case DW_AT_start_scope:
6435 case DW_AT_visibility:
6436 case DW_AT_specification:
6437 case DW_AT_abstract_origin:
6438 case DW_AT_sibling:
6439 break;
6440 }
6441 }
6442 }
6443
Daniel Malead01b2952012-11-29 21:49:15 +00006444 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 +00006445
Greg Clayton57ee3062013-07-11 22:46:58 +00006446 ClangASTType enumerator_clang_type;
Pavel Labathc7c30eb2015-06-08 23:38:06 +00006447 clang_type.SetClangType (ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die));
Greg Clayton57ee3062013-07-11 22:46:58 +00006448 if (!clang_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00006449 {
Greg Clayton5d14fc02013-03-06 06:23:54 +00006450 if (encoding_uid != DW_INVALID_OFFSET)
6451 {
6452 Type *enumerator_type = ResolveTypeUID(encoding_uid);
6453 if (enumerator_type)
6454 enumerator_clang_type = enumerator_type->GetClangFullType();
6455 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006456
Greg Clayton57ee3062013-07-11 22:46:58 +00006457 if (!enumerator_clang_type)
Greg Clayton5d14fc02013-03-06 06:23:54 +00006458 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
6459 DW_ATE_signed,
6460 byte_size * 8);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006461
Greg Claytonca512b32011-01-14 04:54:56 +00006462 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00006463 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00006464 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006465 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00006466 }
6467 else
6468 {
Pavel Labathc7c30eb2015-06-08 23:38:06 +00006469 enumerator_clang_type = clang_type.GetEnumerationIntegerType ();
Greg Clayton1be10fc2010-09-29 01:12:09 +00006470 }
6471
Pavel Labathc7c30eb2015-06-08 23:38:06 +00006472 LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006473
Greg Clayton81c22f62011-10-19 18:09:39 +00006474 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006475 this,
6476 type_name_const_str,
6477 byte_size,
6478 NULL,
6479 encoding_uid,
6480 Type::eEncodingIsUID,
6481 &decl,
6482 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006483 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006484
Pavel Labathc7c30eb2015-06-08 23:38:06 +00006485 clang_type.StartTagDeclarationDefinition ();
Greg Clayton6beaaa62011-01-17 03:46:26 +00006486 if (die->HasChildren())
6487 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006488 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00006489 bool is_signed = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00006490 enumerator_clang_type.IsIntegerType(is_signed);
Greg Clayton3e067532013-03-05 23:54:39 +00006491 ParseChildEnumerators(cu_sc, clang_type, is_signed, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00006492 }
Pavel Labathc7c30eb2015-06-08 23:38:06 +00006493 clang_type.CompleteTagDeclarationDefinition ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006494 }
6495 }
6496 break;
6497
Jim Inghamb0be4422010-08-12 01:20:14 +00006498 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006499 case DW_TAG_subprogram:
6500 case DW_TAG_subroutine_type:
6501 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006502 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006503 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006504
Greg Clayton23f59502012-07-17 03:23:13 +00006505 //const char *mangled = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006506 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00006507 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006508 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00006509 bool is_static = false;
6510 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00006511 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00006512 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00006513 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
6514 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Jim Ingham379397632012-10-27 02:54:13 +00006515 dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00006516
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006517 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00006518 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006519
6520
Greg Claytond88d7592010-09-15 08:33:30 +00006521 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006522 if (num_attributes > 0)
6523 {
6524 uint32_t i;
6525 for (i=0; i<num_attributes; ++i)
6526 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006527 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006528 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6529 {
6530 switch (attr)
6531 {
6532 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6533 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6534 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6535 case DW_AT_name:
6536 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006537 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006538 break;
6539
Greg Clayton71415542012-12-08 00:24:40 +00006540 case DW_AT_linkage_name:
Greg Clayton23f59502012-07-17 03:23:13 +00006541 case DW_AT_MIPS_linkage_name: break; // mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00006542 case DW_AT_type: type_die_offset = form_value.Reference(); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00006543 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006544 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
6545 case DW_AT_inline: is_inline = form_value.Boolean(); break;
6546 case DW_AT_virtuality: is_virtual = form_value.Boolean(); break;
6547 case DW_AT_explicit: is_explicit = form_value.Boolean(); break;
6548 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006549
Greg Claytonf51de672010-10-01 02:31:07 +00006550
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006551 case DW_AT_external:
6552 if (form_value.Unsigned())
6553 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00006554 if (storage == clang::SC_None)
6555 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006556 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00006557 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006558 }
6559 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006560
Greg Clayton72da3972011-08-16 18:40:23 +00006561 case DW_AT_specification:
Greg Clayton54166af2014-11-22 01:58:59 +00006562 specification_die_offset = form_value.Reference();
Greg Clayton72da3972011-08-16 18:40:23 +00006563 break;
6564
6565 case DW_AT_abstract_origin:
Greg Clayton54166af2014-11-22 01:58:59 +00006566 abstract_origin_die_offset = form_value.Reference();
Greg Clayton72da3972011-08-16 18:40:23 +00006567 break;
6568
Jim Ingham379397632012-10-27 02:54:13 +00006569 case DW_AT_object_pointer:
Greg Clayton54166af2014-11-22 01:58:59 +00006570 object_pointer_die_offset = form_value.Reference();
Jim Ingham379397632012-10-27 02:54:13 +00006571 break;
6572
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006573 case DW_AT_allocated:
6574 case DW_AT_associated:
6575 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006576 case DW_AT_calling_convention:
6577 case DW_AT_data_location:
6578 case DW_AT_elemental:
6579 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006580 case DW_AT_frame_base:
6581 case DW_AT_high_pc:
6582 case DW_AT_low_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006583 case DW_AT_prototyped:
6584 case DW_AT_pure:
6585 case DW_AT_ranges:
6586 case DW_AT_recursive:
6587 case DW_AT_return_addr:
6588 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006589 case DW_AT_start_scope:
6590 case DW_AT_static_link:
6591 case DW_AT_trampoline:
6592 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006593 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006594 case DW_AT_description:
6595 case DW_AT_sibling:
6596 break;
6597 }
6598 }
6599 }
Greg Clayton24739922010-10-13 03:15:28 +00006600 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006601
Jim Ingham379397632012-10-27 02:54:13 +00006602 std::string object_pointer_name;
6603 if (object_pointer_die_offset != DW_INVALID_OFFSET)
6604 {
6605 // Get the name from the object pointer die
6606 StreamString s;
6607 if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s))
6608 {
6609 object_pointer_name.assign(s.GetData());
6610 }
6611 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006612
Daniel Malead01b2952012-11-29 21:49:15 +00006613 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 +00006614
Greg Clayton57ee3062013-07-11 22:46:58 +00006615 ClangASTType return_clang_type;
Greg Clayton24739922010-10-13 03:15:28 +00006616 Type *func_type = NULL;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006617
Greg Clayton24739922010-10-13 03:15:28 +00006618 if (type_die_offset != DW_INVALID_OFFSET)
6619 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00006620
Greg Clayton24739922010-10-13 03:15:28 +00006621 if (func_type)
Greg Clayton42ce2f32011-12-12 21:50:19 +00006622 return_clang_type = func_type->GetClangForwardType();
Greg Clayton24739922010-10-13 03:15:28 +00006623 else
Greg Clayton57ee3062013-07-11 22:46:58 +00006624 return_clang_type = ast.GetBasicType(eBasicTypeVoid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006625
Greg Claytonf51de672010-10-01 02:31:07 +00006626
Greg Clayton57ee3062013-07-11 22:46:58 +00006627 std::vector<ClangASTType> function_param_types;
Greg Clayton24739922010-10-13 03:15:28 +00006628 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006629
Greg Clayton24739922010-10-13 03:15:28 +00006630 // Parse the function children for the parameters
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006631
Greg Claytoncb5860a2011-10-13 23:49:28 +00006632 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
6633 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00006634 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
6635
Greg Claytonf0705c82011-10-22 03:33:13 +00006636 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00006637 // Start off static. This will be set to false in ParseChildParameters(...)
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00006638 // if we find a "this" parameters as the first parameter
Greg Clayton5113dc82011-08-12 06:47:54 +00006639 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00006640 is_static = true;
Greg Claytond20deac2014-04-04 18:15:18 +00006641
Greg Clayton24739922010-10-13 03:15:28 +00006642 if (die->HasChildren())
6643 {
Greg Clayton0fffff52010-09-24 05:15:53 +00006644 bool skip_artificial = true;
Jim Ingham379397632012-10-27 02:54:13 +00006645 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00006646 containing_decl_ctx,
Jim Ingham379397632012-10-27 02:54:13 +00006647 dwarf_cu,
6648 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00006649 skip_artificial,
6650 is_static,
Greg Clayton03969752014-02-24 18:53:11 +00006651 is_variadic,
Jim Ingham379397632012-10-27 02:54:13 +00006652 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00006653 function_param_decls,
Greg Claytond20deac2014-04-04 18:15:18 +00006654 type_quals);
Greg Clayton24739922010-10-13 03:15:28 +00006655 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006656
Greg Clayton24739922010-10-13 03:15:28 +00006657 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006658 clang_type = ast.CreateFunctionType (return_clang_type,
Greg Clayton9cb25c42012-10-30 17:02:18 +00006659 function_param_types.data(),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006660 function_param_types.size(),
6661 is_variadic,
6662 type_quals);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006663
Sean Callanande9ce872013-05-09 23:13:13 +00006664 bool ignore_containing_context = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006665
Greg Clayton24739922010-10-13 03:15:28 +00006666 if (type_name_cstr)
6667 {
6668 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00006669 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006670 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00006671 ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true);
6672 if (objc_method.IsValid(true))
Greg Clayton0fffff52010-09-24 05:15:53 +00006673 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006674 ClangASTType class_opaque_type;
Greg Clayton1b3815c2013-01-30 00:18:29 +00006675 ConstString class_name(objc_method.GetClassName());
Greg Clayton7c810422012-01-18 23:40:49 +00006676 if (class_name)
Greg Clayton0fffff52010-09-24 05:15:53 +00006677 {
Greg Clayton278a16b2012-01-19 00:52:59 +00006678 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
Greg Claytonc7f03b62012-01-12 04:33:28 +00006679
6680 if (complete_objc_class_type_sp)
Greg Clayton0fffff52010-09-24 05:15:53 +00006681 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006682 ClangASTType type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
Pavel Labathc7c30eb2015-06-08 23:38:06 +00006683 if (type_clang_forward_type.IsObjCObjectOrInterfaceType ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00006684 class_opaque_type = type_clang_forward_type;
Greg Clayton0fffff52010-09-24 05:15:53 +00006685 }
Greg Clayton24739922010-10-13 03:15:28 +00006686 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006687
Greg Clayton24739922010-10-13 03:15:28 +00006688 if (class_opaque_type)
6689 {
6690 // If accessibility isn't set to anything valid, assume public for
6691 // now...
6692 if (accessibility == eAccessNone)
6693 accessibility = eAccessPublic;
6694
Pavel Labathc7c30eb2015-06-08 23:38:06 +00006695 clang::ObjCMethodDecl *objc_method_decl = class_opaque_type.AddMethodToObjCObjectType (type_name_cstr,
6696 clang_type,
6697 accessibility,
6698 is_artificial);
Greg Clayton24739922010-10-13 03:15:28 +00006699 type_handled = objc_method_decl != NULL;
Sean Callanan464a5b52012-10-04 22:06:29 +00006700 if (type_handled)
6701 {
6702 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Claytond0029442013-03-27 01:48:02 +00006703 GetClangASTContext().SetMetadataAsUserID (objc_method_decl, MakeUserID(die->GetOffset()));
Sean Callanan464a5b52012-10-04 22:06:29 +00006704 }
Sean Callananc3a1d562013-02-06 23:21:59 +00006705 else
6706 {
Jason Molendac1a65832013-03-07 22:44:42 +00006707 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 +00006708 die->GetOffset(),
6709 tag,
6710 DW_TAG_value_to_name(tag));
6711 }
Greg Clayton24739922010-10-13 03:15:28 +00006712 }
6713 }
Greg Clayton5113dc82011-08-12 06:47:54 +00006714 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00006715 {
6716 // Look at the parent of this DIE and see if is is
6717 // a class or struct and see if this is actually a
6718 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00006719 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00006720 if (class_type)
6721 {
Greg Clayton4116e932012-05-15 02:33:01 +00006722 if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset()))
6723 {
6724 // We uniqued the parent class of this function to another class
6725 // so we now need to associate all dies under "decl_ctx_die" to
6726 // DIEs in the DIE for "class_type"...
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006727 SymbolFileDWARF *class_symfile = NULL;
Greg Clayton4116e932012-05-15 02:33:01 +00006728 DWARFCompileUnitSP class_type_cu_sp;
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006729 const DWARFDebugInfoEntry *class_type_die = NULL;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006730
Sean Callanan2367f8a2013-02-26 01:12:25 +00006731 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
6732 if (debug_map_symfile)
6733 {
6734 class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID()));
6735 class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6736 }
6737 else
6738 {
6739 class_symfile = this;
6740 class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6741 }
Greg Clayton4116e932012-05-15 02:33:01 +00006742 if (class_type_die)
6743 {
Greg Claytond20deac2014-04-04 18:15:18 +00006744 DWARFDIECollection failures;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006745
Sean Callanan2367f8a2013-02-26 01:12:25 +00006746 CopyUniqueClassMethodTypes (class_symfile,
6747 class_type,
6748 class_type_cu_sp.get(),
6749 class_type_die,
6750 dwarf_cu,
6751 decl_ctx_die,
6752 failures);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006753
Sean Callanan2367f8a2013-02-26 01:12:25 +00006754 // FIXME do something with these failures that's smarter than
6755 // just dropping them on the ground. Unfortunately classes don't
6756 // like having stuff added to them after their definitions are
6757 // complete...
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006758
Sean Callanan2367f8a2013-02-26 01:12:25 +00006759 type_ptr = m_die_to_type[die];
6760 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton4116e932012-05-15 02:33:01 +00006761 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006762 type_sp = type_ptr->shared_from_this();
6763 break;
Greg Clayton4116e932012-05-15 02:33:01 +00006764 }
6765 }
6766 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006767
Greg Clayton72da3972011-08-16 18:40:23 +00006768 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00006769 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006770 // We have a specification which we are going to base our function
6771 // prototype off of, so we need this type to be completed so that the
6772 // m_die_to_decl_ctx for the method in the specification has a valid
6773 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006774 class_type->GetClangForwardType();
Greg Clayton72da3972011-08-16 18:40:23 +00006775 // If we have a specification, then the function type should have been
6776 // made with the specification and not with this die.
6777 DWARFCompileUnitSP spec_cu_sp;
6778 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006779 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006780 if (spec_clang_decl_ctx)
6781 {
6782 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
6783 }
6784 else
Jim Inghamc1663042011-09-29 22:12:35 +00006785 {
Daniel Malead01b2952012-11-29 21:49:15 +00006786 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8x) has no decl\n",
Greg Claytone38a5ed2012-01-05 03:57:59 +00006787 MakeUserID(die->GetOffset()),
6788 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006789 }
Greg Clayton72da3972011-08-16 18:40:23 +00006790 type_handled = true;
6791 }
6792 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
6793 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006794 // We have a specification which we are going to base our function
6795 // prototype off of, so we need this type to be completed so that the
6796 // m_die_to_decl_ctx for the method in the abstract origin has a valid
6797 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006798 class_type->GetClangForwardType();
Greg Clayton5cf58b92011-10-05 22:22:08 +00006799
Greg Clayton72da3972011-08-16 18:40:23 +00006800 DWARFCompileUnitSP abs_cu_sp;
6801 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006802 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006803 if (abs_clang_decl_ctx)
6804 {
6805 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
6806 }
6807 else
Jim Inghamc1663042011-09-29 22:12:35 +00006808 {
Daniel Malead01b2952012-11-29 21:49:15 +00006809 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 +00006810 MakeUserID(die->GetOffset()),
6811 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006812 }
Greg Clayton72da3972011-08-16 18:40:23 +00006813 type_handled = true;
6814 }
6815 else
6816 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006817 ClangASTType class_opaque_type = class_type->GetClangForwardType();
Pavel Labathc7c30eb2015-06-08 23:38:06 +00006818 if (class_opaque_type.IsCXXClassType ())
Greg Clayton931180e2011-01-27 06:44:37 +00006819 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006820 if (class_opaque_type.IsBeingDefined ())
Greg Clayton72da3972011-08-16 18:40:23 +00006821 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006822 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
6823 // in the DWARF for C++ methods... Default to public for now...
6824 if (accessibility == eAccessNone)
6825 accessibility = eAccessPublic;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006826
Greg Clayton20568dd2011-10-13 23:13:20 +00006827 if (!is_static && !die->HasChildren())
6828 {
6829 // We have a C++ member function with no children (this pointer!)
6830 // and clang will get mad if we try and make a function that isn't
6831 // well formed in the DWARF, so we will just skip it...
6832 type_handled = true;
6833 }
6834 else
6835 {
6836 clang::CXXMethodDecl *cxx_method_decl;
6837 // REMOVE THE CRASH DESCRIPTION BELOW
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00006838 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 +00006839 type_name_cstr,
6840 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00006841 MakeUserID(die->GetOffset()),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00006842 m_obj_file->GetFileSpec().GetPath().c_str());
Greg Clayton20568dd2011-10-13 23:13:20 +00006843
Sean Callananc1b732d2011-11-01 18:07:13 +00006844 const bool is_attr_used = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006845
Pavel Labathc7c30eb2015-06-08 23:38:06 +00006846 cxx_method_decl = class_opaque_type.AddMethodToCXXRecordType (type_name_cstr,
6847 clang_type,
6848 accessibility,
6849 is_virtual,
6850 is_static,
6851 is_inline,
6852 is_explicit,
6853 is_attr_used,
6854 is_artificial);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006855
Greg Clayton20568dd2011-10-13 23:13:20 +00006856 type_handled = cxx_method_decl != NULL;
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006857
6858 if (type_handled)
Jim Ingham379397632012-10-27 02:54:13 +00006859 {
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006860 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
6861
6862 Host::SetCrashDescription (NULL);
6863
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006864
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006865 ClangASTMetadata metadata;
6866 metadata.SetUserID(MakeUserID(die->GetOffset()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006867
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006868 if (!object_pointer_name.empty())
6869 {
6870 metadata.SetObjectPtrName(object_pointer_name.c_str());
6871 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006872 log->Printf ("Setting object pointer name: %s on method object %p.\n",
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006873 object_pointer_name.c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006874 static_cast<void*>(cxx_method_decl));
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006875 }
Greg Claytond0029442013-03-27 01:48:02 +00006876 GetClangASTContext().SetMetadata (cxx_method_decl, metadata);
Jim Ingham379397632012-10-27 02:54:13 +00006877 }
Sean Callananb0640dc2013-04-09 23:22:08 +00006878 else
6879 {
Sean Callanande9ce872013-05-09 23:13:13 +00006880 ignore_containing_context = true;
Sean Callananb0640dc2013-04-09 23:22:08 +00006881 }
Greg Clayton20568dd2011-10-13 23:13:20 +00006882 }
Greg Clayton72da3972011-08-16 18:40:23 +00006883 }
6884 else
6885 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006886 // We were asked to parse the type for a method in a class, yet the
6887 // class hasn't been asked to complete itself through the
6888 // clang::ExternalASTSource protocol, so we need to just have the
6889 // class complete itself and do things the right way, then our
6890 // DIE should then have an entry in the m_die_to_type map. First
6891 // we need to modify the m_die_to_type so it doesn't think we are
6892 // trying to parse this DIE anymore...
6893 m_die_to_type[die] = NULL;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006894
Greg Clayton20568dd2011-10-13 23:13:20 +00006895 // Now we get the full type to force our class type to complete itself
6896 // using the clang::ExternalASTSource protocol which will parse all
6897 // base classes and all methods (including the method for this DIE).
6898 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00006899
Greg Clayton20568dd2011-10-13 23:13:20 +00006900 // The type for this DIE should have been filled in the function call above
6901 type_ptr = m_die_to_type[die];
Greg Claytone5476db2012-06-01 20:32:35 +00006902 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton20568dd2011-10-13 23:13:20 +00006903 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006904 type_sp = type_ptr->shared_from_this();
Greg Clayton20568dd2011-10-13 23:13:20 +00006905 break;
6906 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006907
Sean Callanan02eee4d2012-04-12 23:10:00 +00006908 // FIXME This is fixing some even uglier behavior but we really need to
6909 // uniq the methods of each class as well as the class itself.
6910 // <rdar://problem/11240464>
6911 type_handled = true;
Greg Clayton72da3972011-08-16 18:40:23 +00006912 }
Greg Clayton931180e2011-01-27 06:44:37 +00006913 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006914 }
6915 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006916 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006917 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006918
Greg Clayton24739922010-10-13 03:15:28 +00006919 if (!type_handled)
6920 {
6921 // We just have a function that isn't part of a class
Sean Callanande9ce872013-05-09 23:13:13 +00006922 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (ignore_containing_context ? GetClangASTContext().GetTranslationUnitDecl() : containing_decl_ctx,
Greg Clayton147e1fa2011-10-14 22:47:18 +00006923 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006924 clang_type,
6925 storage,
6926 is_inline);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006927
6928// if (template_param_infos.GetSize() > 0)
6929// {
6930// clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
6931// function_decl,
6932// type_name_cstr,
6933// template_param_infos);
6934//
6935// ast.CreateFunctionTemplateSpecializationInfo (function_decl,
6936// func_template_decl,
6937// template_param_infos);
6938// }
Greg Clayton24739922010-10-13 03:15:28 +00006939 // Add the decl to our DIE to decl context map
6940 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00006941 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00006942 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006943 ast.SetFunctionParameters (function_decl,
6944 &function_param_decls.front(),
6945 function_param_decls.size());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006946
Jim Ingham379397632012-10-27 02:54:13 +00006947 ClangASTMetadata metadata;
6948 metadata.SetUserID(MakeUserID(die->GetOffset()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006949
Jim Ingham379397632012-10-27 02:54:13 +00006950 if (!object_pointer_name.empty())
6951 {
6952 metadata.SetObjectPtrName(object_pointer_name.c_str());
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006953 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006954 log->Printf ("Setting object pointer name: %s on function object %p.",
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006955 object_pointer_name.c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006956 static_cast<void*>(function_decl));
Jim Ingham379397632012-10-27 02:54:13 +00006957 }
Greg Claytond0029442013-03-27 01:48:02 +00006958 GetClangASTContext().SetMetadata (function_decl, metadata);
Greg Clayton24739922010-10-13 03:15:28 +00006959 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006960 }
Greg Clayton81c22f62011-10-19 18:09:39 +00006961 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006962 this,
6963 type_name_const_str,
6964 0,
6965 NULL,
6966 LLDB_INVALID_UID,
6967 Type::eEncodingIsUID,
6968 &decl,
6969 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006970 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00006971 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006972 }
6973 break;
6974
6975 case DW_TAG_array_type:
6976 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006977 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006978 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006979
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006980 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006981 int64_t first_index = 0;
6982 uint32_t byte_stride = 0;
6983 uint32_t bit_stride = 0;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006984 bool is_vector = false;
Greg Claytond88d7592010-09-15 08:33:30 +00006985 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006986
6987 if (num_attributes > 0)
6988 {
6989 uint32_t i;
6990 for (i=0; i<num_attributes; ++i)
6991 {
6992 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006993 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6994 {
6995 switch (attr)
6996 {
6997 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6998 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6999 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
7000 case DW_AT_name:
7001 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00007002 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007003 break;
7004
Greg Clayton54166af2014-11-22 01:58:59 +00007005 case DW_AT_type: type_die_offset = form_value.Reference(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00007006 case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007007 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
7008 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00007009 case DW_AT_GNU_vector: is_vector = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00007010 case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00007011 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007012 case DW_AT_allocated:
7013 case DW_AT_associated:
7014 case DW_AT_data_location:
7015 case DW_AT_description:
7016 case DW_AT_ordering:
7017 case DW_AT_start_scope:
7018 case DW_AT_visibility:
7019 case DW_AT_specification:
7020 case DW_AT_abstract_origin:
7021 case DW_AT_sibling:
7022 break;
7023 }
7024 }
7025 }
7026
Daniel Malead01b2952012-11-29 21:49:15 +00007027 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 +00007028
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007029 Type *element_type = ResolveTypeUID(type_die_offset);
7030
7031 if (element_type)
7032 {
7033 std::vector<uint64_t> element_orders;
7034 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
7035 if (byte_stride == 0 && bit_stride == 0)
7036 byte_stride = element_type->GetByteSize();
Greg Clayton57ee3062013-07-11 22:46:58 +00007037 ClangASTType array_element_type = element_type->GetClangForwardType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007038 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
Siva Chandra89ce9552015-01-05 23:06:14 +00007039 if (element_orders.size() > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007040 {
Siva Chandra89ce9552015-01-05 23:06:14 +00007041 uint64_t num_elements = 0;
7042 std::vector<uint64_t>::const_reverse_iterator pos;
7043 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
7044 for (pos = element_orders.rbegin(); pos != end; ++pos)
7045 {
7046 num_elements = *pos;
7047 clang_type = ast.CreateArrayType (array_element_type,
7048 num_elements,
7049 is_vector);
7050 array_element_type = clang_type;
7051 array_element_bit_stride = num_elements ?
7052 array_element_bit_stride * num_elements :
7053 array_element_bit_stride;
7054 }
7055 }
7056 else
7057 {
7058 clang_type = ast.CreateArrayType (array_element_type, 0, is_vector);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007059 }
7060 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00007061 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00007062 this,
7063 empty_name,
7064 array_element_bit_stride / 8,
7065 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00007066 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00007067 Type::eEncodingIsUID,
7068 &decl,
7069 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00007070 Type::eResolveStateFull));
7071 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007072 }
7073 }
7074 }
7075 break;
7076
Greg Clayton9b81a312010-06-12 01:20:30 +00007077 case DW_TAG_ptr_to_member_type:
7078 {
7079 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
7080 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
7081
Greg Claytond88d7592010-09-15 08:33:30 +00007082 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007083
Greg Clayton9b81a312010-06-12 01:20:30 +00007084 if (num_attributes > 0) {
7085 uint32_t i;
7086 for (i=0; i<num_attributes; ++i)
7087 {
7088 attr = attributes.AttributeAtIndex(i);
Greg Clayton9b81a312010-06-12 01:20:30 +00007089 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
7090 {
7091 switch (attr)
7092 {
7093 case DW_AT_type:
Greg Clayton54166af2014-11-22 01:58:59 +00007094 type_die_offset = form_value.Reference(); break;
Greg Clayton9b81a312010-06-12 01:20:30 +00007095 case DW_AT_containing_type:
Greg Clayton54166af2014-11-22 01:58:59 +00007096 containing_type_die_offset = form_value.Reference(); break;
Greg Clayton9b81a312010-06-12 01:20:30 +00007097 }
7098 }
7099 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007100
Greg Clayton9b81a312010-06-12 01:20:30 +00007101 Type *pointee_type = ResolveTypeUID(type_die_offset);
7102 Type *class_type = ResolveTypeUID(containing_type_die_offset);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007103
Greg Clayton57ee3062013-07-11 22:46:58 +00007104 ClangASTType pointee_clang_type = pointee_type->GetClangForwardType();
7105 ClangASTType class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00007106
Pavel Labathc7c30eb2015-06-08 23:38:06 +00007107 clang_type = pointee_clang_type.CreateMemberPointerType(class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00007108
Enrico Granata1cd5e922015-01-28 00:07:51 +00007109 byte_size = clang_type.GetByteSize(nullptr);
Greg Clayton9b81a312010-06-12 01:20:30 +00007110
Greg Clayton81c22f62011-10-19 18:09:39 +00007111 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00007112 this,
7113 type_name_const_str,
7114 byte_size,
7115 NULL,
7116 LLDB_INVALID_UID,
7117 Type::eEncodingIsUID,
7118 NULL,
7119 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00007120 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00007121 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007122
Greg Clayton9b81a312010-06-12 01:20:30 +00007123 break;
7124 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007125 default:
Greg Clayton84afacd2012-11-07 23:09:32 +00007126 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",
7127 die->GetOffset(),
7128 tag,
7129 DW_TAG_value_to_name(tag));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007130 break;
7131 }
7132
7133 if (type_sp.get())
7134 {
7135 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7136 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7137
7138 SymbolContextScope * symbol_context_scope = NULL;
7139 if (sc_parent_tag == DW_TAG_compile_unit)
7140 {
7141 symbol_context_scope = sc.comp_unit;
7142 }
Jason Molenda60db6e42014-10-16 01:40:16 +00007143 else if (sc.function != NULL && sc_parent_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007144 {
Greg Clayton81c22f62011-10-19 18:09:39 +00007145 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007146 if (symbol_context_scope == NULL)
7147 symbol_context_scope = sc.function;
7148 }
7149
7150 if (symbol_context_scope != NULL)
7151 {
7152 type_sp->SetSymbolContextScope(symbol_context_scope);
7153 }
7154
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00007155 // We are ready to put this type into the uniqued list up at the module level
7156 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00007157
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00007158 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007159 }
7160 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00007161 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007162 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00007163 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007164 }
7165 }
7166 return type_sp;
7167}
7168
7169size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00007170SymbolFileDWARF::ParseTypes
7171(
7172 const SymbolContext& sc,
7173 DWARFCompileUnit* dwarf_cu,
7174 const DWARFDebugInfoEntry *die,
7175 bool parse_siblings,
7176 bool parse_children
7177)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007178{
7179 size_t types_added = 0;
7180 while (die != NULL)
7181 {
7182 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00007183 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007184 {
7185 if (type_is_new)
7186 ++types_added;
7187 }
7188
7189 if (parse_children && die->HasChildren())
7190 {
7191 if (die->Tag() == DW_TAG_subprogram)
7192 {
7193 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00007194 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007195 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
7196 }
7197 else
7198 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
7199 }
7200
7201 if (parse_siblings)
7202 die = die->GetSibling();
7203 else
7204 die = NULL;
7205 }
7206 return types_added;
7207}
7208
7209
7210size_t
7211SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
7212{
7213 assert(sc.comp_unit && sc.function);
7214 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00007215 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007216 if (dwarf_cu)
7217 {
7218 dw_offset_t function_die_offset = sc.function->GetID();
7219 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
7220 if (function_die)
7221 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00007222 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007223 }
7224 }
7225
7226 return functions_added;
7227}
7228
7229
7230size_t
7231SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
7232{
7233 // At least a compile unit must be valid
7234 assert(sc.comp_unit);
7235 size_t types_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00007236 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007237 if (dwarf_cu)
7238 {
7239 if (sc.function)
7240 {
7241 dw_offset_t function_die_offset = sc.function->GetID();
7242 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
7243 if (func_die && func_die->HasChildren())
7244 {
7245 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
7246 }
7247 }
7248 else
7249 {
7250 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
7251 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
7252 {
7253 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
7254 }
7255 }
7256 }
7257
7258 return types_added;
7259}
7260
7261size_t
7262SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
7263{
7264 if (sc.comp_unit != NULL)
7265 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00007266 DWARFDebugInfo* info = DebugInfo();
7267 if (info == NULL)
7268 return 0;
7269
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007270 if (sc.function)
7271 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007272 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get();
7273
7274 if (dwarf_cu == NULL)
7275 return 0;
7276
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007277 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00007278
Greg Claytonc7bece562013-01-25 18:06:21 +00007279 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
7280 if (func_lo_pc != LLDB_INVALID_ADDRESS)
Greg Claytone38a5ed2012-01-05 03:57:59 +00007281 {
7282 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00007283
Greg Claytone38a5ed2012-01-05 03:57:59 +00007284 // Let all blocks know they have parse all their variables
7285 sc.function->GetBlock (false).SetDidParseVariables (true, true);
7286 return num_variables;
7287 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007288 }
7289 else if (sc.comp_unit)
7290 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007291 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get();
7292
7293 if (dwarf_cu == NULL)
7294 return 0;
7295
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007296 uint32_t vars_added = 0;
7297 VariableListSP variables (sc.comp_unit->GetVariableList(false));
7298
7299 if (variables.get() == NULL)
7300 {
7301 variables.reset(new VariableList());
7302 sc.comp_unit->SetVariableList(variables);
7303
Greg Claytond4a2b372011-09-12 23:21:58 +00007304 DWARFCompileUnit* match_dwarf_cu = NULL;
7305 const DWARFDebugInfoEntry* die = NULL;
7306 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00007307 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00007308 {
Greg Clayton97fbc342011-10-20 22:30:33 +00007309 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00007310 {
7311 DWARFMappedHash::DIEInfoArray hash_data_array;
7312 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
7313 dwarf_cu->GetNextCompileUnitOffset(),
7314 hash_data_array))
7315 {
7316 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
7317 }
7318 }
Greg Clayton7f995132011-10-04 22:41:51 +00007319 }
7320 else
7321 {
7322 // Index if we already haven't to make sure the compile units
7323 // get indexed and make their global DIE index list
7324 if (!m_indexed)
7325 Index ();
7326
7327 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
7328 dwarf_cu->GetNextCompileUnitOffset(),
7329 die_offsets);
7330 }
7331
7332 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00007333 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007334 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007335 DWARFDebugInfo* debug_info = DebugInfo();
7336 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007337 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007338 const dw_offset_t die_offset = die_offsets[i];
7339 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00007340 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00007341 {
Greg Clayton95d87902011-11-11 03:16:25 +00007342 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
7343 if (var_sp)
7344 {
7345 variables->AddVariableIfUnique (var_sp);
7346 ++vars_added;
7347 }
Greg Claytond4a2b372011-09-12 23:21:58 +00007348 }
Greg Clayton95d87902011-11-11 03:16:25 +00007349 else
7350 {
7351 if (m_using_apple_tables)
7352 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00007353 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 +00007354 }
7355 }
7356
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007357 }
7358 }
7359 }
7360 return vars_added;
7361 }
7362 }
7363 return 0;
7364}
7365
7366
7367VariableSP
7368SymbolFileDWARF::ParseVariableDIE
7369(
7370 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007371 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007372 const DWARFDebugInfoEntry *die,
7373 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007374)
7375{
Greg Clayton83c5cd92010-11-14 22:13:40 +00007376 VariableSP var_sp (m_die_to_variable_sp[die]);
7377 if (var_sp)
7378 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007379
7380 const dw_tag_t tag = die->Tag();
Richard Mitton0a558352013-10-17 21:14:00 +00007381 ModuleSP module = GetObjectFile()->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00007382
7383 if ((tag == DW_TAG_variable) ||
7384 (tag == DW_TAG_constant) ||
7385 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007386 {
Greg Clayton7f995132011-10-04 22:41:51 +00007387 DWARFDebugInfoEntry::Attributes attributes;
7388 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
7389 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007390 {
Greg Clayton7f995132011-10-04 22:41:51 +00007391 const char *name = NULL;
7392 const char *mangled = NULL;
7393 Declaration decl;
7394 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00007395 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00007396 DWARFExpression location;
7397 bool is_external = false;
7398 bool is_artificial = false;
7399 bool location_is_const_value_data = false;
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007400 bool has_explicit_location = false;
Enrico Granata4ec130d2014-08-11 19:16:35 +00007401 DWARFFormValue const_value;
Greg Clayton23f59502012-07-17 03:23:13 +00007402 //AccessType accessibility = eAccessNone;
Greg Clayton7f995132011-10-04 22:41:51 +00007403
7404 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007405 {
Greg Clayton7f995132011-10-04 22:41:51 +00007406 dw_attr_t attr = attributes.AttributeAtIndex(i);
7407 DWARFFormValue form_value;
Greg Clayton54166af2014-11-22 01:58:59 +00007408
Greg Clayton7f995132011-10-04 22:41:51 +00007409 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007410 {
Greg Clayton7f995132011-10-04 22:41:51 +00007411 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007412 {
Greg Clayton7f995132011-10-04 22:41:51 +00007413 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
7414 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
7415 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
7416 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton71415542012-12-08 00:24:40 +00007417 case DW_AT_linkage_name:
Greg Clayton7f995132011-10-04 22:41:51 +00007418 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00007419 case DW_AT_type: type_uid = form_value.Reference(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00007420 case DW_AT_external: is_external = form_value.Boolean(); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007421 case DW_AT_const_value:
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007422 // If we have already found a DW_AT_location attribute, ignore this attribute.
7423 if (!has_explicit_location)
7424 {
7425 location_is_const_value_data = true;
7426 // The constant value will be either a block, a data value or a string.
Ed Masteeeae7212013-10-24 20:43:47 +00007427 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007428 if (DWARFFormValue::IsBlockForm(form_value.Form()))
7429 {
7430 // Retrieve the value as a block expression.
7431 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7432 uint32_t block_length = form_value.Unsigned();
Richard Mitton0a558352013-10-17 21:14:00 +00007433 location.CopyOpcodeData(module, debug_info_data, block_offset, block_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007434 }
7435 else if (DWARFFormValue::IsDataForm(form_value.Form()))
7436 {
7437 // Retrieve the value as a data expression.
Greg Clayton54166af2014-11-22 01:58:59 +00007438 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (attributes.CompileUnitAtIndex(i)->GetAddressByteSize(), attributes.CompileUnitAtIndex(i)->IsDWARF64());
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007439 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7440 uint32_t data_length = fixed_form_sizes[form_value.Form()];
Enrico Granata4ec130d2014-08-11 19:16:35 +00007441 if (data_length == 0)
7442 {
7443 const uint8_t *data_pointer = form_value.BlockData();
7444 if (data_pointer)
7445 {
Jason Molenda18f5fd32014-10-16 07:52:17 +00007446 form_value.Unsigned();
Enrico Granata4ec130d2014-08-11 19:16:35 +00007447 }
7448 else if (DWARFFormValue::IsDataForm(form_value.Form()))
7449 {
7450 // we need to get the byte size of the type later after we create the variable
7451 const_value = form_value;
7452 }
7453 }
7454 else
7455 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007456 }
7457 else
7458 {
7459 // Retrieve the value as a string expression.
7460 if (form_value.Form() == DW_FORM_strp)
7461 {
Greg Clayton54166af2014-11-22 01:58:59 +00007462 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (attributes.CompileUnitAtIndex(i)->GetAddressByteSize(), attributes.CompileUnitAtIndex(i)->IsDWARF64());
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007463 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7464 uint32_t data_length = fixed_form_sizes[form_value.Form()];
Richard Mitton0a558352013-10-17 21:14:00 +00007465 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007466 }
7467 else
7468 {
7469 const char *str = form_value.AsCString(&debug_info_data);
7470 uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart();
7471 uint32_t string_length = strlen(str) + 1;
Richard Mitton0a558352013-10-17 21:14:00 +00007472 location.CopyOpcodeData(module, debug_info_data, string_offset, string_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007473 }
7474 }
7475 }
7476 break;
Greg Clayton7f995132011-10-04 22:41:51 +00007477 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007478 {
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007479 location_is_const_value_data = false;
7480 has_explicit_location = true;
Greg Clayton7f995132011-10-04 22:41:51 +00007481 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007482 {
Ed Masteeeae7212013-10-24 20:43:47 +00007483 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Clayton7f995132011-10-04 22:41:51 +00007484
7485 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7486 uint32_t block_length = form_value.Unsigned();
Richard Mitton0a558352013-10-17 21:14:00 +00007487 location.CopyOpcodeData(module, get_debug_info_data(), block_offset, block_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007488 }
7489 else
7490 {
Ed Masteeeae7212013-10-24 20:43:47 +00007491 const DWARFDataExtractor& debug_loc_data = get_debug_loc_data();
Greg Clayton7f995132011-10-04 22:41:51 +00007492 const dw_offset_t debug_loc_offset = form_value.Unsigned();
7493
7494 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
7495 if (loc_list_length > 0)
7496 {
Richard Mitton0a558352013-10-17 21:14:00 +00007497 location.CopyOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007498 assert (func_low_pc != LLDB_INVALID_ADDRESS);
Greg Clayton54166af2014-11-22 01:58:59 +00007499 location.SetLocationListSlide (func_low_pc - attributes.CompileUnitAtIndex(i)->GetBaseAddress());
Greg Clayton7f995132011-10-04 22:41:51 +00007500 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007501 }
7502 }
Greg Clayton7f995132011-10-04 22:41:51 +00007503 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007504
Greg Clayton1c8ef472013-04-05 23:27:21 +00007505 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00007506 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007507 case DW_AT_declaration:
7508 case DW_AT_description:
7509 case DW_AT_endianity:
7510 case DW_AT_segment:
7511 case DW_AT_start_scope:
7512 case DW_AT_visibility:
7513 default:
7514 case DW_AT_abstract_origin:
7515 case DW_AT_sibling:
7516 case DW_AT_specification:
7517 break;
7518 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007519 }
7520 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007521
Greg Clayton9e9f2192013-05-17 00:55:28 +00007522 ValueType scope = eValueTypeInvalid;
7523
7524 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7525 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7526 SymbolContextScope * symbol_context_scope = NULL;
7527
Siva Chandra0783ab92015-03-24 18:32:27 +00007528 if (!mangled)
7529 {
7530 // LLDB relies on the mangled name (DW_TAG_linkage_name or DW_AT_MIPS_linkage_name) to
7531 // generate fully qualified names of global variables with commands like "frame var j".
7532 // For example, if j were an int variable holding a value 4 and declared in a namespace
7533 // B which in turn is contained in a namespace A, the command "frame var j" returns
7534 // "(int) A::B::j = 4". If the compiler does not emit a linkage name, we should be able
7535 // to generate a fully qualified name from the declaration context.
7536 if (die->GetParent()->Tag() == DW_TAG_compile_unit &&
7537 LanguageRuntime::LanguageIsCPlusPlus(dwarf_cu->GetLanguageType()))
7538 {
7539 DWARFDeclContext decl_ctx;
7540
7541 die->GetDWARFDeclContext(this, dwarf_cu, decl_ctx);
7542 mangled = decl_ctx.GetQualifiedNameAsConstString().GetCString();
7543 }
7544 }
7545
Greg Clayton9e9f2192013-05-17 00:55:28 +00007546 // DWARF doesn't specify if a DW_TAG_variable is a local, global
7547 // or static variable, so we have to do a little digging by
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00007548 // looking at the location of a variable to see if it contains
Greg Clayton9e9f2192013-05-17 00:55:28 +00007549 // a DW_OP_addr opcode _somewhere_ in the definition. I say
7550 // somewhere because clang likes to combine small global variables
7551 // into the same symbol and have locations like:
7552 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
7553 // So if we don't have a DW_TAG_formal_parameter, we can look at
7554 // the location to see if it contains a DW_OP_addr opcode, and
7555 // then we can correctly classify our variables.
7556 if (tag == DW_TAG_formal_parameter)
7557 scope = eValueTypeVariableArgument;
7558 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007559 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007560 bool op_error = false;
7561 // Check if the location has a DW_OP_addr with any address value...
7562 lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS;
7563 if (!location_is_const_value_data)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007564 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007565 location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error);
7566 if (op_error)
Greg Clayton96c09682012-01-04 22:56:43 +00007567 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007568 StreamString strm;
7569 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
7570 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 +00007571 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007572 }
Greg Claytond1767f02011-12-08 02:13:16 +00007573
Greg Clayton9e9f2192013-05-17 00:55:28 +00007574 if (location_DW_OP_addr != LLDB_INVALID_ADDRESS)
7575 {
7576 if (is_external)
7577 scope = eValueTypeVariableGlobal;
7578 else
7579 scope = eValueTypeVariableStatic;
7580
7581
7582 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile ();
7583
7584 if (debug_map_symfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007585 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007586 // When leaving the DWARF in the .o files on darwin,
7587 // when we have a global variable that wasn't initialized,
7588 // the .o file might not have allocated a virtual
7589 // address for the global variable. In this case it will
7590 // have created a symbol for the global variable
7591 // that is undefined/data and external and the value will
7592 // be the byte size of the variable. When we do the
7593 // address map in SymbolFileDWARFDebugMap we rely on
7594 // having an address, we need to do some magic here
7595 // so we can get the correct address for our global
7596 // variable. The address for all of these entries
7597 // will be zero, and there will be an undefined symbol
7598 // in this object file, and the executable will have
7599 // a matching symbol with a good address. So here we
7600 // dig up the correct address and replace it in the
7601 // location for the variable, and set the variable's
7602 // symbol context scope to be that of the main executable
7603 // so the file address will resolve correctly.
7604 bool linked_oso_file_addr = false;
7605 if (is_external && location_DW_OP_addr == 0)
Greg Clayton9422dd62013-03-04 21:46:16 +00007606 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007607 // we have a possible uninitialized extern global
7608 ConstString const_name(mangled ? mangled : name);
7609 ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile();
7610 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007611 {
Greg Clayton3046e662013-07-10 01:23:25 +00007612 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
Greg Clayton9e9f2192013-05-17 00:55:28 +00007613 if (debug_map_symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007614 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007615 Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
7616 eSymbolTypeData,
7617 Symtab::eDebugYes,
7618 Symtab::eVisibilityExtern);
7619 if (exe_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007620 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007621 if (exe_symbol->ValueIsAddress())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007622 {
Greg Clayton358cf1e2015-06-25 21:46:34 +00007623 const addr_t exe_file_addr = exe_symbol->GetAddressRef().GetFileAddress();
Greg Clayton9e9f2192013-05-17 00:55:28 +00007624 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007625 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007626 if (location.Update_DW_OP_addr (exe_file_addr))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007627 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007628 linked_oso_file_addr = true;
7629 symbol_context_scope = exe_symbol;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007630 }
7631 }
7632 }
7633 }
7634 }
7635 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007636 }
Greg Clayton9422dd62013-03-04 21:46:16 +00007637
Greg Clayton9e9f2192013-05-17 00:55:28 +00007638 if (!linked_oso_file_addr)
7639 {
7640 // The DW_OP_addr is not zero, but it contains a .o file address which
7641 // needs to be linked up correctly.
7642 const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr);
7643 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton9422dd62013-03-04 21:46:16 +00007644 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007645 // Update the file address for this variable
7646 location.Update_DW_OP_addr (exe_file_addr);
7647 }
7648 else
7649 {
7650 // Variable didn't make it into the final executable
7651 return var_sp;
Greg Clayton9422dd62013-03-04 21:46:16 +00007652 }
Greg Claytond1767f02011-12-08 02:13:16 +00007653 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007654 }
Greg Clayton5cf58b92011-10-05 22:22:08 +00007655 }
7656 else
7657 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007658 scope = eValueTypeVariableLocal;
Greg Clayton5cf58b92011-10-05 22:22:08 +00007659 }
Greg Clayton7f995132011-10-04 22:41:51 +00007660 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007661
7662 if (symbol_context_scope == NULL)
7663 {
7664 switch (parent_tag)
7665 {
7666 case DW_TAG_subprogram:
7667 case DW_TAG_inlined_subroutine:
7668 case DW_TAG_lexical_block:
7669 if (sc.function)
7670 {
7671 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
7672 if (symbol_context_scope == NULL)
7673 symbol_context_scope = sc.function;
7674 }
7675 break;
7676
7677 default:
7678 symbol_context_scope = sc.comp_unit;
7679 break;
7680 }
7681 }
7682
7683 if (symbol_context_scope)
7684 {
Enrico Granata4ec130d2014-08-11 19:16:35 +00007685 SymbolFileTypeSP type_sp(new SymbolFileType(*this, type_uid));
7686
7687 if (const_value.Form() && type_sp && type_sp->GetType())
7688 location.CopyOpcodeData(const_value.Unsigned(), type_sp->GetType()->GetByteSize(), dwarf_cu->GetAddressByteSize());
7689
Greg Clayton9e9f2192013-05-17 00:55:28 +00007690 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
7691 name,
7692 mangled,
Enrico Granata4ec130d2014-08-11 19:16:35 +00007693 type_sp,
Greg Clayton9e9f2192013-05-17 00:55:28 +00007694 scope,
7695 symbol_context_scope,
7696 &decl,
7697 location,
7698 is_external,
7699 is_artificial));
7700
7701 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
7702 }
7703 else
7704 {
7705 // Not ready to parse this variable yet. It might be a global
7706 // or static variable that is in a function scope and the function
7707 // in the symbol context wasn't filled in yet
7708 return var_sp;
7709 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007710 }
Greg Clayton7f995132011-10-04 22:41:51 +00007711 // Cache var_sp even if NULL (the variable was just a specification or
7712 // was missing vital information to be able to be displayed in the debugger
7713 // (missing location due to optimization, etc)) so we don't re-parse
7714 // this DIE over and over later...
7715 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007716 }
7717 return var_sp;
7718}
7719
Greg Claytonc662ec82011-06-17 22:10:16 +00007720
7721const DWARFDebugInfoEntry *
7722SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
7723 dw_offset_t spec_block_die_offset,
7724 DWARFCompileUnit **result_die_cu_handle)
7725{
7726 // Give the concrete function die specified by "func_die_offset", find the
7727 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7728 // to "spec_block_die_offset"
7729 DWARFDebugInfo* info = DebugInfo();
7730
7731 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
7732 if (die)
7733 {
7734 assert (*result_die_cu_handle);
7735 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
7736 }
7737 return NULL;
7738}
7739
7740
7741const DWARFDebugInfoEntry *
7742SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
7743 const DWARFDebugInfoEntry *die,
7744 dw_offset_t spec_block_die_offset,
7745 DWARFCompileUnit **result_die_cu_handle)
7746{
7747 if (die)
7748 {
7749 switch (die->Tag())
7750 {
7751 case DW_TAG_subprogram:
7752 case DW_TAG_inlined_subroutine:
7753 case DW_TAG_lexical_block:
7754 {
7755 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
7756 {
7757 *result_die_cu_handle = dwarf_cu;
7758 return die;
7759 }
7760
7761 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
7762 {
7763 *result_die_cu_handle = dwarf_cu;
7764 return die;
7765 }
7766 }
7767 break;
7768 }
7769
7770 // Give the concrete function die specified by "func_die_offset", find the
7771 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7772 // to "spec_block_die_offset"
7773 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
7774 {
7775 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
7776 child_die,
7777 spec_block_die_offset,
7778 result_die_cu_handle);
7779 if (result_die)
7780 return result_die;
7781 }
7782 }
7783
7784 *result_die_cu_handle = NULL;
7785 return NULL;
7786}
7787
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007788size_t
7789SymbolFileDWARF::ParseVariables
7790(
7791 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007792 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007793 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007794 const DWARFDebugInfoEntry *orig_die,
7795 bool parse_siblings,
7796 bool parse_children,
7797 VariableList* cc_variable_list
7798)
7799{
7800 if (orig_die == NULL)
7801 return 0;
7802
Greg Claytonc662ec82011-06-17 22:10:16 +00007803 VariableListSP variable_list_sp;
7804
7805 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007806 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00007807 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007808 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007809 dw_tag_t tag = die->Tag();
7810
7811 // Check to see if we have already parsed this variable or constant?
7812 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007813 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007814 if (cc_variable_list)
7815 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007816 }
7817 else
7818 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007819 // We haven't already parsed it, lets do that now.
7820 if ((tag == DW_TAG_variable) ||
7821 (tag == DW_TAG_constant) ||
7822 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007823 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007824 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00007825 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007826 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
7827 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7828 switch (parent_tag)
7829 {
7830 case DW_TAG_compile_unit:
7831 if (sc.comp_unit != NULL)
7832 {
7833 variable_list_sp = sc.comp_unit->GetVariableList(false);
7834 if (variable_list_sp.get() == NULL)
7835 {
7836 variable_list_sp.reset(new VariableList());
7837 sc.comp_unit->SetVariableList(variable_list_sp);
7838 }
7839 }
7840 else
7841 {
Daniel Malead01b2952012-11-29 21:49:15 +00007842 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 +00007843 MakeUserID(sc_parent_die->GetOffset()),
7844 DW_TAG_value_to_name (parent_tag),
7845 MakeUserID(orig_die->GetOffset()),
7846 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007847 }
7848 break;
7849
7850 case DW_TAG_subprogram:
7851 case DW_TAG_inlined_subroutine:
7852 case DW_TAG_lexical_block:
7853 if (sc.function != NULL)
7854 {
7855 // Check to see if we already have parsed the variables for the given scope
7856
Greg Clayton81c22f62011-10-19 18:09:39 +00007857 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007858 if (block == NULL)
7859 {
7860 // This must be a specification or abstract origin with
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00007861 // a concrete block counterpart in the current function. We need
Greg Claytonc662ec82011-06-17 22:10:16 +00007862 // to find the concrete block so we can correctly add the
7863 // variable to it
7864 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
7865 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
7866 sc_parent_die->GetOffset(),
7867 &concrete_block_die_cu);
7868 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00007869 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007870 }
7871
7872 if (block != NULL)
7873 {
7874 const bool can_create = false;
7875 variable_list_sp = block->GetBlockVariableList (can_create);
7876 if (variable_list_sp.get() == NULL)
7877 {
7878 variable_list_sp.reset(new VariableList());
7879 block->SetVariableList(variable_list_sp);
7880 }
7881 }
7882 }
7883 break;
7884
7885 default:
Daniel Malead01b2952012-11-29 21:49:15 +00007886 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 +00007887 MakeUserID(orig_die->GetOffset()),
7888 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007889 break;
7890 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00007891 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007892
7893 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007894 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00007895 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
7896 if (var_sp)
7897 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007898 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00007899 if (cc_variable_list)
7900 cc_variable_list->AddVariableIfUnique (var_sp);
7901 ++vars_added;
7902 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007903 }
7904 }
7905 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007906
7907 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
7908
7909 if (!skip_children && parse_children && die->HasChildren())
7910 {
7911 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
7912 }
7913
7914 if (parse_siblings)
7915 die = die->GetSibling();
7916 else
7917 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007918 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007919 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007920}
7921
7922//------------------------------------------------------------------
7923// PluginInterface protocol
7924//------------------------------------------------------------------
Greg Clayton57abc5d2013-05-10 21:47:16 +00007925ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007926SymbolFileDWARF::GetPluginName()
7927{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007928 return GetPluginNameStatic();
7929}
7930
7931uint32_t
7932SymbolFileDWARF::GetPluginVersion()
7933{
7934 return 1;
7935}
7936
7937void
Greg Clayton6beaaa62011-01-17 03:46:26 +00007938SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
7939{
7940 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
Greg Clayton57ee3062013-07-11 22:46:58 +00007941 ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
Greg Clayton6beaaa62011-01-17 03:46:26 +00007942 if (clang_type)
7943 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7944}
7945
7946void
7947SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
7948{
7949 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
Greg Clayton57ee3062013-07-11 22:46:58 +00007950 ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
Greg Clayton6beaaa62011-01-17 03:46:26 +00007951 if (clang_type)
7952 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7953}
7954
Greg Claytona2721472011-06-25 00:44:06 +00007955void
Sean Callanancc427fa2011-07-30 02:42:06 +00007956SymbolFileDWARF::DumpIndexes ()
7957{
7958 StreamFile s(stdout, false);
7959
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00007960 s.Printf ("DWARF index for (%s) '%s':",
Sean Callanancc427fa2011-07-30 02:42:06 +00007961 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00007962 GetObjectFile()->GetFileSpec().GetPath().c_str());
Sean Callanancc427fa2011-07-30 02:42:06 +00007963 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
7964 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
7965 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
7966 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
7967 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
7968 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
7969 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
7970 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
7971}
7972
7973void
7974SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
7975 const char *name,
7976 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00007977{
Sean Callanancc427fa2011-07-30 02:42:06 +00007978 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00007979
7980 if (iter == m_decl_ctx_to_die.end())
7981 return;
7982
Greg Claytoncb5860a2011-10-13 23:49:28 +00007983 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00007984 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007985 const DWARFDebugInfoEntry *context_die = *pos;
7986
7987 if (!results)
7988 return;
7989
7990 DWARFDebugInfo* info = DebugInfo();
7991
7992 DIEArray die_offsets;
7993
7994 DWARFCompileUnit* dwarf_cu = NULL;
7995 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton220a0072011-12-09 08:48:30 +00007996
7997 if (m_using_apple_tables)
7998 {
7999 if (m_apple_types_ap.get())
8000 m_apple_types_ap->FindByName (name, die_offsets);
8001 }
8002 else
8003 {
8004 if (!m_indexed)
8005 Index ();
8006
8007 m_type_index.Find (ConstString(name), die_offsets);
8008 }
8009
Greg Clayton220a0072011-12-09 08:48:30 +00008010 const size_t num_matches = die_offsets.size();
Greg Claytoncb5860a2011-10-13 23:49:28 +00008011
8012 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00008013 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00008014 for (size_t i = 0; i < num_matches; ++i)
8015 {
8016 const dw_offset_t die_offset = die_offsets[i];
8017 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00008018
Greg Claytoncb5860a2011-10-13 23:49:28 +00008019 if (die->GetParent() != context_die)
8020 continue;
8021
8022 Type *matching_type = ResolveType (dwarf_cu, die);
8023
Pavel Labathc7c30eb2015-06-08 23:38:06 +00008024 clang::QualType qual_type = matching_type->GetClangForwardType().GetQualType();
Greg Claytoncb5860a2011-10-13 23:49:28 +00008025
8026 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
8027 {
8028 clang::TagDecl *tag_decl = tag_type->getDecl();
8029 results->push_back(tag_decl);
8030 }
8031 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
8032 {
8033 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
8034 results->push_back(typedef_decl);
8035 }
Greg Claytona2721472011-06-25 00:44:06 +00008036 }
8037 }
8038 }
8039}
8040
8041void
8042SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00008043 const clang::DeclContext *decl_context,
8044 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00008045 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
8046{
Greg Clayton85ae2e12011-10-18 23:36:41 +00008047
8048 switch (decl_context->getDeclKind())
8049 {
8050 case clang::Decl::Namespace:
8051 case clang::Decl::TranslationUnit:
8052 {
8053 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
8054 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
8055 }
8056 break;
8057 default:
8058 break;
8059 }
Greg Claytona2721472011-06-25 00:44:06 +00008060}
Greg Claytoncaab74e2012-01-28 00:48:57 +00008061
Zachary Turner504f38d2015-03-24 16:24:50 +00008062bool
8063SymbolFileDWARF::LayoutRecordType(void *baton, const clang::RecordDecl *record_decl, uint64_t &size,
8064 uint64_t &alignment,
Zachary Turnera98fac22015-03-24 18:56:08 +00008065 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
8066 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
8067 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
Greg Claytoncaab74e2012-01-28 00:48:57 +00008068{
8069 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
8070 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
8071}
8072
Zachary Turner504f38d2015-03-24 16:24:50 +00008073bool
8074SymbolFileDWARF::LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &bit_size, uint64_t &alignment,
Zachary Turnera98fac22015-03-24 18:56:08 +00008075 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
8076 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
8077 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
Greg Claytoncaab74e2012-01-28 00:48:57 +00008078{
Greg Clayton5160ce52013-03-27 23:08:40 +00008079 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Claytoncaab74e2012-01-28 00:48:57 +00008080 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
8081 bool success = false;
8082 base_offsets.clear();
8083 vbase_offsets.clear();
8084 if (pos != m_record_decl_to_layout_map.end())
8085 {
8086 bit_size = pos->second.bit_size;
8087 alignment = pos->second.alignment;
8088 field_offsets.swap(pos->second.field_offsets);
Greg Clayton2508b9b2012-11-01 23:20:02 +00008089 base_offsets.swap (pos->second.base_offsets);
8090 vbase_offsets.swap (pos->second.vbase_offsets);
Greg Claytoncaab74e2012-01-28 00:48:57 +00008091 m_record_decl_to_layout_map.erase(pos);
8092 success = true;
8093 }
8094 else
8095 {
8096 bit_size = 0;
8097 alignment = 0;
8098 field_offsets.clear();
8099 }
8100
8101 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00008102 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00008103 "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 +00008104 static_cast<const void*>(record_decl),
8105 bit_size, alignment,
8106 static_cast<uint32_t>(field_offsets.size()),
8107 static_cast<uint32_t>(base_offsets.size()),
8108 static_cast<uint32_t>(vbase_offsets.size()),
Greg Claytoncaab74e2012-01-28 00:48:57 +00008109 success);
8110 return success;
8111}
8112
8113
Greg Clayton1f746072012-08-29 21:13:06 +00008114SymbolFileDWARFDebugMap *
8115SymbolFileDWARF::GetDebugMapSymfile ()
8116{
8117 if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired())
8118 {
8119 lldb::ModuleSP module_sp (m_debug_map_module_wp.lock());
8120 if (module_sp)
8121 {
8122 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
8123 if (sym_vendor)
8124 m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile();
8125 }
8126 }
8127 return m_debug_map_symfile;
8128}
8129
Greg Claytoncaab74e2012-01-28 00:48:57 +00008130