blob: 7ed2998c92bd731e93cc88b4f7751bd1a18a4560 [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.
980 if (cu_file_spec.IsRelativeToCurrentWorkingDirectory())
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
992 LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
993
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)
1195 {
1196 const uint32_t language = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
1197 if (language)
1198 return (lldb::LanguageType)language;
1199 }
Greg Clayton1f746072012-08-29 21:13:06 +00001200 }
1201 return eLanguageTypeUnknown;
1202}
1203
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001204size_t
1205SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
1206{
1207 assert (sc.comp_unit);
1208 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00001209 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001210 if (dwarf_cu)
1211 {
1212 DWARFDIECollection function_dies;
Greg Clayton1f746072012-08-29 21:13:06 +00001213 const size_t num_functions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001214 size_t func_idx;
Greg Clayton1f746072012-08-29 21:13:06 +00001215 for (func_idx = 0; func_idx < num_functions; ++func_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001216 {
1217 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
Greg Clayton81c22f62011-10-19 18:09:39 +00001218 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001219 {
1220 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
1221 ++functions_added;
1222 }
1223 }
1224 //FixupTypes();
1225 }
1226 return functions_added;
1227}
1228
1229bool
1230SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
1231{
1232 assert (sc.comp_unit);
Greg Clayton1f746072012-08-29 21:13:06 +00001233 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Greg Claytonda2455b2012-11-01 17:28:37 +00001234 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001235 {
Greg Claytonda2455b2012-11-01 17:28:37 +00001236 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001237
Greg Claytonda2455b2012-11-01 17:28:37 +00001238 if (cu_die)
1239 {
1240 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
Matthew Gardinere81df3b2014-08-26 06:57:23 +00001241
1242 // DWARF2/3 suggests the form hostname:pathname for compilation directory.
1243 // Remove the host part if present.
1244 cu_comp_dir = removeHostnameFromPathname(cu_comp_dir);
1245
Greg Claytonda2455b2012-11-01 17:28:37 +00001246 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 +00001247
Greg Claytonda2455b2012-11-01 17:28:37 +00001248 // All file indexes in DWARF are one based and a file of index zero is
1249 // supposed to be the compile unit itself.
1250 support_files.Append (*sc.comp_unit);
1251
1252 return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
1253 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001254 }
1255 return false;
1256}
1257
Sean Callananf0c5aeb2015-04-20 16:31:29 +00001258bool
1259SymbolFileDWARF::ParseImportedModules (const lldb_private::SymbolContext &sc, std::vector<lldb_private::ConstString> &imported_modules)
1260{
1261 assert (sc.comp_unit);
1262 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1263 if (dwarf_cu)
1264 {
1265 if (ClangModulesDeclVendor::LanguageSupportsClangModules(sc.comp_unit->GetLanguage()))
1266 {
1267 UpdateExternalModuleListIfNeeded();
1268 for (const std::pair<uint64_t, const ClangModuleInfo> &external_type_module : m_external_type_modules)
1269 {
1270 imported_modules.push_back(external_type_module.second.m_name);
1271 }
1272 }
1273 }
1274 return false;
1275}
1276
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001277struct ParseDWARFLineTableCallbackInfo
1278{
1279 LineTable* line_table;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001280 std::unique_ptr<LineSequence> sequence_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001281};
1282
1283//----------------------------------------------------------------------
1284// ParseStatementTableCallback
1285//----------------------------------------------------------------------
1286static void
1287ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
1288{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001289 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
1290 {
1291 // Just started parsing the line table
1292 }
1293 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
1294 {
1295 // Done parsing line table, nothing to do for the cleanup
1296 }
1297 else
1298 {
1299 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
Greg Clayton9422dd62013-03-04 21:46:16 +00001300 LineTable* line_table = info->line_table;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001301
Greg Clayton9422dd62013-03-04 21:46:16 +00001302 // If this is our first time here, we need to create a
1303 // sequence container.
1304 if (!info->sequence_ap.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001305 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001306 info->sequence_ap.reset(line_table->CreateLineSequenceContainer());
1307 assert(info->sequence_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001308 }
Greg Clayton9422dd62013-03-04 21:46:16 +00001309 line_table->AppendLineEntryToSequence (info->sequence_ap.get(),
1310 state.address,
1311 state.line,
1312 state.column,
1313 state.file,
1314 state.is_stmt,
1315 state.basic_block,
1316 state.prologue_end,
1317 state.epilogue_begin,
1318 state.end_sequence);
1319 if (state.end_sequence)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001320 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001321 // First, put the current sequence into the line table.
1322 line_table->InsertSequence(info->sequence_ap.get());
1323 // Then, empty it to prepare for the next sequence.
1324 info->sequence_ap->Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001325 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001326 }
1327}
1328
1329bool
1330SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1331{
1332 assert (sc.comp_unit);
1333 if (sc.comp_unit->GetLineTable() != NULL)
1334 return true;
1335
Greg Clayton1f746072012-08-29 21:13:06 +00001336 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001337 if (dwarf_cu)
1338 {
1339 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Greg Clayton129d12c2011-11-28 03:29:03 +00001340 if (dwarf_cu_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001341 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001342 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1343 if (cu_line_offset != DW_INVALID_OFFSET)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001344 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001345 std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
Greg Clayton129d12c2011-11-28 03:29:03 +00001346 if (line_table_ap.get())
1347 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001348 ParseDWARFLineTableCallbackInfo info;
1349 info.line_table = line_table_ap.get();
Greg Claytonc7bece562013-01-25 18:06:21 +00001350 lldb::offset_t offset = cu_line_offset;
Greg Clayton129d12c2011-11-28 03:29:03 +00001351 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
Greg Clayton9422dd62013-03-04 21:46:16 +00001352 if (m_debug_map_symfile)
1353 {
1354 // We have an object file that has a line table with addresses
1355 // that are not linked. We need to link the line table and convert
1356 // the addresses that are relative to the .o file into addresses
1357 // for the main executable.
1358 sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get()));
1359 }
1360 else
1361 {
1362 sc.comp_unit->SetLineTable(line_table_ap.release());
1363 return true;
1364 }
Greg Clayton129d12c2011-11-28 03:29:03 +00001365 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001366 }
1367 }
1368 }
1369 return false;
1370}
1371
1372size_t
1373SymbolFileDWARF::ParseFunctionBlocks
1374(
1375 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001376 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001377 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001378 const DWARFDebugInfoEntry *die,
1379 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001380 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001381)
1382{
1383 size_t blocks_added = 0;
1384 while (die != NULL)
1385 {
1386 dw_tag_t tag = die->Tag();
1387
1388 switch (tag)
1389 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001390 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001391 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001392 case DW_TAG_lexical_block:
1393 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001394 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001395 if (tag == DW_TAG_subprogram)
1396 {
1397 // Skip any DW_TAG_subprogram DIEs that are inside
1398 // of a normal or inlined functions. These will be
1399 // parsed on their own as separate entities.
1400
1401 if (depth > 0)
1402 break;
1403
1404 block = parent_block;
1405 }
1406 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001407 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001408 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001409 parent_block->AddChild(block_sp);
1410 block = block_sp.get();
1411 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001412 DWARFDebugRanges::RangeList ranges;
1413 const char *name = NULL;
1414 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001415
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001416 int decl_file = 0;
1417 int decl_line = 0;
1418 int decl_column = 0;
1419 int call_file = 0;
1420 int call_line = 0;
1421 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001422 if (die->GetDIENamesAndRanges (this,
1423 dwarf_cu,
1424 name,
1425 mangled_name,
1426 ranges,
1427 decl_file, decl_line, decl_column,
1428 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001429 {
1430 if (tag == DW_TAG_subprogram)
1431 {
1432 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001433 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001434 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001435 else if (tag == DW_TAG_inlined_subroutine)
1436 {
1437 // We get called here for inlined subroutines in two ways.
1438 // The first time is when we are making the Function object
1439 // for this inlined concrete instance. Since we're creating a top level block at
1440 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1441 // adjust the containing address.
1442 // The second time is when we are parsing the blocks inside the function that contains
1443 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1444 // function the offset will be for that function.
1445 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1446 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001447 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001448 }
1449 }
Greg Clayton103f3092015-01-15 03:04:37 +00001450
1451 const size_t num_ranges = ranges.GetSize();
1452 for (size_t i = 0; i<num_ranges; ++i)
1453 {
1454 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i);
1455 const addr_t range_base = range.GetRangeBase();
1456 if (range_base >= subprogram_low_pc)
1457 block->AddRange(Block::Range (range_base - subprogram_low_pc, range.GetByteSize()));
1458 else
1459 {
1460 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",
1461 block->GetID(),
1462 range_base,
1463 range.GetRangeEnd(),
1464 subprogram_low_pc);
1465 }
1466 }
1467 block->FinalizeRanges ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001468
1469 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1470 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001471 std::unique_ptr<Declaration> decl_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001472 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001473 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1474 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001475
Greg Clayton7b0992d2013-04-18 22:45:39 +00001476 std::unique_ptr<Declaration> call_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001477 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001478 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1479 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001480
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001481 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001482 }
1483
1484 ++blocks_added;
1485
Greg Claytondd7feaf2011-08-12 17:54:33 +00001486 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001487 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001488 blocks_added += ParseFunctionBlocks (sc,
1489 block,
1490 dwarf_cu,
1491 die->GetFirstChild(),
1492 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001493 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001494 }
1495 }
1496 }
1497 break;
1498 default:
1499 break;
1500 }
1501
Greg Claytondd7feaf2011-08-12 17:54:33 +00001502 // Only parse siblings of the block if we are not at depth zero. A depth
1503 // of zero indicates we are currently parsing the top level
1504 // DW_TAG_subprogram DIE
1505
1506 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001507 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001508 else
1509 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001510 }
1511 return blocks_added;
1512}
1513
Greg Claytonf0705c82011-10-22 03:33:13 +00001514bool
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001515SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu,
1516 const DWARFDebugInfoEntry *die,
1517 ClangASTContext::TemplateParameterInfos &template_param_infos)
1518{
1519 const dw_tag_t tag = die->Tag();
1520
1521 switch (tag)
1522 {
1523 case DW_TAG_template_type_parameter:
1524 case DW_TAG_template_value_parameter:
1525 {
Todd Fialaee8bfc62014-09-11 17:29:12 +00001526 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001527
1528 DWARFDebugInfoEntry::Attributes attributes;
1529 const size_t num_attributes = die->GetAttributes (this,
1530 dwarf_cu,
1531 fixed_form_sizes,
1532 attributes);
1533 const char *name = NULL;
1534 Type *lldb_type = NULL;
Greg Clayton57ee3062013-07-11 22:46:58 +00001535 ClangASTType clang_type;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001536 uint64_t uval64 = 0;
1537 bool uval64_valid = false;
1538 if (num_attributes > 0)
1539 {
1540 DWARFFormValue form_value;
1541 for (size_t i=0; i<num_attributes; ++i)
1542 {
1543 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1544
1545 switch (attr)
1546 {
1547 case DW_AT_name:
1548 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1549 name = form_value.AsCString(&get_debug_str_data());
1550 break;
1551
1552 case DW_AT_type:
1553 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1554 {
Greg Clayton54166af2014-11-22 01:58:59 +00001555 const dw_offset_t type_die_offset = form_value.Reference();
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001556 lldb_type = ResolveTypeUID(type_die_offset);
1557 if (lldb_type)
1558 clang_type = lldb_type->GetClangForwardType();
1559 }
1560 break;
1561
1562 case DW_AT_const_value:
1563 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1564 {
1565 uval64_valid = true;
1566 uval64 = form_value.Unsigned();
1567 }
1568 break;
1569 default:
1570 break;
1571 }
1572 }
1573
Greg Clayton283b2652013-04-23 22:38:02 +00001574 clang::ASTContext *ast = GetClangASTContext().getASTContext();
1575 if (!clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00001576 clang_type = GetClangASTContext().GetBasicType(eBasicTypeVoid);
Greg Clayton283b2652013-04-23 22:38:02 +00001577
1578 if (clang_type)
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001579 {
1580 bool is_signed = false;
Greg Clayton283b2652013-04-23 22:38:02 +00001581 if (name && name[0])
1582 template_param_infos.names.push_back(name);
1583 else
1584 template_param_infos.names.push_back(NULL);
1585
Greg Clayton283b2652013-04-23 22:38:02 +00001586 if (tag == DW_TAG_template_value_parameter &&
1587 lldb_type != NULL &&
Greg Clayton57ee3062013-07-11 22:46:58 +00001588 clang_type.IsIntegerType (is_signed) &&
Greg Clayton283b2652013-04-23 22:38:02 +00001589 uval64_valid)
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001590 {
1591 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
Greg Clayton283b2652013-04-23 22:38:02 +00001592 template_param_infos.args.push_back (clang::TemplateArgument (*ast,
Sean Callanan3d654b32012-09-24 22:25:51 +00001593 llvm::APSInt(apint),
Greg Clayton57ee3062013-07-11 22:46:58 +00001594 clang_type.GetQualType()));
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001595 }
1596 else
1597 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001598 template_param_infos.args.push_back (clang::TemplateArgument (clang_type.GetQualType()));
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001599 }
1600 }
1601 else
1602 {
1603 return false;
1604 }
1605
1606 }
1607 }
1608 return true;
1609
1610 default:
1611 break;
1612 }
1613 return false;
1614}
1615
1616bool
Greg Claytonf0705c82011-10-22 03:33:13 +00001617SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1618 const DWARFDebugInfoEntry *parent_die,
1619 ClangASTContext::TemplateParameterInfos &template_param_infos)
1620{
1621
1622 if (parent_die == NULL)
Filipe Cabecinhas52008c62012-05-23 16:24:11 +00001623 return false;
Greg Claytonf0705c82011-10-22 03:33:13 +00001624
Greg Claytonf0705c82011-10-22 03:33:13 +00001625 Args template_parameter_names;
1626 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1627 die != NULL;
1628 die = die->GetSibling())
1629 {
1630 const dw_tag_t tag = die->Tag();
1631
1632 switch (tag)
1633 {
1634 case DW_TAG_template_type_parameter:
1635 case DW_TAG_template_value_parameter:
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001636 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Claytonf0705c82011-10-22 03:33:13 +00001637 break;
1638
1639 default:
1640 break;
1641 }
1642 }
1643 if (template_param_infos.args.empty())
1644 return false;
1645 return template_param_infos.args.size() == template_param_infos.names.size();
1646}
1647
1648clang::ClassTemplateDecl *
1649SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001650 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001651 const char *parent_name,
1652 int tag_decl_kind,
1653 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1654{
1655 if (template_param_infos.IsValid())
1656 {
1657 std::string template_basename(parent_name);
1658 template_basename.erase (template_basename.find('<'));
1659 ClangASTContext &ast = GetClangASTContext();
1660
1661 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001662 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001663 template_basename.c_str(),
1664 tag_decl_kind,
1665 template_param_infos);
1666 }
1667 return NULL;
1668}
1669
Sean Callanana0b80ab2012-06-04 22:28:05 +00001670class SymbolFileDWARF::DelayedAddObjCClassProperty
1671{
1672public:
1673 DelayedAddObjCClassProperty
1674 (
Greg Clayton57ee3062013-07-11 22:46:58 +00001675 const ClangASTType &class_opaque_type,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001676 const char *property_name,
Greg Clayton57ee3062013-07-11 22:46:58 +00001677 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 +00001678 clang::ObjCIvarDecl *ivar_decl,
1679 const char *property_setter_name,
1680 const char *property_getter_name,
1681 uint32_t property_attributes,
Greg Claytonc4ffd662013-03-08 01:37:30 +00001682 const ClangASTMetadata *metadata
Sean Callanana0b80ab2012-06-04 22:28:05 +00001683 ) :
Sean Callanana0b80ab2012-06-04 22:28:05 +00001684 m_class_opaque_type (class_opaque_type),
1685 m_property_name (property_name),
1686 m_property_opaque_type (property_opaque_type),
1687 m_ivar_decl (ivar_decl),
1688 m_property_setter_name (property_setter_name),
1689 m_property_getter_name (property_getter_name),
Jim Ingham379397632012-10-27 02:54:13 +00001690 m_property_attributes (property_attributes)
Sean Callanana0b80ab2012-06-04 22:28:05 +00001691 {
Jim Ingham379397632012-10-27 02:54:13 +00001692 if (metadata != NULL)
1693 {
1694 m_metadata_ap.reset(new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001695 *m_metadata_ap = *metadata;
Jim Ingham379397632012-10-27 02:54:13 +00001696 }
1697 }
1698
1699 DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs)
1700 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001701 *this = rhs;
Daniel Malead4c5be62012-11-12 21:02:14 +00001702 }
1703
1704 DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs)
1705 {
Jim Ingham379397632012-10-27 02:54:13 +00001706 m_class_opaque_type = rhs.m_class_opaque_type;
1707 m_property_name = rhs.m_property_name;
1708 m_property_opaque_type = rhs.m_property_opaque_type;
1709 m_ivar_decl = rhs.m_ivar_decl;
1710 m_property_setter_name = rhs.m_property_setter_name;
1711 m_property_getter_name = rhs.m_property_getter_name;
1712 m_property_attributes = rhs.m_property_attributes;
1713
1714 if (rhs.m_metadata_ap.get())
1715 {
1716 m_metadata_ap.reset (new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001717 *m_metadata_ap = *rhs.m_metadata_ap;
Jim Ingham379397632012-10-27 02:54:13 +00001718 }
Daniel Malead4c5be62012-11-12 21:02:14 +00001719 return *this;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001720 }
1721
Greg Clayton57ee3062013-07-11 22:46:58 +00001722 bool
1723 Finalize()
Sean Callanana0b80ab2012-06-04 22:28:05 +00001724 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001725 return m_class_opaque_type.AddObjCClassProperty (m_property_name,
1726 m_property_opaque_type,
1727 m_ivar_decl,
1728 m_property_setter_name,
1729 m_property_getter_name,
1730 m_property_attributes,
1731 m_metadata_ap.get());
Sean Callanana0b80ab2012-06-04 22:28:05 +00001732 }
1733private:
Greg Clayton57ee3062013-07-11 22:46:58 +00001734 ClangASTType m_class_opaque_type;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001735 const char *m_property_name;
Greg Clayton57ee3062013-07-11 22:46:58 +00001736 ClangASTType m_property_opaque_type;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001737 clang::ObjCIvarDecl *m_ivar_decl;
1738 const char *m_property_setter_name;
1739 const char *m_property_getter_name;
1740 uint32_t m_property_attributes;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001741 std::unique_ptr<ClangASTMetadata> m_metadata_ap;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001742};
1743
Sean Callananfaa0bb32012-12-05 23:37:14 +00001744struct BitfieldInfo
1745{
1746 uint64_t bit_size;
1747 uint64_t bit_offset;
1748
1749 BitfieldInfo () :
1750 bit_size (LLDB_INVALID_ADDRESS),
1751 bit_offset (LLDB_INVALID_ADDRESS)
1752 {
1753 }
1754
Greg Clayton78f4d952013-12-11 23:10:39 +00001755 void
1756 Clear()
1757 {
1758 bit_size = LLDB_INVALID_ADDRESS;
1759 bit_offset = LLDB_INVALID_ADDRESS;
1760 }
1761
Sean Callananfaa0bb32012-12-05 23:37:14 +00001762 bool IsValid ()
1763 {
1764 return (bit_size != LLDB_INVALID_ADDRESS) &&
1765 (bit_offset != LLDB_INVALID_ADDRESS);
1766 }
1767};
1768
Greg Claytonc4ffd662013-03-08 01:37:30 +00001769
1770bool
1771SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu,
1772 const DWARFDebugInfoEntry *parent_die)
1773{
1774 if (parent_die)
1775 {
1776 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1777 {
1778 dw_tag_t tag = die->Tag();
1779 bool check_virtuality = false;
1780 switch (tag)
1781 {
1782 case DW_TAG_inheritance:
1783 case DW_TAG_subprogram:
1784 check_virtuality = true;
1785 break;
1786 default:
1787 break;
1788 }
1789 if (check_virtuality)
1790 {
1791 if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0)
1792 return true;
1793 }
1794 }
1795 }
1796 return false;
1797}
1798
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001799size_t
1800SymbolFileDWARF::ParseChildMembers
1801(
1802 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001803 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001804 const DWARFDebugInfoEntry *parent_die,
Greg Clayton57ee3062013-07-11 22:46:58 +00001805 ClangASTType &class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001806 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001807 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1808 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001809 DWARFDIECollection& member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001810 DelayedPropertyList& delayed_properties,
Sean Callananc7fbf732010-08-06 00:32:49 +00001811 AccessType& default_accessibility,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001812 bool &is_a_class,
1813 LayoutInfo &layout_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001814)
1815{
1816 if (parent_die == NULL)
1817 return 0;
1818
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001819 size_t count = 0;
1820 const DWARFDebugInfoEntry *die;
Todd Fialaee8bfc62014-09-11 17:29:12 +00001821 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001822 uint32_t member_idx = 0;
Sean Callananfaa0bb32012-12-05 23:37:14 +00001823 BitfieldInfo last_field_info;
Richard Mitton0a558352013-10-17 21:14:00 +00001824 ModuleSP module = GetObjectFile()->GetModule();
Greg Claytond88d7592010-09-15 08:33:30 +00001825
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001826 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1827 {
1828 dw_tag_t tag = die->Tag();
1829
1830 switch (tag)
1831 {
1832 case DW_TAG_member:
Sean Callanan3d654b32012-09-24 22:25:51 +00001833 case DW_TAG_APPLE_property:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001834 {
1835 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001836 const size_t num_attributes = die->GetAttributes (this,
1837 dwarf_cu,
1838 fixed_form_sizes,
1839 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001840 if (num_attributes > 0)
1841 {
1842 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001843 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001844 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001845 const char *prop_name = NULL;
1846 const char *prop_getter_name = NULL;
1847 const char *prop_setter_name = NULL;
Greg Claytone528efd72013-02-26 23:45:18 +00001848 uint32_t prop_attributes = 0;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001849
1850
Greg Clayton24739922010-10-13 03:15:28 +00001851 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001852 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001853 AccessType accessibility = eAccessNone;
Greg Claytoncaab74e2012-01-28 00:48:57 +00001854 uint32_t member_byte_offset = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001855 size_t byte_size = 0;
1856 size_t bit_offset = 0;
1857 size_t bit_size = 0;
Greg Claytone528efd72013-02-26 23:45:18 +00001858 bool is_external = false; // On DW_TAG_members, this means the member is static
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001859 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001860 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001861 {
1862 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1863 DWARFFormValue form_value;
1864 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1865 {
1866 switch (attr)
1867 {
1868 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1869 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1870 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1871 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00001872 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001873 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1874 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1875 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1876 case DW_AT_data_member_location:
Greg Claytoncaab74e2012-01-28 00:48:57 +00001877 if (form_value.BlockData())
1878 {
1879 Value initialValue(0);
1880 Value memberOffset(0);
Ed Masteeeae7212013-10-24 20:43:47 +00001881 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Claytoncaab74e2012-01-28 00:48:57 +00001882 uint32_t block_length = form_value.Unsigned();
1883 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1884 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
Greg Claytoncaab74e2012-01-28 00:48:57 +00001885 NULL, // ClangExpressionVariableList *
1886 NULL, // ClangExpressionDeclMap *
1887 NULL, // RegisterContext *
Richard Mitton0a558352013-10-17 21:14:00 +00001888 module,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001889 debug_info_data,
1890 block_offset,
1891 block_length,
1892 eRegisterKindDWARF,
1893 &initialValue,
1894 memberOffset,
1895 NULL))
1896 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001897 member_byte_offset = memberOffset.ResolveValue(NULL).UInt();
Greg Claytoncaab74e2012-01-28 00:48:57 +00001898 }
1899 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00001900 else
1901 {
1902 // With DWARF 3 and later, if the value is an integer constant,
1903 // this form value is the offset in bytes from the beginning
1904 // of the containing entity.
1905 member_byte_offset = form_value.Unsigned();
1906 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001907 break;
1908
Greg Clayton8cf05932010-07-22 18:30:50 +00001909 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00001910 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001911 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1912 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1913 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1914 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00001915 case DW_AT_external: is_external = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001916
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001917 default:
Greg Clayton1b02c172012-03-14 21:00:47 +00001918 case DW_AT_declaration:
1919 case DW_AT_description:
1920 case DW_AT_mutable:
1921 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001922 case DW_AT_sibling:
1923 break;
1924 }
1925 }
1926 }
Sean Callanana6582262012-04-05 00:12:52 +00001927
1928 if (prop_name)
Sean Callanan751aac62012-03-29 19:07:06 +00001929 {
Sean Callanana6582262012-04-05 00:12:52 +00001930 ConstString fixed_getter;
1931 ConstString fixed_setter;
1932
1933 // Check if the property getter/setter were provided as full
1934 // names. We want basenames, so we extract them.
1935
1936 if (prop_getter_name && prop_getter_name[0] == '-')
1937 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001938 ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true);
1939 prop_getter_name = prop_getter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001940 }
1941
1942 if (prop_setter_name && prop_setter_name[0] == '-')
1943 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001944 ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true);
1945 prop_setter_name = prop_setter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001946 }
1947
1948 // If the names haven't been provided, they need to be
1949 // filled in.
1950
1951 if (!prop_getter_name)
1952 {
1953 prop_getter_name = prop_name;
1954 }
1955 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly))
1956 {
1957 StreamString ss;
1958
1959 ss.Printf("set%c%s:",
1960 toupper(prop_name[0]),
1961 &prop_name[1]);
1962
1963 fixed_setter.SetCString(ss.GetData());
1964 prop_setter_name = fixed_setter.GetCString();
1965 }
Sean Callanan751aac62012-03-29 19:07:06 +00001966 }
1967
1968 // Clang has a DWARF generation bug where sometimes it
Greg Clayton44953932011-10-25 01:25:35 +00001969 // represents fields that are references with bad byte size
1970 // and bit size/offset information such as:
1971 //
1972 // DW_AT_byte_size( 0x00 )
1973 // DW_AT_bit_size( 0x40 )
1974 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1975 //
1976 // So check the bit offset to make sure it is sane, and if
1977 // the values are not sane, remove them. If we don't do this
1978 // then we will end up with a crash if we try to use this
1979 // type in an expression when clang becomes unhappy with its
1980 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001981
Greg Clayton44953932011-10-25 01:25:35 +00001982 if (bit_offset > 128)
1983 {
1984 bit_size = 0;
1985 bit_offset = 0;
1986 }
1987
1988 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00001989 if (class_language == eLanguageTypeObjC ||
1990 class_language == eLanguageTypeObjC_plus_plus)
1991 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001992
1993 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1994 {
1995 // Not all compilers will mark the vtable pointer
1996 // member as artificial (llvm-gcc). We can't have
1997 // the virtual members in our classes otherwise it
1998 // throws off all child offsets since we end up
1999 // having and extra pointer sized member in our
2000 // class layouts.
2001 is_artificial = true;
2002 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002003
Greg Clayton29659712013-07-12 20:08:35 +00002004 // Handle static members
Greg Claytone528efd72013-02-26 23:45:18 +00002005 if (is_external && member_byte_offset == UINT32_MAX)
Greg Clayton973b6c92013-04-11 16:57:51 +00002006 {
2007 Type *var_type = ResolveTypeUID(encoding_uid);
2008
2009 if (var_type)
2010 {
Greg Clayton29659712013-07-12 20:08:35 +00002011 if (accessibility == eAccessNone)
2012 accessibility = eAccessPublic;
Greg Clayton57ee3062013-07-11 22:46:58 +00002013 class_clang_type.AddVariableToRecordType (name,
2014 var_type->GetClangLayoutType(),
2015 accessibility);
Greg Clayton973b6c92013-04-11 16:57:51 +00002016 }
Greg Claytone528efd72013-02-26 23:45:18 +00002017 break;
Greg Clayton973b6c92013-04-11 16:57:51 +00002018 }
Greg Claytone528efd72013-02-26 23:45:18 +00002019
Greg Clayton24739922010-10-13 03:15:28 +00002020 if (is_artificial == false)
2021 {
2022 Type *member_type = ResolveTypeUID(encoding_uid);
Sean Callananfa3ab452012-12-14 00:54:13 +00002023
Jim Inghame3ae82a2011-11-12 01:36:43 +00002024 clang::FieldDecl *field_decl = NULL;
Sean Callanan751aac62012-03-29 19:07:06 +00002025 if (tag == DW_TAG_member)
Greg Claytond16e1e52011-07-12 17:06:17 +00002026 {
Sean Callanan751aac62012-03-29 19:07:06 +00002027 if (member_type)
2028 {
2029 if (accessibility == eAccessNone)
2030 accessibility = default_accessibility;
2031 member_accessibilities.push_back(accessibility);
Sean Callananfaa0bb32012-12-05 23:37:14 +00002032
Greg Clayton78f4d952013-12-11 23:10:39 +00002033 uint64_t field_bit_offset = (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
2034 if (bit_size > 0)
Greg Clayton88bc7f32012-11-06 00:20:41 +00002035 {
Greg Clayton78f4d952013-12-11 23:10:39 +00002036
2037 BitfieldInfo this_field_info;
2038 this_field_info.bit_offset = field_bit_offset;
2039 this_field_info.bit_size = bit_size;
2040
Sean Callananfaa0bb32012-12-05 23:37:14 +00002041 /////////////////////////////////////////////////////////////
2042 // How to locate a field given the DWARF debug information
2043 //
2044 // AT_byte_size indicates the size of the word in which the
2045 // bit offset must be interpreted.
2046 //
2047 // AT_data_member_location indicates the byte offset of the
2048 // word from the base address of the structure.
2049 //
2050 // AT_bit_offset indicates how many bits into the word
2051 // (according to the host endianness) the low-order bit of
2052 // the field starts. AT_bit_offset can be negative.
2053 //
2054 // AT_bit_size indicates the size of the field in bits.
2055 /////////////////////////////////////////////////////////////
2056
Greg Clayton78f4d952013-12-11 23:10:39 +00002057 if (byte_size == 0)
2058 byte_size = member_type->GetByteSize();
2059
Sean Callananfaa0bb32012-12-05 23:37:14 +00002060 if (GetObjectFile()->GetByteOrder() == eByteOrderLittle)
2061 {
2062 this_field_info.bit_offset += byte_size * 8;
2063 this_field_info.bit_offset -= (bit_offset + bit_size);
2064 }
2065 else
2066 {
2067 this_field_info.bit_offset += bit_offset;
2068 }
Greg Clayton78f4d952013-12-11 23:10:39 +00002069
2070 // Update the field bit offset we will report for layout
2071 field_bit_offset = this_field_info.bit_offset;
Sean Callananfaa0bb32012-12-05 23:37:14 +00002072
Greg Clayton78f4d952013-12-11 23:10:39 +00002073 // If the member to be emitted did not start on a character boundary and there is
2074 // empty space between the last field and this one, then we need to emit an
2075 // anonymous member filling up the space up to its start. There are three cases
2076 // here:
2077 //
2078 // 1 If the previous member ended on a character boundary, then we can emit an
2079 // anonymous member starting at the most recent character boundary.
2080 //
2081 // 2 If the previous member did not end on a character boundary and the distance
2082 // from the end of the previous member to the current member is less than a
2083 // word width, then we can emit an anonymous member starting right after the
2084 // previous member and right before this member.
2085 //
2086 // 3 If the previous member did not end on a character boundary and the distance
2087 // from the end of the previous member to the current member is greater than
2088 // or equal a word width, then we act as in Case 1.
2089
2090 const uint64_t character_width = 8;
2091 const uint64_t word_width = 32;
2092
Sean Callananfaa0bb32012-12-05 23:37:14 +00002093 // Objective-C has invalid DW_AT_bit_offset values in older versions
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +00002094 // of clang, so we have to be careful and only insert unnamed bitfields
Greg Clayton37c36e42012-11-27 00:59:26 +00002095 // if we have a new enough clang.
2096 bool detect_unnamed_bitfields = true;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002097
Greg Clayton37c36e42012-11-27 00:59:26 +00002098 if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus)
2099 detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields ();
2100
2101 if (detect_unnamed_bitfields)
Greg Clayton88bc7f32012-11-06 00:20:41 +00002102 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00002103 BitfieldInfo anon_field_info;
2104
2105 if ((this_field_info.bit_offset % character_width) != 0) // not char aligned
Greg Clayton88bc7f32012-11-06 00:20:41 +00002106 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00002107 uint64_t last_field_end = 0;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002108
Sean Callananfaa0bb32012-12-05 23:37:14 +00002109 if (last_field_info.IsValid())
2110 last_field_end = last_field_info.bit_offset + last_field_info.bit_size;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002111
Sean Callananfaa0bb32012-12-05 23:37:14 +00002112 if (this_field_info.bit_offset != last_field_end)
2113 {
2114 if (((last_field_end % character_width) == 0) || // case 1
2115 (this_field_info.bit_offset - last_field_end >= word_width)) // case 3
2116 {
2117 anon_field_info.bit_size = this_field_info.bit_offset % character_width;
2118 anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size;
2119 }
2120 else // case 2
2121 {
2122 anon_field_info.bit_size = this_field_info.bit_offset - last_field_end;
2123 anon_field_info.bit_offset = last_field_end;
2124 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00002125 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00002126 }
2127
Sean Callananfaa0bb32012-12-05 23:37:14 +00002128 if (anon_field_info.IsValid())
Greg Clayton88bc7f32012-11-06 00:20:41 +00002129 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002130 clang::FieldDecl *unnamed_bitfield_decl = class_clang_type.AddFieldToRecordType (NULL,
2131 GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width),
2132 accessibility,
2133 anon_field_info.bit_size);
Zachary Turner504f38d2015-03-24 16:24:50 +00002134
Zachary Turnera98fac22015-03-24 18:56:08 +00002135 layout_info.field_offsets.insert(
Zachary Turner504f38d2015-03-24 16:24:50 +00002136 std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset));
Greg Clayton88bc7f32012-11-06 00:20:41 +00002137 }
2138 }
Greg Clayton78f4d952013-12-11 23:10:39 +00002139 last_field_info = this_field_info;
2140 }
2141 else
2142 {
2143 last_field_info.Clear();
Greg Clayton88bc7f32012-11-06 00:20:41 +00002144 }
Sean Callananfaa0bb32012-12-05 23:37:14 +00002145
Greg Clayton57ee3062013-07-11 22:46:58 +00002146 ClangASTType member_clang_type = member_type->GetClangLayoutType();
Sean Callananfa3ab452012-12-14 00:54:13 +00002147
2148 {
2149 // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>).
2150 // If the current field is at the end of the structure, then there is definitely no room for extra
2151 // elements and we override the type to array[0].
2152
Greg Clayton57ee3062013-07-11 22:46:58 +00002153 ClangASTType member_array_element_type;
Sean Callananfa3ab452012-12-14 00:54:13 +00002154 uint64_t member_array_size;
2155 bool member_array_is_incomplete;
2156
Greg Clayton57ee3062013-07-11 22:46:58 +00002157 if (member_clang_type.IsArrayType(&member_array_element_type,
2158 &member_array_size,
2159 &member_array_is_incomplete) &&
Sean Callananfa3ab452012-12-14 00:54:13 +00002160 !member_array_is_incomplete)
2161 {
2162 uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX);
2163
2164 if (member_byte_offset >= parent_byte_size)
2165 {
2166 if (member_array_size != 1)
2167 {
2168 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,
2169 MakeUserID(die->GetOffset()),
2170 name,
2171 encoding_uid,
2172 MakeUserID(parent_die->GetOffset()));
2173 }
2174
Greg Clayton1c8ef472013-04-05 23:27:21 +00002175 member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0, false);
Sean Callananfa3ab452012-12-14 00:54:13 +00002176 }
2177 }
2178 }
2179
Greg Clayton57ee3062013-07-11 22:46:58 +00002180 field_decl = class_clang_type.AddFieldToRecordType (name,
2181 member_clang_type,
2182 accessibility,
2183 bit_size);
Sean Callanan60217122012-04-13 00:10:03 +00002184
Greg Claytond0029442013-03-27 01:48:02 +00002185 GetClangASTContext().SetMetadataAsUserID (field_decl, MakeUserID(die->GetOffset()));
Greg Clayton78f4d952013-12-11 23:10:39 +00002186
Zachary Turnera98fac22015-03-24 18:56:08 +00002187 layout_info.field_offsets.insert(std::make_pair(field_decl, field_bit_offset));
Sean Callanan5b26f272012-02-04 08:49:35 +00002188 }
2189 else
2190 {
Sean Callanan751aac62012-03-29 19:07:06 +00002191 if (name)
Daniel Malead01b2952012-11-29 21:49:15 +00002192 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 +00002193 MakeUserID(die->GetOffset()),
2194 name,
2195 encoding_uid);
2196 else
Daniel Malead01b2952012-11-29 21:49:15 +00002197 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 +00002198 MakeUserID(die->GetOffset()),
2199 encoding_uid);
Sean Callanan5b26f272012-02-04 08:49:35 +00002200 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002201 }
Sean Callanan751aac62012-03-29 19:07:06 +00002202
Jim Inghame3ae82a2011-11-12 01:36:43 +00002203 if (prop_name != NULL)
2204 {
Sean Callanan751aac62012-03-29 19:07:06 +00002205 clang::ObjCIvarDecl *ivar_decl = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00002206
Sean Callanan751aac62012-03-29 19:07:06 +00002207 if (field_decl)
2208 {
2209 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
2210 assert (ivar_decl != NULL);
2211 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00002212
Jim Ingham379397632012-10-27 02:54:13 +00002213 ClangASTMetadata metadata;
2214 metadata.SetUserID (MakeUserID(die->GetOffset()));
Greg Clayton57ee3062013-07-11 22:46:58 +00002215 delayed_properties.push_back(DelayedAddObjCClassProperty(class_clang_type,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002216 prop_name,
2217 member_type->GetClangLayoutType(),
2218 ivar_decl,
2219 prop_setter_name,
2220 prop_getter_name,
2221 prop_attributes,
Jim Ingham379397632012-10-27 02:54:13 +00002222 &metadata));
Sean Callanan60217122012-04-13 00:10:03 +00002223
Sean Callananad880762012-04-18 01:06:17 +00002224 if (ivar_decl)
Greg Claytond0029442013-03-27 01:48:02 +00002225 GetClangASTContext().SetMetadataAsUserID (ivar_decl, MakeUserID(die->GetOffset()));
Jim Inghame3ae82a2011-11-12 01:36:43 +00002226 }
Greg Clayton24739922010-10-13 03:15:28 +00002227 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002228 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00002229 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002230 }
2231 break;
2232
2233 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00002234 // Let the type parsing code handle this one for us.
2235 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002236 break;
2237
2238 case DW_TAG_inheritance:
2239 {
2240 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00002241 if (default_accessibility == eAccessNone)
2242 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002243 // TODO: implement DW_TAG_inheritance type parsing
2244 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00002245 const size_t num_attributes = die->GetAttributes (this,
2246 dwarf_cu,
2247 fixed_form_sizes,
2248 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002249 if (num_attributes > 0)
2250 {
2251 Declaration decl;
2252 DWARFExpression location;
2253 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00002254 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002255 bool is_virtual = false;
2256 bool is_base_of_class = true;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002257 off_t member_byte_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002258 uint32_t i;
2259 for (i=0; i<num_attributes; ++i)
2260 {
2261 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2262 DWARFFormValue form_value;
2263 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2264 {
2265 switch (attr)
2266 {
2267 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2268 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2269 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00002270 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002271 case DW_AT_data_member_location:
2272 if (form_value.BlockData())
2273 {
2274 Value initialValue(0);
2275 Value memberOffset(0);
Ed Masteeeae7212013-10-24 20:43:47 +00002276 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002277 uint32_t block_length = form_value.Unsigned();
2278 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
2279 if (DWARFExpression::Evaluate (NULL,
2280 NULL,
2281 NULL,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002282 NULL,
Richard Mitton0a558352013-10-17 21:14:00 +00002283 module,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002284 debug_info_data,
2285 block_offset,
2286 block_length,
2287 eRegisterKindDWARF,
2288 &initialValue,
2289 memberOffset,
2290 NULL))
2291 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002292 member_byte_offset = memberOffset.ResolveValue(NULL).UInt();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002293 }
2294 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002295 else
2296 {
2297 // With DWARF 3 and later, if the value is an integer constant,
2298 // this form value is the offset in bytes from the beginning
2299 // of the containing entity.
2300 member_byte_offset = form_value.Unsigned();
2301 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002302 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002303
2304 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00002305 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002306 break;
2307
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002308 case DW_AT_virtuality:
2309 is_virtual = form_value.Boolean();
2310 break;
2311
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002312 case DW_AT_sibling:
2313 break;
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002314
2315 default:
2316 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002317 }
2318 }
2319 }
2320
Greg Clayton526e5af2010-11-13 03:52:47 +00002321 Type *base_class_type = ResolveTypeUID(encoding_uid);
Greg Clayton898c1b22015-05-15 22:31:18 +00002322 if (base_class_type == NULL)
2323 {
2324 GetObjectFile()->GetModule()->ReportError("0x%8.8x: DW_TAG_inheritance failed to resolve a 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",
2325 die->GetOffset(),
2326 encoding_uid,
2327 parent_die->GetOffset());
2328 break;
2329 }
2330
Greg Clayton57ee3062013-07-11 22:46:58 +00002331 ClangASTType base_class_clang_type = base_class_type->GetClangFullType();
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002332 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002333 if (class_language == eLanguageTypeObjC)
2334 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002335 class_clang_type.SetObjCSuperClass(base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002336 }
2337 else
2338 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002339 base_classes.push_back (base_class_clang_type.CreateBaseClassSpecifier (accessibility,
Greg Claytonba2d22d2010-11-13 22:57:37 +00002340 is_virtual,
2341 is_base_of_class));
Greg Clayton2508b9b2012-11-01 23:20:02 +00002342
2343 if (is_virtual)
2344 {
Greg Clayton52694e32013-09-16 21:57:07 +00002345 // Do not specify any offset for virtual inheritance. The DWARF produced by clang doesn't
2346 // give us a constant offset, but gives us a DWARF expressions that requires an actual object
2347 // in memory. the DW_AT_data_member_location for a virtual base class looks like:
2348 // DW_AT_data_member_location( DW_OP_dup, DW_OP_deref, DW_OP_constu(0x00000018), DW_OP_minus, DW_OP_deref, DW_OP_plus )
2349 // Given this, there is really no valid response we can give to clang for virtual base
2350 // class offsets, and this should eventually be removed from LayoutRecordType() in the external
2351 // AST source in clang.
Greg Clayton2508b9b2012-11-01 23:20:02 +00002352 }
2353 else
2354 {
Zachary Turnera98fac22015-03-24 18:56:08 +00002355 layout_info.base_offsets.insert(
Zachary Turner504f38d2015-03-24 16:24:50 +00002356 std::make_pair(base_class_clang_type.GetAsCXXRecordDecl(),
2357 clang::CharUnits::fromQuantity(member_byte_offset)));
Greg Clayton2508b9b2012-11-01 23:20:02 +00002358 }
Greg Clayton9e409562010-07-28 02:04:09 +00002359 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002360 }
2361 }
2362 break;
2363
2364 default:
2365 break;
2366 }
2367 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002368
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002369 return count;
2370}
2371
2372
2373clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00002374SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002375{
2376 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00002377 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002378 {
2379 DWARFCompileUnitSP cu_sp;
2380 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
2381 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00002382 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00002383 }
2384 return NULL;
2385}
2386
2387clang::DeclContext*
2388SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
2389{
Greg Clayton81c22f62011-10-19 18:09:39 +00002390 if (UserIDMatches(type_uid))
2391 return GetClangDeclContextForDIEOffset (sc, type_uid);
2392 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002393}
2394
2395Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00002396SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002397{
Greg Clayton81c22f62011-10-19 18:09:39 +00002398 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002399 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002400 DWARFDebugInfo* debug_info = DebugInfo();
2401 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00002402 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002403 DWARFCompileUnitSP cu_sp;
2404 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00002405 const bool assert_not_being_parsed = true;
2406 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00002407 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002408 }
2409 return NULL;
2410}
2411
Greg Claytoncab36a32011-12-08 05:16:30 +00002412Type*
2413SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00002414{
Greg Claytoncab36a32011-12-08 05:16:30 +00002415 if (die != NULL)
2416 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002417 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00002418 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002419 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002420 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
2421 die->GetOffset(),
2422 DW_TAG_value_to_name(die->Tag()),
2423 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00002424
Greg Claytoncab36a32011-12-08 05:16:30 +00002425 // We might be coming in in the middle of a type tree (a class
2426 // withing a class, an enum within a class), so parse any needed
2427 // parent DIEs before we get to this one...
2428 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2429 switch (decl_ctx_die->Tag())
2430 {
2431 case DW_TAG_structure_type:
2432 case DW_TAG_union_type:
2433 case DW_TAG_class_type:
2434 {
2435 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00002436 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002437 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002438 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
2439 die->GetOffset(),
2440 DW_TAG_value_to_name(die->Tag()),
2441 die->GetName(this, cu),
2442 decl_ctx_die->GetOffset());
Greg Clayton219cf312012-03-30 00:51:13 +00002443//
2444// Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
2445// if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
2446// {
2447// if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002448// GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton219cf312012-03-30 00:51:13 +00002449// "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
2450// die->GetOffset(),
2451// DW_TAG_value_to_name(die->Tag()),
2452// die->GetName(this, cu),
2453// decl_ctx_die->GetOffset());
2454// // Ask the type to complete itself if it already hasn't since if we
2455// // want a function (method or static) from a class, the class must
2456// // create itself and add it's own methods and class functions.
2457// if (parent_type)
2458// parent_type->GetClangFullType();
2459// }
Greg Claytoncab36a32011-12-08 05:16:30 +00002460 }
2461 break;
2462
2463 default:
2464 break;
2465 }
2466 return ResolveType (cu, die);
2467 }
2468 return NULL;
2469}
2470
Greg Clayton6beaaa62011-01-17 03:46:26 +00002471// This function is used when SymbolFileDWARFDebugMap owns a bunch of
2472// SymbolFileDWARF objects to detect if this DWARF file is the one that
2473// can resolve a clang_type.
2474bool
Greg Clayton57ee3062013-07-11 22:46:58 +00002475SymbolFileDWARF::HasForwardDeclForClangType (const ClangASTType &clang_type)
Greg Clayton6beaaa62011-01-17 03:46:26 +00002476{
Greg Clayton57ee3062013-07-11 22:46:58 +00002477 ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers();
2478 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton6beaaa62011-01-17 03:46:26 +00002479 return die != NULL;
2480}
2481
2482
Greg Clayton57ee3062013-07-11 22:46:58 +00002483bool
2484SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (ClangASTType &clang_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00002485{
2486 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton57ee3062013-07-11 22:46:58 +00002487 ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers();
2488 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton1be10fc2010-09-29 01:12:09 +00002489 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00002490 {
2491 // We have already resolved this type...
Greg Clayton57ee3062013-07-11 22:46:58 +00002492 return true;
Greg Clayton73b472d2010-10-27 03:32:59 +00002493 }
2494 // Once we start resolving this type, remove it from the forward declaration
2495 // map in case anyone child members or other types require this type to get resolved.
2496 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
2497 // are done.
Greg Clayton57ee3062013-07-11 22:46:58 +00002498 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton1be10fc2010-09-29 01:12:09 +00002499
Greg Clayton85ae2e12011-10-18 23:36:41 +00002500 // Disable external storage for this type so we don't get anymore
2501 // clang::ExternalASTSource queries for this type.
Greg Clayton57ee3062013-07-11 22:46:58 +00002502 clang_type.SetHasExternalStorage (false);
Greg Clayton85ae2e12011-10-18 23:36:41 +00002503
Greg Clayton450e3f32010-10-12 02:24:53 +00002504 DWARFDebugInfo* debug_info = DebugInfo();
2505
Greg Clayton53eb1c22012-04-02 22:59:12 +00002506 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002507 Type *type = m_die_to_type.lookup (die);
2508
2509 const dw_tag_t tag = die->Tag();
2510
Greg Clayton5160ce52013-03-27 23:08:40 +00002511 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
Greg Clayton3bffb082011-12-10 02:15:28 +00002512 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002513 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002514 "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...",
Greg Claytond61c0fc2012-04-23 22:55:20 +00002515 MakeUserID(die->GetOffset()),
2516 DW_TAG_value_to_name(tag),
2517 type->GetName().AsCString());
Greg Clayton1be10fc2010-09-29 01:12:09 +00002518 assert (clang_type);
2519 DWARFDebugInfoEntry::Attributes attributes;
2520
Greg Clayton1be10fc2010-09-29 01:12:09 +00002521 switch (tag)
2522 {
2523 case DW_TAG_structure_type:
2524 case DW_TAG_union_type:
2525 case DW_TAG_class_type:
Greg Claytonc93237c2010-10-01 20:48:32 +00002526 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002527 LayoutInfo layout_info;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002528
Greg Clayton1be10fc2010-09-29 01:12:09 +00002529 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002530 if (die->HasChildren())
Greg Claytonc93237c2010-10-01 20:48:32 +00002531 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002532 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton57ee3062013-07-11 22:46:58 +00002533 if (clang_type.IsObjCObjectOrInterfaceType())
Greg Clayton219cf312012-03-30 00:51:13 +00002534 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002535 class_language = eLanguageTypeObjC;
Greg Clayton219cf312012-03-30 00:51:13 +00002536 // For objective C we don't start the definition when
2537 // the class is created.
Greg Clayton57ee3062013-07-11 22:46:58 +00002538 clang_type.StartTagDeclarationDefinition ();
Greg Clayton219cf312012-03-30 00:51:13 +00002539 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002540
Sean Callanan77a1fd32012-02-27 20:07:01 +00002541 int tag_decl_kind = -1;
2542 AccessType default_accessibility = eAccessNone;
2543 if (tag == DW_TAG_structure_type)
2544 {
2545 tag_decl_kind = clang::TTK_Struct;
2546 default_accessibility = eAccessPublic;
2547 }
2548 else if (tag == DW_TAG_union_type)
2549 {
2550 tag_decl_kind = clang::TTK_Union;
2551 default_accessibility = eAccessPublic;
2552 }
2553 else if (tag == DW_TAG_class_type)
2554 {
2555 tag_decl_kind = clang::TTK_Class;
2556 default_accessibility = eAccessPrivate;
2557 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002558
Greg Clayton53eb1c22012-04-02 22:59:12 +00002559 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002560 std::vector<clang::CXXBaseSpecifier *> base_classes;
2561 std::vector<int> member_accessibilities;
2562 bool is_a_class = false;
2563 // Parse members and base classes first
2564 DWARFDIECollection member_function_dies;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002565
Sean Callanana0b80ab2012-06-04 22:28:05 +00002566 DelayedPropertyList delayed_properties;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002567 ParseChildMembers (sc,
Greg Clayton53eb1c22012-04-02 22:59:12 +00002568 dwarf_cu,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002569 die,
2570 clang_type,
2571 class_language,
2572 base_classes,
2573 member_accessibilities,
2574 member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002575 delayed_properties,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002576 default_accessibility,
2577 is_a_class,
2578 layout_info);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002579
Sean Callanan77a1fd32012-02-27 20:07:01 +00002580 // Now parse any methods if there were any...
2581 size_t num_functions = member_function_dies.Size();
2582 if (num_functions > 0)
2583 {
2584 for (size_t i=0; i<num_functions; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002585 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002586 ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytoncaab74e2012-01-28 00:48:57 +00002587 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002588 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002589
Sean Callanan77a1fd32012-02-27 20:07:01 +00002590 if (class_language == eLanguageTypeObjC)
2591 {
Jim Inghamfb6fc0d2013-09-27 20:59:37 +00002592 ConstString class_name (clang_type.GetTypeName());
2593 if (class_name)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002594 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002595 DIEArray method_die_offsets;
2596 if (m_using_apple_tables)
Greg Clayton95d87902011-11-11 03:16:25 +00002597 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002598 if (m_apple_objc_ap.get())
Jim Inghamfb6fc0d2013-09-27 20:59:37 +00002599 m_apple_objc_ap->FindByName(class_name.GetCString(), method_die_offsets);
Sean Callanan77a1fd32012-02-27 20:07:01 +00002600 }
2601 else
2602 {
2603 if (!m_indexed)
2604 Index ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002605
Sean Callanan77a1fd32012-02-27 20:07:01 +00002606 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
2607 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002608
Sean Callanan77a1fd32012-02-27 20:07:01 +00002609 if (!method_die_offsets.empty())
2610 {
2611 DWARFDebugInfo* debug_info = DebugInfo();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002612
Sean Callanan77a1fd32012-02-27 20:07:01 +00002613 DWARFCompileUnit* method_cu = NULL;
2614 const size_t num_matches = method_die_offsets.size();
2615 for (size_t i=0; i<num_matches; ++i)
Greg Clayton95d87902011-11-11 03:16:25 +00002616 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002617 const dw_offset_t die_offset = method_die_offsets[i];
2618 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002619
Sean Callanan77a1fd32012-02-27 20:07:01 +00002620 if (method_die)
2621 ResolveType (method_cu, method_die);
2622 else
Greg Claytoncaab74e2012-01-28 00:48:57 +00002623 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002624 if (m_using_apple_tables)
2625 {
2626 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 +00002627 die_offset, class_name.GetCString());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002628 }
2629 }
2630 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002631 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002632
Greg Clayton57ee3062013-07-11 22:46:58 +00002633 for (DelayedPropertyList::iterator pi = delayed_properties.begin(), pe = delayed_properties.end();
Sean Callanana0b80ab2012-06-04 22:28:05 +00002634 pi != pe;
2635 ++pi)
2636 pi->Finalize();
Greg Clayton450e3f32010-10-12 02:24:53 +00002637 }
2638 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002639
Sean Callanan77a1fd32012-02-27 20:07:01 +00002640 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2641 // need to tell the clang type it is actually a class.
2642 if (class_language != eLanguageTypeObjC)
2643 {
2644 if (is_a_class && tag_decl_kind != clang::TTK_Class)
Greg Clayton57ee3062013-07-11 22:46:58 +00002645 clang_type.SetTagTypeKind (clang::TTK_Class);
Sean Callanan77a1fd32012-02-27 20:07:01 +00002646 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002647
Sean Callanan77a1fd32012-02-27 20:07:01 +00002648 // Since DW_TAG_structure_type gets used for both classes
2649 // and structures, we may need to set any DW_TAG_member
2650 // fields to have a "private" access if none was specified.
2651 // When we parsed the child members we tracked that actual
2652 // accessibility value for each DW_TAG_member in the
2653 // "member_accessibilities" array. If the value for the
2654 // member is zero, then it was set to the "default_accessibility"
2655 // which for structs was "public". Below we correct this
2656 // by setting any fields to "private" that weren't correctly
2657 // set.
2658 if (is_a_class && !member_accessibilities.empty())
2659 {
2660 // This is a class and all members that didn't have
2661 // their access specified are private.
Greg Clayton57ee3062013-07-11 22:46:58 +00002662 clang_type.SetDefaultAccessForRecordFields (eAccessPrivate,
2663 &member_accessibilities.front(),
2664 member_accessibilities.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002665 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002666
Sean Callanan77a1fd32012-02-27 20:07:01 +00002667 if (!base_classes.empty())
2668 {
Greg Clayton4705f8d2013-12-12 01:54:04 +00002669 // Make sure all base classes refer to complete types and not
2670 // forward declarations. If we don't do this, clang will crash
2671 // with an assertion in the call to clang_type.SetBaseClassesForClassType()
2672 bool base_class_error = false;
2673 for (auto &base_class : base_classes)
2674 {
2675 clang::TypeSourceInfo *type_source_info = base_class->getTypeSourceInfo();
2676 if (type_source_info)
2677 {
2678 ClangASTType base_class_type (GetClangASTContext().getASTContext(), type_source_info->getType());
2679 if (base_class_type.GetCompleteType() == false)
2680 {
2681 if (!base_class_error)
2682 {
2683 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",
2684 die->GetOffset(),
2685 die->GetName(this, dwarf_cu),
2686 base_class_type.GetTypeName().GetCString(),
2687 sc.comp_unit ? sc.comp_unit->GetPath().c_str() : "the source file");
2688 }
2689 // We have no choice other than to pretend that the base class
2690 // is complete. If we don't do this, clang will crash when we
2691 // call setBases() inside of "clang_type.SetBaseClassesForClassType()"
2692 // below. Since we provide layout assistance, all ivars in this
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00002693 // class and other classes will be fine, this is the best we can do
Greg Clayton4705f8d2013-12-12 01:54:04 +00002694 // short of crashing.
2695 base_class_type.StartTagDeclarationDefinition ();
2696 base_class_type.CompleteTagDeclarationDefinition ();
2697 }
2698 }
2699 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002700 clang_type.SetBaseClassesForClassType (&base_classes.front(),
2701 base_classes.size());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002702
Sean Callanan77a1fd32012-02-27 20:07:01 +00002703 // Clang will copy each CXXBaseSpecifier in "base_classes"
2704 // so we have to free them all.
Greg Clayton57ee3062013-07-11 22:46:58 +00002705 ClangASTType::DeleteBaseClassSpecifiers (&base_classes.front(),
2706 base_classes.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002707 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002708 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002709 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002710
Greg Clayton57ee3062013-07-11 22:46:58 +00002711 clang_type.BuildIndirectFields ();
2712 clang_type.CompleteTagDeclarationDefinition ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002713
Greg Clayton2508b9b2012-11-01 23:20:02 +00002714 if (!layout_info.field_offsets.empty() ||
2715 !layout_info.base_offsets.empty() ||
2716 !layout_info.vbase_offsets.empty() )
Greg Claytoncaab74e2012-01-28 00:48:57 +00002717 {
2718 if (type)
2719 layout_info.bit_size = type->GetByteSize() * 8;
2720 if (layout_info.bit_size == 0)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002721 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002722
Greg Clayton57ee3062013-07-11 22:46:58 +00002723 clang::CXXRecordDecl *record_decl = clang_type.GetAsCXXRecordDecl();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002724 if (record_decl)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002725 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002726 if (log)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002727 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002728 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002729 "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 +00002730 static_cast<void*>(clang_type.GetOpaqueQualType()),
2731 static_cast<void*>(record_decl),
Greg Claytoncaab74e2012-01-28 00:48:57 +00002732 layout_info.bit_size,
2733 layout_info.alignment,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002734 static_cast<uint32_t>(layout_info.field_offsets.size()),
2735 static_cast<uint32_t>(layout_info.base_offsets.size()),
2736 static_cast<uint32_t>(layout_info.vbase_offsets.size()));
2737
Zachary Turnera98fac22015-03-24 18:56:08 +00002738 uint32_t idx;
2739 {
2740 llvm::DenseMap<const clang::FieldDecl *, uint64_t>::const_iterator pos,
2741 end = layout_info.field_offsets.end();
2742 for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx)
Greg Clayton2508b9b2012-11-01 23:20:02 +00002743 {
Zachary Turner504f38d2015-03-24 16:24:50 +00002744 GetObjectFile()->GetModule()->LogMessage(
2745 log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = "
2746 "{ bit_offset=%u, name='%s' }",
Zachary Turner504f38d2015-03-24 16:24:50 +00002747 static_cast<void *>(clang_type.GetOpaqueQualType()), idx,
Zachary Turnera98fac22015-03-24 18:56:08 +00002748 static_cast<uint32_t>(pos->second), pos->first->getNameAsString().c_str());
2749 }
2750 }
2751
2752 {
2753 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos,
2754 base_end = layout_info.base_offsets.end();
2755 for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end;
2756 ++base_pos, ++idx)
2757 {
2758 GetObjectFile()->GetModule()->LogMessage(
2759 log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] "
2760 "= { byte_offset=%u, name='%s' }",
2761 clang_type.GetOpaqueQualType(), idx, (uint32_t)base_pos->second.getQuantity(),
2762 base_pos->first->getNameAsString().c_str());
2763 }
2764 }
2765 {
2766 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos,
2767 vbase_end = layout_info.vbase_offsets.end();
2768 for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end;
2769 ++vbase_pos, ++idx)
2770 {
2771 GetObjectFile()->GetModule()->LogMessage(
2772 log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) "
2773 "vbase[%u] = { byte_offset=%u, name='%s' }",
2774 static_cast<void *>(clang_type.GetOpaqueQualType()), idx,
2775 static_cast<uint32_t>(vbase_pos->second.getQuantity()),
2776 vbase_pos->first->getNameAsString().c_str());
2777 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002778 }
Greg Clayton821ac6d2012-01-28 02:22:27 +00002779 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002780 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2781 }
2782 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002783 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002784
Sean Callanan9076c0f2013-10-04 21:35:29 +00002785 return (bool)clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002786
2787 case DW_TAG_enumeration_type:
Greg Clayton57ee3062013-07-11 22:46:58 +00002788 clang_type.StartTagDeclarationDefinition ();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002789 if (die->HasChildren())
2790 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002791 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00002792 bool is_signed = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00002793 clang_type.IsIntegerType(is_signed);
Greg Clayton3e067532013-03-05 23:54:39 +00002794 ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002795 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002796 clang_type.CompleteTagDeclarationDefinition ();
Sean Callanan9076c0f2013-10-04 21:35:29 +00002797 return (bool)clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002798
2799 default:
2800 assert(false && "not a forward clang type decl!");
2801 break;
2802 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002803 return false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002804}
2805
Greg Claytonc685f8e2010-09-15 04:15:46 +00002806Type*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002807SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002808{
2809 if (type_die != NULL)
2810 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002811 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00002812
Greg Claytonc685f8e2010-09-15 04:15:46 +00002813 if (type == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002814 type = GetTypeForDIE (dwarf_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00002815
Greg Clayton24739922010-10-13 03:15:28 +00002816 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00002817 {
2818 if (type != DIE_IS_BEING_PARSED)
2819 return type;
2820
2821 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
Greg Clayton53eb1c22012-04-02 22:59:12 +00002822 type_die->GetOffset(),
2823 DW_TAG_value_to_name(type_die->Tag()),
2824 type_die->GetName(this, dwarf_cu));
Jim Inghamc3549282012-01-11 02:21:12 +00002825
2826 }
2827 else
2828 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002829 }
2830 return NULL;
2831}
2832
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002833CompileUnit*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002834SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002835{
2836 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002837 if (dwarf_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002838 {
2839 // The symbol vendor doesn't know about this compile unit, we
2840 // need to parse and add it to the symbol vendor object.
Greg Clayton53eb1c22012-04-02 22:59:12 +00002841 return ParseCompileUnit(dwarf_cu, cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002842 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00002843 return (CompileUnit*)dwarf_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002844}
2845
2846bool
Greg Clayton53eb1c22012-04-02 22:59:12 +00002847SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002848{
Greg Clayton72310352013-02-23 04:12:47 +00002849 sc.Clear(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002850 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002851 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002852
Greg Clayton81c22f62011-10-19 18:09:39 +00002853 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002854 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002855 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002856
2857 if (sc.function)
2858 {
Greg Claytone72dfb32012-02-24 01:59:29 +00002859 sc.module_sp = sc.function->CalculateSymbolContextModule();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002860 return true;
2861 }
2862
2863 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002864}
2865
Sean Callananf0c5aeb2015-04-20 16:31:29 +00002866void
2867SymbolFileDWARF::UpdateExternalModuleListIfNeeded()
2868{
2869 if (m_fetched_external_modules)
2870 return;
2871 m_fetched_external_modules = true;
2872
2873 DWARFDebugInfo * debug_info = DebugInfo();
2874 debug_info->GetNumCompileUnits();
2875
2876 const uint32_t num_compile_units = GetNumCompileUnits();
2877 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2878 {
2879 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
2880
2881 const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly();
2882 if (die && die->HasChildren() == false)
2883 {
2884 const uint64_t name_strp = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_name, UINT64_MAX);
2885 const uint64_t dwo_path_strp = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_GNU_dwo_name, UINT64_MAX);
2886
2887 if (name_strp != UINT64_MAX)
2888 {
2889 if (m_external_type_modules.find(dwo_path_strp) == m_external_type_modules.end())
2890 {
2891 const char *name = get_debug_str_data().PeekCStr(name_strp);
2892 const char *dwo_path = get_debug_str_data().PeekCStr(dwo_path_strp);
2893 if (name || dwo_path)
2894 {
2895 ModuleSP module_sp;
2896 if (dwo_path)
2897 {
2898 ModuleSpec dwo_module_spec;
2899 dwo_module_spec.GetFileSpec().SetFile(dwo_path, false);
2900 dwo_module_spec.GetArchitecture() = m_obj_file->GetModule()->GetArchitecture();
2901 //printf ("Loading dwo = '%s'\n", dwo_path);
2902 Error error = ModuleList::GetSharedModule (dwo_module_spec, module_sp, NULL, NULL, NULL);
2903 }
2904
2905 if (dwo_path_strp != LLDB_INVALID_UID)
2906 {
2907 m_external_type_modules[dwo_path_strp] = ClangModuleInfo { ConstString(name), module_sp };
2908 }
2909 else
2910 {
2911 // This hack should be removed promptly once clang emits both.
2912 m_external_type_modules[name_strp] = ClangModuleInfo { ConstString(name), module_sp };
2913 }
2914 }
2915 }
2916 }
2917 }
2918 }
2919}
Greg Clayton2501e5e2015-01-15 02:59:20 +00002920
2921SymbolFileDWARF::GlobalVariableMap &
2922SymbolFileDWARF::GetGlobalAranges()
2923{
2924 if (!m_global_aranges_ap)
2925 {
2926 m_global_aranges_ap.reset (new GlobalVariableMap());
2927
2928 ModuleSP module_sp = GetObjectFile()->GetModule();
2929 if (module_sp)
2930 {
2931 const size_t num_cus = module_sp->GetNumCompileUnits();
2932 for (size_t i = 0; i < num_cus; ++i)
2933 {
2934 CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(i);
2935 if (cu_sp)
2936 {
2937 VariableListSP globals_sp = cu_sp->GetVariableList(true);
2938 if (globals_sp)
2939 {
2940 const size_t num_globals = globals_sp->GetSize();
2941 for (size_t g = 0; g < num_globals; ++g)
2942 {
2943 VariableSP var_sp = globals_sp->GetVariableAtIndex(g);
2944 if (var_sp && !var_sp->GetLocationIsConstantValueData())
2945 {
2946 const DWARFExpression &location = var_sp->LocationExpression();
2947 Value location_result;
2948 Error error;
2949 if (location.Evaluate(NULL, NULL, NULL, LLDB_INVALID_ADDRESS, NULL, location_result, &error))
2950 {
2951 if (location_result.GetValueType() == Value::eValueTypeFileAddress)
2952 {
2953 lldb::addr_t file_addr = location_result.GetScalar().ULongLong();
2954 lldb::addr_t byte_size = 1;
2955 if (var_sp->GetType())
2956 byte_size = var_sp->GetType()->GetByteSize();
2957 m_global_aranges_ap->Append(GlobalVariableMap::Entry(file_addr, byte_size, var_sp.get()));
2958 }
2959 }
2960 }
2961 }
2962 }
2963 }
2964 }
2965 }
2966 m_global_aranges_ap->Sort();
2967 }
2968 return *m_global_aranges_ap;
2969}
2970
2971
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002972uint32_t
2973SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2974{
2975 Timer scoped_timer(__PRETTY_FUNCTION__,
Daniel Malead01b2952012-11-29 21:49:15 +00002976 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002977 static_cast<void*>(so_addr.GetSection().get()),
2978 so_addr.GetOffset(), resolve_scope);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002979 uint32_t resolved = 0;
Greg Clayton2501e5e2015-01-15 02:59:20 +00002980 if (resolve_scope & ( eSymbolContextCompUnit |
2981 eSymbolContextFunction |
2982 eSymbolContextBlock |
2983 eSymbolContextLineEntry |
2984 eSymbolContextVariable ))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002985 {
2986 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2987
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002988 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00002989 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002990 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002991 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Greg Clayton2501e5e2015-01-15 02:59:20 +00002992 if (cu_offset == DW_INVALID_OFFSET)
2993 {
2994 // Global variables are not in the compile unit address ranges. The only way to
2995 // currently find global variables is to iterate over the .debug_pubnames or the
2996 // __apple_names table and find all items in there that point to DW_TAG_variable
2997 // DIEs and then find the address that matches.
2998 if (resolve_scope & eSymbolContextVariable)
2999 {
3000 GlobalVariableMap &map = GetGlobalAranges();
3001 const GlobalVariableMap::Entry *entry = map.FindEntryThatContains(file_vm_addr);
3002 if (entry && entry->data)
3003 {
3004 Variable *variable = entry->data;
3005 SymbolContextScope *scc = variable->GetSymbolContextScope();
3006 if (scc)
3007 {
3008 scc->CalculateSymbolContext(&sc);
3009 sc.variable = variable;
3010 }
3011 return sc.GetResolvedMask();
3012 }
3013 }
3014 }
3015 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003016 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003017 uint32_t cu_idx = DW_INVALID_INDEX;
Greg Clayton53eb1c22012-04-02 22:59:12 +00003018 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
3019 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003020 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003021 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00003022 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003023 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003024 resolved |= eSymbolContextCompUnit;
3025
Greg Clayton6ab80132012-12-12 17:30:52 +00003026 bool force_check_line_table = false;
Greg Clayton526a4ae2012-05-16 22:09:01 +00003027 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
3028 {
3029 DWARFDebugInfoEntry *function_die = NULL;
3030 DWARFDebugInfoEntry *block_die = NULL;
3031 if (resolve_scope & eSymbolContextBlock)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003032 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003033 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
3034 }
3035 else
3036 {
3037 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL);
3038 }
3039
3040 if (function_die != NULL)
3041 {
3042 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
3043 if (sc.function == NULL)
3044 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
3045 }
3046 else
3047 {
3048 // We might have had a compile unit that had discontiguous
3049 // address ranges where the gaps are symbols that don't have
3050 // any debug info. Discontiguous compile unit address ranges
3051 // should only happen when there aren't other functions from
3052 // other compile units in these gaps. This helps keep the size
3053 // of the aranges down.
Greg Clayton6ab80132012-12-12 17:30:52 +00003054 force_check_line_table = true;
Greg Clayton526a4ae2012-05-16 22:09:01 +00003055 }
3056
3057 if (sc.function != NULL)
3058 {
3059 resolved |= eSymbolContextFunction;
3060
3061 if (resolve_scope & eSymbolContextBlock)
3062 {
3063 Block& block = sc.function->GetBlock (true);
3064
3065 if (block_die != NULL)
3066 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
3067 else
3068 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
3069 if (sc.block)
3070 resolved |= eSymbolContextBlock;
3071 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003072 }
3073 }
Greg Clayton6ab80132012-12-12 17:30:52 +00003074
3075 if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table)
3076 {
3077 LineTable *line_table = sc.comp_unit->GetLineTable();
3078 if (line_table != NULL)
3079 {
Greg Clayton9422dd62013-03-04 21:46:16 +00003080 // And address that makes it into this function should be in terms
3081 // of this debug file if there is no debug map, or it will be an
3082 // address in the .o file which needs to be fixed up to be in terms
3083 // of the debug map executable. Either way, calling FixupAddress()
3084 // will work for us.
3085 Address exe_so_addr (so_addr);
3086 if (FixupAddress(exe_so_addr))
Greg Clayton6ab80132012-12-12 17:30:52 +00003087 {
Greg Clayton9422dd62013-03-04 21:46:16 +00003088 if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry))
Greg Clayton6ab80132012-12-12 17:30:52 +00003089 {
3090 resolved |= eSymbolContextLineEntry;
3091 }
3092 }
Greg Clayton6ab80132012-12-12 17:30:52 +00003093 }
3094 }
3095
3096 if (force_check_line_table && !(resolved & eSymbolContextLineEntry))
3097 {
3098 // We might have had a compile unit that had discontiguous
3099 // address ranges where the gaps are symbols that don't have
3100 // any debug info. Discontiguous compile unit address ranges
3101 // should only happen when there aren't other functions from
3102 // other compile units in these gaps. This helps keep the size
3103 // of the aranges down.
3104 sc.comp_unit = NULL;
3105 resolved &= ~eSymbolContextCompUnit;
3106 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003107 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00003108 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003109 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003110 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.",
3111 cu_offset,
3112 cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003113 }
3114 }
3115 }
3116 }
3117 }
3118 return resolved;
3119}
3120
3121
3122
3123uint32_t
3124SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
3125{
3126 const uint32_t prev_size = sc_list.GetSize();
3127 if (resolve_scope & eSymbolContextCompUnit)
3128 {
3129 DWARFDebugInfo* debug_info = DebugInfo();
3130 if (debug_info)
3131 {
3132 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00003133 DWARFCompileUnit* dwarf_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003134
Greg Clayton53eb1c22012-04-02 22:59:12 +00003135 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003136 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003137 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Sean Callananddd7a2a2013-10-03 22:27:29 +00003138 const bool full_match = (bool)file_spec.GetDirectory();
Greg Clayton1f746072012-08-29 21:13:06 +00003139 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 +00003140 if (check_inlines || file_spec_matches_cu_file_spec)
3141 {
3142 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton53eb1c22012-04-02 22:59:12 +00003143 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00003144 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003145 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003146 uint32_t file_idx = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003147
Greg Clayton526a4ae2012-05-16 22:09:01 +00003148 // If we are looking for inline functions only and we don't
3149 // find it in the support files, we are done.
3150 if (check_inlines)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003151 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003152 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
3153 if (file_idx == UINT32_MAX)
3154 continue;
3155 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003156
Greg Clayton526a4ae2012-05-16 22:09:01 +00003157 if (line != 0)
3158 {
3159 LineTable *line_table = sc.comp_unit->GetLineTable();
3160
3161 if (line_table != NULL && line != 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003162 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003163 // We will have already looked up the file index if
3164 // we are searching for inline entries.
3165 if (!check_inlines)
3166 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003167
Greg Clayton526a4ae2012-05-16 22:09:01 +00003168 if (file_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003169 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003170 uint32_t found_line;
3171 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
3172 found_line = sc.line_entry.line;
3173
3174 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003175 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003176 sc.function = NULL;
3177 sc.block = NULL;
3178 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003179 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003180 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
3181 if (file_vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003182 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003183 DWARFDebugInfoEntry *function_die = NULL;
3184 DWARFDebugInfoEntry *block_die = NULL;
3185 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003186
Greg Clayton526a4ae2012-05-16 22:09:01 +00003187 if (function_die != NULL)
3188 {
3189 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
3190 if (sc.function == NULL)
3191 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
3192 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003193
Greg Clayton526a4ae2012-05-16 22:09:01 +00003194 if (sc.function != NULL)
3195 {
3196 Block& block = sc.function->GetBlock (true);
3197
3198 if (block_die != NULL)
3199 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
Jason Molenda60db6e42014-10-16 01:40:16 +00003200 else if (function_die != NULL)
Greg Clayton526a4ae2012-05-16 22:09:01 +00003201 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
3202 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003203 }
3204 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003205
Greg Clayton526a4ae2012-05-16 22:09:01 +00003206 sc_list.Append(sc);
3207 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
3208 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003209 }
3210 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00003211 else if (file_spec_matches_cu_file_spec && !check_inlines)
3212 {
3213 // only append the context if we aren't looking for inline call sites
3214 // by file and line and if the file spec matches that of the compile unit
3215 sc_list.Append(sc);
3216 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003217 }
3218 else if (file_spec_matches_cu_file_spec && !check_inlines)
3219 {
3220 // only append the context if we aren't looking for inline call sites
3221 // by file and line and if the file spec matches that of the compile unit
3222 sc_list.Append(sc);
3223 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003224
Greg Clayton526a4ae2012-05-16 22:09:01 +00003225 if (!check_inlines)
3226 break;
3227 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003228 }
3229 }
3230 }
3231 }
3232 return sc_list.GetSize() - prev_size;
3233}
3234
3235void
3236SymbolFileDWARF::Index ()
3237{
3238 if (m_indexed)
3239 return;
3240 m_indexed = true;
3241 Timer scoped_timer (__PRETTY_FUNCTION__,
3242 "SymbolFileDWARF::Index (%s)",
Jim Ingham4af59612014-12-19 19:20:44 +00003243 GetObjectFile()->GetFileSpec().GetFilename().AsCString("<Unknown>"));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003244
3245 DWARFDebugInfo* debug_info = DebugInfo();
3246 if (debug_info)
3247 {
3248 uint32_t cu_idx = 0;
3249 const uint32_t num_compile_units = GetNumCompileUnits();
3250 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
3251 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003252 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003253
Greg Clayton53eb1c22012-04-02 22:59:12 +00003254 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003255
Greg Clayton53eb1c22012-04-02 22:59:12 +00003256 dwarf_cu->Index (cu_idx,
3257 m_function_basename_index,
3258 m_function_fullname_index,
3259 m_function_method_index,
3260 m_function_selector_index,
3261 m_objc_class_selectors_index,
3262 m_global_index,
3263 m_type_index,
3264 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003265
3266 // Keep memory down by clearing DIEs if this generate function
3267 // caused them to be parsed
3268 if (clear_dies)
Greg Clayton53eb1c22012-04-02 22:59:12 +00003269 dwarf_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003270 }
3271
Greg Claytond4a2b372011-09-12 23:21:58 +00003272 m_function_basename_index.Finalize();
3273 m_function_fullname_index.Finalize();
3274 m_function_method_index.Finalize();
3275 m_function_selector_index.Finalize();
3276 m_objc_class_selectors_index.Finalize();
3277 m_global_index.Finalize();
3278 m_type_index.Finalize();
3279 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003280
Greg Clayton24739922010-10-13 03:15:28 +00003281#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00003282 StreamFile s(stdout, false);
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00003283 s.Printf ("DWARF index for '%s':",
3284 GetObjectFile()->GetFileSpec().GetPath().c_str());
Greg Claytonba2d22d2010-11-13 22:57:37 +00003285 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
3286 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
3287 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
3288 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
3289 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
3290 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00003291 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00003292 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00003293#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003294 }
3295}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003296
3297bool
3298SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
3299{
3300 if (namespace_decl == NULL)
3301 {
3302 // Invalid namespace decl which means we aren't matching only things
3303 // in this symbol file, so return true to indicate it matches this
3304 // symbol file.
3305 return true;
3306 }
3307
3308 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
3309
3310 if (namespace_ast == NULL)
3311 return true; // No AST in the "namespace_decl", return true since it
3312 // could then match any symbol file, including this one
3313
3314 if (namespace_ast == GetClangASTContext().getASTContext())
3315 return true; // The ASTs match, return true
3316
3317 // The namespace AST was valid, and it does not match...
Greg Clayton5160ce52013-03-27 23:08:40 +00003318 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Sean Callananc41e68b2011-10-13 21:08:11 +00003319
3320 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003321 GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00003322
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003323 return false;
3324}
3325
Greg Clayton2506a7a2011-10-12 23:34:26 +00003326bool
3327SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
3328 DWARFCompileUnit* cu,
3329 const DWARFDebugInfoEntry* die)
3330{
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +00003331 // No namespace specified, so the answer is
Greg Clayton2506a7a2011-10-12 23:34:26 +00003332 if (namespace_decl == NULL)
3333 return true;
Sean Callananebe60672011-10-13 21:50:33 +00003334
Greg Clayton5160ce52013-03-27 23:08:40 +00003335 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003336
Greg Clayton437a1352012-04-09 22:43:43 +00003337 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
3338 clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00003339 if (decl_ctx_die)
Greg Clayton437a1352012-04-09 22:43:43 +00003340 {
Greg Clayton2506a7a2011-10-12 23:34:26 +00003341 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
Greg Clayton437a1352012-04-09 22:43:43 +00003342
Greg Clayton2506a7a2011-10-12 23:34:26 +00003343 if (clang_namespace_decl)
3344 {
3345 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00003346 {
3347 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003348 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00003349 return false;
Sean Callananebe60672011-10-13 21:50:33 +00003350 }
3351
Greg Clayton437a1352012-04-09 22:43:43 +00003352 if (clang_namespace_decl == die_clang_decl_ctx)
3353 return true;
3354 else
Greg Clayton2506a7a2011-10-12 23:34:26 +00003355 return false;
Greg Clayton2506a7a2011-10-12 23:34:26 +00003356 }
3357 else
3358 {
3359 // We have a namespace_decl that was not NULL but it contained
3360 // a NULL "clang::NamespaceDecl", so this means the global namespace
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00003361 // So as long the contained decl context DIE isn't a namespace
Greg Clayton2506a7a2011-10-12 23:34:26 +00003362 // we should be ok.
3363 if (decl_ctx_die->Tag() != DW_TAG_namespace)
3364 return true;
3365 }
3366 }
Sean Callananebe60672011-10-13 21:50:33 +00003367
3368 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003369 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00003370
Greg Clayton2506a7a2011-10-12 23:34:26 +00003371 return false;
3372}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003373uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00003374SymbolFileDWARF::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 +00003375{
Greg Clayton5160ce52013-03-27 23:08:40 +00003376 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003377
3378 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003379 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003380 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
3381 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003382 static_cast<const void*>(namespace_decl),
3383 append, max_matches);
3384
Sean Callanan213fdb82011-10-13 01:49:10 +00003385 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00003386 return 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003387
Greg Claytonc685f8e2010-09-15 04:15:46 +00003388 DWARFDebugInfo* info = DebugInfo();
3389 if (info == NULL)
3390 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003391
3392 // If we aren't appending the results to this list, then clear the list
3393 if (!append)
3394 variables.Clear();
3395
3396 // Remember how many variables are in the list before we search in case
3397 // we are appending the results to a variable list.
3398 const uint32_t original_size = variables.GetSize();
3399
Greg Claytond4a2b372011-09-12 23:21:58 +00003400 DIEArray die_offsets;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003401
Greg Clayton97fbc342011-10-20 22:30:33 +00003402 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003403 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003404 if (m_apple_names_ap.get())
3405 {
3406 const char *name_cstr = name.GetCString();
Jim Inghamfa39bb42014-10-25 00:33:55 +00003407 llvm::StringRef basename;
3408 llvm::StringRef context;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003409
Jim Inghamfa39bb42014-10-25 00:33:55 +00003410 if (!CPPLanguageRuntime::ExtractContextAndIdentifier(name_cstr, context, basename))
3411 basename = name_cstr;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003412
Jim Inghamfa39bb42014-10-25 00:33:55 +00003413 m_apple_names_ap->FindByName (basename.data(), die_offsets);
Greg Clayton97fbc342011-10-20 22:30:33 +00003414 }
Greg Clayton7f995132011-10-04 22:41:51 +00003415 }
3416 else
3417 {
3418 // Index the DWARF if we haven't already
3419 if (!m_indexed)
3420 Index ();
3421
3422 m_global_index.Find (name, die_offsets);
3423 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003424
Greg Clayton437a1352012-04-09 22:43:43 +00003425 const size_t num_die_matches = die_offsets.size();
3426 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003427 {
Greg Clayton7f995132011-10-04 22:41:51 +00003428 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003429 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00003430 assert (sc.module_sp);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003431
Greg Claytond4a2b372011-09-12 23:21:58 +00003432 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00003433 DWARFCompileUnit* dwarf_cu = NULL;
3434 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton437a1352012-04-09 22:43:43 +00003435 bool done = false;
3436 for (size_t i=0; i<num_die_matches && !done; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00003437 {
3438 const dw_offset_t die_offset = die_offsets[i];
3439 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003440
Greg Clayton95d87902011-11-11 03:16:25 +00003441 if (die)
3442 {
Greg Clayton437a1352012-04-09 22:43:43 +00003443 switch (die->Tag())
3444 {
3445 default:
3446 case DW_TAG_subprogram:
3447 case DW_TAG_inlined_subroutine:
3448 case DW_TAG_try_block:
3449 case DW_TAG_catch_block:
3450 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003451
Greg Clayton437a1352012-04-09 22:43:43 +00003452 case DW_TAG_variable:
3453 {
3454 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003455
Greg Clayton437a1352012-04-09 22:43:43 +00003456 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3457 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003458
Greg Clayton437a1352012-04-09 22:43:43 +00003459 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003460
Greg Clayton437a1352012-04-09 22:43:43 +00003461 if (variables.GetSize() - original_size >= max_matches)
3462 done = true;
3463 }
3464 break;
3465 }
Greg Clayton95d87902011-11-11 03:16:25 +00003466 }
3467 else
3468 {
3469 if (m_using_apple_tables)
3470 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003471 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
3472 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003473 }
3474 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003475 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003476 }
3477
3478 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003479 const uint32_t num_matches = variables.GetSize() - original_size;
3480 if (log && num_matches > 0)
3481 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003482 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003483 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003484 name.GetCString(),
3485 static_cast<const void*>(namespace_decl),
3486 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00003487 num_matches);
3488 }
3489 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003490}
3491
3492uint32_t
3493SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
3494{
Greg Clayton5160ce52013-03-27 23:08:40 +00003495 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003496
Greg Clayton21f2a492011-10-06 00:09:08 +00003497 if (log)
3498 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003499 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003500 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003501 regex.GetText(), append,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003502 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003503 }
3504
Greg Claytonc685f8e2010-09-15 04:15:46 +00003505 DWARFDebugInfo* info = DebugInfo();
3506 if (info == NULL)
3507 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003508
3509 // If we aren't appending the results to this list, then clear the list
3510 if (!append)
3511 variables.Clear();
3512
3513 // Remember how many variables are in the list before we search in case
3514 // we are appending the results to a variable list.
3515 const uint32_t original_size = variables.GetSize();
3516
Greg Clayton7f995132011-10-04 22:41:51 +00003517 DIEArray die_offsets;
3518
Greg Clayton97fbc342011-10-20 22:30:33 +00003519 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003520 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003521 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00003522 {
3523 DWARFMappedHash::DIEInfoArray hash_data_array;
3524 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
3525 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
3526 }
Greg Clayton7f995132011-10-04 22:41:51 +00003527 }
3528 else
3529 {
3530 // Index the DWARF if we haven't already
3531 if (!m_indexed)
3532 Index ();
3533
3534 m_global_index.Find (regex, die_offsets);
3535 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003536
Greg Claytonc685f8e2010-09-15 04:15:46 +00003537 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003538 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003539 assert (sc.module_sp);
3540
Greg Claytond4a2b372011-09-12 23:21:58 +00003541 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00003542 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003543 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003544 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003545 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003546 DWARFDebugInfo* debug_info = DebugInfo();
3547 for (size_t i=0; i<num_matches; ++i)
3548 {
3549 const dw_offset_t die_offset = die_offsets[i];
3550 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00003551
3552 if (die)
3553 {
3554 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003555
Greg Clayton95d87902011-11-11 03:16:25 +00003556 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003557
Greg Clayton95d87902011-11-11 03:16:25 +00003558 if (variables.GetSize() - original_size >= max_matches)
3559 break;
3560 }
3561 else
3562 {
3563 if (m_using_apple_tables)
3564 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003565 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
3566 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00003567 }
3568 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003569 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003570 }
3571
3572 // Return the number of variable that were appended to the list
3573 return variables.GetSize() - original_size;
3574}
3575
Greg Claytonaa044962011-10-13 00:59:38 +00003576
Jim Ingham4cda6e02011-10-07 22:23:45 +00003577bool
3578SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
3579 DWARFCompileUnit *&dwarf_cu,
Pavel Labatha73d6572015-03-13 10:22:00 +00003580 bool include_inlines,
Jim Ingham4cda6e02011-10-07 22:23:45 +00003581 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00003582{
Greg Claytonaa044962011-10-13 00:59:38 +00003583 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Pavel Labatha73d6572015-03-13 10:22:00 +00003584 return ResolveFunction (dwarf_cu, die, include_inlines, sc_list);
Greg Claytonaa044962011-10-13 00:59:38 +00003585}
3586
3587
3588bool
3589SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
3590 const DWARFDebugInfoEntry *die,
Pavel Labatha73d6572015-03-13 10:22:00 +00003591 bool include_inlines,
Greg Claytonaa044962011-10-13 00:59:38 +00003592 SymbolContextList& sc_list)
3593{
Greg Clayton9e315582011-09-02 04:03:59 +00003594 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00003595
3596 if (die == NULL)
3597 return false;
3598
Jim Ingham4cda6e02011-10-07 22:23:45 +00003599 // If we were passed a die that is not a function, just return false...
Pavel Labatha73d6572015-03-13 10:22:00 +00003600 if (! (die->Tag() == DW_TAG_subprogram || (include_inlines && die->Tag() == DW_TAG_inlined_subroutine)))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003601 return false;
3602
3603 const DWARFDebugInfoEntry* inlined_die = NULL;
3604 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00003605 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003606 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00003607
Jim Ingham4cda6e02011-10-07 22:23:45 +00003608 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003609 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003610 if (die->Tag() == DW_TAG_subprogram)
3611 break;
Greg Clayton9e315582011-09-02 04:03:59 +00003612 }
3613 }
Jason Molenda60db6e42014-10-16 01:40:16 +00003614 assert (die && die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00003615 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003616 {
3617 Address addr;
3618 // Parse all blocks if needed
3619 if (inlined_die)
3620 {
Greg Claytonf7bb1fb2015-01-15 03:13:44 +00003621 Block &function_block = sc.function->GetBlock (true);
3622 sc.block = function_block.FindBlockByID (MakeUserID(inlined_die->GetOffset()));
3623 if (sc.block == NULL)
3624 sc.block = function_block.FindBlockByID (inlined_die->GetOffset());
3625 if (sc.block == NULL || sc.block->GetStartAddress (addr) == false)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003626 addr.Clear();
3627 }
3628 else
3629 {
3630 sc.block = NULL;
3631 addr = sc.function->GetAddressRange().GetBaseAddress();
3632 }
3633
3634 if (addr.IsValid())
3635 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003636 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00003637 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003638 }
3639 }
3640
Greg Claytonaa044962011-10-13 00:59:38 +00003641 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00003642}
3643
Greg Clayton7f995132011-10-04 22:41:51 +00003644void
3645SymbolFileDWARF::FindFunctions (const ConstString &name,
3646 const NameToDIE &name_to_die,
Pavel Labatha73d6572015-03-13 10:22:00 +00003647 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003648 SymbolContextList& sc_list)
3649{
Greg Claytond4a2b372011-09-12 23:21:58 +00003650 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003651 if (name_to_die.Find (name, die_offsets))
3652 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003653 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003654 }
3655}
3656
3657
3658void
3659SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3660 const NameToDIE &name_to_die,
Pavel Labatha73d6572015-03-13 10:22:00 +00003661 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003662 SymbolContextList& sc_list)
3663{
3664 DIEArray die_offsets;
3665 if (name_to_die.Find (regex, die_offsets))
3666 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003667 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003668 }
3669}
3670
3671
3672void
3673SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3674 const DWARFMappedHash::MemoryTable &memory_table,
Pavel Labatha73d6572015-03-13 10:22:00 +00003675 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003676 SymbolContextList& sc_list)
3677{
3678 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00003679 DWARFMappedHash::DIEInfoArray hash_data_array;
3680 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00003681 {
Greg Claytond1767f02011-12-08 02:13:16 +00003682 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Pavel Labatha73d6572015-03-13 10:22:00 +00003683 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003684 }
3685}
3686
3687void
3688SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
Pavel Labatha73d6572015-03-13 10:22:00 +00003689 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003690 SymbolContextList& sc_list)
3691{
3692 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003693 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00003694 {
Greg Clayton7f995132011-10-04 22:41:51 +00003695 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003696 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00003697 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003698 const dw_offset_t die_offset = die_offsets[i];
Pavel Labatha73d6572015-03-13 10:22:00 +00003699 ResolveFunction (die_offset, dwarf_cu, include_inlines, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003700 }
3701 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00003702}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003703
Jim Ingham4cda6e02011-10-07 22:23:45 +00003704bool
3705SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
3706 const DWARFCompileUnit *dwarf_cu,
3707 uint32_t name_type_mask,
3708 const char *partial_name,
3709 const char *base_name_start,
3710 const char *base_name_end)
3711{
Greg Claytonfbea0f62012-11-15 18:05:43 +00003712 // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes:
3713 if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003714 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003715 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
3716 if (!containing_decl_ctx)
3717 return false;
3718
3719 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
3720
Greg Claytonfbea0f62012-11-15 18:05:43 +00003721 if (name_type_mask == eFunctionNameTypeMethod)
3722 {
3723 if (is_cxx_method == false)
3724 return false;
3725 }
3726
3727 if (name_type_mask == eFunctionNameTypeBase)
3728 {
3729 if (is_cxx_method == true)
3730 return false;
3731 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003732 }
3733
3734 // Now we need to check whether the name we got back for this type matches the extra specifications
3735 // that were in the name we're looking up:
3736 if (base_name_start != partial_name || *base_name_end != '\0')
3737 {
3738 // First see if the stuff to the left matches the full name. To do that let's see if
3739 // we can pull out the mips linkage name attribute:
3740
3741 Mangled best_name;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003742 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonfbea0f62012-11-15 18:05:43 +00003743 DWARFFormValue form_value;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003744 die->GetAttributes(this, dwarf_cu, NULL, attributes);
3745 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
Greg Clayton71415542012-12-08 00:24:40 +00003746 if (idx == UINT32_MAX)
3747 idx = attributes.FindAttributeIndex(DW_AT_linkage_name);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003748 if (idx != UINT32_MAX)
3749 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003750 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
3751 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003752 const char *mangled_name = form_value.AsCString(&get_debug_str_data());
3753 if (mangled_name)
3754 best_name.SetValue (ConstString(mangled_name), true);
3755 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003756 }
Greg Claytonfbea0f62012-11-15 18:05:43 +00003757
3758 if (!best_name)
3759 {
3760 idx = attributes.FindAttributeIndex(DW_AT_name);
3761 if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value))
3762 {
3763 const char *name = form_value.AsCString(&get_debug_str_data());
3764 best_name.SetValue (ConstString(name), false);
3765 }
3766 }
3767
3768 if (best_name.GetDemangledName())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003769 {
3770 const char *demangled = best_name.GetDemangledName().GetCString();
3771 if (demangled)
3772 {
3773 std::string name_no_parens(partial_name, base_name_end - partial_name);
Jim Ingham85c13d72012-03-02 02:24:42 +00003774 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str());
3775 if (partial_in_demangled == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003776 return false;
Jim Ingham85c13d72012-03-02 02:24:42 +00003777 else
3778 {
3779 // Sort out the case where our name is something like "Process::Destroy" and the match is
3780 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on
3781 // namespace boundaries...
3782
3783 if (partial_name[0] == ':' && partial_name[1] == ':')
3784 {
3785 // The partial name was already on a namespace boundary so all matches are good.
3786 return true;
3787 }
3788 else if (partial_in_demangled == demangled)
3789 {
3790 // They both start the same, so this is an good match.
3791 return true;
3792 }
3793 else
3794 {
3795 if (partial_in_demangled - demangled == 1)
3796 {
3797 // Only one character difference, can't be a namespace boundary...
3798 return false;
3799 }
3800 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':')
3801 {
3802 // We are on a namespace boundary, so this is also good.
3803 return true;
3804 }
3805 else
3806 return false;
3807 }
3808 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003809 }
3810 }
3811 }
3812
3813 return true;
3814}
Greg Claytonc685f8e2010-09-15 04:15:46 +00003815
Greg Clayton0c5cd902010-06-28 21:30:43 +00003816uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00003817SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00003818 const lldb_private::ClangNamespaceDecl *namespace_decl,
Sean Callanan9df05fb2012-02-10 22:52:19 +00003819 uint32_t name_type_mask,
3820 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00003821 bool append,
3822 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00003823{
3824 Timer scoped_timer (__PRETTY_FUNCTION__,
3825 "SymbolFileDWARF::FindFunctions (name = '%s')",
3826 name.AsCString());
3827
Greg Clayton43fe2172013-04-03 02:00:15 +00003828 // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup()
3829 assert ((name_type_mask & eFunctionNameTypeAuto) == 0);
3830
Greg Clayton5160ce52013-03-27 23:08:40 +00003831 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003832
3833 if (log)
3834 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003835 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003836 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
3837 name.GetCString(),
3838 name_type_mask,
3839 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003840 }
3841
Greg Clayton0c5cd902010-06-28 21:30:43 +00003842 // If we aren't appending the results to this list, then clear the list
3843 if (!append)
3844 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003845
3846 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00003847 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003848
3849 // If name is empty then we won't find anything.
3850 if (name.IsEmpty())
3851 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00003852
3853 // Remember how many sc_list are in the list before we search in case
3854 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00003855
Jim Ingham4cda6e02011-10-07 22:23:45 +00003856 const char *name_cstr = name.GetCString();
Greg Clayton43fe2172013-04-03 02:00:15 +00003857
3858 const uint32_t original_size = sc_list.GetSize();
3859
Jim Ingham4cda6e02011-10-07 22:23:45 +00003860 DWARFDebugInfo* info = DebugInfo();
3861 if (info == NULL)
3862 return 0;
3863
Greg Claytonaa044962011-10-13 00:59:38 +00003864 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton43fe2172013-04-03 02:00:15 +00003865 std::set<const DWARFDebugInfoEntry *> resolved_dies;
Greg Clayton97fbc342011-10-20 22:30:33 +00003866 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00003867 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003868 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003869 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003870
3871 DIEArray die_offsets;
3872
3873 uint32_t num_matches = 0;
3874
Greg Clayton43fe2172013-04-03 02:00:15 +00003875 if (name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00003876 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003877 // If they asked for the full name, match what they typed. At some point we may
3878 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
3879 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00003880 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003881 for (uint32_t i = 0; i < num_matches; i++)
3882 {
Greg Clayton95d87902011-11-11 03:16:25 +00003883 const dw_offset_t die_offset = die_offsets[i];
3884 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00003885 if (die)
3886 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003887 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3888 continue;
3889
Greg Clayton43fe2172013-04-03 02:00:15 +00003890 if (resolved_dies.find(die) == resolved_dies.end())
3891 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003892 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00003893 resolved_dies.insert(die);
3894 }
Greg Claytonaa044962011-10-13 00:59:38 +00003895 }
Greg Clayton95d87902011-11-11 03:16:25 +00003896 else
3897 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003898 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3899 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003900 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003901 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003902 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003903
3904 if (name_type_mask & eFunctionNameTypeSelector)
3905 {
3906 if (namespace_decl && *namespace_decl)
3907 return 0; // no selectors in namespaces
Greg Clayton97fbc342011-10-20 22:30:33 +00003908
Greg Clayton43fe2172013-04-03 02:00:15 +00003909 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3910 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
3911 // and if it is an ObjC method name, we're good.
Greg Clayton97fbc342011-10-20 22:30:33 +00003912
Greg Clayton43fe2172013-04-03 02:00:15 +00003913 for (uint32_t i = 0; i < num_matches; i++)
Greg Clayton97fbc342011-10-20 22:30:33 +00003914 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003915 const dw_offset_t die_offset = die_offsets[i];
3916 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3917 if (die)
Greg Clayton97fbc342011-10-20 22:30:33 +00003918 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003919 const char *die_name = die->GetName(this, dwarf_cu);
3920 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
Greg Clayton97fbc342011-10-20 22:30:33 +00003921 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003922 if (resolved_dies.find(die) == resolved_dies.end())
3923 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003924 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00003925 resolved_dies.insert(die);
3926 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003927 }
3928 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003929 else
3930 {
3931 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3932 die_offset, name_cstr);
3933 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003934 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003935 die_offsets.clear();
3936 }
3937
3938 if (((name_type_mask & eFunctionNameTypeMethod) && !namespace_decl) || name_type_mask & eFunctionNameTypeBase)
3939 {
3940 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
3941 // extract the base name, look that up, and if there is any other information in the name we were
3942 // passed in we have to post-filter based on that.
3943
3944 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
3945 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3946
3947 for (uint32_t i = 0; i < num_matches; i++)
3948 {
3949 const dw_offset_t die_offset = die_offsets[i];
3950 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3951 if (die)
3952 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003953 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3954 continue;
3955
3956 // If we get to here, the die is good, and we should add it:
3957 if (resolved_dies.find(die) == resolved_dies.end())
Pavel Labatha73d6572015-03-13 10:22:00 +00003958 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00003959 {
3960 bool keep_die = true;
3961 if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod))
3962 {
3963 // We are looking for either basenames or methods, so we need to
3964 // trim out the ones we won't want by looking at the type
3965 SymbolContext sc;
3966 if (sc_list.GetLastContext(sc))
3967 {
3968 if (sc.block)
3969 {
3970 // We have an inlined function
3971 }
3972 else if (sc.function)
3973 {
3974 Type *type = sc.function->GetType();
3975
Sean Callananc370a8a2013-09-18 22:59:55 +00003976 if (type)
Greg Clayton43fe2172013-04-03 02:00:15 +00003977 {
Sean Callananc370a8a2013-09-18 22:59:55 +00003978 clang::DeclContext* decl_ctx = GetClangDeclContextContainingTypeUID (type->GetID());
3979 if (decl_ctx->isRecord())
Greg Clayton43fe2172013-04-03 02:00:15 +00003980 {
Sean Callananc370a8a2013-09-18 22:59:55 +00003981 if (name_type_mask & eFunctionNameTypeBase)
3982 {
3983 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3984 keep_die = false;
3985 }
3986 }
3987 else
3988 {
3989 if (name_type_mask & eFunctionNameTypeMethod)
3990 {
3991 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3992 keep_die = false;
3993 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003994 }
3995 }
3996 else
3997 {
Sean Callananc370a8a2013-09-18 22:59:55 +00003998 GetObjectFile()->GetModule()->ReportWarning ("function at die offset 0x%8.8x had no function type",
3999 die_offset);
Greg Clayton43fe2172013-04-03 02:00:15 +00004000 }
4001 }
4002 }
4003 }
4004 if (keep_die)
4005 resolved_dies.insert(die);
4006 }
4007 }
4008 else
4009 {
4010 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
4011 die_offset, name_cstr);
4012 }
4013 }
4014 die_offsets.clear();
Jim Ingham4cda6e02011-10-07 22:23:45 +00004015 }
4016 }
Greg Clayton7f995132011-10-04 22:41:51 +00004017 }
4018 else
4019 {
4020
4021 // Index the DWARF if we haven't already
4022 if (!m_indexed)
4023 Index ();
4024
Greg Clayton7f995132011-10-04 22:41:51 +00004025 if (name_type_mask & eFunctionNameTypeFull)
Matt Kopecd6089962013-05-10 17:53:48 +00004026 {
Pavel Labatha73d6572015-03-13 10:22:00 +00004027 FindFunctions (name, m_function_fullname_index, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00004028
Ed Mastefc7baa02013-09-09 18:00:45 +00004029 // FIXME Temporary workaround for global/anonymous namespace
Robert Flack5cbd3bf2015-05-13 18:20:02 +00004030 // functions debugging FreeBSD and Linux binaries.
Matt Kopecd6089962013-05-10 17:53:48 +00004031 // If we didn't find any functions in the global namespace try
4032 // looking in the basename index but ignore any returned
Robert Flackeb83fab2015-05-15 18:59:59 +00004033 // functions that have a namespace but keep functions which
4034 // have an anonymous namespace
4035 // TODO: The arch in the object file isn't correct for MSVC
4036 // binaries on windows, we should find a way to make it
4037 // correct and handle those symbols as well.
Matt Kopecd6089962013-05-10 17:53:48 +00004038 if (sc_list.GetSize() == 0)
4039 {
Robert Flackeb83fab2015-05-15 18:59:59 +00004040 ArchSpec arch;
4041 if (!namespace_decl &&
4042 GetObjectFile()->GetArchitecture(arch) &&
4043 (arch.GetTriple().isOSFreeBSD() || arch.GetTriple().isOSLinux() ||
4044 arch.GetMachine() == llvm::Triple::hexagon))
Matt Kopecd6089962013-05-10 17:53:48 +00004045 {
Robert Flackeb83fab2015-05-15 18:59:59 +00004046 SymbolContextList temp_sc_list;
4047 FindFunctions (name, m_function_basename_index, include_inlines, temp_sc_list);
Matt Kopecd6089962013-05-10 17:53:48 +00004048 SymbolContext sc;
4049 for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++)
4050 {
4051 if (temp_sc_list.GetContextAtIndex(i, sc))
4052 {
Matt Kopeca189d492013-05-10 22:55:24 +00004053 ConstString mangled_name = sc.GetFunctionName(Mangled::ePreferMangled);
4054 ConstString demangled_name = sc.GetFunctionName(Mangled::ePreferDemangled);
Robert Flackeb83fab2015-05-15 18:59:59 +00004055 // Mangled names on Linux and FreeBSD are of the form:
4056 // _ZN18function_namespace13function_nameEv.
Matt Kopec04e5d582013-05-14 19:00:41 +00004057 if (strncmp(mangled_name.GetCString(), "_ZN", 3) ||
4058 !strncmp(demangled_name.GetCString(), "(anonymous namespace)", 21))
Matt Kopecd6089962013-05-10 17:53:48 +00004059 {
4060 sc_list.Append(sc);
4061 }
4062 }
4063 }
4064 }
4065 }
Matt Kopecd6089962013-05-10 17:53:48 +00004066 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00004067 DIEArray die_offsets;
4068 DWARFCompileUnit *dwarf_cu = NULL;
4069
Greg Clayton43fe2172013-04-03 02:00:15 +00004070 if (name_type_mask & eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00004071 {
Greg Clayton43fe2172013-04-03 02:00:15 +00004072 uint32_t num_base = m_function_basename_index.Find(name, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00004073 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00004074 {
Greg Claytonaa044962011-10-13 00:59:38 +00004075 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
4076 if (die)
4077 {
Sean Callanan213fdb82011-10-13 01:49:10 +00004078 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
4079 continue;
4080
Greg Claytonaa044962011-10-13 00:59:38 +00004081 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00004082 if (resolved_dies.find(die) == resolved_dies.end())
4083 {
Pavel Labatha73d6572015-03-13 10:22:00 +00004084 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00004085 resolved_dies.insert(die);
4086 }
Greg Claytonaa044962011-10-13 00:59:38 +00004087 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00004088 }
4089 die_offsets.clear();
4090 }
4091
Greg Clayton43fe2172013-04-03 02:00:15 +00004092 if (name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00004093 {
Sean Callanan213fdb82011-10-13 01:49:10 +00004094 if (namespace_decl && *namespace_decl)
4095 return 0; // no methods in namespaces
4096
Greg Clayton43fe2172013-04-03 02:00:15 +00004097 uint32_t num_base = m_function_method_index.Find(name, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00004098 {
Greg Claytonaa044962011-10-13 00:59:38 +00004099 for (uint32_t i = 0; i < num_base; i++)
4100 {
4101 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
4102 if (die)
4103 {
Greg Claytonaa044962011-10-13 00:59:38 +00004104 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00004105 if (resolved_dies.find(die) == resolved_dies.end())
4106 {
Pavel Labatha73d6572015-03-13 10:22:00 +00004107 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00004108 resolved_dies.insert(die);
4109 }
Greg Claytonaa044962011-10-13 00:59:38 +00004110 }
4111 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00004112 }
4113 die_offsets.clear();
4114 }
Greg Clayton7f995132011-10-04 22:41:51 +00004115
Greg Clayton43fe2172013-04-03 02:00:15 +00004116 if ((name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00004117 {
Pavel Labatha73d6572015-03-13 10:22:00 +00004118 FindFunctions (name, m_function_selector_index, include_inlines, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00004119 }
4120
Greg Clayton4d01ace2011-09-29 16:58:15 +00004121 }
4122
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004123 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00004124 const uint32_t num_matches = sc_list.GetSize() - original_size;
4125
4126 if (log && num_matches > 0)
4127 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004128 GetObjectFile()->GetModule()->LogMessage (log,
Pavel Labatha73d6572015-03-13 10:22:00 +00004129 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, include_inlines=%d, append=%u, sc_list) => %u",
Greg Clayton437a1352012-04-09 22:43:43 +00004130 name.GetCString(),
4131 name_type_mask,
Pavel Labatha73d6572015-03-13 10:22:00 +00004132 include_inlines,
Greg Clayton437a1352012-04-09 22:43:43 +00004133 append,
4134 num_matches);
4135 }
4136 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004137}
4138
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004139uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00004140SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004141{
4142 Timer scoped_timer (__PRETTY_FUNCTION__,
4143 "SymbolFileDWARF::FindFunctions (regex = '%s')",
4144 regex.GetText());
4145
Greg Clayton5160ce52013-03-27 23:08:40 +00004146 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00004147
4148 if (log)
4149 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004150 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00004151 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
4152 regex.GetText(),
4153 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00004154 }
4155
4156
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004157 // If we aren't appending the results to this list, then clear the list
4158 if (!append)
4159 sc_list.Clear();
4160
4161 // Remember how many sc_list are in the list before we search in case
4162 // we are appending the results to a variable list.
4163 uint32_t original_size = sc_list.GetSize();
4164
Greg Clayton97fbc342011-10-20 22:30:33 +00004165 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004166 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004167 if (m_apple_names_ap.get())
Pavel Labatha73d6572015-03-13 10:22:00 +00004168 FindFunctions (regex, *m_apple_names_ap, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00004169 }
4170 else
4171 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00004172 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00004173 if (!m_indexed)
4174 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004175
Pavel Labatha73d6572015-03-13 10:22:00 +00004176 FindFunctions (regex, m_function_basename_index, include_inlines, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004177
Pavel Labatha73d6572015-03-13 10:22:00 +00004178 FindFunctions (regex, m_function_fullname_index, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00004179 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004180
4181 // Return the number of variable that were appended to the list
4182 return sc_list.GetSize() - original_size;
4183}
Jim Ingham318c9f22011-08-26 19:44:13 +00004184
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004185uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00004186SymbolFileDWARF::FindTypes (const SymbolContext& sc,
4187 const ConstString &name,
4188 const lldb_private::ClangNamespaceDecl *namespace_decl,
4189 bool append,
4190 uint32_t max_matches,
4191 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004192{
Greg Claytonc685f8e2010-09-15 04:15:46 +00004193 DWARFDebugInfo* info = DebugInfo();
4194 if (info == NULL)
4195 return 0;
4196
Greg Clayton5160ce52013-03-27 23:08:40 +00004197 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004198
Greg Clayton21f2a492011-10-06 00:09:08 +00004199 if (log)
4200 {
Greg Clayton437a1352012-04-09 22:43:43 +00004201 if (namespace_decl)
Greg Clayton5160ce52013-03-27 23:08:40 +00004202 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004203 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)",
4204 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004205 static_cast<void*>(namespace_decl->GetNamespaceDecl()),
Greg Clayton437a1352012-04-09 22:43:43 +00004206 namespace_decl->GetQualifiedName().c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004207 append, max_matches);
Greg Clayton437a1352012-04-09 22:43:43 +00004208 else
Greg Clayton5160ce52013-03-27 23:08:40 +00004209 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004210 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004211 name.GetCString(), append,
Greg Clayton437a1352012-04-09 22:43:43 +00004212 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00004213 }
4214
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004215 // If we aren't appending the results to this list, then clear the list
4216 if (!append)
4217 types.Clear();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004218
Sean Callanan213fdb82011-10-13 01:49:10 +00004219 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00004220 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004221
Greg Claytond4a2b372011-09-12 23:21:58 +00004222 DIEArray die_offsets;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004223
Greg Clayton97fbc342011-10-20 22:30:33 +00004224 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004225 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004226 if (m_apple_types_ap.get())
4227 {
4228 const char *name_cstr = name.GetCString();
4229 m_apple_types_ap->FindByName (name_cstr, die_offsets);
4230 }
Greg Clayton7f995132011-10-04 22:41:51 +00004231 }
4232 else
4233 {
4234 if (!m_indexed)
4235 Index ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004236
Greg Clayton7f995132011-10-04 22:41:51 +00004237 m_type_index.Find (name, die_offsets);
4238 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004239
Greg Clayton437a1352012-04-09 22:43:43 +00004240 const size_t num_die_matches = die_offsets.size();
Greg Clayton7f995132011-10-04 22:41:51 +00004241
Greg Clayton437a1352012-04-09 22:43:43 +00004242 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004243 {
Greg Clayton7f995132011-10-04 22:41:51 +00004244 const uint32_t initial_types_size = types.GetSize();
4245 DWARFCompileUnit* dwarf_cu = NULL;
4246 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00004247 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00004248 for (size_t i=0; i<num_die_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004249 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004250 const dw_offset_t die_offset = die_offsets[i];
4251 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
4252
Greg Clayton95d87902011-11-11 03:16:25 +00004253 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00004254 {
Greg Clayton95d87902011-11-11 03:16:25 +00004255 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
4256 continue;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004257
Greg Clayton95d87902011-11-11 03:16:25 +00004258 Type *matching_type = ResolveType (dwarf_cu, die);
4259 if (matching_type)
4260 {
4261 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00004262 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00004263 if (types.GetSize() >= max_matches)
4264 break;
4265 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00004266 }
Greg Clayton95d87902011-11-11 03:16:25 +00004267 else
4268 {
4269 if (m_using_apple_tables)
4270 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004271 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4272 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004273 }
4274 }
4275
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004276 }
Greg Clayton437a1352012-04-09 22:43:43 +00004277 const uint32_t num_matches = types.GetSize() - initial_types_size;
4278 if (log && num_matches)
4279 {
4280 if (namespace_decl)
4281 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004282 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004283 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u",
4284 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004285 static_cast<void*>(namespace_decl->GetNamespaceDecl()),
Greg Clayton437a1352012-04-09 22:43:43 +00004286 namespace_decl->GetQualifiedName().c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004287 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00004288 num_matches);
4289 }
4290 else
4291 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004292 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004293 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u",
4294 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004295 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00004296 num_matches);
4297 }
4298 }
4299 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004300 }
Greg Clayton7f995132011-10-04 22:41:51 +00004301 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004302}
4303
4304
Greg Clayton526e5af2010-11-13 03:52:47 +00004305ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00004306SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00004307 const ConstString &name,
4308 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004309{
Greg Clayton5160ce52013-03-27 23:08:40 +00004310 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00004311
4312 if (log)
4313 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004314 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00004315 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
4316 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00004317 }
Sean Callanan213fdb82011-10-13 01:49:10 +00004318
4319 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00004320 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00004321
Greg Clayton526e5af2010-11-13 03:52:47 +00004322 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004323 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00004324 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00004325 {
Greg Clayton7f995132011-10-04 22:41:51 +00004326 DIEArray die_offsets;
4327
Greg Clayton526e5af2010-11-13 03:52:47 +00004328 // Index if we already haven't to make sure the compile units
4329 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00004330 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004331 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004332 if (m_apple_namespaces_ap.get())
4333 {
4334 const char *name_cstr = name.GetCString();
4335 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
4336 }
Greg Clayton7f995132011-10-04 22:41:51 +00004337 }
4338 else
4339 {
4340 if (!m_indexed)
4341 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00004342
Greg Clayton7f995132011-10-04 22:41:51 +00004343 m_namespace_index.Find (name, die_offsets);
4344 }
Greg Claytond4a2b372011-09-12 23:21:58 +00004345
4346 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00004347 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00004348 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00004349 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00004350 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004351 DWARFDebugInfo* debug_info = DebugInfo();
4352 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00004353 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004354 const dw_offset_t die_offset = die_offsets[i];
4355 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00004356
Greg Clayton95d87902011-11-11 03:16:25 +00004357 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00004358 {
Greg Clayton95d87902011-11-11 03:16:25 +00004359 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
4360 continue;
4361
4362 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
4363 if (clang_namespace_decl)
4364 {
4365 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
4366 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
Greg Claytond1767f02011-12-08 02:13:16 +00004367 break;
Greg Clayton95d87902011-11-11 03:16:25 +00004368 }
Greg Claytond4a2b372011-09-12 23:21:58 +00004369 }
Greg Clayton95d87902011-11-11 03:16:25 +00004370 else
4371 {
4372 if (m_using_apple_tables)
4373 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004374 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
4375 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004376 }
4377 }
4378
Greg Clayton526e5af2010-11-13 03:52:47 +00004379 }
4380 }
Greg Clayton96d7d742010-11-10 23:42:09 +00004381 }
Greg Clayton437a1352012-04-09 22:43:43 +00004382 if (log && namespace_decl.GetNamespaceDecl())
4383 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004384 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004385 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"",
4386 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004387 static_cast<const void*>(namespace_decl.GetNamespaceDecl()),
Greg Clayton437a1352012-04-09 22:43:43 +00004388 namespace_decl.GetQualifiedName().c_str());
4389 }
4390
Greg Clayton526e5af2010-11-13 03:52:47 +00004391 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004392}
4393
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004394uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004395SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004396{
4397 // Remember how many sc_list are in the list before we search in case
4398 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004399 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004400
4401 const uint32_t num_die_offsets = die_offsets.size();
4402 // Parse all of the types we found from the pubtypes matches
4403 uint32_t i;
4404 uint32_t num_matches = 0;
4405 for (i = 0; i < num_die_offsets; ++i)
4406 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004407 Type *matching_type = ResolveTypeUID (die_offsets[i]);
4408 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004409 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004410 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00004411 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004412 ++num_matches;
4413 if (num_matches >= max_matches)
4414 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004415 }
4416 }
4417
4418 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004419 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004420}
4421
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004422
4423size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00004424SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
4425 clang::DeclContext *containing_decl_ctx,
Greg Clayton5113dc82011-08-12 06:47:54 +00004426 DWARFCompileUnit* dwarf_cu,
4427 const DWARFDebugInfoEntry *parent_die,
4428 bool skip_artificial,
4429 bool &is_static,
Greg Clayton03969752014-02-24 18:53:11 +00004430 bool &is_variadic,
Greg Clayton57ee3062013-07-11 22:46:58 +00004431 std::vector<ClangASTType>& function_param_types,
Greg Clayton5113dc82011-08-12 06:47:54 +00004432 std::vector<clang::ParmVarDecl*>& function_param_decls,
Greg Claytond20deac2014-04-04 18:15:18 +00004433 unsigned &type_quals) // ,
4434 // ClangASTContext::TemplateParameterInfos &template_param_infos))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004435{
4436 if (parent_die == NULL)
4437 return 0;
4438
Todd Fialaee8bfc62014-09-11 17:29:12 +00004439 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Claytond88d7592010-09-15 08:33:30 +00004440
Greg Clayton7fedea22010-11-16 02:10:54 +00004441 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004442 const DWARFDebugInfoEntry *die;
4443 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4444 {
4445 dw_tag_t tag = die->Tag();
4446 switch (tag)
4447 {
4448 case DW_TAG_formal_parameter:
4449 {
4450 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004451 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004452 if (num_attributes > 0)
4453 {
4454 const char *name = NULL;
4455 Declaration decl;
4456 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00004457 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004458 // one of None, Auto, Register, Extern, Static, PrivateExtern
4459
Sean Callanane2ef6e32010-09-23 03:01:22 +00004460 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004461 uint32_t i;
4462 for (i=0; i<num_attributes; ++i)
4463 {
4464 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4465 DWARFFormValue form_value;
4466 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4467 {
4468 switch (attr)
4469 {
4470 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4471 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4472 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4473 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00004474 case DW_AT_type: param_type_die_offset = form_value.Reference(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00004475 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004476 case DW_AT_location:
4477 // if (form_value.BlockData())
4478 // {
Ed Masteeeae7212013-10-24 20:43:47 +00004479 // const DWARFDataExtractor& debug_info_data = debug_info();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004480 // uint32_t block_length = form_value.Unsigned();
Ed Masteeeae7212013-10-24 20:43:47 +00004481 // DWARFDataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004482 // }
4483 // else
4484 // {
4485 // }
4486 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004487 case DW_AT_const_value:
4488 case DW_AT_default_value:
4489 case DW_AT_description:
4490 case DW_AT_endianity:
4491 case DW_AT_is_optional:
4492 case DW_AT_segment:
4493 case DW_AT_variable_parameter:
4494 default:
4495 case DW_AT_abstract_origin:
4496 case DW_AT_sibling:
4497 break;
4498 }
4499 }
4500 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00004501
Greg Clayton0fffff52010-09-24 05:15:53 +00004502 bool skip = false;
4503 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004504 {
Greg Clayton0fffff52010-09-24 05:15:53 +00004505 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00004506 {
4507 // In order to determine if a C++ member function is
4508 // "const" we have to look at the const-ness of "this"...
4509 // Ugly, but that
4510 if (arg_idx == 0)
4511 {
Greg Claytonf0705c82011-10-22 03:33:13 +00004512 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00004513 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004514 // Often times compilers omit the "this" name for the
4515 // specification DIEs, so we can't rely upon the name
4516 // being in the formal parameter DIE...
4517 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00004518 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004519 Type *this_type = ResolveTypeUID (param_type_die_offset);
4520 if (this_type)
4521 {
4522 uint32_t encoding_mask = this_type->GetEncodingMask();
4523 if (encoding_mask & Type::eEncodingIsPointerUID)
4524 {
4525 is_static = false;
4526
4527 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
4528 type_quals |= clang::Qualifiers::Const;
4529 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
4530 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00004531 }
4532 }
4533 }
4534 }
4535 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004536 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00004537 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004538 else
4539 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004540
Greg Clayton0fffff52010-09-24 05:15:53 +00004541 // HACK: Objective C formal parameters "self" and "_cmd"
4542 // are not marked as artificial in the DWARF...
Greg Clayton53eb1c22012-04-02 22:59:12 +00004543 CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
4544 if (comp_unit)
Greg Clayton0fffff52010-09-24 05:15:53 +00004545 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004546 switch (comp_unit->GetLanguage())
4547 {
4548 case eLanguageTypeObjC:
4549 case eLanguageTypeObjC_plus_plus:
4550 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
4551 skip = true;
4552 break;
4553 default:
4554 break;
4555 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004556 }
4557 }
4558 }
4559
4560 if (!skip)
4561 {
4562 Type *type = ResolveTypeUID(param_type_die_offset);
4563 if (type)
4564 {
Greg Claytonc93237c2010-10-01 20:48:32 +00004565 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00004566
Greg Clayton42ce2f32011-12-12 21:50:19 +00004567 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
4568 type->GetClangForwardType(),
4569 storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00004570 assert(param_var_decl);
4571 function_param_decls.push_back(param_var_decl);
Sean Callanan60217122012-04-13 00:10:03 +00004572
Greg Claytond0029442013-03-27 01:48:02 +00004573 GetClangASTContext().SetMetadataAsUserID (param_var_decl, MakeUserID(die->GetOffset()));
Greg Clayton0fffff52010-09-24 05:15:53 +00004574 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004575 }
4576 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004577 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004578 }
4579 break;
4580
Greg Clayton03969752014-02-24 18:53:11 +00004581 case DW_TAG_unspecified_parameters:
4582 is_variadic = true;
4583 break;
4584
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004585 case DW_TAG_template_type_parameter:
4586 case DW_TAG_template_value_parameter:
Greg Claytond20deac2014-04-04 18:15:18 +00004587 // The one caller of this was never using the template_param_infos,
4588 // and the local variable was taking up a large amount of stack space
4589 // in SymbolFileDWARF::ParseType() so this was removed. If we ever need
4590 // the template params back, we can add them back.
4591 // ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004592 break;
4593
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004594 default:
4595 break;
4596 }
4597 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004598 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004599}
4600
4601size_t
4602SymbolFileDWARF::ParseChildEnumerators
4603(
4604 const SymbolContext& sc,
Greg Clayton57ee3062013-07-11 22:46:58 +00004605 lldb_private::ClangASTType &clang_type,
Greg Clayton3e067532013-03-05 23:54:39 +00004606 bool is_signed,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004607 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00004608 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004609 const DWARFDebugInfoEntry *parent_die
4610)
4611{
4612 if (parent_die == NULL)
4613 return 0;
4614
4615 size_t enumerators_added = 0;
4616 const DWARFDebugInfoEntry *die;
Todd Fialaee8bfc62014-09-11 17:29:12 +00004617 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Claytond88d7592010-09-15 08:33:30 +00004618
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004619 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4620 {
4621 const dw_tag_t tag = die->Tag();
4622 if (tag == DW_TAG_enumerator)
4623 {
4624 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004625 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004626 if (num_child_attributes > 0)
4627 {
4628 const char *name = NULL;
4629 bool got_value = false;
4630 int64_t enum_value = 0;
4631 Declaration decl;
4632
4633 uint32_t i;
4634 for (i=0; i<num_child_attributes; ++i)
4635 {
4636 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4637 DWARFFormValue form_value;
4638 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4639 {
4640 switch (attr)
4641 {
4642 case DW_AT_const_value:
4643 got_value = true;
Greg Clayton3e067532013-03-05 23:54:39 +00004644 if (is_signed)
4645 enum_value = form_value.Signed();
4646 else
4647 enum_value = form_value.Unsigned();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004648 break;
4649
4650 case DW_AT_name:
4651 name = form_value.AsCString(&get_debug_str_data());
4652 break;
4653
4654 case DW_AT_description:
4655 default:
4656 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4657 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4658 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4659 case DW_AT_sibling:
4660 break;
4661 }
4662 }
4663 }
4664
4665 if (name && name[0] && got_value)
4666 {
Greg Clayton57ee3062013-07-11 22:46:58 +00004667 clang_type.AddEnumerationValueToEnumerationType (clang_type.GetEnumerationIntegerType(),
4668 decl,
4669 name,
4670 enum_value,
4671 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004672 ++enumerators_added;
4673 }
4674 }
4675 }
4676 }
4677 return enumerators_added;
4678}
4679
4680void
4681SymbolFileDWARF::ParseChildArrayInfo
4682(
4683 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004684 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004685 const DWARFDebugInfoEntry *parent_die,
4686 int64_t& first_index,
4687 std::vector<uint64_t>& element_orders,
4688 uint32_t& byte_stride,
4689 uint32_t& bit_stride
4690)
4691{
4692 if (parent_die == NULL)
4693 return;
4694
4695 const DWARFDebugInfoEntry *die;
Todd Fialaee8bfc62014-09-11 17:29:12 +00004696 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004697 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4698 {
4699 const dw_tag_t tag = die->Tag();
4700 switch (tag)
4701 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004702 case DW_TAG_subrange_type:
4703 {
4704 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004705 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004706 if (num_child_attributes > 0)
4707 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004708 uint64_t num_elements = 0;
4709 uint64_t lower_bound = 0;
4710 uint64_t upper_bound = 0;
Greg Clayton4ef877f2012-12-06 02:33:54 +00004711 bool upper_bound_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004712 uint32_t i;
4713 for (i=0; i<num_child_attributes; ++i)
4714 {
4715 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4716 DWARFFormValue form_value;
4717 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4718 {
4719 switch (attr)
4720 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004721 case DW_AT_name:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004722 break;
4723
4724 case DW_AT_count:
4725 num_elements = form_value.Unsigned();
4726 break;
4727
4728 case DW_AT_bit_stride:
4729 bit_stride = form_value.Unsigned();
4730 break;
4731
4732 case DW_AT_byte_stride:
4733 byte_stride = form_value.Unsigned();
4734 break;
4735
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004736 case DW_AT_lower_bound:
4737 lower_bound = form_value.Unsigned();
4738 break;
4739
4740 case DW_AT_upper_bound:
Greg Clayton4ef877f2012-12-06 02:33:54 +00004741 upper_bound_valid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004742 upper_bound = form_value.Unsigned();
4743 break;
4744
4745 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004746 case DW_AT_abstract_origin:
4747 case DW_AT_accessibility:
4748 case DW_AT_allocated:
4749 case DW_AT_associated:
4750 case DW_AT_data_location:
4751 case DW_AT_declaration:
4752 case DW_AT_description:
4753 case DW_AT_sibling:
4754 case DW_AT_threads_scaled:
4755 case DW_AT_type:
4756 case DW_AT_visibility:
4757 break;
4758 }
4759 }
4760 }
4761
Greg Claytone6a07792012-12-05 21:59:39 +00004762 if (num_elements == 0)
4763 {
Greg Clayton4ef877f2012-12-06 02:33:54 +00004764 if (upper_bound_valid && upper_bound >= lower_bound)
Greg Claytone6a07792012-12-05 21:59:39 +00004765 num_elements = upper_bound - lower_bound + 1;
4766 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004767
Sean Callananec979ba2012-10-22 23:56:48 +00004768 element_orders.push_back (num_elements);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004769 }
4770 }
4771 break;
4772 }
4773 }
4774}
4775
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004776TypeSP
Greg Clayton53eb1c22012-04-02 22:59:12 +00004777SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004778{
4779 TypeSP type_sp;
4780 if (die != NULL)
4781 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004782 assert(dwarf_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00004783 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004784 if (type_ptr == NULL)
4785 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004786 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu);
Greg Claytonca512b32011-01-14 04:54:56 +00004787 assert (lldb_cu);
4788 SymbolContext sc(lldb_cu);
Greg Clayton53eb1c22012-04-02 22:59:12 +00004789 type_sp = ParseType(sc, dwarf_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004790 }
4791 else if (type_ptr != DIE_IS_BEING_PARSED)
4792 {
4793 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00004794 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004795 }
4796
4797 }
4798 return type_sp;
4799}
4800
4801clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00004802SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004803{
4804 if (die_offset != DW_INVALID_OFFSET)
4805 {
4806 DWARFCompileUnitSP cu_sp;
4807 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004808 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004809 }
4810 return NULL;
4811}
4812
Sean Callanan72e49402011-08-05 23:43:37 +00004813clang::DeclContext *
4814SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
4815{
4816 if (die_offset != DW_INVALID_OFFSET)
4817 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004818 DWARFDebugInfo* debug_info = DebugInfo();
4819 if (debug_info)
4820 {
4821 DWARFCompileUnitSP cu_sp;
4822 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
4823 if (die)
4824 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
4825 }
Sean Callanan72e49402011-08-05 23:43:37 +00004826 }
4827 return NULL;
4828}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004829
Greg Clayton96d7d742010-11-10 23:42:09 +00004830clang::NamespaceDecl *
Greg Clayton53eb1c22012-04-02 22:59:12 +00004831SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die)
Greg Clayton96d7d742010-11-10 23:42:09 +00004832{
Greg Clayton030a2042011-10-14 21:34:45 +00004833 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00004834 {
Greg Clayton030a2042011-10-14 21:34:45 +00004835 // See if we already parsed this namespace DIE and associated it with a
4836 // uniqued namespace declaration
4837 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
4838 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004839 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00004840 else
4841 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004842 const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL);
4843 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00004844 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
Greg Clayton5160ce52013-03-27 23:08:40 +00004845 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton9d3d6882011-10-31 23:51:19 +00004846 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00004847 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00004848 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00004849 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004850 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00004851 "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 +00004852 static_cast<void*>(GetClangASTContext().getASTContext()),
Greg Claytone38a5ed2012-01-05 03:57:59 +00004853 MakeUserID(die->GetOffset()),
4854 namespace_name,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004855 static_cast<void*>(namespace_decl),
4856 static_cast<void*>(namespace_decl->getOriginalNamespace()));
Greg Clayton030a2042011-10-14 21:34:45 +00004857 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004858 else
4859 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004860 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00004861 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004862 static_cast<void*>(GetClangASTContext().getASTContext()),
Greg Claytone38a5ed2012-01-05 03:57:59 +00004863 MakeUserID(die->GetOffset()),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004864 static_cast<void*>(namespace_decl),
4865 static_cast<void*>(namespace_decl->getOriginalNamespace()));
Greg Clayton9d3d6882011-10-31 23:51:19 +00004866 }
Greg Clayton030a2042011-10-14 21:34:45 +00004867 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004868
4869 if (namespace_decl)
4870 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
4871 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004872 }
4873 }
4874 return NULL;
4875}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004876
4877clang::DeclContext *
Greg Claytoncab36a32011-12-08 05:16:30 +00004878SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Sean Callanan72e49402011-08-05 23:43:37 +00004879{
Greg Clayton5cf58b92011-10-05 22:22:08 +00004880 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4881 if (clang_decl_ctx)
4882 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004883 // If this DIE has a specification, or an abstract origin, then trace to those.
4884
Greg Claytoncab36a32011-12-08 05:16:30 +00004885 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, 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 Claytoncab36a32011-12-08 05:16:30 +00004889 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004890 if (die_offset != DW_INVALID_OFFSET)
4891 return GetClangDeclContextForDIEOffset (sc, die_offset);
4892
Greg Clayton5160ce52013-03-27 23:08:40 +00004893 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00004894 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004895 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 +00004896 // This is the DIE we want. Parse it, then query our map.
Greg Claytoncab36a32011-12-08 05:16:30 +00004897 bool assert_not_being_parsed = true;
4898 ResolveTypeUID (cu, die, assert_not_being_parsed);
4899
Greg Clayton5cf58b92011-10-05 22:22:08 +00004900 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4901
4902 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004903}
4904
4905clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00004906SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004907{
Greg Claytonca512b32011-01-14 04:54:56 +00004908 if (m_clang_tu_decl == NULL)
4909 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004910
Greg Clayton2bc22f82011-09-30 03:20:47 +00004911 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004912
4913 if (decl_ctx_die_copy)
4914 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00004915
4916 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004917 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00004918
Greg Clayton2bc22f82011-09-30 03:20:47 +00004919 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
4920 if (pos != m_die_to_decl_ctx.end())
4921 return pos->second;
4922
4923 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004924 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004925 case DW_TAG_compile_unit:
4926 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004927
Greg Clayton2bc22f82011-09-30 03:20:47 +00004928 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00004929 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00004930 break;
4931
4932 case DW_TAG_structure_type:
4933 case DW_TAG_union_type:
4934 case DW_TAG_class_type:
4935 {
4936 Type* type = ResolveType (cu, decl_ctx_die);
4937 if (type)
4938 {
Greg Clayton57ee3062013-07-11 22:46:58 +00004939 clang::DeclContext *decl_ctx = type->GetClangForwardType().GetDeclContextForType ();
Greg Clayton2bc22f82011-09-30 03:20:47 +00004940 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00004941 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004942 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
4943 if (decl_ctx)
4944 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00004945 }
4946 }
Greg Claytonca512b32011-01-14 04:54:56 +00004947 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00004948 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004949
Greg Clayton2bc22f82011-09-30 03:20:47 +00004950 default:
4951 break;
Greg Claytonca512b32011-01-14 04:54:56 +00004952 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004953 }
Greg Clayton7a345282010-11-09 23:46:37 +00004954 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004955}
4956
Greg Clayton2bc22f82011-09-30 03:20:47 +00004957
4958const DWARFDebugInfoEntry *
4959SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4960{
4961 if (cu && die)
4962 {
4963 const DWARFDebugInfoEntry * const decl_die = die;
4964
4965 while (die != NULL)
4966 {
4967 // If this is the original DIE that we are searching for a declaration
4968 // for, then don't look in the cache as we don't want our own decl
4969 // context to be our decl context...
4970 if (decl_die != die)
4971 {
4972 switch (die->Tag())
4973 {
4974 case DW_TAG_compile_unit:
4975 case DW_TAG_namespace:
4976 case DW_TAG_structure_type:
4977 case DW_TAG_union_type:
4978 case DW_TAG_class_type:
4979 return die;
4980
4981 default:
4982 break;
4983 }
4984 }
4985
4986 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4987 if (die_offset != DW_INVALID_OFFSET)
4988 {
4989 DWARFCompileUnit *spec_cu = cu;
4990 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
4991 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
4992 if (spec_die_decl_ctx_die)
4993 return spec_die_decl_ctx_die;
4994 }
4995
4996 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
4997 if (die_offset != DW_INVALID_OFFSET)
4998 {
4999 DWARFCompileUnit *abs_cu = cu;
5000 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
5001 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
5002 if (abs_die_decl_ctx_die)
5003 return abs_die_decl_ctx_die;
5004 }
5005
5006 die = die->GetParent();
5007 }
5008 }
5009 return NULL;
5010}
5011
5012
Greg Clayton901c5ca2011-12-03 04:40:03 +00005013Symbol *
5014SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
5015{
5016 Symbol *objc_class_symbol = NULL;
5017 if (m_obj_file)
5018 {
Greg Clayton3046e662013-07-10 01:23:25 +00005019 Symtab *symtab = m_obj_file->GetSymtab ();
Greg Clayton901c5ca2011-12-03 04:40:03 +00005020 if (symtab)
5021 {
5022 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
5023 eSymbolTypeObjCClass,
5024 Symtab::eDebugNo,
5025 Symtab::eVisibilityAny);
5026 }
5027 }
5028 return objc_class_symbol;
5029}
5030
Greg Claytonc7f03b62012-01-12 04:33:28 +00005031// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
5032// then we can end up looking through all class types for a complete type and never find
5033// the full definition. We need to know if this attribute is supported, so we determine
5034// this here and cache th result. We also need to worry about the debug map DWARF file
5035// if we are doing darwin DWARF in .o file debugging.
5036bool
5037SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
5038{
5039 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
5040 {
5041 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
5042 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
5043 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
5044 else
5045 {
5046 DWARFDebugInfo* debug_info = DebugInfo();
5047 const uint32_t num_compile_units = GetNumCompileUnits();
5048 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
5049 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00005050 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
5051 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00005052 {
5053 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
5054 break;
5055 }
5056 }
5057 }
Greg Clayton1f746072012-08-29 21:13:06 +00005058 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00005059 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
5060 }
5061 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
5062}
Greg Clayton901c5ca2011-12-03 04:40:03 +00005063
5064// This function can be used when a DIE is found that is a forward declaration
5065// DIE and we want to try and find a type that has the complete definition.
5066TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00005067SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
5068 const ConstString &type_name,
5069 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00005070{
5071
5072 TypeSP type_sp;
5073
Greg Claytonc7f03b62012-01-12 04:33:28 +00005074 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00005075 return type_sp;
5076
5077 DIEArray die_offsets;
5078
5079 if (m_using_apple_tables)
5080 {
5081 if (m_apple_types_ap.get())
5082 {
5083 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00005084 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00005085 }
5086 }
5087 else
5088 {
5089 if (!m_indexed)
5090 Index ();
5091
5092 m_type_index.Find (type_name, die_offsets);
5093 }
5094
Greg Clayton901c5ca2011-12-03 04:40:03 +00005095 const size_t num_matches = die_offsets.size();
5096
Greg Clayton901c5ca2011-12-03 04:40:03 +00005097 DWARFCompileUnit* type_cu = NULL;
5098 const DWARFDebugInfoEntry* type_die = NULL;
5099 if (num_matches)
5100 {
5101 DWARFDebugInfo* debug_info = DebugInfo();
5102 for (size_t i=0; i<num_matches; ++i)
5103 {
5104 const dw_offset_t die_offset = die_offsets[i];
5105 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
5106
5107 if (type_die)
5108 {
5109 bool try_resolving_type = false;
5110
5111 // Don't try and resolve the DIE we are looking for with the DIE itself!
5112 if (type_die != die)
5113 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005114 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00005115 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005116 case DW_TAG_class_type:
5117 case DW_TAG_structure_type:
5118 try_resolving_type = true;
5119 break;
5120 default:
5121 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00005122 }
5123 }
5124
5125 if (try_resolving_type)
5126 {
Ed Maste4c24b122013-10-17 20:13:14 +00005127 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
5128 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00005129
5130 if (try_resolving_type)
5131 {
5132 Type *resolved_type = ResolveType (type_cu, type_die, false);
5133 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5134 {
Ed Mastea0191d12013-10-17 20:42:56 +00005135 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 +00005136 MakeUserID(die->GetOffset()),
Jim Ingham4af59612014-12-19 19:20:44 +00005137 m_obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>"),
Greg Clayton901c5ca2011-12-03 04:40:03 +00005138 MakeUserID(type_die->GetOffset()),
5139 MakeUserID(type_cu->GetOffset()));
5140
Greg Claytonc7f03b62012-01-12 04:33:28 +00005141 if (die)
5142 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00005143 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00005144 break;
5145 }
5146 }
5147 }
5148 }
5149 else
5150 {
5151 if (m_using_apple_tables)
5152 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005153 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5154 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00005155 }
5156 }
5157
5158 }
5159 }
5160 return type_sp;
5161}
5162
Greg Claytona8022fa2012-04-24 21:22:41 +00005163
Greg Clayton80c26302012-02-05 06:12:47 +00005164//----------------------------------------------------------------------
5165// This function helps to ensure that the declaration contexts match for
5166// two different DIEs. Often times debug information will refer to a
5167// forward declaration of a type (the equivalent of "struct my_struct;".
5168// There will often be a declaration of that type elsewhere that has the
5169// full definition. When we go looking for the full type "my_struct", we
5170// will find one or more matches in the accelerator tables and we will
5171// then need to make sure the type was in the same declaration context
5172// as the original DIE. This function can efficiently compare two DIEs
5173// and will return true when the declaration context matches, and false
5174// when they don't.
5175//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00005176bool
5177SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
5178 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
5179{
Greg Claytona8022fa2012-04-24 21:22:41 +00005180 if (die1 == die2)
5181 return true;
5182
5183#if defined (LLDB_CONFIGURATION_DEBUG)
5184 // You can't and shouldn't call this function with a compile unit from
5185 // two different SymbolFileDWARF instances.
5186 assert (DebugInfo()->ContainsCompileUnit (cu1));
5187 assert (DebugInfo()->ContainsCompileUnit (cu2));
5188#endif
5189
Greg Clayton890ff562012-02-02 05:48:16 +00005190 DWARFDIECollection decl_ctx_1;
5191 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00005192 //The declaration DIE stack is a stack of the declaration context
5193 // DIEs all the way back to the compile unit. If a type "T" is
5194 // declared inside a class "B", and class "B" is declared inside
5195 // a class "A" and class "A" is in a namespace "lldb", and the
5196 // namespace is in a compile unit, there will be a stack of DIEs:
5197 //
5198 // [0] DW_TAG_class_type for "B"
5199 // [1] DW_TAG_class_type for "A"
5200 // [2] DW_TAG_namespace for "lldb"
5201 // [3] DW_TAG_compile_unit for the source file.
5202 //
5203 // We grab both contexts and make sure that everything matches
5204 // all the way back to the compiler unit.
5205
5206 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00005207 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00005208 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00005209 // Make sure the context arrays have the same size, otherwise
5210 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00005211 const size_t count1 = decl_ctx_1.Size();
5212 const size_t count2 = decl_ctx_2.Size();
5213 if (count1 != count2)
5214 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00005215
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00005216 // Make sure the DW_TAG values match all the way back up the
Greg Clayton80c26302012-02-05 06:12:47 +00005217 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00005218 const DWARFDebugInfoEntry *decl_ctx_die1;
5219 const DWARFDebugInfoEntry *decl_ctx_die2;
5220 size_t i;
5221 for (i=0; i<count1; i++)
5222 {
5223 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
5224 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
5225 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
5226 return false;
5227 }
Greg Clayton890ff562012-02-02 05:48:16 +00005228#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00005229
5230 // Make sure the top item in the decl context die array is always
5231 // DW_TAG_compile_unit. If it isn't then something went wrong in
5232 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00005233 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00005234
Greg Clayton890ff562012-02-02 05:48:16 +00005235#endif
5236 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00005237 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00005238 for (i=0; i<count1 - 1; i++)
5239 {
5240 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
5241 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
5242 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00005243 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00005244 // If the string was from a DW_FORM_strp, then the pointer will often
5245 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00005246 if (name1 == name2)
5247 continue;
5248
5249 // Name pointers are not equal, so only compare the strings
5250 // if both are not NULL.
5251 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00005252 {
Greg Clayton5569e642012-02-06 01:44:54 +00005253 // If the strings don't compare, we are done...
5254 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00005255 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00005256 }
5257 else
5258 {
5259 // One name was NULL while the other wasn't
5260 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00005261 }
5262 }
Greg Clayton80c26302012-02-05 06:12:47 +00005263 // We made it through all of the checks and the declaration contexts
5264 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00005265 return true;
5266}
Greg Clayton220a0072011-12-09 08:48:30 +00005267
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005268
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005269TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00005270SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx)
5271{
5272 TypeSP type_sp;
5273
5274 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
5275 if (dwarf_decl_ctx_count > 0)
5276 {
5277 const ConstString type_name(dwarf_decl_ctx[0].name);
5278 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
5279
5280 if (type_name)
5281 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005282 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
Greg Claytona8022fa2012-04-24 21:22:41 +00005283 if (log)
5284 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005285 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005286 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')",
5287 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5288 dwarf_decl_ctx.GetQualifiedName());
5289 }
5290
5291 DIEArray die_offsets;
5292
5293 if (m_using_apple_tables)
5294 {
5295 if (m_apple_types_ap.get())
5296 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005297 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
5298 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
5299 if (has_tag && has_qualified_name_hash)
Greg Claytona8022fa2012-04-24 21:22:41 +00005300 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005301 const char *qualified_name = dwarf_decl_ctx.GetQualifiedName();
5302 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name);
5303 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005304 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005305 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets);
5306 }
5307 else if (has_tag)
5308 {
5309 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005310 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
Greg Claytona8022fa2012-04-24 21:22:41 +00005311 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets);
5312 }
5313 else
5314 {
5315 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
5316 }
5317 }
5318 }
5319 else
5320 {
5321 if (!m_indexed)
5322 Index ();
5323
5324 m_type_index.Find (type_name, die_offsets);
5325 }
5326
5327 const size_t num_matches = die_offsets.size();
5328
5329
5330 DWARFCompileUnit* type_cu = NULL;
5331 const DWARFDebugInfoEntry* type_die = NULL;
5332 if (num_matches)
5333 {
5334 DWARFDebugInfo* debug_info = DebugInfo();
5335 for (size_t i=0; i<num_matches; ++i)
5336 {
5337 const dw_offset_t die_offset = die_offsets[i];
5338 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
5339
5340 if (type_die)
5341 {
5342 bool try_resolving_type = false;
5343
5344 // Don't try and resolve the DIE we are looking for with the DIE itself!
5345 const dw_tag_t type_tag = type_die->Tag();
5346 // Make sure the tags match
5347 if (type_tag == tag)
5348 {
5349 // The tags match, lets try resolving this type
5350 try_resolving_type = true;
5351 }
5352 else
5353 {
5354 // The tags don't match, but we need to watch our for a
5355 // forward declaration for a struct and ("struct foo")
5356 // ends up being a class ("class foo { ... };") or
5357 // vice versa.
5358 switch (type_tag)
5359 {
5360 case DW_TAG_class_type:
5361 // We had a "class foo", see if we ended up with a "struct foo { ... };"
5362 try_resolving_type = (tag == DW_TAG_structure_type);
5363 break;
5364 case DW_TAG_structure_type:
5365 // We had a "struct foo", see if we ended up with a "class foo { ... };"
5366 try_resolving_type = (tag == DW_TAG_class_type);
5367 break;
5368 default:
5369 // Tags don't match, don't event try to resolve
5370 // using this type whose name matches....
5371 break;
5372 }
5373 }
5374
5375 if (try_resolving_type)
5376 {
5377 DWARFDeclContext type_dwarf_decl_ctx;
5378 type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx);
5379
5380 if (log)
5381 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005382 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005383 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)",
5384 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5385 dwarf_decl_ctx.GetQualifiedName(),
5386 type_die->GetOffset(),
5387 type_dwarf_decl_ctx.GetQualifiedName());
5388 }
5389
5390 // Make sure the decl contexts match all the way up
5391 if (dwarf_decl_ctx == type_dwarf_decl_ctx)
5392 {
5393 Type *resolved_type = ResolveType (type_cu, type_die, false);
5394 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5395 {
5396 type_sp = resolved_type->shared_from_this();
5397 break;
5398 }
5399 }
5400 }
5401 else
5402 {
5403 if (log)
5404 {
5405 std::string qualified_name;
5406 type_die->GetQualifiedName(this, type_cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00005407 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005408 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)",
5409 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5410 dwarf_decl_ctx.GetQualifiedName(),
5411 type_die->GetOffset(),
5412 qualified_name.c_str());
5413 }
5414 }
5415 }
5416 else
5417 {
5418 if (m_using_apple_tables)
5419 {
5420 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5421 die_offset, type_name.GetCString());
5422 }
5423 }
5424
5425 }
5426 }
5427 }
5428 }
5429 return type_sp;
5430}
5431
Greg Clayton4116e932012-05-15 02:33:01 +00005432bool
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005433SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005434 Type *class_type,
Greg Clayton4116e932012-05-15 02:33:01 +00005435 DWARFCompileUnit* src_cu,
5436 const DWARFDebugInfoEntry *src_class_die,
5437 DWARFCompileUnit* dst_cu,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005438 const DWARFDebugInfoEntry *dst_class_die,
Greg Claytond20deac2014-04-04 18:15:18 +00005439 DWARFDIECollection &failures)
Greg Clayton4116e932012-05-15 02:33:01 +00005440{
5441 if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die)
5442 return false;
5443 if (src_class_die->Tag() != dst_class_die->Tag())
5444 return false;
5445
5446 // We need to complete the class type so we can get all of the method types
5447 // parsed so we can then unique those types to their equivalent counterparts
5448 // in "dst_cu" and "dst_class_die"
5449 class_type->GetClangFullType();
5450
5451 const DWARFDebugInfoEntry *src_die;
5452 const DWARFDebugInfoEntry *dst_die;
5453 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die;
5454 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die;
Greg Clayton65ec1032012-11-12 21:27:20 +00005455 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial;
5456 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial;
Greg Clayton4116e932012-05-15 02:33:01 +00005457 for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling())
5458 {
5459 if (src_die->Tag() == DW_TAG_subprogram)
5460 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005461 // Make sure this is a declaration and not a concrete instance by looking
5462 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5463 // are placed inside the class definitions and shouldn't be included in
5464 // the list of things are are tracking here.
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005465 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_declaration, 0) == 1)
Greg Clayton84afacd2012-11-07 23:09:32 +00005466 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005467 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton84afacd2012-11-07 23:09:32 +00005468 if (src_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005469 {
5470 ConstString src_const_name(src_name);
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005471 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0))
Greg Clayton65ec1032012-11-12 21:27:20 +00005472 src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die);
5473 else
5474 src_name_to_die.Append(src_const_name.GetCString(), src_die);
5475 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005476 }
Greg Clayton4116e932012-05-15 02:33:01 +00005477 }
5478 }
5479 for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling())
5480 {
5481 if (dst_die->Tag() == DW_TAG_subprogram)
5482 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005483 // Make sure this is a declaration and not a concrete instance by looking
5484 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5485 // are placed inside the class definitions and shouldn't be included in
5486 // the list of things are are tracking here.
5487 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1)
5488 {
5489 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5490 if (dst_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005491 {
5492 ConstString dst_const_name(dst_name);
5493 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0))
5494 dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die);
5495 else
5496 dst_name_to_die.Append(dst_const_name.GetCString(), dst_die);
5497 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005498 }
Greg Clayton4116e932012-05-15 02:33:01 +00005499 }
5500 }
5501 const uint32_t src_size = src_name_to_die.GetSize ();
5502 const uint32_t dst_size = dst_name_to_die.GetSize ();
Greg Clayton5160ce52013-03-27 23:08:40 +00005503 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005504
5505 // Is everything kosher so we can go through the members at top speed?
5506 bool fast_path = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005507
Sean Callanan2367f8a2013-02-26 01:12:25 +00005508 if (src_size != dst_size)
Greg Clayton4116e932012-05-15 02:33:01 +00005509 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005510 if (src_size != 0 && dst_size != 0)
5511 {
5512 if (log)
5513 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)",
5514 src_class_die->GetOffset(),
5515 dst_class_die->GetOffset(),
5516 src_size,
5517 dst_size);
5518 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005519
Sean Callanan2367f8a2013-02-26 01:12:25 +00005520 fast_path = false;
5521 }
5522
5523 uint32_t idx;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005524
Sean Callanan2367f8a2013-02-26 01:12:25 +00005525 if (fast_path)
5526 {
Greg Clayton4116e932012-05-15 02:33:01 +00005527 for (idx = 0; idx < src_size; ++idx)
5528 {
5529 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5530 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5531
5532 if (src_die->Tag() != dst_die->Tag())
5533 {
5534 if (log)
5535 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)",
5536 src_class_die->GetOffset(),
5537 dst_class_die->GetOffset(),
5538 src_die->GetOffset(),
5539 DW_TAG_value_to_name(src_die->Tag()),
5540 dst_die->GetOffset(),
5541 DW_TAG_value_to_name(src_die->Tag()));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005542 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005543 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005544
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005545 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton4116e932012-05-15 02:33:01 +00005546 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005547
Greg Clayton4116e932012-05-15 02:33:01 +00005548 // Make sure the names match
5549 if (src_name == dst_name || (strcmp (src_name, dst_name) == 0))
5550 continue;
5551
5552 if (log)
5553 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)",
5554 src_class_die->GetOffset(),
5555 dst_class_die->GetOffset(),
5556 src_die->GetOffset(),
5557 src_name,
5558 dst_die->GetOffset(),
5559 dst_name);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005560
Sean Callanan2367f8a2013-02-26 01:12:25 +00005561 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005562 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005563 }
Greg Clayton4116e932012-05-15 02:33:01 +00005564
Sean Callanan2367f8a2013-02-26 01:12:25 +00005565 // Now do the work of linking the DeclContexts and Types.
5566 if (fast_path)
5567 {
5568 // We can do this quickly. Just run across the tables index-for-index since
5569 // we know each node has matching names and tags.
Greg Clayton4116e932012-05-15 02:33:01 +00005570 for (idx = 0; idx < src_size; ++idx)
5571 {
5572 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5573 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005574
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005575 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Greg Clayton4116e932012-05-15 02:33:01 +00005576 if (src_decl_ctx)
5577 {
5578 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005579 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
5580 static_cast<void*>(src_decl_ctx),
5581 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005582 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5583 }
5584 else
5585 {
5586 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005587 log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found",
5588 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005589 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005590
Greg Clayton4116e932012-05-15 02:33:01 +00005591 Type *src_child_type = m_die_to_type[src_die];
5592 if (src_child_type)
5593 {
5594 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005595 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
5596 static_cast<void*>(src_child_type),
5597 src_child_type->GetID(),
5598 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005599 m_die_to_type[dst_die] = src_child_type;
5600 }
5601 else
5602 {
5603 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005604 log->Printf ("warning: tried to unique lldb_private::Type from 0x%8.8x for 0x%8.8x, but none was found", src_die->GetOffset(), dst_die->GetOffset());
5605 }
5606 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005607 }
5608 else
5609 {
5610 // We must do this slowly. For each member of the destination, look
5611 // up a member in the source with the same name, check its tag, and
5612 // unique them if everything matches up. Report failures.
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005613
Sean Callanan2367f8a2013-02-26 01:12:25 +00005614 if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty())
5615 {
5616 src_name_to_die.Sort();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005617
Sean Callanan2367f8a2013-02-26 01:12:25 +00005618 for (idx = 0; idx < dst_size; ++idx)
5619 {
5620 const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx);
5621 dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
5622 src_die = src_name_to_die.Find(dst_name, NULL);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005623
Sean Callanan2367f8a2013-02-26 01:12:25 +00005624 if (src_die && (src_die->Tag() == dst_die->Tag()))
5625 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005626 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Sean Callanan2367f8a2013-02-26 01:12:25 +00005627 if (src_decl_ctx)
5628 {
5629 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005630 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
5631 static_cast<void*>(src_decl_ctx),
5632 src_die->GetOffset(),
5633 dst_die->GetOffset());
Sean Callanan2367f8a2013-02-26 01:12:25 +00005634 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5635 }
5636 else
5637 {
5638 if (log)
5639 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());
5640 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005641
Sean Callanan2367f8a2013-02-26 01:12:25 +00005642 Type *src_child_type = m_die_to_type[src_die];
5643 if (src_child_type)
5644 {
5645 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005646 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
5647 static_cast<void*>(src_child_type),
5648 src_child_type->GetID(),
5649 src_die->GetOffset(),
5650 dst_die->GetOffset());
Sean Callanan2367f8a2013-02-26 01:12:25 +00005651 m_die_to_type[dst_die] = src_child_type;
5652 }
5653 else
5654 {
5655 if (log)
5656 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());
5657 }
5658 }
5659 else
5660 {
5661 if (log)
5662 log->Printf ("warning: couldn't find a match for 0x%8.8x", dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005663
Greg Claytond20deac2014-04-04 18:15:18 +00005664 failures.Append(dst_die);
Sean Callanan2367f8a2013-02-26 01:12:25 +00005665 }
5666 }
5667 }
5668 }
5669
5670 const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize ();
5671 const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize ();
5672
5673 UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src;
5674
5675 if (src_size_artificial && dst_size_artificial)
5676 {
5677 dst_name_to_die_artificial.Sort();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005678
Greg Clayton65ec1032012-11-12 21:27:20 +00005679 for (idx = 0; idx < src_size_artificial; ++idx)
5680 {
5681 const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx);
5682 src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5683 dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005684
Greg Clayton65ec1032012-11-12 21:27:20 +00005685 if (dst_die)
5686 {
Greg Clayton65ec1032012-11-12 21:27:20 +00005687 // Both classes have the artificial types, link them
5688 clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die];
5689 if (src_decl_ctx)
5690 {
5691 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005692 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
5693 static_cast<void*>(src_decl_ctx),
5694 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005695 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5696 }
5697 else
5698 {
5699 if (log)
5700 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());
5701 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005702
Greg Clayton65ec1032012-11-12 21:27:20 +00005703 Type *src_child_type = m_die_to_type[src_die];
5704 if (src_child_type)
5705 {
5706 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005707 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
5708 static_cast<void*>(src_child_type),
5709 src_child_type->GetID(),
5710 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005711 m_die_to_type[dst_die] = src_child_type;
5712 }
5713 else
5714 {
5715 if (log)
5716 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());
5717 }
5718 }
5719 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005720 }
Greg Clayton65ec1032012-11-12 21:27:20 +00005721
Sean Callanan2367f8a2013-02-26 01:12:25 +00005722 if (dst_size_artificial)
Greg Clayton4116e932012-05-15 02:33:01 +00005723 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005724 for (idx = 0; idx < dst_size_artificial; ++idx)
5725 {
5726 const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx);
5727 dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5728 if (log)
5729 log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial);
5730
Greg Claytond20deac2014-04-04 18:15:18 +00005731 failures.Append(dst_die);
Sean Callanan2367f8a2013-02-26 01:12:25 +00005732 }
Greg Clayton4116e932012-05-15 02:33:01 +00005733 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005734
Greg Claytond20deac2014-04-04 18:15:18 +00005735 return (failures.Size() != 0);
Greg Clayton4116e932012-05-15 02:33:01 +00005736}
Greg Claytona8022fa2012-04-24 21:22:41 +00005737
5738TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00005739SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005740{
5741 TypeSP type_sp;
5742
Greg Clayton1be10fc2010-09-29 01:12:09 +00005743 if (type_is_new_ptr)
5744 *type_is_new_ptr = false;
Greg Clayton1fba87112012-02-09 20:03:49 +00005745
Todd Fiala0a70a842014-05-28 16:43:26 +00005746#if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE)
Greg Clayton1fba87112012-02-09 20:03:49 +00005747 static DIEStack g_die_stack;
5748 DIEStack::ScopedPopper scoped_die_logger(g_die_stack);
5749#endif
Greg Clayton1be10fc2010-09-29 01:12:09 +00005750
Sean Callananc7fbf732010-08-06 00:32:49 +00005751 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005752 if (die != NULL)
5753 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005754 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005755 if (log)
Sean Callanan5b26f272012-02-04 08:49:35 +00005756 {
5757 const DWARFDebugInfoEntry *context_die;
5758 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005759
Greg Clayton5160ce52013-03-27 23:08:40 +00005760 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 +00005761 die->GetOffset(),
5762 static_cast<void*>(context),
5763 context_die->GetOffset(),
5764 DW_TAG_value_to_name(die->Tag()),
5765 die->GetName(this, dwarf_cu));
5766
Todd Fiala0a70a842014-05-28 16:43:26 +00005767#if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE)
Greg Clayton1fba87112012-02-09 20:03:49 +00005768 scoped_die_logger.Push (dwarf_cu, die);
Greg Clayton5160ce52013-03-27 23:08:40 +00005769 g_die_stack.LogDIEs(log, this);
Greg Clayton1fba87112012-02-09 20:03:49 +00005770#endif
Sean Callanan5b26f272012-02-04 08:49:35 +00005771 }
Greg Clayton3bffb082011-12-10 02:15:28 +00005772//
Greg Clayton5160ce52013-03-27 23:08:40 +00005773// Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005774// if (log && dwarf_cu)
5775// {
5776// StreamString s;
5777// die->DumpLocation (this, dwarf_cu, s);
Greg Clayton5160ce52013-03-27 23:08:40 +00005778// GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Greg Clayton3bffb082011-12-10 02:15:28 +00005779//
5780// }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005781
Greg Clayton594e5ed2010-09-27 21:07:38 +00005782 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005783 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00005784 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005785 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005786 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00005787 if (type_is_new_ptr)
5788 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005789
Greg Clayton594e5ed2010-09-27 21:07:38 +00005790 const dw_tag_t tag = die->Tag();
5791
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005792 bool is_forward_declaration = false;
5793 DWARFDebugInfoEntry::Attributes attributes;
5794 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00005795 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00005796 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
Greg Claytonfaac1112013-03-14 18:31:44 +00005797 uint64_t byte_size = 0;
Greg Clayton526e5af2010-11-13 03:52:47 +00005798 Declaration decl;
5799
Greg Clayton4957bf62010-09-30 21:49:03 +00005800 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton57ee3062013-07-11 22:46:58 +00005801 ClangASTType clang_type;
Greg Claytond20deac2014-04-04 18:15:18 +00005802 DWARFFormValue form_value;
5803
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005804 dw_attr_t attr;
5805
5806 switch (tag)
5807 {
5808 case DW_TAG_base_type:
5809 case DW_TAG_pointer_type:
5810 case DW_TAG_reference_type:
Sean Callanance8af862012-05-21 23:31:51 +00005811 case DW_TAG_rvalue_reference_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005812 case DW_TAG_typedef:
5813 case DW_TAG_const_type:
5814 case DW_TAG_restrict_type:
5815 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00005816 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005817 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005818 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005819 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005820
Greg Claytond88d7592010-09-15 08:33:30 +00005821 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005822 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005823 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
5824
5825 if (num_attributes > 0)
5826 {
5827 uint32_t i;
5828 for (i=0; i<num_attributes; ++i)
5829 {
5830 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005831 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5832 {
5833 switch (attr)
5834 {
5835 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5836 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5837 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5838 case DW_AT_name:
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005839
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005840 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00005841 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
5842 // include the "&"...
5843 if (tag == DW_TAG_reference_type)
5844 {
5845 if (strchr (type_name_cstr, '&') == NULL)
5846 type_name_cstr = NULL;
5847 }
5848 if (type_name_cstr)
5849 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005850 break;
Greg Clayton23f59502012-07-17 03:23:13 +00005851 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005852 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
Greg Clayton54166af2014-11-22 01:58:59 +00005853 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005854 default:
5855 case DW_AT_sibling:
5856 break;
5857 }
5858 }
5859 }
5860 }
5861
Ed Mastea0191d12013-10-17 20:42:56 +00005862 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 +00005863
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005864 switch (tag)
5865 {
5866 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00005867 break;
5868
Greg Claytond4436412011-10-28 21:00:00 +00005869 case DW_TAG_unspecified_type:
Greg Clayton7fba2632013-07-01 21:01:52 +00005870 if (strcmp(type_name_cstr, "nullptr_t") == 0 ||
5871 strcmp(type_name_cstr, "decltype(nullptr)") == 0 )
Greg Claytond4436412011-10-28 21:00:00 +00005872 {
5873 resolve_state = Type::eResolveStateFull;
Greg Clayton57ee3062013-07-11 22:46:58 +00005874 clang_type = ast.GetBasicType(eBasicTypeNullPtr);
Greg Claytond4436412011-10-28 21:00:00 +00005875 break;
5876 }
5877 // Fall through to base type below in case we can handle the type there...
5878
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005879 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00005880 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005881 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
5882 encoding,
5883 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005884 break;
5885
Sean Callanance8af862012-05-21 23:31:51 +00005886 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
5887 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
5888 case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break;
5889 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
5890 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
5891 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
5892 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005893 }
5894
Greg Clayton57ee3062013-07-11 22:46:58 +00005895 if (!clang_type && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID) && sc.comp_unit != NULL)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005896 {
Sean Callanan82587052013-01-03 00:05:56 +00005897 bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005898
Sean Callanan82587052013-01-03 00:05:56 +00005899 if (translation_unit_is_objc)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005900 {
Sean Callanan82587052013-01-03 00:05:56 +00005901 if (type_name_cstr != NULL)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005902 {
Sean Callanan82587052013-01-03 00:05:56 +00005903 static ConstString g_objc_type_name_id("id");
5904 static ConstString g_objc_type_name_Class("Class");
5905 static ConstString g_objc_type_name_selector("SEL");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005906
Sean Callanan82587052013-01-03 00:05:56 +00005907 if (type_name_const_str == g_objc_type_name_id)
5908 {
5909 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005910 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 +00005911 die->GetOffset(),
5912 DW_TAG_value_to_name(die->Tag()),
5913 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005914 clang_type = ast.GetBasicType(eBasicTypeObjCID);
Sean Callanan82587052013-01-03 00:05:56 +00005915 encoding_data_type = Type::eEncodingIsUID;
5916 encoding_uid = LLDB_INVALID_UID;
5917 resolve_state = Type::eResolveStateFull;
Greg Clayton526e5af2010-11-13 03:52:47 +00005918
Sean Callanan82587052013-01-03 00:05:56 +00005919 }
5920 else if (type_name_const_str == g_objc_type_name_Class)
5921 {
5922 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005923 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 +00005924 die->GetOffset(),
5925 DW_TAG_value_to_name(die->Tag()),
5926 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005927 clang_type = ast.GetBasicType(eBasicTypeObjCClass);
Sean Callanan82587052013-01-03 00:05:56 +00005928 encoding_data_type = Type::eEncodingIsUID;
5929 encoding_uid = LLDB_INVALID_UID;
5930 resolve_state = Type::eResolveStateFull;
5931 }
5932 else if (type_name_const_str == g_objc_type_name_selector)
5933 {
5934 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005935 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 +00005936 die->GetOffset(),
5937 DW_TAG_value_to_name(die->Tag()),
5938 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005939 clang_type = ast.GetBasicType(eBasicTypeObjCSel);
Sean Callanan82587052013-01-03 00:05:56 +00005940 encoding_data_type = Type::eEncodingIsUID;
5941 encoding_uid = LLDB_INVALID_UID;
5942 resolve_state = Type::eResolveStateFull;
5943 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005944 }
Sean Callanan82587052013-01-03 00:05:56 +00005945 else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005946 {
Sean Callanan82587052013-01-03 00:05:56 +00005947 // 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 +00005948
Sean Callanan82587052013-01-03 00:05:56 +00005949 DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005950
Sean Callanan82587052013-01-03 00:05:56 +00005951 if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005952 {
Sean Callanan82587052013-01-03 00:05:56 +00005953 if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL))
5954 {
5955 if (!strcmp(struct_name, "objc_object"))
5956 {
5957 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005958 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 +00005959 die->GetOffset(),
5960 DW_TAG_value_to_name(die->Tag()),
5961 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005962 clang_type = ast.GetBasicType(eBasicTypeObjCID);
Sean Callanan82587052013-01-03 00:05:56 +00005963 encoding_data_type = Type::eEncodingIsUID;
5964 encoding_uid = LLDB_INVALID_UID;
5965 resolve_state = Type::eResolveStateFull;
5966 }
5967 }
5968 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005969 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005970 }
5971 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005972
Greg Clayton81c22f62011-10-19 18:09:39 +00005973 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005974 this,
5975 type_name_const_str,
5976 byte_size,
5977 NULL,
5978 encoding_uid,
5979 encoding_data_type,
5980 &decl,
5981 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005982 resolve_state));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005983
Greg Clayton594e5ed2010-09-27 21:07:38 +00005984 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005985
5986// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
5987// if (encoding_type != NULL)
5988// {
5989// if (encoding_type != DIE_IS_BEING_PARSED)
5990// type_sp->SetEncodingType(encoding_type);
5991// else
5992// m_indirect_fixups.push_back(type_sp.get());
5993// }
5994 }
5995 break;
5996
5997 case DW_TAG_structure_type:
5998 case DW_TAG_union_type:
5999 case DW_TAG_class_type:
6000 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006001 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006002 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Greg Clayton23f59502012-07-17 03:23:13 +00006003 bool byte_size_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006004
Greg Clayton9e409562010-07-28 02:04:09 +00006005 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00006006 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006007 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00006008 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006009 if (num_attributes > 0)
6010 {
6011 uint32_t i;
6012 for (i=0; i<num_attributes; ++i)
6013 {
6014 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006015 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6016 {
6017 switch (attr)
6018 {
Greg Clayton9e409562010-07-28 02:04:09 +00006019 case DW_AT_decl_file:
Greg Claytonc7f03b62012-01-12 04:33:28 +00006020 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
Ed Maste4c24b122013-10-17 20:13:14 +00006021 {
6022 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
6023 // point to the compile unit file, so we clear this invalid value
6024 // so that we can still unique types efficiently.
Greg Claytonc7f03b62012-01-12 04:33:28 +00006025 decl.SetFile(FileSpec ("<invalid>", false));
Ed Maste4c24b122013-10-17 20:13:14 +00006026 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00006027 else
6028 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
Greg Clayton9e409562010-07-28 02:04:09 +00006029 break;
6030
6031 case DW_AT_decl_line:
6032 decl.SetLine(form_value.Unsigned());
6033 break;
6034
6035 case DW_AT_decl_column:
6036 decl.SetColumn(form_value.Unsigned());
6037 break;
6038
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006039 case DW_AT_name:
6040 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006041 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006042 break;
Greg Clayton9e409562010-07-28 02:04:09 +00006043
6044 case DW_AT_byte_size:
6045 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00006046 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00006047 break;
6048
6049 case DW_AT_accessibility:
6050 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
6051 break;
6052
6053 case DW_AT_declaration:
Greg Clayton1c8ef472013-04-05 23:27:21 +00006054 is_forward_declaration = form_value.Boolean();
Greg Clayton9e409562010-07-28 02:04:09 +00006055 break;
6056
6057 case DW_AT_APPLE_runtime_class:
6058 class_language = (LanguageType)form_value.Signed();
6059 break;
6060
Greg Clayton18774842011-11-29 23:40:34 +00006061 case DW_AT_APPLE_objc_complete_type:
6062 is_complete_objc_class = form_value.Signed();
6063 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006064
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006065 case DW_AT_allocated:
6066 case DW_AT_associated:
6067 case DW_AT_data_location:
6068 case DW_AT_description:
6069 case DW_AT_start_scope:
6070 case DW_AT_visibility:
6071 default:
6072 case DW_AT_sibling:
6073 break;
6074 }
6075 }
6076 }
6077 }
Greg Claytond20deac2014-04-04 18:15:18 +00006078
6079 // UniqueDWARFASTType is large, so don't create a local variables on the
6080 // stack, put it on the heap. This function is often called recursively
6081 // and clang isn't good and sharing the stack space for variables in different blocks.
6082 std::unique_ptr<UniqueDWARFASTType> unique_ast_entry_ap(new UniqueDWARFASTType());
Sean Callanan8e8072d2012-02-07 21:13:38 +00006083
Greg Clayton123edca2012-03-02 00:07:15 +00006084 // Only try and unique the type if it has a name.
6085 if (type_name_const_str &&
6086 GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Sean Callanan8e8072d2012-02-07 21:13:38 +00006087 this,
6088 dwarf_cu,
6089 die,
6090 decl,
6091 byte_size_valid ? byte_size : -1,
Greg Claytond20deac2014-04-04 18:15:18 +00006092 *unique_ast_entry_ap))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006093 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00006094 // We have already parsed this type or from another
6095 // compile unit. GCC loves to use the "one definition
6096 // rule" which can result in multiple definitions
6097 // of the same class over and over in each compile
6098 // unit.
Greg Claytond20deac2014-04-04 18:15:18 +00006099 type_sp = unique_ast_entry_ap->m_type_sp;
Sean Callanan8e8072d2012-02-07 21:13:38 +00006100 if (type_sp)
Greg Claytonc615ce42010-11-09 04:42:43 +00006101 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00006102 m_die_to_type[die] = type_sp.get();
6103 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00006104 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006105 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006106
Daniel Malead01b2952012-11-29 21:49:15 +00006107 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 +00006108
6109 int tag_decl_kind = -1;
6110 AccessType default_accessibility = eAccessNone;
6111 if (tag == DW_TAG_structure_type)
6112 {
6113 tag_decl_kind = clang::TTK_Struct;
6114 default_accessibility = eAccessPublic;
6115 }
6116 else if (tag == DW_TAG_union_type)
6117 {
6118 tag_decl_kind = clang::TTK_Union;
6119 default_accessibility = eAccessPublic;
6120 }
6121 else if (tag == DW_TAG_class_type)
6122 {
6123 tag_decl_kind = clang::TTK_Class;
6124 default_accessibility = eAccessPrivate;
6125 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006126
Greg Clayton3a5f29a2011-11-30 02:48:28 +00006127 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
6128 die->HasChildren() == false &&
6129 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
6130 {
6131 // Work around an issue with clang at the moment where
6132 // forward declarations for objective C classes are emitted
6133 // as:
6134 // DW_TAG_structure_type [2]
6135 // DW_AT_name( "ForwardObjcClass" )
6136 // DW_AT_byte_size( 0x00 )
6137 // DW_AT_decl_file( "..." )
6138 // DW_AT_decl_line( 1 )
6139 //
6140 // Note that there is no DW_AT_declaration and there are
6141 // no children, and the byte size is zero.
6142 is_forward_declaration = true;
6143 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006144
Sean Callanan7457f8d2012-04-25 01:03:57 +00006145 if (class_language == eLanguageTypeObjC ||
6146 class_language == eLanguageTypeObjC_plus_plus)
Greg Clayton18774842011-11-29 23:40:34 +00006147 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00006148 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
Greg Clayton901c5ca2011-12-03 04:40:03 +00006149 {
6150 // We have a valid eSymbolTypeObjCClass class symbol whose
6151 // name matches the current objective C class that we
6152 // are trying to find and this DIE isn't the complete
6153 // definition (we checked is_complete_objc_class above and
6154 // know it is false), so the real definition is in here somewhere
Greg Claytonc7f03b62012-01-12 04:33:28 +00006155 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006156
Greg Clayton1f746072012-08-29 21:13:06 +00006157 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton901c5ca2011-12-03 04:40:03 +00006158 {
6159 // We weren't able to find a full declaration in
6160 // this DWARF, see if we have a declaration anywhere
6161 // else...
Greg Claytonc7f03b62012-01-12 04:33:28 +00006162 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00006163 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006164
Greg Clayton901c5ca2011-12-03 04:40:03 +00006165 if (type_sp)
6166 {
6167 if (log)
6168 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006169 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00006170 "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 +00006171 static_cast<void*>(this),
Greg Claytone38a5ed2012-01-05 03:57:59 +00006172 die->GetOffset(),
6173 DW_TAG_value_to_name(tag),
6174 type_name_cstr,
6175 type_sp->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00006176 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006177
Greg Clayton901c5ca2011-12-03 04:40:03 +00006178 // We found a real definition for this type elsewhere
6179 // so lets use it and cache the fact that we found
6180 // a complete type for this die
6181 m_die_to_type[die] = type_sp.get();
6182 return type_sp;
6183 }
6184 }
6185 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006186
Greg Clayton901c5ca2011-12-03 04:40:03 +00006187
6188 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006189 {
6190 // We have a forward declaration to a type and we need
6191 // to try and find a full declaration. We look in the
6192 // current type index just in case we have a forward
6193 // declaration followed by an actual declarations in the
6194 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00006195 if (log)
6196 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006197 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00006198 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006199 static_cast<void*>(this),
Greg Claytone38a5ed2012-01-05 03:57:59 +00006200 die->GetOffset(),
6201 DW_TAG_value_to_name(tag),
6202 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00006203 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006204
Greg Claytona8022fa2012-04-24 21:22:41 +00006205 DWARFDeclContext die_decl_ctx;
6206 die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx);
6207
6208 //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
6209 type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006210
Greg Clayton1f746072012-08-29 21:13:06 +00006211 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton4272cc72011-02-02 02:24:04 +00006212 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006213 // We weren't able to find a full declaration in
6214 // this DWARF, see if we have a declaration anywhere
6215 // else...
Greg Claytona8022fa2012-04-24 21:22:41 +00006216 type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton4272cc72011-02-02 02:24:04 +00006217 }
6218
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006219 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00006220 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00006221 if (log)
6222 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006223 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00006224 "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 +00006225 static_cast<void*>(this),
Greg Claytone38a5ed2012-01-05 03:57:59 +00006226 die->GetOffset(),
6227 DW_TAG_value_to_name(tag),
6228 type_name_cstr,
6229 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00006230 }
6231
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006232 // We found a real definition for this type elsewhere
6233 // so lets use it and cache the fact that we found
6234 // a complete type for this die
6235 m_die_to_type[die] = type_sp.get();
6236 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00006237 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006238 }
6239 assert (tag_decl_kind != -1);
6240 bool clang_type_was_created = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00006241 clang_type.SetClangType(ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die));
6242 if (!clang_type)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006243 {
Sean Callanan4d04c6a2012-02-09 22:54:11 +00006244 const DWARFDebugInfoEntry *decl_ctx_die;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006245
Sean Callanan4d04c6a2012-02-09 22:54:11 +00006246 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton55561e92011-10-26 03:31:36 +00006247 if (accessibility == eAccessNone && decl_ctx)
6248 {
6249 // Check the decl context that contains this class/struct/union.
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00006250 // If it is a class we must give it an accessibility.
Greg Clayton55561e92011-10-26 03:31:36 +00006251 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
6252 if (DeclKindIsCXXClass (containing_decl_kind))
6253 accessibility = default_accessibility;
6254 }
6255
Greg Claytonc4ffd662013-03-08 01:37:30 +00006256 ClangASTMetadata metadata;
6257 metadata.SetUserID(MakeUserID(die->GetOffset()));
6258 metadata.SetIsDynamicCXXType(ClassOrStructIsVirtual (dwarf_cu, die));
6259
Greg Claytonf0705c82011-10-22 03:33:13 +00006260 if (type_name_cstr && strchr (type_name_cstr, '<'))
6261 {
6262 ClangASTContext::TemplateParameterInfos template_param_infos;
6263 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
6264 {
6265 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00006266 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00006267 type_name_cstr,
6268 tag_decl_kind,
6269 template_param_infos);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006270
Greg Claytonf0705c82011-10-22 03:33:13 +00006271 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
6272 class_template_decl,
6273 tag_decl_kind,
6274 template_param_infos);
6275 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
6276 clang_type_was_created = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006277
Greg Claytond0029442013-03-27 01:48:02 +00006278 GetClangASTContext().SetMetadata (class_template_decl, metadata);
6279 GetClangASTContext().SetMetadata (class_specialization_decl, metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00006280 }
6281 }
6282
6283 if (!clang_type_was_created)
6284 {
6285 clang_type_was_created = true;
Greg Clayton55561e92011-10-26 03:31:36 +00006286 clang_type = ast.CreateRecordType (decl_ctx,
6287 accessibility,
6288 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00006289 tag_decl_kind,
Sean Callanan60217122012-04-13 00:10:03 +00006290 class_language,
Jim Ingham379397632012-10-27 02:54:13 +00006291 &metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00006292 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006293 }
6294
6295 // Store a forward declaration to this class type in case any
6296 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00006297 // types for function prototypes.
Greg Clayton57ee3062013-07-11 22:46:58 +00006298 LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00006299 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006300 this,
6301 type_name_const_str,
6302 byte_size,
6303 NULL,
6304 LLDB_INVALID_UID,
6305 Type::eEncodingIsUID,
6306 &decl,
6307 clang_type,
6308 Type::eResolveStateForward));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006309
Sean Callanan72772842012-02-22 23:57:45 +00006310 type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006311
6312
6313 // Add our type to the unique type map so we don't
6314 // end up creating many copies of the same type over
6315 // and over in the ASTContext for our module
Greg Claytond20deac2014-04-04 18:15:18 +00006316 unique_ast_entry_ap->m_type_sp = type_sp;
6317 unique_ast_entry_ap->m_symfile = this;
6318 unique_ast_entry_ap->m_cu = dwarf_cu;
6319 unique_ast_entry_ap->m_die = die;
6320 unique_ast_entry_ap->m_declaration = decl;
6321 unique_ast_entry_ap->m_byte_size = byte_size;
Greg Claytone576ab22011-02-15 00:19:15 +00006322 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
Greg Claytond20deac2014-04-04 18:15:18 +00006323 *unique_ast_entry_ap);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006324
Greg Clayton0ec71a02013-08-10 00:09:35 +00006325 if (is_forward_declaration && die->HasChildren())
6326 {
6327 // Check to see if the DIE actually has a definition, some version of GCC will
6328 // emit DIEs with DW_AT_declaration set to true, but yet still have subprogram,
6329 // members, or inheritance, so we can't trust it
6330 const DWARFDebugInfoEntry *child_die = die->GetFirstChild();
6331 while (child_die)
6332 {
6333 switch (child_die->Tag())
6334 {
6335 case DW_TAG_inheritance:
6336 case DW_TAG_subprogram:
6337 case DW_TAG_member:
6338 case DW_TAG_APPLE_property:
Greg Clayton4c484ec2014-02-07 19:21:56 +00006339 case DW_TAG_class_type:
6340 case DW_TAG_structure_type:
6341 case DW_TAG_enumeration_type:
6342 case DW_TAG_typedef:
6343 case DW_TAG_union_type:
Greg Clayton0ec71a02013-08-10 00:09:35 +00006344 child_die = NULL;
6345 is_forward_declaration = false;
6346 break;
6347 default:
6348 child_die = child_die->GetSibling();
6349 break;
6350 }
6351 }
6352 }
6353
Sean Callanan12014a02011-12-08 23:45:45 +00006354 if (!is_forward_declaration)
Greg Clayton219cf312012-03-30 00:51:13 +00006355 {
6356 // Always start the definition for a class type so that
6357 // if the class has child classes or types that require
6358 // the class to be created for use as their decl contexts
6359 // the class will be ready to accept these child definitions.
Sean Callanan12014a02011-12-08 23:45:45 +00006360 if (die->HasChildren() == false)
6361 {
6362 // No children for this struct/union/class, lets finish it
Greg Clayton57ee3062013-07-11 22:46:58 +00006363 clang_type.StartTagDeclarationDefinition ();
6364 clang_type.CompleteTagDeclarationDefinition ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006365
Sean Callanan433cd222012-10-19 01:37:25 +00006366 if (tag == DW_TAG_structure_type) // this only applies in C
6367 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006368 clang::RecordDecl *record_decl = clang_type.GetAsRecordDecl();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006369
Greg Clayton57ee3062013-07-11 22:46:58 +00006370 if (record_decl)
Greg Claytond20deac2014-04-04 18:15:18 +00006371 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, LayoutInfo()));
Sean Callanan433cd222012-10-19 01:37:25 +00006372 }
Sean Callanan12014a02011-12-08 23:45:45 +00006373 }
6374 else if (clang_type_was_created)
6375 {
Greg Clayton219cf312012-03-30 00:51:13 +00006376 // Start the definition if the class is not objective C since
6377 // the underlying decls respond to isCompleteDefinition(). Objective
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +00006378 // C decls don't respond to isCompleteDefinition() so we can't
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00006379 // start the declaration definition right away. For C++ class/union/structs
Greg Clayton219cf312012-03-30 00:51:13 +00006380 // we want to start the definition in case the class is needed as the
6381 // declaration context for a contained class or type without the need
6382 // to complete that type..
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006383
Sean Callanan7457f8d2012-04-25 01:03:57 +00006384 if (class_language != eLanguageTypeObjC &&
6385 class_language != eLanguageTypeObjC_plus_plus)
Greg Clayton57ee3062013-07-11 22:46:58 +00006386 clang_type.StartTagDeclarationDefinition ();
Greg Clayton219cf312012-03-30 00:51:13 +00006387
Sean Callanan12014a02011-12-08 23:45:45 +00006388 // Leave this as a forward declaration until we need
6389 // to know the details of the type. lldb_private::Type
6390 // will automatically call the SymbolFile virtual function
6391 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
6392 // When the definition needs to be defined.
Greg Clayton57ee3062013-07-11 22:46:58 +00006393 m_forward_decl_die_to_clang_type[die] = clang_type.GetOpaqueQualType();
6394 m_forward_decl_clang_type_to_die[clang_type.RemoveFastQualifiers().GetOpaqueQualType()] = die;
6395 clang_type.SetHasExternalStorage (true);
Sean Callanan12014a02011-12-08 23:45:45 +00006396 }
Greg Claytonc615ce42010-11-09 04:42:43 +00006397 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006398
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006399 }
6400 break;
6401
6402 case DW_TAG_enumeration_type:
6403 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006404 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006405 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006406
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006407 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006408
Greg Claytond88d7592010-09-15 08:33:30 +00006409 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006410 if (num_attributes > 0)
6411 {
6412 uint32_t i;
6413
6414 for (i=0; i<num_attributes; ++i)
6415 {
6416 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006417 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6418 {
6419 switch (attr)
6420 {
Greg Clayton7a345282010-11-09 23:46:37 +00006421 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6422 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6423 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006424 case DW_AT_name:
6425 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006426 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006427 break;
Greg Clayton54166af2014-11-22 01:58:59 +00006428 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006429 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
6430 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006431 case DW_AT_declaration: break; //is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006432 case DW_AT_allocated:
6433 case DW_AT_associated:
6434 case DW_AT_bit_stride:
6435 case DW_AT_byte_stride:
6436 case DW_AT_data_location:
6437 case DW_AT_description:
6438 case DW_AT_start_scope:
6439 case DW_AT_visibility:
6440 case DW_AT_specification:
6441 case DW_AT_abstract_origin:
6442 case DW_AT_sibling:
6443 break;
6444 }
6445 }
6446 }
6447
Daniel Malead01b2952012-11-29 21:49:15 +00006448 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 +00006449
Greg Clayton57ee3062013-07-11 22:46:58 +00006450 ClangASTType enumerator_clang_type;
6451 clang_type.SetClangType (ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die));
6452 if (!clang_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00006453 {
Greg Clayton5d14fc02013-03-06 06:23:54 +00006454 if (encoding_uid != DW_INVALID_OFFSET)
6455 {
6456 Type *enumerator_type = ResolveTypeUID(encoding_uid);
6457 if (enumerator_type)
6458 enumerator_clang_type = enumerator_type->GetClangFullType();
6459 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006460
Greg Clayton57ee3062013-07-11 22:46:58 +00006461 if (!enumerator_clang_type)
Greg Clayton5d14fc02013-03-06 06:23:54 +00006462 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
6463 DW_ATE_signed,
6464 byte_size * 8);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006465
Greg Claytonca512b32011-01-14 04:54:56 +00006466 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00006467 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00006468 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006469 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00006470 }
6471 else
6472 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006473 enumerator_clang_type = clang_type.GetEnumerationIntegerType ();
Greg Clayton1be10fc2010-09-29 01:12:09 +00006474 }
6475
Greg Clayton57ee3062013-07-11 22:46:58 +00006476 LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006477
Greg Clayton81c22f62011-10-19 18:09:39 +00006478 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006479 this,
6480 type_name_const_str,
6481 byte_size,
6482 NULL,
6483 encoding_uid,
6484 Type::eEncodingIsUID,
6485 &decl,
6486 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006487 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006488
Greg Clayton57ee3062013-07-11 22:46:58 +00006489 clang_type.StartTagDeclarationDefinition ();
Greg Clayton6beaaa62011-01-17 03:46:26 +00006490 if (die->HasChildren())
6491 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006492 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00006493 bool is_signed = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00006494 enumerator_clang_type.IsIntegerType(is_signed);
Greg Clayton3e067532013-03-05 23:54:39 +00006495 ParseChildEnumerators(cu_sc, clang_type, is_signed, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00006496 }
Greg Clayton57ee3062013-07-11 22:46:58 +00006497 clang_type.CompleteTagDeclarationDefinition ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006498 }
6499 }
6500 break;
6501
Jim Inghamb0be4422010-08-12 01:20:14 +00006502 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006503 case DW_TAG_subprogram:
6504 case DW_TAG_subroutine_type:
6505 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006506 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006507 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006508
Greg Clayton23f59502012-07-17 03:23:13 +00006509 //const char *mangled = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006510 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00006511 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006512 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00006513 bool is_static = false;
6514 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00006515 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00006516 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00006517 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
6518 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Jim Ingham379397632012-10-27 02:54:13 +00006519 dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00006520
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006521 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00006522 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006523
6524
Greg Claytond88d7592010-09-15 08:33:30 +00006525 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006526 if (num_attributes > 0)
6527 {
6528 uint32_t i;
6529 for (i=0; i<num_attributes; ++i)
6530 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006531 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006532 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6533 {
6534 switch (attr)
6535 {
6536 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6537 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6538 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6539 case DW_AT_name:
6540 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006541 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006542 break;
6543
Greg Clayton71415542012-12-08 00:24:40 +00006544 case DW_AT_linkage_name:
Greg Clayton23f59502012-07-17 03:23:13 +00006545 case DW_AT_MIPS_linkage_name: break; // mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00006546 case DW_AT_type: type_die_offset = form_value.Reference(); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00006547 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006548 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
6549 case DW_AT_inline: is_inline = form_value.Boolean(); break;
6550 case DW_AT_virtuality: is_virtual = form_value.Boolean(); break;
6551 case DW_AT_explicit: is_explicit = form_value.Boolean(); break;
6552 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006553
Greg Claytonf51de672010-10-01 02:31:07 +00006554
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006555 case DW_AT_external:
6556 if (form_value.Unsigned())
6557 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00006558 if (storage == clang::SC_None)
6559 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006560 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00006561 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006562 }
6563 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006564
Greg Clayton72da3972011-08-16 18:40:23 +00006565 case DW_AT_specification:
Greg Clayton54166af2014-11-22 01:58:59 +00006566 specification_die_offset = form_value.Reference();
Greg Clayton72da3972011-08-16 18:40:23 +00006567 break;
6568
6569 case DW_AT_abstract_origin:
Greg Clayton54166af2014-11-22 01:58:59 +00006570 abstract_origin_die_offset = form_value.Reference();
Greg Clayton72da3972011-08-16 18:40:23 +00006571 break;
6572
Jim Ingham379397632012-10-27 02:54:13 +00006573 case DW_AT_object_pointer:
Greg Clayton54166af2014-11-22 01:58:59 +00006574 object_pointer_die_offset = form_value.Reference();
Jim Ingham379397632012-10-27 02:54:13 +00006575 break;
6576
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006577 case DW_AT_allocated:
6578 case DW_AT_associated:
6579 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006580 case DW_AT_calling_convention:
6581 case DW_AT_data_location:
6582 case DW_AT_elemental:
6583 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006584 case DW_AT_frame_base:
6585 case DW_AT_high_pc:
6586 case DW_AT_low_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006587 case DW_AT_prototyped:
6588 case DW_AT_pure:
6589 case DW_AT_ranges:
6590 case DW_AT_recursive:
6591 case DW_AT_return_addr:
6592 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006593 case DW_AT_start_scope:
6594 case DW_AT_static_link:
6595 case DW_AT_trampoline:
6596 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006597 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006598 case DW_AT_description:
6599 case DW_AT_sibling:
6600 break;
6601 }
6602 }
6603 }
Greg Clayton24739922010-10-13 03:15:28 +00006604 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006605
Jim Ingham379397632012-10-27 02:54:13 +00006606 std::string object_pointer_name;
6607 if (object_pointer_die_offset != DW_INVALID_OFFSET)
6608 {
6609 // Get the name from the object pointer die
6610 StreamString s;
6611 if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s))
6612 {
6613 object_pointer_name.assign(s.GetData());
6614 }
6615 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006616
Daniel Malead01b2952012-11-29 21:49:15 +00006617 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 +00006618
Greg Clayton57ee3062013-07-11 22:46:58 +00006619 ClangASTType return_clang_type;
Greg Clayton24739922010-10-13 03:15:28 +00006620 Type *func_type = NULL;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006621
Greg Clayton24739922010-10-13 03:15:28 +00006622 if (type_die_offset != DW_INVALID_OFFSET)
6623 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00006624
Greg Clayton24739922010-10-13 03:15:28 +00006625 if (func_type)
Greg Clayton42ce2f32011-12-12 21:50:19 +00006626 return_clang_type = func_type->GetClangForwardType();
Greg Clayton24739922010-10-13 03:15:28 +00006627 else
Greg Clayton57ee3062013-07-11 22:46:58 +00006628 return_clang_type = ast.GetBasicType(eBasicTypeVoid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006629
Greg Claytonf51de672010-10-01 02:31:07 +00006630
Greg Clayton57ee3062013-07-11 22:46:58 +00006631 std::vector<ClangASTType> function_param_types;
Greg Clayton24739922010-10-13 03:15:28 +00006632 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006633
Greg Clayton24739922010-10-13 03:15:28 +00006634 // Parse the function children for the parameters
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006635
Greg Claytoncb5860a2011-10-13 23:49:28 +00006636 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
6637 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00006638 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
6639
Greg Claytonf0705c82011-10-22 03:33:13 +00006640 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00006641 // Start off static. This will be set to false in ParseChildParameters(...)
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00006642 // if we find a "this" parameters as the first parameter
Greg Clayton5113dc82011-08-12 06:47:54 +00006643 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00006644 is_static = true;
Greg Claytond20deac2014-04-04 18:15:18 +00006645
Greg Clayton24739922010-10-13 03:15:28 +00006646 if (die->HasChildren())
6647 {
Greg Clayton0fffff52010-09-24 05:15:53 +00006648 bool skip_artificial = true;
Jim Ingham379397632012-10-27 02:54:13 +00006649 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00006650 containing_decl_ctx,
Jim Ingham379397632012-10-27 02:54:13 +00006651 dwarf_cu,
6652 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00006653 skip_artificial,
6654 is_static,
Greg Clayton03969752014-02-24 18:53:11 +00006655 is_variadic,
Jim Ingham379397632012-10-27 02:54:13 +00006656 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00006657 function_param_decls,
Greg Claytond20deac2014-04-04 18:15:18 +00006658 type_quals);
Greg Clayton24739922010-10-13 03:15:28 +00006659 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006660
Greg Clayton24739922010-10-13 03:15:28 +00006661 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006662 clang_type = ast.CreateFunctionType (return_clang_type,
Greg Clayton9cb25c42012-10-30 17:02:18 +00006663 function_param_types.data(),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006664 function_param_types.size(),
6665 is_variadic,
6666 type_quals);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006667
Sean Callanande9ce872013-05-09 23:13:13 +00006668 bool ignore_containing_context = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006669
Greg Clayton24739922010-10-13 03:15:28 +00006670 if (type_name_cstr)
6671 {
6672 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00006673 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006674 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00006675 ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true);
6676 if (objc_method.IsValid(true))
Greg Clayton0fffff52010-09-24 05:15:53 +00006677 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006678 ClangASTType class_opaque_type;
Greg Clayton1b3815c2013-01-30 00:18:29 +00006679 ConstString class_name(objc_method.GetClassName());
Greg Clayton7c810422012-01-18 23:40:49 +00006680 if (class_name)
Greg Clayton0fffff52010-09-24 05:15:53 +00006681 {
Greg Clayton278a16b2012-01-19 00:52:59 +00006682 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
Greg Claytonc7f03b62012-01-12 04:33:28 +00006683
6684 if (complete_objc_class_type_sp)
Greg Clayton0fffff52010-09-24 05:15:53 +00006685 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006686 ClangASTType type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
6687 if (type_clang_forward_type.IsObjCObjectOrInterfaceType ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00006688 class_opaque_type = type_clang_forward_type;
Greg Clayton0fffff52010-09-24 05:15:53 +00006689 }
Greg Clayton24739922010-10-13 03:15:28 +00006690 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006691
Greg Clayton24739922010-10-13 03:15:28 +00006692 if (class_opaque_type)
6693 {
6694 // If accessibility isn't set to anything valid, assume public for
6695 // now...
6696 if (accessibility == eAccessNone)
6697 accessibility = eAccessPublic;
6698
Greg Clayton57ee3062013-07-11 22:46:58 +00006699 clang::ObjCMethodDecl *objc_method_decl = class_opaque_type.AddMethodToObjCObjectType (type_name_cstr,
6700 clang_type,
6701 accessibility,
6702 is_artificial);
Greg Clayton24739922010-10-13 03:15:28 +00006703 type_handled = objc_method_decl != NULL;
Sean Callanan464a5b52012-10-04 22:06:29 +00006704 if (type_handled)
6705 {
6706 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Claytond0029442013-03-27 01:48:02 +00006707 GetClangASTContext().SetMetadataAsUserID (objc_method_decl, MakeUserID(die->GetOffset()));
Sean Callanan464a5b52012-10-04 22:06:29 +00006708 }
Sean Callananc3a1d562013-02-06 23:21:59 +00006709 else
6710 {
Jason Molendac1a65832013-03-07 22:44:42 +00006711 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 +00006712 die->GetOffset(),
6713 tag,
6714 DW_TAG_value_to_name(tag));
6715 }
Greg Clayton24739922010-10-13 03:15:28 +00006716 }
6717 }
Greg Clayton5113dc82011-08-12 06:47:54 +00006718 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00006719 {
6720 // Look at the parent of this DIE and see if is is
6721 // a class or struct and see if this is actually a
6722 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00006723 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00006724 if (class_type)
6725 {
Greg Clayton4116e932012-05-15 02:33:01 +00006726 if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset()))
6727 {
6728 // We uniqued the parent class of this function to another class
6729 // so we now need to associate all dies under "decl_ctx_die" to
6730 // DIEs in the DIE for "class_type"...
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006731 SymbolFileDWARF *class_symfile = NULL;
Greg Clayton4116e932012-05-15 02:33:01 +00006732 DWARFCompileUnitSP class_type_cu_sp;
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006733 const DWARFDebugInfoEntry *class_type_die = NULL;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006734
Sean Callanan2367f8a2013-02-26 01:12:25 +00006735 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
6736 if (debug_map_symfile)
6737 {
6738 class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID()));
6739 class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6740 }
6741 else
6742 {
6743 class_symfile = this;
6744 class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6745 }
Greg Clayton4116e932012-05-15 02:33:01 +00006746 if (class_type_die)
6747 {
Greg Claytond20deac2014-04-04 18:15:18 +00006748 DWARFDIECollection failures;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006749
Sean Callanan2367f8a2013-02-26 01:12:25 +00006750 CopyUniqueClassMethodTypes (class_symfile,
6751 class_type,
6752 class_type_cu_sp.get(),
6753 class_type_die,
6754 dwarf_cu,
6755 decl_ctx_die,
6756 failures);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006757
Sean Callanan2367f8a2013-02-26 01:12:25 +00006758 // FIXME do something with these failures that's smarter than
6759 // just dropping them on the ground. Unfortunately classes don't
6760 // like having stuff added to them after their definitions are
6761 // complete...
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006762
Sean Callanan2367f8a2013-02-26 01:12:25 +00006763 type_ptr = m_die_to_type[die];
6764 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton4116e932012-05-15 02:33:01 +00006765 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006766 type_sp = type_ptr->shared_from_this();
6767 break;
Greg Clayton4116e932012-05-15 02:33:01 +00006768 }
6769 }
6770 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006771
Greg Clayton72da3972011-08-16 18:40:23 +00006772 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00006773 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006774 // We have a specification which we are going to base our function
6775 // prototype off of, so we need this type to be completed so that the
6776 // m_die_to_decl_ctx for the method in the specification has a valid
6777 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006778 class_type->GetClangForwardType();
Greg Clayton72da3972011-08-16 18:40:23 +00006779 // If we have a specification, then the function type should have been
6780 // made with the specification and not with this die.
6781 DWARFCompileUnitSP spec_cu_sp;
6782 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006783 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006784 if (spec_clang_decl_ctx)
6785 {
6786 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
6787 }
6788 else
Jim Inghamc1663042011-09-29 22:12:35 +00006789 {
Daniel Malead01b2952012-11-29 21:49:15 +00006790 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8x) has no decl\n",
Greg Claytone38a5ed2012-01-05 03:57:59 +00006791 MakeUserID(die->GetOffset()),
6792 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006793 }
Greg Clayton72da3972011-08-16 18:40:23 +00006794 type_handled = true;
6795 }
6796 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
6797 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006798 // We have a specification which we are going to base our function
6799 // prototype off of, so we need this type to be completed so that the
6800 // m_die_to_decl_ctx for the method in the abstract origin has a valid
6801 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006802 class_type->GetClangForwardType();
Greg Clayton5cf58b92011-10-05 22:22:08 +00006803
Greg Clayton72da3972011-08-16 18:40:23 +00006804 DWARFCompileUnitSP abs_cu_sp;
6805 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006806 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006807 if (abs_clang_decl_ctx)
6808 {
6809 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
6810 }
6811 else
Jim Inghamc1663042011-09-29 22:12:35 +00006812 {
Daniel Malead01b2952012-11-29 21:49:15 +00006813 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 +00006814 MakeUserID(die->GetOffset()),
6815 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006816 }
Greg Clayton72da3972011-08-16 18:40:23 +00006817 type_handled = true;
6818 }
6819 else
6820 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006821 ClangASTType class_opaque_type = class_type->GetClangForwardType();
6822 if (class_opaque_type.IsCXXClassType ())
Greg Clayton931180e2011-01-27 06:44:37 +00006823 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006824 if (class_opaque_type.IsBeingDefined ())
Greg Clayton72da3972011-08-16 18:40:23 +00006825 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006826 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
6827 // in the DWARF for C++ methods... Default to public for now...
6828 if (accessibility == eAccessNone)
6829 accessibility = eAccessPublic;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006830
Greg Clayton20568dd2011-10-13 23:13:20 +00006831 if (!is_static && !die->HasChildren())
6832 {
6833 // We have a C++ member function with no children (this pointer!)
6834 // and clang will get mad if we try and make a function that isn't
6835 // well formed in the DWARF, so we will just skip it...
6836 type_handled = true;
6837 }
6838 else
6839 {
6840 clang::CXXMethodDecl *cxx_method_decl;
6841 // REMOVE THE CRASH DESCRIPTION BELOW
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00006842 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 +00006843 type_name_cstr,
6844 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00006845 MakeUserID(die->GetOffset()),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00006846 m_obj_file->GetFileSpec().GetPath().c_str());
Greg Clayton20568dd2011-10-13 23:13:20 +00006847
Sean Callananc1b732d2011-11-01 18:07:13 +00006848 const bool is_attr_used = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006849
Greg Clayton57ee3062013-07-11 22:46:58 +00006850 cxx_method_decl = class_opaque_type.AddMethodToCXXRecordType (type_name_cstr,
6851 clang_type,
6852 accessibility,
6853 is_virtual,
6854 is_static,
6855 is_inline,
6856 is_explicit,
6857 is_attr_used,
6858 is_artificial);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006859
Greg Clayton20568dd2011-10-13 23:13:20 +00006860 type_handled = cxx_method_decl != NULL;
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006861
6862 if (type_handled)
Jim Ingham379397632012-10-27 02:54:13 +00006863 {
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006864 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
6865
6866 Host::SetCrashDescription (NULL);
6867
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006868
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006869 ClangASTMetadata metadata;
6870 metadata.SetUserID(MakeUserID(die->GetOffset()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006871
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006872 if (!object_pointer_name.empty())
6873 {
6874 metadata.SetObjectPtrName(object_pointer_name.c_str());
6875 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006876 log->Printf ("Setting object pointer name: %s on method object %p.\n",
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006877 object_pointer_name.c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006878 static_cast<void*>(cxx_method_decl));
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006879 }
Greg Claytond0029442013-03-27 01:48:02 +00006880 GetClangASTContext().SetMetadata (cxx_method_decl, metadata);
Jim Ingham379397632012-10-27 02:54:13 +00006881 }
Sean Callananb0640dc2013-04-09 23:22:08 +00006882 else
6883 {
Sean Callanande9ce872013-05-09 23:13:13 +00006884 ignore_containing_context = true;
Sean Callananb0640dc2013-04-09 23:22:08 +00006885 }
Greg Clayton20568dd2011-10-13 23:13:20 +00006886 }
Greg Clayton72da3972011-08-16 18:40:23 +00006887 }
6888 else
6889 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006890 // We were asked to parse the type for a method in a class, yet the
6891 // class hasn't been asked to complete itself through the
6892 // clang::ExternalASTSource protocol, so we need to just have the
6893 // class complete itself and do things the right way, then our
6894 // DIE should then have an entry in the m_die_to_type map. First
6895 // we need to modify the m_die_to_type so it doesn't think we are
6896 // trying to parse this DIE anymore...
6897 m_die_to_type[die] = NULL;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006898
Greg Clayton20568dd2011-10-13 23:13:20 +00006899 // Now we get the full type to force our class type to complete itself
6900 // using the clang::ExternalASTSource protocol which will parse all
6901 // base classes and all methods (including the method for this DIE).
6902 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00006903
Greg Clayton20568dd2011-10-13 23:13:20 +00006904 // The type for this DIE should have been filled in the function call above
6905 type_ptr = m_die_to_type[die];
Greg Claytone5476db2012-06-01 20:32:35 +00006906 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton20568dd2011-10-13 23:13:20 +00006907 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006908 type_sp = type_ptr->shared_from_this();
Greg Clayton20568dd2011-10-13 23:13:20 +00006909 break;
6910 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006911
Sean Callanan02eee4d2012-04-12 23:10:00 +00006912 // FIXME This is fixing some even uglier behavior but we really need to
6913 // uniq the methods of each class as well as the class itself.
6914 // <rdar://problem/11240464>
6915 type_handled = true;
Greg Clayton72da3972011-08-16 18:40:23 +00006916 }
Greg Clayton931180e2011-01-27 06:44:37 +00006917 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006918 }
6919 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006920 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006921 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006922
Greg Clayton24739922010-10-13 03:15:28 +00006923 if (!type_handled)
6924 {
6925 // We just have a function that isn't part of a class
Sean Callanande9ce872013-05-09 23:13:13 +00006926 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (ignore_containing_context ? GetClangASTContext().GetTranslationUnitDecl() : containing_decl_ctx,
Greg Clayton147e1fa2011-10-14 22:47:18 +00006927 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006928 clang_type,
6929 storage,
6930 is_inline);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006931
6932// if (template_param_infos.GetSize() > 0)
6933// {
6934// clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
6935// function_decl,
6936// type_name_cstr,
6937// template_param_infos);
6938//
6939// ast.CreateFunctionTemplateSpecializationInfo (function_decl,
6940// func_template_decl,
6941// template_param_infos);
6942// }
Greg Clayton24739922010-10-13 03:15:28 +00006943 // Add the decl to our DIE to decl context map
6944 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00006945 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00006946 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006947 ast.SetFunctionParameters (function_decl,
6948 &function_param_decls.front(),
6949 function_param_decls.size());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006950
Jim Ingham379397632012-10-27 02:54:13 +00006951 ClangASTMetadata metadata;
6952 metadata.SetUserID(MakeUserID(die->GetOffset()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006953
Jim Ingham379397632012-10-27 02:54:13 +00006954 if (!object_pointer_name.empty())
6955 {
6956 metadata.SetObjectPtrName(object_pointer_name.c_str());
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006957 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006958 log->Printf ("Setting object pointer name: %s on function object %p.",
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006959 object_pointer_name.c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006960 static_cast<void*>(function_decl));
Jim Ingham379397632012-10-27 02:54:13 +00006961 }
Greg Claytond0029442013-03-27 01:48:02 +00006962 GetClangASTContext().SetMetadata (function_decl, metadata);
Greg Clayton24739922010-10-13 03:15:28 +00006963 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006964 }
Greg Clayton81c22f62011-10-19 18:09:39 +00006965 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006966 this,
6967 type_name_const_str,
6968 0,
6969 NULL,
6970 LLDB_INVALID_UID,
6971 Type::eEncodingIsUID,
6972 &decl,
6973 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006974 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00006975 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006976 }
6977 break;
6978
6979 case DW_TAG_array_type:
6980 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006981 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006982 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006983
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006984 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006985 int64_t first_index = 0;
6986 uint32_t byte_stride = 0;
6987 uint32_t bit_stride = 0;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006988 bool is_vector = false;
Greg Claytond88d7592010-09-15 08:33:30 +00006989 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006990
6991 if (num_attributes > 0)
6992 {
6993 uint32_t i;
6994 for (i=0; i<num_attributes; ++i)
6995 {
6996 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006997 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6998 {
6999 switch (attr)
7000 {
7001 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
7002 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
7003 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
7004 case DW_AT_name:
7005 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00007006 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007007 break;
7008
Greg Clayton54166af2014-11-22 01:58:59 +00007009 case DW_AT_type: type_die_offset = form_value.Reference(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00007010 case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007011 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
7012 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00007013 case DW_AT_GNU_vector: is_vector = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00007014 case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00007015 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007016 case DW_AT_allocated:
7017 case DW_AT_associated:
7018 case DW_AT_data_location:
7019 case DW_AT_description:
7020 case DW_AT_ordering:
7021 case DW_AT_start_scope:
7022 case DW_AT_visibility:
7023 case DW_AT_specification:
7024 case DW_AT_abstract_origin:
7025 case DW_AT_sibling:
7026 break;
7027 }
7028 }
7029 }
7030
Daniel Malead01b2952012-11-29 21:49:15 +00007031 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 +00007032
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007033 Type *element_type = ResolveTypeUID(type_die_offset);
7034
7035 if (element_type)
7036 {
7037 std::vector<uint64_t> element_orders;
7038 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
7039 if (byte_stride == 0 && bit_stride == 0)
7040 byte_stride = element_type->GetByteSize();
Greg Clayton57ee3062013-07-11 22:46:58 +00007041 ClangASTType array_element_type = element_type->GetClangForwardType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007042 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
Siva Chandra89ce9552015-01-05 23:06:14 +00007043 if (element_orders.size() > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007044 {
Siva Chandra89ce9552015-01-05 23:06:14 +00007045 uint64_t num_elements = 0;
7046 std::vector<uint64_t>::const_reverse_iterator pos;
7047 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
7048 for (pos = element_orders.rbegin(); pos != end; ++pos)
7049 {
7050 num_elements = *pos;
7051 clang_type = ast.CreateArrayType (array_element_type,
7052 num_elements,
7053 is_vector);
7054 array_element_type = clang_type;
7055 array_element_bit_stride = num_elements ?
7056 array_element_bit_stride * num_elements :
7057 array_element_bit_stride;
7058 }
7059 }
7060 else
7061 {
7062 clang_type = ast.CreateArrayType (array_element_type, 0, is_vector);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007063 }
7064 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00007065 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00007066 this,
7067 empty_name,
7068 array_element_bit_stride / 8,
7069 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00007070 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00007071 Type::eEncodingIsUID,
7072 &decl,
7073 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00007074 Type::eResolveStateFull));
7075 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007076 }
7077 }
7078 }
7079 break;
7080
Greg Clayton9b81a312010-06-12 01:20:30 +00007081 case DW_TAG_ptr_to_member_type:
7082 {
7083 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
7084 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
7085
Greg Claytond88d7592010-09-15 08:33:30 +00007086 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007087
Greg Clayton9b81a312010-06-12 01:20:30 +00007088 if (num_attributes > 0) {
7089 uint32_t i;
7090 for (i=0; i<num_attributes; ++i)
7091 {
7092 attr = attributes.AttributeAtIndex(i);
Greg Clayton9b81a312010-06-12 01:20:30 +00007093 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
7094 {
7095 switch (attr)
7096 {
7097 case DW_AT_type:
Greg Clayton54166af2014-11-22 01:58:59 +00007098 type_die_offset = form_value.Reference(); break;
Greg Clayton9b81a312010-06-12 01:20:30 +00007099 case DW_AT_containing_type:
Greg Clayton54166af2014-11-22 01:58:59 +00007100 containing_type_die_offset = form_value.Reference(); break;
Greg Clayton9b81a312010-06-12 01:20:30 +00007101 }
7102 }
7103 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007104
Greg Clayton9b81a312010-06-12 01:20:30 +00007105 Type *pointee_type = ResolveTypeUID(type_die_offset);
7106 Type *class_type = ResolveTypeUID(containing_type_die_offset);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007107
Greg Clayton57ee3062013-07-11 22:46:58 +00007108 ClangASTType pointee_clang_type = pointee_type->GetClangForwardType();
7109 ClangASTType class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00007110
Greg Clayton57ee3062013-07-11 22:46:58 +00007111 clang_type = pointee_clang_type.CreateMemberPointerType(class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00007112
Enrico Granata1cd5e922015-01-28 00:07:51 +00007113 byte_size = clang_type.GetByteSize(nullptr);
Greg Clayton9b81a312010-06-12 01:20:30 +00007114
Greg Clayton81c22f62011-10-19 18:09:39 +00007115 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00007116 this,
7117 type_name_const_str,
7118 byte_size,
7119 NULL,
7120 LLDB_INVALID_UID,
7121 Type::eEncodingIsUID,
7122 NULL,
7123 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00007124 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00007125 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007126
Greg Clayton9b81a312010-06-12 01:20:30 +00007127 break;
7128 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007129 default:
Greg Clayton84afacd2012-11-07 23:09:32 +00007130 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",
7131 die->GetOffset(),
7132 tag,
7133 DW_TAG_value_to_name(tag));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007134 break;
7135 }
7136
7137 if (type_sp.get())
7138 {
7139 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7140 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7141
7142 SymbolContextScope * symbol_context_scope = NULL;
7143 if (sc_parent_tag == DW_TAG_compile_unit)
7144 {
7145 symbol_context_scope = sc.comp_unit;
7146 }
Jason Molenda60db6e42014-10-16 01:40:16 +00007147 else if (sc.function != NULL && sc_parent_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007148 {
Greg Clayton81c22f62011-10-19 18:09:39 +00007149 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007150 if (symbol_context_scope == NULL)
7151 symbol_context_scope = sc.function;
7152 }
7153
7154 if (symbol_context_scope != NULL)
7155 {
7156 type_sp->SetSymbolContextScope(symbol_context_scope);
7157 }
7158
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00007159 // We are ready to put this type into the uniqued list up at the module level
7160 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00007161
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00007162 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007163 }
7164 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00007165 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007166 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00007167 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007168 }
7169 }
7170 return type_sp;
7171}
7172
7173size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00007174SymbolFileDWARF::ParseTypes
7175(
7176 const SymbolContext& sc,
7177 DWARFCompileUnit* dwarf_cu,
7178 const DWARFDebugInfoEntry *die,
7179 bool parse_siblings,
7180 bool parse_children
7181)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007182{
7183 size_t types_added = 0;
7184 while (die != NULL)
7185 {
7186 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00007187 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007188 {
7189 if (type_is_new)
7190 ++types_added;
7191 }
7192
7193 if (parse_children && die->HasChildren())
7194 {
7195 if (die->Tag() == DW_TAG_subprogram)
7196 {
7197 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00007198 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007199 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
7200 }
7201 else
7202 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
7203 }
7204
7205 if (parse_siblings)
7206 die = die->GetSibling();
7207 else
7208 die = NULL;
7209 }
7210 return types_added;
7211}
7212
7213
7214size_t
7215SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
7216{
7217 assert(sc.comp_unit && sc.function);
7218 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00007219 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007220 if (dwarf_cu)
7221 {
7222 dw_offset_t function_die_offset = sc.function->GetID();
7223 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
7224 if (function_die)
7225 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00007226 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007227 }
7228 }
7229
7230 return functions_added;
7231}
7232
7233
7234size_t
7235SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
7236{
7237 // At least a compile unit must be valid
7238 assert(sc.comp_unit);
7239 size_t types_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00007240 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007241 if (dwarf_cu)
7242 {
7243 if (sc.function)
7244 {
7245 dw_offset_t function_die_offset = sc.function->GetID();
7246 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
7247 if (func_die && func_die->HasChildren())
7248 {
7249 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
7250 }
7251 }
7252 else
7253 {
7254 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
7255 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
7256 {
7257 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
7258 }
7259 }
7260 }
7261
7262 return types_added;
7263}
7264
7265size_t
7266SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
7267{
7268 if (sc.comp_unit != NULL)
7269 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00007270 DWARFDebugInfo* info = DebugInfo();
7271 if (info == NULL)
7272 return 0;
7273
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007274 if (sc.function)
7275 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007276 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get();
7277
7278 if (dwarf_cu == NULL)
7279 return 0;
7280
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007281 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00007282
Greg Claytonc7bece562013-01-25 18:06:21 +00007283 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
7284 if (func_lo_pc != LLDB_INVALID_ADDRESS)
Greg Claytone38a5ed2012-01-05 03:57:59 +00007285 {
7286 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00007287
Greg Claytone38a5ed2012-01-05 03:57:59 +00007288 // Let all blocks know they have parse all their variables
7289 sc.function->GetBlock (false).SetDidParseVariables (true, true);
7290 return num_variables;
7291 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007292 }
7293 else if (sc.comp_unit)
7294 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007295 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get();
7296
7297 if (dwarf_cu == NULL)
7298 return 0;
7299
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007300 uint32_t vars_added = 0;
7301 VariableListSP variables (sc.comp_unit->GetVariableList(false));
7302
7303 if (variables.get() == NULL)
7304 {
7305 variables.reset(new VariableList());
7306 sc.comp_unit->SetVariableList(variables);
7307
Greg Claytond4a2b372011-09-12 23:21:58 +00007308 DWARFCompileUnit* match_dwarf_cu = NULL;
7309 const DWARFDebugInfoEntry* die = NULL;
7310 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00007311 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00007312 {
Greg Clayton97fbc342011-10-20 22:30:33 +00007313 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00007314 {
7315 DWARFMappedHash::DIEInfoArray hash_data_array;
7316 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
7317 dwarf_cu->GetNextCompileUnitOffset(),
7318 hash_data_array))
7319 {
7320 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
7321 }
7322 }
Greg Clayton7f995132011-10-04 22:41:51 +00007323 }
7324 else
7325 {
7326 // Index if we already haven't to make sure the compile units
7327 // get indexed and make their global DIE index list
7328 if (!m_indexed)
7329 Index ();
7330
7331 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
7332 dwarf_cu->GetNextCompileUnitOffset(),
7333 die_offsets);
7334 }
7335
7336 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00007337 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007338 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007339 DWARFDebugInfo* debug_info = DebugInfo();
7340 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007341 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007342 const dw_offset_t die_offset = die_offsets[i];
7343 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00007344 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00007345 {
Greg Clayton95d87902011-11-11 03:16:25 +00007346 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
7347 if (var_sp)
7348 {
7349 variables->AddVariableIfUnique (var_sp);
7350 ++vars_added;
7351 }
Greg Claytond4a2b372011-09-12 23:21:58 +00007352 }
Greg Clayton95d87902011-11-11 03:16:25 +00007353 else
7354 {
7355 if (m_using_apple_tables)
7356 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00007357 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 +00007358 }
7359 }
7360
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007361 }
7362 }
7363 }
7364 return vars_added;
7365 }
7366 }
7367 return 0;
7368}
7369
7370
7371VariableSP
7372SymbolFileDWARF::ParseVariableDIE
7373(
7374 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007375 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007376 const DWARFDebugInfoEntry *die,
7377 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007378)
7379{
Greg Clayton83c5cd92010-11-14 22:13:40 +00007380 VariableSP var_sp (m_die_to_variable_sp[die]);
7381 if (var_sp)
7382 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007383
7384 const dw_tag_t tag = die->Tag();
Richard Mitton0a558352013-10-17 21:14:00 +00007385 ModuleSP module = GetObjectFile()->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00007386
7387 if ((tag == DW_TAG_variable) ||
7388 (tag == DW_TAG_constant) ||
7389 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007390 {
Greg Clayton7f995132011-10-04 22:41:51 +00007391 DWARFDebugInfoEntry::Attributes attributes;
7392 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
7393 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007394 {
Greg Clayton7f995132011-10-04 22:41:51 +00007395 const char *name = NULL;
7396 const char *mangled = NULL;
7397 Declaration decl;
7398 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00007399 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00007400 DWARFExpression location;
7401 bool is_external = false;
7402 bool is_artificial = false;
7403 bool location_is_const_value_data = false;
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007404 bool has_explicit_location = false;
Enrico Granata4ec130d2014-08-11 19:16:35 +00007405 DWARFFormValue const_value;
Greg Clayton23f59502012-07-17 03:23:13 +00007406 //AccessType accessibility = eAccessNone;
Greg Clayton7f995132011-10-04 22:41:51 +00007407
7408 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007409 {
Greg Clayton7f995132011-10-04 22:41:51 +00007410 dw_attr_t attr = attributes.AttributeAtIndex(i);
7411 DWARFFormValue form_value;
Greg Clayton54166af2014-11-22 01:58:59 +00007412
Greg Clayton7f995132011-10-04 22:41:51 +00007413 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007414 {
Greg Clayton7f995132011-10-04 22:41:51 +00007415 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007416 {
Greg Clayton7f995132011-10-04 22:41:51 +00007417 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
7418 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
7419 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
7420 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton71415542012-12-08 00:24:40 +00007421 case DW_AT_linkage_name:
Greg Clayton7f995132011-10-04 22:41:51 +00007422 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00007423 case DW_AT_type: type_uid = form_value.Reference(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00007424 case DW_AT_external: is_external = form_value.Boolean(); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007425 case DW_AT_const_value:
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007426 // If we have already found a DW_AT_location attribute, ignore this attribute.
7427 if (!has_explicit_location)
7428 {
7429 location_is_const_value_data = true;
7430 // The constant value will be either a block, a data value or a string.
Ed Masteeeae7212013-10-24 20:43:47 +00007431 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007432 if (DWARFFormValue::IsBlockForm(form_value.Form()))
7433 {
7434 // Retrieve the value as a block expression.
7435 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7436 uint32_t block_length = form_value.Unsigned();
Richard Mitton0a558352013-10-17 21:14:00 +00007437 location.CopyOpcodeData(module, debug_info_data, block_offset, block_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007438 }
7439 else if (DWARFFormValue::IsDataForm(form_value.Form()))
7440 {
7441 // Retrieve the value as a data expression.
Greg Clayton54166af2014-11-22 01:58:59 +00007442 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (attributes.CompileUnitAtIndex(i)->GetAddressByteSize(), attributes.CompileUnitAtIndex(i)->IsDWARF64());
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007443 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7444 uint32_t data_length = fixed_form_sizes[form_value.Form()];
Enrico Granata4ec130d2014-08-11 19:16:35 +00007445 if (data_length == 0)
7446 {
7447 const uint8_t *data_pointer = form_value.BlockData();
7448 if (data_pointer)
7449 {
Jason Molenda18f5fd32014-10-16 07:52:17 +00007450 form_value.Unsigned();
Enrico Granata4ec130d2014-08-11 19:16:35 +00007451 }
7452 else if (DWARFFormValue::IsDataForm(form_value.Form()))
7453 {
7454 // we need to get the byte size of the type later after we create the variable
7455 const_value = form_value;
7456 }
7457 }
7458 else
7459 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007460 }
7461 else
7462 {
7463 // Retrieve the value as a string expression.
7464 if (form_value.Form() == DW_FORM_strp)
7465 {
Greg Clayton54166af2014-11-22 01:58:59 +00007466 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (attributes.CompileUnitAtIndex(i)->GetAddressByteSize(), attributes.CompileUnitAtIndex(i)->IsDWARF64());
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007467 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7468 uint32_t data_length = fixed_form_sizes[form_value.Form()];
Richard Mitton0a558352013-10-17 21:14:00 +00007469 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007470 }
7471 else
7472 {
7473 const char *str = form_value.AsCString(&debug_info_data);
7474 uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart();
7475 uint32_t string_length = strlen(str) + 1;
Richard Mitton0a558352013-10-17 21:14:00 +00007476 location.CopyOpcodeData(module, debug_info_data, string_offset, string_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007477 }
7478 }
7479 }
7480 break;
Greg Clayton7f995132011-10-04 22:41:51 +00007481 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007482 {
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007483 location_is_const_value_data = false;
7484 has_explicit_location = true;
Greg Clayton7f995132011-10-04 22:41:51 +00007485 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007486 {
Ed Masteeeae7212013-10-24 20:43:47 +00007487 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Clayton7f995132011-10-04 22:41:51 +00007488
7489 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7490 uint32_t block_length = form_value.Unsigned();
Richard Mitton0a558352013-10-17 21:14:00 +00007491 location.CopyOpcodeData(module, get_debug_info_data(), block_offset, block_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007492 }
7493 else
7494 {
Ed Masteeeae7212013-10-24 20:43:47 +00007495 const DWARFDataExtractor& debug_loc_data = get_debug_loc_data();
Greg Clayton7f995132011-10-04 22:41:51 +00007496 const dw_offset_t debug_loc_offset = form_value.Unsigned();
7497
7498 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
7499 if (loc_list_length > 0)
7500 {
Richard Mitton0a558352013-10-17 21:14:00 +00007501 location.CopyOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007502 assert (func_low_pc != LLDB_INVALID_ADDRESS);
Greg Clayton54166af2014-11-22 01:58:59 +00007503 location.SetLocationListSlide (func_low_pc - attributes.CompileUnitAtIndex(i)->GetBaseAddress());
Greg Clayton7f995132011-10-04 22:41:51 +00007504 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007505 }
7506 }
Greg Clayton7f995132011-10-04 22:41:51 +00007507 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007508
Greg Clayton1c8ef472013-04-05 23:27:21 +00007509 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00007510 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007511 case DW_AT_declaration:
7512 case DW_AT_description:
7513 case DW_AT_endianity:
7514 case DW_AT_segment:
7515 case DW_AT_start_scope:
7516 case DW_AT_visibility:
7517 default:
7518 case DW_AT_abstract_origin:
7519 case DW_AT_sibling:
7520 case DW_AT_specification:
7521 break;
7522 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007523 }
7524 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007525
Greg Clayton9e9f2192013-05-17 00:55:28 +00007526 ValueType scope = eValueTypeInvalid;
7527
7528 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7529 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7530 SymbolContextScope * symbol_context_scope = NULL;
7531
Siva Chandra0783ab92015-03-24 18:32:27 +00007532 if (!mangled)
7533 {
7534 // LLDB relies on the mangled name (DW_TAG_linkage_name or DW_AT_MIPS_linkage_name) to
7535 // generate fully qualified names of global variables with commands like "frame var j".
7536 // For example, if j were an int variable holding a value 4 and declared in a namespace
7537 // B which in turn is contained in a namespace A, the command "frame var j" returns
7538 // "(int) A::B::j = 4". If the compiler does not emit a linkage name, we should be able
7539 // to generate a fully qualified name from the declaration context.
7540 if (die->GetParent()->Tag() == DW_TAG_compile_unit &&
7541 LanguageRuntime::LanguageIsCPlusPlus(dwarf_cu->GetLanguageType()))
7542 {
7543 DWARFDeclContext decl_ctx;
7544
7545 die->GetDWARFDeclContext(this, dwarf_cu, decl_ctx);
7546 mangled = decl_ctx.GetQualifiedNameAsConstString().GetCString();
7547 }
7548 }
7549
Greg Clayton9e9f2192013-05-17 00:55:28 +00007550 // DWARF doesn't specify if a DW_TAG_variable is a local, global
7551 // or static variable, so we have to do a little digging by
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00007552 // looking at the location of a variable to see if it contains
Greg Clayton9e9f2192013-05-17 00:55:28 +00007553 // a DW_OP_addr opcode _somewhere_ in the definition. I say
7554 // somewhere because clang likes to combine small global variables
7555 // into the same symbol and have locations like:
7556 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
7557 // So if we don't have a DW_TAG_formal_parameter, we can look at
7558 // the location to see if it contains a DW_OP_addr opcode, and
7559 // then we can correctly classify our variables.
7560 if (tag == DW_TAG_formal_parameter)
7561 scope = eValueTypeVariableArgument;
7562 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007563 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007564 bool op_error = false;
7565 // Check if the location has a DW_OP_addr with any address value...
7566 lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS;
7567 if (!location_is_const_value_data)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007568 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007569 location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error);
7570 if (op_error)
Greg Clayton96c09682012-01-04 22:56:43 +00007571 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007572 StreamString strm;
7573 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
7574 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 +00007575 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007576 }
Greg Claytond1767f02011-12-08 02:13:16 +00007577
Greg Clayton9e9f2192013-05-17 00:55:28 +00007578 if (location_DW_OP_addr != LLDB_INVALID_ADDRESS)
7579 {
7580 if (is_external)
7581 scope = eValueTypeVariableGlobal;
7582 else
7583 scope = eValueTypeVariableStatic;
7584
7585
7586 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile ();
7587
7588 if (debug_map_symfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007589 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007590 // When leaving the DWARF in the .o files on darwin,
7591 // when we have a global variable that wasn't initialized,
7592 // the .o file might not have allocated a virtual
7593 // address for the global variable. In this case it will
7594 // have created a symbol for the global variable
7595 // that is undefined/data and external and the value will
7596 // be the byte size of the variable. When we do the
7597 // address map in SymbolFileDWARFDebugMap we rely on
7598 // having an address, we need to do some magic here
7599 // so we can get the correct address for our global
7600 // variable. The address for all of these entries
7601 // will be zero, and there will be an undefined symbol
7602 // in this object file, and the executable will have
7603 // a matching symbol with a good address. So here we
7604 // dig up the correct address and replace it in the
7605 // location for the variable, and set the variable's
7606 // symbol context scope to be that of the main executable
7607 // so the file address will resolve correctly.
7608 bool linked_oso_file_addr = false;
7609 if (is_external && location_DW_OP_addr == 0)
Greg Clayton9422dd62013-03-04 21:46:16 +00007610 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007611 // we have a possible uninitialized extern global
7612 ConstString const_name(mangled ? mangled : name);
7613 ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile();
7614 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007615 {
Greg Clayton3046e662013-07-10 01:23:25 +00007616 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
Greg Clayton9e9f2192013-05-17 00:55:28 +00007617 if (debug_map_symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007618 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007619 Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
7620 eSymbolTypeData,
7621 Symtab::eDebugYes,
7622 Symtab::eVisibilityExtern);
7623 if (exe_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007624 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007625 if (exe_symbol->ValueIsAddress())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007626 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007627 const addr_t exe_file_addr = exe_symbol->GetAddress().GetFileAddress();
7628 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007629 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007630 if (location.Update_DW_OP_addr (exe_file_addr))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007631 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007632 linked_oso_file_addr = true;
7633 symbol_context_scope = exe_symbol;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007634 }
7635 }
7636 }
7637 }
7638 }
7639 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007640 }
Greg Clayton9422dd62013-03-04 21:46:16 +00007641
Greg Clayton9e9f2192013-05-17 00:55:28 +00007642 if (!linked_oso_file_addr)
7643 {
7644 // The DW_OP_addr is not zero, but it contains a .o file address which
7645 // needs to be linked up correctly.
7646 const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr);
7647 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton9422dd62013-03-04 21:46:16 +00007648 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007649 // Update the file address for this variable
7650 location.Update_DW_OP_addr (exe_file_addr);
7651 }
7652 else
7653 {
7654 // Variable didn't make it into the final executable
7655 return var_sp;
Greg Clayton9422dd62013-03-04 21:46:16 +00007656 }
Greg Claytond1767f02011-12-08 02:13:16 +00007657 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007658 }
Greg Clayton5cf58b92011-10-05 22:22:08 +00007659 }
7660 else
7661 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007662 scope = eValueTypeVariableLocal;
Greg Clayton5cf58b92011-10-05 22:22:08 +00007663 }
Greg Clayton7f995132011-10-04 22:41:51 +00007664 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007665
7666 if (symbol_context_scope == NULL)
7667 {
7668 switch (parent_tag)
7669 {
7670 case DW_TAG_subprogram:
7671 case DW_TAG_inlined_subroutine:
7672 case DW_TAG_lexical_block:
7673 if (sc.function)
7674 {
7675 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
7676 if (symbol_context_scope == NULL)
7677 symbol_context_scope = sc.function;
7678 }
7679 break;
7680
7681 default:
7682 symbol_context_scope = sc.comp_unit;
7683 break;
7684 }
7685 }
7686
7687 if (symbol_context_scope)
7688 {
Enrico Granata4ec130d2014-08-11 19:16:35 +00007689 SymbolFileTypeSP type_sp(new SymbolFileType(*this, type_uid));
7690
7691 if (const_value.Form() && type_sp && type_sp->GetType())
7692 location.CopyOpcodeData(const_value.Unsigned(), type_sp->GetType()->GetByteSize(), dwarf_cu->GetAddressByteSize());
7693
Greg Clayton9e9f2192013-05-17 00:55:28 +00007694 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
7695 name,
7696 mangled,
Enrico Granata4ec130d2014-08-11 19:16:35 +00007697 type_sp,
Greg Clayton9e9f2192013-05-17 00:55:28 +00007698 scope,
7699 symbol_context_scope,
7700 &decl,
7701 location,
7702 is_external,
7703 is_artificial));
7704
7705 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
7706 }
7707 else
7708 {
7709 // Not ready to parse this variable yet. It might be a global
7710 // or static variable that is in a function scope and the function
7711 // in the symbol context wasn't filled in yet
7712 return var_sp;
7713 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007714 }
Greg Clayton7f995132011-10-04 22:41:51 +00007715 // Cache var_sp even if NULL (the variable was just a specification or
7716 // was missing vital information to be able to be displayed in the debugger
7717 // (missing location due to optimization, etc)) so we don't re-parse
7718 // this DIE over and over later...
7719 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007720 }
7721 return var_sp;
7722}
7723
Greg Claytonc662ec82011-06-17 22:10:16 +00007724
7725const DWARFDebugInfoEntry *
7726SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
7727 dw_offset_t spec_block_die_offset,
7728 DWARFCompileUnit **result_die_cu_handle)
7729{
7730 // Give the concrete function die specified by "func_die_offset", find the
7731 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7732 // to "spec_block_die_offset"
7733 DWARFDebugInfo* info = DebugInfo();
7734
7735 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
7736 if (die)
7737 {
7738 assert (*result_die_cu_handle);
7739 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
7740 }
7741 return NULL;
7742}
7743
7744
7745const DWARFDebugInfoEntry *
7746SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
7747 const DWARFDebugInfoEntry *die,
7748 dw_offset_t spec_block_die_offset,
7749 DWARFCompileUnit **result_die_cu_handle)
7750{
7751 if (die)
7752 {
7753 switch (die->Tag())
7754 {
7755 case DW_TAG_subprogram:
7756 case DW_TAG_inlined_subroutine:
7757 case DW_TAG_lexical_block:
7758 {
7759 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
7760 {
7761 *result_die_cu_handle = dwarf_cu;
7762 return die;
7763 }
7764
7765 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
7766 {
7767 *result_die_cu_handle = dwarf_cu;
7768 return die;
7769 }
7770 }
7771 break;
7772 }
7773
7774 // Give the concrete function die specified by "func_die_offset", find the
7775 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7776 // to "spec_block_die_offset"
7777 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
7778 {
7779 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
7780 child_die,
7781 spec_block_die_offset,
7782 result_die_cu_handle);
7783 if (result_die)
7784 return result_die;
7785 }
7786 }
7787
7788 *result_die_cu_handle = NULL;
7789 return NULL;
7790}
7791
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007792size_t
7793SymbolFileDWARF::ParseVariables
7794(
7795 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007796 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007797 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007798 const DWARFDebugInfoEntry *orig_die,
7799 bool parse_siblings,
7800 bool parse_children,
7801 VariableList* cc_variable_list
7802)
7803{
7804 if (orig_die == NULL)
7805 return 0;
7806
Greg Claytonc662ec82011-06-17 22:10:16 +00007807 VariableListSP variable_list_sp;
7808
7809 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007810 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00007811 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007812 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007813 dw_tag_t tag = die->Tag();
7814
7815 // Check to see if we have already parsed this variable or constant?
7816 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007817 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007818 if (cc_variable_list)
7819 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007820 }
7821 else
7822 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007823 // We haven't already parsed it, lets do that now.
7824 if ((tag == DW_TAG_variable) ||
7825 (tag == DW_TAG_constant) ||
7826 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007827 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007828 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00007829 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007830 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
7831 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7832 switch (parent_tag)
7833 {
7834 case DW_TAG_compile_unit:
7835 if (sc.comp_unit != NULL)
7836 {
7837 variable_list_sp = sc.comp_unit->GetVariableList(false);
7838 if (variable_list_sp.get() == NULL)
7839 {
7840 variable_list_sp.reset(new VariableList());
7841 sc.comp_unit->SetVariableList(variable_list_sp);
7842 }
7843 }
7844 else
7845 {
Daniel Malead01b2952012-11-29 21:49:15 +00007846 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 +00007847 MakeUserID(sc_parent_die->GetOffset()),
7848 DW_TAG_value_to_name (parent_tag),
7849 MakeUserID(orig_die->GetOffset()),
7850 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007851 }
7852 break;
7853
7854 case DW_TAG_subprogram:
7855 case DW_TAG_inlined_subroutine:
7856 case DW_TAG_lexical_block:
7857 if (sc.function != NULL)
7858 {
7859 // Check to see if we already have parsed the variables for the given scope
7860
Greg Clayton81c22f62011-10-19 18:09:39 +00007861 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007862 if (block == NULL)
7863 {
7864 // This must be a specification or abstract origin with
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00007865 // a concrete block counterpart in the current function. We need
Greg Claytonc662ec82011-06-17 22:10:16 +00007866 // to find the concrete block so we can correctly add the
7867 // variable to it
7868 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
7869 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
7870 sc_parent_die->GetOffset(),
7871 &concrete_block_die_cu);
7872 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00007873 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007874 }
7875
7876 if (block != NULL)
7877 {
7878 const bool can_create = false;
7879 variable_list_sp = block->GetBlockVariableList (can_create);
7880 if (variable_list_sp.get() == NULL)
7881 {
7882 variable_list_sp.reset(new VariableList());
7883 block->SetVariableList(variable_list_sp);
7884 }
7885 }
7886 }
7887 break;
7888
7889 default:
Daniel Malead01b2952012-11-29 21:49:15 +00007890 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 +00007891 MakeUserID(orig_die->GetOffset()),
7892 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007893 break;
7894 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00007895 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007896
7897 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007898 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00007899 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
7900 if (var_sp)
7901 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007902 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00007903 if (cc_variable_list)
7904 cc_variable_list->AddVariableIfUnique (var_sp);
7905 ++vars_added;
7906 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007907 }
7908 }
7909 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007910
7911 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
7912
7913 if (!skip_children && parse_children && die->HasChildren())
7914 {
7915 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
7916 }
7917
7918 if (parse_siblings)
7919 die = die->GetSibling();
7920 else
7921 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007922 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007923 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007924}
7925
7926//------------------------------------------------------------------
7927// PluginInterface protocol
7928//------------------------------------------------------------------
Greg Clayton57abc5d2013-05-10 21:47:16 +00007929ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007930SymbolFileDWARF::GetPluginName()
7931{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007932 return GetPluginNameStatic();
7933}
7934
7935uint32_t
7936SymbolFileDWARF::GetPluginVersion()
7937{
7938 return 1;
7939}
7940
7941void
Greg Clayton6beaaa62011-01-17 03:46:26 +00007942SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
7943{
7944 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
Greg Clayton57ee3062013-07-11 22:46:58 +00007945 ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
Greg Clayton6beaaa62011-01-17 03:46:26 +00007946 if (clang_type)
7947 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7948}
7949
7950void
7951SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
7952{
7953 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
Greg Clayton57ee3062013-07-11 22:46:58 +00007954 ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
Greg Clayton6beaaa62011-01-17 03:46:26 +00007955 if (clang_type)
7956 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7957}
7958
Greg Claytona2721472011-06-25 00:44:06 +00007959void
Sean Callanancc427fa2011-07-30 02:42:06 +00007960SymbolFileDWARF::DumpIndexes ()
7961{
7962 StreamFile s(stdout, false);
7963
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00007964 s.Printf ("DWARF index for (%s) '%s':",
Sean Callanancc427fa2011-07-30 02:42:06 +00007965 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00007966 GetObjectFile()->GetFileSpec().GetPath().c_str());
Sean Callanancc427fa2011-07-30 02:42:06 +00007967 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
7968 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
7969 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
7970 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
7971 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
7972 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
7973 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
7974 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
7975}
7976
7977void
7978SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
7979 const char *name,
7980 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00007981{
Sean Callanancc427fa2011-07-30 02:42:06 +00007982 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00007983
7984 if (iter == m_decl_ctx_to_die.end())
7985 return;
7986
Greg Claytoncb5860a2011-10-13 23:49:28 +00007987 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00007988 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007989 const DWARFDebugInfoEntry *context_die = *pos;
7990
7991 if (!results)
7992 return;
7993
7994 DWARFDebugInfo* info = DebugInfo();
7995
7996 DIEArray die_offsets;
7997
7998 DWARFCompileUnit* dwarf_cu = NULL;
7999 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton220a0072011-12-09 08:48:30 +00008000
8001 if (m_using_apple_tables)
8002 {
8003 if (m_apple_types_ap.get())
8004 m_apple_types_ap->FindByName (name, die_offsets);
8005 }
8006 else
8007 {
8008 if (!m_indexed)
8009 Index ();
8010
8011 m_type_index.Find (ConstString(name), die_offsets);
8012 }
8013
Greg Clayton220a0072011-12-09 08:48:30 +00008014 const size_t num_matches = die_offsets.size();
Greg Claytoncb5860a2011-10-13 23:49:28 +00008015
8016 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00008017 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00008018 for (size_t i = 0; i < num_matches; ++i)
8019 {
8020 const dw_offset_t die_offset = die_offsets[i];
8021 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00008022
Greg Claytoncb5860a2011-10-13 23:49:28 +00008023 if (die->GetParent() != context_die)
8024 continue;
8025
8026 Type *matching_type = ResolveType (dwarf_cu, die);
8027
Greg Clayton57ee3062013-07-11 22:46:58 +00008028 clang::QualType qual_type = matching_type->GetClangForwardType().GetQualType();
Greg Claytoncb5860a2011-10-13 23:49:28 +00008029
8030 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
8031 {
8032 clang::TagDecl *tag_decl = tag_type->getDecl();
8033 results->push_back(tag_decl);
8034 }
8035 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
8036 {
8037 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
8038 results->push_back(typedef_decl);
8039 }
Greg Claytona2721472011-06-25 00:44:06 +00008040 }
8041 }
8042 }
8043}
8044
8045void
8046SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00008047 const clang::DeclContext *decl_context,
8048 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00008049 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
8050{
Greg Clayton85ae2e12011-10-18 23:36:41 +00008051
8052 switch (decl_context->getDeclKind())
8053 {
8054 case clang::Decl::Namespace:
8055 case clang::Decl::TranslationUnit:
8056 {
8057 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
8058 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
8059 }
8060 break;
8061 default:
8062 break;
8063 }
Greg Claytona2721472011-06-25 00:44:06 +00008064}
Greg Claytoncaab74e2012-01-28 00:48:57 +00008065
Zachary Turner504f38d2015-03-24 16:24:50 +00008066bool
8067SymbolFileDWARF::LayoutRecordType(void *baton, const clang::RecordDecl *record_decl, uint64_t &size,
8068 uint64_t &alignment,
Zachary Turnera98fac22015-03-24 18:56:08 +00008069 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
8070 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
8071 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
Greg Claytoncaab74e2012-01-28 00:48:57 +00008072{
8073 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
8074 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
8075}
8076
Zachary Turner504f38d2015-03-24 16:24:50 +00008077bool
8078SymbolFileDWARF::LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &bit_size, uint64_t &alignment,
Zachary Turnera98fac22015-03-24 18:56:08 +00008079 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
8080 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
8081 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
Greg Claytoncaab74e2012-01-28 00:48:57 +00008082{
Greg Clayton5160ce52013-03-27 23:08:40 +00008083 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Claytoncaab74e2012-01-28 00:48:57 +00008084 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
8085 bool success = false;
8086 base_offsets.clear();
8087 vbase_offsets.clear();
8088 if (pos != m_record_decl_to_layout_map.end())
8089 {
8090 bit_size = pos->second.bit_size;
8091 alignment = pos->second.alignment;
8092 field_offsets.swap(pos->second.field_offsets);
Greg Clayton2508b9b2012-11-01 23:20:02 +00008093 base_offsets.swap (pos->second.base_offsets);
8094 vbase_offsets.swap (pos->second.vbase_offsets);
Greg Claytoncaab74e2012-01-28 00:48:57 +00008095 m_record_decl_to_layout_map.erase(pos);
8096 success = true;
8097 }
8098 else
8099 {
8100 bit_size = 0;
8101 alignment = 0;
8102 field_offsets.clear();
8103 }
8104
8105 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00008106 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00008107 "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 +00008108 static_cast<const void*>(record_decl),
8109 bit_size, alignment,
8110 static_cast<uint32_t>(field_offsets.size()),
8111 static_cast<uint32_t>(base_offsets.size()),
8112 static_cast<uint32_t>(vbase_offsets.size()),
Greg Claytoncaab74e2012-01-28 00:48:57 +00008113 success);
8114 return success;
8115}
8116
8117
Greg Clayton1f746072012-08-29 21:13:06 +00008118SymbolFileDWARFDebugMap *
8119SymbolFileDWARF::GetDebugMapSymfile ()
8120{
8121 if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired())
8122 {
8123 lldb::ModuleSP module_sp (m_debug_map_module_wp.lock());
8124 if (module_sp)
8125 {
8126 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
8127 if (sym_vendor)
8128 m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile();
8129 }
8130 }
8131 return m_debug_map_symfile;
8132}
8133
Greg Claytoncaab74e2012-01-28 00:48:57 +00008134