blob: c3351d4adeaac1bf10ce7984aa9cfe916b88bd48 [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
Oleksiy Vyalov5d9c50b2015-07-21 02:09:42 +000044#include "lldb/Host/FileSystem.h"
Greg Clayton20568dd2011-10-13 23:13:20 +000045#include "lldb/Host/Host.h"
46
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +000047#include "lldb/Interpreter/OptionValueFileSpecList.h"
48#include "lldb/Interpreter/OptionValueProperties.h"
49
Chris Lattner30fdc8d2010-06-08 16:52:24 +000050#include "lldb/Symbol/Block.h"
Greg Clayton6beaaa62011-01-17 03:46:26 +000051#include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052#include "lldb/Symbol/CompileUnit.h"
53#include "lldb/Symbol/LineTable.h"
54#include "lldb/Symbol/ObjectFile.h"
55#include "lldb/Symbol/SymbolVendor.h"
56#include "lldb/Symbol/VariableList.h"
57
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000058#include "lldb/Target/ObjCLanguageRuntime.h"
Jim Ingham4cda6e02011-10-07 22:23:45 +000059#include "lldb/Target/CPPLanguageRuntime.h"
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000060
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061#include "DWARFCompileUnit.h"
62#include "DWARFDebugAbbrev.h"
63#include "DWARFDebugAranges.h"
64#include "DWARFDebugInfo.h"
65#include "DWARFDebugInfoEntry.h"
66#include "DWARFDebugLine.h"
67#include "DWARFDebugPubnames.h"
68#include "DWARFDebugRanges.h"
Greg Claytona8022fa2012-04-24 21:22:41 +000069#include "DWARFDeclContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000070#include "DWARFDIECollection.h"
71#include "DWARFFormValue.h"
72#include "DWARFLocationList.h"
73#include "LogChannelDWARF.h"
Greg Clayton450e3f32010-10-12 02:24:53 +000074#include "SymbolFileDWARFDebugMap.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000075
76#include <map>
77
Matthew Gardinere81df3b2014-08-26 06:57:23 +000078#include <ctype.h>
79#include <string.h>
80
Greg Clayton62742b12010-11-11 01:09:45 +000081//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
Greg Claytonc93237c2010-10-01 20:48:32 +000082
83#ifdef ENABLE_DEBUG_PRINTF
84#include <stdio.h>
Ed Mastea0191d12013-10-17 20:42:56 +000085#define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__)
Greg Claytonc93237c2010-10-01 20:48:32 +000086#else
87#define DEBUG_PRINTF(fmt, ...)
88#endif
89
Greg Clayton594e5ed2010-09-27 21:07:38 +000090#define DIE_IS_BEING_PARSED ((lldb_private::Type*)1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000091
92using namespace lldb;
93using namespace lldb_private;
94
Greg Clayton219cf312012-03-30 00:51:13 +000095//static inline bool
96//child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag)
97//{
98// switch (tag)
99// {
100// default:
101// break;
102// case DW_TAG_subprogram:
103// case DW_TAG_inlined_subroutine:
104// case DW_TAG_class_type:
105// case DW_TAG_structure_type:
106// case DW_TAG_union_type:
107// return true;
108// }
109// return false;
110//}
111//
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +0000112
113namespace {
114
115 PropertyDefinition
116 g_properties[] =
117 {
118 { "comp-dir-symlink-paths" , OptionValue::eTypeFileSpecList, true, 0 , nullptr, nullptr, "If the DW_AT_comp_dir matches any of these paths the symbolic links will be resolved at DWARF parse time." },
119 { nullptr , OptionValue::eTypeInvalid , false, 0, nullptr, nullptr, nullptr }
120 };
121
122 enum
123 {
124 ePropertySymLinkPaths
125 };
126
127
128 class PluginProperties : public Properties
129 {
130 public:
131 static ConstString
132 GetSettingName()
133 {
134 return SymbolFileDWARF::GetPluginNameStatic();
135 }
136
137 PluginProperties()
138 {
139 m_collection_sp.reset (new OptionValueProperties(GetSettingName()));
140 m_collection_sp->Initialize(g_properties);
141 }
142
143 FileSpecList&
144 GetSymLinkPaths()
145 {
146 OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(nullptr, true, ePropertySymLinkPaths);
147 assert(option_value);
148 return option_value->GetCurrentValue();
149 }
150
151 };
152
153 typedef std::shared_ptr<PluginProperties> SymbolFileDWARFPropertiesSP;
154
155 static const SymbolFileDWARFPropertiesSP&
156 GetGlobalPluginProperties()
157 {
158 static const auto g_settings_sp(std::make_shared<PluginProperties>());
159 return g_settings_sp;
160 }
161
162} // anonymous namespace end
163
164
Sean Callananc7fbf732010-08-06 00:32:49 +0000165static AccessType
Greg Clayton8cf05932010-07-22 18:30:50 +0000166DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000167{
168 switch (dwarf_accessibility)
169 {
Sean Callananc7fbf732010-08-06 00:32:49 +0000170 case DW_ACCESS_public: return eAccessPublic;
171 case DW_ACCESS_private: return eAccessPrivate;
172 case DW_ACCESS_protected: return eAccessProtected;
Greg Clayton8cf05932010-07-22 18:30:50 +0000173 default: break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000174 }
Sean Callananc7fbf732010-08-06 00:32:49 +0000175 return eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000176}
177
Matthew Gardinere81df3b2014-08-26 06:57:23 +0000178static const char*
179removeHostnameFromPathname(const char* path_from_dwarf)
180{
181 if (!path_from_dwarf || !path_from_dwarf[0])
182 {
183 return path_from_dwarf;
184 }
Enrico Granata99e5e222015-07-27 21:27:02 +0000185
Matthew Gardinere81df3b2014-08-26 06:57:23 +0000186 const char *colon_pos = strchr(path_from_dwarf, ':');
Enrico Granata99e5e222015-07-27 21:27:02 +0000187 if (nullptr == colon_pos)
188 {
189 return path_from_dwarf;
190 }
191
192 const char *slash_pos = strchr(path_from_dwarf, '/');
193 if (slash_pos && (slash_pos < colon_pos))
Matthew Gardinere81df3b2014-08-26 06:57:23 +0000194 {
195 return path_from_dwarf;
196 }
197
198 // check whether we have a windows path, and so the first character
199 // is a drive-letter not a hostname.
200 if (
201 colon_pos == path_from_dwarf + 1 &&
202 isalpha(*path_from_dwarf) &&
203 strlen(path_from_dwarf) > 2 &&
204 '\\' == path_from_dwarf[2])
205 {
206 return path_from_dwarf;
207 }
Enrico Granata99e5e222015-07-27 21:27:02 +0000208
Matthew Gardinere81df3b2014-08-26 06:57:23 +0000209 return colon_pos + 1;
210}
211
Oleksiy Vyalov5d9c50b2015-07-21 02:09:42 +0000212static const char*
213resolveCompDir(const char* path_from_dwarf)
214{
215 if (!path_from_dwarf)
216 return nullptr;
217
218 // DWARF2/3 suggests the form hostname:pathname for compilation directory.
219 // Remove the host part if present.
220 const char* local_path = removeHostnameFromPathname(path_from_dwarf);
221 if (!local_path)
222 return nullptr;
223
224 bool is_symlink = false;
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +0000225 FileSpec local_path_spec(local_path, false);
226 const auto& file_specs = GetGlobalPluginProperties()->GetSymLinkPaths();
227 for (size_t i = 0; i < file_specs.GetSize() && !is_symlink; ++i)
228 is_symlink = FileSpec::Equal(file_specs.GetFileSpecAtIndex(i), local_path_spec, true);
Oleksiy Vyalov5d9c50b2015-07-21 02:09:42 +0000229
230 if (!is_symlink)
231 return local_path;
232
Oleksiy Vyalov5d9c50b2015-07-21 02:09:42 +0000233 if (!local_path_spec.IsSymbolicLink())
234 return local_path;
235
236 FileSpec resolved_local_path_spec;
237 const auto error = FileSystem::Readlink(local_path_spec, resolved_local_path_spec);
238 if (error.Success())
239 return resolved_local_path_spec.GetCString();
240
241 return nullptr;
242}
243
244
Todd Fiala0a70a842014-05-28 16:43:26 +0000245#if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE)
Greg Clayton1fba87112012-02-09 20:03:49 +0000246
247class DIEStack
248{
249public:
250
251 void Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
252 {
253 m_dies.push_back (DIEInfo(cu, die));
254 }
255
256
257 void LogDIEs (Log *log, SymbolFileDWARF *dwarf)
258 {
259 StreamString log_strm;
260 const size_t n = m_dies.size();
Daniel Malead01b2952012-11-29 21:49:15 +0000261 log_strm.Printf("DIEStack[%" PRIu64 "]:\n", (uint64_t)n);
Greg Clayton1fba87112012-02-09 20:03:49 +0000262 for (size_t i=0; i<n; i++)
263 {
264 DWARFCompileUnit *cu = m_dies[i].cu;
265 const DWARFDebugInfoEntry *die = m_dies[i].die;
266 std::string qualified_name;
267 die->GetQualifiedName(dwarf, cu, qualified_name);
Daniel Malead01b2952012-11-29 21:49:15 +0000268 log_strm.Printf ("[%" PRIu64 "] 0x%8.8x: %s name='%s'\n",
Greg Clayton43e0af02012-09-18 18:04:04 +0000269 (uint64_t)i,
Greg Clayton1fba87112012-02-09 20:03:49 +0000270 die->GetOffset(),
271 DW_TAG_value_to_name(die->Tag()),
272 qualified_name.c_str());
273 }
274 log->PutCString(log_strm.GetData());
275 }
276 void Pop ()
277 {
278 m_dies.pop_back();
279 }
280
281 class ScopedPopper
282 {
283 public:
284 ScopedPopper (DIEStack &die_stack) :
285 m_die_stack (die_stack),
286 m_valid (false)
287 {
288 }
289
290 void
291 Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
292 {
293 m_valid = true;
294 m_die_stack.Push (cu, die);
295 }
296
297 ~ScopedPopper ()
298 {
299 if (m_valid)
300 m_die_stack.Pop();
301 }
302
303
304
305 protected:
306 DIEStack &m_die_stack;
307 bool m_valid;
308 };
309
310protected:
311 struct DIEInfo {
312 DIEInfo (DWARFCompileUnit *c, const DWARFDebugInfoEntry *d) :
313 cu(c),
314 die(d)
315 {
316 }
317 DWARFCompileUnit *cu;
318 const DWARFDebugInfoEntry *die;
319 };
320 typedef std::vector<DIEInfo> Stack;
321 Stack m_dies;
322};
323#endif
324
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000325void
326SymbolFileDWARF::Initialize()
327{
328 LogChannelDWARF::Initialize();
329 PluginManager::RegisterPlugin (GetPluginNameStatic(),
330 GetPluginDescriptionStatic(),
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +0000331 CreateInstance,
332 DebuggerInitialize);
333}
334
335void
336SymbolFileDWARF::DebuggerInitialize(Debugger &debugger)
337{
338 if (!PluginManager::GetSettingForSymbolFilePlugin(debugger, PluginProperties::GetSettingName()))
339 {
340 const bool is_global_setting = true;
341 PluginManager::CreateSettingForSymbolFilePlugin(debugger,
342 GetGlobalPluginProperties()->GetValueProperties(),
343 ConstString ("Properties for the dwarf symbol-file plug-in."),
344 is_global_setting);
345 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000346}
347
348void
349SymbolFileDWARF::Terminate()
350{
351 PluginManager::UnregisterPlugin (CreateInstance);
352 LogChannelDWARF::Initialize();
353}
354
355
Greg Clayton57abc5d2013-05-10 21:47:16 +0000356lldb_private::ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000357SymbolFileDWARF::GetPluginNameStatic()
358{
Greg Clayton57abc5d2013-05-10 21:47:16 +0000359 static ConstString g_name("dwarf");
360 return g_name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000361}
362
363const char *
364SymbolFileDWARF::GetPluginDescriptionStatic()
365{
366 return "DWARF and DWARF3 debug symbol file reader.";
367}
368
369
370SymbolFile*
371SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
372{
373 return new SymbolFileDWARF(obj_file);
374}
375
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000376TypeList *
377SymbolFileDWARF::GetTypeList ()
378{
Greg Clayton1f746072012-08-29 21:13:06 +0000379 if (GetDebugMapSymfile ())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000380 return m_debug_map_symfile->GetTypeList();
381 return m_obj_file->GetModule()->GetTypeList();
382
383}
Greg Claytonf02500c2013-06-18 22:51:05 +0000384void
385SymbolFileDWARF::GetTypes (DWARFCompileUnit* cu,
386 const DWARFDebugInfoEntry *die,
387 dw_offset_t min_die_offset,
388 dw_offset_t max_die_offset,
389 uint32_t type_mask,
390 TypeSet &type_set)
391{
392 if (cu)
393 {
394 if (die)
395 {
396 const dw_offset_t die_offset = die->GetOffset();
397
398 if (die_offset >= max_die_offset)
399 return;
400
401 if (die_offset >= min_die_offset)
402 {
403 const dw_tag_t tag = die->Tag();
404
405 bool add_type = false;
406
407 switch (tag)
408 {
409 case DW_TAG_array_type: add_type = (type_mask & eTypeClassArray ) != 0; break;
410 case DW_TAG_unspecified_type:
411 case DW_TAG_base_type: add_type = (type_mask & eTypeClassBuiltin ) != 0; break;
412 case DW_TAG_class_type: add_type = (type_mask & eTypeClassClass ) != 0; break;
413 case DW_TAG_structure_type: add_type = (type_mask & eTypeClassStruct ) != 0; break;
414 case DW_TAG_union_type: add_type = (type_mask & eTypeClassUnion ) != 0; break;
415 case DW_TAG_enumeration_type: add_type = (type_mask & eTypeClassEnumeration ) != 0; break;
416 case DW_TAG_subroutine_type:
417 case DW_TAG_subprogram:
418 case DW_TAG_inlined_subroutine: add_type = (type_mask & eTypeClassFunction ) != 0; break;
419 case DW_TAG_pointer_type: add_type = (type_mask & eTypeClassPointer ) != 0; break;
420 case DW_TAG_rvalue_reference_type:
421 case DW_TAG_reference_type: add_type = (type_mask & eTypeClassReference ) != 0; break;
422 case DW_TAG_typedef: add_type = (type_mask & eTypeClassTypedef ) != 0; break;
423 case DW_TAG_ptr_to_member_type: add_type = (type_mask & eTypeClassMemberPointer ) != 0; break;
424 }
425
426 if (add_type)
427 {
428 const bool assert_not_being_parsed = true;
429 Type *type = ResolveTypeUID (cu, die, assert_not_being_parsed);
430 if (type)
431 {
432 if (type_set.find(type) == type_set.end())
433 type_set.insert(type);
434 }
435 }
436 }
437
438 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild();
439 child_die != NULL;
440 child_die = child_die->GetSibling())
441 {
442 GetTypes (cu, child_die, min_die_offset, max_die_offset, type_mask, type_set);
443 }
444 }
445 }
446}
447
448size_t
449SymbolFileDWARF::GetTypes (SymbolContextScope *sc_scope,
450 uint32_t type_mask,
451 TypeList &type_list)
452
453{
454 TypeSet type_set;
455
456 CompileUnit *comp_unit = NULL;
457 DWARFCompileUnit* dwarf_cu = NULL;
458 if (sc_scope)
459 comp_unit = sc_scope->CalculateSymbolContextCompileUnit();
460
461 if (comp_unit)
462 {
463 dwarf_cu = GetDWARFCompileUnit(comp_unit);
464 if (dwarf_cu == 0)
465 return 0;
466 GetTypes (dwarf_cu,
467 dwarf_cu->DIE(),
468 dwarf_cu->GetOffset(),
469 dwarf_cu->GetNextCompileUnitOffset(),
470 type_mask,
471 type_set);
472 }
473 else
474 {
475 DWARFDebugInfo* info = DebugInfo();
476 if (info)
477 {
478 const size_t num_cus = info->GetNumCompileUnits();
479 for (size_t cu_idx=0; cu_idx<num_cus; ++cu_idx)
480 {
481 dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
482 if (dwarf_cu)
483 {
484 GetTypes (dwarf_cu,
485 dwarf_cu->DIE(),
486 0,
487 UINT32_MAX,
488 type_mask,
489 type_set);
490 }
491 }
492 }
493 }
494// if (m_using_apple_tables)
495// {
496// DWARFMappedHash::MemoryTable *apple_types = m_apple_types_ap.get();
497// if (apple_types)
498// {
499// apple_types->ForEach([this, &type_set, apple_types, type_mask](const DWARFMappedHash::DIEInfoArray &die_info_array) -> bool {
500//
501// for (auto die_info: die_info_array)
502// {
503// bool add_type = TagMatchesTypeMask (type_mask, 0);
504// if (!add_type)
505// {
506// dw_tag_t tag = die_info.tag;
507// if (tag == 0)
508// {
509// const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_info.offset, NULL);
510// tag = die->Tag();
511// }
512// add_type = TagMatchesTypeMask (type_mask, tag);
513// }
514// if (add_type)
515// {
516// Type *type = ResolveTypeUID(die_info.offset);
517//
518// if (type_set.find(type) == type_set.end())
519// type_set.insert(type);
520// }
521// }
522// return true; // Keep iterating
523// });
524// }
525// }
526// else
527// {
528// if (!m_indexed)
529// Index ();
530//
531// m_type_index.ForEach([this, &type_set, type_mask](const char *name, uint32_t die_offset) -> bool {
532//
533// bool add_type = TagMatchesTypeMask (type_mask, 0);
534//
535// if (!add_type)
536// {
537// const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_offset, NULL);
538// if (die)
539// {
540// const dw_tag_t tag = die->Tag();
541// add_type = TagMatchesTypeMask (type_mask, tag);
542// }
543// }
544//
545// if (add_type)
546// {
547// Type *type = ResolveTypeUID(die_offset);
548//
549// if (type_set.find(type) == type_set.end())
550// type_set.insert(type);
551// }
552// return true; // Keep iterating
553// });
554// }
555
Greg Claytona1e5dc82015-08-11 22:53:00 +0000556 std::set<CompilerType> clang_type_set;
Greg Claytonf02500c2013-06-18 22:51:05 +0000557 size_t num_types_added = 0;
558 for (Type *type : type_set)
559 {
Greg Claytona1e5dc82015-08-11 22:53:00 +0000560 CompilerType clang_type = type->GetClangForwardType();
Greg Clayton0fc4f312013-06-20 01:23:18 +0000561 if (clang_type_set.find(clang_type) == clang_type_set.end())
562 {
563 clang_type_set.insert(clang_type);
564 type_list.Insert (type->shared_from_this());
565 ++num_types_added;
566 }
Greg Claytonf02500c2013-06-18 22:51:05 +0000567 }
568 return num_types_added;
569}
570
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000571
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000572//----------------------------------------------------------------------
573// Gets the first parent that is a lexical block, function or inlined
574// subroutine, or compile unit.
575//----------------------------------------------------------------------
576static const DWARFDebugInfoEntry *
577GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
578{
579 const DWARFDebugInfoEntry *die;
580 for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
581 {
582 dw_tag_t tag = die->Tag();
583
584 switch (tag)
585 {
586 case DW_TAG_compile_unit:
587 case DW_TAG_subprogram:
588 case DW_TAG_inlined_subroutine:
589 case DW_TAG_lexical_block:
590 return die;
591 }
592 }
593 return NULL;
594}
595
596
Greg Clayton450e3f32010-10-12 02:24:53 +0000597SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
598 SymbolFile (objfile),
Greg Clayton81c22f62011-10-19 18:09:39 +0000599 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 +0000600 m_debug_map_module_wp (),
Greg Clayton450e3f32010-10-12 02:24:53 +0000601 m_debug_map_symfile (NULL),
Greg Clayton7a345282010-11-09 23:46:37 +0000602 m_clang_tu_decl (NULL),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000603 m_flags(),
Greg Claytond4a2b372011-09-12 23:21:58 +0000604 m_data_debug_abbrev (),
605 m_data_debug_aranges (),
606 m_data_debug_frame (),
607 m_data_debug_info (),
608 m_data_debug_line (),
609 m_data_debug_loc (),
610 m_data_debug_ranges (),
611 m_data_debug_str (),
Greg Clayton17674402011-09-28 17:06:40 +0000612 m_data_apple_names (),
613 m_data_apple_types (),
Greg Clayton7f995132011-10-04 22:41:51 +0000614 m_data_apple_namespaces (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000615 m_abbr(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000616 m_info(),
617 m_line(),
Greg Clayton7f995132011-10-04 22:41:51 +0000618 m_apple_names_ap (),
619 m_apple_types_ap (),
620 m_apple_namespaces_ap (),
Greg Clayton5009f9d2011-10-27 17:55:14 +0000621 m_apple_objc_ap (),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000622 m_function_basename_index(),
623 m_function_fullname_index(),
624 m_function_method_index(),
625 m_function_selector_index(),
Greg Clayton450e3f32010-10-12 02:24:53 +0000626 m_objc_class_selectors_index(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000627 m_global_index(),
Greg Clayton69b04882010-10-15 02:03:22 +0000628 m_type_index(),
629 m_namespace_index(),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000630 m_indexed (false),
631 m_is_external_ast_source (false),
Greg Clayton97fbc342011-10-20 22:30:33 +0000632 m_using_apple_tables (false),
Sean Callananf0c5aeb2015-04-20 16:31:29 +0000633 m_fetched_external_modules (false),
Greg Claytonc7f03b62012-01-12 04:33:28 +0000634 m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +0000635 m_ranges(),
636 m_unique_ast_type_map ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000637{
638}
639
640SymbolFileDWARF::~SymbolFileDWARF()
641{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000642 if (m_is_external_ast_source)
Greg Claytone72dfb32012-02-24 01:59:29 +0000643 {
644 ModuleSP module_sp (m_obj_file->GetModule());
645 if (module_sp)
646 module_sp->GetClangASTContext().RemoveExternalSource ();
647 }
Greg Clayton6beaaa62011-01-17 03:46:26 +0000648}
649
650static const ConstString &
651GetDWARFMachOSegmentName ()
652{
653 static ConstString g_dwarf_section_name ("__DWARF");
654 return g_dwarf_section_name;
655}
656
Greg Claytone576ab22011-02-15 00:19:15 +0000657UniqueDWARFASTTypeMap &
658SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
659{
Greg Clayton1f746072012-08-29 21:13:06 +0000660 if (GetDebugMapSymfile ())
Greg Claytone576ab22011-02-15 00:19:15 +0000661 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
662 return m_unique_ast_type_map;
663}
664
Greg Clayton6beaaa62011-01-17 03:46:26 +0000665ClangASTContext &
666SymbolFileDWARF::GetClangASTContext ()
667{
Greg Clayton1f746072012-08-29 21:13:06 +0000668 if (GetDebugMapSymfile ())
Greg Clayton6beaaa62011-01-17 03:46:26 +0000669 return m_debug_map_symfile->GetClangASTContext ();
670
671 ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext();
672 if (!m_is_external_ast_source)
673 {
674 m_is_external_ast_source = true;
Todd Fiala955fe6f2014-02-27 17:18:23 +0000675 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source_ap (
Greg Clayton6beaaa62011-01-17 03:46:26 +0000676 new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl,
677 SymbolFileDWARF::CompleteObjCInterfaceDecl,
Greg Claytona2721472011-06-25 00:44:06 +0000678 SymbolFileDWARF::FindExternalVisibleDeclsByName,
Greg Claytoncaab74e2012-01-28 00:48:57 +0000679 SymbolFileDWARF::LayoutRecordType,
Greg Clayton6beaaa62011-01-17 03:46:26 +0000680 this));
Greg Clayton6beaaa62011-01-17 03:46:26 +0000681 ast.SetExternalSource (ast_source_ap);
682 }
683 return ast;
684}
685
686void
687SymbolFileDWARF::InitializeObject()
688{
689 // Install our external AST source callbacks so we can complete Clang types.
Greg Claytone72dfb32012-02-24 01:59:29 +0000690 ModuleSP module_sp (m_obj_file->GetModule());
691 if (module_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +0000692 {
Greg Clayton3046e662013-07-10 01:23:25 +0000693 const SectionList *section_list = module_sp->GetSectionList();
Greg Clayton6beaaa62011-01-17 03:46:26 +0000694
695 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
696
697 // Memory map the DWARF mach-o segment so we have everything mmap'ed
698 // to keep our heap memory usage down.
699 if (section)
Greg Claytonc9660542012-02-05 02:38:54 +0000700 m_obj_file->MemoryMapSectionData(section, m_dwarf_data);
Greg Clayton6beaaa62011-01-17 03:46:26 +0000701 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000702 get_apple_names_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000703 if (m_data_apple_names.GetByteSize() > 0)
704 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000705 m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names"));
706 if (m_apple_names_ap->IsValid())
707 m_using_apple_tables = true;
708 else
Greg Clayton7f995132011-10-04 22:41:51 +0000709 m_apple_names_ap.reset();
710 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000711 get_apple_types_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000712 if (m_data_apple_types.GetByteSize() > 0)
713 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000714 m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types"));
715 if (m_apple_types_ap->IsValid())
716 m_using_apple_tables = true;
717 else
Greg Clayton7f995132011-10-04 22:41:51 +0000718 m_apple_types_ap.reset();
719 }
720
721 get_apple_namespaces_data();
722 if (m_data_apple_namespaces.GetByteSize() > 0)
723 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000724 m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces"));
725 if (m_apple_namespaces_ap->IsValid())
726 m_using_apple_tables = true;
727 else
Greg Clayton7f995132011-10-04 22:41:51 +0000728 m_apple_namespaces_ap.reset();
729 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000730
Greg Clayton5009f9d2011-10-27 17:55:14 +0000731 get_apple_objc_data();
732 if (m_data_apple_objc.GetByteSize() > 0)
733 {
734 m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc"));
735 if (m_apple_objc_ap->IsValid())
736 m_using_apple_tables = true;
737 else
738 m_apple_objc_ap.reset();
739 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000740}
741
742bool
743SymbolFileDWARF::SupportedVersion(uint16_t version)
744{
Greg Claytonabcbfe52013-04-04 00:00:36 +0000745 return version == 2 || version == 3 || version == 4;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000746}
747
748uint32_t
Sean Callananbfaf54d2011-12-03 04:38:43 +0000749SymbolFileDWARF::CalculateAbilities ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000750{
751 uint32_t abilities = 0;
752 if (m_obj_file != NULL)
753 {
754 const Section* section = NULL;
755 const SectionList *section_list = m_obj_file->GetSectionList();
756 if (section_list == NULL)
757 return 0;
758
759 uint64_t debug_abbrev_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000760 uint64_t debug_info_file_size = 0;
761 uint64_t debug_line_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000762
Greg Clayton6beaaa62011-01-17 03:46:26 +0000763 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000764
765 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000766 section_list = &section->GetChildren ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000767
Greg Clayton4ceb9982010-07-21 22:54:26 +0000768 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000769 if (section != NULL)
770 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000771 debug_info_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000772
Greg Clayton4ceb9982010-07-21 22:54:26 +0000773 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000774 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000775 debug_abbrev_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000776 else
777 m_flags.Set (flagsGotDebugAbbrevData);
778
Greg Clayton4ceb9982010-07-21 22:54:26 +0000779 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000780 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000781 m_flags.Set (flagsGotDebugArangesData);
782
Greg Clayton4ceb9982010-07-21 22:54:26 +0000783 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000784 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000785 m_flags.Set (flagsGotDebugFrameData);
786
Greg Clayton4ceb9982010-07-21 22:54:26 +0000787 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000788 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000789 debug_line_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000790 else
791 m_flags.Set (flagsGotDebugLineData);
792
Greg Clayton4ceb9982010-07-21 22:54:26 +0000793 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000794 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000795 m_flags.Set (flagsGotDebugLocData);
796
Greg Clayton4ceb9982010-07-21 22:54:26 +0000797 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000798 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000799 m_flags.Set (flagsGotDebugMacInfoData);
800
Greg Clayton4ceb9982010-07-21 22:54:26 +0000801 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000802 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000803 m_flags.Set (flagsGotDebugPubNamesData);
804
Greg Clayton4ceb9982010-07-21 22:54:26 +0000805 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000806 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000807 m_flags.Set (flagsGotDebugPubTypesData);
808
Greg Clayton4ceb9982010-07-21 22:54:26 +0000809 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000810 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000811 m_flags.Set (flagsGotDebugRangesData);
812
Greg Clayton4ceb9982010-07-21 22:54:26 +0000813 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000814 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000815 m_flags.Set (flagsGotDebugStrData);
816 }
Greg Clayton6c596612012-05-18 21:47:20 +0000817 else
818 {
819 const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString();
820 if (symfile_dir_cstr)
821 {
822 if (strcasestr(symfile_dir_cstr, ".dsym"))
823 {
824 if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo)
825 {
826 // We have a dSYM file that didn't have a any debug info.
827 // If the string table has a size of 1, then it was made from
828 // an executable with no debug info, or from an executable that
829 // was stripped.
830 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
831 if (section && section->GetFileSize() == 1)
832 {
833 m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info.");
834 }
835 }
836 }
837 }
838 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000839
840 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
841 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
842
843 if (debug_line_file_size > 0)
844 abilities |= LineTables;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000845 }
846 return abilities;
847}
848
Ed Masteeeae7212013-10-24 20:43:47 +0000849const DWARFDataExtractor&
850SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DWARFDataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000851{
852 if (m_flags.IsClear (got_flag))
853 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000854 ModuleSP module_sp (m_obj_file->GetModule());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000855 m_flags.Set (got_flag);
Greg Clayton3046e662013-07-10 01:23:25 +0000856 const SectionList *section_list = module_sp->GetSectionList();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000857 if (section_list)
858 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000859 SectionSP section_sp (section_list->FindSectionByType(sect_type, true));
860 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000861 {
862 // See if we memory mapped the DWARF segment?
863 if (m_dwarf_data.GetByteSize())
864 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000865 data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000866 }
867 else
868 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000869 if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000870 data.Clear();
871 }
872 }
873 }
874 }
875 return data;
876}
877
Ed Masteeeae7212013-10-24 20:43:47 +0000878const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000879SymbolFileDWARF::get_debug_abbrev_data()
880{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000881 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000882}
883
Ed Masteeeae7212013-10-24 20:43:47 +0000884const DWARFDataExtractor&
Greg Claytond4a2b372011-09-12 23:21:58 +0000885SymbolFileDWARF::get_debug_aranges_data()
886{
887 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
888}
889
Ed Masteeeae7212013-10-24 20:43:47 +0000890const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000891SymbolFileDWARF::get_debug_frame_data()
892{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000893 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000894}
895
Ed Masteeeae7212013-10-24 20:43:47 +0000896const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000897SymbolFileDWARF::get_debug_info_data()
898{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000899 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000900}
901
Ed Masteeeae7212013-10-24 20:43:47 +0000902const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000903SymbolFileDWARF::get_debug_line_data()
904{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000905 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000906}
907
Ed Masteeeae7212013-10-24 20:43:47 +0000908const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000909SymbolFileDWARF::get_debug_loc_data()
910{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000911 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000912}
913
Ed Masteeeae7212013-10-24 20:43:47 +0000914const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000915SymbolFileDWARF::get_debug_ranges_data()
916{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000917 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000918}
919
Ed Masteeeae7212013-10-24 20:43:47 +0000920const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000921SymbolFileDWARF::get_debug_str_data()
922{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000923 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000924}
925
Ed Masteeeae7212013-10-24 20:43:47 +0000926const DWARFDataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000927SymbolFileDWARF::get_apple_names_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000928{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000929 return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names);
Greg Claytonf9eec202011-09-01 23:16:13 +0000930}
931
Ed Masteeeae7212013-10-24 20:43:47 +0000932const DWARFDataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000933SymbolFileDWARF::get_apple_types_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000934{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000935 return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types);
Greg Claytonf9eec202011-09-01 23:16:13 +0000936}
937
Ed Masteeeae7212013-10-24 20:43:47 +0000938const DWARFDataExtractor&
Greg Clayton7f995132011-10-04 22:41:51 +0000939SymbolFileDWARF::get_apple_namespaces_data()
940{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000941 return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
942}
943
Ed Masteeeae7212013-10-24 20:43:47 +0000944const DWARFDataExtractor&
Greg Clayton5009f9d2011-10-27 17:55:14 +0000945SymbolFileDWARF::get_apple_objc_data()
946{
947 return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc);
Greg Clayton7f995132011-10-04 22:41:51 +0000948}
949
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000950
951DWARFDebugAbbrev*
952SymbolFileDWARF::DebugAbbrev()
953{
954 if (m_abbr.get() == NULL)
955 {
Ed Masteeeae7212013-10-24 20:43:47 +0000956 const DWARFDataExtractor &debug_abbrev_data = get_debug_abbrev_data();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000957 if (debug_abbrev_data.GetByteSize() > 0)
958 {
959 m_abbr.reset(new DWARFDebugAbbrev());
960 if (m_abbr.get())
961 m_abbr->Parse(debug_abbrev_data);
962 }
963 }
964 return m_abbr.get();
965}
966
967const DWARFDebugAbbrev*
968SymbolFileDWARF::DebugAbbrev() const
969{
970 return m_abbr.get();
971}
972
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000973
974DWARFDebugInfo*
975SymbolFileDWARF::DebugInfo()
976{
977 if (m_info.get() == NULL)
978 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000979 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p",
980 __PRETTY_FUNCTION__, static_cast<void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000981 if (get_debug_info_data().GetByteSize() > 0)
982 {
983 m_info.reset(new DWARFDebugInfo());
984 if (m_info.get())
985 {
986 m_info->SetDwarfData(this);
987 }
988 }
989 }
990 return m_info.get();
991}
992
993const DWARFDebugInfo*
994SymbolFileDWARF::DebugInfo() const
995{
996 return m_info.get();
997}
998
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000999DWARFCompileUnit*
Greg Clayton1f746072012-08-29 21:13:06 +00001000SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001001{
1002 DWARFDebugInfo* info = DebugInfo();
Greg Clayton1f746072012-08-29 21:13:06 +00001003 if (info)
1004 {
1005 if (GetDebugMapSymfile ())
1006 {
1007 // The debug map symbol file made the compile units for this DWARF
1008 // file which is .o file with DWARF in it, and we should have
1009 // only 1 compile unit which is at offset zero in the DWARF.
1010 // TODO: modify to support LTO .o files where each .o file might
1011 // have multiple DW_TAG_compile_unit tags.
Greg Clayton68c00bd2015-02-05 02:10:29 +00001012
1013 DWARFCompileUnit *dwarf_cu = info->GetCompileUnit(0).get();
1014 if (dwarf_cu && dwarf_cu->GetUserData() == NULL)
1015 dwarf_cu->SetUserData(comp_unit);
1016 return dwarf_cu;
Greg Clayton1f746072012-08-29 21:13:06 +00001017 }
1018 else
1019 {
1020 // Just a normal DWARF file whose user ID for the compile unit is
1021 // the DWARF offset itself
Greg Clayton68c00bd2015-02-05 02:10:29 +00001022
1023 DWARFCompileUnit *dwarf_cu = info->GetCompileUnit((dw_offset_t)comp_unit->GetID()).get();
1024 if (dwarf_cu && dwarf_cu->GetUserData() == NULL)
1025 dwarf_cu->SetUserData(comp_unit);
1026 return dwarf_cu;
1027
Greg Clayton1f746072012-08-29 21:13:06 +00001028 }
1029 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001030 return NULL;
1031}
1032
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001033
1034DWARFDebugRanges*
1035SymbolFileDWARF::DebugRanges()
1036{
1037 if (m_ranges.get() == NULL)
1038 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001039 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p",
1040 __PRETTY_FUNCTION__, static_cast<void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001041 if (get_debug_ranges_data().GetByteSize() > 0)
1042 {
1043 m_ranges.reset(new DWARFDebugRanges());
1044 if (m_ranges.get())
1045 m_ranges->Extract(this);
1046 }
1047 }
1048 return m_ranges.get();
1049}
1050
1051const DWARFDebugRanges*
1052SymbolFileDWARF::DebugRanges() const
1053{
1054 return m_ranges.get();
1055}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001056
Greg Clayton53eb1c22012-04-02 22:59:12 +00001057lldb::CompUnitSP
1058SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001059{
Greg Clayton53eb1c22012-04-02 22:59:12 +00001060 CompUnitSP cu_sp;
1061 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001062 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00001063 CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData();
1064 if (comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001065 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00001066 // We already parsed this compile unit, had out a shared pointer to it
1067 cu_sp = comp_unit->shared_from_this();
1068 }
1069 else
1070 {
Greg Clayton1f746072012-08-29 21:13:06 +00001071 if (GetDebugMapSymfile ())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001072 {
Greg Clayton1f746072012-08-29 21:13:06 +00001073 // Let the debug map create the compile unit
1074 cu_sp = m_debug_map_symfile->GetCompileUnit(this);
1075 dwarf_cu->SetUserData(cu_sp.get());
1076 }
1077 else
1078 {
1079 ModuleSP module_sp (m_obj_file->GetModule());
1080 if (module_sp)
Greg Clayton53eb1c22012-04-02 22:59:12 +00001081 {
Greg Clayton1f746072012-08-29 21:13:06 +00001082 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly ();
1083 if (cu_die)
Greg Clayton53eb1c22012-04-02 22:59:12 +00001084 {
Chaoren Lin0c5a9c12015-06-05 00:28:06 +00001085 FileSpec cu_file_spec{cu_die->GetName(this, dwarf_cu), false};
1086 if (cu_file_spec)
Greg Clayton1f746072012-08-29 21:13:06 +00001087 {
Chaoren Lin0c5a9c12015-06-05 00:28:06 +00001088 // If we have a full path to the compile unit, we don't need to resolve
1089 // the file. This can be expensive e.g. when the source files are NFS mounted.
Chaoren Lin372e9062015-06-09 17:54:27 +00001090 if (cu_file_spec.IsRelative())
Greg Clayton53eb1c22012-04-02 22:59:12 +00001091 {
Chaoren Lin0c5a9c12015-06-05 00:28:06 +00001092 const char *cu_comp_dir{cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, nullptr)};
Oleksiy Vyalov5d9c50b2015-07-21 02:09:42 +00001093 cu_file_spec.PrependPathComponent(resolveCompDir(cu_comp_dir));
Greg Clayton1f746072012-08-29 21:13:06 +00001094 }
1095
Chaoren Lin0c5a9c12015-06-05 00:28:06 +00001096 std::string remapped_file;
1097 if (module_sp->RemapSourceFile(cu_file_spec.GetCString(), remapped_file))
1098 cu_file_spec.SetFile(remapped_file, false);
David Srbeckyd515e942015-07-08 14:00:04 +00001099 }
Chaoren Lin0c5a9c12015-06-05 00:28:06 +00001100
David Srbeckyd515e942015-07-08 14:00:04 +00001101 LanguageType cu_language = DWARFCompileUnit::LanguageTypeFromDWARF(cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0));
Chaoren Lin0c5a9c12015-06-05 00:28:06 +00001102
Jason Molendac7099582015-07-31 05:47:00 +00001103 bool is_optimized = dwarf_cu->GetIsOptimized ();
David Srbeckyd515e942015-07-08 14:00:04 +00001104 cu_sp.reset(new CompileUnit (module_sp,
1105 dwarf_cu,
1106 cu_file_spec,
1107 MakeUserID(dwarf_cu->GetOffset()),
Jason Molenda6ab659a2015-07-29 00:42:47 +00001108 cu_language,
1109 is_optimized));
David Srbeckyd515e942015-07-08 14:00:04 +00001110 if (cu_sp)
1111 {
1112 // If we just created a compile unit with an invalid file spec, try and get the
1113 // first entry in the supports files from the line table as that should be the
1114 // compile unit.
1115 if (!cu_file_spec)
Greg Clayton1f746072012-08-29 21:13:06 +00001116 {
David Srbeckyd515e942015-07-08 14:00:04 +00001117 cu_file_spec = cu_sp->GetSupportFiles().GetFileSpecAtIndex(1);
1118 if (cu_file_spec)
1119 {
1120 (FileSpec &)(*cu_sp) = cu_file_spec;
1121 // Also fix the invalid file spec which was copied from the compile unit.
1122 cu_sp->GetSupportFiles().Replace(0, cu_file_spec);
1123 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00001124 }
David Srbeckyd515e942015-07-08 14:00:04 +00001125
1126 dwarf_cu->SetUserData(cu_sp.get());
1127
1128 // Figure out the compile unit index if we weren't given one
1129 if (cu_idx == UINT32_MAX)
1130 DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx);
1131
1132 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp);
Greg Clayton53eb1c22012-04-02 22:59:12 +00001133 }
1134 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001135 }
1136 }
1137 }
1138 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00001139 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001140}
1141
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001142uint32_t
1143SymbolFileDWARF::GetNumCompileUnits()
1144{
1145 DWARFDebugInfo* info = DebugInfo();
1146 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001147 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001148 return 0;
1149}
1150
1151CompUnitSP
1152SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
1153{
Greg Clayton53eb1c22012-04-02 22:59:12 +00001154 CompUnitSP cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001155 DWARFDebugInfo* info = DebugInfo();
1156 if (info)
1157 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00001158 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
1159 if (dwarf_cu)
1160 cu_sp = ParseCompileUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001161 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00001162 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001163}
1164
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001165Function *
Greg Clayton0fffff52010-09-24 05:15:53 +00001166SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001167{
1168 DWARFDebugRanges::RangeList func_ranges;
1169 const char *name = NULL;
1170 const char *mangled = NULL;
1171 int decl_file = 0;
1172 int decl_line = 0;
1173 int decl_column = 0;
1174 int call_file = 0;
1175 int call_line = 0;
1176 int call_column = 0;
1177 DWARFExpression frame_base;
1178
Greg Claytonc93237c2010-10-01 20:48:32 +00001179 assert (die->Tag() == DW_TAG_subprogram);
1180
1181 if (die->Tag() != DW_TAG_subprogram)
1182 return NULL;
1183
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001184 if (die->GetDIENamesAndRanges (this,
1185 dwarf_cu,
1186 name,
1187 mangled,
1188 func_ranges,
1189 decl_file,
1190 decl_line,
1191 decl_column,
1192 call_file,
1193 call_line,
1194 call_column,
1195 &frame_base))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001196 {
1197 // Union of all ranges in the function DIE (if the function is discontiguous)
1198 AddressRange func_range;
Greg Claytonea3e7d52011-10-08 00:49:15 +00001199 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0);
1200 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001201 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
1202 {
Michael Sartaina7499c92013-07-01 19:45:50 +00001203 ModuleSP module_sp (m_obj_file->GetModule());
Greg Clayton3046e662013-07-10 01:23:25 +00001204 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, module_sp->GetSectionList());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001205 if (func_range.GetBaseAddress().IsValid())
1206 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
1207 }
1208
1209 if (func_range.GetBaseAddress().IsValid())
1210 {
1211 Mangled func_name;
1212 if (mangled)
Greg Clayton037520e2012-07-18 23:18:10 +00001213 func_name.SetValue(ConstString(mangled), true);
Siva Chandra462722d2015-03-27 00:10:04 +00001214 else if (die->GetParent()->Tag() == DW_TAG_compile_unit &&
1215 LanguageRuntime::LanguageIsCPlusPlus(dwarf_cu->GetLanguageType()) &&
Greg Clayton94380562015-05-15 22:20:29 +00001216 name && strcmp(name, "main") != 0)
Siva Chandra462722d2015-03-27 00:10:04 +00001217 {
1218 // If the mangled name is not present in the DWARF, generate the demangled name
1219 // using the decl context. We skip if the function is "main" as its name is
1220 // never mangled.
1221 bool is_static = false;
1222 bool is_variadic = false;
1223 unsigned type_quals = 0;
Greg Claytona1e5dc82015-08-11 22:53:00 +00001224 std::vector<CompilerType> param_types;
Siva Chandra462722d2015-03-27 00:10:04 +00001225 std::vector<clang::ParmVarDecl*> param_decls;
1226 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
1227 DWARFDeclContext decl_ctx;
1228 StreamString sstr;
1229
1230 die->GetDWARFDeclContext(this, dwarf_cu, decl_ctx);
1231 sstr << decl_ctx.GetQualifiedName();
1232
1233 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE(dwarf_cu,
1234 die,
1235 &decl_ctx_die);
1236 ParseChildParameters(sc,
1237 containing_decl_ctx,
1238 dwarf_cu,
1239 die,
1240 true,
1241 is_static,
1242 is_variadic,
1243 param_types,
1244 param_decls,
1245 type_quals);
1246 sstr << "(";
1247 for (size_t i = 0; i < param_types.size(); i++)
1248 {
1249 if (i > 0)
1250 sstr << ", ";
1251 sstr << param_types[i].GetTypeName();
1252 }
1253 if (is_variadic)
1254 sstr << ", ...";
1255 sstr << ")";
1256 if (type_quals & clang::Qualifiers::Const)
1257 sstr << " const";
1258
1259 func_name.SetValue(ConstString(sstr.GetData()), false);
1260 }
1261 else
Greg Clayton037520e2012-07-18 23:18:10 +00001262 func_name.SetValue(ConstString(name), false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001263
1264 FunctionSP func_sp;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001265 std::unique_ptr<Declaration> decl_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001266 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +00001267 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1268 decl_line,
1269 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001270
Greg Clayton0bd4e1b2011-09-30 20:52:25 +00001271 // Supply the type _only_ if it has already been parsed
Greg Clayton594e5ed2010-09-27 21:07:38 +00001272 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001273
1274 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
1275
Greg Clayton9422dd62013-03-04 21:46:16 +00001276 if (FixupAddress (func_range.GetBaseAddress()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001277 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001278 const user_id_t func_user_id = MakeUserID(die->GetOffset());
1279 func_sp.reset(new Function (sc.comp_unit,
1280 MakeUserID(func_user_id), // UserID is the DIE offset
1281 MakeUserID(func_user_id),
1282 func_name,
1283 func_type,
1284 func_range)); // first address range
1285
1286 if (func_sp.get() != NULL)
1287 {
1288 if (frame_base.IsValid())
1289 func_sp->GetFrameBaseExpression() = frame_base;
1290 sc.comp_unit->AddFunction(func_sp);
1291 return func_sp.get();
1292 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001293 }
1294 }
1295 }
1296 return NULL;
1297}
1298
Greg Clayton9422dd62013-03-04 21:46:16 +00001299bool
1300SymbolFileDWARF::FixupAddress (Address &addr)
1301{
1302 SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile ();
1303 if (debug_map_symfile)
1304 {
1305 return debug_map_symfile->LinkOSOAddress(addr);
1306 }
1307 // This is a normal DWARF file, no address fixups need to happen
1308 return true;
1309}
Greg Clayton1f746072012-08-29 21:13:06 +00001310lldb::LanguageType
1311SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc)
1312{
1313 assert (sc.comp_unit);
1314 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1315 if (dwarf_cu)
1316 {
1317 const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly();
Jim Ingham28eb5712012-10-12 17:34:26 +00001318 if (die)
Dawn Perchikd0e87eb2015-06-17 22:30:24 +00001319 return DWARFCompileUnit::LanguageTypeFromDWARF(die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0));
Greg Clayton1f746072012-08-29 21:13:06 +00001320 }
1321 return eLanguageTypeUnknown;
1322}
1323
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001324size_t
1325SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
1326{
1327 assert (sc.comp_unit);
1328 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00001329 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001330 if (dwarf_cu)
1331 {
1332 DWARFDIECollection function_dies;
Greg Clayton1f746072012-08-29 21:13:06 +00001333 const size_t num_functions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001334 size_t func_idx;
Greg Clayton1f746072012-08-29 21:13:06 +00001335 for (func_idx = 0; func_idx < num_functions; ++func_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001336 {
1337 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
Greg Clayton81c22f62011-10-19 18:09:39 +00001338 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001339 {
1340 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
1341 ++functions_added;
1342 }
1343 }
1344 //FixupTypes();
1345 }
1346 return functions_added;
1347}
1348
1349bool
1350SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
1351{
1352 assert (sc.comp_unit);
Greg Clayton1f746072012-08-29 21:13:06 +00001353 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Greg Claytonda2455b2012-11-01 17:28:37 +00001354 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001355 {
Greg Claytonda2455b2012-11-01 17:28:37 +00001356 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001357
Greg Claytonda2455b2012-11-01 17:28:37 +00001358 if (cu_die)
1359 {
Oleksiy Vyalov5d9c50b2015-07-21 02:09:42 +00001360 const char * cu_comp_dir = resolveCompDir(cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, nullptr));
Matthew Gardinere81df3b2014-08-26 06:57:23 +00001361
Greg Claytonda2455b2012-11-01 17:28:37 +00001362 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 +00001363
Greg Claytonda2455b2012-11-01 17:28:37 +00001364 // All file indexes in DWARF are one based and a file of index zero is
1365 // supposed to be the compile unit itself.
1366 support_files.Append (*sc.comp_unit);
1367
1368 return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
1369 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001370 }
1371 return false;
1372}
1373
Sean Callananf0c5aeb2015-04-20 16:31:29 +00001374bool
1375SymbolFileDWARF::ParseImportedModules (const lldb_private::SymbolContext &sc, std::vector<lldb_private::ConstString> &imported_modules)
1376{
1377 assert (sc.comp_unit);
1378 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1379 if (dwarf_cu)
1380 {
1381 if (ClangModulesDeclVendor::LanguageSupportsClangModules(sc.comp_unit->GetLanguage()))
1382 {
1383 UpdateExternalModuleListIfNeeded();
1384 for (const std::pair<uint64_t, const ClangModuleInfo> &external_type_module : m_external_type_modules)
1385 {
1386 imported_modules.push_back(external_type_module.second.m_name);
1387 }
1388 }
1389 }
1390 return false;
1391}
1392
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001393struct ParseDWARFLineTableCallbackInfo
1394{
1395 LineTable* line_table;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001396 std::unique_ptr<LineSequence> sequence_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001397};
1398
1399//----------------------------------------------------------------------
1400// ParseStatementTableCallback
1401//----------------------------------------------------------------------
1402static void
1403ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
1404{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001405 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
1406 {
1407 // Just started parsing the line table
1408 }
1409 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
1410 {
1411 // Done parsing line table, nothing to do for the cleanup
1412 }
1413 else
1414 {
1415 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
Greg Clayton9422dd62013-03-04 21:46:16 +00001416 LineTable* line_table = info->line_table;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001417
Greg Clayton9422dd62013-03-04 21:46:16 +00001418 // If this is our first time here, we need to create a
1419 // sequence container.
1420 if (!info->sequence_ap.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001421 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001422 info->sequence_ap.reset(line_table->CreateLineSequenceContainer());
1423 assert(info->sequence_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001424 }
Greg Clayton9422dd62013-03-04 21:46:16 +00001425 line_table->AppendLineEntryToSequence (info->sequence_ap.get(),
1426 state.address,
1427 state.line,
1428 state.column,
1429 state.file,
1430 state.is_stmt,
1431 state.basic_block,
1432 state.prologue_end,
1433 state.epilogue_begin,
1434 state.end_sequence);
1435 if (state.end_sequence)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001436 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001437 // First, put the current sequence into the line table.
1438 line_table->InsertSequence(info->sequence_ap.get());
1439 // Then, empty it to prepare for the next sequence.
1440 info->sequence_ap->Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001441 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001442 }
1443}
1444
1445bool
1446SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1447{
1448 assert (sc.comp_unit);
1449 if (sc.comp_unit->GetLineTable() != NULL)
1450 return true;
1451
Greg Clayton1f746072012-08-29 21:13:06 +00001452 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001453 if (dwarf_cu)
1454 {
1455 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Greg Clayton129d12c2011-11-28 03:29:03 +00001456 if (dwarf_cu_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001457 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001458 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1459 if (cu_line_offset != DW_INVALID_OFFSET)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001460 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001461 std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
Greg Clayton129d12c2011-11-28 03:29:03 +00001462 if (line_table_ap.get())
1463 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001464 ParseDWARFLineTableCallbackInfo info;
1465 info.line_table = line_table_ap.get();
Greg Claytonc7bece562013-01-25 18:06:21 +00001466 lldb::offset_t offset = cu_line_offset;
Greg Clayton129d12c2011-11-28 03:29:03 +00001467 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
Greg Clayton9422dd62013-03-04 21:46:16 +00001468 if (m_debug_map_symfile)
1469 {
1470 // We have an object file that has a line table with addresses
1471 // that are not linked. We need to link the line table and convert
1472 // the addresses that are relative to the .o file into addresses
1473 // for the main executable.
1474 sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get()));
1475 }
1476 else
1477 {
1478 sc.comp_unit->SetLineTable(line_table_ap.release());
1479 return true;
1480 }
Greg Clayton129d12c2011-11-28 03:29:03 +00001481 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001482 }
1483 }
1484 }
1485 return false;
1486}
1487
1488size_t
1489SymbolFileDWARF::ParseFunctionBlocks
1490(
1491 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001492 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001493 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001494 const DWARFDebugInfoEntry *die,
1495 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001496 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001497)
1498{
1499 size_t blocks_added = 0;
1500 while (die != NULL)
1501 {
1502 dw_tag_t tag = die->Tag();
1503
1504 switch (tag)
1505 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001506 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001507 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001508 case DW_TAG_lexical_block:
1509 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001510 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001511 if (tag == DW_TAG_subprogram)
1512 {
1513 // Skip any DW_TAG_subprogram DIEs that are inside
1514 // of a normal or inlined functions. These will be
1515 // parsed on their own as separate entities.
1516
1517 if (depth > 0)
1518 break;
1519
1520 block = parent_block;
1521 }
1522 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001523 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001524 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001525 parent_block->AddChild(block_sp);
1526 block = block_sp.get();
1527 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001528 DWARFDebugRanges::RangeList ranges;
1529 const char *name = NULL;
1530 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001531
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001532 int decl_file = 0;
1533 int decl_line = 0;
1534 int decl_column = 0;
1535 int call_file = 0;
1536 int call_line = 0;
1537 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001538 if (die->GetDIENamesAndRanges (this,
1539 dwarf_cu,
1540 name,
1541 mangled_name,
1542 ranges,
1543 decl_file, decl_line, decl_column,
1544 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001545 {
1546 if (tag == DW_TAG_subprogram)
1547 {
1548 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001549 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001550 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001551 else if (tag == DW_TAG_inlined_subroutine)
1552 {
1553 // We get called here for inlined subroutines in two ways.
1554 // The first time is when we are making the Function object
1555 // for this inlined concrete instance. Since we're creating a top level block at
1556 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1557 // adjust the containing address.
1558 // The second time is when we are parsing the blocks inside the function that contains
1559 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1560 // function the offset will be for that function.
1561 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1562 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001563 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001564 }
1565 }
Greg Clayton103f3092015-01-15 03:04:37 +00001566
1567 const size_t num_ranges = ranges.GetSize();
1568 for (size_t i = 0; i<num_ranges; ++i)
1569 {
1570 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i);
1571 const addr_t range_base = range.GetRangeBase();
1572 if (range_base >= subprogram_low_pc)
1573 block->AddRange(Block::Range (range_base - subprogram_low_pc, range.GetByteSize()));
1574 else
1575 {
1576 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",
1577 block->GetID(),
1578 range_base,
1579 range.GetRangeEnd(),
1580 subprogram_low_pc);
1581 }
1582 }
1583 block->FinalizeRanges ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001584
1585 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1586 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001587 std::unique_ptr<Declaration> decl_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001588 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001589 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1590 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001591
Greg Clayton7b0992d2013-04-18 22:45:39 +00001592 std::unique_ptr<Declaration> call_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001593 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001594 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1595 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001596
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001597 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001598 }
1599
1600 ++blocks_added;
1601
Greg Claytondd7feaf2011-08-12 17:54:33 +00001602 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001603 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001604 blocks_added += ParseFunctionBlocks (sc,
1605 block,
1606 dwarf_cu,
1607 die->GetFirstChild(),
1608 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001609 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001610 }
1611 }
1612 }
1613 break;
1614 default:
1615 break;
1616 }
1617
Greg Claytondd7feaf2011-08-12 17:54:33 +00001618 // Only parse siblings of the block if we are not at depth zero. A depth
1619 // of zero indicates we are currently parsing the top level
1620 // DW_TAG_subprogram DIE
1621
1622 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001623 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001624 else
1625 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001626 }
1627 return blocks_added;
1628}
1629
Greg Claytonf0705c82011-10-22 03:33:13 +00001630bool
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001631SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu,
1632 const DWARFDebugInfoEntry *die,
1633 ClangASTContext::TemplateParameterInfos &template_param_infos)
1634{
1635 const dw_tag_t tag = die->Tag();
1636
1637 switch (tag)
1638 {
1639 case DW_TAG_template_type_parameter:
1640 case DW_TAG_template_value_parameter:
1641 {
Todd Fialaee8bfc62014-09-11 17:29:12 +00001642 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001643
1644 DWARFDebugInfoEntry::Attributes attributes;
1645 const size_t num_attributes = die->GetAttributes (this,
1646 dwarf_cu,
1647 fixed_form_sizes,
1648 attributes);
1649 const char *name = NULL;
1650 Type *lldb_type = NULL;
Greg Claytona1e5dc82015-08-11 22:53:00 +00001651 CompilerType clang_type;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001652 uint64_t uval64 = 0;
1653 bool uval64_valid = false;
1654 if (num_attributes > 0)
1655 {
1656 DWARFFormValue form_value;
1657 for (size_t i=0; i<num_attributes; ++i)
1658 {
1659 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1660
1661 switch (attr)
1662 {
1663 case DW_AT_name:
1664 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1665 name = form_value.AsCString(&get_debug_str_data());
1666 break;
1667
1668 case DW_AT_type:
1669 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1670 {
Greg Clayton54166af2014-11-22 01:58:59 +00001671 const dw_offset_t type_die_offset = form_value.Reference();
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001672 lldb_type = ResolveTypeUID(type_die_offset);
1673 if (lldb_type)
1674 clang_type = lldb_type->GetClangForwardType();
1675 }
1676 break;
1677
1678 case DW_AT_const_value:
1679 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1680 {
1681 uval64_valid = true;
1682 uval64 = form_value.Unsigned();
1683 }
1684 break;
1685 default:
1686 break;
1687 }
1688 }
1689
Greg Clayton283b2652013-04-23 22:38:02 +00001690 clang::ASTContext *ast = GetClangASTContext().getASTContext();
1691 if (!clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00001692 clang_type = GetClangASTContext().GetBasicType(eBasicTypeVoid);
Greg Clayton283b2652013-04-23 22:38:02 +00001693
1694 if (clang_type)
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001695 {
1696 bool is_signed = false;
Greg Clayton283b2652013-04-23 22:38:02 +00001697 if (name && name[0])
1698 template_param_infos.names.push_back(name);
1699 else
1700 template_param_infos.names.push_back(NULL);
1701
Greg Clayton283b2652013-04-23 22:38:02 +00001702 if (tag == DW_TAG_template_value_parameter &&
1703 lldb_type != NULL &&
Greg Clayton57ee3062013-07-11 22:46:58 +00001704 clang_type.IsIntegerType (is_signed) &&
Greg Clayton283b2652013-04-23 22:38:02 +00001705 uval64_valid)
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001706 {
1707 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
Greg Clayton283b2652013-04-23 22:38:02 +00001708 template_param_infos.args.push_back (clang::TemplateArgument (*ast,
Sean Callanan3d654b32012-09-24 22:25:51 +00001709 llvm::APSInt(apint),
Greg Claytond8d4a572015-08-11 21:38:15 +00001710 ClangASTContext::GetQualType(clang_type)));
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001711 }
1712 else
1713 {
Greg Claytond8d4a572015-08-11 21:38:15 +00001714 template_param_infos.args.push_back (clang::TemplateArgument (ClangASTContext::GetQualType(clang_type)));
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001715 }
1716 }
1717 else
1718 {
1719 return false;
1720 }
1721
1722 }
1723 }
1724 return true;
1725
1726 default:
1727 break;
1728 }
1729 return false;
1730}
1731
1732bool
Greg Claytonf0705c82011-10-22 03:33:13 +00001733SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1734 const DWARFDebugInfoEntry *parent_die,
1735 ClangASTContext::TemplateParameterInfos &template_param_infos)
1736{
1737
1738 if (parent_die == NULL)
Filipe Cabecinhas52008c62012-05-23 16:24:11 +00001739 return false;
Greg Claytonf0705c82011-10-22 03:33:13 +00001740
Greg Claytonf0705c82011-10-22 03:33:13 +00001741 Args template_parameter_names;
1742 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1743 die != NULL;
1744 die = die->GetSibling())
1745 {
1746 const dw_tag_t tag = die->Tag();
1747
1748 switch (tag)
1749 {
1750 case DW_TAG_template_type_parameter:
1751 case DW_TAG_template_value_parameter:
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001752 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Claytonf0705c82011-10-22 03:33:13 +00001753 break;
1754
1755 default:
1756 break;
1757 }
1758 }
1759 if (template_param_infos.args.empty())
1760 return false;
1761 return template_param_infos.args.size() == template_param_infos.names.size();
1762}
1763
1764clang::ClassTemplateDecl *
1765SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001766 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001767 const char *parent_name,
1768 int tag_decl_kind,
1769 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1770{
1771 if (template_param_infos.IsValid())
1772 {
1773 std::string template_basename(parent_name);
1774 template_basename.erase (template_basename.find('<'));
1775 ClangASTContext &ast = GetClangASTContext();
1776
1777 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001778 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001779 template_basename.c_str(),
1780 tag_decl_kind,
1781 template_param_infos);
1782 }
1783 return NULL;
1784}
1785
Sean Callanana0b80ab2012-06-04 22:28:05 +00001786class SymbolFileDWARF::DelayedAddObjCClassProperty
1787{
1788public:
1789 DelayedAddObjCClassProperty
1790 (
Greg Claytona1e5dc82015-08-11 22:53:00 +00001791 const CompilerType &class_opaque_type,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001792 const char *property_name,
Greg Claytona1e5dc82015-08-11 22:53:00 +00001793 const CompilerType &property_opaque_type, // The property type is only required if you don't have an ivar decl
Sean Callanana0b80ab2012-06-04 22:28:05 +00001794 clang::ObjCIvarDecl *ivar_decl,
1795 const char *property_setter_name,
1796 const char *property_getter_name,
1797 uint32_t property_attributes,
Greg Claytonc4ffd662013-03-08 01:37:30 +00001798 const ClangASTMetadata *metadata
Sean Callanana0b80ab2012-06-04 22:28:05 +00001799 ) :
Sean Callanana0b80ab2012-06-04 22:28:05 +00001800 m_class_opaque_type (class_opaque_type),
1801 m_property_name (property_name),
1802 m_property_opaque_type (property_opaque_type),
1803 m_ivar_decl (ivar_decl),
1804 m_property_setter_name (property_setter_name),
1805 m_property_getter_name (property_getter_name),
Jim Ingham379397632012-10-27 02:54:13 +00001806 m_property_attributes (property_attributes)
Sean Callanana0b80ab2012-06-04 22:28:05 +00001807 {
Jim Ingham379397632012-10-27 02:54:13 +00001808 if (metadata != NULL)
1809 {
1810 m_metadata_ap.reset(new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001811 *m_metadata_ap = *metadata;
Jim Ingham379397632012-10-27 02:54:13 +00001812 }
1813 }
1814
1815 DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs)
1816 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001817 *this = rhs;
Daniel Malead4c5be62012-11-12 21:02:14 +00001818 }
1819
1820 DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs)
1821 {
Jim Ingham379397632012-10-27 02:54:13 +00001822 m_class_opaque_type = rhs.m_class_opaque_type;
1823 m_property_name = rhs.m_property_name;
1824 m_property_opaque_type = rhs.m_property_opaque_type;
1825 m_ivar_decl = rhs.m_ivar_decl;
1826 m_property_setter_name = rhs.m_property_setter_name;
1827 m_property_getter_name = rhs.m_property_getter_name;
1828 m_property_attributes = rhs.m_property_attributes;
1829
1830 if (rhs.m_metadata_ap.get())
1831 {
1832 m_metadata_ap.reset (new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001833 *m_metadata_ap = *rhs.m_metadata_ap;
Jim Ingham379397632012-10-27 02:54:13 +00001834 }
Daniel Malead4c5be62012-11-12 21:02:14 +00001835 return *this;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001836 }
1837
Greg Clayton57ee3062013-07-11 22:46:58 +00001838 bool
1839 Finalize()
Sean Callanana0b80ab2012-06-04 22:28:05 +00001840 {
Greg Claytond8d4a572015-08-11 21:38:15 +00001841 ClangASTContext* ast = m_class_opaque_type.GetTypeSystem()->AsClangASTContext();
1842 assert(ast);
1843 return ast->AddObjCClassProperty (m_class_opaque_type,
1844 m_property_name,
1845 m_property_opaque_type,
1846 m_ivar_decl,
1847 m_property_setter_name,
1848 m_property_getter_name,
1849 m_property_attributes,
1850 m_metadata_ap.get());
Sean Callanana0b80ab2012-06-04 22:28:05 +00001851 }
1852private:
Greg Claytona1e5dc82015-08-11 22:53:00 +00001853 CompilerType m_class_opaque_type;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001854 const char *m_property_name;
Greg Claytona1e5dc82015-08-11 22:53:00 +00001855 CompilerType m_property_opaque_type;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001856 clang::ObjCIvarDecl *m_ivar_decl;
1857 const char *m_property_setter_name;
1858 const char *m_property_getter_name;
1859 uint32_t m_property_attributes;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001860 std::unique_ptr<ClangASTMetadata> m_metadata_ap;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001861};
1862
Sean Callananfaa0bb32012-12-05 23:37:14 +00001863struct BitfieldInfo
1864{
1865 uint64_t bit_size;
1866 uint64_t bit_offset;
1867
1868 BitfieldInfo () :
1869 bit_size (LLDB_INVALID_ADDRESS),
1870 bit_offset (LLDB_INVALID_ADDRESS)
1871 {
1872 }
1873
Greg Clayton78f4d952013-12-11 23:10:39 +00001874 void
1875 Clear()
1876 {
1877 bit_size = LLDB_INVALID_ADDRESS;
1878 bit_offset = LLDB_INVALID_ADDRESS;
1879 }
1880
Sean Callananfaa0bb32012-12-05 23:37:14 +00001881 bool IsValid ()
1882 {
1883 return (bit_size != LLDB_INVALID_ADDRESS) &&
1884 (bit_offset != LLDB_INVALID_ADDRESS);
1885 }
1886};
1887
Greg Claytonc4ffd662013-03-08 01:37:30 +00001888
1889bool
1890SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu,
1891 const DWARFDebugInfoEntry *parent_die)
1892{
1893 if (parent_die)
1894 {
1895 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1896 {
1897 dw_tag_t tag = die->Tag();
1898 bool check_virtuality = false;
1899 switch (tag)
1900 {
1901 case DW_TAG_inheritance:
1902 case DW_TAG_subprogram:
1903 check_virtuality = true;
1904 break;
1905 default:
1906 break;
1907 }
1908 if (check_virtuality)
1909 {
1910 if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0)
1911 return true;
1912 }
1913 }
1914 }
1915 return false;
1916}
1917
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001918size_t
1919SymbolFileDWARF::ParseChildMembers
1920(
1921 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001922 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001923 const DWARFDebugInfoEntry *parent_die,
Greg Claytona1e5dc82015-08-11 22:53:00 +00001924 CompilerType &class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001925 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001926 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1927 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001928 DWARFDIECollection& member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001929 DelayedPropertyList& delayed_properties,
Sean Callananc7fbf732010-08-06 00:32:49 +00001930 AccessType& default_accessibility,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001931 bool &is_a_class,
1932 LayoutInfo &layout_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001933)
1934{
1935 if (parent_die == NULL)
1936 return 0;
1937
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001938 size_t count = 0;
1939 const DWARFDebugInfoEntry *die;
Todd Fialaee8bfc62014-09-11 17:29:12 +00001940 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001941 uint32_t member_idx = 0;
Sean Callananfaa0bb32012-12-05 23:37:14 +00001942 BitfieldInfo last_field_info;
Richard Mitton0a558352013-10-17 21:14:00 +00001943 ModuleSP module = GetObjectFile()->GetModule();
Greg Claytond8d4a572015-08-11 21:38:15 +00001944 ClangASTContext* ast = class_clang_type.GetTypeSystem()->AsClangASTContext();
1945 if (ast == nullptr)
1946 return 0;
Greg Claytond88d7592010-09-15 08:33:30 +00001947
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001948 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1949 {
1950 dw_tag_t tag = die->Tag();
1951
1952 switch (tag)
1953 {
1954 case DW_TAG_member:
Sean Callanan3d654b32012-09-24 22:25:51 +00001955 case DW_TAG_APPLE_property:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001956 {
1957 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001958 const size_t num_attributes = die->GetAttributes (this,
1959 dwarf_cu,
1960 fixed_form_sizes,
1961 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001962 if (num_attributes > 0)
1963 {
1964 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001965 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001966 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001967 const char *prop_name = NULL;
1968 const char *prop_getter_name = NULL;
1969 const char *prop_setter_name = NULL;
Greg Claytone528efd72013-02-26 23:45:18 +00001970 uint32_t prop_attributes = 0;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001971
1972
Greg Clayton24739922010-10-13 03:15:28 +00001973 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001974 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001975 AccessType accessibility = eAccessNone;
Greg Claytoncaab74e2012-01-28 00:48:57 +00001976 uint32_t member_byte_offset = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001977 size_t byte_size = 0;
1978 size_t bit_offset = 0;
1979 size_t bit_size = 0;
Greg Claytone528efd72013-02-26 23:45:18 +00001980 bool is_external = false; // On DW_TAG_members, this means the member is static
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001981 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001982 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001983 {
1984 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1985 DWARFFormValue form_value;
1986 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1987 {
1988 switch (attr)
1989 {
1990 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1991 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1992 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1993 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00001994 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001995 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1996 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1997 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1998 case DW_AT_data_member_location:
Greg Claytoncaab74e2012-01-28 00:48:57 +00001999 if (form_value.BlockData())
2000 {
2001 Value initialValue(0);
2002 Value memberOffset(0);
Ed Masteeeae7212013-10-24 20:43:47 +00002003 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Claytoncaab74e2012-01-28 00:48:57 +00002004 uint32_t block_length = form_value.Unsigned();
2005 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
2006 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
Greg Claytoncaab74e2012-01-28 00:48:57 +00002007 NULL, // ClangExpressionVariableList *
2008 NULL, // ClangExpressionDeclMap *
2009 NULL, // RegisterContext *
Richard Mitton0a558352013-10-17 21:14:00 +00002010 module,
Greg Claytoncaab74e2012-01-28 00:48:57 +00002011 debug_info_data,
2012 block_offset,
2013 block_length,
2014 eRegisterKindDWARF,
2015 &initialValue,
2016 memberOffset,
2017 NULL))
2018 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002019 member_byte_offset = memberOffset.ResolveValue(NULL).UInt();
Greg Claytoncaab74e2012-01-28 00:48:57 +00002020 }
2021 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002022 else
2023 {
2024 // With DWARF 3 and later, if the value is an integer constant,
2025 // this form value is the offset in bytes from the beginning
2026 // of the containing entity.
2027 member_byte_offset = form_value.Unsigned();
2028 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002029 break;
2030
Greg Clayton8cf05932010-07-22 18:30:50 +00002031 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00002032 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00002033 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
2034 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
2035 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
2036 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00002037 case DW_AT_external: is_external = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00002038
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002039 default:
Greg Clayton1b02c172012-03-14 21:00:47 +00002040 case DW_AT_declaration:
2041 case DW_AT_description:
2042 case DW_AT_mutable:
2043 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002044 case DW_AT_sibling:
2045 break;
2046 }
2047 }
2048 }
Sean Callanana6582262012-04-05 00:12:52 +00002049
2050 if (prop_name)
Sean Callanan751aac62012-03-29 19:07:06 +00002051 {
Sean Callanana6582262012-04-05 00:12:52 +00002052 ConstString fixed_getter;
2053 ConstString fixed_setter;
2054
2055 // Check if the property getter/setter were provided as full
2056 // names. We want basenames, so we extract them.
2057
2058 if (prop_getter_name && prop_getter_name[0] == '-')
2059 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00002060 ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true);
2061 prop_getter_name = prop_getter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00002062 }
2063
2064 if (prop_setter_name && prop_setter_name[0] == '-')
2065 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00002066 ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true);
2067 prop_setter_name = prop_setter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00002068 }
2069
2070 // If the names haven't been provided, they need to be
2071 // filled in.
2072
2073 if (!prop_getter_name)
2074 {
2075 prop_getter_name = prop_name;
2076 }
2077 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly))
2078 {
2079 StreamString ss;
2080
2081 ss.Printf("set%c%s:",
2082 toupper(prop_name[0]),
2083 &prop_name[1]);
2084
2085 fixed_setter.SetCString(ss.GetData());
2086 prop_setter_name = fixed_setter.GetCString();
2087 }
Sean Callanan751aac62012-03-29 19:07:06 +00002088 }
2089
2090 // Clang has a DWARF generation bug where sometimes it
Greg Clayton44953932011-10-25 01:25:35 +00002091 // represents fields that are references with bad byte size
2092 // and bit size/offset information such as:
2093 //
2094 // DW_AT_byte_size( 0x00 )
2095 // DW_AT_bit_size( 0x40 )
2096 // DW_AT_bit_offset( 0xffffffffffffffc0 )
2097 //
2098 // So check the bit offset to make sure it is sane, and if
2099 // the values are not sane, remove them. If we don't do this
2100 // then we will end up with a crash if we try to use this
2101 // type in an expression when clang becomes unhappy with its
2102 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00002103
Greg Clayton44953932011-10-25 01:25:35 +00002104 if (bit_offset > 128)
2105 {
2106 bit_size = 0;
2107 bit_offset = 0;
2108 }
2109
2110 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00002111 if (class_language == eLanguageTypeObjC ||
2112 class_language == eLanguageTypeObjC_plus_plus)
2113 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00002114
2115 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
2116 {
2117 // Not all compilers will mark the vtable pointer
2118 // member as artificial (llvm-gcc). We can't have
2119 // the virtual members in our classes otherwise it
2120 // throws off all child offsets since we end up
2121 // having and extra pointer sized member in our
2122 // class layouts.
2123 is_artificial = true;
2124 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002125
Greg Clayton29659712013-07-12 20:08:35 +00002126 // Handle static members
Greg Claytone528efd72013-02-26 23:45:18 +00002127 if (is_external && member_byte_offset == UINT32_MAX)
Greg Clayton973b6c92013-04-11 16:57:51 +00002128 {
2129 Type *var_type = ResolveTypeUID(encoding_uid);
2130
2131 if (var_type)
2132 {
Greg Clayton29659712013-07-12 20:08:35 +00002133 if (accessibility == eAccessNone)
2134 accessibility = eAccessPublic;
Greg Claytond8d4a572015-08-11 21:38:15 +00002135 ClangASTContext::AddVariableToRecordType (class_clang_type,
2136 name,
Greg Clayton57ee3062013-07-11 22:46:58 +00002137 var_type->GetClangLayoutType(),
2138 accessibility);
Greg Clayton973b6c92013-04-11 16:57:51 +00002139 }
Greg Claytone528efd72013-02-26 23:45:18 +00002140 break;
Greg Clayton973b6c92013-04-11 16:57:51 +00002141 }
Greg Claytone528efd72013-02-26 23:45:18 +00002142
Greg Clayton24739922010-10-13 03:15:28 +00002143 if (is_artificial == false)
2144 {
2145 Type *member_type = ResolveTypeUID(encoding_uid);
Sean Callananfa3ab452012-12-14 00:54:13 +00002146
Jim Inghame3ae82a2011-11-12 01:36:43 +00002147 clang::FieldDecl *field_decl = NULL;
Sean Callanan751aac62012-03-29 19:07:06 +00002148 if (tag == DW_TAG_member)
Greg Claytond16e1e52011-07-12 17:06:17 +00002149 {
Sean Callanan751aac62012-03-29 19:07:06 +00002150 if (member_type)
2151 {
2152 if (accessibility == eAccessNone)
2153 accessibility = default_accessibility;
2154 member_accessibilities.push_back(accessibility);
Sean Callananfaa0bb32012-12-05 23:37:14 +00002155
Greg Clayton78f4d952013-12-11 23:10:39 +00002156 uint64_t field_bit_offset = (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
2157 if (bit_size > 0)
Greg Clayton88bc7f32012-11-06 00:20:41 +00002158 {
Greg Clayton78f4d952013-12-11 23:10:39 +00002159
2160 BitfieldInfo this_field_info;
2161 this_field_info.bit_offset = field_bit_offset;
2162 this_field_info.bit_size = bit_size;
2163
Sean Callananfaa0bb32012-12-05 23:37:14 +00002164 /////////////////////////////////////////////////////////////
2165 // How to locate a field given the DWARF debug information
2166 //
2167 // AT_byte_size indicates the size of the word in which the
2168 // bit offset must be interpreted.
2169 //
2170 // AT_data_member_location indicates the byte offset of the
2171 // word from the base address of the structure.
2172 //
2173 // AT_bit_offset indicates how many bits into the word
2174 // (according to the host endianness) the low-order bit of
2175 // the field starts. AT_bit_offset can be negative.
2176 //
2177 // AT_bit_size indicates the size of the field in bits.
2178 /////////////////////////////////////////////////////////////
2179
Greg Clayton78f4d952013-12-11 23:10:39 +00002180 if (byte_size == 0)
2181 byte_size = member_type->GetByteSize();
2182
Sean Callananfaa0bb32012-12-05 23:37:14 +00002183 if (GetObjectFile()->GetByteOrder() == eByteOrderLittle)
2184 {
2185 this_field_info.bit_offset += byte_size * 8;
2186 this_field_info.bit_offset -= (bit_offset + bit_size);
2187 }
2188 else
2189 {
2190 this_field_info.bit_offset += bit_offset;
2191 }
Greg Clayton78f4d952013-12-11 23:10:39 +00002192
2193 // Update the field bit offset we will report for layout
2194 field_bit_offset = this_field_info.bit_offset;
Sean Callananfaa0bb32012-12-05 23:37:14 +00002195
Greg Clayton78f4d952013-12-11 23:10:39 +00002196 // If the member to be emitted did not start on a character boundary and there is
2197 // empty space between the last field and this one, then we need to emit an
2198 // anonymous member filling up the space up to its start. There are three cases
2199 // here:
2200 //
2201 // 1 If the previous member ended on a character boundary, then we can emit an
2202 // anonymous member starting at the most recent character boundary.
2203 //
2204 // 2 If the previous member did not end on a character boundary and the distance
2205 // from the end of the previous member to the current member is less than a
2206 // word width, then we can emit an anonymous member starting right after the
2207 // previous member and right before this member.
2208 //
2209 // 3 If the previous member did not end on a character boundary and the distance
2210 // from the end of the previous member to the current member is greater than
2211 // or equal a word width, then we act as in Case 1.
2212
2213 const uint64_t character_width = 8;
2214 const uint64_t word_width = 32;
2215
Sean Callananfaa0bb32012-12-05 23:37:14 +00002216 // Objective-C has invalid DW_AT_bit_offset values in older versions
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +00002217 // of clang, so we have to be careful and only insert unnamed bitfields
Greg Clayton37c36e42012-11-27 00:59:26 +00002218 // if we have a new enough clang.
2219 bool detect_unnamed_bitfields = true;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002220
Greg Clayton37c36e42012-11-27 00:59:26 +00002221 if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus)
2222 detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields ();
2223
2224 if (detect_unnamed_bitfields)
Greg Clayton88bc7f32012-11-06 00:20:41 +00002225 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00002226 BitfieldInfo anon_field_info;
2227
2228 if ((this_field_info.bit_offset % character_width) != 0) // not char aligned
Greg Clayton88bc7f32012-11-06 00:20:41 +00002229 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00002230 uint64_t last_field_end = 0;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002231
Sean Callananfaa0bb32012-12-05 23:37:14 +00002232 if (last_field_info.IsValid())
2233 last_field_end = last_field_info.bit_offset + last_field_info.bit_size;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002234
Sean Callananfaa0bb32012-12-05 23:37:14 +00002235 if (this_field_info.bit_offset != last_field_end)
2236 {
2237 if (((last_field_end % character_width) == 0) || // case 1
2238 (this_field_info.bit_offset - last_field_end >= word_width)) // case 3
2239 {
2240 anon_field_info.bit_size = this_field_info.bit_offset % character_width;
2241 anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size;
2242 }
2243 else // case 2
2244 {
2245 anon_field_info.bit_size = this_field_info.bit_offset - last_field_end;
2246 anon_field_info.bit_offset = last_field_end;
2247 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00002248 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00002249 }
2250
Sean Callananfaa0bb32012-12-05 23:37:14 +00002251 if (anon_field_info.IsValid())
Greg Clayton88bc7f32012-11-06 00:20:41 +00002252 {
Greg Claytond8d4a572015-08-11 21:38:15 +00002253 clang::FieldDecl *unnamed_bitfield_decl =
2254 ClangASTContext::AddFieldToRecordType (class_clang_type,
2255 NULL,
2256 GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width),
2257 accessibility,
2258 anon_field_info.bit_size);
Zachary Turner504f38d2015-03-24 16:24:50 +00002259
Zachary Turnera98fac22015-03-24 18:56:08 +00002260 layout_info.field_offsets.insert(
Zachary Turner504f38d2015-03-24 16:24:50 +00002261 std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset));
Greg Clayton88bc7f32012-11-06 00:20:41 +00002262 }
2263 }
Greg Clayton78f4d952013-12-11 23:10:39 +00002264 last_field_info = this_field_info;
2265 }
2266 else
2267 {
2268 last_field_info.Clear();
Greg Clayton88bc7f32012-11-06 00:20:41 +00002269 }
Sean Callananfaa0bb32012-12-05 23:37:14 +00002270
Greg Claytona1e5dc82015-08-11 22:53:00 +00002271 CompilerType member_clang_type = member_type->GetClangLayoutType();
Sean Callananfa3ab452012-12-14 00:54:13 +00002272
2273 {
2274 // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>).
2275 // If the current field is at the end of the structure, then there is definitely no room for extra
2276 // elements and we override the type to array[0].
2277
Greg Claytona1e5dc82015-08-11 22:53:00 +00002278 CompilerType member_array_element_type;
Sean Callananfa3ab452012-12-14 00:54:13 +00002279 uint64_t member_array_size;
2280 bool member_array_is_incomplete;
2281
Greg Clayton57ee3062013-07-11 22:46:58 +00002282 if (member_clang_type.IsArrayType(&member_array_element_type,
2283 &member_array_size,
2284 &member_array_is_incomplete) &&
Sean Callananfa3ab452012-12-14 00:54:13 +00002285 !member_array_is_incomplete)
2286 {
2287 uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX);
2288
2289 if (member_byte_offset >= parent_byte_size)
2290 {
2291 if (member_array_size != 1)
2292 {
2293 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,
2294 MakeUserID(die->GetOffset()),
2295 name,
2296 encoding_uid,
2297 MakeUserID(parent_die->GetOffset()));
2298 }
2299
Greg Clayton1c8ef472013-04-05 23:27:21 +00002300 member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0, false);
Sean Callananfa3ab452012-12-14 00:54:13 +00002301 }
2302 }
2303 }
2304
Greg Claytond8d4a572015-08-11 21:38:15 +00002305 field_decl = ClangASTContext::AddFieldToRecordType (class_clang_type,
2306 name,
Greg Clayton57ee3062013-07-11 22:46:58 +00002307 member_clang_type,
2308 accessibility,
2309 bit_size);
Sean Callanan60217122012-04-13 00:10:03 +00002310
Greg Claytond0029442013-03-27 01:48:02 +00002311 GetClangASTContext().SetMetadataAsUserID (field_decl, MakeUserID(die->GetOffset()));
Greg Clayton78f4d952013-12-11 23:10:39 +00002312
Zachary Turnera98fac22015-03-24 18:56:08 +00002313 layout_info.field_offsets.insert(std::make_pair(field_decl, field_bit_offset));
Sean Callanan5b26f272012-02-04 08:49:35 +00002314 }
2315 else
2316 {
Sean Callanan751aac62012-03-29 19:07:06 +00002317 if (name)
Daniel Malead01b2952012-11-29 21:49:15 +00002318 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 +00002319 MakeUserID(die->GetOffset()),
2320 name,
2321 encoding_uid);
2322 else
Daniel Malead01b2952012-11-29 21:49:15 +00002323 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 +00002324 MakeUserID(die->GetOffset()),
2325 encoding_uid);
Sean Callanan5b26f272012-02-04 08:49:35 +00002326 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002327 }
Sean Callanan751aac62012-03-29 19:07:06 +00002328
Greg Clayton3ca8f422015-07-13 22:08:16 +00002329 if (prop_name != NULL && member_type)
Jim Inghame3ae82a2011-11-12 01:36:43 +00002330 {
Sean Callanan751aac62012-03-29 19:07:06 +00002331 clang::ObjCIvarDecl *ivar_decl = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00002332
Sean Callanan751aac62012-03-29 19:07:06 +00002333 if (field_decl)
2334 {
2335 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
2336 assert (ivar_decl != NULL);
2337 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00002338
Jim Ingham379397632012-10-27 02:54:13 +00002339 ClangASTMetadata metadata;
2340 metadata.SetUserID (MakeUserID(die->GetOffset()));
Greg Clayton57ee3062013-07-11 22:46:58 +00002341 delayed_properties.push_back(DelayedAddObjCClassProperty(class_clang_type,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002342 prop_name,
2343 member_type->GetClangLayoutType(),
2344 ivar_decl,
2345 prop_setter_name,
2346 prop_getter_name,
2347 prop_attributes,
Jim Ingham379397632012-10-27 02:54:13 +00002348 &metadata));
Sean Callanan60217122012-04-13 00:10:03 +00002349
Sean Callananad880762012-04-18 01:06:17 +00002350 if (ivar_decl)
Greg Claytond0029442013-03-27 01:48:02 +00002351 GetClangASTContext().SetMetadataAsUserID (ivar_decl, MakeUserID(die->GetOffset()));
Jim Inghame3ae82a2011-11-12 01:36:43 +00002352 }
Greg Clayton24739922010-10-13 03:15:28 +00002353 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002354 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00002355 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002356 }
2357 break;
2358
2359 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00002360 // Let the type parsing code handle this one for us.
2361 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002362 break;
2363
2364 case DW_TAG_inheritance:
2365 {
2366 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00002367 if (default_accessibility == eAccessNone)
2368 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002369 // TODO: implement DW_TAG_inheritance type parsing
2370 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00002371 const size_t num_attributes = die->GetAttributes (this,
2372 dwarf_cu,
2373 fixed_form_sizes,
2374 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002375 if (num_attributes > 0)
2376 {
2377 Declaration decl;
2378 DWARFExpression location;
2379 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00002380 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002381 bool is_virtual = false;
2382 bool is_base_of_class = true;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002383 off_t member_byte_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002384 uint32_t i;
2385 for (i=0; i<num_attributes; ++i)
2386 {
2387 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2388 DWARFFormValue form_value;
2389 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2390 {
2391 switch (attr)
2392 {
2393 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2394 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2395 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00002396 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002397 case DW_AT_data_member_location:
2398 if (form_value.BlockData())
2399 {
2400 Value initialValue(0);
2401 Value memberOffset(0);
Ed Masteeeae7212013-10-24 20:43:47 +00002402 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002403 uint32_t block_length = form_value.Unsigned();
2404 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
2405 if (DWARFExpression::Evaluate (NULL,
2406 NULL,
2407 NULL,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002408 NULL,
Richard Mitton0a558352013-10-17 21:14:00 +00002409 module,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002410 debug_info_data,
2411 block_offset,
2412 block_length,
2413 eRegisterKindDWARF,
2414 &initialValue,
2415 memberOffset,
2416 NULL))
2417 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002418 member_byte_offset = memberOffset.ResolveValue(NULL).UInt();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002419 }
2420 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002421 else
2422 {
2423 // With DWARF 3 and later, if the value is an integer constant,
2424 // this form value is the offset in bytes from the beginning
2425 // of the containing entity.
2426 member_byte_offset = form_value.Unsigned();
2427 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002428 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002429
2430 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00002431 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002432 break;
2433
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002434 case DW_AT_virtuality:
2435 is_virtual = form_value.Boolean();
2436 break;
2437
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002438 case DW_AT_sibling:
2439 break;
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002440
2441 default:
2442 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002443 }
2444 }
2445 }
2446
Greg Clayton526e5af2010-11-13 03:52:47 +00002447 Type *base_class_type = ResolveTypeUID(encoding_uid);
Greg Clayton898c1b22015-05-15 22:31:18 +00002448 if (base_class_type == NULL)
2449 {
Bruce Mitchener58ef3912015-06-18 05:27:05 +00002450 GetObjectFile()->GetModule()->ReportError("0x%8.8x: DW_TAG_inheritance failed to resolve the base class at 0x%8.8" PRIx64 " from enclosing type 0x%8.8x. \nPlease file a bug and attach the file at the start of this error message",
Greg Clayton898c1b22015-05-15 22:31:18 +00002451 die->GetOffset(),
2452 encoding_uid,
2453 parent_die->GetOffset());
2454 break;
2455 }
2456
Greg Claytona1e5dc82015-08-11 22:53:00 +00002457 CompilerType base_class_clang_type = base_class_type->GetClangFullType();
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002458 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002459 if (class_language == eLanguageTypeObjC)
2460 {
Greg Claytond8d4a572015-08-11 21:38:15 +00002461 ast->SetObjCSuperClass(class_clang_type, base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002462 }
2463 else
2464 {
Greg Claytond8d4a572015-08-11 21:38:15 +00002465 base_classes.push_back (ast->CreateBaseClassSpecifier (base_class_clang_type.GetOpaqueQualType(),
2466 accessibility,
2467 is_virtual,
2468 is_base_of_class));
Greg Clayton2508b9b2012-11-01 23:20:02 +00002469
2470 if (is_virtual)
2471 {
Greg Clayton52694e32013-09-16 21:57:07 +00002472 // Do not specify any offset for virtual inheritance. The DWARF produced by clang doesn't
2473 // give us a constant offset, but gives us a DWARF expressions that requires an actual object
2474 // in memory. the DW_AT_data_member_location for a virtual base class looks like:
2475 // DW_AT_data_member_location( DW_OP_dup, DW_OP_deref, DW_OP_constu(0x00000018), DW_OP_minus, DW_OP_deref, DW_OP_plus )
2476 // Given this, there is really no valid response we can give to clang for virtual base
2477 // class offsets, and this should eventually be removed from LayoutRecordType() in the external
2478 // AST source in clang.
Greg Clayton2508b9b2012-11-01 23:20:02 +00002479 }
2480 else
2481 {
Zachary Turnera98fac22015-03-24 18:56:08 +00002482 layout_info.base_offsets.insert(
Greg Claytond8d4a572015-08-11 21:38:15 +00002483 std::make_pair(ast->GetAsCXXRecordDecl(base_class_clang_type.GetOpaqueQualType()),
Zachary Turner504f38d2015-03-24 16:24:50 +00002484 clang::CharUnits::fromQuantity(member_byte_offset)));
Greg Clayton2508b9b2012-11-01 23:20:02 +00002485 }
Greg Clayton9e409562010-07-28 02:04:09 +00002486 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002487 }
2488 }
2489 break;
2490
2491 default:
2492 break;
2493 }
2494 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002495
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002496 return count;
2497}
2498
2499
2500clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00002501SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002502{
2503 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00002504 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002505 {
2506 DWARFCompileUnitSP cu_sp;
2507 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
2508 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00002509 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00002510 }
2511 return NULL;
2512}
2513
2514clang::DeclContext*
2515SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
2516{
Greg Clayton81c22f62011-10-19 18:09:39 +00002517 if (UserIDMatches(type_uid))
2518 return GetClangDeclContextForDIEOffset (sc, type_uid);
2519 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002520}
2521
2522Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00002523SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002524{
Greg Clayton81c22f62011-10-19 18:09:39 +00002525 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002526 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002527 DWARFDebugInfo* debug_info = DebugInfo();
2528 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00002529 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002530 DWARFCompileUnitSP cu_sp;
2531 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00002532 const bool assert_not_being_parsed = true;
2533 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00002534 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002535 }
2536 return NULL;
2537}
2538
Greg Claytoncab36a32011-12-08 05:16:30 +00002539Type*
2540SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00002541{
Greg Claytoncab36a32011-12-08 05:16:30 +00002542 if (die != NULL)
2543 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002544 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00002545 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002546 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002547 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
2548 die->GetOffset(),
2549 DW_TAG_value_to_name(die->Tag()),
2550 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00002551
Greg Claytoncab36a32011-12-08 05:16:30 +00002552 // We might be coming in in the middle of a type tree (a class
2553 // withing a class, an enum within a class), so parse any needed
2554 // parent DIEs before we get to this one...
2555 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2556 switch (decl_ctx_die->Tag())
2557 {
2558 case DW_TAG_structure_type:
2559 case DW_TAG_union_type:
2560 case DW_TAG_class_type:
2561 {
2562 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00002563 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002564 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002565 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
2566 die->GetOffset(),
2567 DW_TAG_value_to_name(die->Tag()),
2568 die->GetName(this, cu),
2569 decl_ctx_die->GetOffset());
Greg Clayton219cf312012-03-30 00:51:13 +00002570//
2571// Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
2572// if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
2573// {
2574// if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002575// GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton219cf312012-03-30 00:51:13 +00002576// "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
2577// die->GetOffset(),
2578// DW_TAG_value_to_name(die->Tag()),
2579// die->GetName(this, cu),
2580// decl_ctx_die->GetOffset());
2581// // Ask the type to complete itself if it already hasn't since if we
2582// // want a function (method or static) from a class, the class must
2583// // create itself and add it's own methods and class functions.
2584// if (parent_type)
2585// parent_type->GetClangFullType();
2586// }
Greg Claytoncab36a32011-12-08 05:16:30 +00002587 }
2588 break;
2589
2590 default:
2591 break;
2592 }
2593 return ResolveType (cu, die);
2594 }
2595 return NULL;
2596}
2597
Greg Clayton6beaaa62011-01-17 03:46:26 +00002598// This function is used when SymbolFileDWARFDebugMap owns a bunch of
2599// SymbolFileDWARF objects to detect if this DWARF file is the one that
2600// can resolve a clang_type.
2601bool
Greg Claytona1e5dc82015-08-11 22:53:00 +00002602SymbolFileDWARF::HasForwardDeclForClangType (const CompilerType &clang_type)
Greg Clayton6beaaa62011-01-17 03:46:26 +00002603{
Greg Claytona1e5dc82015-08-11 22:53:00 +00002604 CompilerType clang_type_no_qualifiers = ClangASTContext::RemoveFastQualifiers(clang_type);
Greg Clayton57ee3062013-07-11 22:46:58 +00002605 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton6beaaa62011-01-17 03:46:26 +00002606 return die != NULL;
2607}
2608
2609
Greg Clayton57ee3062013-07-11 22:46:58 +00002610bool
Greg Claytona1e5dc82015-08-11 22:53:00 +00002611SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (CompilerType &clang_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00002612{
2613 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Claytona1e5dc82015-08-11 22:53:00 +00002614 CompilerType clang_type_no_qualifiers = ClangASTContext::RemoveFastQualifiers(clang_type);
Greg Clayton57ee3062013-07-11 22:46:58 +00002615 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton1be10fc2010-09-29 01:12:09 +00002616 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00002617 {
2618 // We have already resolved this type...
Greg Clayton57ee3062013-07-11 22:46:58 +00002619 return true;
Greg Clayton73b472d2010-10-27 03:32:59 +00002620 }
2621 // Once we start resolving this type, remove it from the forward declaration
2622 // map in case anyone child members or other types require this type to get resolved.
2623 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
2624 // are done.
Greg Clayton57ee3062013-07-11 22:46:58 +00002625 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton1be10fc2010-09-29 01:12:09 +00002626
Greg Claytond8d4a572015-08-11 21:38:15 +00002627 ClangASTContext* ast = clang_type.GetTypeSystem()->AsClangASTContext();
2628 if (ast == NULL)
2629 {
2630 // Not a clang type
2631 return true;
2632 }
2633
Greg Clayton85ae2e12011-10-18 23:36:41 +00002634 // Disable external storage for this type so we don't get anymore
2635 // clang::ExternalASTSource queries for this type.
Greg Claytond8d4a572015-08-11 21:38:15 +00002636 ast->SetHasExternalStorage (clang_type.GetOpaqueQualType(), false);
Greg Clayton85ae2e12011-10-18 23:36:41 +00002637
Greg Clayton450e3f32010-10-12 02:24:53 +00002638 DWARFDebugInfo* debug_info = DebugInfo();
2639
Greg Clayton53eb1c22012-04-02 22:59:12 +00002640 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002641 Type *type = m_die_to_type.lookup (die);
2642
2643 const dw_tag_t tag = die->Tag();
2644
Greg Clayton5160ce52013-03-27 23:08:40 +00002645 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
Greg Clayton3bffb082011-12-10 02:15:28 +00002646 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002647 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002648 "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...",
Greg Claytond61c0fc2012-04-23 22:55:20 +00002649 MakeUserID(die->GetOffset()),
2650 DW_TAG_value_to_name(tag),
2651 type->GetName().AsCString());
Greg Clayton1be10fc2010-09-29 01:12:09 +00002652 assert (clang_type);
2653 DWARFDebugInfoEntry::Attributes attributes;
2654
Greg Clayton1be10fc2010-09-29 01:12:09 +00002655 switch (tag)
2656 {
2657 case DW_TAG_structure_type:
2658 case DW_TAG_union_type:
2659 case DW_TAG_class_type:
Greg Claytonc93237c2010-10-01 20:48:32 +00002660 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002661 LayoutInfo layout_info;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002662
Greg Clayton1be10fc2010-09-29 01:12:09 +00002663 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002664 if (die->HasChildren())
Greg Claytonc93237c2010-10-01 20:48:32 +00002665 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002666 LanguageType class_language = eLanguageTypeUnknown;
Greg Claytond8d4a572015-08-11 21:38:15 +00002667 if (ClangASTContext::IsObjCObjectOrInterfaceType(clang_type))
Greg Clayton219cf312012-03-30 00:51:13 +00002668 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002669 class_language = eLanguageTypeObjC;
Greg Clayton219cf312012-03-30 00:51:13 +00002670 // For objective C we don't start the definition when
2671 // the class is created.
Greg Claytond8d4a572015-08-11 21:38:15 +00002672 ClangASTContext::StartTagDeclarationDefinition (clang_type);
Greg Clayton219cf312012-03-30 00:51:13 +00002673 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002674
Sean Callanan77a1fd32012-02-27 20:07:01 +00002675 int tag_decl_kind = -1;
2676 AccessType default_accessibility = eAccessNone;
2677 if (tag == DW_TAG_structure_type)
2678 {
2679 tag_decl_kind = clang::TTK_Struct;
2680 default_accessibility = eAccessPublic;
2681 }
2682 else if (tag == DW_TAG_union_type)
2683 {
2684 tag_decl_kind = clang::TTK_Union;
2685 default_accessibility = eAccessPublic;
2686 }
2687 else if (tag == DW_TAG_class_type)
2688 {
2689 tag_decl_kind = clang::TTK_Class;
2690 default_accessibility = eAccessPrivate;
2691 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002692
Greg Clayton53eb1c22012-04-02 22:59:12 +00002693 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002694 std::vector<clang::CXXBaseSpecifier *> base_classes;
2695 std::vector<int> member_accessibilities;
2696 bool is_a_class = false;
2697 // Parse members and base classes first
2698 DWARFDIECollection member_function_dies;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002699
Sean Callanana0b80ab2012-06-04 22:28:05 +00002700 DelayedPropertyList delayed_properties;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002701 ParseChildMembers (sc,
Greg Clayton53eb1c22012-04-02 22:59:12 +00002702 dwarf_cu,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002703 die,
2704 clang_type,
2705 class_language,
2706 base_classes,
2707 member_accessibilities,
2708 member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002709 delayed_properties,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002710 default_accessibility,
2711 is_a_class,
2712 layout_info);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002713
Sean Callanan77a1fd32012-02-27 20:07:01 +00002714 // Now parse any methods if there were any...
2715 size_t num_functions = member_function_dies.Size();
2716 if (num_functions > 0)
2717 {
2718 for (size_t i=0; i<num_functions; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002719 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002720 ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytoncaab74e2012-01-28 00:48:57 +00002721 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002722 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002723
Sean Callanan77a1fd32012-02-27 20:07:01 +00002724 if (class_language == eLanguageTypeObjC)
2725 {
Jim Inghamfb6fc0d2013-09-27 20:59:37 +00002726 ConstString class_name (clang_type.GetTypeName());
2727 if (class_name)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002728 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002729 DIEArray method_die_offsets;
2730 if (m_using_apple_tables)
Greg Clayton95d87902011-11-11 03:16:25 +00002731 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002732 if (m_apple_objc_ap.get())
Jim Inghamfb6fc0d2013-09-27 20:59:37 +00002733 m_apple_objc_ap->FindByName(class_name.GetCString(), method_die_offsets);
Sean Callanan77a1fd32012-02-27 20:07:01 +00002734 }
2735 else
2736 {
2737 if (!m_indexed)
2738 Index ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002739
Sean Callanan77a1fd32012-02-27 20:07:01 +00002740 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
2741 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002742
Sean Callanan77a1fd32012-02-27 20:07:01 +00002743 if (!method_die_offsets.empty())
2744 {
2745 DWARFDebugInfo* debug_info = DebugInfo();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002746
Sean Callanan77a1fd32012-02-27 20:07:01 +00002747 DWARFCompileUnit* method_cu = NULL;
2748 const size_t num_matches = method_die_offsets.size();
2749 for (size_t i=0; i<num_matches; ++i)
Greg Clayton95d87902011-11-11 03:16:25 +00002750 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002751 const dw_offset_t die_offset = method_die_offsets[i];
2752 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002753
Sean Callanan77a1fd32012-02-27 20:07:01 +00002754 if (method_die)
2755 ResolveType (method_cu, method_die);
2756 else
Greg Claytoncaab74e2012-01-28 00:48:57 +00002757 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002758 if (m_using_apple_tables)
2759 {
2760 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 +00002761 die_offset, class_name.GetCString());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002762 }
2763 }
2764 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002765 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002766
Greg Clayton57ee3062013-07-11 22:46:58 +00002767 for (DelayedPropertyList::iterator pi = delayed_properties.begin(), pe = delayed_properties.end();
Sean Callanana0b80ab2012-06-04 22:28:05 +00002768 pi != pe;
2769 ++pi)
2770 pi->Finalize();
Greg Clayton450e3f32010-10-12 02:24:53 +00002771 }
2772 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002773
Sean Callanan77a1fd32012-02-27 20:07:01 +00002774 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2775 // need to tell the clang type it is actually a class.
2776 if (class_language != eLanguageTypeObjC)
2777 {
2778 if (is_a_class && tag_decl_kind != clang::TTK_Class)
Greg Claytond8d4a572015-08-11 21:38:15 +00002779 GetClangASTContext().SetTagTypeKind (ClangASTContext::GetQualType(clang_type), clang::TTK_Class);
Sean Callanan77a1fd32012-02-27 20:07:01 +00002780 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002781
Sean Callanan77a1fd32012-02-27 20:07:01 +00002782 // Since DW_TAG_structure_type gets used for both classes
2783 // and structures, we may need to set any DW_TAG_member
2784 // fields to have a "private" access if none was specified.
2785 // When we parsed the child members we tracked that actual
2786 // accessibility value for each DW_TAG_member in the
2787 // "member_accessibilities" array. If the value for the
2788 // member is zero, then it was set to the "default_accessibility"
2789 // which for structs was "public". Below we correct this
2790 // by setting any fields to "private" that weren't correctly
2791 // set.
2792 if (is_a_class && !member_accessibilities.empty())
2793 {
2794 // This is a class and all members that didn't have
2795 // their access specified are private.
Greg Claytond8d4a572015-08-11 21:38:15 +00002796 GetClangASTContext().SetDefaultAccessForRecordFields (ast->GetAsRecordDecl(clang_type),
2797 eAccessPrivate,
2798 &member_accessibilities.front(),
2799 member_accessibilities.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002800 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002801
Sean Callanan77a1fd32012-02-27 20:07:01 +00002802 if (!base_classes.empty())
2803 {
Greg Clayton4705f8d2013-12-12 01:54:04 +00002804 // Make sure all base classes refer to complete types and not
2805 // forward declarations. If we don't do this, clang will crash
2806 // with an assertion in the call to clang_type.SetBaseClassesForClassType()
2807 bool base_class_error = false;
2808 for (auto &base_class : base_classes)
2809 {
2810 clang::TypeSourceInfo *type_source_info = base_class->getTypeSourceInfo();
2811 if (type_source_info)
2812 {
Greg Claytona1e5dc82015-08-11 22:53:00 +00002813 CompilerType base_class_type (GetClangASTContext().getASTContext(), type_source_info->getType());
Greg Clayton4705f8d2013-12-12 01:54:04 +00002814 if (base_class_type.GetCompleteType() == false)
2815 {
2816 if (!base_class_error)
2817 {
2818 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",
2819 die->GetOffset(),
2820 die->GetName(this, dwarf_cu),
2821 base_class_type.GetTypeName().GetCString(),
2822 sc.comp_unit ? sc.comp_unit->GetPath().c_str() : "the source file");
2823 }
2824 // We have no choice other than to pretend that the base class
2825 // is complete. If we don't do this, clang will crash when we
2826 // call setBases() inside of "clang_type.SetBaseClassesForClassType()"
2827 // below. Since we provide layout assistance, all ivars in this
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00002828 // class and other classes will be fine, this is the best we can do
Greg Clayton4705f8d2013-12-12 01:54:04 +00002829 // short of crashing.
Greg Claytond8d4a572015-08-11 21:38:15 +00002830
2831 ClangASTContext::StartTagDeclarationDefinition (base_class_type);
2832 ClangASTContext::CompleteTagDeclarationDefinition (base_class_type);
Greg Clayton4705f8d2013-12-12 01:54:04 +00002833 }
2834 }
2835 }
Greg Claytond8d4a572015-08-11 21:38:15 +00002836 ast->SetBaseClassesForClassType (clang_type.GetOpaqueQualType(),
2837 &base_classes.front(),
2838 base_classes.size());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002839
Sean Callanan77a1fd32012-02-27 20:07:01 +00002840 // Clang will copy each CXXBaseSpecifier in "base_classes"
2841 // so we have to free them all.
Greg Claytond8d4a572015-08-11 21:38:15 +00002842 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
2843 base_classes.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002844 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002845 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002846 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002847
Greg Claytond8d4a572015-08-11 21:38:15 +00002848 ClangASTContext::BuildIndirectFields (clang_type);
2849 ClangASTContext::CompleteTagDeclarationDefinition (clang_type);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002850
Greg Clayton2508b9b2012-11-01 23:20:02 +00002851 if (!layout_info.field_offsets.empty() ||
2852 !layout_info.base_offsets.empty() ||
2853 !layout_info.vbase_offsets.empty() )
Greg Claytoncaab74e2012-01-28 00:48:57 +00002854 {
2855 if (type)
2856 layout_info.bit_size = type->GetByteSize() * 8;
2857 if (layout_info.bit_size == 0)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002858 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002859
Greg Claytond8d4a572015-08-11 21:38:15 +00002860 clang::CXXRecordDecl *record_decl = ast->GetAsCXXRecordDecl(clang_type.GetOpaqueQualType());
Greg Clayton2508b9b2012-11-01 23:20:02 +00002861 if (record_decl)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002862 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002863 if (log)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002864 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002865 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002866 "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 +00002867 static_cast<void*>(clang_type.GetOpaqueQualType()),
2868 static_cast<void*>(record_decl),
Greg Claytoncaab74e2012-01-28 00:48:57 +00002869 layout_info.bit_size,
2870 layout_info.alignment,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002871 static_cast<uint32_t>(layout_info.field_offsets.size()),
2872 static_cast<uint32_t>(layout_info.base_offsets.size()),
2873 static_cast<uint32_t>(layout_info.vbase_offsets.size()));
2874
Zachary Turnera98fac22015-03-24 18:56:08 +00002875 uint32_t idx;
2876 {
2877 llvm::DenseMap<const clang::FieldDecl *, uint64_t>::const_iterator pos,
2878 end = layout_info.field_offsets.end();
2879 for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx)
Greg Clayton2508b9b2012-11-01 23:20:02 +00002880 {
Zachary Turner504f38d2015-03-24 16:24:50 +00002881 GetObjectFile()->GetModule()->LogMessage(
2882 log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = "
2883 "{ bit_offset=%u, name='%s' }",
Zachary Turner504f38d2015-03-24 16:24:50 +00002884 static_cast<void *>(clang_type.GetOpaqueQualType()), idx,
Zachary Turnera98fac22015-03-24 18:56:08 +00002885 static_cast<uint32_t>(pos->second), pos->first->getNameAsString().c_str());
2886 }
2887 }
2888
2889 {
2890 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos,
2891 base_end = layout_info.base_offsets.end();
2892 for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end;
2893 ++base_pos, ++idx)
2894 {
2895 GetObjectFile()->GetModule()->LogMessage(
2896 log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] "
2897 "= { byte_offset=%u, name='%s' }",
2898 clang_type.GetOpaqueQualType(), idx, (uint32_t)base_pos->second.getQuantity(),
2899 base_pos->first->getNameAsString().c_str());
2900 }
2901 }
2902 {
2903 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos,
2904 vbase_end = layout_info.vbase_offsets.end();
2905 for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end;
2906 ++vbase_pos, ++idx)
2907 {
2908 GetObjectFile()->GetModule()->LogMessage(
2909 log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) "
2910 "vbase[%u] = { byte_offset=%u, name='%s' }",
2911 static_cast<void *>(clang_type.GetOpaqueQualType()), idx,
2912 static_cast<uint32_t>(vbase_pos->second.getQuantity()),
2913 vbase_pos->first->getNameAsString().c_str());
2914 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002915 }
Greg Clayton821ac6d2012-01-28 02:22:27 +00002916 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002917 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2918 }
2919 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002920 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002921
Sean Callanan9076c0f2013-10-04 21:35:29 +00002922 return (bool)clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002923
2924 case DW_TAG_enumeration_type:
Greg Claytond8d4a572015-08-11 21:38:15 +00002925 ClangASTContext::StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002926 if (die->HasChildren())
2927 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002928 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00002929 bool is_signed = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00002930 clang_type.IsIntegerType(is_signed);
Greg Clayton3e067532013-03-05 23:54:39 +00002931 ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002932 }
Greg Claytond8d4a572015-08-11 21:38:15 +00002933 ClangASTContext::CompleteTagDeclarationDefinition (clang_type);
Sean Callanan9076c0f2013-10-04 21:35:29 +00002934 return (bool)clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002935
2936 default:
2937 assert(false && "not a forward clang type decl!");
2938 break;
2939 }
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00002940 return false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002941}
2942
Greg Claytonc685f8e2010-09-15 04:15:46 +00002943Type*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002944SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002945{
2946 if (type_die != NULL)
2947 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002948 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00002949
Greg Claytonc685f8e2010-09-15 04:15:46 +00002950 if (type == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002951 type = GetTypeForDIE (dwarf_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00002952
Greg Clayton24739922010-10-13 03:15:28 +00002953 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00002954 {
2955 if (type != DIE_IS_BEING_PARSED)
2956 return type;
2957
2958 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
Greg Clayton53eb1c22012-04-02 22:59:12 +00002959 type_die->GetOffset(),
2960 DW_TAG_value_to_name(type_die->Tag()),
2961 type_die->GetName(this, dwarf_cu));
Jim Inghamc3549282012-01-11 02:21:12 +00002962
2963 }
2964 else
2965 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002966 }
2967 return NULL;
2968}
2969
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002970CompileUnit*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002971SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002972{
2973 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002974 if (dwarf_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002975 {
2976 // The symbol vendor doesn't know about this compile unit, we
2977 // need to parse and add it to the symbol vendor object.
Greg Clayton53eb1c22012-04-02 22:59:12 +00002978 return ParseCompileUnit(dwarf_cu, cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002979 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00002980 return (CompileUnit*)dwarf_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002981}
2982
2983bool
Greg Clayton53eb1c22012-04-02 22:59:12 +00002984SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002985{
Greg Clayton72310352013-02-23 04:12:47 +00002986 sc.Clear(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002987 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002988 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002989
Greg Clayton81c22f62011-10-19 18:09:39 +00002990 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002991 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002992 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002993
2994 if (sc.function)
2995 {
Greg Claytone72dfb32012-02-24 01:59:29 +00002996 sc.module_sp = sc.function->CalculateSymbolContextModule();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002997 return true;
2998 }
2999
3000 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003001}
3002
Sean Callananf0c5aeb2015-04-20 16:31:29 +00003003void
3004SymbolFileDWARF::UpdateExternalModuleListIfNeeded()
3005{
3006 if (m_fetched_external_modules)
3007 return;
3008 m_fetched_external_modules = true;
3009
3010 DWARFDebugInfo * debug_info = DebugInfo();
3011 debug_info->GetNumCompileUnits();
3012
3013 const uint32_t num_compile_units = GetNumCompileUnits();
3014 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
3015 {
3016 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
3017
3018 const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly();
3019 if (die && die->HasChildren() == false)
3020 {
3021 const uint64_t name_strp = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_name, UINT64_MAX);
3022 const uint64_t dwo_path_strp = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_GNU_dwo_name, UINT64_MAX);
3023
3024 if (name_strp != UINT64_MAX)
3025 {
3026 if (m_external_type_modules.find(dwo_path_strp) == m_external_type_modules.end())
3027 {
3028 const char *name = get_debug_str_data().PeekCStr(name_strp);
3029 const char *dwo_path = get_debug_str_data().PeekCStr(dwo_path_strp);
3030 if (name || dwo_path)
3031 {
3032 ModuleSP module_sp;
3033 if (dwo_path)
3034 {
3035 ModuleSpec dwo_module_spec;
3036 dwo_module_spec.GetFileSpec().SetFile(dwo_path, false);
3037 dwo_module_spec.GetArchitecture() = m_obj_file->GetModule()->GetArchitecture();
3038 //printf ("Loading dwo = '%s'\n", dwo_path);
3039 Error error = ModuleList::GetSharedModule (dwo_module_spec, module_sp, NULL, NULL, NULL);
3040 }
3041
3042 if (dwo_path_strp != LLDB_INVALID_UID)
3043 {
3044 m_external_type_modules[dwo_path_strp] = ClangModuleInfo { ConstString(name), module_sp };
3045 }
3046 else
3047 {
3048 // This hack should be removed promptly once clang emits both.
3049 m_external_type_modules[name_strp] = ClangModuleInfo { ConstString(name), module_sp };
3050 }
3051 }
3052 }
3053 }
3054 }
3055 }
3056}
Greg Clayton2501e5e2015-01-15 02:59:20 +00003057
3058SymbolFileDWARF::GlobalVariableMap &
3059SymbolFileDWARF::GetGlobalAranges()
3060{
3061 if (!m_global_aranges_ap)
3062 {
3063 m_global_aranges_ap.reset (new GlobalVariableMap());
3064
3065 ModuleSP module_sp = GetObjectFile()->GetModule();
3066 if (module_sp)
3067 {
3068 const size_t num_cus = module_sp->GetNumCompileUnits();
3069 for (size_t i = 0; i < num_cus; ++i)
3070 {
3071 CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(i);
3072 if (cu_sp)
3073 {
3074 VariableListSP globals_sp = cu_sp->GetVariableList(true);
3075 if (globals_sp)
3076 {
3077 const size_t num_globals = globals_sp->GetSize();
3078 for (size_t g = 0; g < num_globals; ++g)
3079 {
3080 VariableSP var_sp = globals_sp->GetVariableAtIndex(g);
3081 if (var_sp && !var_sp->GetLocationIsConstantValueData())
3082 {
3083 const DWARFExpression &location = var_sp->LocationExpression();
3084 Value location_result;
3085 Error error;
3086 if (location.Evaluate(NULL, NULL, NULL, LLDB_INVALID_ADDRESS, NULL, location_result, &error))
3087 {
3088 if (location_result.GetValueType() == Value::eValueTypeFileAddress)
3089 {
3090 lldb::addr_t file_addr = location_result.GetScalar().ULongLong();
3091 lldb::addr_t byte_size = 1;
3092 if (var_sp->GetType())
3093 byte_size = var_sp->GetType()->GetByteSize();
3094 m_global_aranges_ap->Append(GlobalVariableMap::Entry(file_addr, byte_size, var_sp.get()));
3095 }
3096 }
3097 }
3098 }
3099 }
3100 }
3101 }
3102 }
3103 m_global_aranges_ap->Sort();
3104 }
3105 return *m_global_aranges_ap;
3106}
3107
3108
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003109uint32_t
3110SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
3111{
3112 Timer scoped_timer(__PRETTY_FUNCTION__,
Daniel Malead01b2952012-11-29 21:49:15 +00003113 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003114 static_cast<void*>(so_addr.GetSection().get()),
3115 so_addr.GetOffset(), resolve_scope);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003116 uint32_t resolved = 0;
Greg Clayton2501e5e2015-01-15 02:59:20 +00003117 if (resolve_scope & ( eSymbolContextCompUnit |
3118 eSymbolContextFunction |
3119 eSymbolContextBlock |
3120 eSymbolContextLineEntry |
3121 eSymbolContextVariable ))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003122 {
3123 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
3124
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003125 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00003126 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003127 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003128 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Greg Clayton2501e5e2015-01-15 02:59:20 +00003129 if (cu_offset == DW_INVALID_OFFSET)
3130 {
3131 // Global variables are not in the compile unit address ranges. The only way to
3132 // currently find global variables is to iterate over the .debug_pubnames or the
3133 // __apple_names table and find all items in there that point to DW_TAG_variable
3134 // DIEs and then find the address that matches.
3135 if (resolve_scope & eSymbolContextVariable)
3136 {
3137 GlobalVariableMap &map = GetGlobalAranges();
3138 const GlobalVariableMap::Entry *entry = map.FindEntryThatContains(file_vm_addr);
3139 if (entry && entry->data)
3140 {
3141 Variable *variable = entry->data;
3142 SymbolContextScope *scc = variable->GetSymbolContextScope();
3143 if (scc)
3144 {
3145 scc->CalculateSymbolContext(&sc);
3146 sc.variable = variable;
3147 }
3148 return sc.GetResolvedMask();
3149 }
3150 }
3151 }
3152 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003153 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003154 uint32_t cu_idx = DW_INVALID_INDEX;
Greg Clayton53eb1c22012-04-02 22:59:12 +00003155 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
3156 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003157 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003158 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00003159 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003160 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003161 resolved |= eSymbolContextCompUnit;
3162
Greg Clayton6ab80132012-12-12 17:30:52 +00003163 bool force_check_line_table = false;
Greg Clayton526a4ae2012-05-16 22:09:01 +00003164 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
3165 {
3166 DWARFDebugInfoEntry *function_die = NULL;
3167 DWARFDebugInfoEntry *block_die = NULL;
3168 if (resolve_scope & eSymbolContextBlock)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003169 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003170 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
3171 }
3172 else
3173 {
3174 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL);
3175 }
3176
3177 if (function_die != NULL)
3178 {
3179 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
3180 if (sc.function == NULL)
3181 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
3182 }
3183 else
3184 {
3185 // We might have had a compile unit that had discontiguous
3186 // address ranges where the gaps are symbols that don't have
3187 // any debug info. Discontiguous compile unit address ranges
3188 // should only happen when there aren't other functions from
3189 // other compile units in these gaps. This helps keep the size
3190 // of the aranges down.
Greg Clayton6ab80132012-12-12 17:30:52 +00003191 force_check_line_table = true;
Greg Clayton526a4ae2012-05-16 22:09:01 +00003192 }
3193
3194 if (sc.function != NULL)
3195 {
3196 resolved |= eSymbolContextFunction;
3197
3198 if (resolve_scope & eSymbolContextBlock)
3199 {
3200 Block& block = sc.function->GetBlock (true);
3201
3202 if (block_die != NULL)
3203 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
3204 else
3205 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
3206 if (sc.block)
3207 resolved |= eSymbolContextBlock;
3208 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003209 }
3210 }
Greg Clayton6ab80132012-12-12 17:30:52 +00003211
3212 if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table)
3213 {
3214 LineTable *line_table = sc.comp_unit->GetLineTable();
3215 if (line_table != NULL)
3216 {
Greg Clayton9422dd62013-03-04 21:46:16 +00003217 // And address that makes it into this function should be in terms
3218 // of this debug file if there is no debug map, or it will be an
3219 // address in the .o file which needs to be fixed up to be in terms
3220 // of the debug map executable. Either way, calling FixupAddress()
3221 // will work for us.
3222 Address exe_so_addr (so_addr);
3223 if (FixupAddress(exe_so_addr))
Greg Clayton6ab80132012-12-12 17:30:52 +00003224 {
Greg Clayton9422dd62013-03-04 21:46:16 +00003225 if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry))
Greg Clayton6ab80132012-12-12 17:30:52 +00003226 {
3227 resolved |= eSymbolContextLineEntry;
3228 }
3229 }
Greg Clayton6ab80132012-12-12 17:30:52 +00003230 }
3231 }
3232
3233 if (force_check_line_table && !(resolved & eSymbolContextLineEntry))
3234 {
3235 // We might have had a compile unit that had discontiguous
3236 // address ranges where the gaps are symbols that don't have
3237 // any debug info. Discontiguous compile unit address ranges
3238 // should only happen when there aren't other functions from
3239 // other compile units in these gaps. This helps keep the size
3240 // of the aranges down.
3241 sc.comp_unit = NULL;
3242 resolved &= ~eSymbolContextCompUnit;
3243 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003244 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00003245 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003246 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003247 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.",
3248 cu_offset,
3249 cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003250 }
3251 }
3252 }
3253 }
3254 }
3255 return resolved;
3256}
3257
3258
3259
3260uint32_t
3261SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
3262{
3263 const uint32_t prev_size = sc_list.GetSize();
3264 if (resolve_scope & eSymbolContextCompUnit)
3265 {
3266 DWARFDebugInfo* debug_info = DebugInfo();
3267 if (debug_info)
3268 {
3269 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00003270 DWARFCompileUnit* dwarf_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003271
Greg Clayton53eb1c22012-04-02 22:59:12 +00003272 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003273 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003274 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Sean Callananddd7a2a2013-10-03 22:27:29 +00003275 const bool full_match = (bool)file_spec.GetDirectory();
Greg Clayton1f746072012-08-29 21:13:06 +00003276 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 +00003277 if (check_inlines || file_spec_matches_cu_file_spec)
3278 {
3279 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton53eb1c22012-04-02 22:59:12 +00003280 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00003281 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003282 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003283 uint32_t file_idx = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003284
Greg Clayton526a4ae2012-05-16 22:09:01 +00003285 // If we are looking for inline functions only and we don't
3286 // find it in the support files, we are done.
3287 if (check_inlines)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003288 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003289 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
3290 if (file_idx == UINT32_MAX)
3291 continue;
3292 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003293
Greg Clayton526a4ae2012-05-16 22:09:01 +00003294 if (line != 0)
3295 {
3296 LineTable *line_table = sc.comp_unit->GetLineTable();
3297
3298 if (line_table != NULL && line != 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003299 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003300 // We will have already looked up the file index if
3301 // we are searching for inline entries.
3302 if (!check_inlines)
3303 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003304
Greg Clayton526a4ae2012-05-16 22:09:01 +00003305 if (file_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003306 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003307 uint32_t found_line;
3308 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
3309 found_line = sc.line_entry.line;
3310
3311 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003312 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003313 sc.function = NULL;
3314 sc.block = NULL;
3315 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003316 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003317 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
3318 if (file_vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003319 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00003320 DWARFDebugInfoEntry *function_die = NULL;
3321 DWARFDebugInfoEntry *block_die = NULL;
3322 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003323
Greg Clayton526a4ae2012-05-16 22:09:01 +00003324 if (function_die != NULL)
3325 {
3326 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
3327 if (sc.function == NULL)
3328 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
3329 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003330
Greg Clayton526a4ae2012-05-16 22:09:01 +00003331 if (sc.function != NULL)
3332 {
3333 Block& block = sc.function->GetBlock (true);
3334
3335 if (block_die != NULL)
3336 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
Jason Molenda60db6e42014-10-16 01:40:16 +00003337 else if (function_die != NULL)
Greg Clayton526a4ae2012-05-16 22:09:01 +00003338 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
3339 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003340 }
3341 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003342
Greg Clayton526a4ae2012-05-16 22:09:01 +00003343 sc_list.Append(sc);
3344 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
3345 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003346 }
3347 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00003348 else if (file_spec_matches_cu_file_spec && !check_inlines)
3349 {
3350 // only append the context if we aren't looking for inline call sites
3351 // by file and line and if the file spec matches that of the compile unit
3352 sc_list.Append(sc);
3353 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003354 }
3355 else if (file_spec_matches_cu_file_spec && !check_inlines)
3356 {
3357 // only append the context if we aren't looking for inline call sites
3358 // by file and line and if the file spec matches that of the compile unit
3359 sc_list.Append(sc);
3360 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003361
Greg Clayton526a4ae2012-05-16 22:09:01 +00003362 if (!check_inlines)
3363 break;
3364 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003365 }
3366 }
3367 }
3368 }
3369 return sc_list.GetSize() - prev_size;
3370}
3371
3372void
3373SymbolFileDWARF::Index ()
3374{
3375 if (m_indexed)
3376 return;
3377 m_indexed = true;
3378 Timer scoped_timer (__PRETTY_FUNCTION__,
3379 "SymbolFileDWARF::Index (%s)",
Jim Ingham4af59612014-12-19 19:20:44 +00003380 GetObjectFile()->GetFileSpec().GetFilename().AsCString("<Unknown>"));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003381
3382 DWARFDebugInfo* debug_info = DebugInfo();
3383 if (debug_info)
3384 {
3385 uint32_t cu_idx = 0;
3386 const uint32_t num_compile_units = GetNumCompileUnits();
3387 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
3388 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003389 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003390
Greg Clayton53eb1c22012-04-02 22:59:12 +00003391 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003392
Greg Clayton53eb1c22012-04-02 22:59:12 +00003393 dwarf_cu->Index (cu_idx,
3394 m_function_basename_index,
3395 m_function_fullname_index,
3396 m_function_method_index,
3397 m_function_selector_index,
3398 m_objc_class_selectors_index,
3399 m_global_index,
3400 m_type_index,
3401 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003402
3403 // Keep memory down by clearing DIEs if this generate function
3404 // caused them to be parsed
3405 if (clear_dies)
Greg Clayton53eb1c22012-04-02 22:59:12 +00003406 dwarf_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003407 }
3408
Greg Claytond4a2b372011-09-12 23:21:58 +00003409 m_function_basename_index.Finalize();
3410 m_function_fullname_index.Finalize();
3411 m_function_method_index.Finalize();
3412 m_function_selector_index.Finalize();
3413 m_objc_class_selectors_index.Finalize();
3414 m_global_index.Finalize();
3415 m_type_index.Finalize();
3416 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003417
Greg Clayton24739922010-10-13 03:15:28 +00003418#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00003419 StreamFile s(stdout, false);
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00003420 s.Printf ("DWARF index for '%s':",
3421 GetObjectFile()->GetFileSpec().GetPath().c_str());
Greg Claytonba2d22d2010-11-13 22:57:37 +00003422 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
3423 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
3424 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
3425 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
3426 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
3427 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00003428 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Bruce Mitchenere171da52015-07-22 00:16:02 +00003429 s.Printf("\nNamespaces:\n") m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00003430#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003431 }
3432}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003433
3434bool
3435SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
3436{
3437 if (namespace_decl == NULL)
3438 {
3439 // Invalid namespace decl which means we aren't matching only things
3440 // in this symbol file, so return true to indicate it matches this
3441 // symbol file.
3442 return true;
3443 }
3444
3445 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
3446
3447 if (namespace_ast == NULL)
3448 return true; // No AST in the "namespace_decl", return true since it
3449 // could then match any symbol file, including this one
3450
3451 if (namespace_ast == GetClangASTContext().getASTContext())
3452 return true; // The ASTs match, return true
3453
3454 // The namespace AST was valid, and it does not match...
Greg Clayton5160ce52013-03-27 23:08:40 +00003455 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Sean Callananc41e68b2011-10-13 21:08:11 +00003456
3457 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003458 GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00003459
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003460 return false;
3461}
3462
Greg Clayton2506a7a2011-10-12 23:34:26 +00003463bool
3464SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
3465 DWARFCompileUnit* cu,
3466 const DWARFDebugInfoEntry* die)
3467{
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +00003468 // No namespace specified, so the answer is
Greg Clayton2506a7a2011-10-12 23:34:26 +00003469 if (namespace_decl == NULL)
3470 return true;
Sean Callananebe60672011-10-13 21:50:33 +00003471
Greg Clayton5160ce52013-03-27 23:08:40 +00003472 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00003473
Greg Clayton437a1352012-04-09 22:43:43 +00003474 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
3475 clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00003476 if (decl_ctx_die)
Greg Clayton437a1352012-04-09 22:43:43 +00003477 {
Greg Clayton2506a7a2011-10-12 23:34:26 +00003478 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
Greg Clayton437a1352012-04-09 22:43:43 +00003479
Greg Clayton2506a7a2011-10-12 23:34:26 +00003480 if (clang_namespace_decl)
3481 {
3482 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00003483 {
3484 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003485 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00003486 return false;
Sean Callananebe60672011-10-13 21:50:33 +00003487 }
3488
Greg Clayton437a1352012-04-09 22:43:43 +00003489 if (clang_namespace_decl == die_clang_decl_ctx)
3490 return true;
3491 else
Greg Clayton2506a7a2011-10-12 23:34:26 +00003492 return false;
Greg Clayton2506a7a2011-10-12 23:34:26 +00003493 }
3494 else
3495 {
3496 // We have a namespace_decl that was not NULL but it contained
3497 // a NULL "clang::NamespaceDecl", so this means the global namespace
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00003498 // So as long the contained decl context DIE isn't a namespace
Greg Clayton2506a7a2011-10-12 23:34:26 +00003499 // we should be ok.
3500 if (decl_ctx_die->Tag() != DW_TAG_namespace)
3501 return true;
3502 }
3503 }
Sean Callananebe60672011-10-13 21:50:33 +00003504
3505 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003506 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00003507
Greg Clayton2506a7a2011-10-12 23:34:26 +00003508 return false;
3509}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003510uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00003511SymbolFileDWARF::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 +00003512{
Greg Clayton5160ce52013-03-27 23:08:40 +00003513 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003514
3515 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003516 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003517 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
3518 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003519 static_cast<const void*>(namespace_decl),
3520 append, max_matches);
3521
Sean Callanan213fdb82011-10-13 01:49:10 +00003522 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00003523 return 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003524
Greg Claytonc685f8e2010-09-15 04:15:46 +00003525 DWARFDebugInfo* info = DebugInfo();
3526 if (info == NULL)
3527 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003528
3529 // If we aren't appending the results to this list, then clear the list
3530 if (!append)
3531 variables.Clear();
3532
3533 // Remember how many variables are in the list before we search in case
3534 // we are appending the results to a variable list.
3535 const uint32_t original_size = variables.GetSize();
3536
Greg Claytond4a2b372011-09-12 23:21:58 +00003537 DIEArray die_offsets;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003538
Greg Clayton97fbc342011-10-20 22:30:33 +00003539 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003540 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003541 if (m_apple_names_ap.get())
3542 {
3543 const char *name_cstr = name.GetCString();
Jim Inghamfa39bb42014-10-25 00:33:55 +00003544 llvm::StringRef basename;
3545 llvm::StringRef context;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003546
Jim Inghamfa39bb42014-10-25 00:33:55 +00003547 if (!CPPLanguageRuntime::ExtractContextAndIdentifier(name_cstr, context, basename))
3548 basename = name_cstr;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003549
Jim Inghamfa39bb42014-10-25 00:33:55 +00003550 m_apple_names_ap->FindByName (basename.data(), die_offsets);
Greg Clayton97fbc342011-10-20 22:30:33 +00003551 }
Greg Clayton7f995132011-10-04 22:41:51 +00003552 }
3553 else
3554 {
3555 // Index the DWARF if we haven't already
3556 if (!m_indexed)
3557 Index ();
3558
3559 m_global_index.Find (name, die_offsets);
3560 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003561
Greg Clayton437a1352012-04-09 22:43:43 +00003562 const size_t num_die_matches = die_offsets.size();
3563 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003564 {
Greg Clayton7f995132011-10-04 22:41:51 +00003565 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003566 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00003567 assert (sc.module_sp);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003568
Greg Claytond4a2b372011-09-12 23:21:58 +00003569 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00003570 DWARFCompileUnit* dwarf_cu = NULL;
3571 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton437a1352012-04-09 22:43:43 +00003572 bool done = false;
3573 for (size_t i=0; i<num_die_matches && !done; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00003574 {
3575 const dw_offset_t die_offset = die_offsets[i];
3576 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003577
Greg Clayton95d87902011-11-11 03:16:25 +00003578 if (die)
3579 {
Greg Clayton437a1352012-04-09 22:43:43 +00003580 switch (die->Tag())
3581 {
3582 default:
3583 case DW_TAG_subprogram:
3584 case DW_TAG_inlined_subroutine:
3585 case DW_TAG_try_block:
3586 case DW_TAG_catch_block:
3587 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003588
Greg Clayton437a1352012-04-09 22:43:43 +00003589 case DW_TAG_variable:
3590 {
3591 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003592
Greg Clayton437a1352012-04-09 22:43:43 +00003593 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3594 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003595
Greg Clayton437a1352012-04-09 22:43:43 +00003596 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003597
Greg Clayton437a1352012-04-09 22:43:43 +00003598 if (variables.GetSize() - original_size >= max_matches)
3599 done = true;
3600 }
3601 break;
3602 }
Greg Clayton95d87902011-11-11 03:16:25 +00003603 }
3604 else
3605 {
3606 if (m_using_apple_tables)
3607 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003608 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
3609 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003610 }
3611 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003612 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003613 }
3614
3615 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003616 const uint32_t num_matches = variables.GetSize() - original_size;
3617 if (log && num_matches > 0)
3618 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003619 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003620 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003621 name.GetCString(),
3622 static_cast<const void*>(namespace_decl),
3623 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00003624 num_matches);
3625 }
3626 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003627}
3628
3629uint32_t
3630SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
3631{
Greg Clayton5160ce52013-03-27 23:08:40 +00003632 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003633
Greg Clayton21f2a492011-10-06 00:09:08 +00003634 if (log)
3635 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003636 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003637 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003638 regex.GetText(), append,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003639 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003640 }
3641
Greg Claytonc685f8e2010-09-15 04:15:46 +00003642 DWARFDebugInfo* info = DebugInfo();
3643 if (info == NULL)
3644 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003645
3646 // If we aren't appending the results to this list, then clear the list
3647 if (!append)
3648 variables.Clear();
3649
3650 // Remember how many variables are in the list before we search in case
3651 // we are appending the results to a variable list.
3652 const uint32_t original_size = variables.GetSize();
3653
Greg Clayton7f995132011-10-04 22:41:51 +00003654 DIEArray die_offsets;
3655
Greg Clayton97fbc342011-10-20 22:30:33 +00003656 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003657 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003658 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00003659 {
3660 DWARFMappedHash::DIEInfoArray hash_data_array;
3661 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
3662 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
3663 }
Greg Clayton7f995132011-10-04 22:41:51 +00003664 }
3665 else
3666 {
3667 // Index the DWARF if we haven't already
3668 if (!m_indexed)
3669 Index ();
3670
3671 m_global_index.Find (regex, die_offsets);
3672 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003673
Greg Claytonc685f8e2010-09-15 04:15:46 +00003674 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003675 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003676 assert (sc.module_sp);
3677
Greg Claytond4a2b372011-09-12 23:21:58 +00003678 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00003679 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003680 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003681 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003682 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003683 DWARFDebugInfo* debug_info = DebugInfo();
3684 for (size_t i=0; i<num_matches; ++i)
3685 {
3686 const dw_offset_t die_offset = die_offsets[i];
3687 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00003688
3689 if (die)
3690 {
3691 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003692
Greg Clayton95d87902011-11-11 03:16:25 +00003693 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003694
Greg Clayton95d87902011-11-11 03:16:25 +00003695 if (variables.GetSize() - original_size >= max_matches)
3696 break;
3697 }
3698 else
3699 {
3700 if (m_using_apple_tables)
3701 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003702 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
3703 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00003704 }
3705 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003706 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003707 }
3708
3709 // Return the number of variable that were appended to the list
3710 return variables.GetSize() - original_size;
3711}
3712
Greg Claytonaa044962011-10-13 00:59:38 +00003713
Jim Ingham4cda6e02011-10-07 22:23:45 +00003714bool
3715SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
3716 DWARFCompileUnit *&dwarf_cu,
Pavel Labatha73d6572015-03-13 10:22:00 +00003717 bool include_inlines,
Jim Ingham4cda6e02011-10-07 22:23:45 +00003718 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00003719{
Greg Claytonaa044962011-10-13 00:59:38 +00003720 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Pavel Labatha73d6572015-03-13 10:22:00 +00003721 return ResolveFunction (dwarf_cu, die, include_inlines, sc_list);
Greg Claytonaa044962011-10-13 00:59:38 +00003722}
3723
3724
3725bool
3726SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
3727 const DWARFDebugInfoEntry *die,
Pavel Labatha73d6572015-03-13 10:22:00 +00003728 bool include_inlines,
Greg Claytonaa044962011-10-13 00:59:38 +00003729 SymbolContextList& sc_list)
3730{
Greg Clayton9e315582011-09-02 04:03:59 +00003731 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00003732
3733 if (die == NULL)
3734 return false;
3735
Jim Ingham4cda6e02011-10-07 22:23:45 +00003736 // If we were passed a die that is not a function, just return false...
Pavel Labatha73d6572015-03-13 10:22:00 +00003737 if (! (die->Tag() == DW_TAG_subprogram || (include_inlines && die->Tag() == DW_TAG_inlined_subroutine)))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003738 return false;
3739
3740 const DWARFDebugInfoEntry* inlined_die = NULL;
3741 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00003742 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003743 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00003744
Jim Ingham4cda6e02011-10-07 22:23:45 +00003745 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003746 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003747 if (die->Tag() == DW_TAG_subprogram)
3748 break;
Greg Clayton9e315582011-09-02 04:03:59 +00003749 }
3750 }
Jason Molenda60db6e42014-10-16 01:40:16 +00003751 assert (die && die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00003752 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003753 {
3754 Address addr;
3755 // Parse all blocks if needed
3756 if (inlined_die)
3757 {
Greg Claytonf7bb1fb2015-01-15 03:13:44 +00003758 Block &function_block = sc.function->GetBlock (true);
3759 sc.block = function_block.FindBlockByID (MakeUserID(inlined_die->GetOffset()));
3760 if (sc.block == NULL)
3761 sc.block = function_block.FindBlockByID (inlined_die->GetOffset());
3762 if (sc.block == NULL || sc.block->GetStartAddress (addr) == false)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003763 addr.Clear();
3764 }
3765 else
3766 {
3767 sc.block = NULL;
3768 addr = sc.function->GetAddressRange().GetBaseAddress();
3769 }
3770
3771 if (addr.IsValid())
3772 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003773 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00003774 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003775 }
3776 }
3777
Greg Claytonaa044962011-10-13 00:59:38 +00003778 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00003779}
3780
Greg Clayton7f995132011-10-04 22:41:51 +00003781void
3782SymbolFileDWARF::FindFunctions (const ConstString &name,
3783 const NameToDIE &name_to_die,
Pavel Labatha73d6572015-03-13 10:22:00 +00003784 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003785 SymbolContextList& sc_list)
3786{
Greg Claytond4a2b372011-09-12 23:21:58 +00003787 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003788 if (name_to_die.Find (name, die_offsets))
3789 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003790 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003791 }
3792}
3793
3794
3795void
3796SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3797 const NameToDIE &name_to_die,
Pavel Labatha73d6572015-03-13 10:22:00 +00003798 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003799 SymbolContextList& sc_list)
3800{
3801 DIEArray die_offsets;
3802 if (name_to_die.Find (regex, die_offsets))
3803 {
Pavel Labatha73d6572015-03-13 10:22:00 +00003804 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003805 }
3806}
3807
3808
3809void
3810SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3811 const DWARFMappedHash::MemoryTable &memory_table,
Pavel Labatha73d6572015-03-13 10:22:00 +00003812 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003813 SymbolContextList& sc_list)
3814{
3815 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00003816 DWARFMappedHash::DIEInfoArray hash_data_array;
3817 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00003818 {
Greg Claytond1767f02011-12-08 02:13:16 +00003819 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Pavel Labatha73d6572015-03-13 10:22:00 +00003820 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003821 }
3822}
3823
3824void
3825SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
Pavel Labatha73d6572015-03-13 10:22:00 +00003826 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00003827 SymbolContextList& sc_list)
3828{
3829 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003830 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00003831 {
Greg Clayton7f995132011-10-04 22:41:51 +00003832 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003833 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00003834 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003835 const dw_offset_t die_offset = die_offsets[i];
Pavel Labatha73d6572015-03-13 10:22:00 +00003836 ResolveFunction (die_offset, dwarf_cu, include_inlines, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003837 }
3838 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00003839}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003840
Jim Ingham4cda6e02011-10-07 22:23:45 +00003841bool
3842SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
3843 const DWARFCompileUnit *dwarf_cu,
3844 uint32_t name_type_mask,
3845 const char *partial_name,
3846 const char *base_name_start,
3847 const char *base_name_end)
3848{
Greg Claytonfbea0f62012-11-15 18:05:43 +00003849 // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes:
3850 if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003851 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003852 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
3853 if (!containing_decl_ctx)
3854 return false;
3855
3856 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
3857
Greg Claytonfbea0f62012-11-15 18:05:43 +00003858 if (name_type_mask == eFunctionNameTypeMethod)
3859 {
3860 if (is_cxx_method == false)
3861 return false;
3862 }
3863
3864 if (name_type_mask == eFunctionNameTypeBase)
3865 {
3866 if (is_cxx_method == true)
3867 return false;
3868 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003869 }
3870
3871 // Now we need to check whether the name we got back for this type matches the extra specifications
3872 // that were in the name we're looking up:
3873 if (base_name_start != partial_name || *base_name_end != '\0')
3874 {
3875 // First see if the stuff to the left matches the full name. To do that let's see if
3876 // we can pull out the mips linkage name attribute:
3877
3878 Mangled best_name;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003879 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonfbea0f62012-11-15 18:05:43 +00003880 DWARFFormValue form_value;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003881 die->GetAttributes(this, dwarf_cu, NULL, attributes);
3882 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
Greg Clayton71415542012-12-08 00:24:40 +00003883 if (idx == UINT32_MAX)
3884 idx = attributes.FindAttributeIndex(DW_AT_linkage_name);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003885 if (idx != UINT32_MAX)
3886 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003887 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
3888 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003889 const char *mangled_name = form_value.AsCString(&get_debug_str_data());
3890 if (mangled_name)
3891 best_name.SetValue (ConstString(mangled_name), true);
3892 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003893 }
Greg Claytonfbea0f62012-11-15 18:05:43 +00003894
3895 if (!best_name)
3896 {
3897 idx = attributes.FindAttributeIndex(DW_AT_name);
3898 if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value))
3899 {
3900 const char *name = form_value.AsCString(&get_debug_str_data());
3901 best_name.SetValue (ConstString(name), false);
3902 }
3903 }
3904
Greg Claytonddaf6a72015-07-08 22:32:23 +00003905 const LanguageType cu_language = const_cast<DWARFCompileUnit *>(dwarf_cu)->GetLanguageType();
3906 if (best_name.GetDemangledName(cu_language))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003907 {
Greg Claytonddaf6a72015-07-08 22:32:23 +00003908 const char *demangled = best_name.GetDemangledName(cu_language).GetCString();
Jim Ingham4cda6e02011-10-07 22:23:45 +00003909 if (demangled)
3910 {
3911 std::string name_no_parens(partial_name, base_name_end - partial_name);
Jim Ingham85c13d72012-03-02 02:24:42 +00003912 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str());
3913 if (partial_in_demangled == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003914 return false;
Jim Ingham85c13d72012-03-02 02:24:42 +00003915 else
3916 {
3917 // Sort out the case where our name is something like "Process::Destroy" and the match is
3918 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on
3919 // namespace boundaries...
3920
3921 if (partial_name[0] == ':' && partial_name[1] == ':')
3922 {
3923 // The partial name was already on a namespace boundary so all matches are good.
3924 return true;
3925 }
3926 else if (partial_in_demangled == demangled)
3927 {
3928 // They both start the same, so this is an good match.
3929 return true;
3930 }
3931 else
3932 {
3933 if (partial_in_demangled - demangled == 1)
3934 {
3935 // Only one character difference, can't be a namespace boundary...
3936 return false;
3937 }
3938 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':')
3939 {
3940 // We are on a namespace boundary, so this is also good.
3941 return true;
3942 }
3943 else
3944 return false;
3945 }
3946 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003947 }
3948 }
3949 }
3950
3951 return true;
3952}
Greg Claytonc685f8e2010-09-15 04:15:46 +00003953
Greg Clayton0c5cd902010-06-28 21:30:43 +00003954uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00003955SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00003956 const lldb_private::ClangNamespaceDecl *namespace_decl,
Sean Callanan9df05fb2012-02-10 22:52:19 +00003957 uint32_t name_type_mask,
3958 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00003959 bool append,
3960 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00003961{
3962 Timer scoped_timer (__PRETTY_FUNCTION__,
3963 "SymbolFileDWARF::FindFunctions (name = '%s')",
3964 name.AsCString());
3965
Greg Clayton43fe2172013-04-03 02:00:15 +00003966 // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup()
3967 assert ((name_type_mask & eFunctionNameTypeAuto) == 0);
3968
Greg Clayton5160ce52013-03-27 23:08:40 +00003969 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003970
3971 if (log)
3972 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003973 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003974 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
3975 name.GetCString(),
3976 name_type_mask,
3977 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003978 }
3979
Greg Clayton0c5cd902010-06-28 21:30:43 +00003980 // If we aren't appending the results to this list, then clear the list
3981 if (!append)
3982 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003983
3984 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00003985 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003986
3987 // If name is empty then we won't find anything.
3988 if (name.IsEmpty())
3989 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00003990
3991 // Remember how many sc_list are in the list before we search in case
3992 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00003993
Jim Ingham4cda6e02011-10-07 22:23:45 +00003994 const char *name_cstr = name.GetCString();
Greg Clayton43fe2172013-04-03 02:00:15 +00003995
3996 const uint32_t original_size = sc_list.GetSize();
3997
Jim Ingham4cda6e02011-10-07 22:23:45 +00003998 DWARFDebugInfo* info = DebugInfo();
3999 if (info == NULL)
4000 return 0;
4001
Greg Claytonaa044962011-10-13 00:59:38 +00004002 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton43fe2172013-04-03 02:00:15 +00004003 std::set<const DWARFDebugInfoEntry *> resolved_dies;
Greg Clayton97fbc342011-10-20 22:30:33 +00004004 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00004005 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004006 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00004007 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004008
4009 DIEArray die_offsets;
4010
4011 uint32_t num_matches = 0;
4012
Greg Clayton43fe2172013-04-03 02:00:15 +00004013 if (name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00004014 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004015 // If they asked for the full name, match what they typed. At some point we may
4016 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
4017 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00004018 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00004019 for (uint32_t i = 0; i < num_matches; i++)
4020 {
Greg Clayton95d87902011-11-11 03:16:25 +00004021 const dw_offset_t die_offset = die_offsets[i];
4022 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00004023 if (die)
4024 {
Sean Callanan213fdb82011-10-13 01:49:10 +00004025 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
4026 continue;
4027
Greg Clayton43fe2172013-04-03 02:00:15 +00004028 if (resolved_dies.find(die) == resolved_dies.end())
4029 {
Pavel Labatha73d6572015-03-13 10:22:00 +00004030 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00004031 resolved_dies.insert(die);
4032 }
Greg Claytonaa044962011-10-13 00:59:38 +00004033 }
Greg Clayton95d87902011-11-11 03:16:25 +00004034 else
4035 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004036 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
4037 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00004038 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00004039 }
Greg Clayton97fbc342011-10-20 22:30:33 +00004040 }
Greg Clayton43fe2172013-04-03 02:00:15 +00004041
4042 if (name_type_mask & eFunctionNameTypeSelector)
4043 {
4044 if (namespace_decl && *namespace_decl)
4045 return 0; // no selectors in namespaces
Greg Clayton97fbc342011-10-20 22:30:33 +00004046
Greg Clayton43fe2172013-04-03 02:00:15 +00004047 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
4048 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
4049 // and if it is an ObjC method name, we're good.
Greg Clayton97fbc342011-10-20 22:30:33 +00004050
Greg Clayton43fe2172013-04-03 02:00:15 +00004051 for (uint32_t i = 0; i < num_matches; i++)
Greg Clayton97fbc342011-10-20 22:30:33 +00004052 {
Greg Clayton43fe2172013-04-03 02:00:15 +00004053 const dw_offset_t die_offset = die_offsets[i];
4054 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
4055 if (die)
Greg Clayton97fbc342011-10-20 22:30:33 +00004056 {
Greg Clayton43fe2172013-04-03 02:00:15 +00004057 const char *die_name = die->GetName(this, dwarf_cu);
4058 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
Greg Clayton97fbc342011-10-20 22:30:33 +00004059 {
Greg Clayton43fe2172013-04-03 02:00:15 +00004060 if (resolved_dies.find(die) == resolved_dies.end())
4061 {
Pavel Labatha73d6572015-03-13 10:22:00 +00004062 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00004063 resolved_dies.insert(die);
4064 }
Greg Clayton97fbc342011-10-20 22:30:33 +00004065 }
4066 }
Greg Clayton43fe2172013-04-03 02:00:15 +00004067 else
4068 {
4069 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
4070 die_offset, name_cstr);
4071 }
Greg Clayton97fbc342011-10-20 22:30:33 +00004072 }
Greg Clayton43fe2172013-04-03 02:00:15 +00004073 die_offsets.clear();
4074 }
4075
4076 if (((name_type_mask & eFunctionNameTypeMethod) && !namespace_decl) || name_type_mask & eFunctionNameTypeBase)
4077 {
4078 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
4079 // extract the base name, look that up, and if there is any other information in the name we were
4080 // passed in we have to post-filter based on that.
4081
4082 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
4083 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
4084
4085 for (uint32_t i = 0; i < num_matches; i++)
4086 {
4087 const dw_offset_t die_offset = die_offsets[i];
4088 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
4089 if (die)
4090 {
Greg Clayton43fe2172013-04-03 02:00:15 +00004091 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
4092 continue;
4093
4094 // If we get to here, the die is good, and we should add it:
4095 if (resolved_dies.find(die) == resolved_dies.end())
Pavel Labatha73d6572015-03-13 10:22:00 +00004096 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00004097 {
4098 bool keep_die = true;
4099 if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod))
4100 {
4101 // We are looking for either basenames or methods, so we need to
4102 // trim out the ones we won't want by looking at the type
4103 SymbolContext sc;
4104 if (sc_list.GetLastContext(sc))
4105 {
4106 if (sc.block)
4107 {
4108 // We have an inlined function
4109 }
4110 else if (sc.function)
4111 {
4112 Type *type = sc.function->GetType();
4113
Sean Callananc370a8a2013-09-18 22:59:55 +00004114 if (type)
Greg Clayton43fe2172013-04-03 02:00:15 +00004115 {
Sean Callananc370a8a2013-09-18 22:59:55 +00004116 clang::DeclContext* decl_ctx = GetClangDeclContextContainingTypeUID (type->GetID());
4117 if (decl_ctx->isRecord())
Greg Clayton43fe2172013-04-03 02:00:15 +00004118 {
Sean Callananc370a8a2013-09-18 22:59:55 +00004119 if (name_type_mask & eFunctionNameTypeBase)
4120 {
4121 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
4122 keep_die = false;
4123 }
4124 }
4125 else
4126 {
4127 if (name_type_mask & eFunctionNameTypeMethod)
4128 {
4129 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
4130 keep_die = false;
4131 }
Greg Clayton43fe2172013-04-03 02:00:15 +00004132 }
4133 }
4134 else
4135 {
Sean Callananc370a8a2013-09-18 22:59:55 +00004136 GetObjectFile()->GetModule()->ReportWarning ("function at die offset 0x%8.8x had no function type",
4137 die_offset);
Greg Clayton43fe2172013-04-03 02:00:15 +00004138 }
4139 }
4140 }
4141 }
4142 if (keep_die)
4143 resolved_dies.insert(die);
4144 }
4145 }
4146 else
4147 {
4148 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
4149 die_offset, name_cstr);
4150 }
4151 }
4152 die_offsets.clear();
Jim Ingham4cda6e02011-10-07 22:23:45 +00004153 }
4154 }
Greg Clayton7f995132011-10-04 22:41:51 +00004155 }
4156 else
4157 {
4158
4159 // Index the DWARF if we haven't already
4160 if (!m_indexed)
4161 Index ();
4162
Greg Clayton7f995132011-10-04 22:41:51 +00004163 if (name_type_mask & eFunctionNameTypeFull)
Matt Kopecd6089962013-05-10 17:53:48 +00004164 {
Pavel Labatha73d6572015-03-13 10:22:00 +00004165 FindFunctions (name, m_function_fullname_index, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00004166
Ed Mastefc7baa02013-09-09 18:00:45 +00004167 // FIXME Temporary workaround for global/anonymous namespace
Robert Flack5cbd3bf2015-05-13 18:20:02 +00004168 // functions debugging FreeBSD and Linux binaries.
Matt Kopecd6089962013-05-10 17:53:48 +00004169 // If we didn't find any functions in the global namespace try
4170 // looking in the basename index but ignore any returned
Robert Flackeb83fab2015-05-15 18:59:59 +00004171 // functions that have a namespace but keep functions which
4172 // have an anonymous namespace
4173 // TODO: The arch in the object file isn't correct for MSVC
4174 // binaries on windows, we should find a way to make it
4175 // correct and handle those symbols as well.
Matt Kopecd6089962013-05-10 17:53:48 +00004176 if (sc_list.GetSize() == 0)
4177 {
Robert Flackeb83fab2015-05-15 18:59:59 +00004178 ArchSpec arch;
4179 if (!namespace_decl &&
4180 GetObjectFile()->GetArchitecture(arch) &&
4181 (arch.GetTriple().isOSFreeBSD() || arch.GetTriple().isOSLinux() ||
4182 arch.GetMachine() == llvm::Triple::hexagon))
Matt Kopecd6089962013-05-10 17:53:48 +00004183 {
Robert Flackeb83fab2015-05-15 18:59:59 +00004184 SymbolContextList temp_sc_list;
4185 FindFunctions (name, m_function_basename_index, include_inlines, temp_sc_list);
Matt Kopecd6089962013-05-10 17:53:48 +00004186 SymbolContext sc;
4187 for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++)
4188 {
4189 if (temp_sc_list.GetContextAtIndex(i, sc))
4190 {
Matt Kopeca189d492013-05-10 22:55:24 +00004191 ConstString mangled_name = sc.GetFunctionName(Mangled::ePreferMangled);
4192 ConstString demangled_name = sc.GetFunctionName(Mangled::ePreferDemangled);
Robert Flackeb83fab2015-05-15 18:59:59 +00004193 // Mangled names on Linux and FreeBSD are of the form:
4194 // _ZN18function_namespace13function_nameEv.
Matt Kopec04e5d582013-05-14 19:00:41 +00004195 if (strncmp(mangled_name.GetCString(), "_ZN", 3) ||
4196 !strncmp(demangled_name.GetCString(), "(anonymous namespace)", 21))
Matt Kopecd6089962013-05-10 17:53:48 +00004197 {
4198 sc_list.Append(sc);
4199 }
4200 }
4201 }
4202 }
4203 }
Matt Kopecd6089962013-05-10 17:53:48 +00004204 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00004205 DIEArray die_offsets;
4206 DWARFCompileUnit *dwarf_cu = NULL;
4207
Greg Clayton43fe2172013-04-03 02:00:15 +00004208 if (name_type_mask & eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00004209 {
Greg Clayton43fe2172013-04-03 02:00:15 +00004210 uint32_t num_base = m_function_basename_index.Find(name, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00004211 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00004212 {
Greg Claytonaa044962011-10-13 00:59:38 +00004213 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
4214 if (die)
4215 {
Sean Callanan213fdb82011-10-13 01:49:10 +00004216 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
4217 continue;
4218
Greg Claytonaa044962011-10-13 00:59:38 +00004219 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00004220 if (resolved_dies.find(die) == resolved_dies.end())
4221 {
Pavel Labatha73d6572015-03-13 10:22:00 +00004222 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00004223 resolved_dies.insert(die);
4224 }
Greg Claytonaa044962011-10-13 00:59:38 +00004225 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00004226 }
4227 die_offsets.clear();
4228 }
4229
Greg Clayton43fe2172013-04-03 02:00:15 +00004230 if (name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00004231 {
Sean Callanan213fdb82011-10-13 01:49:10 +00004232 if (namespace_decl && *namespace_decl)
4233 return 0; // no methods in namespaces
4234
Greg Clayton43fe2172013-04-03 02:00:15 +00004235 uint32_t num_base = m_function_method_index.Find(name, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00004236 {
Greg Claytonaa044962011-10-13 00:59:38 +00004237 for (uint32_t i = 0; i < num_base; i++)
4238 {
4239 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
4240 if (die)
4241 {
Greg Claytonaa044962011-10-13 00:59:38 +00004242 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00004243 if (resolved_dies.find(die) == resolved_dies.end())
4244 {
Pavel Labatha73d6572015-03-13 10:22:00 +00004245 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00004246 resolved_dies.insert(die);
4247 }
Greg Claytonaa044962011-10-13 00:59:38 +00004248 }
4249 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00004250 }
4251 die_offsets.clear();
4252 }
Greg Clayton7f995132011-10-04 22:41:51 +00004253
Greg Clayton43fe2172013-04-03 02:00:15 +00004254 if ((name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00004255 {
Pavel Labatha73d6572015-03-13 10:22:00 +00004256 FindFunctions (name, m_function_selector_index, include_inlines, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00004257 }
4258
Greg Clayton4d01ace2011-09-29 16:58:15 +00004259 }
4260
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004261 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00004262 const uint32_t num_matches = sc_list.GetSize() - original_size;
4263
4264 if (log && num_matches > 0)
4265 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004266 GetObjectFile()->GetModule()->LogMessage (log,
Pavel Labatha73d6572015-03-13 10:22:00 +00004267 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, include_inlines=%d, append=%u, sc_list) => %u",
Greg Clayton437a1352012-04-09 22:43:43 +00004268 name.GetCString(),
4269 name_type_mask,
Pavel Labatha73d6572015-03-13 10:22:00 +00004270 include_inlines,
Greg Clayton437a1352012-04-09 22:43:43 +00004271 append,
4272 num_matches);
4273 }
4274 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004275}
4276
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004277uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00004278SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004279{
4280 Timer scoped_timer (__PRETTY_FUNCTION__,
4281 "SymbolFileDWARF::FindFunctions (regex = '%s')",
4282 regex.GetText());
4283
Greg Clayton5160ce52013-03-27 23:08:40 +00004284 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00004285
4286 if (log)
4287 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004288 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00004289 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
4290 regex.GetText(),
4291 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00004292 }
4293
4294
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004295 // If we aren't appending the results to this list, then clear the list
4296 if (!append)
4297 sc_list.Clear();
4298
4299 // Remember how many sc_list are in the list before we search in case
4300 // we are appending the results to a variable list.
4301 uint32_t original_size = sc_list.GetSize();
4302
Greg Clayton97fbc342011-10-20 22:30:33 +00004303 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004304 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004305 if (m_apple_names_ap.get())
Pavel Labatha73d6572015-03-13 10:22:00 +00004306 FindFunctions (regex, *m_apple_names_ap, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00004307 }
4308 else
4309 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00004310 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00004311 if (!m_indexed)
4312 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004313
Pavel Labatha73d6572015-03-13 10:22:00 +00004314 FindFunctions (regex, m_function_basename_index, include_inlines, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004315
Pavel Labatha73d6572015-03-13 10:22:00 +00004316 FindFunctions (regex, m_function_fullname_index, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00004317 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004318
4319 // Return the number of variable that were appended to the list
4320 return sc_list.GetSize() - original_size;
4321}
Jim Ingham318c9f22011-08-26 19:44:13 +00004322
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004323uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00004324SymbolFileDWARF::FindTypes (const SymbolContext& sc,
4325 const ConstString &name,
4326 const lldb_private::ClangNamespaceDecl *namespace_decl,
4327 bool append,
4328 uint32_t max_matches,
4329 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004330{
Greg Claytonc685f8e2010-09-15 04:15:46 +00004331 DWARFDebugInfo* info = DebugInfo();
4332 if (info == NULL)
4333 return 0;
4334
Greg Clayton5160ce52013-03-27 23:08:40 +00004335 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004336
Greg Clayton21f2a492011-10-06 00:09:08 +00004337 if (log)
4338 {
Greg Clayton437a1352012-04-09 22:43:43 +00004339 if (namespace_decl)
Greg Clayton5160ce52013-03-27 23:08:40 +00004340 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004341 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)",
4342 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004343 static_cast<void*>(namespace_decl->GetNamespaceDecl()),
Greg Clayton437a1352012-04-09 22:43:43 +00004344 namespace_decl->GetQualifiedName().c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004345 append, max_matches);
Greg Clayton437a1352012-04-09 22:43:43 +00004346 else
Greg Clayton5160ce52013-03-27 23:08:40 +00004347 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004348 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004349 name.GetCString(), append,
Greg Clayton437a1352012-04-09 22:43:43 +00004350 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00004351 }
4352
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004353 // If we aren't appending the results to this list, then clear the list
4354 if (!append)
4355 types.Clear();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004356
Sean Callanan213fdb82011-10-13 01:49:10 +00004357 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00004358 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004359
Greg Claytond4a2b372011-09-12 23:21:58 +00004360 DIEArray die_offsets;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004361
Greg Clayton97fbc342011-10-20 22:30:33 +00004362 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004363 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004364 if (m_apple_types_ap.get())
4365 {
4366 const char *name_cstr = name.GetCString();
4367 m_apple_types_ap->FindByName (name_cstr, die_offsets);
4368 }
Greg Clayton7f995132011-10-04 22:41:51 +00004369 }
4370 else
4371 {
4372 if (!m_indexed)
4373 Index ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004374
Greg Clayton7f995132011-10-04 22:41:51 +00004375 m_type_index.Find (name, die_offsets);
4376 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004377
Greg Clayton437a1352012-04-09 22:43:43 +00004378 const size_t num_die_matches = die_offsets.size();
Greg Clayton7f995132011-10-04 22:41:51 +00004379
Greg Clayton437a1352012-04-09 22:43:43 +00004380 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004381 {
Greg Clayton7f995132011-10-04 22:41:51 +00004382 const uint32_t initial_types_size = types.GetSize();
4383 DWARFCompileUnit* dwarf_cu = NULL;
4384 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00004385 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00004386 for (size_t i=0; i<num_die_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004387 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004388 const dw_offset_t die_offset = die_offsets[i];
4389 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
4390
Greg Clayton95d87902011-11-11 03:16:25 +00004391 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00004392 {
Greg Clayton95d87902011-11-11 03:16:25 +00004393 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
4394 continue;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004395
Greg Clayton95d87902011-11-11 03:16:25 +00004396 Type *matching_type = ResolveType (dwarf_cu, die);
4397 if (matching_type)
4398 {
4399 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00004400 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00004401 if (types.GetSize() >= max_matches)
4402 break;
4403 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00004404 }
Greg Clayton95d87902011-11-11 03:16:25 +00004405 else
4406 {
4407 if (m_using_apple_tables)
4408 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004409 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4410 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004411 }
4412 }
4413
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004414 }
Greg Clayton437a1352012-04-09 22:43:43 +00004415 const uint32_t num_matches = types.GetSize() - initial_types_size;
4416 if (log && num_matches)
4417 {
4418 if (namespace_decl)
4419 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004420 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004421 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u",
4422 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004423 static_cast<void*>(namespace_decl->GetNamespaceDecl()),
Greg Clayton437a1352012-04-09 22:43:43 +00004424 namespace_decl->GetQualifiedName().c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004425 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00004426 num_matches);
4427 }
4428 else
4429 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004430 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004431 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u",
4432 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004433 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00004434 num_matches);
4435 }
4436 }
4437 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004438 }
Greg Clayton7f995132011-10-04 22:41:51 +00004439 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004440}
4441
4442
Greg Clayton526e5af2010-11-13 03:52:47 +00004443ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00004444SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00004445 const ConstString &name,
4446 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004447{
Greg Clayton5160ce52013-03-27 23:08:40 +00004448 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00004449
4450 if (log)
4451 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004452 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00004453 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
4454 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00004455 }
Sean Callanan213fdb82011-10-13 01:49:10 +00004456
4457 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
Ed Maste4c24b122013-10-17 20:13:14 +00004458 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00004459
Greg Clayton526e5af2010-11-13 03:52:47 +00004460 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004461 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00004462 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00004463 {
Greg Clayton7f995132011-10-04 22:41:51 +00004464 DIEArray die_offsets;
4465
Greg Clayton526e5af2010-11-13 03:52:47 +00004466 // Index if we already haven't to make sure the compile units
4467 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00004468 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004469 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004470 if (m_apple_namespaces_ap.get())
4471 {
4472 const char *name_cstr = name.GetCString();
4473 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
4474 }
Greg Clayton7f995132011-10-04 22:41:51 +00004475 }
4476 else
4477 {
4478 if (!m_indexed)
4479 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00004480
Greg Clayton7f995132011-10-04 22:41:51 +00004481 m_namespace_index.Find (name, die_offsets);
4482 }
Greg Claytond4a2b372011-09-12 23:21:58 +00004483
4484 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00004485 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00004486 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00004487 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00004488 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004489 DWARFDebugInfo* debug_info = DebugInfo();
4490 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00004491 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004492 const dw_offset_t die_offset = die_offsets[i];
4493 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00004494
Greg Clayton95d87902011-11-11 03:16:25 +00004495 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00004496 {
Greg Clayton95d87902011-11-11 03:16:25 +00004497 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
4498 continue;
4499
4500 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
4501 if (clang_namespace_decl)
4502 {
4503 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
4504 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
Greg Claytond1767f02011-12-08 02:13:16 +00004505 break;
Greg Clayton95d87902011-11-11 03:16:25 +00004506 }
Greg Claytond4a2b372011-09-12 23:21:58 +00004507 }
Greg Clayton95d87902011-11-11 03:16:25 +00004508 else
4509 {
4510 if (m_using_apple_tables)
4511 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004512 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
4513 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004514 }
4515 }
4516
Greg Clayton526e5af2010-11-13 03:52:47 +00004517 }
4518 }
Greg Clayton96d7d742010-11-10 23:42:09 +00004519 }
Greg Clayton437a1352012-04-09 22:43:43 +00004520 if (log && namespace_decl.GetNamespaceDecl())
4521 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004522 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00004523 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"",
4524 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004525 static_cast<const void*>(namespace_decl.GetNamespaceDecl()),
Greg Clayton437a1352012-04-09 22:43:43 +00004526 namespace_decl.GetQualifiedName().c_str());
4527 }
4528
Greg Clayton526e5af2010-11-13 03:52:47 +00004529 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004530}
4531
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004532uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004533SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004534{
4535 // Remember how many sc_list are in the list before we search in case
4536 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004537 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004538
4539 const uint32_t num_die_offsets = die_offsets.size();
4540 // Parse all of the types we found from the pubtypes matches
4541 uint32_t i;
4542 uint32_t num_matches = 0;
4543 for (i = 0; i < num_die_offsets; ++i)
4544 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004545 Type *matching_type = ResolveTypeUID (die_offsets[i]);
4546 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004547 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004548 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00004549 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004550 ++num_matches;
4551 if (num_matches >= max_matches)
4552 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004553 }
4554 }
4555
4556 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004557 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004558}
4559
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004560
4561size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00004562SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
4563 clang::DeclContext *containing_decl_ctx,
Greg Clayton5113dc82011-08-12 06:47:54 +00004564 DWARFCompileUnit* dwarf_cu,
4565 const DWARFDebugInfoEntry *parent_die,
4566 bool skip_artificial,
4567 bool &is_static,
Greg Clayton03969752014-02-24 18:53:11 +00004568 bool &is_variadic,
Greg Claytona1e5dc82015-08-11 22:53:00 +00004569 std::vector<CompilerType>& function_param_types,
Greg Clayton5113dc82011-08-12 06:47:54 +00004570 std::vector<clang::ParmVarDecl*>& function_param_decls,
Greg Claytond20deac2014-04-04 18:15:18 +00004571 unsigned &type_quals) // ,
4572 // ClangASTContext::TemplateParameterInfos &template_param_infos))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004573{
4574 if (parent_die == NULL)
4575 return 0;
4576
Todd Fialaee8bfc62014-09-11 17:29:12 +00004577 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Claytond88d7592010-09-15 08:33:30 +00004578
Greg Clayton7fedea22010-11-16 02:10:54 +00004579 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004580 const DWARFDebugInfoEntry *die;
4581 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4582 {
4583 dw_tag_t tag = die->Tag();
4584 switch (tag)
4585 {
4586 case DW_TAG_formal_parameter:
4587 {
4588 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004589 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004590 if (num_attributes > 0)
4591 {
4592 const char *name = NULL;
4593 Declaration decl;
4594 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00004595 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004596 // one of None, Auto, Register, Extern, Static, PrivateExtern
4597
Sean Callanane2ef6e32010-09-23 03:01:22 +00004598 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004599 uint32_t i;
4600 for (i=0; i<num_attributes; ++i)
4601 {
4602 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4603 DWARFFormValue form_value;
4604 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4605 {
4606 switch (attr)
4607 {
4608 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4609 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4610 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4611 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00004612 case DW_AT_type: param_type_die_offset = form_value.Reference(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00004613 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004614 case DW_AT_location:
4615 // if (form_value.BlockData())
4616 // {
Ed Masteeeae7212013-10-24 20:43:47 +00004617 // const DWARFDataExtractor& debug_info_data = debug_info();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004618 // uint32_t block_length = form_value.Unsigned();
Ed Masteeeae7212013-10-24 20:43:47 +00004619 // DWARFDataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004620 // }
4621 // else
4622 // {
4623 // }
4624 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004625 case DW_AT_const_value:
4626 case DW_AT_default_value:
4627 case DW_AT_description:
4628 case DW_AT_endianity:
4629 case DW_AT_is_optional:
4630 case DW_AT_segment:
4631 case DW_AT_variable_parameter:
4632 default:
4633 case DW_AT_abstract_origin:
4634 case DW_AT_sibling:
4635 break;
4636 }
4637 }
4638 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00004639
Greg Clayton0fffff52010-09-24 05:15:53 +00004640 bool skip = false;
4641 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004642 {
Greg Clayton0fffff52010-09-24 05:15:53 +00004643 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00004644 {
4645 // In order to determine if a C++ member function is
4646 // "const" we have to look at the const-ness of "this"...
4647 // Ugly, but that
4648 if (arg_idx == 0)
4649 {
Greg Claytonf0705c82011-10-22 03:33:13 +00004650 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00004651 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004652 // Often times compilers omit the "this" name for the
4653 // specification DIEs, so we can't rely upon the name
4654 // being in the formal parameter DIE...
4655 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00004656 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004657 Type *this_type = ResolveTypeUID (param_type_die_offset);
4658 if (this_type)
4659 {
4660 uint32_t encoding_mask = this_type->GetEncodingMask();
4661 if (encoding_mask & Type::eEncodingIsPointerUID)
4662 {
4663 is_static = false;
4664
4665 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
4666 type_quals |= clang::Qualifiers::Const;
4667 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
4668 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00004669 }
4670 }
4671 }
4672 }
4673 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004674 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00004675 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004676 else
4677 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004678
Greg Clayton0fffff52010-09-24 05:15:53 +00004679 // HACK: Objective C formal parameters "self" and "_cmd"
4680 // are not marked as artificial in the DWARF...
Greg Clayton53eb1c22012-04-02 22:59:12 +00004681 CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
4682 if (comp_unit)
Greg Clayton0fffff52010-09-24 05:15:53 +00004683 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004684 switch (comp_unit->GetLanguage())
4685 {
4686 case eLanguageTypeObjC:
4687 case eLanguageTypeObjC_plus_plus:
4688 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
4689 skip = true;
4690 break;
4691 default:
4692 break;
4693 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004694 }
4695 }
4696 }
4697
4698 if (!skip)
4699 {
4700 Type *type = ResolveTypeUID(param_type_die_offset);
4701 if (type)
4702 {
Greg Claytonc93237c2010-10-01 20:48:32 +00004703 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00004704
Greg Clayton42ce2f32011-12-12 21:50:19 +00004705 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
4706 type->GetClangForwardType(),
4707 storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00004708 assert(param_var_decl);
4709 function_param_decls.push_back(param_var_decl);
Sean Callanan60217122012-04-13 00:10:03 +00004710
Greg Claytond0029442013-03-27 01:48:02 +00004711 GetClangASTContext().SetMetadataAsUserID (param_var_decl, MakeUserID(die->GetOffset()));
Greg Clayton0fffff52010-09-24 05:15:53 +00004712 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004713 }
4714 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004715 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004716 }
4717 break;
4718
Greg Clayton03969752014-02-24 18:53:11 +00004719 case DW_TAG_unspecified_parameters:
4720 is_variadic = true;
4721 break;
4722
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004723 case DW_TAG_template_type_parameter:
4724 case DW_TAG_template_value_parameter:
Greg Claytond20deac2014-04-04 18:15:18 +00004725 // The one caller of this was never using the template_param_infos,
4726 // and the local variable was taking up a large amount of stack space
4727 // in SymbolFileDWARF::ParseType() so this was removed. If we ever need
4728 // the template params back, we can add them back.
4729 // ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004730 break;
4731
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004732 default:
4733 break;
4734 }
4735 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004736 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004737}
4738
4739size_t
4740SymbolFileDWARF::ParseChildEnumerators
4741(
4742 const SymbolContext& sc,
Greg Claytona1e5dc82015-08-11 22:53:00 +00004743 lldb_private::CompilerType &clang_type,
Greg Clayton3e067532013-03-05 23:54:39 +00004744 bool is_signed,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004745 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00004746 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004747 const DWARFDebugInfoEntry *parent_die
4748)
4749{
4750 if (parent_die == NULL)
4751 return 0;
4752
4753 size_t enumerators_added = 0;
4754 const DWARFDebugInfoEntry *die;
Todd Fialaee8bfc62014-09-11 17:29:12 +00004755 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Greg Claytond88d7592010-09-15 08:33:30 +00004756
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004757 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4758 {
4759 const dw_tag_t tag = die->Tag();
4760 if (tag == DW_TAG_enumerator)
4761 {
4762 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004763 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004764 if (num_child_attributes > 0)
4765 {
4766 const char *name = NULL;
4767 bool got_value = false;
4768 int64_t enum_value = 0;
4769 Declaration decl;
4770
4771 uint32_t i;
4772 for (i=0; i<num_child_attributes; ++i)
4773 {
4774 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4775 DWARFFormValue form_value;
4776 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4777 {
4778 switch (attr)
4779 {
4780 case DW_AT_const_value:
4781 got_value = true;
Greg Clayton3e067532013-03-05 23:54:39 +00004782 if (is_signed)
4783 enum_value = form_value.Signed();
4784 else
4785 enum_value = form_value.Unsigned();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004786 break;
4787
4788 case DW_AT_name:
4789 name = form_value.AsCString(&get_debug_str_data());
4790 break;
4791
4792 case DW_AT_description:
4793 default:
4794 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4795 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4796 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4797 case DW_AT_sibling:
4798 break;
4799 }
4800 }
4801 }
4802
4803 if (name && name[0] && got_value)
4804 {
Greg Claytond8d4a572015-08-11 21:38:15 +00004805 ClangASTContext* ast = clang_type.GetTypeSystem()->AsClangASTContext();
4806 if (ast)
4807 {
4808 ast->AddEnumerationValueToEnumerationType (clang_type.GetOpaqueQualType(),
4809 ast->GetEnumerationIntegerType(clang_type.GetOpaqueQualType()),
4810 decl,
4811 name,
4812 enum_value,
4813 enumerator_byte_size * 8);
4814 ++enumerators_added;
4815 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004816 }
4817 }
4818 }
4819 }
4820 return enumerators_added;
4821}
4822
4823void
4824SymbolFileDWARF::ParseChildArrayInfo
4825(
4826 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004827 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004828 const DWARFDebugInfoEntry *parent_die,
4829 int64_t& first_index,
4830 std::vector<uint64_t>& element_orders,
4831 uint32_t& byte_stride,
4832 uint32_t& bit_stride
4833)
4834{
4835 if (parent_die == NULL)
4836 return;
4837
4838 const DWARFDebugInfoEntry *die;
Todd Fialaee8bfc62014-09-11 17:29:12 +00004839 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004840 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4841 {
4842 const dw_tag_t tag = die->Tag();
4843 switch (tag)
4844 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004845 case DW_TAG_subrange_type:
4846 {
4847 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004848 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004849 if (num_child_attributes > 0)
4850 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004851 uint64_t num_elements = 0;
4852 uint64_t lower_bound = 0;
4853 uint64_t upper_bound = 0;
Greg Clayton4ef877f2012-12-06 02:33:54 +00004854 bool upper_bound_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004855 uint32_t i;
4856 for (i=0; i<num_child_attributes; ++i)
4857 {
4858 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4859 DWARFFormValue form_value;
4860 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4861 {
4862 switch (attr)
4863 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004864 case DW_AT_name:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004865 break;
4866
4867 case DW_AT_count:
4868 num_elements = form_value.Unsigned();
4869 break;
4870
4871 case DW_AT_bit_stride:
4872 bit_stride = form_value.Unsigned();
4873 break;
4874
4875 case DW_AT_byte_stride:
4876 byte_stride = form_value.Unsigned();
4877 break;
4878
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004879 case DW_AT_lower_bound:
4880 lower_bound = form_value.Unsigned();
4881 break;
4882
4883 case DW_AT_upper_bound:
Greg Clayton4ef877f2012-12-06 02:33:54 +00004884 upper_bound_valid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004885 upper_bound = form_value.Unsigned();
4886 break;
4887
4888 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004889 case DW_AT_abstract_origin:
4890 case DW_AT_accessibility:
4891 case DW_AT_allocated:
4892 case DW_AT_associated:
4893 case DW_AT_data_location:
4894 case DW_AT_declaration:
4895 case DW_AT_description:
4896 case DW_AT_sibling:
4897 case DW_AT_threads_scaled:
4898 case DW_AT_type:
4899 case DW_AT_visibility:
4900 break;
4901 }
4902 }
4903 }
4904
Greg Claytone6a07792012-12-05 21:59:39 +00004905 if (num_elements == 0)
4906 {
Greg Clayton4ef877f2012-12-06 02:33:54 +00004907 if (upper_bound_valid && upper_bound >= lower_bound)
Greg Claytone6a07792012-12-05 21:59:39 +00004908 num_elements = upper_bound - lower_bound + 1;
4909 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004910
Sean Callananec979ba2012-10-22 23:56:48 +00004911 element_orders.push_back (num_elements);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004912 }
4913 }
4914 break;
4915 }
4916 }
4917}
4918
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004919TypeSP
Greg Clayton53eb1c22012-04-02 22:59:12 +00004920SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004921{
4922 TypeSP type_sp;
4923 if (die != NULL)
4924 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004925 assert(dwarf_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00004926 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004927 if (type_ptr == NULL)
4928 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004929 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu);
Greg Claytonca512b32011-01-14 04:54:56 +00004930 assert (lldb_cu);
4931 SymbolContext sc(lldb_cu);
Greg Clayton53eb1c22012-04-02 22:59:12 +00004932 type_sp = ParseType(sc, dwarf_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004933 }
4934 else if (type_ptr != DIE_IS_BEING_PARSED)
4935 {
4936 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00004937 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004938 }
4939
4940 }
4941 return type_sp;
4942}
4943
4944clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00004945SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004946{
4947 if (die_offset != DW_INVALID_OFFSET)
4948 {
4949 DWARFCompileUnitSP cu_sp;
4950 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004951 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004952 }
4953 return NULL;
4954}
4955
Sean Callanan72e49402011-08-05 23:43:37 +00004956clang::DeclContext *
4957SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
4958{
4959 if (die_offset != DW_INVALID_OFFSET)
4960 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004961 DWARFDebugInfo* debug_info = DebugInfo();
4962 if (debug_info)
4963 {
4964 DWARFCompileUnitSP cu_sp;
4965 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
4966 if (die)
4967 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
4968 }
Sean Callanan72e49402011-08-05 23:43:37 +00004969 }
4970 return NULL;
4971}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004972
Greg Clayton96d7d742010-11-10 23:42:09 +00004973clang::NamespaceDecl *
Greg Clayton53eb1c22012-04-02 22:59:12 +00004974SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die)
Greg Clayton96d7d742010-11-10 23:42:09 +00004975{
Greg Clayton030a2042011-10-14 21:34:45 +00004976 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00004977 {
Greg Clayton030a2042011-10-14 21:34:45 +00004978 // See if we already parsed this namespace DIE and associated it with a
4979 // uniqued namespace declaration
4980 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
4981 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004982 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00004983 else
4984 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004985 const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL);
4986 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00004987 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
Greg Clayton5160ce52013-03-27 23:08:40 +00004988 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton9d3d6882011-10-31 23:51:19 +00004989 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00004990 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00004991 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00004992 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004993 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00004994 "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 +00004995 static_cast<void*>(GetClangASTContext().getASTContext()),
Greg Claytone38a5ed2012-01-05 03:57:59 +00004996 MakeUserID(die->GetOffset()),
4997 namespace_name,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004998 static_cast<void*>(namespace_decl),
4999 static_cast<void*>(namespace_decl->getOriginalNamespace()));
Greg Clayton030a2042011-10-14 21:34:45 +00005000 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00005001 else
5002 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005003 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00005004 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005005 static_cast<void*>(GetClangASTContext().getASTContext()),
Greg Claytone38a5ed2012-01-05 03:57:59 +00005006 MakeUserID(die->GetOffset()),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005007 static_cast<void*>(namespace_decl),
5008 static_cast<void*>(namespace_decl->getOriginalNamespace()));
Greg Clayton9d3d6882011-10-31 23:51:19 +00005009 }
Greg Clayton030a2042011-10-14 21:34:45 +00005010 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00005011
5012 if (namespace_decl)
5013 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
5014 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00005015 }
5016 }
5017 return NULL;
5018}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005019
5020clang::DeclContext *
Greg Claytoncab36a32011-12-08 05:16:30 +00005021SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Sean Callanan72e49402011-08-05 23:43:37 +00005022{
Greg Clayton5cf58b92011-10-05 22:22:08 +00005023 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
5024 if (clang_decl_ctx)
5025 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00005026 // If this DIE has a specification, or an abstract origin, then trace to those.
5027
Greg Claytoncab36a32011-12-08 05:16:30 +00005028 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00005029 if (die_offset != DW_INVALID_OFFSET)
5030 return GetClangDeclContextForDIEOffset (sc, die_offset);
5031
Greg Claytoncab36a32011-12-08 05:16:30 +00005032 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00005033 if (die_offset != DW_INVALID_OFFSET)
5034 return GetClangDeclContextForDIEOffset (sc, die_offset);
5035
Greg Clayton5160ce52013-03-27 23:08:40 +00005036 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005037 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005038 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 +00005039 // This is the DIE we want. Parse it, then query our map.
Greg Claytoncab36a32011-12-08 05:16:30 +00005040 bool assert_not_being_parsed = true;
5041 ResolveTypeUID (cu, die, assert_not_being_parsed);
5042
Greg Clayton5cf58b92011-10-05 22:22:08 +00005043 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
5044
5045 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00005046}
5047
5048clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00005049SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005050{
Greg Claytonca512b32011-01-14 04:54:56 +00005051 if (m_clang_tu_decl == NULL)
5052 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005053
Greg Clayton2bc22f82011-09-30 03:20:47 +00005054 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00005055
5056 if (decl_ctx_die_copy)
5057 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00005058
5059 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005060 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00005061
Greg Clayton2bc22f82011-09-30 03:20:47 +00005062 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
5063 if (pos != m_die_to_decl_ctx.end())
5064 return pos->second;
5065
5066 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005067 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00005068 case DW_TAG_compile_unit:
5069 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005070
Greg Clayton2bc22f82011-09-30 03:20:47 +00005071 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00005072 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00005073 break;
5074
5075 case DW_TAG_structure_type:
5076 case DW_TAG_union_type:
5077 case DW_TAG_class_type:
5078 {
5079 Type* type = ResolveType (cu, decl_ctx_die);
5080 if (type)
5081 {
Greg Claytond8d4a572015-08-11 21:38:15 +00005082 clang::DeclContext *decl_ctx = GetClangASTContext().GetDeclContextForType(type->GetClangForwardType());
Greg Clayton2bc22f82011-09-30 03:20:47 +00005083 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00005084 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00005085 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
5086 if (decl_ctx)
5087 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00005088 }
5089 }
Greg Claytonca512b32011-01-14 04:54:56 +00005090 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00005091 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005092
Greg Clayton2bc22f82011-09-30 03:20:47 +00005093 default:
5094 break;
Greg Claytonca512b32011-01-14 04:54:56 +00005095 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005096 }
Greg Clayton7a345282010-11-09 23:46:37 +00005097 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005098}
5099
Greg Clayton2bc22f82011-09-30 03:20:47 +00005100
5101const DWARFDebugInfoEntry *
5102SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
5103{
5104 if (cu && die)
5105 {
5106 const DWARFDebugInfoEntry * const decl_die = die;
5107
5108 while (die != NULL)
5109 {
5110 // If this is the original DIE that we are searching for a declaration
5111 // for, then don't look in the cache as we don't want our own decl
5112 // context to be our decl context...
5113 if (decl_die != die)
5114 {
5115 switch (die->Tag())
5116 {
5117 case DW_TAG_compile_unit:
5118 case DW_TAG_namespace:
5119 case DW_TAG_structure_type:
5120 case DW_TAG_union_type:
5121 case DW_TAG_class_type:
5122 return die;
5123
5124 default:
5125 break;
5126 }
5127 }
5128
5129 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
5130 if (die_offset != DW_INVALID_OFFSET)
5131 {
5132 DWARFCompileUnit *spec_cu = cu;
5133 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
5134 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
5135 if (spec_die_decl_ctx_die)
5136 return spec_die_decl_ctx_die;
5137 }
5138
5139 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
5140 if (die_offset != DW_INVALID_OFFSET)
5141 {
5142 DWARFCompileUnit *abs_cu = cu;
5143 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
5144 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
5145 if (abs_die_decl_ctx_die)
5146 return abs_die_decl_ctx_die;
5147 }
5148
5149 die = die->GetParent();
5150 }
5151 }
5152 return NULL;
5153}
5154
5155
Greg Clayton901c5ca2011-12-03 04:40:03 +00005156Symbol *
5157SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
5158{
5159 Symbol *objc_class_symbol = NULL;
5160 if (m_obj_file)
5161 {
Greg Clayton3046e662013-07-10 01:23:25 +00005162 Symtab *symtab = m_obj_file->GetSymtab ();
Greg Clayton901c5ca2011-12-03 04:40:03 +00005163 if (symtab)
5164 {
5165 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
5166 eSymbolTypeObjCClass,
5167 Symtab::eDebugNo,
5168 Symtab::eVisibilityAny);
5169 }
5170 }
5171 return objc_class_symbol;
5172}
5173
Greg Claytonc7f03b62012-01-12 04:33:28 +00005174// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
5175// then we can end up looking through all class types for a complete type and never find
5176// the full definition. We need to know if this attribute is supported, so we determine
5177// this here and cache th result. We also need to worry about the debug map DWARF file
5178// if we are doing darwin DWARF in .o file debugging.
5179bool
5180SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
5181{
5182 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
5183 {
5184 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
5185 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
5186 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
5187 else
5188 {
5189 DWARFDebugInfo* debug_info = DebugInfo();
5190 const uint32_t num_compile_units = GetNumCompileUnits();
5191 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
5192 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00005193 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
5194 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00005195 {
5196 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
5197 break;
5198 }
5199 }
5200 }
Greg Clayton1f746072012-08-29 21:13:06 +00005201 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00005202 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
5203 }
5204 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
5205}
Greg Clayton901c5ca2011-12-03 04:40:03 +00005206
5207// This function can be used when a DIE is found that is a forward declaration
5208// DIE and we want to try and find a type that has the complete definition.
5209TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00005210SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
5211 const ConstString &type_name,
5212 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00005213{
5214
5215 TypeSP type_sp;
5216
Greg Claytonc7f03b62012-01-12 04:33:28 +00005217 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00005218 return type_sp;
5219
5220 DIEArray die_offsets;
5221
5222 if (m_using_apple_tables)
5223 {
5224 if (m_apple_types_ap.get())
5225 {
5226 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00005227 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00005228 }
5229 }
5230 else
5231 {
5232 if (!m_indexed)
5233 Index ();
5234
5235 m_type_index.Find (type_name, die_offsets);
5236 }
5237
Greg Clayton901c5ca2011-12-03 04:40:03 +00005238 const size_t num_matches = die_offsets.size();
5239
Greg Clayton901c5ca2011-12-03 04:40:03 +00005240 DWARFCompileUnit* type_cu = NULL;
5241 const DWARFDebugInfoEntry* type_die = NULL;
5242 if (num_matches)
5243 {
5244 DWARFDebugInfo* debug_info = DebugInfo();
5245 for (size_t i=0; i<num_matches; ++i)
5246 {
5247 const dw_offset_t die_offset = die_offsets[i];
5248 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
5249
5250 if (type_die)
5251 {
5252 bool try_resolving_type = false;
5253
5254 // Don't try and resolve the DIE we are looking for with the DIE itself!
5255 if (type_die != die)
5256 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005257 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00005258 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005259 case DW_TAG_class_type:
5260 case DW_TAG_structure_type:
5261 try_resolving_type = true;
5262 break;
5263 default:
5264 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00005265 }
5266 }
5267
5268 if (try_resolving_type)
5269 {
Ed Maste4c24b122013-10-17 20:13:14 +00005270 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
5271 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00005272
5273 if (try_resolving_type)
5274 {
5275 Type *resolved_type = ResolveType (type_cu, type_die, false);
5276 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5277 {
Ed Mastea0191d12013-10-17 20:42:56 +00005278 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 +00005279 MakeUserID(die->GetOffset()),
Jim Ingham4af59612014-12-19 19:20:44 +00005280 m_obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>"),
Greg Clayton901c5ca2011-12-03 04:40:03 +00005281 MakeUserID(type_die->GetOffset()),
5282 MakeUserID(type_cu->GetOffset()));
5283
Greg Claytonc7f03b62012-01-12 04:33:28 +00005284 if (die)
5285 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00005286 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00005287 break;
5288 }
5289 }
5290 }
5291 }
5292 else
5293 {
5294 if (m_using_apple_tables)
5295 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005296 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5297 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00005298 }
5299 }
5300
5301 }
5302 }
5303 return type_sp;
5304}
5305
Greg Claytona8022fa2012-04-24 21:22:41 +00005306
Greg Clayton80c26302012-02-05 06:12:47 +00005307//----------------------------------------------------------------------
5308// This function helps to ensure that the declaration contexts match for
5309// two different DIEs. Often times debug information will refer to a
5310// forward declaration of a type (the equivalent of "struct my_struct;".
5311// There will often be a declaration of that type elsewhere that has the
5312// full definition. When we go looking for the full type "my_struct", we
5313// will find one or more matches in the accelerator tables and we will
5314// then need to make sure the type was in the same declaration context
5315// as the original DIE. This function can efficiently compare two DIEs
5316// and will return true when the declaration context matches, and false
5317// when they don't.
5318//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00005319bool
5320SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
5321 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
5322{
Greg Claytona8022fa2012-04-24 21:22:41 +00005323 if (die1 == die2)
5324 return true;
5325
5326#if defined (LLDB_CONFIGURATION_DEBUG)
5327 // You can't and shouldn't call this function with a compile unit from
5328 // two different SymbolFileDWARF instances.
5329 assert (DebugInfo()->ContainsCompileUnit (cu1));
5330 assert (DebugInfo()->ContainsCompileUnit (cu2));
5331#endif
5332
Greg Clayton890ff562012-02-02 05:48:16 +00005333 DWARFDIECollection decl_ctx_1;
5334 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00005335 //The declaration DIE stack is a stack of the declaration context
5336 // DIEs all the way back to the compile unit. If a type "T" is
5337 // declared inside a class "B", and class "B" is declared inside
5338 // a class "A" and class "A" is in a namespace "lldb", and the
5339 // namespace is in a compile unit, there will be a stack of DIEs:
5340 //
5341 // [0] DW_TAG_class_type for "B"
5342 // [1] DW_TAG_class_type for "A"
5343 // [2] DW_TAG_namespace for "lldb"
5344 // [3] DW_TAG_compile_unit for the source file.
5345 //
5346 // We grab both contexts and make sure that everything matches
5347 // all the way back to the compiler unit.
5348
5349 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00005350 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00005351 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00005352 // Make sure the context arrays have the same size, otherwise
5353 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00005354 const size_t count1 = decl_ctx_1.Size();
5355 const size_t count2 = decl_ctx_2.Size();
5356 if (count1 != count2)
5357 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00005358
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00005359 // Make sure the DW_TAG values match all the way back up the
Greg Clayton80c26302012-02-05 06:12:47 +00005360 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00005361 const DWARFDebugInfoEntry *decl_ctx_die1;
5362 const DWARFDebugInfoEntry *decl_ctx_die2;
5363 size_t i;
5364 for (i=0; i<count1; i++)
5365 {
5366 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
5367 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
5368 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
5369 return false;
5370 }
Greg Clayton890ff562012-02-02 05:48:16 +00005371#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00005372
5373 // Make sure the top item in the decl context die array is always
5374 // DW_TAG_compile_unit. If it isn't then something went wrong in
5375 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00005376 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00005377
Greg Clayton890ff562012-02-02 05:48:16 +00005378#endif
5379 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00005380 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00005381 for (i=0; i<count1 - 1; i++)
5382 {
5383 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
5384 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
5385 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00005386 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00005387 // If the string was from a DW_FORM_strp, then the pointer will often
5388 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00005389 if (name1 == name2)
5390 continue;
5391
5392 // Name pointers are not equal, so only compare the strings
5393 // if both are not NULL.
5394 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00005395 {
Greg Clayton5569e642012-02-06 01:44:54 +00005396 // If the strings don't compare, we are done...
5397 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00005398 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00005399 }
5400 else
5401 {
5402 // One name was NULL while the other wasn't
5403 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00005404 }
5405 }
Greg Clayton80c26302012-02-05 06:12:47 +00005406 // We made it through all of the checks and the declaration contexts
5407 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00005408 return true;
5409}
Greg Clayton220a0072011-12-09 08:48:30 +00005410
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005411
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005412TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00005413SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx)
5414{
5415 TypeSP type_sp;
5416
5417 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
5418 if (dwarf_decl_ctx_count > 0)
5419 {
5420 const ConstString type_name(dwarf_decl_ctx[0].name);
5421 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
5422
5423 if (type_name)
5424 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005425 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
Greg Claytona8022fa2012-04-24 21:22:41 +00005426 if (log)
5427 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005428 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005429 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')",
5430 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5431 dwarf_decl_ctx.GetQualifiedName());
5432 }
5433
5434 DIEArray die_offsets;
5435
5436 if (m_using_apple_tables)
5437 {
5438 if (m_apple_types_ap.get())
5439 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005440 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
5441 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
5442 if (has_tag && has_qualified_name_hash)
Greg Claytona8022fa2012-04-24 21:22:41 +00005443 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005444 const char *qualified_name = dwarf_decl_ctx.GetQualifiedName();
5445 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name);
5446 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005447 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005448 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets);
5449 }
5450 else if (has_tag)
5451 {
5452 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005453 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
Greg Claytona8022fa2012-04-24 21:22:41 +00005454 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets);
5455 }
5456 else
5457 {
5458 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
5459 }
5460 }
5461 }
5462 else
5463 {
5464 if (!m_indexed)
5465 Index ();
5466
5467 m_type_index.Find (type_name, die_offsets);
5468 }
5469
5470 const size_t num_matches = die_offsets.size();
5471
5472
5473 DWARFCompileUnit* type_cu = NULL;
5474 const DWARFDebugInfoEntry* type_die = NULL;
5475 if (num_matches)
5476 {
5477 DWARFDebugInfo* debug_info = DebugInfo();
5478 for (size_t i=0; i<num_matches; ++i)
5479 {
5480 const dw_offset_t die_offset = die_offsets[i];
5481 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
5482
5483 if (type_die)
5484 {
5485 bool try_resolving_type = false;
5486
5487 // Don't try and resolve the DIE we are looking for with the DIE itself!
5488 const dw_tag_t type_tag = type_die->Tag();
5489 // Make sure the tags match
5490 if (type_tag == tag)
5491 {
5492 // The tags match, lets try resolving this type
5493 try_resolving_type = true;
5494 }
5495 else
5496 {
5497 // The tags don't match, but we need to watch our for a
5498 // forward declaration for a struct and ("struct foo")
5499 // ends up being a class ("class foo { ... };") or
5500 // vice versa.
5501 switch (type_tag)
5502 {
5503 case DW_TAG_class_type:
5504 // We had a "class foo", see if we ended up with a "struct foo { ... };"
5505 try_resolving_type = (tag == DW_TAG_structure_type);
5506 break;
5507 case DW_TAG_structure_type:
5508 // We had a "struct foo", see if we ended up with a "class foo { ... };"
5509 try_resolving_type = (tag == DW_TAG_class_type);
5510 break;
5511 default:
5512 // Tags don't match, don't event try to resolve
5513 // using this type whose name matches....
5514 break;
5515 }
5516 }
5517
5518 if (try_resolving_type)
5519 {
5520 DWARFDeclContext type_dwarf_decl_ctx;
5521 type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx);
5522
5523 if (log)
5524 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005525 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005526 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)",
5527 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5528 dwarf_decl_ctx.GetQualifiedName(),
5529 type_die->GetOffset(),
5530 type_dwarf_decl_ctx.GetQualifiedName());
5531 }
5532
5533 // Make sure the decl contexts match all the way up
5534 if (dwarf_decl_ctx == type_dwarf_decl_ctx)
5535 {
5536 Type *resolved_type = ResolveType (type_cu, type_die, false);
5537 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5538 {
5539 type_sp = resolved_type->shared_from_this();
5540 break;
5541 }
5542 }
5543 }
5544 else
5545 {
5546 if (log)
5547 {
5548 std::string qualified_name;
5549 type_die->GetQualifiedName(this, type_cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00005550 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005551 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)",
5552 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5553 dwarf_decl_ctx.GetQualifiedName(),
5554 type_die->GetOffset(),
5555 qualified_name.c_str());
5556 }
5557 }
5558 }
5559 else
5560 {
5561 if (m_using_apple_tables)
5562 {
5563 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5564 die_offset, type_name.GetCString());
5565 }
5566 }
5567
5568 }
5569 }
5570 }
5571 }
5572 return type_sp;
5573}
5574
Greg Clayton4116e932012-05-15 02:33:01 +00005575bool
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005576SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005577 Type *class_type,
Greg Clayton4116e932012-05-15 02:33:01 +00005578 DWARFCompileUnit* src_cu,
5579 const DWARFDebugInfoEntry *src_class_die,
5580 DWARFCompileUnit* dst_cu,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005581 const DWARFDebugInfoEntry *dst_class_die,
Greg Claytond20deac2014-04-04 18:15:18 +00005582 DWARFDIECollection &failures)
Greg Clayton4116e932012-05-15 02:33:01 +00005583{
5584 if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die)
5585 return false;
5586 if (src_class_die->Tag() != dst_class_die->Tag())
5587 return false;
5588
5589 // We need to complete the class type so we can get all of the method types
5590 // parsed so we can then unique those types to their equivalent counterparts
5591 // in "dst_cu" and "dst_class_die"
5592 class_type->GetClangFullType();
5593
5594 const DWARFDebugInfoEntry *src_die;
5595 const DWARFDebugInfoEntry *dst_die;
5596 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die;
5597 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die;
Greg Clayton65ec1032012-11-12 21:27:20 +00005598 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial;
5599 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial;
Greg Clayton4116e932012-05-15 02:33:01 +00005600 for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling())
5601 {
5602 if (src_die->Tag() == DW_TAG_subprogram)
5603 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005604 // Make sure this is a declaration and not a concrete instance by looking
5605 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5606 // are placed inside the class definitions and shouldn't be included in
5607 // the list of things are are tracking here.
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005608 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_declaration, 0) == 1)
Greg Clayton84afacd2012-11-07 23:09:32 +00005609 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005610 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton84afacd2012-11-07 23:09:32 +00005611 if (src_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005612 {
5613 ConstString src_const_name(src_name);
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005614 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0))
Greg Clayton65ec1032012-11-12 21:27:20 +00005615 src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die);
5616 else
5617 src_name_to_die.Append(src_const_name.GetCString(), src_die);
5618 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005619 }
Greg Clayton4116e932012-05-15 02:33:01 +00005620 }
5621 }
5622 for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling())
5623 {
5624 if (dst_die->Tag() == DW_TAG_subprogram)
5625 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005626 // Make sure this is a declaration and not a concrete instance by looking
5627 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5628 // are placed inside the class definitions and shouldn't be included in
5629 // the list of things are are tracking here.
5630 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1)
5631 {
5632 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5633 if (dst_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005634 {
5635 ConstString dst_const_name(dst_name);
5636 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0))
5637 dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die);
5638 else
5639 dst_name_to_die.Append(dst_const_name.GetCString(), dst_die);
5640 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005641 }
Greg Clayton4116e932012-05-15 02:33:01 +00005642 }
5643 }
5644 const uint32_t src_size = src_name_to_die.GetSize ();
5645 const uint32_t dst_size = dst_name_to_die.GetSize ();
Greg Clayton5160ce52013-03-27 23:08:40 +00005646 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005647
5648 // Is everything kosher so we can go through the members at top speed?
5649 bool fast_path = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005650
Sean Callanan2367f8a2013-02-26 01:12:25 +00005651 if (src_size != dst_size)
Greg Clayton4116e932012-05-15 02:33:01 +00005652 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005653 if (src_size != 0 && dst_size != 0)
5654 {
5655 if (log)
5656 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)",
5657 src_class_die->GetOffset(),
5658 dst_class_die->GetOffset(),
5659 src_size,
5660 dst_size);
5661 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005662
Sean Callanan2367f8a2013-02-26 01:12:25 +00005663 fast_path = false;
5664 }
5665
5666 uint32_t idx;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005667
Sean Callanan2367f8a2013-02-26 01:12:25 +00005668 if (fast_path)
5669 {
Greg Clayton4116e932012-05-15 02:33:01 +00005670 for (idx = 0; idx < src_size; ++idx)
5671 {
5672 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5673 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5674
5675 if (src_die->Tag() != dst_die->Tag())
5676 {
5677 if (log)
5678 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)",
5679 src_class_die->GetOffset(),
5680 dst_class_die->GetOffset(),
5681 src_die->GetOffset(),
5682 DW_TAG_value_to_name(src_die->Tag()),
5683 dst_die->GetOffset(),
5684 DW_TAG_value_to_name(src_die->Tag()));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005685 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005686 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005687
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005688 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton4116e932012-05-15 02:33:01 +00005689 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005690
Greg Clayton4116e932012-05-15 02:33:01 +00005691 // Make sure the names match
5692 if (src_name == dst_name || (strcmp (src_name, dst_name) == 0))
5693 continue;
5694
5695 if (log)
5696 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)",
5697 src_class_die->GetOffset(),
5698 dst_class_die->GetOffset(),
5699 src_die->GetOffset(),
5700 src_name,
5701 dst_die->GetOffset(),
5702 dst_name);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005703
Sean Callanan2367f8a2013-02-26 01:12:25 +00005704 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005705 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005706 }
Greg Clayton4116e932012-05-15 02:33:01 +00005707
Sean Callanan2367f8a2013-02-26 01:12:25 +00005708 // Now do the work of linking the DeclContexts and Types.
5709 if (fast_path)
5710 {
5711 // We can do this quickly. Just run across the tables index-for-index since
5712 // we know each node has matching names and tags.
Greg Clayton4116e932012-05-15 02:33:01 +00005713 for (idx = 0; idx < src_size; ++idx)
5714 {
5715 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5716 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005717
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005718 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Greg Clayton4116e932012-05-15 02:33:01 +00005719 if (src_decl_ctx)
5720 {
5721 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005722 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
5723 static_cast<void*>(src_decl_ctx),
5724 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005725 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5726 }
5727 else
5728 {
5729 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005730 log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found",
5731 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005732 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005733
Greg Clayton4116e932012-05-15 02:33:01 +00005734 Type *src_child_type = m_die_to_type[src_die];
5735 if (src_child_type)
5736 {
5737 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005738 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
5739 static_cast<void*>(src_child_type),
5740 src_child_type->GetID(),
5741 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005742 m_die_to_type[dst_die] = src_child_type;
5743 }
5744 else
5745 {
5746 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005747 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());
5748 }
5749 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005750 }
5751 else
5752 {
5753 // We must do this slowly. For each member of the destination, look
5754 // up a member in the source with the same name, check its tag, and
5755 // unique them if everything matches up. Report failures.
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005756
Sean Callanan2367f8a2013-02-26 01:12:25 +00005757 if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty())
5758 {
5759 src_name_to_die.Sort();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005760
Sean Callanan2367f8a2013-02-26 01:12:25 +00005761 for (idx = 0; idx < dst_size; ++idx)
5762 {
5763 const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx);
5764 dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
5765 src_die = src_name_to_die.Find(dst_name, NULL);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005766
Sean Callanan2367f8a2013-02-26 01:12:25 +00005767 if (src_die && (src_die->Tag() == dst_die->Tag()))
5768 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005769 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Sean Callanan2367f8a2013-02-26 01:12:25 +00005770 if (src_decl_ctx)
5771 {
5772 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005773 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
5774 static_cast<void*>(src_decl_ctx),
5775 src_die->GetOffset(),
5776 dst_die->GetOffset());
Sean Callanan2367f8a2013-02-26 01:12:25 +00005777 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5778 }
5779 else
5780 {
5781 if (log)
5782 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());
5783 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005784
Sean Callanan2367f8a2013-02-26 01:12:25 +00005785 Type *src_child_type = m_die_to_type[src_die];
5786 if (src_child_type)
5787 {
5788 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005789 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
5790 static_cast<void*>(src_child_type),
5791 src_child_type->GetID(),
5792 src_die->GetOffset(),
5793 dst_die->GetOffset());
Sean Callanan2367f8a2013-02-26 01:12:25 +00005794 m_die_to_type[dst_die] = src_child_type;
5795 }
5796 else
5797 {
5798 if (log)
5799 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());
5800 }
5801 }
5802 else
5803 {
5804 if (log)
5805 log->Printf ("warning: couldn't find a match for 0x%8.8x", dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005806
Greg Claytond20deac2014-04-04 18:15:18 +00005807 failures.Append(dst_die);
Sean Callanan2367f8a2013-02-26 01:12:25 +00005808 }
5809 }
5810 }
5811 }
5812
5813 const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize ();
5814 const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize ();
5815
5816 UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src;
5817
5818 if (src_size_artificial && dst_size_artificial)
5819 {
5820 dst_name_to_die_artificial.Sort();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005821
Greg Clayton65ec1032012-11-12 21:27:20 +00005822 for (idx = 0; idx < src_size_artificial; ++idx)
5823 {
5824 const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx);
5825 src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5826 dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005827
Greg Clayton65ec1032012-11-12 21:27:20 +00005828 if (dst_die)
5829 {
Greg Clayton65ec1032012-11-12 21:27:20 +00005830 // Both classes have the artificial types, link them
5831 clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die];
5832 if (src_decl_ctx)
5833 {
5834 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005835 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
5836 static_cast<void*>(src_decl_ctx),
5837 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005838 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5839 }
5840 else
5841 {
5842 if (log)
5843 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());
5844 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005845
Greg Clayton65ec1032012-11-12 21:27:20 +00005846 Type *src_child_type = m_die_to_type[src_die];
5847 if (src_child_type)
5848 {
5849 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005850 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
5851 static_cast<void*>(src_child_type),
5852 src_child_type->GetID(),
5853 src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005854 m_die_to_type[dst_die] = src_child_type;
5855 }
5856 else
5857 {
5858 if (log)
5859 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());
5860 }
5861 }
5862 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005863 }
Greg Clayton65ec1032012-11-12 21:27:20 +00005864
Sean Callanan2367f8a2013-02-26 01:12:25 +00005865 if (dst_size_artificial)
Greg Clayton4116e932012-05-15 02:33:01 +00005866 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005867 for (idx = 0; idx < dst_size_artificial; ++idx)
5868 {
5869 const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx);
5870 dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5871 if (log)
5872 log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial);
5873
Greg Claytond20deac2014-04-04 18:15:18 +00005874 failures.Append(dst_die);
Sean Callanan2367f8a2013-02-26 01:12:25 +00005875 }
Greg Clayton4116e932012-05-15 02:33:01 +00005876 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005877
Greg Claytond20deac2014-04-04 18:15:18 +00005878 return (failures.Size() != 0);
Greg Clayton4116e932012-05-15 02:33:01 +00005879}
Greg Claytona8022fa2012-04-24 21:22:41 +00005880
5881TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00005882SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005883{
5884 TypeSP type_sp;
5885
Greg Clayton1be10fc2010-09-29 01:12:09 +00005886 if (type_is_new_ptr)
5887 *type_is_new_ptr = false;
Greg Clayton1fba87112012-02-09 20:03:49 +00005888
Todd Fiala0a70a842014-05-28 16:43:26 +00005889#if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE)
Greg Clayton1fba87112012-02-09 20:03:49 +00005890 static DIEStack g_die_stack;
5891 DIEStack::ScopedPopper scoped_die_logger(g_die_stack);
5892#endif
Greg Clayton1be10fc2010-09-29 01:12:09 +00005893
Sean Callananc7fbf732010-08-06 00:32:49 +00005894 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005895 if (die != NULL)
5896 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005897 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005898 if (log)
Sean Callanan5b26f272012-02-04 08:49:35 +00005899 {
5900 const DWARFDebugInfoEntry *context_die;
5901 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005902
Greg Clayton5160ce52013-03-27 23:08:40 +00005903 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 +00005904 die->GetOffset(),
5905 static_cast<void*>(context),
5906 context_die->GetOffset(),
5907 DW_TAG_value_to_name(die->Tag()),
5908 die->GetName(this, dwarf_cu));
5909
Todd Fiala0a70a842014-05-28 16:43:26 +00005910#if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE)
Greg Clayton1fba87112012-02-09 20:03:49 +00005911 scoped_die_logger.Push (dwarf_cu, die);
Greg Clayton5160ce52013-03-27 23:08:40 +00005912 g_die_stack.LogDIEs(log, this);
Greg Clayton1fba87112012-02-09 20:03:49 +00005913#endif
Sean Callanan5b26f272012-02-04 08:49:35 +00005914 }
Greg Clayton3bffb082011-12-10 02:15:28 +00005915//
Greg Clayton5160ce52013-03-27 23:08:40 +00005916// Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005917// if (log && dwarf_cu)
5918// {
5919// StreamString s;
5920// die->DumpLocation (this, dwarf_cu, s);
Greg Clayton5160ce52013-03-27 23:08:40 +00005921// GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Greg Clayton3bffb082011-12-10 02:15:28 +00005922//
5923// }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005924
Greg Clayton594e5ed2010-09-27 21:07:38 +00005925 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005926 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00005927 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005928 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005929 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00005930 if (type_is_new_ptr)
5931 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005932
Greg Clayton594e5ed2010-09-27 21:07:38 +00005933 const dw_tag_t tag = die->Tag();
5934
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005935 bool is_forward_declaration = false;
5936 DWARFDebugInfoEntry::Attributes attributes;
5937 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00005938 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00005939 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
Greg Claytonfaac1112013-03-14 18:31:44 +00005940 uint64_t byte_size = 0;
Greg Clayton526e5af2010-11-13 03:52:47 +00005941 Declaration decl;
5942
Greg Clayton4957bf62010-09-30 21:49:03 +00005943 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Claytona1e5dc82015-08-11 22:53:00 +00005944 CompilerType clang_type;
Greg Claytond20deac2014-04-04 18:15:18 +00005945 DWARFFormValue form_value;
5946
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005947 dw_attr_t attr;
5948
5949 switch (tag)
5950 {
5951 case DW_TAG_base_type:
5952 case DW_TAG_pointer_type:
5953 case DW_TAG_reference_type:
Sean Callanance8af862012-05-21 23:31:51 +00005954 case DW_TAG_rvalue_reference_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005955 case DW_TAG_typedef:
5956 case DW_TAG_const_type:
5957 case DW_TAG_restrict_type:
5958 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00005959 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005960 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005961 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005962 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005963
Greg Claytond88d7592010-09-15 08:33:30 +00005964 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005965 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005966 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
5967
5968 if (num_attributes > 0)
5969 {
5970 uint32_t i;
5971 for (i=0; i<num_attributes; ++i)
5972 {
5973 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005974 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5975 {
5976 switch (attr)
5977 {
5978 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5979 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5980 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5981 case DW_AT_name:
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005982
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005983 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00005984 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
5985 // include the "&"...
5986 if (tag == DW_TAG_reference_type)
5987 {
5988 if (strchr (type_name_cstr, '&') == NULL)
5989 type_name_cstr = NULL;
5990 }
5991 if (type_name_cstr)
5992 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005993 break;
Greg Clayton23f59502012-07-17 03:23:13 +00005994 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005995 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
Greg Clayton54166af2014-11-22 01:58:59 +00005996 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005997 default:
5998 case DW_AT_sibling:
5999 break;
6000 }
6001 }
6002 }
6003 }
6004
Ed Mastea0191d12013-10-17 20:42:56 +00006005 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 +00006006
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006007 switch (tag)
6008 {
6009 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00006010 break;
6011
Greg Claytond4436412011-10-28 21:00:00 +00006012 case DW_TAG_unspecified_type:
Greg Clayton7fba2632013-07-01 21:01:52 +00006013 if (strcmp(type_name_cstr, "nullptr_t") == 0 ||
6014 strcmp(type_name_cstr, "decltype(nullptr)") == 0 )
Greg Claytond4436412011-10-28 21:00:00 +00006015 {
6016 resolve_state = Type::eResolveStateFull;
Greg Clayton57ee3062013-07-11 22:46:58 +00006017 clang_type = ast.GetBasicType(eBasicTypeNullPtr);
Greg Claytond4436412011-10-28 21:00:00 +00006018 break;
6019 }
6020 // Fall through to base type below in case we can handle the type there...
6021
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006022 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00006023 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006024 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
6025 encoding,
6026 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006027 break;
6028
Sean Callanance8af862012-05-21 23:31:51 +00006029 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
6030 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
6031 case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break;
6032 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
6033 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
6034 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
6035 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006036 }
6037
Greg Clayton57ee3062013-07-11 22:46:58 +00006038 if (!clang_type && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID) && sc.comp_unit != NULL)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00006039 {
Sean Callanan82587052013-01-03 00:05:56 +00006040 bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006041
Sean Callanan82587052013-01-03 00:05:56 +00006042 if (translation_unit_is_objc)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00006043 {
Sean Callanan82587052013-01-03 00:05:56 +00006044 if (type_name_cstr != NULL)
Greg Claytonc7f03b62012-01-12 04:33:28 +00006045 {
Sean Callanan82587052013-01-03 00:05:56 +00006046 static ConstString g_objc_type_name_id("id");
6047 static ConstString g_objc_type_name_Class("Class");
6048 static ConstString g_objc_type_name_selector("SEL");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006049
Sean Callanan82587052013-01-03 00:05:56 +00006050 if (type_name_const_str == g_objc_type_name_id)
6051 {
6052 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00006053 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 +00006054 die->GetOffset(),
6055 DW_TAG_value_to_name(die->Tag()),
6056 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00006057 clang_type = ast.GetBasicType(eBasicTypeObjCID);
Sean Callanan82587052013-01-03 00:05:56 +00006058 encoding_data_type = Type::eEncodingIsUID;
6059 encoding_uid = LLDB_INVALID_UID;
6060 resolve_state = Type::eResolveStateFull;
Greg Clayton526e5af2010-11-13 03:52:47 +00006061
Sean Callanan82587052013-01-03 00:05:56 +00006062 }
6063 else if (type_name_const_str == g_objc_type_name_Class)
6064 {
6065 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00006066 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 +00006067 die->GetOffset(),
6068 DW_TAG_value_to_name(die->Tag()),
6069 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00006070 clang_type = ast.GetBasicType(eBasicTypeObjCClass);
Sean Callanan82587052013-01-03 00:05:56 +00006071 encoding_data_type = Type::eEncodingIsUID;
6072 encoding_uid = LLDB_INVALID_UID;
6073 resolve_state = Type::eResolveStateFull;
6074 }
6075 else if (type_name_const_str == g_objc_type_name_selector)
6076 {
6077 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00006078 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 +00006079 die->GetOffset(),
6080 DW_TAG_value_to_name(die->Tag()),
6081 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00006082 clang_type = ast.GetBasicType(eBasicTypeObjCSel);
Sean Callanan82587052013-01-03 00:05:56 +00006083 encoding_data_type = Type::eEncodingIsUID;
6084 encoding_uid = LLDB_INVALID_UID;
6085 resolve_state = Type::eResolveStateFull;
6086 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00006087 }
Sean Callanan82587052013-01-03 00:05:56 +00006088 else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID)
Greg Claytonc7f03b62012-01-12 04:33:28 +00006089 {
Sean Callanan82587052013-01-03 00:05:56 +00006090 // 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 +00006091
Sean Callanan82587052013-01-03 00:05:56 +00006092 DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006093
Sean Callanan82587052013-01-03 00:05:56 +00006094 if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006095 {
Sean Callanan82587052013-01-03 00:05:56 +00006096 if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL))
6097 {
6098 if (!strcmp(struct_name, "objc_object"))
6099 {
6100 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00006101 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 +00006102 die->GetOffset(),
6103 DW_TAG_value_to_name(die->Tag()),
6104 die->GetName(this, dwarf_cu));
Greg Clayton57ee3062013-07-11 22:46:58 +00006105 clang_type = ast.GetBasicType(eBasicTypeObjCID);
Sean Callanan82587052013-01-03 00:05:56 +00006106 encoding_data_type = Type::eEncodingIsUID;
6107 encoding_uid = LLDB_INVALID_UID;
6108 resolve_state = Type::eResolveStateFull;
6109 }
6110 }
6111 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00006112 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00006113 }
6114 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006115
Greg Clayton81c22f62011-10-19 18:09:39 +00006116 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006117 this,
6118 type_name_const_str,
6119 byte_size,
6120 NULL,
6121 encoding_uid,
6122 encoding_data_type,
6123 &decl,
6124 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006125 resolve_state));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006126
Greg Clayton594e5ed2010-09-27 21:07:38 +00006127 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006128
6129// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
6130// if (encoding_type != NULL)
6131// {
6132// if (encoding_type != DIE_IS_BEING_PARSED)
6133// type_sp->SetEncodingType(encoding_type);
6134// else
6135// m_indirect_fixups.push_back(type_sp.get());
6136// }
6137 }
6138 break;
6139
6140 case DW_TAG_structure_type:
6141 case DW_TAG_union_type:
6142 case DW_TAG_class_type:
6143 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006144 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006145 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Greg Clayton23f59502012-07-17 03:23:13 +00006146 bool byte_size_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006147
Greg Clayton9e409562010-07-28 02:04:09 +00006148 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00006149 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006150 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00006151 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006152 if (num_attributes > 0)
6153 {
6154 uint32_t i;
6155 for (i=0; i<num_attributes; ++i)
6156 {
6157 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006158 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6159 {
6160 switch (attr)
6161 {
Greg Clayton9e409562010-07-28 02:04:09 +00006162 case DW_AT_decl_file:
Greg Claytonc7f03b62012-01-12 04:33:28 +00006163 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
Ed Maste4c24b122013-10-17 20:13:14 +00006164 {
6165 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
6166 // point to the compile unit file, so we clear this invalid value
6167 // so that we can still unique types efficiently.
Greg Claytonc7f03b62012-01-12 04:33:28 +00006168 decl.SetFile(FileSpec ("<invalid>", false));
Ed Maste4c24b122013-10-17 20:13:14 +00006169 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00006170 else
6171 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
Greg Clayton9e409562010-07-28 02:04:09 +00006172 break;
6173
6174 case DW_AT_decl_line:
6175 decl.SetLine(form_value.Unsigned());
6176 break;
6177
6178 case DW_AT_decl_column:
6179 decl.SetColumn(form_value.Unsigned());
6180 break;
6181
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006182 case DW_AT_name:
6183 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006184 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006185 break;
Greg Clayton9e409562010-07-28 02:04:09 +00006186
6187 case DW_AT_byte_size:
6188 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00006189 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00006190 break;
6191
6192 case DW_AT_accessibility:
6193 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
6194 break;
6195
6196 case DW_AT_declaration:
Greg Clayton1c8ef472013-04-05 23:27:21 +00006197 is_forward_declaration = form_value.Boolean();
Greg Clayton9e409562010-07-28 02:04:09 +00006198 break;
6199
6200 case DW_AT_APPLE_runtime_class:
6201 class_language = (LanguageType)form_value.Signed();
6202 break;
6203
Greg Clayton18774842011-11-29 23:40:34 +00006204 case DW_AT_APPLE_objc_complete_type:
6205 is_complete_objc_class = form_value.Signed();
6206 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006207
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006208 case DW_AT_allocated:
6209 case DW_AT_associated:
6210 case DW_AT_data_location:
6211 case DW_AT_description:
6212 case DW_AT_start_scope:
6213 case DW_AT_visibility:
6214 default:
6215 case DW_AT_sibling:
6216 break;
6217 }
6218 }
6219 }
6220 }
Greg Claytond20deac2014-04-04 18:15:18 +00006221
6222 // UniqueDWARFASTType is large, so don't create a local variables on the
6223 // stack, put it on the heap. This function is often called recursively
6224 // and clang isn't good and sharing the stack space for variables in different blocks.
6225 std::unique_ptr<UniqueDWARFASTType> unique_ast_entry_ap(new UniqueDWARFASTType());
Sean Callanan8e8072d2012-02-07 21:13:38 +00006226
Greg Clayton123edca2012-03-02 00:07:15 +00006227 // Only try and unique the type if it has a name.
6228 if (type_name_const_str &&
6229 GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Sean Callanan8e8072d2012-02-07 21:13:38 +00006230 this,
6231 dwarf_cu,
6232 die,
6233 decl,
6234 byte_size_valid ? byte_size : -1,
Greg Claytond20deac2014-04-04 18:15:18 +00006235 *unique_ast_entry_ap))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006236 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00006237 // We have already parsed this type or from another
6238 // compile unit. GCC loves to use the "one definition
6239 // rule" which can result in multiple definitions
6240 // of the same class over and over in each compile
6241 // unit.
Greg Claytond20deac2014-04-04 18:15:18 +00006242 type_sp = unique_ast_entry_ap->m_type_sp;
Sean Callanan8e8072d2012-02-07 21:13:38 +00006243 if (type_sp)
Greg Claytonc615ce42010-11-09 04:42:43 +00006244 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00006245 m_die_to_type[die] = type_sp.get();
6246 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00006247 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006248 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006249
Daniel Malead01b2952012-11-29 21:49:15 +00006250 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 +00006251
6252 int tag_decl_kind = -1;
6253 AccessType default_accessibility = eAccessNone;
6254 if (tag == DW_TAG_structure_type)
6255 {
6256 tag_decl_kind = clang::TTK_Struct;
6257 default_accessibility = eAccessPublic;
6258 }
6259 else if (tag == DW_TAG_union_type)
6260 {
6261 tag_decl_kind = clang::TTK_Union;
6262 default_accessibility = eAccessPublic;
6263 }
6264 else if (tag == DW_TAG_class_type)
6265 {
6266 tag_decl_kind = clang::TTK_Class;
6267 default_accessibility = eAccessPrivate;
6268 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006269
Greg Clayton3a5f29a2011-11-30 02:48:28 +00006270 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
6271 die->HasChildren() == false &&
6272 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
6273 {
6274 // Work around an issue with clang at the moment where
6275 // forward declarations for objective C classes are emitted
6276 // as:
6277 // DW_TAG_structure_type [2]
6278 // DW_AT_name( "ForwardObjcClass" )
6279 // DW_AT_byte_size( 0x00 )
6280 // DW_AT_decl_file( "..." )
6281 // DW_AT_decl_line( 1 )
6282 //
6283 // Note that there is no DW_AT_declaration and there are
6284 // no children, and the byte size is zero.
6285 is_forward_declaration = true;
6286 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006287
Sean Callanan7457f8d2012-04-25 01:03:57 +00006288 if (class_language == eLanguageTypeObjC ||
6289 class_language == eLanguageTypeObjC_plus_plus)
Greg Clayton18774842011-11-29 23:40:34 +00006290 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00006291 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
Greg Clayton901c5ca2011-12-03 04:40:03 +00006292 {
6293 // We have a valid eSymbolTypeObjCClass class symbol whose
6294 // name matches the current objective C class that we
6295 // are trying to find and this DIE isn't the complete
6296 // definition (we checked is_complete_objc_class above and
6297 // know it is false), so the real definition is in here somewhere
Greg Claytonc7f03b62012-01-12 04:33:28 +00006298 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006299
Greg Clayton1f746072012-08-29 21:13:06 +00006300 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton901c5ca2011-12-03 04:40:03 +00006301 {
6302 // We weren't able to find a full declaration in
6303 // this DWARF, see if we have a declaration anywhere
6304 // else...
Greg Claytonc7f03b62012-01-12 04:33:28 +00006305 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00006306 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006307
Greg Clayton901c5ca2011-12-03 04:40:03 +00006308 if (type_sp)
6309 {
6310 if (log)
6311 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006312 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00006313 "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 +00006314 static_cast<void*>(this),
Greg Claytone38a5ed2012-01-05 03:57:59 +00006315 die->GetOffset(),
6316 DW_TAG_value_to_name(tag),
6317 type_name_cstr,
6318 type_sp->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00006319 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006320
Greg Clayton901c5ca2011-12-03 04:40:03 +00006321 // We found a real definition for this type elsewhere
6322 // so lets use it and cache the fact that we found
6323 // a complete type for this die
6324 m_die_to_type[die] = type_sp.get();
6325 return type_sp;
6326 }
6327 }
6328 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006329
Greg Clayton901c5ca2011-12-03 04:40:03 +00006330
6331 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006332 {
6333 // We have a forward declaration to a type and we need
6334 // to try and find a full declaration. We look in the
6335 // current type index just in case we have a forward
6336 // declaration followed by an actual declarations in the
6337 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00006338 if (log)
6339 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006340 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00006341 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006342 static_cast<void*>(this),
Greg Claytone38a5ed2012-01-05 03:57:59 +00006343 die->GetOffset(),
6344 DW_TAG_value_to_name(tag),
6345 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00006346 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006347
Greg Claytona8022fa2012-04-24 21:22:41 +00006348 DWARFDeclContext die_decl_ctx;
6349 die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx);
6350
6351 //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
6352 type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006353
Greg Clayton1f746072012-08-29 21:13:06 +00006354 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton4272cc72011-02-02 02:24:04 +00006355 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006356 // We weren't able to find a full declaration in
6357 // this DWARF, see if we have a declaration anywhere
6358 // else...
Greg Claytona8022fa2012-04-24 21:22:41 +00006359 type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton4272cc72011-02-02 02:24:04 +00006360 }
6361
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006362 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00006363 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00006364 if (log)
6365 {
Greg Clayton5160ce52013-03-27 23:08:40 +00006366 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00006367 "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 +00006368 static_cast<void*>(this),
Greg Claytone38a5ed2012-01-05 03:57:59 +00006369 die->GetOffset(),
6370 DW_TAG_value_to_name(tag),
6371 type_name_cstr,
6372 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00006373 }
6374
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006375 // We found a real definition for this type elsewhere
6376 // so lets use it and cache the fact that we found
6377 // a complete type for this die
6378 m_die_to_type[die] = type_sp.get();
6379 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00006380 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006381 }
6382 assert (tag_decl_kind != -1);
6383 bool clang_type_was_created = false;
Greg Claytond8d4a572015-08-11 21:38:15 +00006384 clang_type.SetClangType(&ast, m_forward_decl_die_to_clang_type.lookup (die));
Greg Clayton57ee3062013-07-11 22:46:58 +00006385 if (!clang_type)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006386 {
Sean Callanan4d04c6a2012-02-09 22:54:11 +00006387 const DWARFDebugInfoEntry *decl_ctx_die;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006388
Sean Callanan4d04c6a2012-02-09 22:54:11 +00006389 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton55561e92011-10-26 03:31:36 +00006390 if (accessibility == eAccessNone && decl_ctx)
6391 {
6392 // Check the decl context that contains this class/struct/union.
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00006393 // If it is a class we must give it an accessibility.
Greg Clayton55561e92011-10-26 03:31:36 +00006394 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
6395 if (DeclKindIsCXXClass (containing_decl_kind))
6396 accessibility = default_accessibility;
6397 }
6398
Greg Claytonc4ffd662013-03-08 01:37:30 +00006399 ClangASTMetadata metadata;
6400 metadata.SetUserID(MakeUserID(die->GetOffset()));
6401 metadata.SetIsDynamicCXXType(ClassOrStructIsVirtual (dwarf_cu, die));
6402
Greg Claytonf0705c82011-10-22 03:33:13 +00006403 if (type_name_cstr && strchr (type_name_cstr, '<'))
6404 {
6405 ClangASTContext::TemplateParameterInfos template_param_infos;
6406 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
6407 {
6408 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00006409 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00006410 type_name_cstr,
6411 tag_decl_kind,
6412 template_param_infos);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006413
Greg Claytonf0705c82011-10-22 03:33:13 +00006414 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
6415 class_template_decl,
6416 tag_decl_kind,
6417 template_param_infos);
6418 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
6419 clang_type_was_created = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006420
Greg Claytond0029442013-03-27 01:48:02 +00006421 GetClangASTContext().SetMetadata (class_template_decl, metadata);
6422 GetClangASTContext().SetMetadata (class_specialization_decl, metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00006423 }
6424 }
6425
6426 if (!clang_type_was_created)
6427 {
6428 clang_type_was_created = true;
Greg Clayton55561e92011-10-26 03:31:36 +00006429 clang_type = ast.CreateRecordType (decl_ctx,
6430 accessibility,
6431 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00006432 tag_decl_kind,
Sean Callanan60217122012-04-13 00:10:03 +00006433 class_language,
Jim Ingham379397632012-10-27 02:54:13 +00006434 &metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00006435 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006436 }
6437
6438 // Store a forward declaration to this class type in case any
6439 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00006440 // types for function prototypes.
Greg Claytond8d4a572015-08-11 21:38:15 +00006441 LinkDeclContextToDIE(ast.GetDeclContextForType(clang_type), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00006442 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006443 this,
6444 type_name_const_str,
6445 byte_size,
6446 NULL,
6447 LLDB_INVALID_UID,
6448 Type::eEncodingIsUID,
6449 &decl,
6450 clang_type,
6451 Type::eResolveStateForward));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006452
Sean Callanan72772842012-02-22 23:57:45 +00006453 type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006454
6455
6456 // Add our type to the unique type map so we don't
6457 // end up creating many copies of the same type over
6458 // and over in the ASTContext for our module
Greg Claytond20deac2014-04-04 18:15:18 +00006459 unique_ast_entry_ap->m_type_sp = type_sp;
6460 unique_ast_entry_ap->m_symfile = this;
6461 unique_ast_entry_ap->m_cu = dwarf_cu;
6462 unique_ast_entry_ap->m_die = die;
6463 unique_ast_entry_ap->m_declaration = decl;
6464 unique_ast_entry_ap->m_byte_size = byte_size;
Greg Claytone576ab22011-02-15 00:19:15 +00006465 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
Greg Claytond20deac2014-04-04 18:15:18 +00006466 *unique_ast_entry_ap);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006467
Greg Clayton0ec71a02013-08-10 00:09:35 +00006468 if (is_forward_declaration && die->HasChildren())
6469 {
6470 // Check to see if the DIE actually has a definition, some version of GCC will
6471 // emit DIEs with DW_AT_declaration set to true, but yet still have subprogram,
6472 // members, or inheritance, so we can't trust it
6473 const DWARFDebugInfoEntry *child_die = die->GetFirstChild();
6474 while (child_die)
6475 {
6476 switch (child_die->Tag())
6477 {
6478 case DW_TAG_inheritance:
6479 case DW_TAG_subprogram:
6480 case DW_TAG_member:
6481 case DW_TAG_APPLE_property:
Greg Clayton4c484ec2014-02-07 19:21:56 +00006482 case DW_TAG_class_type:
6483 case DW_TAG_structure_type:
6484 case DW_TAG_enumeration_type:
6485 case DW_TAG_typedef:
6486 case DW_TAG_union_type:
Greg Clayton0ec71a02013-08-10 00:09:35 +00006487 child_die = NULL;
6488 is_forward_declaration = false;
6489 break;
6490 default:
6491 child_die = child_die->GetSibling();
6492 break;
6493 }
6494 }
6495 }
6496
Sean Callanan12014a02011-12-08 23:45:45 +00006497 if (!is_forward_declaration)
Greg Clayton219cf312012-03-30 00:51:13 +00006498 {
6499 // Always start the definition for a class type so that
6500 // if the class has child classes or types that require
6501 // the class to be created for use as their decl contexts
6502 // the class will be ready to accept these child definitions.
Sean Callanan12014a02011-12-08 23:45:45 +00006503 if (die->HasChildren() == false)
6504 {
6505 // No children for this struct/union/class, lets finish it
Greg Claytond8d4a572015-08-11 21:38:15 +00006506 ClangASTContext::StartTagDeclarationDefinition (clang_type);
6507 ClangASTContext::CompleteTagDeclarationDefinition (clang_type);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006508
Sean Callanan433cd222012-10-19 01:37:25 +00006509 if (tag == DW_TAG_structure_type) // this only applies in C
6510 {
Greg Claytond8d4a572015-08-11 21:38:15 +00006511 clang::RecordDecl *record_decl = ClangASTContext::GetAsRecordDecl(clang_type);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006512
Greg Clayton57ee3062013-07-11 22:46:58 +00006513 if (record_decl)
Greg Claytond20deac2014-04-04 18:15:18 +00006514 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, LayoutInfo()));
Sean Callanan433cd222012-10-19 01:37:25 +00006515 }
Sean Callanan12014a02011-12-08 23:45:45 +00006516 }
6517 else if (clang_type_was_created)
6518 {
Greg Clayton219cf312012-03-30 00:51:13 +00006519 // Start the definition if the class is not objective C since
6520 // the underlying decls respond to isCompleteDefinition(). Objective
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +00006521 // C decls don't respond to isCompleteDefinition() so we can't
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00006522 // start the declaration definition right away. For C++ class/union/structs
Greg Clayton219cf312012-03-30 00:51:13 +00006523 // we want to start the definition in case the class is needed as the
6524 // declaration context for a contained class or type without the need
6525 // to complete that type..
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006526
Sean Callanan7457f8d2012-04-25 01:03:57 +00006527 if (class_language != eLanguageTypeObjC &&
6528 class_language != eLanguageTypeObjC_plus_plus)
Greg Claytond8d4a572015-08-11 21:38:15 +00006529 ClangASTContext::StartTagDeclarationDefinition (clang_type);
Greg Clayton219cf312012-03-30 00:51:13 +00006530
Sean Callanan12014a02011-12-08 23:45:45 +00006531 // Leave this as a forward declaration until we need
6532 // to know the details of the type. lldb_private::Type
6533 // will automatically call the SymbolFile virtual function
6534 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
6535 // When the definition needs to be defined.
Greg Clayton57ee3062013-07-11 22:46:58 +00006536 m_forward_decl_die_to_clang_type[die] = clang_type.GetOpaqueQualType();
Greg Claytond8d4a572015-08-11 21:38:15 +00006537 m_forward_decl_clang_type_to_die[ClangASTContext::RemoveFastQualifiers(clang_type).GetOpaqueQualType()] = die;
6538 ast.SetHasExternalStorage (clang_type.GetOpaqueQualType(), true);
Sean Callanan12014a02011-12-08 23:45:45 +00006539 }
Greg Claytonc615ce42010-11-09 04:42:43 +00006540 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006541
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006542 }
6543 break;
6544
6545 case DW_TAG_enumeration_type:
6546 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006547 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006548 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006549
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006550 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006551
Greg Claytond88d7592010-09-15 08:33:30 +00006552 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006553 if (num_attributes > 0)
6554 {
6555 uint32_t i;
6556
6557 for (i=0; i<num_attributes; ++i)
6558 {
6559 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006560 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6561 {
6562 switch (attr)
6563 {
Greg Clayton7a345282010-11-09 23:46:37 +00006564 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6565 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6566 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006567 case DW_AT_name:
6568 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006569 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006570 break;
Greg Clayton54166af2014-11-22 01:58:59 +00006571 case DW_AT_type: encoding_uid = form_value.Reference(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006572 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
6573 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006574 case DW_AT_declaration: break; //is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006575 case DW_AT_allocated:
6576 case DW_AT_associated:
6577 case DW_AT_bit_stride:
6578 case DW_AT_byte_stride:
6579 case DW_AT_data_location:
6580 case DW_AT_description:
6581 case DW_AT_start_scope:
6582 case DW_AT_visibility:
6583 case DW_AT_specification:
6584 case DW_AT_abstract_origin:
6585 case DW_AT_sibling:
6586 break;
6587 }
6588 }
6589 }
6590
Daniel Malead01b2952012-11-29 21:49:15 +00006591 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 +00006592
Greg Claytona1e5dc82015-08-11 22:53:00 +00006593 CompilerType enumerator_clang_type;
Greg Claytond8d4a572015-08-11 21:38:15 +00006594 clang_type.SetClangType (&ast, m_forward_decl_die_to_clang_type.lookup (die));
Greg Clayton57ee3062013-07-11 22:46:58 +00006595 if (!clang_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00006596 {
Greg Clayton5d14fc02013-03-06 06:23:54 +00006597 if (encoding_uid != DW_INVALID_OFFSET)
6598 {
6599 Type *enumerator_type = ResolveTypeUID(encoding_uid);
6600 if (enumerator_type)
6601 enumerator_clang_type = enumerator_type->GetClangFullType();
6602 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006603
Greg Clayton57ee3062013-07-11 22:46:58 +00006604 if (!enumerator_clang_type)
Greg Clayton5d14fc02013-03-06 06:23:54 +00006605 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
6606 DW_ATE_signed,
6607 byte_size * 8);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006608
Greg Claytonca512b32011-01-14 04:54:56 +00006609 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00006610 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00006611 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006612 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00006613 }
6614 else
6615 {
Greg Claytond8d4a572015-08-11 21:38:15 +00006616 enumerator_clang_type = ast.GetEnumerationIntegerType (clang_type.GetOpaqueQualType());
Greg Clayton1be10fc2010-09-29 01:12:09 +00006617 }
6618
Greg Claytond8d4a572015-08-11 21:38:15 +00006619 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006620
Greg Clayton81c22f62011-10-19 18:09:39 +00006621 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006622 this,
6623 type_name_const_str,
6624 byte_size,
6625 NULL,
6626 encoding_uid,
6627 Type::eEncodingIsUID,
6628 &decl,
6629 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006630 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006631
Greg Claytond8d4a572015-08-11 21:38:15 +00006632 ClangASTContext::StartTagDeclarationDefinition (clang_type);
Greg Clayton6beaaa62011-01-17 03:46:26 +00006633 if (die->HasChildren())
6634 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006635 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00006636 bool is_signed = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00006637 enumerator_clang_type.IsIntegerType(is_signed);
Greg Clayton3e067532013-03-05 23:54:39 +00006638 ParseChildEnumerators(cu_sc, clang_type, is_signed, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00006639 }
Greg Claytond8d4a572015-08-11 21:38:15 +00006640 ClangASTContext::CompleteTagDeclarationDefinition (clang_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006641 }
6642 }
6643 break;
6644
Jim Inghamb0be4422010-08-12 01:20:14 +00006645 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006646 case DW_TAG_subprogram:
6647 case DW_TAG_subroutine_type:
6648 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006649 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006650 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006651
Greg Clayton23f59502012-07-17 03:23:13 +00006652 //const char *mangled = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006653 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00006654 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006655 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00006656 bool is_static = false;
6657 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00006658 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00006659 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00006660 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
6661 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Jim Ingham379397632012-10-27 02:54:13 +00006662 dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00006663
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006664 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00006665 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006666
6667
Greg Claytond88d7592010-09-15 08:33:30 +00006668 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006669 if (num_attributes > 0)
6670 {
6671 uint32_t i;
6672 for (i=0; i<num_attributes; ++i)
6673 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006674 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006675 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6676 {
6677 switch (attr)
6678 {
6679 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6680 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6681 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6682 case DW_AT_name:
6683 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006684 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006685 break;
6686
Greg Clayton71415542012-12-08 00:24:40 +00006687 case DW_AT_linkage_name:
Greg Clayton23f59502012-07-17 03:23:13 +00006688 case DW_AT_MIPS_linkage_name: break; // mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00006689 case DW_AT_type: type_die_offset = form_value.Reference(); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00006690 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006691 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
6692 case DW_AT_inline: is_inline = form_value.Boolean(); break;
6693 case DW_AT_virtuality: is_virtual = form_value.Boolean(); break;
6694 case DW_AT_explicit: is_explicit = form_value.Boolean(); break;
6695 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006696
Greg Claytonf51de672010-10-01 02:31:07 +00006697
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006698 case DW_AT_external:
6699 if (form_value.Unsigned())
6700 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00006701 if (storage == clang::SC_None)
6702 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006703 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00006704 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006705 }
6706 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006707
Greg Clayton72da3972011-08-16 18:40:23 +00006708 case DW_AT_specification:
Greg Clayton54166af2014-11-22 01:58:59 +00006709 specification_die_offset = form_value.Reference();
Greg Clayton72da3972011-08-16 18:40:23 +00006710 break;
6711
6712 case DW_AT_abstract_origin:
Greg Clayton54166af2014-11-22 01:58:59 +00006713 abstract_origin_die_offset = form_value.Reference();
Greg Clayton72da3972011-08-16 18:40:23 +00006714 break;
6715
Jim Ingham379397632012-10-27 02:54:13 +00006716 case DW_AT_object_pointer:
Greg Clayton54166af2014-11-22 01:58:59 +00006717 object_pointer_die_offset = form_value.Reference();
Jim Ingham379397632012-10-27 02:54:13 +00006718 break;
6719
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006720 case DW_AT_allocated:
6721 case DW_AT_associated:
6722 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006723 case DW_AT_calling_convention:
6724 case DW_AT_data_location:
6725 case DW_AT_elemental:
6726 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006727 case DW_AT_frame_base:
6728 case DW_AT_high_pc:
6729 case DW_AT_low_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006730 case DW_AT_prototyped:
6731 case DW_AT_pure:
6732 case DW_AT_ranges:
6733 case DW_AT_recursive:
6734 case DW_AT_return_addr:
6735 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006736 case DW_AT_start_scope:
6737 case DW_AT_static_link:
6738 case DW_AT_trampoline:
6739 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006740 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006741 case DW_AT_description:
6742 case DW_AT_sibling:
6743 break;
6744 }
6745 }
6746 }
Greg Clayton24739922010-10-13 03:15:28 +00006747 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006748
Jim Ingham379397632012-10-27 02:54:13 +00006749 std::string object_pointer_name;
6750 if (object_pointer_die_offset != DW_INVALID_OFFSET)
6751 {
6752 // Get the name from the object pointer die
6753 StreamString s;
6754 if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s))
6755 {
6756 object_pointer_name.assign(s.GetData());
6757 }
6758 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006759
Daniel Malead01b2952012-11-29 21:49:15 +00006760 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 +00006761
Greg Claytona1e5dc82015-08-11 22:53:00 +00006762 CompilerType return_clang_type;
Greg Clayton24739922010-10-13 03:15:28 +00006763 Type *func_type = NULL;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006764
Greg Clayton24739922010-10-13 03:15:28 +00006765 if (type_die_offset != DW_INVALID_OFFSET)
6766 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00006767
Greg Clayton24739922010-10-13 03:15:28 +00006768 if (func_type)
Greg Clayton42ce2f32011-12-12 21:50:19 +00006769 return_clang_type = func_type->GetClangForwardType();
Greg Clayton24739922010-10-13 03:15:28 +00006770 else
Greg Clayton57ee3062013-07-11 22:46:58 +00006771 return_clang_type = ast.GetBasicType(eBasicTypeVoid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006772
Greg Claytonf51de672010-10-01 02:31:07 +00006773
Greg Claytona1e5dc82015-08-11 22:53:00 +00006774 std::vector<CompilerType> function_param_types;
Greg Clayton24739922010-10-13 03:15:28 +00006775 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006776
Greg Clayton24739922010-10-13 03:15:28 +00006777 // Parse the function children for the parameters
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006778
Greg Claytoncb5860a2011-10-13 23:49:28 +00006779 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
6780 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00006781 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
6782
Greg Claytonf0705c82011-10-22 03:33:13 +00006783 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00006784 // Start off static. This will be set to false in ParseChildParameters(...)
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00006785 // if we find a "this" parameters as the first parameter
Greg Clayton5113dc82011-08-12 06:47:54 +00006786 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00006787 is_static = true;
Greg Claytond20deac2014-04-04 18:15:18 +00006788
Greg Clayton24739922010-10-13 03:15:28 +00006789 if (die->HasChildren())
6790 {
Greg Clayton0fffff52010-09-24 05:15:53 +00006791 bool skip_artificial = true;
Jim Ingham379397632012-10-27 02:54:13 +00006792 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00006793 containing_decl_ctx,
Jim Ingham379397632012-10-27 02:54:13 +00006794 dwarf_cu,
6795 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00006796 skip_artificial,
6797 is_static,
Greg Clayton03969752014-02-24 18:53:11 +00006798 is_variadic,
Jim Ingham379397632012-10-27 02:54:13 +00006799 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00006800 function_param_decls,
Greg Claytond20deac2014-04-04 18:15:18 +00006801 type_quals);
Greg Clayton24739922010-10-13 03:15:28 +00006802 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006803
Greg Clayton24739922010-10-13 03:15:28 +00006804 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006805 clang_type = ast.CreateFunctionType (return_clang_type,
Greg Clayton9cb25c42012-10-30 17:02:18 +00006806 function_param_types.data(),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006807 function_param_types.size(),
6808 is_variadic,
6809 type_quals);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006810
Sean Callanande9ce872013-05-09 23:13:13 +00006811 bool ignore_containing_context = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006812
Greg Clayton24739922010-10-13 03:15:28 +00006813 if (type_name_cstr)
6814 {
6815 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00006816 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006817 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00006818 ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true);
6819 if (objc_method.IsValid(true))
Greg Clayton0fffff52010-09-24 05:15:53 +00006820 {
Greg Claytona1e5dc82015-08-11 22:53:00 +00006821 CompilerType class_opaque_type;
Greg Clayton1b3815c2013-01-30 00:18:29 +00006822 ConstString class_name(objc_method.GetClassName());
Greg Clayton7c810422012-01-18 23:40:49 +00006823 if (class_name)
Greg Clayton0fffff52010-09-24 05:15:53 +00006824 {
Greg Clayton278a16b2012-01-19 00:52:59 +00006825 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
Greg Claytonc7f03b62012-01-12 04:33:28 +00006826
6827 if (complete_objc_class_type_sp)
Greg Clayton0fffff52010-09-24 05:15:53 +00006828 {
Greg Claytona1e5dc82015-08-11 22:53:00 +00006829 CompilerType type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
Greg Claytond8d4a572015-08-11 21:38:15 +00006830 if (ClangASTContext::IsObjCObjectOrInterfaceType(type_clang_forward_type))
Greg Claytonc7f03b62012-01-12 04:33:28 +00006831 class_opaque_type = type_clang_forward_type;
Greg Clayton0fffff52010-09-24 05:15:53 +00006832 }
Greg Clayton24739922010-10-13 03:15:28 +00006833 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006834
Greg Clayton24739922010-10-13 03:15:28 +00006835 if (class_opaque_type)
6836 {
6837 // If accessibility isn't set to anything valid, assume public for
6838 // now...
6839 if (accessibility == eAccessNone)
6840 accessibility = eAccessPublic;
6841
Greg Claytond8d4a572015-08-11 21:38:15 +00006842 clang::ObjCMethodDecl *objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
6843 type_name_cstr,
6844 clang_type,
6845 accessibility,
6846 is_artificial);
Greg Clayton24739922010-10-13 03:15:28 +00006847 type_handled = objc_method_decl != NULL;
Sean Callanan464a5b52012-10-04 22:06:29 +00006848 if (type_handled)
6849 {
6850 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Claytond0029442013-03-27 01:48:02 +00006851 GetClangASTContext().SetMetadataAsUserID (objc_method_decl, MakeUserID(die->GetOffset()));
Sean Callanan464a5b52012-10-04 22:06:29 +00006852 }
Sean Callananc3a1d562013-02-06 23:21:59 +00006853 else
6854 {
Jason Molendac1a65832013-03-07 22:44:42 +00006855 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 +00006856 die->GetOffset(),
6857 tag,
6858 DW_TAG_value_to_name(tag));
6859 }
Greg Clayton24739922010-10-13 03:15:28 +00006860 }
6861 }
Greg Clayton5113dc82011-08-12 06:47:54 +00006862 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00006863 {
6864 // Look at the parent of this DIE and see if is is
6865 // a class or struct and see if this is actually a
6866 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00006867 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00006868 if (class_type)
6869 {
Greg Clayton4116e932012-05-15 02:33:01 +00006870 if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset()))
6871 {
6872 // We uniqued the parent class of this function to another class
6873 // so we now need to associate all dies under "decl_ctx_die" to
6874 // DIEs in the DIE for "class_type"...
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006875 SymbolFileDWARF *class_symfile = NULL;
Greg Clayton4116e932012-05-15 02:33:01 +00006876 DWARFCompileUnitSP class_type_cu_sp;
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006877 const DWARFDebugInfoEntry *class_type_die = NULL;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006878
Sean Callanan2367f8a2013-02-26 01:12:25 +00006879 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
6880 if (debug_map_symfile)
6881 {
6882 class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID()));
6883 class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6884 }
6885 else
6886 {
6887 class_symfile = this;
6888 class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6889 }
Greg Clayton4116e932012-05-15 02:33:01 +00006890 if (class_type_die)
6891 {
Greg Claytond20deac2014-04-04 18:15:18 +00006892 DWARFDIECollection failures;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006893
Sean Callanan2367f8a2013-02-26 01:12:25 +00006894 CopyUniqueClassMethodTypes (class_symfile,
6895 class_type,
6896 class_type_cu_sp.get(),
6897 class_type_die,
6898 dwarf_cu,
6899 decl_ctx_die,
6900 failures);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006901
Sean Callanan2367f8a2013-02-26 01:12:25 +00006902 // FIXME do something with these failures that's smarter than
6903 // just dropping them on the ground. Unfortunately classes don't
6904 // like having stuff added to them after their definitions are
6905 // complete...
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006906
Sean Callanan2367f8a2013-02-26 01:12:25 +00006907 type_ptr = m_die_to_type[die];
6908 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton4116e932012-05-15 02:33:01 +00006909 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006910 type_sp = type_ptr->shared_from_this();
6911 break;
Greg Clayton4116e932012-05-15 02:33:01 +00006912 }
6913 }
6914 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006915
Greg Clayton72da3972011-08-16 18:40:23 +00006916 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00006917 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006918 // We have a specification which we are going to base our function
6919 // prototype off of, so we need this type to be completed so that the
6920 // m_die_to_decl_ctx for the method in the specification has a valid
6921 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006922 class_type->GetClangForwardType();
Greg Clayton72da3972011-08-16 18:40:23 +00006923 // If we have a specification, then the function type should have been
6924 // made with the specification and not with this die.
6925 DWARFCompileUnitSP spec_cu_sp;
6926 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006927 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006928 if (spec_clang_decl_ctx)
6929 {
6930 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
6931 }
6932 else
Jim Inghamc1663042011-09-29 22:12:35 +00006933 {
Daniel Malead01b2952012-11-29 21:49:15 +00006934 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8x) has no decl\n",
Greg Claytone38a5ed2012-01-05 03:57:59 +00006935 MakeUserID(die->GetOffset()),
6936 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006937 }
Greg Clayton72da3972011-08-16 18:40:23 +00006938 type_handled = true;
6939 }
6940 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
6941 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006942 // We have a specification which we are going to base our function
6943 // prototype off of, so we need this type to be completed so that the
6944 // m_die_to_decl_ctx for the method in the abstract origin has a valid
6945 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006946 class_type->GetClangForwardType();
Greg Clayton5cf58b92011-10-05 22:22:08 +00006947
Greg Clayton72da3972011-08-16 18:40:23 +00006948 DWARFCompileUnitSP abs_cu_sp;
6949 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006950 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006951 if (abs_clang_decl_ctx)
6952 {
6953 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
6954 }
6955 else
Jim Inghamc1663042011-09-29 22:12:35 +00006956 {
Daniel Malead01b2952012-11-29 21:49:15 +00006957 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 +00006958 MakeUserID(die->GetOffset()),
6959 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006960 }
Greg Clayton72da3972011-08-16 18:40:23 +00006961 type_handled = true;
6962 }
6963 else
6964 {
Greg Claytona1e5dc82015-08-11 22:53:00 +00006965 CompilerType class_opaque_type = class_type->GetClangForwardType();
Greg Claytond8d4a572015-08-11 21:38:15 +00006966 if (ClangASTContext::IsCXXClassType(class_opaque_type))
Greg Clayton931180e2011-01-27 06:44:37 +00006967 {
Greg Clayton57ee3062013-07-11 22:46:58 +00006968 if (class_opaque_type.IsBeingDefined ())
Greg Clayton72da3972011-08-16 18:40:23 +00006969 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006970 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
6971 // in the DWARF for C++ methods... Default to public for now...
6972 if (accessibility == eAccessNone)
6973 accessibility = eAccessPublic;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006974
Greg Clayton20568dd2011-10-13 23:13:20 +00006975 if (!is_static && !die->HasChildren())
6976 {
6977 // We have a C++ member function with no children (this pointer!)
6978 // and clang will get mad if we try and make a function that isn't
6979 // well formed in the DWARF, so we will just skip it...
6980 type_handled = true;
6981 }
6982 else
6983 {
6984 clang::CXXMethodDecl *cxx_method_decl;
6985 // REMOVE THE CRASH DESCRIPTION BELOW
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00006986 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 +00006987 type_name_cstr,
6988 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00006989 MakeUserID(die->GetOffset()),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00006990 m_obj_file->GetFileSpec().GetPath().c_str());
Greg Clayton20568dd2011-10-13 23:13:20 +00006991
Sean Callananc1b732d2011-11-01 18:07:13 +00006992 const bool is_attr_used = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00006993
Greg Claytond8d4a572015-08-11 21:38:15 +00006994 cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type.GetOpaqueQualType(),
6995 type_name_cstr,
6996 clang_type,
6997 accessibility,
6998 is_virtual,
6999 is_static,
7000 is_inline,
7001 is_explicit,
7002 is_attr_used,
7003 is_artificial);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007004
Greg Clayton20568dd2011-10-13 23:13:20 +00007005 type_handled = cxx_method_decl != NULL;
Sean Callanan4ac7ec72012-10-31 02:01:58 +00007006
7007 if (type_handled)
Jim Ingham379397632012-10-27 02:54:13 +00007008 {
Sean Callanan4ac7ec72012-10-31 02:01:58 +00007009 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
7010
7011 Host::SetCrashDescription (NULL);
7012
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007013
Sean Callanan4ac7ec72012-10-31 02:01:58 +00007014 ClangASTMetadata metadata;
7015 metadata.SetUserID(MakeUserID(die->GetOffset()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007016
Sean Callanan4ac7ec72012-10-31 02:01:58 +00007017 if (!object_pointer_name.empty())
7018 {
7019 metadata.SetObjectPtrName(object_pointer_name.c_str());
7020 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00007021 log->Printf ("Setting object pointer name: %s on method object %p.\n",
Sean Callanan4ac7ec72012-10-31 02:01:58 +00007022 object_pointer_name.c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007023 static_cast<void*>(cxx_method_decl));
Sean Callanan4ac7ec72012-10-31 02:01:58 +00007024 }
Greg Claytond0029442013-03-27 01:48:02 +00007025 GetClangASTContext().SetMetadata (cxx_method_decl, metadata);
Jim Ingham379397632012-10-27 02:54:13 +00007026 }
Sean Callananb0640dc2013-04-09 23:22:08 +00007027 else
7028 {
Sean Callanande9ce872013-05-09 23:13:13 +00007029 ignore_containing_context = true;
Sean Callananb0640dc2013-04-09 23:22:08 +00007030 }
Greg Clayton20568dd2011-10-13 23:13:20 +00007031 }
Greg Clayton72da3972011-08-16 18:40:23 +00007032 }
7033 else
7034 {
Greg Clayton20568dd2011-10-13 23:13:20 +00007035 // We were asked to parse the type for a method in a class, yet the
7036 // class hasn't been asked to complete itself through the
7037 // clang::ExternalASTSource protocol, so we need to just have the
7038 // class complete itself and do things the right way, then our
7039 // DIE should then have an entry in the m_die_to_type map. First
7040 // we need to modify the m_die_to_type so it doesn't think we are
7041 // trying to parse this DIE anymore...
7042 m_die_to_type[die] = NULL;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007043
Greg Clayton20568dd2011-10-13 23:13:20 +00007044 // Now we get the full type to force our class type to complete itself
7045 // using the clang::ExternalASTSource protocol which will parse all
7046 // base classes and all methods (including the method for this DIE).
7047 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00007048
Greg Clayton20568dd2011-10-13 23:13:20 +00007049 // The type for this DIE should have been filled in the function call above
7050 type_ptr = m_die_to_type[die];
Greg Claytone5476db2012-06-01 20:32:35 +00007051 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton20568dd2011-10-13 23:13:20 +00007052 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00007053 type_sp = type_ptr->shared_from_this();
Greg Clayton20568dd2011-10-13 23:13:20 +00007054 break;
7055 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007056
Sean Callanan02eee4d2012-04-12 23:10:00 +00007057 // FIXME This is fixing some even uglier behavior but we really need to
7058 // uniq the methods of each class as well as the class itself.
7059 // <rdar://problem/11240464>
7060 type_handled = true;
Greg Clayton72da3972011-08-16 18:40:23 +00007061 }
Greg Clayton931180e2011-01-27 06:44:37 +00007062 }
Greg Clayton0fffff52010-09-24 05:15:53 +00007063 }
7064 }
Greg Clayton0fffff52010-09-24 05:15:53 +00007065 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007066 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007067
Greg Clayton24739922010-10-13 03:15:28 +00007068 if (!type_handled)
7069 {
7070 // We just have a function that isn't part of a class
Sean Callanande9ce872013-05-09 23:13:13 +00007071 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (ignore_containing_context ? GetClangASTContext().GetTranslationUnitDecl() : containing_decl_ctx,
Greg Clayton147e1fa2011-10-14 22:47:18 +00007072 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00007073 clang_type,
7074 storage,
7075 is_inline);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00007076
7077// if (template_param_infos.GetSize() > 0)
7078// {
7079// clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
7080// function_decl,
7081// type_name_cstr,
7082// template_param_infos);
7083//
7084// ast.CreateFunctionTemplateSpecializationInfo (function_decl,
7085// func_template_decl,
7086// template_param_infos);
7087// }
Greg Clayton24739922010-10-13 03:15:28 +00007088 // Add the decl to our DIE to decl context map
7089 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00007090 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00007091 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00007092 ast.SetFunctionParameters (function_decl,
7093 &function_param_decls.front(),
7094 function_param_decls.size());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007095
Jim Ingham379397632012-10-27 02:54:13 +00007096 ClangASTMetadata metadata;
7097 metadata.SetUserID(MakeUserID(die->GetOffset()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007098
Jim Ingham379397632012-10-27 02:54:13 +00007099 if (!object_pointer_name.empty())
7100 {
7101 metadata.SetObjectPtrName(object_pointer_name.c_str());
Jim Ingham2cffda3f2012-10-30 23:34:07 +00007102 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00007103 log->Printf ("Setting object pointer name: %s on function object %p.",
Jim Ingham2cffda3f2012-10-30 23:34:07 +00007104 object_pointer_name.c_str(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007105 static_cast<void*>(function_decl));
Jim Ingham379397632012-10-27 02:54:13 +00007106 }
Greg Claytond0029442013-03-27 01:48:02 +00007107 GetClangASTContext().SetMetadata (function_decl, metadata);
Greg Clayton24739922010-10-13 03:15:28 +00007108 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007109 }
Greg Clayton81c22f62011-10-19 18:09:39 +00007110 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00007111 this,
7112 type_name_const_str,
7113 0,
7114 NULL,
7115 LLDB_INVALID_UID,
7116 Type::eEncodingIsUID,
7117 &decl,
7118 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00007119 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00007120 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007121 }
7122 break;
7123
7124 case DW_TAG_array_type:
7125 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007126 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00007127 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007128
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007129 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007130 int64_t first_index = 0;
7131 uint32_t byte_stride = 0;
7132 uint32_t bit_stride = 0;
Greg Clayton1c8ef472013-04-05 23:27:21 +00007133 bool is_vector = false;
Greg Claytond88d7592010-09-15 08:33:30 +00007134 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007135
7136 if (num_attributes > 0)
7137 {
7138 uint32_t i;
7139 for (i=0; i<num_attributes; ++i)
7140 {
7141 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007142 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
7143 {
7144 switch (attr)
7145 {
7146 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
7147 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
7148 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
7149 case DW_AT_name:
7150 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00007151 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007152 break;
7153
Greg Clayton54166af2014-11-22 01:58:59 +00007154 case DW_AT_type: type_die_offset = form_value.Reference(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00007155 case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007156 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
7157 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00007158 case DW_AT_GNU_vector: is_vector = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00007159 case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00007160 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007161 case DW_AT_allocated:
7162 case DW_AT_associated:
7163 case DW_AT_data_location:
7164 case DW_AT_description:
7165 case DW_AT_ordering:
7166 case DW_AT_start_scope:
7167 case DW_AT_visibility:
7168 case DW_AT_specification:
7169 case DW_AT_abstract_origin:
7170 case DW_AT_sibling:
7171 break;
7172 }
7173 }
7174 }
7175
Daniel Malead01b2952012-11-29 21:49:15 +00007176 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 +00007177
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007178 Type *element_type = ResolveTypeUID(type_die_offset);
7179
7180 if (element_type)
7181 {
7182 std::vector<uint64_t> element_orders;
7183 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
7184 if (byte_stride == 0 && bit_stride == 0)
7185 byte_stride = element_type->GetByteSize();
Greg Claytona1e5dc82015-08-11 22:53:00 +00007186 CompilerType array_element_type = element_type->GetClangForwardType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007187 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
Siva Chandra89ce9552015-01-05 23:06:14 +00007188 if (element_orders.size() > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007189 {
Siva Chandra89ce9552015-01-05 23:06:14 +00007190 uint64_t num_elements = 0;
7191 std::vector<uint64_t>::const_reverse_iterator pos;
7192 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
7193 for (pos = element_orders.rbegin(); pos != end; ++pos)
7194 {
7195 num_elements = *pos;
7196 clang_type = ast.CreateArrayType (array_element_type,
7197 num_elements,
7198 is_vector);
7199 array_element_type = clang_type;
7200 array_element_bit_stride = num_elements ?
7201 array_element_bit_stride * num_elements :
7202 array_element_bit_stride;
7203 }
7204 }
7205 else
7206 {
7207 clang_type = ast.CreateArrayType (array_element_type, 0, is_vector);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007208 }
7209 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00007210 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00007211 this,
7212 empty_name,
7213 array_element_bit_stride / 8,
7214 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00007215 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00007216 Type::eEncodingIsUID,
7217 &decl,
7218 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00007219 Type::eResolveStateFull));
7220 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007221 }
7222 }
7223 }
7224 break;
7225
Greg Clayton9b81a312010-06-12 01:20:30 +00007226 case DW_TAG_ptr_to_member_type:
7227 {
7228 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
7229 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
7230
Greg Claytond88d7592010-09-15 08:33:30 +00007231 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007232
Greg Clayton9b81a312010-06-12 01:20:30 +00007233 if (num_attributes > 0) {
7234 uint32_t i;
7235 for (i=0; i<num_attributes; ++i)
7236 {
7237 attr = attributes.AttributeAtIndex(i);
Greg Clayton9b81a312010-06-12 01:20:30 +00007238 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
7239 {
7240 switch (attr)
7241 {
7242 case DW_AT_type:
Greg Clayton54166af2014-11-22 01:58:59 +00007243 type_die_offset = form_value.Reference(); break;
Greg Clayton9b81a312010-06-12 01:20:30 +00007244 case DW_AT_containing_type:
Greg Clayton54166af2014-11-22 01:58:59 +00007245 containing_type_die_offset = form_value.Reference(); break;
Greg Clayton9b81a312010-06-12 01:20:30 +00007246 }
7247 }
7248 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007249
Greg Clayton9b81a312010-06-12 01:20:30 +00007250 Type *pointee_type = ResolveTypeUID(type_die_offset);
7251 Type *class_type = ResolveTypeUID(containing_type_die_offset);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007252
Greg Claytona1e5dc82015-08-11 22:53:00 +00007253 CompilerType pointee_clang_type = pointee_type->GetClangForwardType();
7254 CompilerType class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00007255
Greg Claytond8d4a572015-08-11 21:38:15 +00007256 clang_type = ClangASTContext::CreateMemberPointerType(pointee_clang_type, class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00007257
Enrico Granata1cd5e922015-01-28 00:07:51 +00007258 byte_size = clang_type.GetByteSize(nullptr);
Greg Clayton9b81a312010-06-12 01:20:30 +00007259
Greg Clayton81c22f62011-10-19 18:09:39 +00007260 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00007261 this,
7262 type_name_const_str,
7263 byte_size,
7264 NULL,
7265 LLDB_INVALID_UID,
7266 Type::eEncodingIsUID,
7267 NULL,
7268 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00007269 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00007270 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00007271
Greg Clayton9b81a312010-06-12 01:20:30 +00007272 break;
7273 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007274 default:
Greg Clayton84afacd2012-11-07 23:09:32 +00007275 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",
7276 die->GetOffset(),
7277 tag,
7278 DW_TAG_value_to_name(tag));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007279 break;
7280 }
7281
7282 if (type_sp.get())
7283 {
7284 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7285 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7286
7287 SymbolContextScope * symbol_context_scope = NULL;
7288 if (sc_parent_tag == DW_TAG_compile_unit)
7289 {
7290 symbol_context_scope = sc.comp_unit;
7291 }
Jason Molenda60db6e42014-10-16 01:40:16 +00007292 else if (sc.function != NULL && sc_parent_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007293 {
Greg Clayton81c22f62011-10-19 18:09:39 +00007294 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007295 if (symbol_context_scope == NULL)
7296 symbol_context_scope = sc.function;
7297 }
7298
7299 if (symbol_context_scope != NULL)
7300 {
7301 type_sp->SetSymbolContextScope(symbol_context_scope);
7302 }
7303
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00007304 // We are ready to put this type into the uniqued list up at the module level
7305 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00007306
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00007307 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007308 }
7309 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00007310 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007311 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00007312 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007313 }
7314 }
7315 return type_sp;
7316}
7317
7318size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00007319SymbolFileDWARF::ParseTypes
7320(
7321 const SymbolContext& sc,
7322 DWARFCompileUnit* dwarf_cu,
7323 const DWARFDebugInfoEntry *die,
7324 bool parse_siblings,
7325 bool parse_children
7326)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007327{
7328 size_t types_added = 0;
7329 while (die != NULL)
7330 {
7331 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00007332 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007333 {
7334 if (type_is_new)
7335 ++types_added;
7336 }
7337
7338 if (parse_children && die->HasChildren())
7339 {
7340 if (die->Tag() == DW_TAG_subprogram)
7341 {
7342 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00007343 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007344 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
7345 }
7346 else
7347 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
7348 }
7349
7350 if (parse_siblings)
7351 die = die->GetSibling();
7352 else
7353 die = NULL;
7354 }
7355 return types_added;
7356}
7357
7358
7359size_t
7360SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
7361{
7362 assert(sc.comp_unit && sc.function);
7363 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00007364 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007365 if (dwarf_cu)
7366 {
7367 dw_offset_t function_die_offset = sc.function->GetID();
7368 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
7369 if (function_die)
7370 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00007371 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007372 }
7373 }
7374
7375 return functions_added;
7376}
7377
7378
7379size_t
7380SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
7381{
7382 // At least a compile unit must be valid
7383 assert(sc.comp_unit);
7384 size_t types_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00007385 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007386 if (dwarf_cu)
7387 {
7388 if (sc.function)
7389 {
7390 dw_offset_t function_die_offset = sc.function->GetID();
7391 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
7392 if (func_die && func_die->HasChildren())
7393 {
7394 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
7395 }
7396 }
7397 else
7398 {
7399 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
7400 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
7401 {
7402 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
7403 }
7404 }
7405 }
7406
7407 return types_added;
7408}
7409
7410size_t
7411SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
7412{
7413 if (sc.comp_unit != NULL)
7414 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00007415 DWARFDebugInfo* info = DebugInfo();
7416 if (info == NULL)
7417 return 0;
7418
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007419 if (sc.function)
7420 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007421 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get();
7422
7423 if (dwarf_cu == NULL)
7424 return 0;
7425
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007426 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00007427
Greg Claytonc7bece562013-01-25 18:06:21 +00007428 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
7429 if (func_lo_pc != LLDB_INVALID_ADDRESS)
Greg Claytone38a5ed2012-01-05 03:57:59 +00007430 {
7431 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00007432
Greg Claytone38a5ed2012-01-05 03:57:59 +00007433 // Let all blocks know they have parse all their variables
7434 sc.function->GetBlock (false).SetDidParseVariables (true, true);
7435 return num_variables;
7436 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007437 }
7438 else if (sc.comp_unit)
7439 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007440 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get();
7441
7442 if (dwarf_cu == NULL)
7443 return 0;
7444
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007445 uint32_t vars_added = 0;
7446 VariableListSP variables (sc.comp_unit->GetVariableList(false));
7447
7448 if (variables.get() == NULL)
7449 {
7450 variables.reset(new VariableList());
7451 sc.comp_unit->SetVariableList(variables);
7452
Greg Claytond4a2b372011-09-12 23:21:58 +00007453 DWARFCompileUnit* match_dwarf_cu = NULL;
7454 const DWARFDebugInfoEntry* die = NULL;
7455 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00007456 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00007457 {
Greg Clayton97fbc342011-10-20 22:30:33 +00007458 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00007459 {
7460 DWARFMappedHash::DIEInfoArray hash_data_array;
7461 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
7462 dwarf_cu->GetNextCompileUnitOffset(),
7463 hash_data_array))
7464 {
7465 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
7466 }
7467 }
Greg Clayton7f995132011-10-04 22:41:51 +00007468 }
7469 else
7470 {
7471 // Index if we already haven't to make sure the compile units
7472 // get indexed and make their global DIE index list
7473 if (!m_indexed)
7474 Index ();
7475
7476 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
7477 dwarf_cu->GetNextCompileUnitOffset(),
7478 die_offsets);
7479 }
7480
7481 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00007482 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007483 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007484 DWARFDebugInfo* debug_info = DebugInfo();
7485 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007486 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007487 const dw_offset_t die_offset = die_offsets[i];
7488 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00007489 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00007490 {
Greg Clayton95d87902011-11-11 03:16:25 +00007491 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
7492 if (var_sp)
7493 {
7494 variables->AddVariableIfUnique (var_sp);
7495 ++vars_added;
7496 }
Greg Claytond4a2b372011-09-12 23:21:58 +00007497 }
Greg Clayton95d87902011-11-11 03:16:25 +00007498 else
7499 {
7500 if (m_using_apple_tables)
7501 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00007502 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 +00007503 }
7504 }
7505
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007506 }
7507 }
7508 }
7509 return vars_added;
7510 }
7511 }
7512 return 0;
7513}
7514
7515
7516VariableSP
7517SymbolFileDWARF::ParseVariableDIE
7518(
7519 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007520 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007521 const DWARFDebugInfoEntry *die,
7522 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007523)
7524{
Greg Clayton83c5cd92010-11-14 22:13:40 +00007525 VariableSP var_sp (m_die_to_variable_sp[die]);
7526 if (var_sp)
7527 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007528
7529 const dw_tag_t tag = die->Tag();
Richard Mitton0a558352013-10-17 21:14:00 +00007530 ModuleSP module = GetObjectFile()->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00007531
7532 if ((tag == DW_TAG_variable) ||
7533 (tag == DW_TAG_constant) ||
7534 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007535 {
Greg Clayton7f995132011-10-04 22:41:51 +00007536 DWARFDebugInfoEntry::Attributes attributes;
7537 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
7538 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007539 {
Greg Clayton7f995132011-10-04 22:41:51 +00007540 const char *name = NULL;
7541 const char *mangled = NULL;
7542 Declaration decl;
7543 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00007544 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00007545 DWARFExpression location;
7546 bool is_external = false;
7547 bool is_artificial = false;
7548 bool location_is_const_value_data = false;
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007549 bool has_explicit_location = false;
Enrico Granata4ec130d2014-08-11 19:16:35 +00007550 DWARFFormValue const_value;
Greg Clayton23f59502012-07-17 03:23:13 +00007551 //AccessType accessibility = eAccessNone;
Greg Clayton7f995132011-10-04 22:41:51 +00007552
7553 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007554 {
Greg Clayton7f995132011-10-04 22:41:51 +00007555 dw_attr_t attr = attributes.AttributeAtIndex(i);
7556 DWARFFormValue form_value;
Greg Clayton54166af2014-11-22 01:58:59 +00007557
Greg Clayton7f995132011-10-04 22:41:51 +00007558 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007559 {
Greg Clayton7f995132011-10-04 22:41:51 +00007560 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007561 {
Greg Clayton7f995132011-10-04 22:41:51 +00007562 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
7563 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
7564 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
7565 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton71415542012-12-08 00:24:40 +00007566 case DW_AT_linkage_name:
Greg Clayton7f995132011-10-04 22:41:51 +00007567 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00007568 case DW_AT_type: type_uid = form_value.Reference(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00007569 case DW_AT_external: is_external = form_value.Boolean(); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007570 case DW_AT_const_value:
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007571 // If we have already found a DW_AT_location attribute, ignore this attribute.
7572 if (!has_explicit_location)
7573 {
7574 location_is_const_value_data = true;
7575 // The constant value will be either a block, a data value or a string.
Ed Masteeeae7212013-10-24 20:43:47 +00007576 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007577 if (DWARFFormValue::IsBlockForm(form_value.Form()))
7578 {
7579 // Retrieve the value as a block expression.
7580 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7581 uint32_t block_length = form_value.Unsigned();
Richard Mitton0a558352013-10-17 21:14:00 +00007582 location.CopyOpcodeData(module, debug_info_data, block_offset, block_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007583 }
7584 else if (DWARFFormValue::IsDataForm(form_value.Form()))
7585 {
7586 // Retrieve the value as a data expression.
Greg Clayton54166af2014-11-22 01:58:59 +00007587 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (attributes.CompileUnitAtIndex(i)->GetAddressByteSize(), attributes.CompileUnitAtIndex(i)->IsDWARF64());
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007588 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7589 uint32_t data_length = fixed_form_sizes[form_value.Form()];
Enrico Granata4ec130d2014-08-11 19:16:35 +00007590 if (data_length == 0)
7591 {
7592 const uint8_t *data_pointer = form_value.BlockData();
7593 if (data_pointer)
7594 {
Jason Molenda18f5fd32014-10-16 07:52:17 +00007595 form_value.Unsigned();
Enrico Granata4ec130d2014-08-11 19:16:35 +00007596 }
7597 else if (DWARFFormValue::IsDataForm(form_value.Form()))
7598 {
7599 // we need to get the byte size of the type later after we create the variable
7600 const_value = form_value;
7601 }
7602 }
7603 else
7604 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007605 }
7606 else
7607 {
7608 // Retrieve the value as a string expression.
7609 if (form_value.Form() == DW_FORM_strp)
7610 {
Greg Clayton54166af2014-11-22 01:58:59 +00007611 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (attributes.CompileUnitAtIndex(i)->GetAddressByteSize(), attributes.CompileUnitAtIndex(i)->IsDWARF64());
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007612 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7613 uint32_t data_length = fixed_form_sizes[form_value.Form()];
Richard Mitton0a558352013-10-17 21:14:00 +00007614 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007615 }
7616 else
7617 {
7618 const char *str = form_value.AsCString(&debug_info_data);
7619 uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart();
7620 uint32_t string_length = strlen(str) + 1;
Richard Mitton0a558352013-10-17 21:14:00 +00007621 location.CopyOpcodeData(module, debug_info_data, string_offset, string_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007622 }
7623 }
7624 }
7625 break;
Greg Clayton7f995132011-10-04 22:41:51 +00007626 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007627 {
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007628 location_is_const_value_data = false;
7629 has_explicit_location = true;
Greg Clayton7f995132011-10-04 22:41:51 +00007630 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007631 {
Ed Masteeeae7212013-10-24 20:43:47 +00007632 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Clayton7f995132011-10-04 22:41:51 +00007633
7634 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7635 uint32_t block_length = form_value.Unsigned();
Richard Mitton0a558352013-10-17 21:14:00 +00007636 location.CopyOpcodeData(module, get_debug_info_data(), block_offset, block_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007637 }
7638 else
7639 {
Ed Masteeeae7212013-10-24 20:43:47 +00007640 const DWARFDataExtractor& debug_loc_data = get_debug_loc_data();
Greg Clayton7f995132011-10-04 22:41:51 +00007641 const dw_offset_t debug_loc_offset = form_value.Unsigned();
7642
7643 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
7644 if (loc_list_length > 0)
7645 {
Richard Mitton0a558352013-10-17 21:14:00 +00007646 location.CopyOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007647 assert (func_low_pc != LLDB_INVALID_ADDRESS);
Greg Clayton54166af2014-11-22 01:58:59 +00007648 location.SetLocationListSlide (func_low_pc - attributes.CompileUnitAtIndex(i)->GetBaseAddress());
Greg Clayton7f995132011-10-04 22:41:51 +00007649 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007650 }
7651 }
Greg Clayton7f995132011-10-04 22:41:51 +00007652 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007653
Greg Clayton1c8ef472013-04-05 23:27:21 +00007654 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00007655 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007656 case DW_AT_declaration:
7657 case DW_AT_description:
7658 case DW_AT_endianity:
7659 case DW_AT_segment:
7660 case DW_AT_start_scope:
7661 case DW_AT_visibility:
7662 default:
7663 case DW_AT_abstract_origin:
7664 case DW_AT_sibling:
7665 case DW_AT_specification:
7666 break;
7667 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007668 }
7669 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007670
Greg Clayton9e9f2192013-05-17 00:55:28 +00007671 ValueType scope = eValueTypeInvalid;
7672
7673 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7674 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7675 SymbolContextScope * symbol_context_scope = NULL;
7676
Siva Chandra0783ab92015-03-24 18:32:27 +00007677 if (!mangled)
7678 {
7679 // LLDB relies on the mangled name (DW_TAG_linkage_name or DW_AT_MIPS_linkage_name) to
7680 // generate fully qualified names of global variables with commands like "frame var j".
7681 // For example, if j were an int variable holding a value 4 and declared in a namespace
7682 // B which in turn is contained in a namespace A, the command "frame var j" returns
7683 // "(int) A::B::j = 4". If the compiler does not emit a linkage name, we should be able
7684 // to generate a fully qualified name from the declaration context.
7685 if (die->GetParent()->Tag() == DW_TAG_compile_unit &&
7686 LanguageRuntime::LanguageIsCPlusPlus(dwarf_cu->GetLanguageType()))
7687 {
7688 DWARFDeclContext decl_ctx;
7689
7690 die->GetDWARFDeclContext(this, dwarf_cu, decl_ctx);
7691 mangled = decl_ctx.GetQualifiedNameAsConstString().GetCString();
7692 }
7693 }
7694
Greg Clayton9e9f2192013-05-17 00:55:28 +00007695 // DWARF doesn't specify if a DW_TAG_variable is a local, global
7696 // or static variable, so we have to do a little digging by
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00007697 // looking at the location of a variable to see if it contains
Greg Clayton9e9f2192013-05-17 00:55:28 +00007698 // a DW_OP_addr opcode _somewhere_ in the definition. I say
7699 // somewhere because clang likes to combine small global variables
7700 // into the same symbol and have locations like:
7701 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
7702 // So if we don't have a DW_TAG_formal_parameter, we can look at
7703 // the location to see if it contains a DW_OP_addr opcode, and
7704 // then we can correctly classify our variables.
7705 if (tag == DW_TAG_formal_parameter)
7706 scope = eValueTypeVariableArgument;
7707 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007708 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007709 bool op_error = false;
7710 // Check if the location has a DW_OP_addr with any address value...
7711 lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS;
7712 if (!location_is_const_value_data)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007713 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007714 location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error);
7715 if (op_error)
Greg Clayton96c09682012-01-04 22:56:43 +00007716 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007717 StreamString strm;
7718 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
7719 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 +00007720 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007721 }
Greg Claytond1767f02011-12-08 02:13:16 +00007722
Greg Clayton9e9f2192013-05-17 00:55:28 +00007723 if (location_DW_OP_addr != LLDB_INVALID_ADDRESS)
7724 {
7725 if (is_external)
7726 scope = eValueTypeVariableGlobal;
7727 else
7728 scope = eValueTypeVariableStatic;
7729
7730
7731 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile ();
7732
7733 if (debug_map_symfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007734 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007735 // When leaving the DWARF in the .o files on darwin,
7736 // when we have a global variable that wasn't initialized,
7737 // the .o file might not have allocated a virtual
7738 // address for the global variable. In this case it will
7739 // have created a symbol for the global variable
7740 // that is undefined/data and external and the value will
7741 // be the byte size of the variable. When we do the
7742 // address map in SymbolFileDWARFDebugMap we rely on
7743 // having an address, we need to do some magic here
7744 // so we can get the correct address for our global
7745 // variable. The address for all of these entries
7746 // will be zero, and there will be an undefined symbol
7747 // in this object file, and the executable will have
7748 // a matching symbol with a good address. So here we
7749 // dig up the correct address and replace it in the
7750 // location for the variable, and set the variable's
7751 // symbol context scope to be that of the main executable
7752 // so the file address will resolve correctly.
7753 bool linked_oso_file_addr = false;
7754 if (is_external && location_DW_OP_addr == 0)
Greg Clayton9422dd62013-03-04 21:46:16 +00007755 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007756 // we have a possible uninitialized extern global
7757 ConstString const_name(mangled ? mangled : name);
7758 ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile();
7759 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007760 {
Greg Clayton3046e662013-07-10 01:23:25 +00007761 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
Greg Clayton9e9f2192013-05-17 00:55:28 +00007762 if (debug_map_symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007763 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007764 Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
7765 eSymbolTypeData,
7766 Symtab::eDebugYes,
7767 Symtab::eVisibilityExtern);
7768 if (exe_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007769 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007770 if (exe_symbol->ValueIsAddress())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007771 {
Greg Clayton358cf1e2015-06-25 21:46:34 +00007772 const addr_t exe_file_addr = exe_symbol->GetAddressRef().GetFileAddress();
Greg Clayton9e9f2192013-05-17 00:55:28 +00007773 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007774 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007775 if (location.Update_DW_OP_addr (exe_file_addr))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007776 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007777 linked_oso_file_addr = true;
7778 symbol_context_scope = exe_symbol;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007779 }
7780 }
7781 }
7782 }
7783 }
7784 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007785 }
Greg Clayton9422dd62013-03-04 21:46:16 +00007786
Greg Clayton9e9f2192013-05-17 00:55:28 +00007787 if (!linked_oso_file_addr)
7788 {
7789 // The DW_OP_addr is not zero, but it contains a .o file address which
7790 // needs to be linked up correctly.
7791 const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr);
7792 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton9422dd62013-03-04 21:46:16 +00007793 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007794 // Update the file address for this variable
7795 location.Update_DW_OP_addr (exe_file_addr);
7796 }
7797 else
7798 {
7799 // Variable didn't make it into the final executable
7800 return var_sp;
Greg Clayton9422dd62013-03-04 21:46:16 +00007801 }
Greg Claytond1767f02011-12-08 02:13:16 +00007802 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007803 }
Greg Clayton5cf58b92011-10-05 22:22:08 +00007804 }
7805 else
7806 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00007807 scope = eValueTypeVariableLocal;
Greg Clayton5cf58b92011-10-05 22:22:08 +00007808 }
Greg Clayton7f995132011-10-04 22:41:51 +00007809 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00007810
7811 if (symbol_context_scope == NULL)
7812 {
7813 switch (parent_tag)
7814 {
7815 case DW_TAG_subprogram:
7816 case DW_TAG_inlined_subroutine:
7817 case DW_TAG_lexical_block:
7818 if (sc.function)
7819 {
7820 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
7821 if (symbol_context_scope == NULL)
7822 symbol_context_scope = sc.function;
7823 }
7824 break;
7825
7826 default:
7827 symbol_context_scope = sc.comp_unit;
7828 break;
7829 }
7830 }
7831
7832 if (symbol_context_scope)
7833 {
Enrico Granata4ec130d2014-08-11 19:16:35 +00007834 SymbolFileTypeSP type_sp(new SymbolFileType(*this, type_uid));
7835
7836 if (const_value.Form() && type_sp && type_sp->GetType())
7837 location.CopyOpcodeData(const_value.Unsigned(), type_sp->GetType()->GetByteSize(), dwarf_cu->GetAddressByteSize());
7838
Greg Clayton9e9f2192013-05-17 00:55:28 +00007839 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
7840 name,
7841 mangled,
Enrico Granata4ec130d2014-08-11 19:16:35 +00007842 type_sp,
Greg Clayton9e9f2192013-05-17 00:55:28 +00007843 scope,
7844 symbol_context_scope,
7845 &decl,
7846 location,
7847 is_external,
7848 is_artificial));
7849
7850 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
7851 }
7852 else
7853 {
7854 // Not ready to parse this variable yet. It might be a global
7855 // or static variable that is in a function scope and the function
7856 // in the symbol context wasn't filled in yet
7857 return var_sp;
7858 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007859 }
Greg Clayton7f995132011-10-04 22:41:51 +00007860 // Cache var_sp even if NULL (the variable was just a specification or
7861 // was missing vital information to be able to be displayed in the debugger
7862 // (missing location due to optimization, etc)) so we don't re-parse
7863 // this DIE over and over later...
7864 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007865 }
7866 return var_sp;
7867}
7868
Greg Claytonc662ec82011-06-17 22:10:16 +00007869
7870const DWARFDebugInfoEntry *
7871SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
7872 dw_offset_t spec_block_die_offset,
7873 DWARFCompileUnit **result_die_cu_handle)
7874{
7875 // Give the concrete function die specified by "func_die_offset", find the
7876 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7877 // to "spec_block_die_offset"
7878 DWARFDebugInfo* info = DebugInfo();
7879
7880 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
7881 if (die)
7882 {
7883 assert (*result_die_cu_handle);
7884 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
7885 }
7886 return NULL;
7887}
7888
7889
7890const DWARFDebugInfoEntry *
7891SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
7892 const DWARFDebugInfoEntry *die,
7893 dw_offset_t spec_block_die_offset,
7894 DWARFCompileUnit **result_die_cu_handle)
7895{
7896 if (die)
7897 {
7898 switch (die->Tag())
7899 {
7900 case DW_TAG_subprogram:
7901 case DW_TAG_inlined_subroutine:
7902 case DW_TAG_lexical_block:
7903 {
7904 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
7905 {
7906 *result_die_cu_handle = dwarf_cu;
7907 return die;
7908 }
7909
7910 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
7911 {
7912 *result_die_cu_handle = dwarf_cu;
7913 return die;
7914 }
7915 }
7916 break;
7917 }
7918
7919 // Give the concrete function die specified by "func_die_offset", find the
7920 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7921 // to "spec_block_die_offset"
7922 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
7923 {
7924 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
7925 child_die,
7926 spec_block_die_offset,
7927 result_die_cu_handle);
7928 if (result_die)
7929 return result_die;
7930 }
7931 }
7932
7933 *result_die_cu_handle = NULL;
7934 return NULL;
7935}
7936
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007937size_t
7938SymbolFileDWARF::ParseVariables
7939(
7940 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007941 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007942 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007943 const DWARFDebugInfoEntry *orig_die,
7944 bool parse_siblings,
7945 bool parse_children,
7946 VariableList* cc_variable_list
7947)
7948{
7949 if (orig_die == NULL)
7950 return 0;
7951
Greg Claytonc662ec82011-06-17 22:10:16 +00007952 VariableListSP variable_list_sp;
7953
7954 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007955 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00007956 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007957 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007958 dw_tag_t tag = die->Tag();
7959
7960 // Check to see if we have already parsed this variable or constant?
7961 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007962 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007963 if (cc_variable_list)
7964 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007965 }
7966 else
7967 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007968 // We haven't already parsed it, lets do that now.
7969 if ((tag == DW_TAG_variable) ||
7970 (tag == DW_TAG_constant) ||
7971 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007972 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007973 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00007974 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007975 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
7976 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7977 switch (parent_tag)
7978 {
7979 case DW_TAG_compile_unit:
7980 if (sc.comp_unit != NULL)
7981 {
7982 variable_list_sp = sc.comp_unit->GetVariableList(false);
7983 if (variable_list_sp.get() == NULL)
7984 {
7985 variable_list_sp.reset(new VariableList());
7986 sc.comp_unit->SetVariableList(variable_list_sp);
7987 }
7988 }
7989 else
7990 {
Daniel Malead01b2952012-11-29 21:49:15 +00007991 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 +00007992 MakeUserID(sc_parent_die->GetOffset()),
7993 DW_TAG_value_to_name (parent_tag),
7994 MakeUserID(orig_die->GetOffset()),
7995 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007996 }
7997 break;
7998
7999 case DW_TAG_subprogram:
8000 case DW_TAG_inlined_subroutine:
8001 case DW_TAG_lexical_block:
8002 if (sc.function != NULL)
8003 {
8004 // Check to see if we already have parsed the variables for the given scope
8005
Greg Clayton81c22f62011-10-19 18:09:39 +00008006 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00008007 if (block == NULL)
8008 {
8009 // This must be a specification or abstract origin with
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00008010 // a concrete block counterpart in the current function. We need
Greg Claytonc662ec82011-06-17 22:10:16 +00008011 // to find the concrete block so we can correctly add the
8012 // variable to it
8013 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
8014 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
8015 sc_parent_die->GetOffset(),
8016 &concrete_block_die_cu);
8017 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00008018 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00008019 }
8020
8021 if (block != NULL)
8022 {
8023 const bool can_create = false;
8024 variable_list_sp = block->GetBlockVariableList (can_create);
8025 if (variable_list_sp.get() == NULL)
8026 {
8027 variable_list_sp.reset(new VariableList());
8028 block->SetVariableList(variable_list_sp);
8029 }
8030 }
8031 }
8032 break;
8033
8034 default:
Daniel Malead01b2952012-11-29 21:49:15 +00008035 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 +00008036 MakeUserID(orig_die->GetOffset()),
8037 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00008038 break;
8039 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00008040 }
Greg Claytonc662ec82011-06-17 22:10:16 +00008041
8042 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00008043 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00008044 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
8045 if (var_sp)
8046 {
Greg Claytonc662ec82011-06-17 22:10:16 +00008047 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00008048 if (cc_variable_list)
8049 cc_variable_list->AddVariableIfUnique (var_sp);
8050 ++vars_added;
8051 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00008052 }
8053 }
8054 }
Greg Claytonc662ec82011-06-17 22:10:16 +00008055
8056 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
8057
8058 if (!skip_children && parse_children && die->HasChildren())
8059 {
8060 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
8061 }
8062
8063 if (parse_siblings)
8064 die = die->GetSibling();
8065 else
8066 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00008067 }
Greg Claytonc662ec82011-06-17 22:10:16 +00008068 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00008069}
8070
8071//------------------------------------------------------------------
8072// PluginInterface protocol
8073//------------------------------------------------------------------
Greg Clayton57abc5d2013-05-10 21:47:16 +00008074ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +00008075SymbolFileDWARF::GetPluginName()
8076{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00008077 return GetPluginNameStatic();
8078}
8079
8080uint32_t
8081SymbolFileDWARF::GetPluginVersion()
8082{
8083 return 1;
8084}
8085
8086void
Greg Clayton6beaaa62011-01-17 03:46:26 +00008087SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
8088{
8089 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
Greg Claytona1e5dc82015-08-11 22:53:00 +00008090 CompilerType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
Greg Clayton6beaaa62011-01-17 03:46:26 +00008091 if (clang_type)
8092 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
8093}
8094
8095void
8096SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
8097{
8098 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
Greg Claytona1e5dc82015-08-11 22:53:00 +00008099 CompilerType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
Greg Clayton6beaaa62011-01-17 03:46:26 +00008100 if (clang_type)
8101 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
8102}
8103
Greg Claytona2721472011-06-25 00:44:06 +00008104void
Sean Callanancc427fa2011-07-30 02:42:06 +00008105SymbolFileDWARF::DumpIndexes ()
8106{
8107 StreamFile s(stdout, false);
8108
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00008109 s.Printf ("DWARF index for (%s) '%s':",
Sean Callanancc427fa2011-07-30 02:42:06 +00008110 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00008111 GetObjectFile()->GetFileSpec().GetPath().c_str());
Sean Callanancc427fa2011-07-30 02:42:06 +00008112 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
8113 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
8114 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
8115 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
8116 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
8117 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
8118 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Bruce Mitchenere171da52015-07-22 00:16:02 +00008119 s.Printf("\nNamespaces:\n"); m_namespace_index.Dump (&s);
Sean Callanancc427fa2011-07-30 02:42:06 +00008120}
8121
8122void
8123SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
8124 const char *name,
8125 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00008126{
Sean Callanancc427fa2011-07-30 02:42:06 +00008127 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00008128
8129 if (iter == m_decl_ctx_to_die.end())
8130 return;
8131
Greg Claytoncb5860a2011-10-13 23:49:28 +00008132 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00008133 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00008134 const DWARFDebugInfoEntry *context_die = *pos;
8135
8136 if (!results)
8137 return;
8138
8139 DWARFDebugInfo* info = DebugInfo();
8140
8141 DIEArray die_offsets;
8142
8143 DWARFCompileUnit* dwarf_cu = NULL;
8144 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton220a0072011-12-09 08:48:30 +00008145
8146 if (m_using_apple_tables)
8147 {
8148 if (m_apple_types_ap.get())
8149 m_apple_types_ap->FindByName (name, die_offsets);
8150 }
8151 else
8152 {
8153 if (!m_indexed)
8154 Index ();
8155
8156 m_type_index.Find (ConstString(name), die_offsets);
8157 }
8158
Greg Clayton220a0072011-12-09 08:48:30 +00008159 const size_t num_matches = die_offsets.size();
Greg Claytoncb5860a2011-10-13 23:49:28 +00008160
8161 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00008162 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00008163 for (size_t i = 0; i < num_matches; ++i)
8164 {
8165 const dw_offset_t die_offset = die_offsets[i];
8166 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00008167
Greg Claytoncb5860a2011-10-13 23:49:28 +00008168 if (die->GetParent() != context_die)
8169 continue;
8170
8171 Type *matching_type = ResolveType (dwarf_cu, die);
8172
Greg Claytond8d4a572015-08-11 21:38:15 +00008173 clang::QualType qual_type = ClangASTContext::GetQualType(matching_type->GetClangForwardType());
Greg Claytoncb5860a2011-10-13 23:49:28 +00008174
8175 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
8176 {
8177 clang::TagDecl *tag_decl = tag_type->getDecl();
8178 results->push_back(tag_decl);
8179 }
8180 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
8181 {
8182 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
8183 results->push_back(typedef_decl);
8184 }
Greg Claytona2721472011-06-25 00:44:06 +00008185 }
8186 }
8187 }
8188}
8189
8190void
8191SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00008192 const clang::DeclContext *decl_context,
8193 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00008194 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
8195{
Greg Clayton85ae2e12011-10-18 23:36:41 +00008196
8197 switch (decl_context->getDeclKind())
8198 {
8199 case clang::Decl::Namespace:
8200 case clang::Decl::TranslationUnit:
8201 {
8202 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
8203 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
8204 }
8205 break;
8206 default:
8207 break;
8208 }
Greg Claytona2721472011-06-25 00:44:06 +00008209}
Greg Claytoncaab74e2012-01-28 00:48:57 +00008210
Zachary Turner504f38d2015-03-24 16:24:50 +00008211bool
8212SymbolFileDWARF::LayoutRecordType(void *baton, const clang::RecordDecl *record_decl, uint64_t &size,
8213 uint64_t &alignment,
Zachary Turnera98fac22015-03-24 18:56:08 +00008214 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
8215 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
8216 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
Greg Claytoncaab74e2012-01-28 00:48:57 +00008217{
8218 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
8219 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
8220}
8221
Zachary Turner504f38d2015-03-24 16:24:50 +00008222bool
8223SymbolFileDWARF::LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &bit_size, uint64_t &alignment,
Zachary Turnera98fac22015-03-24 18:56:08 +00008224 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
8225 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
8226 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
Greg Claytoncaab74e2012-01-28 00:48:57 +00008227{
Greg Clayton5160ce52013-03-27 23:08:40 +00008228 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Claytoncaab74e2012-01-28 00:48:57 +00008229 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
8230 bool success = false;
8231 base_offsets.clear();
8232 vbase_offsets.clear();
8233 if (pos != m_record_decl_to_layout_map.end())
8234 {
8235 bit_size = pos->second.bit_size;
8236 alignment = pos->second.alignment;
8237 field_offsets.swap(pos->second.field_offsets);
Greg Clayton2508b9b2012-11-01 23:20:02 +00008238 base_offsets.swap (pos->second.base_offsets);
8239 vbase_offsets.swap (pos->second.vbase_offsets);
Greg Claytoncaab74e2012-01-28 00:48:57 +00008240 m_record_decl_to_layout_map.erase(pos);
8241 success = true;
8242 }
8243 else
8244 {
8245 bit_size = 0;
8246 alignment = 0;
8247 field_offsets.clear();
8248 }
8249
8250 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00008251 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00008252 "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 +00008253 static_cast<const void*>(record_decl),
8254 bit_size, alignment,
8255 static_cast<uint32_t>(field_offsets.size()),
8256 static_cast<uint32_t>(base_offsets.size()),
8257 static_cast<uint32_t>(vbase_offsets.size()),
Greg Claytoncaab74e2012-01-28 00:48:57 +00008258 success);
8259 return success;
8260}
8261
8262
Greg Clayton1f746072012-08-29 21:13:06 +00008263SymbolFileDWARFDebugMap *
8264SymbolFileDWARF::GetDebugMapSymfile ()
8265{
8266 if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired())
8267 {
8268 lldb::ModuleSP module_sp (m_debug_map_module_wp.lock());
8269 if (module_sp)
8270 {
8271 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
8272 if (sym_vendor)
8273 m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile();
8274 }
8275 }
8276 return m_debug_map_symfile;
8277}
8278
Greg Claytoncaab74e2012-01-28 00:48:57 +00008279