blob: dd34a364c7306a9a587d547dcb960fc59cbbb936 [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
210const char *
211SymbolFileDWARF::GetPluginNameStatic()
212{
Greg Claytond4a2b372011-09-12 23:21:58 +0000213 return "dwarf";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000214}
215
216const char *
217SymbolFileDWARF::GetPluginDescriptionStatic()
218{
219 return "DWARF and DWARF3 debug symbol file reader.";
220}
221
222
223SymbolFile*
224SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
225{
226 return new SymbolFileDWARF(obj_file);
227}
228
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000229TypeList *
230SymbolFileDWARF::GetTypeList ()
231{
Greg Clayton1f746072012-08-29 21:13:06 +0000232 if (GetDebugMapSymfile ())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000233 return m_debug_map_symfile->GetTypeList();
234 return m_obj_file->GetModule()->GetTypeList();
235
236}
237
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000238//----------------------------------------------------------------------
239// Gets the first parent that is a lexical block, function or inlined
240// subroutine, or compile unit.
241//----------------------------------------------------------------------
242static const DWARFDebugInfoEntry *
243GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
244{
245 const DWARFDebugInfoEntry *die;
246 for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
247 {
248 dw_tag_t tag = die->Tag();
249
250 switch (tag)
251 {
252 case DW_TAG_compile_unit:
253 case DW_TAG_subprogram:
254 case DW_TAG_inlined_subroutine:
255 case DW_TAG_lexical_block:
256 return die;
257 }
258 }
259 return NULL;
260}
261
262
Greg Clayton450e3f32010-10-12 02:24:53 +0000263SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
264 SymbolFile (objfile),
Greg Clayton81c22f62011-10-19 18:09:39 +0000265 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 +0000266 m_debug_map_module_wp (),
Greg Clayton450e3f32010-10-12 02:24:53 +0000267 m_debug_map_symfile (NULL),
Greg Clayton7a345282010-11-09 23:46:37 +0000268 m_clang_tu_decl (NULL),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000269 m_flags(),
Greg Claytond4a2b372011-09-12 23:21:58 +0000270 m_data_debug_abbrev (),
271 m_data_debug_aranges (),
272 m_data_debug_frame (),
273 m_data_debug_info (),
274 m_data_debug_line (),
275 m_data_debug_loc (),
276 m_data_debug_ranges (),
277 m_data_debug_str (),
Greg Clayton17674402011-09-28 17:06:40 +0000278 m_data_apple_names (),
279 m_data_apple_types (),
Greg Clayton7f995132011-10-04 22:41:51 +0000280 m_data_apple_namespaces (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000281 m_abbr(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000282 m_info(),
283 m_line(),
Greg Clayton7f995132011-10-04 22:41:51 +0000284 m_apple_names_ap (),
285 m_apple_types_ap (),
286 m_apple_namespaces_ap (),
Greg Clayton5009f9d2011-10-27 17:55:14 +0000287 m_apple_objc_ap (),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000288 m_function_basename_index(),
289 m_function_fullname_index(),
290 m_function_method_index(),
291 m_function_selector_index(),
Greg Clayton450e3f32010-10-12 02:24:53 +0000292 m_objc_class_selectors_index(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000293 m_global_index(),
Greg Clayton69b04882010-10-15 02:03:22 +0000294 m_type_index(),
295 m_namespace_index(),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000296 m_indexed (false),
297 m_is_external_ast_source (false),
Greg Clayton97fbc342011-10-20 22:30:33 +0000298 m_using_apple_tables (false),
Greg Claytonc7f03b62012-01-12 04:33:28 +0000299 m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +0000300 m_ranges(),
301 m_unique_ast_type_map ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000302{
303}
304
305SymbolFileDWARF::~SymbolFileDWARF()
306{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000307 if (m_is_external_ast_source)
Greg Claytone72dfb32012-02-24 01:59:29 +0000308 {
309 ModuleSP module_sp (m_obj_file->GetModule());
310 if (module_sp)
311 module_sp->GetClangASTContext().RemoveExternalSource ();
312 }
Greg Clayton6beaaa62011-01-17 03:46:26 +0000313}
314
315static const ConstString &
316GetDWARFMachOSegmentName ()
317{
318 static ConstString g_dwarf_section_name ("__DWARF");
319 return g_dwarf_section_name;
320}
321
Greg Claytone576ab22011-02-15 00:19:15 +0000322UniqueDWARFASTTypeMap &
323SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
324{
Greg Clayton1f746072012-08-29 21:13:06 +0000325 if (GetDebugMapSymfile ())
Greg Claytone576ab22011-02-15 00:19:15 +0000326 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
327 return m_unique_ast_type_map;
328}
329
Greg Clayton6beaaa62011-01-17 03:46:26 +0000330ClangASTContext &
331SymbolFileDWARF::GetClangASTContext ()
332{
Greg Clayton1f746072012-08-29 21:13:06 +0000333 if (GetDebugMapSymfile ())
Greg Clayton6beaaa62011-01-17 03:46:26 +0000334 return m_debug_map_symfile->GetClangASTContext ();
335
336 ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext();
337 if (!m_is_external_ast_source)
338 {
339 m_is_external_ast_source = true;
340 llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap (
341 new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl,
342 SymbolFileDWARF::CompleteObjCInterfaceDecl,
Greg Claytona2721472011-06-25 00:44:06 +0000343 SymbolFileDWARF::FindExternalVisibleDeclsByName,
Greg Claytoncaab74e2012-01-28 00:48:57 +0000344 SymbolFileDWARF::LayoutRecordType,
Greg Clayton6beaaa62011-01-17 03:46:26 +0000345 this));
Greg Clayton6beaaa62011-01-17 03:46:26 +0000346 ast.SetExternalSource (ast_source_ap);
347 }
348 return ast;
349}
350
351void
352SymbolFileDWARF::InitializeObject()
353{
354 // Install our external AST source callbacks so we can complete Clang types.
Greg Claytone72dfb32012-02-24 01:59:29 +0000355 ModuleSP module_sp (m_obj_file->GetModule());
356 if (module_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +0000357 {
358 const SectionList *section_list = m_obj_file->GetSectionList();
359
360 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
361
362 // Memory map the DWARF mach-o segment so we have everything mmap'ed
363 // to keep our heap memory usage down.
364 if (section)
Greg Claytonc9660542012-02-05 02:38:54 +0000365 m_obj_file->MemoryMapSectionData(section, m_dwarf_data);
Greg Clayton6beaaa62011-01-17 03:46:26 +0000366 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000367 get_apple_names_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000368 if (m_data_apple_names.GetByteSize() > 0)
369 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000370 m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names"));
371 if (m_apple_names_ap->IsValid())
372 m_using_apple_tables = true;
373 else
Greg Clayton7f995132011-10-04 22:41:51 +0000374 m_apple_names_ap.reset();
375 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000376 get_apple_types_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000377 if (m_data_apple_types.GetByteSize() > 0)
378 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000379 m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types"));
380 if (m_apple_types_ap->IsValid())
381 m_using_apple_tables = true;
382 else
Greg Clayton7f995132011-10-04 22:41:51 +0000383 m_apple_types_ap.reset();
384 }
385
386 get_apple_namespaces_data();
387 if (m_data_apple_namespaces.GetByteSize() > 0)
388 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000389 m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces"));
390 if (m_apple_namespaces_ap->IsValid())
391 m_using_apple_tables = true;
392 else
Greg Clayton7f995132011-10-04 22:41:51 +0000393 m_apple_namespaces_ap.reset();
394 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000395
Greg Clayton5009f9d2011-10-27 17:55:14 +0000396 get_apple_objc_data();
397 if (m_data_apple_objc.GetByteSize() > 0)
398 {
399 m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc"));
400 if (m_apple_objc_ap->IsValid())
401 m_using_apple_tables = true;
402 else
403 m_apple_objc_ap.reset();
404 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000405}
406
407bool
408SymbolFileDWARF::SupportedVersion(uint16_t version)
409{
Greg Claytonabcbfe52013-04-04 00:00:36 +0000410 return version == 2 || version == 3 || version == 4;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000411}
412
413uint32_t
Sean Callananbfaf54d2011-12-03 04:38:43 +0000414SymbolFileDWARF::CalculateAbilities ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000415{
416 uint32_t abilities = 0;
417 if (m_obj_file != NULL)
418 {
419 const Section* section = NULL;
420 const SectionList *section_list = m_obj_file->GetSectionList();
421 if (section_list == NULL)
422 return 0;
423
424 uint64_t debug_abbrev_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000425 uint64_t debug_info_file_size = 0;
426 uint64_t debug_line_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000427
Greg Clayton6beaaa62011-01-17 03:46:26 +0000428 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000429
430 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000431 section_list = &section->GetChildren ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000432
Greg Clayton4ceb9982010-07-21 22:54:26 +0000433 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000434 if (section != NULL)
435 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000436 debug_info_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000437
Greg Clayton4ceb9982010-07-21 22:54:26 +0000438 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000439 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000440 debug_abbrev_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000441 else
442 m_flags.Set (flagsGotDebugAbbrevData);
443
Greg Clayton4ceb9982010-07-21 22:54:26 +0000444 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000445 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000446 m_flags.Set (flagsGotDebugArangesData);
447
Greg Clayton4ceb9982010-07-21 22:54:26 +0000448 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000449 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000450 m_flags.Set (flagsGotDebugFrameData);
451
Greg Clayton4ceb9982010-07-21 22:54:26 +0000452 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000453 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000454 debug_line_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000455 else
456 m_flags.Set (flagsGotDebugLineData);
457
Greg Clayton4ceb9982010-07-21 22:54:26 +0000458 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000459 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000460 m_flags.Set (flagsGotDebugLocData);
461
Greg Clayton4ceb9982010-07-21 22:54:26 +0000462 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000463 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000464 m_flags.Set (flagsGotDebugMacInfoData);
465
Greg Clayton4ceb9982010-07-21 22:54:26 +0000466 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000467 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000468 m_flags.Set (flagsGotDebugPubNamesData);
469
Greg Clayton4ceb9982010-07-21 22:54:26 +0000470 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000471 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000472 m_flags.Set (flagsGotDebugPubTypesData);
473
Greg Clayton4ceb9982010-07-21 22:54:26 +0000474 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000475 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000476 m_flags.Set (flagsGotDebugRangesData);
477
Greg Clayton4ceb9982010-07-21 22:54:26 +0000478 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000479 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000480 m_flags.Set (flagsGotDebugStrData);
481 }
Greg Clayton6c596612012-05-18 21:47:20 +0000482 else
483 {
484 const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString();
485 if (symfile_dir_cstr)
486 {
487 if (strcasestr(symfile_dir_cstr, ".dsym"))
488 {
489 if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo)
490 {
491 // We have a dSYM file that didn't have a any debug info.
492 // If the string table has a size of 1, then it was made from
493 // an executable with no debug info, or from an executable that
494 // was stripped.
495 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
496 if (section && section->GetFileSize() == 1)
497 {
498 m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info.");
499 }
500 }
501 }
502 }
503 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000504
505 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
506 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
507
508 if (debug_line_file_size > 0)
509 abilities |= LineTables;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000510 }
511 return abilities;
512}
513
514const DataExtractor&
Greg Clayton4ceb9982010-07-21 22:54:26 +0000515SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000516{
517 if (m_flags.IsClear (got_flag))
518 {
519 m_flags.Set (got_flag);
520 const SectionList *section_list = m_obj_file->GetSectionList();
521 if (section_list)
522 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000523 SectionSP section_sp (section_list->FindSectionByType(sect_type, true));
524 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000525 {
526 // See if we memory mapped the DWARF segment?
527 if (m_dwarf_data.GetByteSize())
528 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000529 data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000530 }
531 else
532 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000533 if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000534 data.Clear();
535 }
536 }
537 }
538 }
539 return data;
540}
541
542const DataExtractor&
543SymbolFileDWARF::get_debug_abbrev_data()
544{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000545 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000546}
547
548const DataExtractor&
Greg Claytond4a2b372011-09-12 23:21:58 +0000549SymbolFileDWARF::get_debug_aranges_data()
550{
551 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
552}
553
554const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000555SymbolFileDWARF::get_debug_frame_data()
556{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000557 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000558}
559
560const DataExtractor&
561SymbolFileDWARF::get_debug_info_data()
562{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000563 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000564}
565
566const DataExtractor&
567SymbolFileDWARF::get_debug_line_data()
568{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000569 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000570}
571
572const DataExtractor&
573SymbolFileDWARF::get_debug_loc_data()
574{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000575 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000576}
577
578const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000579SymbolFileDWARF::get_debug_ranges_data()
580{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000581 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000582}
583
584const DataExtractor&
585SymbolFileDWARF::get_debug_str_data()
586{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000587 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000588}
589
Greg Claytonf9eec202011-09-01 23:16:13 +0000590const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000591SymbolFileDWARF::get_apple_names_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000592{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000593 return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names);
Greg Claytonf9eec202011-09-01 23:16:13 +0000594}
595
596const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000597SymbolFileDWARF::get_apple_types_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000598{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000599 return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types);
Greg Claytonf9eec202011-09-01 23:16:13 +0000600}
601
Greg Clayton7f995132011-10-04 22:41:51 +0000602const DataExtractor&
603SymbolFileDWARF::get_apple_namespaces_data()
604{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000605 return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
606}
607
608const DataExtractor&
609SymbolFileDWARF::get_apple_objc_data()
610{
611 return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc);
Greg Clayton7f995132011-10-04 22:41:51 +0000612}
613
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000614
615DWARFDebugAbbrev*
616SymbolFileDWARF::DebugAbbrev()
617{
618 if (m_abbr.get() == NULL)
619 {
620 const DataExtractor &debug_abbrev_data = get_debug_abbrev_data();
621 if (debug_abbrev_data.GetByteSize() > 0)
622 {
623 m_abbr.reset(new DWARFDebugAbbrev());
624 if (m_abbr.get())
625 m_abbr->Parse(debug_abbrev_data);
626 }
627 }
628 return m_abbr.get();
629}
630
631const DWARFDebugAbbrev*
632SymbolFileDWARF::DebugAbbrev() const
633{
634 return m_abbr.get();
635}
636
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000637
638DWARFDebugInfo*
639SymbolFileDWARF::DebugInfo()
640{
641 if (m_info.get() == NULL)
642 {
643 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
644 if (get_debug_info_data().GetByteSize() > 0)
645 {
646 m_info.reset(new DWARFDebugInfo());
647 if (m_info.get())
648 {
649 m_info->SetDwarfData(this);
650 }
651 }
652 }
653 return m_info.get();
654}
655
656const DWARFDebugInfo*
657SymbolFileDWARF::DebugInfo() const
658{
659 return m_info.get();
660}
661
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000662DWARFCompileUnit*
Greg Clayton1f746072012-08-29 21:13:06 +0000663SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000664{
665 DWARFDebugInfo* info = DebugInfo();
Greg Clayton1f746072012-08-29 21:13:06 +0000666 if (info)
667 {
668 if (GetDebugMapSymfile ())
669 {
670 // The debug map symbol file made the compile units for this DWARF
671 // file which is .o file with DWARF in it, and we should have
672 // only 1 compile unit which is at offset zero in the DWARF.
673 // TODO: modify to support LTO .o files where each .o file might
674 // have multiple DW_TAG_compile_unit tags.
675 return info->GetCompileUnit(0).get();
676 }
677 else
678 {
679 // Just a normal DWARF file whose user ID for the compile unit is
680 // the DWARF offset itself
681 return info->GetCompileUnit((dw_offset_t)comp_unit->GetID()).get();
682 }
683 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000684 return NULL;
685}
686
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000687
688DWARFDebugRanges*
689SymbolFileDWARF::DebugRanges()
690{
691 if (m_ranges.get() == NULL)
692 {
693 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
694 if (get_debug_ranges_data().GetByteSize() > 0)
695 {
696 m_ranges.reset(new DWARFDebugRanges());
697 if (m_ranges.get())
698 m_ranges->Extract(this);
699 }
700 }
701 return m_ranges.get();
702}
703
704const DWARFDebugRanges*
705SymbolFileDWARF::DebugRanges() const
706{
707 return m_ranges.get();
708}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000709
Greg Clayton53eb1c22012-04-02 22:59:12 +0000710lldb::CompUnitSP
711SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000712{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000713 CompUnitSP cu_sp;
714 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000715 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000716 CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData();
717 if (comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000718 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000719 // We already parsed this compile unit, had out a shared pointer to it
720 cu_sp = comp_unit->shared_from_this();
721 }
722 else
723 {
Greg Clayton1f746072012-08-29 21:13:06 +0000724 if (GetDebugMapSymfile ())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000725 {
Greg Clayton1f746072012-08-29 21:13:06 +0000726 // Let the debug map create the compile unit
727 cu_sp = m_debug_map_symfile->GetCompileUnit(this);
728 dwarf_cu->SetUserData(cu_sp.get());
729 }
730 else
731 {
732 ModuleSP module_sp (m_obj_file->GetModule());
733 if (module_sp)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000734 {
Greg Clayton1f746072012-08-29 21:13:06 +0000735 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly ();
736 if (cu_die)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000737 {
Greg Clayton1f746072012-08-29 21:13:06 +0000738 const char * cu_die_name = cu_die->GetName(this, dwarf_cu);
739 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
740 LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
741 if (cu_die_name)
742 {
743 std::string ramapped_file;
744 FileSpec cu_file_spec;
Jim Ingham0909e5f2010-09-16 00:57:33 +0000745
Greg Clayton1f746072012-08-29 21:13:06 +0000746 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0')
Greg Clayton53eb1c22012-04-02 22:59:12 +0000747 {
Greg Clayton1f746072012-08-29 21:13:06 +0000748 // If we have a full path to the compile unit, we don't need to resolve
749 // the file. This can be expensive e.g. when the source files are NFS mounted.
750 if (module_sp->RemapSourceFile(cu_die_name, ramapped_file))
751 cu_file_spec.SetFile (ramapped_file.c_str(), false);
752 else
753 cu_file_spec.SetFile (cu_die_name, false);
Greg Clayton53eb1c22012-04-02 22:59:12 +0000754 }
755 else
756 {
Greg Clayton1f746072012-08-29 21:13:06 +0000757 std::string fullpath(cu_comp_dir);
758 if (*fullpath.rbegin() != '/')
759 fullpath += '/';
760 fullpath += cu_die_name;
761 if (module_sp->RemapSourceFile (fullpath.c_str(), ramapped_file))
762 cu_file_spec.SetFile (ramapped_file.c_str(), false);
763 else
764 cu_file_spec.SetFile (fullpath.c_str(), false);
765 }
766
767 cu_sp.reset(new CompileUnit (module_sp,
768 dwarf_cu,
769 cu_file_spec,
770 MakeUserID(dwarf_cu->GetOffset()),
771 cu_language));
772 if (cu_sp)
773 {
774 dwarf_cu->SetUserData(cu_sp.get());
775
Greg Clayton53eb1c22012-04-02 22:59:12 +0000776 // Figure out the compile unit index if we weren't given one
777 if (cu_idx == UINT32_MAX)
778 DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx);
779
780 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp);
781 }
782 }
783 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000784 }
785 }
786 }
787 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000788 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000789}
790
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000791uint32_t
792SymbolFileDWARF::GetNumCompileUnits()
793{
794 DWARFDebugInfo* info = DebugInfo();
795 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000796 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000797 return 0;
798}
799
800CompUnitSP
801SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
802{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000803 CompUnitSP cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000804 DWARFDebugInfo* info = DebugInfo();
805 if (info)
806 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000807 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
808 if (dwarf_cu)
809 cu_sp = ParseCompileUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000810 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000811 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000812}
813
814static void
Greg Claytonea3e7d52011-10-08 00:49:15 +0000815AddRangesToBlock (Block& block,
816 DWARFDebugRanges::RangeList& ranges,
817 addr_t block_base_addr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000818{
Greg Claytonea3e7d52011-10-08 00:49:15 +0000819 const size_t num_ranges = ranges.GetSize();
820 for (size_t i = 0; i<num_ranges; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000821 {
Greg Claytonea3e7d52011-10-08 00:49:15 +0000822 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i);
823 const addr_t range_base = range.GetRangeBase();
824 assert (range_base >= block_base_addr);
825 block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000826 }
Greg Claytonea3e7d52011-10-08 00:49:15 +0000827 block.FinalizeRanges ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000828}
829
830
831Function *
Greg Clayton0fffff52010-09-24 05:15:53 +0000832SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000833{
834 DWARFDebugRanges::RangeList func_ranges;
835 const char *name = NULL;
836 const char *mangled = NULL;
837 int decl_file = 0;
838 int decl_line = 0;
839 int decl_column = 0;
840 int call_file = 0;
841 int call_line = 0;
842 int call_column = 0;
843 DWARFExpression frame_base;
844
Greg Claytonc93237c2010-10-01 20:48:32 +0000845 assert (die->Tag() == DW_TAG_subprogram);
846
847 if (die->Tag() != DW_TAG_subprogram)
848 return NULL;
849
Greg Clayton3c2e3ae2012-02-06 06:42:51 +0000850 if (die->GetDIENamesAndRanges (this,
851 dwarf_cu,
852 name,
853 mangled,
854 func_ranges,
855 decl_file,
856 decl_line,
857 decl_column,
858 call_file,
859 call_line,
860 call_column,
861 &frame_base))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000862 {
863 // Union of all ranges in the function DIE (if the function is discontiguous)
864 AddressRange func_range;
Greg Claytonea3e7d52011-10-08 00:49:15 +0000865 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0);
866 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000867 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
868 {
869 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList());
870 if (func_range.GetBaseAddress().IsValid())
871 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
872 }
873
874 if (func_range.GetBaseAddress().IsValid())
875 {
876 Mangled func_name;
877 if (mangled)
Greg Clayton037520e2012-07-18 23:18:10 +0000878 func_name.SetValue(ConstString(mangled), true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000879 else if (name)
Greg Clayton037520e2012-07-18 23:18:10 +0000880 func_name.SetValue(ConstString(name), false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000881
882 FunctionSP func_sp;
Greg Clayton7b0992d2013-04-18 22:45:39 +0000883 std::unique_ptr<Declaration> decl_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000884 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +0000885 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
886 decl_line,
887 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000888
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000889 // Supply the type _only_ if it has already been parsed
Greg Clayton594e5ed2010-09-27 21:07:38 +0000890 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000891
892 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
893
Greg Clayton9422dd62013-03-04 21:46:16 +0000894 if (FixupAddress (func_range.GetBaseAddress()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000895 {
Greg Clayton9422dd62013-03-04 21:46:16 +0000896 const user_id_t func_user_id = MakeUserID(die->GetOffset());
897 func_sp.reset(new Function (sc.comp_unit,
898 MakeUserID(func_user_id), // UserID is the DIE offset
899 MakeUserID(func_user_id),
900 func_name,
901 func_type,
902 func_range)); // first address range
903
904 if (func_sp.get() != NULL)
905 {
906 if (frame_base.IsValid())
907 func_sp->GetFrameBaseExpression() = frame_base;
908 sc.comp_unit->AddFunction(func_sp);
909 return func_sp.get();
910 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000911 }
912 }
913 }
914 return NULL;
915}
916
Greg Clayton9422dd62013-03-04 21:46:16 +0000917bool
918SymbolFileDWARF::FixupAddress (Address &addr)
919{
920 SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile ();
921 if (debug_map_symfile)
922 {
923 return debug_map_symfile->LinkOSOAddress(addr);
924 }
925 // This is a normal DWARF file, no address fixups need to happen
926 return true;
927}
Greg Clayton1f746072012-08-29 21:13:06 +0000928lldb::LanguageType
929SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc)
930{
931 assert (sc.comp_unit);
932 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
933 if (dwarf_cu)
934 {
935 const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly();
Jim Ingham28eb5712012-10-12 17:34:26 +0000936 if (die)
937 {
938 const uint32_t language = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
939 if (language)
940 return (lldb::LanguageType)language;
941 }
Greg Clayton1f746072012-08-29 21:13:06 +0000942 }
943 return eLanguageTypeUnknown;
944}
945
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000946size_t
947SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
948{
949 assert (sc.comp_unit);
950 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +0000951 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000952 if (dwarf_cu)
953 {
954 DWARFDIECollection function_dies;
Greg Clayton1f746072012-08-29 21:13:06 +0000955 const size_t num_functions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000956 size_t func_idx;
Greg Clayton1f746072012-08-29 21:13:06 +0000957 for (func_idx = 0; func_idx < num_functions; ++func_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000958 {
959 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
Greg Clayton81c22f62011-10-19 18:09:39 +0000960 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000961 {
962 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
963 ++functions_added;
964 }
965 }
966 //FixupTypes();
967 }
968 return functions_added;
969}
970
971bool
972SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
973{
974 assert (sc.comp_unit);
Greg Clayton1f746072012-08-29 21:13:06 +0000975 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Greg Claytonda2455b2012-11-01 17:28:37 +0000976 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000977 {
Greg Claytonda2455b2012-11-01 17:28:37 +0000978 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000979
Greg Claytonda2455b2012-11-01 17:28:37 +0000980 if (cu_die)
981 {
982 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
983 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 +0000984
Greg Claytonda2455b2012-11-01 17:28:37 +0000985 // All file indexes in DWARF are one based and a file of index zero is
986 // supposed to be the compile unit itself.
987 support_files.Append (*sc.comp_unit);
988
989 return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
990 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000991 }
992 return false;
993}
994
995struct ParseDWARFLineTableCallbackInfo
996{
997 LineTable* line_table;
Greg Clayton7b0992d2013-04-18 22:45:39 +0000998 std::unique_ptr<LineSequence> sequence_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000999};
1000
1001//----------------------------------------------------------------------
1002// ParseStatementTableCallback
1003//----------------------------------------------------------------------
1004static void
1005ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
1006{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001007 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
1008 {
1009 // Just started parsing the line table
1010 }
1011 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
1012 {
1013 // Done parsing line table, nothing to do for the cleanup
1014 }
1015 else
1016 {
1017 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
Greg Clayton9422dd62013-03-04 21:46:16 +00001018 LineTable* line_table = info->line_table;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001019
Greg Clayton9422dd62013-03-04 21:46:16 +00001020 // If this is our first time here, we need to create a
1021 // sequence container.
1022 if (!info->sequence_ap.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001023 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001024 info->sequence_ap.reset(line_table->CreateLineSequenceContainer());
1025 assert(info->sequence_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001026 }
Greg Clayton9422dd62013-03-04 21:46:16 +00001027 line_table->AppendLineEntryToSequence (info->sequence_ap.get(),
1028 state.address,
1029 state.line,
1030 state.column,
1031 state.file,
1032 state.is_stmt,
1033 state.basic_block,
1034 state.prologue_end,
1035 state.epilogue_begin,
1036 state.end_sequence);
1037 if (state.end_sequence)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001038 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001039 // First, put the current sequence into the line table.
1040 line_table->InsertSequence(info->sequence_ap.get());
1041 // Then, empty it to prepare for the next sequence.
1042 info->sequence_ap->Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001043 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001044 }
1045}
1046
1047bool
1048SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1049{
1050 assert (sc.comp_unit);
1051 if (sc.comp_unit->GetLineTable() != NULL)
1052 return true;
1053
Greg Clayton1f746072012-08-29 21:13:06 +00001054 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001055 if (dwarf_cu)
1056 {
1057 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Greg Clayton129d12c2011-11-28 03:29:03 +00001058 if (dwarf_cu_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001059 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001060 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1061 if (cu_line_offset != DW_INVALID_OFFSET)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001062 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001063 std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
Greg Clayton129d12c2011-11-28 03:29:03 +00001064 if (line_table_ap.get())
1065 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001066 ParseDWARFLineTableCallbackInfo info;
1067 info.line_table = line_table_ap.get();
Greg Claytonc7bece562013-01-25 18:06:21 +00001068 lldb::offset_t offset = cu_line_offset;
Greg Clayton129d12c2011-11-28 03:29:03 +00001069 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
Greg Clayton9422dd62013-03-04 21:46:16 +00001070 if (m_debug_map_symfile)
1071 {
1072 // We have an object file that has a line table with addresses
1073 // that are not linked. We need to link the line table and convert
1074 // the addresses that are relative to the .o file into addresses
1075 // for the main executable.
1076 sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get()));
1077 }
1078 else
1079 {
1080 sc.comp_unit->SetLineTable(line_table_ap.release());
1081 return true;
1082 }
Greg Clayton129d12c2011-11-28 03:29:03 +00001083 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001084 }
1085 }
1086 }
1087 return false;
1088}
1089
1090size_t
1091SymbolFileDWARF::ParseFunctionBlocks
1092(
1093 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001094 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001095 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001096 const DWARFDebugInfoEntry *die,
1097 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001098 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001099)
1100{
1101 size_t blocks_added = 0;
1102 while (die != NULL)
1103 {
1104 dw_tag_t tag = die->Tag();
1105
1106 switch (tag)
1107 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001108 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001109 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001110 case DW_TAG_lexical_block:
1111 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001112 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001113 if (tag == DW_TAG_subprogram)
1114 {
1115 // Skip any DW_TAG_subprogram DIEs that are inside
1116 // of a normal or inlined functions. These will be
1117 // parsed on their own as separate entities.
1118
1119 if (depth > 0)
1120 break;
1121
1122 block = parent_block;
1123 }
1124 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001125 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001126 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001127 parent_block->AddChild(block_sp);
1128 block = block_sp.get();
1129 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001130 DWARFDebugRanges::RangeList ranges;
1131 const char *name = NULL;
1132 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001133
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001134 int decl_file = 0;
1135 int decl_line = 0;
1136 int decl_column = 0;
1137 int call_file = 0;
1138 int call_line = 0;
1139 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001140 if (die->GetDIENamesAndRanges (this,
1141 dwarf_cu,
1142 name,
1143 mangled_name,
1144 ranges,
1145 decl_file, decl_line, decl_column,
1146 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001147 {
1148 if (tag == DW_TAG_subprogram)
1149 {
1150 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001151 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001152 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001153 else if (tag == DW_TAG_inlined_subroutine)
1154 {
1155 // We get called here for inlined subroutines in two ways.
1156 // The first time is when we are making the Function object
1157 // for this inlined concrete instance. Since we're creating a top level block at
1158 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1159 // adjust the containing address.
1160 // The second time is when we are parsing the blocks inside the function that contains
1161 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1162 // function the offset will be for that function.
1163 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1164 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001165 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001166 }
1167 }
1168
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001169 AddRangesToBlock (*block, ranges, subprogram_low_pc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001170
1171 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1172 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001173 std::unique_ptr<Declaration> decl_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001174 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001175 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1176 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001177
Greg Clayton7b0992d2013-04-18 22:45:39 +00001178 std::unique_ptr<Declaration> call_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001179 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001180 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1181 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001182
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001183 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001184 }
1185
1186 ++blocks_added;
1187
Greg Claytondd7feaf2011-08-12 17:54:33 +00001188 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001189 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001190 blocks_added += ParseFunctionBlocks (sc,
1191 block,
1192 dwarf_cu,
1193 die->GetFirstChild(),
1194 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001195 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001196 }
1197 }
1198 }
1199 break;
1200 default:
1201 break;
1202 }
1203
Greg Claytondd7feaf2011-08-12 17:54:33 +00001204 // Only parse siblings of the block if we are not at depth zero. A depth
1205 // of zero indicates we are currently parsing the top level
1206 // DW_TAG_subprogram DIE
1207
1208 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001209 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001210 else
1211 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001212 }
1213 return blocks_added;
1214}
1215
Greg Claytonf0705c82011-10-22 03:33:13 +00001216bool
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001217SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu,
1218 const DWARFDebugInfoEntry *die,
1219 ClangASTContext::TemplateParameterInfos &template_param_infos)
1220{
1221 const dw_tag_t tag = die->Tag();
1222
1223 switch (tag)
1224 {
1225 case DW_TAG_template_type_parameter:
1226 case DW_TAG_template_value_parameter:
1227 {
1228 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
1229
1230 DWARFDebugInfoEntry::Attributes attributes;
1231 const size_t num_attributes = die->GetAttributes (this,
1232 dwarf_cu,
1233 fixed_form_sizes,
1234 attributes);
1235 const char *name = NULL;
1236 Type *lldb_type = NULL;
1237 clang_type_t clang_type = NULL;
1238 uint64_t uval64 = 0;
1239 bool uval64_valid = false;
1240 if (num_attributes > 0)
1241 {
1242 DWARFFormValue form_value;
1243 for (size_t i=0; i<num_attributes; ++i)
1244 {
1245 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1246
1247 switch (attr)
1248 {
1249 case DW_AT_name:
1250 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1251 name = form_value.AsCString(&get_debug_str_data());
1252 break;
1253
1254 case DW_AT_type:
1255 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1256 {
1257 const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu);
1258 lldb_type = ResolveTypeUID(type_die_offset);
1259 if (lldb_type)
1260 clang_type = lldb_type->GetClangForwardType();
1261 }
1262 break;
1263
1264 case DW_AT_const_value:
1265 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1266 {
1267 uval64_valid = true;
1268 uval64 = form_value.Unsigned();
1269 }
1270 break;
1271 default:
1272 break;
1273 }
1274 }
1275
Greg Clayton283b2652013-04-23 22:38:02 +00001276 clang::ASTContext *ast = GetClangASTContext().getASTContext();
1277 if (!clang_type)
1278 clang_type = ast->VoidTy.getAsOpaquePtr();
1279
1280 if (clang_type)
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001281 {
1282 bool is_signed = false;
Greg Clayton283b2652013-04-23 22:38:02 +00001283 if (name && name[0])
1284 template_param_infos.names.push_back(name);
1285 else
1286 template_param_infos.names.push_back(NULL);
1287
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001288 clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type));
Greg Clayton283b2652013-04-23 22:38:02 +00001289 if (tag == DW_TAG_template_value_parameter &&
1290 lldb_type != NULL &&
1291 ClangASTContext::IsIntegerType (clang_type, is_signed) &&
1292 uval64_valid)
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001293 {
1294 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
Greg Clayton283b2652013-04-23 22:38:02 +00001295 template_param_infos.args.push_back (clang::TemplateArgument (*ast,
Sean Callanan3d654b32012-09-24 22:25:51 +00001296 llvm::APSInt(apint),
1297 clang_qual_type));
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001298 }
1299 else
1300 {
1301 template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type));
1302 }
1303 }
1304 else
1305 {
1306 return false;
1307 }
1308
1309 }
1310 }
1311 return true;
1312
1313 default:
1314 break;
1315 }
1316 return false;
1317}
1318
1319bool
Greg Claytonf0705c82011-10-22 03:33:13 +00001320SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1321 const DWARFDebugInfoEntry *parent_die,
1322 ClangASTContext::TemplateParameterInfos &template_param_infos)
1323{
1324
1325 if (parent_die == NULL)
Filipe Cabecinhas52008c62012-05-23 16:24:11 +00001326 return false;
Greg Claytonf0705c82011-10-22 03:33:13 +00001327
Greg Claytonf0705c82011-10-22 03:33:13 +00001328 Args template_parameter_names;
1329 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1330 die != NULL;
1331 die = die->GetSibling())
1332 {
1333 const dw_tag_t tag = die->Tag();
1334
1335 switch (tag)
1336 {
1337 case DW_TAG_template_type_parameter:
1338 case DW_TAG_template_value_parameter:
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001339 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Claytonf0705c82011-10-22 03:33:13 +00001340 break;
1341
1342 default:
1343 break;
1344 }
1345 }
1346 if (template_param_infos.args.empty())
1347 return false;
1348 return template_param_infos.args.size() == template_param_infos.names.size();
1349}
1350
1351clang::ClassTemplateDecl *
1352SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001353 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001354 const char *parent_name,
1355 int tag_decl_kind,
1356 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1357{
1358 if (template_param_infos.IsValid())
1359 {
1360 std::string template_basename(parent_name);
1361 template_basename.erase (template_basename.find('<'));
1362 ClangASTContext &ast = GetClangASTContext();
1363
1364 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001365 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001366 template_basename.c_str(),
1367 tag_decl_kind,
1368 template_param_infos);
1369 }
1370 return NULL;
1371}
1372
Sean Callanana0b80ab2012-06-04 22:28:05 +00001373class SymbolFileDWARF::DelayedAddObjCClassProperty
1374{
1375public:
1376 DelayedAddObjCClassProperty
1377 (
1378 clang::ASTContext *ast,
1379 lldb::clang_type_t class_opaque_type,
1380 const char *property_name,
1381 lldb::clang_type_t property_opaque_type, // The property type is only required if you don't have an ivar decl
1382 clang::ObjCIvarDecl *ivar_decl,
1383 const char *property_setter_name,
1384 const char *property_getter_name,
1385 uint32_t property_attributes,
Greg Claytonc4ffd662013-03-08 01:37:30 +00001386 const ClangASTMetadata *metadata
Sean Callanana0b80ab2012-06-04 22:28:05 +00001387 ) :
1388 m_ast (ast),
1389 m_class_opaque_type (class_opaque_type),
1390 m_property_name (property_name),
1391 m_property_opaque_type (property_opaque_type),
1392 m_ivar_decl (ivar_decl),
1393 m_property_setter_name (property_setter_name),
1394 m_property_getter_name (property_getter_name),
Jim Ingham379397632012-10-27 02:54:13 +00001395 m_property_attributes (property_attributes)
Sean Callanana0b80ab2012-06-04 22:28:05 +00001396 {
Jim Ingham379397632012-10-27 02:54:13 +00001397 if (metadata != NULL)
1398 {
1399 m_metadata_ap.reset(new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001400 *m_metadata_ap = *metadata;
Jim Ingham379397632012-10-27 02:54:13 +00001401 }
1402 }
1403
1404 DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs)
1405 {
Daniel Malead4c5be62012-11-12 21:02:14 +00001406 *this = rhs;
1407 }
1408
1409 DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs)
1410 {
Jim Ingham379397632012-10-27 02:54:13 +00001411 m_ast = rhs.m_ast;
1412 m_class_opaque_type = rhs.m_class_opaque_type;
1413 m_property_name = rhs.m_property_name;
1414 m_property_opaque_type = rhs.m_property_opaque_type;
1415 m_ivar_decl = rhs.m_ivar_decl;
1416 m_property_setter_name = rhs.m_property_setter_name;
1417 m_property_getter_name = rhs.m_property_getter_name;
1418 m_property_attributes = rhs.m_property_attributes;
1419
1420 if (rhs.m_metadata_ap.get())
1421 {
1422 m_metadata_ap.reset (new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001423 *m_metadata_ap = *rhs.m_metadata_ap;
Jim Ingham379397632012-10-27 02:54:13 +00001424 }
Daniel Malead4c5be62012-11-12 21:02:14 +00001425 return *this;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001426 }
1427
1428 bool Finalize() const
1429 {
Greg Claytonc4ffd662013-03-08 01:37:30 +00001430 return ClangASTContext::AddObjCClassProperty (m_ast,
1431 m_class_opaque_type,
1432 m_property_name,
1433 m_property_opaque_type,
1434 m_ivar_decl,
1435 m_property_setter_name,
1436 m_property_getter_name,
1437 m_property_attributes,
1438 m_metadata_ap.get());
Sean Callanana0b80ab2012-06-04 22:28:05 +00001439 }
1440private:
1441 clang::ASTContext *m_ast;
1442 lldb::clang_type_t m_class_opaque_type;
1443 const char *m_property_name;
1444 lldb::clang_type_t m_property_opaque_type;
1445 clang::ObjCIvarDecl *m_ivar_decl;
1446 const char *m_property_setter_name;
1447 const char *m_property_getter_name;
1448 uint32_t m_property_attributes;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001449 std::unique_ptr<ClangASTMetadata> m_metadata_ap;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001450};
1451
Sean Callananfaa0bb32012-12-05 23:37:14 +00001452struct BitfieldInfo
1453{
1454 uint64_t bit_size;
1455 uint64_t bit_offset;
1456
1457 BitfieldInfo () :
1458 bit_size (LLDB_INVALID_ADDRESS),
1459 bit_offset (LLDB_INVALID_ADDRESS)
1460 {
1461 }
1462
1463 bool IsValid ()
1464 {
1465 return (bit_size != LLDB_INVALID_ADDRESS) &&
1466 (bit_offset != LLDB_INVALID_ADDRESS);
1467 }
1468};
1469
Greg Claytonc4ffd662013-03-08 01:37:30 +00001470
1471bool
1472SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu,
1473 const DWARFDebugInfoEntry *parent_die)
1474{
1475 if (parent_die)
1476 {
1477 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1478 {
1479 dw_tag_t tag = die->Tag();
1480 bool check_virtuality = false;
1481 switch (tag)
1482 {
1483 case DW_TAG_inheritance:
1484 case DW_TAG_subprogram:
1485 check_virtuality = true;
1486 break;
1487 default:
1488 break;
1489 }
1490 if (check_virtuality)
1491 {
1492 if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0)
1493 return true;
1494 }
1495 }
1496 }
1497 return false;
1498}
1499
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001500size_t
1501SymbolFileDWARF::ParseChildMembers
1502(
1503 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001504 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001505 const DWARFDebugInfoEntry *parent_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00001506 clang_type_t class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001507 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001508 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1509 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001510 DWARFDIECollection& member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001511 DelayedPropertyList& delayed_properties,
Sean Callananc7fbf732010-08-06 00:32:49 +00001512 AccessType& default_accessibility,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001513 bool &is_a_class,
1514 LayoutInfo &layout_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001515)
1516{
1517 if (parent_die == NULL)
1518 return 0;
1519
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001520 size_t count = 0;
1521 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001522 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001523 uint32_t member_idx = 0;
Sean Callananfaa0bb32012-12-05 23:37:14 +00001524 BitfieldInfo last_field_info;
Greg Claytond88d7592010-09-15 08:33:30 +00001525
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001526 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1527 {
1528 dw_tag_t tag = die->Tag();
1529
1530 switch (tag)
1531 {
1532 case DW_TAG_member:
Sean Callanan3d654b32012-09-24 22:25:51 +00001533 case DW_TAG_APPLE_property:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001534 {
1535 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001536 const size_t num_attributes = die->GetAttributes (this,
1537 dwarf_cu,
1538 fixed_form_sizes,
1539 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001540 if (num_attributes > 0)
1541 {
1542 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001543 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001544 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001545 const char *prop_name = NULL;
1546 const char *prop_getter_name = NULL;
1547 const char *prop_setter_name = NULL;
Greg Claytone528efd72013-02-26 23:45:18 +00001548 uint32_t prop_attributes = 0;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001549
1550
Greg Clayton24739922010-10-13 03:15:28 +00001551 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001552 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001553 AccessType accessibility = eAccessNone;
Greg Claytoncaab74e2012-01-28 00:48:57 +00001554 uint32_t member_byte_offset = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001555 size_t byte_size = 0;
1556 size_t bit_offset = 0;
1557 size_t bit_size = 0;
Greg Claytone528efd72013-02-26 23:45:18 +00001558 bool is_external = false; // On DW_TAG_members, this means the member is static
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001559 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001560 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001561 {
1562 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1563 DWARFFormValue form_value;
1564 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1565 {
1566 switch (attr)
1567 {
1568 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1569 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1570 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1571 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1572 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1573 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1574 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1575 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1576 case DW_AT_data_member_location:
Greg Claytoncaab74e2012-01-28 00:48:57 +00001577 if (form_value.BlockData())
1578 {
1579 Value initialValue(0);
1580 Value memberOffset(0);
1581 const DataExtractor& debug_info_data = get_debug_info_data();
1582 uint32_t block_length = form_value.Unsigned();
1583 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1584 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
1585 NULL, // clang::ASTContext *
1586 NULL, // ClangExpressionVariableList *
1587 NULL, // ClangExpressionDeclMap *
1588 NULL, // RegisterContext *
1589 debug_info_data,
1590 block_offset,
1591 block_length,
1592 eRegisterKindDWARF,
1593 &initialValue,
1594 memberOffset,
1595 NULL))
1596 {
1597 member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1598 }
1599 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001600 break;
1601
Greg Clayton8cf05932010-07-22 18:30:50 +00001602 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00001603 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001604 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1605 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1606 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1607 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00001608 case DW_AT_external: is_external = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001609
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001610 default:
Greg Clayton1b02c172012-03-14 21:00:47 +00001611 case DW_AT_declaration:
1612 case DW_AT_description:
1613 case DW_AT_mutable:
1614 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001615 case DW_AT_sibling:
1616 break;
1617 }
1618 }
1619 }
Sean Callanana6582262012-04-05 00:12:52 +00001620
1621 if (prop_name)
Sean Callanan751aac62012-03-29 19:07:06 +00001622 {
Sean Callanana6582262012-04-05 00:12:52 +00001623 ConstString fixed_getter;
1624 ConstString fixed_setter;
1625
1626 // Check if the property getter/setter were provided as full
1627 // names. We want basenames, so we extract them.
1628
1629 if (prop_getter_name && prop_getter_name[0] == '-')
1630 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001631 ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true);
1632 prop_getter_name = prop_getter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001633 }
1634
1635 if (prop_setter_name && prop_setter_name[0] == '-')
1636 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001637 ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true);
1638 prop_setter_name = prop_setter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001639 }
1640
1641 // If the names haven't been provided, they need to be
1642 // filled in.
1643
1644 if (!prop_getter_name)
1645 {
1646 prop_getter_name = prop_name;
1647 }
1648 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly))
1649 {
1650 StreamString ss;
1651
1652 ss.Printf("set%c%s:",
1653 toupper(prop_name[0]),
1654 &prop_name[1]);
1655
1656 fixed_setter.SetCString(ss.GetData());
1657 prop_setter_name = fixed_setter.GetCString();
1658 }
Sean Callanan751aac62012-03-29 19:07:06 +00001659 }
1660
1661 // Clang has a DWARF generation bug where sometimes it
Greg Clayton44953932011-10-25 01:25:35 +00001662 // represents fields that are references with bad byte size
1663 // and bit size/offset information such as:
1664 //
1665 // DW_AT_byte_size( 0x00 )
1666 // DW_AT_bit_size( 0x40 )
1667 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1668 //
1669 // So check the bit offset to make sure it is sane, and if
1670 // the values are not sane, remove them. If we don't do this
1671 // then we will end up with a crash if we try to use this
1672 // type in an expression when clang becomes unhappy with its
1673 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001674
Greg Clayton44953932011-10-25 01:25:35 +00001675 if (bit_offset > 128)
1676 {
1677 bit_size = 0;
1678 bit_offset = 0;
1679 }
1680
1681 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00001682 if (class_language == eLanguageTypeObjC ||
1683 class_language == eLanguageTypeObjC_plus_plus)
1684 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001685
1686 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1687 {
1688 // Not all compilers will mark the vtable pointer
1689 // member as artificial (llvm-gcc). We can't have
1690 // the virtual members in our classes otherwise it
1691 // throws off all child offsets since we end up
1692 // having and extra pointer sized member in our
1693 // class layouts.
1694 is_artificial = true;
1695 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001696
Greg Claytone528efd72013-02-26 23:45:18 +00001697 // Skip static members
1698 if (is_external && member_byte_offset == UINT32_MAX)
Greg Clayton973b6c92013-04-11 16:57:51 +00001699 {
1700 Type *var_type = ResolveTypeUID(encoding_uid);
1701
1702 if (var_type)
1703 {
1704 GetClangASTContext().AddVariableToRecordType (class_clang_type,
1705 name,
1706 var_type->GetClangLayoutType(),
1707 accessibility);
1708 }
Greg Claytone528efd72013-02-26 23:45:18 +00001709 break;
Greg Clayton973b6c92013-04-11 16:57:51 +00001710 }
Greg Claytone528efd72013-02-26 23:45:18 +00001711
Greg Clayton24739922010-10-13 03:15:28 +00001712 if (is_artificial == false)
1713 {
1714 Type *member_type = ResolveTypeUID(encoding_uid);
Sean Callananfa3ab452012-12-14 00:54:13 +00001715
Jim Inghame3ae82a2011-11-12 01:36:43 +00001716 clang::FieldDecl *field_decl = NULL;
Sean Callanan751aac62012-03-29 19:07:06 +00001717 if (tag == DW_TAG_member)
Greg Claytond16e1e52011-07-12 17:06:17 +00001718 {
Sean Callanan751aac62012-03-29 19:07:06 +00001719 if (member_type)
1720 {
1721 if (accessibility == eAccessNone)
1722 accessibility = default_accessibility;
1723 member_accessibilities.push_back(accessibility);
Sean Callananfaa0bb32012-12-05 23:37:14 +00001724
1725 BitfieldInfo this_field_info;
1726
1727 this_field_info.bit_size = bit_size;
1728
1729 if (member_byte_offset != UINT32_MAX || bit_size != 0)
Greg Clayton88bc7f32012-11-06 00:20:41 +00001730 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001731 /////////////////////////////////////////////////////////////
1732 // How to locate a field given the DWARF debug information
1733 //
1734 // AT_byte_size indicates the size of the word in which the
1735 // bit offset must be interpreted.
1736 //
1737 // AT_data_member_location indicates the byte offset of the
1738 // word from the base address of the structure.
1739 //
1740 // AT_bit_offset indicates how many bits into the word
1741 // (according to the host endianness) the low-order bit of
1742 // the field starts. AT_bit_offset can be negative.
1743 //
1744 // AT_bit_size indicates the size of the field in bits.
1745 /////////////////////////////////////////////////////////////
1746
1747 this_field_info.bit_offset = 0;
1748
1749 this_field_info.bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
1750
1751 if (GetObjectFile()->GetByteOrder() == eByteOrderLittle)
1752 {
1753 this_field_info.bit_offset += byte_size * 8;
1754 this_field_info.bit_offset -= (bit_offset + bit_size);
1755 }
1756 else
1757 {
1758 this_field_info.bit_offset += bit_offset;
1759 }
1760 }
1761
1762 // If the member to be emitted did not start on a character boundary and there is
1763 // empty space between the last field and this one, then we need to emit an
1764 // anonymous member filling up the space up to its start. There are three cases
1765 // here:
1766 //
1767 // 1 If the previous member ended on a character boundary, then we can emit an
1768 // anonymous member starting at the most recent character boundary.
1769 //
1770 // 2 If the previous member did not end on a character boundary and the distance
1771 // from the end of the previous member to the current member is less than a
1772 // word width, then we can emit an anonymous member starting right after the
1773 // previous member and right before this member.
1774 //
1775 // 3 If the previous member did not end on a character boundary and the distance
1776 // from the end of the previous member to the current member is greater than
1777 // or equal a word width, then we act as in Case 1.
1778
1779 const uint64_t character_width = 8;
1780 const uint64_t word_width = 32;
1781
1782 if (this_field_info.IsValid())
1783 {
1784 // Objective-C has invalid DW_AT_bit_offset values in older versions
1785 // of clang, so we have to be careful and only insert unnammed bitfields
Greg Clayton37c36e42012-11-27 00:59:26 +00001786 // if we have a new enough clang.
1787 bool detect_unnamed_bitfields = true;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001788
Greg Clayton37c36e42012-11-27 00:59:26 +00001789 if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus)
1790 detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields ();
1791
1792 if (detect_unnamed_bitfields)
Greg Clayton88bc7f32012-11-06 00:20:41 +00001793 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001794 BitfieldInfo anon_field_info;
1795
1796 if ((this_field_info.bit_offset % character_width) != 0) // not char aligned
Greg Clayton88bc7f32012-11-06 00:20:41 +00001797 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001798 uint64_t last_field_end = 0;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001799
Sean Callananfaa0bb32012-12-05 23:37:14 +00001800 if (last_field_info.IsValid())
1801 last_field_end = last_field_info.bit_offset + last_field_info.bit_size;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001802
Sean Callananfaa0bb32012-12-05 23:37:14 +00001803 if (this_field_info.bit_offset != last_field_end)
1804 {
1805 if (((last_field_end % character_width) == 0) || // case 1
1806 (this_field_info.bit_offset - last_field_end >= word_width)) // case 3
1807 {
1808 anon_field_info.bit_size = this_field_info.bit_offset % character_width;
1809 anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size;
1810 }
1811 else // case 2
1812 {
1813 anon_field_info.bit_size = this_field_info.bit_offset - last_field_end;
1814 anon_field_info.bit_offset = last_field_end;
1815 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00001816 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00001817 }
1818
Sean Callananfaa0bb32012-12-05 23:37:14 +00001819 if (anon_field_info.IsValid())
Greg Clayton88bc7f32012-11-06 00:20:41 +00001820 {
Greg Clayton88bc7f32012-11-06 00:20:41 +00001821 clang::FieldDecl *unnamed_bitfield_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
1822 NULL,
Sean Callananfaa0bb32012-12-05 23:37:14 +00001823 GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width),
Greg Clayton88bc7f32012-11-06 00:20:41 +00001824 accessibility,
Sean Callananfaa0bb32012-12-05 23:37:14 +00001825 anon_field_info.bit_size);
Greg Clayton88bc7f32012-11-06 00:20:41 +00001826
Sean Callananfaa0bb32012-12-05 23:37:14 +00001827 layout_info.field_offsets.insert(std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset));
Greg Clayton88bc7f32012-11-06 00:20:41 +00001828 }
1829 }
1830 }
Sean Callananfaa0bb32012-12-05 23:37:14 +00001831
Sean Callananfa3ab452012-12-14 00:54:13 +00001832 clang_type_t member_clang_type = member_type->GetClangLayoutType();
1833
1834 {
1835 // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>).
1836 // If the current field is at the end of the structure, then there is definitely no room for extra
1837 // elements and we override the type to array[0].
1838
1839 clang_type_t member_array_element_type;
1840 uint64_t member_array_size;
1841 bool member_array_is_incomplete;
1842
1843 if (GetClangASTContext().IsArrayType(member_clang_type,
1844 &member_array_element_type,
1845 &member_array_size,
1846 &member_array_is_incomplete) &&
1847 !member_array_is_incomplete)
1848 {
1849 uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX);
1850
1851 if (member_byte_offset >= parent_byte_size)
1852 {
1853 if (member_array_size != 1)
1854 {
1855 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,
1856 MakeUserID(die->GetOffset()),
1857 name,
1858 encoding_uid,
1859 MakeUserID(parent_die->GetOffset()));
1860 }
1861
Greg Clayton1c8ef472013-04-05 23:27:21 +00001862 member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0, false);
Sean Callananfa3ab452012-12-14 00:54:13 +00001863 }
1864 }
1865 }
1866
Greg Clayton88bc7f32012-11-06 00:20:41 +00001867 field_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
Sean Callanan751aac62012-03-29 19:07:06 +00001868 name,
Sean Callananfa3ab452012-12-14 00:54:13 +00001869 member_clang_type,
Sean Callanan751aac62012-03-29 19:07:06 +00001870 accessibility,
1871 bit_size);
Sean Callanan60217122012-04-13 00:10:03 +00001872
Greg Claytond0029442013-03-27 01:48:02 +00001873 GetClangASTContext().SetMetadataAsUserID (field_decl, MakeUserID(die->GetOffset()));
Sean Callananfaa0bb32012-12-05 23:37:14 +00001874
1875 if (this_field_info.IsValid())
1876 {
1877 layout_info.field_offsets.insert(std::make_pair(field_decl, this_field_info.bit_offset));
1878 last_field_info = this_field_info;
1879 }
Sean Callanan5b26f272012-02-04 08:49:35 +00001880 }
1881 else
1882 {
Sean Callanan751aac62012-03-29 19:07:06 +00001883 if (name)
Daniel Malead01b2952012-11-29 21:49:15 +00001884 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 +00001885 MakeUserID(die->GetOffset()),
1886 name,
1887 encoding_uid);
1888 else
Daniel Malead01b2952012-11-29 21:49:15 +00001889 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 +00001890 MakeUserID(die->GetOffset()),
1891 encoding_uid);
Sean Callanan5b26f272012-02-04 08:49:35 +00001892 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00001893 }
Sean Callanan751aac62012-03-29 19:07:06 +00001894
Jim Inghame3ae82a2011-11-12 01:36:43 +00001895 if (prop_name != NULL)
1896 {
Sean Callanan751aac62012-03-29 19:07:06 +00001897 clang::ObjCIvarDecl *ivar_decl = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001898
Sean Callanan751aac62012-03-29 19:07:06 +00001899 if (field_decl)
1900 {
1901 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
1902 assert (ivar_decl != NULL);
1903 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00001904
Jim Ingham379397632012-10-27 02:54:13 +00001905 ClangASTMetadata metadata;
1906 metadata.SetUserID (MakeUserID(die->GetOffset()));
Sean Callanana0b80ab2012-06-04 22:28:05 +00001907 delayed_properties.push_back(DelayedAddObjCClassProperty(GetClangASTContext().getASTContext(),
1908 class_clang_type,
1909 prop_name,
1910 member_type->GetClangLayoutType(),
1911 ivar_decl,
1912 prop_setter_name,
1913 prop_getter_name,
1914 prop_attributes,
Jim Ingham379397632012-10-27 02:54:13 +00001915 &metadata));
Sean Callanan60217122012-04-13 00:10:03 +00001916
Sean Callananad880762012-04-18 01:06:17 +00001917 if (ivar_decl)
Greg Claytond0029442013-03-27 01:48:02 +00001918 GetClangASTContext().SetMetadataAsUserID (ivar_decl, MakeUserID(die->GetOffset()));
Jim Inghame3ae82a2011-11-12 01:36:43 +00001919 }
Greg Clayton24739922010-10-13 03:15:28 +00001920 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001921 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00001922 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001923 }
1924 break;
1925
1926 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00001927 // Let the type parsing code handle this one for us.
1928 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001929 break;
1930
1931 case DW_TAG_inheritance:
1932 {
1933 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00001934 if (default_accessibility == eAccessNone)
1935 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001936 // TODO: implement DW_TAG_inheritance type parsing
1937 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001938 const size_t num_attributes = die->GetAttributes (this,
1939 dwarf_cu,
1940 fixed_form_sizes,
1941 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001942 if (num_attributes > 0)
1943 {
1944 Declaration decl;
1945 DWARFExpression location;
1946 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001947 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001948 bool is_virtual = false;
1949 bool is_base_of_class = true;
Greg Clayton2508b9b2012-11-01 23:20:02 +00001950 off_t member_byte_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001951 uint32_t i;
1952 for (i=0; i<num_attributes; ++i)
1953 {
1954 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1955 DWARFFormValue form_value;
1956 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1957 {
1958 switch (attr)
1959 {
1960 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1961 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1962 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1963 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton2508b9b2012-11-01 23:20:02 +00001964 case DW_AT_data_member_location:
1965 if (form_value.BlockData())
1966 {
1967 Value initialValue(0);
1968 Value memberOffset(0);
1969 const DataExtractor& debug_info_data = get_debug_info_data();
1970 uint32_t block_length = form_value.Unsigned();
1971 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1972 if (DWARFExpression::Evaluate (NULL,
1973 NULL,
1974 NULL,
1975 NULL,
1976 NULL,
1977 debug_info_data,
1978 block_offset,
1979 block_length,
1980 eRegisterKindDWARF,
1981 &initialValue,
1982 memberOffset,
1983 NULL))
1984 {
1985 member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1986 }
1987 }
1988 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001989
1990 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00001991 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001992 break;
1993
Greg Clayton1c8ef472013-04-05 23:27:21 +00001994 case DW_AT_virtuality: is_virtual = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001995 default:
1996 case DW_AT_sibling:
1997 break;
1998 }
1999 }
2000 }
2001
Greg Clayton526e5af2010-11-13 03:52:47 +00002002 Type *base_class_type = ResolveTypeUID(encoding_uid);
2003 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002004
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002005 clang_type_t base_class_clang_type = base_class_type->GetClangFullType();
2006 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002007 if (class_language == eLanguageTypeObjC)
2008 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002009 GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002010 }
2011 else
2012 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002013 base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type,
Greg Claytonba2d22d2010-11-13 22:57:37 +00002014 accessibility,
2015 is_virtual,
2016 is_base_of_class));
Greg Clayton2508b9b2012-11-01 23:20:02 +00002017
2018 if (is_virtual)
2019 {
2020 layout_info.vbase_offsets.insert(std::make_pair(ClangASTType::GetAsCXXRecordDecl(class_clang_type),
2021 clang::CharUnits::fromQuantity(member_byte_offset)));
2022 }
2023 else
2024 {
2025 layout_info.base_offsets.insert(std::make_pair(ClangASTType::GetAsCXXRecordDecl(class_clang_type),
2026 clang::CharUnits::fromQuantity(member_byte_offset)));
2027 }
Greg Clayton9e409562010-07-28 02:04:09 +00002028 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002029 }
2030 }
2031 break;
2032
2033 default:
2034 break;
2035 }
2036 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002037
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002038 return count;
2039}
2040
2041
2042clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00002043SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002044{
2045 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00002046 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002047 {
2048 DWARFCompileUnitSP cu_sp;
2049 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
2050 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00002051 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00002052 }
2053 return NULL;
2054}
2055
2056clang::DeclContext*
2057SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
2058{
Greg Clayton81c22f62011-10-19 18:09:39 +00002059 if (UserIDMatches(type_uid))
2060 return GetClangDeclContextForDIEOffset (sc, type_uid);
2061 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002062}
2063
2064Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00002065SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002066{
Greg Clayton81c22f62011-10-19 18:09:39 +00002067 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002068 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002069 DWARFDebugInfo* debug_info = DebugInfo();
2070 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00002071 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002072 DWARFCompileUnitSP cu_sp;
2073 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00002074 const bool assert_not_being_parsed = true;
2075 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00002076 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002077 }
2078 return NULL;
2079}
2080
Greg Claytoncab36a32011-12-08 05:16:30 +00002081Type*
2082SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00002083{
Greg Claytoncab36a32011-12-08 05:16:30 +00002084 if (die != NULL)
2085 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002086 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00002087 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002088 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002089 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
2090 die->GetOffset(),
2091 DW_TAG_value_to_name(die->Tag()),
2092 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00002093
Greg Claytoncab36a32011-12-08 05:16:30 +00002094 // We might be coming in in the middle of a type tree (a class
2095 // withing a class, an enum within a class), so parse any needed
2096 // parent DIEs before we get to this one...
2097 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2098 switch (decl_ctx_die->Tag())
2099 {
2100 case DW_TAG_structure_type:
2101 case DW_TAG_union_type:
2102 case DW_TAG_class_type:
2103 {
2104 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00002105 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002106 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002107 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
2108 die->GetOffset(),
2109 DW_TAG_value_to_name(die->Tag()),
2110 die->GetName(this, cu),
2111 decl_ctx_die->GetOffset());
Greg Clayton219cf312012-03-30 00:51:13 +00002112//
2113// Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
2114// if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
2115// {
2116// if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002117// GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton219cf312012-03-30 00:51:13 +00002118// "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
2119// die->GetOffset(),
2120// DW_TAG_value_to_name(die->Tag()),
2121// die->GetName(this, cu),
2122// decl_ctx_die->GetOffset());
2123// // Ask the type to complete itself if it already hasn't since if we
2124// // want a function (method or static) from a class, the class must
2125// // create itself and add it's own methods and class functions.
2126// if (parent_type)
2127// parent_type->GetClangFullType();
2128// }
Greg Claytoncab36a32011-12-08 05:16:30 +00002129 }
2130 break;
2131
2132 default:
2133 break;
2134 }
2135 return ResolveType (cu, die);
2136 }
2137 return NULL;
2138}
2139
Greg Clayton6beaaa62011-01-17 03:46:26 +00002140// This function is used when SymbolFileDWARFDebugMap owns a bunch of
2141// SymbolFileDWARF objects to detect if this DWARF file is the one that
2142// can resolve a clang_type.
2143bool
2144SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type)
2145{
2146 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
2147 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
2148 return die != NULL;
2149}
2150
2151
Greg Clayton1be10fc2010-09-29 01:12:09 +00002152lldb::clang_type_t
2153SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
2154{
2155 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton6beaaa62011-01-17 03:46:26 +00002156 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
2157 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002158 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00002159 {
2160 // We have already resolved this type...
2161 return clang_type;
2162 }
2163 // Once we start resolving this type, remove it from the forward declaration
2164 // map in case anyone child members or other types require this type to get resolved.
2165 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
2166 // are done.
Greg Clayton6beaaa62011-01-17 03:46:26 +00002167 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers);
Greg Clayton73b472d2010-10-27 03:32:59 +00002168
Greg Clayton1be10fc2010-09-29 01:12:09 +00002169
Greg Clayton85ae2e12011-10-18 23:36:41 +00002170 // Disable external storage for this type so we don't get anymore
2171 // clang::ExternalASTSource queries for this type.
2172 ClangASTContext::SetHasExternalStorage (clang_type, false);
2173
Greg Clayton450e3f32010-10-12 02:24:53 +00002174 DWARFDebugInfo* debug_info = DebugInfo();
2175
Greg Clayton53eb1c22012-04-02 22:59:12 +00002176 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002177 Type *type = m_die_to_type.lookup (die);
2178
2179 const dw_tag_t tag = die->Tag();
2180
Greg Clayton5160ce52013-03-27 23:08:40 +00002181 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
Greg Clayton3bffb082011-12-10 02:15:28 +00002182 if (log)
Greg Claytonbaf95da2012-03-30 23:50:54 +00002183 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002184 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002185 "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...",
Greg Claytond61c0fc2012-04-23 22:55:20 +00002186 MakeUserID(die->GetOffset()),
2187 DW_TAG_value_to_name(tag),
2188 type->GetName().AsCString());
Greg Claytonbaf95da2012-03-30 23:50:54 +00002189
Greg Claytonbaf95da2012-03-30 23:50:54 +00002190 }
Greg Clayton1be10fc2010-09-29 01:12:09 +00002191 assert (clang_type);
2192 DWARFDebugInfoEntry::Attributes attributes;
2193
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002194 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002195
2196 switch (tag)
2197 {
2198 case DW_TAG_structure_type:
2199 case DW_TAG_union_type:
2200 case DW_TAG_class_type:
Greg Claytonc93237c2010-10-01 20:48:32 +00002201 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002202 LayoutInfo layout_info;
Sean Callanan77a1fd32012-02-27 20:07:01 +00002203
Greg Clayton1be10fc2010-09-29 01:12:09 +00002204 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002205 if (die->HasChildren())
Greg Claytonc93237c2010-10-01 20:48:32 +00002206 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002207
Sean Callanan77a1fd32012-02-27 20:07:01 +00002208 LanguageType class_language = eLanguageTypeUnknown;
2209 bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
2210 if (is_objc_class)
Greg Clayton219cf312012-03-30 00:51:13 +00002211 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002212 class_language = eLanguageTypeObjC;
Greg Clayton219cf312012-03-30 00:51:13 +00002213 // For objective C we don't start the definition when
2214 // the class is created.
2215 ast.StartTagDeclarationDefinition (clang_type);
2216 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002217
2218 int tag_decl_kind = -1;
2219 AccessType default_accessibility = eAccessNone;
2220 if (tag == DW_TAG_structure_type)
2221 {
2222 tag_decl_kind = clang::TTK_Struct;
2223 default_accessibility = eAccessPublic;
2224 }
2225 else if (tag == DW_TAG_union_type)
2226 {
2227 tag_decl_kind = clang::TTK_Union;
2228 default_accessibility = eAccessPublic;
2229 }
2230 else if (tag == DW_TAG_class_type)
2231 {
2232 tag_decl_kind = clang::TTK_Class;
2233 default_accessibility = eAccessPrivate;
2234 }
2235
Greg Clayton53eb1c22012-04-02 22:59:12 +00002236 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002237 std::vector<clang::CXXBaseSpecifier *> base_classes;
2238 std::vector<int> member_accessibilities;
2239 bool is_a_class = false;
2240 // Parse members and base classes first
2241 DWARFDIECollection member_function_dies;
Sean Callanana0b80ab2012-06-04 22:28:05 +00002242
2243 DelayedPropertyList delayed_properties;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002244 ParseChildMembers (sc,
Greg Clayton53eb1c22012-04-02 22:59:12 +00002245 dwarf_cu,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002246 die,
2247 clang_type,
2248 class_language,
2249 base_classes,
2250 member_accessibilities,
2251 member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002252 delayed_properties,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002253 default_accessibility,
2254 is_a_class,
2255 layout_info);
2256
2257 // Now parse any methods if there were any...
2258 size_t num_functions = member_function_dies.Size();
2259 if (num_functions > 0)
2260 {
2261 for (size_t i=0; i<num_functions; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002262 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002263 ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytoncaab74e2012-01-28 00:48:57 +00002264 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002265 }
2266
2267 if (class_language == eLanguageTypeObjC)
2268 {
Greg Clayton84db9102012-03-26 23:03:23 +00002269 std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(ast.getASTContext(), clang_type));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002270 if (!class_str.empty())
Greg Claytoncaab74e2012-01-28 00:48:57 +00002271 {
Greg Clayton450e3f32010-10-12 02:24:53 +00002272
Sean Callanan77a1fd32012-02-27 20:07:01 +00002273 DIEArray method_die_offsets;
2274 if (m_using_apple_tables)
Greg Clayton95d87902011-11-11 03:16:25 +00002275 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002276 if (m_apple_objc_ap.get())
2277 m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets);
2278 }
2279 else
2280 {
2281 if (!m_indexed)
2282 Index ();
Greg Claytoncaab74e2012-01-28 00:48:57 +00002283
Sean Callanan77a1fd32012-02-27 20:07:01 +00002284 ConstString class_name (class_str.c_str());
2285 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
2286 }
2287
2288 if (!method_die_offsets.empty())
2289 {
2290 DWARFDebugInfo* debug_info = DebugInfo();
2291
2292 DWARFCompileUnit* method_cu = NULL;
2293 const size_t num_matches = method_die_offsets.size();
2294 for (size_t i=0; i<num_matches; ++i)
Greg Clayton95d87902011-11-11 03:16:25 +00002295 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002296 const dw_offset_t die_offset = method_die_offsets[i];
2297 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
2298
2299 if (method_die)
2300 ResolveType (method_cu, method_die);
2301 else
Greg Claytoncaab74e2012-01-28 00:48:57 +00002302 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002303 if (m_using_apple_tables)
2304 {
2305 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n",
2306 die_offset, class_str.c_str());
2307 }
2308 }
2309 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002310 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002311
2312 for (DelayedPropertyList::const_iterator pi = delayed_properties.begin(), pe = delayed_properties.end();
2313 pi != pe;
2314 ++pi)
2315 pi->Finalize();
Greg Clayton450e3f32010-10-12 02:24:53 +00002316 }
2317 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002318
2319 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2320 // need to tell the clang type it is actually a class.
2321 if (class_language != eLanguageTypeObjC)
2322 {
2323 if (is_a_class && tag_decl_kind != clang::TTK_Class)
2324 ast.SetTagTypeKind (clang_type, clang::TTK_Class);
2325 }
2326
2327 // Since DW_TAG_structure_type gets used for both classes
2328 // and structures, we may need to set any DW_TAG_member
2329 // fields to have a "private" access if none was specified.
2330 // When we parsed the child members we tracked that actual
2331 // accessibility value for each DW_TAG_member in the
2332 // "member_accessibilities" array. If the value for the
2333 // member is zero, then it was set to the "default_accessibility"
2334 // which for structs was "public". Below we correct this
2335 // by setting any fields to "private" that weren't correctly
2336 // set.
2337 if (is_a_class && !member_accessibilities.empty())
2338 {
2339 // This is a class and all members that didn't have
2340 // their access specified are private.
2341 ast.SetDefaultAccessForRecordFields (clang_type,
2342 eAccessPrivate,
2343 &member_accessibilities.front(),
2344 member_accessibilities.size());
2345 }
2346
2347 if (!base_classes.empty())
2348 {
2349 ast.SetBaseClassesForClassType (clang_type,
2350 &base_classes.front(),
2351 base_classes.size());
2352
2353 // Clang will copy each CXXBaseSpecifier in "base_classes"
2354 // so we have to free them all.
2355 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
2356 base_classes.size());
2357 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002358 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002359 }
Sean Callanane8c0cfb2012-03-02 01:03:45 +00002360
2361 ast.BuildIndirectFields (clang_type);
2362
Sean Callanan77a1fd32012-02-27 20:07:01 +00002363 ast.CompleteTagDeclarationDefinition (clang_type);
Sean Callanan5b26f272012-02-04 08:49:35 +00002364
Greg Clayton2508b9b2012-11-01 23:20:02 +00002365 if (!layout_info.field_offsets.empty() ||
2366 !layout_info.base_offsets.empty() ||
2367 !layout_info.vbase_offsets.empty() )
Greg Claytoncaab74e2012-01-28 00:48:57 +00002368 {
2369 if (type)
2370 layout_info.bit_size = type->GetByteSize() * 8;
2371 if (layout_info.bit_size == 0)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002372 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002373
2374 clang::CXXRecordDecl *record_decl = ClangASTType::GetAsCXXRecordDecl(clang_type);
2375 if (record_decl)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002376 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002377 if (log)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002378 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002379 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002380 "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 +00002381 clang_type,
2382 record_decl,
2383 layout_info.bit_size,
2384 layout_info.alignment,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002385 (uint32_t)layout_info.field_offsets.size(),
2386 (uint32_t)layout_info.base_offsets.size(),
2387 (uint32_t)layout_info.vbase_offsets.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002388
Greg Clayton2508b9b2012-11-01 23:20:02 +00002389 uint32_t idx;
2390 {
Greg Clayton821ac6d2012-01-28 02:22:27 +00002391 llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002392 for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002393 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002394 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002395 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = { bit_offset=%u, name='%s' }",
Greg Clayton821ac6d2012-01-28 02:22:27 +00002396 clang_type,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002397 idx,
Greg Clayton821ac6d2012-01-28 02:22:27 +00002398 (uint32_t)pos->second,
2399 pos->first->getNameAsString().c_str());
2400 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002401 }
2402
2403 {
2404 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos, base_end = layout_info.base_offsets.end();
2405 for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; ++base_pos, ++idx)
2406 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002407 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002408 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] = { byte_offset=%u, name='%s' }",
2409 clang_type,
2410 idx,
2411 (uint32_t)base_pos->second.getQuantity(),
2412 base_pos->first->getNameAsString().c_str());
2413 }
2414 }
2415 {
2416 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos, vbase_end = layout_info.vbase_offsets.end();
2417 for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; ++vbase_pos, ++idx)
2418 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002419 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002420 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) vbase[%u] = { byte_offset=%u, name='%s' }",
2421 clang_type,
2422 idx,
2423 (uint32_t)vbase_pos->second.getQuantity(),
2424 vbase_pos->first->getNameAsString().c_str());
2425 }
2426 }
Greg Clayton821ac6d2012-01-28 02:22:27 +00002427 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002428 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2429 }
2430 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002431 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002432
Greg Claytonc93237c2010-10-01 20:48:32 +00002433 return clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002434
2435 case DW_TAG_enumeration_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002436 ast.StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002437 if (die->HasChildren())
2438 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002439 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00002440 bool is_signed = false;
2441 ast.IsIntegerType(clang_type, is_signed);
2442 ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002443 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002444 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002445 return clang_type;
2446
2447 default:
2448 assert(false && "not a forward clang type decl!");
2449 break;
2450 }
2451 return NULL;
2452}
2453
Greg Claytonc685f8e2010-09-15 04:15:46 +00002454Type*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002455SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002456{
2457 if (type_die != NULL)
2458 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002459 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00002460
Greg Claytonc685f8e2010-09-15 04:15:46 +00002461 if (type == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002462 type = GetTypeForDIE (dwarf_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00002463
Greg Clayton24739922010-10-13 03:15:28 +00002464 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00002465 {
2466 if (type != DIE_IS_BEING_PARSED)
2467 return type;
2468
2469 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
Greg Clayton53eb1c22012-04-02 22:59:12 +00002470 type_die->GetOffset(),
2471 DW_TAG_value_to_name(type_die->Tag()),
2472 type_die->GetName(this, dwarf_cu));
Jim Inghamc3549282012-01-11 02:21:12 +00002473
2474 }
2475 else
2476 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002477 }
2478 return NULL;
2479}
2480
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002481CompileUnit*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002482SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002483{
2484 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002485 if (dwarf_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002486 {
2487 // The symbol vendor doesn't know about this compile unit, we
2488 // need to parse and add it to the symbol vendor object.
Greg Clayton53eb1c22012-04-02 22:59:12 +00002489 return ParseCompileUnit(dwarf_cu, cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002490 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00002491 return (CompileUnit*)dwarf_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002492}
2493
2494bool
Greg Clayton53eb1c22012-04-02 22:59:12 +00002495SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002496{
Greg Clayton72310352013-02-23 04:12:47 +00002497 sc.Clear(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002498 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002499 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002500
Greg Clayton81c22f62011-10-19 18:09:39 +00002501 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002502 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002503 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002504
2505 if (sc.function)
2506 {
Greg Claytone72dfb32012-02-24 01:59:29 +00002507 sc.module_sp = sc.function->CalculateSymbolContextModule();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002508 return true;
2509 }
2510
2511 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002512}
2513
2514uint32_t
2515SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2516{
2517 Timer scoped_timer(__PRETTY_FUNCTION__,
Daniel Malead01b2952012-11-29 21:49:15 +00002518 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)",
Greg Claytone72dfb32012-02-24 01:59:29 +00002519 so_addr.GetSection().get(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002520 so_addr.GetOffset(),
2521 resolve_scope);
2522 uint32_t resolved = 0;
2523 if (resolve_scope & ( eSymbolContextCompUnit |
2524 eSymbolContextFunction |
2525 eSymbolContextBlock |
2526 eSymbolContextLineEntry))
2527 {
2528 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2529
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002530 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00002531 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002532 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002533 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002534 if (cu_offset != DW_INVALID_OFFSET)
2535 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002536 uint32_t cu_idx = DW_INVALID_INDEX;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002537 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
2538 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002539 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002540 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002541 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002542 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002543 resolved |= eSymbolContextCompUnit;
2544
Greg Clayton6ab80132012-12-12 17:30:52 +00002545 bool force_check_line_table = false;
Greg Clayton526a4ae2012-05-16 22:09:01 +00002546 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2547 {
2548 DWARFDebugInfoEntry *function_die = NULL;
2549 DWARFDebugInfoEntry *block_die = NULL;
2550 if (resolve_scope & eSymbolContextBlock)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002551 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002552 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
2553 }
2554 else
2555 {
2556 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL);
2557 }
2558
2559 if (function_die != NULL)
2560 {
2561 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2562 if (sc.function == NULL)
2563 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2564 }
2565 else
2566 {
2567 // We might have had a compile unit that had discontiguous
2568 // address ranges where the gaps are symbols that don't have
2569 // any debug info. Discontiguous compile unit address ranges
2570 // should only happen when there aren't other functions from
2571 // other compile units in these gaps. This helps keep the size
2572 // of the aranges down.
Greg Clayton6ab80132012-12-12 17:30:52 +00002573 force_check_line_table = true;
Greg Clayton526a4ae2012-05-16 22:09:01 +00002574 }
2575
2576 if (sc.function != NULL)
2577 {
2578 resolved |= eSymbolContextFunction;
2579
2580 if (resolve_scope & eSymbolContextBlock)
2581 {
2582 Block& block = sc.function->GetBlock (true);
2583
2584 if (block_die != NULL)
2585 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2586 else
2587 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2588 if (sc.block)
2589 resolved |= eSymbolContextBlock;
2590 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002591 }
2592 }
Greg Clayton6ab80132012-12-12 17:30:52 +00002593
2594 if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table)
2595 {
2596 LineTable *line_table = sc.comp_unit->GetLineTable();
2597 if (line_table != NULL)
2598 {
Greg Clayton9422dd62013-03-04 21:46:16 +00002599 // And address that makes it into this function should be in terms
2600 // of this debug file if there is no debug map, or it will be an
2601 // address in the .o file which needs to be fixed up to be in terms
2602 // of the debug map executable. Either way, calling FixupAddress()
2603 // will work for us.
2604 Address exe_so_addr (so_addr);
2605 if (FixupAddress(exe_so_addr))
Greg Clayton6ab80132012-12-12 17:30:52 +00002606 {
Greg Clayton9422dd62013-03-04 21:46:16 +00002607 if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry))
Greg Clayton6ab80132012-12-12 17:30:52 +00002608 {
2609 resolved |= eSymbolContextLineEntry;
2610 }
2611 }
Greg Clayton6ab80132012-12-12 17:30:52 +00002612 }
2613 }
2614
2615 if (force_check_line_table && !(resolved & eSymbolContextLineEntry))
2616 {
2617 // We might have had a compile unit that had discontiguous
2618 // address ranges where the gaps are symbols that don't have
2619 // any debug info. Discontiguous compile unit address ranges
2620 // should only happen when there aren't other functions from
2621 // other compile units in these gaps. This helps keep the size
2622 // of the aranges down.
2623 sc.comp_unit = NULL;
2624 resolved &= ~eSymbolContextCompUnit;
2625 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002626 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002627 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002628 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002629 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.",
2630 cu_offset,
2631 cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002632 }
2633 }
2634 }
2635 }
2636 }
2637 return resolved;
2638}
2639
2640
2641
2642uint32_t
2643SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
2644{
2645 const uint32_t prev_size = sc_list.GetSize();
2646 if (resolve_scope & eSymbolContextCompUnit)
2647 {
2648 DWARFDebugInfo* debug_info = DebugInfo();
2649 if (debug_info)
2650 {
2651 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002652 DWARFCompileUnit* dwarf_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002653
Greg Clayton53eb1c22012-04-02 22:59:12 +00002654 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002655 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002656 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton1f746072012-08-29 21:13:06 +00002657 const bool full_match = file_spec.GetDirectory();
2658 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 +00002659 if (check_inlines || file_spec_matches_cu_file_spec)
2660 {
2661 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton53eb1c22012-04-02 22:59:12 +00002662 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002663 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002664 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002665 uint32_t file_idx = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002666
Greg Clayton526a4ae2012-05-16 22:09:01 +00002667 // If we are looking for inline functions only and we don't
2668 // find it in the support files, we are done.
2669 if (check_inlines)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002670 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002671 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
2672 if (file_idx == UINT32_MAX)
2673 continue;
2674 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002675
Greg Clayton526a4ae2012-05-16 22:09:01 +00002676 if (line != 0)
2677 {
2678 LineTable *line_table = sc.comp_unit->GetLineTable();
2679
2680 if (line_table != NULL && line != 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002681 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002682 // We will have already looked up the file index if
2683 // we are searching for inline entries.
2684 if (!check_inlines)
2685 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002686
Greg Clayton526a4ae2012-05-16 22:09:01 +00002687 if (file_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002688 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002689 uint32_t found_line;
2690 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
2691 found_line = sc.line_entry.line;
2692
2693 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002694 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002695 sc.function = NULL;
2696 sc.block = NULL;
2697 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002698 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002699 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
2700 if (file_vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002701 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002702 DWARFDebugInfoEntry *function_die = NULL;
2703 DWARFDebugInfoEntry *block_die = NULL;
2704 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002705
Greg Clayton526a4ae2012-05-16 22:09:01 +00002706 if (function_die != NULL)
2707 {
2708 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2709 if (sc.function == NULL)
2710 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2711 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002712
Greg Clayton526a4ae2012-05-16 22:09:01 +00002713 if (sc.function != NULL)
2714 {
2715 Block& block = sc.function->GetBlock (true);
2716
2717 if (block_die != NULL)
2718 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2719 else
2720 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2721 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002722 }
2723 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002724
Greg Clayton526a4ae2012-05-16 22:09:01 +00002725 sc_list.Append(sc);
2726 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2727 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002728 }
2729 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002730 else if (file_spec_matches_cu_file_spec && !check_inlines)
2731 {
2732 // only append the context if we aren't looking for inline call sites
2733 // by file and line and if the file spec matches that of the compile unit
2734 sc_list.Append(sc);
2735 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002736 }
2737 else if (file_spec_matches_cu_file_spec && !check_inlines)
2738 {
2739 // only append the context if we aren't looking for inline call sites
2740 // by file and line and if the file spec matches that of the compile unit
2741 sc_list.Append(sc);
2742 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002743
Greg Clayton526a4ae2012-05-16 22:09:01 +00002744 if (!check_inlines)
2745 break;
2746 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002747 }
2748 }
2749 }
2750 }
2751 return sc_list.GetSize() - prev_size;
2752}
2753
2754void
2755SymbolFileDWARF::Index ()
2756{
2757 if (m_indexed)
2758 return;
2759 m_indexed = true;
2760 Timer scoped_timer (__PRETTY_FUNCTION__,
2761 "SymbolFileDWARF::Index (%s)",
2762 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
2763
2764 DWARFDebugInfo* debug_info = DebugInfo();
2765 if (debug_info)
2766 {
2767 uint32_t cu_idx = 0;
2768 const uint32_t num_compile_units = GetNumCompileUnits();
2769 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2770 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002771 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002772
Greg Clayton53eb1c22012-04-02 22:59:12 +00002773 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002774
Greg Clayton53eb1c22012-04-02 22:59:12 +00002775 dwarf_cu->Index (cu_idx,
2776 m_function_basename_index,
2777 m_function_fullname_index,
2778 m_function_method_index,
2779 m_function_selector_index,
2780 m_objc_class_selectors_index,
2781 m_global_index,
2782 m_type_index,
2783 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002784
2785 // Keep memory down by clearing DIEs if this generate function
2786 // caused them to be parsed
2787 if (clear_dies)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002788 dwarf_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002789 }
2790
Greg Claytond4a2b372011-09-12 23:21:58 +00002791 m_function_basename_index.Finalize();
2792 m_function_fullname_index.Finalize();
2793 m_function_method_index.Finalize();
2794 m_function_selector_index.Finalize();
2795 m_objc_class_selectors_index.Finalize();
2796 m_global_index.Finalize();
2797 m_type_index.Finalize();
2798 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002799
Greg Clayton24739922010-10-13 03:15:28 +00002800#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00002801 StreamFile s(stdout, false);
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00002802 s.Printf ("DWARF index for '%s':",
2803 GetObjectFile()->GetFileSpec().GetPath().c_str());
Greg Claytonba2d22d2010-11-13 22:57:37 +00002804 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
2805 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
2806 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
2807 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
2808 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
2809 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00002810 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00002811 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002812#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002813 }
2814}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002815
2816bool
2817SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
2818{
2819 if (namespace_decl == NULL)
2820 {
2821 // Invalid namespace decl which means we aren't matching only things
2822 // in this symbol file, so return true to indicate it matches this
2823 // symbol file.
2824 return true;
2825 }
2826
2827 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
2828
2829 if (namespace_ast == NULL)
2830 return true; // No AST in the "namespace_decl", return true since it
2831 // could then match any symbol file, including this one
2832
2833 if (namespace_ast == GetClangASTContext().getASTContext())
2834 return true; // The ASTs match, return true
2835
2836 // The namespace AST was valid, and it does not match...
Greg Clayton5160ce52013-03-27 23:08:40 +00002837 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Sean Callananc41e68b2011-10-13 21:08:11 +00002838
2839 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002840 GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00002841
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002842 return false;
2843}
2844
Greg Clayton2506a7a2011-10-12 23:34:26 +00002845bool
2846SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
2847 DWARFCompileUnit* cu,
2848 const DWARFDebugInfoEntry* die)
2849{
2850 // No namespace specified, so the answesr i
2851 if (namespace_decl == NULL)
2852 return true;
Sean Callananebe60672011-10-13 21:50:33 +00002853
Greg Clayton5160ce52013-03-27 23:08:40 +00002854 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002855
Greg Clayton437a1352012-04-09 22:43:43 +00002856 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
2857 clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00002858 if (decl_ctx_die)
Greg Clayton437a1352012-04-09 22:43:43 +00002859 {
Greg Clayton2506a7a2011-10-12 23:34:26 +00002860 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
Greg Clayton437a1352012-04-09 22:43:43 +00002861
Greg Clayton2506a7a2011-10-12 23:34:26 +00002862 if (clang_namespace_decl)
2863 {
2864 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00002865 {
2866 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002867 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00002868 return false;
Sean Callananebe60672011-10-13 21:50:33 +00002869 }
2870
Greg Clayton437a1352012-04-09 22:43:43 +00002871 if (clang_namespace_decl == die_clang_decl_ctx)
2872 return true;
2873 else
Greg Clayton2506a7a2011-10-12 23:34:26 +00002874 return false;
Greg Clayton2506a7a2011-10-12 23:34:26 +00002875 }
2876 else
2877 {
2878 // We have a namespace_decl that was not NULL but it contained
2879 // a NULL "clang::NamespaceDecl", so this means the global namespace
2880 // So as long the the contained decl context DIE isn't a namespace
2881 // we should be ok.
2882 if (decl_ctx_die->Tag() != DW_TAG_namespace)
2883 return true;
2884 }
2885 }
Sean Callananebe60672011-10-13 21:50:33 +00002886
2887 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002888 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00002889
Greg Clayton2506a7a2011-10-12 23:34:26 +00002890 return false;
2891}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002892uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00002893SymbolFileDWARF::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 +00002894{
Greg Clayton5160ce52013-03-27 23:08:40 +00002895 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00002896
2897 if (log)
2898 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002899 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002900 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
2901 name.GetCString(),
2902 namespace_decl,
2903 append,
2904 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002905 }
Sean Callanan213fdb82011-10-13 01:49:10 +00002906
2907 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2908 return 0;
2909
Greg Claytonc685f8e2010-09-15 04:15:46 +00002910 DWARFDebugInfo* info = DebugInfo();
2911 if (info == NULL)
2912 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002913
2914 // If we aren't appending the results to this list, then clear the list
2915 if (!append)
2916 variables.Clear();
2917
2918 // Remember how many variables are in the list before we search in case
2919 // we are appending the results to a variable list.
2920 const uint32_t original_size = variables.GetSize();
2921
Greg Claytond4a2b372011-09-12 23:21:58 +00002922 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002923
Greg Clayton97fbc342011-10-20 22:30:33 +00002924 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002925 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002926 if (m_apple_names_ap.get())
2927 {
2928 const char *name_cstr = name.GetCString();
2929 const char *base_name_start;
2930 const char *base_name_end = NULL;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002931
Greg Clayton97fbc342011-10-20 22:30:33 +00002932 if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end))
2933 base_name_start = name_cstr;
2934
2935 m_apple_names_ap->FindByName (base_name_start, die_offsets);
2936 }
Greg Clayton7f995132011-10-04 22:41:51 +00002937 }
2938 else
2939 {
2940 // Index the DWARF if we haven't already
2941 if (!m_indexed)
2942 Index ();
2943
2944 m_global_index.Find (name, die_offsets);
2945 }
2946
Greg Clayton437a1352012-04-09 22:43:43 +00002947 const size_t num_die_matches = die_offsets.size();
2948 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002949 {
Greg Clayton7f995132011-10-04 22:41:51 +00002950 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00002951 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00002952 assert (sc.module_sp);
2953
Greg Claytond4a2b372011-09-12 23:21:58 +00002954 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00002955 DWARFCompileUnit* dwarf_cu = NULL;
2956 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton437a1352012-04-09 22:43:43 +00002957 bool done = false;
2958 for (size_t i=0; i<num_die_matches && !done; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002959 {
2960 const dw_offset_t die_offset = die_offsets[i];
2961 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002962
Greg Clayton95d87902011-11-11 03:16:25 +00002963 if (die)
2964 {
Greg Clayton437a1352012-04-09 22:43:43 +00002965 switch (die->Tag())
2966 {
2967 default:
2968 case DW_TAG_subprogram:
2969 case DW_TAG_inlined_subroutine:
2970 case DW_TAG_try_block:
2971 case DW_TAG_catch_block:
2972 break;
2973
2974 case DW_TAG_variable:
2975 {
2976 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Greg Clayton437a1352012-04-09 22:43:43 +00002977
2978 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2979 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002980
Greg Clayton437a1352012-04-09 22:43:43 +00002981 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002982
Greg Clayton437a1352012-04-09 22:43:43 +00002983 if (variables.GetSize() - original_size >= max_matches)
2984 done = true;
2985 }
2986 break;
2987 }
Greg Clayton95d87902011-11-11 03:16:25 +00002988 }
2989 else
2990 {
2991 if (m_using_apple_tables)
2992 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002993 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
2994 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00002995 }
2996 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002997 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002998 }
2999
3000 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003001 const uint32_t num_matches = variables.GetSize() - original_size;
3002 if (log && num_matches > 0)
3003 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003004 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003005 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u",
3006 name.GetCString(),
3007 namespace_decl,
3008 append,
3009 max_matches,
3010 num_matches);
3011 }
3012 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003013}
3014
3015uint32_t
3016SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
3017{
Greg Clayton5160ce52013-03-27 23:08:40 +00003018 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003019
3020 if (log)
3021 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003022 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003023 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
3024 regex.GetText(),
3025 append,
3026 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003027 }
3028
Greg Claytonc685f8e2010-09-15 04:15:46 +00003029 DWARFDebugInfo* info = DebugInfo();
3030 if (info == NULL)
3031 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003032
3033 // If we aren't appending the results to this list, then clear the list
3034 if (!append)
3035 variables.Clear();
3036
3037 // Remember how many variables are in the list before we search in case
3038 // we are appending the results to a variable list.
3039 const uint32_t original_size = variables.GetSize();
3040
Greg Clayton7f995132011-10-04 22:41:51 +00003041 DIEArray die_offsets;
3042
Greg Clayton97fbc342011-10-20 22:30:33 +00003043 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003044 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003045 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00003046 {
3047 DWARFMappedHash::DIEInfoArray hash_data_array;
3048 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
3049 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
3050 }
Greg Clayton7f995132011-10-04 22:41:51 +00003051 }
3052 else
3053 {
3054 // Index the DWARF if we haven't already
3055 if (!m_indexed)
3056 Index ();
3057
3058 m_global_index.Find (regex, die_offsets);
3059 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003060
Greg Claytonc685f8e2010-09-15 04:15:46 +00003061 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003062 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003063 assert (sc.module_sp);
3064
Greg Claytond4a2b372011-09-12 23:21:58 +00003065 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00003066 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003067 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003068 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003069 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003070 DWARFDebugInfo* debug_info = DebugInfo();
3071 for (size_t i=0; i<num_matches; ++i)
3072 {
3073 const dw_offset_t die_offset = die_offsets[i];
3074 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00003075
3076 if (die)
3077 {
3078 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003079
Greg Clayton95d87902011-11-11 03:16:25 +00003080 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003081
Greg Clayton95d87902011-11-11 03:16:25 +00003082 if (variables.GetSize() - original_size >= max_matches)
3083 break;
3084 }
3085 else
3086 {
3087 if (m_using_apple_tables)
3088 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003089 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
3090 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00003091 }
3092 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003093 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003094 }
3095
3096 // Return the number of variable that were appended to the list
3097 return variables.GetSize() - original_size;
3098}
3099
Greg Claytonaa044962011-10-13 00:59:38 +00003100
Jim Ingham4cda6e02011-10-07 22:23:45 +00003101bool
3102SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
3103 DWARFCompileUnit *&dwarf_cu,
3104 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00003105{
Greg Claytonaa044962011-10-13 00:59:38 +00003106 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3107 return ResolveFunction (dwarf_cu, die, sc_list);
3108}
3109
3110
3111bool
3112SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
3113 const DWARFDebugInfoEntry *die,
3114 SymbolContextList& sc_list)
3115{
Greg Clayton9e315582011-09-02 04:03:59 +00003116 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00003117
3118 if (die == NULL)
3119 return false;
3120
Jim Ingham4cda6e02011-10-07 22:23:45 +00003121 // If we were passed a die that is not a function, just return false...
3122 if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine)
3123 return false;
3124
3125 const DWARFDebugInfoEntry* inlined_die = NULL;
3126 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00003127 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003128 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00003129
Jim Ingham4cda6e02011-10-07 22:23:45 +00003130 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003131 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003132 if (die->Tag() == DW_TAG_subprogram)
3133 break;
Greg Clayton9e315582011-09-02 04:03:59 +00003134 }
3135 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003136 assert (die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00003137 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003138 {
3139 Address addr;
3140 // Parse all blocks if needed
3141 if (inlined_die)
3142 {
Greg Clayton81c22f62011-10-19 18:09:39 +00003143 sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset()));
Jim Ingham4cda6e02011-10-07 22:23:45 +00003144 assert (sc.block != NULL);
3145 if (sc.block->GetStartAddress (addr) == false)
3146 addr.Clear();
3147 }
3148 else
3149 {
3150 sc.block = NULL;
3151 addr = sc.function->GetAddressRange().GetBaseAddress();
3152 }
3153
3154 if (addr.IsValid())
3155 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003156 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00003157 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003158 }
3159 }
3160
Greg Claytonaa044962011-10-13 00:59:38 +00003161 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00003162}
3163
Greg Clayton7f995132011-10-04 22:41:51 +00003164void
3165SymbolFileDWARF::FindFunctions (const ConstString &name,
3166 const NameToDIE &name_to_die,
3167 SymbolContextList& sc_list)
3168{
Greg Claytond4a2b372011-09-12 23:21:58 +00003169 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003170 if (name_to_die.Find (name, die_offsets))
3171 {
3172 ParseFunctions (die_offsets, sc_list);
3173 }
3174}
3175
3176
3177void
3178SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3179 const NameToDIE &name_to_die,
3180 SymbolContextList& sc_list)
3181{
3182 DIEArray die_offsets;
3183 if (name_to_die.Find (regex, die_offsets))
3184 {
3185 ParseFunctions (die_offsets, sc_list);
3186 }
3187}
3188
3189
3190void
3191SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3192 const DWARFMappedHash::MemoryTable &memory_table,
3193 SymbolContextList& sc_list)
3194{
3195 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00003196 DWARFMappedHash::DIEInfoArray hash_data_array;
3197 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00003198 {
Greg Claytond1767f02011-12-08 02:13:16 +00003199 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Greg Clayton7f995132011-10-04 22:41:51 +00003200 ParseFunctions (die_offsets, sc_list);
3201 }
3202}
3203
3204void
3205SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
3206 SymbolContextList& sc_list)
3207{
3208 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003209 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00003210 {
Greg Clayton7f995132011-10-04 22:41:51 +00003211 SymbolContext sc;
Greg Clayton7f995132011-10-04 22:41:51 +00003212
3213 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003214 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00003215 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003216 const dw_offset_t die_offset = die_offsets[i];
Jim Ingham4cda6e02011-10-07 22:23:45 +00003217 ResolveFunction (die_offset, dwarf_cu, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003218 }
3219 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00003220}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003221
Jim Ingham4cda6e02011-10-07 22:23:45 +00003222bool
3223SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
3224 const DWARFCompileUnit *dwarf_cu,
3225 uint32_t name_type_mask,
3226 const char *partial_name,
3227 const char *base_name_start,
3228 const char *base_name_end)
3229{
Greg Claytonfbea0f62012-11-15 18:05:43 +00003230 // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes:
3231 if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003232 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003233 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
3234 if (!containing_decl_ctx)
3235 return false;
3236
3237 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
3238
Greg Claytonfbea0f62012-11-15 18:05:43 +00003239 if (name_type_mask == eFunctionNameTypeMethod)
3240 {
3241 if (is_cxx_method == false)
3242 return false;
3243 }
3244
3245 if (name_type_mask == eFunctionNameTypeBase)
3246 {
3247 if (is_cxx_method == true)
3248 return false;
3249 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003250 }
3251
3252 // Now we need to check whether the name we got back for this type matches the extra specifications
3253 // that were in the name we're looking up:
3254 if (base_name_start != partial_name || *base_name_end != '\0')
3255 {
3256 // First see if the stuff to the left matches the full name. To do that let's see if
3257 // we can pull out the mips linkage name attribute:
3258
3259 Mangled best_name;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003260 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonfbea0f62012-11-15 18:05:43 +00003261 DWARFFormValue form_value;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003262 die->GetAttributes(this, dwarf_cu, NULL, attributes);
3263 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
Greg Clayton71415542012-12-08 00:24:40 +00003264 if (idx == UINT32_MAX)
3265 idx = attributes.FindAttributeIndex(DW_AT_linkage_name);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003266 if (idx != UINT32_MAX)
3267 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003268 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
3269 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003270 const char *mangled_name = form_value.AsCString(&get_debug_str_data());
3271 if (mangled_name)
3272 best_name.SetValue (ConstString(mangled_name), true);
3273 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003274 }
Greg Claytonfbea0f62012-11-15 18:05:43 +00003275
3276 if (!best_name)
3277 {
3278 idx = attributes.FindAttributeIndex(DW_AT_name);
3279 if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value))
3280 {
3281 const char *name = form_value.AsCString(&get_debug_str_data());
3282 best_name.SetValue (ConstString(name), false);
3283 }
3284 }
3285
3286 if (best_name.GetDemangledName())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003287 {
3288 const char *demangled = best_name.GetDemangledName().GetCString();
3289 if (demangled)
3290 {
3291 std::string name_no_parens(partial_name, base_name_end - partial_name);
Jim Ingham85c13d72012-03-02 02:24:42 +00003292 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str());
3293 if (partial_in_demangled == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003294 return false;
Jim Ingham85c13d72012-03-02 02:24:42 +00003295 else
3296 {
3297 // Sort out the case where our name is something like "Process::Destroy" and the match is
3298 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on
3299 // namespace boundaries...
3300
3301 if (partial_name[0] == ':' && partial_name[1] == ':')
3302 {
3303 // The partial name was already on a namespace boundary so all matches are good.
3304 return true;
3305 }
3306 else if (partial_in_demangled == demangled)
3307 {
3308 // They both start the same, so this is an good match.
3309 return true;
3310 }
3311 else
3312 {
3313 if (partial_in_demangled - demangled == 1)
3314 {
3315 // Only one character difference, can't be a namespace boundary...
3316 return false;
3317 }
3318 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':')
3319 {
3320 // We are on a namespace boundary, so this is also good.
3321 return true;
3322 }
3323 else
3324 return false;
3325 }
3326 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003327 }
3328 }
3329 }
3330
3331 return true;
3332}
Greg Claytonc685f8e2010-09-15 04:15:46 +00003333
Greg Clayton0c5cd902010-06-28 21:30:43 +00003334uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00003335SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00003336 const lldb_private::ClangNamespaceDecl *namespace_decl,
Sean Callanan9df05fb2012-02-10 22:52:19 +00003337 uint32_t name_type_mask,
3338 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00003339 bool append,
3340 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00003341{
3342 Timer scoped_timer (__PRETTY_FUNCTION__,
3343 "SymbolFileDWARF::FindFunctions (name = '%s')",
3344 name.AsCString());
3345
Greg Clayton43fe2172013-04-03 02:00:15 +00003346 // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup()
3347 assert ((name_type_mask & eFunctionNameTypeAuto) == 0);
3348
Greg Clayton5160ce52013-03-27 23:08:40 +00003349 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003350
3351 if (log)
3352 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003353 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003354 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
3355 name.GetCString(),
3356 name_type_mask,
3357 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003358 }
3359
Greg Clayton0c5cd902010-06-28 21:30:43 +00003360 // If we aren't appending the results to this list, then clear the list
3361 if (!append)
3362 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003363
3364 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3365 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003366
3367 // If name is empty then we won't find anything.
3368 if (name.IsEmpty())
3369 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00003370
3371 // Remember how many sc_list are in the list before we search in case
3372 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00003373
Jim Ingham4cda6e02011-10-07 22:23:45 +00003374 const char *name_cstr = name.GetCString();
Greg Clayton43fe2172013-04-03 02:00:15 +00003375
3376 const uint32_t original_size = sc_list.GetSize();
3377
Jim Ingham4cda6e02011-10-07 22:23:45 +00003378 DWARFDebugInfo* info = DebugInfo();
3379 if (info == NULL)
3380 return 0;
3381
Greg Claytonaa044962011-10-13 00:59:38 +00003382 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton43fe2172013-04-03 02:00:15 +00003383 std::set<const DWARFDebugInfoEntry *> resolved_dies;
Greg Clayton97fbc342011-10-20 22:30:33 +00003384 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00003385 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003386 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003387 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003388
3389 DIEArray die_offsets;
3390
3391 uint32_t num_matches = 0;
3392
Greg Clayton43fe2172013-04-03 02:00:15 +00003393 if (name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00003394 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003395 // If they asked for the full name, match what they typed. At some point we may
3396 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
3397 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00003398 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003399 for (uint32_t i = 0; i < num_matches; i++)
3400 {
Greg Clayton95d87902011-11-11 03:16:25 +00003401 const dw_offset_t die_offset = die_offsets[i];
3402 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00003403 if (die)
3404 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003405 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3406 continue;
3407
Sean Callanan9df05fb2012-02-10 22:52:19 +00003408 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3409 continue;
3410
Greg Clayton43fe2172013-04-03 02:00:15 +00003411 if (resolved_dies.find(die) == resolved_dies.end())
3412 {
3413 if (ResolveFunction (dwarf_cu, die, sc_list))
3414 resolved_dies.insert(die);
3415 }
Greg Claytonaa044962011-10-13 00:59:38 +00003416 }
Greg Clayton95d87902011-11-11 03:16:25 +00003417 else
3418 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003419 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3420 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003421 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003422 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003423 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003424
3425 if (name_type_mask & eFunctionNameTypeSelector)
3426 {
3427 if (namespace_decl && *namespace_decl)
3428 return 0; // no selectors in namespaces
Greg Clayton97fbc342011-10-20 22:30:33 +00003429
Greg Clayton43fe2172013-04-03 02:00:15 +00003430 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3431 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
3432 // and if it is an ObjC method name, we're good.
Greg Clayton97fbc342011-10-20 22:30:33 +00003433
Greg Clayton43fe2172013-04-03 02:00:15 +00003434 for (uint32_t i = 0; i < num_matches; i++)
Greg Clayton97fbc342011-10-20 22:30:33 +00003435 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003436 const dw_offset_t die_offset = die_offsets[i];
3437 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3438 if (die)
Greg Clayton97fbc342011-10-20 22:30:33 +00003439 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003440 const char *die_name = die->GetName(this, dwarf_cu);
3441 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
Greg Clayton97fbc342011-10-20 22:30:33 +00003442 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003443 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3444 continue;
3445
Greg Clayton43fe2172013-04-03 02:00:15 +00003446 if (resolved_dies.find(die) == resolved_dies.end())
3447 {
3448 if (ResolveFunction (dwarf_cu, die, sc_list))
3449 resolved_dies.insert(die);
3450 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003451 }
3452 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003453 else
3454 {
3455 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3456 die_offset, name_cstr);
3457 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003458 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003459 die_offsets.clear();
3460 }
3461
3462 if (((name_type_mask & eFunctionNameTypeMethod) && !namespace_decl) || name_type_mask & eFunctionNameTypeBase)
3463 {
3464 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
3465 // extract the base name, look that up, and if there is any other information in the name we were
3466 // passed in we have to post-filter based on that.
3467
3468 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
3469 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3470
3471 for (uint32_t i = 0; i < num_matches; i++)
3472 {
3473 const dw_offset_t die_offset = die_offsets[i];
3474 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3475 if (die)
3476 {
3477 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3478 continue;
3479
3480 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3481 continue;
3482
3483 // If we get to here, the die is good, and we should add it:
3484 if (resolved_dies.find(die) == resolved_dies.end())
3485 if (ResolveFunction (dwarf_cu, die, sc_list))
3486 {
3487 bool keep_die = true;
3488 if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod))
3489 {
3490 // We are looking for either basenames or methods, so we need to
3491 // trim out the ones we won't want by looking at the type
3492 SymbolContext sc;
3493 if (sc_list.GetLastContext(sc))
3494 {
3495 if (sc.block)
3496 {
3497 // We have an inlined function
3498 }
3499 else if (sc.function)
3500 {
3501 Type *type = sc.function->GetType();
3502
3503 clang::DeclContext* decl_ctx = GetClangDeclContextContainingTypeUID (type->GetID());
3504 if (decl_ctx->isRecord())
3505 {
3506 if (name_type_mask & eFunctionNameTypeBase)
3507 {
3508 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3509 keep_die = false;
3510 }
3511 }
3512 else
3513 {
3514 if (name_type_mask & eFunctionNameTypeMethod)
3515 {
3516 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3517 keep_die = false;
3518 }
3519 }
3520 }
3521 }
3522 }
3523 if (keep_die)
3524 resolved_dies.insert(die);
3525 }
3526 }
3527 else
3528 {
3529 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3530 die_offset, name_cstr);
3531 }
3532 }
3533 die_offsets.clear();
Jim Ingham4cda6e02011-10-07 22:23:45 +00003534 }
3535 }
Greg Clayton7f995132011-10-04 22:41:51 +00003536 }
3537 else
3538 {
3539
3540 // Index the DWARF if we haven't already
3541 if (!m_indexed)
3542 Index ();
3543
Greg Clayton7f995132011-10-04 22:41:51 +00003544 if (name_type_mask & eFunctionNameTypeFull)
3545 FindFunctions (name, m_function_fullname_index, sc_list);
3546
Jim Ingham4cda6e02011-10-07 22:23:45 +00003547 DIEArray die_offsets;
3548 DWARFCompileUnit *dwarf_cu = NULL;
3549
Greg Clayton43fe2172013-04-03 02:00:15 +00003550 if (name_type_mask & eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003551 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003552 uint32_t num_base = m_function_basename_index.Find(name, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00003553 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003554 {
Greg Claytonaa044962011-10-13 00:59:38 +00003555 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3556 if (die)
3557 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003558 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3559 continue;
3560
Sean Callanan213fdb82011-10-13 01:49:10 +00003561 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3562 continue;
3563
Greg Claytonaa044962011-10-13 00:59:38 +00003564 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00003565 if (resolved_dies.find(die) == resolved_dies.end())
3566 {
3567 if (ResolveFunction (dwarf_cu, die, sc_list))
3568 resolved_dies.insert(die);
3569 }
Greg Claytonaa044962011-10-13 00:59:38 +00003570 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003571 }
3572 die_offsets.clear();
3573 }
3574
Greg Clayton43fe2172013-04-03 02:00:15 +00003575 if (name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003576 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003577 if (namespace_decl && *namespace_decl)
3578 return 0; // no methods in namespaces
3579
Greg Clayton43fe2172013-04-03 02:00:15 +00003580 uint32_t num_base = m_function_method_index.Find(name, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003581 {
Greg Claytonaa044962011-10-13 00:59:38 +00003582 for (uint32_t i = 0; i < num_base; i++)
3583 {
3584 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3585 if (die)
3586 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003587 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3588 continue;
3589
Greg Claytonaa044962011-10-13 00:59:38 +00003590 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00003591 if (resolved_dies.find(die) == resolved_dies.end())
3592 {
3593 if (ResolveFunction (dwarf_cu, die, sc_list))
3594 resolved_dies.insert(die);
3595 }
Greg Claytonaa044962011-10-13 00:59:38 +00003596 }
3597 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003598 }
3599 die_offsets.clear();
3600 }
Greg Clayton7f995132011-10-04 22:41:51 +00003601
Greg Clayton43fe2172013-04-03 02:00:15 +00003602 if ((name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003603 {
Greg Clayton7f995132011-10-04 22:41:51 +00003604 FindFunctions (name, m_function_selector_index, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003605 }
3606
Greg Clayton4d01ace2011-09-29 16:58:15 +00003607 }
3608
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003609 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003610 const uint32_t num_matches = sc_list.GetSize() - original_size;
3611
3612 if (log && num_matches > 0)
3613 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003614 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003615 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list) => %u",
3616 name.GetCString(),
3617 name_type_mask,
3618 append,
3619 num_matches);
3620 }
3621 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003622}
3623
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003624uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00003625SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003626{
3627 Timer scoped_timer (__PRETTY_FUNCTION__,
3628 "SymbolFileDWARF::FindFunctions (regex = '%s')",
3629 regex.GetText());
3630
Greg Clayton5160ce52013-03-27 23:08:40 +00003631 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003632
3633 if (log)
3634 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003635 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003636 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
3637 regex.GetText(),
3638 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003639 }
3640
3641
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003642 // If we aren't appending the results to this list, then clear the list
3643 if (!append)
3644 sc_list.Clear();
3645
3646 // Remember how many sc_list are in the list before we search in case
3647 // we are appending the results to a variable list.
3648 uint32_t original_size = sc_list.GetSize();
3649
Greg Clayton97fbc342011-10-20 22:30:33 +00003650 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003651 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003652 if (m_apple_names_ap.get())
3653 FindFunctions (regex, *m_apple_names_ap, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003654 }
3655 else
3656 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003657 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00003658 if (!m_indexed)
3659 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003660
Greg Clayton7f995132011-10-04 22:41:51 +00003661 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003662
Greg Clayton7f995132011-10-04 22:41:51 +00003663 FindFunctions (regex, m_function_fullname_index, sc_list);
3664 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003665
3666 // Return the number of variable that were appended to the list
3667 return sc_list.GetSize() - original_size;
3668}
Jim Ingham318c9f22011-08-26 19:44:13 +00003669
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003670uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00003671SymbolFileDWARF::FindTypes (const SymbolContext& sc,
3672 const ConstString &name,
3673 const lldb_private::ClangNamespaceDecl *namespace_decl,
3674 bool append,
3675 uint32_t max_matches,
3676 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003677{
Greg Claytonc685f8e2010-09-15 04:15:46 +00003678 DWARFDebugInfo* info = DebugInfo();
3679 if (info == NULL)
3680 return 0;
3681
Greg Clayton5160ce52013-03-27 23:08:40 +00003682 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003683
3684 if (log)
3685 {
Greg Clayton437a1352012-04-09 22:43:43 +00003686 if (namespace_decl)
3687 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003688 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003689 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)",
3690 name.GetCString(),
3691 namespace_decl->GetNamespaceDecl(),
3692 namespace_decl->GetQualifiedName().c_str(),
3693 append,
3694 max_matches);
3695 }
3696 else
3697 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003698 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003699 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)",
3700 name.GetCString(),
3701 append,
3702 max_matches);
3703 }
Greg Clayton21f2a492011-10-06 00:09:08 +00003704 }
3705
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003706 // If we aren't appending the results to this list, then clear the list
3707 if (!append)
3708 types.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003709
3710 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3711 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003712
Greg Claytond4a2b372011-09-12 23:21:58 +00003713 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003714
Greg Clayton97fbc342011-10-20 22:30:33 +00003715 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003716 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003717 if (m_apple_types_ap.get())
3718 {
3719 const char *name_cstr = name.GetCString();
3720 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3721 }
Greg Clayton7f995132011-10-04 22:41:51 +00003722 }
3723 else
3724 {
3725 if (!m_indexed)
3726 Index ();
3727
3728 m_type_index.Find (name, die_offsets);
3729 }
3730
Greg Clayton437a1352012-04-09 22:43:43 +00003731 const size_t num_die_matches = die_offsets.size();
Greg Clayton7f995132011-10-04 22:41:51 +00003732
Greg Clayton437a1352012-04-09 22:43:43 +00003733 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003734 {
Greg Clayton7f995132011-10-04 22:41:51 +00003735 const uint32_t initial_types_size = types.GetSize();
3736 DWARFCompileUnit* dwarf_cu = NULL;
3737 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003738 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00003739 for (size_t i=0; i<num_die_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003740 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003741 const dw_offset_t die_offset = die_offsets[i];
3742 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3743
Greg Clayton95d87902011-11-11 03:16:25 +00003744 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00003745 {
Greg Clayton95d87902011-11-11 03:16:25 +00003746 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3747 continue;
3748
3749 Type *matching_type = ResolveType (dwarf_cu, die);
3750 if (matching_type)
3751 {
3752 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003753 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00003754 if (types.GetSize() >= max_matches)
3755 break;
3756 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00003757 }
Greg Clayton95d87902011-11-11 03:16:25 +00003758 else
3759 {
3760 if (m_using_apple_tables)
3761 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003762 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
3763 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003764 }
3765 }
3766
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003767 }
Greg Clayton437a1352012-04-09 22:43:43 +00003768 const uint32_t num_matches = types.GetSize() - initial_types_size;
3769 if (log && num_matches)
3770 {
3771 if (namespace_decl)
3772 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003773 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003774 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u",
3775 name.GetCString(),
3776 namespace_decl->GetNamespaceDecl(),
3777 namespace_decl->GetQualifiedName().c_str(),
3778 append,
3779 max_matches,
3780 num_matches);
3781 }
3782 else
3783 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003784 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003785 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u",
3786 name.GetCString(),
3787 append,
3788 max_matches,
3789 num_matches);
3790 }
3791 }
3792 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003793 }
Greg Clayton7f995132011-10-04 22:41:51 +00003794 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003795}
3796
3797
Greg Clayton526e5af2010-11-13 03:52:47 +00003798ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00003799SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00003800 const ConstString &name,
3801 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00003802{
Greg Clayton5160ce52013-03-27 23:08:40 +00003803 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003804
3805 if (log)
3806 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003807 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003808 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
3809 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00003810 }
Sean Callanan213fdb82011-10-13 01:49:10 +00003811
3812 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
3813 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00003814
Greg Clayton526e5af2010-11-13 03:52:47 +00003815 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003816 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00003817 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00003818 {
Greg Clayton7f995132011-10-04 22:41:51 +00003819 DIEArray die_offsets;
3820
Greg Clayton526e5af2010-11-13 03:52:47 +00003821 // Index if we already haven't to make sure the compile units
3822 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00003823 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003824 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003825 if (m_apple_namespaces_ap.get())
3826 {
3827 const char *name_cstr = name.GetCString();
3828 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
3829 }
Greg Clayton7f995132011-10-04 22:41:51 +00003830 }
3831 else
3832 {
3833 if (!m_indexed)
3834 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00003835
Greg Clayton7f995132011-10-04 22:41:51 +00003836 m_namespace_index.Find (name, die_offsets);
3837 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003838
3839 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00003840 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003841 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003842 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00003843 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003844 DWARFDebugInfo* debug_info = DebugInfo();
3845 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00003846 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003847 const dw_offset_t die_offset = die_offsets[i];
3848 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00003849
Greg Clayton95d87902011-11-11 03:16:25 +00003850 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00003851 {
Greg Clayton95d87902011-11-11 03:16:25 +00003852 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
3853 continue;
3854
3855 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
3856 if (clang_namespace_decl)
3857 {
3858 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
3859 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
Greg Claytond1767f02011-12-08 02:13:16 +00003860 break;
Greg Clayton95d87902011-11-11 03:16:25 +00003861 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003862 }
Greg Clayton95d87902011-11-11 03:16:25 +00003863 else
3864 {
3865 if (m_using_apple_tables)
3866 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003867 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
3868 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003869 }
3870 }
3871
Greg Clayton526e5af2010-11-13 03:52:47 +00003872 }
3873 }
Greg Clayton96d7d742010-11-10 23:42:09 +00003874 }
Greg Clayton437a1352012-04-09 22:43:43 +00003875 if (log && namespace_decl.GetNamespaceDecl())
3876 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003877 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003878 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"",
3879 name.GetCString(),
3880 namespace_decl.GetNamespaceDecl(),
3881 namespace_decl.GetQualifiedName().c_str());
3882 }
3883
Greg Clayton526e5af2010-11-13 03:52:47 +00003884 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003885}
3886
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003887uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003888SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003889{
3890 // Remember how many sc_list are in the list before we search in case
3891 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003892 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003893
3894 const uint32_t num_die_offsets = die_offsets.size();
3895 // Parse all of the types we found from the pubtypes matches
3896 uint32_t i;
3897 uint32_t num_matches = 0;
3898 for (i = 0; i < num_die_offsets; ++i)
3899 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003900 Type *matching_type = ResolveTypeUID (die_offsets[i]);
3901 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003902 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003903 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003904 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003905 ++num_matches;
3906 if (num_matches >= max_matches)
3907 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003908 }
3909 }
3910
3911 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003912 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003913}
3914
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003915
3916size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00003917SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
3918 clang::DeclContext *containing_decl_ctx,
Greg Clayton5113dc82011-08-12 06:47:54 +00003919 DWARFCompileUnit* dwarf_cu,
3920 const DWARFDebugInfoEntry *parent_die,
3921 bool skip_artificial,
3922 bool &is_static,
3923 TypeList* type_list,
3924 std::vector<clang_type_t>& function_param_types,
3925 std::vector<clang::ParmVarDecl*>& function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00003926 unsigned &type_quals,
3927 ClangASTContext::TemplateParameterInfos &template_param_infos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003928{
3929 if (parent_die == NULL)
3930 return 0;
3931
Greg Claytond88d7592010-09-15 08:33:30 +00003932 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3933
Greg Clayton7fedea22010-11-16 02:10:54 +00003934 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003935 const DWARFDebugInfoEntry *die;
3936 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3937 {
3938 dw_tag_t tag = die->Tag();
3939 switch (tag)
3940 {
3941 case DW_TAG_formal_parameter:
3942 {
3943 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003944 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003945 if (num_attributes > 0)
3946 {
3947 const char *name = NULL;
3948 Declaration decl;
3949 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003950 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003951 // one of None, Auto, Register, Extern, Static, PrivateExtern
3952
Sean Callanane2ef6e32010-09-23 03:01:22 +00003953 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003954 uint32_t i;
3955 for (i=0; i<num_attributes; ++i)
3956 {
3957 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3958 DWARFFormValue form_value;
3959 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3960 {
3961 switch (attr)
3962 {
3963 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3964 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3965 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3966 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
3967 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00003968 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003969 case DW_AT_location:
3970 // if (form_value.BlockData())
3971 // {
3972 // const DataExtractor& debug_info_data = debug_info();
3973 // uint32_t block_length = form_value.Unsigned();
3974 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
3975 // }
3976 // else
3977 // {
3978 // }
3979 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003980 case DW_AT_const_value:
3981 case DW_AT_default_value:
3982 case DW_AT_description:
3983 case DW_AT_endianity:
3984 case DW_AT_is_optional:
3985 case DW_AT_segment:
3986 case DW_AT_variable_parameter:
3987 default:
3988 case DW_AT_abstract_origin:
3989 case DW_AT_sibling:
3990 break;
3991 }
3992 }
3993 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00003994
Greg Clayton0fffff52010-09-24 05:15:53 +00003995 bool skip = false;
3996 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003997 {
Greg Clayton0fffff52010-09-24 05:15:53 +00003998 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00003999 {
4000 // In order to determine if a C++ member function is
4001 // "const" we have to look at the const-ness of "this"...
4002 // Ugly, but that
4003 if (arg_idx == 0)
4004 {
Greg Claytonf0705c82011-10-22 03:33:13 +00004005 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00004006 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004007 // Often times compilers omit the "this" name for the
4008 // specification DIEs, so we can't rely upon the name
4009 // being in the formal parameter DIE...
4010 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00004011 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004012 Type *this_type = ResolveTypeUID (param_type_die_offset);
4013 if (this_type)
4014 {
4015 uint32_t encoding_mask = this_type->GetEncodingMask();
4016 if (encoding_mask & Type::eEncodingIsPointerUID)
4017 {
4018 is_static = false;
4019
4020 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
4021 type_quals |= clang::Qualifiers::Const;
4022 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
4023 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00004024 }
4025 }
4026 }
4027 }
4028 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004029 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00004030 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004031 else
4032 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004033
Greg Clayton0fffff52010-09-24 05:15:53 +00004034 // HACK: Objective C formal parameters "self" and "_cmd"
4035 // are not marked as artificial in the DWARF...
Greg Clayton53eb1c22012-04-02 22:59:12 +00004036 CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
4037 if (comp_unit)
Greg Clayton0fffff52010-09-24 05:15:53 +00004038 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004039 switch (comp_unit->GetLanguage())
4040 {
4041 case eLanguageTypeObjC:
4042 case eLanguageTypeObjC_plus_plus:
4043 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
4044 skip = true;
4045 break;
4046 default:
4047 break;
4048 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004049 }
4050 }
4051 }
4052
4053 if (!skip)
4054 {
4055 Type *type = ResolveTypeUID(param_type_die_offset);
4056 if (type)
4057 {
Greg Claytonc93237c2010-10-01 20:48:32 +00004058 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00004059
Greg Clayton42ce2f32011-12-12 21:50:19 +00004060 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
4061 type->GetClangForwardType(),
4062 storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00004063 assert(param_var_decl);
4064 function_param_decls.push_back(param_var_decl);
Sean Callanan60217122012-04-13 00:10:03 +00004065
Greg Claytond0029442013-03-27 01:48:02 +00004066 GetClangASTContext().SetMetadataAsUserID (param_var_decl, MakeUserID(die->GetOffset()));
Greg Clayton0fffff52010-09-24 05:15:53 +00004067 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004068 }
4069 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004070 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004071 }
4072 break;
4073
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004074 case DW_TAG_template_type_parameter:
4075 case DW_TAG_template_value_parameter:
4076 ParseTemplateDIE (dwarf_cu, die,template_param_infos);
4077 break;
4078
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004079 default:
4080 break;
4081 }
4082 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004083 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004084}
4085
4086size_t
4087SymbolFileDWARF::ParseChildEnumerators
4088(
4089 const SymbolContext& sc,
Greg Clayton3e067532013-03-05 23:54:39 +00004090 clang_type_t enumerator_clang_type,
4091 bool is_signed,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004092 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00004093 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004094 const DWARFDebugInfoEntry *parent_die
4095)
4096{
4097 if (parent_die == NULL)
4098 return 0;
4099
4100 size_t enumerators_added = 0;
4101 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00004102 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
4103
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004104 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4105 {
4106 const dw_tag_t tag = die->Tag();
4107 if (tag == DW_TAG_enumerator)
4108 {
4109 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004110 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004111 if (num_child_attributes > 0)
4112 {
4113 const char *name = NULL;
4114 bool got_value = false;
4115 int64_t enum_value = 0;
4116 Declaration decl;
4117
4118 uint32_t i;
4119 for (i=0; i<num_child_attributes; ++i)
4120 {
4121 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4122 DWARFFormValue form_value;
4123 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4124 {
4125 switch (attr)
4126 {
4127 case DW_AT_const_value:
4128 got_value = true;
Greg Clayton3e067532013-03-05 23:54:39 +00004129 if (is_signed)
4130 enum_value = form_value.Signed();
4131 else
4132 enum_value = form_value.Unsigned();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004133 break;
4134
4135 case DW_AT_name:
4136 name = form_value.AsCString(&get_debug_str_data());
4137 break;
4138
4139 case DW_AT_description:
4140 default:
4141 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4142 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4143 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4144 case DW_AT_sibling:
4145 break;
4146 }
4147 }
4148 }
4149
4150 if (name && name[0] && got_value)
4151 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004152 GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
4153 enumerator_clang_type,
4154 decl,
4155 name,
4156 enum_value,
4157 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004158 ++enumerators_added;
4159 }
4160 }
4161 }
4162 }
4163 return enumerators_added;
4164}
4165
4166void
4167SymbolFileDWARF::ParseChildArrayInfo
4168(
4169 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004170 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004171 const DWARFDebugInfoEntry *parent_die,
4172 int64_t& first_index,
4173 std::vector<uint64_t>& element_orders,
4174 uint32_t& byte_stride,
4175 uint32_t& bit_stride
4176)
4177{
4178 if (parent_die == NULL)
4179 return;
4180
4181 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00004182 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004183 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4184 {
4185 const dw_tag_t tag = die->Tag();
4186 switch (tag)
4187 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004188 case DW_TAG_subrange_type:
4189 {
4190 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004191 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004192 if (num_child_attributes > 0)
4193 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004194 uint64_t num_elements = 0;
4195 uint64_t lower_bound = 0;
4196 uint64_t upper_bound = 0;
Greg Clayton4ef877f2012-12-06 02:33:54 +00004197 bool upper_bound_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004198 uint32_t i;
4199 for (i=0; i<num_child_attributes; ++i)
4200 {
4201 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4202 DWARFFormValue form_value;
4203 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4204 {
4205 switch (attr)
4206 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004207 case DW_AT_name:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004208 break;
4209
4210 case DW_AT_count:
4211 num_elements = form_value.Unsigned();
4212 break;
4213
4214 case DW_AT_bit_stride:
4215 bit_stride = form_value.Unsigned();
4216 break;
4217
4218 case DW_AT_byte_stride:
4219 byte_stride = form_value.Unsigned();
4220 break;
4221
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004222 case DW_AT_lower_bound:
4223 lower_bound = form_value.Unsigned();
4224 break;
4225
4226 case DW_AT_upper_bound:
Greg Clayton4ef877f2012-12-06 02:33:54 +00004227 upper_bound_valid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004228 upper_bound = form_value.Unsigned();
4229 break;
4230
4231 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004232 case DW_AT_abstract_origin:
4233 case DW_AT_accessibility:
4234 case DW_AT_allocated:
4235 case DW_AT_associated:
4236 case DW_AT_data_location:
4237 case DW_AT_declaration:
4238 case DW_AT_description:
4239 case DW_AT_sibling:
4240 case DW_AT_threads_scaled:
4241 case DW_AT_type:
4242 case DW_AT_visibility:
4243 break;
4244 }
4245 }
4246 }
4247
Greg Claytone6a07792012-12-05 21:59:39 +00004248 if (num_elements == 0)
4249 {
Greg Clayton4ef877f2012-12-06 02:33:54 +00004250 if (upper_bound_valid && upper_bound >= lower_bound)
Greg Claytone6a07792012-12-05 21:59:39 +00004251 num_elements = upper_bound - lower_bound + 1;
4252 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004253
Sean Callananec979ba2012-10-22 23:56:48 +00004254 element_orders.push_back (num_elements);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004255 }
4256 }
4257 break;
4258 }
4259 }
4260}
4261
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004262TypeSP
Greg Clayton53eb1c22012-04-02 22:59:12 +00004263SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004264{
4265 TypeSP type_sp;
4266 if (die != NULL)
4267 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004268 assert(dwarf_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00004269 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004270 if (type_ptr == NULL)
4271 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004272 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu);
Greg Claytonca512b32011-01-14 04:54:56 +00004273 assert (lldb_cu);
4274 SymbolContext sc(lldb_cu);
Greg Clayton53eb1c22012-04-02 22:59:12 +00004275 type_sp = ParseType(sc, dwarf_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004276 }
4277 else if (type_ptr != DIE_IS_BEING_PARSED)
4278 {
4279 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00004280 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004281 }
4282
4283 }
4284 return type_sp;
4285}
4286
4287clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00004288SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004289{
4290 if (die_offset != DW_INVALID_OFFSET)
4291 {
4292 DWARFCompileUnitSP cu_sp;
4293 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004294 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004295 }
4296 return NULL;
4297}
4298
Sean Callanan72e49402011-08-05 23:43:37 +00004299clang::DeclContext *
4300SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
4301{
4302 if (die_offset != DW_INVALID_OFFSET)
4303 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004304 DWARFDebugInfo* debug_info = DebugInfo();
4305 if (debug_info)
4306 {
4307 DWARFCompileUnitSP cu_sp;
4308 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
4309 if (die)
4310 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
4311 }
Sean Callanan72e49402011-08-05 23:43:37 +00004312 }
4313 return NULL;
4314}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004315
Greg Clayton96d7d742010-11-10 23:42:09 +00004316clang::NamespaceDecl *
Greg Clayton53eb1c22012-04-02 22:59:12 +00004317SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die)
Greg Clayton96d7d742010-11-10 23:42:09 +00004318{
Greg Clayton030a2042011-10-14 21:34:45 +00004319 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00004320 {
Greg Clayton030a2042011-10-14 21:34:45 +00004321 // See if we already parsed this namespace DIE and associated it with a
4322 // uniqued namespace declaration
4323 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
4324 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004325 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00004326 else
4327 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004328 const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL);
4329 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00004330 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
Greg Clayton5160ce52013-03-27 23:08:40 +00004331 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton9d3d6882011-10-31 23:51:19 +00004332 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00004333 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00004334 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00004335 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004336 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00004337 "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 +00004338 GetClangASTContext().getASTContext(),
4339 MakeUserID(die->GetOffset()),
4340 namespace_name,
4341 namespace_decl,
4342 namespace_decl->getOriginalNamespace());
Greg Clayton030a2042011-10-14 21:34:45 +00004343 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004344 else
4345 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004346 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00004347 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
Greg Claytone38a5ed2012-01-05 03:57:59 +00004348 GetClangASTContext().getASTContext(),
4349 MakeUserID(die->GetOffset()),
4350 namespace_decl,
4351 namespace_decl->getOriginalNamespace());
Greg Clayton9d3d6882011-10-31 23:51:19 +00004352 }
Greg Clayton030a2042011-10-14 21:34:45 +00004353 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004354
4355 if (namespace_decl)
4356 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
4357 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004358 }
4359 }
4360 return NULL;
4361}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004362
4363clang::DeclContext *
Greg Claytoncab36a32011-12-08 05:16:30 +00004364SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Sean Callanan72e49402011-08-05 23:43:37 +00004365{
Greg Clayton5cf58b92011-10-05 22:22:08 +00004366 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4367 if (clang_decl_ctx)
4368 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004369 // If this DIE has a specification, or an abstract origin, then trace to those.
4370
Greg Claytoncab36a32011-12-08 05:16:30 +00004371 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004372 if (die_offset != DW_INVALID_OFFSET)
4373 return GetClangDeclContextForDIEOffset (sc, die_offset);
4374
Greg Claytoncab36a32011-12-08 05:16:30 +00004375 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004376 if (die_offset != DW_INVALID_OFFSET)
4377 return GetClangDeclContextForDIEOffset (sc, die_offset);
4378
Greg Clayton5160ce52013-03-27 23:08:40 +00004379 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00004380 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004381 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 +00004382 // This is the DIE we want. Parse it, then query our map.
Greg Claytoncab36a32011-12-08 05:16:30 +00004383 bool assert_not_being_parsed = true;
4384 ResolveTypeUID (cu, die, assert_not_being_parsed);
4385
Greg Clayton5cf58b92011-10-05 22:22:08 +00004386 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4387
4388 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004389}
4390
4391clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00004392SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004393{
Greg Claytonca512b32011-01-14 04:54:56 +00004394 if (m_clang_tu_decl == NULL)
4395 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004396
Greg Clayton2bc22f82011-09-30 03:20:47 +00004397 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004398
4399 if (decl_ctx_die_copy)
4400 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00004401
4402 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004403 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00004404
Greg Clayton2bc22f82011-09-30 03:20:47 +00004405 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
4406 if (pos != m_die_to_decl_ctx.end())
4407 return pos->second;
4408
4409 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004410 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004411 case DW_TAG_compile_unit:
4412 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004413
Greg Clayton2bc22f82011-09-30 03:20:47 +00004414 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00004415 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00004416 break;
4417
4418 case DW_TAG_structure_type:
4419 case DW_TAG_union_type:
4420 case DW_TAG_class_type:
4421 {
4422 Type* type = ResolveType (cu, decl_ctx_die);
4423 if (type)
4424 {
4425 clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ());
4426 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00004427 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004428 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
4429 if (decl_ctx)
4430 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00004431 }
4432 }
Greg Claytonca512b32011-01-14 04:54:56 +00004433 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00004434 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004435
Greg Clayton2bc22f82011-09-30 03:20:47 +00004436 default:
4437 break;
Greg Claytonca512b32011-01-14 04:54:56 +00004438 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004439 }
Greg Clayton7a345282010-11-09 23:46:37 +00004440 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004441}
4442
Greg Clayton2bc22f82011-09-30 03:20:47 +00004443
4444const DWARFDebugInfoEntry *
4445SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4446{
4447 if (cu && die)
4448 {
4449 const DWARFDebugInfoEntry * const decl_die = die;
4450
4451 while (die != NULL)
4452 {
4453 // If this is the original DIE that we are searching for a declaration
4454 // for, then don't look in the cache as we don't want our own decl
4455 // context to be our decl context...
4456 if (decl_die != die)
4457 {
4458 switch (die->Tag())
4459 {
4460 case DW_TAG_compile_unit:
4461 case DW_TAG_namespace:
4462 case DW_TAG_structure_type:
4463 case DW_TAG_union_type:
4464 case DW_TAG_class_type:
4465 return die;
4466
4467 default:
4468 break;
4469 }
4470 }
4471
4472 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4473 if (die_offset != DW_INVALID_OFFSET)
4474 {
4475 DWARFCompileUnit *spec_cu = cu;
4476 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
4477 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
4478 if (spec_die_decl_ctx_die)
4479 return spec_die_decl_ctx_die;
4480 }
4481
4482 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
4483 if (die_offset != DW_INVALID_OFFSET)
4484 {
4485 DWARFCompileUnit *abs_cu = cu;
4486 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
4487 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
4488 if (abs_die_decl_ctx_die)
4489 return abs_die_decl_ctx_die;
4490 }
4491
4492 die = die->GetParent();
4493 }
4494 }
4495 return NULL;
4496}
4497
4498
Greg Clayton901c5ca2011-12-03 04:40:03 +00004499Symbol *
4500SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
4501{
4502 Symbol *objc_class_symbol = NULL;
4503 if (m_obj_file)
4504 {
4505 Symtab *symtab = m_obj_file->GetSymtab();
4506 if (symtab)
4507 {
4508 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
4509 eSymbolTypeObjCClass,
4510 Symtab::eDebugNo,
4511 Symtab::eVisibilityAny);
4512 }
4513 }
4514 return objc_class_symbol;
4515}
4516
Greg Claytonc7f03b62012-01-12 04:33:28 +00004517// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
4518// then we can end up looking through all class types for a complete type and never find
4519// the full definition. We need to know if this attribute is supported, so we determine
4520// this here and cache th result. We also need to worry about the debug map DWARF file
4521// if we are doing darwin DWARF in .o file debugging.
4522bool
4523SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
4524{
4525 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
4526 {
4527 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
4528 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
4529 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4530 else
4531 {
4532 DWARFDebugInfo* debug_info = DebugInfo();
4533 const uint32_t num_compile_units = GetNumCompileUnits();
4534 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
4535 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004536 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
4537 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004538 {
4539 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4540 break;
4541 }
4542 }
4543 }
Greg Clayton1f746072012-08-29 21:13:06 +00004544 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004545 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
4546 }
4547 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
4548}
Greg Clayton901c5ca2011-12-03 04:40:03 +00004549
4550// This function can be used when a DIE is found that is a forward declaration
4551// DIE and we want to try and find a type that has the complete definition.
4552TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00004553SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
4554 const ConstString &type_name,
4555 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00004556{
4557
4558 TypeSP type_sp;
4559
Greg Claytonc7f03b62012-01-12 04:33:28 +00004560 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00004561 return type_sp;
4562
4563 DIEArray die_offsets;
4564
4565 if (m_using_apple_tables)
4566 {
4567 if (m_apple_types_ap.get())
4568 {
4569 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00004570 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004571 }
4572 }
4573 else
4574 {
4575 if (!m_indexed)
4576 Index ();
4577
4578 m_type_index.Find (type_name, die_offsets);
4579 }
4580
Greg Clayton901c5ca2011-12-03 04:40:03 +00004581 const size_t num_matches = die_offsets.size();
4582
Greg Clayton901c5ca2011-12-03 04:40:03 +00004583 DWARFCompileUnit* type_cu = NULL;
4584 const DWARFDebugInfoEntry* type_die = NULL;
4585 if (num_matches)
4586 {
4587 DWARFDebugInfo* debug_info = DebugInfo();
4588 for (size_t i=0; i<num_matches; ++i)
4589 {
4590 const dw_offset_t die_offset = die_offsets[i];
4591 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4592
4593 if (type_die)
4594 {
4595 bool try_resolving_type = false;
4596
4597 // Don't try and resolve the DIE we are looking for with the DIE itself!
4598 if (type_die != die)
4599 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004600 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00004601 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004602 case DW_TAG_class_type:
4603 case DW_TAG_structure_type:
4604 try_resolving_type = true;
4605 break;
4606 default:
4607 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00004608 }
4609 }
4610
4611 if (try_resolving_type)
4612 {
Sean Callanana9bc0652012-01-19 02:17:40 +00004613 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004614 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004615
4616 if (try_resolving_type)
4617 {
4618 Type *resolved_type = ResolveType (type_cu, type_die, false);
4619 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4620 {
Daniel Malead01b2952012-11-29 21:49:15 +00004621 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 +00004622 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00004623 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton901c5ca2011-12-03 04:40:03 +00004624 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4625 MakeUserID(type_die->GetOffset()),
4626 MakeUserID(type_cu->GetOffset()));
4627
Greg Claytonc7f03b62012-01-12 04:33:28 +00004628 if (die)
4629 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00004630 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00004631 break;
4632 }
4633 }
4634 }
4635 }
4636 else
4637 {
4638 if (m_using_apple_tables)
4639 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004640 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4641 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00004642 }
4643 }
4644
4645 }
4646 }
4647 return type_sp;
4648}
4649
Greg Claytona8022fa2012-04-24 21:22:41 +00004650
Greg Clayton80c26302012-02-05 06:12:47 +00004651//----------------------------------------------------------------------
4652// This function helps to ensure that the declaration contexts match for
4653// two different DIEs. Often times debug information will refer to a
4654// forward declaration of a type (the equivalent of "struct my_struct;".
4655// There will often be a declaration of that type elsewhere that has the
4656// full definition. When we go looking for the full type "my_struct", we
4657// will find one or more matches in the accelerator tables and we will
4658// then need to make sure the type was in the same declaration context
4659// as the original DIE. This function can efficiently compare two DIEs
4660// and will return true when the declaration context matches, and false
4661// when they don't.
4662//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00004663bool
4664SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
4665 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
4666{
Greg Claytona8022fa2012-04-24 21:22:41 +00004667 if (die1 == die2)
4668 return true;
4669
4670#if defined (LLDB_CONFIGURATION_DEBUG)
4671 // You can't and shouldn't call this function with a compile unit from
4672 // two different SymbolFileDWARF instances.
4673 assert (DebugInfo()->ContainsCompileUnit (cu1));
4674 assert (DebugInfo()->ContainsCompileUnit (cu2));
4675#endif
4676
Greg Clayton890ff562012-02-02 05:48:16 +00004677 DWARFDIECollection decl_ctx_1;
4678 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00004679 //The declaration DIE stack is a stack of the declaration context
4680 // DIEs all the way back to the compile unit. If a type "T" is
4681 // declared inside a class "B", and class "B" is declared inside
4682 // a class "A" and class "A" is in a namespace "lldb", and the
4683 // namespace is in a compile unit, there will be a stack of DIEs:
4684 //
4685 // [0] DW_TAG_class_type for "B"
4686 // [1] DW_TAG_class_type for "A"
4687 // [2] DW_TAG_namespace for "lldb"
4688 // [3] DW_TAG_compile_unit for the source file.
4689 //
4690 // We grab both contexts and make sure that everything matches
4691 // all the way back to the compiler unit.
4692
4693 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00004694 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004695 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00004696 // Make sure the context arrays have the same size, otherwise
4697 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00004698 const size_t count1 = decl_ctx_1.Size();
4699 const size_t count2 = decl_ctx_2.Size();
4700 if (count1 != count2)
4701 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00004702
4703 // Make sure the DW_TAG values match all the way back up the the
4704 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00004705 const DWARFDebugInfoEntry *decl_ctx_die1;
4706 const DWARFDebugInfoEntry *decl_ctx_die2;
4707 size_t i;
4708 for (i=0; i<count1; i++)
4709 {
4710 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4711 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4712 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
4713 return false;
4714 }
Greg Clayton890ff562012-02-02 05:48:16 +00004715#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00004716
4717 // Make sure the top item in the decl context die array is always
4718 // DW_TAG_compile_unit. If it isn't then something went wrong in
4719 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00004720 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00004721
Greg Clayton890ff562012-02-02 05:48:16 +00004722#endif
4723 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00004724 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00004725 for (i=0; i<count1 - 1; i++)
4726 {
4727 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4728 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4729 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004730 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00004731 // If the string was from a DW_FORM_strp, then the pointer will often
4732 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00004733 if (name1 == name2)
4734 continue;
4735
4736 // Name pointers are not equal, so only compare the strings
4737 // if both are not NULL.
4738 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00004739 {
Greg Clayton5569e642012-02-06 01:44:54 +00004740 // If the strings don't compare, we are done...
4741 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00004742 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00004743 }
4744 else
4745 {
4746 // One name was NULL while the other wasn't
4747 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00004748 }
4749 }
Greg Clayton80c26302012-02-05 06:12:47 +00004750 // We made it through all of the checks and the declaration contexts
4751 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00004752 return true;
4753}
Greg Clayton220a0072011-12-09 08:48:30 +00004754
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004755// This function can be used when a DIE is found that is a forward declaration
4756// DIE and we want to try and find a type that has the complete definition.
Greg Claytona8022fa2012-04-24 21:22:41 +00004757// "cu" and "die" must be from this SymbolFileDWARF
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004758TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00004759SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
Greg Clayton7f995132011-10-04 22:41:51 +00004760 const DWARFDebugInfoEntry *die,
4761 const ConstString &type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004762{
4763 TypeSP type_sp;
4764
Greg Claytona8022fa2012-04-24 21:22:41 +00004765#if defined (LLDB_CONFIGURATION_DEBUG)
4766 // You can't and shouldn't call this function with a compile unit from
4767 // another SymbolFileDWARF instance.
4768 assert (DebugInfo()->ContainsCompileUnit (cu));
4769#endif
4770
Greg Clayton1a65ae12011-01-25 23:55:37 +00004771 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004772 return type_sp;
4773
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004774 std::string qualified_name;
4775
Greg Clayton5160ce52013-03-27 23:08:40 +00004776 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004777 if (log)
4778 {
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004779 die->GetQualifiedName(this, cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00004780 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004781 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x (%s), name='%s')",
4782 die->GetOffset(),
4783 qualified_name.c_str(),
4784 type_name.GetCString());
4785 }
4786
Greg Clayton7f995132011-10-04 22:41:51 +00004787 DIEArray die_offsets;
4788
Greg Clayton97fbc342011-10-20 22:30:33 +00004789 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004790 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004791 if (m_apple_types_ap.get())
4792 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004793 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
4794 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
4795 if (has_tag && has_qualified_name_hash)
Greg Claytond1767f02011-12-08 02:13:16 +00004796 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004797 if (qualified_name.empty())
4798 die->GetQualifiedName(this, cu, qualified_name);
4799
4800 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name.c_str());
4801 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004802 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004803 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), die->Tag(), qualified_name_hash, die_offsets);
4804 }
4805 else if (has_tag > 1)
4806 {
4807 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004808 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
Greg Claytonae920b62012-01-06 00:17:16 +00004809 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets);
Greg Claytond1767f02011-12-08 02:13:16 +00004810 }
4811 else
4812 {
4813 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
4814 }
Greg Clayton97fbc342011-10-20 22:30:33 +00004815 }
Greg Clayton7f995132011-10-04 22:41:51 +00004816 }
4817 else
4818 {
4819 if (!m_indexed)
4820 Index ();
4821
4822 m_type_index.Find (type_name, die_offsets);
4823 }
Greg Clayton7f995132011-10-04 22:41:51 +00004824
4825 const size_t num_matches = die_offsets.size();
Greg Clayton69974892010-12-03 21:42:06 +00004826
Greg Clayton934cb052011-12-03 00:27:05 +00004827 const dw_tag_t die_tag = die->Tag();
Greg Claytond4a2b372011-09-12 23:21:58 +00004828
4829 DWARFCompileUnit* type_cu = NULL;
4830 const DWARFDebugInfoEntry* type_die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00004831 if (num_matches)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004832 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004833 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004834 for (size_t i=0; i<num_matches; ++i)
4835 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004836 const dw_offset_t die_offset = die_offsets[i];
4837 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004838
Greg Clayton95d87902011-11-11 03:16:25 +00004839 if (type_die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004840 {
Greg Clayton934cb052011-12-03 00:27:05 +00004841 bool try_resolving_type = false;
4842
4843 // Don't try and resolve the DIE we are looking for with the DIE itself!
4844 if (type_die != die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004845 {
Greg Clayton934cb052011-12-03 00:27:05 +00004846 const dw_tag_t type_die_tag = type_die->Tag();
4847 // Make sure the tags match
4848 if (type_die_tag == die_tag)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004849 {
Greg Clayton934cb052011-12-03 00:27:05 +00004850 // The tags match, lets try resolving this type
4851 try_resolving_type = true;
4852 }
4853 else
4854 {
4855 // The tags don't match, but we need to watch our for a
4856 // forward declaration for a struct and ("struct foo")
4857 // ends up being a class ("class foo { ... };") or
4858 // vice versa.
4859 switch (type_die_tag)
Greg Clayton95d87902011-11-11 03:16:25 +00004860 {
Greg Clayton934cb052011-12-03 00:27:05 +00004861 case DW_TAG_class_type:
4862 // We had a "class foo", see if we ended up with a "struct foo { ... };"
4863 try_resolving_type = (die_tag == DW_TAG_structure_type);
4864 break;
4865 case DW_TAG_structure_type:
4866 // We had a "struct foo", see if we ended up with a "class foo { ... };"
4867 try_resolving_type = (die_tag == DW_TAG_class_type);
4868 break;
4869 default:
4870 // Tags don't match, don't event try to resolve
4871 // using this type whose name matches....
Greg Clayton95d87902011-11-11 03:16:25 +00004872 break;
4873 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004874 }
4875 }
Greg Clayton934cb052011-12-03 00:27:05 +00004876
4877 if (try_resolving_type)
4878 {
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004879 if (log)
4880 {
4881 std::string qualified_name;
4882 type_die->GetQualifiedName(this, cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00004883 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004884 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') trying die=0x%8.8x (%s)",
4885 die->GetOffset(),
4886 type_name.GetCString(),
4887 type_die->GetOffset(),
4888 qualified_name.c_str());
4889 }
4890
Greg Clayton890ff562012-02-02 05:48:16 +00004891 // Make sure the decl contexts match all the way up
4892 if (DIEDeclContextsMatch(cu, die, type_cu, type_die))
Greg Clayton934cb052011-12-03 00:27:05 +00004893 {
Greg Clayton890ff562012-02-02 05:48:16 +00004894 Type *resolved_type = ResolveType (type_cu, type_die, false);
4895 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4896 {
Daniel Malead01b2952012-11-29 21:49:15 +00004897 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 +00004898 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00004899 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton890ff562012-02-02 05:48:16 +00004900 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4901 MakeUserID(type_die->GetOffset()),
4902 MakeUserID(type_cu->GetOffset()));
4903
4904 m_die_to_type[die] = resolved_type;
Greg Claytonff7692a2012-02-02 18:16:59 +00004905 type_sp = resolved_type->shared_from_this();
Greg Clayton890ff562012-02-02 05:48:16 +00004906 break;
4907 }
Greg Clayton934cb052011-12-03 00:27:05 +00004908 }
4909 }
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004910 else
4911 {
4912 if (log)
4913 {
4914 std::string qualified_name;
4915 type_die->GetQualifiedName(this, cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00004916 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004917 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') ignoring die=0x%8.8x (%s)",
4918 die->GetOffset(),
4919 type_name.GetCString(),
4920 type_die->GetOffset(),
4921 qualified_name.c_str());
4922 }
4923 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004924 }
Greg Clayton95d87902011-11-11 03:16:25 +00004925 else
4926 {
4927 if (m_using_apple_tables)
4928 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004929 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4930 die_offset, type_name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004931 }
4932 }
4933
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004934 }
4935 }
4936 return type_sp;
4937}
4938
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004939TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00004940SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx)
4941{
4942 TypeSP type_sp;
4943
4944 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
4945 if (dwarf_decl_ctx_count > 0)
4946 {
4947 const ConstString type_name(dwarf_decl_ctx[0].name);
4948 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
4949
4950 if (type_name)
4951 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004952 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
Greg Claytona8022fa2012-04-24 21:22:41 +00004953 if (log)
4954 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004955 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00004956 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')",
4957 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
4958 dwarf_decl_ctx.GetQualifiedName());
4959 }
4960
4961 DIEArray die_offsets;
4962
4963 if (m_using_apple_tables)
4964 {
4965 if (m_apple_types_ap.get())
4966 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004967 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
4968 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
4969 if (has_tag && has_qualified_name_hash)
Greg Claytona8022fa2012-04-24 21:22:41 +00004970 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004971 const char *qualified_name = dwarf_decl_ctx.GetQualifiedName();
4972 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name);
4973 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004974 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004975 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets);
4976 }
4977 else if (has_tag)
4978 {
4979 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004980 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
Greg Claytona8022fa2012-04-24 21:22:41 +00004981 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets);
4982 }
4983 else
4984 {
4985 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
4986 }
4987 }
4988 }
4989 else
4990 {
4991 if (!m_indexed)
4992 Index ();
4993
4994 m_type_index.Find (type_name, die_offsets);
4995 }
4996
4997 const size_t num_matches = die_offsets.size();
4998
4999
5000 DWARFCompileUnit* type_cu = NULL;
5001 const DWARFDebugInfoEntry* type_die = NULL;
5002 if (num_matches)
5003 {
5004 DWARFDebugInfo* debug_info = DebugInfo();
5005 for (size_t i=0; i<num_matches; ++i)
5006 {
5007 const dw_offset_t die_offset = die_offsets[i];
5008 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
5009
5010 if (type_die)
5011 {
5012 bool try_resolving_type = false;
5013
5014 // Don't try and resolve the DIE we are looking for with the DIE itself!
5015 const dw_tag_t type_tag = type_die->Tag();
5016 // Make sure the tags match
5017 if (type_tag == tag)
5018 {
5019 // The tags match, lets try resolving this type
5020 try_resolving_type = true;
5021 }
5022 else
5023 {
5024 // The tags don't match, but we need to watch our for a
5025 // forward declaration for a struct and ("struct foo")
5026 // ends up being a class ("class foo { ... };") or
5027 // vice versa.
5028 switch (type_tag)
5029 {
5030 case DW_TAG_class_type:
5031 // We had a "class foo", see if we ended up with a "struct foo { ... };"
5032 try_resolving_type = (tag == DW_TAG_structure_type);
5033 break;
5034 case DW_TAG_structure_type:
5035 // We had a "struct foo", see if we ended up with a "class foo { ... };"
5036 try_resolving_type = (tag == DW_TAG_class_type);
5037 break;
5038 default:
5039 // Tags don't match, don't event try to resolve
5040 // using this type whose name matches....
5041 break;
5042 }
5043 }
5044
5045 if (try_resolving_type)
5046 {
5047 DWARFDeclContext type_dwarf_decl_ctx;
5048 type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx);
5049
5050 if (log)
5051 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005052 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005053 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)",
5054 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5055 dwarf_decl_ctx.GetQualifiedName(),
5056 type_die->GetOffset(),
5057 type_dwarf_decl_ctx.GetQualifiedName());
5058 }
5059
5060 // Make sure the decl contexts match all the way up
5061 if (dwarf_decl_ctx == type_dwarf_decl_ctx)
5062 {
5063 Type *resolved_type = ResolveType (type_cu, type_die, false);
5064 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5065 {
5066 type_sp = resolved_type->shared_from_this();
5067 break;
5068 }
5069 }
5070 }
5071 else
5072 {
5073 if (log)
5074 {
5075 std::string qualified_name;
5076 type_die->GetQualifiedName(this, type_cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00005077 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005078 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)",
5079 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5080 dwarf_decl_ctx.GetQualifiedName(),
5081 type_die->GetOffset(),
5082 qualified_name.c_str());
5083 }
5084 }
5085 }
5086 else
5087 {
5088 if (m_using_apple_tables)
5089 {
5090 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5091 die_offset, type_name.GetCString());
5092 }
5093 }
5094
5095 }
5096 }
5097 }
5098 }
5099 return type_sp;
5100}
5101
Greg Clayton4116e932012-05-15 02:33:01 +00005102bool
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005103SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005104 Type *class_type,
Greg Clayton4116e932012-05-15 02:33:01 +00005105 DWARFCompileUnit* src_cu,
5106 const DWARFDebugInfoEntry *src_class_die,
5107 DWARFCompileUnit* dst_cu,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005108 const DWARFDebugInfoEntry *dst_class_die,
5109 llvm::SmallVectorImpl <const DWARFDebugInfoEntry *> &failures)
Greg Clayton4116e932012-05-15 02:33:01 +00005110{
5111 if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die)
5112 return false;
5113 if (src_class_die->Tag() != dst_class_die->Tag())
5114 return false;
5115
5116 // We need to complete the class type so we can get all of the method types
5117 // parsed so we can then unique those types to their equivalent counterparts
5118 // in "dst_cu" and "dst_class_die"
5119 class_type->GetClangFullType();
5120
5121 const DWARFDebugInfoEntry *src_die;
5122 const DWARFDebugInfoEntry *dst_die;
5123 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die;
5124 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die;
Greg Clayton65ec1032012-11-12 21:27:20 +00005125 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial;
5126 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial;
Greg Clayton4116e932012-05-15 02:33:01 +00005127 for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling())
5128 {
5129 if (src_die->Tag() == DW_TAG_subprogram)
5130 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005131 // Make sure this is a declaration and not a concrete instance by looking
5132 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5133 // are placed inside the class definitions and shouldn't be included in
5134 // the list of things are are tracking here.
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005135 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_declaration, 0) == 1)
Greg Clayton84afacd2012-11-07 23:09:32 +00005136 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005137 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton84afacd2012-11-07 23:09:32 +00005138 if (src_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005139 {
5140 ConstString src_const_name(src_name);
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005141 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0))
Greg Clayton65ec1032012-11-12 21:27:20 +00005142 src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die);
5143 else
5144 src_name_to_die.Append(src_const_name.GetCString(), src_die);
5145 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005146 }
Greg Clayton4116e932012-05-15 02:33:01 +00005147 }
5148 }
5149 for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling())
5150 {
5151 if (dst_die->Tag() == DW_TAG_subprogram)
5152 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005153 // Make sure this is a declaration and not a concrete instance by looking
5154 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5155 // are placed inside the class definitions and shouldn't be included in
5156 // the list of things are are tracking here.
5157 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1)
5158 {
5159 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5160 if (dst_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005161 {
5162 ConstString dst_const_name(dst_name);
5163 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0))
5164 dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die);
5165 else
5166 dst_name_to_die.Append(dst_const_name.GetCString(), dst_die);
5167 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005168 }
Greg Clayton4116e932012-05-15 02:33:01 +00005169 }
5170 }
5171 const uint32_t src_size = src_name_to_die.GetSize ();
5172 const uint32_t dst_size = dst_name_to_die.GetSize ();
Greg Clayton5160ce52013-03-27 23:08:40 +00005173 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005174
5175 // Is everything kosher so we can go through the members at top speed?
5176 bool fast_path = true;
5177
5178 if (src_size != dst_size)
Greg Clayton4116e932012-05-15 02:33:01 +00005179 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005180 if (src_size != 0 && dst_size != 0)
5181 {
5182 if (log)
5183 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)",
5184 src_class_die->GetOffset(),
5185 dst_class_die->GetOffset(),
5186 src_size,
5187 dst_size);
5188 }
5189
5190 fast_path = false;
5191 }
5192
5193 uint32_t idx;
5194
5195 if (fast_path)
5196 {
Greg Clayton4116e932012-05-15 02:33:01 +00005197 for (idx = 0; idx < src_size; ++idx)
5198 {
5199 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5200 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5201
5202 if (src_die->Tag() != dst_die->Tag())
5203 {
5204 if (log)
5205 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)",
5206 src_class_die->GetOffset(),
5207 dst_class_die->GetOffset(),
5208 src_die->GetOffset(),
5209 DW_TAG_value_to_name(src_die->Tag()),
5210 dst_die->GetOffset(),
5211 DW_TAG_value_to_name(src_die->Tag()));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005212 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005213 }
5214
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005215 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton4116e932012-05-15 02:33:01 +00005216 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5217
5218 // Make sure the names match
5219 if (src_name == dst_name || (strcmp (src_name, dst_name) == 0))
5220 continue;
5221
5222 if (log)
5223 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)",
5224 src_class_die->GetOffset(),
5225 dst_class_die->GetOffset(),
5226 src_die->GetOffset(),
5227 src_name,
5228 dst_die->GetOffset(),
5229 dst_name);
5230
Sean Callanan2367f8a2013-02-26 01:12:25 +00005231 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005232 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005233 }
Greg Clayton4116e932012-05-15 02:33:01 +00005234
Sean Callanan2367f8a2013-02-26 01:12:25 +00005235 // Now do the work of linking the DeclContexts and Types.
5236 if (fast_path)
5237 {
5238 // We can do this quickly. Just run across the tables index-for-index since
5239 // we know each node has matching names and tags.
Greg Clayton4116e932012-05-15 02:33:01 +00005240 for (idx = 0; idx < src_size; ++idx)
5241 {
5242 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5243 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5244
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005245 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Greg Clayton4116e932012-05-15 02:33:01 +00005246 if (src_decl_ctx)
5247 {
5248 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005249 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 +00005250 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5251 }
5252 else
5253 {
5254 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005255 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 +00005256 }
5257
5258 Type *src_child_type = m_die_to_type[src_die];
5259 if (src_child_type)
5260 {
5261 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00005262 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 +00005263 m_die_to_type[dst_die] = src_child_type;
5264 }
5265 else
5266 {
5267 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005268 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());
5269 }
5270 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005271 }
5272 else
5273 {
5274 // We must do this slowly. For each member of the destination, look
5275 // up a member in the source with the same name, check its tag, and
5276 // unique them if everything matches up. Report failures.
Greg Clayton65ec1032012-11-12 21:27:20 +00005277
Sean Callanan2367f8a2013-02-26 01:12:25 +00005278 if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty())
5279 {
5280 src_name_to_die.Sort();
Greg Clayton65ec1032012-11-12 21:27:20 +00005281
Sean Callanan2367f8a2013-02-26 01:12:25 +00005282 for (idx = 0; idx < dst_size; ++idx)
5283 {
5284 const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx);
5285 dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
5286 src_die = src_name_to_die.Find(dst_name, NULL);
5287
5288 if (src_die && (src_die->Tag() == dst_die->Tag()))
5289 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005290 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Sean Callanan2367f8a2013-02-26 01:12:25 +00005291 if (src_decl_ctx)
5292 {
5293 if (log)
5294 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
5295 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5296 }
5297 else
5298 {
5299 if (log)
5300 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());
5301 }
5302
5303 Type *src_child_type = m_die_to_type[src_die];
5304 if (src_child_type)
5305 {
5306 if (log)
5307 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());
5308 m_die_to_type[dst_die] = src_child_type;
5309 }
5310 else
5311 {
5312 if (log)
5313 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());
5314 }
5315 }
5316 else
5317 {
5318 if (log)
5319 log->Printf ("warning: couldn't find a match for 0x%8.8x", dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005320
Sean Callanan2367f8a2013-02-26 01:12:25 +00005321 failures.push_back(dst_die);
5322 }
5323 }
5324 }
5325 }
5326
5327 const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize ();
5328 const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize ();
5329
5330 UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src;
5331
5332 if (src_size_artificial && dst_size_artificial)
5333 {
5334 dst_name_to_die_artificial.Sort();
5335
Greg Clayton65ec1032012-11-12 21:27:20 +00005336 for (idx = 0; idx < src_size_artificial; ++idx)
5337 {
5338 const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx);
5339 src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5340 dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL);
5341
5342 if (dst_die)
5343 {
Greg Clayton65ec1032012-11-12 21:27:20 +00005344 // Both classes have the artificial types, link them
5345 clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die];
5346 if (src_decl_ctx)
5347 {
5348 if (log)
5349 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
5350 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5351 }
5352 else
5353 {
5354 if (log)
5355 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());
5356 }
5357
5358 Type *src_child_type = m_die_to_type[src_die];
5359 if (src_child_type)
5360 {
5361 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00005362 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 +00005363 m_die_to_type[dst_die] = src_child_type;
5364 }
5365 else
5366 {
5367 if (log)
5368 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());
5369 }
5370 }
5371 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005372 }
Greg Clayton65ec1032012-11-12 21:27:20 +00005373
Sean Callanan2367f8a2013-02-26 01:12:25 +00005374 if (dst_size_artificial)
Greg Clayton4116e932012-05-15 02:33:01 +00005375 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005376 for (idx = 0; idx < dst_size_artificial; ++idx)
5377 {
5378 const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx);
5379 dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5380 if (log)
5381 log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial);
5382
5383 failures.push_back(dst_die);
5384 }
Greg Clayton4116e932012-05-15 02:33:01 +00005385 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005386
5387 return (failures.size() != 0);
Greg Clayton4116e932012-05-15 02:33:01 +00005388}
Greg Claytona8022fa2012-04-24 21:22:41 +00005389
5390TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00005391SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005392{
5393 TypeSP type_sp;
5394
Greg Clayton1be10fc2010-09-29 01:12:09 +00005395 if (type_is_new_ptr)
5396 *type_is_new_ptr = false;
Greg Clayton1fba87112012-02-09 20:03:49 +00005397
5398#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5399 static DIEStack g_die_stack;
5400 DIEStack::ScopedPopper scoped_die_logger(g_die_stack);
5401#endif
Greg Clayton1be10fc2010-09-29 01:12:09 +00005402
Sean Callananc7fbf732010-08-06 00:32:49 +00005403 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005404 if (die != NULL)
5405 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005406 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005407 if (log)
Sean Callanan5b26f272012-02-04 08:49:35 +00005408 {
5409 const DWARFDebugInfoEntry *context_die;
5410 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
5411
Greg Clayton5160ce52013-03-27 23:08:40 +00005412 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 +00005413 die->GetOffset(),
5414 context,
5415 context_die->GetOffset(),
Greg Clayton3bffb082011-12-10 02:15:28 +00005416 DW_TAG_value_to_name(die->Tag()),
Greg Clayton1fba87112012-02-09 20:03:49 +00005417 die->GetName(this, dwarf_cu));
5418
5419#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5420 scoped_die_logger.Push (dwarf_cu, die);
Greg Clayton5160ce52013-03-27 23:08:40 +00005421 g_die_stack.LogDIEs(log, this);
Greg Clayton1fba87112012-02-09 20:03:49 +00005422#endif
Sean Callanan5b26f272012-02-04 08:49:35 +00005423 }
Greg Clayton3bffb082011-12-10 02:15:28 +00005424//
Greg Clayton5160ce52013-03-27 23:08:40 +00005425// Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005426// if (log && dwarf_cu)
5427// {
5428// StreamString s;
5429// die->DumpLocation (this, dwarf_cu, s);
Greg Clayton5160ce52013-03-27 23:08:40 +00005430// GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Greg Clayton3bffb082011-12-10 02:15:28 +00005431//
5432// }
Jim Ingham16746d12011-08-25 23:21:43 +00005433
Greg Clayton594e5ed2010-09-27 21:07:38 +00005434 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005435 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00005436 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005437 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005438 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00005439 if (type_is_new_ptr)
5440 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005441
Greg Clayton594e5ed2010-09-27 21:07:38 +00005442 const dw_tag_t tag = die->Tag();
5443
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005444 bool is_forward_declaration = false;
5445 DWARFDebugInfoEntry::Attributes attributes;
5446 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00005447 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00005448 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
Greg Claytonfaac1112013-03-14 18:31:44 +00005449 uint64_t byte_size = 0;
Greg Clayton526e5af2010-11-13 03:52:47 +00005450 Declaration decl;
5451
Greg Clayton4957bf62010-09-30 21:49:03 +00005452 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton1be10fc2010-09-29 01:12:09 +00005453 clang_type_t clang_type = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005454
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005455 dw_attr_t attr;
5456
5457 switch (tag)
5458 {
5459 case DW_TAG_base_type:
5460 case DW_TAG_pointer_type:
5461 case DW_TAG_reference_type:
Sean Callanance8af862012-05-21 23:31:51 +00005462 case DW_TAG_rvalue_reference_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005463 case DW_TAG_typedef:
5464 case DW_TAG_const_type:
5465 case DW_TAG_restrict_type:
5466 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00005467 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005468 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005469 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005470 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005471
Greg Claytond88d7592010-09-15 08:33:30 +00005472 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005473 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005474 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
5475
5476 if (num_attributes > 0)
5477 {
5478 uint32_t i;
5479 for (i=0; i<num_attributes; ++i)
5480 {
5481 attr = attributes.AttributeAtIndex(i);
5482 DWARFFormValue form_value;
5483 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5484 {
5485 switch (attr)
5486 {
5487 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5488 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5489 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5490 case DW_AT_name:
Jim Ingham337030f2011-04-15 23:41:23 +00005491
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005492 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00005493 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
5494 // include the "&"...
5495 if (tag == DW_TAG_reference_type)
5496 {
5497 if (strchr (type_name_cstr, '&') == NULL)
5498 type_name_cstr = NULL;
5499 }
5500 if (type_name_cstr)
5501 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005502 break;
Greg Clayton23f59502012-07-17 03:23:13 +00005503 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005504 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
5505 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
5506 default:
5507 case DW_AT_sibling:
5508 break;
5509 }
5510 }
5511 }
5512 }
5513
Daniel Malead01b2952012-11-29 21:49:15 +00005514 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 +00005515
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005516 switch (tag)
5517 {
5518 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00005519 break;
5520
Greg Claytond4436412011-10-28 21:00:00 +00005521 case DW_TAG_unspecified_type:
5522 if (strcmp(type_name_cstr, "nullptr_t") == 0)
5523 {
5524 resolve_state = Type::eResolveStateFull;
5525 clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr();
5526 break;
5527 }
5528 // Fall through to base type below in case we can handle the type there...
5529
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005530 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00005531 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005532 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
5533 encoding,
5534 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005535 break;
5536
Sean Callanance8af862012-05-21 23:31:51 +00005537 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
5538 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
5539 case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break;
5540 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
5541 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
5542 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
5543 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005544 }
5545
Sean Callanan82587052013-01-03 00:05:56 +00005546 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 +00005547 {
Sean Callanan82587052013-01-03 00:05:56 +00005548 bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus);
5549
5550 if (translation_unit_is_objc)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005551 {
Sean Callanan82587052013-01-03 00:05:56 +00005552 if (type_name_cstr != NULL)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005553 {
Sean Callanan82587052013-01-03 00:05:56 +00005554 static ConstString g_objc_type_name_id("id");
5555 static ConstString g_objc_type_name_Class("Class");
5556 static ConstString g_objc_type_name_selector("SEL");
5557
5558 if (type_name_const_str == g_objc_type_name_id)
5559 {
5560 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005561 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 +00005562 die->GetOffset(),
5563 DW_TAG_value_to_name(die->Tag()),
5564 die->GetName(this, dwarf_cu));
5565 clang_type = ast.GetBuiltInType_objc_id();
5566 encoding_data_type = Type::eEncodingIsUID;
5567 encoding_uid = LLDB_INVALID_UID;
5568 resolve_state = Type::eResolveStateFull;
Greg Clayton526e5af2010-11-13 03:52:47 +00005569
Sean Callanan82587052013-01-03 00:05:56 +00005570 }
5571 else if (type_name_const_str == g_objc_type_name_Class)
5572 {
5573 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005574 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 +00005575 die->GetOffset(),
5576 DW_TAG_value_to_name(die->Tag()),
5577 die->GetName(this, dwarf_cu));
5578 clang_type = ast.GetBuiltInType_objc_Class();
5579 encoding_data_type = Type::eEncodingIsUID;
5580 encoding_uid = LLDB_INVALID_UID;
5581 resolve_state = Type::eResolveStateFull;
5582 }
5583 else if (type_name_const_str == g_objc_type_name_selector)
5584 {
5585 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005586 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 +00005587 die->GetOffset(),
5588 DW_TAG_value_to_name(die->Tag()),
5589 die->GetName(this, dwarf_cu));
5590 clang_type = ast.GetBuiltInType_objc_selector();
5591 encoding_data_type = Type::eEncodingIsUID;
5592 encoding_uid = LLDB_INVALID_UID;
5593 resolve_state = Type::eResolveStateFull;
5594 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005595 }
Sean Callanan82587052013-01-03 00:05:56 +00005596 else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005597 {
Sean Callanan82587052013-01-03 00:05:56 +00005598 // Clang sometimes erroneously emits id as objc_object*. In that case we fix up the type to "id".
5599
5600 DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid);
5601
5602 if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type)
5603 {
5604 if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL))
5605 {
5606 if (!strcmp(struct_name, "objc_object"))
5607 {
5608 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005609 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 +00005610 die->GetOffset(),
5611 DW_TAG_value_to_name(die->Tag()),
5612 die->GetName(this, dwarf_cu));
5613 clang_type = ast.GetBuiltInType_objc_id();
5614 encoding_data_type = Type::eEncodingIsUID;
5615 encoding_uid = LLDB_INVALID_UID;
5616 resolve_state = Type::eResolveStateFull;
5617 }
5618 }
5619 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005620 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005621 }
5622 }
5623
Greg Clayton81c22f62011-10-19 18:09:39 +00005624 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005625 this,
5626 type_name_const_str,
5627 byte_size,
5628 NULL,
5629 encoding_uid,
5630 encoding_data_type,
5631 &decl,
5632 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005633 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005634
Greg Clayton594e5ed2010-09-27 21:07:38 +00005635 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005636
5637// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
5638// if (encoding_type != NULL)
5639// {
5640// if (encoding_type != DIE_IS_BEING_PARSED)
5641// type_sp->SetEncodingType(encoding_type);
5642// else
5643// m_indirect_fixups.push_back(type_sp.get());
5644// }
5645 }
5646 break;
5647
5648 case DW_TAG_structure_type:
5649 case DW_TAG_union_type:
5650 case DW_TAG_class_type:
5651 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005652 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005653 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Greg Clayton23f59502012-07-17 03:23:13 +00005654 bool byte_size_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005655
Greg Clayton9e409562010-07-28 02:04:09 +00005656 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00005657 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005658 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00005659 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005660 if (num_attributes > 0)
5661 {
5662 uint32_t i;
5663 for (i=0; i<num_attributes; ++i)
5664 {
5665 attr = attributes.AttributeAtIndex(i);
5666 DWARFFormValue form_value;
5667 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5668 {
5669 switch (attr)
5670 {
Greg Clayton9e409562010-07-28 02:04:09 +00005671 case DW_AT_decl_file:
Greg Claytonc7f03b62012-01-12 04:33:28 +00005672 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
5673 {
5674 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
5675 // point to the compile unit file, so we clear this invalid value
5676 // so that we can still unique types efficiently.
5677 decl.SetFile(FileSpec ("<invalid>", false));
5678 }
5679 else
5680 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
Greg Clayton9e409562010-07-28 02:04:09 +00005681 break;
5682
5683 case DW_AT_decl_line:
5684 decl.SetLine(form_value.Unsigned());
5685 break;
5686
5687 case DW_AT_decl_column:
5688 decl.SetColumn(form_value.Unsigned());
5689 break;
5690
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005691 case DW_AT_name:
5692 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005693 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005694 break;
Greg Clayton9e409562010-07-28 02:04:09 +00005695
5696 case DW_AT_byte_size:
5697 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00005698 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00005699 break;
5700
5701 case DW_AT_accessibility:
5702 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
5703 break;
5704
5705 case DW_AT_declaration:
Greg Clayton1c8ef472013-04-05 23:27:21 +00005706 is_forward_declaration = form_value.Boolean();
Greg Clayton9e409562010-07-28 02:04:09 +00005707 break;
5708
5709 case DW_AT_APPLE_runtime_class:
5710 class_language = (LanguageType)form_value.Signed();
5711 break;
5712
Greg Clayton18774842011-11-29 23:40:34 +00005713 case DW_AT_APPLE_objc_complete_type:
5714 is_complete_objc_class = form_value.Signed();
5715 break;
5716
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005717 case DW_AT_allocated:
5718 case DW_AT_associated:
5719 case DW_AT_data_location:
5720 case DW_AT_description:
5721 case DW_AT_start_scope:
5722 case DW_AT_visibility:
5723 default:
5724 case DW_AT_sibling:
5725 break;
5726 }
5727 }
5728 }
5729 }
5730
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005731 UniqueDWARFASTType unique_ast_entry;
Sean Callanan8e8072d2012-02-07 21:13:38 +00005732
Greg Clayton123edca2012-03-02 00:07:15 +00005733 // Only try and unique the type if it has a name.
5734 if (type_name_const_str &&
5735 GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Sean Callanan8e8072d2012-02-07 21:13:38 +00005736 this,
5737 dwarf_cu,
5738 die,
5739 decl,
5740 byte_size_valid ? byte_size : -1,
5741 unique_ast_entry))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005742 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005743 // We have already parsed this type or from another
5744 // compile unit. GCC loves to use the "one definition
5745 // rule" which can result in multiple definitions
5746 // of the same class over and over in each compile
5747 // unit.
5748 type_sp = unique_ast_entry.m_type_sp;
5749 if (type_sp)
Greg Claytonc615ce42010-11-09 04:42:43 +00005750 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005751 m_die_to_type[die] = type_sp.get();
5752 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005753 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005754 }
5755
Daniel Malead01b2952012-11-29 21:49:15 +00005756 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 +00005757
5758 int tag_decl_kind = -1;
5759 AccessType default_accessibility = eAccessNone;
5760 if (tag == DW_TAG_structure_type)
5761 {
5762 tag_decl_kind = clang::TTK_Struct;
5763 default_accessibility = eAccessPublic;
5764 }
5765 else if (tag == DW_TAG_union_type)
5766 {
5767 tag_decl_kind = clang::TTK_Union;
5768 default_accessibility = eAccessPublic;
5769 }
5770 else if (tag == DW_TAG_class_type)
5771 {
5772 tag_decl_kind = clang::TTK_Class;
5773 default_accessibility = eAccessPrivate;
5774 }
Greg Clayton3a5f29a2011-11-30 02:48:28 +00005775
5776 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
5777 die->HasChildren() == false &&
5778 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
5779 {
5780 // Work around an issue with clang at the moment where
5781 // forward declarations for objective C classes are emitted
5782 // as:
5783 // DW_TAG_structure_type [2]
5784 // DW_AT_name( "ForwardObjcClass" )
5785 // DW_AT_byte_size( 0x00 )
5786 // DW_AT_decl_file( "..." )
5787 // DW_AT_decl_line( 1 )
5788 //
5789 // Note that there is no DW_AT_declaration and there are
5790 // no children, and the byte size is zero.
5791 is_forward_declaration = true;
5792 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005793
Sean Callanan7457f8d2012-04-25 01:03:57 +00005794 if (class_language == eLanguageTypeObjC ||
5795 class_language == eLanguageTypeObjC_plus_plus)
Greg Clayton18774842011-11-29 23:40:34 +00005796 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005797 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
Greg Clayton901c5ca2011-12-03 04:40:03 +00005798 {
5799 // We have a valid eSymbolTypeObjCClass class symbol whose
5800 // name matches the current objective C class that we
5801 // are trying to find and this DIE isn't the complete
5802 // definition (we checked is_complete_objc_class above and
5803 // know it is false), so the real definition is in here somewhere
Greg Claytonc7f03b62012-01-12 04:33:28 +00005804 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005805
Greg Clayton1f746072012-08-29 21:13:06 +00005806 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton901c5ca2011-12-03 04:40:03 +00005807 {
5808 // We weren't able to find a full declaration in
5809 // this DWARF, see if we have a declaration anywhere
5810 // else...
Greg Claytonc7f03b62012-01-12 04:33:28 +00005811 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00005812 }
5813
5814 if (type_sp)
5815 {
5816 if (log)
5817 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005818 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00005819 "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 +00005820 this,
5821 die->GetOffset(),
5822 DW_TAG_value_to_name(tag),
5823 type_name_cstr,
5824 type_sp->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00005825 }
5826
5827 // We found a real definition for this type elsewhere
5828 // so lets use it and cache the fact that we found
5829 // a complete type for this die
5830 m_die_to_type[die] = type_sp.get();
5831 return type_sp;
5832 }
5833 }
5834 }
5835
5836
5837 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005838 {
5839 // We have a forward declaration to a type and we need
5840 // to try and find a full declaration. We look in the
5841 // current type index just in case we have a forward
5842 // declaration followed by an actual declarations in the
5843 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00005844 if (log)
5845 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005846 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00005847 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
5848 this,
5849 die->GetOffset(),
5850 DW_TAG_value_to_name(tag),
5851 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00005852 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005853
Greg Claytona8022fa2012-04-24 21:22:41 +00005854 DWARFDeclContext die_decl_ctx;
5855 die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx);
5856
5857 //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
5858 type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005859
Greg Clayton1f746072012-08-29 21:13:06 +00005860 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton4272cc72011-02-02 02:24:04 +00005861 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005862 // We weren't able to find a full declaration in
5863 // this DWARF, see if we have a declaration anywhere
5864 // else...
Greg Claytona8022fa2012-04-24 21:22:41 +00005865 type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton4272cc72011-02-02 02:24:04 +00005866 }
5867
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005868 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00005869 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00005870 if (log)
5871 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005872 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00005873 "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 +00005874 this,
5875 die->GetOffset(),
5876 DW_TAG_value_to_name(tag),
5877 type_name_cstr,
5878 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00005879 }
5880
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005881 // We found a real definition for this type elsewhere
5882 // so lets use it and cache the fact that we found
5883 // a complete type for this die
5884 m_die_to_type[die] = type_sp.get();
5885 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005886 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005887 }
5888 assert (tag_decl_kind != -1);
5889 bool clang_type_was_created = false;
5890 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
5891 if (clang_type == NULL)
5892 {
Sean Callanan4d04c6a2012-02-09 22:54:11 +00005893 const DWARFDebugInfoEntry *decl_ctx_die;
5894
5895 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton55561e92011-10-26 03:31:36 +00005896 if (accessibility == eAccessNone && decl_ctx)
5897 {
5898 // Check the decl context that contains this class/struct/union.
5899 // If it is a class we must give it an accessability.
5900 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
5901 if (DeclKindIsCXXClass (containing_decl_kind))
5902 accessibility = default_accessibility;
5903 }
5904
Greg Claytonc4ffd662013-03-08 01:37:30 +00005905 ClangASTMetadata metadata;
5906 metadata.SetUserID(MakeUserID(die->GetOffset()));
5907 metadata.SetIsDynamicCXXType(ClassOrStructIsVirtual (dwarf_cu, die));
5908
Greg Claytonf0705c82011-10-22 03:33:13 +00005909 if (type_name_cstr && strchr (type_name_cstr, '<'))
5910 {
5911 ClangASTContext::TemplateParameterInfos template_param_infos;
5912 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
5913 {
5914 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00005915 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00005916 type_name_cstr,
5917 tag_decl_kind,
5918 template_param_infos);
5919
5920 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
5921 class_template_decl,
5922 tag_decl_kind,
5923 template_param_infos);
5924 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
5925 clang_type_was_created = true;
Sean Callanan60217122012-04-13 00:10:03 +00005926
Greg Claytond0029442013-03-27 01:48:02 +00005927 GetClangASTContext().SetMetadata (class_template_decl, metadata);
5928 GetClangASTContext().SetMetadata (class_specialization_decl, metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00005929 }
5930 }
5931
5932 if (!clang_type_was_created)
5933 {
5934 clang_type_was_created = true;
Greg Clayton55561e92011-10-26 03:31:36 +00005935 clang_type = ast.CreateRecordType (decl_ctx,
5936 accessibility,
5937 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00005938 tag_decl_kind,
Sean Callanan60217122012-04-13 00:10:03 +00005939 class_language,
Jim Ingham379397632012-10-27 02:54:13 +00005940 &metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00005941 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005942 }
5943
5944 // Store a forward declaration to this class type in case any
5945 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00005946 // types for function prototypes.
5947 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00005948 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005949 this,
5950 type_name_const_str,
5951 byte_size,
5952 NULL,
5953 LLDB_INVALID_UID,
5954 Type::eEncodingIsUID,
5955 &decl,
5956 clang_type,
5957 Type::eResolveStateForward));
Sean Callanan72772842012-02-22 23:57:45 +00005958
5959 type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005960
5961
5962 // Add our type to the unique type map so we don't
5963 // end up creating many copies of the same type over
5964 // and over in the ASTContext for our module
5965 unique_ast_entry.m_type_sp = type_sp;
Greg Clayton36909642011-03-15 04:38:20 +00005966 unique_ast_entry.m_symfile = this;
5967 unique_ast_entry.m_cu = dwarf_cu;
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005968 unique_ast_entry.m_die = die;
5969 unique_ast_entry.m_declaration = decl;
Sean Callanan59700592012-02-13 22:30:16 +00005970 unique_ast_entry.m_byte_size = byte_size;
Greg Claytone576ab22011-02-15 00:19:15 +00005971 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
5972 unique_ast_entry);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005973
Sean Callanan12014a02011-12-08 23:45:45 +00005974 if (!is_forward_declaration)
Greg Clayton219cf312012-03-30 00:51:13 +00005975 {
5976 // Always start the definition for a class type so that
5977 // if the class has child classes or types that require
5978 // the class to be created for use as their decl contexts
5979 // the class will be ready to accept these child definitions.
Sean Callanan12014a02011-12-08 23:45:45 +00005980 if (die->HasChildren() == false)
5981 {
5982 // No children for this struct/union/class, lets finish it
5983 ast.StartTagDeclarationDefinition (clang_type);
5984 ast.CompleteTagDeclarationDefinition (clang_type);
Sean Callanan433cd222012-10-19 01:37:25 +00005985
5986 if (tag == DW_TAG_structure_type) // this only applies in C
5987 {
5988 clang::QualType qual_type = clang::QualType::getFromOpaquePtr (clang_type);
5989 const clang::RecordType *record_type = qual_type->getAs<clang::RecordType> ();
5990
5991 if (record_type)
5992 {
5993 clang::RecordDecl *record_decl = record_type->getDecl();
5994
5995 if (record_decl)
5996 {
5997 LayoutInfo layout_info;
5998
5999 layout_info.alignment = 0;
6000 layout_info.bit_size = 0;
6001
6002 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
6003 }
6004 }
6005 }
Sean Callanan12014a02011-12-08 23:45:45 +00006006 }
6007 else if (clang_type_was_created)
6008 {
Greg Clayton219cf312012-03-30 00:51:13 +00006009 // Start the definition if the class is not objective C since
6010 // the underlying decls respond to isCompleteDefinition(). Objective
6011 // C decls dont' respond to isCompleteDefinition() so we can't
6012 // start the declaration definition right away. For C++ classs/union/structs
6013 // we want to start the definition in case the class is needed as the
6014 // declaration context for a contained class or type without the need
6015 // to complete that type..
6016
Sean Callanan7457f8d2012-04-25 01:03:57 +00006017 if (class_language != eLanguageTypeObjC &&
6018 class_language != eLanguageTypeObjC_plus_plus)
Greg Clayton219cf312012-03-30 00:51:13 +00006019 ast.StartTagDeclarationDefinition (clang_type);
6020
Sean Callanan12014a02011-12-08 23:45:45 +00006021 // Leave this as a forward declaration until we need
6022 // to know the details of the type. lldb_private::Type
6023 // will automatically call the SymbolFile virtual function
6024 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
6025 // When the definition needs to be defined.
6026 m_forward_decl_die_to_clang_type[die] = clang_type;
6027 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
6028 ClangASTContext::SetHasExternalStorage (clang_type, true);
6029 }
Greg Claytonc615ce42010-11-09 04:42:43 +00006030 }
Greg Claytoncab36a32011-12-08 05:16:30 +00006031
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006032 }
6033 break;
6034
6035 case DW_TAG_enumeration_type:
6036 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006037 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006038 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006039
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006040 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006041
Greg Claytond88d7592010-09-15 08:33:30 +00006042 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006043 if (num_attributes > 0)
6044 {
6045 uint32_t i;
6046
6047 for (i=0; i<num_attributes; ++i)
6048 {
6049 attr = attributes.AttributeAtIndex(i);
6050 DWARFFormValue form_value;
6051 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6052 {
6053 switch (attr)
6054 {
Greg Clayton7a345282010-11-09 23:46:37 +00006055 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6056 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6057 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006058 case DW_AT_name:
6059 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006060 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006061 break;
Greg Clayton7a345282010-11-09 23:46:37 +00006062 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006063 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
6064 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006065 case DW_AT_declaration: break; //is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006066 case DW_AT_allocated:
6067 case DW_AT_associated:
6068 case DW_AT_bit_stride:
6069 case DW_AT_byte_stride:
6070 case DW_AT_data_location:
6071 case DW_AT_description:
6072 case DW_AT_start_scope:
6073 case DW_AT_visibility:
6074 case DW_AT_specification:
6075 case DW_AT_abstract_origin:
6076 case DW_AT_sibling:
6077 break;
6078 }
6079 }
6080 }
6081
Daniel Malead01b2952012-11-29 21:49:15 +00006082 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 +00006083
Greg Clayton1be10fc2010-09-29 01:12:09 +00006084 clang_type_t enumerator_clang_type = NULL;
6085 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
6086 if (clang_type == NULL)
6087 {
Greg Clayton5d14fc02013-03-06 06:23:54 +00006088 if (encoding_uid != DW_INVALID_OFFSET)
6089 {
6090 Type *enumerator_type = ResolveTypeUID(encoding_uid);
6091 if (enumerator_type)
6092 enumerator_clang_type = enumerator_type->GetClangFullType();
6093 }
6094
6095 if (enumerator_clang_type == NULL)
6096 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
6097 DW_ATE_signed,
6098 byte_size * 8);
6099
Greg Claytonca512b32011-01-14 04:54:56 +00006100 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00006101 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00006102 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006103 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00006104 }
6105 else
6106 {
6107 enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00006108 }
6109
Greg Claytona2721472011-06-25 00:44:06 +00006110 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
6111
Greg Clayton81c22f62011-10-19 18:09:39 +00006112 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006113 this,
6114 type_name_const_str,
6115 byte_size,
6116 NULL,
6117 encoding_uid,
6118 Type::eEncodingIsUID,
6119 &decl,
6120 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006121 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006122
Greg Clayton6beaaa62011-01-17 03:46:26 +00006123 ast.StartTagDeclarationDefinition (clang_type);
6124 if (die->HasChildren())
6125 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006126 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00006127 bool is_signed = false;
Greg Clayton5d14fc02013-03-06 06:23:54 +00006128 ast.IsIntegerType(enumerator_clang_type, is_signed);
Greg Clayton3e067532013-03-05 23:54:39 +00006129 ParseChildEnumerators(cu_sc, clang_type, is_signed, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00006130 }
6131 ast.CompleteTagDeclarationDefinition (clang_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006132 }
6133 }
6134 break;
6135
Jim Inghamb0be4422010-08-12 01:20:14 +00006136 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006137 case DW_TAG_subprogram:
6138 case DW_TAG_subroutine_type:
6139 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006140 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006141 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006142
Greg Clayton23f59502012-07-17 03:23:13 +00006143 //const char *mangled = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006144 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00006145 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006146 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00006147 bool is_static = false;
6148 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00006149 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00006150 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00006151 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
6152 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Jim Ingham379397632012-10-27 02:54:13 +00006153 dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00006154
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006155 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00006156 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006157
6158
Greg Claytond88d7592010-09-15 08:33:30 +00006159 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006160 if (num_attributes > 0)
6161 {
6162 uint32_t i;
6163 for (i=0; i<num_attributes; ++i)
6164 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006165 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006166 DWARFFormValue form_value;
6167 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6168 {
6169 switch (attr)
6170 {
6171 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6172 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6173 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6174 case DW_AT_name:
6175 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006176 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006177 break;
6178
Greg Clayton71415542012-12-08 00:24:40 +00006179 case DW_AT_linkage_name:
Greg Clayton23f59502012-07-17 03:23:13 +00006180 case DW_AT_MIPS_linkage_name: break; // mangled = form_value.AsCString(&get_debug_str_data()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006181 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00006182 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006183 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
6184 case DW_AT_inline: is_inline = form_value.Boolean(); break;
6185 case DW_AT_virtuality: is_virtual = form_value.Boolean(); break;
6186 case DW_AT_explicit: is_explicit = form_value.Boolean(); break;
6187 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Sean Callanandbb58392011-11-02 01:38:59 +00006188
Greg Claytonf51de672010-10-01 02:31:07 +00006189
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006190 case DW_AT_external:
6191 if (form_value.Unsigned())
6192 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00006193 if (storage == clang::SC_None)
6194 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006195 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00006196 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006197 }
6198 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006199
Greg Clayton72da3972011-08-16 18:40:23 +00006200 case DW_AT_specification:
6201 specification_die_offset = form_value.Reference(dwarf_cu);
6202 break;
6203
6204 case DW_AT_abstract_origin:
6205 abstract_origin_die_offset = form_value.Reference(dwarf_cu);
6206 break;
6207
Jim Ingham379397632012-10-27 02:54:13 +00006208 case DW_AT_object_pointer:
6209 object_pointer_die_offset = form_value.Reference(dwarf_cu);
6210 break;
6211
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006212 case DW_AT_allocated:
6213 case DW_AT_associated:
6214 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006215 case DW_AT_calling_convention:
6216 case DW_AT_data_location:
6217 case DW_AT_elemental:
6218 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006219 case DW_AT_frame_base:
6220 case DW_AT_high_pc:
6221 case DW_AT_low_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006222 case DW_AT_prototyped:
6223 case DW_AT_pure:
6224 case DW_AT_ranges:
6225 case DW_AT_recursive:
6226 case DW_AT_return_addr:
6227 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006228 case DW_AT_start_scope:
6229 case DW_AT_static_link:
6230 case DW_AT_trampoline:
6231 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006232 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006233 case DW_AT_description:
6234 case DW_AT_sibling:
6235 break;
6236 }
6237 }
6238 }
Greg Clayton24739922010-10-13 03:15:28 +00006239 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006240
Jim Ingham379397632012-10-27 02:54:13 +00006241 std::string object_pointer_name;
6242 if (object_pointer_die_offset != DW_INVALID_OFFSET)
6243 {
6244 // Get the name from the object pointer die
6245 StreamString s;
6246 if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s))
6247 {
6248 object_pointer_name.assign(s.GetData());
6249 }
6250 }
6251
Daniel Malead01b2952012-11-29 21:49:15 +00006252 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 +00006253
Greg Clayton24739922010-10-13 03:15:28 +00006254 clang_type_t return_clang_type = NULL;
6255 Type *func_type = NULL;
6256
6257 if (type_die_offset != DW_INVALID_OFFSET)
6258 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00006259
Greg Clayton24739922010-10-13 03:15:28 +00006260 if (func_type)
Greg Clayton42ce2f32011-12-12 21:50:19 +00006261 return_clang_type = func_type->GetClangForwardType();
Greg Clayton24739922010-10-13 03:15:28 +00006262 else
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006263 return_clang_type = ast.GetBuiltInType_void();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006264
Greg Claytonf51de672010-10-01 02:31:07 +00006265
Greg Clayton24739922010-10-13 03:15:28 +00006266 std::vector<clang_type_t> function_param_types;
6267 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006268
Greg Clayton24739922010-10-13 03:15:28 +00006269 // Parse the function children for the parameters
Sean Callanan763d72a2011-08-02 22:21:50 +00006270
Greg Claytoncb5860a2011-10-13 23:49:28 +00006271 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
6272 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00006273 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
6274
Greg Claytonf0705c82011-10-22 03:33:13 +00006275 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00006276 // Start off static. This will be set to false in ParseChildParameters(...)
6277 // if we find a "this" paramters as the first parameter
6278 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00006279 is_static = true;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006280 ClangASTContext::TemplateParameterInfos template_param_infos;
6281
Greg Clayton24739922010-10-13 03:15:28 +00006282 if (die->HasChildren())
6283 {
Greg Clayton0fffff52010-09-24 05:15:53 +00006284 bool skip_artificial = true;
Jim Ingham379397632012-10-27 02:54:13 +00006285 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00006286 containing_decl_ctx,
Jim Ingham379397632012-10-27 02:54:13 +00006287 dwarf_cu,
6288 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00006289 skip_artificial,
6290 is_static,
Jim Ingham379397632012-10-27 02:54:13 +00006291 type_list,
6292 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00006293 function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006294 type_quals,
6295 template_param_infos);
Greg Clayton24739922010-10-13 03:15:28 +00006296 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006297
Greg Clayton24739922010-10-13 03:15:28 +00006298 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006299 clang_type = ast.CreateFunctionType (return_clang_type,
Greg Clayton9cb25c42012-10-30 17:02:18 +00006300 function_param_types.data(),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006301 function_param_types.size(),
6302 is_variadic,
6303 type_quals);
6304
Sean Callanande9ce872013-05-09 23:13:13 +00006305 bool ignore_containing_context = false;
6306
Greg Clayton24739922010-10-13 03:15:28 +00006307 if (type_name_cstr)
6308 {
6309 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00006310 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006311 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00006312 ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true);
6313 if (objc_method.IsValid(true))
Greg Clayton0fffff52010-09-24 05:15:53 +00006314 {
Greg Clayton24739922010-10-13 03:15:28 +00006315 SymbolContext empty_sc;
6316 clang_type_t class_opaque_type = NULL;
Greg Clayton1b3815c2013-01-30 00:18:29 +00006317 ConstString class_name(objc_method.GetClassName());
Greg Clayton7c810422012-01-18 23:40:49 +00006318 if (class_name)
Greg Clayton0fffff52010-09-24 05:15:53 +00006319 {
Greg Clayton24739922010-10-13 03:15:28 +00006320 TypeList types;
Greg Clayton278a16b2012-01-19 00:52:59 +00006321 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
Greg Claytonc7f03b62012-01-12 04:33:28 +00006322
6323 if (complete_objc_class_type_sp)
Greg Clayton0fffff52010-09-24 05:15:53 +00006324 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00006325 clang_type_t type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
6326 if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
6327 class_opaque_type = type_clang_forward_type;
Greg Clayton0fffff52010-09-24 05:15:53 +00006328 }
Greg Clayton24739922010-10-13 03:15:28 +00006329 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006330
Greg Clayton24739922010-10-13 03:15:28 +00006331 if (class_opaque_type)
6332 {
6333 // If accessibility isn't set to anything valid, assume public for
6334 // now...
6335 if (accessibility == eAccessNone)
6336 accessibility = eAccessPublic;
6337
Sean Callanan464a5b52012-10-04 22:06:29 +00006338 clang::ObjCMethodDecl *objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
6339 type_name_cstr,
6340 clang_type,
Greg Clayton1bbcc032013-03-08 02:42:06 +00006341 accessibility,
6342 is_artificial);
Greg Clayton24739922010-10-13 03:15:28 +00006343 type_handled = objc_method_decl != NULL;
Sean Callanan464a5b52012-10-04 22:06:29 +00006344 if (type_handled)
6345 {
6346 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Claytond0029442013-03-27 01:48:02 +00006347 GetClangASTContext().SetMetadataAsUserID (objc_method_decl, MakeUserID(die->GetOffset()));
Sean Callanan464a5b52012-10-04 22:06:29 +00006348 }
Sean Callananc3a1d562013-02-06 23:21:59 +00006349 else
6350 {
Jason Molendac1a65832013-03-07 22:44:42 +00006351 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 +00006352 die->GetOffset(),
6353 tag,
6354 DW_TAG_value_to_name(tag));
6355 }
Greg Clayton24739922010-10-13 03:15:28 +00006356 }
6357 }
Greg Clayton5113dc82011-08-12 06:47:54 +00006358 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00006359 {
6360 // Look at the parent of this DIE and see if is is
6361 // a class or struct and see if this is actually a
6362 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00006363 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00006364 if (class_type)
6365 {
Greg Clayton4116e932012-05-15 02:33:01 +00006366 if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset()))
6367 {
6368 // We uniqued the parent class of this function to another class
6369 // so we now need to associate all dies under "decl_ctx_die" to
6370 // DIEs in the DIE for "class_type"...
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006371 SymbolFileDWARF *class_symfile = NULL;
Greg Clayton4116e932012-05-15 02:33:01 +00006372 DWARFCompileUnitSP class_type_cu_sp;
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006373 const DWARFDebugInfoEntry *class_type_die = NULL;
Sean Callanan2367f8a2013-02-26 01:12:25 +00006374
6375 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
6376 if (debug_map_symfile)
6377 {
6378 class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID()));
6379 class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6380 }
6381 else
6382 {
6383 class_symfile = this;
6384 class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6385 }
Greg Clayton4116e932012-05-15 02:33:01 +00006386 if (class_type_die)
6387 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006388 llvm::SmallVector<const DWARFDebugInfoEntry *, 0> failures;
6389
6390 CopyUniqueClassMethodTypes (class_symfile,
6391 class_type,
6392 class_type_cu_sp.get(),
6393 class_type_die,
6394 dwarf_cu,
6395 decl_ctx_die,
6396 failures);
6397
6398 // FIXME do something with these failures that's smarter than
6399 // just dropping them on the ground. Unfortunately classes don't
6400 // like having stuff added to them after their definitions are
6401 // complete...
6402
6403 type_ptr = m_die_to_type[die];
6404 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton4116e932012-05-15 02:33:01 +00006405 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006406 type_sp = type_ptr->shared_from_this();
6407 break;
Greg Clayton4116e932012-05-15 02:33:01 +00006408 }
6409 }
6410 }
6411
Greg Clayton72da3972011-08-16 18:40:23 +00006412 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00006413 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006414 // We have a specification which we are going to base our function
6415 // prototype off of, so we need this type to be completed so that the
6416 // m_die_to_decl_ctx for the method in the specification has a valid
6417 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006418 class_type->GetClangForwardType();
Greg Clayton72da3972011-08-16 18:40:23 +00006419 // If we have a specification, then the function type should have been
6420 // made with the specification and not with this die.
6421 DWARFCompileUnitSP spec_cu_sp;
6422 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006423 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006424 if (spec_clang_decl_ctx)
6425 {
6426 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
6427 }
6428 else
Jim Inghamc1663042011-09-29 22:12:35 +00006429 {
Daniel Malead01b2952012-11-29 21:49:15 +00006430 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8x) has no decl\n",
Greg Claytone38a5ed2012-01-05 03:57:59 +00006431 MakeUserID(die->GetOffset()),
6432 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006433 }
Greg Clayton72da3972011-08-16 18:40:23 +00006434 type_handled = true;
6435 }
6436 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
6437 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006438 // We have a specification which we are going to base our function
6439 // prototype off of, so we need this type to be completed so that the
6440 // m_die_to_decl_ctx for the method in the abstract origin has a valid
6441 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006442 class_type->GetClangForwardType();
Greg Clayton5cf58b92011-10-05 22:22:08 +00006443
Greg Clayton72da3972011-08-16 18:40:23 +00006444 DWARFCompileUnitSP abs_cu_sp;
6445 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006446 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006447 if (abs_clang_decl_ctx)
6448 {
6449 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
6450 }
6451 else
Jim Inghamc1663042011-09-29 22:12:35 +00006452 {
Daniel Malead01b2952012-11-29 21:49:15 +00006453 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 +00006454 MakeUserID(die->GetOffset()),
6455 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006456 }
Greg Clayton72da3972011-08-16 18:40:23 +00006457 type_handled = true;
6458 }
6459 else
6460 {
6461 clang_type_t class_opaque_type = class_type->GetClangForwardType();
6462 if (ClangASTContext::IsCXXClassType (class_opaque_type))
Greg Clayton931180e2011-01-27 06:44:37 +00006463 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006464 if (ClangASTContext::IsBeingDefined (class_opaque_type))
Greg Clayton72da3972011-08-16 18:40:23 +00006465 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006466 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
6467 // in the DWARF for C++ methods... Default to public for now...
6468 if (accessibility == eAccessNone)
6469 accessibility = eAccessPublic;
6470
6471 if (!is_static && !die->HasChildren())
6472 {
6473 // We have a C++ member function with no children (this pointer!)
6474 // and clang will get mad if we try and make a function that isn't
6475 // well formed in the DWARF, so we will just skip it...
6476 type_handled = true;
6477 }
6478 else
6479 {
6480 clang::CXXMethodDecl *cxx_method_decl;
6481 // REMOVE THE CRASH DESCRIPTION BELOW
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00006482 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 +00006483 type_name_cstr,
6484 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00006485 MakeUserID(die->GetOffset()),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00006486 m_obj_file->GetFileSpec().GetPath().c_str());
Greg Clayton20568dd2011-10-13 23:13:20 +00006487
Sean Callananc1b732d2011-11-01 18:07:13 +00006488 const bool is_attr_used = false;
6489
Greg Clayton20568dd2011-10-13 23:13:20 +00006490 cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type,
6491 type_name_cstr,
6492 clang_type,
6493 accessibility,
6494 is_virtual,
6495 is_static,
6496 is_inline,
Sean Callananc1b732d2011-11-01 18:07:13 +00006497 is_explicit,
Sean Callanandbb58392011-11-02 01:38:59 +00006498 is_attr_used,
6499 is_artificial);
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006500
Greg Clayton20568dd2011-10-13 23:13:20 +00006501 type_handled = cxx_method_decl != NULL;
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006502
6503 if (type_handled)
Jim Ingham379397632012-10-27 02:54:13 +00006504 {
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006505 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
6506
6507 Host::SetCrashDescription (NULL);
6508
6509
6510 ClangASTMetadata metadata;
6511 metadata.SetUserID(MakeUserID(die->GetOffset()));
6512
6513 if (!object_pointer_name.empty())
6514 {
6515 metadata.SetObjectPtrName(object_pointer_name.c_str());
6516 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006517 log->Printf ("Setting object pointer name: %s on method object %p.\n",
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006518 object_pointer_name.c_str(),
Greg Claytond0029442013-03-27 01:48:02 +00006519 cxx_method_decl);
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006520 }
Greg Claytond0029442013-03-27 01:48:02 +00006521 GetClangASTContext().SetMetadata (cxx_method_decl, metadata);
Jim Ingham379397632012-10-27 02:54:13 +00006522 }
Sean Callananb0640dc2013-04-09 23:22:08 +00006523 else
6524 {
Sean Callanande9ce872013-05-09 23:13:13 +00006525 ignore_containing_context = true;
Sean Callananb0640dc2013-04-09 23:22:08 +00006526 }
Greg Clayton20568dd2011-10-13 23:13:20 +00006527 }
Greg Clayton72da3972011-08-16 18:40:23 +00006528 }
6529 else
6530 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006531 // We were asked to parse the type for a method in a class, yet the
6532 // class hasn't been asked to complete itself through the
6533 // clang::ExternalASTSource protocol, so we need to just have the
6534 // class complete itself and do things the right way, then our
6535 // DIE should then have an entry in the m_die_to_type map. First
6536 // we need to modify the m_die_to_type so it doesn't think we are
6537 // trying to parse this DIE anymore...
6538 m_die_to_type[die] = NULL;
6539
6540 // Now we get the full type to force our class type to complete itself
6541 // using the clang::ExternalASTSource protocol which will parse all
6542 // base classes and all methods (including the method for this DIE).
6543 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00006544
Greg Clayton20568dd2011-10-13 23:13:20 +00006545 // The type for this DIE should have been filled in the function call above
6546 type_ptr = m_die_to_type[die];
Greg Claytone5476db2012-06-01 20:32:35 +00006547 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton20568dd2011-10-13 23:13:20 +00006548 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006549 type_sp = type_ptr->shared_from_this();
Greg Clayton20568dd2011-10-13 23:13:20 +00006550 break;
6551 }
Sean Callanan02eee4d2012-04-12 23:10:00 +00006552
6553 // FIXME This is fixing some even uglier behavior but we really need to
6554 // uniq the methods of each class as well as the class itself.
6555 // <rdar://problem/11240464>
6556 type_handled = true;
Greg Clayton72da3972011-08-16 18:40:23 +00006557 }
Greg Clayton931180e2011-01-27 06:44:37 +00006558 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006559 }
6560 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006561 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006562 }
Greg Clayton24739922010-10-13 03:15:28 +00006563
6564 if (!type_handled)
6565 {
6566 // We just have a function that isn't part of a class
Sean Callanande9ce872013-05-09 23:13:13 +00006567 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (ignore_containing_context ? GetClangASTContext().GetTranslationUnitDecl() : containing_decl_ctx,
Greg Clayton147e1fa2011-10-14 22:47:18 +00006568 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006569 clang_type,
6570 storage,
6571 is_inline);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006572
6573// if (template_param_infos.GetSize() > 0)
6574// {
6575// clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
6576// function_decl,
6577// type_name_cstr,
6578// template_param_infos);
6579//
6580// ast.CreateFunctionTemplateSpecializationInfo (function_decl,
6581// func_template_decl,
6582// template_param_infos);
6583// }
Greg Clayton24739922010-10-13 03:15:28 +00006584 // Add the decl to our DIE to decl context map
6585 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00006586 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00006587 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006588 ast.SetFunctionParameters (function_decl,
6589 &function_param_decls.front(),
6590 function_param_decls.size());
Sean Callanan60217122012-04-13 00:10:03 +00006591
Jim Ingham379397632012-10-27 02:54:13 +00006592 ClangASTMetadata metadata;
6593 metadata.SetUserID(MakeUserID(die->GetOffset()));
6594
6595 if (!object_pointer_name.empty())
6596 {
6597 metadata.SetObjectPtrName(object_pointer_name.c_str());
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006598 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006599 log->Printf ("Setting object pointer name: %s on function object %p.",
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006600 object_pointer_name.c_str(),
Greg Claytond0029442013-03-27 01:48:02 +00006601 function_decl);
Jim Ingham379397632012-10-27 02:54:13 +00006602 }
Greg Claytond0029442013-03-27 01:48:02 +00006603 GetClangASTContext().SetMetadata (function_decl, metadata);
Greg Clayton24739922010-10-13 03:15:28 +00006604 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006605 }
Greg Clayton81c22f62011-10-19 18:09:39 +00006606 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006607 this,
6608 type_name_const_str,
6609 0,
6610 NULL,
6611 LLDB_INVALID_UID,
6612 Type::eEncodingIsUID,
6613 &decl,
6614 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006615 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00006616 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006617 }
6618 break;
6619
6620 case DW_TAG_array_type:
6621 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006622 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006623 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006624
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006625 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006626 int64_t first_index = 0;
6627 uint32_t byte_stride = 0;
6628 uint32_t bit_stride = 0;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006629 bool is_vector = false;
Greg Claytond88d7592010-09-15 08:33:30 +00006630 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006631
6632 if (num_attributes > 0)
6633 {
6634 uint32_t i;
6635 for (i=0; i<num_attributes; ++i)
6636 {
6637 attr = attributes.AttributeAtIndex(i);
6638 DWARFFormValue form_value;
6639 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6640 {
6641 switch (attr)
6642 {
6643 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6644 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6645 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6646 case DW_AT_name:
6647 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006648 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006649 break;
6650
6651 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006652 case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006653 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
6654 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006655 case DW_AT_GNU_vector: is_vector = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006656 case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006657 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006658 case DW_AT_allocated:
6659 case DW_AT_associated:
6660 case DW_AT_data_location:
6661 case DW_AT_description:
6662 case DW_AT_ordering:
6663 case DW_AT_start_scope:
6664 case DW_AT_visibility:
6665 case DW_AT_specification:
6666 case DW_AT_abstract_origin:
6667 case DW_AT_sibling:
6668 break;
6669 }
6670 }
6671 }
6672
Daniel Malead01b2952012-11-29 21:49:15 +00006673 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 +00006674
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006675 Type *element_type = ResolveTypeUID(type_die_offset);
6676
6677 if (element_type)
6678 {
6679 std::vector<uint64_t> element_orders;
6680 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
6681 if (byte_stride == 0 && bit_stride == 0)
6682 byte_stride = element_type->GetByteSize();
Greg Clayton42ce2f32011-12-12 21:50:19 +00006683 clang_type_t array_element_type = element_type->GetClangForwardType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006684 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
6685 uint64_t num_elements = 0;
6686 std::vector<uint64_t>::const_reverse_iterator pos;
6687 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
6688 for (pos = element_orders.rbegin(); pos != end; ++pos)
6689 {
6690 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006691 clang_type = ast.CreateArrayType (array_element_type,
Greg Clayton1c8ef472013-04-05 23:27:21 +00006692 num_elements,
6693 is_vector);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006694 array_element_type = clang_type;
Greg Clayton4ef877f2012-12-06 02:33:54 +00006695 array_element_bit_stride = num_elements ? array_element_bit_stride * num_elements : array_element_bit_stride;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006696 }
6697 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00006698 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006699 this,
6700 empty_name,
6701 array_element_bit_stride / 8,
6702 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00006703 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006704 Type::eEncodingIsUID,
6705 &decl,
6706 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006707 Type::eResolveStateFull));
6708 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006709 }
6710 }
6711 }
6712 break;
6713
Greg Clayton9b81a312010-06-12 01:20:30 +00006714 case DW_TAG_ptr_to_member_type:
6715 {
6716 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
6717 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
6718
Greg Claytond88d7592010-09-15 08:33:30 +00006719 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00006720
6721 if (num_attributes > 0) {
6722 uint32_t i;
6723 for (i=0; i<num_attributes; ++i)
6724 {
6725 attr = attributes.AttributeAtIndex(i);
6726 DWARFFormValue form_value;
6727 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6728 {
6729 switch (attr)
6730 {
6731 case DW_AT_type:
6732 type_die_offset = form_value.Reference(dwarf_cu); break;
6733 case DW_AT_containing_type:
6734 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
6735 }
6736 }
6737 }
6738
6739 Type *pointee_type = ResolveTypeUID(type_die_offset);
6740 Type *class_type = ResolveTypeUID(containing_type_die_offset);
6741
Greg Clayton526e5af2010-11-13 03:52:47 +00006742 clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
6743 clang_type_t class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00006744
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006745 clang_type = ast.CreateMemberPointerType(pointee_clang_type,
6746 class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00006747
Greg Clayton526e5af2010-11-13 03:52:47 +00006748 byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(),
6749 clang_type) / 8;
Greg Clayton9b81a312010-06-12 01:20:30 +00006750
Greg Clayton81c22f62011-10-19 18:09:39 +00006751 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006752 this,
6753 type_name_const_str,
6754 byte_size,
6755 NULL,
6756 LLDB_INVALID_UID,
6757 Type::eEncodingIsUID,
6758 NULL,
6759 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006760 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00006761 }
6762
6763 break;
6764 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006765 default:
Greg Clayton84afacd2012-11-07 23:09:32 +00006766 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",
6767 die->GetOffset(),
6768 tag,
6769 DW_TAG_value_to_name(tag));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006770 break;
6771 }
6772
6773 if (type_sp.get())
6774 {
6775 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
6776 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
6777
6778 SymbolContextScope * symbol_context_scope = NULL;
6779 if (sc_parent_tag == DW_TAG_compile_unit)
6780 {
6781 symbol_context_scope = sc.comp_unit;
6782 }
6783 else if (sc.function != NULL)
6784 {
Greg Clayton81c22f62011-10-19 18:09:39 +00006785 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006786 if (symbol_context_scope == NULL)
6787 symbol_context_scope = sc.function;
6788 }
6789
6790 if (symbol_context_scope != NULL)
6791 {
6792 type_sp->SetSymbolContextScope(symbol_context_scope);
6793 }
6794
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006795 // We are ready to put this type into the uniqued list up at the module level
6796 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00006797
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006798 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006799 }
6800 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00006801 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006802 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006803 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006804 }
6805 }
6806 return type_sp;
6807}
6808
6809size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00006810SymbolFileDWARF::ParseTypes
6811(
6812 const SymbolContext& sc,
6813 DWARFCompileUnit* dwarf_cu,
6814 const DWARFDebugInfoEntry *die,
6815 bool parse_siblings,
6816 bool parse_children
6817)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006818{
6819 size_t types_added = 0;
6820 while (die != NULL)
6821 {
6822 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00006823 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006824 {
6825 if (type_is_new)
6826 ++types_added;
6827 }
6828
6829 if (parse_children && die->HasChildren())
6830 {
6831 if (die->Tag() == DW_TAG_subprogram)
6832 {
6833 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00006834 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006835 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
6836 }
6837 else
6838 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
6839 }
6840
6841 if (parse_siblings)
6842 die = die->GetSibling();
6843 else
6844 die = NULL;
6845 }
6846 return types_added;
6847}
6848
6849
6850size_t
6851SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
6852{
6853 assert(sc.comp_unit && sc.function);
6854 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00006855 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006856 if (dwarf_cu)
6857 {
6858 dw_offset_t function_die_offset = sc.function->GetID();
6859 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
6860 if (function_die)
6861 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00006862 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006863 }
6864 }
6865
6866 return functions_added;
6867}
6868
6869
6870size_t
6871SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
6872{
6873 // At least a compile unit must be valid
6874 assert(sc.comp_unit);
6875 size_t types_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00006876 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006877 if (dwarf_cu)
6878 {
6879 if (sc.function)
6880 {
6881 dw_offset_t function_die_offset = sc.function->GetID();
6882 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
6883 if (func_die && func_die->HasChildren())
6884 {
6885 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
6886 }
6887 }
6888 else
6889 {
6890 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
6891 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
6892 {
6893 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
6894 }
6895 }
6896 }
6897
6898 return types_added;
6899}
6900
6901size_t
6902SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
6903{
6904 if (sc.comp_unit != NULL)
6905 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00006906 DWARFDebugInfo* info = DebugInfo();
6907 if (info == NULL)
6908 return 0;
6909
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006910 if (sc.function)
6911 {
Greg Clayton9422dd62013-03-04 21:46:16 +00006912 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get();
6913
6914 if (dwarf_cu == NULL)
6915 return 0;
6916
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006917 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00006918
Greg Claytonc7bece562013-01-25 18:06:21 +00006919 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
6920 if (func_lo_pc != LLDB_INVALID_ADDRESS)
Greg Claytone38a5ed2012-01-05 03:57:59 +00006921 {
6922 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00006923
Greg Claytone38a5ed2012-01-05 03:57:59 +00006924 // Let all blocks know they have parse all their variables
6925 sc.function->GetBlock (false).SetDidParseVariables (true, true);
6926 return num_variables;
6927 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006928 }
6929 else if (sc.comp_unit)
6930 {
Greg Clayton9422dd62013-03-04 21:46:16 +00006931 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get();
6932
6933 if (dwarf_cu == NULL)
6934 return 0;
6935
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006936 uint32_t vars_added = 0;
6937 VariableListSP variables (sc.comp_unit->GetVariableList(false));
6938
6939 if (variables.get() == NULL)
6940 {
6941 variables.reset(new VariableList());
6942 sc.comp_unit->SetVariableList(variables);
6943
Greg Claytond4a2b372011-09-12 23:21:58 +00006944 DWARFCompileUnit* match_dwarf_cu = NULL;
6945 const DWARFDebugInfoEntry* die = NULL;
6946 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00006947 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00006948 {
Greg Clayton97fbc342011-10-20 22:30:33 +00006949 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00006950 {
6951 DWARFMappedHash::DIEInfoArray hash_data_array;
6952 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
6953 dwarf_cu->GetNextCompileUnitOffset(),
6954 hash_data_array))
6955 {
6956 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
6957 }
6958 }
Greg Clayton7f995132011-10-04 22:41:51 +00006959 }
6960 else
6961 {
6962 // Index if we already haven't to make sure the compile units
6963 // get indexed and make their global DIE index list
6964 if (!m_indexed)
6965 Index ();
6966
6967 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
6968 dwarf_cu->GetNextCompileUnitOffset(),
6969 die_offsets);
6970 }
6971
6972 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00006973 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006974 {
Greg Claytond4a2b372011-09-12 23:21:58 +00006975 DWARFDebugInfo* debug_info = DebugInfo();
6976 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006977 {
Greg Claytond4a2b372011-09-12 23:21:58 +00006978 const dw_offset_t die_offset = die_offsets[i];
6979 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00006980 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00006981 {
Greg Clayton95d87902011-11-11 03:16:25 +00006982 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
6983 if (var_sp)
6984 {
6985 variables->AddVariableIfUnique (var_sp);
6986 ++vars_added;
6987 }
Greg Claytond4a2b372011-09-12 23:21:58 +00006988 }
Greg Clayton95d87902011-11-11 03:16:25 +00006989 else
6990 {
6991 if (m_using_apple_tables)
6992 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00006993 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 +00006994 }
6995 }
6996
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006997 }
6998 }
6999 }
7000 return vars_added;
7001 }
7002 }
7003 return 0;
7004}
7005
7006
7007VariableSP
7008SymbolFileDWARF::ParseVariableDIE
7009(
7010 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007011 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007012 const DWARFDebugInfoEntry *die,
7013 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007014)
7015{
7016
Greg Clayton83c5cd92010-11-14 22:13:40 +00007017 VariableSP var_sp (m_die_to_variable_sp[die]);
7018 if (var_sp)
7019 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007020
7021 const dw_tag_t tag = die->Tag();
Greg Clayton7f995132011-10-04 22:41:51 +00007022
7023 if ((tag == DW_TAG_variable) ||
7024 (tag == DW_TAG_constant) ||
7025 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007026 {
Greg Clayton7f995132011-10-04 22:41:51 +00007027 DWARFDebugInfoEntry::Attributes attributes;
7028 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
7029 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007030 {
Greg Clayton7f995132011-10-04 22:41:51 +00007031 const char *name = NULL;
7032 const char *mangled = NULL;
7033 Declaration decl;
7034 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00007035 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00007036 DWARFExpression location;
7037 bool is_external = false;
7038 bool is_artificial = false;
7039 bool location_is_const_value_data = false;
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007040 bool has_explicit_location = false;
Greg Clayton23f59502012-07-17 03:23:13 +00007041 //AccessType accessibility = eAccessNone;
Greg Clayton7f995132011-10-04 22:41:51 +00007042
7043 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007044 {
Greg Clayton7f995132011-10-04 22:41:51 +00007045 dw_attr_t attr = attributes.AttributeAtIndex(i);
7046 DWARFFormValue form_value;
7047 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007048 {
Greg Clayton7f995132011-10-04 22:41:51 +00007049 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007050 {
Greg Clayton7f995132011-10-04 22:41:51 +00007051 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
7052 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
7053 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
7054 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton71415542012-12-08 00:24:40 +00007055 case DW_AT_linkage_name:
Greg Clayton7f995132011-10-04 22:41:51 +00007056 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Claytond1767f02011-12-08 02:13:16 +00007057 case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00007058 case DW_AT_external: is_external = form_value.Boolean(); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007059 case DW_AT_const_value:
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007060 // If we have already found a DW_AT_location attribute, ignore this attribute.
7061 if (!has_explicit_location)
7062 {
7063 location_is_const_value_data = true;
7064 // The constant value will be either a block, a data value or a string.
7065 const DataExtractor& debug_info_data = get_debug_info_data();
7066 if (DWARFFormValue::IsBlockForm(form_value.Form()))
7067 {
7068 // Retrieve the value as a block expression.
7069 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7070 uint32_t block_length = form_value.Unsigned();
7071 location.CopyOpcodeData(debug_info_data, block_offset, block_length);
7072 }
7073 else if (DWARFFormValue::IsDataForm(form_value.Form()))
7074 {
7075 // Retrieve the value as a data expression.
7076 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
7077 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7078 uint32_t data_length = fixed_form_sizes[form_value.Form()];
7079 location.CopyOpcodeData(debug_info_data, data_offset, data_length);
7080 }
7081 else
7082 {
7083 // Retrieve the value as a string expression.
7084 if (form_value.Form() == DW_FORM_strp)
7085 {
7086 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
7087 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7088 uint32_t data_length = fixed_form_sizes[form_value.Form()];
7089 location.CopyOpcodeData(debug_info_data, data_offset, data_length);
7090 }
7091 else
7092 {
7093 const char *str = form_value.AsCString(&debug_info_data);
7094 uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart();
7095 uint32_t string_length = strlen(str) + 1;
7096 location.CopyOpcodeData(debug_info_data, string_offset, string_length);
7097 }
7098 }
7099 }
7100 break;
Greg Clayton7f995132011-10-04 22:41:51 +00007101 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007102 {
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007103 location_is_const_value_data = false;
7104 has_explicit_location = true;
Greg Clayton7f995132011-10-04 22:41:51 +00007105 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007106 {
Greg Clayton7f995132011-10-04 22:41:51 +00007107 const DataExtractor& debug_info_data = get_debug_info_data();
7108
7109 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7110 uint32_t block_length = form_value.Unsigned();
Greg Clayton7f4c7432012-08-11 00:49:14 +00007111 location.CopyOpcodeData(get_debug_info_data(), block_offset, block_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007112 }
7113 else
7114 {
7115 const DataExtractor& debug_loc_data = get_debug_loc_data();
7116 const dw_offset_t debug_loc_offset = form_value.Unsigned();
7117
7118 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
7119 if (loc_list_length > 0)
7120 {
Greg Clayton7f4c7432012-08-11 00:49:14 +00007121 location.CopyOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007122 assert (func_low_pc != LLDB_INVALID_ADDRESS);
7123 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
7124 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007125 }
7126 }
Greg Clayton7f995132011-10-04 22:41:51 +00007127 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007128
Greg Clayton1c8ef472013-04-05 23:27:21 +00007129 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00007130 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007131 case DW_AT_declaration:
7132 case DW_AT_description:
7133 case DW_AT_endianity:
7134 case DW_AT_segment:
7135 case DW_AT_start_scope:
7136 case DW_AT_visibility:
7137 default:
7138 case DW_AT_abstract_origin:
7139 case DW_AT_sibling:
7140 case DW_AT_specification:
7141 break;
7142 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007143 }
7144 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007145
Greg Clayton7f995132011-10-04 22:41:51 +00007146 if (location.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007147 {
Greg Clayton7f995132011-10-04 22:41:51 +00007148 ValueType scope = eValueTypeInvalid;
7149
7150 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7151 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007152 SymbolContextScope * symbol_context_scope = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00007153
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007154 // DWARF doesn't specify if a DW_TAG_variable is a local, global
7155 // or static variable, so we have to do a little digging by
7156 // looking at the location of a varaible to see if it contains
7157 // a DW_OP_addr opcode _somewhere_ in the definition. I say
7158 // somewhere because clang likes to combine small global variables
7159 // into the same symbol and have locations like:
7160 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
7161 // So if we don't have a DW_TAG_formal_parameter, we can look at
7162 // the location to see if it contains a DW_OP_addr opcode, and
7163 // then we can correctly classify our variables.
Greg Clayton7f995132011-10-04 22:41:51 +00007164 if (tag == DW_TAG_formal_parameter)
7165 scope = eValueTypeVariableArgument;
Greg Claytond1767f02011-12-08 02:13:16 +00007166 else
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007167 {
Greg Clayton96c09682012-01-04 22:56:43 +00007168 bool op_error = false;
Greg Claytond1767f02011-12-08 02:13:16 +00007169 // Check if the location has a DW_OP_addr with any address value...
Greg Clayton9422dd62013-03-04 21:46:16 +00007170 lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS;
Greg Claytond1767f02011-12-08 02:13:16 +00007171 if (!location_is_const_value_data)
Greg Clayton96c09682012-01-04 22:56:43 +00007172 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007173 location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error);
Greg Clayton96c09682012-01-04 22:56:43 +00007174 if (op_error)
7175 {
7176 StreamString strm;
7177 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
Greg Claytone38a5ed2012-01-05 03:57:59 +00007178 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 +00007179 }
7180 }
Greg Claytond1767f02011-12-08 02:13:16 +00007181
Greg Clayton9422dd62013-03-04 21:46:16 +00007182 if (location_DW_OP_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007183 {
Greg Claytond1767f02011-12-08 02:13:16 +00007184 if (is_external)
Greg Claytond1767f02011-12-08 02:13:16 +00007185 scope = eValueTypeVariableGlobal;
Greg Clayton9422dd62013-03-04 21:46:16 +00007186 else
7187 scope = eValueTypeVariableStatic;
7188
7189
7190 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile ();
7191
7192 if (debug_map_symfile)
7193 {
7194 // When leaving the DWARF in the .o files on darwin,
7195 // when we have a global variable that wasn't initialized,
7196 // the .o file might not have allocated a virtual
7197 // address for the global variable. In this case it will
7198 // have created a symbol for the global variable
7199 // that is undefined/data and external and the value will
7200 // be the byte size of the variable. When we do the
7201 // address map in SymbolFileDWARFDebugMap we rely on
7202 // having an address, we need to do some magic here
7203 // so we can get the correct address for our global
7204 // variable. The address for all of these entries
7205 // will be zero, and there will be an undefined symbol
7206 // in this object file, and the executable will have
7207 // a matching symbol with a good address. So here we
7208 // dig up the correct address and replace it in the
7209 // location for the variable, and set the variable's
7210 // symbol context scope to be that of the main executable
7211 // so the file address will resolve correctly.
7212 bool linked_oso_file_addr = false;
7213 if (is_external && location_DW_OP_addr == 0)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007214 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007215
7216 // we have a possible uninitialized extern global
7217 ConstString const_name(mangled ? mangled : name);
7218 ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile();
7219 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007220 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007221 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
7222 if (debug_map_symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007223 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007224 Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
7225 eSymbolTypeData,
7226 Symtab::eDebugYes,
7227 Symtab::eVisibilityExtern);
7228 if (exe_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007229 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007230 if (exe_symbol->ValueIsAddress())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007231 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007232 const addr_t exe_file_addr = exe_symbol->GetAddress().GetFileAddress();
7233 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007234 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007235 if (location.Update_DW_OP_addr (exe_file_addr))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007236 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007237 linked_oso_file_addr = true;
7238 symbol_context_scope = exe_symbol;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007239 }
7240 }
7241 }
7242 }
7243 }
7244 }
7245 }
Greg Clayton9422dd62013-03-04 21:46:16 +00007246
7247 if (!linked_oso_file_addr)
7248 {
7249 // The DW_OP_addr is not zero, but it contains a .o file address which
7250 // needs to be linked up correctly.
7251 const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr);
7252 if (exe_file_addr != LLDB_INVALID_ADDRESS)
7253 {
7254 // Update the file address for this variable
7255 location.Update_DW_OP_addr (exe_file_addr);
7256 }
7257 else
7258 {
7259 // Variable didn't make it into the final executable
7260 return var_sp;
7261 }
7262 }
Greg Claytond1767f02011-12-08 02:13:16 +00007263 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007264 }
7265 else
Greg Claytond1767f02011-12-08 02:13:16 +00007266 {
7267 scope = eValueTypeVariableLocal;
7268 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007269 }
Greg Clayton7f995132011-10-04 22:41:51 +00007270
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007271 if (symbol_context_scope == NULL)
Greg Clayton7f995132011-10-04 22:41:51 +00007272 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007273 switch (parent_tag)
Greg Clayton5cf58b92011-10-05 22:22:08 +00007274 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007275 case DW_TAG_subprogram:
7276 case DW_TAG_inlined_subroutine:
7277 case DW_TAG_lexical_block:
7278 if (sc.function)
7279 {
7280 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
7281 if (symbol_context_scope == NULL)
7282 symbol_context_scope = sc.function;
7283 }
7284 break;
7285
7286 default:
7287 symbol_context_scope = sc.comp_unit;
7288 break;
Greg Clayton5cf58b92011-10-05 22:22:08 +00007289 }
Greg Clayton7f995132011-10-04 22:41:51 +00007290 }
7291
Greg Clayton5cf58b92011-10-05 22:22:08 +00007292 if (symbol_context_scope)
7293 {
Greg Clayton81c22f62011-10-19 18:09:39 +00007294 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
7295 name,
7296 mangled,
Greg Claytond1767f02011-12-08 02:13:16 +00007297 SymbolFileTypeSP (new SymbolFileType(*this, type_uid)),
Greg Clayton81c22f62011-10-19 18:09:39 +00007298 scope,
7299 symbol_context_scope,
7300 &decl,
7301 location,
7302 is_external,
7303 is_artificial));
Greg Clayton5cf58b92011-10-05 22:22:08 +00007304
7305 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
7306 }
7307 else
7308 {
7309 // Not ready to parse this variable yet. It might be a global
7310 // or static variable that is in a function scope and the function
7311 // in the symbol context wasn't filled in yet
7312 return var_sp;
7313 }
Greg Clayton7f995132011-10-04 22:41:51 +00007314 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007315 }
Greg Clayton7f995132011-10-04 22:41:51 +00007316 // Cache var_sp even if NULL (the variable was just a specification or
7317 // was missing vital information to be able to be displayed in the debugger
7318 // (missing location due to optimization, etc)) so we don't re-parse
7319 // this DIE over and over later...
7320 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007321 }
7322 return var_sp;
7323}
7324
Greg Claytonc662ec82011-06-17 22:10:16 +00007325
7326const DWARFDebugInfoEntry *
7327SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
7328 dw_offset_t spec_block_die_offset,
7329 DWARFCompileUnit **result_die_cu_handle)
7330{
7331 // Give the concrete function die specified by "func_die_offset", find the
7332 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7333 // to "spec_block_die_offset"
7334 DWARFDebugInfo* info = DebugInfo();
7335
7336 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
7337 if (die)
7338 {
7339 assert (*result_die_cu_handle);
7340 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
7341 }
7342 return NULL;
7343}
7344
7345
7346const DWARFDebugInfoEntry *
7347SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
7348 const DWARFDebugInfoEntry *die,
7349 dw_offset_t spec_block_die_offset,
7350 DWARFCompileUnit **result_die_cu_handle)
7351{
7352 if (die)
7353 {
7354 switch (die->Tag())
7355 {
7356 case DW_TAG_subprogram:
7357 case DW_TAG_inlined_subroutine:
7358 case DW_TAG_lexical_block:
7359 {
7360 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
7361 {
7362 *result_die_cu_handle = dwarf_cu;
7363 return die;
7364 }
7365
7366 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
7367 {
7368 *result_die_cu_handle = dwarf_cu;
7369 return die;
7370 }
7371 }
7372 break;
7373 }
7374
7375 // Give the concrete function die specified by "func_die_offset", find the
7376 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7377 // to "spec_block_die_offset"
7378 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
7379 {
7380 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
7381 child_die,
7382 spec_block_die_offset,
7383 result_die_cu_handle);
7384 if (result_die)
7385 return result_die;
7386 }
7387 }
7388
7389 *result_die_cu_handle = NULL;
7390 return NULL;
7391}
7392
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007393size_t
7394SymbolFileDWARF::ParseVariables
7395(
7396 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007397 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007398 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007399 const DWARFDebugInfoEntry *orig_die,
7400 bool parse_siblings,
7401 bool parse_children,
7402 VariableList* cc_variable_list
7403)
7404{
7405 if (orig_die == NULL)
7406 return 0;
7407
Greg Claytonc662ec82011-06-17 22:10:16 +00007408 VariableListSP variable_list_sp;
7409
7410 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007411 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00007412 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007413 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007414 dw_tag_t tag = die->Tag();
7415
7416 // Check to see if we have already parsed this variable or constant?
7417 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007418 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007419 if (cc_variable_list)
7420 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007421 }
7422 else
7423 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007424 // We haven't already parsed it, lets do that now.
7425 if ((tag == DW_TAG_variable) ||
7426 (tag == DW_TAG_constant) ||
7427 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007428 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007429 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00007430 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007431 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
7432 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7433 switch (parent_tag)
7434 {
7435 case DW_TAG_compile_unit:
7436 if (sc.comp_unit != NULL)
7437 {
7438 variable_list_sp = sc.comp_unit->GetVariableList(false);
7439 if (variable_list_sp.get() == NULL)
7440 {
7441 variable_list_sp.reset(new VariableList());
7442 sc.comp_unit->SetVariableList(variable_list_sp);
7443 }
7444 }
7445 else
7446 {
Daniel Malead01b2952012-11-29 21:49:15 +00007447 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 +00007448 MakeUserID(sc_parent_die->GetOffset()),
7449 DW_TAG_value_to_name (parent_tag),
7450 MakeUserID(orig_die->GetOffset()),
7451 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007452 }
7453 break;
7454
7455 case DW_TAG_subprogram:
7456 case DW_TAG_inlined_subroutine:
7457 case DW_TAG_lexical_block:
7458 if (sc.function != NULL)
7459 {
7460 // Check to see if we already have parsed the variables for the given scope
7461
Greg Clayton81c22f62011-10-19 18:09:39 +00007462 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007463 if (block == NULL)
7464 {
7465 // This must be a specification or abstract origin with
7466 // a concrete block couterpart in the current function. We need
7467 // to find the concrete block so we can correctly add the
7468 // variable to it
7469 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
7470 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
7471 sc_parent_die->GetOffset(),
7472 &concrete_block_die_cu);
7473 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00007474 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007475 }
7476
7477 if (block != NULL)
7478 {
7479 const bool can_create = false;
7480 variable_list_sp = block->GetBlockVariableList (can_create);
7481 if (variable_list_sp.get() == NULL)
7482 {
7483 variable_list_sp.reset(new VariableList());
7484 block->SetVariableList(variable_list_sp);
7485 }
7486 }
7487 }
7488 break;
7489
7490 default:
Daniel Malead01b2952012-11-29 21:49:15 +00007491 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 +00007492 MakeUserID(orig_die->GetOffset()),
7493 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007494 break;
7495 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00007496 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007497
7498 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007499 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00007500 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
7501 if (var_sp)
7502 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007503 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00007504 if (cc_variable_list)
7505 cc_variable_list->AddVariableIfUnique (var_sp);
7506 ++vars_added;
7507 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007508 }
7509 }
7510 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007511
7512 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
7513
7514 if (!skip_children && parse_children && die->HasChildren())
7515 {
7516 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
7517 }
7518
7519 if (parse_siblings)
7520 die = die->GetSibling();
7521 else
7522 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007523 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007524 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007525}
7526
7527//------------------------------------------------------------------
7528// PluginInterface protocol
7529//------------------------------------------------------------------
7530const char *
7531SymbolFileDWARF::GetPluginName()
7532{
7533 return "SymbolFileDWARF";
7534}
7535
7536const char *
7537SymbolFileDWARF::GetShortPluginName()
7538{
7539 return GetPluginNameStatic();
7540}
7541
7542uint32_t
7543SymbolFileDWARF::GetPluginVersion()
7544{
7545 return 1;
7546}
7547
7548void
Greg Clayton6beaaa62011-01-17 03:46:26 +00007549SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
7550{
7551 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7552 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
7553 if (clang_type)
7554 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7555}
7556
7557void
7558SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
7559{
7560 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7561 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
7562 if (clang_type)
7563 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7564}
7565
Greg Claytona2721472011-06-25 00:44:06 +00007566void
Sean Callanancc427fa2011-07-30 02:42:06 +00007567SymbolFileDWARF::DumpIndexes ()
7568{
7569 StreamFile s(stdout, false);
7570
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00007571 s.Printf ("DWARF index for (%s) '%s':",
Sean Callanancc427fa2011-07-30 02:42:06 +00007572 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00007573 GetObjectFile()->GetFileSpec().GetPath().c_str());
Sean Callanancc427fa2011-07-30 02:42:06 +00007574 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
7575 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
7576 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
7577 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
7578 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
7579 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
7580 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
7581 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
7582}
7583
7584void
7585SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
7586 const char *name,
7587 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00007588{
Sean Callanancc427fa2011-07-30 02:42:06 +00007589 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00007590
7591 if (iter == m_decl_ctx_to_die.end())
7592 return;
7593
Greg Claytoncb5860a2011-10-13 23:49:28 +00007594 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00007595 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007596 const DWARFDebugInfoEntry *context_die = *pos;
7597
7598 if (!results)
7599 return;
7600
7601 DWARFDebugInfo* info = DebugInfo();
7602
7603 DIEArray die_offsets;
7604
7605 DWARFCompileUnit* dwarf_cu = NULL;
7606 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton220a0072011-12-09 08:48:30 +00007607
7608 if (m_using_apple_tables)
7609 {
7610 if (m_apple_types_ap.get())
7611 m_apple_types_ap->FindByName (name, die_offsets);
7612 }
7613 else
7614 {
7615 if (!m_indexed)
7616 Index ();
7617
7618 m_type_index.Find (ConstString(name), die_offsets);
7619 }
7620
Greg Clayton220a0072011-12-09 08:48:30 +00007621 const size_t num_matches = die_offsets.size();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007622
7623 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00007624 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007625 for (size_t i = 0; i < num_matches; ++i)
7626 {
7627 const dw_offset_t die_offset = die_offsets[i];
7628 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00007629
Greg Claytoncb5860a2011-10-13 23:49:28 +00007630 if (die->GetParent() != context_die)
7631 continue;
7632
7633 Type *matching_type = ResolveType (dwarf_cu, die);
7634
Greg Clayton42ce2f32011-12-12 21:50:19 +00007635 lldb::clang_type_t type = matching_type->GetClangForwardType();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007636 clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type);
7637
7638 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
7639 {
7640 clang::TagDecl *tag_decl = tag_type->getDecl();
7641 results->push_back(tag_decl);
7642 }
7643 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
7644 {
7645 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
7646 results->push_back(typedef_decl);
7647 }
Greg Claytona2721472011-06-25 00:44:06 +00007648 }
7649 }
7650 }
7651}
7652
7653void
7654SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00007655 const clang::DeclContext *decl_context,
7656 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00007657 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
7658{
Greg Clayton85ae2e12011-10-18 23:36:41 +00007659
7660 switch (decl_context->getDeclKind())
7661 {
7662 case clang::Decl::Namespace:
7663 case clang::Decl::TranslationUnit:
7664 {
7665 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7666 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
7667 }
7668 break;
7669 default:
7670 break;
7671 }
Greg Claytona2721472011-06-25 00:44:06 +00007672}
Greg Claytoncaab74e2012-01-28 00:48:57 +00007673
7674bool
7675SymbolFileDWARF::LayoutRecordType (void *baton,
7676 const clang::RecordDecl *record_decl,
7677 uint64_t &size,
7678 uint64_t &alignment,
7679 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7680 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7681 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7682{
7683 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7684 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
7685}
7686
7687
7688bool
7689SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl,
7690 uint64_t &bit_size,
7691 uint64_t &alignment,
7692 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7693 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7694 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7695{
Greg Clayton5160ce52013-03-27 23:08:40 +00007696 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Claytoncaab74e2012-01-28 00:48:57 +00007697 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
7698 bool success = false;
7699 base_offsets.clear();
7700 vbase_offsets.clear();
7701 if (pos != m_record_decl_to_layout_map.end())
7702 {
7703 bit_size = pos->second.bit_size;
7704 alignment = pos->second.alignment;
7705 field_offsets.swap(pos->second.field_offsets);
Greg Clayton2508b9b2012-11-01 23:20:02 +00007706 base_offsets.swap (pos->second.base_offsets);
7707 vbase_offsets.swap (pos->second.vbase_offsets);
Greg Claytoncaab74e2012-01-28 00:48:57 +00007708 m_record_decl_to_layout_map.erase(pos);
7709 success = true;
7710 }
7711 else
7712 {
7713 bit_size = 0;
7714 alignment = 0;
7715 field_offsets.clear();
7716 }
7717
7718 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00007719 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00007720 "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 +00007721 record_decl,
7722 bit_size,
7723 alignment,
7724 (uint32_t)field_offsets.size(),
7725 (uint32_t)base_offsets.size(),
7726 (uint32_t)vbase_offsets.size(),
7727 success);
7728 return success;
7729}
7730
7731
Greg Clayton1f746072012-08-29 21:13:06 +00007732SymbolFileDWARFDebugMap *
7733SymbolFileDWARF::GetDebugMapSymfile ()
7734{
7735 if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired())
7736 {
7737 lldb::ModuleSP module_sp (m_debug_map_module_wp.lock());
7738 if (module_sp)
7739 {
7740 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
7741 if (sym_vendor)
7742 m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile();
7743 }
7744 }
7745 return m_debug_map_symfile;
7746}
7747
Greg Claytoncaab74e2012-01-28 00:48:57 +00007748