blob: 9a8030a0fe44f4b0ba34c3124bea8b6218a2fc56 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SymbolFileDWARF.cpp ------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "SymbolFileDWARF.h"
11
12// Other libraries and framework includes
13#include "clang/AST/ASTConsumer.h"
14#include "clang/AST/ASTContext.h"
15#include "clang/AST/Decl.h"
16#include "clang/AST/DeclGroup.h"
Jim Inghame3ae82a2011-11-12 01:36:43 +000017#include "clang/AST/DeclObjC.h"
Greg Clayton3c2e3ae2012-02-06 06:42:51 +000018#include "clang/AST/DeclTemplate.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "clang/Basic/Builtins.h"
20#include "clang/Basic/IdentifierTable.h"
21#include "clang/Basic/LangOptions.h"
22#include "clang/Basic/SourceManager.h"
23#include "clang/Basic/TargetInfo.h"
24#include "clang/Basic/Specifiers.h"
Greg Clayton7fedea22010-11-16 02:10:54 +000025#include "clang/Sema/DeclSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026
Sean Callanancc427fa2011-07-30 02:42:06 +000027#include "llvm/Support/Casting.h"
28
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Core/Module.h"
30#include "lldb/Core/PluginManager.h"
31#include "lldb/Core/RegularExpression.h"
32#include "lldb/Core/Scalar.h"
33#include "lldb/Core/Section.h"
Greg Claytonc685f8e2010-09-15 04:15:46 +000034#include "lldb/Core/StreamFile.h"
Jim Ingham318c9f22011-08-26 19:44:13 +000035#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000036#include "lldb/Core/Timer.h"
37#include "lldb/Core/Value.h"
38
Greg Clayton20568dd2011-10-13 23:13:20 +000039#include "lldb/Host/Host.h"
40
Chris Lattner30fdc8d2010-06-08 16:52:24 +000041#include "lldb/Symbol/Block.h"
Greg Clayton6beaaa62011-01-17 03:46:26 +000042#include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043#include "lldb/Symbol/CompileUnit.h"
44#include "lldb/Symbol/LineTable.h"
45#include "lldb/Symbol/ObjectFile.h"
46#include "lldb/Symbol/SymbolVendor.h"
47#include "lldb/Symbol/VariableList.h"
48
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000049#include "lldb/Target/ObjCLanguageRuntime.h"
Jim Ingham4cda6e02011-10-07 22:23:45 +000050#include "lldb/Target/CPPLanguageRuntime.h"
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000051
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052#include "DWARFCompileUnit.h"
53#include "DWARFDebugAbbrev.h"
54#include "DWARFDebugAranges.h"
55#include "DWARFDebugInfo.h"
56#include "DWARFDebugInfoEntry.h"
57#include "DWARFDebugLine.h"
58#include "DWARFDebugPubnames.h"
59#include "DWARFDebugRanges.h"
Greg Claytona8022fa2012-04-24 21:22:41 +000060#include "DWARFDeclContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061#include "DWARFDIECollection.h"
62#include "DWARFFormValue.h"
63#include "DWARFLocationList.h"
64#include "LogChannelDWARF.h"
Greg Clayton450e3f32010-10-12 02:24:53 +000065#include "SymbolFileDWARFDebugMap.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066
67#include <map>
68
Greg Clayton62742b12010-11-11 01:09:45 +000069//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
Greg Claytonc93237c2010-10-01 20:48:32 +000070
71#ifdef ENABLE_DEBUG_PRINTF
72#include <stdio.h>
73#define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
74#else
75#define DEBUG_PRINTF(fmt, ...)
76#endif
77
Greg Clayton594e5ed2010-09-27 21:07:38 +000078#define DIE_IS_BEING_PARSED ((lldb_private::Type*)1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000079
80using namespace lldb;
81using namespace lldb_private;
82
Greg Clayton219cf312012-03-30 00:51:13 +000083//static inline bool
84//child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag)
85//{
86// switch (tag)
87// {
88// default:
89// break;
90// case DW_TAG_subprogram:
91// case DW_TAG_inlined_subroutine:
92// case DW_TAG_class_type:
93// case DW_TAG_structure_type:
94// case DW_TAG_union_type:
95// return true;
96// }
97// return false;
98//}
99//
Sean Callananc7fbf732010-08-06 00:32:49 +0000100static AccessType
Greg Clayton8cf05932010-07-22 18:30:50 +0000101DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000102{
103 switch (dwarf_accessibility)
104 {
Sean Callananc7fbf732010-08-06 00:32:49 +0000105 case DW_ACCESS_public: return eAccessPublic;
106 case DW_ACCESS_private: return eAccessPrivate;
107 case DW_ACCESS_protected: return eAccessProtected;
Greg Clayton8cf05932010-07-22 18:30:50 +0000108 default: break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000109 }
Sean Callananc7fbf732010-08-06 00:32:49 +0000110 return eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000111}
112
Greg Clayton1fba87112012-02-09 20:03:49 +0000113#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
114
115class DIEStack
116{
117public:
118
119 void Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
120 {
121 m_dies.push_back (DIEInfo(cu, die));
122 }
123
124
125 void LogDIEs (Log *log, SymbolFileDWARF *dwarf)
126 {
127 StreamString log_strm;
128 const size_t n = m_dies.size();
Daniel Malead01b2952012-11-29 21:49:15 +0000129 log_strm.Printf("DIEStack[%" PRIu64 "]:\n", (uint64_t)n);
Greg Clayton1fba87112012-02-09 20:03:49 +0000130 for (size_t i=0; i<n; i++)
131 {
132 DWARFCompileUnit *cu = m_dies[i].cu;
133 const DWARFDebugInfoEntry *die = m_dies[i].die;
134 std::string qualified_name;
135 die->GetQualifiedName(dwarf, cu, qualified_name);
Daniel Malead01b2952012-11-29 21:49:15 +0000136 log_strm.Printf ("[%" PRIu64 "] 0x%8.8x: %s name='%s'\n",
Greg Clayton43e0af02012-09-18 18:04:04 +0000137 (uint64_t)i,
Greg Clayton1fba87112012-02-09 20:03:49 +0000138 die->GetOffset(),
139 DW_TAG_value_to_name(die->Tag()),
140 qualified_name.c_str());
141 }
142 log->PutCString(log_strm.GetData());
143 }
144 void Pop ()
145 {
146 m_dies.pop_back();
147 }
148
149 class ScopedPopper
150 {
151 public:
152 ScopedPopper (DIEStack &die_stack) :
153 m_die_stack (die_stack),
154 m_valid (false)
155 {
156 }
157
158 void
159 Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
160 {
161 m_valid = true;
162 m_die_stack.Push (cu, die);
163 }
164
165 ~ScopedPopper ()
166 {
167 if (m_valid)
168 m_die_stack.Pop();
169 }
170
171
172
173 protected:
174 DIEStack &m_die_stack;
175 bool m_valid;
176 };
177
178protected:
179 struct DIEInfo {
180 DIEInfo (DWARFCompileUnit *c, const DWARFDebugInfoEntry *d) :
181 cu(c),
182 die(d)
183 {
184 }
185 DWARFCompileUnit *cu;
186 const DWARFDebugInfoEntry *die;
187 };
188 typedef std::vector<DIEInfo> Stack;
189 Stack m_dies;
190};
191#endif
192
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000193void
194SymbolFileDWARF::Initialize()
195{
196 LogChannelDWARF::Initialize();
197 PluginManager::RegisterPlugin (GetPluginNameStatic(),
198 GetPluginDescriptionStatic(),
199 CreateInstance);
200}
201
202void
203SymbolFileDWARF::Terminate()
204{
205 PluginManager::UnregisterPlugin (CreateInstance);
206 LogChannelDWARF::Initialize();
207}
208
209
Greg Clayton57abc5d2013-05-10 21:47:16 +0000210lldb_private::ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000211SymbolFileDWARF::GetPluginNameStatic()
212{
Greg Clayton57abc5d2013-05-10 21:47:16 +0000213 static ConstString g_name("dwarf");
214 return g_name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000215}
216
217const char *
218SymbolFileDWARF::GetPluginDescriptionStatic()
219{
220 return "DWARF and DWARF3 debug symbol file reader.";
221}
222
223
224SymbolFile*
225SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
226{
227 return new SymbolFileDWARF(obj_file);
228}
229
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000230TypeList *
231SymbolFileDWARF::GetTypeList ()
232{
Greg Clayton1f746072012-08-29 21:13:06 +0000233 if (GetDebugMapSymfile ())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000234 return m_debug_map_symfile->GetTypeList();
235 return m_obj_file->GetModule()->GetTypeList();
236
237}
238
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000239//----------------------------------------------------------------------
240// Gets the first parent that is a lexical block, function or inlined
241// subroutine, or compile unit.
242//----------------------------------------------------------------------
243static const DWARFDebugInfoEntry *
244GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
245{
246 const DWARFDebugInfoEntry *die;
247 for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
248 {
249 dw_tag_t tag = die->Tag();
250
251 switch (tag)
252 {
253 case DW_TAG_compile_unit:
254 case DW_TAG_subprogram:
255 case DW_TAG_inlined_subroutine:
256 case DW_TAG_lexical_block:
257 return die;
258 }
259 }
260 return NULL;
261}
262
263
Greg Clayton450e3f32010-10-12 02:24:53 +0000264SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
265 SymbolFile (objfile),
Greg Clayton81c22f62011-10-19 18:09:39 +0000266 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 +0000267 m_debug_map_module_wp (),
Greg Clayton450e3f32010-10-12 02:24:53 +0000268 m_debug_map_symfile (NULL),
Greg Clayton7a345282010-11-09 23:46:37 +0000269 m_clang_tu_decl (NULL),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000270 m_flags(),
Greg Claytond4a2b372011-09-12 23:21:58 +0000271 m_data_debug_abbrev (),
272 m_data_debug_aranges (),
273 m_data_debug_frame (),
274 m_data_debug_info (),
275 m_data_debug_line (),
276 m_data_debug_loc (),
277 m_data_debug_ranges (),
278 m_data_debug_str (),
Greg Clayton17674402011-09-28 17:06:40 +0000279 m_data_apple_names (),
280 m_data_apple_types (),
Greg Clayton7f995132011-10-04 22:41:51 +0000281 m_data_apple_namespaces (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000282 m_abbr(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000283 m_info(),
284 m_line(),
Greg Clayton7f995132011-10-04 22:41:51 +0000285 m_apple_names_ap (),
286 m_apple_types_ap (),
287 m_apple_namespaces_ap (),
Greg Clayton5009f9d2011-10-27 17:55:14 +0000288 m_apple_objc_ap (),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000289 m_function_basename_index(),
290 m_function_fullname_index(),
291 m_function_method_index(),
292 m_function_selector_index(),
Greg Clayton450e3f32010-10-12 02:24:53 +0000293 m_objc_class_selectors_index(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000294 m_global_index(),
Greg Clayton69b04882010-10-15 02:03:22 +0000295 m_type_index(),
296 m_namespace_index(),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000297 m_indexed (false),
298 m_is_external_ast_source (false),
Greg Clayton97fbc342011-10-20 22:30:33 +0000299 m_using_apple_tables (false),
Greg Claytonc7f03b62012-01-12 04:33:28 +0000300 m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +0000301 m_ranges(),
302 m_unique_ast_type_map ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000303{
304}
305
306SymbolFileDWARF::~SymbolFileDWARF()
307{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000308 if (m_is_external_ast_source)
Greg Claytone72dfb32012-02-24 01:59:29 +0000309 {
310 ModuleSP module_sp (m_obj_file->GetModule());
311 if (module_sp)
312 module_sp->GetClangASTContext().RemoveExternalSource ();
313 }
Greg Clayton6beaaa62011-01-17 03:46:26 +0000314}
315
316static const ConstString &
317GetDWARFMachOSegmentName ()
318{
319 static ConstString g_dwarf_section_name ("__DWARF");
320 return g_dwarf_section_name;
321}
322
Greg Claytone576ab22011-02-15 00:19:15 +0000323UniqueDWARFASTTypeMap &
324SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
325{
Greg Clayton1f746072012-08-29 21:13:06 +0000326 if (GetDebugMapSymfile ())
Greg Claytone576ab22011-02-15 00:19:15 +0000327 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
328 return m_unique_ast_type_map;
329}
330
Greg Clayton6beaaa62011-01-17 03:46:26 +0000331ClangASTContext &
332SymbolFileDWARF::GetClangASTContext ()
333{
Greg Clayton1f746072012-08-29 21:13:06 +0000334 if (GetDebugMapSymfile ())
Greg Clayton6beaaa62011-01-17 03:46:26 +0000335 return m_debug_map_symfile->GetClangASTContext ();
336
337 ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext();
338 if (!m_is_external_ast_source)
339 {
340 m_is_external_ast_source = true;
341 llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap (
342 new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl,
343 SymbolFileDWARF::CompleteObjCInterfaceDecl,
Greg Claytona2721472011-06-25 00:44:06 +0000344 SymbolFileDWARF::FindExternalVisibleDeclsByName,
Greg Claytoncaab74e2012-01-28 00:48:57 +0000345 SymbolFileDWARF::LayoutRecordType,
Greg Clayton6beaaa62011-01-17 03:46:26 +0000346 this));
Greg Clayton6beaaa62011-01-17 03:46:26 +0000347 ast.SetExternalSource (ast_source_ap);
348 }
349 return ast;
350}
351
352void
353SymbolFileDWARF::InitializeObject()
354{
355 // Install our external AST source callbacks so we can complete Clang types.
Greg Claytone72dfb32012-02-24 01:59:29 +0000356 ModuleSP module_sp (m_obj_file->GetModule());
357 if (module_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +0000358 {
359 const SectionList *section_list = m_obj_file->GetSectionList();
360
361 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
362
363 // Memory map the DWARF mach-o segment so we have everything mmap'ed
364 // to keep our heap memory usage down.
365 if (section)
Greg Claytonc9660542012-02-05 02:38:54 +0000366 m_obj_file->MemoryMapSectionData(section, m_dwarf_data);
Greg Clayton6beaaa62011-01-17 03:46:26 +0000367 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000368 get_apple_names_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000369 if (m_data_apple_names.GetByteSize() > 0)
370 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000371 m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names"));
372 if (m_apple_names_ap->IsValid())
373 m_using_apple_tables = true;
374 else
Greg Clayton7f995132011-10-04 22:41:51 +0000375 m_apple_names_ap.reset();
376 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000377 get_apple_types_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000378 if (m_data_apple_types.GetByteSize() > 0)
379 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000380 m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types"));
381 if (m_apple_types_ap->IsValid())
382 m_using_apple_tables = true;
383 else
Greg Clayton7f995132011-10-04 22:41:51 +0000384 m_apple_types_ap.reset();
385 }
386
387 get_apple_namespaces_data();
388 if (m_data_apple_namespaces.GetByteSize() > 0)
389 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000390 m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces"));
391 if (m_apple_namespaces_ap->IsValid())
392 m_using_apple_tables = true;
393 else
Greg Clayton7f995132011-10-04 22:41:51 +0000394 m_apple_namespaces_ap.reset();
395 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000396
Greg Clayton5009f9d2011-10-27 17:55:14 +0000397 get_apple_objc_data();
398 if (m_data_apple_objc.GetByteSize() > 0)
399 {
400 m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc"));
401 if (m_apple_objc_ap->IsValid())
402 m_using_apple_tables = true;
403 else
404 m_apple_objc_ap.reset();
405 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000406}
407
408bool
409SymbolFileDWARF::SupportedVersion(uint16_t version)
410{
Greg Claytonabcbfe52013-04-04 00:00:36 +0000411 return version == 2 || version == 3 || version == 4;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000412}
413
414uint32_t
Sean Callananbfaf54d2011-12-03 04:38:43 +0000415SymbolFileDWARF::CalculateAbilities ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000416{
417 uint32_t abilities = 0;
418 if (m_obj_file != NULL)
419 {
420 const Section* section = NULL;
421 const SectionList *section_list = m_obj_file->GetSectionList();
422 if (section_list == NULL)
423 return 0;
424
425 uint64_t debug_abbrev_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000426 uint64_t debug_info_file_size = 0;
427 uint64_t debug_line_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000428
Greg Clayton6beaaa62011-01-17 03:46:26 +0000429 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000430
431 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000432 section_list = &section->GetChildren ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000433
Greg Clayton4ceb9982010-07-21 22:54:26 +0000434 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000435 if (section != NULL)
436 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000437 debug_info_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000438
Greg Clayton4ceb9982010-07-21 22:54:26 +0000439 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000440 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000441 debug_abbrev_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000442 else
443 m_flags.Set (flagsGotDebugAbbrevData);
444
Greg Clayton4ceb9982010-07-21 22:54:26 +0000445 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000446 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000447 m_flags.Set (flagsGotDebugArangesData);
448
Greg Clayton4ceb9982010-07-21 22:54:26 +0000449 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000450 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000451 m_flags.Set (flagsGotDebugFrameData);
452
Greg Clayton4ceb9982010-07-21 22:54:26 +0000453 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000454 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000455 debug_line_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000456 else
457 m_flags.Set (flagsGotDebugLineData);
458
Greg Clayton4ceb9982010-07-21 22:54:26 +0000459 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000460 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000461 m_flags.Set (flagsGotDebugLocData);
462
Greg Clayton4ceb9982010-07-21 22:54:26 +0000463 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000464 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000465 m_flags.Set (flagsGotDebugMacInfoData);
466
Greg Clayton4ceb9982010-07-21 22:54:26 +0000467 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000468 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000469 m_flags.Set (flagsGotDebugPubNamesData);
470
Greg Clayton4ceb9982010-07-21 22:54:26 +0000471 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000472 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000473 m_flags.Set (flagsGotDebugPubTypesData);
474
Greg Clayton4ceb9982010-07-21 22:54:26 +0000475 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000476 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000477 m_flags.Set (flagsGotDebugRangesData);
478
Greg Clayton4ceb9982010-07-21 22:54:26 +0000479 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000480 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000481 m_flags.Set (flagsGotDebugStrData);
482 }
Greg Clayton6c596612012-05-18 21:47:20 +0000483 else
484 {
485 const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString();
486 if (symfile_dir_cstr)
487 {
488 if (strcasestr(symfile_dir_cstr, ".dsym"))
489 {
490 if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo)
491 {
492 // We have a dSYM file that didn't have a any debug info.
493 // If the string table has a size of 1, then it was made from
494 // an executable with no debug info, or from an executable that
495 // was stripped.
496 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
497 if (section && section->GetFileSize() == 1)
498 {
499 m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info.");
500 }
501 }
502 }
503 }
504 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000505
506 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
507 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
508
509 if (debug_line_file_size > 0)
510 abilities |= LineTables;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000511 }
512 return abilities;
513}
514
515const DataExtractor&
Greg Clayton4ceb9982010-07-21 22:54:26 +0000516SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000517{
518 if (m_flags.IsClear (got_flag))
519 {
520 m_flags.Set (got_flag);
521 const SectionList *section_list = m_obj_file->GetSectionList();
522 if (section_list)
523 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000524 SectionSP section_sp (section_list->FindSectionByType(sect_type, true));
525 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000526 {
527 // See if we memory mapped the DWARF segment?
528 if (m_dwarf_data.GetByteSize())
529 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000530 data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000531 }
532 else
533 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000534 if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000535 data.Clear();
536 }
537 }
538 }
539 }
540 return data;
541}
542
543const DataExtractor&
544SymbolFileDWARF::get_debug_abbrev_data()
545{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000546 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000547}
548
549const DataExtractor&
Greg Claytond4a2b372011-09-12 23:21:58 +0000550SymbolFileDWARF::get_debug_aranges_data()
551{
552 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
553}
554
555const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000556SymbolFileDWARF::get_debug_frame_data()
557{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000558 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000559}
560
561const DataExtractor&
562SymbolFileDWARF::get_debug_info_data()
563{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000564 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000565}
566
567const DataExtractor&
568SymbolFileDWARF::get_debug_line_data()
569{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000570 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000571}
572
573const DataExtractor&
574SymbolFileDWARF::get_debug_loc_data()
575{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000576 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000577}
578
579const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000580SymbolFileDWARF::get_debug_ranges_data()
581{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000582 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000583}
584
585const DataExtractor&
586SymbolFileDWARF::get_debug_str_data()
587{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000588 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000589}
590
Greg Claytonf9eec202011-09-01 23:16:13 +0000591const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000592SymbolFileDWARF::get_apple_names_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000593{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000594 return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names);
Greg Claytonf9eec202011-09-01 23:16:13 +0000595}
596
597const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000598SymbolFileDWARF::get_apple_types_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000599{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000600 return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types);
Greg Claytonf9eec202011-09-01 23:16:13 +0000601}
602
Greg Clayton7f995132011-10-04 22:41:51 +0000603const DataExtractor&
604SymbolFileDWARF::get_apple_namespaces_data()
605{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000606 return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
607}
608
609const DataExtractor&
610SymbolFileDWARF::get_apple_objc_data()
611{
612 return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc);
Greg Clayton7f995132011-10-04 22:41:51 +0000613}
614
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000615
616DWARFDebugAbbrev*
617SymbolFileDWARF::DebugAbbrev()
618{
619 if (m_abbr.get() == NULL)
620 {
621 const DataExtractor &debug_abbrev_data = get_debug_abbrev_data();
622 if (debug_abbrev_data.GetByteSize() > 0)
623 {
624 m_abbr.reset(new DWARFDebugAbbrev());
625 if (m_abbr.get())
626 m_abbr->Parse(debug_abbrev_data);
627 }
628 }
629 return m_abbr.get();
630}
631
632const DWARFDebugAbbrev*
633SymbolFileDWARF::DebugAbbrev() const
634{
635 return m_abbr.get();
636}
637
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000638
639DWARFDebugInfo*
640SymbolFileDWARF::DebugInfo()
641{
642 if (m_info.get() == NULL)
643 {
644 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
645 if (get_debug_info_data().GetByteSize() > 0)
646 {
647 m_info.reset(new DWARFDebugInfo());
648 if (m_info.get())
649 {
650 m_info->SetDwarfData(this);
651 }
652 }
653 }
654 return m_info.get();
655}
656
657const DWARFDebugInfo*
658SymbolFileDWARF::DebugInfo() const
659{
660 return m_info.get();
661}
662
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000663DWARFCompileUnit*
Greg Clayton1f746072012-08-29 21:13:06 +0000664SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000665{
666 DWARFDebugInfo* info = DebugInfo();
Greg Clayton1f746072012-08-29 21:13:06 +0000667 if (info)
668 {
669 if (GetDebugMapSymfile ())
670 {
671 // The debug map symbol file made the compile units for this DWARF
672 // file which is .o file with DWARF in it, and we should have
673 // only 1 compile unit which is at offset zero in the DWARF.
674 // TODO: modify to support LTO .o files where each .o file might
675 // have multiple DW_TAG_compile_unit tags.
676 return info->GetCompileUnit(0).get();
677 }
678 else
679 {
680 // Just a normal DWARF file whose user ID for the compile unit is
681 // the DWARF offset itself
682 return info->GetCompileUnit((dw_offset_t)comp_unit->GetID()).get();
683 }
684 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000685 return NULL;
686}
687
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000688
689DWARFDebugRanges*
690SymbolFileDWARF::DebugRanges()
691{
692 if (m_ranges.get() == NULL)
693 {
694 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
695 if (get_debug_ranges_data().GetByteSize() > 0)
696 {
697 m_ranges.reset(new DWARFDebugRanges());
698 if (m_ranges.get())
699 m_ranges->Extract(this);
700 }
701 }
702 return m_ranges.get();
703}
704
705const DWARFDebugRanges*
706SymbolFileDWARF::DebugRanges() const
707{
708 return m_ranges.get();
709}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000710
Greg Clayton53eb1c22012-04-02 22:59:12 +0000711lldb::CompUnitSP
712SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000713{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000714 CompUnitSP cu_sp;
715 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000716 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000717 CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData();
718 if (comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000719 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000720 // We already parsed this compile unit, had out a shared pointer to it
721 cu_sp = comp_unit->shared_from_this();
722 }
723 else
724 {
Greg Clayton1f746072012-08-29 21:13:06 +0000725 if (GetDebugMapSymfile ())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000726 {
Greg Clayton1f746072012-08-29 21:13:06 +0000727 // Let the debug map create the compile unit
728 cu_sp = m_debug_map_symfile->GetCompileUnit(this);
729 dwarf_cu->SetUserData(cu_sp.get());
730 }
731 else
732 {
733 ModuleSP module_sp (m_obj_file->GetModule());
734 if (module_sp)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000735 {
Greg Clayton1f746072012-08-29 21:13:06 +0000736 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly ();
737 if (cu_die)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000738 {
Greg Clayton1f746072012-08-29 21:13:06 +0000739 const char * cu_die_name = cu_die->GetName(this, dwarf_cu);
740 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
741 LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
742 if (cu_die_name)
743 {
744 std::string ramapped_file;
745 FileSpec cu_file_spec;
Jim Ingham0909e5f2010-09-16 00:57:33 +0000746
Greg Clayton1f746072012-08-29 21:13:06 +0000747 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0')
Greg Clayton53eb1c22012-04-02 22:59:12 +0000748 {
Greg Clayton1f746072012-08-29 21:13:06 +0000749 // If we have a full path to the compile unit, we don't need to resolve
750 // the file. This can be expensive e.g. when the source files are NFS mounted.
751 if (module_sp->RemapSourceFile(cu_die_name, ramapped_file))
752 cu_file_spec.SetFile (ramapped_file.c_str(), false);
753 else
754 cu_file_spec.SetFile (cu_die_name, false);
Greg Clayton53eb1c22012-04-02 22:59:12 +0000755 }
756 else
757 {
Greg Clayton1f746072012-08-29 21:13:06 +0000758 std::string fullpath(cu_comp_dir);
759 if (*fullpath.rbegin() != '/')
760 fullpath += '/';
761 fullpath += cu_die_name;
762 if (module_sp->RemapSourceFile (fullpath.c_str(), ramapped_file))
763 cu_file_spec.SetFile (ramapped_file.c_str(), false);
764 else
765 cu_file_spec.SetFile (fullpath.c_str(), false);
766 }
767
768 cu_sp.reset(new CompileUnit (module_sp,
769 dwarf_cu,
770 cu_file_spec,
771 MakeUserID(dwarf_cu->GetOffset()),
772 cu_language));
773 if (cu_sp)
774 {
775 dwarf_cu->SetUserData(cu_sp.get());
776
Greg Clayton53eb1c22012-04-02 22:59:12 +0000777 // Figure out the compile unit index if we weren't given one
778 if (cu_idx == UINT32_MAX)
779 DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx);
780
781 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp);
782 }
783 }
784 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000785 }
786 }
787 }
788 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000789 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000790}
791
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000792uint32_t
793SymbolFileDWARF::GetNumCompileUnits()
794{
795 DWARFDebugInfo* info = DebugInfo();
796 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000797 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000798 return 0;
799}
800
801CompUnitSP
802SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
803{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000804 CompUnitSP cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000805 DWARFDebugInfo* info = DebugInfo();
806 if (info)
807 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000808 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
809 if (dwarf_cu)
810 cu_sp = ParseCompileUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000811 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000812 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000813}
814
815static void
Greg Claytonea3e7d52011-10-08 00:49:15 +0000816AddRangesToBlock (Block& block,
817 DWARFDebugRanges::RangeList& ranges,
818 addr_t block_base_addr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000819{
Greg Claytonea3e7d52011-10-08 00:49:15 +0000820 const size_t num_ranges = ranges.GetSize();
821 for (size_t i = 0; i<num_ranges; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000822 {
Greg Claytonea3e7d52011-10-08 00:49:15 +0000823 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i);
824 const addr_t range_base = range.GetRangeBase();
825 assert (range_base >= block_base_addr);
826 block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000827 }
Greg Claytonea3e7d52011-10-08 00:49:15 +0000828 block.FinalizeRanges ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000829}
830
831
832Function *
Greg Clayton0fffff52010-09-24 05:15:53 +0000833SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000834{
835 DWARFDebugRanges::RangeList func_ranges;
836 const char *name = NULL;
837 const char *mangled = NULL;
838 int decl_file = 0;
839 int decl_line = 0;
840 int decl_column = 0;
841 int call_file = 0;
842 int call_line = 0;
843 int call_column = 0;
844 DWARFExpression frame_base;
845
Greg Claytonc93237c2010-10-01 20:48:32 +0000846 assert (die->Tag() == DW_TAG_subprogram);
847
848 if (die->Tag() != DW_TAG_subprogram)
849 return NULL;
850
Greg Clayton3c2e3ae2012-02-06 06:42:51 +0000851 if (die->GetDIENamesAndRanges (this,
852 dwarf_cu,
853 name,
854 mangled,
855 func_ranges,
856 decl_file,
857 decl_line,
858 decl_column,
859 call_file,
860 call_line,
861 call_column,
862 &frame_base))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000863 {
864 // Union of all ranges in the function DIE (if the function is discontiguous)
865 AddressRange func_range;
Greg Claytonea3e7d52011-10-08 00:49:15 +0000866 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0);
867 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000868 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
869 {
870 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList());
871 if (func_range.GetBaseAddress().IsValid())
872 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
873 }
874
875 if (func_range.GetBaseAddress().IsValid())
876 {
877 Mangled func_name;
878 if (mangled)
Greg Clayton037520e2012-07-18 23:18:10 +0000879 func_name.SetValue(ConstString(mangled), true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000880 else if (name)
Greg Clayton037520e2012-07-18 23:18:10 +0000881 func_name.SetValue(ConstString(name), false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000882
883 FunctionSP func_sp;
Greg Clayton7b0992d2013-04-18 22:45:39 +0000884 std::unique_ptr<Declaration> decl_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000885 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +0000886 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
887 decl_line,
888 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000889
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000890 // Supply the type _only_ if it has already been parsed
Greg Clayton594e5ed2010-09-27 21:07:38 +0000891 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000892
893 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
894
Greg Clayton9422dd62013-03-04 21:46:16 +0000895 if (FixupAddress (func_range.GetBaseAddress()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000896 {
Greg Clayton9422dd62013-03-04 21:46:16 +0000897 const user_id_t func_user_id = MakeUserID(die->GetOffset());
898 func_sp.reset(new Function (sc.comp_unit,
899 MakeUserID(func_user_id), // UserID is the DIE offset
900 MakeUserID(func_user_id),
901 func_name,
902 func_type,
903 func_range)); // first address range
904
905 if (func_sp.get() != NULL)
906 {
907 if (frame_base.IsValid())
908 func_sp->GetFrameBaseExpression() = frame_base;
909 sc.comp_unit->AddFunction(func_sp);
910 return func_sp.get();
911 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000912 }
913 }
914 }
915 return NULL;
916}
917
Greg Clayton9422dd62013-03-04 21:46:16 +0000918bool
919SymbolFileDWARF::FixupAddress (Address &addr)
920{
921 SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile ();
922 if (debug_map_symfile)
923 {
924 return debug_map_symfile->LinkOSOAddress(addr);
925 }
926 // This is a normal DWARF file, no address fixups need to happen
927 return true;
928}
Greg Clayton1f746072012-08-29 21:13:06 +0000929lldb::LanguageType
930SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc)
931{
932 assert (sc.comp_unit);
933 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
934 if (dwarf_cu)
935 {
936 const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly();
Jim Ingham28eb5712012-10-12 17:34:26 +0000937 if (die)
938 {
939 const uint32_t language = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
940 if (language)
941 return (lldb::LanguageType)language;
942 }
Greg Clayton1f746072012-08-29 21:13:06 +0000943 }
944 return eLanguageTypeUnknown;
945}
946
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000947size_t
948SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
949{
950 assert (sc.comp_unit);
951 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +0000952 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000953 if (dwarf_cu)
954 {
955 DWARFDIECollection function_dies;
Greg Clayton1f746072012-08-29 21:13:06 +0000956 const size_t num_functions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000957 size_t func_idx;
Greg Clayton1f746072012-08-29 21:13:06 +0000958 for (func_idx = 0; func_idx < num_functions; ++func_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000959 {
960 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
Greg Clayton81c22f62011-10-19 18:09:39 +0000961 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000962 {
963 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
964 ++functions_added;
965 }
966 }
967 //FixupTypes();
968 }
969 return functions_added;
970}
971
972bool
973SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
974{
975 assert (sc.comp_unit);
Greg Clayton1f746072012-08-29 21:13:06 +0000976 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Greg Claytonda2455b2012-11-01 17:28:37 +0000977 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000978 {
Greg Claytonda2455b2012-11-01 17:28:37 +0000979 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000980
Greg Claytonda2455b2012-11-01 17:28:37 +0000981 if (cu_die)
982 {
983 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
984 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 +0000985
Greg Claytonda2455b2012-11-01 17:28:37 +0000986 // All file indexes in DWARF are one based and a file of index zero is
987 // supposed to be the compile unit itself.
988 support_files.Append (*sc.comp_unit);
989
990 return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
991 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000992 }
993 return false;
994}
995
996struct ParseDWARFLineTableCallbackInfo
997{
998 LineTable* line_table;
Greg Clayton7b0992d2013-04-18 22:45:39 +0000999 std::unique_ptr<LineSequence> sequence_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001000};
1001
1002//----------------------------------------------------------------------
1003// ParseStatementTableCallback
1004//----------------------------------------------------------------------
1005static void
1006ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
1007{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001008 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
1009 {
1010 // Just started parsing the line table
1011 }
1012 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
1013 {
1014 // Done parsing line table, nothing to do for the cleanup
1015 }
1016 else
1017 {
1018 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
Greg Clayton9422dd62013-03-04 21:46:16 +00001019 LineTable* line_table = info->line_table;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001020
Greg Clayton9422dd62013-03-04 21:46:16 +00001021 // If this is our first time here, we need to create a
1022 // sequence container.
1023 if (!info->sequence_ap.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001024 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001025 info->sequence_ap.reset(line_table->CreateLineSequenceContainer());
1026 assert(info->sequence_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001027 }
Greg Clayton9422dd62013-03-04 21:46:16 +00001028 line_table->AppendLineEntryToSequence (info->sequence_ap.get(),
1029 state.address,
1030 state.line,
1031 state.column,
1032 state.file,
1033 state.is_stmt,
1034 state.basic_block,
1035 state.prologue_end,
1036 state.epilogue_begin,
1037 state.end_sequence);
1038 if (state.end_sequence)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001039 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001040 // First, put the current sequence into the line table.
1041 line_table->InsertSequence(info->sequence_ap.get());
1042 // Then, empty it to prepare for the next sequence.
1043 info->sequence_ap->Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001044 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001045 }
1046}
1047
1048bool
1049SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1050{
1051 assert (sc.comp_unit);
1052 if (sc.comp_unit->GetLineTable() != NULL)
1053 return true;
1054
Greg Clayton1f746072012-08-29 21:13:06 +00001055 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001056 if (dwarf_cu)
1057 {
1058 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Greg Clayton129d12c2011-11-28 03:29:03 +00001059 if (dwarf_cu_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001060 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001061 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1062 if (cu_line_offset != DW_INVALID_OFFSET)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001063 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001064 std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
Greg Clayton129d12c2011-11-28 03:29:03 +00001065 if (line_table_ap.get())
1066 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001067 ParseDWARFLineTableCallbackInfo info;
1068 info.line_table = line_table_ap.get();
Greg Claytonc7bece562013-01-25 18:06:21 +00001069 lldb::offset_t offset = cu_line_offset;
Greg Clayton129d12c2011-11-28 03:29:03 +00001070 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
Greg Clayton9422dd62013-03-04 21:46:16 +00001071 if (m_debug_map_symfile)
1072 {
1073 // We have an object file that has a line table with addresses
1074 // that are not linked. We need to link the line table and convert
1075 // the addresses that are relative to the .o file into addresses
1076 // for the main executable.
1077 sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get()));
1078 }
1079 else
1080 {
1081 sc.comp_unit->SetLineTable(line_table_ap.release());
1082 return true;
1083 }
Greg Clayton129d12c2011-11-28 03:29:03 +00001084 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001085 }
1086 }
1087 }
1088 return false;
1089}
1090
1091size_t
1092SymbolFileDWARF::ParseFunctionBlocks
1093(
1094 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001095 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001096 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001097 const DWARFDebugInfoEntry *die,
1098 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001099 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001100)
1101{
1102 size_t blocks_added = 0;
1103 while (die != NULL)
1104 {
1105 dw_tag_t tag = die->Tag();
1106
1107 switch (tag)
1108 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001109 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001110 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001111 case DW_TAG_lexical_block:
1112 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001113 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001114 if (tag == DW_TAG_subprogram)
1115 {
1116 // Skip any DW_TAG_subprogram DIEs that are inside
1117 // of a normal or inlined functions. These will be
1118 // parsed on their own as separate entities.
1119
1120 if (depth > 0)
1121 break;
1122
1123 block = parent_block;
1124 }
1125 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001126 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001127 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001128 parent_block->AddChild(block_sp);
1129 block = block_sp.get();
1130 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001131 DWARFDebugRanges::RangeList ranges;
1132 const char *name = NULL;
1133 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001134
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001135 int decl_file = 0;
1136 int decl_line = 0;
1137 int decl_column = 0;
1138 int call_file = 0;
1139 int call_line = 0;
1140 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001141 if (die->GetDIENamesAndRanges (this,
1142 dwarf_cu,
1143 name,
1144 mangled_name,
1145 ranges,
1146 decl_file, decl_line, decl_column,
1147 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001148 {
1149 if (tag == DW_TAG_subprogram)
1150 {
1151 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001152 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001153 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001154 else if (tag == DW_TAG_inlined_subroutine)
1155 {
1156 // We get called here for inlined subroutines in two ways.
1157 // The first time is when we are making the Function object
1158 // for this inlined concrete instance. Since we're creating a top level block at
1159 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1160 // adjust the containing address.
1161 // The second time is when we are parsing the blocks inside the function that contains
1162 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1163 // function the offset will be for that function.
1164 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1165 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001166 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001167 }
1168 }
1169
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001170 AddRangesToBlock (*block, ranges, subprogram_low_pc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001171
1172 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1173 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001174 std::unique_ptr<Declaration> decl_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001175 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001176 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1177 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001178
Greg Clayton7b0992d2013-04-18 22:45:39 +00001179 std::unique_ptr<Declaration> call_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001180 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001181 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1182 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001183
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001184 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001185 }
1186
1187 ++blocks_added;
1188
Greg Claytondd7feaf2011-08-12 17:54:33 +00001189 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001190 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001191 blocks_added += ParseFunctionBlocks (sc,
1192 block,
1193 dwarf_cu,
1194 die->GetFirstChild(),
1195 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001196 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001197 }
1198 }
1199 }
1200 break;
1201 default:
1202 break;
1203 }
1204
Greg Claytondd7feaf2011-08-12 17:54:33 +00001205 // Only parse siblings of the block if we are not at depth zero. A depth
1206 // of zero indicates we are currently parsing the top level
1207 // DW_TAG_subprogram DIE
1208
1209 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001210 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001211 else
1212 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001213 }
1214 return blocks_added;
1215}
1216
Greg Claytonf0705c82011-10-22 03:33:13 +00001217bool
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001218SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu,
1219 const DWARFDebugInfoEntry *die,
1220 ClangASTContext::TemplateParameterInfos &template_param_infos)
1221{
1222 const dw_tag_t tag = die->Tag();
1223
1224 switch (tag)
1225 {
1226 case DW_TAG_template_type_parameter:
1227 case DW_TAG_template_value_parameter:
1228 {
1229 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
1230
1231 DWARFDebugInfoEntry::Attributes attributes;
1232 const size_t num_attributes = die->GetAttributes (this,
1233 dwarf_cu,
1234 fixed_form_sizes,
1235 attributes);
1236 const char *name = NULL;
1237 Type *lldb_type = NULL;
1238 clang_type_t clang_type = NULL;
1239 uint64_t uval64 = 0;
1240 bool uval64_valid = false;
1241 if (num_attributes > 0)
1242 {
1243 DWARFFormValue form_value;
1244 for (size_t i=0; i<num_attributes; ++i)
1245 {
1246 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1247
1248 switch (attr)
1249 {
1250 case DW_AT_name:
1251 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1252 name = form_value.AsCString(&get_debug_str_data());
1253 break;
1254
1255 case DW_AT_type:
1256 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1257 {
1258 const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu);
1259 lldb_type = ResolveTypeUID(type_die_offset);
1260 if (lldb_type)
1261 clang_type = lldb_type->GetClangForwardType();
1262 }
1263 break;
1264
1265 case DW_AT_const_value:
1266 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1267 {
1268 uval64_valid = true;
1269 uval64 = form_value.Unsigned();
1270 }
1271 break;
1272 default:
1273 break;
1274 }
1275 }
1276
Greg Clayton283b2652013-04-23 22:38:02 +00001277 clang::ASTContext *ast = GetClangASTContext().getASTContext();
1278 if (!clang_type)
1279 clang_type = ast->VoidTy.getAsOpaquePtr();
1280
1281 if (clang_type)
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001282 {
1283 bool is_signed = false;
Greg Clayton283b2652013-04-23 22:38:02 +00001284 if (name && name[0])
1285 template_param_infos.names.push_back(name);
1286 else
1287 template_param_infos.names.push_back(NULL);
1288
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001289 clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type));
Greg Clayton283b2652013-04-23 22:38:02 +00001290 if (tag == DW_TAG_template_value_parameter &&
1291 lldb_type != NULL &&
1292 ClangASTContext::IsIntegerType (clang_type, is_signed) &&
1293 uval64_valid)
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001294 {
1295 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
Greg Clayton283b2652013-04-23 22:38:02 +00001296 template_param_infos.args.push_back (clang::TemplateArgument (*ast,
Sean Callanan3d654b32012-09-24 22:25:51 +00001297 llvm::APSInt(apint),
1298 clang_qual_type));
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001299 }
1300 else
1301 {
1302 template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type));
1303 }
1304 }
1305 else
1306 {
1307 return false;
1308 }
1309
1310 }
1311 }
1312 return true;
1313
1314 default:
1315 break;
1316 }
1317 return false;
1318}
1319
1320bool
Greg Claytonf0705c82011-10-22 03:33:13 +00001321SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1322 const DWARFDebugInfoEntry *parent_die,
1323 ClangASTContext::TemplateParameterInfos &template_param_infos)
1324{
1325
1326 if (parent_die == NULL)
Filipe Cabecinhas52008c62012-05-23 16:24:11 +00001327 return false;
Greg Claytonf0705c82011-10-22 03:33:13 +00001328
Greg Claytonf0705c82011-10-22 03:33:13 +00001329 Args template_parameter_names;
1330 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1331 die != NULL;
1332 die = die->GetSibling())
1333 {
1334 const dw_tag_t tag = die->Tag();
1335
1336 switch (tag)
1337 {
1338 case DW_TAG_template_type_parameter:
1339 case DW_TAG_template_value_parameter:
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001340 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Claytonf0705c82011-10-22 03:33:13 +00001341 break;
1342
1343 default:
1344 break;
1345 }
1346 }
1347 if (template_param_infos.args.empty())
1348 return false;
1349 return template_param_infos.args.size() == template_param_infos.names.size();
1350}
1351
1352clang::ClassTemplateDecl *
1353SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001354 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001355 const char *parent_name,
1356 int tag_decl_kind,
1357 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1358{
1359 if (template_param_infos.IsValid())
1360 {
1361 std::string template_basename(parent_name);
1362 template_basename.erase (template_basename.find('<'));
1363 ClangASTContext &ast = GetClangASTContext();
1364
1365 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001366 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001367 template_basename.c_str(),
1368 tag_decl_kind,
1369 template_param_infos);
1370 }
1371 return NULL;
1372}
1373
Sean Callanana0b80ab2012-06-04 22:28:05 +00001374class SymbolFileDWARF::DelayedAddObjCClassProperty
1375{
1376public:
1377 DelayedAddObjCClassProperty
1378 (
1379 clang::ASTContext *ast,
1380 lldb::clang_type_t class_opaque_type,
1381 const char *property_name,
1382 lldb::clang_type_t property_opaque_type, // The property type is only required if you don't have an ivar decl
1383 clang::ObjCIvarDecl *ivar_decl,
1384 const char *property_setter_name,
1385 const char *property_getter_name,
1386 uint32_t property_attributes,
Greg Claytonc4ffd662013-03-08 01:37:30 +00001387 const ClangASTMetadata *metadata
Sean Callanana0b80ab2012-06-04 22:28:05 +00001388 ) :
1389 m_ast (ast),
1390 m_class_opaque_type (class_opaque_type),
1391 m_property_name (property_name),
1392 m_property_opaque_type (property_opaque_type),
1393 m_ivar_decl (ivar_decl),
1394 m_property_setter_name (property_setter_name),
1395 m_property_getter_name (property_getter_name),
Jim Ingham379397632012-10-27 02:54:13 +00001396 m_property_attributes (property_attributes)
Sean Callanana0b80ab2012-06-04 22:28:05 +00001397 {
Jim Ingham379397632012-10-27 02:54:13 +00001398 if (metadata != NULL)
1399 {
1400 m_metadata_ap.reset(new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001401 *m_metadata_ap = *metadata;
Jim Ingham379397632012-10-27 02:54:13 +00001402 }
1403 }
1404
1405 DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs)
1406 {
Daniel Malead4c5be62012-11-12 21:02:14 +00001407 *this = rhs;
1408 }
1409
1410 DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs)
1411 {
Jim Ingham379397632012-10-27 02:54:13 +00001412 m_ast = rhs.m_ast;
1413 m_class_opaque_type = rhs.m_class_opaque_type;
1414 m_property_name = rhs.m_property_name;
1415 m_property_opaque_type = rhs.m_property_opaque_type;
1416 m_ivar_decl = rhs.m_ivar_decl;
1417 m_property_setter_name = rhs.m_property_setter_name;
1418 m_property_getter_name = rhs.m_property_getter_name;
1419 m_property_attributes = rhs.m_property_attributes;
1420
1421 if (rhs.m_metadata_ap.get())
1422 {
1423 m_metadata_ap.reset (new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001424 *m_metadata_ap = *rhs.m_metadata_ap;
Jim Ingham379397632012-10-27 02:54:13 +00001425 }
Daniel Malead4c5be62012-11-12 21:02:14 +00001426 return *this;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001427 }
1428
1429 bool Finalize() const
1430 {
Greg Claytonc4ffd662013-03-08 01:37:30 +00001431 return ClangASTContext::AddObjCClassProperty (m_ast,
1432 m_class_opaque_type,
1433 m_property_name,
1434 m_property_opaque_type,
1435 m_ivar_decl,
1436 m_property_setter_name,
1437 m_property_getter_name,
1438 m_property_attributes,
1439 m_metadata_ap.get());
Sean Callanana0b80ab2012-06-04 22:28:05 +00001440 }
1441private:
1442 clang::ASTContext *m_ast;
1443 lldb::clang_type_t m_class_opaque_type;
1444 const char *m_property_name;
1445 lldb::clang_type_t m_property_opaque_type;
1446 clang::ObjCIvarDecl *m_ivar_decl;
1447 const char *m_property_setter_name;
1448 const char *m_property_getter_name;
1449 uint32_t m_property_attributes;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001450 std::unique_ptr<ClangASTMetadata> m_metadata_ap;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001451};
1452
Sean Callananfaa0bb32012-12-05 23:37:14 +00001453struct BitfieldInfo
1454{
1455 uint64_t bit_size;
1456 uint64_t bit_offset;
1457
1458 BitfieldInfo () :
1459 bit_size (LLDB_INVALID_ADDRESS),
1460 bit_offset (LLDB_INVALID_ADDRESS)
1461 {
1462 }
1463
1464 bool IsValid ()
1465 {
1466 return (bit_size != LLDB_INVALID_ADDRESS) &&
1467 (bit_offset != LLDB_INVALID_ADDRESS);
1468 }
1469};
1470
Greg Claytonc4ffd662013-03-08 01:37:30 +00001471
1472bool
1473SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu,
1474 const DWARFDebugInfoEntry *parent_die)
1475{
1476 if (parent_die)
1477 {
1478 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1479 {
1480 dw_tag_t tag = die->Tag();
1481 bool check_virtuality = false;
1482 switch (tag)
1483 {
1484 case DW_TAG_inheritance:
1485 case DW_TAG_subprogram:
1486 check_virtuality = true;
1487 break;
1488 default:
1489 break;
1490 }
1491 if (check_virtuality)
1492 {
1493 if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0)
1494 return true;
1495 }
1496 }
1497 }
1498 return false;
1499}
1500
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001501size_t
1502SymbolFileDWARF::ParseChildMembers
1503(
1504 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001505 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001506 const DWARFDebugInfoEntry *parent_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00001507 clang_type_t class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001508 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001509 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1510 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001511 DWARFDIECollection& member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001512 DelayedPropertyList& delayed_properties,
Sean Callananc7fbf732010-08-06 00:32:49 +00001513 AccessType& default_accessibility,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001514 bool &is_a_class,
1515 LayoutInfo &layout_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001516)
1517{
1518 if (parent_die == NULL)
1519 return 0;
1520
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001521 size_t count = 0;
1522 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001523 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001524 uint32_t member_idx = 0;
Sean Callananfaa0bb32012-12-05 23:37:14 +00001525 BitfieldInfo last_field_info;
Greg Claytond88d7592010-09-15 08:33:30 +00001526
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001527 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1528 {
1529 dw_tag_t tag = die->Tag();
1530
1531 switch (tag)
1532 {
1533 case DW_TAG_member:
Sean Callanan3d654b32012-09-24 22:25:51 +00001534 case DW_TAG_APPLE_property:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001535 {
1536 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001537 const size_t num_attributes = die->GetAttributes (this,
1538 dwarf_cu,
1539 fixed_form_sizes,
1540 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001541 if (num_attributes > 0)
1542 {
1543 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001544 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001545 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001546 const char *prop_name = NULL;
1547 const char *prop_getter_name = NULL;
1548 const char *prop_setter_name = NULL;
Greg Claytone528efd72013-02-26 23:45:18 +00001549 uint32_t prop_attributes = 0;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001550
1551
Greg Clayton24739922010-10-13 03:15:28 +00001552 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001553 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001554 AccessType accessibility = eAccessNone;
Greg Claytoncaab74e2012-01-28 00:48:57 +00001555 uint32_t member_byte_offset = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001556 size_t byte_size = 0;
1557 size_t bit_offset = 0;
1558 size_t bit_size = 0;
Greg Claytone528efd72013-02-26 23:45:18 +00001559 bool is_external = false; // On DW_TAG_members, this means the member is static
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001560 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001561 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001562 {
1563 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1564 DWARFFormValue form_value;
1565 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1566 {
1567 switch (attr)
1568 {
1569 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1570 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1571 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1572 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1573 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1574 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1575 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1576 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1577 case DW_AT_data_member_location:
Greg Claytoncaab74e2012-01-28 00:48:57 +00001578 if (form_value.BlockData())
1579 {
1580 Value initialValue(0);
1581 Value memberOffset(0);
1582 const DataExtractor& debug_info_data = get_debug_info_data();
1583 uint32_t block_length = form_value.Unsigned();
1584 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1585 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
1586 NULL, // clang::ASTContext *
1587 NULL, // ClangExpressionVariableList *
1588 NULL, // ClangExpressionDeclMap *
1589 NULL, // RegisterContext *
1590 debug_info_data,
1591 block_offset,
1592 block_length,
1593 eRegisterKindDWARF,
1594 &initialValue,
1595 memberOffset,
1596 NULL))
1597 {
1598 member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1599 }
1600 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001601 break;
1602
Greg Clayton8cf05932010-07-22 18:30:50 +00001603 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00001604 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001605 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1606 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1607 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1608 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00001609 case DW_AT_external: is_external = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001610
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001611 default:
Greg Clayton1b02c172012-03-14 21:00:47 +00001612 case DW_AT_declaration:
1613 case DW_AT_description:
1614 case DW_AT_mutable:
1615 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001616 case DW_AT_sibling:
1617 break;
1618 }
1619 }
1620 }
Sean Callanana6582262012-04-05 00:12:52 +00001621
1622 if (prop_name)
Sean Callanan751aac62012-03-29 19:07:06 +00001623 {
Sean Callanana6582262012-04-05 00:12:52 +00001624 ConstString fixed_getter;
1625 ConstString fixed_setter;
1626
1627 // Check if the property getter/setter were provided as full
1628 // names. We want basenames, so we extract them.
1629
1630 if (prop_getter_name && prop_getter_name[0] == '-')
1631 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001632 ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true);
1633 prop_getter_name = prop_getter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001634 }
1635
1636 if (prop_setter_name && prop_setter_name[0] == '-')
1637 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001638 ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true);
1639 prop_setter_name = prop_setter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001640 }
1641
1642 // If the names haven't been provided, they need to be
1643 // filled in.
1644
1645 if (!prop_getter_name)
1646 {
1647 prop_getter_name = prop_name;
1648 }
1649 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly))
1650 {
1651 StreamString ss;
1652
1653 ss.Printf("set%c%s:",
1654 toupper(prop_name[0]),
1655 &prop_name[1]);
1656
1657 fixed_setter.SetCString(ss.GetData());
1658 prop_setter_name = fixed_setter.GetCString();
1659 }
Sean Callanan751aac62012-03-29 19:07:06 +00001660 }
1661
1662 // Clang has a DWARF generation bug where sometimes it
Greg Clayton44953932011-10-25 01:25:35 +00001663 // represents fields that are references with bad byte size
1664 // and bit size/offset information such as:
1665 //
1666 // DW_AT_byte_size( 0x00 )
1667 // DW_AT_bit_size( 0x40 )
1668 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1669 //
1670 // So check the bit offset to make sure it is sane, and if
1671 // the values are not sane, remove them. If we don't do this
1672 // then we will end up with a crash if we try to use this
1673 // type in an expression when clang becomes unhappy with its
1674 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001675
Greg Clayton44953932011-10-25 01:25:35 +00001676 if (bit_offset > 128)
1677 {
1678 bit_size = 0;
1679 bit_offset = 0;
1680 }
1681
1682 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00001683 if (class_language == eLanguageTypeObjC ||
1684 class_language == eLanguageTypeObjC_plus_plus)
1685 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001686
1687 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1688 {
1689 // Not all compilers will mark the vtable pointer
1690 // member as artificial (llvm-gcc). We can't have
1691 // the virtual members in our classes otherwise it
1692 // throws off all child offsets since we end up
1693 // having and extra pointer sized member in our
1694 // class layouts.
1695 is_artificial = true;
1696 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001697
Greg Claytone528efd72013-02-26 23:45:18 +00001698 // Skip static members
1699 if (is_external && member_byte_offset == UINT32_MAX)
Greg Clayton973b6c92013-04-11 16:57:51 +00001700 {
1701 Type *var_type = ResolveTypeUID(encoding_uid);
1702
1703 if (var_type)
1704 {
1705 GetClangASTContext().AddVariableToRecordType (class_clang_type,
1706 name,
1707 var_type->GetClangLayoutType(),
1708 accessibility);
1709 }
Greg Claytone528efd72013-02-26 23:45:18 +00001710 break;
Greg Clayton973b6c92013-04-11 16:57:51 +00001711 }
Greg Claytone528efd72013-02-26 23:45:18 +00001712
Greg Clayton24739922010-10-13 03:15:28 +00001713 if (is_artificial == false)
1714 {
1715 Type *member_type = ResolveTypeUID(encoding_uid);
Sean Callananfa3ab452012-12-14 00:54:13 +00001716
Jim Inghame3ae82a2011-11-12 01:36:43 +00001717 clang::FieldDecl *field_decl = NULL;
Sean Callanan751aac62012-03-29 19:07:06 +00001718 if (tag == DW_TAG_member)
Greg Claytond16e1e52011-07-12 17:06:17 +00001719 {
Sean Callanan751aac62012-03-29 19:07:06 +00001720 if (member_type)
1721 {
1722 if (accessibility == eAccessNone)
1723 accessibility = default_accessibility;
1724 member_accessibilities.push_back(accessibility);
Sean Callananfaa0bb32012-12-05 23:37:14 +00001725
1726 BitfieldInfo this_field_info;
1727
1728 this_field_info.bit_size = bit_size;
1729
1730 if (member_byte_offset != UINT32_MAX || bit_size != 0)
Greg Clayton88bc7f32012-11-06 00:20:41 +00001731 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001732 /////////////////////////////////////////////////////////////
1733 // How to locate a field given the DWARF debug information
1734 //
1735 // AT_byte_size indicates the size of the word in which the
1736 // bit offset must be interpreted.
1737 //
1738 // AT_data_member_location indicates the byte offset of the
1739 // word from the base address of the structure.
1740 //
1741 // AT_bit_offset indicates how many bits into the word
1742 // (according to the host endianness) the low-order bit of
1743 // the field starts. AT_bit_offset can be negative.
1744 //
1745 // AT_bit_size indicates the size of the field in bits.
1746 /////////////////////////////////////////////////////////////
1747
1748 this_field_info.bit_offset = 0;
1749
1750 this_field_info.bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
1751
1752 if (GetObjectFile()->GetByteOrder() == eByteOrderLittle)
1753 {
1754 this_field_info.bit_offset += byte_size * 8;
1755 this_field_info.bit_offset -= (bit_offset + bit_size);
1756 }
1757 else
1758 {
1759 this_field_info.bit_offset += bit_offset;
1760 }
1761 }
1762
1763 // If the member to be emitted did not start on a character boundary and there is
1764 // empty space between the last field and this one, then we need to emit an
1765 // anonymous member filling up the space up to its start. There are three cases
1766 // here:
1767 //
1768 // 1 If the previous member ended on a character boundary, then we can emit an
1769 // anonymous member starting at the most recent character boundary.
1770 //
1771 // 2 If the previous member did not end on a character boundary and the distance
1772 // from the end of the previous member to the current member is less than a
1773 // word width, then we can emit an anonymous member starting right after the
1774 // previous member and right before this member.
1775 //
1776 // 3 If the previous member did not end on a character boundary and the distance
1777 // from the end of the previous member to the current member is greater than
1778 // or equal a word width, then we act as in Case 1.
1779
1780 const uint64_t character_width = 8;
1781 const uint64_t word_width = 32;
1782
1783 if (this_field_info.IsValid())
1784 {
1785 // Objective-C has invalid DW_AT_bit_offset values in older versions
1786 // of clang, so we have to be careful and only insert unnammed bitfields
Greg Clayton37c36e42012-11-27 00:59:26 +00001787 // if we have a new enough clang.
1788 bool detect_unnamed_bitfields = true;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001789
Greg Clayton37c36e42012-11-27 00:59:26 +00001790 if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus)
1791 detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields ();
1792
1793 if (detect_unnamed_bitfields)
Greg Clayton88bc7f32012-11-06 00:20:41 +00001794 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001795 BitfieldInfo anon_field_info;
1796
1797 if ((this_field_info.bit_offset % character_width) != 0) // not char aligned
Greg Clayton88bc7f32012-11-06 00:20:41 +00001798 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001799 uint64_t last_field_end = 0;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001800
Sean Callananfaa0bb32012-12-05 23:37:14 +00001801 if (last_field_info.IsValid())
1802 last_field_end = last_field_info.bit_offset + last_field_info.bit_size;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001803
Sean Callananfaa0bb32012-12-05 23:37:14 +00001804 if (this_field_info.bit_offset != last_field_end)
1805 {
1806 if (((last_field_end % character_width) == 0) || // case 1
1807 (this_field_info.bit_offset - last_field_end >= word_width)) // case 3
1808 {
1809 anon_field_info.bit_size = this_field_info.bit_offset % character_width;
1810 anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size;
1811 }
1812 else // case 2
1813 {
1814 anon_field_info.bit_size = this_field_info.bit_offset - last_field_end;
1815 anon_field_info.bit_offset = last_field_end;
1816 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00001817 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00001818 }
1819
Sean Callananfaa0bb32012-12-05 23:37:14 +00001820 if (anon_field_info.IsValid())
Greg Clayton88bc7f32012-11-06 00:20:41 +00001821 {
Greg Clayton88bc7f32012-11-06 00:20:41 +00001822 clang::FieldDecl *unnamed_bitfield_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
1823 NULL,
Sean Callananfaa0bb32012-12-05 23:37:14 +00001824 GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width),
Greg Clayton88bc7f32012-11-06 00:20:41 +00001825 accessibility,
Sean Callananfaa0bb32012-12-05 23:37:14 +00001826 anon_field_info.bit_size);
Greg Clayton88bc7f32012-11-06 00:20:41 +00001827
Sean Callananfaa0bb32012-12-05 23:37:14 +00001828 layout_info.field_offsets.insert(std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset));
Greg Clayton88bc7f32012-11-06 00:20:41 +00001829 }
1830 }
1831 }
Sean Callananfaa0bb32012-12-05 23:37:14 +00001832
Sean Callananfa3ab452012-12-14 00:54:13 +00001833 clang_type_t member_clang_type = member_type->GetClangLayoutType();
1834
1835 {
1836 // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>).
1837 // If the current field is at the end of the structure, then there is definitely no room for extra
1838 // elements and we override the type to array[0].
1839
1840 clang_type_t member_array_element_type;
1841 uint64_t member_array_size;
1842 bool member_array_is_incomplete;
1843
1844 if (GetClangASTContext().IsArrayType(member_clang_type,
1845 &member_array_element_type,
1846 &member_array_size,
1847 &member_array_is_incomplete) &&
1848 !member_array_is_incomplete)
1849 {
1850 uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX);
1851
1852 if (member_byte_offset >= parent_byte_size)
1853 {
1854 if (member_array_size != 1)
1855 {
1856 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,
1857 MakeUserID(die->GetOffset()),
1858 name,
1859 encoding_uid,
1860 MakeUserID(parent_die->GetOffset()));
1861 }
1862
Greg Clayton1c8ef472013-04-05 23:27:21 +00001863 member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0, false);
Sean Callananfa3ab452012-12-14 00:54:13 +00001864 }
1865 }
1866 }
1867
Greg Clayton88bc7f32012-11-06 00:20:41 +00001868 field_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
Sean Callanan751aac62012-03-29 19:07:06 +00001869 name,
Sean Callananfa3ab452012-12-14 00:54:13 +00001870 member_clang_type,
Sean Callanan751aac62012-03-29 19:07:06 +00001871 accessibility,
1872 bit_size);
Sean Callanan60217122012-04-13 00:10:03 +00001873
Greg Claytond0029442013-03-27 01:48:02 +00001874 GetClangASTContext().SetMetadataAsUserID (field_decl, MakeUserID(die->GetOffset()));
Sean Callananfaa0bb32012-12-05 23:37:14 +00001875
1876 if (this_field_info.IsValid())
1877 {
1878 layout_info.field_offsets.insert(std::make_pair(field_decl, this_field_info.bit_offset));
1879 last_field_info = this_field_info;
1880 }
Sean Callanan5b26f272012-02-04 08:49:35 +00001881 }
1882 else
1883 {
Sean Callanan751aac62012-03-29 19:07:06 +00001884 if (name)
Daniel Malead01b2952012-11-29 21:49:15 +00001885 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 +00001886 MakeUserID(die->GetOffset()),
1887 name,
1888 encoding_uid);
1889 else
Daniel Malead01b2952012-11-29 21:49:15 +00001890 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 +00001891 MakeUserID(die->GetOffset()),
1892 encoding_uid);
Sean Callanan5b26f272012-02-04 08:49:35 +00001893 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00001894 }
Sean Callanan751aac62012-03-29 19:07:06 +00001895
Jim Inghame3ae82a2011-11-12 01:36:43 +00001896 if (prop_name != NULL)
1897 {
Sean Callanan751aac62012-03-29 19:07:06 +00001898 clang::ObjCIvarDecl *ivar_decl = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001899
Sean Callanan751aac62012-03-29 19:07:06 +00001900 if (field_decl)
1901 {
1902 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
1903 assert (ivar_decl != NULL);
1904 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00001905
Jim Ingham379397632012-10-27 02:54:13 +00001906 ClangASTMetadata metadata;
1907 metadata.SetUserID (MakeUserID(die->GetOffset()));
Sean Callanana0b80ab2012-06-04 22:28:05 +00001908 delayed_properties.push_back(DelayedAddObjCClassProperty(GetClangASTContext().getASTContext(),
1909 class_clang_type,
1910 prop_name,
1911 member_type->GetClangLayoutType(),
1912 ivar_decl,
1913 prop_setter_name,
1914 prop_getter_name,
1915 prop_attributes,
Jim Ingham379397632012-10-27 02:54:13 +00001916 &metadata));
Sean Callanan60217122012-04-13 00:10:03 +00001917
Sean Callananad880762012-04-18 01:06:17 +00001918 if (ivar_decl)
Greg Claytond0029442013-03-27 01:48:02 +00001919 GetClangASTContext().SetMetadataAsUserID (ivar_decl, MakeUserID(die->GetOffset()));
Jim Inghame3ae82a2011-11-12 01:36:43 +00001920 }
Greg Clayton24739922010-10-13 03:15:28 +00001921 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001922 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00001923 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001924 }
1925 break;
1926
1927 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00001928 // Let the type parsing code handle this one for us.
1929 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001930 break;
1931
1932 case DW_TAG_inheritance:
1933 {
1934 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00001935 if (default_accessibility == eAccessNone)
1936 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001937 // TODO: implement DW_TAG_inheritance type parsing
1938 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001939 const size_t num_attributes = die->GetAttributes (this,
1940 dwarf_cu,
1941 fixed_form_sizes,
1942 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001943 if (num_attributes > 0)
1944 {
1945 Declaration decl;
1946 DWARFExpression location;
1947 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001948 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001949 bool is_virtual = false;
1950 bool is_base_of_class = true;
Greg Clayton2508b9b2012-11-01 23:20:02 +00001951 off_t member_byte_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001952 uint32_t i;
1953 for (i=0; i<num_attributes; ++i)
1954 {
1955 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1956 DWARFFormValue form_value;
1957 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1958 {
1959 switch (attr)
1960 {
1961 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1962 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1963 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1964 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton2508b9b2012-11-01 23:20:02 +00001965 case DW_AT_data_member_location:
1966 if (form_value.BlockData())
1967 {
1968 Value initialValue(0);
1969 Value memberOffset(0);
1970 const DataExtractor& debug_info_data = get_debug_info_data();
1971 uint32_t block_length = form_value.Unsigned();
1972 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1973 if (DWARFExpression::Evaluate (NULL,
1974 NULL,
1975 NULL,
1976 NULL,
1977 NULL,
1978 debug_info_data,
1979 block_offset,
1980 block_length,
1981 eRegisterKindDWARF,
1982 &initialValue,
1983 memberOffset,
1984 NULL))
1985 {
1986 member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1987 }
1988 }
1989 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001990
1991 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00001992 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001993 break;
1994
Greg Clayton1c8ef472013-04-05 23:27:21 +00001995 case DW_AT_virtuality: is_virtual = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001996 default:
1997 case DW_AT_sibling:
1998 break;
1999 }
2000 }
2001 }
2002
Greg Clayton526e5af2010-11-13 03:52:47 +00002003 Type *base_class_type = ResolveTypeUID(encoding_uid);
2004 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002005
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002006 clang_type_t base_class_clang_type = base_class_type->GetClangFullType();
2007 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002008 if (class_language == eLanguageTypeObjC)
2009 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002010 GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002011 }
2012 else
2013 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002014 base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type,
Greg Claytonba2d22d2010-11-13 22:57:37 +00002015 accessibility,
2016 is_virtual,
2017 is_base_of_class));
Greg Clayton2508b9b2012-11-01 23:20:02 +00002018
2019 if (is_virtual)
2020 {
2021 layout_info.vbase_offsets.insert(std::make_pair(ClangASTType::GetAsCXXRecordDecl(class_clang_type),
2022 clang::CharUnits::fromQuantity(member_byte_offset)));
2023 }
2024 else
2025 {
2026 layout_info.base_offsets.insert(std::make_pair(ClangASTType::GetAsCXXRecordDecl(class_clang_type),
2027 clang::CharUnits::fromQuantity(member_byte_offset)));
2028 }
Greg Clayton9e409562010-07-28 02:04:09 +00002029 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002030 }
2031 }
2032 break;
2033
2034 default:
2035 break;
2036 }
2037 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002038
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002039 return count;
2040}
2041
2042
2043clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00002044SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002045{
2046 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00002047 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002048 {
2049 DWARFCompileUnitSP cu_sp;
2050 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
2051 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00002052 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00002053 }
2054 return NULL;
2055}
2056
2057clang::DeclContext*
2058SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
2059{
Greg Clayton81c22f62011-10-19 18:09:39 +00002060 if (UserIDMatches(type_uid))
2061 return GetClangDeclContextForDIEOffset (sc, type_uid);
2062 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002063}
2064
2065Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00002066SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002067{
Greg Clayton81c22f62011-10-19 18:09:39 +00002068 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002069 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002070 DWARFDebugInfo* debug_info = DebugInfo();
2071 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00002072 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002073 DWARFCompileUnitSP cu_sp;
2074 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00002075 const bool assert_not_being_parsed = true;
2076 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00002077 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002078 }
2079 return NULL;
2080}
2081
Greg Claytoncab36a32011-12-08 05:16:30 +00002082Type*
2083SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00002084{
Greg Claytoncab36a32011-12-08 05:16:30 +00002085 if (die != NULL)
2086 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002087 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00002088 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002089 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002090 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
2091 die->GetOffset(),
2092 DW_TAG_value_to_name(die->Tag()),
2093 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00002094
Greg Claytoncab36a32011-12-08 05:16:30 +00002095 // We might be coming in in the middle of a type tree (a class
2096 // withing a class, an enum within a class), so parse any needed
2097 // parent DIEs before we get to this one...
2098 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2099 switch (decl_ctx_die->Tag())
2100 {
2101 case DW_TAG_structure_type:
2102 case DW_TAG_union_type:
2103 case DW_TAG_class_type:
2104 {
2105 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00002106 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002107 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002108 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
2109 die->GetOffset(),
2110 DW_TAG_value_to_name(die->Tag()),
2111 die->GetName(this, cu),
2112 decl_ctx_die->GetOffset());
Greg Clayton219cf312012-03-30 00:51:13 +00002113//
2114// Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
2115// if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
2116// {
2117// if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002118// GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton219cf312012-03-30 00:51:13 +00002119// "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
2120// die->GetOffset(),
2121// DW_TAG_value_to_name(die->Tag()),
2122// die->GetName(this, cu),
2123// decl_ctx_die->GetOffset());
2124// // Ask the type to complete itself if it already hasn't since if we
2125// // want a function (method or static) from a class, the class must
2126// // create itself and add it's own methods and class functions.
2127// if (parent_type)
2128// parent_type->GetClangFullType();
2129// }
Greg Claytoncab36a32011-12-08 05:16:30 +00002130 }
2131 break;
2132
2133 default:
2134 break;
2135 }
2136 return ResolveType (cu, die);
2137 }
2138 return NULL;
2139}
2140
Greg Clayton6beaaa62011-01-17 03:46:26 +00002141// This function is used when SymbolFileDWARFDebugMap owns a bunch of
2142// SymbolFileDWARF objects to detect if this DWARF file is the one that
2143// can resolve a clang_type.
2144bool
2145SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type)
2146{
2147 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
2148 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
2149 return die != NULL;
2150}
2151
2152
Greg Clayton1be10fc2010-09-29 01:12:09 +00002153lldb::clang_type_t
2154SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
2155{
2156 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton6beaaa62011-01-17 03:46:26 +00002157 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
2158 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002159 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00002160 {
2161 // We have already resolved this type...
2162 return clang_type;
2163 }
2164 // Once we start resolving this type, remove it from the forward declaration
2165 // map in case anyone child members or other types require this type to get resolved.
2166 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
2167 // are done.
Greg Clayton6beaaa62011-01-17 03:46:26 +00002168 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers);
Greg Clayton73b472d2010-10-27 03:32:59 +00002169
Greg Clayton1be10fc2010-09-29 01:12:09 +00002170
Greg Clayton85ae2e12011-10-18 23:36:41 +00002171 // Disable external storage for this type so we don't get anymore
2172 // clang::ExternalASTSource queries for this type.
2173 ClangASTContext::SetHasExternalStorage (clang_type, false);
2174
Greg Clayton450e3f32010-10-12 02:24:53 +00002175 DWARFDebugInfo* debug_info = DebugInfo();
2176
Greg Clayton53eb1c22012-04-02 22:59:12 +00002177 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002178 Type *type = m_die_to_type.lookup (die);
2179
2180 const dw_tag_t tag = die->Tag();
2181
Greg Clayton5160ce52013-03-27 23:08:40 +00002182 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
Greg Clayton3bffb082011-12-10 02:15:28 +00002183 if (log)
Greg Claytonbaf95da2012-03-30 23:50:54 +00002184 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002185 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002186 "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...",
Greg Claytond61c0fc2012-04-23 22:55:20 +00002187 MakeUserID(die->GetOffset()),
2188 DW_TAG_value_to_name(tag),
2189 type->GetName().AsCString());
Greg Claytonbaf95da2012-03-30 23:50:54 +00002190
Greg Claytonbaf95da2012-03-30 23:50:54 +00002191 }
Greg Clayton1be10fc2010-09-29 01:12:09 +00002192 assert (clang_type);
2193 DWARFDebugInfoEntry::Attributes attributes;
2194
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002195 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002196
2197 switch (tag)
2198 {
2199 case DW_TAG_structure_type:
2200 case DW_TAG_union_type:
2201 case DW_TAG_class_type:
Greg Claytonc93237c2010-10-01 20:48:32 +00002202 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002203 LayoutInfo layout_info;
Sean Callanan77a1fd32012-02-27 20:07:01 +00002204
Greg Clayton1be10fc2010-09-29 01:12:09 +00002205 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002206 if (die->HasChildren())
Greg Claytonc93237c2010-10-01 20:48:32 +00002207 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002208
Sean Callanan77a1fd32012-02-27 20:07:01 +00002209 LanguageType class_language = eLanguageTypeUnknown;
2210 bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
2211 if (is_objc_class)
Greg Clayton219cf312012-03-30 00:51:13 +00002212 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002213 class_language = eLanguageTypeObjC;
Greg Clayton219cf312012-03-30 00:51:13 +00002214 // For objective C we don't start the definition when
2215 // the class is created.
2216 ast.StartTagDeclarationDefinition (clang_type);
2217 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002218
2219 int tag_decl_kind = -1;
2220 AccessType default_accessibility = eAccessNone;
2221 if (tag == DW_TAG_structure_type)
2222 {
2223 tag_decl_kind = clang::TTK_Struct;
2224 default_accessibility = eAccessPublic;
2225 }
2226 else if (tag == DW_TAG_union_type)
2227 {
2228 tag_decl_kind = clang::TTK_Union;
2229 default_accessibility = eAccessPublic;
2230 }
2231 else if (tag == DW_TAG_class_type)
2232 {
2233 tag_decl_kind = clang::TTK_Class;
2234 default_accessibility = eAccessPrivate;
2235 }
2236
Greg Clayton53eb1c22012-04-02 22:59:12 +00002237 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002238 std::vector<clang::CXXBaseSpecifier *> base_classes;
2239 std::vector<int> member_accessibilities;
2240 bool is_a_class = false;
2241 // Parse members and base classes first
2242 DWARFDIECollection member_function_dies;
Sean Callanana0b80ab2012-06-04 22:28:05 +00002243
2244 DelayedPropertyList delayed_properties;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002245 ParseChildMembers (sc,
Greg Clayton53eb1c22012-04-02 22:59:12 +00002246 dwarf_cu,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002247 die,
2248 clang_type,
2249 class_language,
2250 base_classes,
2251 member_accessibilities,
2252 member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002253 delayed_properties,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002254 default_accessibility,
2255 is_a_class,
2256 layout_info);
2257
2258 // Now parse any methods if there were any...
2259 size_t num_functions = member_function_dies.Size();
2260 if (num_functions > 0)
2261 {
2262 for (size_t i=0; i<num_functions; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002263 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002264 ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytoncaab74e2012-01-28 00:48:57 +00002265 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002266 }
2267
2268 if (class_language == eLanguageTypeObjC)
2269 {
Greg Clayton84db9102012-03-26 23:03:23 +00002270 std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(ast.getASTContext(), clang_type));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002271 if (!class_str.empty())
Greg Claytoncaab74e2012-01-28 00:48:57 +00002272 {
Greg Clayton450e3f32010-10-12 02:24:53 +00002273
Sean Callanan77a1fd32012-02-27 20:07:01 +00002274 DIEArray method_die_offsets;
2275 if (m_using_apple_tables)
Greg Clayton95d87902011-11-11 03:16:25 +00002276 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002277 if (m_apple_objc_ap.get())
2278 m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets);
2279 }
2280 else
2281 {
2282 if (!m_indexed)
2283 Index ();
Greg Claytoncaab74e2012-01-28 00:48:57 +00002284
Sean Callanan77a1fd32012-02-27 20:07:01 +00002285 ConstString class_name (class_str.c_str());
2286 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
2287 }
2288
2289 if (!method_die_offsets.empty())
2290 {
2291 DWARFDebugInfo* debug_info = DebugInfo();
2292
2293 DWARFCompileUnit* method_cu = NULL;
2294 const size_t num_matches = method_die_offsets.size();
2295 for (size_t i=0; i<num_matches; ++i)
Greg Clayton95d87902011-11-11 03:16:25 +00002296 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002297 const dw_offset_t die_offset = method_die_offsets[i];
2298 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
2299
2300 if (method_die)
2301 ResolveType (method_cu, method_die);
2302 else
Greg Claytoncaab74e2012-01-28 00:48:57 +00002303 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002304 if (m_using_apple_tables)
2305 {
2306 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n",
2307 die_offset, class_str.c_str());
2308 }
2309 }
2310 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002311 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002312
2313 for (DelayedPropertyList::const_iterator pi = delayed_properties.begin(), pe = delayed_properties.end();
2314 pi != pe;
2315 ++pi)
2316 pi->Finalize();
Greg Clayton450e3f32010-10-12 02:24:53 +00002317 }
2318 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002319
2320 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2321 // need to tell the clang type it is actually a class.
2322 if (class_language != eLanguageTypeObjC)
2323 {
2324 if (is_a_class && tag_decl_kind != clang::TTK_Class)
2325 ast.SetTagTypeKind (clang_type, clang::TTK_Class);
2326 }
2327
2328 // Since DW_TAG_structure_type gets used for both classes
2329 // and structures, we may need to set any DW_TAG_member
2330 // fields to have a "private" access if none was specified.
2331 // When we parsed the child members we tracked that actual
2332 // accessibility value for each DW_TAG_member in the
2333 // "member_accessibilities" array. If the value for the
2334 // member is zero, then it was set to the "default_accessibility"
2335 // which for structs was "public". Below we correct this
2336 // by setting any fields to "private" that weren't correctly
2337 // set.
2338 if (is_a_class && !member_accessibilities.empty())
2339 {
2340 // This is a class and all members that didn't have
2341 // their access specified are private.
2342 ast.SetDefaultAccessForRecordFields (clang_type,
2343 eAccessPrivate,
2344 &member_accessibilities.front(),
2345 member_accessibilities.size());
2346 }
2347
2348 if (!base_classes.empty())
2349 {
2350 ast.SetBaseClassesForClassType (clang_type,
2351 &base_classes.front(),
2352 base_classes.size());
2353
2354 // Clang will copy each CXXBaseSpecifier in "base_classes"
2355 // so we have to free them all.
2356 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
2357 base_classes.size());
2358 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002359 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002360 }
Sean Callanane8c0cfb2012-03-02 01:03:45 +00002361
2362 ast.BuildIndirectFields (clang_type);
2363
Sean Callanan77a1fd32012-02-27 20:07:01 +00002364 ast.CompleteTagDeclarationDefinition (clang_type);
Sean Callanan5b26f272012-02-04 08:49:35 +00002365
Greg Clayton2508b9b2012-11-01 23:20:02 +00002366 if (!layout_info.field_offsets.empty() ||
2367 !layout_info.base_offsets.empty() ||
2368 !layout_info.vbase_offsets.empty() )
Greg Claytoncaab74e2012-01-28 00:48:57 +00002369 {
2370 if (type)
2371 layout_info.bit_size = type->GetByteSize() * 8;
2372 if (layout_info.bit_size == 0)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002373 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002374
2375 clang::CXXRecordDecl *record_decl = ClangASTType::GetAsCXXRecordDecl(clang_type);
2376 if (record_decl)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002377 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002378 if (log)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002379 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002380 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002381 "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])",
Greg Claytoncaab74e2012-01-28 00:48:57 +00002382 clang_type,
2383 record_decl,
2384 layout_info.bit_size,
2385 layout_info.alignment,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002386 (uint32_t)layout_info.field_offsets.size(),
2387 (uint32_t)layout_info.base_offsets.size(),
2388 (uint32_t)layout_info.vbase_offsets.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002389
Greg Clayton2508b9b2012-11-01 23:20:02 +00002390 uint32_t idx;
2391 {
Greg Clayton821ac6d2012-01-28 02:22:27 +00002392 llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002393 for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002394 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002395 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002396 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = { bit_offset=%u, name='%s' }",
Greg Clayton821ac6d2012-01-28 02:22:27 +00002397 clang_type,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002398 idx,
Greg Clayton821ac6d2012-01-28 02:22:27 +00002399 (uint32_t)pos->second,
2400 pos->first->getNameAsString().c_str());
2401 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002402 }
2403
2404 {
2405 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos, base_end = layout_info.base_offsets.end();
2406 for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; ++base_pos, ++idx)
2407 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002408 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002409 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] = { byte_offset=%u, name='%s' }",
2410 clang_type,
2411 idx,
2412 (uint32_t)base_pos->second.getQuantity(),
2413 base_pos->first->getNameAsString().c_str());
2414 }
2415 }
2416 {
2417 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos, vbase_end = layout_info.vbase_offsets.end();
2418 for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; ++vbase_pos, ++idx)
2419 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002420 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002421 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) vbase[%u] = { byte_offset=%u, name='%s' }",
2422 clang_type,
2423 idx,
2424 (uint32_t)vbase_pos->second.getQuantity(),
2425 vbase_pos->first->getNameAsString().c_str());
2426 }
2427 }
Greg Clayton821ac6d2012-01-28 02:22:27 +00002428 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002429 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2430 }
2431 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002432 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002433
Greg Claytonc93237c2010-10-01 20:48:32 +00002434 return clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002435
2436 case DW_TAG_enumeration_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002437 ast.StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002438 if (die->HasChildren())
2439 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002440 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00002441 bool is_signed = false;
2442 ast.IsIntegerType(clang_type, is_signed);
2443 ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002444 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002445 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002446 return clang_type;
2447
2448 default:
2449 assert(false && "not a forward clang type decl!");
2450 break;
2451 }
2452 return NULL;
2453}
2454
Greg Claytonc685f8e2010-09-15 04:15:46 +00002455Type*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002456SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002457{
2458 if (type_die != NULL)
2459 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002460 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00002461
Greg Claytonc685f8e2010-09-15 04:15:46 +00002462 if (type == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002463 type = GetTypeForDIE (dwarf_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00002464
Greg Clayton24739922010-10-13 03:15:28 +00002465 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00002466 {
2467 if (type != DIE_IS_BEING_PARSED)
2468 return type;
2469
2470 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
Greg Clayton53eb1c22012-04-02 22:59:12 +00002471 type_die->GetOffset(),
2472 DW_TAG_value_to_name(type_die->Tag()),
2473 type_die->GetName(this, dwarf_cu));
Jim Inghamc3549282012-01-11 02:21:12 +00002474
2475 }
2476 else
2477 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002478 }
2479 return NULL;
2480}
2481
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002482CompileUnit*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002483SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002484{
2485 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002486 if (dwarf_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002487 {
2488 // The symbol vendor doesn't know about this compile unit, we
2489 // need to parse and add it to the symbol vendor object.
Greg Clayton53eb1c22012-04-02 22:59:12 +00002490 return ParseCompileUnit(dwarf_cu, cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002491 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00002492 return (CompileUnit*)dwarf_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002493}
2494
2495bool
Greg Clayton53eb1c22012-04-02 22:59:12 +00002496SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002497{
Greg Clayton72310352013-02-23 04:12:47 +00002498 sc.Clear(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002499 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002500 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002501
Greg Clayton81c22f62011-10-19 18:09:39 +00002502 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002503 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002504 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002505
2506 if (sc.function)
2507 {
Greg Claytone72dfb32012-02-24 01:59:29 +00002508 sc.module_sp = sc.function->CalculateSymbolContextModule();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002509 return true;
2510 }
2511
2512 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002513}
2514
2515uint32_t
2516SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2517{
2518 Timer scoped_timer(__PRETTY_FUNCTION__,
Daniel Malead01b2952012-11-29 21:49:15 +00002519 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)",
Greg Claytone72dfb32012-02-24 01:59:29 +00002520 so_addr.GetSection().get(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002521 so_addr.GetOffset(),
2522 resolve_scope);
2523 uint32_t resolved = 0;
2524 if (resolve_scope & ( eSymbolContextCompUnit |
2525 eSymbolContextFunction |
2526 eSymbolContextBlock |
2527 eSymbolContextLineEntry))
2528 {
2529 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2530
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002531 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00002532 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002533 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002534 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002535 if (cu_offset != DW_INVALID_OFFSET)
2536 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002537 uint32_t cu_idx = DW_INVALID_INDEX;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002538 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
2539 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002540 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002541 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002542 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002543 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002544 resolved |= eSymbolContextCompUnit;
2545
Greg Clayton6ab80132012-12-12 17:30:52 +00002546 bool force_check_line_table = false;
Greg Clayton526a4ae2012-05-16 22:09:01 +00002547 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2548 {
2549 DWARFDebugInfoEntry *function_die = NULL;
2550 DWARFDebugInfoEntry *block_die = NULL;
2551 if (resolve_scope & eSymbolContextBlock)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002552 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002553 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
2554 }
2555 else
2556 {
2557 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL);
2558 }
2559
2560 if (function_die != NULL)
2561 {
2562 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2563 if (sc.function == NULL)
2564 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2565 }
2566 else
2567 {
2568 // We might have had a compile unit that had discontiguous
2569 // address ranges where the gaps are symbols that don't have
2570 // any debug info. Discontiguous compile unit address ranges
2571 // should only happen when there aren't other functions from
2572 // other compile units in these gaps. This helps keep the size
2573 // of the aranges down.
Greg Clayton6ab80132012-12-12 17:30:52 +00002574 force_check_line_table = true;
Greg Clayton526a4ae2012-05-16 22:09:01 +00002575 }
2576
2577 if (sc.function != NULL)
2578 {
2579 resolved |= eSymbolContextFunction;
2580
2581 if (resolve_scope & eSymbolContextBlock)
2582 {
2583 Block& block = sc.function->GetBlock (true);
2584
2585 if (block_die != NULL)
2586 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2587 else
2588 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2589 if (sc.block)
2590 resolved |= eSymbolContextBlock;
2591 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002592 }
2593 }
Greg Clayton6ab80132012-12-12 17:30:52 +00002594
2595 if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table)
2596 {
2597 LineTable *line_table = sc.comp_unit->GetLineTable();
2598 if (line_table != NULL)
2599 {
Greg Clayton9422dd62013-03-04 21:46:16 +00002600 // And address that makes it into this function should be in terms
2601 // of this debug file if there is no debug map, or it will be an
2602 // address in the .o file which needs to be fixed up to be in terms
2603 // of the debug map executable. Either way, calling FixupAddress()
2604 // will work for us.
2605 Address exe_so_addr (so_addr);
2606 if (FixupAddress(exe_so_addr))
Greg Clayton6ab80132012-12-12 17:30:52 +00002607 {
Greg Clayton9422dd62013-03-04 21:46:16 +00002608 if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry))
Greg Clayton6ab80132012-12-12 17:30:52 +00002609 {
2610 resolved |= eSymbolContextLineEntry;
2611 }
2612 }
Greg Clayton6ab80132012-12-12 17:30:52 +00002613 }
2614 }
2615
2616 if (force_check_line_table && !(resolved & eSymbolContextLineEntry))
2617 {
2618 // We might have had a compile unit that had discontiguous
2619 // address ranges where the gaps are symbols that don't have
2620 // any debug info. Discontiguous compile unit address ranges
2621 // should only happen when there aren't other functions from
2622 // other compile units in these gaps. This helps keep the size
2623 // of the aranges down.
2624 sc.comp_unit = NULL;
2625 resolved &= ~eSymbolContextCompUnit;
2626 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002627 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002628 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002629 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002630 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.",
2631 cu_offset,
2632 cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002633 }
2634 }
2635 }
2636 }
2637 }
2638 return resolved;
2639}
2640
2641
2642
2643uint32_t
2644SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
2645{
2646 const uint32_t prev_size = sc_list.GetSize();
2647 if (resolve_scope & eSymbolContextCompUnit)
2648 {
2649 DWARFDebugInfo* debug_info = DebugInfo();
2650 if (debug_info)
2651 {
2652 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002653 DWARFCompileUnit* dwarf_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002654
Greg Clayton53eb1c22012-04-02 22:59:12 +00002655 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002656 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002657 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton1f746072012-08-29 21:13:06 +00002658 const bool full_match = file_spec.GetDirectory();
2659 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 +00002660 if (check_inlines || file_spec_matches_cu_file_spec)
2661 {
2662 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton53eb1c22012-04-02 22:59:12 +00002663 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002664 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002665 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002666 uint32_t file_idx = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002667
Greg Clayton526a4ae2012-05-16 22:09:01 +00002668 // If we are looking for inline functions only and we don't
2669 // find it in the support files, we are done.
2670 if (check_inlines)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002671 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002672 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
2673 if (file_idx == UINT32_MAX)
2674 continue;
2675 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002676
Greg Clayton526a4ae2012-05-16 22:09:01 +00002677 if (line != 0)
2678 {
2679 LineTable *line_table = sc.comp_unit->GetLineTable();
2680
2681 if (line_table != NULL && line != 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002682 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002683 // We will have already looked up the file index if
2684 // we are searching for inline entries.
2685 if (!check_inlines)
2686 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002687
Greg Clayton526a4ae2012-05-16 22:09:01 +00002688 if (file_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002689 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002690 uint32_t found_line;
2691 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
2692 found_line = sc.line_entry.line;
2693
2694 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002695 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002696 sc.function = NULL;
2697 sc.block = NULL;
2698 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002699 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002700 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
2701 if (file_vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002702 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002703 DWARFDebugInfoEntry *function_die = NULL;
2704 DWARFDebugInfoEntry *block_die = NULL;
2705 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002706
Greg Clayton526a4ae2012-05-16 22:09:01 +00002707 if (function_die != NULL)
2708 {
2709 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2710 if (sc.function == NULL)
2711 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2712 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002713
Greg Clayton526a4ae2012-05-16 22:09:01 +00002714 if (sc.function != NULL)
2715 {
2716 Block& block = sc.function->GetBlock (true);
2717
2718 if (block_die != NULL)
2719 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2720 else
2721 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2722 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002723 }
2724 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002725
Greg Clayton526a4ae2012-05-16 22:09:01 +00002726 sc_list.Append(sc);
2727 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2728 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002729 }
2730 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002731 else if (file_spec_matches_cu_file_spec && !check_inlines)
2732 {
2733 // only append the context if we aren't looking for inline call sites
2734 // by file and line and if the file spec matches that of the compile unit
2735 sc_list.Append(sc);
2736 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002737 }
2738 else if (file_spec_matches_cu_file_spec && !check_inlines)
2739 {
2740 // only append the context if we aren't looking for inline call sites
2741 // by file and line and if the file spec matches that of the compile unit
2742 sc_list.Append(sc);
2743 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002744
Greg Clayton526a4ae2012-05-16 22:09:01 +00002745 if (!check_inlines)
2746 break;
2747 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002748 }
2749 }
2750 }
2751 }
2752 return sc_list.GetSize() - prev_size;
2753}
2754
2755void
2756SymbolFileDWARF::Index ()
2757{
2758 if (m_indexed)
2759 return;
2760 m_indexed = true;
2761 Timer scoped_timer (__PRETTY_FUNCTION__,
2762 "SymbolFileDWARF::Index (%s)",
2763 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
2764
2765 DWARFDebugInfo* debug_info = DebugInfo();
2766 if (debug_info)
2767 {
2768 uint32_t cu_idx = 0;
2769 const uint32_t num_compile_units = GetNumCompileUnits();
2770 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2771 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002772 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002773
Greg Clayton53eb1c22012-04-02 22:59:12 +00002774 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002775
Greg Clayton53eb1c22012-04-02 22:59:12 +00002776 dwarf_cu->Index (cu_idx,
2777 m_function_basename_index,
2778 m_function_fullname_index,
2779 m_function_method_index,
2780 m_function_selector_index,
2781 m_objc_class_selectors_index,
2782 m_global_index,
2783 m_type_index,
2784 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002785
2786 // Keep memory down by clearing DIEs if this generate function
2787 // caused them to be parsed
2788 if (clear_dies)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002789 dwarf_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002790 }
2791
Greg Claytond4a2b372011-09-12 23:21:58 +00002792 m_function_basename_index.Finalize();
2793 m_function_fullname_index.Finalize();
2794 m_function_method_index.Finalize();
2795 m_function_selector_index.Finalize();
2796 m_objc_class_selectors_index.Finalize();
2797 m_global_index.Finalize();
2798 m_type_index.Finalize();
2799 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002800
Greg Clayton24739922010-10-13 03:15:28 +00002801#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00002802 StreamFile s(stdout, false);
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00002803 s.Printf ("DWARF index for '%s':",
2804 GetObjectFile()->GetFileSpec().GetPath().c_str());
Greg Claytonba2d22d2010-11-13 22:57:37 +00002805 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
2806 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
2807 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
2808 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
2809 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
2810 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00002811 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00002812 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002813#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002814 }
2815}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002816
2817bool
2818SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
2819{
2820 if (namespace_decl == NULL)
2821 {
2822 // Invalid namespace decl which means we aren't matching only things
2823 // in this symbol file, so return true to indicate it matches this
2824 // symbol file.
2825 return true;
2826 }
2827
2828 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
2829
2830 if (namespace_ast == NULL)
2831 return true; // No AST in the "namespace_decl", return true since it
2832 // could then match any symbol file, including this one
2833
2834 if (namespace_ast == GetClangASTContext().getASTContext())
2835 return true; // The ASTs match, return true
2836
2837 // The namespace AST was valid, and it does not match...
Greg Clayton5160ce52013-03-27 23:08:40 +00002838 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Sean Callananc41e68b2011-10-13 21:08:11 +00002839
2840 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002841 GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00002842
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002843 return false;
2844}
2845
Greg Clayton2506a7a2011-10-12 23:34:26 +00002846bool
2847SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
2848 DWARFCompileUnit* cu,
2849 const DWARFDebugInfoEntry* die)
2850{
2851 // No namespace specified, so the answesr i
2852 if (namespace_decl == NULL)
2853 return true;
Sean Callananebe60672011-10-13 21:50:33 +00002854
Greg Clayton5160ce52013-03-27 23:08:40 +00002855 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002856
Greg Clayton437a1352012-04-09 22:43:43 +00002857 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
2858 clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00002859 if (decl_ctx_die)
Greg Clayton437a1352012-04-09 22:43:43 +00002860 {
Greg Clayton2506a7a2011-10-12 23:34:26 +00002861 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
Greg Clayton437a1352012-04-09 22:43:43 +00002862
Greg Clayton2506a7a2011-10-12 23:34:26 +00002863 if (clang_namespace_decl)
2864 {
2865 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00002866 {
2867 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002868 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00002869 return false;
Sean Callananebe60672011-10-13 21:50:33 +00002870 }
2871
Greg Clayton437a1352012-04-09 22:43:43 +00002872 if (clang_namespace_decl == die_clang_decl_ctx)
2873 return true;
2874 else
Greg Clayton2506a7a2011-10-12 23:34:26 +00002875 return false;
Greg Clayton2506a7a2011-10-12 23:34:26 +00002876 }
2877 else
2878 {
2879 // We have a namespace_decl that was not NULL but it contained
2880 // a NULL "clang::NamespaceDecl", so this means the global namespace
2881 // So as long the the contained decl context DIE isn't a namespace
2882 // we should be ok.
2883 if (decl_ctx_die->Tag() != DW_TAG_namespace)
2884 return true;
2885 }
2886 }
Sean Callananebe60672011-10-13 21:50:33 +00002887
2888 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002889 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00002890
Greg Clayton2506a7a2011-10-12 23:34:26 +00002891 return false;
2892}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002893uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00002894SymbolFileDWARF::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 +00002895{
Greg Clayton5160ce52013-03-27 23:08:40 +00002896 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00002897
2898 if (log)
2899 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002900 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002901 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
2902 name.GetCString(),
2903 namespace_decl,
2904 append,
2905 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002906 }
Sean Callanan213fdb82011-10-13 01:49:10 +00002907
2908 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2909 return 0;
2910
Greg Claytonc685f8e2010-09-15 04:15:46 +00002911 DWARFDebugInfo* info = DebugInfo();
2912 if (info == NULL)
2913 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002914
2915 // If we aren't appending the results to this list, then clear the list
2916 if (!append)
2917 variables.Clear();
2918
2919 // Remember how many variables are in the list before we search in case
2920 // we are appending the results to a variable list.
2921 const uint32_t original_size = variables.GetSize();
2922
Greg Claytond4a2b372011-09-12 23:21:58 +00002923 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002924
Greg Clayton97fbc342011-10-20 22:30:33 +00002925 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002926 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002927 if (m_apple_names_ap.get())
2928 {
2929 const char *name_cstr = name.GetCString();
2930 const char *base_name_start;
2931 const char *base_name_end = NULL;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002932
Greg Clayton97fbc342011-10-20 22:30:33 +00002933 if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end))
2934 base_name_start = name_cstr;
2935
2936 m_apple_names_ap->FindByName (base_name_start, die_offsets);
2937 }
Greg Clayton7f995132011-10-04 22:41:51 +00002938 }
2939 else
2940 {
2941 // Index the DWARF if we haven't already
2942 if (!m_indexed)
2943 Index ();
2944
2945 m_global_index.Find (name, die_offsets);
2946 }
2947
Greg Clayton437a1352012-04-09 22:43:43 +00002948 const size_t num_die_matches = die_offsets.size();
2949 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002950 {
Greg Clayton7f995132011-10-04 22:41:51 +00002951 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00002952 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00002953 assert (sc.module_sp);
2954
Greg Claytond4a2b372011-09-12 23:21:58 +00002955 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00002956 DWARFCompileUnit* dwarf_cu = NULL;
2957 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton437a1352012-04-09 22:43:43 +00002958 bool done = false;
2959 for (size_t i=0; i<num_die_matches && !done; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002960 {
2961 const dw_offset_t die_offset = die_offsets[i];
2962 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002963
Greg Clayton95d87902011-11-11 03:16:25 +00002964 if (die)
2965 {
Greg Clayton437a1352012-04-09 22:43:43 +00002966 switch (die->Tag())
2967 {
2968 default:
2969 case DW_TAG_subprogram:
2970 case DW_TAG_inlined_subroutine:
2971 case DW_TAG_try_block:
2972 case DW_TAG_catch_block:
2973 break;
2974
2975 case DW_TAG_variable:
2976 {
2977 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Greg Clayton437a1352012-04-09 22:43:43 +00002978
2979 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2980 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002981
Greg Clayton437a1352012-04-09 22:43:43 +00002982 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002983
Greg Clayton437a1352012-04-09 22:43:43 +00002984 if (variables.GetSize() - original_size >= max_matches)
2985 done = true;
2986 }
2987 break;
2988 }
Greg Clayton95d87902011-11-11 03:16:25 +00002989 }
2990 else
2991 {
2992 if (m_using_apple_tables)
2993 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002994 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
2995 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00002996 }
2997 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002998 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002999 }
3000
3001 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003002 const uint32_t num_matches = variables.GetSize() - original_size;
3003 if (log && num_matches > 0)
3004 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003005 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003006 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u",
3007 name.GetCString(),
3008 namespace_decl,
3009 append,
3010 max_matches,
3011 num_matches);
3012 }
3013 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003014}
3015
3016uint32_t
3017SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
3018{
Greg Clayton5160ce52013-03-27 23:08:40 +00003019 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003020
3021 if (log)
3022 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003023 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003024 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
3025 regex.GetText(),
3026 append,
3027 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003028 }
3029
Greg Claytonc685f8e2010-09-15 04:15:46 +00003030 DWARFDebugInfo* info = DebugInfo();
3031 if (info == NULL)
3032 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003033
3034 // If we aren't appending the results to this list, then clear the list
3035 if (!append)
3036 variables.Clear();
3037
3038 // Remember how many variables are in the list before we search in case
3039 // we are appending the results to a variable list.
3040 const uint32_t original_size = variables.GetSize();
3041
Greg Clayton7f995132011-10-04 22:41:51 +00003042 DIEArray die_offsets;
3043
Greg Clayton97fbc342011-10-20 22:30:33 +00003044 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003045 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003046 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00003047 {
3048 DWARFMappedHash::DIEInfoArray hash_data_array;
3049 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
3050 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
3051 }
Greg Clayton7f995132011-10-04 22:41:51 +00003052 }
3053 else
3054 {
3055 // Index the DWARF if we haven't already
3056 if (!m_indexed)
3057 Index ();
3058
3059 m_global_index.Find (regex, die_offsets);
3060 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003061
Greg Claytonc685f8e2010-09-15 04:15:46 +00003062 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003063 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003064 assert (sc.module_sp);
3065
Greg Claytond4a2b372011-09-12 23:21:58 +00003066 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00003067 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003068 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003069 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003070 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003071 DWARFDebugInfo* debug_info = DebugInfo();
3072 for (size_t i=0; i<num_matches; ++i)
3073 {
3074 const dw_offset_t die_offset = die_offsets[i];
3075 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00003076
3077 if (die)
3078 {
3079 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003080
Greg Clayton95d87902011-11-11 03:16:25 +00003081 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003082
Greg Clayton95d87902011-11-11 03:16:25 +00003083 if (variables.GetSize() - original_size >= max_matches)
3084 break;
3085 }
3086 else
3087 {
3088 if (m_using_apple_tables)
3089 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003090 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
3091 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00003092 }
3093 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003094 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003095 }
3096
3097 // Return the number of variable that were appended to the list
3098 return variables.GetSize() - original_size;
3099}
3100
Greg Claytonaa044962011-10-13 00:59:38 +00003101
Jim Ingham4cda6e02011-10-07 22:23:45 +00003102bool
3103SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
3104 DWARFCompileUnit *&dwarf_cu,
3105 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00003106{
Greg Claytonaa044962011-10-13 00:59:38 +00003107 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3108 return ResolveFunction (dwarf_cu, die, sc_list);
3109}
3110
3111
3112bool
3113SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
3114 const DWARFDebugInfoEntry *die,
3115 SymbolContextList& sc_list)
3116{
Greg Clayton9e315582011-09-02 04:03:59 +00003117 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00003118
3119 if (die == NULL)
3120 return false;
3121
Jim Ingham4cda6e02011-10-07 22:23:45 +00003122 // If we were passed a die that is not a function, just return false...
3123 if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine)
3124 return false;
3125
3126 const DWARFDebugInfoEntry* inlined_die = NULL;
3127 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00003128 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003129 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00003130
Jim Ingham4cda6e02011-10-07 22:23:45 +00003131 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003132 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003133 if (die->Tag() == DW_TAG_subprogram)
3134 break;
Greg Clayton9e315582011-09-02 04:03:59 +00003135 }
3136 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003137 assert (die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00003138 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003139 {
3140 Address addr;
3141 // Parse all blocks if needed
3142 if (inlined_die)
3143 {
Greg Clayton81c22f62011-10-19 18:09:39 +00003144 sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset()));
Jim Ingham4cda6e02011-10-07 22:23:45 +00003145 assert (sc.block != NULL);
3146 if (sc.block->GetStartAddress (addr) == false)
3147 addr.Clear();
3148 }
3149 else
3150 {
3151 sc.block = NULL;
3152 addr = sc.function->GetAddressRange().GetBaseAddress();
3153 }
3154
3155 if (addr.IsValid())
3156 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003157 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00003158 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003159 }
3160 }
3161
Greg Claytonaa044962011-10-13 00:59:38 +00003162 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00003163}
3164
Greg Clayton7f995132011-10-04 22:41:51 +00003165void
3166SymbolFileDWARF::FindFunctions (const ConstString &name,
3167 const NameToDIE &name_to_die,
3168 SymbolContextList& sc_list)
3169{
Greg Claytond4a2b372011-09-12 23:21:58 +00003170 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003171 if (name_to_die.Find (name, die_offsets))
3172 {
3173 ParseFunctions (die_offsets, sc_list);
3174 }
3175}
3176
3177
3178void
3179SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3180 const NameToDIE &name_to_die,
3181 SymbolContextList& sc_list)
3182{
3183 DIEArray die_offsets;
3184 if (name_to_die.Find (regex, die_offsets))
3185 {
3186 ParseFunctions (die_offsets, sc_list);
3187 }
3188}
3189
3190
3191void
3192SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3193 const DWARFMappedHash::MemoryTable &memory_table,
3194 SymbolContextList& sc_list)
3195{
3196 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00003197 DWARFMappedHash::DIEInfoArray hash_data_array;
3198 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00003199 {
Greg Claytond1767f02011-12-08 02:13:16 +00003200 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Greg Clayton7f995132011-10-04 22:41:51 +00003201 ParseFunctions (die_offsets, sc_list);
3202 }
3203}
3204
3205void
3206SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
3207 SymbolContextList& sc_list)
3208{
3209 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003210 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00003211 {
Greg Clayton7f995132011-10-04 22:41:51 +00003212 SymbolContext sc;
Greg Clayton7f995132011-10-04 22:41:51 +00003213
3214 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003215 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00003216 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003217 const dw_offset_t die_offset = die_offsets[i];
Jim Ingham4cda6e02011-10-07 22:23:45 +00003218 ResolveFunction (die_offset, dwarf_cu, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003219 }
3220 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00003221}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003222
Jim Ingham4cda6e02011-10-07 22:23:45 +00003223bool
3224SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
3225 const DWARFCompileUnit *dwarf_cu,
3226 uint32_t name_type_mask,
3227 const char *partial_name,
3228 const char *base_name_start,
3229 const char *base_name_end)
3230{
Greg Claytonfbea0f62012-11-15 18:05:43 +00003231 // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes:
3232 if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003233 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003234 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
3235 if (!containing_decl_ctx)
3236 return false;
3237
3238 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
3239
Greg Claytonfbea0f62012-11-15 18:05:43 +00003240 if (name_type_mask == eFunctionNameTypeMethod)
3241 {
3242 if (is_cxx_method == false)
3243 return false;
3244 }
3245
3246 if (name_type_mask == eFunctionNameTypeBase)
3247 {
3248 if (is_cxx_method == true)
3249 return false;
3250 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003251 }
3252
3253 // Now we need to check whether the name we got back for this type matches the extra specifications
3254 // that were in the name we're looking up:
3255 if (base_name_start != partial_name || *base_name_end != '\0')
3256 {
3257 // First see if the stuff to the left matches the full name. To do that let's see if
3258 // we can pull out the mips linkage name attribute:
3259
3260 Mangled best_name;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003261 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonfbea0f62012-11-15 18:05:43 +00003262 DWARFFormValue form_value;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003263 die->GetAttributes(this, dwarf_cu, NULL, attributes);
3264 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
Greg Clayton71415542012-12-08 00:24:40 +00003265 if (idx == UINT32_MAX)
3266 idx = attributes.FindAttributeIndex(DW_AT_linkage_name);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003267 if (idx != UINT32_MAX)
3268 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003269 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
3270 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003271 const char *mangled_name = form_value.AsCString(&get_debug_str_data());
3272 if (mangled_name)
3273 best_name.SetValue (ConstString(mangled_name), true);
3274 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003275 }
Greg Claytonfbea0f62012-11-15 18:05:43 +00003276
3277 if (!best_name)
3278 {
3279 idx = attributes.FindAttributeIndex(DW_AT_name);
3280 if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value))
3281 {
3282 const char *name = form_value.AsCString(&get_debug_str_data());
3283 best_name.SetValue (ConstString(name), false);
3284 }
3285 }
3286
3287 if (best_name.GetDemangledName())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003288 {
3289 const char *demangled = best_name.GetDemangledName().GetCString();
3290 if (demangled)
3291 {
3292 std::string name_no_parens(partial_name, base_name_end - partial_name);
Jim Ingham85c13d72012-03-02 02:24:42 +00003293 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str());
3294 if (partial_in_demangled == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003295 return false;
Jim Ingham85c13d72012-03-02 02:24:42 +00003296 else
3297 {
3298 // Sort out the case where our name is something like "Process::Destroy" and the match is
3299 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on
3300 // namespace boundaries...
3301
3302 if (partial_name[0] == ':' && partial_name[1] == ':')
3303 {
3304 // The partial name was already on a namespace boundary so all matches are good.
3305 return true;
3306 }
3307 else if (partial_in_demangled == demangled)
3308 {
3309 // They both start the same, so this is an good match.
3310 return true;
3311 }
3312 else
3313 {
3314 if (partial_in_demangled - demangled == 1)
3315 {
3316 // Only one character difference, can't be a namespace boundary...
3317 return false;
3318 }
3319 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':')
3320 {
3321 // We are on a namespace boundary, so this is also good.
3322 return true;
3323 }
3324 else
3325 return false;
3326 }
3327 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003328 }
3329 }
3330 }
3331
3332 return true;
3333}
Greg Claytonc685f8e2010-09-15 04:15:46 +00003334
Greg Clayton0c5cd902010-06-28 21:30:43 +00003335uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00003336SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00003337 const lldb_private::ClangNamespaceDecl *namespace_decl,
Sean Callanan9df05fb2012-02-10 22:52:19 +00003338 uint32_t name_type_mask,
3339 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00003340 bool append,
3341 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00003342{
3343 Timer scoped_timer (__PRETTY_FUNCTION__,
3344 "SymbolFileDWARF::FindFunctions (name = '%s')",
3345 name.AsCString());
3346
Greg Clayton43fe2172013-04-03 02:00:15 +00003347 // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup()
3348 assert ((name_type_mask & eFunctionNameTypeAuto) == 0);
3349
Greg Clayton5160ce52013-03-27 23:08:40 +00003350 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003351
3352 if (log)
3353 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003354 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003355 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
3356 name.GetCString(),
3357 name_type_mask,
3358 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003359 }
3360
Greg Clayton0c5cd902010-06-28 21:30:43 +00003361 // If we aren't appending the results to this list, then clear the list
3362 if (!append)
3363 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003364
3365 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3366 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003367
3368 // If name is empty then we won't find anything.
3369 if (name.IsEmpty())
3370 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00003371
3372 // Remember how many sc_list are in the list before we search in case
3373 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00003374
Jim Ingham4cda6e02011-10-07 22:23:45 +00003375 const char *name_cstr = name.GetCString();
Greg Clayton43fe2172013-04-03 02:00:15 +00003376
3377 const uint32_t original_size = sc_list.GetSize();
3378
Jim Ingham4cda6e02011-10-07 22:23:45 +00003379 DWARFDebugInfo* info = DebugInfo();
3380 if (info == NULL)
3381 return 0;
3382
Greg Claytonaa044962011-10-13 00:59:38 +00003383 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton43fe2172013-04-03 02:00:15 +00003384 std::set<const DWARFDebugInfoEntry *> resolved_dies;
Greg Clayton97fbc342011-10-20 22:30:33 +00003385 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00003386 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003387 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003388 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003389
3390 DIEArray die_offsets;
3391
3392 uint32_t num_matches = 0;
3393
Greg Clayton43fe2172013-04-03 02:00:15 +00003394 if (name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00003395 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003396 // If they asked for the full name, match what they typed. At some point we may
3397 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
3398 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00003399 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003400 for (uint32_t i = 0; i < num_matches; i++)
3401 {
Greg Clayton95d87902011-11-11 03:16:25 +00003402 const dw_offset_t die_offset = die_offsets[i];
3403 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00003404 if (die)
3405 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003406 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3407 continue;
3408
Sean Callanan9df05fb2012-02-10 22:52:19 +00003409 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3410 continue;
3411
Greg Clayton43fe2172013-04-03 02:00:15 +00003412 if (resolved_dies.find(die) == resolved_dies.end())
3413 {
3414 if (ResolveFunction (dwarf_cu, die, sc_list))
3415 resolved_dies.insert(die);
3416 }
Greg Claytonaa044962011-10-13 00:59:38 +00003417 }
Greg Clayton95d87902011-11-11 03:16:25 +00003418 else
3419 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003420 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3421 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003422 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003423 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003424 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003425
3426 if (name_type_mask & eFunctionNameTypeSelector)
3427 {
3428 if (namespace_decl && *namespace_decl)
3429 return 0; // no selectors in namespaces
Greg Clayton97fbc342011-10-20 22:30:33 +00003430
Greg Clayton43fe2172013-04-03 02:00:15 +00003431 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3432 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
3433 // and if it is an ObjC method name, we're good.
Greg Clayton97fbc342011-10-20 22:30:33 +00003434
Greg Clayton43fe2172013-04-03 02:00:15 +00003435 for (uint32_t i = 0; i < num_matches; i++)
Greg Clayton97fbc342011-10-20 22:30:33 +00003436 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003437 const dw_offset_t die_offset = die_offsets[i];
3438 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3439 if (die)
Greg Clayton97fbc342011-10-20 22:30:33 +00003440 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003441 const char *die_name = die->GetName(this, dwarf_cu);
3442 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
Greg Clayton97fbc342011-10-20 22:30:33 +00003443 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003444 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3445 continue;
3446
Greg Clayton43fe2172013-04-03 02:00:15 +00003447 if (resolved_dies.find(die) == resolved_dies.end())
3448 {
3449 if (ResolveFunction (dwarf_cu, die, sc_list))
3450 resolved_dies.insert(die);
3451 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003452 }
3453 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003454 else
3455 {
3456 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3457 die_offset, name_cstr);
3458 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003459 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003460 die_offsets.clear();
3461 }
3462
3463 if (((name_type_mask & eFunctionNameTypeMethod) && !namespace_decl) || name_type_mask & eFunctionNameTypeBase)
3464 {
3465 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
3466 // extract the base name, look that up, and if there is any other information in the name we were
3467 // passed in we have to post-filter based on that.
3468
3469 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
3470 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3471
3472 for (uint32_t i = 0; i < num_matches; i++)
3473 {
3474 const dw_offset_t die_offset = die_offsets[i];
3475 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3476 if (die)
3477 {
3478 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3479 continue;
3480
3481 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3482 continue;
3483
3484 // If we get to here, the die is good, and we should add it:
3485 if (resolved_dies.find(die) == resolved_dies.end())
3486 if (ResolveFunction (dwarf_cu, die, sc_list))
3487 {
3488 bool keep_die = true;
3489 if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod))
3490 {
3491 // We are looking for either basenames or methods, so we need to
3492 // trim out the ones we won't want by looking at the type
3493 SymbolContext sc;
3494 if (sc_list.GetLastContext(sc))
3495 {
3496 if (sc.block)
3497 {
3498 // We have an inlined function
3499 }
3500 else if (sc.function)
3501 {
3502 Type *type = sc.function->GetType();
3503
3504 clang::DeclContext* decl_ctx = GetClangDeclContextContainingTypeUID (type->GetID());
3505 if (decl_ctx->isRecord())
3506 {
3507 if (name_type_mask & eFunctionNameTypeBase)
3508 {
3509 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3510 keep_die = false;
3511 }
3512 }
3513 else
3514 {
3515 if (name_type_mask & eFunctionNameTypeMethod)
3516 {
3517 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3518 keep_die = false;
3519 }
3520 }
3521 }
3522 }
3523 }
3524 if (keep_die)
3525 resolved_dies.insert(die);
3526 }
3527 }
3528 else
3529 {
3530 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3531 die_offset, name_cstr);
3532 }
3533 }
3534 die_offsets.clear();
Jim Ingham4cda6e02011-10-07 22:23:45 +00003535 }
3536 }
Greg Clayton7f995132011-10-04 22:41:51 +00003537 }
3538 else
3539 {
3540
3541 // Index the DWARF if we haven't already
3542 if (!m_indexed)
3543 Index ();
3544
Greg Clayton7f995132011-10-04 22:41:51 +00003545 if (name_type_mask & eFunctionNameTypeFull)
Matt Kopecd6089962013-05-10 17:53:48 +00003546 {
Greg Clayton7f995132011-10-04 22:41:51 +00003547 FindFunctions (name, m_function_fullname_index, sc_list);
3548
Matt Kopecd6089962013-05-10 17:53:48 +00003549 // Temporary workaround for global/anonymous namespace functions on linux
3550#if defined (__linux__)
3551 // If we didn't find any functions in the global namespace try
3552 // looking in the basename index but ignore any returned
3553 // functions that have a namespace (ie. mangled names starting with
3554 // '_ZN') but keep functions which have an anonymous namespace
3555 if (sc_list.GetSize() == 0)
3556 {
3557 SymbolContextList temp_sc_list;
3558 FindFunctions (name, m_function_basename_index, temp_sc_list);
3559 if (!namespace_decl)
3560 {
3561 SymbolContext sc;
3562 for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++)
3563 {
3564 if (temp_sc_list.GetContextAtIndex(i, sc))
3565 {
3566 ConstString func_name = sc.GetFunctionName(Mangled::ePreferDemangled);
3567 if (!strncmp(name.GetCString(), "_ZN", 3) ||
3568 strncmp(name.GetCString(), "(anonymous namespace)", 21))
3569 {
3570 sc_list.Append(sc);
3571 }
3572 }
3573 }
3574 }
3575 }
3576#endif
3577 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003578 DIEArray die_offsets;
3579 DWARFCompileUnit *dwarf_cu = NULL;
3580
Greg Clayton43fe2172013-04-03 02:00:15 +00003581 if (name_type_mask & eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003582 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003583 uint32_t num_base = m_function_basename_index.Find(name, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00003584 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003585 {
Greg Claytonaa044962011-10-13 00:59:38 +00003586 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3587 if (die)
3588 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003589 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3590 continue;
3591
Sean Callanan213fdb82011-10-13 01:49:10 +00003592 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3593 continue;
3594
Greg Claytonaa044962011-10-13 00:59:38 +00003595 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00003596 if (resolved_dies.find(die) == resolved_dies.end())
3597 {
3598 if (ResolveFunction (dwarf_cu, die, sc_list))
3599 resolved_dies.insert(die);
3600 }
Greg Claytonaa044962011-10-13 00:59:38 +00003601 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003602 }
3603 die_offsets.clear();
3604 }
3605
Greg Clayton43fe2172013-04-03 02:00:15 +00003606 if (name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003607 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003608 if (namespace_decl && *namespace_decl)
3609 return 0; // no methods in namespaces
3610
Greg Clayton43fe2172013-04-03 02:00:15 +00003611 uint32_t num_base = m_function_method_index.Find(name, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003612 {
Greg Claytonaa044962011-10-13 00:59:38 +00003613 for (uint32_t i = 0; i < num_base; i++)
3614 {
3615 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3616 if (die)
3617 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003618 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3619 continue;
3620
Greg Claytonaa044962011-10-13 00:59:38 +00003621 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00003622 if (resolved_dies.find(die) == resolved_dies.end())
3623 {
3624 if (ResolveFunction (dwarf_cu, die, sc_list))
3625 resolved_dies.insert(die);
3626 }
Greg Claytonaa044962011-10-13 00:59:38 +00003627 }
3628 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003629 }
3630 die_offsets.clear();
3631 }
Greg Clayton7f995132011-10-04 22:41:51 +00003632
Greg Clayton43fe2172013-04-03 02:00:15 +00003633 if ((name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003634 {
Greg Clayton7f995132011-10-04 22:41:51 +00003635 FindFunctions (name, m_function_selector_index, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003636 }
3637
Greg Clayton4d01ace2011-09-29 16:58:15 +00003638 }
3639
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003640 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003641 const uint32_t num_matches = sc_list.GetSize() - original_size;
3642
3643 if (log && num_matches > 0)
3644 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003645 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003646 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list) => %u",
3647 name.GetCString(),
3648 name_type_mask,
3649 append,
3650 num_matches);
3651 }
3652 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003653}
3654
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003655uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00003656SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003657{
3658 Timer scoped_timer (__PRETTY_FUNCTION__,
3659 "SymbolFileDWARF::FindFunctions (regex = '%s')",
3660 regex.GetText());
3661
Greg Clayton5160ce52013-03-27 23:08:40 +00003662 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003663
3664 if (log)
3665 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003666 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003667 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
3668 regex.GetText(),
3669 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003670 }
3671
3672
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003673 // If we aren't appending the results to this list, then clear the list
3674 if (!append)
3675 sc_list.Clear();
3676
3677 // Remember how many sc_list are in the list before we search in case
3678 // we are appending the results to a variable list.
3679 uint32_t original_size = sc_list.GetSize();
3680
Greg Clayton97fbc342011-10-20 22:30:33 +00003681 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003682 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003683 if (m_apple_names_ap.get())
3684 FindFunctions (regex, *m_apple_names_ap, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003685 }
3686 else
3687 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003688 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00003689 if (!m_indexed)
3690 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003691
Greg Clayton7f995132011-10-04 22:41:51 +00003692 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003693
Greg Clayton7f995132011-10-04 22:41:51 +00003694 FindFunctions (regex, m_function_fullname_index, sc_list);
3695 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003696
3697 // Return the number of variable that were appended to the list
3698 return sc_list.GetSize() - original_size;
3699}
Jim Ingham318c9f22011-08-26 19:44:13 +00003700
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003701uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00003702SymbolFileDWARF::FindTypes (const SymbolContext& sc,
3703 const ConstString &name,
3704 const lldb_private::ClangNamespaceDecl *namespace_decl,
3705 bool append,
3706 uint32_t max_matches,
3707 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003708{
Greg Claytonc685f8e2010-09-15 04:15:46 +00003709 DWARFDebugInfo* info = DebugInfo();
3710 if (info == NULL)
3711 return 0;
3712
Greg Clayton5160ce52013-03-27 23:08:40 +00003713 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003714
3715 if (log)
3716 {
Greg Clayton437a1352012-04-09 22:43:43 +00003717 if (namespace_decl)
3718 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003719 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003720 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)",
3721 name.GetCString(),
3722 namespace_decl->GetNamespaceDecl(),
3723 namespace_decl->GetQualifiedName().c_str(),
3724 append,
3725 max_matches);
3726 }
3727 else
3728 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003729 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003730 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)",
3731 name.GetCString(),
3732 append,
3733 max_matches);
3734 }
Greg Clayton21f2a492011-10-06 00:09:08 +00003735 }
3736
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003737 // If we aren't appending the results to this list, then clear the list
3738 if (!append)
3739 types.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003740
3741 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3742 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003743
Greg Claytond4a2b372011-09-12 23:21:58 +00003744 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003745
Greg Clayton97fbc342011-10-20 22:30:33 +00003746 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003747 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003748 if (m_apple_types_ap.get())
3749 {
3750 const char *name_cstr = name.GetCString();
3751 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3752 }
Greg Clayton7f995132011-10-04 22:41:51 +00003753 }
3754 else
3755 {
3756 if (!m_indexed)
3757 Index ();
3758
3759 m_type_index.Find (name, die_offsets);
3760 }
3761
Greg Clayton437a1352012-04-09 22:43:43 +00003762 const size_t num_die_matches = die_offsets.size();
Greg Clayton7f995132011-10-04 22:41:51 +00003763
Greg Clayton437a1352012-04-09 22:43:43 +00003764 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003765 {
Greg Clayton7f995132011-10-04 22:41:51 +00003766 const uint32_t initial_types_size = types.GetSize();
3767 DWARFCompileUnit* dwarf_cu = NULL;
3768 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003769 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00003770 for (size_t i=0; i<num_die_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003771 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003772 const dw_offset_t die_offset = die_offsets[i];
3773 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3774
Greg Clayton95d87902011-11-11 03:16:25 +00003775 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00003776 {
Greg Clayton95d87902011-11-11 03:16:25 +00003777 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3778 continue;
3779
3780 Type *matching_type = ResolveType (dwarf_cu, die);
3781 if (matching_type)
3782 {
3783 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003784 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00003785 if (types.GetSize() >= max_matches)
3786 break;
3787 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00003788 }
Greg Clayton95d87902011-11-11 03:16:25 +00003789 else
3790 {
3791 if (m_using_apple_tables)
3792 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003793 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
3794 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003795 }
3796 }
3797
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003798 }
Greg Clayton437a1352012-04-09 22:43:43 +00003799 const uint32_t num_matches = types.GetSize() - initial_types_size;
3800 if (log && num_matches)
3801 {
3802 if (namespace_decl)
3803 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003804 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003805 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u",
3806 name.GetCString(),
3807 namespace_decl->GetNamespaceDecl(),
3808 namespace_decl->GetQualifiedName().c_str(),
3809 append,
3810 max_matches,
3811 num_matches);
3812 }
3813 else
3814 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003815 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003816 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u",
3817 name.GetCString(),
3818 append,
3819 max_matches,
3820 num_matches);
3821 }
3822 }
3823 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003824 }
Greg Clayton7f995132011-10-04 22:41:51 +00003825 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003826}
3827
3828
Greg Clayton526e5af2010-11-13 03:52:47 +00003829ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00003830SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00003831 const ConstString &name,
3832 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00003833{
Greg Clayton5160ce52013-03-27 23:08:40 +00003834 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003835
3836 if (log)
3837 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003838 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003839 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
3840 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00003841 }
Sean Callanan213fdb82011-10-13 01:49:10 +00003842
3843 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
3844 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00003845
Greg Clayton526e5af2010-11-13 03:52:47 +00003846 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003847 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00003848 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00003849 {
Greg Clayton7f995132011-10-04 22:41:51 +00003850 DIEArray die_offsets;
3851
Greg Clayton526e5af2010-11-13 03:52:47 +00003852 // Index if we already haven't to make sure the compile units
3853 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00003854 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003855 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003856 if (m_apple_namespaces_ap.get())
3857 {
3858 const char *name_cstr = name.GetCString();
3859 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
3860 }
Greg Clayton7f995132011-10-04 22:41:51 +00003861 }
3862 else
3863 {
3864 if (!m_indexed)
3865 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00003866
Greg Clayton7f995132011-10-04 22:41:51 +00003867 m_namespace_index.Find (name, die_offsets);
3868 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003869
3870 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00003871 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003872 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003873 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00003874 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003875 DWARFDebugInfo* debug_info = DebugInfo();
3876 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00003877 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003878 const dw_offset_t die_offset = die_offsets[i];
3879 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00003880
Greg Clayton95d87902011-11-11 03:16:25 +00003881 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00003882 {
Greg Clayton95d87902011-11-11 03:16:25 +00003883 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
3884 continue;
3885
3886 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
3887 if (clang_namespace_decl)
3888 {
3889 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
3890 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
Greg Claytond1767f02011-12-08 02:13:16 +00003891 break;
Greg Clayton95d87902011-11-11 03:16:25 +00003892 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003893 }
Greg Clayton95d87902011-11-11 03:16:25 +00003894 else
3895 {
3896 if (m_using_apple_tables)
3897 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003898 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
3899 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003900 }
3901 }
3902
Greg Clayton526e5af2010-11-13 03:52:47 +00003903 }
3904 }
Greg Clayton96d7d742010-11-10 23:42:09 +00003905 }
Greg Clayton437a1352012-04-09 22:43:43 +00003906 if (log && namespace_decl.GetNamespaceDecl())
3907 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003908 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003909 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"",
3910 name.GetCString(),
3911 namespace_decl.GetNamespaceDecl(),
3912 namespace_decl.GetQualifiedName().c_str());
3913 }
3914
Greg Clayton526e5af2010-11-13 03:52:47 +00003915 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003916}
3917
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003918uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003919SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003920{
3921 // Remember how many sc_list are in the list before we search in case
3922 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003923 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003924
3925 const uint32_t num_die_offsets = die_offsets.size();
3926 // Parse all of the types we found from the pubtypes matches
3927 uint32_t i;
3928 uint32_t num_matches = 0;
3929 for (i = 0; i < num_die_offsets; ++i)
3930 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003931 Type *matching_type = ResolveTypeUID (die_offsets[i]);
3932 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003933 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003934 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003935 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003936 ++num_matches;
3937 if (num_matches >= max_matches)
3938 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003939 }
3940 }
3941
3942 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003943 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003944}
3945
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003946
3947size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00003948SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
3949 clang::DeclContext *containing_decl_ctx,
Greg Clayton5113dc82011-08-12 06:47:54 +00003950 DWARFCompileUnit* dwarf_cu,
3951 const DWARFDebugInfoEntry *parent_die,
3952 bool skip_artificial,
3953 bool &is_static,
3954 TypeList* type_list,
3955 std::vector<clang_type_t>& function_param_types,
3956 std::vector<clang::ParmVarDecl*>& function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00003957 unsigned &type_quals,
3958 ClangASTContext::TemplateParameterInfos &template_param_infos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003959{
3960 if (parent_die == NULL)
3961 return 0;
3962
Greg Claytond88d7592010-09-15 08:33:30 +00003963 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3964
Greg Clayton7fedea22010-11-16 02:10:54 +00003965 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003966 const DWARFDebugInfoEntry *die;
3967 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3968 {
3969 dw_tag_t tag = die->Tag();
3970 switch (tag)
3971 {
3972 case DW_TAG_formal_parameter:
3973 {
3974 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003975 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003976 if (num_attributes > 0)
3977 {
3978 const char *name = NULL;
3979 Declaration decl;
3980 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003981 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003982 // one of None, Auto, Register, Extern, Static, PrivateExtern
3983
Sean Callanane2ef6e32010-09-23 03:01:22 +00003984 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003985 uint32_t i;
3986 for (i=0; i<num_attributes; ++i)
3987 {
3988 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3989 DWARFFormValue form_value;
3990 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3991 {
3992 switch (attr)
3993 {
3994 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3995 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3996 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3997 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
3998 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00003999 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004000 case DW_AT_location:
4001 // if (form_value.BlockData())
4002 // {
4003 // const DataExtractor& debug_info_data = debug_info();
4004 // uint32_t block_length = form_value.Unsigned();
4005 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
4006 // }
4007 // else
4008 // {
4009 // }
4010 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004011 case DW_AT_const_value:
4012 case DW_AT_default_value:
4013 case DW_AT_description:
4014 case DW_AT_endianity:
4015 case DW_AT_is_optional:
4016 case DW_AT_segment:
4017 case DW_AT_variable_parameter:
4018 default:
4019 case DW_AT_abstract_origin:
4020 case DW_AT_sibling:
4021 break;
4022 }
4023 }
4024 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00004025
Greg Clayton0fffff52010-09-24 05:15:53 +00004026 bool skip = false;
4027 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004028 {
Greg Clayton0fffff52010-09-24 05:15:53 +00004029 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00004030 {
4031 // In order to determine if a C++ member function is
4032 // "const" we have to look at the const-ness of "this"...
4033 // Ugly, but that
4034 if (arg_idx == 0)
4035 {
Greg Claytonf0705c82011-10-22 03:33:13 +00004036 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00004037 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004038 // Often times compilers omit the "this" name for the
4039 // specification DIEs, so we can't rely upon the name
4040 // being in the formal parameter DIE...
4041 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00004042 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004043 Type *this_type = ResolveTypeUID (param_type_die_offset);
4044 if (this_type)
4045 {
4046 uint32_t encoding_mask = this_type->GetEncodingMask();
4047 if (encoding_mask & Type::eEncodingIsPointerUID)
4048 {
4049 is_static = false;
4050
4051 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
4052 type_quals |= clang::Qualifiers::Const;
4053 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
4054 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00004055 }
4056 }
4057 }
4058 }
4059 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004060 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00004061 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004062 else
4063 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004064
Greg Clayton0fffff52010-09-24 05:15:53 +00004065 // HACK: Objective C formal parameters "self" and "_cmd"
4066 // are not marked as artificial in the DWARF...
Greg Clayton53eb1c22012-04-02 22:59:12 +00004067 CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
4068 if (comp_unit)
Greg Clayton0fffff52010-09-24 05:15:53 +00004069 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004070 switch (comp_unit->GetLanguage())
4071 {
4072 case eLanguageTypeObjC:
4073 case eLanguageTypeObjC_plus_plus:
4074 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
4075 skip = true;
4076 break;
4077 default:
4078 break;
4079 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004080 }
4081 }
4082 }
4083
4084 if (!skip)
4085 {
4086 Type *type = ResolveTypeUID(param_type_die_offset);
4087 if (type)
4088 {
Greg Claytonc93237c2010-10-01 20:48:32 +00004089 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00004090
Greg Clayton42ce2f32011-12-12 21:50:19 +00004091 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
4092 type->GetClangForwardType(),
4093 storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00004094 assert(param_var_decl);
4095 function_param_decls.push_back(param_var_decl);
Sean Callanan60217122012-04-13 00:10:03 +00004096
Greg Claytond0029442013-03-27 01:48:02 +00004097 GetClangASTContext().SetMetadataAsUserID (param_var_decl, MakeUserID(die->GetOffset()));
Greg Clayton0fffff52010-09-24 05:15:53 +00004098 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004099 }
4100 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004101 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004102 }
4103 break;
4104
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004105 case DW_TAG_template_type_parameter:
4106 case DW_TAG_template_value_parameter:
4107 ParseTemplateDIE (dwarf_cu, die,template_param_infos);
4108 break;
4109
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004110 default:
4111 break;
4112 }
4113 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004114 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004115}
4116
4117size_t
4118SymbolFileDWARF::ParseChildEnumerators
4119(
4120 const SymbolContext& sc,
Greg Clayton3e067532013-03-05 23:54:39 +00004121 clang_type_t enumerator_clang_type,
4122 bool is_signed,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004123 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00004124 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004125 const DWARFDebugInfoEntry *parent_die
4126)
4127{
4128 if (parent_die == NULL)
4129 return 0;
4130
4131 size_t enumerators_added = 0;
4132 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00004133 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
4134
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004135 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4136 {
4137 const dw_tag_t tag = die->Tag();
4138 if (tag == DW_TAG_enumerator)
4139 {
4140 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004141 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004142 if (num_child_attributes > 0)
4143 {
4144 const char *name = NULL;
4145 bool got_value = false;
4146 int64_t enum_value = 0;
4147 Declaration decl;
4148
4149 uint32_t i;
4150 for (i=0; i<num_child_attributes; ++i)
4151 {
4152 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4153 DWARFFormValue form_value;
4154 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4155 {
4156 switch (attr)
4157 {
4158 case DW_AT_const_value:
4159 got_value = true;
Greg Clayton3e067532013-03-05 23:54:39 +00004160 if (is_signed)
4161 enum_value = form_value.Signed();
4162 else
4163 enum_value = form_value.Unsigned();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004164 break;
4165
4166 case DW_AT_name:
4167 name = form_value.AsCString(&get_debug_str_data());
4168 break;
4169
4170 case DW_AT_description:
4171 default:
4172 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4173 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4174 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4175 case DW_AT_sibling:
4176 break;
4177 }
4178 }
4179 }
4180
4181 if (name && name[0] && got_value)
4182 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004183 GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
4184 enumerator_clang_type,
4185 decl,
4186 name,
4187 enum_value,
4188 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004189 ++enumerators_added;
4190 }
4191 }
4192 }
4193 }
4194 return enumerators_added;
4195}
4196
4197void
4198SymbolFileDWARF::ParseChildArrayInfo
4199(
4200 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004201 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004202 const DWARFDebugInfoEntry *parent_die,
4203 int64_t& first_index,
4204 std::vector<uint64_t>& element_orders,
4205 uint32_t& byte_stride,
4206 uint32_t& bit_stride
4207)
4208{
4209 if (parent_die == NULL)
4210 return;
4211
4212 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00004213 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004214 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4215 {
4216 const dw_tag_t tag = die->Tag();
4217 switch (tag)
4218 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004219 case DW_TAG_subrange_type:
4220 {
4221 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004222 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004223 if (num_child_attributes > 0)
4224 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004225 uint64_t num_elements = 0;
4226 uint64_t lower_bound = 0;
4227 uint64_t upper_bound = 0;
Greg Clayton4ef877f2012-12-06 02:33:54 +00004228 bool upper_bound_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004229 uint32_t i;
4230 for (i=0; i<num_child_attributes; ++i)
4231 {
4232 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4233 DWARFFormValue form_value;
4234 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4235 {
4236 switch (attr)
4237 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004238 case DW_AT_name:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004239 break;
4240
4241 case DW_AT_count:
4242 num_elements = form_value.Unsigned();
4243 break;
4244
4245 case DW_AT_bit_stride:
4246 bit_stride = form_value.Unsigned();
4247 break;
4248
4249 case DW_AT_byte_stride:
4250 byte_stride = form_value.Unsigned();
4251 break;
4252
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004253 case DW_AT_lower_bound:
4254 lower_bound = form_value.Unsigned();
4255 break;
4256
4257 case DW_AT_upper_bound:
Greg Clayton4ef877f2012-12-06 02:33:54 +00004258 upper_bound_valid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004259 upper_bound = form_value.Unsigned();
4260 break;
4261
4262 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004263 case DW_AT_abstract_origin:
4264 case DW_AT_accessibility:
4265 case DW_AT_allocated:
4266 case DW_AT_associated:
4267 case DW_AT_data_location:
4268 case DW_AT_declaration:
4269 case DW_AT_description:
4270 case DW_AT_sibling:
4271 case DW_AT_threads_scaled:
4272 case DW_AT_type:
4273 case DW_AT_visibility:
4274 break;
4275 }
4276 }
4277 }
4278
Greg Claytone6a07792012-12-05 21:59:39 +00004279 if (num_elements == 0)
4280 {
Greg Clayton4ef877f2012-12-06 02:33:54 +00004281 if (upper_bound_valid && upper_bound >= lower_bound)
Greg Claytone6a07792012-12-05 21:59:39 +00004282 num_elements = upper_bound - lower_bound + 1;
4283 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004284
Sean Callananec979ba2012-10-22 23:56:48 +00004285 element_orders.push_back (num_elements);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004286 }
4287 }
4288 break;
4289 }
4290 }
4291}
4292
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004293TypeSP
Greg Clayton53eb1c22012-04-02 22:59:12 +00004294SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004295{
4296 TypeSP type_sp;
4297 if (die != NULL)
4298 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004299 assert(dwarf_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00004300 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004301 if (type_ptr == NULL)
4302 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004303 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu);
Greg Claytonca512b32011-01-14 04:54:56 +00004304 assert (lldb_cu);
4305 SymbolContext sc(lldb_cu);
Greg Clayton53eb1c22012-04-02 22:59:12 +00004306 type_sp = ParseType(sc, dwarf_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004307 }
4308 else if (type_ptr != DIE_IS_BEING_PARSED)
4309 {
4310 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00004311 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004312 }
4313
4314 }
4315 return type_sp;
4316}
4317
4318clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00004319SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004320{
4321 if (die_offset != DW_INVALID_OFFSET)
4322 {
4323 DWARFCompileUnitSP cu_sp;
4324 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004325 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004326 }
4327 return NULL;
4328}
4329
Sean Callanan72e49402011-08-05 23:43:37 +00004330clang::DeclContext *
4331SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
4332{
4333 if (die_offset != DW_INVALID_OFFSET)
4334 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004335 DWARFDebugInfo* debug_info = DebugInfo();
4336 if (debug_info)
4337 {
4338 DWARFCompileUnitSP cu_sp;
4339 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
4340 if (die)
4341 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
4342 }
Sean Callanan72e49402011-08-05 23:43:37 +00004343 }
4344 return NULL;
4345}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004346
Greg Clayton96d7d742010-11-10 23:42:09 +00004347clang::NamespaceDecl *
Greg Clayton53eb1c22012-04-02 22:59:12 +00004348SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die)
Greg Clayton96d7d742010-11-10 23:42:09 +00004349{
Greg Clayton030a2042011-10-14 21:34:45 +00004350 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00004351 {
Greg Clayton030a2042011-10-14 21:34:45 +00004352 // See if we already parsed this namespace DIE and associated it with a
4353 // uniqued namespace declaration
4354 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
4355 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004356 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00004357 else
4358 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004359 const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL);
4360 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00004361 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
Greg Clayton5160ce52013-03-27 23:08:40 +00004362 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton9d3d6882011-10-31 23:51:19 +00004363 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00004364 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00004365 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00004366 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004367 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00004368 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)",
Greg Claytone38a5ed2012-01-05 03:57:59 +00004369 GetClangASTContext().getASTContext(),
4370 MakeUserID(die->GetOffset()),
4371 namespace_name,
4372 namespace_decl,
4373 namespace_decl->getOriginalNamespace());
Greg Clayton030a2042011-10-14 21:34:45 +00004374 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004375 else
4376 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004377 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00004378 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
Greg Claytone38a5ed2012-01-05 03:57:59 +00004379 GetClangASTContext().getASTContext(),
4380 MakeUserID(die->GetOffset()),
4381 namespace_decl,
4382 namespace_decl->getOriginalNamespace());
Greg Clayton9d3d6882011-10-31 23:51:19 +00004383 }
Greg Clayton030a2042011-10-14 21:34:45 +00004384 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004385
4386 if (namespace_decl)
4387 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
4388 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004389 }
4390 }
4391 return NULL;
4392}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004393
4394clang::DeclContext *
Greg Claytoncab36a32011-12-08 05:16:30 +00004395SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Sean Callanan72e49402011-08-05 23:43:37 +00004396{
Greg Clayton5cf58b92011-10-05 22:22:08 +00004397 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4398 if (clang_decl_ctx)
4399 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004400 // If this DIE has a specification, or an abstract origin, then trace to those.
4401
Greg Claytoncab36a32011-12-08 05:16:30 +00004402 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004403 if (die_offset != DW_INVALID_OFFSET)
4404 return GetClangDeclContextForDIEOffset (sc, die_offset);
4405
Greg Claytoncab36a32011-12-08 05:16:30 +00004406 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004407 if (die_offset != DW_INVALID_OFFSET)
4408 return GetClangDeclContextForDIEOffset (sc, die_offset);
4409
Greg Clayton5160ce52013-03-27 23:08:40 +00004410 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00004411 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004412 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 +00004413 // This is the DIE we want. Parse it, then query our map.
Greg Claytoncab36a32011-12-08 05:16:30 +00004414 bool assert_not_being_parsed = true;
4415 ResolveTypeUID (cu, die, assert_not_being_parsed);
4416
Greg Clayton5cf58b92011-10-05 22:22:08 +00004417 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4418
4419 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004420}
4421
4422clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00004423SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004424{
Greg Claytonca512b32011-01-14 04:54:56 +00004425 if (m_clang_tu_decl == NULL)
4426 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004427
Greg Clayton2bc22f82011-09-30 03:20:47 +00004428 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004429
4430 if (decl_ctx_die_copy)
4431 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00004432
4433 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004434 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00004435
Greg Clayton2bc22f82011-09-30 03:20:47 +00004436 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
4437 if (pos != m_die_to_decl_ctx.end())
4438 return pos->second;
4439
4440 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004441 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004442 case DW_TAG_compile_unit:
4443 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004444
Greg Clayton2bc22f82011-09-30 03:20:47 +00004445 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00004446 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00004447 break;
4448
4449 case DW_TAG_structure_type:
4450 case DW_TAG_union_type:
4451 case DW_TAG_class_type:
4452 {
4453 Type* type = ResolveType (cu, decl_ctx_die);
4454 if (type)
4455 {
4456 clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ());
4457 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00004458 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004459 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
4460 if (decl_ctx)
4461 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00004462 }
4463 }
Greg Claytonca512b32011-01-14 04:54:56 +00004464 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00004465 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004466
Greg Clayton2bc22f82011-09-30 03:20:47 +00004467 default:
4468 break;
Greg Claytonca512b32011-01-14 04:54:56 +00004469 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004470 }
Greg Clayton7a345282010-11-09 23:46:37 +00004471 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004472}
4473
Greg Clayton2bc22f82011-09-30 03:20:47 +00004474
4475const DWARFDebugInfoEntry *
4476SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4477{
4478 if (cu && die)
4479 {
4480 const DWARFDebugInfoEntry * const decl_die = die;
4481
4482 while (die != NULL)
4483 {
4484 // If this is the original DIE that we are searching for a declaration
4485 // for, then don't look in the cache as we don't want our own decl
4486 // context to be our decl context...
4487 if (decl_die != die)
4488 {
4489 switch (die->Tag())
4490 {
4491 case DW_TAG_compile_unit:
4492 case DW_TAG_namespace:
4493 case DW_TAG_structure_type:
4494 case DW_TAG_union_type:
4495 case DW_TAG_class_type:
4496 return die;
4497
4498 default:
4499 break;
4500 }
4501 }
4502
4503 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4504 if (die_offset != DW_INVALID_OFFSET)
4505 {
4506 DWARFCompileUnit *spec_cu = cu;
4507 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
4508 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
4509 if (spec_die_decl_ctx_die)
4510 return spec_die_decl_ctx_die;
4511 }
4512
4513 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
4514 if (die_offset != DW_INVALID_OFFSET)
4515 {
4516 DWARFCompileUnit *abs_cu = cu;
4517 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
4518 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
4519 if (abs_die_decl_ctx_die)
4520 return abs_die_decl_ctx_die;
4521 }
4522
4523 die = die->GetParent();
4524 }
4525 }
4526 return NULL;
4527}
4528
4529
Greg Clayton901c5ca2011-12-03 04:40:03 +00004530Symbol *
4531SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
4532{
4533 Symbol *objc_class_symbol = NULL;
4534 if (m_obj_file)
4535 {
4536 Symtab *symtab = m_obj_file->GetSymtab();
4537 if (symtab)
4538 {
4539 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
4540 eSymbolTypeObjCClass,
4541 Symtab::eDebugNo,
4542 Symtab::eVisibilityAny);
4543 }
4544 }
4545 return objc_class_symbol;
4546}
4547
Greg Claytonc7f03b62012-01-12 04:33:28 +00004548// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
4549// then we can end up looking through all class types for a complete type and never find
4550// the full definition. We need to know if this attribute is supported, so we determine
4551// this here and cache th result. We also need to worry about the debug map DWARF file
4552// if we are doing darwin DWARF in .o file debugging.
4553bool
4554SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
4555{
4556 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
4557 {
4558 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
4559 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
4560 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4561 else
4562 {
4563 DWARFDebugInfo* debug_info = DebugInfo();
4564 const uint32_t num_compile_units = GetNumCompileUnits();
4565 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
4566 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004567 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
4568 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004569 {
4570 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4571 break;
4572 }
4573 }
4574 }
Greg Clayton1f746072012-08-29 21:13:06 +00004575 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004576 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
4577 }
4578 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
4579}
Greg Clayton901c5ca2011-12-03 04:40:03 +00004580
4581// This function can be used when a DIE is found that is a forward declaration
4582// DIE and we want to try and find a type that has the complete definition.
4583TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00004584SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
4585 const ConstString &type_name,
4586 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00004587{
4588
4589 TypeSP type_sp;
4590
Greg Claytonc7f03b62012-01-12 04:33:28 +00004591 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00004592 return type_sp;
4593
4594 DIEArray die_offsets;
4595
4596 if (m_using_apple_tables)
4597 {
4598 if (m_apple_types_ap.get())
4599 {
4600 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00004601 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004602 }
4603 }
4604 else
4605 {
4606 if (!m_indexed)
4607 Index ();
4608
4609 m_type_index.Find (type_name, die_offsets);
4610 }
4611
Greg Clayton901c5ca2011-12-03 04:40:03 +00004612 const size_t num_matches = die_offsets.size();
4613
Greg Clayton901c5ca2011-12-03 04:40:03 +00004614 DWARFCompileUnit* type_cu = NULL;
4615 const DWARFDebugInfoEntry* type_die = NULL;
4616 if (num_matches)
4617 {
4618 DWARFDebugInfo* debug_info = DebugInfo();
4619 for (size_t i=0; i<num_matches; ++i)
4620 {
4621 const dw_offset_t die_offset = die_offsets[i];
4622 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4623
4624 if (type_die)
4625 {
4626 bool try_resolving_type = false;
4627
4628 // Don't try and resolve the DIE we are looking for with the DIE itself!
4629 if (type_die != die)
4630 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004631 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00004632 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004633 case DW_TAG_class_type:
4634 case DW_TAG_structure_type:
4635 try_resolving_type = true;
4636 break;
4637 default:
4638 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00004639 }
4640 }
4641
4642 if (try_resolving_type)
4643 {
Sean Callanana9bc0652012-01-19 02:17:40 +00004644 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004645 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004646
4647 if (try_resolving_type)
4648 {
4649 Type *resolved_type = ResolveType (type_cu, type_die, false);
4650 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4651 {
Daniel Malead01b2952012-11-29 21:49:15 +00004652 DEBUG_PRINTF ("resolved 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ") from %s to 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ")\n",
Greg Clayton901c5ca2011-12-03 04:40:03 +00004653 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00004654 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton901c5ca2011-12-03 04:40:03 +00004655 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4656 MakeUserID(type_die->GetOffset()),
4657 MakeUserID(type_cu->GetOffset()));
4658
Greg Claytonc7f03b62012-01-12 04:33:28 +00004659 if (die)
4660 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00004661 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00004662 break;
4663 }
4664 }
4665 }
4666 }
4667 else
4668 {
4669 if (m_using_apple_tables)
4670 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004671 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4672 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00004673 }
4674 }
4675
4676 }
4677 }
4678 return type_sp;
4679}
4680
Greg Claytona8022fa2012-04-24 21:22:41 +00004681
Greg Clayton80c26302012-02-05 06:12:47 +00004682//----------------------------------------------------------------------
4683// This function helps to ensure that the declaration contexts match for
4684// two different DIEs. Often times debug information will refer to a
4685// forward declaration of a type (the equivalent of "struct my_struct;".
4686// There will often be a declaration of that type elsewhere that has the
4687// full definition. When we go looking for the full type "my_struct", we
4688// will find one or more matches in the accelerator tables and we will
4689// then need to make sure the type was in the same declaration context
4690// as the original DIE. This function can efficiently compare two DIEs
4691// and will return true when the declaration context matches, and false
4692// when they don't.
4693//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00004694bool
4695SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
4696 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
4697{
Greg Claytona8022fa2012-04-24 21:22:41 +00004698 if (die1 == die2)
4699 return true;
4700
4701#if defined (LLDB_CONFIGURATION_DEBUG)
4702 // You can't and shouldn't call this function with a compile unit from
4703 // two different SymbolFileDWARF instances.
4704 assert (DebugInfo()->ContainsCompileUnit (cu1));
4705 assert (DebugInfo()->ContainsCompileUnit (cu2));
4706#endif
4707
Greg Clayton890ff562012-02-02 05:48:16 +00004708 DWARFDIECollection decl_ctx_1;
4709 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00004710 //The declaration DIE stack is a stack of the declaration context
4711 // DIEs all the way back to the compile unit. If a type "T" is
4712 // declared inside a class "B", and class "B" is declared inside
4713 // a class "A" and class "A" is in a namespace "lldb", and the
4714 // namespace is in a compile unit, there will be a stack of DIEs:
4715 //
4716 // [0] DW_TAG_class_type for "B"
4717 // [1] DW_TAG_class_type for "A"
4718 // [2] DW_TAG_namespace for "lldb"
4719 // [3] DW_TAG_compile_unit for the source file.
4720 //
4721 // We grab both contexts and make sure that everything matches
4722 // all the way back to the compiler unit.
4723
4724 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00004725 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004726 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00004727 // Make sure the context arrays have the same size, otherwise
4728 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00004729 const size_t count1 = decl_ctx_1.Size();
4730 const size_t count2 = decl_ctx_2.Size();
4731 if (count1 != count2)
4732 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00004733
4734 // Make sure the DW_TAG values match all the way back up the the
4735 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00004736 const DWARFDebugInfoEntry *decl_ctx_die1;
4737 const DWARFDebugInfoEntry *decl_ctx_die2;
4738 size_t i;
4739 for (i=0; i<count1; i++)
4740 {
4741 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4742 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4743 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
4744 return false;
4745 }
Greg Clayton890ff562012-02-02 05:48:16 +00004746#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00004747
4748 // Make sure the top item in the decl context die array is always
4749 // DW_TAG_compile_unit. If it isn't then something went wrong in
4750 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00004751 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00004752
Greg Clayton890ff562012-02-02 05:48:16 +00004753#endif
4754 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00004755 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00004756 for (i=0; i<count1 - 1; i++)
4757 {
4758 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4759 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4760 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004761 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00004762 // If the string was from a DW_FORM_strp, then the pointer will often
4763 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00004764 if (name1 == name2)
4765 continue;
4766
4767 // Name pointers are not equal, so only compare the strings
4768 // if both are not NULL.
4769 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00004770 {
Greg Clayton5569e642012-02-06 01:44:54 +00004771 // If the strings don't compare, we are done...
4772 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00004773 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00004774 }
4775 else
4776 {
4777 // One name was NULL while the other wasn't
4778 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00004779 }
4780 }
Greg Clayton80c26302012-02-05 06:12:47 +00004781 // We made it through all of the checks and the declaration contexts
4782 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00004783 return true;
4784}
Greg Clayton220a0072011-12-09 08:48:30 +00004785
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004786// This function can be used when a DIE is found that is a forward declaration
4787// DIE and we want to try and find a type that has the complete definition.
Greg Claytona8022fa2012-04-24 21:22:41 +00004788// "cu" and "die" must be from this SymbolFileDWARF
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004789TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00004790SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
Greg Clayton7f995132011-10-04 22:41:51 +00004791 const DWARFDebugInfoEntry *die,
4792 const ConstString &type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004793{
4794 TypeSP type_sp;
4795
Greg Claytona8022fa2012-04-24 21:22:41 +00004796#if defined (LLDB_CONFIGURATION_DEBUG)
4797 // You can't and shouldn't call this function with a compile unit from
4798 // another SymbolFileDWARF instance.
4799 assert (DebugInfo()->ContainsCompileUnit (cu));
4800#endif
4801
Greg Clayton1a65ae12011-01-25 23:55:37 +00004802 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004803 return type_sp;
4804
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004805 std::string qualified_name;
4806
Greg Clayton5160ce52013-03-27 23:08:40 +00004807 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004808 if (log)
4809 {
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004810 die->GetQualifiedName(this, cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00004811 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004812 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x (%s), name='%s')",
4813 die->GetOffset(),
4814 qualified_name.c_str(),
4815 type_name.GetCString());
4816 }
4817
Greg Clayton7f995132011-10-04 22:41:51 +00004818 DIEArray die_offsets;
4819
Greg Clayton97fbc342011-10-20 22:30:33 +00004820 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004821 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004822 if (m_apple_types_ap.get())
4823 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004824 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
4825 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
4826 if (has_tag && has_qualified_name_hash)
Greg Claytond1767f02011-12-08 02:13:16 +00004827 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004828 if (qualified_name.empty())
4829 die->GetQualifiedName(this, cu, qualified_name);
4830
4831 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name.c_str());
4832 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004833 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004834 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), die->Tag(), qualified_name_hash, die_offsets);
4835 }
4836 else if (has_tag > 1)
4837 {
4838 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004839 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
Greg Claytonae920b62012-01-06 00:17:16 +00004840 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets);
Greg Claytond1767f02011-12-08 02:13:16 +00004841 }
4842 else
4843 {
4844 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
4845 }
Greg Clayton97fbc342011-10-20 22:30:33 +00004846 }
Greg Clayton7f995132011-10-04 22:41:51 +00004847 }
4848 else
4849 {
4850 if (!m_indexed)
4851 Index ();
4852
4853 m_type_index.Find (type_name, die_offsets);
4854 }
Greg Clayton7f995132011-10-04 22:41:51 +00004855
4856 const size_t num_matches = die_offsets.size();
Greg Clayton69974892010-12-03 21:42:06 +00004857
Greg Clayton934cb052011-12-03 00:27:05 +00004858 const dw_tag_t die_tag = die->Tag();
Greg Claytond4a2b372011-09-12 23:21:58 +00004859
4860 DWARFCompileUnit* type_cu = NULL;
4861 const DWARFDebugInfoEntry* type_die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00004862 if (num_matches)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004863 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004864 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004865 for (size_t i=0; i<num_matches; ++i)
4866 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004867 const dw_offset_t die_offset = die_offsets[i];
4868 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004869
Greg Clayton95d87902011-11-11 03:16:25 +00004870 if (type_die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004871 {
Greg Clayton934cb052011-12-03 00:27:05 +00004872 bool try_resolving_type = false;
4873
4874 // Don't try and resolve the DIE we are looking for with the DIE itself!
4875 if (type_die != die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004876 {
Greg Clayton934cb052011-12-03 00:27:05 +00004877 const dw_tag_t type_die_tag = type_die->Tag();
4878 // Make sure the tags match
4879 if (type_die_tag == die_tag)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004880 {
Greg Clayton934cb052011-12-03 00:27:05 +00004881 // The tags match, lets try resolving this type
4882 try_resolving_type = true;
4883 }
4884 else
4885 {
4886 // The tags don't match, but we need to watch our for a
4887 // forward declaration for a struct and ("struct foo")
4888 // ends up being a class ("class foo { ... };") or
4889 // vice versa.
4890 switch (type_die_tag)
Greg Clayton95d87902011-11-11 03:16:25 +00004891 {
Greg Clayton934cb052011-12-03 00:27:05 +00004892 case DW_TAG_class_type:
4893 // We had a "class foo", see if we ended up with a "struct foo { ... };"
4894 try_resolving_type = (die_tag == DW_TAG_structure_type);
4895 break;
4896 case DW_TAG_structure_type:
4897 // We had a "struct foo", see if we ended up with a "class foo { ... };"
4898 try_resolving_type = (die_tag == DW_TAG_class_type);
4899 break;
4900 default:
4901 // Tags don't match, don't event try to resolve
4902 // using this type whose name matches....
Greg Clayton95d87902011-11-11 03:16:25 +00004903 break;
4904 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004905 }
4906 }
Greg Clayton934cb052011-12-03 00:27:05 +00004907
4908 if (try_resolving_type)
4909 {
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004910 if (log)
4911 {
4912 std::string qualified_name;
4913 type_die->GetQualifiedName(this, cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00004914 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004915 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') trying die=0x%8.8x (%s)",
4916 die->GetOffset(),
4917 type_name.GetCString(),
4918 type_die->GetOffset(),
4919 qualified_name.c_str());
4920 }
4921
Greg Clayton890ff562012-02-02 05:48:16 +00004922 // Make sure the decl contexts match all the way up
4923 if (DIEDeclContextsMatch(cu, die, type_cu, type_die))
Greg Clayton934cb052011-12-03 00:27:05 +00004924 {
Greg Clayton890ff562012-02-02 05:48:16 +00004925 Type *resolved_type = ResolveType (type_cu, type_die, false);
4926 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4927 {
Daniel Malead01b2952012-11-29 21:49:15 +00004928 DEBUG_PRINTF ("resolved 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ") from %s to 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ")\n",
Greg Clayton890ff562012-02-02 05:48:16 +00004929 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00004930 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton890ff562012-02-02 05:48:16 +00004931 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4932 MakeUserID(type_die->GetOffset()),
4933 MakeUserID(type_cu->GetOffset()));
4934
4935 m_die_to_type[die] = resolved_type;
Greg Claytonff7692a2012-02-02 18:16:59 +00004936 type_sp = resolved_type->shared_from_this();
Greg Clayton890ff562012-02-02 05:48:16 +00004937 break;
4938 }
Greg Clayton934cb052011-12-03 00:27:05 +00004939 }
4940 }
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004941 else
4942 {
4943 if (log)
4944 {
4945 std::string qualified_name;
4946 type_die->GetQualifiedName(this, cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00004947 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004948 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') ignoring die=0x%8.8x (%s)",
4949 die->GetOffset(),
4950 type_name.GetCString(),
4951 type_die->GetOffset(),
4952 qualified_name.c_str());
4953 }
4954 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004955 }
Greg Clayton95d87902011-11-11 03:16:25 +00004956 else
4957 {
4958 if (m_using_apple_tables)
4959 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004960 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4961 die_offset, type_name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004962 }
4963 }
4964
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004965 }
4966 }
4967 return type_sp;
4968}
4969
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004970TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00004971SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx)
4972{
4973 TypeSP type_sp;
4974
4975 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
4976 if (dwarf_decl_ctx_count > 0)
4977 {
4978 const ConstString type_name(dwarf_decl_ctx[0].name);
4979 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
4980
4981 if (type_name)
4982 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004983 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
Greg Claytona8022fa2012-04-24 21:22:41 +00004984 if (log)
4985 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004986 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00004987 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')",
4988 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
4989 dwarf_decl_ctx.GetQualifiedName());
4990 }
4991
4992 DIEArray die_offsets;
4993
4994 if (m_using_apple_tables)
4995 {
4996 if (m_apple_types_ap.get())
4997 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004998 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
4999 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
5000 if (has_tag && has_qualified_name_hash)
Greg Claytona8022fa2012-04-24 21:22:41 +00005001 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005002 const char *qualified_name = dwarf_decl_ctx.GetQualifiedName();
5003 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name);
5004 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005005 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005006 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets);
5007 }
5008 else if (has_tag)
5009 {
5010 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005011 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
Greg Claytona8022fa2012-04-24 21:22:41 +00005012 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets);
5013 }
5014 else
5015 {
5016 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
5017 }
5018 }
5019 }
5020 else
5021 {
5022 if (!m_indexed)
5023 Index ();
5024
5025 m_type_index.Find (type_name, die_offsets);
5026 }
5027
5028 const size_t num_matches = die_offsets.size();
5029
5030
5031 DWARFCompileUnit* type_cu = NULL;
5032 const DWARFDebugInfoEntry* type_die = NULL;
5033 if (num_matches)
5034 {
5035 DWARFDebugInfo* debug_info = DebugInfo();
5036 for (size_t i=0; i<num_matches; ++i)
5037 {
5038 const dw_offset_t die_offset = die_offsets[i];
5039 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
5040
5041 if (type_die)
5042 {
5043 bool try_resolving_type = false;
5044
5045 // Don't try and resolve the DIE we are looking for with the DIE itself!
5046 const dw_tag_t type_tag = type_die->Tag();
5047 // Make sure the tags match
5048 if (type_tag == tag)
5049 {
5050 // The tags match, lets try resolving this type
5051 try_resolving_type = true;
5052 }
5053 else
5054 {
5055 // The tags don't match, but we need to watch our for a
5056 // forward declaration for a struct and ("struct foo")
5057 // ends up being a class ("class foo { ... };") or
5058 // vice versa.
5059 switch (type_tag)
5060 {
5061 case DW_TAG_class_type:
5062 // We had a "class foo", see if we ended up with a "struct foo { ... };"
5063 try_resolving_type = (tag == DW_TAG_structure_type);
5064 break;
5065 case DW_TAG_structure_type:
5066 // We had a "struct foo", see if we ended up with a "class foo { ... };"
5067 try_resolving_type = (tag == DW_TAG_class_type);
5068 break;
5069 default:
5070 // Tags don't match, don't event try to resolve
5071 // using this type whose name matches....
5072 break;
5073 }
5074 }
5075
5076 if (try_resolving_type)
5077 {
5078 DWARFDeclContext type_dwarf_decl_ctx;
5079 type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx);
5080
5081 if (log)
5082 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005083 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005084 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)",
5085 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5086 dwarf_decl_ctx.GetQualifiedName(),
5087 type_die->GetOffset(),
5088 type_dwarf_decl_ctx.GetQualifiedName());
5089 }
5090
5091 // Make sure the decl contexts match all the way up
5092 if (dwarf_decl_ctx == type_dwarf_decl_ctx)
5093 {
5094 Type *resolved_type = ResolveType (type_cu, type_die, false);
5095 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5096 {
5097 type_sp = resolved_type->shared_from_this();
5098 break;
5099 }
5100 }
5101 }
5102 else
5103 {
5104 if (log)
5105 {
5106 std::string qualified_name;
5107 type_die->GetQualifiedName(this, type_cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00005108 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005109 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)",
5110 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5111 dwarf_decl_ctx.GetQualifiedName(),
5112 type_die->GetOffset(),
5113 qualified_name.c_str());
5114 }
5115 }
5116 }
5117 else
5118 {
5119 if (m_using_apple_tables)
5120 {
5121 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5122 die_offset, type_name.GetCString());
5123 }
5124 }
5125
5126 }
5127 }
5128 }
5129 }
5130 return type_sp;
5131}
5132
Greg Clayton4116e932012-05-15 02:33:01 +00005133bool
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005134SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005135 Type *class_type,
Greg Clayton4116e932012-05-15 02:33:01 +00005136 DWARFCompileUnit* src_cu,
5137 const DWARFDebugInfoEntry *src_class_die,
5138 DWARFCompileUnit* dst_cu,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005139 const DWARFDebugInfoEntry *dst_class_die,
5140 llvm::SmallVectorImpl <const DWARFDebugInfoEntry *> &failures)
Greg Clayton4116e932012-05-15 02:33:01 +00005141{
5142 if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die)
5143 return false;
5144 if (src_class_die->Tag() != dst_class_die->Tag())
5145 return false;
5146
5147 // We need to complete the class type so we can get all of the method types
5148 // parsed so we can then unique those types to their equivalent counterparts
5149 // in "dst_cu" and "dst_class_die"
5150 class_type->GetClangFullType();
5151
5152 const DWARFDebugInfoEntry *src_die;
5153 const DWARFDebugInfoEntry *dst_die;
5154 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die;
5155 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die;
Greg Clayton65ec1032012-11-12 21:27:20 +00005156 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial;
5157 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial;
Greg Clayton4116e932012-05-15 02:33:01 +00005158 for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling())
5159 {
5160 if (src_die->Tag() == DW_TAG_subprogram)
5161 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005162 // Make sure this is a declaration and not a concrete instance by looking
5163 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5164 // are placed inside the class definitions and shouldn't be included in
5165 // the list of things are are tracking here.
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005166 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_declaration, 0) == 1)
Greg Clayton84afacd2012-11-07 23:09:32 +00005167 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005168 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton84afacd2012-11-07 23:09:32 +00005169 if (src_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005170 {
5171 ConstString src_const_name(src_name);
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005172 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0))
Greg Clayton65ec1032012-11-12 21:27:20 +00005173 src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die);
5174 else
5175 src_name_to_die.Append(src_const_name.GetCString(), src_die);
5176 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005177 }
Greg Clayton4116e932012-05-15 02:33:01 +00005178 }
5179 }
5180 for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling())
5181 {
5182 if (dst_die->Tag() == DW_TAG_subprogram)
5183 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005184 // Make sure this is a declaration and not a concrete instance by looking
5185 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5186 // are placed inside the class definitions and shouldn't be included in
5187 // the list of things are are tracking here.
5188 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1)
5189 {
5190 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5191 if (dst_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005192 {
5193 ConstString dst_const_name(dst_name);
5194 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0))
5195 dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die);
5196 else
5197 dst_name_to_die.Append(dst_const_name.GetCString(), dst_die);
5198 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005199 }
Greg Clayton4116e932012-05-15 02:33:01 +00005200 }
5201 }
5202 const uint32_t src_size = src_name_to_die.GetSize ();
5203 const uint32_t dst_size = dst_name_to_die.GetSize ();
Greg Clayton5160ce52013-03-27 23:08:40 +00005204 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005205
5206 // Is everything kosher so we can go through the members at top speed?
5207 bool fast_path = true;
5208
5209 if (src_size != dst_size)
Greg Clayton4116e932012-05-15 02:33:01 +00005210 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005211 if (src_size != 0 && dst_size != 0)
5212 {
5213 if (log)
5214 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)",
5215 src_class_die->GetOffset(),
5216 dst_class_die->GetOffset(),
5217 src_size,
5218 dst_size);
5219 }
5220
5221 fast_path = false;
5222 }
5223
5224 uint32_t idx;
5225
5226 if (fast_path)
5227 {
Greg Clayton4116e932012-05-15 02:33:01 +00005228 for (idx = 0; idx < src_size; ++idx)
5229 {
5230 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5231 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5232
5233 if (src_die->Tag() != dst_die->Tag())
5234 {
5235 if (log)
5236 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)",
5237 src_class_die->GetOffset(),
5238 dst_class_die->GetOffset(),
5239 src_die->GetOffset(),
5240 DW_TAG_value_to_name(src_die->Tag()),
5241 dst_die->GetOffset(),
5242 DW_TAG_value_to_name(src_die->Tag()));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005243 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005244 }
5245
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005246 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton4116e932012-05-15 02:33:01 +00005247 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5248
5249 // Make sure the names match
5250 if (src_name == dst_name || (strcmp (src_name, dst_name) == 0))
5251 continue;
5252
5253 if (log)
5254 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)",
5255 src_class_die->GetOffset(),
5256 dst_class_die->GetOffset(),
5257 src_die->GetOffset(),
5258 src_name,
5259 dst_die->GetOffset(),
5260 dst_name);
5261
Sean Callanan2367f8a2013-02-26 01:12:25 +00005262 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005263 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005264 }
Greg Clayton4116e932012-05-15 02:33:01 +00005265
Sean Callanan2367f8a2013-02-26 01:12:25 +00005266 // Now do the work of linking the DeclContexts and Types.
5267 if (fast_path)
5268 {
5269 // We can do this quickly. Just run across the tables index-for-index since
5270 // we know each node has matching names and tags.
Greg Clayton4116e932012-05-15 02:33:01 +00005271 for (idx = 0; idx < src_size; ++idx)
5272 {
5273 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5274 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5275
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005276 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Greg Clayton4116e932012-05-15 02:33:01 +00005277 if (src_decl_ctx)
5278 {
5279 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005280 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005281 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5282 }
5283 else
5284 {
5285 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005286 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());
Greg Clayton4116e932012-05-15 02:33:01 +00005287 }
5288
5289 Type *src_child_type = m_die_to_type[src_die];
5290 if (src_child_type)
5291 {
5292 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00005293 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", src_child_type, src_child_type->GetID(), src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005294 m_die_to_type[dst_die] = src_child_type;
5295 }
5296 else
5297 {
5298 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005299 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());
5300 }
5301 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005302 }
5303 else
5304 {
5305 // We must do this slowly. For each member of the destination, look
5306 // up a member in the source with the same name, check its tag, and
5307 // unique them if everything matches up. Report failures.
Greg Clayton65ec1032012-11-12 21:27:20 +00005308
Sean Callanan2367f8a2013-02-26 01:12:25 +00005309 if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty())
5310 {
5311 src_name_to_die.Sort();
Greg Clayton65ec1032012-11-12 21:27:20 +00005312
Sean Callanan2367f8a2013-02-26 01:12:25 +00005313 for (idx = 0; idx < dst_size; ++idx)
5314 {
5315 const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx);
5316 dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
5317 src_die = src_name_to_die.Find(dst_name, NULL);
5318
5319 if (src_die && (src_die->Tag() == dst_die->Tag()))
5320 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005321 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Sean Callanan2367f8a2013-02-26 01:12:25 +00005322 if (src_decl_ctx)
5323 {
5324 if (log)
5325 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
5326 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5327 }
5328 else
5329 {
5330 if (log)
5331 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());
5332 }
5333
5334 Type *src_child_type = m_die_to_type[src_die];
5335 if (src_child_type)
5336 {
5337 if (log)
5338 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", src_child_type, src_child_type->GetID(), src_die->GetOffset(), dst_die->GetOffset());
5339 m_die_to_type[dst_die] = src_child_type;
5340 }
5341 else
5342 {
5343 if (log)
5344 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());
5345 }
5346 }
5347 else
5348 {
5349 if (log)
5350 log->Printf ("warning: couldn't find a match for 0x%8.8x", dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005351
Sean Callanan2367f8a2013-02-26 01:12:25 +00005352 failures.push_back(dst_die);
5353 }
5354 }
5355 }
5356 }
5357
5358 const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize ();
5359 const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize ();
5360
5361 UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src;
5362
5363 if (src_size_artificial && dst_size_artificial)
5364 {
5365 dst_name_to_die_artificial.Sort();
5366
Greg Clayton65ec1032012-11-12 21:27:20 +00005367 for (idx = 0; idx < src_size_artificial; ++idx)
5368 {
5369 const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx);
5370 src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5371 dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL);
5372
5373 if (dst_die)
5374 {
Greg Clayton65ec1032012-11-12 21:27:20 +00005375 // Both classes have the artificial types, link them
5376 clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die];
5377 if (src_decl_ctx)
5378 {
5379 if (log)
5380 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
5381 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5382 }
5383 else
5384 {
5385 if (log)
5386 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());
5387 }
5388
5389 Type *src_child_type = m_die_to_type[src_die];
5390 if (src_child_type)
5391 {
5392 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00005393 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", src_child_type, src_child_type->GetID(), src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005394 m_die_to_type[dst_die] = src_child_type;
5395 }
5396 else
5397 {
5398 if (log)
5399 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());
5400 }
5401 }
5402 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005403 }
Greg Clayton65ec1032012-11-12 21:27:20 +00005404
Sean Callanan2367f8a2013-02-26 01:12:25 +00005405 if (dst_size_artificial)
Greg Clayton4116e932012-05-15 02:33:01 +00005406 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005407 for (idx = 0; idx < dst_size_artificial; ++idx)
5408 {
5409 const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx);
5410 dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5411 if (log)
5412 log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial);
5413
5414 failures.push_back(dst_die);
5415 }
Greg Clayton4116e932012-05-15 02:33:01 +00005416 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005417
5418 return (failures.size() != 0);
Greg Clayton4116e932012-05-15 02:33:01 +00005419}
Greg Claytona8022fa2012-04-24 21:22:41 +00005420
5421TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00005422SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005423{
5424 TypeSP type_sp;
5425
Greg Clayton1be10fc2010-09-29 01:12:09 +00005426 if (type_is_new_ptr)
5427 *type_is_new_ptr = false;
Greg Clayton1fba87112012-02-09 20:03:49 +00005428
5429#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5430 static DIEStack g_die_stack;
5431 DIEStack::ScopedPopper scoped_die_logger(g_die_stack);
5432#endif
Greg Clayton1be10fc2010-09-29 01:12:09 +00005433
Sean Callananc7fbf732010-08-06 00:32:49 +00005434 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005435 if (die != NULL)
5436 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005437 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005438 if (log)
Sean Callanan5b26f272012-02-04 08:49:35 +00005439 {
5440 const DWARFDebugInfoEntry *context_die;
5441 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
5442
Greg Clayton5160ce52013-03-27 23:08:40 +00005443 GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x, decl_ctx = %p (die 0x%8.8x)) %s name = '%s')",
Sean Callanan5b26f272012-02-04 08:49:35 +00005444 die->GetOffset(),
5445 context,
5446 context_die->GetOffset(),
Greg Clayton3bffb082011-12-10 02:15:28 +00005447 DW_TAG_value_to_name(die->Tag()),
Greg Clayton1fba87112012-02-09 20:03:49 +00005448 die->GetName(this, dwarf_cu));
5449
5450#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5451 scoped_die_logger.Push (dwarf_cu, die);
Greg Clayton5160ce52013-03-27 23:08:40 +00005452 g_die_stack.LogDIEs(log, this);
Greg Clayton1fba87112012-02-09 20:03:49 +00005453#endif
Sean Callanan5b26f272012-02-04 08:49:35 +00005454 }
Greg Clayton3bffb082011-12-10 02:15:28 +00005455//
Greg Clayton5160ce52013-03-27 23:08:40 +00005456// Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005457// if (log && dwarf_cu)
5458// {
5459// StreamString s;
5460// die->DumpLocation (this, dwarf_cu, s);
Greg Clayton5160ce52013-03-27 23:08:40 +00005461// GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Greg Clayton3bffb082011-12-10 02:15:28 +00005462//
5463// }
Jim Ingham16746d12011-08-25 23:21:43 +00005464
Greg Clayton594e5ed2010-09-27 21:07:38 +00005465 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005466 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00005467 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005468 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005469 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00005470 if (type_is_new_ptr)
5471 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005472
Greg Clayton594e5ed2010-09-27 21:07:38 +00005473 const dw_tag_t tag = die->Tag();
5474
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005475 bool is_forward_declaration = false;
5476 DWARFDebugInfoEntry::Attributes attributes;
5477 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00005478 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00005479 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
Greg Claytonfaac1112013-03-14 18:31:44 +00005480 uint64_t byte_size = 0;
Greg Clayton526e5af2010-11-13 03:52:47 +00005481 Declaration decl;
5482
Greg Clayton4957bf62010-09-30 21:49:03 +00005483 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton1be10fc2010-09-29 01:12:09 +00005484 clang_type_t clang_type = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005485
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005486 dw_attr_t attr;
5487
5488 switch (tag)
5489 {
5490 case DW_TAG_base_type:
5491 case DW_TAG_pointer_type:
5492 case DW_TAG_reference_type:
Sean Callanance8af862012-05-21 23:31:51 +00005493 case DW_TAG_rvalue_reference_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005494 case DW_TAG_typedef:
5495 case DW_TAG_const_type:
5496 case DW_TAG_restrict_type:
5497 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00005498 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005499 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005500 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005501 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005502
Greg Claytond88d7592010-09-15 08:33:30 +00005503 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005504 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005505 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
5506
5507 if (num_attributes > 0)
5508 {
5509 uint32_t i;
5510 for (i=0; i<num_attributes; ++i)
5511 {
5512 attr = attributes.AttributeAtIndex(i);
5513 DWARFFormValue form_value;
5514 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5515 {
5516 switch (attr)
5517 {
5518 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5519 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5520 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5521 case DW_AT_name:
Jim Ingham337030f2011-04-15 23:41:23 +00005522
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005523 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00005524 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
5525 // include the "&"...
5526 if (tag == DW_TAG_reference_type)
5527 {
5528 if (strchr (type_name_cstr, '&') == NULL)
5529 type_name_cstr = NULL;
5530 }
5531 if (type_name_cstr)
5532 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005533 break;
Greg Clayton23f59502012-07-17 03:23:13 +00005534 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005535 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
5536 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
5537 default:
5538 case DW_AT_sibling:
5539 break;
5540 }
5541 }
5542 }
5543 }
5544
Daniel Malead01b2952012-11-29 21:49:15 +00005545 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\") type => 0x%8.8x\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr, encoding_uid);
Greg Claytonc93237c2010-10-01 20:48:32 +00005546
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005547 switch (tag)
5548 {
5549 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00005550 break;
5551
Greg Claytond4436412011-10-28 21:00:00 +00005552 case DW_TAG_unspecified_type:
5553 if (strcmp(type_name_cstr, "nullptr_t") == 0)
5554 {
5555 resolve_state = Type::eResolveStateFull;
5556 clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr();
5557 break;
5558 }
5559 // Fall through to base type below in case we can handle the type there...
5560
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005561 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00005562 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005563 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
5564 encoding,
5565 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005566 break;
5567
Sean Callanance8af862012-05-21 23:31:51 +00005568 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
5569 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
5570 case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break;
5571 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
5572 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
5573 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
5574 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005575 }
5576
Sean Callanan82587052013-01-03 00:05:56 +00005577 if (clang_type == NULL && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID) && sc.comp_unit != NULL)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005578 {
Sean Callanan82587052013-01-03 00:05:56 +00005579 bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus);
5580
5581 if (translation_unit_is_objc)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005582 {
Sean Callanan82587052013-01-03 00:05:56 +00005583 if (type_name_cstr != NULL)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005584 {
Sean Callanan82587052013-01-03 00:05:56 +00005585 static ConstString g_objc_type_name_id("id");
5586 static ConstString g_objc_type_name_Class("Class");
5587 static ConstString g_objc_type_name_selector("SEL");
5588
5589 if (type_name_const_str == g_objc_type_name_id)
5590 {
5591 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005592 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 +00005593 die->GetOffset(),
5594 DW_TAG_value_to_name(die->Tag()),
5595 die->GetName(this, dwarf_cu));
5596 clang_type = ast.GetBuiltInType_objc_id();
5597 encoding_data_type = Type::eEncodingIsUID;
5598 encoding_uid = LLDB_INVALID_UID;
5599 resolve_state = Type::eResolveStateFull;
Greg Clayton526e5af2010-11-13 03:52:47 +00005600
Sean Callanan82587052013-01-03 00:05:56 +00005601 }
5602 else if (type_name_const_str == g_objc_type_name_Class)
5603 {
5604 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005605 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 +00005606 die->GetOffset(),
5607 DW_TAG_value_to_name(die->Tag()),
5608 die->GetName(this, dwarf_cu));
5609 clang_type = ast.GetBuiltInType_objc_Class();
5610 encoding_data_type = Type::eEncodingIsUID;
5611 encoding_uid = LLDB_INVALID_UID;
5612 resolve_state = Type::eResolveStateFull;
5613 }
5614 else if (type_name_const_str == g_objc_type_name_selector)
5615 {
5616 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005617 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 +00005618 die->GetOffset(),
5619 DW_TAG_value_to_name(die->Tag()),
5620 die->GetName(this, dwarf_cu));
5621 clang_type = ast.GetBuiltInType_objc_selector();
5622 encoding_data_type = Type::eEncodingIsUID;
5623 encoding_uid = LLDB_INVALID_UID;
5624 resolve_state = Type::eResolveStateFull;
5625 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005626 }
Sean Callanan82587052013-01-03 00:05:56 +00005627 else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005628 {
Sean Callanan82587052013-01-03 00:05:56 +00005629 // Clang sometimes erroneously emits id as objc_object*. In that case we fix up the type to "id".
5630
5631 DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid);
5632
5633 if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type)
5634 {
5635 if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL))
5636 {
5637 if (!strcmp(struct_name, "objc_object"))
5638 {
5639 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005640 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 +00005641 die->GetOffset(),
5642 DW_TAG_value_to_name(die->Tag()),
5643 die->GetName(this, dwarf_cu));
5644 clang_type = ast.GetBuiltInType_objc_id();
5645 encoding_data_type = Type::eEncodingIsUID;
5646 encoding_uid = LLDB_INVALID_UID;
5647 resolve_state = Type::eResolveStateFull;
5648 }
5649 }
5650 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005651 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005652 }
5653 }
5654
Greg Clayton81c22f62011-10-19 18:09:39 +00005655 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005656 this,
5657 type_name_const_str,
5658 byte_size,
5659 NULL,
5660 encoding_uid,
5661 encoding_data_type,
5662 &decl,
5663 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005664 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005665
Greg Clayton594e5ed2010-09-27 21:07:38 +00005666 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005667
5668// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
5669// if (encoding_type != NULL)
5670// {
5671// if (encoding_type != DIE_IS_BEING_PARSED)
5672// type_sp->SetEncodingType(encoding_type);
5673// else
5674// m_indirect_fixups.push_back(type_sp.get());
5675// }
5676 }
5677 break;
5678
5679 case DW_TAG_structure_type:
5680 case DW_TAG_union_type:
5681 case DW_TAG_class_type:
5682 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005683 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005684 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Greg Clayton23f59502012-07-17 03:23:13 +00005685 bool byte_size_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005686
Greg Clayton9e409562010-07-28 02:04:09 +00005687 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00005688 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005689 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00005690 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005691 if (num_attributes > 0)
5692 {
5693 uint32_t i;
5694 for (i=0; i<num_attributes; ++i)
5695 {
5696 attr = attributes.AttributeAtIndex(i);
5697 DWARFFormValue form_value;
5698 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5699 {
5700 switch (attr)
5701 {
Greg Clayton9e409562010-07-28 02:04:09 +00005702 case DW_AT_decl_file:
Greg Claytonc7f03b62012-01-12 04:33:28 +00005703 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
5704 {
5705 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
5706 // point to the compile unit file, so we clear this invalid value
5707 // so that we can still unique types efficiently.
5708 decl.SetFile(FileSpec ("<invalid>", false));
5709 }
5710 else
5711 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
Greg Clayton9e409562010-07-28 02:04:09 +00005712 break;
5713
5714 case DW_AT_decl_line:
5715 decl.SetLine(form_value.Unsigned());
5716 break;
5717
5718 case DW_AT_decl_column:
5719 decl.SetColumn(form_value.Unsigned());
5720 break;
5721
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005722 case DW_AT_name:
5723 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005724 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005725 break;
Greg Clayton9e409562010-07-28 02:04:09 +00005726
5727 case DW_AT_byte_size:
5728 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00005729 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00005730 break;
5731
5732 case DW_AT_accessibility:
5733 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
5734 break;
5735
5736 case DW_AT_declaration:
Greg Clayton1c8ef472013-04-05 23:27:21 +00005737 is_forward_declaration = form_value.Boolean();
Greg Clayton9e409562010-07-28 02:04:09 +00005738 break;
5739
5740 case DW_AT_APPLE_runtime_class:
5741 class_language = (LanguageType)form_value.Signed();
5742 break;
5743
Greg Clayton18774842011-11-29 23:40:34 +00005744 case DW_AT_APPLE_objc_complete_type:
5745 is_complete_objc_class = form_value.Signed();
5746 break;
5747
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005748 case DW_AT_allocated:
5749 case DW_AT_associated:
5750 case DW_AT_data_location:
5751 case DW_AT_description:
5752 case DW_AT_start_scope:
5753 case DW_AT_visibility:
5754 default:
5755 case DW_AT_sibling:
5756 break;
5757 }
5758 }
5759 }
5760 }
5761
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005762 UniqueDWARFASTType unique_ast_entry;
Sean Callanan8e8072d2012-02-07 21:13:38 +00005763
Greg Clayton123edca2012-03-02 00:07:15 +00005764 // Only try and unique the type if it has a name.
5765 if (type_name_const_str &&
5766 GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Sean Callanan8e8072d2012-02-07 21:13:38 +00005767 this,
5768 dwarf_cu,
5769 die,
5770 decl,
5771 byte_size_valid ? byte_size : -1,
5772 unique_ast_entry))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005773 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005774 // We have already parsed this type or from another
5775 // compile unit. GCC loves to use the "one definition
5776 // rule" which can result in multiple definitions
5777 // of the same class over and over in each compile
5778 // unit.
5779 type_sp = unique_ast_entry.m_type_sp;
5780 if (type_sp)
Greg Claytonc615ce42010-11-09 04:42:43 +00005781 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005782 m_die_to_type[die] = type_sp.get();
5783 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005784 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005785 }
5786
Daniel Malead01b2952012-11-29 21:49:15 +00005787 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 +00005788
5789 int tag_decl_kind = -1;
5790 AccessType default_accessibility = eAccessNone;
5791 if (tag == DW_TAG_structure_type)
5792 {
5793 tag_decl_kind = clang::TTK_Struct;
5794 default_accessibility = eAccessPublic;
5795 }
5796 else if (tag == DW_TAG_union_type)
5797 {
5798 tag_decl_kind = clang::TTK_Union;
5799 default_accessibility = eAccessPublic;
5800 }
5801 else if (tag == DW_TAG_class_type)
5802 {
5803 tag_decl_kind = clang::TTK_Class;
5804 default_accessibility = eAccessPrivate;
5805 }
Greg Clayton3a5f29a2011-11-30 02:48:28 +00005806
5807 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
5808 die->HasChildren() == false &&
5809 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
5810 {
5811 // Work around an issue with clang at the moment where
5812 // forward declarations for objective C classes are emitted
5813 // as:
5814 // DW_TAG_structure_type [2]
5815 // DW_AT_name( "ForwardObjcClass" )
5816 // DW_AT_byte_size( 0x00 )
5817 // DW_AT_decl_file( "..." )
5818 // DW_AT_decl_line( 1 )
5819 //
5820 // Note that there is no DW_AT_declaration and there are
5821 // no children, and the byte size is zero.
5822 is_forward_declaration = true;
5823 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005824
Sean Callanan7457f8d2012-04-25 01:03:57 +00005825 if (class_language == eLanguageTypeObjC ||
5826 class_language == eLanguageTypeObjC_plus_plus)
Greg Clayton18774842011-11-29 23:40:34 +00005827 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005828 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
Greg Clayton901c5ca2011-12-03 04:40:03 +00005829 {
5830 // We have a valid eSymbolTypeObjCClass class symbol whose
5831 // name matches the current objective C class that we
5832 // are trying to find and this DIE isn't the complete
5833 // definition (we checked is_complete_objc_class above and
5834 // know it is false), so the real definition is in here somewhere
Greg Claytonc7f03b62012-01-12 04:33:28 +00005835 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005836
Greg Clayton1f746072012-08-29 21:13:06 +00005837 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton901c5ca2011-12-03 04:40:03 +00005838 {
5839 // We weren't able to find a full declaration in
5840 // this DWARF, see if we have a declaration anywhere
5841 // else...
Greg Claytonc7f03b62012-01-12 04:33:28 +00005842 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00005843 }
5844
5845 if (type_sp)
5846 {
5847 if (log)
5848 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005849 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00005850 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8" PRIx64,
Greg Claytone38a5ed2012-01-05 03:57:59 +00005851 this,
5852 die->GetOffset(),
5853 DW_TAG_value_to_name(tag),
5854 type_name_cstr,
5855 type_sp->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00005856 }
5857
5858 // We found a real definition for this type elsewhere
5859 // so lets use it and cache the fact that we found
5860 // a complete type for this die
5861 m_die_to_type[die] = type_sp.get();
5862 return type_sp;
5863 }
5864 }
5865 }
5866
5867
5868 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005869 {
5870 // We have a forward declaration to a type and we need
5871 // to try and find a full declaration. We look in the
5872 // current type index just in case we have a forward
5873 // declaration followed by an actual declarations in the
5874 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00005875 if (log)
5876 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005877 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00005878 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
5879 this,
5880 die->GetOffset(),
5881 DW_TAG_value_to_name(tag),
5882 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00005883 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005884
Greg Claytona8022fa2012-04-24 21:22:41 +00005885 DWARFDeclContext die_decl_ctx;
5886 die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx);
5887
5888 //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
5889 type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005890
Greg Clayton1f746072012-08-29 21:13:06 +00005891 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton4272cc72011-02-02 02:24:04 +00005892 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005893 // We weren't able to find a full declaration in
5894 // this DWARF, see if we have a declaration anywhere
5895 // else...
Greg Claytona8022fa2012-04-24 21:22:41 +00005896 type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton4272cc72011-02-02 02:24:04 +00005897 }
5898
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005899 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00005900 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00005901 if (log)
5902 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005903 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00005904 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8" PRIx64,
Greg Claytone38a5ed2012-01-05 03:57:59 +00005905 this,
5906 die->GetOffset(),
5907 DW_TAG_value_to_name(tag),
5908 type_name_cstr,
5909 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00005910 }
5911
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005912 // We found a real definition for this type elsewhere
5913 // so lets use it and cache the fact that we found
5914 // a complete type for this die
5915 m_die_to_type[die] = type_sp.get();
5916 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005917 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005918 }
5919 assert (tag_decl_kind != -1);
5920 bool clang_type_was_created = false;
5921 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
5922 if (clang_type == NULL)
5923 {
Sean Callanan4d04c6a2012-02-09 22:54:11 +00005924 const DWARFDebugInfoEntry *decl_ctx_die;
5925
5926 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton55561e92011-10-26 03:31:36 +00005927 if (accessibility == eAccessNone && decl_ctx)
5928 {
5929 // Check the decl context that contains this class/struct/union.
5930 // If it is a class we must give it an accessability.
5931 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
5932 if (DeclKindIsCXXClass (containing_decl_kind))
5933 accessibility = default_accessibility;
5934 }
5935
Greg Claytonc4ffd662013-03-08 01:37:30 +00005936 ClangASTMetadata metadata;
5937 metadata.SetUserID(MakeUserID(die->GetOffset()));
5938 metadata.SetIsDynamicCXXType(ClassOrStructIsVirtual (dwarf_cu, die));
5939
Greg Claytonf0705c82011-10-22 03:33:13 +00005940 if (type_name_cstr && strchr (type_name_cstr, '<'))
5941 {
5942 ClangASTContext::TemplateParameterInfos template_param_infos;
5943 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
5944 {
5945 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00005946 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00005947 type_name_cstr,
5948 tag_decl_kind,
5949 template_param_infos);
5950
5951 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
5952 class_template_decl,
5953 tag_decl_kind,
5954 template_param_infos);
5955 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
5956 clang_type_was_created = true;
Sean Callanan60217122012-04-13 00:10:03 +00005957
Greg Claytond0029442013-03-27 01:48:02 +00005958 GetClangASTContext().SetMetadata (class_template_decl, metadata);
5959 GetClangASTContext().SetMetadata (class_specialization_decl, metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00005960 }
5961 }
5962
5963 if (!clang_type_was_created)
5964 {
5965 clang_type_was_created = true;
Greg Clayton55561e92011-10-26 03:31:36 +00005966 clang_type = ast.CreateRecordType (decl_ctx,
5967 accessibility,
5968 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00005969 tag_decl_kind,
Sean Callanan60217122012-04-13 00:10:03 +00005970 class_language,
Jim Ingham379397632012-10-27 02:54:13 +00005971 &metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00005972 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005973 }
5974
5975 // Store a forward declaration to this class type in case any
5976 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00005977 // types for function prototypes.
5978 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00005979 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005980 this,
5981 type_name_const_str,
5982 byte_size,
5983 NULL,
5984 LLDB_INVALID_UID,
5985 Type::eEncodingIsUID,
5986 &decl,
5987 clang_type,
5988 Type::eResolveStateForward));
Sean Callanan72772842012-02-22 23:57:45 +00005989
5990 type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005991
5992
5993 // Add our type to the unique type map so we don't
5994 // end up creating many copies of the same type over
5995 // and over in the ASTContext for our module
5996 unique_ast_entry.m_type_sp = type_sp;
Greg Clayton36909642011-03-15 04:38:20 +00005997 unique_ast_entry.m_symfile = this;
5998 unique_ast_entry.m_cu = dwarf_cu;
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005999 unique_ast_entry.m_die = die;
6000 unique_ast_entry.m_declaration = decl;
Sean Callanan59700592012-02-13 22:30:16 +00006001 unique_ast_entry.m_byte_size = byte_size;
Greg Claytone576ab22011-02-15 00:19:15 +00006002 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
6003 unique_ast_entry);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006004
Sean Callanan12014a02011-12-08 23:45:45 +00006005 if (!is_forward_declaration)
Greg Clayton219cf312012-03-30 00:51:13 +00006006 {
6007 // Always start the definition for a class type so that
6008 // if the class has child classes or types that require
6009 // the class to be created for use as their decl contexts
6010 // the class will be ready to accept these child definitions.
Sean Callanan12014a02011-12-08 23:45:45 +00006011 if (die->HasChildren() == false)
6012 {
6013 // No children for this struct/union/class, lets finish it
6014 ast.StartTagDeclarationDefinition (clang_type);
6015 ast.CompleteTagDeclarationDefinition (clang_type);
Sean Callanan433cd222012-10-19 01:37:25 +00006016
6017 if (tag == DW_TAG_structure_type) // this only applies in C
6018 {
6019 clang::QualType qual_type = clang::QualType::getFromOpaquePtr (clang_type);
6020 const clang::RecordType *record_type = qual_type->getAs<clang::RecordType> ();
6021
6022 if (record_type)
6023 {
6024 clang::RecordDecl *record_decl = record_type->getDecl();
6025
6026 if (record_decl)
6027 {
6028 LayoutInfo layout_info;
6029
6030 layout_info.alignment = 0;
6031 layout_info.bit_size = 0;
6032
6033 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
6034 }
6035 }
6036 }
Sean Callanan12014a02011-12-08 23:45:45 +00006037 }
6038 else if (clang_type_was_created)
6039 {
Greg Clayton219cf312012-03-30 00:51:13 +00006040 // Start the definition if the class is not objective C since
6041 // the underlying decls respond to isCompleteDefinition(). Objective
6042 // C decls dont' respond to isCompleteDefinition() so we can't
6043 // start the declaration definition right away. For C++ classs/union/structs
6044 // we want to start the definition in case the class is needed as the
6045 // declaration context for a contained class or type without the need
6046 // to complete that type..
6047
Sean Callanan7457f8d2012-04-25 01:03:57 +00006048 if (class_language != eLanguageTypeObjC &&
6049 class_language != eLanguageTypeObjC_plus_plus)
Greg Clayton219cf312012-03-30 00:51:13 +00006050 ast.StartTagDeclarationDefinition (clang_type);
6051
Sean Callanan12014a02011-12-08 23:45:45 +00006052 // Leave this as a forward declaration until we need
6053 // to know the details of the type. lldb_private::Type
6054 // will automatically call the SymbolFile virtual function
6055 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
6056 // When the definition needs to be defined.
6057 m_forward_decl_die_to_clang_type[die] = clang_type;
6058 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
6059 ClangASTContext::SetHasExternalStorage (clang_type, true);
6060 }
Greg Claytonc615ce42010-11-09 04:42:43 +00006061 }
Greg Claytoncab36a32011-12-08 05:16:30 +00006062
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006063 }
6064 break;
6065
6066 case DW_TAG_enumeration_type:
6067 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006068 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006069 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006070
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006071 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006072
Greg Claytond88d7592010-09-15 08:33:30 +00006073 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006074 if (num_attributes > 0)
6075 {
6076 uint32_t i;
6077
6078 for (i=0; i<num_attributes; ++i)
6079 {
6080 attr = attributes.AttributeAtIndex(i);
6081 DWARFFormValue form_value;
6082 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6083 {
6084 switch (attr)
6085 {
Greg Clayton7a345282010-11-09 23:46:37 +00006086 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6087 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6088 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006089 case DW_AT_name:
6090 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006091 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006092 break;
Greg Clayton7a345282010-11-09 23:46:37 +00006093 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006094 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
6095 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006096 case DW_AT_declaration: break; //is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006097 case DW_AT_allocated:
6098 case DW_AT_associated:
6099 case DW_AT_bit_stride:
6100 case DW_AT_byte_stride:
6101 case DW_AT_data_location:
6102 case DW_AT_description:
6103 case DW_AT_start_scope:
6104 case DW_AT_visibility:
6105 case DW_AT_specification:
6106 case DW_AT_abstract_origin:
6107 case DW_AT_sibling:
6108 break;
6109 }
6110 }
6111 }
6112
Daniel Malead01b2952012-11-29 21:49:15 +00006113 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 +00006114
Greg Clayton1be10fc2010-09-29 01:12:09 +00006115 clang_type_t enumerator_clang_type = NULL;
6116 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
6117 if (clang_type == NULL)
6118 {
Greg Clayton5d14fc02013-03-06 06:23:54 +00006119 if (encoding_uid != DW_INVALID_OFFSET)
6120 {
6121 Type *enumerator_type = ResolveTypeUID(encoding_uid);
6122 if (enumerator_type)
6123 enumerator_clang_type = enumerator_type->GetClangFullType();
6124 }
6125
6126 if (enumerator_clang_type == NULL)
6127 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
6128 DW_ATE_signed,
6129 byte_size * 8);
6130
Greg Claytonca512b32011-01-14 04:54:56 +00006131 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00006132 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00006133 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006134 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00006135 }
6136 else
6137 {
6138 enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00006139 }
6140
Greg Claytona2721472011-06-25 00:44:06 +00006141 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
6142
Greg Clayton81c22f62011-10-19 18:09:39 +00006143 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006144 this,
6145 type_name_const_str,
6146 byte_size,
6147 NULL,
6148 encoding_uid,
6149 Type::eEncodingIsUID,
6150 &decl,
6151 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006152 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006153
Greg Clayton6beaaa62011-01-17 03:46:26 +00006154 ast.StartTagDeclarationDefinition (clang_type);
6155 if (die->HasChildren())
6156 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006157 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00006158 bool is_signed = false;
Greg Clayton5d14fc02013-03-06 06:23:54 +00006159 ast.IsIntegerType(enumerator_clang_type, is_signed);
Greg Clayton3e067532013-03-05 23:54:39 +00006160 ParseChildEnumerators(cu_sc, clang_type, is_signed, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00006161 }
6162 ast.CompleteTagDeclarationDefinition (clang_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006163 }
6164 }
6165 break;
6166
Jim Inghamb0be4422010-08-12 01:20:14 +00006167 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006168 case DW_TAG_subprogram:
6169 case DW_TAG_subroutine_type:
6170 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006171 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006172 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006173
Greg Clayton23f59502012-07-17 03:23:13 +00006174 //const char *mangled = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006175 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00006176 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006177 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00006178 bool is_static = false;
6179 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00006180 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00006181 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00006182 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
6183 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Jim Ingham379397632012-10-27 02:54:13 +00006184 dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00006185
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006186 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00006187 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006188
6189
Greg Claytond88d7592010-09-15 08:33:30 +00006190 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006191 if (num_attributes > 0)
6192 {
6193 uint32_t i;
6194 for (i=0; i<num_attributes; ++i)
6195 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006196 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006197 DWARFFormValue form_value;
6198 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6199 {
6200 switch (attr)
6201 {
6202 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6203 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6204 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6205 case DW_AT_name:
6206 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006207 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006208 break;
6209
Greg Clayton71415542012-12-08 00:24:40 +00006210 case DW_AT_linkage_name:
Greg Clayton23f59502012-07-17 03:23:13 +00006211 case DW_AT_MIPS_linkage_name: break; // mangled = form_value.AsCString(&get_debug_str_data()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006212 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00006213 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006214 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
6215 case DW_AT_inline: is_inline = form_value.Boolean(); break;
6216 case DW_AT_virtuality: is_virtual = form_value.Boolean(); break;
6217 case DW_AT_explicit: is_explicit = form_value.Boolean(); break;
6218 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Sean Callanandbb58392011-11-02 01:38:59 +00006219
Greg Claytonf51de672010-10-01 02:31:07 +00006220
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006221 case DW_AT_external:
6222 if (form_value.Unsigned())
6223 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00006224 if (storage == clang::SC_None)
6225 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006226 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00006227 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006228 }
6229 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006230
Greg Clayton72da3972011-08-16 18:40:23 +00006231 case DW_AT_specification:
6232 specification_die_offset = form_value.Reference(dwarf_cu);
6233 break;
6234
6235 case DW_AT_abstract_origin:
6236 abstract_origin_die_offset = form_value.Reference(dwarf_cu);
6237 break;
6238
Jim Ingham379397632012-10-27 02:54:13 +00006239 case DW_AT_object_pointer:
6240 object_pointer_die_offset = form_value.Reference(dwarf_cu);
6241 break;
6242
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006243 case DW_AT_allocated:
6244 case DW_AT_associated:
6245 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006246 case DW_AT_calling_convention:
6247 case DW_AT_data_location:
6248 case DW_AT_elemental:
6249 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006250 case DW_AT_frame_base:
6251 case DW_AT_high_pc:
6252 case DW_AT_low_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006253 case DW_AT_prototyped:
6254 case DW_AT_pure:
6255 case DW_AT_ranges:
6256 case DW_AT_recursive:
6257 case DW_AT_return_addr:
6258 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006259 case DW_AT_start_scope:
6260 case DW_AT_static_link:
6261 case DW_AT_trampoline:
6262 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006263 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006264 case DW_AT_description:
6265 case DW_AT_sibling:
6266 break;
6267 }
6268 }
6269 }
Greg Clayton24739922010-10-13 03:15:28 +00006270 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006271
Jim Ingham379397632012-10-27 02:54:13 +00006272 std::string object_pointer_name;
6273 if (object_pointer_die_offset != DW_INVALID_OFFSET)
6274 {
6275 // Get the name from the object pointer die
6276 StreamString s;
6277 if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s))
6278 {
6279 object_pointer_name.assign(s.GetData());
6280 }
6281 }
6282
Daniel Malead01b2952012-11-29 21:49:15 +00006283 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 +00006284
Greg Clayton24739922010-10-13 03:15:28 +00006285 clang_type_t return_clang_type = NULL;
6286 Type *func_type = NULL;
6287
6288 if (type_die_offset != DW_INVALID_OFFSET)
6289 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00006290
Greg Clayton24739922010-10-13 03:15:28 +00006291 if (func_type)
Greg Clayton42ce2f32011-12-12 21:50:19 +00006292 return_clang_type = func_type->GetClangForwardType();
Greg Clayton24739922010-10-13 03:15:28 +00006293 else
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006294 return_clang_type = ast.GetBuiltInType_void();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006295
Greg Claytonf51de672010-10-01 02:31:07 +00006296
Greg Clayton24739922010-10-13 03:15:28 +00006297 std::vector<clang_type_t> function_param_types;
6298 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006299
Greg Clayton24739922010-10-13 03:15:28 +00006300 // Parse the function children for the parameters
Sean Callanan763d72a2011-08-02 22:21:50 +00006301
Greg Claytoncb5860a2011-10-13 23:49:28 +00006302 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
6303 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00006304 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
6305
Greg Claytonf0705c82011-10-22 03:33:13 +00006306 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00006307 // Start off static. This will be set to false in ParseChildParameters(...)
6308 // if we find a "this" paramters as the first parameter
6309 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00006310 is_static = true;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006311 ClangASTContext::TemplateParameterInfos template_param_infos;
6312
Greg Clayton24739922010-10-13 03:15:28 +00006313 if (die->HasChildren())
6314 {
Greg Clayton0fffff52010-09-24 05:15:53 +00006315 bool skip_artificial = true;
Jim Ingham379397632012-10-27 02:54:13 +00006316 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00006317 containing_decl_ctx,
Jim Ingham379397632012-10-27 02:54:13 +00006318 dwarf_cu,
6319 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00006320 skip_artificial,
6321 is_static,
Jim Ingham379397632012-10-27 02:54:13 +00006322 type_list,
6323 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00006324 function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006325 type_quals,
6326 template_param_infos);
Greg Clayton24739922010-10-13 03:15:28 +00006327 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006328
Greg Clayton24739922010-10-13 03:15:28 +00006329 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006330 clang_type = ast.CreateFunctionType (return_clang_type,
Greg Clayton9cb25c42012-10-30 17:02:18 +00006331 function_param_types.data(),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006332 function_param_types.size(),
6333 is_variadic,
6334 type_quals);
6335
Sean Callanande9ce872013-05-09 23:13:13 +00006336 bool ignore_containing_context = false;
6337
Greg Clayton24739922010-10-13 03:15:28 +00006338 if (type_name_cstr)
6339 {
6340 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00006341 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006342 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00006343 ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true);
6344 if (objc_method.IsValid(true))
Greg Clayton0fffff52010-09-24 05:15:53 +00006345 {
Greg Clayton24739922010-10-13 03:15:28 +00006346 SymbolContext empty_sc;
6347 clang_type_t class_opaque_type = NULL;
Greg Clayton1b3815c2013-01-30 00:18:29 +00006348 ConstString class_name(objc_method.GetClassName());
Greg Clayton7c810422012-01-18 23:40:49 +00006349 if (class_name)
Greg Clayton0fffff52010-09-24 05:15:53 +00006350 {
Greg Clayton24739922010-10-13 03:15:28 +00006351 TypeList types;
Greg Clayton278a16b2012-01-19 00:52:59 +00006352 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
Greg Claytonc7f03b62012-01-12 04:33:28 +00006353
6354 if (complete_objc_class_type_sp)
Greg Clayton0fffff52010-09-24 05:15:53 +00006355 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00006356 clang_type_t type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
6357 if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
6358 class_opaque_type = type_clang_forward_type;
Greg Clayton0fffff52010-09-24 05:15:53 +00006359 }
Greg Clayton24739922010-10-13 03:15:28 +00006360 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006361
Greg Clayton24739922010-10-13 03:15:28 +00006362 if (class_opaque_type)
6363 {
6364 // If accessibility isn't set to anything valid, assume public for
6365 // now...
6366 if (accessibility == eAccessNone)
6367 accessibility = eAccessPublic;
6368
Sean Callanan464a5b52012-10-04 22:06:29 +00006369 clang::ObjCMethodDecl *objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
6370 type_name_cstr,
6371 clang_type,
Greg Clayton1bbcc032013-03-08 02:42:06 +00006372 accessibility,
6373 is_artificial);
Greg Clayton24739922010-10-13 03:15:28 +00006374 type_handled = objc_method_decl != NULL;
Sean Callanan464a5b52012-10-04 22:06:29 +00006375 if (type_handled)
6376 {
6377 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Claytond0029442013-03-27 01:48:02 +00006378 GetClangASTContext().SetMetadataAsUserID (objc_method_decl, MakeUserID(die->GetOffset()));
Sean Callanan464a5b52012-10-04 22:06:29 +00006379 }
Sean Callananc3a1d562013-02-06 23:21:59 +00006380 else
6381 {
Jason Molendac1a65832013-03-07 22:44:42 +00006382 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 +00006383 die->GetOffset(),
6384 tag,
6385 DW_TAG_value_to_name(tag));
6386 }
Greg Clayton24739922010-10-13 03:15:28 +00006387 }
6388 }
Greg Clayton5113dc82011-08-12 06:47:54 +00006389 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00006390 {
6391 // Look at the parent of this DIE and see if is is
6392 // a class or struct and see if this is actually a
6393 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00006394 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00006395 if (class_type)
6396 {
Greg Clayton4116e932012-05-15 02:33:01 +00006397 if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset()))
6398 {
6399 // We uniqued the parent class of this function to another class
6400 // so we now need to associate all dies under "decl_ctx_die" to
6401 // DIEs in the DIE for "class_type"...
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006402 SymbolFileDWARF *class_symfile = NULL;
Greg Clayton4116e932012-05-15 02:33:01 +00006403 DWARFCompileUnitSP class_type_cu_sp;
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006404 const DWARFDebugInfoEntry *class_type_die = NULL;
Sean Callanan2367f8a2013-02-26 01:12:25 +00006405
6406 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
6407 if (debug_map_symfile)
6408 {
6409 class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID()));
6410 class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6411 }
6412 else
6413 {
6414 class_symfile = this;
6415 class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6416 }
Greg Clayton4116e932012-05-15 02:33:01 +00006417 if (class_type_die)
6418 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006419 llvm::SmallVector<const DWARFDebugInfoEntry *, 0> failures;
6420
6421 CopyUniqueClassMethodTypes (class_symfile,
6422 class_type,
6423 class_type_cu_sp.get(),
6424 class_type_die,
6425 dwarf_cu,
6426 decl_ctx_die,
6427 failures);
6428
6429 // FIXME do something with these failures that's smarter than
6430 // just dropping them on the ground. Unfortunately classes don't
6431 // like having stuff added to them after their definitions are
6432 // complete...
6433
6434 type_ptr = m_die_to_type[die];
6435 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton4116e932012-05-15 02:33:01 +00006436 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006437 type_sp = type_ptr->shared_from_this();
6438 break;
Greg Clayton4116e932012-05-15 02:33:01 +00006439 }
6440 }
6441 }
6442
Greg Clayton72da3972011-08-16 18:40:23 +00006443 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00006444 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006445 // We have a specification which we are going to base our function
6446 // prototype off of, so we need this type to be completed so that the
6447 // m_die_to_decl_ctx for the method in the specification has a valid
6448 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006449 class_type->GetClangForwardType();
Greg Clayton72da3972011-08-16 18:40:23 +00006450 // If we have a specification, then the function type should have been
6451 // made with the specification and not with this die.
6452 DWARFCompileUnitSP spec_cu_sp;
6453 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006454 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006455 if (spec_clang_decl_ctx)
6456 {
6457 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
6458 }
6459 else
Jim Inghamc1663042011-09-29 22:12:35 +00006460 {
Daniel Malead01b2952012-11-29 21:49:15 +00006461 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8x) has no decl\n",
Greg Claytone38a5ed2012-01-05 03:57:59 +00006462 MakeUserID(die->GetOffset()),
6463 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006464 }
Greg Clayton72da3972011-08-16 18:40:23 +00006465 type_handled = true;
6466 }
6467 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
6468 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006469 // We have a specification which we are going to base our function
6470 // prototype off of, so we need this type to be completed so that the
6471 // m_die_to_decl_ctx for the method in the abstract origin has a valid
6472 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006473 class_type->GetClangForwardType();
Greg Clayton5cf58b92011-10-05 22:22:08 +00006474
Greg Clayton72da3972011-08-16 18:40:23 +00006475 DWARFCompileUnitSP abs_cu_sp;
6476 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006477 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006478 if (abs_clang_decl_ctx)
6479 {
6480 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
6481 }
6482 else
Jim Inghamc1663042011-09-29 22:12:35 +00006483 {
Daniel Malead01b2952012-11-29 21:49:15 +00006484 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 +00006485 MakeUserID(die->GetOffset()),
6486 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006487 }
Greg Clayton72da3972011-08-16 18:40:23 +00006488 type_handled = true;
6489 }
6490 else
6491 {
6492 clang_type_t class_opaque_type = class_type->GetClangForwardType();
6493 if (ClangASTContext::IsCXXClassType (class_opaque_type))
Greg Clayton931180e2011-01-27 06:44:37 +00006494 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006495 if (ClangASTContext::IsBeingDefined (class_opaque_type))
Greg Clayton72da3972011-08-16 18:40:23 +00006496 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006497 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
6498 // in the DWARF for C++ methods... Default to public for now...
6499 if (accessibility == eAccessNone)
6500 accessibility = eAccessPublic;
6501
6502 if (!is_static && !die->HasChildren())
6503 {
6504 // We have a C++ member function with no children (this pointer!)
6505 // and clang will get mad if we try and make a function that isn't
6506 // well formed in the DWARF, so we will just skip it...
6507 type_handled = true;
6508 }
6509 else
6510 {
6511 clang::CXXMethodDecl *cxx_method_decl;
6512 // REMOVE THE CRASH DESCRIPTION BELOW
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00006513 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 +00006514 type_name_cstr,
6515 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00006516 MakeUserID(die->GetOffset()),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00006517 m_obj_file->GetFileSpec().GetPath().c_str());
Greg Clayton20568dd2011-10-13 23:13:20 +00006518
Sean Callananc1b732d2011-11-01 18:07:13 +00006519 const bool is_attr_used = false;
6520
Greg Clayton20568dd2011-10-13 23:13:20 +00006521 cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type,
6522 type_name_cstr,
6523 clang_type,
6524 accessibility,
6525 is_virtual,
6526 is_static,
6527 is_inline,
Sean Callananc1b732d2011-11-01 18:07:13 +00006528 is_explicit,
Sean Callanandbb58392011-11-02 01:38:59 +00006529 is_attr_used,
6530 is_artificial);
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006531
Greg Clayton20568dd2011-10-13 23:13:20 +00006532 type_handled = cxx_method_decl != NULL;
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006533
6534 if (type_handled)
Jim Ingham379397632012-10-27 02:54:13 +00006535 {
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006536 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
6537
6538 Host::SetCrashDescription (NULL);
6539
6540
6541 ClangASTMetadata metadata;
6542 metadata.SetUserID(MakeUserID(die->GetOffset()));
6543
6544 if (!object_pointer_name.empty())
6545 {
6546 metadata.SetObjectPtrName(object_pointer_name.c_str());
6547 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006548 log->Printf ("Setting object pointer name: %s on method object %p.\n",
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006549 object_pointer_name.c_str(),
Greg Claytond0029442013-03-27 01:48:02 +00006550 cxx_method_decl);
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006551 }
Greg Claytond0029442013-03-27 01:48:02 +00006552 GetClangASTContext().SetMetadata (cxx_method_decl, metadata);
Jim Ingham379397632012-10-27 02:54:13 +00006553 }
Sean Callananb0640dc2013-04-09 23:22:08 +00006554 else
6555 {
Sean Callanande9ce872013-05-09 23:13:13 +00006556 ignore_containing_context = true;
Sean Callananb0640dc2013-04-09 23:22:08 +00006557 }
Greg Clayton20568dd2011-10-13 23:13:20 +00006558 }
Greg Clayton72da3972011-08-16 18:40:23 +00006559 }
6560 else
6561 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006562 // We were asked to parse the type for a method in a class, yet the
6563 // class hasn't been asked to complete itself through the
6564 // clang::ExternalASTSource protocol, so we need to just have the
6565 // class complete itself and do things the right way, then our
6566 // DIE should then have an entry in the m_die_to_type map. First
6567 // we need to modify the m_die_to_type so it doesn't think we are
6568 // trying to parse this DIE anymore...
6569 m_die_to_type[die] = NULL;
6570
6571 // Now we get the full type to force our class type to complete itself
6572 // using the clang::ExternalASTSource protocol which will parse all
6573 // base classes and all methods (including the method for this DIE).
6574 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00006575
Greg Clayton20568dd2011-10-13 23:13:20 +00006576 // The type for this DIE should have been filled in the function call above
6577 type_ptr = m_die_to_type[die];
Greg Claytone5476db2012-06-01 20:32:35 +00006578 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton20568dd2011-10-13 23:13:20 +00006579 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006580 type_sp = type_ptr->shared_from_this();
Greg Clayton20568dd2011-10-13 23:13:20 +00006581 break;
6582 }
Sean Callanan02eee4d2012-04-12 23:10:00 +00006583
6584 // FIXME This is fixing some even uglier behavior but we really need to
6585 // uniq the methods of each class as well as the class itself.
6586 // <rdar://problem/11240464>
6587 type_handled = true;
Greg Clayton72da3972011-08-16 18:40:23 +00006588 }
Greg Clayton931180e2011-01-27 06:44:37 +00006589 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006590 }
6591 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006592 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006593 }
Greg Clayton24739922010-10-13 03:15:28 +00006594
6595 if (!type_handled)
6596 {
6597 // We just have a function that isn't part of a class
Sean Callanande9ce872013-05-09 23:13:13 +00006598 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (ignore_containing_context ? GetClangASTContext().GetTranslationUnitDecl() : containing_decl_ctx,
Greg Clayton147e1fa2011-10-14 22:47:18 +00006599 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006600 clang_type,
6601 storage,
6602 is_inline);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006603
6604// if (template_param_infos.GetSize() > 0)
6605// {
6606// clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
6607// function_decl,
6608// type_name_cstr,
6609// template_param_infos);
6610//
6611// ast.CreateFunctionTemplateSpecializationInfo (function_decl,
6612// func_template_decl,
6613// template_param_infos);
6614// }
Greg Clayton24739922010-10-13 03:15:28 +00006615 // Add the decl to our DIE to decl context map
6616 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00006617 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00006618 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006619 ast.SetFunctionParameters (function_decl,
6620 &function_param_decls.front(),
6621 function_param_decls.size());
Sean Callanan60217122012-04-13 00:10:03 +00006622
Jim Ingham379397632012-10-27 02:54:13 +00006623 ClangASTMetadata metadata;
6624 metadata.SetUserID(MakeUserID(die->GetOffset()));
6625
6626 if (!object_pointer_name.empty())
6627 {
6628 metadata.SetObjectPtrName(object_pointer_name.c_str());
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006629 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006630 log->Printf ("Setting object pointer name: %s on function object %p.",
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006631 object_pointer_name.c_str(),
Greg Claytond0029442013-03-27 01:48:02 +00006632 function_decl);
Jim Ingham379397632012-10-27 02:54:13 +00006633 }
Greg Claytond0029442013-03-27 01:48:02 +00006634 GetClangASTContext().SetMetadata (function_decl, metadata);
Greg Clayton24739922010-10-13 03:15:28 +00006635 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006636 }
Greg Clayton81c22f62011-10-19 18:09:39 +00006637 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006638 this,
6639 type_name_const_str,
6640 0,
6641 NULL,
6642 LLDB_INVALID_UID,
6643 Type::eEncodingIsUID,
6644 &decl,
6645 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006646 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00006647 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006648 }
6649 break;
6650
6651 case DW_TAG_array_type:
6652 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006653 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006654 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006655
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006656 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006657 int64_t first_index = 0;
6658 uint32_t byte_stride = 0;
6659 uint32_t bit_stride = 0;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006660 bool is_vector = false;
Greg Claytond88d7592010-09-15 08:33:30 +00006661 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006662
6663 if (num_attributes > 0)
6664 {
6665 uint32_t i;
6666 for (i=0; i<num_attributes; ++i)
6667 {
6668 attr = attributes.AttributeAtIndex(i);
6669 DWARFFormValue form_value;
6670 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6671 {
6672 switch (attr)
6673 {
6674 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6675 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6676 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6677 case DW_AT_name:
6678 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006679 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006680 break;
6681
6682 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006683 case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006684 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
6685 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006686 case DW_AT_GNU_vector: is_vector = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006687 case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006688 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006689 case DW_AT_allocated:
6690 case DW_AT_associated:
6691 case DW_AT_data_location:
6692 case DW_AT_description:
6693 case DW_AT_ordering:
6694 case DW_AT_start_scope:
6695 case DW_AT_visibility:
6696 case DW_AT_specification:
6697 case DW_AT_abstract_origin:
6698 case DW_AT_sibling:
6699 break;
6700 }
6701 }
6702 }
6703
Daniel Malead01b2952012-11-29 21:49:15 +00006704 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 +00006705
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006706 Type *element_type = ResolveTypeUID(type_die_offset);
6707
6708 if (element_type)
6709 {
6710 std::vector<uint64_t> element_orders;
6711 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
6712 if (byte_stride == 0 && bit_stride == 0)
6713 byte_stride = element_type->GetByteSize();
Greg Clayton42ce2f32011-12-12 21:50:19 +00006714 clang_type_t array_element_type = element_type->GetClangForwardType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006715 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
6716 uint64_t num_elements = 0;
6717 std::vector<uint64_t>::const_reverse_iterator pos;
6718 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
6719 for (pos = element_orders.rbegin(); pos != end; ++pos)
6720 {
6721 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006722 clang_type = ast.CreateArrayType (array_element_type,
Greg Clayton1c8ef472013-04-05 23:27:21 +00006723 num_elements,
6724 is_vector);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006725 array_element_type = clang_type;
Greg Clayton4ef877f2012-12-06 02:33:54 +00006726 array_element_bit_stride = num_elements ? array_element_bit_stride * num_elements : array_element_bit_stride;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006727 }
6728 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00006729 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006730 this,
6731 empty_name,
6732 array_element_bit_stride / 8,
6733 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00006734 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006735 Type::eEncodingIsUID,
6736 &decl,
6737 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006738 Type::eResolveStateFull));
6739 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006740 }
6741 }
6742 }
6743 break;
6744
Greg Clayton9b81a312010-06-12 01:20:30 +00006745 case DW_TAG_ptr_to_member_type:
6746 {
6747 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
6748 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
6749
Greg Claytond88d7592010-09-15 08:33:30 +00006750 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00006751
6752 if (num_attributes > 0) {
6753 uint32_t i;
6754 for (i=0; i<num_attributes; ++i)
6755 {
6756 attr = attributes.AttributeAtIndex(i);
6757 DWARFFormValue form_value;
6758 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6759 {
6760 switch (attr)
6761 {
6762 case DW_AT_type:
6763 type_die_offset = form_value.Reference(dwarf_cu); break;
6764 case DW_AT_containing_type:
6765 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
6766 }
6767 }
6768 }
6769
6770 Type *pointee_type = ResolveTypeUID(type_die_offset);
6771 Type *class_type = ResolveTypeUID(containing_type_die_offset);
6772
Greg Clayton526e5af2010-11-13 03:52:47 +00006773 clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
6774 clang_type_t class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00006775
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006776 clang_type = ast.CreateMemberPointerType(pointee_clang_type,
6777 class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00006778
Greg Clayton526e5af2010-11-13 03:52:47 +00006779 byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(),
6780 clang_type) / 8;
Greg Clayton9b81a312010-06-12 01:20:30 +00006781
Greg Clayton81c22f62011-10-19 18:09:39 +00006782 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006783 this,
6784 type_name_const_str,
6785 byte_size,
6786 NULL,
6787 LLDB_INVALID_UID,
6788 Type::eEncodingIsUID,
6789 NULL,
6790 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006791 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00006792 }
6793
6794 break;
6795 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006796 default:
Greg Clayton84afacd2012-11-07 23:09:32 +00006797 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",
6798 die->GetOffset(),
6799 tag,
6800 DW_TAG_value_to_name(tag));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006801 break;
6802 }
6803
6804 if (type_sp.get())
6805 {
6806 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
6807 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
6808
6809 SymbolContextScope * symbol_context_scope = NULL;
6810 if (sc_parent_tag == DW_TAG_compile_unit)
6811 {
6812 symbol_context_scope = sc.comp_unit;
6813 }
6814 else if (sc.function != NULL)
6815 {
Greg Clayton81c22f62011-10-19 18:09:39 +00006816 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006817 if (symbol_context_scope == NULL)
6818 symbol_context_scope = sc.function;
6819 }
6820
6821 if (symbol_context_scope != NULL)
6822 {
6823 type_sp->SetSymbolContextScope(symbol_context_scope);
6824 }
6825
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006826 // We are ready to put this type into the uniqued list up at the module level
6827 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00006828
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006829 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006830 }
6831 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00006832 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006833 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006834 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006835 }
6836 }
6837 return type_sp;
6838}
6839
6840size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00006841SymbolFileDWARF::ParseTypes
6842(
6843 const SymbolContext& sc,
6844 DWARFCompileUnit* dwarf_cu,
6845 const DWARFDebugInfoEntry *die,
6846 bool parse_siblings,
6847 bool parse_children
6848)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006849{
6850 size_t types_added = 0;
6851 while (die != NULL)
6852 {
6853 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00006854 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006855 {
6856 if (type_is_new)
6857 ++types_added;
6858 }
6859
6860 if (parse_children && die->HasChildren())
6861 {
6862 if (die->Tag() == DW_TAG_subprogram)
6863 {
6864 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00006865 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006866 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
6867 }
6868 else
6869 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
6870 }
6871
6872 if (parse_siblings)
6873 die = die->GetSibling();
6874 else
6875 die = NULL;
6876 }
6877 return types_added;
6878}
6879
6880
6881size_t
6882SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
6883{
6884 assert(sc.comp_unit && sc.function);
6885 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00006886 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006887 if (dwarf_cu)
6888 {
6889 dw_offset_t function_die_offset = sc.function->GetID();
6890 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
6891 if (function_die)
6892 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00006893 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006894 }
6895 }
6896
6897 return functions_added;
6898}
6899
6900
6901size_t
6902SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
6903{
6904 // At least a compile unit must be valid
6905 assert(sc.comp_unit);
6906 size_t types_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00006907 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006908 if (dwarf_cu)
6909 {
6910 if (sc.function)
6911 {
6912 dw_offset_t function_die_offset = sc.function->GetID();
6913 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
6914 if (func_die && func_die->HasChildren())
6915 {
6916 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
6917 }
6918 }
6919 else
6920 {
6921 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
6922 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
6923 {
6924 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
6925 }
6926 }
6927 }
6928
6929 return types_added;
6930}
6931
6932size_t
6933SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
6934{
6935 if (sc.comp_unit != NULL)
6936 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00006937 DWARFDebugInfo* info = DebugInfo();
6938 if (info == NULL)
6939 return 0;
6940
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006941 if (sc.function)
6942 {
Greg Clayton9422dd62013-03-04 21:46:16 +00006943 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get();
6944
6945 if (dwarf_cu == NULL)
6946 return 0;
6947
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006948 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00006949
Greg Claytonc7bece562013-01-25 18:06:21 +00006950 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
6951 if (func_lo_pc != LLDB_INVALID_ADDRESS)
Greg Claytone38a5ed2012-01-05 03:57:59 +00006952 {
6953 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00006954
Greg Claytone38a5ed2012-01-05 03:57:59 +00006955 // Let all blocks know they have parse all their variables
6956 sc.function->GetBlock (false).SetDidParseVariables (true, true);
6957 return num_variables;
6958 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006959 }
6960 else if (sc.comp_unit)
6961 {
Greg Clayton9422dd62013-03-04 21:46:16 +00006962 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get();
6963
6964 if (dwarf_cu == NULL)
6965 return 0;
6966
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006967 uint32_t vars_added = 0;
6968 VariableListSP variables (sc.comp_unit->GetVariableList(false));
6969
6970 if (variables.get() == NULL)
6971 {
6972 variables.reset(new VariableList());
6973 sc.comp_unit->SetVariableList(variables);
6974
Greg Claytond4a2b372011-09-12 23:21:58 +00006975 DWARFCompileUnit* match_dwarf_cu = NULL;
6976 const DWARFDebugInfoEntry* die = NULL;
6977 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00006978 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00006979 {
Greg Clayton97fbc342011-10-20 22:30:33 +00006980 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00006981 {
6982 DWARFMappedHash::DIEInfoArray hash_data_array;
6983 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
6984 dwarf_cu->GetNextCompileUnitOffset(),
6985 hash_data_array))
6986 {
6987 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
6988 }
6989 }
Greg Clayton7f995132011-10-04 22:41:51 +00006990 }
6991 else
6992 {
6993 // Index if we already haven't to make sure the compile units
6994 // get indexed and make their global DIE index list
6995 if (!m_indexed)
6996 Index ();
6997
6998 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
6999 dwarf_cu->GetNextCompileUnitOffset(),
7000 die_offsets);
7001 }
7002
7003 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00007004 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007005 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007006 DWARFDebugInfo* debug_info = DebugInfo();
7007 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007008 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007009 const dw_offset_t die_offset = die_offsets[i];
7010 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00007011 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00007012 {
Greg Clayton95d87902011-11-11 03:16:25 +00007013 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
7014 if (var_sp)
7015 {
7016 variables->AddVariableIfUnique (var_sp);
7017 ++vars_added;
7018 }
Greg Claytond4a2b372011-09-12 23:21:58 +00007019 }
Greg Clayton95d87902011-11-11 03:16:25 +00007020 else
7021 {
7022 if (m_using_apple_tables)
7023 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00007024 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 +00007025 }
7026 }
7027
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007028 }
7029 }
7030 }
7031 return vars_added;
7032 }
7033 }
7034 return 0;
7035}
7036
7037
7038VariableSP
7039SymbolFileDWARF::ParseVariableDIE
7040(
7041 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007042 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007043 const DWARFDebugInfoEntry *die,
7044 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007045)
7046{
7047
Greg Clayton83c5cd92010-11-14 22:13:40 +00007048 VariableSP var_sp (m_die_to_variable_sp[die]);
7049 if (var_sp)
7050 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007051
7052 const dw_tag_t tag = die->Tag();
Greg Clayton7f995132011-10-04 22:41:51 +00007053
7054 if ((tag == DW_TAG_variable) ||
7055 (tag == DW_TAG_constant) ||
7056 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007057 {
Greg Clayton7f995132011-10-04 22:41:51 +00007058 DWARFDebugInfoEntry::Attributes attributes;
7059 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
7060 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007061 {
Greg Clayton7f995132011-10-04 22:41:51 +00007062 const char *name = NULL;
7063 const char *mangled = NULL;
7064 Declaration decl;
7065 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00007066 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00007067 DWARFExpression location;
7068 bool is_external = false;
7069 bool is_artificial = false;
7070 bool location_is_const_value_data = false;
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007071 bool has_explicit_location = false;
Greg Clayton23f59502012-07-17 03:23:13 +00007072 //AccessType accessibility = eAccessNone;
Greg Clayton7f995132011-10-04 22:41:51 +00007073
7074 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007075 {
Greg Clayton7f995132011-10-04 22:41:51 +00007076 dw_attr_t attr = attributes.AttributeAtIndex(i);
7077 DWARFFormValue form_value;
7078 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007079 {
Greg Clayton7f995132011-10-04 22:41:51 +00007080 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007081 {
Greg Clayton7f995132011-10-04 22:41:51 +00007082 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
7083 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
7084 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
7085 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton71415542012-12-08 00:24:40 +00007086 case DW_AT_linkage_name:
Greg Clayton7f995132011-10-04 22:41:51 +00007087 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Claytond1767f02011-12-08 02:13:16 +00007088 case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00007089 case DW_AT_external: is_external = form_value.Boolean(); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007090 case DW_AT_const_value:
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007091 // If we have already found a DW_AT_location attribute, ignore this attribute.
7092 if (!has_explicit_location)
7093 {
7094 location_is_const_value_data = true;
7095 // The constant value will be either a block, a data value or a string.
7096 const DataExtractor& debug_info_data = get_debug_info_data();
7097 if (DWARFFormValue::IsBlockForm(form_value.Form()))
7098 {
7099 // Retrieve the value as a block expression.
7100 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7101 uint32_t block_length = form_value.Unsigned();
7102 location.CopyOpcodeData(debug_info_data, block_offset, block_length);
7103 }
7104 else if (DWARFFormValue::IsDataForm(form_value.Form()))
7105 {
7106 // Retrieve the value as a data expression.
7107 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
7108 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7109 uint32_t data_length = fixed_form_sizes[form_value.Form()];
7110 location.CopyOpcodeData(debug_info_data, data_offset, data_length);
7111 }
7112 else
7113 {
7114 // Retrieve the value as a string expression.
7115 if (form_value.Form() == DW_FORM_strp)
7116 {
7117 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
7118 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7119 uint32_t data_length = fixed_form_sizes[form_value.Form()];
7120 location.CopyOpcodeData(debug_info_data, data_offset, data_length);
7121 }
7122 else
7123 {
7124 const char *str = form_value.AsCString(&debug_info_data);
7125 uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart();
7126 uint32_t string_length = strlen(str) + 1;
7127 location.CopyOpcodeData(debug_info_data, string_offset, string_length);
7128 }
7129 }
7130 }
7131 break;
Greg Clayton7f995132011-10-04 22:41:51 +00007132 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007133 {
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007134 location_is_const_value_data = false;
7135 has_explicit_location = true;
Greg Clayton7f995132011-10-04 22:41:51 +00007136 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007137 {
Greg Clayton7f995132011-10-04 22:41:51 +00007138 const DataExtractor& debug_info_data = get_debug_info_data();
7139
7140 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7141 uint32_t block_length = form_value.Unsigned();
Greg Clayton7f4c7432012-08-11 00:49:14 +00007142 location.CopyOpcodeData(get_debug_info_data(), block_offset, block_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007143 }
7144 else
7145 {
7146 const DataExtractor& debug_loc_data = get_debug_loc_data();
7147 const dw_offset_t debug_loc_offset = form_value.Unsigned();
7148
7149 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
7150 if (loc_list_length > 0)
7151 {
Greg Clayton7f4c7432012-08-11 00:49:14 +00007152 location.CopyOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007153 assert (func_low_pc != LLDB_INVALID_ADDRESS);
7154 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
7155 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007156 }
7157 }
Greg Clayton7f995132011-10-04 22:41:51 +00007158 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007159
Greg Clayton1c8ef472013-04-05 23:27:21 +00007160 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00007161 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007162 case DW_AT_declaration:
7163 case DW_AT_description:
7164 case DW_AT_endianity:
7165 case DW_AT_segment:
7166 case DW_AT_start_scope:
7167 case DW_AT_visibility:
7168 default:
7169 case DW_AT_abstract_origin:
7170 case DW_AT_sibling:
7171 case DW_AT_specification:
7172 break;
7173 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007174 }
7175 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007176
Greg Clayton7f995132011-10-04 22:41:51 +00007177 if (location.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007178 {
Greg Clayton7f995132011-10-04 22:41:51 +00007179 ValueType scope = eValueTypeInvalid;
7180
7181 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7182 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007183 SymbolContextScope * symbol_context_scope = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00007184
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007185 // DWARF doesn't specify if a DW_TAG_variable is a local, global
7186 // or static variable, so we have to do a little digging by
7187 // looking at the location of a varaible to see if it contains
7188 // a DW_OP_addr opcode _somewhere_ in the definition. I say
7189 // somewhere because clang likes to combine small global variables
7190 // into the same symbol and have locations like:
7191 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
7192 // So if we don't have a DW_TAG_formal_parameter, we can look at
7193 // the location to see if it contains a DW_OP_addr opcode, and
7194 // then we can correctly classify our variables.
Greg Clayton7f995132011-10-04 22:41:51 +00007195 if (tag == DW_TAG_formal_parameter)
7196 scope = eValueTypeVariableArgument;
Greg Claytond1767f02011-12-08 02:13:16 +00007197 else
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007198 {
Greg Clayton96c09682012-01-04 22:56:43 +00007199 bool op_error = false;
Greg Claytond1767f02011-12-08 02:13:16 +00007200 // Check if the location has a DW_OP_addr with any address value...
Greg Clayton9422dd62013-03-04 21:46:16 +00007201 lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS;
Greg Claytond1767f02011-12-08 02:13:16 +00007202 if (!location_is_const_value_data)
Greg Clayton96c09682012-01-04 22:56:43 +00007203 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007204 location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error);
Greg Clayton96c09682012-01-04 22:56:43 +00007205 if (op_error)
7206 {
7207 StreamString strm;
7208 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
Greg Claytone38a5ed2012-01-05 03:57:59 +00007209 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 +00007210 }
7211 }
Greg Claytond1767f02011-12-08 02:13:16 +00007212
Greg Clayton9422dd62013-03-04 21:46:16 +00007213 if (location_DW_OP_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007214 {
Greg Claytond1767f02011-12-08 02:13:16 +00007215 if (is_external)
Greg Claytond1767f02011-12-08 02:13:16 +00007216 scope = eValueTypeVariableGlobal;
Greg Clayton9422dd62013-03-04 21:46:16 +00007217 else
7218 scope = eValueTypeVariableStatic;
7219
7220
7221 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile ();
7222
7223 if (debug_map_symfile)
7224 {
7225 // When leaving the DWARF in the .o files on darwin,
7226 // when we have a global variable that wasn't initialized,
7227 // the .o file might not have allocated a virtual
7228 // address for the global variable. In this case it will
7229 // have created a symbol for the global variable
7230 // that is undefined/data and external and the value will
7231 // be the byte size of the variable. When we do the
7232 // address map in SymbolFileDWARFDebugMap we rely on
7233 // having an address, we need to do some magic here
7234 // so we can get the correct address for our global
7235 // variable. The address for all of these entries
7236 // will be zero, and there will be an undefined symbol
7237 // in this object file, and the executable will have
7238 // a matching symbol with a good address. So here we
7239 // dig up the correct address and replace it in the
7240 // location for the variable, and set the variable's
7241 // symbol context scope to be that of the main executable
7242 // so the file address will resolve correctly.
7243 bool linked_oso_file_addr = false;
7244 if (is_external && location_DW_OP_addr == 0)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007245 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007246
7247 // we have a possible uninitialized extern global
7248 ConstString const_name(mangled ? mangled : name);
7249 ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile();
7250 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007251 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007252 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
7253 if (debug_map_symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007254 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007255 Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
7256 eSymbolTypeData,
7257 Symtab::eDebugYes,
7258 Symtab::eVisibilityExtern);
7259 if (exe_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007260 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007261 if (exe_symbol->ValueIsAddress())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007262 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007263 const addr_t exe_file_addr = exe_symbol->GetAddress().GetFileAddress();
7264 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007265 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007266 if (location.Update_DW_OP_addr (exe_file_addr))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007267 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007268 linked_oso_file_addr = true;
7269 symbol_context_scope = exe_symbol;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007270 }
7271 }
7272 }
7273 }
7274 }
7275 }
7276 }
Greg Clayton9422dd62013-03-04 21:46:16 +00007277
7278 if (!linked_oso_file_addr)
7279 {
7280 // The DW_OP_addr is not zero, but it contains a .o file address which
7281 // needs to be linked up correctly.
7282 const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr);
7283 if (exe_file_addr != LLDB_INVALID_ADDRESS)
7284 {
7285 // Update the file address for this variable
7286 location.Update_DW_OP_addr (exe_file_addr);
7287 }
7288 else
7289 {
7290 // Variable didn't make it into the final executable
7291 return var_sp;
7292 }
7293 }
Greg Claytond1767f02011-12-08 02:13:16 +00007294 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007295 }
7296 else
Greg Claytond1767f02011-12-08 02:13:16 +00007297 {
7298 scope = eValueTypeVariableLocal;
7299 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007300 }
Greg Clayton7f995132011-10-04 22:41:51 +00007301
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007302 if (symbol_context_scope == NULL)
Greg Clayton7f995132011-10-04 22:41:51 +00007303 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007304 switch (parent_tag)
Greg Clayton5cf58b92011-10-05 22:22:08 +00007305 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007306 case DW_TAG_subprogram:
7307 case DW_TAG_inlined_subroutine:
7308 case DW_TAG_lexical_block:
7309 if (sc.function)
7310 {
7311 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
7312 if (symbol_context_scope == NULL)
7313 symbol_context_scope = sc.function;
7314 }
7315 break;
7316
7317 default:
7318 symbol_context_scope = sc.comp_unit;
7319 break;
Greg Clayton5cf58b92011-10-05 22:22:08 +00007320 }
Greg Clayton7f995132011-10-04 22:41:51 +00007321 }
7322
Greg Clayton5cf58b92011-10-05 22:22:08 +00007323 if (symbol_context_scope)
7324 {
Greg Clayton81c22f62011-10-19 18:09:39 +00007325 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
7326 name,
7327 mangled,
Greg Claytond1767f02011-12-08 02:13:16 +00007328 SymbolFileTypeSP (new SymbolFileType(*this, type_uid)),
Greg Clayton81c22f62011-10-19 18:09:39 +00007329 scope,
7330 symbol_context_scope,
7331 &decl,
7332 location,
7333 is_external,
7334 is_artificial));
Greg Clayton5cf58b92011-10-05 22:22:08 +00007335
7336 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
7337 }
7338 else
7339 {
7340 // Not ready to parse this variable yet. It might be a global
7341 // or static variable that is in a function scope and the function
7342 // in the symbol context wasn't filled in yet
7343 return var_sp;
7344 }
Greg Clayton7f995132011-10-04 22:41:51 +00007345 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007346 }
Greg Clayton7f995132011-10-04 22:41:51 +00007347 // Cache var_sp even if NULL (the variable was just a specification or
7348 // was missing vital information to be able to be displayed in the debugger
7349 // (missing location due to optimization, etc)) so we don't re-parse
7350 // this DIE over and over later...
7351 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007352 }
7353 return var_sp;
7354}
7355
Greg Claytonc662ec82011-06-17 22:10:16 +00007356
7357const DWARFDebugInfoEntry *
7358SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
7359 dw_offset_t spec_block_die_offset,
7360 DWARFCompileUnit **result_die_cu_handle)
7361{
7362 // Give the concrete function die specified by "func_die_offset", find the
7363 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7364 // to "spec_block_die_offset"
7365 DWARFDebugInfo* info = DebugInfo();
7366
7367 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
7368 if (die)
7369 {
7370 assert (*result_die_cu_handle);
7371 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
7372 }
7373 return NULL;
7374}
7375
7376
7377const DWARFDebugInfoEntry *
7378SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
7379 const DWARFDebugInfoEntry *die,
7380 dw_offset_t spec_block_die_offset,
7381 DWARFCompileUnit **result_die_cu_handle)
7382{
7383 if (die)
7384 {
7385 switch (die->Tag())
7386 {
7387 case DW_TAG_subprogram:
7388 case DW_TAG_inlined_subroutine:
7389 case DW_TAG_lexical_block:
7390 {
7391 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
7392 {
7393 *result_die_cu_handle = dwarf_cu;
7394 return die;
7395 }
7396
7397 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
7398 {
7399 *result_die_cu_handle = dwarf_cu;
7400 return die;
7401 }
7402 }
7403 break;
7404 }
7405
7406 // Give the concrete function die specified by "func_die_offset", find the
7407 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7408 // to "spec_block_die_offset"
7409 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
7410 {
7411 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
7412 child_die,
7413 spec_block_die_offset,
7414 result_die_cu_handle);
7415 if (result_die)
7416 return result_die;
7417 }
7418 }
7419
7420 *result_die_cu_handle = NULL;
7421 return NULL;
7422}
7423
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007424size_t
7425SymbolFileDWARF::ParseVariables
7426(
7427 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007428 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007429 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007430 const DWARFDebugInfoEntry *orig_die,
7431 bool parse_siblings,
7432 bool parse_children,
7433 VariableList* cc_variable_list
7434)
7435{
7436 if (orig_die == NULL)
7437 return 0;
7438
Greg Claytonc662ec82011-06-17 22:10:16 +00007439 VariableListSP variable_list_sp;
7440
7441 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007442 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00007443 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007444 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007445 dw_tag_t tag = die->Tag();
7446
7447 // Check to see if we have already parsed this variable or constant?
7448 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007449 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007450 if (cc_variable_list)
7451 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007452 }
7453 else
7454 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007455 // We haven't already parsed it, lets do that now.
7456 if ((tag == DW_TAG_variable) ||
7457 (tag == DW_TAG_constant) ||
7458 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007459 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007460 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00007461 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007462 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
7463 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7464 switch (parent_tag)
7465 {
7466 case DW_TAG_compile_unit:
7467 if (sc.comp_unit != NULL)
7468 {
7469 variable_list_sp = sc.comp_unit->GetVariableList(false);
7470 if (variable_list_sp.get() == NULL)
7471 {
7472 variable_list_sp.reset(new VariableList());
7473 sc.comp_unit->SetVariableList(variable_list_sp);
7474 }
7475 }
7476 else
7477 {
Daniel Malead01b2952012-11-29 21:49:15 +00007478 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 +00007479 MakeUserID(sc_parent_die->GetOffset()),
7480 DW_TAG_value_to_name (parent_tag),
7481 MakeUserID(orig_die->GetOffset()),
7482 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007483 }
7484 break;
7485
7486 case DW_TAG_subprogram:
7487 case DW_TAG_inlined_subroutine:
7488 case DW_TAG_lexical_block:
7489 if (sc.function != NULL)
7490 {
7491 // Check to see if we already have parsed the variables for the given scope
7492
Greg Clayton81c22f62011-10-19 18:09:39 +00007493 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007494 if (block == NULL)
7495 {
7496 // This must be a specification or abstract origin with
7497 // a concrete block couterpart in the current function. We need
7498 // to find the concrete block so we can correctly add the
7499 // variable to it
7500 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
7501 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
7502 sc_parent_die->GetOffset(),
7503 &concrete_block_die_cu);
7504 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00007505 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007506 }
7507
7508 if (block != NULL)
7509 {
7510 const bool can_create = false;
7511 variable_list_sp = block->GetBlockVariableList (can_create);
7512 if (variable_list_sp.get() == NULL)
7513 {
7514 variable_list_sp.reset(new VariableList());
7515 block->SetVariableList(variable_list_sp);
7516 }
7517 }
7518 }
7519 break;
7520
7521 default:
Daniel Malead01b2952012-11-29 21:49:15 +00007522 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 +00007523 MakeUserID(orig_die->GetOffset()),
7524 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007525 break;
7526 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00007527 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007528
7529 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007530 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00007531 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
7532 if (var_sp)
7533 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007534 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00007535 if (cc_variable_list)
7536 cc_variable_list->AddVariableIfUnique (var_sp);
7537 ++vars_added;
7538 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007539 }
7540 }
7541 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007542
7543 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
7544
7545 if (!skip_children && parse_children && die->HasChildren())
7546 {
7547 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
7548 }
7549
7550 if (parse_siblings)
7551 die = die->GetSibling();
7552 else
7553 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007554 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007555 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007556}
7557
7558//------------------------------------------------------------------
7559// PluginInterface protocol
7560//------------------------------------------------------------------
Greg Clayton57abc5d2013-05-10 21:47:16 +00007561ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007562SymbolFileDWARF::GetPluginName()
7563{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007564 return GetPluginNameStatic();
7565}
7566
7567uint32_t
7568SymbolFileDWARF::GetPluginVersion()
7569{
7570 return 1;
7571}
7572
7573void
Greg Clayton6beaaa62011-01-17 03:46:26 +00007574SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
7575{
7576 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7577 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
7578 if (clang_type)
7579 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7580}
7581
7582void
7583SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
7584{
7585 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7586 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
7587 if (clang_type)
7588 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7589}
7590
Greg Claytona2721472011-06-25 00:44:06 +00007591void
Sean Callanancc427fa2011-07-30 02:42:06 +00007592SymbolFileDWARF::DumpIndexes ()
7593{
7594 StreamFile s(stdout, false);
7595
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00007596 s.Printf ("DWARF index for (%s) '%s':",
Sean Callanancc427fa2011-07-30 02:42:06 +00007597 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00007598 GetObjectFile()->GetFileSpec().GetPath().c_str());
Sean Callanancc427fa2011-07-30 02:42:06 +00007599 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
7600 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
7601 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
7602 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
7603 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
7604 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
7605 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
7606 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
7607}
7608
7609void
7610SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
7611 const char *name,
7612 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00007613{
Sean Callanancc427fa2011-07-30 02:42:06 +00007614 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00007615
7616 if (iter == m_decl_ctx_to_die.end())
7617 return;
7618
Greg Claytoncb5860a2011-10-13 23:49:28 +00007619 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00007620 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007621 const DWARFDebugInfoEntry *context_die = *pos;
7622
7623 if (!results)
7624 return;
7625
7626 DWARFDebugInfo* info = DebugInfo();
7627
7628 DIEArray die_offsets;
7629
7630 DWARFCompileUnit* dwarf_cu = NULL;
7631 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton220a0072011-12-09 08:48:30 +00007632
7633 if (m_using_apple_tables)
7634 {
7635 if (m_apple_types_ap.get())
7636 m_apple_types_ap->FindByName (name, die_offsets);
7637 }
7638 else
7639 {
7640 if (!m_indexed)
7641 Index ();
7642
7643 m_type_index.Find (ConstString(name), die_offsets);
7644 }
7645
Greg Clayton220a0072011-12-09 08:48:30 +00007646 const size_t num_matches = die_offsets.size();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007647
7648 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00007649 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007650 for (size_t i = 0; i < num_matches; ++i)
7651 {
7652 const dw_offset_t die_offset = die_offsets[i];
7653 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00007654
Greg Claytoncb5860a2011-10-13 23:49:28 +00007655 if (die->GetParent() != context_die)
7656 continue;
7657
7658 Type *matching_type = ResolveType (dwarf_cu, die);
7659
Greg Clayton42ce2f32011-12-12 21:50:19 +00007660 lldb::clang_type_t type = matching_type->GetClangForwardType();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007661 clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type);
7662
7663 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
7664 {
7665 clang::TagDecl *tag_decl = tag_type->getDecl();
7666 results->push_back(tag_decl);
7667 }
7668 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
7669 {
7670 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
7671 results->push_back(typedef_decl);
7672 }
Greg Claytona2721472011-06-25 00:44:06 +00007673 }
7674 }
7675 }
7676}
7677
7678void
7679SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00007680 const clang::DeclContext *decl_context,
7681 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00007682 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
7683{
Greg Clayton85ae2e12011-10-18 23:36:41 +00007684
7685 switch (decl_context->getDeclKind())
7686 {
7687 case clang::Decl::Namespace:
7688 case clang::Decl::TranslationUnit:
7689 {
7690 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7691 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
7692 }
7693 break;
7694 default:
7695 break;
7696 }
Greg Claytona2721472011-06-25 00:44:06 +00007697}
Greg Claytoncaab74e2012-01-28 00:48:57 +00007698
7699bool
7700SymbolFileDWARF::LayoutRecordType (void *baton,
7701 const clang::RecordDecl *record_decl,
7702 uint64_t &size,
7703 uint64_t &alignment,
7704 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7705 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7706 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7707{
7708 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7709 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
7710}
7711
7712
7713bool
7714SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl,
7715 uint64_t &bit_size,
7716 uint64_t &alignment,
7717 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7718 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7719 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7720{
Greg Clayton5160ce52013-03-27 23:08:40 +00007721 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Claytoncaab74e2012-01-28 00:48:57 +00007722 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
7723 bool success = false;
7724 base_offsets.clear();
7725 vbase_offsets.clear();
7726 if (pos != m_record_decl_to_layout_map.end())
7727 {
7728 bit_size = pos->second.bit_size;
7729 alignment = pos->second.alignment;
7730 field_offsets.swap(pos->second.field_offsets);
Greg Clayton2508b9b2012-11-01 23:20:02 +00007731 base_offsets.swap (pos->second.base_offsets);
7732 vbase_offsets.swap (pos->second.vbase_offsets);
Greg Claytoncaab74e2012-01-28 00:48:57 +00007733 m_record_decl_to_layout_map.erase(pos);
7734 success = true;
7735 }
7736 else
7737 {
7738 bit_size = 0;
7739 alignment = 0;
7740 field_offsets.clear();
7741 }
7742
7743 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00007744 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00007745 "SymbolFileDWARF::LayoutRecordType (record_decl = %p, bit_size = %" PRIu64 ", alignment = %" PRIu64 ", field_offsets[%u],base_offsets[%u], vbase_offsets[%u]) success = %i",
Greg Claytoncaab74e2012-01-28 00:48:57 +00007746 record_decl,
7747 bit_size,
7748 alignment,
7749 (uint32_t)field_offsets.size(),
7750 (uint32_t)base_offsets.size(),
7751 (uint32_t)vbase_offsets.size(),
7752 success);
7753 return success;
7754}
7755
7756
Greg Clayton1f746072012-08-29 21:13:06 +00007757SymbolFileDWARFDebugMap *
7758SymbolFileDWARF::GetDebugMapSymfile ()
7759{
7760 if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired())
7761 {
7762 lldb::ModuleSP module_sp (m_debug_map_module_wp.lock());
7763 if (module_sp)
7764 {
7765 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
7766 if (sym_vendor)
7767 m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile();
7768 }
7769 }
7770 return m_debug_map_symfile;
7771}
7772
Greg Claytoncaab74e2012-01-28 00:48:57 +00007773