blob: 66695640dc6319c49b6240e7c396280a51cdc6be [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 {
Greg Clayton1f746072012-08-29 21:13:06 +0000975 const char * cu_die_name = cu_die->GetName(this, dwarf_cu);
976 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
977 LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
978 if (cu_die_name)
979 {
980 std::string ramapped_file;
981 FileSpec cu_file_spec;
Jim Ingham0909e5f2010-09-16 00:57:33 +0000982
Greg Clayton1f746072012-08-29 21:13:06 +0000983 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0')
Greg Clayton53eb1c22012-04-02 22:59:12 +0000984 {
Greg Clayton1f746072012-08-29 21:13:06 +0000985 // If we have a full path to the compile unit, we don't need to resolve
986 // the file. This can be expensive e.g. when the source files are NFS mounted.
987 if (module_sp->RemapSourceFile(cu_die_name, ramapped_file))
988 cu_file_spec.SetFile (ramapped_file.c_str(), false);
989 else
990 cu_file_spec.SetFile (cu_die_name, false);
Greg Clayton53eb1c22012-04-02 22:59:12 +0000991 }
992 else
993 {
Matthew Gardinere81df3b2014-08-26 06:57:23 +0000994 // DWARF2/3 suggests the form hostname:pathname for compilation directory.
995 // Remove the host part if present.
996 cu_comp_dir = removeHostnameFromPathname(cu_comp_dir);
Greg Clayton1f746072012-08-29 21:13:06 +0000997 std::string fullpath(cu_comp_dir);
Matthew Gardinere81df3b2014-08-26 06:57:23 +0000998
Greg Clayton1f746072012-08-29 21:13:06 +0000999 if (*fullpath.rbegin() != '/')
1000 fullpath += '/';
1001 fullpath += cu_die_name;
1002 if (module_sp->RemapSourceFile (fullpath.c_str(), ramapped_file))
1003 cu_file_spec.SetFile (ramapped_file.c_str(), false);
1004 else
1005 cu_file_spec.SetFile (fullpath.c_str(), false);
1006 }
1007
1008 cu_sp.reset(new CompileUnit (module_sp,
1009 dwarf_cu,
1010 cu_file_spec,
1011 MakeUserID(dwarf_cu->GetOffset()),
1012 cu_language));
1013 if (cu_sp)
1014 {
1015 dwarf_cu->SetUserData(cu_sp.get());
1016
Greg Clayton53eb1c22012-04-02 22:59:12 +00001017 // Figure out the compile unit index if we weren't given one
1018 if (cu_idx == UINT32_MAX)
1019 DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx);
1020
1021 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp);
1022 }
1023 }
1024 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001025 }
1026 }
1027 }
1028 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00001029 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001030}
1031
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001032uint32_t
1033SymbolFileDWARF::GetNumCompileUnits()
1034{
1035 DWARFDebugInfo* info = DebugInfo();
1036 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001037 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001038 return 0;
1039}
1040
1041CompUnitSP
1042SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
1043{
Greg Clayton53eb1c22012-04-02 22:59:12 +00001044 CompUnitSP cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001045 DWARFDebugInfo* info = DebugInfo();
1046 if (info)
1047 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00001048 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
1049 if (dwarf_cu)
1050 cu_sp = ParseCompileUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001051 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00001052 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001053}
1054
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001055Function *
Greg Clayton0fffff52010-09-24 05:15:53 +00001056SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001057{
1058 DWARFDebugRanges::RangeList func_ranges;
1059 const char *name = NULL;
1060 const char *mangled = NULL;
1061 int decl_file = 0;
1062 int decl_line = 0;
1063 int decl_column = 0;
1064 int call_file = 0;
1065 int call_line = 0;
1066 int call_column = 0;
1067 DWARFExpression frame_base;
1068
Greg Claytonc93237c2010-10-01 20:48:32 +00001069 assert (die->Tag() == DW_TAG_subprogram);
1070
1071 if (die->Tag() != DW_TAG_subprogram)
1072 return NULL;
1073
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001074 if (die->GetDIENamesAndRanges (this,
1075 dwarf_cu,
1076 name,
1077 mangled,
1078 func_ranges,
1079 decl_file,
1080 decl_line,
1081 decl_column,
1082 call_file,
1083 call_line,
1084 call_column,
1085 &frame_base))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001086 {
1087 // Union of all ranges in the function DIE (if the function is discontiguous)
1088 AddressRange func_range;
Greg Claytonea3e7d52011-10-08 00:49:15 +00001089 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0);
1090 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001091 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
1092 {
Michael Sartaina7499c92013-07-01 19:45:50 +00001093 ModuleSP module_sp (m_obj_file->GetModule());
Greg Clayton3046e662013-07-10 01:23:25 +00001094 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, module_sp->GetSectionList());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001095 if (func_range.GetBaseAddress().IsValid())
1096 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
1097 }
1098
1099 if (func_range.GetBaseAddress().IsValid())
1100 {
1101 Mangled func_name;
1102 if (mangled)
Greg Clayton037520e2012-07-18 23:18:10 +00001103 func_name.SetValue(ConstString(mangled), true);
Siva Chandra462722d2015-03-27 00:10:04 +00001104 else if (die->GetParent()->Tag() == DW_TAG_compile_unit &&
1105 LanguageRuntime::LanguageIsCPlusPlus(dwarf_cu->GetLanguageType()) &&
Greg Clayton94380562015-05-15 22:20:29 +00001106 name && strcmp(name, "main") != 0)
Siva Chandra462722d2015-03-27 00:10:04 +00001107 {
1108 // If the mangled name is not present in the DWARF, generate the demangled name
1109 // using the decl context. We skip if the function is "main" as its name is
1110 // never mangled.
1111 bool is_static = false;
1112 bool is_variadic = false;
1113 unsigned type_quals = 0;
1114 std::vector<ClangASTType> param_types;
1115 std::vector<clang::ParmVarDecl*> param_decls;
1116 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
1117 DWARFDeclContext decl_ctx;
1118 StreamString sstr;
1119
1120 die->GetDWARFDeclContext(this, dwarf_cu, decl_ctx);
1121 sstr << decl_ctx.GetQualifiedName();
1122
1123 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE(dwarf_cu,
1124 die,
1125 &decl_ctx_die);
1126 ParseChildParameters(sc,
1127 containing_decl_ctx,
1128 dwarf_cu,
1129 die,
1130 true,
1131 is_static,
1132 is_variadic,
1133 param_types,
1134 param_decls,
1135 type_quals);
1136 sstr << "(";
1137 for (size_t i = 0; i < param_types.size(); i++)
1138 {
1139 if (i > 0)
1140 sstr << ", ";
1141 sstr << param_types[i].GetTypeName();
1142 }
1143 if (is_variadic)
1144 sstr << ", ...";
1145 sstr << ")";
1146 if (type_quals & clang::Qualifiers::Const)
1147 sstr << " const";
1148
1149 func_name.SetValue(ConstString(sstr.GetData()), false);
1150 }
1151 else
Greg Clayton037520e2012-07-18 23:18:10 +00001152 func_name.SetValue(ConstString(name), false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001153
1154 FunctionSP func_sp;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001155 std::unique_ptr<Declaration> decl_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001156 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +00001157 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1158 decl_line,
1159 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001160
Greg Clayton0bd4e1b2011-09-30 20:52:25 +00001161 // Supply the type _only_ if it has already been parsed
Greg Clayton594e5ed2010-09-27 21:07:38 +00001162 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001163
1164 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
1165
Greg Clayton9422dd62013-03-04 21:46:16 +00001166 if (FixupAddress (func_range.GetBaseAddress()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001167 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001168 const user_id_t func_user_id = MakeUserID(die->GetOffset());
1169 func_sp.reset(new Function (sc.comp_unit,
1170 MakeUserID(func_user_id), // UserID is the DIE offset
1171 MakeUserID(func_user_id),
1172 func_name,
1173 func_type,
1174 func_range)); // first address range
1175
1176 if (func_sp.get() != NULL)
1177 {
1178 if (frame_base.IsValid())
1179 func_sp->GetFrameBaseExpression() = frame_base;
1180 sc.comp_unit->AddFunction(func_sp);
1181 return func_sp.get();
1182 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001183 }
1184 }
1185 }
1186 return NULL;
1187}
1188
Greg Clayton9422dd62013-03-04 21:46:16 +00001189bool
1190SymbolFileDWARF::FixupAddress (Address &addr)
1191{
1192 SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile ();
1193 if (debug_map_symfile)
1194 {
1195 return debug_map_symfile->LinkOSOAddress(addr);
1196 }
1197 // This is a normal DWARF file, no address fixups need to happen
1198 return true;
1199}
Greg Clayton1f746072012-08-29 21:13:06 +00001200lldb::LanguageType
1201SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc)
1202{
1203 assert (sc.comp_unit);
1204 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1205 if (dwarf_cu)
1206 {
1207 const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly();
Jim Ingham28eb5712012-10-12 17:34:26 +00001208 if (die)
1209 {
1210 const uint32_t language = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
1211 if (language)
1212 return (lldb::LanguageType)language;
1213 }
Greg Clayton1f746072012-08-29 21:13:06 +00001214 }
1215 return eLanguageTypeUnknown;
1216}
1217
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001218size_t
1219SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
1220{
1221 assert (sc.comp_unit);
1222 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00001223 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001224 if (dwarf_cu)
1225 {
1226 DWARFDIECollection function_dies;
Greg Clayton1f746072012-08-29 21:13:06 +00001227 const size_t num_functions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001228 size_t func_idx;
Greg Clayton1f746072012-08-29 21:13:06 +00001229 for (func_idx = 0; func_idx < num_functions; ++func_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001230 {
1231 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
Greg Clayton81c22f62011-10-19 18:09:39 +00001232 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001233 {
1234 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
1235 ++functions_added;
1236 }
1237 }
1238 //FixupTypes();
1239 }
1240 return functions_added;
1241}
1242
1243bool
1244SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
1245{
1246 assert (sc.comp_unit);
Greg Clayton1f746072012-08-29 21:13:06 +00001247 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Greg Claytonda2455b2012-11-01 17:28:37 +00001248 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001249 {
Greg Claytonda2455b2012-11-01 17:28:37 +00001250 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001251
Greg Claytonda2455b2012-11-01 17:28:37 +00001252 if (cu_die)
1253 {
1254 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
Matthew Gardinere81df3b2014-08-26 06:57:23 +00001255
1256 // DWARF2/3 suggests the form hostname:pathname for compilation directory.
1257 // Remove the host part if present.
1258 cu_comp_dir = removeHostnameFromPathname(cu_comp_dir);
1259
Greg Claytonda2455b2012-11-01 17:28:37 +00001260 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 +00001261
Greg Claytonda2455b2012-11-01 17:28:37 +00001262 // All file indexes in DWARF are one based and a file of index zero is
1263 // supposed to be the compile unit itself.
1264 support_files.Append (*sc.comp_unit);
1265
1266 return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
1267 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001268 }
1269 return false;
1270}
1271
Sean Callananf0c5aeb2015-04-20 16:31:29 +00001272bool
1273SymbolFileDWARF::ParseImportedModules (const lldb_private::SymbolContext &sc, std::vector<lldb_private::ConstString> &imported_modules)
1274{
1275 assert (sc.comp_unit);
1276 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1277 if (dwarf_cu)
1278 {
1279 if (ClangModulesDeclVendor::LanguageSupportsClangModules(sc.comp_unit->GetLanguage()))
1280 {
1281 UpdateExternalModuleListIfNeeded();
1282 for (const std::pair<uint64_t, const ClangModuleInfo> &external_type_module : m_external_type_modules)
1283 {
1284 imported_modules.push_back(external_type_module.second.m_name);
1285 }
1286 }
1287 }
1288 return false;
1289}
1290
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001291struct ParseDWARFLineTableCallbackInfo
1292{
1293 LineTable* line_table;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001294 std::unique_ptr<LineSequence> sequence_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001295};
1296
1297//----------------------------------------------------------------------
1298// ParseStatementTableCallback
1299//----------------------------------------------------------------------
1300static void
1301ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
1302{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001303 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
1304 {
1305 // Just started parsing the line table
1306 }
1307 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
1308 {
1309 // Done parsing line table, nothing to do for the cleanup
1310 }
1311 else
1312 {
1313 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
Greg Clayton9422dd62013-03-04 21:46:16 +00001314 LineTable* line_table = info->line_table;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001315
Greg Clayton9422dd62013-03-04 21:46:16 +00001316 // If this is our first time here, we need to create a
1317 // sequence container.
1318 if (!info->sequence_ap.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001319 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001320 info->sequence_ap.reset(line_table->CreateLineSequenceContainer());
1321 assert(info->sequence_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001322 }
Greg Clayton9422dd62013-03-04 21:46:16 +00001323 line_table->AppendLineEntryToSequence (info->sequence_ap.get(),
1324 state.address,
1325 state.line,
1326 state.column,
1327 state.file,
1328 state.is_stmt,
1329 state.basic_block,
1330 state.prologue_end,
1331 state.epilogue_begin,
1332 state.end_sequence);
1333 if (state.end_sequence)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001334 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001335 // First, put the current sequence into the line table.
1336 line_table->InsertSequence(info->sequence_ap.get());
1337 // Then, empty it to prepare for the next sequence.
1338 info->sequence_ap->Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001339 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001340 }
1341}
1342
1343bool
1344SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1345{
1346 assert (sc.comp_unit);
1347 if (sc.comp_unit->GetLineTable() != NULL)
1348 return true;
1349
Greg Clayton1f746072012-08-29 21:13:06 +00001350 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001351 if (dwarf_cu)
1352 {
1353 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Greg Clayton129d12c2011-11-28 03:29:03 +00001354 if (dwarf_cu_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001355 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001356 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1357 if (cu_line_offset != DW_INVALID_OFFSET)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001358 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001359 std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
Greg Clayton129d12c2011-11-28 03:29:03 +00001360 if (line_table_ap.get())
1361 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001362 ParseDWARFLineTableCallbackInfo info;
1363 info.line_table = line_table_ap.get();
Greg Claytonc7bece562013-01-25 18:06:21 +00001364 lldb::offset_t offset = cu_line_offset;
Greg Clayton129d12c2011-11-28 03:29:03 +00001365 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
Greg Clayton9422dd62013-03-04 21:46:16 +00001366 if (m_debug_map_symfile)
1367 {
1368 // We have an object file that has a line table with addresses
1369 // that are not linked. We need to link the line table and convert
1370 // the addresses that are relative to the .o file into addresses
1371 // for the main executable.
1372 sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get()));
1373 }
1374 else
1375 {
1376 sc.comp_unit->SetLineTable(line_table_ap.release());
1377 return true;
1378 }
Greg Clayton129d12c2011-11-28 03:29:03 +00001379 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001380 }
1381 }
1382 }
1383 return false;
1384}
1385
1386size_t
1387SymbolFileDWARF::ParseFunctionBlocks
1388(
1389 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001390 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001391 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001392 const DWARFDebugInfoEntry *die,
1393 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001394 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001395)
1396{
1397 size_t blocks_added = 0;
1398 while (die != NULL)
1399 {
1400 dw_tag_t tag = die->Tag();
1401
1402 switch (tag)
1403 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001404 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001405 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001406 case DW_TAG_lexical_block:
1407 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001408 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001409 if (tag == DW_TAG_subprogram)
1410 {
1411 // Skip any DW_TAG_subprogram DIEs that are inside
1412 // of a normal or inlined functions. These will be
1413 // parsed on their own as separate entities.
1414
1415 if (depth > 0)
1416 break;
1417
1418 block = parent_block;
1419 }
1420 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001421 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001422 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001423 parent_block->AddChild(block_sp);
1424 block = block_sp.get();
1425 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001426 DWARFDebugRanges::RangeList ranges;
1427 const char *name = NULL;
1428 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001429
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001430 int decl_file = 0;
1431 int decl_line = 0;
1432 int decl_column = 0;
1433 int call_file = 0;
1434 int call_line = 0;
1435 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001436 if (die->GetDIENamesAndRanges (this,
1437 dwarf_cu,
1438 name,
1439 mangled_name,
1440 ranges,
1441 decl_file, decl_line, decl_column,
1442 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001443 {
1444 if (tag == DW_TAG_subprogram)
1445 {
1446 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001447 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001448 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001449 else if (tag == DW_TAG_inlined_subroutine)
1450 {
1451 // We get called here for inlined subroutines in two ways.
1452 // The first time is when we are making the Function object
1453 // for this inlined concrete instance. Since we're creating a top level block at
1454 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1455 // adjust the containing address.
1456 // The second time is when we are parsing the blocks inside the function that contains
1457 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1458 // function the offset will be for that function.
1459 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1460 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001461 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001462 }
1463 }
Greg Clayton103f3092015-01-15 03:04:37 +00001464
1465 const size_t num_ranges = ranges.GetSize();
1466 for (size_t i = 0; i<num_ranges; ++i)
1467 {
1468 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i);
1469 const addr_t range_base = range.GetRangeBase();
1470 if (range_base >= subprogram_low_pc)
1471 block->AddRange(Block::Range (range_base - subprogram_low_pc, range.GetByteSize()));
1472 else
1473 {
1474 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",
1475 block->GetID(),
1476 range_base,
1477 range.GetRangeEnd(),
1478 subprogram_low_pc);
1479 }
1480 }
1481 block->FinalizeRanges ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001482
1483 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1484 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001485 std::unique_ptr<Declaration> decl_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001486 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001487 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1488 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001489
Greg Clayton7b0992d2013-04-18 22:45:39 +00001490 std::unique_ptr<Declaration> call_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001491 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001492 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1493 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001494
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001495 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001496 }
1497
1498 ++blocks_added;
1499
Greg Claytondd7feaf2011-08-12 17:54:33 +00001500 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001501 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001502 blocks_added += ParseFunctionBlocks (sc,
1503 block,
1504 dwarf_cu,
1505 die->GetFirstChild(),
1506 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001507 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001508 }
1509 }
1510 }
1511 break;
1512 default:
1513 break;
1514 }
1515
Greg Claytondd7feaf2011-08-12 17:54:33 +00001516 // Only parse siblings of the block if we are not at depth zero. A depth
1517 // of zero indicates we are currently parsing the top level
1518 // DW_TAG_subprogram DIE
1519
1520 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001521 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001522 else
1523 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001524 }
1525 return blocks_added;
1526}
1527
Greg Claytonf0705c82011-10-22 03:33:13 +00001528bool
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001529SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu,
1530 const DWARFDebugInfoEntry *die,
1531 ClangASTContext::TemplateParameterInfos &template_param_infos)
1532{
1533 const dw_tag_t tag = die->Tag();
1534
1535 switch (tag)
1536 {
1537 case DW_TAG_template_type_parameter:
1538 case DW_TAG_template_value_parameter:
1539 {
Todd Fialaee8bfc62014-09-11 17:29:12 +00001540 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001541
1542 DWARFDebugInfoEntry::Attributes attributes;
1543 const size_t num_attributes = die->GetAttributes (this,
1544 dwarf_cu,
1545 fixed_form_sizes,
1546 attributes);
1547 const char *name = NULL;
1548 Type *lldb_type = NULL;
Greg Clayton57ee3062013-07-11 22:46:58 +00001549 ClangASTType clang_type;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001550 uint64_t uval64 = 0;
1551 bool uval64_valid = false;
1552 if (num_attributes > 0)
1553 {
1554 DWARFFormValue form_value;
1555 for (size_t i=0; i<num_attributes; ++i)
1556 {
1557 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1558
1559 switch (attr)
1560 {
1561 case DW_AT_name:
1562 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1563 name = form_value.AsCString(&get_debug_str_data());
1564 break;
1565
1566 case DW_AT_type:
1567 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1568 {
Greg Clayton54166af2014-11-22 01:58:59 +00001569 const dw_offset_t type_die_offset = form_value.Reference();
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001570 lldb_type = ResolveTypeUID(type_die_offset);
1571 if (lldb_type)
1572 clang_type = lldb_type->GetClangForwardType();
1573 }
1574 break;
1575
1576 case DW_AT_const_value:
1577 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1578 {
1579 uval64_valid = true;
1580 uval64 = form_value.Unsigned();
1581 }
1582 break;
1583 default:
1584 break;
1585 }
1586 }
1587
Greg Clayton283b2652013-04-23 22:38:02 +00001588 clang::ASTContext *ast = GetClangASTContext().getASTContext();
1589 if (!clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00001590 clang_type = GetClangASTContext().GetBasicType(eBasicTypeVoid);
Greg Clayton283b2652013-04-23 22:38:02 +00001591
1592 if (clang_type)
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001593 {
1594 bool is_signed = false;
Greg Clayton283b2652013-04-23 22:38:02 +00001595 if (name && name[0])
1596 template_param_infos.names.push_back(name);
1597 else
1598 template_param_infos.names.push_back(NULL);
1599
Greg Clayton283b2652013-04-23 22:38:02 +00001600 if (tag == DW_TAG_template_value_parameter &&
1601 lldb_type != NULL &&
Greg Clayton57ee3062013-07-11 22:46:58 +00001602 clang_type.IsIntegerType (is_signed) &&
Greg Clayton283b2652013-04-23 22:38:02 +00001603 uval64_valid)
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001604 {
1605 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
Greg Clayton283b2652013-04-23 22:38:02 +00001606 template_param_infos.args.push_back (clang::TemplateArgument (*ast,
Sean Callanan3d654b32012-09-24 22:25:51 +00001607 llvm::APSInt(apint),
Greg Clayton57ee3062013-07-11 22:46:58 +00001608 clang_type.GetQualType()));
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001609 }
1610 else
1611 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001612 template_param_infos.args.push_back (clang::TemplateArgument (clang_type.GetQualType()));
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001613 }
1614 }
1615 else
1616 {
1617 return false;
1618 }
1619
1620 }
1621 }
1622 return true;
1623
1624 default:
1625 break;
1626 }
1627 return false;
1628}
1629
1630bool
Greg Claytonf0705c82011-10-22 03:33:13 +00001631SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1632 const DWARFDebugInfoEntry *parent_die,
1633 ClangASTContext::TemplateParameterInfos &template_param_infos)
1634{
1635
1636 if (parent_die == NULL)
Filipe Cabecinhas52008c62012-05-23 16:24:11 +00001637 return false;
Greg Claytonf0705c82011-10-22 03:33:13 +00001638
Greg Claytonf0705c82011-10-22 03:33:13 +00001639 Args template_parameter_names;
1640 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1641 die != NULL;
1642 die = die->GetSibling())
1643 {
1644 const dw_tag_t tag = die->Tag();
1645
1646 switch (tag)
1647 {
1648 case DW_TAG_template_type_parameter:
1649 case DW_TAG_template_value_parameter:
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001650 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Claytonf0705c82011-10-22 03:33:13 +00001651 break;
1652
1653 default:
1654 break;
1655 }
1656 }
1657 if (template_param_infos.args.empty())
1658 return false;
1659 return template_param_infos.args.size() == template_param_infos.names.size();
1660}
1661
1662clang::ClassTemplateDecl *
1663SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001664 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001665 const char *parent_name,
1666 int tag_decl_kind,
1667 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1668{
1669 if (template_param_infos.IsValid())
1670 {
1671 std::string template_basename(parent_name);
1672 template_basename.erase (template_basename.find('<'));
1673 ClangASTContext &ast = GetClangASTContext();
1674
1675 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001676 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001677 template_basename.c_str(),
1678 tag_decl_kind,
1679 template_param_infos);
1680 }
1681 return NULL;
1682}
1683
Sean Callanana0b80ab2012-06-04 22:28:05 +00001684class SymbolFileDWARF::DelayedAddObjCClassProperty
1685{
1686public:
1687 DelayedAddObjCClassProperty
1688 (
Greg Clayton57ee3062013-07-11 22:46:58 +00001689 const ClangASTType &class_opaque_type,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001690 const char *property_name,
Greg Clayton57ee3062013-07-11 22:46:58 +00001691 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 +00001692 clang::ObjCIvarDecl *ivar_decl,
1693 const char *property_setter_name,
1694 const char *property_getter_name,
1695 uint32_t property_attributes,
Greg Claytonc4ffd662013-03-08 01:37:30 +00001696 const ClangASTMetadata *metadata
Sean Callanana0b80ab2012-06-04 22:28:05 +00001697 ) :
Sean Callanana0b80ab2012-06-04 22:28:05 +00001698 m_class_opaque_type (class_opaque_type),
1699 m_property_name (property_name),
1700 m_property_opaque_type (property_opaque_type),
1701 m_ivar_decl (ivar_decl),
1702 m_property_setter_name (property_setter_name),
1703 m_property_getter_name (property_getter_name),
Jim Ingham379397632012-10-27 02:54:13 +00001704 m_property_attributes (property_attributes)
Sean Callanana0b80ab2012-06-04 22:28:05 +00001705 {
Jim Ingham379397632012-10-27 02:54:13 +00001706 if (metadata != NULL)
1707 {
1708 m_metadata_ap.reset(new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001709 *m_metadata_ap = *metadata;
Jim Ingham379397632012-10-27 02:54:13 +00001710 }
1711 }
1712
1713 DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs)
1714 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001715 *this = rhs;
Daniel Malead4c5be62012-11-12 21:02:14 +00001716 }
1717
1718 DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs)
1719 {
Jim Ingham379397632012-10-27 02:54:13 +00001720 m_class_opaque_type = rhs.m_class_opaque_type;
1721 m_property_name = rhs.m_property_name;
1722 m_property_opaque_type = rhs.m_property_opaque_type;
1723 m_ivar_decl = rhs.m_ivar_decl;
1724 m_property_setter_name = rhs.m_property_setter_name;
1725 m_property_getter_name = rhs.m_property_getter_name;
1726 m_property_attributes = rhs.m_property_attributes;
1727
1728 if (rhs.m_metadata_ap.get())
1729 {
1730 m_metadata_ap.reset (new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001731 *m_metadata_ap = *rhs.m_metadata_ap;
Jim Ingham379397632012-10-27 02:54:13 +00001732 }
Daniel Malead4c5be62012-11-12 21:02:14 +00001733 return *this;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001734 }
1735
Greg Clayton57ee3062013-07-11 22:46:58 +00001736 bool
1737 Finalize()
Sean Callanana0b80ab2012-06-04 22:28:05 +00001738 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001739 return m_class_opaque_type.AddObjCClassProperty (m_property_name,
1740 m_property_opaque_type,
1741 m_ivar_decl,
1742 m_property_setter_name,
1743 m_property_getter_name,
1744 m_property_attributes,
1745 m_metadata_ap.get());
Sean Callanana0b80ab2012-06-04 22:28:05 +00001746 }
1747private:
Greg Clayton57ee3062013-07-11 22:46:58 +00001748 ClangASTType m_class_opaque_type;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001749 const char *m_property_name;
Greg Clayton57ee3062013-07-11 22:46:58 +00001750 ClangASTType m_property_opaque_type;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001751 clang::ObjCIvarDecl *m_ivar_decl;
1752 const char *m_property_setter_name;
1753 const char *m_property_getter_name;
1754 uint32_t m_property_attributes;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001755 std::unique_ptr<ClangASTMetadata> m_metadata_ap;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001756};
1757
Sean Callananfaa0bb32012-12-05 23:37:14 +00001758struct BitfieldInfo
1759{
1760 uint64_t bit_size;
1761 uint64_t bit_offset;
1762
1763 BitfieldInfo () :
1764 bit_size (LLDB_INVALID_ADDRESS),
1765 bit_offset (LLDB_INVALID_ADDRESS)
1766 {
1767 }
1768
Greg Clayton78f4d952013-12-11 23:10:39 +00001769 void
1770 Clear()
1771 {
1772 bit_size = LLDB_INVALID_ADDRESS;
1773 bit_offset = LLDB_INVALID_ADDRESS;
1774 }
1775
Sean Callananfaa0bb32012-12-05 23:37:14 +00001776 bool IsValid ()
1777 {
1778 return (bit_size != LLDB_INVALID_ADDRESS) &&
1779 (bit_offset != LLDB_INVALID_ADDRESS);
1780 }
1781};
1782
Greg Claytonc4ffd662013-03-08 01:37:30 +00001783
1784bool
1785SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu,
1786 const DWARFDebugInfoEntry *parent_die)
1787{
1788 if (parent_die)
1789 {
1790 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1791 {
1792 dw_tag_t tag = die->Tag();
1793 bool check_virtuality = false;
1794 switch (tag)
1795 {
1796 case DW_TAG_inheritance:
1797 case DW_TAG_subprogram:
1798 check_virtuality = true;
1799 break;
1800 default:
1801 break;
1802 }
1803 if (check_virtuality)
1804 {
1805 if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0)
1806 return true;
1807 }
1808 }
1809 }
1810 return false;
1811}
1812
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001813size_t
1814SymbolFileDWARF::ParseChildMembers
1815(
1816 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001817 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001818 const DWARFDebugInfoEntry *parent_die,
Greg Clayton57ee3062013-07-11 22:46:58 +00001819 ClangASTType &class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001820 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001821 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1822 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001823 DWARFDIECollection& member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001824 DelayedPropertyList& delayed_properties,
Sean Callananc7fbf732010-08-06 00:32:49 +00001825 AccessType& default_accessibility,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001826 bool &is_a_class,
1827 LayoutInfo &layout_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001828)
1829{
1830 if (parent_die == NULL)
1831 return 0;
1832
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001833 size_t count = 0;
1834 const DWARFDebugInfoEntry *die;
Todd Fialaee8bfc62014-09-11 17:29:12 +00001835 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001836 uint32_t member_idx = 0;
Sean Callananfaa0bb32012-12-05 23:37:14 +00001837 BitfieldInfo last_field_info;
Richard Mitton0a558352013-10-17 21:14:00 +00001838 ModuleSP module = GetObjectFile()->GetModule();
Greg Claytond88d7592010-09-15 08:33:30 +00001839
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001840 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1841 {
1842 dw_tag_t tag = die->Tag();
1843
1844 switch (tag)
1845 {
1846 case DW_TAG_member:
Sean Callanan3d654b32012-09-24 22:25:51 +00001847 case DW_TAG_APPLE_property:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001848 {
1849 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001850 const size_t num_attributes = die->GetAttributes (this,
1851 dwarf_cu,
1852 fixed_form_sizes,
1853 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001854 if (num_attributes > 0)
1855 {
1856 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001857 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001858 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001859 const char *prop_name = NULL;
1860 const char *prop_getter_name = NULL;
1861 const char *prop_setter_name = NULL;
Greg Claytone528efd72013-02-26 23:45:18 +00001862 uint32_t prop_attributes = 0;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001863
1864
Greg Clayton24739922010-10-13 03:15:28 +00001865 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001866 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001867 AccessType accessibility = eAccessNone;
Greg Claytoncaab74e2012-01-28 00:48:57 +00001868 uint32_t member_byte_offset = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001869 size_t byte_size = 0;
1870 size_t bit_offset = 0;
1871 size_t bit_size = 0;
Greg Claytone528efd72013-02-26 23:45:18 +00001872 bool is_external = false; // On DW_TAG_members, this means the member is static
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001873 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001874 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001875 {
1876 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1877 DWARFFormValue form_value;
1878 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1879 {
1880 switch (attr)
1881 {
1882 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1883 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1884 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1885 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00001886 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001887 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1888 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1889 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1890 case DW_AT_data_member_location:
Greg Claytoncaab74e2012-01-28 00:48:57 +00001891 if (form_value.BlockData())
1892 {
1893 Value initialValue(0);
1894 Value memberOffset(0);
Ed Masteeeae7212013-10-24 20:43:47 +00001895 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Claytoncaab74e2012-01-28 00:48:57 +00001896 uint32_t block_length = form_value.Unsigned();
1897 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1898 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
Greg Claytoncaab74e2012-01-28 00:48:57 +00001899 NULL, // ClangExpressionVariableList *
1900 NULL, // ClangExpressionDeclMap *
1901 NULL, // RegisterContext *
Richard Mitton0a558352013-10-17 21:14:00 +00001902 module,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001903 debug_info_data,
1904 block_offset,
1905 block_length,
1906 eRegisterKindDWARF,
1907 &initialValue,
1908 memberOffset,
1909 NULL))
1910 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001911 member_byte_offset = memberOffset.ResolveValue(NULL).UInt();
Greg Claytoncaab74e2012-01-28 00:48:57 +00001912 }
1913 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00001914 else
1915 {
1916 // With DWARF 3 and later, if the value is an integer constant,
1917 // this form value is the offset in bytes from the beginning
1918 // of the containing entity.
1919 member_byte_offset = form_value.Unsigned();
1920 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001921 break;
1922
Greg Clayton8cf05932010-07-22 18:30:50 +00001923 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00001924 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001925 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1926 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1927 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1928 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00001929 case DW_AT_external: is_external = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001930
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001931 default:
Greg Clayton1b02c172012-03-14 21:00:47 +00001932 case DW_AT_declaration:
1933 case DW_AT_description:
1934 case DW_AT_mutable:
1935 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001936 case DW_AT_sibling:
1937 break;
1938 }
1939 }
1940 }
Sean Callanana6582262012-04-05 00:12:52 +00001941
1942 if (prop_name)
Sean Callanan751aac62012-03-29 19:07:06 +00001943 {
Sean Callanana6582262012-04-05 00:12:52 +00001944 ConstString fixed_getter;
1945 ConstString fixed_setter;
1946
1947 // Check if the property getter/setter were provided as full
1948 // names. We want basenames, so we extract them.
1949
1950 if (prop_getter_name && prop_getter_name[0] == '-')
1951 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001952 ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true);
1953 prop_getter_name = prop_getter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001954 }
1955
1956 if (prop_setter_name && prop_setter_name[0] == '-')
1957 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001958 ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true);
1959 prop_setter_name = prop_setter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001960 }
1961
1962 // If the names haven't been provided, they need to be
1963 // filled in.
1964
1965 if (!prop_getter_name)
1966 {
1967 prop_getter_name = prop_name;
1968 }
1969 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly))
1970 {
1971 StreamString ss;
1972
1973 ss.Printf("set%c%s:",
1974 toupper(prop_name[0]),
1975 &prop_name[1]);
1976
1977 fixed_setter.SetCString(ss.GetData());
1978 prop_setter_name = fixed_setter.GetCString();
1979 }
Sean Callanan751aac62012-03-29 19:07:06 +00001980 }
1981
1982 // Clang has a DWARF generation bug where sometimes it
Greg Clayton44953932011-10-25 01:25:35 +00001983 // represents fields that are references with bad byte size
1984 // and bit size/offset information such as:
1985 //
1986 // DW_AT_byte_size( 0x00 )
1987 // DW_AT_bit_size( 0x40 )
1988 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1989 //
1990 // So check the bit offset to make sure it is sane, and if
1991 // the values are not sane, remove them. If we don't do this
1992 // then we will end up with a crash if we try to use this
1993 // type in an expression when clang becomes unhappy with its
1994 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001995
Greg Clayton44953932011-10-25 01:25:35 +00001996 if (bit_offset > 128)
1997 {
1998 bit_size = 0;
1999 bit_offset = 0;
2000 }
2001
2002 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00002003 if (class_language == eLanguageTypeObjC ||
2004 class_language == eLanguageTypeObjC_plus_plus)
2005 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00002006
2007 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
2008 {
2009 // Not all compilers will mark the vtable pointer
2010 // member as artificial (llvm-gcc). We can't have
2011 // the virtual members in our classes otherwise it
2012 // throws off all child offsets since we end up
2013 // having and extra pointer sized member in our
2014 // class layouts.
2015 is_artificial = true;
2016 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002017
Greg Clayton29659712013-07-12 20:08:35 +00002018 // Handle static members
Greg Claytone528efd72013-02-26 23:45:18 +00002019 if (is_external && member_byte_offset == UINT32_MAX)
Greg Clayton973b6c92013-04-11 16:57:51 +00002020 {
2021 Type *var_type = ResolveTypeUID(encoding_uid);
2022
2023 if (var_type)
2024 {
Greg Clayton29659712013-07-12 20:08:35 +00002025 if (accessibility == eAccessNone)
2026 accessibility = eAccessPublic;
Greg Clayton57ee3062013-07-11 22:46:58 +00002027 class_clang_type.AddVariableToRecordType (name,
2028 var_type->GetClangLayoutType(),
2029 accessibility);
Greg Clayton973b6c92013-04-11 16:57:51 +00002030 }
Greg Claytone528efd72013-02-26 23:45:18 +00002031 break;
Greg Clayton973b6c92013-04-11 16:57:51 +00002032 }
Greg Claytone528efd72013-02-26 23:45:18 +00002033
Greg Clayton24739922010-10-13 03:15:28 +00002034 if (is_artificial == false)
2035 {
2036 Type *member_type = ResolveTypeUID(encoding_uid);
Sean Callananfa3ab452012-12-14 00:54:13 +00002037
Jim Inghame3ae82a2011-11-12 01:36:43 +00002038 clang::FieldDecl *field_decl = NULL;
Sean Callanan751aac62012-03-29 19:07:06 +00002039 if (tag == DW_TAG_member)
Greg Claytond16e1e52011-07-12 17:06:17 +00002040 {
Sean Callanan751aac62012-03-29 19:07:06 +00002041 if (member_type)
2042 {
2043 if (accessibility == eAccessNone)
2044 accessibility = default_accessibility;
2045 member_accessibilities.push_back(accessibility);
Sean Callananfaa0bb32012-12-05 23:37:14 +00002046
Greg Clayton78f4d952013-12-11 23:10:39 +00002047 uint64_t field_bit_offset = (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
2048 if (bit_size > 0)
Greg Clayton88bc7f32012-11-06 00:20:41 +00002049 {
Greg Clayton78f4d952013-12-11 23:10:39 +00002050
2051 BitfieldInfo this_field_info;
2052 this_field_info.bit_offset = field_bit_offset;
2053 this_field_info.bit_size = bit_size;
2054
Sean Callananfaa0bb32012-12-05 23:37:14 +00002055 /////////////////////////////////////////////////////////////
2056 // How to locate a field given the DWARF debug information
2057 //
2058 // AT_byte_size indicates the size of the word in which the
2059 // bit offset must be interpreted.
2060 //
2061 // AT_data_member_location indicates the byte offset of the
2062 // word from the base address of the structure.
2063 //
2064 // AT_bit_offset indicates how many bits into the word
2065 // (according to the host endianness) the low-order bit of
2066 // the field starts. AT_bit_offset can be negative.
2067 //
2068 // AT_bit_size indicates the size of the field in bits.
2069 /////////////////////////////////////////////////////////////
2070
Greg Clayton78f4d952013-12-11 23:10:39 +00002071 if (byte_size == 0)
2072 byte_size = member_type->GetByteSize();
2073
Sean Callananfaa0bb32012-12-05 23:37:14 +00002074 if (GetObjectFile()->GetByteOrder() == eByteOrderLittle)
2075 {
2076 this_field_info.bit_offset += byte_size * 8;
2077 this_field_info.bit_offset -= (bit_offset + bit_size);
2078 }
2079 else
2080 {
2081 this_field_info.bit_offset += bit_offset;
2082 }
Greg Clayton78f4d952013-12-11 23:10:39 +00002083
2084 // Update the field bit offset we will report for layout
2085 field_bit_offset = this_field_info.bit_offset;
Sean Callananfaa0bb32012-12-05 23:37:14 +00002086
Greg Clayton78f4d952013-12-11 23:10:39 +00002087 // If the member to be emitted did not start on a character boundary and there is
2088 // empty space between the last field and this one, then we need to emit an
2089 // anonymous member filling up the space up to its start. There are three cases
2090 // here:
2091 //
2092 // 1 If the previous member ended on a character boundary, then we can emit an
2093 // anonymous member starting at the most recent character boundary.
2094 //
2095 // 2 If the previous member did not end on a character boundary and the distance
2096 // from the end of the previous member to the current member is less than a
2097 // word width, then we can emit an anonymous member starting right after the
2098 // previous member and right before this member.
2099 //
2100 // 3 If the previous member did not end on a character boundary and the distance
2101 // from the end of the previous member to the current member is greater than
2102 // or equal a word width, then we act as in Case 1.
2103
2104 const uint64_t character_width = 8;
2105 const uint64_t word_width = 32;
2106
Sean Callananfaa0bb32012-12-05 23:37:14 +00002107 // Objective-C has invalid DW_AT_bit_offset values in older versions
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +00002108 // of clang, so we have to be careful and only insert unnamed bitfields
Greg Clayton37c36e42012-11-27 00:59:26 +00002109 // if we have a new enough clang.
2110 bool detect_unnamed_bitfields = true;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002111
Greg Clayton37c36e42012-11-27 00:59:26 +00002112 if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus)
2113 detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields ();
2114
2115 if (detect_unnamed_bitfields)
Greg Clayton88bc7f32012-11-06 00:20:41 +00002116 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00002117 BitfieldInfo anon_field_info;
2118
2119 if ((this_field_info.bit_offset % character_width) != 0) // not char aligned
Greg Clayton88bc7f32012-11-06 00:20:41 +00002120 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00002121 uint64_t last_field_end = 0;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002122
Sean Callananfaa0bb32012-12-05 23:37:14 +00002123 if (last_field_info.IsValid())
2124 last_field_end = last_field_info.bit_offset + last_field_info.bit_size;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002125
Sean Callananfaa0bb32012-12-05 23:37:14 +00002126 if (this_field_info.bit_offset != last_field_end)
2127 {
2128 if (((last_field_end % character_width) == 0) || // case 1
2129 (this_field_info.bit_offset - last_field_end >= word_width)) // case 3
2130 {
2131 anon_field_info.bit_size = this_field_info.bit_offset % character_width;
2132 anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size;
2133 }
2134 else // case 2
2135 {
2136 anon_field_info.bit_size = this_field_info.bit_offset - last_field_end;
2137 anon_field_info.bit_offset = last_field_end;
2138 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00002139 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00002140 }
2141
Sean Callananfaa0bb32012-12-05 23:37:14 +00002142 if (anon_field_info.IsValid())
Greg Clayton88bc7f32012-11-06 00:20:41 +00002143 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002144 clang::FieldDecl *unnamed_bitfield_decl = class_clang_type.AddFieldToRecordType (NULL,
2145 GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width),
2146 accessibility,
2147 anon_field_info.bit_size);
Zachary Turner504f38d2015-03-24 16:24:50 +00002148
Zachary Turnera98fac22015-03-24 18:56:08 +00002149 layout_info.field_offsets.insert(
Zachary Turner504f38d2015-03-24 16:24:50 +00002150 std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset));
Greg Clayton88bc7f32012-11-06 00:20:41 +00002151 }
2152 }
Greg Clayton78f4d952013-12-11 23:10:39 +00002153 last_field_info = this_field_info;
2154 }
2155 else
2156 {
2157 last_field_info.Clear();
Greg Clayton88bc7f32012-11-06 00:20:41 +00002158 }
Sean Callananfaa0bb32012-12-05 23:37:14 +00002159
Greg Clayton57ee3062013-07-11 22:46:58 +00002160 ClangASTType member_clang_type = member_type->GetClangLayoutType();
Sean Callananfa3ab452012-12-14 00:54:13 +00002161
2162 {
2163 // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>).
2164 // If the current field is at the end of the structure, then there is definitely no room for extra
2165 // elements and we override the type to array[0].
2166
Greg Clayton57ee3062013-07-11 22:46:58 +00002167 ClangASTType member_array_element_type;
Sean Callananfa3ab452012-12-14 00:54:13 +00002168 uint64_t member_array_size;
2169 bool member_array_is_incomplete;
2170
Greg Clayton57ee3062013-07-11 22:46:58 +00002171 if (member_clang_type.IsArrayType(&member_array_element_type,
2172 &member_array_size,
2173 &member_array_is_incomplete) &&
Sean Callananfa3ab452012-12-14 00:54:13 +00002174 !member_array_is_incomplete)
2175 {
2176 uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX);
2177
2178 if (member_byte_offset >= parent_byte_size)
2179 {
2180 if (member_array_size != 1)
2181 {
2182 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,
2183 MakeUserID(die->GetOffset()),
2184 name,
2185 encoding_uid,
2186 MakeUserID(parent_die->GetOffset()));
2187 }
2188
Greg Clayton1c8ef472013-04-05 23:27:21 +00002189 member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0, false);
Sean Callananfa3ab452012-12-14 00:54:13 +00002190 }
2191 }
2192 }
2193
Greg Clayton57ee3062013-07-11 22:46:58 +00002194 field_decl = class_clang_type.AddFieldToRecordType (name,
2195 member_clang_type,
2196 accessibility,
2197 bit_size);
Sean Callanan60217122012-04-13 00:10:03 +00002198
Greg Claytond0029442013-03-27 01:48:02 +00002199 GetClangASTContext().SetMetadataAsUserID (field_decl, MakeUserID(die->GetOffset()));
Greg Clayton78f4d952013-12-11 23:10:39 +00002200
Zachary Turnera98fac22015-03-24 18:56:08 +00002201 layout_info.field_offsets.insert(std::make_pair(field_decl, field_bit_offset));
Sean Callanan5b26f272012-02-04 08:49:35 +00002202 }
2203 else
2204 {
Sean Callanan751aac62012-03-29 19:07:06 +00002205 if (name)
Daniel Malead01b2952012-11-29 21:49:15 +00002206 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 +00002207 MakeUserID(die->GetOffset()),
2208 name,
2209 encoding_uid);
2210 else
Daniel Malead01b2952012-11-29 21:49:15 +00002211 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 +00002212 MakeUserID(die->GetOffset()),
2213 encoding_uid);
Sean Callanan5b26f272012-02-04 08:49:35 +00002214 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002215 }
Sean Callanan751aac62012-03-29 19:07:06 +00002216
Jim Inghame3ae82a2011-11-12 01:36:43 +00002217 if (prop_name != NULL)
2218 {
Sean Callanan751aac62012-03-29 19:07:06 +00002219 clang::ObjCIvarDecl *ivar_decl = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00002220
Sean Callanan751aac62012-03-29 19:07:06 +00002221 if (field_decl)
2222 {
2223 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
2224 assert (ivar_decl != NULL);
2225 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00002226
Jim Ingham379397632012-10-27 02:54:13 +00002227 ClangASTMetadata metadata;
2228 metadata.SetUserID (MakeUserID(die->GetOffset()));
Greg Clayton57ee3062013-07-11 22:46:58 +00002229 delayed_properties.push_back(DelayedAddObjCClassProperty(class_clang_type,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002230 prop_name,
2231 member_type->GetClangLayoutType(),
2232 ivar_decl,
2233 prop_setter_name,
2234 prop_getter_name,
2235 prop_attributes,
Jim Ingham379397632012-10-27 02:54:13 +00002236 &metadata));
Sean Callanan60217122012-04-13 00:10:03 +00002237
Sean Callananad880762012-04-18 01:06:17 +00002238 if (ivar_decl)
Greg Claytond0029442013-03-27 01:48:02 +00002239 GetClangASTContext().SetMetadataAsUserID (ivar_decl, MakeUserID(die->GetOffset()));
Jim Inghame3ae82a2011-11-12 01:36:43 +00002240 }
Greg Clayton24739922010-10-13 03:15:28 +00002241 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002242 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00002243 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002244 }
2245 break;
2246
2247 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00002248 // Let the type parsing code handle this one for us.
2249 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002250 break;
2251
2252 case DW_TAG_inheritance:
2253 {
2254 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00002255 if (default_accessibility == eAccessNone)
2256 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002257 // TODO: implement DW_TAG_inheritance type parsing
2258 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00002259 const size_t num_attributes = die->GetAttributes (this,
2260 dwarf_cu,
2261 fixed_form_sizes,
2262 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002263 if (num_attributes > 0)
2264 {
2265 Declaration decl;
2266 DWARFExpression location;
2267 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00002268 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002269 bool is_virtual = false;
2270 bool is_base_of_class = true;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002271 off_t member_byte_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002272 uint32_t i;
2273 for (i=0; i<num_attributes; ++i)
2274 {
2275 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2276 DWARFFormValue form_value;
2277 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2278 {
2279 switch (attr)
2280 {
2281 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2282 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2283 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00002284 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002285 case DW_AT_data_member_location:
2286 if (form_value.BlockData())
2287 {
2288 Value initialValue(0);
2289 Value memberOffset(0);
Ed Masteeeae7212013-10-24 20:43:47 +00002290 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002291 uint32_t block_length = form_value.Unsigned();
2292 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
2293 if (DWARFExpression::Evaluate (NULL,
2294 NULL,
2295 NULL,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002296 NULL,
Richard Mitton0a558352013-10-17 21:14:00 +00002297 module,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002298 debug_info_data,
2299 block_offset,
2300 block_length,
2301 eRegisterKindDWARF,
2302 &initialValue,
2303 memberOffset,
2304 NULL))
2305 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002306 member_byte_offset = memberOffset.ResolveValue(NULL).UInt();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002307 }
2308 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002309 else
2310 {
2311 // With DWARF 3 and later, if the value is an integer constant,
2312 // this form value is the offset in bytes from the beginning
2313 // of the containing entity.
2314 member_byte_offset = form_value.Unsigned();
2315 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002316 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002317
2318 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00002319 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002320 break;
2321
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002322 case DW_AT_virtuality:
2323 is_virtual = form_value.Boolean();
2324 break;
2325
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002326 case DW_AT_sibling:
2327 break;
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002328
2329 default:
2330 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002331 }
2332 }
2333 }
2334
Greg Clayton526e5af2010-11-13 03:52:47 +00002335 Type *base_class_type = ResolveTypeUID(encoding_uid);
2336 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002337
Greg Clayton57ee3062013-07-11 22:46:58 +00002338 ClangASTType base_class_clang_type = base_class_type->GetClangFullType();
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002339 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002340 if (class_language == eLanguageTypeObjC)
2341 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002342 class_clang_type.SetObjCSuperClass(base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002343 }
2344 else
2345 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002346 base_classes.push_back (base_class_clang_type.CreateBaseClassSpecifier (accessibility,
Greg Claytonba2d22d2010-11-13 22:57:37 +00002347 is_virtual,
2348 is_base_of_class));
Greg Clayton2508b9b2012-11-01 23:20:02 +00002349
2350 if (is_virtual)
2351 {
Greg Clayton52694e32013-09-16 21:57:07 +00002352 // Do not specify any offset for virtual inheritance. The DWARF produced by clang doesn't
2353 // give us a constant offset, but gives us a DWARF expressions that requires an actual object
2354 // in memory. the DW_AT_data_member_location for a virtual base class looks like:
2355 // DW_AT_data_member_location( DW_OP_dup, DW_OP_deref, DW_OP_constu(0x00000018), DW_OP_minus, DW_OP_deref, DW_OP_plus )
2356 // Given this, there is really no valid response we can give to clang for virtual base
2357 // class offsets, and this should eventually be removed from LayoutRecordType() in the external
2358 // AST source in clang.
Greg Clayton2508b9b2012-11-01 23:20:02 +00002359 }
2360 else
2361 {
Zachary Turnera98fac22015-03-24 18:56:08 +00002362 layout_info.base_offsets.insert(
Zachary Turner504f38d2015-03-24 16:24:50 +00002363 std::make_pair(base_class_clang_type.GetAsCXXRecordDecl(),
2364 clang::CharUnits::fromQuantity(member_byte_offset)));
Greg Clayton2508b9b2012-11-01 23:20:02 +00002365 }
Greg Clayton9e409562010-07-28 02:04:09 +00002366 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002367 }
2368 }
2369 break;
2370
2371 default:
2372 break;
2373 }
2374 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002375
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002376 return count;
2377}
2378
2379
2380clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00002381SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002382{
2383 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00002384 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002385 {
2386 DWARFCompileUnitSP cu_sp;
2387 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
2388 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00002389 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00002390 }
2391 return NULL;
2392}
2393
2394clang::DeclContext*
2395SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
2396{
Greg Clayton81c22f62011-10-19 18:09:39 +00002397 if (UserIDMatches(type_uid))
2398 return GetClangDeclContextForDIEOffset (sc, type_uid);
2399 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002400}
2401
2402Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00002403SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002404{
Greg Clayton81c22f62011-10-19 18:09:39 +00002405 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002406 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002407 DWARFDebugInfo* debug_info = DebugInfo();
2408 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00002409 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002410 DWARFCompileUnitSP cu_sp;
2411 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00002412 const bool assert_not_being_parsed = true;
2413 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00002414 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002415 }
2416 return NULL;
2417}
2418
Greg Claytoncab36a32011-12-08 05:16:30 +00002419Type*
2420SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00002421{
Greg Claytoncab36a32011-12-08 05:16:30 +00002422 if (die != NULL)
2423 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002424 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00002425 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002426 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002427 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
2428 die->GetOffset(),
2429 DW_TAG_value_to_name(die->Tag()),
2430 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00002431
Greg Claytoncab36a32011-12-08 05:16:30 +00002432 // We might be coming in in the middle of a type tree (a class
2433 // withing a class, an enum within a class), so parse any needed
2434 // parent DIEs before we get to this one...
2435 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2436 switch (decl_ctx_die->Tag())
2437 {
2438 case DW_TAG_structure_type:
2439 case DW_TAG_union_type:
2440 case DW_TAG_class_type:
2441 {
2442 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00002443 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002444 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002445 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
2446 die->GetOffset(),
2447 DW_TAG_value_to_name(die->Tag()),
2448 die->GetName(this, cu),
2449 decl_ctx_die->GetOffset());
Greg Clayton219cf312012-03-30 00:51:13 +00002450//
2451// Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
2452// if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
2453// {
2454// if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002455// GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton219cf312012-03-30 00:51:13 +00002456// "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
2457// die->GetOffset(),
2458// DW_TAG_value_to_name(die->Tag()),
2459// die->GetName(this, cu),
2460// decl_ctx_die->GetOffset());
2461// // Ask the type to complete itself if it already hasn't since if we
2462// // want a function (method or static) from a class, the class must
2463// // create itself and add it's own methods and class functions.
2464// if (parent_type)
2465// parent_type->GetClangFullType();
2466// }
Greg Claytoncab36a32011-12-08 05:16:30 +00002467 }
2468 break;
2469
2470 default:
2471 break;
2472 }
2473 return ResolveType (cu, die);
2474 }
2475 return NULL;
2476}
2477
Greg Clayton6beaaa62011-01-17 03:46:26 +00002478// This function is used when SymbolFileDWARFDebugMap owns a bunch of
2479// SymbolFileDWARF objects to detect if this DWARF file is the one that
2480// can resolve a clang_type.
2481bool
Greg Clayton57ee3062013-07-11 22:46:58 +00002482SymbolFileDWARF::HasForwardDeclForClangType (const ClangASTType &clang_type)
Greg Clayton6beaaa62011-01-17 03:46:26 +00002483{
Greg Clayton57ee3062013-07-11 22:46:58 +00002484 ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers();
2485 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton6beaaa62011-01-17 03:46:26 +00002486 return die != NULL;
2487}
2488
2489
Greg Clayton57ee3062013-07-11 22:46:58 +00002490bool
2491SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (ClangASTType &clang_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00002492{
2493 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton57ee3062013-07-11 22:46:58 +00002494 ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers();
2495 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton1be10fc2010-09-29 01:12:09 +00002496 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00002497 {
2498 // We have already resolved this type...
Greg Clayton57ee3062013-07-11 22:46:58 +00002499 return true;
Greg Clayton73b472d2010-10-27 03:32:59 +00002500 }
2501 // Once we start resolving this type, remove it from the forward declaration
2502 // map in case anyone child members or other types require this type to get resolved.
2503 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
2504 // are done.
Greg Clayton57ee3062013-07-11 22:46:58 +00002505 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton1be10fc2010-09-29 01:12:09 +00002506
Greg Clayton85ae2e12011-10-18 23:36:41 +00002507 // Disable external storage for this type so we don't get anymore
2508 // clang::ExternalASTSource queries for this type.
Greg Clayton57ee3062013-07-11 22:46:58 +00002509 clang_type.SetHasExternalStorage (false);
Greg Clayton85ae2e12011-10-18 23:36:41 +00002510
Greg Clayton450e3f32010-10-12 02:24:53 +00002511 DWARFDebugInfo* debug_info = DebugInfo();
2512
Greg Clayton53eb1c22012-04-02 22:59:12 +00002513 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002514 Type *type = m_die_to_type.lookup (die);
2515
2516 const dw_tag_t tag = die->Tag();
2517
Greg Clayton5160ce52013-03-27 23:08:40 +00002518 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
Greg Clayton3bffb082011-12-10 02:15:28 +00002519 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002520 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002521 "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...",
Greg Claytond61c0fc2012-04-23 22:55:20 +00002522 MakeUserID(die->GetOffset()),
2523 DW_TAG_value_to_name(tag),
2524 type->GetName().AsCString());
Greg Clayton1be10fc2010-09-29 01:12:09 +00002525 assert (clang_type);
2526 DWARFDebugInfoEntry::Attributes attributes;
2527
Greg Clayton1be10fc2010-09-29 01:12:09 +00002528 switch (tag)
2529 {
2530 case DW_TAG_structure_type:
2531 case DW_TAG_union_type:
2532 case DW_TAG_class_type:
Greg Claytonc93237c2010-10-01 20:48:32 +00002533 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002534 LayoutInfo layout_info;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002535
Greg Clayton1be10fc2010-09-29 01:12:09 +00002536 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002537 if (die->HasChildren())
Greg Claytonc93237c2010-10-01 20:48:32 +00002538 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002539 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton57ee3062013-07-11 22:46:58 +00002540 if (clang_type.IsObjCObjectOrInterfaceType())
Greg Clayton219cf312012-03-30 00:51:13 +00002541 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002542 class_language = eLanguageTypeObjC;
Greg Clayton219cf312012-03-30 00:51:13 +00002543 // For objective C we don't start the definition when
2544 // the class is created.
Greg Clayton57ee3062013-07-11 22:46:58 +00002545 clang_type.StartTagDeclarationDefinition ();
Greg Clayton219cf312012-03-30 00:51:13 +00002546 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002547
Sean Callanan77a1fd32012-02-27 20:07:01 +00002548 int tag_decl_kind = -1;
2549 AccessType default_accessibility = eAccessNone;
2550 if (tag == DW_TAG_structure_type)
2551 {
2552 tag_decl_kind = clang::TTK_Struct;
2553 default_accessibility = eAccessPublic;
2554 }
2555 else if (tag == DW_TAG_union_type)
2556 {
2557 tag_decl_kind = clang::TTK_Union;
2558 default_accessibility = eAccessPublic;
2559 }
2560 else if (tag == DW_TAG_class_type)
2561 {
2562 tag_decl_kind = clang::TTK_Class;
2563 default_accessibility = eAccessPrivate;
2564 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002565
Greg Clayton53eb1c22012-04-02 22:59:12 +00002566 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002567 std::vector<clang::CXXBaseSpecifier *> base_classes;
2568 std::vector<int> member_accessibilities;
2569 bool is_a_class = false;
2570 // Parse members and base classes first
2571 DWARFDIECollection member_function_dies;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002572
Sean Callanana0b80ab2012-06-04 22:28:05 +00002573 DelayedPropertyList delayed_properties;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002574 ParseChildMembers (sc,
Greg Clayton53eb1c22012-04-02 22:59:12 +00002575 dwarf_cu,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002576 die,
2577 clang_type,
2578 class_language,
2579 base_classes,
2580 member_accessibilities,
2581 member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002582 delayed_properties,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002583 default_accessibility,
2584 is_a_class,
2585 layout_info);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002586
Sean Callanan77a1fd32012-02-27 20:07:01 +00002587 // Now parse any methods if there were any...
2588 size_t num_functions = member_function_dies.Size();
2589 if (num_functions > 0)
2590 {
2591 for (size_t i=0; i<num_functions; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002592 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002593 ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytoncaab74e2012-01-28 00:48:57 +00002594 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002595 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002596
Sean Callanan77a1fd32012-02-27 20:07:01 +00002597 if (class_language == eLanguageTypeObjC)
2598 {
Jim Inghamfb6fc0d2013-09-27 20:59:37 +00002599 ConstString class_name (clang_type.GetTypeName());
2600 if (class_name)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002601 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002602 DIEArray method_die_offsets;
2603 if (m_using_apple_tables)
Greg Clayton95d87902011-11-11 03:16:25 +00002604 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002605 if (m_apple_objc_ap.get())
Jim Inghamfb6fc0d2013-09-27 20:59:37 +00002606 m_apple_objc_ap->FindByName(class_name.GetCString(), method_die_offsets);
Sean Callanan77a1fd32012-02-27 20:07:01 +00002607 }
2608 else
2609 {
2610 if (!m_indexed)
2611 Index ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002612
Sean Callanan77a1fd32012-02-27 20:07:01 +00002613 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
2614 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002615
Sean Callanan77a1fd32012-02-27 20:07:01 +00002616 if (!method_die_offsets.empty())
2617 {
2618 DWARFDebugInfo* debug_info = DebugInfo();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002619
Sean Callanan77a1fd32012-02-27 20:07:01 +00002620 DWARFCompileUnit* method_cu = NULL;
2621 const size_t num_matches = method_die_offsets.size();
2622 for (size_t i=0; i<num_matches; ++i)
Greg Clayton95d87902011-11-11 03:16:25 +00002623 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002624 const dw_offset_t die_offset = method_die_offsets[i];
2625 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002626
Sean Callanan77a1fd32012-02-27 20:07:01 +00002627 if (method_die)
2628 ResolveType (method_cu, method_die);
2629 else
Greg Claytoncaab74e2012-01-28 00:48:57 +00002630 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002631 if (m_using_apple_tables)
2632 {
2633 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 +00002634 die_offset, class_name.GetCString());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002635 }
2636 }
2637 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002638 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002639
Greg Clayton57ee3062013-07-11 22:46:58 +00002640 for (DelayedPropertyList::iterator pi = delayed_properties.begin(), pe = delayed_properties.end();
Sean Callanana0b80ab2012-06-04 22:28:05 +00002641 pi != pe;
2642 ++pi)
2643 pi->Finalize();
Greg Clayton450e3f32010-10-12 02:24:53 +00002644 }
2645 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002646
Sean Callanan77a1fd32012-02-27 20:07:01 +00002647 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2648 // need to tell the clang type it is actually a class.
2649 if (class_language != eLanguageTypeObjC)
2650 {
2651 if (is_a_class && tag_decl_kind != clang::TTK_Class)
Greg Clayton57ee3062013-07-11 22:46:58 +00002652 clang_type.SetTagTypeKind (clang::TTK_Class);
Sean Callanan77a1fd32012-02-27 20:07:01 +00002653 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002654
Sean Callanan77a1fd32012-02-27 20:07:01 +00002655 // Since DW_TAG_structure_type gets used for both classes
2656 // and structures, we may need to set any DW_TAG_member
2657 // fields to have a "private" access if none was specified.
2658 // When we parsed the child members we tracked that actual
2659 // accessibility value for each DW_TAG_member in the
2660 // "member_accessibilities" array. If the value for the
2661 // member is zero, then it was set to the "default_accessibility"
2662 // which for structs was "public". Below we correct this
2663 // by setting any fields to "private" that weren't correctly
2664 // set.
2665 if (is_a_class && !member_accessibilities.empty())
2666 {
2667 // This is a class and all members that didn't have
2668 // their access specified are private.
Greg Clayton57ee3062013-07-11 22:46:58 +00002669 clang_type.SetDefaultAccessForRecordFields (eAccessPrivate,
2670 &member_accessibilities.front(),
2671 member_accessibilities.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002672 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002673
Sean Callanan77a1fd32012-02-27 20:07:01 +00002674 if (!base_classes.empty())
2675 {
Greg Clayton4705f8d2013-12-12 01:54:04 +00002676 // Make sure all base classes refer to complete types and not
2677 // forward declarations. If we don't do this, clang will crash
2678 // with an assertion in the call to clang_type.SetBaseClassesForClassType()
2679 bool base_class_error = false;
2680 for (auto &base_class : base_classes)
2681 {
2682 clang::TypeSourceInfo *type_source_info = base_class->getTypeSourceInfo();
2683 if (type_source_info)
2684 {
2685 ClangASTType base_class_type (GetClangASTContext().getASTContext(), type_source_info->getType());
2686 if (base_class_type.GetCompleteType() == false)
2687 {
2688 if (!base_class_error)
2689 {
2690 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",
2691 die->GetOffset(),
2692 die->GetName(this, dwarf_cu),
2693 base_class_type.GetTypeName().GetCString(),
2694 sc.comp_unit ? sc.comp_unit->GetPath().c_str() : "the source file");
2695 }
2696 // We have no choice other than to pretend that the base class
2697 // is complete. If we don't do this, clang will crash when we
2698 // call setBases() inside of "clang_type.SetBaseClassesForClassType()"
2699 // below. Since we provide layout assistance, all ivars in this
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00002700 // class and other classes will be fine, this is the best we can do
Greg Clayton4705f8d2013-12-12 01:54:04 +00002701 // short of crashing.
2702 base_class_type.StartTagDeclarationDefinition ();
2703 base_class_type.CompleteTagDeclarationDefinition ();
2704 }
2705 }
2706 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002707 clang_type.SetBaseClassesForClassType (&base_classes.front(),
2708 base_classes.size());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002709
Sean Callanan77a1fd32012-02-27 20:07:01 +00002710 // Clang will copy each CXXBaseSpecifier in "base_classes"
2711 // so we have to free them all.
Greg Clayton57ee3062013-07-11 22:46:58 +00002712 ClangASTType::DeleteBaseClassSpecifiers (&base_classes.front(),
2713 base_classes.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002714 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002715 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002716 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002717
Greg Clayton57ee3062013-07-11 22:46:58 +00002718 clang_type.BuildIndirectFields ();
2719 clang_type.CompleteTagDeclarationDefinition ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002720
Greg Clayton2508b9b2012-11-01 23:20:02 +00002721 if (!layout_info.field_offsets.empty() ||
2722 !layout_info.base_offsets.empty() ||
2723 !layout_info.vbase_offsets.empty() )
Greg Claytoncaab74e2012-01-28 00:48:57 +00002724 {
2725 if (type)
2726 layout_info.bit_size = type->GetByteSize() * 8;
2727 if (layout_info.bit_size == 0)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002728 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002729
Greg Clayton57ee3062013-07-11 22:46:58 +00002730 clang::CXXRecordDecl *record_decl = clang_type.GetAsCXXRecordDecl();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002731 if (record_decl)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002732 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002733 if (log)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002734 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002735 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002736 "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 +00002737 static_cast<void*>(clang_type.GetOpaqueQualType()),
2738 static_cast<void*>(record_decl),
Greg Claytoncaab74e2012-01-28 00:48:57 +00002739 layout_info.bit_size,
2740 layout_info.alignment,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002741 static_cast<uint32_t>(layout_info.field_offsets.size()),
2742 static_cast<uint32_t>(layout_info.base_offsets.size()),
2743 static_cast<uint32_t>(layout_info.vbase_offsets.size()));
2744
Zachary Turnera98fac22015-03-24 18:56:08 +00002745 uint32_t idx;
2746 {
2747 llvm::DenseMap<const clang::FieldDecl *, uint64_t>::const_iterator pos,
2748 end = layout_info.field_offsets.end();
2749 for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx)
Greg Clayton2508b9b2012-11-01 23:20:02 +00002750 {
Zachary Turner504f38d2015-03-24 16:24:50 +00002751 GetObjectFile()->GetModule()->LogMessage(
2752 log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = "
2753 "{ bit_offset=%u, name='%s' }",
Zachary Turner504f38d2015-03-24 16:24:50 +00002754 static_cast<void *>(clang_type.GetOpaqueQualType()), idx,
Zachary Turnera98fac22015-03-24 18:56:08 +00002755 static_cast<uint32_t>(pos->second), pos->first->getNameAsString().c_str());
2756 }
2757 }
2758
2759 {
2760 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos,
2761 base_end = layout_info.base_offsets.end();
2762 for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end;
2763 ++base_pos, ++idx)
2764 {
2765 GetObjectFile()->GetModule()->LogMessage(
2766 log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] "
2767 "= { byte_offset=%u, name='%s' }",
2768 clang_type.GetOpaqueQualType(), idx, (uint32_t)base_pos->second.getQuantity(),
2769 base_pos->first->getNameAsString().c_str());
2770 }
2771 }
2772 {
2773 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos,
2774 vbase_end = layout_info.vbase_offsets.end();
2775 for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end;
2776 ++vbase_pos, ++idx)
2777 {
2778 GetObjectFile()->GetModule()->LogMessage(
2779 log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) "
2780 "vbase[%u] = { byte_offset=%u, name='%s' }",
2781 static_cast<void *>(clang_type.GetOpaqueQualType()), idx,
2782 static_cast<uint32_t>(vbase_pos->second.getQuantity()),
2783 vbase_pos->first->getNameAsString().c_str());
2784 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002785 }
Greg Clayton821ac6d2012-01-28 02:22:27 +00002786 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002787 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2788 }
2789 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002790 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002791
Sean Callanan9076c0f2013-10-04 21:35:29 +00002792 return (bool)clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002793
2794 case DW_TAG_enumeration_type:
Greg Clayton57ee3062013-07-11 22:46:58 +00002795 clang_type.StartTagDeclarationDefinition ();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002796 if (die->HasChildren())
2797 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002798 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00002799 bool is_signed = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00002800 clang_type.IsIntegerType(is_signed);
Greg Clayton3e067532013-03-05 23:54:39 +00002801 ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002802 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002803 clang_type.CompleteTagDeclarationDefinition ();
Sean Callanan9076c0f2013-10-04 21:35:29 +00002804 return (bool)clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002805
2806 default:
2807 assert(false && "not a forward clang type decl!");
2808 break;
2809 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002810 return false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002811}
2812
Greg Claytonc685f8e2010-09-15 04:15:46 +00002813Type*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002814SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002815{
2816 if (type_die != NULL)
2817 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002818 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00002819
Greg Claytonc685f8e2010-09-15 04:15:46 +00002820 if (type == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002821 type = GetTypeForDIE (dwarf_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00002822
Greg Clayton24739922010-10-13 03:15:28 +00002823 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00002824 {
2825 if (type != DIE_IS_BEING_PARSED)
2826 return type;
2827
2828 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
Greg Clayton53eb1c22012-04-02 22:59:12 +00002829 type_die->GetOffset(),
2830 DW_TAG_value_to_name(type_die->Tag()),
2831 type_die->GetName(this, dwarf_cu));
Jim Inghamc3549282012-01-11 02:21:12 +00002832
2833 }
2834 else
2835 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002836 }
2837 return NULL;
2838}
2839
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002840CompileUnit*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002841SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002842{
2843 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002844 if (dwarf_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002845 {
2846 // The symbol vendor doesn't know about this compile unit, we
2847 // need to parse and add it to the symbol vendor object.
Greg Clayton53eb1c22012-04-02 22:59:12 +00002848 return ParseCompileUnit(dwarf_cu, cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002849 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00002850 return (CompileUnit*)dwarf_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002851}
2852
2853bool
Greg Clayton53eb1c22012-04-02 22:59:12 +00002854SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002855{
Greg Clayton72310352013-02-23 04:12:47 +00002856 sc.Clear(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002857 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002858 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002859
Greg Clayton81c22f62011-10-19 18:09:39 +00002860 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002861 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002862 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002863
2864 if (sc.function)
2865 {
Greg Claytone72dfb32012-02-24 01:59:29 +00002866 sc.module_sp = sc.function->CalculateSymbolContextModule();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002867 return true;
2868 }
2869
2870 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002871}
2872
Sean Callananf0c5aeb2015-04-20 16:31:29 +00002873void
2874SymbolFileDWARF::UpdateExternalModuleListIfNeeded()
2875{
2876 if (m_fetched_external_modules)
2877 return;
2878 m_fetched_external_modules = true;
2879
2880 DWARFDebugInfo * debug_info = DebugInfo();
2881 debug_info->GetNumCompileUnits();
2882
2883 const uint32_t num_compile_units = GetNumCompileUnits();
2884 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2885 {
2886 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
2887
2888 const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly();
2889 if (die && die->HasChildren() == false)
2890 {
2891 const uint64_t name_strp = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_name, UINT64_MAX);
2892 const uint64_t dwo_path_strp = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_GNU_dwo_name, UINT64_MAX);
2893
2894 if (name_strp != UINT64_MAX)
2895 {
2896 if (m_external_type_modules.find(dwo_path_strp) == m_external_type_modules.end())
2897 {
2898 const char *name = get_debug_str_data().PeekCStr(name_strp);
2899 const char *dwo_path = get_debug_str_data().PeekCStr(dwo_path_strp);
2900 if (name || dwo_path)
2901 {
2902 ModuleSP module_sp;
2903 if (dwo_path)
2904 {
2905 ModuleSpec dwo_module_spec;
2906 dwo_module_spec.GetFileSpec().SetFile(dwo_path, false);
2907 dwo_module_spec.GetArchitecture() = m_obj_file->GetModule()->GetArchitecture();
2908 //printf ("Loading dwo = '%s'\n", dwo_path);
2909 Error error = ModuleList::GetSharedModule (dwo_module_spec, module_sp, NULL, NULL, NULL);
2910 }
2911
2912 if (dwo_path_strp != LLDB_INVALID_UID)
2913 {
2914 m_external_type_modules[dwo_path_strp] = ClangModuleInfo { ConstString(name), module_sp };
2915 }
2916 else
2917 {
2918 // This hack should be removed promptly once clang emits both.
2919 m_external_type_modules[name_strp] = ClangModuleInfo { ConstString(name), module_sp };
2920 }
2921 }
2922 }
2923 }
2924 }
2925 }
2926}
Greg Clayton2501e5e2015-01-15 02:59:20 +00002927
2928SymbolFileDWARF::GlobalVariableMap &
2929SymbolFileDWARF::GetGlobalAranges()
2930{
2931 if (!m_global_aranges_ap)
2932 {
2933 m_global_aranges_ap.reset (new GlobalVariableMap());
2934
2935 ModuleSP module_sp = GetObjectFile()->GetModule();
2936 if (module_sp)
2937 {
2938 const size_t num_cus = module_sp->GetNumCompileUnits();
2939 for (size_t i = 0; i < num_cus; ++i)
2940 {
2941 CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(i);
2942 if (cu_sp)
2943 {
2944 VariableListSP globals_sp = cu_sp->GetVariableList(true);
2945 if (globals_sp)
2946 {
2947 const size_t num_globals = globals_sp->GetSize();
2948 for (size_t g = 0; g < num_globals; ++g)
2949 {
2950 VariableSP var_sp = globals_sp->GetVariableAtIndex(g);
2951 if (var_sp && !var_sp->GetLocationIsConstantValueData())
2952 {
2953 const DWARFExpression &location = var_sp->LocationExpression();
2954 Value location_result;
2955 Error error;
2956 if (location.Evaluate(NULL, NULL, NULL, LLDB_INVALID_ADDRESS, NULL, location_result, &error))
2957 {
2958 if (location_result.GetValueType() == Value::eValueTypeFileAddress)
2959 {
2960 lldb::addr_t file_addr = location_result.GetScalar().ULongLong();
2961 lldb::addr_t byte_size = 1;
2962 if (var_sp->GetType())
2963 byte_size = var_sp->GetType()->GetByteSize();
2964 m_global_aranges_ap->Append(GlobalVariableMap::Entry(file_addr, byte_size, var_sp.get()));
2965 }
2966 }
2967 }
2968 }
2969 }
2970 }
2971 }
2972 }
2973 m_global_aranges_ap->Sort();
2974 }
2975 return *m_global_aranges_ap;
2976}
2977
2978
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002979uint32_t
2980SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2981{
2982 Timer scoped_timer(__PRETTY_FUNCTION__,
Daniel Malead01b2952012-11-29 21:49:15 +00002983 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002984 static_cast<void*>(so_addr.GetSection().get()),
2985 so_addr.GetOffset(), resolve_scope);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002986 uint32_t resolved = 0;
Greg Clayton2501e5e2015-01-15 02:59:20 +00002987 if (resolve_scope & ( eSymbolContextCompUnit |
2988 eSymbolContextFunction |
2989 eSymbolContextBlock |
2990 eSymbolContextLineEntry |
2991 eSymbolContextVariable ))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002992 {
2993 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2994
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002995 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00002996 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002997 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002998 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Greg Clayton2501e5e2015-01-15 02:59:20 +00002999 if (cu_offset == DW_INVALID_OFFSET)
3000 {
3001 // Global variables are not in the compile unit address ranges. The only way to
3002 // currently find global variables is to iterate over the .debug_pubnames or the
3003 // __apple_names table and find all items in there that point to DW_TAG_variable
3004 // DIEs and then find the address that matches.
3005 if (resolve_scope & eSymbolContextVariable)
3006 {
3007 GlobalVariableMap &map = GetGlobalAranges();
3008 const GlobalVariableMap::Entry *entry = map.FindEntryThatContains(file_vm_addr);
3009 if (entry && entry->data)
3010 {
3011 Variable *variable = entry->data;
3012 SymbolContextScope *scc = variable->GetSymbolContextScope();
3013 if (scc)
3014 {
3015 scc->CalculateSymbolContext(&sc);
3016 sc.variable = variable;
3017 }
3018 return sc.GetResolvedMask();
3019 }
3020 }
3021 }
3022 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003023 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003024 uint32_t cu_idx = DW_INVALID_INDEX;
Greg Clayton53eb1c22012-04-02 22:59:12 +00003025 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
3026 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003027 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003028 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00003029 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003030 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003031 resolved |= eSymbolContextCompUnit;
3032
Greg Clayton6ab80132012-12-12 17:30:52 +00003033 bool force_check_line_table = false;
Greg Clayton526a4ae2012-05-16 22:09:01 +00003034 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
3035 {
3036 DWARFDebugInfoEntry *function_die = NULL;
3037 DWARFDebugInfoEntry *block_die = NULL;
3038 if (resolve_scope & eSymbolContextBlock)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003039 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003040 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
3041 }
3042 else
3043 {
3044 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL);
3045 }
3046
3047 if (function_die != NULL)
3048 {
3049 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
3050 if (sc.function == NULL)
3051 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
3052 }
3053 else
3054 {
3055 // We might have had a compile unit that had discontiguous
3056 // address ranges where the gaps are symbols that don't have
3057 // any debug info. Discontiguous compile unit address ranges
3058 // should only happen when there aren't other functions from
3059 // other compile units in these gaps. This helps keep the size
3060 // of the aranges down.
Greg Clayton6ab80132012-12-12 17:30:52 +00003061 force_check_line_table = true;
Greg Clayton526a4ae2012-05-16 22:09:01 +00003062 }
3063
3064 if (sc.function != NULL)
3065 {
3066 resolved |= eSymbolContextFunction;
3067
3068 if (resolve_scope & eSymbolContextBlock)
3069 {
3070 Block& block = sc.function->GetBlock (true);
3071
3072 if (block_die != NULL)
3073 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
3074 else
3075 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
3076 if (sc.block)
3077 resolved |= eSymbolContextBlock;
3078 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003079 }
3080 }
Greg Clayton6ab80132012-12-12 17:30:52 +00003081
3082 if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table)
3083 {
3084 LineTable *line_table = sc.comp_unit->GetLineTable();
3085 if (line_table != NULL)
3086 {
Greg Clayton9422dd62013-03-04 21:46:16 +00003087 // And address that makes it into this function should be in terms
3088 // of this debug file if there is no debug map, or it will be an
3089 // address in the .o file which needs to be fixed up to be in terms
3090 // of the debug map executable. Either way, calling FixupAddress()
3091 // will work for us.
3092 Address exe_so_addr (so_addr);
3093 if (FixupAddress(exe_so_addr))
Greg Clayton6ab80132012-12-12 17:30:52 +00003094 {
Greg Clayton9422dd62013-03-04 21:46:16 +00003095 if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry))
Greg Clayton6ab80132012-12-12 17:30:52 +00003096 {
3097 resolved |= eSymbolContextLineEntry;
3098 }
3099 }
Greg Clayton6ab80132012-12-12 17:30:52 +00003100 }
3101 }
3102
3103 if (force_check_line_table && !(resolved & eSymbolContextLineEntry))
3104 {
3105 // We might have had a compile unit that had discontiguous
3106 // address ranges where the gaps are symbols that don't have
3107 // any debug info. Discontiguous compile unit address ranges
3108 // should only happen when there aren't other functions from
3109 // other compile units in these gaps. This helps keep the size
3110 // of the aranges down.
3111 sc.comp_unit = NULL;
3112 resolved &= ~eSymbolContextCompUnit;
3113 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003114 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00003115 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003116 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003117 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.",
3118 cu_offset,
3119 cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003120 }
3121 }
3122 }
3123 }
3124 }
3125 return resolved;
3126}
3127
3128
3129
3130uint32_t
3131SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
3132{
3133 const uint32_t prev_size = sc_list.GetSize();
3134 if (resolve_scope & eSymbolContextCompUnit)
3135 {
3136 DWARFDebugInfo* debug_info = DebugInfo();
3137 if (debug_info)
3138 {
3139 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00003140 DWARFCompileUnit* dwarf_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003141
Greg Clayton53eb1c22012-04-02 22:59:12 +00003142 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003143 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003144 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Sean Callananddd7a2a2013-10-03 22:27:29 +00003145 const bool full_match = (bool)file_spec.GetDirectory();
Greg Clayton1f746072012-08-29 21:13:06 +00003146 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 +00003147 if (check_inlines || file_spec_matches_cu_file_spec)
3148 {
3149 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton53eb1c22012-04-02 22:59:12 +00003150 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00003151 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003152 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003153 uint32_t file_idx = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003154
Greg Clayton526a4ae2012-05-16 22:09:01 +00003155 // If we are looking for inline functions only and we don't
3156 // find it in the support files, we are done.
3157 if (check_inlines)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003158 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003159 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
3160 if (file_idx == UINT32_MAX)
3161 continue;
3162 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003163
Greg Clayton526a4ae2012-05-16 22:09:01 +00003164 if (line != 0)
3165 {
3166 LineTable *line_table = sc.comp_unit->GetLineTable();
3167
3168 if (line_table != NULL && line != 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003169 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003170 // We will have already looked up the file index if
3171 // we are searching for inline entries.
3172 if (!check_inlines)
3173 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003174
Greg Clayton526a4ae2012-05-16 22:09:01 +00003175 if (file_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003176 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003177 uint32_t found_line;
3178 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
3179 found_line = sc.line_entry.line;
3180
3181 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003182 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003183 sc.function = NULL;
3184 sc.block = NULL;
3185 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003186 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003187 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
3188 if (file_vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003189 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003190 DWARFDebugInfoEntry *function_die = NULL;
3191 DWARFDebugInfoEntry *block_die = NULL;
3192 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003193
Greg Clayton526a4ae2012-05-16 22:09:01 +00003194 if (function_die != NULL)
3195 {
3196 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
3197 if (sc.function == NULL)
3198 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
3199 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003200
Greg Clayton526a4ae2012-05-16 22:09:01 +00003201 if (sc.function != NULL)
3202 {
3203 Block& block = sc.function->GetBlock (true);
3204
3205 if (block_die != NULL)
3206 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
Jason Molenda60db6e42014-10-16 01:40:16 +00003207 else if (function_die != NULL)
Greg Clayton526a4ae2012-05-16 22:09:01 +00003208 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
3209 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003210 }
3211 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003212
Greg Clayton526a4ae2012-05-16 22:09:01 +00003213 sc_list.Append(sc);
3214 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
3215 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003216 }
3217 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00003218 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 }
3225 else if (file_spec_matches_cu_file_spec && !check_inlines)
3226 {
3227 // only append the context if we aren't looking for inline call sites
3228 // by file and line and if the file spec matches that of the compile unit
3229 sc_list.Append(sc);
3230 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003231
Greg Clayton526a4ae2012-05-16 22:09:01 +00003232 if (!check_inlines)
3233 break;
3234 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003235 }
3236 }
3237 }
3238 }
3239 return sc_list.GetSize() - prev_size;
3240}
3241
3242void
3243SymbolFileDWARF::Index ()
3244{
3245 if (m_indexed)
3246 return;
3247 m_indexed = true;
3248 Timer scoped_timer (__PRETTY_FUNCTION__,
3249 "SymbolFileDWARF::Index (%s)",
Jim Ingham4af59612014-12-19 19:20:44 +00003250 GetObjectFile()->GetFileSpec().GetFilename().AsCString("<Unknown>"));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003251
3252 DWARFDebugInfo* debug_info = DebugInfo();
3253 if (debug_info)
3254 {
3255 uint32_t cu_idx = 0;
3256 const uint32_t num_compile_units = GetNumCompileUnits();
3257 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
3258 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003259 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003260
Greg Clayton53eb1c22012-04-02 22:59:12 +00003261 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003262
Greg Clayton53eb1c22012-04-02 22:59:12 +00003263 dwarf_cu->Index (cu_idx,
3264 m_function_basename_index,
3265 m_function_fullname_index,
3266 m_function_method_index,
3267 m_function_selector_index,
3268 m_objc_class_selectors_index,
3269 m_global_index,
3270 m_type_index,
3271 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003272
3273 // Keep memory down by clearing DIEs if this generate function
3274 // caused them to be parsed
3275 if (clear_dies)
Greg Clayton53eb1c22012-04-02 22:59:12 +00003276 dwarf_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003277 }
3278
Greg Claytond4a2b372011-09-12 23:21:58 +00003279 m_function_basename_index.Finalize();
3280 m_function_fullname_index.Finalize();
3281 m_function_method_index.Finalize();
3282 m_function_selector_index.Finalize();
3283 m_objc_class_selectors_index.Finalize();
3284 m_global_index.Finalize();
3285 m_type_index.Finalize();
3286 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003287
Greg Clayton24739922010-10-13 03:15:28 +00003288#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00003289 StreamFile s(stdout, false);
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00003290 s.Printf ("DWARF index for '%s':",
3291 GetObjectFile()->GetFileSpec().GetPath().c_str());
Greg Claytonba2d22d2010-11-13 22:57:37 +00003292 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
3293 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
3294 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
3295 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
3296 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
3297 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00003298 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00003299 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00003300#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003301 }
3302}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003303
3304bool
3305SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
3306{
3307 if (namespace_decl == NULL)
3308 {
3309 // Invalid namespace decl which means we aren't matching only things
3310 // in this symbol file, so return true to indicate it matches this
3311 // symbol file.
3312 return true;
3313 }
3314
3315 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
3316
3317 if (namespace_ast == NULL)
3318 return true; // No AST in the "namespace_decl", return true since it
3319 // could then match any symbol file, including this one
3320
3321 if (namespace_ast == GetClangASTContext().getASTContext())
3322 return true; // The ASTs match, return true
3323
3324 // The namespace AST was valid, and it does not match...
Greg Clayton5160ce52013-03-27 23:08:40 +00003325 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Sean Callananc41e68b2011-10-13 21:08:11 +00003326
3327 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003328 GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00003329
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003330 return false;
3331}
3332
Greg Clayton2506a7a2011-10-12 23:34:26 +00003333bool
3334SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
3335 DWARFCompileUnit* cu,
3336 const DWARFDebugInfoEntry* die)
3337{
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +00003338 // No namespace specified, so the answer is
Greg Clayton2506a7a2011-10-12 23:34:26 +00003339 if (namespace_decl == NULL)
3340 return true;
Sean Callananebe60672011-10-13 21:50:33 +00003341
Greg Clayton5160ce52013-03-27 23:08:40 +00003342 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003343
Greg Clayton437a1352012-04-09 22:43:43 +00003344 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
3345 clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00003346 if (decl_ctx_die)
Greg Clayton437a1352012-04-09 22:43:43 +00003347 {
Greg Clayton2506a7a2011-10-12 23:34:26 +00003348 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
Greg Clayton437a1352012-04-09 22:43:43 +00003349
Greg Clayton2506a7a2011-10-12 23:34:26 +00003350 if (clang_namespace_decl)
3351 {
3352 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00003353 {
3354 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003355 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00003356 return false;
Sean Callananebe60672011-10-13 21:50:33 +00003357 }
3358
Greg Clayton437a1352012-04-09 22:43:43 +00003359 if (clang_namespace_decl == die_clang_decl_ctx)
3360 return true;
3361 else
Greg Clayton2506a7a2011-10-12 23:34:26 +00003362 return false;
Greg Clayton2506a7a2011-10-12 23:34:26 +00003363 }
3364 else
3365 {
3366 // We have a namespace_decl that was not NULL but it contained
3367 // a NULL "clang::NamespaceDecl", so this means the global namespace
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00003368 // So as long the contained decl context DIE isn't a namespace
Greg Clayton2506a7a2011-10-12 23:34:26 +00003369 // we should be ok.
3370 if (decl_ctx_die->Tag() != DW_TAG_namespace)
3371 return true;
3372 }
3373 }
Sean Callananebe60672011-10-13 21:50:33 +00003374
3375 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003376 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00003377
Greg Clayton2506a7a2011-10-12 23:34:26 +00003378 return false;
3379}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003380uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00003381SymbolFileDWARF::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 +00003382{
Greg Clayton5160ce52013-03-27 23:08:40 +00003383 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003384
3385 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003386 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003387 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
3388 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003389 static_cast<const void*>(namespace_decl),
3390 append, max_matches);
3391
Sean Callanan213fdb82011-10-13 01:49:10 +00003392 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00003393 return 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003394
Greg Claytonc685f8e2010-09-15 04:15:46 +00003395 DWARFDebugInfo* info = DebugInfo();
3396 if (info == NULL)
3397 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003398
3399 // If we aren't appending the results to this list, then clear the list
3400 if (!append)
3401 variables.Clear();
3402
3403 // Remember how many variables are in the list before we search in case
3404 // we are appending the results to a variable list.
3405 const uint32_t original_size = variables.GetSize();
3406
Greg Claytond4a2b372011-09-12 23:21:58 +00003407 DIEArray die_offsets;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003408
Greg Clayton97fbc342011-10-20 22:30:33 +00003409 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003410 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003411 if (m_apple_names_ap.get())
3412 {
3413 const char *name_cstr = name.GetCString();
Jim Inghamfa39bb42014-10-25 00:33:55 +00003414 llvm::StringRef basename;
3415 llvm::StringRef context;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003416
Jim Inghamfa39bb42014-10-25 00:33:55 +00003417 if (!CPPLanguageRuntime::ExtractContextAndIdentifier(name_cstr, context, basename))
3418 basename = name_cstr;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003419
Jim Inghamfa39bb42014-10-25 00:33:55 +00003420 m_apple_names_ap->FindByName (basename.data(), die_offsets);
Greg Clayton97fbc342011-10-20 22:30:33 +00003421 }
Greg Clayton7f995132011-10-04 22:41:51 +00003422 }
3423 else
3424 {
3425 // Index the DWARF if we haven't already
3426 if (!m_indexed)
3427 Index ();
3428
3429 m_global_index.Find (name, die_offsets);
3430 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003431
Greg Clayton437a1352012-04-09 22:43:43 +00003432 const size_t num_die_matches = die_offsets.size();
3433 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003434 {
Greg Clayton7f995132011-10-04 22:41:51 +00003435 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003436 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00003437 assert (sc.module_sp);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003438
Greg Claytond4a2b372011-09-12 23:21:58 +00003439 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00003440 DWARFCompileUnit* dwarf_cu = NULL;
3441 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton437a1352012-04-09 22:43:43 +00003442 bool done = false;
3443 for (size_t i=0; i<num_die_matches && !done; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00003444 {
3445 const dw_offset_t die_offset = die_offsets[i];
3446 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003447
Greg Clayton95d87902011-11-11 03:16:25 +00003448 if (die)
3449 {
Greg Clayton437a1352012-04-09 22:43:43 +00003450 switch (die->Tag())
3451 {
3452 default:
3453 case DW_TAG_subprogram:
3454 case DW_TAG_inlined_subroutine:
3455 case DW_TAG_try_block:
3456 case DW_TAG_catch_block:
3457 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003458
Greg Clayton437a1352012-04-09 22:43:43 +00003459 case DW_TAG_variable:
3460 {
3461 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003462
Greg Clayton437a1352012-04-09 22:43:43 +00003463 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3464 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003465
Greg Clayton437a1352012-04-09 22:43:43 +00003466 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003467
Greg Clayton437a1352012-04-09 22:43:43 +00003468 if (variables.GetSize() - original_size >= max_matches)
3469 done = true;
3470 }
3471 break;
3472 }
Greg Clayton95d87902011-11-11 03:16:25 +00003473 }
3474 else
3475 {
3476 if (m_using_apple_tables)
3477 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003478 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
3479 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003480 }
3481 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003482 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003483 }
3484
3485 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003486 const uint32_t num_matches = variables.GetSize() - original_size;
3487 if (log && num_matches > 0)
3488 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003489 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003490 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003491 name.GetCString(),
3492 static_cast<const void*>(namespace_decl),
3493 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00003494 num_matches);
3495 }
3496 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003497}
3498
3499uint32_t
3500SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
3501{
Greg Clayton5160ce52013-03-27 23:08:40 +00003502 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003503
Greg Clayton21f2a492011-10-06 00:09:08 +00003504 if (log)
3505 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003506 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003507 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003508 regex.GetText(), append,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003509 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003510 }
3511
Greg Claytonc685f8e2010-09-15 04:15:46 +00003512 DWARFDebugInfo* info = DebugInfo();
3513 if (info == NULL)
3514 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003515
3516 // If we aren't appending the results to this list, then clear the list
3517 if (!append)
3518 variables.Clear();
3519
3520 // Remember how many variables are in the list before we search in case
3521 // we are appending the results to a variable list.
3522 const uint32_t original_size = variables.GetSize();
3523
Greg Clayton7f995132011-10-04 22:41:51 +00003524 DIEArray die_offsets;
3525
Greg Clayton97fbc342011-10-20 22:30:33 +00003526 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003527 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003528 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00003529 {
3530 DWARFMappedHash::DIEInfoArray hash_data_array;
3531 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
3532 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
3533 }
Greg Clayton7f995132011-10-04 22:41:51 +00003534 }
3535 else
3536 {
3537 // Index the DWARF if we haven't already
3538 if (!m_indexed)
3539 Index ();
3540
3541 m_global_index.Find (regex, die_offsets);
3542 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003543
Greg Claytonc685f8e2010-09-15 04:15:46 +00003544 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003545 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003546 assert (sc.module_sp);
3547
Greg Claytond4a2b372011-09-12 23:21:58 +00003548 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00003549 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003550 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003551 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003552 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003553 DWARFDebugInfo* debug_info = DebugInfo();
3554 for (size_t i=0; i<num_matches; ++i)
3555 {
3556 const dw_offset_t die_offset = die_offsets[i];
3557 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00003558
3559 if (die)
3560 {
3561 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003562
Greg Clayton95d87902011-11-11 03:16:25 +00003563 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003564
Greg Clayton95d87902011-11-11 03:16:25 +00003565 if (variables.GetSize() - original_size >= max_matches)
3566 break;
3567 }
3568 else
3569 {
3570 if (m_using_apple_tables)
3571 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003572 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
3573 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00003574 }
3575 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003576 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003577 }
3578
3579 // Return the number of variable that were appended to the list
3580 return variables.GetSize() - original_size;
3581}
3582
Greg Claytonaa044962011-10-13 00:59:38 +00003583
Jim Ingham4cda6e02011-10-07 22:23:45 +00003584bool
3585SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
3586 DWARFCompileUnit *&dwarf_cu,
Pavel Labatha73d6572015-03-13 10:22:00 +00003587 bool include_inlines,
Jim Ingham4cda6e02011-10-07 22:23:45 +00003588 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00003589{
Greg Claytonaa044962011-10-13 00:59:38 +00003590 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Pavel Labatha73d6572015-03-13 10:22:00 +00003591 return ResolveFunction (dwarf_cu, die, include_inlines, sc_list);
Greg Claytonaa044962011-10-13 00:59:38 +00003592}
3593
3594
3595bool
3596SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
3597 const DWARFDebugInfoEntry *die,
Pavel Labatha73d6572015-03-13 10:22:00 +00003598 bool include_inlines,
Greg Claytonaa044962011-10-13 00:59:38 +00003599 SymbolContextList& sc_list)
3600{
Greg Clayton9e315582011-09-02 04:03:59 +00003601 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00003602
3603 if (die == NULL)
3604 return false;
3605
Jim Ingham4cda6e02011-10-07 22:23:45 +00003606 // If we were passed a die that is not a function, just return false...
Pavel Labatha73d6572015-03-13 10:22:00 +00003607 if (! (die->Tag() == DW_TAG_subprogram || (include_inlines && die->Tag() == DW_TAG_inlined_subroutine)))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003608 return false;
3609
3610 const DWARFDebugInfoEntry* inlined_die = NULL;
3611 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00003612 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003613 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00003614
Jim Ingham4cda6e02011-10-07 22:23:45 +00003615 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003616 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003617 if (die->Tag() == DW_TAG_subprogram)
3618 break;
Greg Clayton9e315582011-09-02 04:03:59 +00003619 }
3620 }
Jason Molenda60db6e42014-10-16 01:40:16 +00003621 assert (die && die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00003622 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003623 {
3624 Address addr;
3625 // Parse all blocks if needed
3626 if (inlined_die)
3627 {
Greg Claytonf7bb1fb2015-01-15 03:13:44 +00003628 Block &function_block = sc.function->GetBlock (true);
3629 sc.block = function_block.FindBlockByID (MakeUserID(inlined_die->GetOffset()));
3630 if (sc.block == NULL)
3631 sc.block = function_block.FindBlockByID (inlined_die->GetOffset());
3632 if (sc.block == NULL || sc.block->GetStartAddress (addr) == false)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003633 addr.Clear();
3634 }
3635 else
3636 {
3637 sc.block = NULL;
3638 addr = sc.function->GetAddressRange().GetBaseAddress();
3639 }
3640
3641 if (addr.IsValid())
3642 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003643 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00003644 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003645 }
3646 }
3647
Greg Claytonaa044962011-10-13 00:59:38 +00003648 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00003649}
3650
Greg Clayton7f995132011-10-04 22:41:51 +00003651void
3652SymbolFileDWARF::FindFunctions (const ConstString &name,
3653 const NameToDIE &name_to_die,
Pavel Labatha73d6572015-03-13 10:22:00 +00003654 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003655 SymbolContextList& sc_list)
3656{
Greg Claytond4a2b372011-09-12 23:21:58 +00003657 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003658 if (name_to_die.Find (name, die_offsets))
3659 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003660 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003661 }
3662}
3663
3664
3665void
3666SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3667 const NameToDIE &name_to_die,
Pavel Labatha73d6572015-03-13 10:22:00 +00003668 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003669 SymbolContextList& sc_list)
3670{
3671 DIEArray die_offsets;
3672 if (name_to_die.Find (regex, die_offsets))
3673 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003674 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003675 }
3676}
3677
3678
3679void
3680SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3681 const DWARFMappedHash::MemoryTable &memory_table,
Pavel Labatha73d6572015-03-13 10:22:00 +00003682 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003683 SymbolContextList& sc_list)
3684{
3685 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00003686 DWARFMappedHash::DIEInfoArray hash_data_array;
3687 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00003688 {
Greg Claytond1767f02011-12-08 02:13:16 +00003689 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Pavel Labatha73d6572015-03-13 10:22:00 +00003690 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003691 }
3692}
3693
3694void
3695SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
Pavel Labatha73d6572015-03-13 10:22:00 +00003696 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003697 SymbolContextList& sc_list)
3698{
3699 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003700 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00003701 {
Greg Clayton7f995132011-10-04 22:41:51 +00003702 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003703 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00003704 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003705 const dw_offset_t die_offset = die_offsets[i];
Pavel Labatha73d6572015-03-13 10:22:00 +00003706 ResolveFunction (die_offset, dwarf_cu, include_inlines, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003707 }
3708 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00003709}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003710
Jim Ingham4cda6e02011-10-07 22:23:45 +00003711bool
3712SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
3713 const DWARFCompileUnit *dwarf_cu,
3714 uint32_t name_type_mask,
3715 const char *partial_name,
3716 const char *base_name_start,
3717 const char *base_name_end)
3718{
Greg Claytonfbea0f62012-11-15 18:05:43 +00003719 // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes:
3720 if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003721 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003722 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
3723 if (!containing_decl_ctx)
3724 return false;
3725
3726 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
3727
Greg Claytonfbea0f62012-11-15 18:05:43 +00003728 if (name_type_mask == eFunctionNameTypeMethod)
3729 {
3730 if (is_cxx_method == false)
3731 return false;
3732 }
3733
3734 if (name_type_mask == eFunctionNameTypeBase)
3735 {
3736 if (is_cxx_method == true)
3737 return false;
3738 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003739 }
3740
3741 // Now we need to check whether the name we got back for this type matches the extra specifications
3742 // that were in the name we're looking up:
3743 if (base_name_start != partial_name || *base_name_end != '\0')
3744 {
3745 // First see if the stuff to the left matches the full name. To do that let's see if
3746 // we can pull out the mips linkage name attribute:
3747
3748 Mangled best_name;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003749 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonfbea0f62012-11-15 18:05:43 +00003750 DWARFFormValue form_value;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003751 die->GetAttributes(this, dwarf_cu, NULL, attributes);
3752 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
Greg Clayton71415542012-12-08 00:24:40 +00003753 if (idx == UINT32_MAX)
3754 idx = attributes.FindAttributeIndex(DW_AT_linkage_name);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003755 if (idx != UINT32_MAX)
3756 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003757 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
3758 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003759 const char *mangled_name = form_value.AsCString(&get_debug_str_data());
3760 if (mangled_name)
3761 best_name.SetValue (ConstString(mangled_name), true);
3762 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003763 }
Greg Claytonfbea0f62012-11-15 18:05:43 +00003764
3765 if (!best_name)
3766 {
3767 idx = attributes.FindAttributeIndex(DW_AT_name);
3768 if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value))
3769 {
3770 const char *name = form_value.AsCString(&get_debug_str_data());
3771 best_name.SetValue (ConstString(name), false);
3772 }
3773 }
3774
3775 if (best_name.GetDemangledName())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003776 {
3777 const char *demangled = best_name.GetDemangledName().GetCString();
3778 if (demangled)
3779 {
3780 std::string name_no_parens(partial_name, base_name_end - partial_name);
Jim Ingham85c13d72012-03-02 02:24:42 +00003781 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str());
3782 if (partial_in_demangled == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003783 return false;
Jim Ingham85c13d72012-03-02 02:24:42 +00003784 else
3785 {
3786 // Sort out the case where our name is something like "Process::Destroy" and the match is
3787 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on
3788 // namespace boundaries...
3789
3790 if (partial_name[0] == ':' && partial_name[1] == ':')
3791 {
3792 // The partial name was already on a namespace boundary so all matches are good.
3793 return true;
3794 }
3795 else if (partial_in_demangled == demangled)
3796 {
3797 // They both start the same, so this is an good match.
3798 return true;
3799 }
3800 else
3801 {
3802 if (partial_in_demangled - demangled == 1)
3803 {
3804 // Only one character difference, can't be a namespace boundary...
3805 return false;
3806 }
3807 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':')
3808 {
3809 // We are on a namespace boundary, so this is also good.
3810 return true;
3811 }
3812 else
3813 return false;
3814 }
3815 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003816 }
3817 }
3818 }
3819
3820 return true;
3821}
Greg Claytonc685f8e2010-09-15 04:15:46 +00003822
Greg Clayton0c5cd902010-06-28 21:30:43 +00003823uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00003824SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00003825 const lldb_private::ClangNamespaceDecl *namespace_decl,
Sean Callanan9df05fb2012-02-10 22:52:19 +00003826 uint32_t name_type_mask,
3827 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00003828 bool append,
3829 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00003830{
3831 Timer scoped_timer (__PRETTY_FUNCTION__,
3832 "SymbolFileDWARF::FindFunctions (name = '%s')",
3833 name.AsCString());
3834
Greg Clayton43fe2172013-04-03 02:00:15 +00003835 // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup()
3836 assert ((name_type_mask & eFunctionNameTypeAuto) == 0);
3837
Greg Clayton5160ce52013-03-27 23:08:40 +00003838 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003839
3840 if (log)
3841 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003842 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003843 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
3844 name.GetCString(),
3845 name_type_mask,
3846 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003847 }
3848
Greg Clayton0c5cd902010-06-28 21:30:43 +00003849 // If we aren't appending the results to this list, then clear the list
3850 if (!append)
3851 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003852
3853 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00003854 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003855
3856 // If name is empty then we won't find anything.
3857 if (name.IsEmpty())
3858 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00003859
3860 // Remember how many sc_list are in the list before we search in case
3861 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00003862
Jim Ingham4cda6e02011-10-07 22:23:45 +00003863 const char *name_cstr = name.GetCString();
Greg Clayton43fe2172013-04-03 02:00:15 +00003864
3865 const uint32_t original_size = sc_list.GetSize();
3866
Jim Ingham4cda6e02011-10-07 22:23:45 +00003867 DWARFDebugInfo* info = DebugInfo();
3868 if (info == NULL)
3869 return 0;
3870
Greg Claytonaa044962011-10-13 00:59:38 +00003871 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton43fe2172013-04-03 02:00:15 +00003872 std::set<const DWARFDebugInfoEntry *> resolved_dies;
Greg Clayton97fbc342011-10-20 22:30:33 +00003873 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00003874 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003875 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003876 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003877
3878 DIEArray die_offsets;
3879
3880 uint32_t num_matches = 0;
3881
Greg Clayton43fe2172013-04-03 02:00:15 +00003882 if (name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00003883 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003884 // If they asked for the full name, match what they typed. At some point we may
3885 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
3886 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00003887 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003888 for (uint32_t i = 0; i < num_matches; i++)
3889 {
Greg Clayton95d87902011-11-11 03:16:25 +00003890 const dw_offset_t die_offset = die_offsets[i];
3891 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00003892 if (die)
3893 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003894 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3895 continue;
3896
Greg Clayton43fe2172013-04-03 02:00:15 +00003897 if (resolved_dies.find(die) == resolved_dies.end())
3898 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003899 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00003900 resolved_dies.insert(die);
3901 }
Greg Claytonaa044962011-10-13 00:59:38 +00003902 }
Greg Clayton95d87902011-11-11 03:16:25 +00003903 else
3904 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003905 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3906 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003907 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003908 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003909 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003910
3911 if (name_type_mask & eFunctionNameTypeSelector)
3912 {
3913 if (namespace_decl && *namespace_decl)
3914 return 0; // no selectors in namespaces
Greg Clayton97fbc342011-10-20 22:30:33 +00003915
Greg Clayton43fe2172013-04-03 02:00:15 +00003916 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3917 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
3918 // and if it is an ObjC method name, we're good.
Greg Clayton97fbc342011-10-20 22:30:33 +00003919
Greg Clayton43fe2172013-04-03 02:00:15 +00003920 for (uint32_t i = 0; i < num_matches; i++)
Greg Clayton97fbc342011-10-20 22:30:33 +00003921 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003922 const dw_offset_t die_offset = die_offsets[i];
3923 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3924 if (die)
Greg Clayton97fbc342011-10-20 22:30:33 +00003925 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003926 const char *die_name = die->GetName(this, dwarf_cu);
3927 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
Greg Clayton97fbc342011-10-20 22:30:33 +00003928 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003929 if (resolved_dies.find(die) == resolved_dies.end())
3930 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003931 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00003932 resolved_dies.insert(die);
3933 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003934 }
3935 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003936 else
3937 {
3938 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3939 die_offset, name_cstr);
3940 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003941 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003942 die_offsets.clear();
3943 }
3944
3945 if (((name_type_mask & eFunctionNameTypeMethod) && !namespace_decl) || name_type_mask & eFunctionNameTypeBase)
3946 {
3947 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
3948 // extract the base name, look that up, and if there is any other information in the name we were
3949 // passed in we have to post-filter based on that.
3950
3951 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
3952 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3953
3954 for (uint32_t i = 0; i < num_matches; i++)
3955 {
3956 const dw_offset_t die_offset = die_offsets[i];
3957 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3958 if (die)
3959 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003960 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3961 continue;
3962
3963 // If we get to here, the die is good, and we should add it:
3964 if (resolved_dies.find(die) == resolved_dies.end())
Pavel Labatha73d6572015-03-13 10:22:00 +00003965 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00003966 {
3967 bool keep_die = true;
3968 if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod))
3969 {
3970 // We are looking for either basenames or methods, so we need to
3971 // trim out the ones we won't want by looking at the type
3972 SymbolContext sc;
3973 if (sc_list.GetLastContext(sc))
3974 {
3975 if (sc.block)
3976 {
3977 // We have an inlined function
3978 }
3979 else if (sc.function)
3980 {
3981 Type *type = sc.function->GetType();
3982
Sean Callananc370a8a2013-09-18 22:59:55 +00003983 if (type)
Greg Clayton43fe2172013-04-03 02:00:15 +00003984 {
Sean Callananc370a8a2013-09-18 22:59:55 +00003985 clang::DeclContext* decl_ctx = GetClangDeclContextContainingTypeUID (type->GetID());
3986 if (decl_ctx->isRecord())
Greg Clayton43fe2172013-04-03 02:00:15 +00003987 {
Sean Callananc370a8a2013-09-18 22:59:55 +00003988 if (name_type_mask & eFunctionNameTypeBase)
3989 {
3990 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3991 keep_die = false;
3992 }
3993 }
3994 else
3995 {
3996 if (name_type_mask & eFunctionNameTypeMethod)
3997 {
3998 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3999 keep_die = false;
4000 }
Greg Clayton43fe2172013-04-03 02:00:15 +00004001 }
4002 }
4003 else
4004 {
Sean Callananc370a8a2013-09-18 22:59:55 +00004005 GetObjectFile()->GetModule()->ReportWarning ("function at die offset 0x%8.8x had no function type",
4006 die_offset);
Greg Clayton43fe2172013-04-03 02:00:15 +00004007 }
4008 }
4009 }
4010 }
4011 if (keep_die)
4012 resolved_dies.insert(die);
4013 }
4014 }
4015 else
4016 {
4017 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
4018 die_offset, name_cstr);
4019 }
4020 }
4021 die_offsets.clear();
Jim Ingham4cda6e02011-10-07 22:23:45 +00004022 }
4023 }
Greg Clayton7f995132011-10-04 22:41:51 +00004024 }
4025 else
4026 {
4027
4028 // Index the DWARF if we haven't already
4029 if (!m_indexed)
4030 Index ();
4031
Greg Clayton7f995132011-10-04 22:41:51 +00004032 if (name_type_mask & eFunctionNameTypeFull)
Matt Kopecd6089962013-05-10 17:53:48 +00004033 {
Pavel Labatha73d6572015-03-13 10:22:00 +00004034 FindFunctions (name, m_function_fullname_index, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00004035
Ed Mastefc7baa02013-09-09 18:00:45 +00004036 // FIXME Temporary workaround for global/anonymous namespace
Robert Flack5cbd3bf2015-05-13 18:20:02 +00004037 // functions debugging FreeBSD and Linux binaries.
Matt Kopecd6089962013-05-10 17:53:48 +00004038 // If we didn't find any functions in the global namespace try
4039 // looking in the basename index but ignore any returned
Robert Flackeb83fab2015-05-15 18:59:59 +00004040 // functions that have a namespace but keep functions which
4041 // have an anonymous namespace
4042 // TODO: The arch in the object file isn't correct for MSVC
4043 // binaries on windows, we should find a way to make it
4044 // correct and handle those symbols as well.
Matt Kopecd6089962013-05-10 17:53:48 +00004045 if (sc_list.GetSize() == 0)
4046 {
Robert Flackeb83fab2015-05-15 18:59:59 +00004047 ArchSpec arch;
4048 if (!namespace_decl &&
4049 GetObjectFile()->GetArchitecture(arch) &&
4050 (arch.GetTriple().isOSFreeBSD() || arch.GetTriple().isOSLinux() ||
4051 arch.GetMachine() == llvm::Triple::hexagon))
Matt Kopecd6089962013-05-10 17:53:48 +00004052 {
Robert Flackeb83fab2015-05-15 18:59:59 +00004053 SymbolContextList temp_sc_list;
4054 FindFunctions (name, m_function_basename_index, include_inlines, temp_sc_list);
Matt Kopecd6089962013-05-10 17:53:48 +00004055 SymbolContext sc;
4056 for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++)
4057 {
4058 if (temp_sc_list.GetContextAtIndex(i, sc))
4059 {
Matt Kopeca189d492013-05-10 22:55:24 +00004060 ConstString mangled_name = sc.GetFunctionName(Mangled::ePreferMangled);
4061 ConstString demangled_name = sc.GetFunctionName(Mangled::ePreferDemangled);
Robert Flackeb83fab2015-05-15 18:59:59 +00004062 // Mangled names on Linux and FreeBSD are of the form:
4063 // _ZN18function_namespace13function_nameEv.
Matt Kopec04e5d582013-05-14 19:00:41 +00004064 if (strncmp(mangled_name.GetCString(), "_ZN", 3) ||
4065 !strncmp(demangled_name.GetCString(), "(anonymous namespace)", 21))
Matt Kopecd6089962013-05-10 17:53:48 +00004066 {
4067 sc_list.Append(sc);
4068 }
4069 }
4070 }
4071 }
4072 }
Matt Kopecd6089962013-05-10 17:53:48 +00004073 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00004074 DIEArray die_offsets;
4075 DWARFCompileUnit *dwarf_cu = NULL;
4076
Greg Clayton43fe2172013-04-03 02:00:15 +00004077 if (name_type_mask & eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00004078 {
Greg Clayton43fe2172013-04-03 02:00:15 +00004079 uint32_t num_base = m_function_basename_index.Find(name, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00004080 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00004081 {
Greg Claytonaa044962011-10-13 00:59:38 +00004082 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
4083 if (die)
4084 {
Sean Callanan213fdb82011-10-13 01:49:10 +00004085 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
4086 continue;
4087
Greg Claytonaa044962011-10-13 00:59:38 +00004088 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00004089 if (resolved_dies.find(die) == resolved_dies.end())
4090 {
Pavel Labatha73d6572015-03-13 10:22:00 +00004091 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00004092 resolved_dies.insert(die);
4093 }
Greg Claytonaa044962011-10-13 00:59:38 +00004094 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00004095 }
4096 die_offsets.clear();
4097 }
4098
Greg Clayton43fe2172013-04-03 02:00:15 +00004099 if (name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00004100 {
Sean Callanan213fdb82011-10-13 01:49:10 +00004101 if (namespace_decl && *namespace_decl)
4102 return 0; // no methods in namespaces
4103
Greg Clayton43fe2172013-04-03 02:00:15 +00004104 uint32_t num_base = m_function_method_index.Find(name, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00004105 {
Greg Claytonaa044962011-10-13 00:59:38 +00004106 for (uint32_t i = 0; i < num_base; i++)
4107 {
4108 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
4109 if (die)
4110 {
Greg Claytonaa044962011-10-13 00:59:38 +00004111 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00004112 if (resolved_dies.find(die) == resolved_dies.end())
4113 {
Pavel Labatha73d6572015-03-13 10:22:00 +00004114 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00004115 resolved_dies.insert(die);
4116 }
Greg Claytonaa044962011-10-13 00:59:38 +00004117 }
4118 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00004119 }
4120 die_offsets.clear();
4121 }
Greg Clayton7f995132011-10-04 22:41:51 +00004122
Greg Clayton43fe2172013-04-03 02:00:15 +00004123 if ((name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00004124 {
Pavel Labatha73d6572015-03-13 10:22:00 +00004125 FindFunctions (name, m_function_selector_index, include_inlines, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00004126 }
4127
Greg Clayton4d01ace2011-09-29 16:58:15 +00004128 }
4129
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004130 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00004131 const uint32_t num_matches = sc_list.GetSize() - original_size;
4132
4133 if (log && num_matches > 0)
4134 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004135 GetObjectFile()->GetModule()->LogMessage (log,
Pavel Labatha73d6572015-03-13 10:22:00 +00004136 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, include_inlines=%d, append=%u, sc_list) => %u",
Greg Clayton437a1352012-04-09 22:43:43 +00004137 name.GetCString(),
4138 name_type_mask,
Pavel Labatha73d6572015-03-13 10:22:00 +00004139 include_inlines,
Greg Clayton437a1352012-04-09 22:43:43 +00004140 append,
4141 num_matches);
4142 }
4143 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004144}
4145
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004146uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00004147SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004148{
4149 Timer scoped_timer (__PRETTY_FUNCTION__,
4150 "SymbolFileDWARF::FindFunctions (regex = '%s')",
4151 regex.GetText());
4152
Greg Clayton5160ce52013-03-27 23:08:40 +00004153 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00004154
4155 if (log)
4156 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004157 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00004158 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
4159 regex.GetText(),
4160 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00004161 }
4162
4163
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004164 // If we aren't appending the results to this list, then clear the list
4165 if (!append)
4166 sc_list.Clear();
4167
4168 // Remember how many sc_list are in the list before we search in case
4169 // we are appending the results to a variable list.
4170 uint32_t original_size = sc_list.GetSize();
4171
Greg Clayton97fbc342011-10-20 22:30:33 +00004172 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004173 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004174 if (m_apple_names_ap.get())
Pavel Labatha73d6572015-03-13 10:22:00 +00004175 FindFunctions (regex, *m_apple_names_ap, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00004176 }
4177 else
4178 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00004179 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00004180 if (!m_indexed)
4181 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004182
Pavel Labatha73d6572015-03-13 10:22:00 +00004183 FindFunctions (regex, m_function_basename_index, include_inlines, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004184
Pavel Labatha73d6572015-03-13 10:22:00 +00004185 FindFunctions (regex, m_function_fullname_index, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00004186 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004187
4188 // Return the number of variable that were appended to the list
4189 return sc_list.GetSize() - original_size;
4190}
Jim Ingham318c9f22011-08-26 19:44:13 +00004191
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004192uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00004193SymbolFileDWARF::FindTypes (const SymbolContext& sc,
4194 const ConstString &name,
4195 const lldb_private::ClangNamespaceDecl *namespace_decl,
4196 bool append,
4197 uint32_t max_matches,
4198 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004199{
Greg Claytonc685f8e2010-09-15 04:15:46 +00004200 DWARFDebugInfo* info = DebugInfo();
4201 if (info == NULL)
4202 return 0;
4203
Greg Clayton5160ce52013-03-27 23:08:40 +00004204 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004205
Greg Clayton21f2a492011-10-06 00:09:08 +00004206 if (log)
4207 {
Greg Clayton437a1352012-04-09 22:43:43 +00004208 if (namespace_decl)
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(%p) \"%s\", append=%u, max_matches=%u, type_list)",
4211 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004212 static_cast<void*>(namespace_decl->GetNamespaceDecl()),
Greg Clayton437a1352012-04-09 22:43:43 +00004213 namespace_decl->GetQualifiedName().c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004214 append, max_matches);
Greg Clayton437a1352012-04-09 22:43:43 +00004215 else
Greg Clayton5160ce52013-03-27 23:08:40 +00004216 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004217 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004218 name.GetCString(), append,
Greg Clayton437a1352012-04-09 22:43:43 +00004219 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00004220 }
4221
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004222 // If we aren't appending the results to this list, then clear the list
4223 if (!append)
4224 types.Clear();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004225
Sean Callanan213fdb82011-10-13 01:49:10 +00004226 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00004227 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004228
Greg Claytond4a2b372011-09-12 23:21:58 +00004229 DIEArray die_offsets;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004230
Greg Clayton97fbc342011-10-20 22:30:33 +00004231 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004232 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004233 if (m_apple_types_ap.get())
4234 {
4235 const char *name_cstr = name.GetCString();
4236 m_apple_types_ap->FindByName (name_cstr, die_offsets);
4237 }
Greg Clayton7f995132011-10-04 22:41:51 +00004238 }
4239 else
4240 {
4241 if (!m_indexed)
4242 Index ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004243
Greg Clayton7f995132011-10-04 22:41:51 +00004244 m_type_index.Find (name, die_offsets);
4245 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004246
Greg Clayton437a1352012-04-09 22:43:43 +00004247 const size_t num_die_matches = die_offsets.size();
Greg Clayton7f995132011-10-04 22:41:51 +00004248
Greg Clayton437a1352012-04-09 22:43:43 +00004249 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004250 {
Greg Clayton7f995132011-10-04 22:41:51 +00004251 const uint32_t initial_types_size = types.GetSize();
4252 DWARFCompileUnit* dwarf_cu = NULL;
4253 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00004254 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00004255 for (size_t i=0; i<num_die_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004256 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004257 const dw_offset_t die_offset = die_offsets[i];
4258 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
4259
Greg Clayton95d87902011-11-11 03:16:25 +00004260 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00004261 {
Greg Clayton95d87902011-11-11 03:16:25 +00004262 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
4263 continue;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004264
Greg Clayton95d87902011-11-11 03:16:25 +00004265 Type *matching_type = ResolveType (dwarf_cu, die);
4266 if (matching_type)
4267 {
4268 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00004269 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00004270 if (types.GetSize() >= max_matches)
4271 break;
4272 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00004273 }
Greg Clayton95d87902011-11-11 03:16:25 +00004274 else
4275 {
4276 if (m_using_apple_tables)
4277 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004278 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4279 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004280 }
4281 }
4282
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004283 }
Greg Clayton437a1352012-04-09 22:43:43 +00004284 const uint32_t num_matches = types.GetSize() - initial_types_size;
4285 if (log && num_matches)
4286 {
4287 if (namespace_decl)
4288 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004289 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004290 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u",
4291 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004292 static_cast<void*>(namespace_decl->GetNamespaceDecl()),
Greg Clayton437a1352012-04-09 22:43:43 +00004293 namespace_decl->GetQualifiedName().c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004294 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00004295 num_matches);
4296 }
4297 else
4298 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004299 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004300 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u",
4301 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004302 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00004303 num_matches);
4304 }
4305 }
4306 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004307 }
Greg Clayton7f995132011-10-04 22:41:51 +00004308 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004309}
4310
4311
Greg Clayton526e5af2010-11-13 03:52:47 +00004312ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00004313SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00004314 const ConstString &name,
4315 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004316{
Greg Clayton5160ce52013-03-27 23:08:40 +00004317 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00004318
4319 if (log)
4320 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004321 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00004322 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
4323 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00004324 }
Sean Callanan213fdb82011-10-13 01:49:10 +00004325
4326 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00004327 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00004328
Greg Clayton526e5af2010-11-13 03:52:47 +00004329 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004330 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00004331 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00004332 {
Greg Clayton7f995132011-10-04 22:41:51 +00004333 DIEArray die_offsets;
4334
Greg Clayton526e5af2010-11-13 03:52:47 +00004335 // Index if we already haven't to make sure the compile units
4336 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00004337 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004338 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004339 if (m_apple_namespaces_ap.get())
4340 {
4341 const char *name_cstr = name.GetCString();
4342 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
4343 }
Greg Clayton7f995132011-10-04 22:41:51 +00004344 }
4345 else
4346 {
4347 if (!m_indexed)
4348 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00004349
Greg Clayton7f995132011-10-04 22:41:51 +00004350 m_namespace_index.Find (name, die_offsets);
4351 }
Greg Claytond4a2b372011-09-12 23:21:58 +00004352
4353 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00004354 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00004355 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00004356 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00004357 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004358 DWARFDebugInfo* debug_info = DebugInfo();
4359 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00004360 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004361 const dw_offset_t die_offset = die_offsets[i];
4362 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00004363
Greg Clayton95d87902011-11-11 03:16:25 +00004364 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00004365 {
Greg Clayton95d87902011-11-11 03:16:25 +00004366 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
4367 continue;
4368
4369 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
4370 if (clang_namespace_decl)
4371 {
4372 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
4373 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
Greg Claytond1767f02011-12-08 02:13:16 +00004374 break;
Greg Clayton95d87902011-11-11 03:16:25 +00004375 }
Greg Claytond4a2b372011-09-12 23:21:58 +00004376 }
Greg Clayton95d87902011-11-11 03:16:25 +00004377 else
4378 {
4379 if (m_using_apple_tables)
4380 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004381 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
4382 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004383 }
4384 }
4385
Greg Clayton526e5af2010-11-13 03:52:47 +00004386 }
4387 }
Greg Clayton96d7d742010-11-10 23:42:09 +00004388 }
Greg Clayton437a1352012-04-09 22:43:43 +00004389 if (log && namespace_decl.GetNamespaceDecl())
4390 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004391 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004392 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"",
4393 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004394 static_cast<const void*>(namespace_decl.GetNamespaceDecl()),
Greg Clayton437a1352012-04-09 22:43:43 +00004395 namespace_decl.GetQualifiedName().c_str());
4396 }
4397
Greg Clayton526e5af2010-11-13 03:52:47 +00004398 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004399}
4400
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004401uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004402SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004403{
4404 // Remember how many sc_list are in the list before we search in case
4405 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004406 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004407
4408 const uint32_t num_die_offsets = die_offsets.size();
4409 // Parse all of the types we found from the pubtypes matches
4410 uint32_t i;
4411 uint32_t num_matches = 0;
4412 for (i = 0; i < num_die_offsets; ++i)
4413 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004414 Type *matching_type = ResolveTypeUID (die_offsets[i]);
4415 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004416 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004417 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00004418 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004419 ++num_matches;
4420 if (num_matches >= max_matches)
4421 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004422 }
4423 }
4424
4425 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004426 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004427}
4428
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004429
4430size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00004431SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
4432 clang::DeclContext *containing_decl_ctx,
Greg Clayton5113dc82011-08-12 06:47:54 +00004433 DWARFCompileUnit* dwarf_cu,
4434 const DWARFDebugInfoEntry *parent_die,
4435 bool skip_artificial,
4436 bool &is_static,
Greg Clayton03969752014-02-24 18:53:11 +00004437 bool &is_variadic,
Greg Clayton57ee3062013-07-11 22:46:58 +00004438 std::vector<ClangASTType>& function_param_types,
Greg Clayton5113dc82011-08-12 06:47:54 +00004439 std::vector<clang::ParmVarDecl*>& function_param_decls,
Greg Claytond20deac2014-04-04 18:15:18 +00004440 unsigned &type_quals) // ,
4441 // ClangASTContext::TemplateParameterInfos &template_param_infos))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004442{
4443 if (parent_die == NULL)
4444 return 0;
4445
Todd Fialaee8bfc62014-09-11 17:29:12 +00004446 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Claytond88d7592010-09-15 08:33:30 +00004447
Greg Clayton7fedea22010-11-16 02:10:54 +00004448 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004449 const DWARFDebugInfoEntry *die;
4450 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4451 {
4452 dw_tag_t tag = die->Tag();
4453 switch (tag)
4454 {
4455 case DW_TAG_formal_parameter:
4456 {
4457 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004458 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004459 if (num_attributes > 0)
4460 {
4461 const char *name = NULL;
4462 Declaration decl;
4463 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00004464 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004465 // one of None, Auto, Register, Extern, Static, PrivateExtern
4466
Sean Callanane2ef6e32010-09-23 03:01:22 +00004467 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004468 uint32_t i;
4469 for (i=0; i<num_attributes; ++i)
4470 {
4471 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4472 DWARFFormValue form_value;
4473 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4474 {
4475 switch (attr)
4476 {
4477 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4478 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4479 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4480 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00004481 case DW_AT_type: param_type_die_offset = form_value.Reference(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00004482 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004483 case DW_AT_location:
4484 // if (form_value.BlockData())
4485 // {
Ed Masteeeae7212013-10-24 20:43:47 +00004486 // const DWARFDataExtractor& debug_info_data = debug_info();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004487 // uint32_t block_length = form_value.Unsigned();
Ed Masteeeae7212013-10-24 20:43:47 +00004488 // DWARFDataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004489 // }
4490 // else
4491 // {
4492 // }
4493 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004494 case DW_AT_const_value:
4495 case DW_AT_default_value:
4496 case DW_AT_description:
4497 case DW_AT_endianity:
4498 case DW_AT_is_optional:
4499 case DW_AT_segment:
4500 case DW_AT_variable_parameter:
4501 default:
4502 case DW_AT_abstract_origin:
4503 case DW_AT_sibling:
4504 break;
4505 }
4506 }
4507 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00004508
Greg Clayton0fffff52010-09-24 05:15:53 +00004509 bool skip = false;
4510 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004511 {
Greg Clayton0fffff52010-09-24 05:15:53 +00004512 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00004513 {
4514 // In order to determine if a C++ member function is
4515 // "const" we have to look at the const-ness of "this"...
4516 // Ugly, but that
4517 if (arg_idx == 0)
4518 {
Greg Claytonf0705c82011-10-22 03:33:13 +00004519 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00004520 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004521 // Often times compilers omit the "this" name for the
4522 // specification DIEs, so we can't rely upon the name
4523 // being in the formal parameter DIE...
4524 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00004525 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004526 Type *this_type = ResolveTypeUID (param_type_die_offset);
4527 if (this_type)
4528 {
4529 uint32_t encoding_mask = this_type->GetEncodingMask();
4530 if (encoding_mask & Type::eEncodingIsPointerUID)
4531 {
4532 is_static = false;
4533
4534 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
4535 type_quals |= clang::Qualifiers::Const;
4536 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
4537 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00004538 }
4539 }
4540 }
4541 }
4542 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004543 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00004544 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004545 else
4546 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004547
Greg Clayton0fffff52010-09-24 05:15:53 +00004548 // HACK: Objective C formal parameters "self" and "_cmd"
4549 // are not marked as artificial in the DWARF...
Greg Clayton53eb1c22012-04-02 22:59:12 +00004550 CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
4551 if (comp_unit)
Greg Clayton0fffff52010-09-24 05:15:53 +00004552 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004553 switch (comp_unit->GetLanguage())
4554 {
4555 case eLanguageTypeObjC:
4556 case eLanguageTypeObjC_plus_plus:
4557 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
4558 skip = true;
4559 break;
4560 default:
4561 break;
4562 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004563 }
4564 }
4565 }
4566
4567 if (!skip)
4568 {
4569 Type *type = ResolveTypeUID(param_type_die_offset);
4570 if (type)
4571 {
Greg Claytonc93237c2010-10-01 20:48:32 +00004572 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00004573
Greg Clayton42ce2f32011-12-12 21:50:19 +00004574 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
4575 type->GetClangForwardType(),
4576 storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00004577 assert(param_var_decl);
4578 function_param_decls.push_back(param_var_decl);
Sean Callanan60217122012-04-13 00:10:03 +00004579
Greg Claytond0029442013-03-27 01:48:02 +00004580 GetClangASTContext().SetMetadataAsUserID (param_var_decl, MakeUserID(die->GetOffset()));
Greg Clayton0fffff52010-09-24 05:15:53 +00004581 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004582 }
4583 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004584 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004585 }
4586 break;
4587
Greg Clayton03969752014-02-24 18:53:11 +00004588 case DW_TAG_unspecified_parameters:
4589 is_variadic = true;
4590 break;
4591
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004592 case DW_TAG_template_type_parameter:
4593 case DW_TAG_template_value_parameter:
Greg Claytond20deac2014-04-04 18:15:18 +00004594 // The one caller of this was never using the template_param_infos,
4595 // and the local variable was taking up a large amount of stack space
4596 // in SymbolFileDWARF::ParseType() so this was removed. If we ever need
4597 // the template params back, we can add them back.
4598 // ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004599 break;
4600
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004601 default:
4602 break;
4603 }
4604 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004605 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004606}
4607
4608size_t
4609SymbolFileDWARF::ParseChildEnumerators
4610(
4611 const SymbolContext& sc,
Greg Clayton57ee3062013-07-11 22:46:58 +00004612 lldb_private::ClangASTType &clang_type,
Greg Clayton3e067532013-03-05 23:54:39 +00004613 bool is_signed,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004614 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00004615 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004616 const DWARFDebugInfoEntry *parent_die
4617)
4618{
4619 if (parent_die == NULL)
4620 return 0;
4621
4622 size_t enumerators_added = 0;
4623 const DWARFDebugInfoEntry *die;
Todd Fialaee8bfc62014-09-11 17:29:12 +00004624 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Claytond88d7592010-09-15 08:33:30 +00004625
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004626 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4627 {
4628 const dw_tag_t tag = die->Tag();
4629 if (tag == DW_TAG_enumerator)
4630 {
4631 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004632 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004633 if (num_child_attributes > 0)
4634 {
4635 const char *name = NULL;
4636 bool got_value = false;
4637 int64_t enum_value = 0;
4638 Declaration decl;
4639
4640 uint32_t i;
4641 for (i=0; i<num_child_attributes; ++i)
4642 {
4643 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4644 DWARFFormValue form_value;
4645 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4646 {
4647 switch (attr)
4648 {
4649 case DW_AT_const_value:
4650 got_value = true;
Greg Clayton3e067532013-03-05 23:54:39 +00004651 if (is_signed)
4652 enum_value = form_value.Signed();
4653 else
4654 enum_value = form_value.Unsigned();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004655 break;
4656
4657 case DW_AT_name:
4658 name = form_value.AsCString(&get_debug_str_data());
4659 break;
4660
4661 case DW_AT_description:
4662 default:
4663 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4664 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4665 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4666 case DW_AT_sibling:
4667 break;
4668 }
4669 }
4670 }
4671
4672 if (name && name[0] && got_value)
4673 {
Greg Clayton57ee3062013-07-11 22:46:58 +00004674 clang_type.AddEnumerationValueToEnumerationType (clang_type.GetEnumerationIntegerType(),
4675 decl,
4676 name,
4677 enum_value,
4678 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004679 ++enumerators_added;
4680 }
4681 }
4682 }
4683 }
4684 return enumerators_added;
4685}
4686
4687void
4688SymbolFileDWARF::ParseChildArrayInfo
4689(
4690 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004691 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004692 const DWARFDebugInfoEntry *parent_die,
4693 int64_t& first_index,
4694 std::vector<uint64_t>& element_orders,
4695 uint32_t& byte_stride,
4696 uint32_t& bit_stride
4697)
4698{
4699 if (parent_die == NULL)
4700 return;
4701
4702 const DWARFDebugInfoEntry *die;
Todd Fialaee8bfc62014-09-11 17:29:12 +00004703 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004704 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4705 {
4706 const dw_tag_t tag = die->Tag();
4707 switch (tag)
4708 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004709 case DW_TAG_subrange_type:
4710 {
4711 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004712 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004713 if (num_child_attributes > 0)
4714 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004715 uint64_t num_elements = 0;
4716 uint64_t lower_bound = 0;
4717 uint64_t upper_bound = 0;
Greg Clayton4ef877f2012-12-06 02:33:54 +00004718 bool upper_bound_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004719 uint32_t i;
4720 for (i=0; i<num_child_attributes; ++i)
4721 {
4722 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4723 DWARFFormValue form_value;
4724 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4725 {
4726 switch (attr)
4727 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004728 case DW_AT_name:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004729 break;
4730
4731 case DW_AT_count:
4732 num_elements = form_value.Unsigned();
4733 break;
4734
4735 case DW_AT_bit_stride:
4736 bit_stride = form_value.Unsigned();
4737 break;
4738
4739 case DW_AT_byte_stride:
4740 byte_stride = form_value.Unsigned();
4741 break;
4742
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004743 case DW_AT_lower_bound:
4744 lower_bound = form_value.Unsigned();
4745 break;
4746
4747 case DW_AT_upper_bound:
Greg Clayton4ef877f2012-12-06 02:33:54 +00004748 upper_bound_valid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004749 upper_bound = form_value.Unsigned();
4750 break;
4751
4752 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004753 case DW_AT_abstract_origin:
4754 case DW_AT_accessibility:
4755 case DW_AT_allocated:
4756 case DW_AT_associated:
4757 case DW_AT_data_location:
4758 case DW_AT_declaration:
4759 case DW_AT_description:
4760 case DW_AT_sibling:
4761 case DW_AT_threads_scaled:
4762 case DW_AT_type:
4763 case DW_AT_visibility:
4764 break;
4765 }
4766 }
4767 }
4768
Greg Claytone6a07792012-12-05 21:59:39 +00004769 if (num_elements == 0)
4770 {
Greg Clayton4ef877f2012-12-06 02:33:54 +00004771 if (upper_bound_valid && upper_bound >= lower_bound)
Greg Claytone6a07792012-12-05 21:59:39 +00004772 num_elements = upper_bound - lower_bound + 1;
4773 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004774
Sean Callananec979ba2012-10-22 23:56:48 +00004775 element_orders.push_back (num_elements);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004776 }
4777 }
4778 break;
4779 }
4780 }
4781}
4782
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004783TypeSP
Greg Clayton53eb1c22012-04-02 22:59:12 +00004784SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004785{
4786 TypeSP type_sp;
4787 if (die != NULL)
4788 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004789 assert(dwarf_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00004790 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004791 if (type_ptr == NULL)
4792 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004793 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu);
Greg Claytonca512b32011-01-14 04:54:56 +00004794 assert (lldb_cu);
4795 SymbolContext sc(lldb_cu);
Greg Clayton53eb1c22012-04-02 22:59:12 +00004796 type_sp = ParseType(sc, dwarf_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004797 }
4798 else if (type_ptr != DIE_IS_BEING_PARSED)
4799 {
4800 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00004801 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004802 }
4803
4804 }
4805 return type_sp;
4806}
4807
4808clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00004809SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004810{
4811 if (die_offset != DW_INVALID_OFFSET)
4812 {
4813 DWARFCompileUnitSP cu_sp;
4814 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004815 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004816 }
4817 return NULL;
4818}
4819
Sean Callanan72e49402011-08-05 23:43:37 +00004820clang::DeclContext *
4821SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
4822{
4823 if (die_offset != DW_INVALID_OFFSET)
4824 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004825 DWARFDebugInfo* debug_info = DebugInfo();
4826 if (debug_info)
4827 {
4828 DWARFCompileUnitSP cu_sp;
4829 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
4830 if (die)
4831 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
4832 }
Sean Callanan72e49402011-08-05 23:43:37 +00004833 }
4834 return NULL;
4835}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004836
Greg Clayton96d7d742010-11-10 23:42:09 +00004837clang::NamespaceDecl *
Greg Clayton53eb1c22012-04-02 22:59:12 +00004838SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die)
Greg Clayton96d7d742010-11-10 23:42:09 +00004839{
Greg Clayton030a2042011-10-14 21:34:45 +00004840 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00004841 {
Greg Clayton030a2042011-10-14 21:34:45 +00004842 // See if we already parsed this namespace DIE and associated it with a
4843 // uniqued namespace declaration
4844 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
4845 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004846 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00004847 else
4848 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004849 const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL);
4850 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00004851 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
Greg Clayton5160ce52013-03-27 23:08:40 +00004852 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton9d3d6882011-10-31 23:51:19 +00004853 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00004854 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00004855 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00004856 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004857 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00004858 "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 +00004859 static_cast<void*>(GetClangASTContext().getASTContext()),
Greg Claytone38a5ed2012-01-05 03:57:59 +00004860 MakeUserID(die->GetOffset()),
4861 namespace_name,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004862 static_cast<void*>(namespace_decl),
4863 static_cast<void*>(namespace_decl->getOriginalNamespace()));
Greg Clayton030a2042011-10-14 21:34:45 +00004864 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004865 else
4866 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004867 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00004868 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004869 static_cast<void*>(GetClangASTContext().getASTContext()),
Greg Claytone38a5ed2012-01-05 03:57:59 +00004870 MakeUserID(die->GetOffset()),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004871 static_cast<void*>(namespace_decl),
4872 static_cast<void*>(namespace_decl->getOriginalNamespace()));
Greg Clayton9d3d6882011-10-31 23:51:19 +00004873 }
Greg Clayton030a2042011-10-14 21:34:45 +00004874 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004875
4876 if (namespace_decl)
4877 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
4878 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004879 }
4880 }
4881 return NULL;
4882}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004883
4884clang::DeclContext *
Greg Claytoncab36a32011-12-08 05:16:30 +00004885SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Sean Callanan72e49402011-08-05 23:43:37 +00004886{
Greg Clayton5cf58b92011-10-05 22:22:08 +00004887 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4888 if (clang_decl_ctx)
4889 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004890 // If this DIE has a specification, or an abstract origin, then trace to those.
4891
Greg Claytoncab36a32011-12-08 05:16:30 +00004892 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004893 if (die_offset != DW_INVALID_OFFSET)
4894 return GetClangDeclContextForDIEOffset (sc, die_offset);
4895
Greg Claytoncab36a32011-12-08 05:16:30 +00004896 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004897 if (die_offset != DW_INVALID_OFFSET)
4898 return GetClangDeclContextForDIEOffset (sc, die_offset);
4899
Greg Clayton5160ce52013-03-27 23:08:40 +00004900 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00004901 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004902 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 +00004903 // This is the DIE we want. Parse it, then query our map.
Greg Claytoncab36a32011-12-08 05:16:30 +00004904 bool assert_not_being_parsed = true;
4905 ResolveTypeUID (cu, die, assert_not_being_parsed);
4906
Greg Clayton5cf58b92011-10-05 22:22:08 +00004907 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4908
4909 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004910}
4911
4912clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00004913SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004914{
Greg Claytonca512b32011-01-14 04:54:56 +00004915 if (m_clang_tu_decl == NULL)
4916 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004917
Greg Clayton2bc22f82011-09-30 03:20:47 +00004918 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004919
4920 if (decl_ctx_die_copy)
4921 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00004922
4923 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004924 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00004925
Greg Clayton2bc22f82011-09-30 03:20:47 +00004926 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
4927 if (pos != m_die_to_decl_ctx.end())
4928 return pos->second;
4929
4930 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004931 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004932 case DW_TAG_compile_unit:
4933 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004934
Greg Clayton2bc22f82011-09-30 03:20:47 +00004935 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00004936 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00004937 break;
4938
4939 case DW_TAG_structure_type:
4940 case DW_TAG_union_type:
4941 case DW_TAG_class_type:
4942 {
4943 Type* type = ResolveType (cu, decl_ctx_die);
4944 if (type)
4945 {
Greg Clayton57ee3062013-07-11 22:46:58 +00004946 clang::DeclContext *decl_ctx = type->GetClangForwardType().GetDeclContextForType ();
Greg Clayton2bc22f82011-09-30 03:20:47 +00004947 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00004948 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004949 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
4950 if (decl_ctx)
4951 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00004952 }
4953 }
Greg Claytonca512b32011-01-14 04:54:56 +00004954 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00004955 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004956
Greg Clayton2bc22f82011-09-30 03:20:47 +00004957 default:
4958 break;
Greg Claytonca512b32011-01-14 04:54:56 +00004959 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004960 }
Greg Clayton7a345282010-11-09 23:46:37 +00004961 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004962}
4963
Greg Clayton2bc22f82011-09-30 03:20:47 +00004964
4965const DWARFDebugInfoEntry *
4966SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4967{
4968 if (cu && die)
4969 {
4970 const DWARFDebugInfoEntry * const decl_die = die;
4971
4972 while (die != NULL)
4973 {
4974 // If this is the original DIE that we are searching for a declaration
4975 // for, then don't look in the cache as we don't want our own decl
4976 // context to be our decl context...
4977 if (decl_die != die)
4978 {
4979 switch (die->Tag())
4980 {
4981 case DW_TAG_compile_unit:
4982 case DW_TAG_namespace:
4983 case DW_TAG_structure_type:
4984 case DW_TAG_union_type:
4985 case DW_TAG_class_type:
4986 return die;
4987
4988 default:
4989 break;
4990 }
4991 }
4992
4993 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4994 if (die_offset != DW_INVALID_OFFSET)
4995 {
4996 DWARFCompileUnit *spec_cu = cu;
4997 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
4998 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
4999 if (spec_die_decl_ctx_die)
5000 return spec_die_decl_ctx_die;
5001 }
5002
5003 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
5004 if (die_offset != DW_INVALID_OFFSET)
5005 {
5006 DWARFCompileUnit *abs_cu = cu;
5007 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
5008 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
5009 if (abs_die_decl_ctx_die)
5010 return abs_die_decl_ctx_die;
5011 }
5012
5013 die = die->GetParent();
5014 }
5015 }
5016 return NULL;
5017}
5018
5019
Greg Clayton901c5ca2011-12-03 04:40:03 +00005020Symbol *
5021SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
5022{
5023 Symbol *objc_class_symbol = NULL;
5024 if (m_obj_file)
5025 {
Greg Clayton3046e662013-07-10 01:23:25 +00005026 Symtab *symtab = m_obj_file->GetSymtab ();
Greg Clayton901c5ca2011-12-03 04:40:03 +00005027 if (symtab)
5028 {
5029 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
5030 eSymbolTypeObjCClass,
5031 Symtab::eDebugNo,
5032 Symtab::eVisibilityAny);
5033 }
5034 }
5035 return objc_class_symbol;
5036}
5037
Greg Claytonc7f03b62012-01-12 04:33:28 +00005038// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
5039// then we can end up looking through all class types for a complete type and never find
5040// the full definition. We need to know if this attribute is supported, so we determine
5041// this here and cache th result. We also need to worry about the debug map DWARF file
5042// if we are doing darwin DWARF in .o file debugging.
5043bool
5044SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
5045{
5046 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
5047 {
5048 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
5049 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
5050 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
5051 else
5052 {
5053 DWARFDebugInfo* debug_info = DebugInfo();
5054 const uint32_t num_compile_units = GetNumCompileUnits();
5055 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
5056 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00005057 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
5058 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00005059 {
5060 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
5061 break;
5062 }
5063 }
5064 }
Greg Clayton1f746072012-08-29 21:13:06 +00005065 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00005066 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
5067 }
5068 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
5069}
Greg Clayton901c5ca2011-12-03 04:40:03 +00005070
5071// This function can be used when a DIE is found that is a forward declaration
5072// DIE and we want to try and find a type that has the complete definition.
5073TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00005074SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
5075 const ConstString &type_name,
5076 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00005077{
5078
5079 TypeSP type_sp;
5080
Greg Claytonc7f03b62012-01-12 04:33:28 +00005081 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00005082 return type_sp;
5083
5084 DIEArray die_offsets;
5085
5086 if (m_using_apple_tables)
5087 {
5088 if (m_apple_types_ap.get())
5089 {
5090 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00005091 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00005092 }
5093 }
5094 else
5095 {
5096 if (!m_indexed)
5097 Index ();
5098
5099 m_type_index.Find (type_name, die_offsets);
5100 }
5101
Greg Clayton901c5ca2011-12-03 04:40:03 +00005102 const size_t num_matches = die_offsets.size();
5103
Greg Clayton901c5ca2011-12-03 04:40:03 +00005104 DWARFCompileUnit* type_cu = NULL;
5105 const DWARFDebugInfoEntry* type_die = NULL;
5106 if (num_matches)
5107 {
5108 DWARFDebugInfo* debug_info = DebugInfo();
5109 for (size_t i=0; i<num_matches; ++i)
5110 {
5111 const dw_offset_t die_offset = die_offsets[i];
5112 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
5113
5114 if (type_die)
5115 {
5116 bool try_resolving_type = false;
5117
5118 // Don't try and resolve the DIE we are looking for with the DIE itself!
5119 if (type_die != die)
5120 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005121 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00005122 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005123 case DW_TAG_class_type:
5124 case DW_TAG_structure_type:
5125 try_resolving_type = true;
5126 break;
5127 default:
5128 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00005129 }
5130 }
5131
5132 if (try_resolving_type)
5133 {
Ed Maste4c24b122013-10-17 20:13:14 +00005134 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
5135 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00005136
5137 if (try_resolving_type)
5138 {
5139 Type *resolved_type = ResolveType (type_cu, type_die, false);
5140 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5141 {
Ed Mastea0191d12013-10-17 20:42:56 +00005142 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 +00005143 MakeUserID(die->GetOffset()),
Jim Ingham4af59612014-12-19 19:20:44 +00005144 m_obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>"),
Greg Clayton901c5ca2011-12-03 04:40:03 +00005145 MakeUserID(type_die->GetOffset()),
5146 MakeUserID(type_cu->GetOffset()));
5147
Greg Claytonc7f03b62012-01-12 04:33:28 +00005148 if (die)
5149 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00005150 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00005151 break;
5152 }
5153 }
5154 }
5155 }
5156 else
5157 {
5158 if (m_using_apple_tables)
5159 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005160 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5161 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00005162 }
5163 }
5164
5165 }
5166 }
5167 return type_sp;
5168}
5169
Greg Claytona8022fa2012-04-24 21:22:41 +00005170
Greg Clayton80c26302012-02-05 06:12:47 +00005171//----------------------------------------------------------------------
5172// This function helps to ensure that the declaration contexts match for
5173// two different DIEs. Often times debug information will refer to a
5174// forward declaration of a type (the equivalent of "struct my_struct;".
5175// There will often be a declaration of that type elsewhere that has the
5176// full definition. When we go looking for the full type "my_struct", we
5177// will find one or more matches in the accelerator tables and we will
5178// then need to make sure the type was in the same declaration context
5179// as the original DIE. This function can efficiently compare two DIEs
5180// and will return true when the declaration context matches, and false
5181// when they don't.
5182//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00005183bool
5184SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
5185 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
5186{
Greg Claytona8022fa2012-04-24 21:22:41 +00005187 if (die1 == die2)
5188 return true;
5189
5190#if defined (LLDB_CONFIGURATION_DEBUG)
5191 // You can't and shouldn't call this function with a compile unit from
5192 // two different SymbolFileDWARF instances.
5193 assert (DebugInfo()->ContainsCompileUnit (cu1));
5194 assert (DebugInfo()->ContainsCompileUnit (cu2));
5195#endif
5196
Greg Clayton890ff562012-02-02 05:48:16 +00005197 DWARFDIECollection decl_ctx_1;
5198 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00005199 //The declaration DIE stack is a stack of the declaration context
5200 // DIEs all the way back to the compile unit. If a type "T" is
5201 // declared inside a class "B", and class "B" is declared inside
5202 // a class "A" and class "A" is in a namespace "lldb", and the
5203 // namespace is in a compile unit, there will be a stack of DIEs:
5204 //
5205 // [0] DW_TAG_class_type for "B"
5206 // [1] DW_TAG_class_type for "A"
5207 // [2] DW_TAG_namespace for "lldb"
5208 // [3] DW_TAG_compile_unit for the source file.
5209 //
5210 // We grab both contexts and make sure that everything matches
5211 // all the way back to the compiler unit.
5212
5213 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00005214 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00005215 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00005216 // Make sure the context arrays have the same size, otherwise
5217 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00005218 const size_t count1 = decl_ctx_1.Size();
5219 const size_t count2 = decl_ctx_2.Size();
5220 if (count1 != count2)
5221 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00005222
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00005223 // Make sure the DW_TAG values match all the way back up the
Greg Clayton80c26302012-02-05 06:12:47 +00005224 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00005225 const DWARFDebugInfoEntry *decl_ctx_die1;
5226 const DWARFDebugInfoEntry *decl_ctx_die2;
5227 size_t i;
5228 for (i=0; i<count1; i++)
5229 {
5230 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
5231 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
5232 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
5233 return false;
5234 }
Greg Clayton890ff562012-02-02 05:48:16 +00005235#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00005236
5237 // Make sure the top item in the decl context die array is always
5238 // DW_TAG_compile_unit. If it isn't then something went wrong in
5239 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00005240 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00005241
Greg Clayton890ff562012-02-02 05:48:16 +00005242#endif
5243 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00005244 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00005245 for (i=0; i<count1 - 1; i++)
5246 {
5247 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
5248 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
5249 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00005250 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00005251 // If the string was from a DW_FORM_strp, then the pointer will often
5252 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00005253 if (name1 == name2)
5254 continue;
5255
5256 // Name pointers are not equal, so only compare the strings
5257 // if both are not NULL.
5258 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00005259 {
Greg Clayton5569e642012-02-06 01:44:54 +00005260 // If the strings don't compare, we are done...
5261 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00005262 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00005263 }
5264 else
5265 {
5266 // One name was NULL while the other wasn't
5267 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00005268 }
5269 }
Greg Clayton80c26302012-02-05 06:12:47 +00005270 // We made it through all of the checks and the declaration contexts
5271 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00005272 return true;
5273}
Greg Clayton220a0072011-12-09 08:48:30 +00005274
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005275
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005276TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00005277SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx)
5278{
5279 TypeSP type_sp;
5280
5281 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
5282 if (dwarf_decl_ctx_count > 0)
5283 {
5284 const ConstString type_name(dwarf_decl_ctx[0].name);
5285 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
5286
5287 if (type_name)
5288 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005289 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
Greg Claytona8022fa2012-04-24 21:22:41 +00005290 if (log)
5291 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005292 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005293 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')",
5294 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5295 dwarf_decl_ctx.GetQualifiedName());
5296 }
5297
5298 DIEArray die_offsets;
5299
5300 if (m_using_apple_tables)
5301 {
5302 if (m_apple_types_ap.get())
5303 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005304 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
5305 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
5306 if (has_tag && has_qualified_name_hash)
Greg Claytona8022fa2012-04-24 21:22:41 +00005307 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005308 const char *qualified_name = dwarf_decl_ctx.GetQualifiedName();
5309 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name);
5310 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005311 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005312 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets);
5313 }
5314 else if (has_tag)
5315 {
5316 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005317 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
Greg Claytona8022fa2012-04-24 21:22:41 +00005318 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets);
5319 }
5320 else
5321 {
5322 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
5323 }
5324 }
5325 }
5326 else
5327 {
5328 if (!m_indexed)
5329 Index ();
5330
5331 m_type_index.Find (type_name, die_offsets);
5332 }
5333
5334 const size_t num_matches = die_offsets.size();
5335
5336
5337 DWARFCompileUnit* type_cu = NULL;
5338 const DWARFDebugInfoEntry* type_die = NULL;
5339 if (num_matches)
5340 {
5341 DWARFDebugInfo* debug_info = DebugInfo();
5342 for (size_t i=0; i<num_matches; ++i)
5343 {
5344 const dw_offset_t die_offset = die_offsets[i];
5345 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
5346
5347 if (type_die)
5348 {
5349 bool try_resolving_type = false;
5350
5351 // Don't try and resolve the DIE we are looking for with the DIE itself!
5352 const dw_tag_t type_tag = type_die->Tag();
5353 // Make sure the tags match
5354 if (type_tag == tag)
5355 {
5356 // The tags match, lets try resolving this type
5357 try_resolving_type = true;
5358 }
5359 else
5360 {
5361 // The tags don't match, but we need to watch our for a
5362 // forward declaration for a struct and ("struct foo")
5363 // ends up being a class ("class foo { ... };") or
5364 // vice versa.
5365 switch (type_tag)
5366 {
5367 case DW_TAG_class_type:
5368 // We had a "class foo", see if we ended up with a "struct foo { ... };"
5369 try_resolving_type = (tag == DW_TAG_structure_type);
5370 break;
5371 case DW_TAG_structure_type:
5372 // We had a "struct foo", see if we ended up with a "class foo { ... };"
5373 try_resolving_type = (tag == DW_TAG_class_type);
5374 break;
5375 default:
5376 // Tags don't match, don't event try to resolve
5377 // using this type whose name matches....
5378 break;
5379 }
5380 }
5381
5382 if (try_resolving_type)
5383 {
5384 DWARFDeclContext type_dwarf_decl_ctx;
5385 type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx);
5386
5387 if (log)
5388 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005389 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005390 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)",
5391 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5392 dwarf_decl_ctx.GetQualifiedName(),
5393 type_die->GetOffset(),
5394 type_dwarf_decl_ctx.GetQualifiedName());
5395 }
5396
5397 // Make sure the decl contexts match all the way up
5398 if (dwarf_decl_ctx == type_dwarf_decl_ctx)
5399 {
5400 Type *resolved_type = ResolveType (type_cu, type_die, false);
5401 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5402 {
5403 type_sp = resolved_type->shared_from_this();
5404 break;
5405 }
5406 }
5407 }
5408 else
5409 {
5410 if (log)
5411 {
5412 std::string qualified_name;
5413 type_die->GetQualifiedName(this, type_cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00005414 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005415 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)",
5416 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5417 dwarf_decl_ctx.GetQualifiedName(),
5418 type_die->GetOffset(),
5419 qualified_name.c_str());
5420 }
5421 }
5422 }
5423 else
5424 {
5425 if (m_using_apple_tables)
5426 {
5427 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5428 die_offset, type_name.GetCString());
5429 }
5430 }
5431
5432 }
5433 }
5434 }
5435 }
5436 return type_sp;
5437}
5438
Greg Clayton4116e932012-05-15 02:33:01 +00005439bool
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005440SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005441 Type *class_type,
Greg Clayton4116e932012-05-15 02:33:01 +00005442 DWARFCompileUnit* src_cu,
5443 const DWARFDebugInfoEntry *src_class_die,
5444 DWARFCompileUnit* dst_cu,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005445 const DWARFDebugInfoEntry *dst_class_die,
Greg Claytond20deac2014-04-04 18:15:18 +00005446 DWARFDIECollection &failures)
Greg Clayton4116e932012-05-15 02:33:01 +00005447{
5448 if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die)
5449 return false;
5450 if (src_class_die->Tag() != dst_class_die->Tag())
5451 return false;
5452
5453 // We need to complete the class type so we can get all of the method types
5454 // parsed so we can then unique those types to their equivalent counterparts
5455 // in "dst_cu" and "dst_class_die"
5456 class_type->GetClangFullType();
5457
5458 const DWARFDebugInfoEntry *src_die;
5459 const DWARFDebugInfoEntry *dst_die;
5460 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die;
5461 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die;
Greg Clayton65ec1032012-11-12 21:27:20 +00005462 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial;
5463 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial;
Greg Clayton4116e932012-05-15 02:33:01 +00005464 for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling())
5465 {
5466 if (src_die->Tag() == DW_TAG_subprogram)
5467 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005468 // Make sure this is a declaration and not a concrete instance by looking
5469 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5470 // are placed inside the class definitions and shouldn't be included in
5471 // the list of things are are tracking here.
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005472 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_declaration, 0) == 1)
Greg Clayton84afacd2012-11-07 23:09:32 +00005473 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005474 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton84afacd2012-11-07 23:09:32 +00005475 if (src_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005476 {
5477 ConstString src_const_name(src_name);
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005478 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0))
Greg Clayton65ec1032012-11-12 21:27:20 +00005479 src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die);
5480 else
5481 src_name_to_die.Append(src_const_name.GetCString(), src_die);
5482 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005483 }
Greg Clayton4116e932012-05-15 02:33:01 +00005484 }
5485 }
5486 for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling())
5487 {
5488 if (dst_die->Tag() == DW_TAG_subprogram)
5489 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005490 // Make sure this is a declaration and not a concrete instance by looking
5491 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5492 // are placed inside the class definitions and shouldn't be included in
5493 // the list of things are are tracking here.
5494 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1)
5495 {
5496 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5497 if (dst_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005498 {
5499 ConstString dst_const_name(dst_name);
5500 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0))
5501 dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die);
5502 else
5503 dst_name_to_die.Append(dst_const_name.GetCString(), dst_die);
5504 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005505 }
Greg Clayton4116e932012-05-15 02:33:01 +00005506 }
5507 }
5508 const uint32_t src_size = src_name_to_die.GetSize ();
5509 const uint32_t dst_size = dst_name_to_die.GetSize ();
Greg Clayton5160ce52013-03-27 23:08:40 +00005510 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005511
5512 // Is everything kosher so we can go through the members at top speed?
5513 bool fast_path = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005514
Sean Callanan2367f8a2013-02-26 01:12:25 +00005515 if (src_size != dst_size)
Greg Clayton4116e932012-05-15 02:33:01 +00005516 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005517 if (src_size != 0 && dst_size != 0)
5518 {
5519 if (log)
5520 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)",
5521 src_class_die->GetOffset(),
5522 dst_class_die->GetOffset(),
5523 src_size,
5524 dst_size);
5525 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005526
Sean Callanan2367f8a2013-02-26 01:12:25 +00005527 fast_path = false;
5528 }
5529
5530 uint32_t idx;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005531
Sean Callanan2367f8a2013-02-26 01:12:25 +00005532 if (fast_path)
5533 {
Greg Clayton4116e932012-05-15 02:33:01 +00005534 for (idx = 0; idx < src_size; ++idx)
5535 {
5536 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5537 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5538
5539 if (src_die->Tag() != dst_die->Tag())
5540 {
5541 if (log)
5542 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)",
5543 src_class_die->GetOffset(),
5544 dst_class_die->GetOffset(),
5545 src_die->GetOffset(),
5546 DW_TAG_value_to_name(src_die->Tag()),
5547 dst_die->GetOffset(),
5548 DW_TAG_value_to_name(src_die->Tag()));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005549 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005550 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005551
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005552 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton4116e932012-05-15 02:33:01 +00005553 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005554
Greg Clayton4116e932012-05-15 02:33:01 +00005555 // Make sure the names match
5556 if (src_name == dst_name || (strcmp (src_name, dst_name) == 0))
5557 continue;
5558
5559 if (log)
5560 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)",
5561 src_class_die->GetOffset(),
5562 dst_class_die->GetOffset(),
5563 src_die->GetOffset(),
5564 src_name,
5565 dst_die->GetOffset(),
5566 dst_name);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005567
Sean Callanan2367f8a2013-02-26 01:12:25 +00005568 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005569 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005570 }
Greg Clayton4116e932012-05-15 02:33:01 +00005571
Sean Callanan2367f8a2013-02-26 01:12:25 +00005572 // Now do the work of linking the DeclContexts and Types.
5573 if (fast_path)
5574 {
5575 // We can do this quickly. Just run across the tables index-for-index since
5576 // we know each node has matching names and tags.
Greg Clayton4116e932012-05-15 02:33:01 +00005577 for (idx = 0; idx < src_size; ++idx)
5578 {
5579 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5580 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005581
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005582 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Greg Clayton4116e932012-05-15 02:33:01 +00005583 if (src_decl_ctx)
5584 {
5585 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005586 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
5587 static_cast<void*>(src_decl_ctx),
5588 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005589 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5590 }
5591 else
5592 {
5593 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005594 log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found",
5595 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005596 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005597
Greg Clayton4116e932012-05-15 02:33:01 +00005598 Type *src_child_type = m_die_to_type[src_die];
5599 if (src_child_type)
5600 {
5601 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005602 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
5603 static_cast<void*>(src_child_type),
5604 src_child_type->GetID(),
5605 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005606 m_die_to_type[dst_die] = src_child_type;
5607 }
5608 else
5609 {
5610 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005611 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());
5612 }
5613 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005614 }
5615 else
5616 {
5617 // We must do this slowly. For each member of the destination, look
5618 // up a member in the source with the same name, check its tag, and
5619 // unique them if everything matches up. Report failures.
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005620
Sean Callanan2367f8a2013-02-26 01:12:25 +00005621 if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty())
5622 {
5623 src_name_to_die.Sort();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005624
Sean Callanan2367f8a2013-02-26 01:12:25 +00005625 for (idx = 0; idx < dst_size; ++idx)
5626 {
5627 const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx);
5628 dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
5629 src_die = src_name_to_die.Find(dst_name, NULL);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005630
Sean Callanan2367f8a2013-02-26 01:12:25 +00005631 if (src_die && (src_die->Tag() == dst_die->Tag()))
5632 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005633 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Sean Callanan2367f8a2013-02-26 01:12:25 +00005634 if (src_decl_ctx)
5635 {
5636 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005637 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
5638 static_cast<void*>(src_decl_ctx),
5639 src_die->GetOffset(),
5640 dst_die->GetOffset());
Sean Callanan2367f8a2013-02-26 01:12:25 +00005641 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5642 }
5643 else
5644 {
5645 if (log)
5646 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());
5647 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005648
Sean Callanan2367f8a2013-02-26 01:12:25 +00005649 Type *src_child_type = m_die_to_type[src_die];
5650 if (src_child_type)
5651 {
5652 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005653 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
5654 static_cast<void*>(src_child_type),
5655 src_child_type->GetID(),
5656 src_die->GetOffset(),
5657 dst_die->GetOffset());
Sean Callanan2367f8a2013-02-26 01:12:25 +00005658 m_die_to_type[dst_die] = src_child_type;
5659 }
5660 else
5661 {
5662 if (log)
5663 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());
5664 }
5665 }
5666 else
5667 {
5668 if (log)
5669 log->Printf ("warning: couldn't find a match for 0x%8.8x", dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005670
Greg Claytond20deac2014-04-04 18:15:18 +00005671 failures.Append(dst_die);
Sean Callanan2367f8a2013-02-26 01:12:25 +00005672 }
5673 }
5674 }
5675 }
5676
5677 const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize ();
5678 const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize ();
5679
5680 UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src;
5681
5682 if (src_size_artificial && dst_size_artificial)
5683 {
5684 dst_name_to_die_artificial.Sort();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005685
Greg Clayton65ec1032012-11-12 21:27:20 +00005686 for (idx = 0; idx < src_size_artificial; ++idx)
5687 {
5688 const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx);
5689 src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5690 dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005691
Greg Clayton65ec1032012-11-12 21:27:20 +00005692 if (dst_die)
5693 {
Greg Clayton65ec1032012-11-12 21:27:20 +00005694 // Both classes have the artificial types, link them
5695 clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die];
5696 if (src_decl_ctx)
5697 {
5698 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005699 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
5700 static_cast<void*>(src_decl_ctx),
5701 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005702 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5703 }
5704 else
5705 {
5706 if (log)
5707 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());
5708 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005709
Greg Clayton65ec1032012-11-12 21:27:20 +00005710 Type *src_child_type = m_die_to_type[src_die];
5711 if (src_child_type)
5712 {
5713 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005714 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
5715 static_cast<void*>(src_child_type),
5716 src_child_type->GetID(),
5717 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005718 m_die_to_type[dst_die] = src_child_type;
5719 }
5720 else
5721 {
5722 if (log)
5723 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());
5724 }
5725 }
5726 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005727 }
Greg Clayton65ec1032012-11-12 21:27:20 +00005728
Sean Callanan2367f8a2013-02-26 01:12:25 +00005729 if (dst_size_artificial)
Greg Clayton4116e932012-05-15 02:33:01 +00005730 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005731 for (idx = 0; idx < dst_size_artificial; ++idx)
5732 {
5733 const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx);
5734 dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5735 if (log)
5736 log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial);
5737
Greg Claytond20deac2014-04-04 18:15:18 +00005738 failures.Append(dst_die);
Sean Callanan2367f8a2013-02-26 01:12:25 +00005739 }
Greg Clayton4116e932012-05-15 02:33:01 +00005740 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005741
Greg Claytond20deac2014-04-04 18:15:18 +00005742 return (failures.Size() != 0);
Greg Clayton4116e932012-05-15 02:33:01 +00005743}
Greg Claytona8022fa2012-04-24 21:22:41 +00005744
5745TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00005746SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005747{
5748 TypeSP type_sp;
5749
Greg Clayton1be10fc2010-09-29 01:12:09 +00005750 if (type_is_new_ptr)
5751 *type_is_new_ptr = false;
Greg Clayton1fba87112012-02-09 20:03:49 +00005752
Todd Fiala0a70a842014-05-28 16:43:26 +00005753#if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE)
Greg Clayton1fba87112012-02-09 20:03:49 +00005754 static DIEStack g_die_stack;
5755 DIEStack::ScopedPopper scoped_die_logger(g_die_stack);
5756#endif
Greg Clayton1be10fc2010-09-29 01:12:09 +00005757
Sean Callananc7fbf732010-08-06 00:32:49 +00005758 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005759 if (die != NULL)
5760 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005761 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005762 if (log)
Sean Callanan5b26f272012-02-04 08:49:35 +00005763 {
5764 const DWARFDebugInfoEntry *context_die;
5765 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005766
Greg Clayton5160ce52013-03-27 23:08:40 +00005767 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 +00005768 die->GetOffset(),
5769 static_cast<void*>(context),
5770 context_die->GetOffset(),
5771 DW_TAG_value_to_name(die->Tag()),
5772 die->GetName(this, dwarf_cu));
5773
Todd Fiala0a70a842014-05-28 16:43:26 +00005774#if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE)
Greg Clayton1fba87112012-02-09 20:03:49 +00005775 scoped_die_logger.Push (dwarf_cu, die);
Greg Clayton5160ce52013-03-27 23:08:40 +00005776 g_die_stack.LogDIEs(log, this);
Greg Clayton1fba87112012-02-09 20:03:49 +00005777#endif
Sean Callanan5b26f272012-02-04 08:49:35 +00005778 }
Greg Clayton3bffb082011-12-10 02:15:28 +00005779//
Greg Clayton5160ce52013-03-27 23:08:40 +00005780// Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005781// if (log && dwarf_cu)
5782// {
5783// StreamString s;
5784// die->DumpLocation (this, dwarf_cu, s);
Greg Clayton5160ce52013-03-27 23:08:40 +00005785// GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Greg Clayton3bffb082011-12-10 02:15:28 +00005786//
5787// }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005788
Greg Clayton594e5ed2010-09-27 21:07:38 +00005789 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005790 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00005791 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005792 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005793 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00005794 if (type_is_new_ptr)
5795 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005796
Greg Clayton594e5ed2010-09-27 21:07:38 +00005797 const dw_tag_t tag = die->Tag();
5798
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005799 bool is_forward_declaration = false;
5800 DWARFDebugInfoEntry::Attributes attributes;
5801 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00005802 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00005803 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
Greg Claytonfaac1112013-03-14 18:31:44 +00005804 uint64_t byte_size = 0;
Greg Clayton526e5af2010-11-13 03:52:47 +00005805 Declaration decl;
5806
Greg Clayton4957bf62010-09-30 21:49:03 +00005807 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton57ee3062013-07-11 22:46:58 +00005808 ClangASTType clang_type;
Greg Claytond20deac2014-04-04 18:15:18 +00005809 DWARFFormValue form_value;
5810
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005811 dw_attr_t attr;
5812
5813 switch (tag)
5814 {
5815 case DW_TAG_base_type:
5816 case DW_TAG_pointer_type:
5817 case DW_TAG_reference_type:
Sean Callanance8af862012-05-21 23:31:51 +00005818 case DW_TAG_rvalue_reference_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005819 case DW_TAG_typedef:
5820 case DW_TAG_const_type:
5821 case DW_TAG_restrict_type:
5822 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00005823 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005824 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005825 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005826 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005827
Greg Claytond88d7592010-09-15 08:33:30 +00005828 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005829 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005830 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
5831
5832 if (num_attributes > 0)
5833 {
5834 uint32_t i;
5835 for (i=0; i<num_attributes; ++i)
5836 {
5837 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005838 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5839 {
5840 switch (attr)
5841 {
5842 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5843 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5844 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5845 case DW_AT_name:
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005846
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005847 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00005848 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
5849 // include the "&"...
5850 if (tag == DW_TAG_reference_type)
5851 {
5852 if (strchr (type_name_cstr, '&') == NULL)
5853 type_name_cstr = NULL;
5854 }
5855 if (type_name_cstr)
5856 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005857 break;
Greg Clayton23f59502012-07-17 03:23:13 +00005858 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005859 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
Greg Clayton54166af2014-11-22 01:58:59 +00005860 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005861 default:
5862 case DW_AT_sibling:
5863 break;
5864 }
5865 }
5866 }
5867 }
5868
Ed Mastea0191d12013-10-17 20:42:56 +00005869 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 +00005870
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005871 switch (tag)
5872 {
5873 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00005874 break;
5875
Greg Claytond4436412011-10-28 21:00:00 +00005876 case DW_TAG_unspecified_type:
Greg Clayton7fba2632013-07-01 21:01:52 +00005877 if (strcmp(type_name_cstr, "nullptr_t") == 0 ||
5878 strcmp(type_name_cstr, "decltype(nullptr)") == 0 )
Greg Claytond4436412011-10-28 21:00:00 +00005879 {
5880 resolve_state = Type::eResolveStateFull;
Greg Clayton57ee3062013-07-11 22:46:58 +00005881 clang_type = ast.GetBasicType(eBasicTypeNullPtr);
Greg Claytond4436412011-10-28 21:00:00 +00005882 break;
5883 }
5884 // Fall through to base type below in case we can handle the type there...
5885
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005886 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00005887 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005888 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
5889 encoding,
5890 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005891 break;
5892
Sean Callanance8af862012-05-21 23:31:51 +00005893 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
5894 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
5895 case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break;
5896 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
5897 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
5898 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
5899 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005900 }
5901
Greg Clayton57ee3062013-07-11 22:46:58 +00005902 if (!clang_type && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID) && sc.comp_unit != NULL)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005903 {
Sean Callanan82587052013-01-03 00:05:56 +00005904 bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005905
Sean Callanan82587052013-01-03 00:05:56 +00005906 if (translation_unit_is_objc)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005907 {
Sean Callanan82587052013-01-03 00:05:56 +00005908 if (type_name_cstr != NULL)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005909 {
Sean Callanan82587052013-01-03 00:05:56 +00005910 static ConstString g_objc_type_name_id("id");
5911 static ConstString g_objc_type_name_Class("Class");
5912 static ConstString g_objc_type_name_selector("SEL");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005913
Sean Callanan82587052013-01-03 00:05:56 +00005914 if (type_name_const_str == g_objc_type_name_id)
5915 {
5916 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005917 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 +00005918 die->GetOffset(),
5919 DW_TAG_value_to_name(die->Tag()),
5920 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005921 clang_type = ast.GetBasicType(eBasicTypeObjCID);
Sean Callanan82587052013-01-03 00:05:56 +00005922 encoding_data_type = Type::eEncodingIsUID;
5923 encoding_uid = LLDB_INVALID_UID;
5924 resolve_state = Type::eResolveStateFull;
Greg Clayton526e5af2010-11-13 03:52:47 +00005925
Sean Callanan82587052013-01-03 00:05:56 +00005926 }
5927 else if (type_name_const_str == g_objc_type_name_Class)
5928 {
5929 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005930 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 +00005931 die->GetOffset(),
5932 DW_TAG_value_to_name(die->Tag()),
5933 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005934 clang_type = ast.GetBasicType(eBasicTypeObjCClass);
Sean Callanan82587052013-01-03 00:05:56 +00005935 encoding_data_type = Type::eEncodingIsUID;
5936 encoding_uid = LLDB_INVALID_UID;
5937 resolve_state = Type::eResolveStateFull;
5938 }
5939 else if (type_name_const_str == g_objc_type_name_selector)
5940 {
5941 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005942 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 +00005943 die->GetOffset(),
5944 DW_TAG_value_to_name(die->Tag()),
5945 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005946 clang_type = ast.GetBasicType(eBasicTypeObjCSel);
Sean Callanan82587052013-01-03 00:05:56 +00005947 encoding_data_type = Type::eEncodingIsUID;
5948 encoding_uid = LLDB_INVALID_UID;
5949 resolve_state = Type::eResolveStateFull;
5950 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005951 }
Sean Callanan82587052013-01-03 00:05:56 +00005952 else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005953 {
Sean Callanan82587052013-01-03 00:05:56 +00005954 // 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 +00005955
Sean Callanan82587052013-01-03 00:05:56 +00005956 DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005957
Sean Callanan82587052013-01-03 00:05:56 +00005958 if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005959 {
Sean Callanan82587052013-01-03 00:05:56 +00005960 if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL))
5961 {
5962 if (!strcmp(struct_name, "objc_object"))
5963 {
5964 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005965 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 +00005966 die->GetOffset(),
5967 DW_TAG_value_to_name(die->Tag()),
5968 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00005969 clang_type = ast.GetBasicType(eBasicTypeObjCID);
Sean Callanan82587052013-01-03 00:05:56 +00005970 encoding_data_type = Type::eEncodingIsUID;
5971 encoding_uid = LLDB_INVALID_UID;
5972 resolve_state = Type::eResolveStateFull;
5973 }
5974 }
5975 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005976 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005977 }
5978 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005979
Greg Clayton81c22f62011-10-19 18:09:39 +00005980 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005981 this,
5982 type_name_const_str,
5983 byte_size,
5984 NULL,
5985 encoding_uid,
5986 encoding_data_type,
5987 &decl,
5988 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005989 resolve_state));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005990
Greg Clayton594e5ed2010-09-27 21:07:38 +00005991 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005992
5993// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
5994// if (encoding_type != NULL)
5995// {
5996// if (encoding_type != DIE_IS_BEING_PARSED)
5997// type_sp->SetEncodingType(encoding_type);
5998// else
5999// m_indirect_fixups.push_back(type_sp.get());
6000// }
6001 }
6002 break;
6003
6004 case DW_TAG_structure_type:
6005 case DW_TAG_union_type:
6006 case DW_TAG_class_type:
6007 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006008 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006009 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Greg Clayton23f59502012-07-17 03:23:13 +00006010 bool byte_size_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006011
Greg Clayton9e409562010-07-28 02:04:09 +00006012 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00006013 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006014 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00006015 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006016 if (num_attributes > 0)
6017 {
6018 uint32_t i;
6019 for (i=0; i<num_attributes; ++i)
6020 {
6021 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006022 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6023 {
6024 switch (attr)
6025 {
Greg Clayton9e409562010-07-28 02:04:09 +00006026 case DW_AT_decl_file:
Greg Claytonc7f03b62012-01-12 04:33:28 +00006027 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
Ed Maste4c24b122013-10-17 20:13:14 +00006028 {
6029 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
6030 // point to the compile unit file, so we clear this invalid value
6031 // so that we can still unique types efficiently.
Greg Claytonc7f03b62012-01-12 04:33:28 +00006032 decl.SetFile(FileSpec ("<invalid>", false));
Ed Maste4c24b122013-10-17 20:13:14 +00006033 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00006034 else
6035 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
Greg Clayton9e409562010-07-28 02:04:09 +00006036 break;
6037
6038 case DW_AT_decl_line:
6039 decl.SetLine(form_value.Unsigned());
6040 break;
6041
6042 case DW_AT_decl_column:
6043 decl.SetColumn(form_value.Unsigned());
6044 break;
6045
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006046 case DW_AT_name:
6047 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006048 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006049 break;
Greg Clayton9e409562010-07-28 02:04:09 +00006050
6051 case DW_AT_byte_size:
6052 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00006053 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00006054 break;
6055
6056 case DW_AT_accessibility:
6057 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
6058 break;
6059
6060 case DW_AT_declaration:
Greg Clayton1c8ef472013-04-05 23:27:21 +00006061 is_forward_declaration = form_value.Boolean();
Greg Clayton9e409562010-07-28 02:04:09 +00006062 break;
6063
6064 case DW_AT_APPLE_runtime_class:
6065 class_language = (LanguageType)form_value.Signed();
6066 break;
6067
Greg Clayton18774842011-11-29 23:40:34 +00006068 case DW_AT_APPLE_objc_complete_type:
6069 is_complete_objc_class = form_value.Signed();
6070 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006071
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006072 case DW_AT_allocated:
6073 case DW_AT_associated:
6074 case DW_AT_data_location:
6075 case DW_AT_description:
6076 case DW_AT_start_scope:
6077 case DW_AT_visibility:
6078 default:
6079 case DW_AT_sibling:
6080 break;
6081 }
6082 }
6083 }
6084 }
Greg Claytond20deac2014-04-04 18:15:18 +00006085
6086 // UniqueDWARFASTType is large, so don't create a local variables on the
6087 // stack, put it on the heap. This function is often called recursively
6088 // and clang isn't good and sharing the stack space for variables in different blocks.
6089 std::unique_ptr<UniqueDWARFASTType> unique_ast_entry_ap(new UniqueDWARFASTType());
Sean Callanan8e8072d2012-02-07 21:13:38 +00006090
Greg Clayton123edca2012-03-02 00:07:15 +00006091 // Only try and unique the type if it has a name.
6092 if (type_name_const_str &&
6093 GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Sean Callanan8e8072d2012-02-07 21:13:38 +00006094 this,
6095 dwarf_cu,
6096 die,
6097 decl,
6098 byte_size_valid ? byte_size : -1,
Greg Claytond20deac2014-04-04 18:15:18 +00006099 *unique_ast_entry_ap))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006100 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00006101 // We have already parsed this type or from another
6102 // compile unit. GCC loves to use the "one definition
6103 // rule" which can result in multiple definitions
6104 // of the same class over and over in each compile
6105 // unit.
Greg Claytond20deac2014-04-04 18:15:18 +00006106 type_sp = unique_ast_entry_ap->m_type_sp;
Sean Callanan8e8072d2012-02-07 21:13:38 +00006107 if (type_sp)
Greg Claytonc615ce42010-11-09 04:42:43 +00006108 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00006109 m_die_to_type[die] = type_sp.get();
6110 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00006111 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006112 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006113
Daniel Malead01b2952012-11-29 21:49:15 +00006114 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 +00006115
6116 int tag_decl_kind = -1;
6117 AccessType default_accessibility = eAccessNone;
6118 if (tag == DW_TAG_structure_type)
6119 {
6120 tag_decl_kind = clang::TTK_Struct;
6121 default_accessibility = eAccessPublic;
6122 }
6123 else if (tag == DW_TAG_union_type)
6124 {
6125 tag_decl_kind = clang::TTK_Union;
6126 default_accessibility = eAccessPublic;
6127 }
6128 else if (tag == DW_TAG_class_type)
6129 {
6130 tag_decl_kind = clang::TTK_Class;
6131 default_accessibility = eAccessPrivate;
6132 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006133
Greg Clayton3a5f29a2011-11-30 02:48:28 +00006134 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
6135 die->HasChildren() == false &&
6136 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
6137 {
6138 // Work around an issue with clang at the moment where
6139 // forward declarations for objective C classes are emitted
6140 // as:
6141 // DW_TAG_structure_type [2]
6142 // DW_AT_name( "ForwardObjcClass" )
6143 // DW_AT_byte_size( 0x00 )
6144 // DW_AT_decl_file( "..." )
6145 // DW_AT_decl_line( 1 )
6146 //
6147 // Note that there is no DW_AT_declaration and there are
6148 // no children, and the byte size is zero.
6149 is_forward_declaration = true;
6150 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006151
Sean Callanan7457f8d2012-04-25 01:03:57 +00006152 if (class_language == eLanguageTypeObjC ||
6153 class_language == eLanguageTypeObjC_plus_plus)
Greg Clayton18774842011-11-29 23:40:34 +00006154 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00006155 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
Greg Clayton901c5ca2011-12-03 04:40:03 +00006156 {
6157 // We have a valid eSymbolTypeObjCClass class symbol whose
6158 // name matches the current objective C class that we
6159 // are trying to find and this DIE isn't the complete
6160 // definition (we checked is_complete_objc_class above and
6161 // know it is false), so the real definition is in here somewhere
Greg Claytonc7f03b62012-01-12 04:33:28 +00006162 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006163
Greg Clayton1f746072012-08-29 21:13:06 +00006164 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton901c5ca2011-12-03 04:40:03 +00006165 {
6166 // We weren't able to find a full declaration in
6167 // this DWARF, see if we have a declaration anywhere
6168 // else...
Greg Claytonc7f03b62012-01-12 04:33:28 +00006169 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00006170 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006171
Greg Clayton901c5ca2011-12-03 04:40:03 +00006172 if (type_sp)
6173 {
6174 if (log)
6175 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006176 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00006177 "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 +00006178 static_cast<void*>(this),
Greg Claytone38a5ed2012-01-05 03:57:59 +00006179 die->GetOffset(),
6180 DW_TAG_value_to_name(tag),
6181 type_name_cstr,
6182 type_sp->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00006183 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006184
Greg Clayton901c5ca2011-12-03 04:40:03 +00006185 // We found a real definition for this type elsewhere
6186 // so lets use it and cache the fact that we found
6187 // a complete type for this die
6188 m_die_to_type[die] = type_sp.get();
6189 return type_sp;
6190 }
6191 }
6192 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006193
Greg Clayton901c5ca2011-12-03 04:40:03 +00006194
6195 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006196 {
6197 // We have a forward declaration to a type and we need
6198 // to try and find a full declaration. We look in the
6199 // current type index just in case we have a forward
6200 // declaration followed by an actual declarations in the
6201 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00006202 if (log)
6203 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006204 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00006205 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006206 static_cast<void*>(this),
Greg Claytone38a5ed2012-01-05 03:57:59 +00006207 die->GetOffset(),
6208 DW_TAG_value_to_name(tag),
6209 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00006210 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006211
Greg Claytona8022fa2012-04-24 21:22:41 +00006212 DWARFDeclContext die_decl_ctx;
6213 die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx);
6214
6215 //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
6216 type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006217
Greg Clayton1f746072012-08-29 21:13:06 +00006218 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton4272cc72011-02-02 02:24:04 +00006219 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006220 // We weren't able to find a full declaration in
6221 // this DWARF, see if we have a declaration anywhere
6222 // else...
Greg Claytona8022fa2012-04-24 21:22:41 +00006223 type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton4272cc72011-02-02 02:24:04 +00006224 }
6225
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006226 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00006227 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00006228 if (log)
6229 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006230 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00006231 "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 +00006232 static_cast<void*>(this),
Greg Claytone38a5ed2012-01-05 03:57:59 +00006233 die->GetOffset(),
6234 DW_TAG_value_to_name(tag),
6235 type_name_cstr,
6236 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00006237 }
6238
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006239 // We found a real definition for this type elsewhere
6240 // so lets use it and cache the fact that we found
6241 // a complete type for this die
6242 m_die_to_type[die] = type_sp.get();
6243 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00006244 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006245 }
6246 assert (tag_decl_kind != -1);
6247 bool clang_type_was_created = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00006248 clang_type.SetClangType(ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die));
6249 if (!clang_type)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006250 {
Sean Callanan4d04c6a2012-02-09 22:54:11 +00006251 const DWARFDebugInfoEntry *decl_ctx_die;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006252
Sean Callanan4d04c6a2012-02-09 22:54:11 +00006253 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton55561e92011-10-26 03:31:36 +00006254 if (accessibility == eAccessNone && decl_ctx)
6255 {
6256 // Check the decl context that contains this class/struct/union.
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00006257 // If it is a class we must give it an accessibility.
Greg Clayton55561e92011-10-26 03:31:36 +00006258 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
6259 if (DeclKindIsCXXClass (containing_decl_kind))
6260 accessibility = default_accessibility;
6261 }
6262
Greg Claytonc4ffd662013-03-08 01:37:30 +00006263 ClangASTMetadata metadata;
6264 metadata.SetUserID(MakeUserID(die->GetOffset()));
6265 metadata.SetIsDynamicCXXType(ClassOrStructIsVirtual (dwarf_cu, die));
6266
Greg Claytonf0705c82011-10-22 03:33:13 +00006267 if (type_name_cstr && strchr (type_name_cstr, '<'))
6268 {
6269 ClangASTContext::TemplateParameterInfos template_param_infos;
6270 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
6271 {
6272 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00006273 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00006274 type_name_cstr,
6275 tag_decl_kind,
6276 template_param_infos);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006277
Greg Claytonf0705c82011-10-22 03:33:13 +00006278 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
6279 class_template_decl,
6280 tag_decl_kind,
6281 template_param_infos);
6282 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
6283 clang_type_was_created = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006284
Greg Claytond0029442013-03-27 01:48:02 +00006285 GetClangASTContext().SetMetadata (class_template_decl, metadata);
6286 GetClangASTContext().SetMetadata (class_specialization_decl, metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00006287 }
6288 }
6289
6290 if (!clang_type_was_created)
6291 {
6292 clang_type_was_created = true;
Greg Clayton55561e92011-10-26 03:31:36 +00006293 clang_type = ast.CreateRecordType (decl_ctx,
6294 accessibility,
6295 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00006296 tag_decl_kind,
Sean Callanan60217122012-04-13 00:10:03 +00006297 class_language,
Jim Ingham379397632012-10-27 02:54:13 +00006298 &metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00006299 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006300 }
6301
6302 // Store a forward declaration to this class type in case any
6303 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00006304 // types for function prototypes.
Greg Clayton57ee3062013-07-11 22:46:58 +00006305 LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00006306 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006307 this,
6308 type_name_const_str,
6309 byte_size,
6310 NULL,
6311 LLDB_INVALID_UID,
6312 Type::eEncodingIsUID,
6313 &decl,
6314 clang_type,
6315 Type::eResolveStateForward));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006316
Sean Callanan72772842012-02-22 23:57:45 +00006317 type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006318
6319
6320 // Add our type to the unique type map so we don't
6321 // end up creating many copies of the same type over
6322 // and over in the ASTContext for our module
Greg Claytond20deac2014-04-04 18:15:18 +00006323 unique_ast_entry_ap->m_type_sp = type_sp;
6324 unique_ast_entry_ap->m_symfile = this;
6325 unique_ast_entry_ap->m_cu = dwarf_cu;
6326 unique_ast_entry_ap->m_die = die;
6327 unique_ast_entry_ap->m_declaration = decl;
6328 unique_ast_entry_ap->m_byte_size = byte_size;
Greg Claytone576ab22011-02-15 00:19:15 +00006329 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
Greg Claytond20deac2014-04-04 18:15:18 +00006330 *unique_ast_entry_ap);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006331
Greg Clayton0ec71a02013-08-10 00:09:35 +00006332 if (is_forward_declaration && die->HasChildren())
6333 {
6334 // Check to see if the DIE actually has a definition, some version of GCC will
6335 // emit DIEs with DW_AT_declaration set to true, but yet still have subprogram,
6336 // members, or inheritance, so we can't trust it
6337 const DWARFDebugInfoEntry *child_die = die->GetFirstChild();
6338 while (child_die)
6339 {
6340 switch (child_die->Tag())
6341 {
6342 case DW_TAG_inheritance:
6343 case DW_TAG_subprogram:
6344 case DW_TAG_member:
6345 case DW_TAG_APPLE_property:
Greg Clayton4c484ec2014-02-07 19:21:56 +00006346 case DW_TAG_class_type:
6347 case DW_TAG_structure_type:
6348 case DW_TAG_enumeration_type:
6349 case DW_TAG_typedef:
6350 case DW_TAG_union_type:
Greg Clayton0ec71a02013-08-10 00:09:35 +00006351 child_die = NULL;
6352 is_forward_declaration = false;
6353 break;
6354 default:
6355 child_die = child_die->GetSibling();
6356 break;
6357 }
6358 }
6359 }
6360
Sean Callanan12014a02011-12-08 23:45:45 +00006361 if (!is_forward_declaration)
Greg Clayton219cf312012-03-30 00:51:13 +00006362 {
6363 // Always start the definition for a class type so that
6364 // if the class has child classes or types that require
6365 // the class to be created for use as their decl contexts
6366 // the class will be ready to accept these child definitions.
Sean Callanan12014a02011-12-08 23:45:45 +00006367 if (die->HasChildren() == false)
6368 {
6369 // No children for this struct/union/class, lets finish it
Greg Clayton57ee3062013-07-11 22:46:58 +00006370 clang_type.StartTagDeclarationDefinition ();
6371 clang_type.CompleteTagDeclarationDefinition ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006372
Sean Callanan433cd222012-10-19 01:37:25 +00006373 if (tag == DW_TAG_structure_type) // this only applies in C
6374 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006375 clang::RecordDecl *record_decl = clang_type.GetAsRecordDecl();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006376
Greg Clayton57ee3062013-07-11 22:46:58 +00006377 if (record_decl)
Greg Claytond20deac2014-04-04 18:15:18 +00006378 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, LayoutInfo()));
Sean Callanan433cd222012-10-19 01:37:25 +00006379 }
Sean Callanan12014a02011-12-08 23:45:45 +00006380 }
6381 else if (clang_type_was_created)
6382 {
Greg Clayton219cf312012-03-30 00:51:13 +00006383 // Start the definition if the class is not objective C since
6384 // the underlying decls respond to isCompleteDefinition(). Objective
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +00006385 // C decls don't respond to isCompleteDefinition() so we can't
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00006386 // start the declaration definition right away. For C++ class/union/structs
Greg Clayton219cf312012-03-30 00:51:13 +00006387 // we want to start the definition in case the class is needed as the
6388 // declaration context for a contained class or type without the need
6389 // to complete that type..
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006390
Sean Callanan7457f8d2012-04-25 01:03:57 +00006391 if (class_language != eLanguageTypeObjC &&
6392 class_language != eLanguageTypeObjC_plus_plus)
Greg Clayton57ee3062013-07-11 22:46:58 +00006393 clang_type.StartTagDeclarationDefinition ();
Greg Clayton219cf312012-03-30 00:51:13 +00006394
Sean Callanan12014a02011-12-08 23:45:45 +00006395 // Leave this as a forward declaration until we need
6396 // to know the details of the type. lldb_private::Type
6397 // will automatically call the SymbolFile virtual function
6398 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
6399 // When the definition needs to be defined.
Greg Clayton57ee3062013-07-11 22:46:58 +00006400 m_forward_decl_die_to_clang_type[die] = clang_type.GetOpaqueQualType();
6401 m_forward_decl_clang_type_to_die[clang_type.RemoveFastQualifiers().GetOpaqueQualType()] = die;
6402 clang_type.SetHasExternalStorage (true);
Sean Callanan12014a02011-12-08 23:45:45 +00006403 }
Greg Claytonc615ce42010-11-09 04:42:43 +00006404 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006405
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006406 }
6407 break;
6408
6409 case DW_TAG_enumeration_type:
6410 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006411 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006412 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006413
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006414 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006415
Greg Claytond88d7592010-09-15 08:33:30 +00006416 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006417 if (num_attributes > 0)
6418 {
6419 uint32_t i;
6420
6421 for (i=0; i<num_attributes; ++i)
6422 {
6423 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006424 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6425 {
6426 switch (attr)
6427 {
Greg Clayton7a345282010-11-09 23:46:37 +00006428 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6429 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6430 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006431 case DW_AT_name:
6432 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006433 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006434 break;
Greg Clayton54166af2014-11-22 01:58:59 +00006435 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006436 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
6437 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006438 case DW_AT_declaration: break; //is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006439 case DW_AT_allocated:
6440 case DW_AT_associated:
6441 case DW_AT_bit_stride:
6442 case DW_AT_byte_stride:
6443 case DW_AT_data_location:
6444 case DW_AT_description:
6445 case DW_AT_start_scope:
6446 case DW_AT_visibility:
6447 case DW_AT_specification:
6448 case DW_AT_abstract_origin:
6449 case DW_AT_sibling:
6450 break;
6451 }
6452 }
6453 }
6454
Daniel Malead01b2952012-11-29 21:49:15 +00006455 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 +00006456
Greg Clayton57ee3062013-07-11 22:46:58 +00006457 ClangASTType enumerator_clang_type;
6458 clang_type.SetClangType (ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die));
6459 if (!clang_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00006460 {
Greg Clayton5d14fc02013-03-06 06:23:54 +00006461 if (encoding_uid != DW_INVALID_OFFSET)
6462 {
6463 Type *enumerator_type = ResolveTypeUID(encoding_uid);
6464 if (enumerator_type)
6465 enumerator_clang_type = enumerator_type->GetClangFullType();
6466 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006467
Greg Clayton57ee3062013-07-11 22:46:58 +00006468 if (!enumerator_clang_type)
Greg Clayton5d14fc02013-03-06 06:23:54 +00006469 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
6470 DW_ATE_signed,
6471 byte_size * 8);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006472
Greg Claytonca512b32011-01-14 04:54:56 +00006473 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00006474 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00006475 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006476 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00006477 }
6478 else
6479 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006480 enumerator_clang_type = clang_type.GetEnumerationIntegerType ();
Greg Clayton1be10fc2010-09-29 01:12:09 +00006481 }
6482
Greg Clayton57ee3062013-07-11 22:46:58 +00006483 LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006484
Greg Clayton81c22f62011-10-19 18:09:39 +00006485 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006486 this,
6487 type_name_const_str,
6488 byte_size,
6489 NULL,
6490 encoding_uid,
6491 Type::eEncodingIsUID,
6492 &decl,
6493 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006494 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006495
Greg Clayton57ee3062013-07-11 22:46:58 +00006496 clang_type.StartTagDeclarationDefinition ();
Greg Clayton6beaaa62011-01-17 03:46:26 +00006497 if (die->HasChildren())
6498 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006499 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00006500 bool is_signed = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00006501 enumerator_clang_type.IsIntegerType(is_signed);
Greg Clayton3e067532013-03-05 23:54:39 +00006502 ParseChildEnumerators(cu_sc, clang_type, is_signed, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00006503 }
Greg Clayton57ee3062013-07-11 22:46:58 +00006504 clang_type.CompleteTagDeclarationDefinition ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006505 }
6506 }
6507 break;
6508
Jim Inghamb0be4422010-08-12 01:20:14 +00006509 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006510 case DW_TAG_subprogram:
6511 case DW_TAG_subroutine_type:
6512 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006513 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006514 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006515
Greg Clayton23f59502012-07-17 03:23:13 +00006516 //const char *mangled = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006517 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00006518 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006519 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00006520 bool is_static = false;
6521 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00006522 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00006523 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00006524 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
6525 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Jim Ingham379397632012-10-27 02:54:13 +00006526 dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00006527
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006528 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00006529 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006530
6531
Greg Claytond88d7592010-09-15 08:33:30 +00006532 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006533 if (num_attributes > 0)
6534 {
6535 uint32_t i;
6536 for (i=0; i<num_attributes; ++i)
6537 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006538 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006539 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6540 {
6541 switch (attr)
6542 {
6543 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6544 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6545 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6546 case DW_AT_name:
6547 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006548 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006549 break;
6550
Greg Clayton71415542012-12-08 00:24:40 +00006551 case DW_AT_linkage_name:
Greg Clayton23f59502012-07-17 03:23:13 +00006552 case DW_AT_MIPS_linkage_name: break; // mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00006553 case DW_AT_type: type_die_offset = form_value.Reference(); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00006554 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006555 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
6556 case DW_AT_inline: is_inline = form_value.Boolean(); break;
6557 case DW_AT_virtuality: is_virtual = form_value.Boolean(); break;
6558 case DW_AT_explicit: is_explicit = form_value.Boolean(); break;
6559 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006560
Greg Claytonf51de672010-10-01 02:31:07 +00006561
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006562 case DW_AT_external:
6563 if (form_value.Unsigned())
6564 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00006565 if (storage == clang::SC_None)
6566 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006567 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00006568 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006569 }
6570 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006571
Greg Clayton72da3972011-08-16 18:40:23 +00006572 case DW_AT_specification:
Greg Clayton54166af2014-11-22 01:58:59 +00006573 specification_die_offset = form_value.Reference();
Greg Clayton72da3972011-08-16 18:40:23 +00006574 break;
6575
6576 case DW_AT_abstract_origin:
Greg Clayton54166af2014-11-22 01:58:59 +00006577 abstract_origin_die_offset = form_value.Reference();
Greg Clayton72da3972011-08-16 18:40:23 +00006578 break;
6579
Jim Ingham379397632012-10-27 02:54:13 +00006580 case DW_AT_object_pointer:
Greg Clayton54166af2014-11-22 01:58:59 +00006581 object_pointer_die_offset = form_value.Reference();
Jim Ingham379397632012-10-27 02:54:13 +00006582 break;
6583
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006584 case DW_AT_allocated:
6585 case DW_AT_associated:
6586 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006587 case DW_AT_calling_convention:
6588 case DW_AT_data_location:
6589 case DW_AT_elemental:
6590 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006591 case DW_AT_frame_base:
6592 case DW_AT_high_pc:
6593 case DW_AT_low_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006594 case DW_AT_prototyped:
6595 case DW_AT_pure:
6596 case DW_AT_ranges:
6597 case DW_AT_recursive:
6598 case DW_AT_return_addr:
6599 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006600 case DW_AT_start_scope:
6601 case DW_AT_static_link:
6602 case DW_AT_trampoline:
6603 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006604 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006605 case DW_AT_description:
6606 case DW_AT_sibling:
6607 break;
6608 }
6609 }
6610 }
Greg Clayton24739922010-10-13 03:15:28 +00006611 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006612
Jim Ingham379397632012-10-27 02:54:13 +00006613 std::string object_pointer_name;
6614 if (object_pointer_die_offset != DW_INVALID_OFFSET)
6615 {
6616 // Get the name from the object pointer die
6617 StreamString s;
6618 if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s))
6619 {
6620 object_pointer_name.assign(s.GetData());
6621 }
6622 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006623
Daniel Malead01b2952012-11-29 21:49:15 +00006624 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 +00006625
Greg Clayton57ee3062013-07-11 22:46:58 +00006626 ClangASTType return_clang_type;
Greg Clayton24739922010-10-13 03:15:28 +00006627 Type *func_type = NULL;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006628
Greg Clayton24739922010-10-13 03:15:28 +00006629 if (type_die_offset != DW_INVALID_OFFSET)
6630 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00006631
Greg Clayton24739922010-10-13 03:15:28 +00006632 if (func_type)
Greg Clayton42ce2f32011-12-12 21:50:19 +00006633 return_clang_type = func_type->GetClangForwardType();
Greg Clayton24739922010-10-13 03:15:28 +00006634 else
Greg Clayton57ee3062013-07-11 22:46:58 +00006635 return_clang_type = ast.GetBasicType(eBasicTypeVoid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006636
Greg Claytonf51de672010-10-01 02:31:07 +00006637
Greg Clayton57ee3062013-07-11 22:46:58 +00006638 std::vector<ClangASTType> function_param_types;
Greg Clayton24739922010-10-13 03:15:28 +00006639 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006640
Greg Clayton24739922010-10-13 03:15:28 +00006641 // Parse the function children for the parameters
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006642
Greg Claytoncb5860a2011-10-13 23:49:28 +00006643 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
6644 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00006645 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
6646
Greg Claytonf0705c82011-10-22 03:33:13 +00006647 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00006648 // Start off static. This will be set to false in ParseChildParameters(...)
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00006649 // if we find a "this" parameters as the first parameter
Greg Clayton5113dc82011-08-12 06:47:54 +00006650 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00006651 is_static = true;
Greg Claytond20deac2014-04-04 18:15:18 +00006652
Greg Clayton24739922010-10-13 03:15:28 +00006653 if (die->HasChildren())
6654 {
Greg Clayton0fffff52010-09-24 05:15:53 +00006655 bool skip_artificial = true;
Jim Ingham379397632012-10-27 02:54:13 +00006656 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00006657 containing_decl_ctx,
Jim Ingham379397632012-10-27 02:54:13 +00006658 dwarf_cu,
6659 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00006660 skip_artificial,
6661 is_static,
Greg Clayton03969752014-02-24 18:53:11 +00006662 is_variadic,
Jim Ingham379397632012-10-27 02:54:13 +00006663 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00006664 function_param_decls,
Greg Claytond20deac2014-04-04 18:15:18 +00006665 type_quals);
Greg Clayton24739922010-10-13 03:15:28 +00006666 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006667
Greg Clayton24739922010-10-13 03:15:28 +00006668 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006669 clang_type = ast.CreateFunctionType (return_clang_type,
Greg Clayton9cb25c42012-10-30 17:02:18 +00006670 function_param_types.data(),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006671 function_param_types.size(),
6672 is_variadic,
6673 type_quals);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006674
Sean Callanande9ce872013-05-09 23:13:13 +00006675 bool ignore_containing_context = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006676
Greg Clayton24739922010-10-13 03:15:28 +00006677 if (type_name_cstr)
6678 {
6679 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00006680 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006681 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00006682 ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true);
6683 if (objc_method.IsValid(true))
Greg Clayton0fffff52010-09-24 05:15:53 +00006684 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006685 ClangASTType class_opaque_type;
Greg Clayton1b3815c2013-01-30 00:18:29 +00006686 ConstString class_name(objc_method.GetClassName());
Greg Clayton7c810422012-01-18 23:40:49 +00006687 if (class_name)
Greg Clayton0fffff52010-09-24 05:15:53 +00006688 {
Greg Clayton278a16b2012-01-19 00:52:59 +00006689 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
Greg Claytonc7f03b62012-01-12 04:33:28 +00006690
6691 if (complete_objc_class_type_sp)
Greg Clayton0fffff52010-09-24 05:15:53 +00006692 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006693 ClangASTType type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
6694 if (type_clang_forward_type.IsObjCObjectOrInterfaceType ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00006695 class_opaque_type = type_clang_forward_type;
Greg Clayton0fffff52010-09-24 05:15:53 +00006696 }
Greg Clayton24739922010-10-13 03:15:28 +00006697 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006698
Greg Clayton24739922010-10-13 03:15:28 +00006699 if (class_opaque_type)
6700 {
6701 // If accessibility isn't set to anything valid, assume public for
6702 // now...
6703 if (accessibility == eAccessNone)
6704 accessibility = eAccessPublic;
6705
Greg Clayton57ee3062013-07-11 22:46:58 +00006706 clang::ObjCMethodDecl *objc_method_decl = class_opaque_type.AddMethodToObjCObjectType (type_name_cstr,
6707 clang_type,
6708 accessibility,
6709 is_artificial);
Greg Clayton24739922010-10-13 03:15:28 +00006710 type_handled = objc_method_decl != NULL;
Sean Callanan464a5b52012-10-04 22:06:29 +00006711 if (type_handled)
6712 {
6713 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Claytond0029442013-03-27 01:48:02 +00006714 GetClangASTContext().SetMetadataAsUserID (objc_method_decl, MakeUserID(die->GetOffset()));
Sean Callanan464a5b52012-10-04 22:06:29 +00006715 }
Sean Callananc3a1d562013-02-06 23:21:59 +00006716 else
6717 {
Jason Molendac1a65832013-03-07 22:44:42 +00006718 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 +00006719 die->GetOffset(),
6720 tag,
6721 DW_TAG_value_to_name(tag));
6722 }
Greg Clayton24739922010-10-13 03:15:28 +00006723 }
6724 }
Greg Clayton5113dc82011-08-12 06:47:54 +00006725 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00006726 {
6727 // Look at the parent of this DIE and see if is is
6728 // a class or struct and see if this is actually a
6729 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00006730 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00006731 if (class_type)
6732 {
Greg Clayton4116e932012-05-15 02:33:01 +00006733 if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset()))
6734 {
6735 // We uniqued the parent class of this function to another class
6736 // so we now need to associate all dies under "decl_ctx_die" to
6737 // DIEs in the DIE for "class_type"...
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006738 SymbolFileDWARF *class_symfile = NULL;
Greg Clayton4116e932012-05-15 02:33:01 +00006739 DWARFCompileUnitSP class_type_cu_sp;
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006740 const DWARFDebugInfoEntry *class_type_die = NULL;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006741
Sean Callanan2367f8a2013-02-26 01:12:25 +00006742 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
6743 if (debug_map_symfile)
6744 {
6745 class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID()));
6746 class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6747 }
6748 else
6749 {
6750 class_symfile = this;
6751 class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6752 }
Greg Clayton4116e932012-05-15 02:33:01 +00006753 if (class_type_die)
6754 {
Greg Claytond20deac2014-04-04 18:15:18 +00006755 DWARFDIECollection failures;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006756
Sean Callanan2367f8a2013-02-26 01:12:25 +00006757 CopyUniqueClassMethodTypes (class_symfile,
6758 class_type,
6759 class_type_cu_sp.get(),
6760 class_type_die,
6761 dwarf_cu,
6762 decl_ctx_die,
6763 failures);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006764
Sean Callanan2367f8a2013-02-26 01:12:25 +00006765 // FIXME do something with these failures that's smarter than
6766 // just dropping them on the ground. Unfortunately classes don't
6767 // like having stuff added to them after their definitions are
6768 // complete...
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006769
Sean Callanan2367f8a2013-02-26 01:12:25 +00006770 type_ptr = m_die_to_type[die];
6771 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton4116e932012-05-15 02:33:01 +00006772 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006773 type_sp = type_ptr->shared_from_this();
6774 break;
Greg Clayton4116e932012-05-15 02:33:01 +00006775 }
6776 }
6777 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006778
Greg Clayton72da3972011-08-16 18:40:23 +00006779 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00006780 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006781 // We have a specification which we are going to base our function
6782 // prototype off of, so we need this type to be completed so that the
6783 // m_die_to_decl_ctx for the method in the specification has a valid
6784 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006785 class_type->GetClangForwardType();
Greg Clayton72da3972011-08-16 18:40:23 +00006786 // If we have a specification, then the function type should have been
6787 // made with the specification and not with this die.
6788 DWARFCompileUnitSP spec_cu_sp;
6789 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006790 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006791 if (spec_clang_decl_ctx)
6792 {
6793 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
6794 }
6795 else
Jim Inghamc1663042011-09-29 22:12:35 +00006796 {
Daniel Malead01b2952012-11-29 21:49:15 +00006797 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8x) has no decl\n",
Greg Claytone38a5ed2012-01-05 03:57:59 +00006798 MakeUserID(die->GetOffset()),
6799 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006800 }
Greg Clayton72da3972011-08-16 18:40:23 +00006801 type_handled = true;
6802 }
6803 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
6804 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006805 // We have a specification which we are going to base our function
6806 // prototype off of, so we need this type to be completed so that the
6807 // m_die_to_decl_ctx for the method in the abstract origin has a valid
6808 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006809 class_type->GetClangForwardType();
Greg Clayton5cf58b92011-10-05 22:22:08 +00006810
Greg Clayton72da3972011-08-16 18:40:23 +00006811 DWARFCompileUnitSP abs_cu_sp;
6812 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006813 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006814 if (abs_clang_decl_ctx)
6815 {
6816 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
6817 }
6818 else
Jim Inghamc1663042011-09-29 22:12:35 +00006819 {
Daniel Malead01b2952012-11-29 21:49:15 +00006820 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 +00006821 MakeUserID(die->GetOffset()),
6822 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006823 }
Greg Clayton72da3972011-08-16 18:40:23 +00006824 type_handled = true;
6825 }
6826 else
6827 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006828 ClangASTType class_opaque_type = class_type->GetClangForwardType();
6829 if (class_opaque_type.IsCXXClassType ())
Greg Clayton931180e2011-01-27 06:44:37 +00006830 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006831 if (class_opaque_type.IsBeingDefined ())
Greg Clayton72da3972011-08-16 18:40:23 +00006832 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006833 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
6834 // in the DWARF for C++ methods... Default to public for now...
6835 if (accessibility == eAccessNone)
6836 accessibility = eAccessPublic;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006837
Greg Clayton20568dd2011-10-13 23:13:20 +00006838 if (!is_static && !die->HasChildren())
6839 {
6840 // We have a C++ member function with no children (this pointer!)
6841 // and clang will get mad if we try and make a function that isn't
6842 // well formed in the DWARF, so we will just skip it...
6843 type_handled = true;
6844 }
6845 else
6846 {
6847 clang::CXXMethodDecl *cxx_method_decl;
6848 // REMOVE THE CRASH DESCRIPTION BELOW
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00006849 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 +00006850 type_name_cstr,
6851 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00006852 MakeUserID(die->GetOffset()),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00006853 m_obj_file->GetFileSpec().GetPath().c_str());
Greg Clayton20568dd2011-10-13 23:13:20 +00006854
Sean Callananc1b732d2011-11-01 18:07:13 +00006855 const bool is_attr_used = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006856
Greg Clayton57ee3062013-07-11 22:46:58 +00006857 cxx_method_decl = class_opaque_type.AddMethodToCXXRecordType (type_name_cstr,
6858 clang_type,
6859 accessibility,
6860 is_virtual,
6861 is_static,
6862 is_inline,
6863 is_explicit,
6864 is_attr_used,
6865 is_artificial);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006866
Greg Clayton20568dd2011-10-13 23:13:20 +00006867 type_handled = cxx_method_decl != NULL;
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006868
6869 if (type_handled)
Jim Ingham379397632012-10-27 02:54:13 +00006870 {
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006871 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
6872
6873 Host::SetCrashDescription (NULL);
6874
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006875
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006876 ClangASTMetadata metadata;
6877 metadata.SetUserID(MakeUserID(die->GetOffset()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006878
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006879 if (!object_pointer_name.empty())
6880 {
6881 metadata.SetObjectPtrName(object_pointer_name.c_str());
6882 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006883 log->Printf ("Setting object pointer name: %s on method object %p.\n",
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006884 object_pointer_name.c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006885 static_cast<void*>(cxx_method_decl));
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006886 }
Greg Claytond0029442013-03-27 01:48:02 +00006887 GetClangASTContext().SetMetadata (cxx_method_decl, metadata);
Jim Ingham379397632012-10-27 02:54:13 +00006888 }
Sean Callananb0640dc2013-04-09 23:22:08 +00006889 else
6890 {
Sean Callanande9ce872013-05-09 23:13:13 +00006891 ignore_containing_context = true;
Sean Callananb0640dc2013-04-09 23:22:08 +00006892 }
Greg Clayton20568dd2011-10-13 23:13:20 +00006893 }
Greg Clayton72da3972011-08-16 18:40:23 +00006894 }
6895 else
6896 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006897 // We were asked to parse the type for a method in a class, yet the
6898 // class hasn't been asked to complete itself through the
6899 // clang::ExternalASTSource protocol, so we need to just have the
6900 // class complete itself and do things the right way, then our
6901 // DIE should then have an entry in the m_die_to_type map. First
6902 // we need to modify the m_die_to_type so it doesn't think we are
6903 // trying to parse this DIE anymore...
6904 m_die_to_type[die] = NULL;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006905
Greg Clayton20568dd2011-10-13 23:13:20 +00006906 // Now we get the full type to force our class type to complete itself
6907 // using the clang::ExternalASTSource protocol which will parse all
6908 // base classes and all methods (including the method for this DIE).
6909 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00006910
Greg Clayton20568dd2011-10-13 23:13:20 +00006911 // The type for this DIE should have been filled in the function call above
6912 type_ptr = m_die_to_type[die];
Greg Claytone5476db2012-06-01 20:32:35 +00006913 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton20568dd2011-10-13 23:13:20 +00006914 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006915 type_sp = type_ptr->shared_from_this();
Greg Clayton20568dd2011-10-13 23:13:20 +00006916 break;
6917 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006918
Sean Callanan02eee4d2012-04-12 23:10:00 +00006919 // FIXME This is fixing some even uglier behavior but we really need to
6920 // uniq the methods of each class as well as the class itself.
6921 // <rdar://problem/11240464>
6922 type_handled = true;
Greg Clayton72da3972011-08-16 18:40:23 +00006923 }
Greg Clayton931180e2011-01-27 06:44:37 +00006924 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006925 }
6926 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006927 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006928 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006929
Greg Clayton24739922010-10-13 03:15:28 +00006930 if (!type_handled)
6931 {
6932 // We just have a function that isn't part of a class
Sean Callanande9ce872013-05-09 23:13:13 +00006933 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (ignore_containing_context ? GetClangASTContext().GetTranslationUnitDecl() : containing_decl_ctx,
Greg Clayton147e1fa2011-10-14 22:47:18 +00006934 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006935 clang_type,
6936 storage,
6937 is_inline);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006938
6939// if (template_param_infos.GetSize() > 0)
6940// {
6941// clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
6942// function_decl,
6943// type_name_cstr,
6944// template_param_infos);
6945//
6946// ast.CreateFunctionTemplateSpecializationInfo (function_decl,
6947// func_template_decl,
6948// template_param_infos);
6949// }
Greg Clayton24739922010-10-13 03:15:28 +00006950 // Add the decl to our DIE to decl context map
6951 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00006952 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00006953 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006954 ast.SetFunctionParameters (function_decl,
6955 &function_param_decls.front(),
6956 function_param_decls.size());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006957
Jim Ingham379397632012-10-27 02:54:13 +00006958 ClangASTMetadata metadata;
6959 metadata.SetUserID(MakeUserID(die->GetOffset()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006960
Jim Ingham379397632012-10-27 02:54:13 +00006961 if (!object_pointer_name.empty())
6962 {
6963 metadata.SetObjectPtrName(object_pointer_name.c_str());
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006964 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006965 log->Printf ("Setting object pointer name: %s on function object %p.",
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006966 object_pointer_name.c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006967 static_cast<void*>(function_decl));
Jim Ingham379397632012-10-27 02:54:13 +00006968 }
Greg Claytond0029442013-03-27 01:48:02 +00006969 GetClangASTContext().SetMetadata (function_decl, metadata);
Greg Clayton24739922010-10-13 03:15:28 +00006970 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006971 }
Greg Clayton81c22f62011-10-19 18:09:39 +00006972 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006973 this,
6974 type_name_const_str,
6975 0,
6976 NULL,
6977 LLDB_INVALID_UID,
6978 Type::eEncodingIsUID,
6979 &decl,
6980 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006981 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00006982 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006983 }
6984 break;
6985
6986 case DW_TAG_array_type:
6987 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006988 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006989 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006990
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006991 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006992 int64_t first_index = 0;
6993 uint32_t byte_stride = 0;
6994 uint32_t bit_stride = 0;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006995 bool is_vector = false;
Greg Claytond88d7592010-09-15 08:33:30 +00006996 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006997
6998 if (num_attributes > 0)
6999 {
7000 uint32_t i;
7001 for (i=0; i<num_attributes; ++i)
7002 {
7003 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007004 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
7005 {
7006 switch (attr)
7007 {
7008 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
7009 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
7010 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
7011 case DW_AT_name:
7012 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00007013 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007014 break;
7015
Greg Clayton54166af2014-11-22 01:58:59 +00007016 case DW_AT_type: type_die_offset = form_value.Reference(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00007017 case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007018 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
7019 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00007020 case DW_AT_GNU_vector: is_vector = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00007021 case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00007022 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007023 case DW_AT_allocated:
7024 case DW_AT_associated:
7025 case DW_AT_data_location:
7026 case DW_AT_description:
7027 case DW_AT_ordering:
7028 case DW_AT_start_scope:
7029 case DW_AT_visibility:
7030 case DW_AT_specification:
7031 case DW_AT_abstract_origin:
7032 case DW_AT_sibling:
7033 break;
7034 }
7035 }
7036 }
7037
Daniel Malead01b2952012-11-29 21:49:15 +00007038 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 +00007039
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007040 Type *element_type = ResolveTypeUID(type_die_offset);
7041
7042 if (element_type)
7043 {
7044 std::vector<uint64_t> element_orders;
7045 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
7046 if (byte_stride == 0 && bit_stride == 0)
7047 byte_stride = element_type->GetByteSize();
Greg Clayton57ee3062013-07-11 22:46:58 +00007048 ClangASTType array_element_type = element_type->GetClangForwardType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007049 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
Siva Chandra89ce9552015-01-05 23:06:14 +00007050 if (element_orders.size() > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007051 {
Siva Chandra89ce9552015-01-05 23:06:14 +00007052 uint64_t num_elements = 0;
7053 std::vector<uint64_t>::const_reverse_iterator pos;
7054 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
7055 for (pos = element_orders.rbegin(); pos != end; ++pos)
7056 {
7057 num_elements = *pos;
7058 clang_type = ast.CreateArrayType (array_element_type,
7059 num_elements,
7060 is_vector);
7061 array_element_type = clang_type;
7062 array_element_bit_stride = num_elements ?
7063 array_element_bit_stride * num_elements :
7064 array_element_bit_stride;
7065 }
7066 }
7067 else
7068 {
7069 clang_type = ast.CreateArrayType (array_element_type, 0, is_vector);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007070 }
7071 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00007072 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00007073 this,
7074 empty_name,
7075 array_element_bit_stride / 8,
7076 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00007077 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00007078 Type::eEncodingIsUID,
7079 &decl,
7080 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00007081 Type::eResolveStateFull));
7082 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007083 }
7084 }
7085 }
7086 break;
7087
Greg Clayton9b81a312010-06-12 01:20:30 +00007088 case DW_TAG_ptr_to_member_type:
7089 {
7090 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
7091 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
7092
Greg Claytond88d7592010-09-15 08:33:30 +00007093 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007094
Greg Clayton9b81a312010-06-12 01:20:30 +00007095 if (num_attributes > 0) {
7096 uint32_t i;
7097 for (i=0; i<num_attributes; ++i)
7098 {
7099 attr = attributes.AttributeAtIndex(i);
Greg Clayton9b81a312010-06-12 01:20:30 +00007100 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
7101 {
7102 switch (attr)
7103 {
7104 case DW_AT_type:
Greg Clayton54166af2014-11-22 01:58:59 +00007105 type_die_offset = form_value.Reference(); break;
Greg Clayton9b81a312010-06-12 01:20:30 +00007106 case DW_AT_containing_type:
Greg Clayton54166af2014-11-22 01:58:59 +00007107 containing_type_die_offset = form_value.Reference(); break;
Greg Clayton9b81a312010-06-12 01:20:30 +00007108 }
7109 }
7110 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007111
Greg Clayton9b81a312010-06-12 01:20:30 +00007112 Type *pointee_type = ResolveTypeUID(type_die_offset);
7113 Type *class_type = ResolveTypeUID(containing_type_die_offset);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007114
Greg Clayton57ee3062013-07-11 22:46:58 +00007115 ClangASTType pointee_clang_type = pointee_type->GetClangForwardType();
7116 ClangASTType class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00007117
Greg Clayton57ee3062013-07-11 22:46:58 +00007118 clang_type = pointee_clang_type.CreateMemberPointerType(class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00007119
Enrico Granata1cd5e922015-01-28 00:07:51 +00007120 byte_size = clang_type.GetByteSize(nullptr);
Greg Clayton9b81a312010-06-12 01:20:30 +00007121
Greg Clayton81c22f62011-10-19 18:09:39 +00007122 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00007123 this,
7124 type_name_const_str,
7125 byte_size,
7126 NULL,
7127 LLDB_INVALID_UID,
7128 Type::eEncodingIsUID,
7129 NULL,
7130 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00007131 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00007132 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007133
Greg Clayton9b81a312010-06-12 01:20:30 +00007134 break;
7135 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007136 default:
Greg Clayton84afacd2012-11-07 23:09:32 +00007137 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",
7138 die->GetOffset(),
7139 tag,
7140 DW_TAG_value_to_name(tag));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007141 break;
7142 }
7143
7144 if (type_sp.get())
7145 {
7146 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7147 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7148
7149 SymbolContextScope * symbol_context_scope = NULL;
7150 if (sc_parent_tag == DW_TAG_compile_unit)
7151 {
7152 symbol_context_scope = sc.comp_unit;
7153 }
Jason Molenda60db6e42014-10-16 01:40:16 +00007154 else if (sc.function != NULL && sc_parent_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007155 {
Greg Clayton81c22f62011-10-19 18:09:39 +00007156 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007157 if (symbol_context_scope == NULL)
7158 symbol_context_scope = sc.function;
7159 }
7160
7161 if (symbol_context_scope != NULL)
7162 {
7163 type_sp->SetSymbolContextScope(symbol_context_scope);
7164 }
7165
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00007166 // We are ready to put this type into the uniqued list up at the module level
7167 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00007168
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00007169 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007170 }
7171 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00007172 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007173 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00007174 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007175 }
7176 }
7177 return type_sp;
7178}
7179
7180size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00007181SymbolFileDWARF::ParseTypes
7182(
7183 const SymbolContext& sc,
7184 DWARFCompileUnit* dwarf_cu,
7185 const DWARFDebugInfoEntry *die,
7186 bool parse_siblings,
7187 bool parse_children
7188)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007189{
7190 size_t types_added = 0;
7191 while (die != NULL)
7192 {
7193 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00007194 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007195 {
7196 if (type_is_new)
7197 ++types_added;
7198 }
7199
7200 if (parse_children && die->HasChildren())
7201 {
7202 if (die->Tag() == DW_TAG_subprogram)
7203 {
7204 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00007205 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007206 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
7207 }
7208 else
7209 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
7210 }
7211
7212 if (parse_siblings)
7213 die = die->GetSibling();
7214 else
7215 die = NULL;
7216 }
7217 return types_added;
7218}
7219
7220
7221size_t
7222SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
7223{
7224 assert(sc.comp_unit && sc.function);
7225 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00007226 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007227 if (dwarf_cu)
7228 {
7229 dw_offset_t function_die_offset = sc.function->GetID();
7230 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
7231 if (function_die)
7232 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00007233 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007234 }
7235 }
7236
7237 return functions_added;
7238}
7239
7240
7241size_t
7242SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
7243{
7244 // At least a compile unit must be valid
7245 assert(sc.comp_unit);
7246 size_t types_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00007247 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007248 if (dwarf_cu)
7249 {
7250 if (sc.function)
7251 {
7252 dw_offset_t function_die_offset = sc.function->GetID();
7253 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
7254 if (func_die && func_die->HasChildren())
7255 {
7256 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
7257 }
7258 }
7259 else
7260 {
7261 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
7262 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
7263 {
7264 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
7265 }
7266 }
7267 }
7268
7269 return types_added;
7270}
7271
7272size_t
7273SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
7274{
7275 if (sc.comp_unit != NULL)
7276 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00007277 DWARFDebugInfo* info = DebugInfo();
7278 if (info == NULL)
7279 return 0;
7280
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007281 if (sc.function)
7282 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007283 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get();
7284
7285 if (dwarf_cu == NULL)
7286 return 0;
7287
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007288 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00007289
Greg Claytonc7bece562013-01-25 18:06:21 +00007290 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
7291 if (func_lo_pc != LLDB_INVALID_ADDRESS)
Greg Claytone38a5ed2012-01-05 03:57:59 +00007292 {
7293 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00007294
Greg Claytone38a5ed2012-01-05 03:57:59 +00007295 // Let all blocks know they have parse all their variables
7296 sc.function->GetBlock (false).SetDidParseVariables (true, true);
7297 return num_variables;
7298 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007299 }
7300 else if (sc.comp_unit)
7301 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007302 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get();
7303
7304 if (dwarf_cu == NULL)
7305 return 0;
7306
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007307 uint32_t vars_added = 0;
7308 VariableListSP variables (sc.comp_unit->GetVariableList(false));
7309
7310 if (variables.get() == NULL)
7311 {
7312 variables.reset(new VariableList());
7313 sc.comp_unit->SetVariableList(variables);
7314
Greg Claytond4a2b372011-09-12 23:21:58 +00007315 DWARFCompileUnit* match_dwarf_cu = NULL;
7316 const DWARFDebugInfoEntry* die = NULL;
7317 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00007318 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00007319 {
Greg Clayton97fbc342011-10-20 22:30:33 +00007320 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00007321 {
7322 DWARFMappedHash::DIEInfoArray hash_data_array;
7323 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
7324 dwarf_cu->GetNextCompileUnitOffset(),
7325 hash_data_array))
7326 {
7327 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
7328 }
7329 }
Greg Clayton7f995132011-10-04 22:41:51 +00007330 }
7331 else
7332 {
7333 // Index if we already haven't to make sure the compile units
7334 // get indexed and make their global DIE index list
7335 if (!m_indexed)
7336 Index ();
7337
7338 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
7339 dwarf_cu->GetNextCompileUnitOffset(),
7340 die_offsets);
7341 }
7342
7343 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00007344 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007345 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007346 DWARFDebugInfo* debug_info = DebugInfo();
7347 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007348 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007349 const dw_offset_t die_offset = die_offsets[i];
7350 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00007351 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00007352 {
Greg Clayton95d87902011-11-11 03:16:25 +00007353 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
7354 if (var_sp)
7355 {
7356 variables->AddVariableIfUnique (var_sp);
7357 ++vars_added;
7358 }
Greg Claytond4a2b372011-09-12 23:21:58 +00007359 }
Greg Clayton95d87902011-11-11 03:16:25 +00007360 else
7361 {
7362 if (m_using_apple_tables)
7363 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00007364 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 +00007365 }
7366 }
7367
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007368 }
7369 }
7370 }
7371 return vars_added;
7372 }
7373 }
7374 return 0;
7375}
7376
7377
7378VariableSP
7379SymbolFileDWARF::ParseVariableDIE
7380(
7381 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007382 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007383 const DWARFDebugInfoEntry *die,
7384 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007385)
7386{
Greg Clayton83c5cd92010-11-14 22:13:40 +00007387 VariableSP var_sp (m_die_to_variable_sp[die]);
7388 if (var_sp)
7389 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007390
7391 const dw_tag_t tag = die->Tag();
Richard Mitton0a558352013-10-17 21:14:00 +00007392 ModuleSP module = GetObjectFile()->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00007393
7394 if ((tag == DW_TAG_variable) ||
7395 (tag == DW_TAG_constant) ||
7396 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007397 {
Greg Clayton7f995132011-10-04 22:41:51 +00007398 DWARFDebugInfoEntry::Attributes attributes;
7399 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
7400 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007401 {
Greg Clayton7f995132011-10-04 22:41:51 +00007402 const char *name = NULL;
7403 const char *mangled = NULL;
7404 Declaration decl;
7405 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00007406 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00007407 DWARFExpression location;
7408 bool is_external = false;
7409 bool is_artificial = false;
7410 bool location_is_const_value_data = false;
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007411 bool has_explicit_location = false;
Enrico Granata4ec130d2014-08-11 19:16:35 +00007412 DWARFFormValue const_value;
Greg Clayton23f59502012-07-17 03:23:13 +00007413 //AccessType accessibility = eAccessNone;
Greg Clayton7f995132011-10-04 22:41:51 +00007414
7415 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007416 {
Greg Clayton7f995132011-10-04 22:41:51 +00007417 dw_attr_t attr = attributes.AttributeAtIndex(i);
7418 DWARFFormValue form_value;
Greg Clayton54166af2014-11-22 01:58:59 +00007419
Greg Clayton7f995132011-10-04 22:41:51 +00007420 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007421 {
Greg Clayton7f995132011-10-04 22:41:51 +00007422 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007423 {
Greg Clayton7f995132011-10-04 22:41:51 +00007424 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
7425 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
7426 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
7427 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton71415542012-12-08 00:24:40 +00007428 case DW_AT_linkage_name:
Greg Clayton7f995132011-10-04 22:41:51 +00007429 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00007430 case DW_AT_type: type_uid = form_value.Reference(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00007431 case DW_AT_external: is_external = form_value.Boolean(); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007432 case DW_AT_const_value:
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007433 // If we have already found a DW_AT_location attribute, ignore this attribute.
7434 if (!has_explicit_location)
7435 {
7436 location_is_const_value_data = true;
7437 // The constant value will be either a block, a data value or a string.
Ed Masteeeae7212013-10-24 20:43:47 +00007438 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007439 if (DWARFFormValue::IsBlockForm(form_value.Form()))
7440 {
7441 // Retrieve the value as a block expression.
7442 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7443 uint32_t block_length = form_value.Unsigned();
Richard Mitton0a558352013-10-17 21:14:00 +00007444 location.CopyOpcodeData(module, debug_info_data, block_offset, block_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007445 }
7446 else if (DWARFFormValue::IsDataForm(form_value.Form()))
7447 {
7448 // Retrieve the value as a data expression.
Greg Clayton54166af2014-11-22 01:58:59 +00007449 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (attributes.CompileUnitAtIndex(i)->GetAddressByteSize(), attributes.CompileUnitAtIndex(i)->IsDWARF64());
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007450 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7451 uint32_t data_length = fixed_form_sizes[form_value.Form()];
Enrico Granata4ec130d2014-08-11 19:16:35 +00007452 if (data_length == 0)
7453 {
7454 const uint8_t *data_pointer = form_value.BlockData();
7455 if (data_pointer)
7456 {
Jason Molenda18f5fd32014-10-16 07:52:17 +00007457 form_value.Unsigned();
Enrico Granata4ec130d2014-08-11 19:16:35 +00007458 }
7459 else if (DWARFFormValue::IsDataForm(form_value.Form()))
7460 {
7461 // we need to get the byte size of the type later after we create the variable
7462 const_value = form_value;
7463 }
7464 }
7465 else
7466 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007467 }
7468 else
7469 {
7470 // Retrieve the value as a string expression.
7471 if (form_value.Form() == DW_FORM_strp)
7472 {
Greg Clayton54166af2014-11-22 01:58:59 +00007473 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (attributes.CompileUnitAtIndex(i)->GetAddressByteSize(), attributes.CompileUnitAtIndex(i)->IsDWARF64());
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007474 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7475 uint32_t data_length = fixed_form_sizes[form_value.Form()];
Richard Mitton0a558352013-10-17 21:14:00 +00007476 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007477 }
7478 else
7479 {
7480 const char *str = form_value.AsCString(&debug_info_data);
7481 uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart();
7482 uint32_t string_length = strlen(str) + 1;
Richard Mitton0a558352013-10-17 21:14:00 +00007483 location.CopyOpcodeData(module, debug_info_data, string_offset, string_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007484 }
7485 }
7486 }
7487 break;
Greg Clayton7f995132011-10-04 22:41:51 +00007488 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007489 {
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007490 location_is_const_value_data = false;
7491 has_explicit_location = true;
Greg Clayton7f995132011-10-04 22:41:51 +00007492 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007493 {
Ed Masteeeae7212013-10-24 20:43:47 +00007494 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Clayton7f995132011-10-04 22:41:51 +00007495
7496 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7497 uint32_t block_length = form_value.Unsigned();
Richard Mitton0a558352013-10-17 21:14:00 +00007498 location.CopyOpcodeData(module, get_debug_info_data(), block_offset, block_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007499 }
7500 else
7501 {
Ed Masteeeae7212013-10-24 20:43:47 +00007502 const DWARFDataExtractor& debug_loc_data = get_debug_loc_data();
Greg Clayton7f995132011-10-04 22:41:51 +00007503 const dw_offset_t debug_loc_offset = form_value.Unsigned();
7504
7505 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
7506 if (loc_list_length > 0)
7507 {
Richard Mitton0a558352013-10-17 21:14:00 +00007508 location.CopyOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007509 assert (func_low_pc != LLDB_INVALID_ADDRESS);
Greg Clayton54166af2014-11-22 01:58:59 +00007510 location.SetLocationListSlide (func_low_pc - attributes.CompileUnitAtIndex(i)->GetBaseAddress());
Greg Clayton7f995132011-10-04 22:41:51 +00007511 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007512 }
7513 }
Greg Clayton7f995132011-10-04 22:41:51 +00007514 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007515
Greg Clayton1c8ef472013-04-05 23:27:21 +00007516 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00007517 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007518 case DW_AT_declaration:
7519 case DW_AT_description:
7520 case DW_AT_endianity:
7521 case DW_AT_segment:
7522 case DW_AT_start_scope:
7523 case DW_AT_visibility:
7524 default:
7525 case DW_AT_abstract_origin:
7526 case DW_AT_sibling:
7527 case DW_AT_specification:
7528 break;
7529 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007530 }
7531 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007532
Greg Clayton9e9f2192013-05-17 00:55:28 +00007533 ValueType scope = eValueTypeInvalid;
7534
7535 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7536 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7537 SymbolContextScope * symbol_context_scope = NULL;
7538
Siva Chandra0783ab92015-03-24 18:32:27 +00007539 if (!mangled)
7540 {
7541 // LLDB relies on the mangled name (DW_TAG_linkage_name or DW_AT_MIPS_linkage_name) to
7542 // generate fully qualified names of global variables with commands like "frame var j".
7543 // For example, if j were an int variable holding a value 4 and declared in a namespace
7544 // B which in turn is contained in a namespace A, the command "frame var j" returns
7545 // "(int) A::B::j = 4". If the compiler does not emit a linkage name, we should be able
7546 // to generate a fully qualified name from the declaration context.
7547 if (die->GetParent()->Tag() == DW_TAG_compile_unit &&
7548 LanguageRuntime::LanguageIsCPlusPlus(dwarf_cu->GetLanguageType()))
7549 {
7550 DWARFDeclContext decl_ctx;
7551
7552 die->GetDWARFDeclContext(this, dwarf_cu, decl_ctx);
7553 mangled = decl_ctx.GetQualifiedNameAsConstString().GetCString();
7554 }
7555 }
7556
Greg Clayton9e9f2192013-05-17 00:55:28 +00007557 // DWARF doesn't specify if a DW_TAG_variable is a local, global
7558 // or static variable, so we have to do a little digging by
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00007559 // looking at the location of a variable to see if it contains
Greg Clayton9e9f2192013-05-17 00:55:28 +00007560 // a DW_OP_addr opcode _somewhere_ in the definition. I say
7561 // somewhere because clang likes to combine small global variables
7562 // into the same symbol and have locations like:
7563 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
7564 // So if we don't have a DW_TAG_formal_parameter, we can look at
7565 // the location to see if it contains a DW_OP_addr opcode, and
7566 // then we can correctly classify our variables.
7567 if (tag == DW_TAG_formal_parameter)
7568 scope = eValueTypeVariableArgument;
7569 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007570 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007571 bool op_error = false;
7572 // Check if the location has a DW_OP_addr with any address value...
7573 lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS;
7574 if (!location_is_const_value_data)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007575 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007576 location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error);
7577 if (op_error)
Greg Clayton96c09682012-01-04 22:56:43 +00007578 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007579 StreamString strm;
7580 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
7581 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 +00007582 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007583 }
Greg Claytond1767f02011-12-08 02:13:16 +00007584
Greg Clayton9e9f2192013-05-17 00:55:28 +00007585 if (location_DW_OP_addr != LLDB_INVALID_ADDRESS)
7586 {
7587 if (is_external)
7588 scope = eValueTypeVariableGlobal;
7589 else
7590 scope = eValueTypeVariableStatic;
7591
7592
7593 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile ();
7594
7595 if (debug_map_symfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007596 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007597 // When leaving the DWARF in the .o files on darwin,
7598 // when we have a global variable that wasn't initialized,
7599 // the .o file might not have allocated a virtual
7600 // address for the global variable. In this case it will
7601 // have created a symbol for the global variable
7602 // that is undefined/data and external and the value will
7603 // be the byte size of the variable. When we do the
7604 // address map in SymbolFileDWARFDebugMap we rely on
7605 // having an address, we need to do some magic here
7606 // so we can get the correct address for our global
7607 // variable. The address for all of these entries
7608 // will be zero, and there will be an undefined symbol
7609 // in this object file, and the executable will have
7610 // a matching symbol with a good address. So here we
7611 // dig up the correct address and replace it in the
7612 // location for the variable, and set the variable's
7613 // symbol context scope to be that of the main executable
7614 // so the file address will resolve correctly.
7615 bool linked_oso_file_addr = false;
7616 if (is_external && location_DW_OP_addr == 0)
Greg Clayton9422dd62013-03-04 21:46:16 +00007617 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007618 // we have a possible uninitialized extern global
7619 ConstString const_name(mangled ? mangled : name);
7620 ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile();
7621 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007622 {
Greg Clayton3046e662013-07-10 01:23:25 +00007623 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
Greg Clayton9e9f2192013-05-17 00:55:28 +00007624 if (debug_map_symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007625 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007626 Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
7627 eSymbolTypeData,
7628 Symtab::eDebugYes,
7629 Symtab::eVisibilityExtern);
7630 if (exe_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007631 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007632 if (exe_symbol->ValueIsAddress())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007633 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007634 const addr_t exe_file_addr = exe_symbol->GetAddress().GetFileAddress();
7635 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007636 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007637 if (location.Update_DW_OP_addr (exe_file_addr))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007638 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007639 linked_oso_file_addr = true;
7640 symbol_context_scope = exe_symbol;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007641 }
7642 }
7643 }
7644 }
7645 }
7646 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007647 }
Greg Clayton9422dd62013-03-04 21:46:16 +00007648
Greg Clayton9e9f2192013-05-17 00:55:28 +00007649 if (!linked_oso_file_addr)
7650 {
7651 // The DW_OP_addr is not zero, but it contains a .o file address which
7652 // needs to be linked up correctly.
7653 const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr);
7654 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton9422dd62013-03-04 21:46:16 +00007655 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007656 // Update the file address for this variable
7657 location.Update_DW_OP_addr (exe_file_addr);
7658 }
7659 else
7660 {
7661 // Variable didn't make it into the final executable
7662 return var_sp;
Greg Clayton9422dd62013-03-04 21:46:16 +00007663 }
Greg Claytond1767f02011-12-08 02:13:16 +00007664 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007665 }
Greg Clayton5cf58b92011-10-05 22:22:08 +00007666 }
7667 else
7668 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007669 scope = eValueTypeVariableLocal;
Greg Clayton5cf58b92011-10-05 22:22:08 +00007670 }
Greg Clayton7f995132011-10-04 22:41:51 +00007671 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007672
7673 if (symbol_context_scope == NULL)
7674 {
7675 switch (parent_tag)
7676 {
7677 case DW_TAG_subprogram:
7678 case DW_TAG_inlined_subroutine:
7679 case DW_TAG_lexical_block:
7680 if (sc.function)
7681 {
7682 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
7683 if (symbol_context_scope == NULL)
7684 symbol_context_scope = sc.function;
7685 }
7686 break;
7687
7688 default:
7689 symbol_context_scope = sc.comp_unit;
7690 break;
7691 }
7692 }
7693
7694 if (symbol_context_scope)
7695 {
Enrico Granata4ec130d2014-08-11 19:16:35 +00007696 SymbolFileTypeSP type_sp(new SymbolFileType(*this, type_uid));
7697
7698 if (const_value.Form() && type_sp && type_sp->GetType())
7699 location.CopyOpcodeData(const_value.Unsigned(), type_sp->GetType()->GetByteSize(), dwarf_cu->GetAddressByteSize());
7700
Greg Clayton9e9f2192013-05-17 00:55:28 +00007701 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
7702 name,
7703 mangled,
Enrico Granata4ec130d2014-08-11 19:16:35 +00007704 type_sp,
Greg Clayton9e9f2192013-05-17 00:55:28 +00007705 scope,
7706 symbol_context_scope,
7707 &decl,
7708 location,
7709 is_external,
7710 is_artificial));
7711
7712 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
7713 }
7714 else
7715 {
7716 // Not ready to parse this variable yet. It might be a global
7717 // or static variable that is in a function scope and the function
7718 // in the symbol context wasn't filled in yet
7719 return var_sp;
7720 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007721 }
Greg Clayton7f995132011-10-04 22:41:51 +00007722 // Cache var_sp even if NULL (the variable was just a specification or
7723 // was missing vital information to be able to be displayed in the debugger
7724 // (missing location due to optimization, etc)) so we don't re-parse
7725 // this DIE over and over later...
7726 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007727 }
7728 return var_sp;
7729}
7730
Greg Claytonc662ec82011-06-17 22:10:16 +00007731
7732const DWARFDebugInfoEntry *
7733SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
7734 dw_offset_t spec_block_die_offset,
7735 DWARFCompileUnit **result_die_cu_handle)
7736{
7737 // Give the concrete function die specified by "func_die_offset", find the
7738 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7739 // to "spec_block_die_offset"
7740 DWARFDebugInfo* info = DebugInfo();
7741
7742 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
7743 if (die)
7744 {
7745 assert (*result_die_cu_handle);
7746 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
7747 }
7748 return NULL;
7749}
7750
7751
7752const DWARFDebugInfoEntry *
7753SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
7754 const DWARFDebugInfoEntry *die,
7755 dw_offset_t spec_block_die_offset,
7756 DWARFCompileUnit **result_die_cu_handle)
7757{
7758 if (die)
7759 {
7760 switch (die->Tag())
7761 {
7762 case DW_TAG_subprogram:
7763 case DW_TAG_inlined_subroutine:
7764 case DW_TAG_lexical_block:
7765 {
7766 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
7767 {
7768 *result_die_cu_handle = dwarf_cu;
7769 return die;
7770 }
7771
7772 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
7773 {
7774 *result_die_cu_handle = dwarf_cu;
7775 return die;
7776 }
7777 }
7778 break;
7779 }
7780
7781 // Give the concrete function die specified by "func_die_offset", find the
7782 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7783 // to "spec_block_die_offset"
7784 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
7785 {
7786 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
7787 child_die,
7788 spec_block_die_offset,
7789 result_die_cu_handle);
7790 if (result_die)
7791 return result_die;
7792 }
7793 }
7794
7795 *result_die_cu_handle = NULL;
7796 return NULL;
7797}
7798
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007799size_t
7800SymbolFileDWARF::ParseVariables
7801(
7802 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007803 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007804 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007805 const DWARFDebugInfoEntry *orig_die,
7806 bool parse_siblings,
7807 bool parse_children,
7808 VariableList* cc_variable_list
7809)
7810{
7811 if (orig_die == NULL)
7812 return 0;
7813
Greg Claytonc662ec82011-06-17 22:10:16 +00007814 VariableListSP variable_list_sp;
7815
7816 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007817 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00007818 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007819 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007820 dw_tag_t tag = die->Tag();
7821
7822 // Check to see if we have already parsed this variable or constant?
7823 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007824 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007825 if (cc_variable_list)
7826 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007827 }
7828 else
7829 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007830 // We haven't already parsed it, lets do that now.
7831 if ((tag == DW_TAG_variable) ||
7832 (tag == DW_TAG_constant) ||
7833 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007834 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007835 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00007836 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007837 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
7838 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7839 switch (parent_tag)
7840 {
7841 case DW_TAG_compile_unit:
7842 if (sc.comp_unit != NULL)
7843 {
7844 variable_list_sp = sc.comp_unit->GetVariableList(false);
7845 if (variable_list_sp.get() == NULL)
7846 {
7847 variable_list_sp.reset(new VariableList());
7848 sc.comp_unit->SetVariableList(variable_list_sp);
7849 }
7850 }
7851 else
7852 {
Daniel Malead01b2952012-11-29 21:49:15 +00007853 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 +00007854 MakeUserID(sc_parent_die->GetOffset()),
7855 DW_TAG_value_to_name (parent_tag),
7856 MakeUserID(orig_die->GetOffset()),
7857 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007858 }
7859 break;
7860
7861 case DW_TAG_subprogram:
7862 case DW_TAG_inlined_subroutine:
7863 case DW_TAG_lexical_block:
7864 if (sc.function != NULL)
7865 {
7866 // Check to see if we already have parsed the variables for the given scope
7867
Greg Clayton81c22f62011-10-19 18:09:39 +00007868 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007869 if (block == NULL)
7870 {
7871 // This must be a specification or abstract origin with
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00007872 // a concrete block counterpart in the current function. We need
Greg Claytonc662ec82011-06-17 22:10:16 +00007873 // to find the concrete block so we can correctly add the
7874 // variable to it
7875 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
7876 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
7877 sc_parent_die->GetOffset(),
7878 &concrete_block_die_cu);
7879 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00007880 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007881 }
7882
7883 if (block != NULL)
7884 {
7885 const bool can_create = false;
7886 variable_list_sp = block->GetBlockVariableList (can_create);
7887 if (variable_list_sp.get() == NULL)
7888 {
7889 variable_list_sp.reset(new VariableList());
7890 block->SetVariableList(variable_list_sp);
7891 }
7892 }
7893 }
7894 break;
7895
7896 default:
Daniel Malead01b2952012-11-29 21:49:15 +00007897 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 +00007898 MakeUserID(orig_die->GetOffset()),
7899 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007900 break;
7901 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00007902 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007903
7904 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007905 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00007906 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
7907 if (var_sp)
7908 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007909 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00007910 if (cc_variable_list)
7911 cc_variable_list->AddVariableIfUnique (var_sp);
7912 ++vars_added;
7913 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007914 }
7915 }
7916 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007917
7918 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
7919
7920 if (!skip_children && parse_children && die->HasChildren())
7921 {
7922 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
7923 }
7924
7925 if (parse_siblings)
7926 die = die->GetSibling();
7927 else
7928 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007929 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007930 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007931}
7932
7933//------------------------------------------------------------------
7934// PluginInterface protocol
7935//------------------------------------------------------------------
Greg Clayton57abc5d2013-05-10 21:47:16 +00007936ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007937SymbolFileDWARF::GetPluginName()
7938{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007939 return GetPluginNameStatic();
7940}
7941
7942uint32_t
7943SymbolFileDWARF::GetPluginVersion()
7944{
7945 return 1;
7946}
7947
7948void
Greg Clayton6beaaa62011-01-17 03:46:26 +00007949SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
7950{
7951 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
Greg Clayton57ee3062013-07-11 22:46:58 +00007952 ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
Greg Clayton6beaaa62011-01-17 03:46:26 +00007953 if (clang_type)
7954 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7955}
7956
7957void
7958SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
7959{
7960 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
Greg Clayton57ee3062013-07-11 22:46:58 +00007961 ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
Greg Clayton6beaaa62011-01-17 03:46:26 +00007962 if (clang_type)
7963 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7964}
7965
Greg Claytona2721472011-06-25 00:44:06 +00007966void
Sean Callanancc427fa2011-07-30 02:42:06 +00007967SymbolFileDWARF::DumpIndexes ()
7968{
7969 StreamFile s(stdout, false);
7970
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00007971 s.Printf ("DWARF index for (%s) '%s':",
Sean Callanancc427fa2011-07-30 02:42:06 +00007972 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00007973 GetObjectFile()->GetFileSpec().GetPath().c_str());
Sean Callanancc427fa2011-07-30 02:42:06 +00007974 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
7975 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
7976 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
7977 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
7978 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
7979 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
7980 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
7981 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
7982}
7983
7984void
7985SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
7986 const char *name,
7987 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00007988{
Sean Callanancc427fa2011-07-30 02:42:06 +00007989 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00007990
7991 if (iter == m_decl_ctx_to_die.end())
7992 return;
7993
Greg Claytoncb5860a2011-10-13 23:49:28 +00007994 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00007995 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007996 const DWARFDebugInfoEntry *context_die = *pos;
7997
7998 if (!results)
7999 return;
8000
8001 DWARFDebugInfo* info = DebugInfo();
8002
8003 DIEArray die_offsets;
8004
8005 DWARFCompileUnit* dwarf_cu = NULL;
8006 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton220a0072011-12-09 08:48:30 +00008007
8008 if (m_using_apple_tables)
8009 {
8010 if (m_apple_types_ap.get())
8011 m_apple_types_ap->FindByName (name, die_offsets);
8012 }
8013 else
8014 {
8015 if (!m_indexed)
8016 Index ();
8017
8018 m_type_index.Find (ConstString(name), die_offsets);
8019 }
8020
Greg Clayton220a0072011-12-09 08:48:30 +00008021 const size_t num_matches = die_offsets.size();
Greg Claytoncb5860a2011-10-13 23:49:28 +00008022
8023 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00008024 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00008025 for (size_t i = 0; i < num_matches; ++i)
8026 {
8027 const dw_offset_t die_offset = die_offsets[i];
8028 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00008029
Greg Claytoncb5860a2011-10-13 23:49:28 +00008030 if (die->GetParent() != context_die)
8031 continue;
8032
8033 Type *matching_type = ResolveType (dwarf_cu, die);
8034
Greg Clayton57ee3062013-07-11 22:46:58 +00008035 clang::QualType qual_type = matching_type->GetClangForwardType().GetQualType();
Greg Claytoncb5860a2011-10-13 23:49:28 +00008036
8037 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
8038 {
8039 clang::TagDecl *tag_decl = tag_type->getDecl();
8040 results->push_back(tag_decl);
8041 }
8042 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
8043 {
8044 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
8045 results->push_back(typedef_decl);
8046 }
Greg Claytona2721472011-06-25 00:44:06 +00008047 }
8048 }
8049 }
8050}
8051
8052void
8053SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00008054 const clang::DeclContext *decl_context,
8055 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00008056 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
8057{
Greg Clayton85ae2e12011-10-18 23:36:41 +00008058
8059 switch (decl_context->getDeclKind())
8060 {
8061 case clang::Decl::Namespace:
8062 case clang::Decl::TranslationUnit:
8063 {
8064 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
8065 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
8066 }
8067 break;
8068 default:
8069 break;
8070 }
Greg Claytona2721472011-06-25 00:44:06 +00008071}
Greg Claytoncaab74e2012-01-28 00:48:57 +00008072
Zachary Turner504f38d2015-03-24 16:24:50 +00008073bool
8074SymbolFileDWARF::LayoutRecordType(void *baton, const clang::RecordDecl *record_decl, uint64_t &size,
8075 uint64_t &alignment,
Zachary Turnera98fac22015-03-24 18:56:08 +00008076 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
8077 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
8078 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
Greg Claytoncaab74e2012-01-28 00:48:57 +00008079{
8080 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
8081 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
8082}
8083
Zachary Turner504f38d2015-03-24 16:24:50 +00008084bool
8085SymbolFileDWARF::LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &bit_size, uint64_t &alignment,
Zachary Turnera98fac22015-03-24 18:56:08 +00008086 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
8087 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
8088 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
Greg Claytoncaab74e2012-01-28 00:48:57 +00008089{
Greg Clayton5160ce52013-03-27 23:08:40 +00008090 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Claytoncaab74e2012-01-28 00:48:57 +00008091 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
8092 bool success = false;
8093 base_offsets.clear();
8094 vbase_offsets.clear();
8095 if (pos != m_record_decl_to_layout_map.end())
8096 {
8097 bit_size = pos->second.bit_size;
8098 alignment = pos->second.alignment;
8099 field_offsets.swap(pos->second.field_offsets);
Greg Clayton2508b9b2012-11-01 23:20:02 +00008100 base_offsets.swap (pos->second.base_offsets);
8101 vbase_offsets.swap (pos->second.vbase_offsets);
Greg Claytoncaab74e2012-01-28 00:48:57 +00008102 m_record_decl_to_layout_map.erase(pos);
8103 success = true;
8104 }
8105 else
8106 {
8107 bit_size = 0;
8108 alignment = 0;
8109 field_offsets.clear();
8110 }
8111
8112 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00008113 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00008114 "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 +00008115 static_cast<const void*>(record_decl),
8116 bit_size, alignment,
8117 static_cast<uint32_t>(field_offsets.size()),
8118 static_cast<uint32_t>(base_offsets.size()),
8119 static_cast<uint32_t>(vbase_offsets.size()),
Greg Claytoncaab74e2012-01-28 00:48:57 +00008120 success);
8121 return success;
8122}
8123
8124
Greg Clayton1f746072012-08-29 21:13:06 +00008125SymbolFileDWARFDebugMap *
8126SymbolFileDWARF::GetDebugMapSymfile ()
8127{
8128 if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired())
8129 {
8130 lldb::ModuleSP module_sp (m_debug_map_module_wp.lock());
8131 if (module_sp)
8132 {
8133 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
8134 if (sym_vendor)
8135 m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile();
8136 }
8137 }
8138 return m_debug_map_symfile;
8139}
8140
Greg Claytoncaab74e2012-01-28 00:48:57 +00008141