blob: 3583779604fce3a231c12f1baf367ae4ea4ff43d [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
1276 if (name && lldb_type && clang_type)
1277 {
1278 bool is_signed = false;
1279 template_param_infos.names.push_back(name);
1280 clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type));
1281 if (tag == DW_TAG_template_value_parameter && ClangASTContext::IsIntegerType (clang_type, is_signed) && uval64_valid)
1282 {
1283 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
Sean Callanan3d654b32012-09-24 22:25:51 +00001284 template_param_infos.args.push_back (clang::TemplateArgument (*GetClangASTContext().getASTContext(),
1285 llvm::APSInt(apint),
1286 clang_qual_type));
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001287 }
1288 else
1289 {
1290 template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type));
1291 }
1292 }
1293 else
1294 {
1295 return false;
1296 }
1297
1298 }
1299 }
1300 return true;
1301
1302 default:
1303 break;
1304 }
1305 return false;
1306}
1307
1308bool
Greg Claytonf0705c82011-10-22 03:33:13 +00001309SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1310 const DWARFDebugInfoEntry *parent_die,
1311 ClangASTContext::TemplateParameterInfos &template_param_infos)
1312{
1313
1314 if (parent_die == NULL)
Filipe Cabecinhas52008c62012-05-23 16:24:11 +00001315 return false;
Greg Claytonf0705c82011-10-22 03:33:13 +00001316
Greg Claytonf0705c82011-10-22 03:33:13 +00001317 Args template_parameter_names;
1318 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1319 die != NULL;
1320 die = die->GetSibling())
1321 {
1322 const dw_tag_t tag = die->Tag();
1323
1324 switch (tag)
1325 {
1326 case DW_TAG_template_type_parameter:
1327 case DW_TAG_template_value_parameter:
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001328 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Claytonf0705c82011-10-22 03:33:13 +00001329 break;
1330
1331 default:
1332 break;
1333 }
1334 }
1335 if (template_param_infos.args.empty())
1336 return false;
1337 return template_param_infos.args.size() == template_param_infos.names.size();
1338}
1339
1340clang::ClassTemplateDecl *
1341SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001342 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001343 const char *parent_name,
1344 int tag_decl_kind,
1345 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1346{
1347 if (template_param_infos.IsValid())
1348 {
1349 std::string template_basename(parent_name);
1350 template_basename.erase (template_basename.find('<'));
1351 ClangASTContext &ast = GetClangASTContext();
1352
1353 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001354 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001355 template_basename.c_str(),
1356 tag_decl_kind,
1357 template_param_infos);
1358 }
1359 return NULL;
1360}
1361
Sean Callanana0b80ab2012-06-04 22:28:05 +00001362class SymbolFileDWARF::DelayedAddObjCClassProperty
1363{
1364public:
1365 DelayedAddObjCClassProperty
1366 (
1367 clang::ASTContext *ast,
1368 lldb::clang_type_t class_opaque_type,
1369 const char *property_name,
1370 lldb::clang_type_t property_opaque_type, // The property type is only required if you don't have an ivar decl
1371 clang::ObjCIvarDecl *ivar_decl,
1372 const char *property_setter_name,
1373 const char *property_getter_name,
1374 uint32_t property_attributes,
Greg Claytonc4ffd662013-03-08 01:37:30 +00001375 const ClangASTMetadata *metadata
Sean Callanana0b80ab2012-06-04 22:28:05 +00001376 ) :
1377 m_ast (ast),
1378 m_class_opaque_type (class_opaque_type),
1379 m_property_name (property_name),
1380 m_property_opaque_type (property_opaque_type),
1381 m_ivar_decl (ivar_decl),
1382 m_property_setter_name (property_setter_name),
1383 m_property_getter_name (property_getter_name),
Jim Ingham379397632012-10-27 02:54:13 +00001384 m_property_attributes (property_attributes)
Sean Callanana0b80ab2012-06-04 22:28:05 +00001385 {
Jim Ingham379397632012-10-27 02:54:13 +00001386 if (metadata != NULL)
1387 {
1388 m_metadata_ap.reset(new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001389 *m_metadata_ap = *metadata;
Jim Ingham379397632012-10-27 02:54:13 +00001390 }
1391 }
1392
1393 DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs)
1394 {
Daniel Malead4c5be62012-11-12 21:02:14 +00001395 *this = rhs;
1396 }
1397
1398 DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs)
1399 {
Jim Ingham379397632012-10-27 02:54:13 +00001400 m_ast = rhs.m_ast;
1401 m_class_opaque_type = rhs.m_class_opaque_type;
1402 m_property_name = rhs.m_property_name;
1403 m_property_opaque_type = rhs.m_property_opaque_type;
1404 m_ivar_decl = rhs.m_ivar_decl;
1405 m_property_setter_name = rhs.m_property_setter_name;
1406 m_property_getter_name = rhs.m_property_getter_name;
1407 m_property_attributes = rhs.m_property_attributes;
1408
1409 if (rhs.m_metadata_ap.get())
1410 {
1411 m_metadata_ap.reset (new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001412 *m_metadata_ap = *rhs.m_metadata_ap;
Jim Ingham379397632012-10-27 02:54:13 +00001413 }
Daniel Malead4c5be62012-11-12 21:02:14 +00001414 return *this;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001415 }
1416
1417 bool Finalize() const
1418 {
Greg Claytonc4ffd662013-03-08 01:37:30 +00001419 return ClangASTContext::AddObjCClassProperty (m_ast,
1420 m_class_opaque_type,
1421 m_property_name,
1422 m_property_opaque_type,
1423 m_ivar_decl,
1424 m_property_setter_name,
1425 m_property_getter_name,
1426 m_property_attributes,
1427 m_metadata_ap.get());
Sean Callanana0b80ab2012-06-04 22:28:05 +00001428 }
1429private:
1430 clang::ASTContext *m_ast;
1431 lldb::clang_type_t m_class_opaque_type;
1432 const char *m_property_name;
1433 lldb::clang_type_t m_property_opaque_type;
1434 clang::ObjCIvarDecl *m_ivar_decl;
1435 const char *m_property_setter_name;
1436 const char *m_property_getter_name;
1437 uint32_t m_property_attributes;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001438 std::unique_ptr<ClangASTMetadata> m_metadata_ap;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001439};
1440
Sean Callananfaa0bb32012-12-05 23:37:14 +00001441struct BitfieldInfo
1442{
1443 uint64_t bit_size;
1444 uint64_t bit_offset;
1445
1446 BitfieldInfo () :
1447 bit_size (LLDB_INVALID_ADDRESS),
1448 bit_offset (LLDB_INVALID_ADDRESS)
1449 {
1450 }
1451
1452 bool IsValid ()
1453 {
1454 return (bit_size != LLDB_INVALID_ADDRESS) &&
1455 (bit_offset != LLDB_INVALID_ADDRESS);
1456 }
1457};
1458
Greg Claytonc4ffd662013-03-08 01:37:30 +00001459
1460bool
1461SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu,
1462 const DWARFDebugInfoEntry *parent_die)
1463{
1464 if (parent_die)
1465 {
1466 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1467 {
1468 dw_tag_t tag = die->Tag();
1469 bool check_virtuality = false;
1470 switch (tag)
1471 {
1472 case DW_TAG_inheritance:
1473 case DW_TAG_subprogram:
1474 check_virtuality = true;
1475 break;
1476 default:
1477 break;
1478 }
1479 if (check_virtuality)
1480 {
1481 if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0)
1482 return true;
1483 }
1484 }
1485 }
1486 return false;
1487}
1488
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001489size_t
1490SymbolFileDWARF::ParseChildMembers
1491(
1492 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001493 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001494 const DWARFDebugInfoEntry *parent_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00001495 clang_type_t class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001496 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001497 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1498 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001499 DWARFDIECollection& member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001500 DelayedPropertyList& delayed_properties,
Sean Callananc7fbf732010-08-06 00:32:49 +00001501 AccessType& default_accessibility,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001502 bool &is_a_class,
1503 LayoutInfo &layout_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001504)
1505{
1506 if (parent_die == NULL)
1507 return 0;
1508
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001509 size_t count = 0;
1510 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001511 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001512 uint32_t member_idx = 0;
Sean Callananfaa0bb32012-12-05 23:37:14 +00001513 BitfieldInfo last_field_info;
Greg Claytond88d7592010-09-15 08:33:30 +00001514
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001515 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1516 {
1517 dw_tag_t tag = die->Tag();
1518
1519 switch (tag)
1520 {
1521 case DW_TAG_member:
Sean Callanan3d654b32012-09-24 22:25:51 +00001522 case DW_TAG_APPLE_property:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001523 {
1524 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001525 const size_t num_attributes = die->GetAttributes (this,
1526 dwarf_cu,
1527 fixed_form_sizes,
1528 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001529 if (num_attributes > 0)
1530 {
1531 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001532 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001533 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001534 const char *prop_name = NULL;
1535 const char *prop_getter_name = NULL;
1536 const char *prop_setter_name = NULL;
Greg Claytone528efd72013-02-26 23:45:18 +00001537 uint32_t prop_attributes = 0;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001538
1539
Greg Clayton24739922010-10-13 03:15:28 +00001540 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001541 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001542 AccessType accessibility = eAccessNone;
Greg Claytoncaab74e2012-01-28 00:48:57 +00001543 uint32_t member_byte_offset = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001544 size_t byte_size = 0;
1545 size_t bit_offset = 0;
1546 size_t bit_size = 0;
Greg Claytone528efd72013-02-26 23:45:18 +00001547 bool is_external = false; // On DW_TAG_members, this means the member is static
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001548 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001549 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001550 {
1551 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1552 DWARFFormValue form_value;
1553 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1554 {
1555 switch (attr)
1556 {
1557 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1558 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1559 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1560 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1561 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1562 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1563 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1564 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1565 case DW_AT_data_member_location:
Greg Claytoncaab74e2012-01-28 00:48:57 +00001566 if (form_value.BlockData())
1567 {
1568 Value initialValue(0);
1569 Value memberOffset(0);
1570 const DataExtractor& debug_info_data = get_debug_info_data();
1571 uint32_t block_length = form_value.Unsigned();
1572 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1573 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
1574 NULL, // clang::ASTContext *
1575 NULL, // ClangExpressionVariableList *
1576 NULL, // ClangExpressionDeclMap *
1577 NULL, // RegisterContext *
1578 debug_info_data,
1579 block_offset,
1580 block_length,
1581 eRegisterKindDWARF,
1582 &initialValue,
1583 memberOffset,
1584 NULL))
1585 {
1586 member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1587 }
1588 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001589 break;
1590
Greg Clayton8cf05932010-07-22 18:30:50 +00001591 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00001592 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001593 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1594 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1595 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1596 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00001597 case DW_AT_external: is_external = form_value.Boolean(); break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001598
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001599 default:
Greg Clayton1b02c172012-03-14 21:00:47 +00001600 case DW_AT_declaration:
1601 case DW_AT_description:
1602 case DW_AT_mutable:
1603 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001604 case DW_AT_sibling:
1605 break;
1606 }
1607 }
1608 }
Sean Callanana6582262012-04-05 00:12:52 +00001609
1610 if (prop_name)
Sean Callanan751aac62012-03-29 19:07:06 +00001611 {
Sean Callanana6582262012-04-05 00:12:52 +00001612 ConstString fixed_getter;
1613 ConstString fixed_setter;
1614
1615 // Check if the property getter/setter were provided as full
1616 // names. We want basenames, so we extract them.
1617
1618 if (prop_getter_name && prop_getter_name[0] == '-')
1619 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001620 ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true);
1621 prop_getter_name = prop_getter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001622 }
1623
1624 if (prop_setter_name && prop_setter_name[0] == '-')
1625 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001626 ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true);
1627 prop_setter_name = prop_setter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001628 }
1629
1630 // If the names haven't been provided, they need to be
1631 // filled in.
1632
1633 if (!prop_getter_name)
1634 {
1635 prop_getter_name = prop_name;
1636 }
1637 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly))
1638 {
1639 StreamString ss;
1640
1641 ss.Printf("set%c%s:",
1642 toupper(prop_name[0]),
1643 &prop_name[1]);
1644
1645 fixed_setter.SetCString(ss.GetData());
1646 prop_setter_name = fixed_setter.GetCString();
1647 }
Sean Callanan751aac62012-03-29 19:07:06 +00001648 }
1649
1650 // Clang has a DWARF generation bug where sometimes it
Greg Clayton44953932011-10-25 01:25:35 +00001651 // represents fields that are references with bad byte size
1652 // and bit size/offset information such as:
1653 //
1654 // DW_AT_byte_size( 0x00 )
1655 // DW_AT_bit_size( 0x40 )
1656 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1657 //
1658 // So check the bit offset to make sure it is sane, and if
1659 // the values are not sane, remove them. If we don't do this
1660 // then we will end up with a crash if we try to use this
1661 // type in an expression when clang becomes unhappy with its
1662 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001663
Greg Clayton44953932011-10-25 01:25:35 +00001664 if (bit_offset > 128)
1665 {
1666 bit_size = 0;
1667 bit_offset = 0;
1668 }
1669
1670 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00001671 if (class_language == eLanguageTypeObjC ||
1672 class_language == eLanguageTypeObjC_plus_plus)
1673 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001674
1675 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1676 {
1677 // Not all compilers will mark the vtable pointer
1678 // member as artificial (llvm-gcc). We can't have
1679 // the virtual members in our classes otherwise it
1680 // throws off all child offsets since we end up
1681 // having and extra pointer sized member in our
1682 // class layouts.
1683 is_artificial = true;
1684 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001685
Greg Claytone528efd72013-02-26 23:45:18 +00001686 // Skip static members
1687 if (is_external && member_byte_offset == UINT32_MAX)
Greg Clayton973b6c92013-04-11 16:57:51 +00001688 {
1689 Type *var_type = ResolveTypeUID(encoding_uid);
1690
1691 if (var_type)
1692 {
1693 GetClangASTContext().AddVariableToRecordType (class_clang_type,
1694 name,
1695 var_type->GetClangLayoutType(),
1696 accessibility);
1697 }
Greg Claytone528efd72013-02-26 23:45:18 +00001698 break;
Greg Clayton973b6c92013-04-11 16:57:51 +00001699 }
Greg Claytone528efd72013-02-26 23:45:18 +00001700
Greg Clayton24739922010-10-13 03:15:28 +00001701 if (is_artificial == false)
1702 {
1703 Type *member_type = ResolveTypeUID(encoding_uid);
Sean Callananfa3ab452012-12-14 00:54:13 +00001704
Jim Inghame3ae82a2011-11-12 01:36:43 +00001705 clang::FieldDecl *field_decl = NULL;
Sean Callanan751aac62012-03-29 19:07:06 +00001706 if (tag == DW_TAG_member)
Greg Claytond16e1e52011-07-12 17:06:17 +00001707 {
Sean Callanan751aac62012-03-29 19:07:06 +00001708 if (member_type)
1709 {
1710 if (accessibility == eAccessNone)
1711 accessibility = default_accessibility;
1712 member_accessibilities.push_back(accessibility);
Sean Callananfaa0bb32012-12-05 23:37:14 +00001713
1714 BitfieldInfo this_field_info;
1715
1716 this_field_info.bit_size = bit_size;
1717
1718 if (member_byte_offset != UINT32_MAX || bit_size != 0)
Greg Clayton88bc7f32012-11-06 00:20:41 +00001719 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001720 /////////////////////////////////////////////////////////////
1721 // How to locate a field given the DWARF debug information
1722 //
1723 // AT_byte_size indicates the size of the word in which the
1724 // bit offset must be interpreted.
1725 //
1726 // AT_data_member_location indicates the byte offset of the
1727 // word from the base address of the structure.
1728 //
1729 // AT_bit_offset indicates how many bits into the word
1730 // (according to the host endianness) the low-order bit of
1731 // the field starts. AT_bit_offset can be negative.
1732 //
1733 // AT_bit_size indicates the size of the field in bits.
1734 /////////////////////////////////////////////////////////////
1735
1736 this_field_info.bit_offset = 0;
1737
1738 this_field_info.bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
1739
1740 if (GetObjectFile()->GetByteOrder() == eByteOrderLittle)
1741 {
1742 this_field_info.bit_offset += byte_size * 8;
1743 this_field_info.bit_offset -= (bit_offset + bit_size);
1744 }
1745 else
1746 {
1747 this_field_info.bit_offset += bit_offset;
1748 }
1749 }
1750
1751 // If the member to be emitted did not start on a character boundary and there is
1752 // empty space between the last field and this one, then we need to emit an
1753 // anonymous member filling up the space up to its start. There are three cases
1754 // here:
1755 //
1756 // 1 If the previous member ended on a character boundary, then we can emit an
1757 // anonymous member starting at the most recent character boundary.
1758 //
1759 // 2 If the previous member did not end on a character boundary and the distance
1760 // from the end of the previous member to the current member is less than a
1761 // word width, then we can emit an anonymous member starting right after the
1762 // previous member and right before this member.
1763 //
1764 // 3 If the previous member did not end on a character boundary and the distance
1765 // from the end of the previous member to the current member is greater than
1766 // or equal a word width, then we act as in Case 1.
1767
1768 const uint64_t character_width = 8;
1769 const uint64_t word_width = 32;
1770
1771 if (this_field_info.IsValid())
1772 {
1773 // Objective-C has invalid DW_AT_bit_offset values in older versions
1774 // of clang, so we have to be careful and only insert unnammed bitfields
Greg Clayton37c36e42012-11-27 00:59:26 +00001775 // if we have a new enough clang.
1776 bool detect_unnamed_bitfields = true;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001777
Greg Clayton37c36e42012-11-27 00:59:26 +00001778 if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus)
1779 detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields ();
1780
1781 if (detect_unnamed_bitfields)
Greg Clayton88bc7f32012-11-06 00:20:41 +00001782 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001783 BitfieldInfo anon_field_info;
1784
1785 if ((this_field_info.bit_offset % character_width) != 0) // not char aligned
Greg Clayton88bc7f32012-11-06 00:20:41 +00001786 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001787 uint64_t last_field_end = 0;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001788
Sean Callananfaa0bb32012-12-05 23:37:14 +00001789 if (last_field_info.IsValid())
1790 last_field_end = last_field_info.bit_offset + last_field_info.bit_size;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001791
Sean Callananfaa0bb32012-12-05 23:37:14 +00001792 if (this_field_info.bit_offset != last_field_end)
1793 {
1794 if (((last_field_end % character_width) == 0) || // case 1
1795 (this_field_info.bit_offset - last_field_end >= word_width)) // case 3
1796 {
1797 anon_field_info.bit_size = this_field_info.bit_offset % character_width;
1798 anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size;
1799 }
1800 else // case 2
1801 {
1802 anon_field_info.bit_size = this_field_info.bit_offset - last_field_end;
1803 anon_field_info.bit_offset = last_field_end;
1804 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00001805 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00001806 }
1807
Sean Callananfaa0bb32012-12-05 23:37:14 +00001808 if (anon_field_info.IsValid())
Greg Clayton88bc7f32012-11-06 00:20:41 +00001809 {
Greg Clayton88bc7f32012-11-06 00:20:41 +00001810 clang::FieldDecl *unnamed_bitfield_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
1811 NULL,
Sean Callananfaa0bb32012-12-05 23:37:14 +00001812 GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width),
Greg Clayton88bc7f32012-11-06 00:20:41 +00001813 accessibility,
Sean Callananfaa0bb32012-12-05 23:37:14 +00001814 anon_field_info.bit_size);
Greg Clayton88bc7f32012-11-06 00:20:41 +00001815
Sean Callananfaa0bb32012-12-05 23:37:14 +00001816 layout_info.field_offsets.insert(std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset));
Greg Clayton88bc7f32012-11-06 00:20:41 +00001817 }
1818 }
1819 }
Sean Callananfaa0bb32012-12-05 23:37:14 +00001820
Sean Callananfa3ab452012-12-14 00:54:13 +00001821 clang_type_t member_clang_type = member_type->GetClangLayoutType();
1822
1823 {
1824 // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>).
1825 // If the current field is at the end of the structure, then there is definitely no room for extra
1826 // elements and we override the type to array[0].
1827
1828 clang_type_t member_array_element_type;
1829 uint64_t member_array_size;
1830 bool member_array_is_incomplete;
1831
1832 if (GetClangASTContext().IsArrayType(member_clang_type,
1833 &member_array_element_type,
1834 &member_array_size,
1835 &member_array_is_incomplete) &&
1836 !member_array_is_incomplete)
1837 {
1838 uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX);
1839
1840 if (member_byte_offset >= parent_byte_size)
1841 {
1842 if (member_array_size != 1)
1843 {
1844 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,
1845 MakeUserID(die->GetOffset()),
1846 name,
1847 encoding_uid,
1848 MakeUserID(parent_die->GetOffset()));
1849 }
1850
Greg Clayton1c8ef472013-04-05 23:27:21 +00001851 member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0, false);
Sean Callananfa3ab452012-12-14 00:54:13 +00001852 }
1853 }
1854 }
1855
Greg Clayton88bc7f32012-11-06 00:20:41 +00001856 field_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
Sean Callanan751aac62012-03-29 19:07:06 +00001857 name,
Sean Callananfa3ab452012-12-14 00:54:13 +00001858 member_clang_type,
Sean Callanan751aac62012-03-29 19:07:06 +00001859 accessibility,
1860 bit_size);
Sean Callanan60217122012-04-13 00:10:03 +00001861
Greg Claytond0029442013-03-27 01:48:02 +00001862 GetClangASTContext().SetMetadataAsUserID (field_decl, MakeUserID(die->GetOffset()));
Sean Callananfaa0bb32012-12-05 23:37:14 +00001863
1864 if (this_field_info.IsValid())
1865 {
1866 layout_info.field_offsets.insert(std::make_pair(field_decl, this_field_info.bit_offset));
1867 last_field_info = this_field_info;
1868 }
Sean Callanan5b26f272012-02-04 08:49:35 +00001869 }
1870 else
1871 {
Sean Callanan751aac62012-03-29 19:07:06 +00001872 if (name)
Daniel Malead01b2952012-11-29 21:49:15 +00001873 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 +00001874 MakeUserID(die->GetOffset()),
1875 name,
1876 encoding_uid);
1877 else
Daniel Malead01b2952012-11-29 21:49:15 +00001878 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 +00001879 MakeUserID(die->GetOffset()),
1880 encoding_uid);
Sean Callanan5b26f272012-02-04 08:49:35 +00001881 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00001882 }
Sean Callanan751aac62012-03-29 19:07:06 +00001883
Jim Inghame3ae82a2011-11-12 01:36:43 +00001884 if (prop_name != NULL)
1885 {
Sean Callanan751aac62012-03-29 19:07:06 +00001886 clang::ObjCIvarDecl *ivar_decl = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001887
Sean Callanan751aac62012-03-29 19:07:06 +00001888 if (field_decl)
1889 {
1890 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
1891 assert (ivar_decl != NULL);
1892 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00001893
Jim Ingham379397632012-10-27 02:54:13 +00001894 ClangASTMetadata metadata;
1895 metadata.SetUserID (MakeUserID(die->GetOffset()));
Sean Callanana0b80ab2012-06-04 22:28:05 +00001896 delayed_properties.push_back(DelayedAddObjCClassProperty(GetClangASTContext().getASTContext(),
1897 class_clang_type,
1898 prop_name,
1899 member_type->GetClangLayoutType(),
1900 ivar_decl,
1901 prop_setter_name,
1902 prop_getter_name,
1903 prop_attributes,
Jim Ingham379397632012-10-27 02:54:13 +00001904 &metadata));
Sean Callanan60217122012-04-13 00:10:03 +00001905
Sean Callananad880762012-04-18 01:06:17 +00001906 if (ivar_decl)
Greg Claytond0029442013-03-27 01:48:02 +00001907 GetClangASTContext().SetMetadataAsUserID (ivar_decl, MakeUserID(die->GetOffset()));
Jim Inghame3ae82a2011-11-12 01:36:43 +00001908 }
Greg Clayton24739922010-10-13 03:15:28 +00001909 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001910 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00001911 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001912 }
1913 break;
1914
1915 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00001916 // Let the type parsing code handle this one for us.
1917 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001918 break;
1919
1920 case DW_TAG_inheritance:
1921 {
1922 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00001923 if (default_accessibility == eAccessNone)
1924 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001925 // TODO: implement DW_TAG_inheritance type parsing
1926 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001927 const size_t num_attributes = die->GetAttributes (this,
1928 dwarf_cu,
1929 fixed_form_sizes,
1930 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001931 if (num_attributes > 0)
1932 {
1933 Declaration decl;
1934 DWARFExpression location;
1935 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001936 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001937 bool is_virtual = false;
1938 bool is_base_of_class = true;
Greg Clayton2508b9b2012-11-01 23:20:02 +00001939 off_t member_byte_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001940 uint32_t i;
1941 for (i=0; i<num_attributes; ++i)
1942 {
1943 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1944 DWARFFormValue form_value;
1945 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1946 {
1947 switch (attr)
1948 {
1949 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1950 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1951 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1952 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton2508b9b2012-11-01 23:20:02 +00001953 case DW_AT_data_member_location:
1954 if (form_value.BlockData())
1955 {
1956 Value initialValue(0);
1957 Value memberOffset(0);
1958 const DataExtractor& debug_info_data = get_debug_info_data();
1959 uint32_t block_length = form_value.Unsigned();
1960 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1961 if (DWARFExpression::Evaluate (NULL,
1962 NULL,
1963 NULL,
1964 NULL,
1965 NULL,
1966 debug_info_data,
1967 block_offset,
1968 block_length,
1969 eRegisterKindDWARF,
1970 &initialValue,
1971 memberOffset,
1972 NULL))
1973 {
1974 member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1975 }
1976 }
1977 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001978
1979 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00001980 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001981 break;
1982
Greg Clayton1c8ef472013-04-05 23:27:21 +00001983 case DW_AT_virtuality: is_virtual = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001984 default:
1985 case DW_AT_sibling:
1986 break;
1987 }
1988 }
1989 }
1990
Greg Clayton526e5af2010-11-13 03:52:47 +00001991 Type *base_class_type = ResolveTypeUID(encoding_uid);
1992 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001993
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001994 clang_type_t base_class_clang_type = base_class_type->GetClangFullType();
1995 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001996 if (class_language == eLanguageTypeObjC)
1997 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001998 GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001999 }
2000 else
2001 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002002 base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type,
Greg Claytonba2d22d2010-11-13 22:57:37 +00002003 accessibility,
2004 is_virtual,
2005 is_base_of_class));
Greg Clayton2508b9b2012-11-01 23:20:02 +00002006
2007 if (is_virtual)
2008 {
2009 layout_info.vbase_offsets.insert(std::make_pair(ClangASTType::GetAsCXXRecordDecl(class_clang_type),
2010 clang::CharUnits::fromQuantity(member_byte_offset)));
2011 }
2012 else
2013 {
2014 layout_info.base_offsets.insert(std::make_pair(ClangASTType::GetAsCXXRecordDecl(class_clang_type),
2015 clang::CharUnits::fromQuantity(member_byte_offset)));
2016 }
Greg Clayton9e409562010-07-28 02:04:09 +00002017 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002018 }
2019 }
2020 break;
2021
2022 default:
2023 break;
2024 }
2025 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002026
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002027 return count;
2028}
2029
2030
2031clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00002032SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002033{
2034 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00002035 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002036 {
2037 DWARFCompileUnitSP cu_sp;
2038 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
2039 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00002040 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00002041 }
2042 return NULL;
2043}
2044
2045clang::DeclContext*
2046SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
2047{
Greg Clayton81c22f62011-10-19 18:09:39 +00002048 if (UserIDMatches(type_uid))
2049 return GetClangDeclContextForDIEOffset (sc, type_uid);
2050 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002051}
2052
2053Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00002054SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002055{
Greg Clayton81c22f62011-10-19 18:09:39 +00002056 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002057 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002058 DWARFDebugInfo* debug_info = DebugInfo();
2059 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00002060 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002061 DWARFCompileUnitSP cu_sp;
2062 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00002063 const bool assert_not_being_parsed = true;
2064 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00002065 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002066 }
2067 return NULL;
2068}
2069
Greg Claytoncab36a32011-12-08 05:16:30 +00002070Type*
2071SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00002072{
Greg Claytoncab36a32011-12-08 05:16:30 +00002073 if (die != NULL)
2074 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002075 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00002076 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002077 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002078 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
2079 die->GetOffset(),
2080 DW_TAG_value_to_name(die->Tag()),
2081 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00002082
Greg Claytoncab36a32011-12-08 05:16:30 +00002083 // We might be coming in in the middle of a type tree (a class
2084 // withing a class, an enum within a class), so parse any needed
2085 // parent DIEs before we get to this one...
2086 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2087 switch (decl_ctx_die->Tag())
2088 {
2089 case DW_TAG_structure_type:
2090 case DW_TAG_union_type:
2091 case DW_TAG_class_type:
2092 {
2093 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00002094 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002095 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002096 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
2097 die->GetOffset(),
2098 DW_TAG_value_to_name(die->Tag()),
2099 die->GetName(this, cu),
2100 decl_ctx_die->GetOffset());
Greg Clayton219cf312012-03-30 00:51:13 +00002101//
2102// Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
2103// if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
2104// {
2105// if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002106// GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton219cf312012-03-30 00:51:13 +00002107// "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
2108// die->GetOffset(),
2109// DW_TAG_value_to_name(die->Tag()),
2110// die->GetName(this, cu),
2111// decl_ctx_die->GetOffset());
2112// // Ask the type to complete itself if it already hasn't since if we
2113// // want a function (method or static) from a class, the class must
2114// // create itself and add it's own methods and class functions.
2115// if (parent_type)
2116// parent_type->GetClangFullType();
2117// }
Greg Claytoncab36a32011-12-08 05:16:30 +00002118 }
2119 break;
2120
2121 default:
2122 break;
2123 }
2124 return ResolveType (cu, die);
2125 }
2126 return NULL;
2127}
2128
Greg Clayton6beaaa62011-01-17 03:46:26 +00002129// This function is used when SymbolFileDWARFDebugMap owns a bunch of
2130// SymbolFileDWARF objects to detect if this DWARF file is the one that
2131// can resolve a clang_type.
2132bool
2133SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type)
2134{
2135 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
2136 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
2137 return die != NULL;
2138}
2139
2140
Greg Clayton1be10fc2010-09-29 01:12:09 +00002141lldb::clang_type_t
2142SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
2143{
2144 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton6beaaa62011-01-17 03:46:26 +00002145 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
2146 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002147 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00002148 {
2149 // We have already resolved this type...
2150 return clang_type;
2151 }
2152 // Once we start resolving this type, remove it from the forward declaration
2153 // map in case anyone child members or other types require this type to get resolved.
2154 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
2155 // are done.
Greg Clayton6beaaa62011-01-17 03:46:26 +00002156 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers);
Greg Clayton73b472d2010-10-27 03:32:59 +00002157
Greg Clayton1be10fc2010-09-29 01:12:09 +00002158
Greg Clayton85ae2e12011-10-18 23:36:41 +00002159 // Disable external storage for this type so we don't get anymore
2160 // clang::ExternalASTSource queries for this type.
2161 ClangASTContext::SetHasExternalStorage (clang_type, false);
2162
Greg Clayton450e3f32010-10-12 02:24:53 +00002163 DWARFDebugInfo* debug_info = DebugInfo();
2164
Greg Clayton53eb1c22012-04-02 22:59:12 +00002165 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002166 Type *type = m_die_to_type.lookup (die);
2167
2168 const dw_tag_t tag = die->Tag();
2169
Greg Clayton5160ce52013-03-27 23:08:40 +00002170 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
Greg Clayton3bffb082011-12-10 02:15:28 +00002171 if (log)
Greg Claytonbaf95da2012-03-30 23:50:54 +00002172 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002173 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002174 "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...",
Greg Claytond61c0fc2012-04-23 22:55:20 +00002175 MakeUserID(die->GetOffset()),
2176 DW_TAG_value_to_name(tag),
2177 type->GetName().AsCString());
Greg Claytonbaf95da2012-03-30 23:50:54 +00002178
Greg Claytonbaf95da2012-03-30 23:50:54 +00002179 }
Greg Clayton1be10fc2010-09-29 01:12:09 +00002180 assert (clang_type);
2181 DWARFDebugInfoEntry::Attributes attributes;
2182
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002183 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002184
2185 switch (tag)
2186 {
2187 case DW_TAG_structure_type:
2188 case DW_TAG_union_type:
2189 case DW_TAG_class_type:
Greg Claytonc93237c2010-10-01 20:48:32 +00002190 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002191 LayoutInfo layout_info;
Sean Callanan77a1fd32012-02-27 20:07:01 +00002192
Greg Clayton1be10fc2010-09-29 01:12:09 +00002193 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002194 if (die->HasChildren())
Greg Claytonc93237c2010-10-01 20:48:32 +00002195 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002196
Sean Callanan77a1fd32012-02-27 20:07:01 +00002197 LanguageType class_language = eLanguageTypeUnknown;
2198 bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
2199 if (is_objc_class)
Greg Clayton219cf312012-03-30 00:51:13 +00002200 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002201 class_language = eLanguageTypeObjC;
Greg Clayton219cf312012-03-30 00:51:13 +00002202 // For objective C we don't start the definition when
2203 // the class is created.
2204 ast.StartTagDeclarationDefinition (clang_type);
2205 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002206
2207 int tag_decl_kind = -1;
2208 AccessType default_accessibility = eAccessNone;
2209 if (tag == DW_TAG_structure_type)
2210 {
2211 tag_decl_kind = clang::TTK_Struct;
2212 default_accessibility = eAccessPublic;
2213 }
2214 else if (tag == DW_TAG_union_type)
2215 {
2216 tag_decl_kind = clang::TTK_Union;
2217 default_accessibility = eAccessPublic;
2218 }
2219 else if (tag == DW_TAG_class_type)
2220 {
2221 tag_decl_kind = clang::TTK_Class;
2222 default_accessibility = eAccessPrivate;
2223 }
2224
Greg Clayton53eb1c22012-04-02 22:59:12 +00002225 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002226 std::vector<clang::CXXBaseSpecifier *> base_classes;
2227 std::vector<int> member_accessibilities;
2228 bool is_a_class = false;
2229 // Parse members and base classes first
2230 DWARFDIECollection member_function_dies;
Sean Callanana0b80ab2012-06-04 22:28:05 +00002231
2232 DelayedPropertyList delayed_properties;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002233 ParseChildMembers (sc,
Greg Clayton53eb1c22012-04-02 22:59:12 +00002234 dwarf_cu,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002235 die,
2236 clang_type,
2237 class_language,
2238 base_classes,
2239 member_accessibilities,
2240 member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002241 delayed_properties,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002242 default_accessibility,
2243 is_a_class,
2244 layout_info);
2245
2246 // Now parse any methods if there were any...
2247 size_t num_functions = member_function_dies.Size();
2248 if (num_functions > 0)
2249 {
2250 for (size_t i=0; i<num_functions; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002251 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002252 ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytoncaab74e2012-01-28 00:48:57 +00002253 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002254 }
2255
2256 if (class_language == eLanguageTypeObjC)
2257 {
Greg Clayton84db9102012-03-26 23:03:23 +00002258 std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(ast.getASTContext(), clang_type));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002259 if (!class_str.empty())
Greg Claytoncaab74e2012-01-28 00:48:57 +00002260 {
Greg Clayton450e3f32010-10-12 02:24:53 +00002261
Sean Callanan77a1fd32012-02-27 20:07:01 +00002262 DIEArray method_die_offsets;
2263 if (m_using_apple_tables)
Greg Clayton95d87902011-11-11 03:16:25 +00002264 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002265 if (m_apple_objc_ap.get())
2266 m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets);
2267 }
2268 else
2269 {
2270 if (!m_indexed)
2271 Index ();
Greg Claytoncaab74e2012-01-28 00:48:57 +00002272
Sean Callanan77a1fd32012-02-27 20:07:01 +00002273 ConstString class_name (class_str.c_str());
2274 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
2275 }
2276
2277 if (!method_die_offsets.empty())
2278 {
2279 DWARFDebugInfo* debug_info = DebugInfo();
2280
2281 DWARFCompileUnit* method_cu = NULL;
2282 const size_t num_matches = method_die_offsets.size();
2283 for (size_t i=0; i<num_matches; ++i)
Greg Clayton95d87902011-11-11 03:16:25 +00002284 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002285 const dw_offset_t die_offset = method_die_offsets[i];
2286 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
2287
2288 if (method_die)
2289 ResolveType (method_cu, method_die);
2290 else
Greg Claytoncaab74e2012-01-28 00:48:57 +00002291 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002292 if (m_using_apple_tables)
2293 {
2294 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n",
2295 die_offset, class_str.c_str());
2296 }
2297 }
2298 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002299 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002300
2301 for (DelayedPropertyList::const_iterator pi = delayed_properties.begin(), pe = delayed_properties.end();
2302 pi != pe;
2303 ++pi)
2304 pi->Finalize();
Greg Clayton450e3f32010-10-12 02:24:53 +00002305 }
2306 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002307
2308 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2309 // need to tell the clang type it is actually a class.
2310 if (class_language != eLanguageTypeObjC)
2311 {
2312 if (is_a_class && tag_decl_kind != clang::TTK_Class)
2313 ast.SetTagTypeKind (clang_type, clang::TTK_Class);
2314 }
2315
2316 // Since DW_TAG_structure_type gets used for both classes
2317 // and structures, we may need to set any DW_TAG_member
2318 // fields to have a "private" access if none was specified.
2319 // When we parsed the child members we tracked that actual
2320 // accessibility value for each DW_TAG_member in the
2321 // "member_accessibilities" array. If the value for the
2322 // member is zero, then it was set to the "default_accessibility"
2323 // which for structs was "public". Below we correct this
2324 // by setting any fields to "private" that weren't correctly
2325 // set.
2326 if (is_a_class && !member_accessibilities.empty())
2327 {
2328 // This is a class and all members that didn't have
2329 // their access specified are private.
2330 ast.SetDefaultAccessForRecordFields (clang_type,
2331 eAccessPrivate,
2332 &member_accessibilities.front(),
2333 member_accessibilities.size());
2334 }
2335
2336 if (!base_classes.empty())
2337 {
2338 ast.SetBaseClassesForClassType (clang_type,
2339 &base_classes.front(),
2340 base_classes.size());
2341
2342 // Clang will copy each CXXBaseSpecifier in "base_classes"
2343 // so we have to free them all.
2344 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
2345 base_classes.size());
2346 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002347 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002348 }
Sean Callanane8c0cfb2012-03-02 01:03:45 +00002349
2350 ast.BuildIndirectFields (clang_type);
2351
Sean Callanan77a1fd32012-02-27 20:07:01 +00002352 ast.CompleteTagDeclarationDefinition (clang_type);
Sean Callanan5b26f272012-02-04 08:49:35 +00002353
Greg Clayton2508b9b2012-11-01 23:20:02 +00002354 if (!layout_info.field_offsets.empty() ||
2355 !layout_info.base_offsets.empty() ||
2356 !layout_info.vbase_offsets.empty() )
Greg Claytoncaab74e2012-01-28 00:48:57 +00002357 {
2358 if (type)
2359 layout_info.bit_size = type->GetByteSize() * 8;
2360 if (layout_info.bit_size == 0)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002361 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002362
2363 clang::CXXRecordDecl *record_decl = ClangASTType::GetAsCXXRecordDecl(clang_type);
2364 if (record_decl)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002365 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002366 if (log)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002367 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002368 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002369 "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 +00002370 clang_type,
2371 record_decl,
2372 layout_info.bit_size,
2373 layout_info.alignment,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002374 (uint32_t)layout_info.field_offsets.size(),
2375 (uint32_t)layout_info.base_offsets.size(),
2376 (uint32_t)layout_info.vbase_offsets.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002377
Greg Clayton2508b9b2012-11-01 23:20:02 +00002378 uint32_t idx;
2379 {
Greg Clayton821ac6d2012-01-28 02:22:27 +00002380 llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002381 for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002382 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002383 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002384 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = { bit_offset=%u, name='%s' }",
Greg Clayton821ac6d2012-01-28 02:22:27 +00002385 clang_type,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002386 idx,
Greg Clayton821ac6d2012-01-28 02:22:27 +00002387 (uint32_t)pos->second,
2388 pos->first->getNameAsString().c_str());
2389 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002390 }
2391
2392 {
2393 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos, base_end = layout_info.base_offsets.end();
2394 for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; ++base_pos, ++idx)
2395 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002396 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002397 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] = { byte_offset=%u, name='%s' }",
2398 clang_type,
2399 idx,
2400 (uint32_t)base_pos->second.getQuantity(),
2401 base_pos->first->getNameAsString().c_str());
2402 }
2403 }
2404 {
2405 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos, vbase_end = layout_info.vbase_offsets.end();
2406 for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; ++vbase_pos, ++idx)
2407 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002408 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002409 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) vbase[%u] = { byte_offset=%u, name='%s' }",
2410 clang_type,
2411 idx,
2412 (uint32_t)vbase_pos->second.getQuantity(),
2413 vbase_pos->first->getNameAsString().c_str());
2414 }
2415 }
Greg Clayton821ac6d2012-01-28 02:22:27 +00002416 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002417 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2418 }
2419 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002420 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002421
Greg Claytonc93237c2010-10-01 20:48:32 +00002422 return clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002423
2424 case DW_TAG_enumeration_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002425 ast.StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002426 if (die->HasChildren())
2427 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002428 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00002429 bool is_signed = false;
2430 ast.IsIntegerType(clang_type, is_signed);
2431 ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002432 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002433 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002434 return clang_type;
2435
2436 default:
2437 assert(false && "not a forward clang type decl!");
2438 break;
2439 }
2440 return NULL;
2441}
2442
Greg Claytonc685f8e2010-09-15 04:15:46 +00002443Type*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002444SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002445{
2446 if (type_die != NULL)
2447 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002448 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00002449
Greg Claytonc685f8e2010-09-15 04:15:46 +00002450 if (type == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002451 type = GetTypeForDIE (dwarf_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00002452
Greg Clayton24739922010-10-13 03:15:28 +00002453 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00002454 {
2455 if (type != DIE_IS_BEING_PARSED)
2456 return type;
2457
2458 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
Greg Clayton53eb1c22012-04-02 22:59:12 +00002459 type_die->GetOffset(),
2460 DW_TAG_value_to_name(type_die->Tag()),
2461 type_die->GetName(this, dwarf_cu));
Jim Inghamc3549282012-01-11 02:21:12 +00002462
2463 }
2464 else
2465 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002466 }
2467 return NULL;
2468}
2469
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002470CompileUnit*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002471SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002472{
2473 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002474 if (dwarf_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002475 {
2476 // The symbol vendor doesn't know about this compile unit, we
2477 // need to parse and add it to the symbol vendor object.
Greg Clayton53eb1c22012-04-02 22:59:12 +00002478 return ParseCompileUnit(dwarf_cu, cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002479 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00002480 return (CompileUnit*)dwarf_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002481}
2482
2483bool
Greg Clayton53eb1c22012-04-02 22:59:12 +00002484SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002485{
Greg Clayton72310352013-02-23 04:12:47 +00002486 sc.Clear(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002487 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002488 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002489
Greg Clayton81c22f62011-10-19 18:09:39 +00002490 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002491 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002492 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002493
2494 if (sc.function)
2495 {
Greg Claytone72dfb32012-02-24 01:59:29 +00002496 sc.module_sp = sc.function->CalculateSymbolContextModule();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002497 return true;
2498 }
2499
2500 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002501}
2502
2503uint32_t
2504SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2505{
2506 Timer scoped_timer(__PRETTY_FUNCTION__,
Daniel Malead01b2952012-11-29 21:49:15 +00002507 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)",
Greg Claytone72dfb32012-02-24 01:59:29 +00002508 so_addr.GetSection().get(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002509 so_addr.GetOffset(),
2510 resolve_scope);
2511 uint32_t resolved = 0;
2512 if (resolve_scope & ( eSymbolContextCompUnit |
2513 eSymbolContextFunction |
2514 eSymbolContextBlock |
2515 eSymbolContextLineEntry))
2516 {
2517 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2518
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002519 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00002520 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002521 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002522 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002523 if (cu_offset != DW_INVALID_OFFSET)
2524 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002525 uint32_t cu_idx = DW_INVALID_INDEX;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002526 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
2527 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002528 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002529 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002530 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002531 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002532 resolved |= eSymbolContextCompUnit;
2533
Greg Clayton6ab80132012-12-12 17:30:52 +00002534 bool force_check_line_table = false;
Greg Clayton526a4ae2012-05-16 22:09:01 +00002535 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2536 {
2537 DWARFDebugInfoEntry *function_die = NULL;
2538 DWARFDebugInfoEntry *block_die = NULL;
2539 if (resolve_scope & eSymbolContextBlock)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002540 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002541 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
2542 }
2543 else
2544 {
2545 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL);
2546 }
2547
2548 if (function_die != NULL)
2549 {
2550 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2551 if (sc.function == NULL)
2552 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2553 }
2554 else
2555 {
2556 // We might have had a compile unit that had discontiguous
2557 // address ranges where the gaps are symbols that don't have
2558 // any debug info. Discontiguous compile unit address ranges
2559 // should only happen when there aren't other functions from
2560 // other compile units in these gaps. This helps keep the size
2561 // of the aranges down.
Greg Clayton6ab80132012-12-12 17:30:52 +00002562 force_check_line_table = true;
Greg Clayton526a4ae2012-05-16 22:09:01 +00002563 }
2564
2565 if (sc.function != NULL)
2566 {
2567 resolved |= eSymbolContextFunction;
2568
2569 if (resolve_scope & eSymbolContextBlock)
2570 {
2571 Block& block = sc.function->GetBlock (true);
2572
2573 if (block_die != NULL)
2574 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2575 else
2576 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2577 if (sc.block)
2578 resolved |= eSymbolContextBlock;
2579 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002580 }
2581 }
Greg Clayton6ab80132012-12-12 17:30:52 +00002582
2583 if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table)
2584 {
2585 LineTable *line_table = sc.comp_unit->GetLineTable();
2586 if (line_table != NULL)
2587 {
Greg Clayton9422dd62013-03-04 21:46:16 +00002588 // And address that makes it into this function should be in terms
2589 // of this debug file if there is no debug map, or it will be an
2590 // address in the .o file which needs to be fixed up to be in terms
2591 // of the debug map executable. Either way, calling FixupAddress()
2592 // will work for us.
2593 Address exe_so_addr (so_addr);
2594 if (FixupAddress(exe_so_addr))
Greg Clayton6ab80132012-12-12 17:30:52 +00002595 {
Greg Clayton9422dd62013-03-04 21:46:16 +00002596 if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry))
Greg Clayton6ab80132012-12-12 17:30:52 +00002597 {
2598 resolved |= eSymbolContextLineEntry;
2599 }
2600 }
Greg Clayton6ab80132012-12-12 17:30:52 +00002601 }
2602 }
2603
2604 if (force_check_line_table && !(resolved & eSymbolContextLineEntry))
2605 {
2606 // We might have had a compile unit that had discontiguous
2607 // address ranges where the gaps are symbols that don't have
2608 // any debug info. Discontiguous compile unit address ranges
2609 // should only happen when there aren't other functions from
2610 // other compile units in these gaps. This helps keep the size
2611 // of the aranges down.
2612 sc.comp_unit = NULL;
2613 resolved &= ~eSymbolContextCompUnit;
2614 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002615 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002616 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002617 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002618 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.",
2619 cu_offset,
2620 cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002621 }
2622 }
2623 }
2624 }
2625 }
2626 return resolved;
2627}
2628
2629
2630
2631uint32_t
2632SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
2633{
2634 const uint32_t prev_size = sc_list.GetSize();
2635 if (resolve_scope & eSymbolContextCompUnit)
2636 {
2637 DWARFDebugInfo* debug_info = DebugInfo();
2638 if (debug_info)
2639 {
2640 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002641 DWARFCompileUnit* dwarf_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002642
Greg Clayton53eb1c22012-04-02 22:59:12 +00002643 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002644 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002645 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton1f746072012-08-29 21:13:06 +00002646 const bool full_match = file_spec.GetDirectory();
2647 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 +00002648 if (check_inlines || file_spec_matches_cu_file_spec)
2649 {
2650 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton53eb1c22012-04-02 22:59:12 +00002651 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002652 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002653 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002654 uint32_t file_idx = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002655
Greg Clayton526a4ae2012-05-16 22:09:01 +00002656 // If we are looking for inline functions only and we don't
2657 // find it in the support files, we are done.
2658 if (check_inlines)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002659 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002660 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
2661 if (file_idx == UINT32_MAX)
2662 continue;
2663 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002664
Greg Clayton526a4ae2012-05-16 22:09:01 +00002665 if (line != 0)
2666 {
2667 LineTable *line_table = sc.comp_unit->GetLineTable();
2668
2669 if (line_table != NULL && line != 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002670 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002671 // We will have already looked up the file index if
2672 // we are searching for inline entries.
2673 if (!check_inlines)
2674 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002675
Greg Clayton526a4ae2012-05-16 22:09:01 +00002676 if (file_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002677 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002678 uint32_t found_line;
2679 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
2680 found_line = sc.line_entry.line;
2681
2682 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002683 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002684 sc.function = NULL;
2685 sc.block = NULL;
2686 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002687 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002688 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
2689 if (file_vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002690 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002691 DWARFDebugInfoEntry *function_die = NULL;
2692 DWARFDebugInfoEntry *block_die = NULL;
2693 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002694
Greg Clayton526a4ae2012-05-16 22:09:01 +00002695 if (function_die != NULL)
2696 {
2697 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2698 if (sc.function == NULL)
2699 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2700 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002701
Greg Clayton526a4ae2012-05-16 22:09:01 +00002702 if (sc.function != NULL)
2703 {
2704 Block& block = sc.function->GetBlock (true);
2705
2706 if (block_die != NULL)
2707 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2708 else
2709 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2710 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002711 }
2712 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002713
Greg Clayton526a4ae2012-05-16 22:09:01 +00002714 sc_list.Append(sc);
2715 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2716 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002717 }
2718 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002719 else if (file_spec_matches_cu_file_spec && !check_inlines)
2720 {
2721 // only append the context if we aren't looking for inline call sites
2722 // by file and line and if the file spec matches that of the compile unit
2723 sc_list.Append(sc);
2724 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002725 }
2726 else if (file_spec_matches_cu_file_spec && !check_inlines)
2727 {
2728 // only append the context if we aren't looking for inline call sites
2729 // by file and line and if the file spec matches that of the compile unit
2730 sc_list.Append(sc);
2731 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002732
Greg Clayton526a4ae2012-05-16 22:09:01 +00002733 if (!check_inlines)
2734 break;
2735 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002736 }
2737 }
2738 }
2739 }
2740 return sc_list.GetSize() - prev_size;
2741}
2742
2743void
2744SymbolFileDWARF::Index ()
2745{
2746 if (m_indexed)
2747 return;
2748 m_indexed = true;
2749 Timer scoped_timer (__PRETTY_FUNCTION__,
2750 "SymbolFileDWARF::Index (%s)",
2751 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
2752
2753 DWARFDebugInfo* debug_info = DebugInfo();
2754 if (debug_info)
2755 {
2756 uint32_t cu_idx = 0;
2757 const uint32_t num_compile_units = GetNumCompileUnits();
2758 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2759 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002760 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002761
Greg Clayton53eb1c22012-04-02 22:59:12 +00002762 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002763
Greg Clayton53eb1c22012-04-02 22:59:12 +00002764 dwarf_cu->Index (cu_idx,
2765 m_function_basename_index,
2766 m_function_fullname_index,
2767 m_function_method_index,
2768 m_function_selector_index,
2769 m_objc_class_selectors_index,
2770 m_global_index,
2771 m_type_index,
2772 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002773
2774 // Keep memory down by clearing DIEs if this generate function
2775 // caused them to be parsed
2776 if (clear_dies)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002777 dwarf_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002778 }
2779
Greg Claytond4a2b372011-09-12 23:21:58 +00002780 m_function_basename_index.Finalize();
2781 m_function_fullname_index.Finalize();
2782 m_function_method_index.Finalize();
2783 m_function_selector_index.Finalize();
2784 m_objc_class_selectors_index.Finalize();
2785 m_global_index.Finalize();
2786 m_type_index.Finalize();
2787 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002788
Greg Clayton24739922010-10-13 03:15:28 +00002789#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00002790 StreamFile s(stdout, false);
Greg Claytonf9eec202011-09-01 23:16:13 +00002791 s.Printf ("DWARF index for '%s/%s':",
Greg Clayton24739922010-10-13 03:15:28 +00002792 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
2793 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
Greg Claytonba2d22d2010-11-13 22:57:37 +00002794 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
2795 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
2796 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
2797 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
2798 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
2799 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00002800 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00002801 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002802#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002803 }
2804}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002805
2806bool
2807SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
2808{
2809 if (namespace_decl == NULL)
2810 {
2811 // Invalid namespace decl which means we aren't matching only things
2812 // in this symbol file, so return true to indicate it matches this
2813 // symbol file.
2814 return true;
2815 }
2816
2817 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
2818
2819 if (namespace_ast == NULL)
2820 return true; // No AST in the "namespace_decl", return true since it
2821 // could then match any symbol file, including this one
2822
2823 if (namespace_ast == GetClangASTContext().getASTContext())
2824 return true; // The ASTs match, return true
2825
2826 // The namespace AST was valid, and it does not match...
Greg Clayton5160ce52013-03-27 23:08:40 +00002827 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Sean Callananc41e68b2011-10-13 21:08:11 +00002828
2829 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002830 GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00002831
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002832 return false;
2833}
2834
Greg Clayton2506a7a2011-10-12 23:34:26 +00002835bool
2836SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
2837 DWARFCompileUnit* cu,
2838 const DWARFDebugInfoEntry* die)
2839{
2840 // No namespace specified, so the answesr i
2841 if (namespace_decl == NULL)
2842 return true;
Sean Callananebe60672011-10-13 21:50:33 +00002843
Greg Clayton5160ce52013-03-27 23:08:40 +00002844 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002845
Greg Clayton437a1352012-04-09 22:43:43 +00002846 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
2847 clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00002848 if (decl_ctx_die)
Greg Clayton437a1352012-04-09 22:43:43 +00002849 {
Greg Clayton2506a7a2011-10-12 23:34:26 +00002850 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
Greg Clayton437a1352012-04-09 22:43:43 +00002851
Greg Clayton2506a7a2011-10-12 23:34:26 +00002852 if (clang_namespace_decl)
2853 {
2854 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00002855 {
2856 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002857 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00002858 return false;
Sean Callananebe60672011-10-13 21:50:33 +00002859 }
2860
Greg Clayton437a1352012-04-09 22:43:43 +00002861 if (clang_namespace_decl == die_clang_decl_ctx)
2862 return true;
2863 else
Greg Clayton2506a7a2011-10-12 23:34:26 +00002864 return false;
Greg Clayton2506a7a2011-10-12 23:34:26 +00002865 }
2866 else
2867 {
2868 // We have a namespace_decl that was not NULL but it contained
2869 // a NULL "clang::NamespaceDecl", so this means the global namespace
2870 // So as long the the contained decl context DIE isn't a namespace
2871 // we should be ok.
2872 if (decl_ctx_die->Tag() != DW_TAG_namespace)
2873 return true;
2874 }
2875 }
Sean Callananebe60672011-10-13 21:50:33 +00002876
2877 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002878 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00002879
Greg Clayton2506a7a2011-10-12 23:34:26 +00002880 return false;
2881}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002882uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00002883SymbolFileDWARF::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 +00002884{
Greg Clayton5160ce52013-03-27 23:08:40 +00002885 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00002886
2887 if (log)
2888 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002889 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002890 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
2891 name.GetCString(),
2892 namespace_decl,
2893 append,
2894 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002895 }
Sean Callanan213fdb82011-10-13 01:49:10 +00002896
2897 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2898 return 0;
2899
Greg Claytonc685f8e2010-09-15 04:15:46 +00002900 DWARFDebugInfo* info = DebugInfo();
2901 if (info == NULL)
2902 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002903
2904 // If we aren't appending the results to this list, then clear the list
2905 if (!append)
2906 variables.Clear();
2907
2908 // Remember how many variables are in the list before we search in case
2909 // we are appending the results to a variable list.
2910 const uint32_t original_size = variables.GetSize();
2911
Greg Claytond4a2b372011-09-12 23:21:58 +00002912 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002913
Greg Clayton97fbc342011-10-20 22:30:33 +00002914 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002915 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002916 if (m_apple_names_ap.get())
2917 {
2918 const char *name_cstr = name.GetCString();
2919 const char *base_name_start;
2920 const char *base_name_end = NULL;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002921
Greg Clayton97fbc342011-10-20 22:30:33 +00002922 if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end))
2923 base_name_start = name_cstr;
2924
2925 m_apple_names_ap->FindByName (base_name_start, die_offsets);
2926 }
Greg Clayton7f995132011-10-04 22:41:51 +00002927 }
2928 else
2929 {
2930 // Index the DWARF if we haven't already
2931 if (!m_indexed)
2932 Index ();
2933
2934 m_global_index.Find (name, die_offsets);
2935 }
2936
Greg Clayton437a1352012-04-09 22:43:43 +00002937 const size_t num_die_matches = die_offsets.size();
2938 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002939 {
Greg Clayton7f995132011-10-04 22:41:51 +00002940 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00002941 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00002942 assert (sc.module_sp);
2943
Greg Claytond4a2b372011-09-12 23:21:58 +00002944 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00002945 DWARFCompileUnit* dwarf_cu = NULL;
2946 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton437a1352012-04-09 22:43:43 +00002947 bool done = false;
2948 for (size_t i=0; i<num_die_matches && !done; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002949 {
2950 const dw_offset_t die_offset = die_offsets[i];
2951 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002952
Greg Clayton95d87902011-11-11 03:16:25 +00002953 if (die)
2954 {
Greg Clayton437a1352012-04-09 22:43:43 +00002955 switch (die->Tag())
2956 {
2957 default:
2958 case DW_TAG_subprogram:
2959 case DW_TAG_inlined_subroutine:
2960 case DW_TAG_try_block:
2961 case DW_TAG_catch_block:
2962 break;
2963
2964 case DW_TAG_variable:
2965 {
2966 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Greg Clayton437a1352012-04-09 22:43:43 +00002967
2968 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2969 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002970
Greg Clayton437a1352012-04-09 22:43:43 +00002971 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002972
Greg Clayton437a1352012-04-09 22:43:43 +00002973 if (variables.GetSize() - original_size >= max_matches)
2974 done = true;
2975 }
2976 break;
2977 }
Greg Clayton95d87902011-11-11 03:16:25 +00002978 }
2979 else
2980 {
2981 if (m_using_apple_tables)
2982 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002983 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
2984 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00002985 }
2986 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002987 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002988 }
2989
2990 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00002991 const uint32_t num_matches = variables.GetSize() - original_size;
2992 if (log && num_matches > 0)
2993 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002994 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00002995 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u",
2996 name.GetCString(),
2997 namespace_decl,
2998 append,
2999 max_matches,
3000 num_matches);
3001 }
3002 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003003}
3004
3005uint32_t
3006SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
3007{
Greg Clayton5160ce52013-03-27 23:08:40 +00003008 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003009
3010 if (log)
3011 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003012 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003013 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
3014 regex.GetText(),
3015 append,
3016 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003017 }
3018
Greg Claytonc685f8e2010-09-15 04:15:46 +00003019 DWARFDebugInfo* info = DebugInfo();
3020 if (info == NULL)
3021 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003022
3023 // If we aren't appending the results to this list, then clear the list
3024 if (!append)
3025 variables.Clear();
3026
3027 // Remember how many variables are in the list before we search in case
3028 // we are appending the results to a variable list.
3029 const uint32_t original_size = variables.GetSize();
3030
Greg Clayton7f995132011-10-04 22:41:51 +00003031 DIEArray die_offsets;
3032
Greg Clayton97fbc342011-10-20 22:30:33 +00003033 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003034 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003035 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00003036 {
3037 DWARFMappedHash::DIEInfoArray hash_data_array;
3038 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
3039 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
3040 }
Greg Clayton7f995132011-10-04 22:41:51 +00003041 }
3042 else
3043 {
3044 // Index the DWARF if we haven't already
3045 if (!m_indexed)
3046 Index ();
3047
3048 m_global_index.Find (regex, die_offsets);
3049 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003050
Greg Claytonc685f8e2010-09-15 04:15:46 +00003051 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003052 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003053 assert (sc.module_sp);
3054
Greg Claytond4a2b372011-09-12 23:21:58 +00003055 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00003056 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003057 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003058 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003059 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003060 DWARFDebugInfo* debug_info = DebugInfo();
3061 for (size_t i=0; i<num_matches; ++i)
3062 {
3063 const dw_offset_t die_offset = die_offsets[i];
3064 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00003065
3066 if (die)
3067 {
3068 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003069
Greg Clayton95d87902011-11-11 03:16:25 +00003070 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003071
Greg Clayton95d87902011-11-11 03:16:25 +00003072 if (variables.GetSize() - original_size >= max_matches)
3073 break;
3074 }
3075 else
3076 {
3077 if (m_using_apple_tables)
3078 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003079 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
3080 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00003081 }
3082 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003083 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003084 }
3085
3086 // Return the number of variable that were appended to the list
3087 return variables.GetSize() - original_size;
3088}
3089
Greg Claytonaa044962011-10-13 00:59:38 +00003090
Jim Ingham4cda6e02011-10-07 22:23:45 +00003091bool
3092SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
3093 DWARFCompileUnit *&dwarf_cu,
3094 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00003095{
Greg Claytonaa044962011-10-13 00:59:38 +00003096 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3097 return ResolveFunction (dwarf_cu, die, sc_list);
3098}
3099
3100
3101bool
3102SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
3103 const DWARFDebugInfoEntry *die,
3104 SymbolContextList& sc_list)
3105{
Greg Clayton9e315582011-09-02 04:03:59 +00003106 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00003107
3108 if (die == NULL)
3109 return false;
3110
Jim Ingham4cda6e02011-10-07 22:23:45 +00003111 // If we were passed a die that is not a function, just return false...
3112 if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine)
3113 return false;
3114
3115 const DWARFDebugInfoEntry* inlined_die = NULL;
3116 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00003117 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003118 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00003119
Jim Ingham4cda6e02011-10-07 22:23:45 +00003120 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003121 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003122 if (die->Tag() == DW_TAG_subprogram)
3123 break;
Greg Clayton9e315582011-09-02 04:03:59 +00003124 }
3125 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003126 assert (die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00003127 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003128 {
3129 Address addr;
3130 // Parse all blocks if needed
3131 if (inlined_die)
3132 {
Greg Clayton81c22f62011-10-19 18:09:39 +00003133 sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset()));
Jim Ingham4cda6e02011-10-07 22:23:45 +00003134 assert (sc.block != NULL);
3135 if (sc.block->GetStartAddress (addr) == false)
3136 addr.Clear();
3137 }
3138 else
3139 {
3140 sc.block = NULL;
3141 addr = sc.function->GetAddressRange().GetBaseAddress();
3142 }
3143
3144 if (addr.IsValid())
3145 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003146 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00003147 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003148 }
3149 }
3150
Greg Claytonaa044962011-10-13 00:59:38 +00003151 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00003152}
3153
Greg Clayton7f995132011-10-04 22:41:51 +00003154void
3155SymbolFileDWARF::FindFunctions (const ConstString &name,
3156 const NameToDIE &name_to_die,
3157 SymbolContextList& sc_list)
3158{
Greg Claytond4a2b372011-09-12 23:21:58 +00003159 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003160 if (name_to_die.Find (name, die_offsets))
3161 {
3162 ParseFunctions (die_offsets, sc_list);
3163 }
3164}
3165
3166
3167void
3168SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3169 const NameToDIE &name_to_die,
3170 SymbolContextList& sc_list)
3171{
3172 DIEArray die_offsets;
3173 if (name_to_die.Find (regex, die_offsets))
3174 {
3175 ParseFunctions (die_offsets, sc_list);
3176 }
3177}
3178
3179
3180void
3181SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3182 const DWARFMappedHash::MemoryTable &memory_table,
3183 SymbolContextList& sc_list)
3184{
3185 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00003186 DWARFMappedHash::DIEInfoArray hash_data_array;
3187 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00003188 {
Greg Claytond1767f02011-12-08 02:13:16 +00003189 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Greg Clayton7f995132011-10-04 22:41:51 +00003190 ParseFunctions (die_offsets, sc_list);
3191 }
3192}
3193
3194void
3195SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
3196 SymbolContextList& sc_list)
3197{
3198 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003199 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00003200 {
Greg Clayton7f995132011-10-04 22:41:51 +00003201 SymbolContext sc;
Greg Clayton7f995132011-10-04 22:41:51 +00003202
3203 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003204 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00003205 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003206 const dw_offset_t die_offset = die_offsets[i];
Jim Ingham4cda6e02011-10-07 22:23:45 +00003207 ResolveFunction (die_offset, dwarf_cu, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003208 }
3209 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00003210}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003211
Jim Ingham4cda6e02011-10-07 22:23:45 +00003212bool
3213SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
3214 const DWARFCompileUnit *dwarf_cu,
3215 uint32_t name_type_mask,
3216 const char *partial_name,
3217 const char *base_name_start,
3218 const char *base_name_end)
3219{
Greg Claytonfbea0f62012-11-15 18:05:43 +00003220 // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes:
3221 if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003222 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003223 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
3224 if (!containing_decl_ctx)
3225 return false;
3226
3227 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
3228
Greg Claytonfbea0f62012-11-15 18:05:43 +00003229 if (name_type_mask == eFunctionNameTypeMethod)
3230 {
3231 if (is_cxx_method == false)
3232 return false;
3233 }
3234
3235 if (name_type_mask == eFunctionNameTypeBase)
3236 {
3237 if (is_cxx_method == true)
3238 return false;
3239 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003240 }
3241
3242 // Now we need to check whether the name we got back for this type matches the extra specifications
3243 // that were in the name we're looking up:
3244 if (base_name_start != partial_name || *base_name_end != '\0')
3245 {
3246 // First see if the stuff to the left matches the full name. To do that let's see if
3247 // we can pull out the mips linkage name attribute:
3248
3249 Mangled best_name;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003250 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonfbea0f62012-11-15 18:05:43 +00003251 DWARFFormValue form_value;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003252 die->GetAttributes(this, dwarf_cu, NULL, attributes);
3253 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
Greg Clayton71415542012-12-08 00:24:40 +00003254 if (idx == UINT32_MAX)
3255 idx = attributes.FindAttributeIndex(DW_AT_linkage_name);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003256 if (idx != UINT32_MAX)
3257 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003258 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
3259 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003260 const char *mangled_name = form_value.AsCString(&get_debug_str_data());
3261 if (mangled_name)
3262 best_name.SetValue (ConstString(mangled_name), true);
3263 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003264 }
Greg Claytonfbea0f62012-11-15 18:05:43 +00003265
3266 if (!best_name)
3267 {
3268 idx = attributes.FindAttributeIndex(DW_AT_name);
3269 if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value))
3270 {
3271 const char *name = form_value.AsCString(&get_debug_str_data());
3272 best_name.SetValue (ConstString(name), false);
3273 }
3274 }
3275
3276 if (best_name.GetDemangledName())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003277 {
3278 const char *demangled = best_name.GetDemangledName().GetCString();
3279 if (demangled)
3280 {
3281 std::string name_no_parens(partial_name, base_name_end - partial_name);
Jim Ingham85c13d72012-03-02 02:24:42 +00003282 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str());
3283 if (partial_in_demangled == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003284 return false;
Jim Ingham85c13d72012-03-02 02:24:42 +00003285 else
3286 {
3287 // Sort out the case where our name is something like "Process::Destroy" and the match is
3288 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on
3289 // namespace boundaries...
3290
3291 if (partial_name[0] == ':' && partial_name[1] == ':')
3292 {
3293 // The partial name was already on a namespace boundary so all matches are good.
3294 return true;
3295 }
3296 else if (partial_in_demangled == demangled)
3297 {
3298 // They both start the same, so this is an good match.
3299 return true;
3300 }
3301 else
3302 {
3303 if (partial_in_demangled - demangled == 1)
3304 {
3305 // Only one character difference, can't be a namespace boundary...
3306 return false;
3307 }
3308 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':')
3309 {
3310 // We are on a namespace boundary, so this is also good.
3311 return true;
3312 }
3313 else
3314 return false;
3315 }
3316 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003317 }
3318 }
3319 }
3320
3321 return true;
3322}
Greg Claytonc685f8e2010-09-15 04:15:46 +00003323
Greg Clayton0c5cd902010-06-28 21:30:43 +00003324uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00003325SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00003326 const lldb_private::ClangNamespaceDecl *namespace_decl,
Sean Callanan9df05fb2012-02-10 22:52:19 +00003327 uint32_t name_type_mask,
3328 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00003329 bool append,
3330 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00003331{
3332 Timer scoped_timer (__PRETTY_FUNCTION__,
3333 "SymbolFileDWARF::FindFunctions (name = '%s')",
3334 name.AsCString());
3335
Greg Clayton43fe2172013-04-03 02:00:15 +00003336 // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup()
3337 assert ((name_type_mask & eFunctionNameTypeAuto) == 0);
3338
Greg Clayton5160ce52013-03-27 23:08:40 +00003339 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003340
3341 if (log)
3342 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003343 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003344 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
3345 name.GetCString(),
3346 name_type_mask,
3347 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003348 }
3349
Greg Clayton0c5cd902010-06-28 21:30:43 +00003350 // If we aren't appending the results to this list, then clear the list
3351 if (!append)
3352 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003353
3354 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3355 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003356
3357 // If name is empty then we won't find anything.
3358 if (name.IsEmpty())
3359 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00003360
3361 // Remember how many sc_list are in the list before we search in case
3362 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00003363
Jim Ingham4cda6e02011-10-07 22:23:45 +00003364 const char *name_cstr = name.GetCString();
Greg Clayton43fe2172013-04-03 02:00:15 +00003365
3366 const uint32_t original_size = sc_list.GetSize();
3367
Jim Ingham4cda6e02011-10-07 22:23:45 +00003368 DWARFDebugInfo* info = DebugInfo();
3369 if (info == NULL)
3370 return 0;
3371
Greg Claytonaa044962011-10-13 00:59:38 +00003372 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton43fe2172013-04-03 02:00:15 +00003373 std::set<const DWARFDebugInfoEntry *> resolved_dies;
Greg Clayton97fbc342011-10-20 22:30:33 +00003374 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00003375 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003376 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003377 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003378
3379 DIEArray die_offsets;
3380
3381 uint32_t num_matches = 0;
3382
Greg Clayton43fe2172013-04-03 02:00:15 +00003383 if (name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00003384 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003385 // If they asked for the full name, match what they typed. At some point we may
3386 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
3387 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00003388 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003389 for (uint32_t i = 0; i < num_matches; i++)
3390 {
Greg Clayton95d87902011-11-11 03:16:25 +00003391 const dw_offset_t die_offset = die_offsets[i];
3392 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00003393 if (die)
3394 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003395 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3396 continue;
3397
Sean Callanan9df05fb2012-02-10 22:52:19 +00003398 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3399 continue;
3400
Greg Clayton43fe2172013-04-03 02:00:15 +00003401 if (resolved_dies.find(die) == resolved_dies.end())
3402 {
3403 if (ResolveFunction (dwarf_cu, die, sc_list))
3404 resolved_dies.insert(die);
3405 }
Greg Claytonaa044962011-10-13 00:59:38 +00003406 }
Greg Clayton95d87902011-11-11 03:16:25 +00003407 else
3408 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003409 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3410 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003411 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003412 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003413 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003414
3415 if (name_type_mask & eFunctionNameTypeSelector)
3416 {
3417 if (namespace_decl && *namespace_decl)
3418 return 0; // no selectors in namespaces
Greg Clayton97fbc342011-10-20 22:30:33 +00003419
Greg Clayton43fe2172013-04-03 02:00:15 +00003420 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3421 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
3422 // and if it is an ObjC method name, we're good.
Greg Clayton97fbc342011-10-20 22:30:33 +00003423
Greg Clayton43fe2172013-04-03 02:00:15 +00003424 for (uint32_t i = 0; i < num_matches; i++)
Greg Clayton97fbc342011-10-20 22:30:33 +00003425 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003426 const dw_offset_t die_offset = die_offsets[i];
3427 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3428 if (die)
Greg Clayton97fbc342011-10-20 22:30:33 +00003429 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003430 const char *die_name = die->GetName(this, dwarf_cu);
3431 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
Greg Clayton97fbc342011-10-20 22:30:33 +00003432 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003433 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3434 continue;
3435
Greg Clayton43fe2172013-04-03 02:00:15 +00003436 if (resolved_dies.find(die) == resolved_dies.end())
3437 {
3438 if (ResolveFunction (dwarf_cu, die, sc_list))
3439 resolved_dies.insert(die);
3440 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003441 }
3442 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003443 else
3444 {
3445 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3446 die_offset, name_cstr);
3447 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003448 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003449 die_offsets.clear();
3450 }
3451
3452 if (((name_type_mask & eFunctionNameTypeMethod) && !namespace_decl) || name_type_mask & eFunctionNameTypeBase)
3453 {
3454 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
3455 // extract the base name, look that up, and if there is any other information in the name we were
3456 // passed in we have to post-filter based on that.
3457
3458 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
3459 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3460
3461 for (uint32_t i = 0; i < num_matches; i++)
3462 {
3463 const dw_offset_t die_offset = die_offsets[i];
3464 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3465 if (die)
3466 {
3467 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3468 continue;
3469
3470 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3471 continue;
3472
3473 // If we get to here, the die is good, and we should add it:
3474 if (resolved_dies.find(die) == resolved_dies.end())
3475 if (ResolveFunction (dwarf_cu, die, sc_list))
3476 {
3477 bool keep_die = true;
3478 if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod))
3479 {
3480 // We are looking for either basenames or methods, so we need to
3481 // trim out the ones we won't want by looking at the type
3482 SymbolContext sc;
3483 if (sc_list.GetLastContext(sc))
3484 {
3485 if (sc.block)
3486 {
3487 // We have an inlined function
3488 }
3489 else if (sc.function)
3490 {
3491 Type *type = sc.function->GetType();
3492
3493 clang::DeclContext* decl_ctx = GetClangDeclContextContainingTypeUID (type->GetID());
3494 if (decl_ctx->isRecord())
3495 {
3496 if (name_type_mask & eFunctionNameTypeBase)
3497 {
3498 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3499 keep_die = false;
3500 }
3501 }
3502 else
3503 {
3504 if (name_type_mask & eFunctionNameTypeMethod)
3505 {
3506 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3507 keep_die = false;
3508 }
3509 }
3510 }
3511 }
3512 }
3513 if (keep_die)
3514 resolved_dies.insert(die);
3515 }
3516 }
3517 else
3518 {
3519 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3520 die_offset, name_cstr);
3521 }
3522 }
3523 die_offsets.clear();
Jim Ingham4cda6e02011-10-07 22:23:45 +00003524 }
3525 }
Greg Clayton7f995132011-10-04 22:41:51 +00003526 }
3527 else
3528 {
3529
3530 // Index the DWARF if we haven't already
3531 if (!m_indexed)
3532 Index ();
3533
Greg Clayton7f995132011-10-04 22:41:51 +00003534 if (name_type_mask & eFunctionNameTypeFull)
3535 FindFunctions (name, m_function_fullname_index, sc_list);
3536
Jim Ingham4cda6e02011-10-07 22:23:45 +00003537 DIEArray die_offsets;
3538 DWARFCompileUnit *dwarf_cu = NULL;
3539
Greg Clayton43fe2172013-04-03 02:00:15 +00003540 if (name_type_mask & eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003541 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003542 uint32_t num_base = m_function_basename_index.Find(name, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00003543 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003544 {
Greg Claytonaa044962011-10-13 00:59:38 +00003545 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3546 if (die)
3547 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003548 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3549 continue;
3550
Sean Callanan213fdb82011-10-13 01:49:10 +00003551 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3552 continue;
3553
Greg Claytonaa044962011-10-13 00:59:38 +00003554 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00003555 if (resolved_dies.find(die) == resolved_dies.end())
3556 {
3557 if (ResolveFunction (dwarf_cu, die, sc_list))
3558 resolved_dies.insert(die);
3559 }
Greg Claytonaa044962011-10-13 00:59:38 +00003560 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003561 }
3562 die_offsets.clear();
3563 }
3564
Greg Clayton43fe2172013-04-03 02:00:15 +00003565 if (name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003566 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003567 if (namespace_decl && *namespace_decl)
3568 return 0; // no methods in namespaces
3569
Greg Clayton43fe2172013-04-03 02:00:15 +00003570 uint32_t num_base = m_function_method_index.Find(name, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003571 {
Greg Claytonaa044962011-10-13 00:59:38 +00003572 for (uint32_t i = 0; i < num_base; i++)
3573 {
3574 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3575 if (die)
3576 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003577 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3578 continue;
3579
Greg Claytonaa044962011-10-13 00:59:38 +00003580 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00003581 if (resolved_dies.find(die) == resolved_dies.end())
3582 {
3583 if (ResolveFunction (dwarf_cu, die, sc_list))
3584 resolved_dies.insert(die);
3585 }
Greg Claytonaa044962011-10-13 00:59:38 +00003586 }
3587 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003588 }
3589 die_offsets.clear();
3590 }
Greg Clayton7f995132011-10-04 22:41:51 +00003591
Greg Clayton43fe2172013-04-03 02:00:15 +00003592 if ((name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003593 {
Greg Clayton7f995132011-10-04 22:41:51 +00003594 FindFunctions (name, m_function_selector_index, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003595 }
3596
Greg Clayton4d01ace2011-09-29 16:58:15 +00003597 }
3598
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003599 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003600 const uint32_t num_matches = sc_list.GetSize() - original_size;
3601
3602 if (log && num_matches > 0)
3603 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003604 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003605 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list) => %u",
3606 name.GetCString(),
3607 name_type_mask,
3608 append,
3609 num_matches);
3610 }
3611 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003612}
3613
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003614uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00003615SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003616{
3617 Timer scoped_timer (__PRETTY_FUNCTION__,
3618 "SymbolFileDWARF::FindFunctions (regex = '%s')",
3619 regex.GetText());
3620
Greg Clayton5160ce52013-03-27 23:08:40 +00003621 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003622
3623 if (log)
3624 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003625 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003626 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
3627 regex.GetText(),
3628 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003629 }
3630
3631
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003632 // If we aren't appending the results to this list, then clear the list
3633 if (!append)
3634 sc_list.Clear();
3635
3636 // Remember how many sc_list are in the list before we search in case
3637 // we are appending the results to a variable list.
3638 uint32_t original_size = sc_list.GetSize();
3639
Greg Clayton97fbc342011-10-20 22:30:33 +00003640 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003641 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003642 if (m_apple_names_ap.get())
3643 FindFunctions (regex, *m_apple_names_ap, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003644 }
3645 else
3646 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003647 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00003648 if (!m_indexed)
3649 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003650
Greg Clayton7f995132011-10-04 22:41:51 +00003651 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003652
Greg Clayton7f995132011-10-04 22:41:51 +00003653 FindFunctions (regex, m_function_fullname_index, sc_list);
3654 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003655
3656 // Return the number of variable that were appended to the list
3657 return sc_list.GetSize() - original_size;
3658}
Jim Ingham318c9f22011-08-26 19:44:13 +00003659
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003660uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00003661SymbolFileDWARF::FindTypes (const SymbolContext& sc,
3662 const ConstString &name,
3663 const lldb_private::ClangNamespaceDecl *namespace_decl,
3664 bool append,
3665 uint32_t max_matches,
3666 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003667{
Greg Claytonc685f8e2010-09-15 04:15:46 +00003668 DWARFDebugInfo* info = DebugInfo();
3669 if (info == NULL)
3670 return 0;
3671
Greg Clayton5160ce52013-03-27 23:08:40 +00003672 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003673
3674 if (log)
3675 {
Greg Clayton437a1352012-04-09 22:43:43 +00003676 if (namespace_decl)
3677 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003678 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003679 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)",
3680 name.GetCString(),
3681 namespace_decl->GetNamespaceDecl(),
3682 namespace_decl->GetQualifiedName().c_str(),
3683 append,
3684 max_matches);
3685 }
3686 else
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(NULL), append=%u, max_matches=%u, type_list)",
3690 name.GetCString(),
3691 append,
3692 max_matches);
3693 }
Greg Clayton21f2a492011-10-06 00:09:08 +00003694 }
3695
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003696 // If we aren't appending the results to this list, then clear the list
3697 if (!append)
3698 types.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003699
3700 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3701 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003702
Greg Claytond4a2b372011-09-12 23:21:58 +00003703 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003704
Greg Clayton97fbc342011-10-20 22:30:33 +00003705 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003706 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003707 if (m_apple_types_ap.get())
3708 {
3709 const char *name_cstr = name.GetCString();
3710 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3711 }
Greg Clayton7f995132011-10-04 22:41:51 +00003712 }
3713 else
3714 {
3715 if (!m_indexed)
3716 Index ();
3717
3718 m_type_index.Find (name, die_offsets);
3719 }
3720
Greg Clayton437a1352012-04-09 22:43:43 +00003721 const size_t num_die_matches = die_offsets.size();
Greg Clayton7f995132011-10-04 22:41:51 +00003722
Greg Clayton437a1352012-04-09 22:43:43 +00003723 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003724 {
Greg Clayton7f995132011-10-04 22:41:51 +00003725 const uint32_t initial_types_size = types.GetSize();
3726 DWARFCompileUnit* dwarf_cu = NULL;
3727 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003728 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00003729 for (size_t i=0; i<num_die_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003730 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003731 const dw_offset_t die_offset = die_offsets[i];
3732 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3733
Greg Clayton95d87902011-11-11 03:16:25 +00003734 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00003735 {
Greg Clayton95d87902011-11-11 03:16:25 +00003736 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3737 continue;
3738
3739 Type *matching_type = ResolveType (dwarf_cu, die);
3740 if (matching_type)
3741 {
3742 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003743 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00003744 if (types.GetSize() >= max_matches)
3745 break;
3746 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00003747 }
Greg Clayton95d87902011-11-11 03:16:25 +00003748 else
3749 {
3750 if (m_using_apple_tables)
3751 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003752 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
3753 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003754 }
3755 }
3756
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003757 }
Greg Clayton437a1352012-04-09 22:43:43 +00003758 const uint32_t num_matches = types.GetSize() - initial_types_size;
3759 if (log && num_matches)
3760 {
3761 if (namespace_decl)
3762 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003763 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003764 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u",
3765 name.GetCString(),
3766 namespace_decl->GetNamespaceDecl(),
3767 namespace_decl->GetQualifiedName().c_str(),
3768 append,
3769 max_matches,
3770 num_matches);
3771 }
3772 else
3773 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003774 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003775 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u",
3776 name.GetCString(),
3777 append,
3778 max_matches,
3779 num_matches);
3780 }
3781 }
3782 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003783 }
Greg Clayton7f995132011-10-04 22:41:51 +00003784 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003785}
3786
3787
Greg Clayton526e5af2010-11-13 03:52:47 +00003788ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00003789SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00003790 const ConstString &name,
3791 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00003792{
Greg Clayton5160ce52013-03-27 23:08:40 +00003793 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003794
3795 if (log)
3796 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003797 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003798 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
3799 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00003800 }
Sean Callanan213fdb82011-10-13 01:49:10 +00003801
3802 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
3803 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00003804
Greg Clayton526e5af2010-11-13 03:52:47 +00003805 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003806 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00003807 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00003808 {
Greg Clayton7f995132011-10-04 22:41:51 +00003809 DIEArray die_offsets;
3810
Greg Clayton526e5af2010-11-13 03:52:47 +00003811 // Index if we already haven't to make sure the compile units
3812 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00003813 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003814 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003815 if (m_apple_namespaces_ap.get())
3816 {
3817 const char *name_cstr = name.GetCString();
3818 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
3819 }
Greg Clayton7f995132011-10-04 22:41:51 +00003820 }
3821 else
3822 {
3823 if (!m_indexed)
3824 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00003825
Greg Clayton7f995132011-10-04 22:41:51 +00003826 m_namespace_index.Find (name, die_offsets);
3827 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003828
3829 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00003830 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003831 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003832 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00003833 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003834 DWARFDebugInfo* debug_info = DebugInfo();
3835 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00003836 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003837 const dw_offset_t die_offset = die_offsets[i];
3838 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00003839
Greg Clayton95d87902011-11-11 03:16:25 +00003840 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00003841 {
Greg Clayton95d87902011-11-11 03:16:25 +00003842 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
3843 continue;
3844
3845 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
3846 if (clang_namespace_decl)
3847 {
3848 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
3849 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
Greg Claytond1767f02011-12-08 02:13:16 +00003850 break;
Greg Clayton95d87902011-11-11 03:16:25 +00003851 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003852 }
Greg Clayton95d87902011-11-11 03:16:25 +00003853 else
3854 {
3855 if (m_using_apple_tables)
3856 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003857 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
3858 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003859 }
3860 }
3861
Greg Clayton526e5af2010-11-13 03:52:47 +00003862 }
3863 }
Greg Clayton96d7d742010-11-10 23:42:09 +00003864 }
Greg Clayton437a1352012-04-09 22:43:43 +00003865 if (log && namespace_decl.GetNamespaceDecl())
3866 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003867 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003868 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"",
3869 name.GetCString(),
3870 namespace_decl.GetNamespaceDecl(),
3871 namespace_decl.GetQualifiedName().c_str());
3872 }
3873
Greg Clayton526e5af2010-11-13 03:52:47 +00003874 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003875}
3876
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003877uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003878SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003879{
3880 // Remember how many sc_list are in the list before we search in case
3881 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003882 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003883
3884 const uint32_t num_die_offsets = die_offsets.size();
3885 // Parse all of the types we found from the pubtypes matches
3886 uint32_t i;
3887 uint32_t num_matches = 0;
3888 for (i = 0; i < num_die_offsets; ++i)
3889 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003890 Type *matching_type = ResolveTypeUID (die_offsets[i]);
3891 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003892 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003893 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003894 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003895 ++num_matches;
3896 if (num_matches >= max_matches)
3897 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003898 }
3899 }
3900
3901 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003902 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003903}
3904
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003905
3906size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00003907SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
3908 clang::DeclContext *containing_decl_ctx,
Greg Clayton5113dc82011-08-12 06:47:54 +00003909 DWARFCompileUnit* dwarf_cu,
3910 const DWARFDebugInfoEntry *parent_die,
3911 bool skip_artificial,
3912 bool &is_static,
3913 TypeList* type_list,
3914 std::vector<clang_type_t>& function_param_types,
3915 std::vector<clang::ParmVarDecl*>& function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00003916 unsigned &type_quals,
3917 ClangASTContext::TemplateParameterInfos &template_param_infos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003918{
3919 if (parent_die == NULL)
3920 return 0;
3921
Greg Claytond88d7592010-09-15 08:33:30 +00003922 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3923
Greg Clayton7fedea22010-11-16 02:10:54 +00003924 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003925 const DWARFDebugInfoEntry *die;
3926 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3927 {
3928 dw_tag_t tag = die->Tag();
3929 switch (tag)
3930 {
3931 case DW_TAG_formal_parameter:
3932 {
3933 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003934 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003935 if (num_attributes > 0)
3936 {
3937 const char *name = NULL;
3938 Declaration decl;
3939 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003940 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003941 // one of None, Auto, Register, Extern, Static, PrivateExtern
3942
Sean Callanane2ef6e32010-09-23 03:01:22 +00003943 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003944 uint32_t i;
3945 for (i=0; i<num_attributes; ++i)
3946 {
3947 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3948 DWARFFormValue form_value;
3949 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3950 {
3951 switch (attr)
3952 {
3953 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3954 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3955 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3956 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
3957 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00003958 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003959 case DW_AT_location:
3960 // if (form_value.BlockData())
3961 // {
3962 // const DataExtractor& debug_info_data = debug_info();
3963 // uint32_t block_length = form_value.Unsigned();
3964 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
3965 // }
3966 // else
3967 // {
3968 // }
3969 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003970 case DW_AT_const_value:
3971 case DW_AT_default_value:
3972 case DW_AT_description:
3973 case DW_AT_endianity:
3974 case DW_AT_is_optional:
3975 case DW_AT_segment:
3976 case DW_AT_variable_parameter:
3977 default:
3978 case DW_AT_abstract_origin:
3979 case DW_AT_sibling:
3980 break;
3981 }
3982 }
3983 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00003984
Greg Clayton0fffff52010-09-24 05:15:53 +00003985 bool skip = false;
3986 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003987 {
Greg Clayton0fffff52010-09-24 05:15:53 +00003988 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00003989 {
3990 // In order to determine if a C++ member function is
3991 // "const" we have to look at the const-ness of "this"...
3992 // Ugly, but that
3993 if (arg_idx == 0)
3994 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003995 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00003996 {
Greg Clayton5113dc82011-08-12 06:47:54 +00003997 // Often times compilers omit the "this" name for the
3998 // specification DIEs, so we can't rely upon the name
3999 // being in the formal parameter DIE...
4000 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00004001 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004002 Type *this_type = ResolveTypeUID (param_type_die_offset);
4003 if (this_type)
4004 {
4005 uint32_t encoding_mask = this_type->GetEncodingMask();
4006 if (encoding_mask & Type::eEncodingIsPointerUID)
4007 {
4008 is_static = false;
4009
4010 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
4011 type_quals |= clang::Qualifiers::Const;
4012 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
4013 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00004014 }
4015 }
4016 }
4017 }
4018 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004019 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00004020 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004021 else
4022 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004023
Greg Clayton0fffff52010-09-24 05:15:53 +00004024 // HACK: Objective C formal parameters "self" and "_cmd"
4025 // are not marked as artificial in the DWARF...
Greg Clayton53eb1c22012-04-02 22:59:12 +00004026 CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
4027 if (comp_unit)
Greg Clayton0fffff52010-09-24 05:15:53 +00004028 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004029 switch (comp_unit->GetLanguage())
4030 {
4031 case eLanguageTypeObjC:
4032 case eLanguageTypeObjC_plus_plus:
4033 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
4034 skip = true;
4035 break;
4036 default:
4037 break;
4038 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004039 }
4040 }
4041 }
4042
4043 if (!skip)
4044 {
4045 Type *type = ResolveTypeUID(param_type_die_offset);
4046 if (type)
4047 {
Greg Claytonc93237c2010-10-01 20:48:32 +00004048 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00004049
Greg Clayton42ce2f32011-12-12 21:50:19 +00004050 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
4051 type->GetClangForwardType(),
4052 storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00004053 assert(param_var_decl);
4054 function_param_decls.push_back(param_var_decl);
Sean Callanan60217122012-04-13 00:10:03 +00004055
Greg Claytond0029442013-03-27 01:48:02 +00004056 GetClangASTContext().SetMetadataAsUserID (param_var_decl, MakeUserID(die->GetOffset()));
Greg Clayton0fffff52010-09-24 05:15:53 +00004057 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004058 }
4059 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004060 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004061 }
4062 break;
4063
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004064 case DW_TAG_template_type_parameter:
4065 case DW_TAG_template_value_parameter:
4066 ParseTemplateDIE (dwarf_cu, die,template_param_infos);
4067 break;
4068
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004069 default:
4070 break;
4071 }
4072 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004073 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004074}
4075
4076size_t
4077SymbolFileDWARF::ParseChildEnumerators
4078(
4079 const SymbolContext& sc,
Greg Clayton3e067532013-03-05 23:54:39 +00004080 clang_type_t enumerator_clang_type,
4081 bool is_signed,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004082 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00004083 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004084 const DWARFDebugInfoEntry *parent_die
4085)
4086{
4087 if (parent_die == NULL)
4088 return 0;
4089
4090 size_t enumerators_added = 0;
4091 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00004092 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
4093
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004094 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4095 {
4096 const dw_tag_t tag = die->Tag();
4097 if (tag == DW_TAG_enumerator)
4098 {
4099 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004100 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004101 if (num_child_attributes > 0)
4102 {
4103 const char *name = NULL;
4104 bool got_value = false;
4105 int64_t enum_value = 0;
4106 Declaration decl;
4107
4108 uint32_t i;
4109 for (i=0; i<num_child_attributes; ++i)
4110 {
4111 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4112 DWARFFormValue form_value;
4113 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4114 {
4115 switch (attr)
4116 {
4117 case DW_AT_const_value:
4118 got_value = true;
Greg Clayton3e067532013-03-05 23:54:39 +00004119 if (is_signed)
4120 enum_value = form_value.Signed();
4121 else
4122 enum_value = form_value.Unsigned();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004123 break;
4124
4125 case DW_AT_name:
4126 name = form_value.AsCString(&get_debug_str_data());
4127 break;
4128
4129 case DW_AT_description:
4130 default:
4131 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4132 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4133 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4134 case DW_AT_sibling:
4135 break;
4136 }
4137 }
4138 }
4139
4140 if (name && name[0] && got_value)
4141 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004142 GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
4143 enumerator_clang_type,
4144 decl,
4145 name,
4146 enum_value,
4147 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004148 ++enumerators_added;
4149 }
4150 }
4151 }
4152 }
4153 return enumerators_added;
4154}
4155
4156void
4157SymbolFileDWARF::ParseChildArrayInfo
4158(
4159 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004160 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004161 const DWARFDebugInfoEntry *parent_die,
4162 int64_t& first_index,
4163 std::vector<uint64_t>& element_orders,
4164 uint32_t& byte_stride,
4165 uint32_t& bit_stride
4166)
4167{
4168 if (parent_die == NULL)
4169 return;
4170
4171 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00004172 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004173 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4174 {
4175 const dw_tag_t tag = die->Tag();
4176 switch (tag)
4177 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004178 case DW_TAG_subrange_type:
4179 {
4180 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004181 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004182 if (num_child_attributes > 0)
4183 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004184 uint64_t num_elements = 0;
4185 uint64_t lower_bound = 0;
4186 uint64_t upper_bound = 0;
Greg Clayton4ef877f2012-12-06 02:33:54 +00004187 bool upper_bound_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004188 uint32_t i;
4189 for (i=0; i<num_child_attributes; ++i)
4190 {
4191 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4192 DWARFFormValue form_value;
4193 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4194 {
4195 switch (attr)
4196 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004197 case DW_AT_name:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004198 break;
4199
4200 case DW_AT_count:
4201 num_elements = form_value.Unsigned();
4202 break;
4203
4204 case DW_AT_bit_stride:
4205 bit_stride = form_value.Unsigned();
4206 break;
4207
4208 case DW_AT_byte_stride:
4209 byte_stride = form_value.Unsigned();
4210 break;
4211
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004212 case DW_AT_lower_bound:
4213 lower_bound = form_value.Unsigned();
4214 break;
4215
4216 case DW_AT_upper_bound:
Greg Clayton4ef877f2012-12-06 02:33:54 +00004217 upper_bound_valid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004218 upper_bound = form_value.Unsigned();
4219 break;
4220
4221 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004222 case DW_AT_abstract_origin:
4223 case DW_AT_accessibility:
4224 case DW_AT_allocated:
4225 case DW_AT_associated:
4226 case DW_AT_data_location:
4227 case DW_AT_declaration:
4228 case DW_AT_description:
4229 case DW_AT_sibling:
4230 case DW_AT_threads_scaled:
4231 case DW_AT_type:
4232 case DW_AT_visibility:
4233 break;
4234 }
4235 }
4236 }
4237
Greg Claytone6a07792012-12-05 21:59:39 +00004238 if (num_elements == 0)
4239 {
Greg Clayton4ef877f2012-12-06 02:33:54 +00004240 if (upper_bound_valid && upper_bound >= lower_bound)
Greg Claytone6a07792012-12-05 21:59:39 +00004241 num_elements = upper_bound - lower_bound + 1;
4242 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004243
Sean Callananec979ba2012-10-22 23:56:48 +00004244 element_orders.push_back (num_elements);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004245 }
4246 }
4247 break;
4248 }
4249 }
4250}
4251
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004252TypeSP
Greg Clayton53eb1c22012-04-02 22:59:12 +00004253SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004254{
4255 TypeSP type_sp;
4256 if (die != NULL)
4257 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004258 assert(dwarf_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00004259 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004260 if (type_ptr == NULL)
4261 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004262 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu);
Greg Claytonca512b32011-01-14 04:54:56 +00004263 assert (lldb_cu);
4264 SymbolContext sc(lldb_cu);
Greg Clayton53eb1c22012-04-02 22:59:12 +00004265 type_sp = ParseType(sc, dwarf_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004266 }
4267 else if (type_ptr != DIE_IS_BEING_PARSED)
4268 {
4269 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00004270 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004271 }
4272
4273 }
4274 return type_sp;
4275}
4276
4277clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00004278SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004279{
4280 if (die_offset != DW_INVALID_OFFSET)
4281 {
4282 DWARFCompileUnitSP cu_sp;
4283 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004284 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004285 }
4286 return NULL;
4287}
4288
Sean Callanan72e49402011-08-05 23:43:37 +00004289clang::DeclContext *
4290SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
4291{
4292 if (die_offset != DW_INVALID_OFFSET)
4293 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004294 DWARFDebugInfo* debug_info = DebugInfo();
4295 if (debug_info)
4296 {
4297 DWARFCompileUnitSP cu_sp;
4298 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
4299 if (die)
4300 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
4301 }
Sean Callanan72e49402011-08-05 23:43:37 +00004302 }
4303 return NULL;
4304}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004305
Greg Clayton96d7d742010-11-10 23:42:09 +00004306clang::NamespaceDecl *
Greg Clayton53eb1c22012-04-02 22:59:12 +00004307SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die)
Greg Clayton96d7d742010-11-10 23:42:09 +00004308{
Greg Clayton030a2042011-10-14 21:34:45 +00004309 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00004310 {
Greg Clayton030a2042011-10-14 21:34:45 +00004311 // See if we already parsed this namespace DIE and associated it with a
4312 // uniqued namespace declaration
4313 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
4314 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004315 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00004316 else
4317 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004318 const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL);
4319 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00004320 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
Greg Clayton5160ce52013-03-27 23:08:40 +00004321 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton9d3d6882011-10-31 23:51:19 +00004322 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00004323 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00004324 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00004325 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004326 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00004327 "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 +00004328 GetClangASTContext().getASTContext(),
4329 MakeUserID(die->GetOffset()),
4330 namespace_name,
4331 namespace_decl,
4332 namespace_decl->getOriginalNamespace());
Greg Clayton030a2042011-10-14 21:34:45 +00004333 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004334 else
4335 {
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 (anonymous) => clang::NamespaceDecl *%p (original = %p)",
Greg Claytone38a5ed2012-01-05 03:57:59 +00004338 GetClangASTContext().getASTContext(),
4339 MakeUserID(die->GetOffset()),
4340 namespace_decl,
4341 namespace_decl->getOriginalNamespace());
Greg Clayton9d3d6882011-10-31 23:51:19 +00004342 }
Greg Clayton030a2042011-10-14 21:34:45 +00004343 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004344
4345 if (namespace_decl)
4346 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
4347 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004348 }
4349 }
4350 return NULL;
4351}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004352
4353clang::DeclContext *
Greg Claytoncab36a32011-12-08 05:16:30 +00004354SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Sean Callanan72e49402011-08-05 23:43:37 +00004355{
Greg Clayton5cf58b92011-10-05 22:22:08 +00004356 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4357 if (clang_decl_ctx)
4358 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004359 // If this DIE has a specification, or an abstract origin, then trace to those.
4360
Greg Claytoncab36a32011-12-08 05:16:30 +00004361 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004362 if (die_offset != DW_INVALID_OFFSET)
4363 return GetClangDeclContextForDIEOffset (sc, die_offset);
4364
Greg Claytoncab36a32011-12-08 05:16:30 +00004365 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004366 if (die_offset != DW_INVALID_OFFSET)
4367 return GetClangDeclContextForDIEOffset (sc, die_offset);
4368
Greg Clayton5160ce52013-03-27 23:08:40 +00004369 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00004370 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004371 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 +00004372 // This is the DIE we want. Parse it, then query our map.
Greg Claytoncab36a32011-12-08 05:16:30 +00004373 bool assert_not_being_parsed = true;
4374 ResolveTypeUID (cu, die, assert_not_being_parsed);
4375
Greg Clayton5cf58b92011-10-05 22:22:08 +00004376 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4377
4378 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004379}
4380
4381clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00004382SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004383{
Greg Claytonca512b32011-01-14 04:54:56 +00004384 if (m_clang_tu_decl == NULL)
4385 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004386
Greg Clayton2bc22f82011-09-30 03:20:47 +00004387 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004388
4389 if (decl_ctx_die_copy)
4390 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00004391
4392 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004393 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00004394
Greg Clayton2bc22f82011-09-30 03:20:47 +00004395 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
4396 if (pos != m_die_to_decl_ctx.end())
4397 return pos->second;
4398
4399 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004400 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004401 case DW_TAG_compile_unit:
4402 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004403
Greg Clayton2bc22f82011-09-30 03:20:47 +00004404 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00004405 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00004406 break;
4407
4408 case DW_TAG_structure_type:
4409 case DW_TAG_union_type:
4410 case DW_TAG_class_type:
4411 {
4412 Type* type = ResolveType (cu, decl_ctx_die);
4413 if (type)
4414 {
4415 clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ());
4416 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00004417 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004418 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
4419 if (decl_ctx)
4420 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00004421 }
4422 }
Greg Claytonca512b32011-01-14 04:54:56 +00004423 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00004424 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004425
Greg Clayton2bc22f82011-09-30 03:20:47 +00004426 default:
4427 break;
Greg Claytonca512b32011-01-14 04:54:56 +00004428 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004429 }
Greg Clayton7a345282010-11-09 23:46:37 +00004430 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004431}
4432
Greg Clayton2bc22f82011-09-30 03:20:47 +00004433
4434const DWARFDebugInfoEntry *
4435SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4436{
4437 if (cu && die)
4438 {
4439 const DWARFDebugInfoEntry * const decl_die = die;
4440
4441 while (die != NULL)
4442 {
4443 // If this is the original DIE that we are searching for a declaration
4444 // for, then don't look in the cache as we don't want our own decl
4445 // context to be our decl context...
4446 if (decl_die != die)
4447 {
4448 switch (die->Tag())
4449 {
4450 case DW_TAG_compile_unit:
4451 case DW_TAG_namespace:
4452 case DW_TAG_structure_type:
4453 case DW_TAG_union_type:
4454 case DW_TAG_class_type:
4455 return die;
4456
4457 default:
4458 break;
4459 }
4460 }
4461
4462 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4463 if (die_offset != DW_INVALID_OFFSET)
4464 {
4465 DWARFCompileUnit *spec_cu = cu;
4466 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
4467 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
4468 if (spec_die_decl_ctx_die)
4469 return spec_die_decl_ctx_die;
4470 }
4471
4472 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
4473 if (die_offset != DW_INVALID_OFFSET)
4474 {
4475 DWARFCompileUnit *abs_cu = cu;
4476 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
4477 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
4478 if (abs_die_decl_ctx_die)
4479 return abs_die_decl_ctx_die;
4480 }
4481
4482 die = die->GetParent();
4483 }
4484 }
4485 return NULL;
4486}
4487
4488
Greg Clayton901c5ca2011-12-03 04:40:03 +00004489Symbol *
4490SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
4491{
4492 Symbol *objc_class_symbol = NULL;
4493 if (m_obj_file)
4494 {
4495 Symtab *symtab = m_obj_file->GetSymtab();
4496 if (symtab)
4497 {
4498 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
4499 eSymbolTypeObjCClass,
4500 Symtab::eDebugNo,
4501 Symtab::eVisibilityAny);
4502 }
4503 }
4504 return objc_class_symbol;
4505}
4506
Greg Claytonc7f03b62012-01-12 04:33:28 +00004507// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
4508// then we can end up looking through all class types for a complete type and never find
4509// the full definition. We need to know if this attribute is supported, so we determine
4510// this here and cache th result. We also need to worry about the debug map DWARF file
4511// if we are doing darwin DWARF in .o file debugging.
4512bool
4513SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
4514{
4515 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
4516 {
4517 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
4518 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
4519 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4520 else
4521 {
4522 DWARFDebugInfo* debug_info = DebugInfo();
4523 const uint32_t num_compile_units = GetNumCompileUnits();
4524 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
4525 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004526 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
4527 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004528 {
4529 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4530 break;
4531 }
4532 }
4533 }
Greg Clayton1f746072012-08-29 21:13:06 +00004534 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004535 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
4536 }
4537 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
4538}
Greg Clayton901c5ca2011-12-03 04:40:03 +00004539
4540// This function can be used when a DIE is found that is a forward declaration
4541// DIE and we want to try and find a type that has the complete definition.
4542TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00004543SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
4544 const ConstString &type_name,
4545 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00004546{
4547
4548 TypeSP type_sp;
4549
Greg Claytonc7f03b62012-01-12 04:33:28 +00004550 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00004551 return type_sp;
4552
4553 DIEArray die_offsets;
4554
4555 if (m_using_apple_tables)
4556 {
4557 if (m_apple_types_ap.get())
4558 {
4559 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00004560 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004561 }
4562 }
4563 else
4564 {
4565 if (!m_indexed)
4566 Index ();
4567
4568 m_type_index.Find (type_name, die_offsets);
4569 }
4570
Greg Clayton901c5ca2011-12-03 04:40:03 +00004571 const size_t num_matches = die_offsets.size();
4572
Greg Clayton901c5ca2011-12-03 04:40:03 +00004573 DWARFCompileUnit* type_cu = NULL;
4574 const DWARFDebugInfoEntry* type_die = NULL;
4575 if (num_matches)
4576 {
4577 DWARFDebugInfo* debug_info = DebugInfo();
4578 for (size_t i=0; i<num_matches; ++i)
4579 {
4580 const dw_offset_t die_offset = die_offsets[i];
4581 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4582
4583 if (type_die)
4584 {
4585 bool try_resolving_type = false;
4586
4587 // Don't try and resolve the DIE we are looking for with the DIE itself!
4588 if (type_die != die)
4589 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004590 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00004591 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004592 case DW_TAG_class_type:
4593 case DW_TAG_structure_type:
4594 try_resolving_type = true;
4595 break;
4596 default:
4597 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00004598 }
4599 }
4600
4601 if (try_resolving_type)
4602 {
Sean Callanana9bc0652012-01-19 02:17:40 +00004603 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004604 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004605
4606 if (try_resolving_type)
4607 {
4608 Type *resolved_type = ResolveType (type_cu, type_die, false);
4609 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4610 {
Daniel Malead01b2952012-11-29 21:49:15 +00004611 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 +00004612 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00004613 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton901c5ca2011-12-03 04:40:03 +00004614 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4615 MakeUserID(type_die->GetOffset()),
4616 MakeUserID(type_cu->GetOffset()));
4617
Greg Claytonc7f03b62012-01-12 04:33:28 +00004618 if (die)
4619 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00004620 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00004621 break;
4622 }
4623 }
4624 }
4625 }
4626 else
4627 {
4628 if (m_using_apple_tables)
4629 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004630 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4631 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00004632 }
4633 }
4634
4635 }
4636 }
4637 return type_sp;
4638}
4639
Greg Claytona8022fa2012-04-24 21:22:41 +00004640
Greg Clayton80c26302012-02-05 06:12:47 +00004641//----------------------------------------------------------------------
4642// This function helps to ensure that the declaration contexts match for
4643// two different DIEs. Often times debug information will refer to a
4644// forward declaration of a type (the equivalent of "struct my_struct;".
4645// There will often be a declaration of that type elsewhere that has the
4646// full definition. When we go looking for the full type "my_struct", we
4647// will find one or more matches in the accelerator tables and we will
4648// then need to make sure the type was in the same declaration context
4649// as the original DIE. This function can efficiently compare two DIEs
4650// and will return true when the declaration context matches, and false
4651// when they don't.
4652//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00004653bool
4654SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
4655 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
4656{
Greg Claytona8022fa2012-04-24 21:22:41 +00004657 if (die1 == die2)
4658 return true;
4659
4660#if defined (LLDB_CONFIGURATION_DEBUG)
4661 // You can't and shouldn't call this function with a compile unit from
4662 // two different SymbolFileDWARF instances.
4663 assert (DebugInfo()->ContainsCompileUnit (cu1));
4664 assert (DebugInfo()->ContainsCompileUnit (cu2));
4665#endif
4666
Greg Clayton890ff562012-02-02 05:48:16 +00004667 DWARFDIECollection decl_ctx_1;
4668 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00004669 //The declaration DIE stack is a stack of the declaration context
4670 // DIEs all the way back to the compile unit. If a type "T" is
4671 // declared inside a class "B", and class "B" is declared inside
4672 // a class "A" and class "A" is in a namespace "lldb", and the
4673 // namespace is in a compile unit, there will be a stack of DIEs:
4674 //
4675 // [0] DW_TAG_class_type for "B"
4676 // [1] DW_TAG_class_type for "A"
4677 // [2] DW_TAG_namespace for "lldb"
4678 // [3] DW_TAG_compile_unit for the source file.
4679 //
4680 // We grab both contexts and make sure that everything matches
4681 // all the way back to the compiler unit.
4682
4683 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00004684 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004685 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00004686 // Make sure the context arrays have the same size, otherwise
4687 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00004688 const size_t count1 = decl_ctx_1.Size();
4689 const size_t count2 = decl_ctx_2.Size();
4690 if (count1 != count2)
4691 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00004692
4693 // Make sure the DW_TAG values match all the way back up the the
4694 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00004695 const DWARFDebugInfoEntry *decl_ctx_die1;
4696 const DWARFDebugInfoEntry *decl_ctx_die2;
4697 size_t i;
4698 for (i=0; i<count1; i++)
4699 {
4700 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4701 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4702 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
4703 return false;
4704 }
Greg Clayton890ff562012-02-02 05:48:16 +00004705#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00004706
4707 // Make sure the top item in the decl context die array is always
4708 // DW_TAG_compile_unit. If it isn't then something went wrong in
4709 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00004710 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00004711
Greg Clayton890ff562012-02-02 05:48:16 +00004712#endif
4713 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00004714 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00004715 for (i=0; i<count1 - 1; i++)
4716 {
4717 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4718 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4719 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004720 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00004721 // If the string was from a DW_FORM_strp, then the pointer will often
4722 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00004723 if (name1 == name2)
4724 continue;
4725
4726 // Name pointers are not equal, so only compare the strings
4727 // if both are not NULL.
4728 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00004729 {
Greg Clayton5569e642012-02-06 01:44:54 +00004730 // If the strings don't compare, we are done...
4731 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00004732 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00004733 }
4734 else
4735 {
4736 // One name was NULL while the other wasn't
4737 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00004738 }
4739 }
Greg Clayton80c26302012-02-05 06:12:47 +00004740 // We made it through all of the checks and the declaration contexts
4741 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00004742 return true;
4743}
Greg Clayton220a0072011-12-09 08:48:30 +00004744
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004745// This function can be used when a DIE is found that is a forward declaration
4746// DIE and we want to try and find a type that has the complete definition.
Greg Claytona8022fa2012-04-24 21:22:41 +00004747// "cu" and "die" must be from this SymbolFileDWARF
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004748TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00004749SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
Greg Clayton7f995132011-10-04 22:41:51 +00004750 const DWARFDebugInfoEntry *die,
4751 const ConstString &type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004752{
4753 TypeSP type_sp;
4754
Greg Claytona8022fa2012-04-24 21:22:41 +00004755#if defined (LLDB_CONFIGURATION_DEBUG)
4756 // You can't and shouldn't call this function with a compile unit from
4757 // another SymbolFileDWARF instance.
4758 assert (DebugInfo()->ContainsCompileUnit (cu));
4759#endif
4760
Greg Clayton1a65ae12011-01-25 23:55:37 +00004761 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004762 return type_sp;
4763
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004764 std::string qualified_name;
4765
Greg Clayton5160ce52013-03-27 23:08:40 +00004766 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004767 if (log)
4768 {
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004769 die->GetQualifiedName(this, cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00004770 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004771 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x (%s), name='%s')",
4772 die->GetOffset(),
4773 qualified_name.c_str(),
4774 type_name.GetCString());
4775 }
4776
Greg Clayton7f995132011-10-04 22:41:51 +00004777 DIEArray die_offsets;
4778
Greg Clayton97fbc342011-10-20 22:30:33 +00004779 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004780 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004781 if (m_apple_types_ap.get())
4782 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004783 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
4784 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
4785 if (has_tag && has_qualified_name_hash)
Greg Claytond1767f02011-12-08 02:13:16 +00004786 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004787 if (qualified_name.empty())
4788 die->GetQualifiedName(this, cu, qualified_name);
4789
4790 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name.c_str());
4791 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004792 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004793 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), die->Tag(), qualified_name_hash, die_offsets);
4794 }
4795 else if (has_tag > 1)
4796 {
4797 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004798 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
Greg Claytonae920b62012-01-06 00:17:16 +00004799 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets);
Greg Claytond1767f02011-12-08 02:13:16 +00004800 }
4801 else
4802 {
4803 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
4804 }
Greg Clayton97fbc342011-10-20 22:30:33 +00004805 }
Greg Clayton7f995132011-10-04 22:41:51 +00004806 }
4807 else
4808 {
4809 if (!m_indexed)
4810 Index ();
4811
4812 m_type_index.Find (type_name, die_offsets);
4813 }
Greg Clayton7f995132011-10-04 22:41:51 +00004814
4815 const size_t num_matches = die_offsets.size();
Greg Clayton69974892010-12-03 21:42:06 +00004816
Greg Clayton934cb052011-12-03 00:27:05 +00004817 const dw_tag_t die_tag = die->Tag();
Greg Claytond4a2b372011-09-12 23:21:58 +00004818
4819 DWARFCompileUnit* type_cu = NULL;
4820 const DWARFDebugInfoEntry* type_die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00004821 if (num_matches)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004822 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004823 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004824 for (size_t i=0; i<num_matches; ++i)
4825 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004826 const dw_offset_t die_offset = die_offsets[i];
4827 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004828
Greg Clayton95d87902011-11-11 03:16:25 +00004829 if (type_die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004830 {
Greg Clayton934cb052011-12-03 00:27:05 +00004831 bool try_resolving_type = false;
4832
4833 // Don't try and resolve the DIE we are looking for with the DIE itself!
4834 if (type_die != die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004835 {
Greg Clayton934cb052011-12-03 00:27:05 +00004836 const dw_tag_t type_die_tag = type_die->Tag();
4837 // Make sure the tags match
4838 if (type_die_tag == die_tag)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004839 {
Greg Clayton934cb052011-12-03 00:27:05 +00004840 // The tags match, lets try resolving this type
4841 try_resolving_type = true;
4842 }
4843 else
4844 {
4845 // The tags don't match, but we need to watch our for a
4846 // forward declaration for a struct and ("struct foo")
4847 // ends up being a class ("class foo { ... };") or
4848 // vice versa.
4849 switch (type_die_tag)
Greg Clayton95d87902011-11-11 03:16:25 +00004850 {
Greg Clayton934cb052011-12-03 00:27:05 +00004851 case DW_TAG_class_type:
4852 // We had a "class foo", see if we ended up with a "struct foo { ... };"
4853 try_resolving_type = (die_tag == DW_TAG_structure_type);
4854 break;
4855 case DW_TAG_structure_type:
4856 // We had a "struct foo", see if we ended up with a "class foo { ... };"
4857 try_resolving_type = (die_tag == DW_TAG_class_type);
4858 break;
4859 default:
4860 // Tags don't match, don't event try to resolve
4861 // using this type whose name matches....
Greg Clayton95d87902011-11-11 03:16:25 +00004862 break;
4863 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004864 }
4865 }
Greg Clayton934cb052011-12-03 00:27:05 +00004866
4867 if (try_resolving_type)
4868 {
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004869 if (log)
4870 {
4871 std::string qualified_name;
4872 type_die->GetQualifiedName(this, cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00004873 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004874 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') trying die=0x%8.8x (%s)",
4875 die->GetOffset(),
4876 type_name.GetCString(),
4877 type_die->GetOffset(),
4878 qualified_name.c_str());
4879 }
4880
Greg Clayton890ff562012-02-02 05:48:16 +00004881 // Make sure the decl contexts match all the way up
4882 if (DIEDeclContextsMatch(cu, die, type_cu, type_die))
Greg Clayton934cb052011-12-03 00:27:05 +00004883 {
Greg Clayton890ff562012-02-02 05:48:16 +00004884 Type *resolved_type = ResolveType (type_cu, type_die, false);
4885 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4886 {
Daniel Malead01b2952012-11-29 21:49:15 +00004887 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 +00004888 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00004889 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton890ff562012-02-02 05:48:16 +00004890 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4891 MakeUserID(type_die->GetOffset()),
4892 MakeUserID(type_cu->GetOffset()));
4893
4894 m_die_to_type[die] = resolved_type;
Greg Claytonff7692a2012-02-02 18:16:59 +00004895 type_sp = resolved_type->shared_from_this();
Greg Clayton890ff562012-02-02 05:48:16 +00004896 break;
4897 }
Greg Clayton934cb052011-12-03 00:27:05 +00004898 }
4899 }
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004900 else
4901 {
4902 if (log)
4903 {
4904 std::string qualified_name;
4905 type_die->GetQualifiedName(this, cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00004906 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004907 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') ignoring die=0x%8.8x (%s)",
4908 die->GetOffset(),
4909 type_name.GetCString(),
4910 type_die->GetOffset(),
4911 qualified_name.c_str());
4912 }
4913 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004914 }
Greg Clayton95d87902011-11-11 03:16:25 +00004915 else
4916 {
4917 if (m_using_apple_tables)
4918 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004919 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4920 die_offset, type_name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004921 }
4922 }
4923
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004924 }
4925 }
4926 return type_sp;
4927}
4928
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004929TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00004930SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx)
4931{
4932 TypeSP type_sp;
4933
4934 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
4935 if (dwarf_decl_ctx_count > 0)
4936 {
4937 const ConstString type_name(dwarf_decl_ctx[0].name);
4938 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
4939
4940 if (type_name)
4941 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004942 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
Greg Claytona8022fa2012-04-24 21:22:41 +00004943 if (log)
4944 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004945 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00004946 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')",
4947 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
4948 dwarf_decl_ctx.GetQualifiedName());
4949 }
4950
4951 DIEArray die_offsets;
4952
4953 if (m_using_apple_tables)
4954 {
4955 if (m_apple_types_ap.get())
4956 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004957 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
4958 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
4959 if (has_tag && has_qualified_name_hash)
Greg Claytona8022fa2012-04-24 21:22:41 +00004960 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004961 const char *qualified_name = dwarf_decl_ctx.GetQualifiedName();
4962 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name);
4963 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004964 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004965 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets);
4966 }
4967 else if (has_tag)
4968 {
4969 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004970 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
Greg Claytona8022fa2012-04-24 21:22:41 +00004971 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets);
4972 }
4973 else
4974 {
4975 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
4976 }
4977 }
4978 }
4979 else
4980 {
4981 if (!m_indexed)
4982 Index ();
4983
4984 m_type_index.Find (type_name, die_offsets);
4985 }
4986
4987 const size_t num_matches = die_offsets.size();
4988
4989
4990 DWARFCompileUnit* type_cu = NULL;
4991 const DWARFDebugInfoEntry* type_die = NULL;
4992 if (num_matches)
4993 {
4994 DWARFDebugInfo* debug_info = DebugInfo();
4995 for (size_t i=0; i<num_matches; ++i)
4996 {
4997 const dw_offset_t die_offset = die_offsets[i];
4998 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4999
5000 if (type_die)
5001 {
5002 bool try_resolving_type = false;
5003
5004 // Don't try and resolve the DIE we are looking for with the DIE itself!
5005 const dw_tag_t type_tag = type_die->Tag();
5006 // Make sure the tags match
5007 if (type_tag == tag)
5008 {
5009 // The tags match, lets try resolving this type
5010 try_resolving_type = true;
5011 }
5012 else
5013 {
5014 // The tags don't match, but we need to watch our for a
5015 // forward declaration for a struct and ("struct foo")
5016 // ends up being a class ("class foo { ... };") or
5017 // vice versa.
5018 switch (type_tag)
5019 {
5020 case DW_TAG_class_type:
5021 // We had a "class foo", see if we ended up with a "struct foo { ... };"
5022 try_resolving_type = (tag == DW_TAG_structure_type);
5023 break;
5024 case DW_TAG_structure_type:
5025 // We had a "struct foo", see if we ended up with a "class foo { ... };"
5026 try_resolving_type = (tag == DW_TAG_class_type);
5027 break;
5028 default:
5029 // Tags don't match, don't event try to resolve
5030 // using this type whose name matches....
5031 break;
5032 }
5033 }
5034
5035 if (try_resolving_type)
5036 {
5037 DWARFDeclContext type_dwarf_decl_ctx;
5038 type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx);
5039
5040 if (log)
5041 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005042 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005043 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)",
5044 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5045 dwarf_decl_ctx.GetQualifiedName(),
5046 type_die->GetOffset(),
5047 type_dwarf_decl_ctx.GetQualifiedName());
5048 }
5049
5050 // Make sure the decl contexts match all the way up
5051 if (dwarf_decl_ctx == type_dwarf_decl_ctx)
5052 {
5053 Type *resolved_type = ResolveType (type_cu, type_die, false);
5054 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5055 {
5056 type_sp = resolved_type->shared_from_this();
5057 break;
5058 }
5059 }
5060 }
5061 else
5062 {
5063 if (log)
5064 {
5065 std::string qualified_name;
5066 type_die->GetQualifiedName(this, type_cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00005067 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005068 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)",
5069 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5070 dwarf_decl_ctx.GetQualifiedName(),
5071 type_die->GetOffset(),
5072 qualified_name.c_str());
5073 }
5074 }
5075 }
5076 else
5077 {
5078 if (m_using_apple_tables)
5079 {
5080 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5081 die_offset, type_name.GetCString());
5082 }
5083 }
5084
5085 }
5086 }
5087 }
5088 }
5089 return type_sp;
5090}
5091
Greg Clayton4116e932012-05-15 02:33:01 +00005092bool
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005093SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005094 Type *class_type,
Greg Clayton4116e932012-05-15 02:33:01 +00005095 DWARFCompileUnit* src_cu,
5096 const DWARFDebugInfoEntry *src_class_die,
5097 DWARFCompileUnit* dst_cu,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005098 const DWARFDebugInfoEntry *dst_class_die,
5099 llvm::SmallVectorImpl <const DWARFDebugInfoEntry *> &failures)
Greg Clayton4116e932012-05-15 02:33:01 +00005100{
5101 if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die)
5102 return false;
5103 if (src_class_die->Tag() != dst_class_die->Tag())
5104 return false;
5105
5106 // We need to complete the class type so we can get all of the method types
5107 // parsed so we can then unique those types to their equivalent counterparts
5108 // in "dst_cu" and "dst_class_die"
5109 class_type->GetClangFullType();
5110
5111 const DWARFDebugInfoEntry *src_die;
5112 const DWARFDebugInfoEntry *dst_die;
5113 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die;
5114 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die;
Greg Clayton65ec1032012-11-12 21:27:20 +00005115 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial;
5116 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial;
Greg Clayton4116e932012-05-15 02:33:01 +00005117 for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling())
5118 {
5119 if (src_die->Tag() == DW_TAG_subprogram)
5120 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005121 // Make sure this is a declaration and not a concrete instance by looking
5122 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5123 // are placed inside the class definitions and shouldn't be included in
5124 // the list of things are are tracking here.
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005125 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_declaration, 0) == 1)
Greg Clayton84afacd2012-11-07 23:09:32 +00005126 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005127 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton84afacd2012-11-07 23:09:32 +00005128 if (src_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005129 {
5130 ConstString src_const_name(src_name);
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005131 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0))
Greg Clayton65ec1032012-11-12 21:27:20 +00005132 src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die);
5133 else
5134 src_name_to_die.Append(src_const_name.GetCString(), src_die);
5135 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005136 }
Greg Clayton4116e932012-05-15 02:33:01 +00005137 }
5138 }
5139 for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling())
5140 {
5141 if (dst_die->Tag() == DW_TAG_subprogram)
5142 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005143 // Make sure this is a declaration and not a concrete instance by looking
5144 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5145 // are placed inside the class definitions and shouldn't be included in
5146 // the list of things are are tracking here.
5147 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1)
5148 {
5149 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5150 if (dst_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005151 {
5152 ConstString dst_const_name(dst_name);
5153 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0))
5154 dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die);
5155 else
5156 dst_name_to_die.Append(dst_const_name.GetCString(), dst_die);
5157 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005158 }
Greg Clayton4116e932012-05-15 02:33:01 +00005159 }
5160 }
5161 const uint32_t src_size = src_name_to_die.GetSize ();
5162 const uint32_t dst_size = dst_name_to_die.GetSize ();
Greg Clayton5160ce52013-03-27 23:08:40 +00005163 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005164
5165 // Is everything kosher so we can go through the members at top speed?
5166 bool fast_path = true;
5167
5168 if (src_size != dst_size)
Greg Clayton4116e932012-05-15 02:33:01 +00005169 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005170 if (src_size != 0 && dst_size != 0)
5171 {
5172 if (log)
5173 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)",
5174 src_class_die->GetOffset(),
5175 dst_class_die->GetOffset(),
5176 src_size,
5177 dst_size);
5178 }
5179
5180 fast_path = false;
5181 }
5182
5183 uint32_t idx;
5184
5185 if (fast_path)
5186 {
Greg Clayton4116e932012-05-15 02:33:01 +00005187 for (idx = 0; idx < src_size; ++idx)
5188 {
5189 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5190 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5191
5192 if (src_die->Tag() != dst_die->Tag())
5193 {
5194 if (log)
5195 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)",
5196 src_class_die->GetOffset(),
5197 dst_class_die->GetOffset(),
5198 src_die->GetOffset(),
5199 DW_TAG_value_to_name(src_die->Tag()),
5200 dst_die->GetOffset(),
5201 DW_TAG_value_to_name(src_die->Tag()));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005202 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005203 }
5204
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005205 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton4116e932012-05-15 02:33:01 +00005206 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5207
5208 // Make sure the names match
5209 if (src_name == dst_name || (strcmp (src_name, dst_name) == 0))
5210 continue;
5211
5212 if (log)
5213 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)",
5214 src_class_die->GetOffset(),
5215 dst_class_die->GetOffset(),
5216 src_die->GetOffset(),
5217 src_name,
5218 dst_die->GetOffset(),
5219 dst_name);
5220
Sean Callanan2367f8a2013-02-26 01:12:25 +00005221 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005222 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005223 }
Greg Clayton4116e932012-05-15 02:33:01 +00005224
Sean Callanan2367f8a2013-02-26 01:12:25 +00005225 // Now do the work of linking the DeclContexts and Types.
5226 if (fast_path)
5227 {
5228 // We can do this quickly. Just run across the tables index-for-index since
5229 // we know each node has matching names and tags.
Greg Clayton4116e932012-05-15 02:33:01 +00005230 for (idx = 0; idx < src_size; ++idx)
5231 {
5232 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5233 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5234
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005235 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Greg Clayton4116e932012-05-15 02:33:01 +00005236 if (src_decl_ctx)
5237 {
5238 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005239 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 +00005240 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5241 }
5242 else
5243 {
5244 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005245 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 +00005246 }
5247
5248 Type *src_child_type = m_die_to_type[src_die];
5249 if (src_child_type)
5250 {
5251 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00005252 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 +00005253 m_die_to_type[dst_die] = src_child_type;
5254 }
5255 else
5256 {
5257 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005258 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());
5259 }
5260 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005261 }
5262 else
5263 {
5264 // We must do this slowly. For each member of the destination, look
5265 // up a member in the source with the same name, check its tag, and
5266 // unique them if everything matches up. Report failures.
Greg Clayton65ec1032012-11-12 21:27:20 +00005267
Sean Callanan2367f8a2013-02-26 01:12:25 +00005268 if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty())
5269 {
5270 src_name_to_die.Sort();
Greg Clayton65ec1032012-11-12 21:27:20 +00005271
Sean Callanan2367f8a2013-02-26 01:12:25 +00005272 for (idx = 0; idx < dst_size; ++idx)
5273 {
5274 const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx);
5275 dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
5276 src_die = src_name_to_die.Find(dst_name, NULL);
5277
5278 if (src_die && (src_die->Tag() == dst_die->Tag()))
5279 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005280 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Sean Callanan2367f8a2013-02-26 01:12:25 +00005281 if (src_decl_ctx)
5282 {
5283 if (log)
5284 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
5285 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5286 }
5287 else
5288 {
5289 if (log)
5290 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());
5291 }
5292
5293 Type *src_child_type = m_die_to_type[src_die];
5294 if (src_child_type)
5295 {
5296 if (log)
5297 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());
5298 m_die_to_type[dst_die] = src_child_type;
5299 }
5300 else
5301 {
5302 if (log)
5303 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());
5304 }
5305 }
5306 else
5307 {
5308 if (log)
5309 log->Printf ("warning: couldn't find a match for 0x%8.8x", dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005310
Sean Callanan2367f8a2013-02-26 01:12:25 +00005311 failures.push_back(dst_die);
5312 }
5313 }
5314 }
5315 }
5316
5317 const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize ();
5318 const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize ();
5319
5320 UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src;
5321
5322 if (src_size_artificial && dst_size_artificial)
5323 {
5324 dst_name_to_die_artificial.Sort();
5325
Greg Clayton65ec1032012-11-12 21:27:20 +00005326 for (idx = 0; idx < src_size_artificial; ++idx)
5327 {
5328 const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx);
5329 src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5330 dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL);
5331
5332 if (dst_die)
5333 {
Greg Clayton65ec1032012-11-12 21:27:20 +00005334 // Both classes have the artificial types, link them
5335 clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die];
5336 if (src_decl_ctx)
5337 {
5338 if (log)
5339 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
5340 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5341 }
5342 else
5343 {
5344 if (log)
5345 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());
5346 }
5347
5348 Type *src_child_type = m_die_to_type[src_die];
5349 if (src_child_type)
5350 {
5351 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00005352 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 +00005353 m_die_to_type[dst_die] = src_child_type;
5354 }
5355 else
5356 {
5357 if (log)
5358 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());
5359 }
5360 }
5361 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005362 }
Greg Clayton65ec1032012-11-12 21:27:20 +00005363
Sean Callanan2367f8a2013-02-26 01:12:25 +00005364 if (dst_size_artificial)
Greg Clayton4116e932012-05-15 02:33:01 +00005365 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005366 for (idx = 0; idx < dst_size_artificial; ++idx)
5367 {
5368 const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx);
5369 dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5370 if (log)
5371 log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial);
5372
5373 failures.push_back(dst_die);
5374 }
Greg Clayton4116e932012-05-15 02:33:01 +00005375 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005376
5377 return (failures.size() != 0);
Greg Clayton4116e932012-05-15 02:33:01 +00005378}
Greg Claytona8022fa2012-04-24 21:22:41 +00005379
5380TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00005381SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005382{
5383 TypeSP type_sp;
5384
Greg Clayton1be10fc2010-09-29 01:12:09 +00005385 if (type_is_new_ptr)
5386 *type_is_new_ptr = false;
Greg Clayton1fba87112012-02-09 20:03:49 +00005387
5388#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5389 static DIEStack g_die_stack;
5390 DIEStack::ScopedPopper scoped_die_logger(g_die_stack);
5391#endif
Greg Clayton1be10fc2010-09-29 01:12:09 +00005392
Sean Callananc7fbf732010-08-06 00:32:49 +00005393 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005394 if (die != NULL)
5395 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005396 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005397 if (log)
Sean Callanan5b26f272012-02-04 08:49:35 +00005398 {
5399 const DWARFDebugInfoEntry *context_die;
5400 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
5401
Greg Clayton5160ce52013-03-27 23:08:40 +00005402 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 +00005403 die->GetOffset(),
5404 context,
5405 context_die->GetOffset(),
Greg Clayton3bffb082011-12-10 02:15:28 +00005406 DW_TAG_value_to_name(die->Tag()),
Greg Clayton1fba87112012-02-09 20:03:49 +00005407 die->GetName(this, dwarf_cu));
5408
5409#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5410 scoped_die_logger.Push (dwarf_cu, die);
Greg Clayton5160ce52013-03-27 23:08:40 +00005411 g_die_stack.LogDIEs(log, this);
Greg Clayton1fba87112012-02-09 20:03:49 +00005412#endif
Sean Callanan5b26f272012-02-04 08:49:35 +00005413 }
Greg Clayton3bffb082011-12-10 02:15:28 +00005414//
Greg Clayton5160ce52013-03-27 23:08:40 +00005415// Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005416// if (log && dwarf_cu)
5417// {
5418// StreamString s;
5419// die->DumpLocation (this, dwarf_cu, s);
Greg Clayton5160ce52013-03-27 23:08:40 +00005420// GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Greg Clayton3bffb082011-12-10 02:15:28 +00005421//
5422// }
Jim Ingham16746d12011-08-25 23:21:43 +00005423
Greg Clayton594e5ed2010-09-27 21:07:38 +00005424 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005425 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00005426 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005427 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005428 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00005429 if (type_is_new_ptr)
5430 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005431
Greg Clayton594e5ed2010-09-27 21:07:38 +00005432 const dw_tag_t tag = die->Tag();
5433
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005434 bool is_forward_declaration = false;
5435 DWARFDebugInfoEntry::Attributes attributes;
5436 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00005437 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00005438 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
Greg Claytonfaac1112013-03-14 18:31:44 +00005439 uint64_t byte_size = 0;
Greg Clayton526e5af2010-11-13 03:52:47 +00005440 Declaration decl;
5441
Greg Clayton4957bf62010-09-30 21:49:03 +00005442 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton1be10fc2010-09-29 01:12:09 +00005443 clang_type_t clang_type = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005444
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005445 dw_attr_t attr;
5446
5447 switch (tag)
5448 {
5449 case DW_TAG_base_type:
5450 case DW_TAG_pointer_type:
5451 case DW_TAG_reference_type:
Sean Callanance8af862012-05-21 23:31:51 +00005452 case DW_TAG_rvalue_reference_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005453 case DW_TAG_typedef:
5454 case DW_TAG_const_type:
5455 case DW_TAG_restrict_type:
5456 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00005457 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005458 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005459 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005460 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005461
Greg Claytond88d7592010-09-15 08:33:30 +00005462 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005463 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005464 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
5465
5466 if (num_attributes > 0)
5467 {
5468 uint32_t i;
5469 for (i=0; i<num_attributes; ++i)
5470 {
5471 attr = attributes.AttributeAtIndex(i);
5472 DWARFFormValue form_value;
5473 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5474 {
5475 switch (attr)
5476 {
5477 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5478 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5479 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5480 case DW_AT_name:
Jim Ingham337030f2011-04-15 23:41:23 +00005481
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005482 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00005483 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
5484 // include the "&"...
5485 if (tag == DW_TAG_reference_type)
5486 {
5487 if (strchr (type_name_cstr, '&') == NULL)
5488 type_name_cstr = NULL;
5489 }
5490 if (type_name_cstr)
5491 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005492 break;
Greg Clayton23f59502012-07-17 03:23:13 +00005493 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005494 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
5495 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
5496 default:
5497 case DW_AT_sibling:
5498 break;
5499 }
5500 }
5501 }
5502 }
5503
Daniel Malead01b2952012-11-29 21:49:15 +00005504 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 +00005505
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005506 switch (tag)
5507 {
5508 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00005509 break;
5510
Greg Claytond4436412011-10-28 21:00:00 +00005511 case DW_TAG_unspecified_type:
5512 if (strcmp(type_name_cstr, "nullptr_t") == 0)
5513 {
5514 resolve_state = Type::eResolveStateFull;
5515 clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr();
5516 break;
5517 }
5518 // Fall through to base type below in case we can handle the type there...
5519
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005520 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00005521 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005522 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
5523 encoding,
5524 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005525 break;
5526
Sean Callanance8af862012-05-21 23:31:51 +00005527 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
5528 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
5529 case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break;
5530 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
5531 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
5532 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
5533 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005534 }
5535
Sean Callanan82587052013-01-03 00:05:56 +00005536 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 +00005537 {
Sean Callanan82587052013-01-03 00:05:56 +00005538 bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus);
5539
5540 if (translation_unit_is_objc)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005541 {
Sean Callanan82587052013-01-03 00:05:56 +00005542 if (type_name_cstr != NULL)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005543 {
Sean Callanan82587052013-01-03 00:05:56 +00005544 static ConstString g_objc_type_name_id("id");
5545 static ConstString g_objc_type_name_Class("Class");
5546 static ConstString g_objc_type_name_selector("SEL");
5547
5548 if (type_name_const_str == g_objc_type_name_id)
5549 {
5550 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005551 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 +00005552 die->GetOffset(),
5553 DW_TAG_value_to_name(die->Tag()),
5554 die->GetName(this, dwarf_cu));
5555 clang_type = ast.GetBuiltInType_objc_id();
5556 encoding_data_type = Type::eEncodingIsUID;
5557 encoding_uid = LLDB_INVALID_UID;
5558 resolve_state = Type::eResolveStateFull;
Greg Clayton526e5af2010-11-13 03:52:47 +00005559
Sean Callanan82587052013-01-03 00:05:56 +00005560 }
5561 else if (type_name_const_str == g_objc_type_name_Class)
5562 {
5563 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005564 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 +00005565 die->GetOffset(),
5566 DW_TAG_value_to_name(die->Tag()),
5567 die->GetName(this, dwarf_cu));
5568 clang_type = ast.GetBuiltInType_objc_Class();
5569 encoding_data_type = Type::eEncodingIsUID;
5570 encoding_uid = LLDB_INVALID_UID;
5571 resolve_state = Type::eResolveStateFull;
5572 }
5573 else if (type_name_const_str == g_objc_type_name_selector)
5574 {
5575 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005576 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 +00005577 die->GetOffset(),
5578 DW_TAG_value_to_name(die->Tag()),
5579 die->GetName(this, dwarf_cu));
5580 clang_type = ast.GetBuiltInType_objc_selector();
5581 encoding_data_type = Type::eEncodingIsUID;
5582 encoding_uid = LLDB_INVALID_UID;
5583 resolve_state = Type::eResolveStateFull;
5584 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005585 }
Sean Callanan82587052013-01-03 00:05:56 +00005586 else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005587 {
Sean Callanan82587052013-01-03 00:05:56 +00005588 // Clang sometimes erroneously emits id as objc_object*. In that case we fix up the type to "id".
5589
5590 DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid);
5591
5592 if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type)
5593 {
5594 if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL))
5595 {
5596 if (!strcmp(struct_name, "objc_object"))
5597 {
5598 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005599 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 +00005600 die->GetOffset(),
5601 DW_TAG_value_to_name(die->Tag()),
5602 die->GetName(this, dwarf_cu));
5603 clang_type = ast.GetBuiltInType_objc_id();
5604 encoding_data_type = Type::eEncodingIsUID;
5605 encoding_uid = LLDB_INVALID_UID;
5606 resolve_state = Type::eResolveStateFull;
5607 }
5608 }
5609 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005610 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005611 }
5612 }
5613
Greg Clayton81c22f62011-10-19 18:09:39 +00005614 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005615 this,
5616 type_name_const_str,
5617 byte_size,
5618 NULL,
5619 encoding_uid,
5620 encoding_data_type,
5621 &decl,
5622 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005623 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005624
Greg Clayton594e5ed2010-09-27 21:07:38 +00005625 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005626
5627// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
5628// if (encoding_type != NULL)
5629// {
5630// if (encoding_type != DIE_IS_BEING_PARSED)
5631// type_sp->SetEncodingType(encoding_type);
5632// else
5633// m_indirect_fixups.push_back(type_sp.get());
5634// }
5635 }
5636 break;
5637
5638 case DW_TAG_structure_type:
5639 case DW_TAG_union_type:
5640 case DW_TAG_class_type:
5641 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005642 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005643 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Greg Clayton23f59502012-07-17 03:23:13 +00005644 bool byte_size_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005645
Greg Clayton9e409562010-07-28 02:04:09 +00005646 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00005647 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005648 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00005649 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005650 if (num_attributes > 0)
5651 {
5652 uint32_t i;
5653 for (i=0; i<num_attributes; ++i)
5654 {
5655 attr = attributes.AttributeAtIndex(i);
5656 DWARFFormValue form_value;
5657 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5658 {
5659 switch (attr)
5660 {
Greg Clayton9e409562010-07-28 02:04:09 +00005661 case DW_AT_decl_file:
Greg Claytonc7f03b62012-01-12 04:33:28 +00005662 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
5663 {
5664 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
5665 // point to the compile unit file, so we clear this invalid value
5666 // so that we can still unique types efficiently.
5667 decl.SetFile(FileSpec ("<invalid>", false));
5668 }
5669 else
5670 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
Greg Clayton9e409562010-07-28 02:04:09 +00005671 break;
5672
5673 case DW_AT_decl_line:
5674 decl.SetLine(form_value.Unsigned());
5675 break;
5676
5677 case DW_AT_decl_column:
5678 decl.SetColumn(form_value.Unsigned());
5679 break;
5680
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005681 case DW_AT_name:
5682 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005683 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005684 break;
Greg Clayton9e409562010-07-28 02:04:09 +00005685
5686 case DW_AT_byte_size:
5687 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00005688 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00005689 break;
5690
5691 case DW_AT_accessibility:
5692 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
5693 break;
5694
5695 case DW_AT_declaration:
Greg Clayton1c8ef472013-04-05 23:27:21 +00005696 is_forward_declaration = form_value.Boolean();
Greg Clayton9e409562010-07-28 02:04:09 +00005697 break;
5698
5699 case DW_AT_APPLE_runtime_class:
5700 class_language = (LanguageType)form_value.Signed();
5701 break;
5702
Greg Clayton18774842011-11-29 23:40:34 +00005703 case DW_AT_APPLE_objc_complete_type:
5704 is_complete_objc_class = form_value.Signed();
5705 break;
5706
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005707 case DW_AT_allocated:
5708 case DW_AT_associated:
5709 case DW_AT_data_location:
5710 case DW_AT_description:
5711 case DW_AT_start_scope:
5712 case DW_AT_visibility:
5713 default:
5714 case DW_AT_sibling:
5715 break;
5716 }
5717 }
5718 }
5719 }
5720
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005721 UniqueDWARFASTType unique_ast_entry;
Sean Callanan8e8072d2012-02-07 21:13:38 +00005722
Greg Clayton123edca2012-03-02 00:07:15 +00005723 // Only try and unique the type if it has a name.
5724 if (type_name_const_str &&
5725 GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Sean Callanan8e8072d2012-02-07 21:13:38 +00005726 this,
5727 dwarf_cu,
5728 die,
5729 decl,
5730 byte_size_valid ? byte_size : -1,
5731 unique_ast_entry))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005732 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005733 // We have already parsed this type or from another
5734 // compile unit. GCC loves to use the "one definition
5735 // rule" which can result in multiple definitions
5736 // of the same class over and over in each compile
5737 // unit.
5738 type_sp = unique_ast_entry.m_type_sp;
5739 if (type_sp)
Greg Claytonc615ce42010-11-09 04:42:43 +00005740 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005741 m_die_to_type[die] = type_sp.get();
5742 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005743 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005744 }
5745
Daniel Malead01b2952012-11-29 21:49:15 +00005746 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 +00005747
5748 int tag_decl_kind = -1;
5749 AccessType default_accessibility = eAccessNone;
5750 if (tag == DW_TAG_structure_type)
5751 {
5752 tag_decl_kind = clang::TTK_Struct;
5753 default_accessibility = eAccessPublic;
5754 }
5755 else if (tag == DW_TAG_union_type)
5756 {
5757 tag_decl_kind = clang::TTK_Union;
5758 default_accessibility = eAccessPublic;
5759 }
5760 else if (tag == DW_TAG_class_type)
5761 {
5762 tag_decl_kind = clang::TTK_Class;
5763 default_accessibility = eAccessPrivate;
5764 }
Greg Clayton3a5f29a2011-11-30 02:48:28 +00005765
5766 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
5767 die->HasChildren() == false &&
5768 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
5769 {
5770 // Work around an issue with clang at the moment where
5771 // forward declarations for objective C classes are emitted
5772 // as:
5773 // DW_TAG_structure_type [2]
5774 // DW_AT_name( "ForwardObjcClass" )
5775 // DW_AT_byte_size( 0x00 )
5776 // DW_AT_decl_file( "..." )
5777 // DW_AT_decl_line( 1 )
5778 //
5779 // Note that there is no DW_AT_declaration and there are
5780 // no children, and the byte size is zero.
5781 is_forward_declaration = true;
5782 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005783
Sean Callanan7457f8d2012-04-25 01:03:57 +00005784 if (class_language == eLanguageTypeObjC ||
5785 class_language == eLanguageTypeObjC_plus_plus)
Greg Clayton18774842011-11-29 23:40:34 +00005786 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005787 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
Greg Clayton901c5ca2011-12-03 04:40:03 +00005788 {
5789 // We have a valid eSymbolTypeObjCClass class symbol whose
5790 // name matches the current objective C class that we
5791 // are trying to find and this DIE isn't the complete
5792 // definition (we checked is_complete_objc_class above and
5793 // know it is false), so the real definition is in here somewhere
Greg Claytonc7f03b62012-01-12 04:33:28 +00005794 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005795
Greg Clayton1f746072012-08-29 21:13:06 +00005796 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton901c5ca2011-12-03 04:40:03 +00005797 {
5798 // We weren't able to find a full declaration in
5799 // this DWARF, see if we have a declaration anywhere
5800 // else...
Greg Claytonc7f03b62012-01-12 04:33:28 +00005801 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00005802 }
5803
5804 if (type_sp)
5805 {
5806 if (log)
5807 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005808 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00005809 "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 +00005810 this,
5811 die->GetOffset(),
5812 DW_TAG_value_to_name(tag),
5813 type_name_cstr,
5814 type_sp->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00005815 }
5816
5817 // We found a real definition for this type elsewhere
5818 // so lets use it and cache the fact that we found
5819 // a complete type for this die
5820 m_die_to_type[die] = type_sp.get();
5821 return type_sp;
5822 }
5823 }
5824 }
5825
5826
5827 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005828 {
5829 // We have a forward declaration to a type and we need
5830 // to try and find a full declaration. We look in the
5831 // current type index just in case we have a forward
5832 // declaration followed by an actual declarations in the
5833 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00005834 if (log)
5835 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005836 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00005837 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
5838 this,
5839 die->GetOffset(),
5840 DW_TAG_value_to_name(tag),
5841 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00005842 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005843
Greg Claytona8022fa2012-04-24 21:22:41 +00005844 DWARFDeclContext die_decl_ctx;
5845 die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx);
5846
5847 //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
5848 type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005849
Greg Clayton1f746072012-08-29 21:13:06 +00005850 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton4272cc72011-02-02 02:24:04 +00005851 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005852 // We weren't able to find a full declaration in
5853 // this DWARF, see if we have a declaration anywhere
5854 // else...
Greg Claytona8022fa2012-04-24 21:22:41 +00005855 type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton4272cc72011-02-02 02:24:04 +00005856 }
5857
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005858 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00005859 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00005860 if (log)
5861 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005862 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00005863 "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 +00005864 this,
5865 die->GetOffset(),
5866 DW_TAG_value_to_name(tag),
5867 type_name_cstr,
5868 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00005869 }
5870
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005871 // We found a real definition for this type elsewhere
5872 // so lets use it and cache the fact that we found
5873 // a complete type for this die
5874 m_die_to_type[die] = type_sp.get();
5875 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005876 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005877 }
5878 assert (tag_decl_kind != -1);
5879 bool clang_type_was_created = false;
5880 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
5881 if (clang_type == NULL)
5882 {
Sean Callanan4d04c6a2012-02-09 22:54:11 +00005883 const DWARFDebugInfoEntry *decl_ctx_die;
5884
5885 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton55561e92011-10-26 03:31:36 +00005886 if (accessibility == eAccessNone && decl_ctx)
5887 {
5888 // Check the decl context that contains this class/struct/union.
5889 // If it is a class we must give it an accessability.
5890 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
5891 if (DeclKindIsCXXClass (containing_decl_kind))
5892 accessibility = default_accessibility;
5893 }
5894
Greg Claytonc4ffd662013-03-08 01:37:30 +00005895 ClangASTMetadata metadata;
5896 metadata.SetUserID(MakeUserID(die->GetOffset()));
5897 metadata.SetIsDynamicCXXType(ClassOrStructIsVirtual (dwarf_cu, die));
5898
Greg Claytonf0705c82011-10-22 03:33:13 +00005899 if (type_name_cstr && strchr (type_name_cstr, '<'))
5900 {
5901 ClangASTContext::TemplateParameterInfos template_param_infos;
5902 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
5903 {
5904 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00005905 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00005906 type_name_cstr,
5907 tag_decl_kind,
5908 template_param_infos);
5909
5910 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
5911 class_template_decl,
5912 tag_decl_kind,
5913 template_param_infos);
5914 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
5915 clang_type_was_created = true;
Sean Callanan60217122012-04-13 00:10:03 +00005916
Greg Claytond0029442013-03-27 01:48:02 +00005917 GetClangASTContext().SetMetadata (class_template_decl, metadata);
5918 GetClangASTContext().SetMetadata (class_specialization_decl, metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00005919 }
5920 }
5921
5922 if (!clang_type_was_created)
5923 {
5924 clang_type_was_created = true;
Greg Clayton55561e92011-10-26 03:31:36 +00005925 clang_type = ast.CreateRecordType (decl_ctx,
5926 accessibility,
5927 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00005928 tag_decl_kind,
Sean Callanan60217122012-04-13 00:10:03 +00005929 class_language,
Jim Ingham379397632012-10-27 02:54:13 +00005930 &metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00005931 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005932 }
5933
5934 // Store a forward declaration to this class type in case any
5935 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00005936 // types for function prototypes.
5937 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00005938 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005939 this,
5940 type_name_const_str,
5941 byte_size,
5942 NULL,
5943 LLDB_INVALID_UID,
5944 Type::eEncodingIsUID,
5945 &decl,
5946 clang_type,
5947 Type::eResolveStateForward));
Sean Callanan72772842012-02-22 23:57:45 +00005948
5949 type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005950
5951
5952 // Add our type to the unique type map so we don't
5953 // end up creating many copies of the same type over
5954 // and over in the ASTContext for our module
5955 unique_ast_entry.m_type_sp = type_sp;
Greg Clayton36909642011-03-15 04:38:20 +00005956 unique_ast_entry.m_symfile = this;
5957 unique_ast_entry.m_cu = dwarf_cu;
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005958 unique_ast_entry.m_die = die;
5959 unique_ast_entry.m_declaration = decl;
Sean Callanan59700592012-02-13 22:30:16 +00005960 unique_ast_entry.m_byte_size = byte_size;
Greg Claytone576ab22011-02-15 00:19:15 +00005961 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
5962 unique_ast_entry);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005963
Sean Callanan12014a02011-12-08 23:45:45 +00005964 if (!is_forward_declaration)
Greg Clayton219cf312012-03-30 00:51:13 +00005965 {
5966 // Always start the definition for a class type so that
5967 // if the class has child classes or types that require
5968 // the class to be created for use as their decl contexts
5969 // the class will be ready to accept these child definitions.
Sean Callanan12014a02011-12-08 23:45:45 +00005970 if (die->HasChildren() == false)
5971 {
5972 // No children for this struct/union/class, lets finish it
5973 ast.StartTagDeclarationDefinition (clang_type);
5974 ast.CompleteTagDeclarationDefinition (clang_type);
Sean Callanan433cd222012-10-19 01:37:25 +00005975
5976 if (tag == DW_TAG_structure_type) // this only applies in C
5977 {
5978 clang::QualType qual_type = clang::QualType::getFromOpaquePtr (clang_type);
5979 const clang::RecordType *record_type = qual_type->getAs<clang::RecordType> ();
5980
5981 if (record_type)
5982 {
5983 clang::RecordDecl *record_decl = record_type->getDecl();
5984
5985 if (record_decl)
5986 {
5987 LayoutInfo layout_info;
5988
5989 layout_info.alignment = 0;
5990 layout_info.bit_size = 0;
5991
5992 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
5993 }
5994 }
5995 }
Sean Callanan12014a02011-12-08 23:45:45 +00005996 }
5997 else if (clang_type_was_created)
5998 {
Greg Clayton219cf312012-03-30 00:51:13 +00005999 // Start the definition if the class is not objective C since
6000 // the underlying decls respond to isCompleteDefinition(). Objective
6001 // C decls dont' respond to isCompleteDefinition() so we can't
6002 // start the declaration definition right away. For C++ classs/union/structs
6003 // we want to start the definition in case the class is needed as the
6004 // declaration context for a contained class or type without the need
6005 // to complete that type..
6006
Sean Callanan7457f8d2012-04-25 01:03:57 +00006007 if (class_language != eLanguageTypeObjC &&
6008 class_language != eLanguageTypeObjC_plus_plus)
Greg Clayton219cf312012-03-30 00:51:13 +00006009 ast.StartTagDeclarationDefinition (clang_type);
6010
Sean Callanan12014a02011-12-08 23:45:45 +00006011 // Leave this as a forward declaration until we need
6012 // to know the details of the type. lldb_private::Type
6013 // will automatically call the SymbolFile virtual function
6014 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
6015 // When the definition needs to be defined.
6016 m_forward_decl_die_to_clang_type[die] = clang_type;
6017 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
6018 ClangASTContext::SetHasExternalStorage (clang_type, true);
6019 }
Greg Claytonc615ce42010-11-09 04:42:43 +00006020 }
Greg Claytoncab36a32011-12-08 05:16:30 +00006021
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006022 }
6023 break;
6024
6025 case DW_TAG_enumeration_type:
6026 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006027 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006028 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006029
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006030 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006031
Greg Claytond88d7592010-09-15 08:33:30 +00006032 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006033 if (num_attributes > 0)
6034 {
6035 uint32_t i;
6036
6037 for (i=0; i<num_attributes; ++i)
6038 {
6039 attr = attributes.AttributeAtIndex(i);
6040 DWARFFormValue form_value;
6041 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6042 {
6043 switch (attr)
6044 {
Greg Clayton7a345282010-11-09 23:46:37 +00006045 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6046 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6047 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006048 case DW_AT_name:
6049 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006050 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006051 break;
Greg Clayton7a345282010-11-09 23:46:37 +00006052 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006053 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
6054 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006055 case DW_AT_declaration: break; //is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006056 case DW_AT_allocated:
6057 case DW_AT_associated:
6058 case DW_AT_bit_stride:
6059 case DW_AT_byte_stride:
6060 case DW_AT_data_location:
6061 case DW_AT_description:
6062 case DW_AT_start_scope:
6063 case DW_AT_visibility:
6064 case DW_AT_specification:
6065 case DW_AT_abstract_origin:
6066 case DW_AT_sibling:
6067 break;
6068 }
6069 }
6070 }
6071
Daniel Malead01b2952012-11-29 21:49:15 +00006072 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 +00006073
Greg Clayton1be10fc2010-09-29 01:12:09 +00006074 clang_type_t enumerator_clang_type = NULL;
6075 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
6076 if (clang_type == NULL)
6077 {
Greg Clayton5d14fc02013-03-06 06:23:54 +00006078 if (encoding_uid != DW_INVALID_OFFSET)
6079 {
6080 Type *enumerator_type = ResolveTypeUID(encoding_uid);
6081 if (enumerator_type)
6082 enumerator_clang_type = enumerator_type->GetClangFullType();
6083 }
6084
6085 if (enumerator_clang_type == NULL)
6086 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
6087 DW_ATE_signed,
6088 byte_size * 8);
6089
Greg Claytonca512b32011-01-14 04:54:56 +00006090 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00006091 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00006092 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006093 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00006094 }
6095 else
6096 {
6097 enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00006098 }
6099
Greg Claytona2721472011-06-25 00:44:06 +00006100 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
6101
Greg Clayton81c22f62011-10-19 18:09:39 +00006102 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006103 this,
6104 type_name_const_str,
6105 byte_size,
6106 NULL,
6107 encoding_uid,
6108 Type::eEncodingIsUID,
6109 &decl,
6110 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006111 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006112
Greg Clayton6beaaa62011-01-17 03:46:26 +00006113 ast.StartTagDeclarationDefinition (clang_type);
6114 if (die->HasChildren())
6115 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006116 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00006117 bool is_signed = false;
Greg Clayton5d14fc02013-03-06 06:23:54 +00006118 ast.IsIntegerType(enumerator_clang_type, is_signed);
Greg Clayton3e067532013-03-05 23:54:39 +00006119 ParseChildEnumerators(cu_sc, clang_type, is_signed, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00006120 }
6121 ast.CompleteTagDeclarationDefinition (clang_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006122 }
6123 }
6124 break;
6125
Jim Inghamb0be4422010-08-12 01:20:14 +00006126 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006127 case DW_TAG_subprogram:
6128 case DW_TAG_subroutine_type:
6129 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006130 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006131 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006132
Greg Clayton23f59502012-07-17 03:23:13 +00006133 //const char *mangled = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006134 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00006135 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006136 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00006137 bool is_static = false;
6138 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00006139 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00006140 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00006141 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
6142 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Jim Ingham379397632012-10-27 02:54:13 +00006143 dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00006144
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006145 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00006146 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006147
6148
Greg Claytond88d7592010-09-15 08:33:30 +00006149 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006150 if (num_attributes > 0)
6151 {
6152 uint32_t i;
6153 for (i=0; i<num_attributes; ++i)
6154 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006155 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006156 DWARFFormValue form_value;
6157 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6158 {
6159 switch (attr)
6160 {
6161 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6162 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6163 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6164 case DW_AT_name:
6165 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006166 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006167 break;
6168
Greg Clayton71415542012-12-08 00:24:40 +00006169 case DW_AT_linkage_name:
Greg Clayton23f59502012-07-17 03:23:13 +00006170 case DW_AT_MIPS_linkage_name: break; // mangled = form_value.AsCString(&get_debug_str_data()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006171 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00006172 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006173 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
6174 case DW_AT_inline: is_inline = form_value.Boolean(); break;
6175 case DW_AT_virtuality: is_virtual = form_value.Boolean(); break;
6176 case DW_AT_explicit: is_explicit = form_value.Boolean(); break;
6177 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Sean Callanandbb58392011-11-02 01:38:59 +00006178
Greg Claytonf51de672010-10-01 02:31:07 +00006179
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006180 case DW_AT_external:
6181 if (form_value.Unsigned())
6182 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00006183 if (storage == clang::SC_None)
6184 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006185 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00006186 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006187 }
6188 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006189
Greg Clayton72da3972011-08-16 18:40:23 +00006190 case DW_AT_specification:
6191 specification_die_offset = form_value.Reference(dwarf_cu);
6192 break;
6193
6194 case DW_AT_abstract_origin:
6195 abstract_origin_die_offset = form_value.Reference(dwarf_cu);
6196 break;
6197
Jim Ingham379397632012-10-27 02:54:13 +00006198 case DW_AT_object_pointer:
6199 object_pointer_die_offset = form_value.Reference(dwarf_cu);
6200 break;
6201
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006202 case DW_AT_allocated:
6203 case DW_AT_associated:
6204 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006205 case DW_AT_calling_convention:
6206 case DW_AT_data_location:
6207 case DW_AT_elemental:
6208 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006209 case DW_AT_frame_base:
6210 case DW_AT_high_pc:
6211 case DW_AT_low_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006212 case DW_AT_prototyped:
6213 case DW_AT_pure:
6214 case DW_AT_ranges:
6215 case DW_AT_recursive:
6216 case DW_AT_return_addr:
6217 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006218 case DW_AT_start_scope:
6219 case DW_AT_static_link:
6220 case DW_AT_trampoline:
6221 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006222 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006223 case DW_AT_description:
6224 case DW_AT_sibling:
6225 break;
6226 }
6227 }
6228 }
Greg Clayton24739922010-10-13 03:15:28 +00006229 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006230
Jim Ingham379397632012-10-27 02:54:13 +00006231 std::string object_pointer_name;
6232 if (object_pointer_die_offset != DW_INVALID_OFFSET)
6233 {
6234 // Get the name from the object pointer die
6235 StreamString s;
6236 if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s))
6237 {
6238 object_pointer_name.assign(s.GetData());
6239 }
6240 }
6241
Daniel Malead01b2952012-11-29 21:49:15 +00006242 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 +00006243
Greg Clayton24739922010-10-13 03:15:28 +00006244 clang_type_t return_clang_type = NULL;
6245 Type *func_type = NULL;
6246
6247 if (type_die_offset != DW_INVALID_OFFSET)
6248 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00006249
Greg Clayton24739922010-10-13 03:15:28 +00006250 if (func_type)
Greg Clayton42ce2f32011-12-12 21:50:19 +00006251 return_clang_type = func_type->GetClangForwardType();
Greg Clayton24739922010-10-13 03:15:28 +00006252 else
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006253 return_clang_type = ast.GetBuiltInType_void();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006254
Greg Claytonf51de672010-10-01 02:31:07 +00006255
Greg Clayton24739922010-10-13 03:15:28 +00006256 std::vector<clang_type_t> function_param_types;
6257 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006258
Greg Clayton24739922010-10-13 03:15:28 +00006259 // Parse the function children for the parameters
Sean Callanan763d72a2011-08-02 22:21:50 +00006260
Greg Claytoncb5860a2011-10-13 23:49:28 +00006261 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
6262 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00006263 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
6264
Greg Claytonf0705c82011-10-22 03:33:13 +00006265 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00006266 // Start off static. This will be set to false in ParseChildParameters(...)
6267 // if we find a "this" paramters as the first parameter
6268 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00006269 is_static = true;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006270 ClangASTContext::TemplateParameterInfos template_param_infos;
6271
Greg Clayton24739922010-10-13 03:15:28 +00006272 if (die->HasChildren())
6273 {
Greg Clayton0fffff52010-09-24 05:15:53 +00006274 bool skip_artificial = true;
Jim Ingham379397632012-10-27 02:54:13 +00006275 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00006276 containing_decl_ctx,
Jim Ingham379397632012-10-27 02:54:13 +00006277 dwarf_cu,
6278 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00006279 skip_artificial,
6280 is_static,
Jim Ingham379397632012-10-27 02:54:13 +00006281 type_list,
6282 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00006283 function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006284 type_quals,
6285 template_param_infos);
Greg Clayton24739922010-10-13 03:15:28 +00006286 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006287
Greg Clayton24739922010-10-13 03:15:28 +00006288 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006289 clang_type = ast.CreateFunctionType (return_clang_type,
Greg Clayton9cb25c42012-10-30 17:02:18 +00006290 function_param_types.data(),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006291 function_param_types.size(),
6292 is_variadic,
6293 type_quals);
6294
Greg Clayton24739922010-10-13 03:15:28 +00006295 if (type_name_cstr)
6296 {
6297 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00006298 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006299 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00006300 ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true);
6301 if (objc_method.IsValid(true))
Greg Clayton0fffff52010-09-24 05:15:53 +00006302 {
Greg Clayton24739922010-10-13 03:15:28 +00006303 SymbolContext empty_sc;
6304 clang_type_t class_opaque_type = NULL;
Greg Clayton1b3815c2013-01-30 00:18:29 +00006305 ConstString class_name(objc_method.GetClassName());
Greg Clayton7c810422012-01-18 23:40:49 +00006306 if (class_name)
Greg Clayton0fffff52010-09-24 05:15:53 +00006307 {
Greg Clayton24739922010-10-13 03:15:28 +00006308 TypeList types;
Greg Clayton278a16b2012-01-19 00:52:59 +00006309 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
Greg Claytonc7f03b62012-01-12 04:33:28 +00006310
6311 if (complete_objc_class_type_sp)
Greg Clayton0fffff52010-09-24 05:15:53 +00006312 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00006313 clang_type_t type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
6314 if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
6315 class_opaque_type = type_clang_forward_type;
Greg Clayton0fffff52010-09-24 05:15:53 +00006316 }
Greg Clayton24739922010-10-13 03:15:28 +00006317 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006318
Greg Clayton24739922010-10-13 03:15:28 +00006319 if (class_opaque_type)
6320 {
6321 // If accessibility isn't set to anything valid, assume public for
6322 // now...
6323 if (accessibility == eAccessNone)
6324 accessibility = eAccessPublic;
6325
Sean Callanan464a5b52012-10-04 22:06:29 +00006326 clang::ObjCMethodDecl *objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
6327 type_name_cstr,
6328 clang_type,
Greg Clayton1bbcc032013-03-08 02:42:06 +00006329 accessibility,
6330 is_artificial);
Greg Clayton24739922010-10-13 03:15:28 +00006331 type_handled = objc_method_decl != NULL;
Sean Callanan464a5b52012-10-04 22:06:29 +00006332 if (type_handled)
6333 {
6334 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Claytond0029442013-03-27 01:48:02 +00006335 GetClangASTContext().SetMetadataAsUserID (objc_method_decl, MakeUserID(die->GetOffset()));
Sean Callanan464a5b52012-10-04 22:06:29 +00006336 }
Sean Callananc3a1d562013-02-06 23:21:59 +00006337 else
6338 {
Jason Molendac1a65832013-03-07 22:44:42 +00006339 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 +00006340 die->GetOffset(),
6341 tag,
6342 DW_TAG_value_to_name(tag));
6343 }
Greg Clayton24739922010-10-13 03:15:28 +00006344 }
6345 }
Greg Clayton5113dc82011-08-12 06:47:54 +00006346 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00006347 {
6348 // Look at the parent of this DIE and see if is is
6349 // a class or struct and see if this is actually a
6350 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00006351 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00006352 if (class_type)
6353 {
Greg Clayton4116e932012-05-15 02:33:01 +00006354 if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset()))
6355 {
6356 // We uniqued the parent class of this function to another class
6357 // so we now need to associate all dies under "decl_ctx_die" to
6358 // DIEs in the DIE for "class_type"...
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006359 SymbolFileDWARF *class_symfile = NULL;
Greg Clayton4116e932012-05-15 02:33:01 +00006360 DWARFCompileUnitSP class_type_cu_sp;
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006361 const DWARFDebugInfoEntry *class_type_die = NULL;
Sean Callanan2367f8a2013-02-26 01:12:25 +00006362
6363 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
6364 if (debug_map_symfile)
6365 {
6366 class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID()));
6367 class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6368 }
6369 else
6370 {
6371 class_symfile = this;
6372 class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6373 }
Greg Clayton4116e932012-05-15 02:33:01 +00006374 if (class_type_die)
6375 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006376 llvm::SmallVector<const DWARFDebugInfoEntry *, 0> failures;
6377
6378 CopyUniqueClassMethodTypes (class_symfile,
6379 class_type,
6380 class_type_cu_sp.get(),
6381 class_type_die,
6382 dwarf_cu,
6383 decl_ctx_die,
6384 failures);
6385
6386 // FIXME do something with these failures that's smarter than
6387 // just dropping them on the ground. Unfortunately classes don't
6388 // like having stuff added to them after their definitions are
6389 // complete...
6390
6391 type_ptr = m_die_to_type[die];
6392 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton4116e932012-05-15 02:33:01 +00006393 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006394 type_sp = type_ptr->shared_from_this();
6395 break;
Greg Clayton4116e932012-05-15 02:33:01 +00006396 }
6397 }
6398 }
6399
Greg Clayton72da3972011-08-16 18:40:23 +00006400 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00006401 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006402 // We have a specification which we are going to base our function
6403 // prototype off of, so we need this type to be completed so that the
6404 // m_die_to_decl_ctx for the method in the specification has a valid
6405 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006406 class_type->GetClangForwardType();
Greg Clayton72da3972011-08-16 18:40:23 +00006407 // If we have a specification, then the function type should have been
6408 // made with the specification and not with this die.
6409 DWARFCompileUnitSP spec_cu_sp;
6410 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006411 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006412 if (spec_clang_decl_ctx)
6413 {
6414 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
6415 }
6416 else
Jim Inghamc1663042011-09-29 22:12:35 +00006417 {
Daniel Malead01b2952012-11-29 21:49:15 +00006418 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8x) has no decl\n",
Greg Claytone38a5ed2012-01-05 03:57:59 +00006419 MakeUserID(die->GetOffset()),
6420 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006421 }
Greg Clayton72da3972011-08-16 18:40:23 +00006422 type_handled = true;
6423 }
6424 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
6425 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006426 // We have a specification which we are going to base our function
6427 // prototype off of, so we need this type to be completed so that the
6428 // m_die_to_decl_ctx for the method in the abstract origin has a valid
6429 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006430 class_type->GetClangForwardType();
Greg Clayton5cf58b92011-10-05 22:22:08 +00006431
Greg Clayton72da3972011-08-16 18:40:23 +00006432 DWARFCompileUnitSP abs_cu_sp;
6433 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006434 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006435 if (abs_clang_decl_ctx)
6436 {
6437 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
6438 }
6439 else
Jim Inghamc1663042011-09-29 22:12:35 +00006440 {
Daniel Malead01b2952012-11-29 21:49:15 +00006441 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 +00006442 MakeUserID(die->GetOffset()),
6443 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006444 }
Greg Clayton72da3972011-08-16 18:40:23 +00006445 type_handled = true;
6446 }
6447 else
6448 {
6449 clang_type_t class_opaque_type = class_type->GetClangForwardType();
6450 if (ClangASTContext::IsCXXClassType (class_opaque_type))
Greg Clayton931180e2011-01-27 06:44:37 +00006451 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006452 if (ClangASTContext::IsBeingDefined (class_opaque_type))
Greg Clayton72da3972011-08-16 18:40:23 +00006453 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006454 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
6455 // in the DWARF for C++ methods... Default to public for now...
6456 if (accessibility == eAccessNone)
6457 accessibility = eAccessPublic;
6458
6459 if (!is_static && !die->HasChildren())
6460 {
6461 // We have a C++ member function with no children (this pointer!)
6462 // and clang will get mad if we try and make a function that isn't
6463 // well formed in the DWARF, so we will just skip it...
6464 type_handled = true;
6465 }
6466 else
6467 {
6468 clang::CXXMethodDecl *cxx_method_decl;
6469 // REMOVE THE CRASH DESCRIPTION BELOW
Daniel Malead01b2952012-11-29 21:49:15 +00006470 Host::SetCrashDescriptionWithFormat ("SymbolFileDWARF::ParseType() is adding a method %s to class %s in DIE 0x%8.8" PRIx64 " from %s/%s",
Greg Clayton20568dd2011-10-13 23:13:20 +00006471 type_name_cstr,
6472 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00006473 MakeUserID(die->GetOffset()),
Greg Clayton20568dd2011-10-13 23:13:20 +00006474 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
6475 m_obj_file->GetFileSpec().GetFilename().GetCString());
6476
Sean Callananc1b732d2011-11-01 18:07:13 +00006477 const bool is_attr_used = false;
6478
Greg Clayton20568dd2011-10-13 23:13:20 +00006479 cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type,
6480 type_name_cstr,
6481 clang_type,
6482 accessibility,
6483 is_virtual,
6484 is_static,
6485 is_inline,
Sean Callananc1b732d2011-11-01 18:07:13 +00006486 is_explicit,
Sean Callanandbb58392011-11-02 01:38:59 +00006487 is_attr_used,
6488 is_artificial);
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006489
Greg Clayton20568dd2011-10-13 23:13:20 +00006490 type_handled = cxx_method_decl != NULL;
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006491
6492 if (type_handled)
Jim Ingham379397632012-10-27 02:54:13 +00006493 {
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006494 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
6495
6496 Host::SetCrashDescription (NULL);
6497
6498
6499 ClangASTMetadata metadata;
6500 metadata.SetUserID(MakeUserID(die->GetOffset()));
6501
6502 if (!object_pointer_name.empty())
6503 {
6504 metadata.SetObjectPtrName(object_pointer_name.c_str());
6505 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006506 log->Printf ("Setting object pointer name: %s on method object %p.\n",
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006507 object_pointer_name.c_str(),
Greg Claytond0029442013-03-27 01:48:02 +00006508 cxx_method_decl);
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006509 }
Greg Claytond0029442013-03-27 01:48:02 +00006510 GetClangASTContext().SetMetadata (cxx_method_decl, metadata);
Jim Ingham379397632012-10-27 02:54:13 +00006511 }
Sean Callananb0640dc2013-04-09 23:22:08 +00006512 else
6513 {
6514 return TypeSP();
6515 }
Greg Clayton20568dd2011-10-13 23:13:20 +00006516 }
Greg Clayton72da3972011-08-16 18:40:23 +00006517 }
6518 else
6519 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006520 // We were asked to parse the type for a method in a class, yet the
6521 // class hasn't been asked to complete itself through the
6522 // clang::ExternalASTSource protocol, so we need to just have the
6523 // class complete itself and do things the right way, then our
6524 // DIE should then have an entry in the m_die_to_type map. First
6525 // we need to modify the m_die_to_type so it doesn't think we are
6526 // trying to parse this DIE anymore...
6527 m_die_to_type[die] = NULL;
6528
6529 // Now we get the full type to force our class type to complete itself
6530 // using the clang::ExternalASTSource protocol which will parse all
6531 // base classes and all methods (including the method for this DIE).
6532 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00006533
Greg Clayton20568dd2011-10-13 23:13:20 +00006534 // The type for this DIE should have been filled in the function call above
6535 type_ptr = m_die_to_type[die];
Greg Claytone5476db2012-06-01 20:32:35 +00006536 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton20568dd2011-10-13 23:13:20 +00006537 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006538 type_sp = type_ptr->shared_from_this();
Greg Clayton20568dd2011-10-13 23:13:20 +00006539 break;
6540 }
Sean Callanan02eee4d2012-04-12 23:10:00 +00006541
6542 // FIXME This is fixing some even uglier behavior but we really need to
6543 // uniq the methods of each class as well as the class itself.
6544 // <rdar://problem/11240464>
6545 type_handled = true;
Greg Clayton72da3972011-08-16 18:40:23 +00006546 }
Greg Clayton931180e2011-01-27 06:44:37 +00006547 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006548 }
6549 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006550 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006551 }
Greg Clayton24739922010-10-13 03:15:28 +00006552
6553 if (!type_handled)
6554 {
6555 // We just have a function that isn't part of a class
Greg Clayton147e1fa2011-10-14 22:47:18 +00006556 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (containing_decl_ctx,
6557 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006558 clang_type,
6559 storage,
6560 is_inline);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006561
6562// if (template_param_infos.GetSize() > 0)
6563// {
6564// clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
6565// function_decl,
6566// type_name_cstr,
6567// template_param_infos);
6568//
6569// ast.CreateFunctionTemplateSpecializationInfo (function_decl,
6570// func_template_decl,
6571// template_param_infos);
6572// }
Greg Clayton24739922010-10-13 03:15:28 +00006573 // Add the decl to our DIE to decl context map
6574 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00006575 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00006576 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006577 ast.SetFunctionParameters (function_decl,
6578 &function_param_decls.front(),
6579 function_param_decls.size());
Sean Callanan60217122012-04-13 00:10:03 +00006580
Jim Ingham379397632012-10-27 02:54:13 +00006581 ClangASTMetadata metadata;
6582 metadata.SetUserID(MakeUserID(die->GetOffset()));
6583
6584 if (!object_pointer_name.empty())
6585 {
6586 metadata.SetObjectPtrName(object_pointer_name.c_str());
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006587 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006588 log->Printf ("Setting object pointer name: %s on function object %p.",
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006589 object_pointer_name.c_str(),
Greg Claytond0029442013-03-27 01:48:02 +00006590 function_decl);
Jim Ingham379397632012-10-27 02:54:13 +00006591 }
Greg Claytond0029442013-03-27 01:48:02 +00006592 GetClangASTContext().SetMetadata (function_decl, metadata);
Greg Clayton24739922010-10-13 03:15:28 +00006593 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006594 }
Greg Clayton81c22f62011-10-19 18:09:39 +00006595 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006596 this,
6597 type_name_const_str,
6598 0,
6599 NULL,
6600 LLDB_INVALID_UID,
6601 Type::eEncodingIsUID,
6602 &decl,
6603 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006604 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00006605 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006606 }
6607 break;
6608
6609 case DW_TAG_array_type:
6610 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006611 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006612 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006613
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006614 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006615 int64_t first_index = 0;
6616 uint32_t byte_stride = 0;
6617 uint32_t bit_stride = 0;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006618 bool is_vector = false;
Greg Claytond88d7592010-09-15 08:33:30 +00006619 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006620
6621 if (num_attributes > 0)
6622 {
6623 uint32_t i;
6624 for (i=0; i<num_attributes; ++i)
6625 {
6626 attr = attributes.AttributeAtIndex(i);
6627 DWARFFormValue form_value;
6628 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6629 {
6630 switch (attr)
6631 {
6632 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6633 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6634 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6635 case DW_AT_name:
6636 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006637 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006638 break;
6639
6640 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006641 case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006642 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
6643 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006644 case DW_AT_GNU_vector: is_vector = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006645 case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00006646 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006647 case DW_AT_allocated:
6648 case DW_AT_associated:
6649 case DW_AT_data_location:
6650 case DW_AT_description:
6651 case DW_AT_ordering:
6652 case DW_AT_start_scope:
6653 case DW_AT_visibility:
6654 case DW_AT_specification:
6655 case DW_AT_abstract_origin:
6656 case DW_AT_sibling:
6657 break;
6658 }
6659 }
6660 }
6661
Daniel Malead01b2952012-11-29 21:49:15 +00006662 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 +00006663
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006664 Type *element_type = ResolveTypeUID(type_die_offset);
6665
6666 if (element_type)
6667 {
6668 std::vector<uint64_t> element_orders;
6669 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
6670 if (byte_stride == 0 && bit_stride == 0)
6671 byte_stride = element_type->GetByteSize();
Greg Clayton42ce2f32011-12-12 21:50:19 +00006672 clang_type_t array_element_type = element_type->GetClangForwardType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006673 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
6674 uint64_t num_elements = 0;
6675 std::vector<uint64_t>::const_reverse_iterator pos;
6676 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
6677 for (pos = element_orders.rbegin(); pos != end; ++pos)
6678 {
6679 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006680 clang_type = ast.CreateArrayType (array_element_type,
Greg Clayton1c8ef472013-04-05 23:27:21 +00006681 num_elements,
6682 is_vector);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006683 array_element_type = clang_type;
Greg Clayton4ef877f2012-12-06 02:33:54 +00006684 array_element_bit_stride = num_elements ? array_element_bit_stride * num_elements : array_element_bit_stride;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006685 }
6686 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00006687 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006688 this,
6689 empty_name,
6690 array_element_bit_stride / 8,
6691 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00006692 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006693 Type::eEncodingIsUID,
6694 &decl,
6695 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006696 Type::eResolveStateFull));
6697 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006698 }
6699 }
6700 }
6701 break;
6702
Greg Clayton9b81a312010-06-12 01:20:30 +00006703 case DW_TAG_ptr_to_member_type:
6704 {
6705 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
6706 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
6707
Greg Claytond88d7592010-09-15 08:33:30 +00006708 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00006709
6710 if (num_attributes > 0) {
6711 uint32_t i;
6712 for (i=0; i<num_attributes; ++i)
6713 {
6714 attr = attributes.AttributeAtIndex(i);
6715 DWARFFormValue form_value;
6716 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6717 {
6718 switch (attr)
6719 {
6720 case DW_AT_type:
6721 type_die_offset = form_value.Reference(dwarf_cu); break;
6722 case DW_AT_containing_type:
6723 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
6724 }
6725 }
6726 }
6727
6728 Type *pointee_type = ResolveTypeUID(type_die_offset);
6729 Type *class_type = ResolveTypeUID(containing_type_die_offset);
6730
Greg Clayton526e5af2010-11-13 03:52:47 +00006731 clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
6732 clang_type_t class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00006733
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006734 clang_type = ast.CreateMemberPointerType(pointee_clang_type,
6735 class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00006736
Greg Clayton526e5af2010-11-13 03:52:47 +00006737 byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(),
6738 clang_type) / 8;
Greg Clayton9b81a312010-06-12 01:20:30 +00006739
Greg Clayton81c22f62011-10-19 18:09:39 +00006740 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006741 this,
6742 type_name_const_str,
6743 byte_size,
6744 NULL,
6745 LLDB_INVALID_UID,
6746 Type::eEncodingIsUID,
6747 NULL,
6748 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006749 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00006750 }
6751
6752 break;
6753 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006754 default:
Greg Clayton84afacd2012-11-07 23:09:32 +00006755 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",
6756 die->GetOffset(),
6757 tag,
6758 DW_TAG_value_to_name(tag));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006759 break;
6760 }
6761
6762 if (type_sp.get())
6763 {
6764 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
6765 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
6766
6767 SymbolContextScope * symbol_context_scope = NULL;
6768 if (sc_parent_tag == DW_TAG_compile_unit)
6769 {
6770 symbol_context_scope = sc.comp_unit;
6771 }
6772 else if (sc.function != NULL)
6773 {
Greg Clayton81c22f62011-10-19 18:09:39 +00006774 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006775 if (symbol_context_scope == NULL)
6776 symbol_context_scope = sc.function;
6777 }
6778
6779 if (symbol_context_scope != NULL)
6780 {
6781 type_sp->SetSymbolContextScope(symbol_context_scope);
6782 }
6783
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006784 // We are ready to put this type into the uniqued list up at the module level
6785 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00006786
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006787 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006788 }
6789 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00006790 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006791 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006792 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006793 }
6794 }
6795 return type_sp;
6796}
6797
6798size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00006799SymbolFileDWARF::ParseTypes
6800(
6801 const SymbolContext& sc,
6802 DWARFCompileUnit* dwarf_cu,
6803 const DWARFDebugInfoEntry *die,
6804 bool parse_siblings,
6805 bool parse_children
6806)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006807{
6808 size_t types_added = 0;
6809 while (die != NULL)
6810 {
6811 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00006812 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006813 {
6814 if (type_is_new)
6815 ++types_added;
6816 }
6817
6818 if (parse_children && die->HasChildren())
6819 {
6820 if (die->Tag() == DW_TAG_subprogram)
6821 {
6822 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00006823 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006824 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
6825 }
6826 else
6827 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
6828 }
6829
6830 if (parse_siblings)
6831 die = die->GetSibling();
6832 else
6833 die = NULL;
6834 }
6835 return types_added;
6836}
6837
6838
6839size_t
6840SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
6841{
6842 assert(sc.comp_unit && sc.function);
6843 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00006844 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006845 if (dwarf_cu)
6846 {
6847 dw_offset_t function_die_offset = sc.function->GetID();
6848 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
6849 if (function_die)
6850 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00006851 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006852 }
6853 }
6854
6855 return functions_added;
6856}
6857
6858
6859size_t
6860SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
6861{
6862 // At least a compile unit must be valid
6863 assert(sc.comp_unit);
6864 size_t types_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00006865 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006866 if (dwarf_cu)
6867 {
6868 if (sc.function)
6869 {
6870 dw_offset_t function_die_offset = sc.function->GetID();
6871 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
6872 if (func_die && func_die->HasChildren())
6873 {
6874 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
6875 }
6876 }
6877 else
6878 {
6879 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
6880 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
6881 {
6882 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
6883 }
6884 }
6885 }
6886
6887 return types_added;
6888}
6889
6890size_t
6891SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
6892{
6893 if (sc.comp_unit != NULL)
6894 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00006895 DWARFDebugInfo* info = DebugInfo();
6896 if (info == NULL)
6897 return 0;
6898
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006899 if (sc.function)
6900 {
Greg Clayton9422dd62013-03-04 21:46:16 +00006901 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get();
6902
6903 if (dwarf_cu == NULL)
6904 return 0;
6905
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006906 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00006907
Greg Claytonc7bece562013-01-25 18:06:21 +00006908 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
6909 if (func_lo_pc != LLDB_INVALID_ADDRESS)
Greg Claytone38a5ed2012-01-05 03:57:59 +00006910 {
6911 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00006912
Greg Claytone38a5ed2012-01-05 03:57:59 +00006913 // Let all blocks know they have parse all their variables
6914 sc.function->GetBlock (false).SetDidParseVariables (true, true);
6915 return num_variables;
6916 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006917 }
6918 else if (sc.comp_unit)
6919 {
Greg Clayton9422dd62013-03-04 21:46:16 +00006920 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get();
6921
6922 if (dwarf_cu == NULL)
6923 return 0;
6924
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006925 uint32_t vars_added = 0;
6926 VariableListSP variables (sc.comp_unit->GetVariableList(false));
6927
6928 if (variables.get() == NULL)
6929 {
6930 variables.reset(new VariableList());
6931 sc.comp_unit->SetVariableList(variables);
6932
Greg Claytond4a2b372011-09-12 23:21:58 +00006933 DWARFCompileUnit* match_dwarf_cu = NULL;
6934 const DWARFDebugInfoEntry* die = NULL;
6935 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00006936 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00006937 {
Greg Clayton97fbc342011-10-20 22:30:33 +00006938 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00006939 {
6940 DWARFMappedHash::DIEInfoArray hash_data_array;
6941 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
6942 dwarf_cu->GetNextCompileUnitOffset(),
6943 hash_data_array))
6944 {
6945 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
6946 }
6947 }
Greg Clayton7f995132011-10-04 22:41:51 +00006948 }
6949 else
6950 {
6951 // Index if we already haven't to make sure the compile units
6952 // get indexed and make their global DIE index list
6953 if (!m_indexed)
6954 Index ();
6955
6956 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
6957 dwarf_cu->GetNextCompileUnitOffset(),
6958 die_offsets);
6959 }
6960
6961 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00006962 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006963 {
Greg Claytond4a2b372011-09-12 23:21:58 +00006964 DWARFDebugInfo* debug_info = DebugInfo();
6965 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006966 {
Greg Claytond4a2b372011-09-12 23:21:58 +00006967 const dw_offset_t die_offset = die_offsets[i];
6968 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00006969 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00006970 {
Greg Clayton95d87902011-11-11 03:16:25 +00006971 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
6972 if (var_sp)
6973 {
6974 variables->AddVariableIfUnique (var_sp);
6975 ++vars_added;
6976 }
Greg Claytond4a2b372011-09-12 23:21:58 +00006977 }
Greg Clayton95d87902011-11-11 03:16:25 +00006978 else
6979 {
6980 if (m_using_apple_tables)
6981 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00006982 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 +00006983 }
6984 }
6985
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006986 }
6987 }
6988 }
6989 return vars_added;
6990 }
6991 }
6992 return 0;
6993}
6994
6995
6996VariableSP
6997SymbolFileDWARF::ParseVariableDIE
6998(
6999 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007000 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007001 const DWARFDebugInfoEntry *die,
7002 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007003)
7004{
7005
Greg Clayton83c5cd92010-11-14 22:13:40 +00007006 VariableSP var_sp (m_die_to_variable_sp[die]);
7007 if (var_sp)
7008 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007009
7010 const dw_tag_t tag = die->Tag();
Greg Clayton7f995132011-10-04 22:41:51 +00007011
7012 if ((tag == DW_TAG_variable) ||
7013 (tag == DW_TAG_constant) ||
7014 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007015 {
Greg Clayton7f995132011-10-04 22:41:51 +00007016 DWARFDebugInfoEntry::Attributes attributes;
7017 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
7018 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007019 {
Greg Clayton7f995132011-10-04 22:41:51 +00007020 const char *name = NULL;
7021 const char *mangled = NULL;
7022 Declaration decl;
7023 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00007024 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00007025 DWARFExpression location;
7026 bool is_external = false;
7027 bool is_artificial = false;
7028 bool location_is_const_value_data = false;
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007029 bool has_explicit_location = false;
Greg Clayton23f59502012-07-17 03:23:13 +00007030 //AccessType accessibility = eAccessNone;
Greg Clayton7f995132011-10-04 22:41:51 +00007031
7032 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007033 {
Greg Clayton7f995132011-10-04 22:41:51 +00007034 dw_attr_t attr = attributes.AttributeAtIndex(i);
7035 DWARFFormValue form_value;
7036 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007037 {
Greg Clayton7f995132011-10-04 22:41:51 +00007038 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007039 {
Greg Clayton7f995132011-10-04 22:41:51 +00007040 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
7041 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
7042 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
7043 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton71415542012-12-08 00:24:40 +00007044 case DW_AT_linkage_name:
Greg Clayton7f995132011-10-04 22:41:51 +00007045 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Claytond1767f02011-12-08 02:13:16 +00007046 case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00007047 case DW_AT_external: is_external = form_value.Boolean(); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007048 case DW_AT_const_value:
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007049 // If we have already found a DW_AT_location attribute, ignore this attribute.
7050 if (!has_explicit_location)
7051 {
7052 location_is_const_value_data = true;
7053 // The constant value will be either a block, a data value or a string.
7054 const DataExtractor& debug_info_data = get_debug_info_data();
7055 if (DWARFFormValue::IsBlockForm(form_value.Form()))
7056 {
7057 // Retrieve the value as a block expression.
7058 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7059 uint32_t block_length = form_value.Unsigned();
7060 location.CopyOpcodeData(debug_info_data, block_offset, block_length);
7061 }
7062 else if (DWARFFormValue::IsDataForm(form_value.Form()))
7063 {
7064 // Retrieve the value as a data expression.
7065 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
7066 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7067 uint32_t data_length = fixed_form_sizes[form_value.Form()];
7068 location.CopyOpcodeData(debug_info_data, data_offset, data_length);
7069 }
7070 else
7071 {
7072 // Retrieve the value as a string expression.
7073 if (form_value.Form() == DW_FORM_strp)
7074 {
7075 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
7076 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7077 uint32_t data_length = fixed_form_sizes[form_value.Form()];
7078 location.CopyOpcodeData(debug_info_data, data_offset, data_length);
7079 }
7080 else
7081 {
7082 const char *str = form_value.AsCString(&debug_info_data);
7083 uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart();
7084 uint32_t string_length = strlen(str) + 1;
7085 location.CopyOpcodeData(debug_info_data, string_offset, string_length);
7086 }
7087 }
7088 }
7089 break;
Greg Clayton7f995132011-10-04 22:41:51 +00007090 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007091 {
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007092 location_is_const_value_data = false;
7093 has_explicit_location = true;
Greg Clayton7f995132011-10-04 22:41:51 +00007094 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007095 {
Greg Clayton7f995132011-10-04 22:41:51 +00007096 const DataExtractor& debug_info_data = get_debug_info_data();
7097
7098 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7099 uint32_t block_length = form_value.Unsigned();
Greg Clayton7f4c7432012-08-11 00:49:14 +00007100 location.CopyOpcodeData(get_debug_info_data(), block_offset, block_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007101 }
7102 else
7103 {
7104 const DataExtractor& debug_loc_data = get_debug_loc_data();
7105 const dw_offset_t debug_loc_offset = form_value.Unsigned();
7106
7107 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
7108 if (loc_list_length > 0)
7109 {
Greg Clayton7f4c7432012-08-11 00:49:14 +00007110 location.CopyOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007111 assert (func_low_pc != LLDB_INVALID_ADDRESS);
7112 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
7113 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007114 }
7115 }
Greg Clayton7f995132011-10-04 22:41:51 +00007116 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007117
Greg Clayton1c8ef472013-04-05 23:27:21 +00007118 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00007119 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007120 case DW_AT_declaration:
7121 case DW_AT_description:
7122 case DW_AT_endianity:
7123 case DW_AT_segment:
7124 case DW_AT_start_scope:
7125 case DW_AT_visibility:
7126 default:
7127 case DW_AT_abstract_origin:
7128 case DW_AT_sibling:
7129 case DW_AT_specification:
7130 break;
7131 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007132 }
7133 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007134
Greg Clayton7f995132011-10-04 22:41:51 +00007135 if (location.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007136 {
Greg Clayton7f995132011-10-04 22:41:51 +00007137 ValueType scope = eValueTypeInvalid;
7138
7139 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7140 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007141 SymbolContextScope * symbol_context_scope = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00007142
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007143 // DWARF doesn't specify if a DW_TAG_variable is a local, global
7144 // or static variable, so we have to do a little digging by
7145 // looking at the location of a varaible to see if it contains
7146 // a DW_OP_addr opcode _somewhere_ in the definition. I say
7147 // somewhere because clang likes to combine small global variables
7148 // into the same symbol and have locations like:
7149 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
7150 // So if we don't have a DW_TAG_formal_parameter, we can look at
7151 // the location to see if it contains a DW_OP_addr opcode, and
7152 // then we can correctly classify our variables.
Greg Clayton7f995132011-10-04 22:41:51 +00007153 if (tag == DW_TAG_formal_parameter)
7154 scope = eValueTypeVariableArgument;
Greg Claytond1767f02011-12-08 02:13:16 +00007155 else
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007156 {
Greg Clayton96c09682012-01-04 22:56:43 +00007157 bool op_error = false;
Greg Claytond1767f02011-12-08 02:13:16 +00007158 // Check if the location has a DW_OP_addr with any address value...
Greg Clayton9422dd62013-03-04 21:46:16 +00007159 lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS;
Greg Claytond1767f02011-12-08 02:13:16 +00007160 if (!location_is_const_value_data)
Greg Clayton96c09682012-01-04 22:56:43 +00007161 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007162 location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error);
Greg Clayton96c09682012-01-04 22:56:43 +00007163 if (op_error)
7164 {
7165 StreamString strm;
7166 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
Greg Claytone38a5ed2012-01-05 03:57:59 +00007167 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 +00007168 }
7169 }
Greg Claytond1767f02011-12-08 02:13:16 +00007170
Greg Clayton9422dd62013-03-04 21:46:16 +00007171 if (location_DW_OP_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007172 {
Greg Claytond1767f02011-12-08 02:13:16 +00007173 if (is_external)
Greg Claytond1767f02011-12-08 02:13:16 +00007174 scope = eValueTypeVariableGlobal;
Greg Clayton9422dd62013-03-04 21:46:16 +00007175 else
7176 scope = eValueTypeVariableStatic;
7177
7178
7179 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile ();
7180
7181 if (debug_map_symfile)
7182 {
7183 // When leaving the DWARF in the .o files on darwin,
7184 // when we have a global variable that wasn't initialized,
7185 // the .o file might not have allocated a virtual
7186 // address for the global variable. In this case it will
7187 // have created a symbol for the global variable
7188 // that is undefined/data and external and the value will
7189 // be the byte size of the variable. When we do the
7190 // address map in SymbolFileDWARFDebugMap we rely on
7191 // having an address, we need to do some magic here
7192 // so we can get the correct address for our global
7193 // variable. The address for all of these entries
7194 // will be zero, and there will be an undefined symbol
7195 // in this object file, and the executable will have
7196 // a matching symbol with a good address. So here we
7197 // dig up the correct address and replace it in the
7198 // location for the variable, and set the variable's
7199 // symbol context scope to be that of the main executable
7200 // so the file address will resolve correctly.
7201 bool linked_oso_file_addr = false;
7202 if (is_external && location_DW_OP_addr == 0)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007203 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007204
7205 // we have a possible uninitialized extern global
7206 ConstString const_name(mangled ? mangled : name);
7207 ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile();
7208 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007209 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007210 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
7211 if (debug_map_symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007212 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007213 Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
7214 eSymbolTypeData,
7215 Symtab::eDebugYes,
7216 Symtab::eVisibilityExtern);
7217 if (exe_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007218 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007219 if (exe_symbol->ValueIsAddress())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007220 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007221 const addr_t exe_file_addr = exe_symbol->GetAddress().GetFileAddress();
7222 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007223 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007224 if (location.Update_DW_OP_addr (exe_file_addr))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007225 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007226 linked_oso_file_addr = true;
7227 symbol_context_scope = exe_symbol;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007228 }
7229 }
7230 }
7231 }
7232 }
7233 }
7234 }
Greg Clayton9422dd62013-03-04 21:46:16 +00007235
7236 if (!linked_oso_file_addr)
7237 {
7238 // The DW_OP_addr is not zero, but it contains a .o file address which
7239 // needs to be linked up correctly.
7240 const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr);
7241 if (exe_file_addr != LLDB_INVALID_ADDRESS)
7242 {
7243 // Update the file address for this variable
7244 location.Update_DW_OP_addr (exe_file_addr);
7245 }
7246 else
7247 {
7248 // Variable didn't make it into the final executable
7249 return var_sp;
7250 }
7251 }
Greg Claytond1767f02011-12-08 02:13:16 +00007252 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007253 }
7254 else
Greg Claytond1767f02011-12-08 02:13:16 +00007255 {
7256 scope = eValueTypeVariableLocal;
7257 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007258 }
Greg Clayton7f995132011-10-04 22:41:51 +00007259
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007260 if (symbol_context_scope == NULL)
Greg Clayton7f995132011-10-04 22:41:51 +00007261 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007262 switch (parent_tag)
Greg Clayton5cf58b92011-10-05 22:22:08 +00007263 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007264 case DW_TAG_subprogram:
7265 case DW_TAG_inlined_subroutine:
7266 case DW_TAG_lexical_block:
7267 if (sc.function)
7268 {
7269 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
7270 if (symbol_context_scope == NULL)
7271 symbol_context_scope = sc.function;
7272 }
7273 break;
7274
7275 default:
7276 symbol_context_scope = sc.comp_unit;
7277 break;
Greg Clayton5cf58b92011-10-05 22:22:08 +00007278 }
Greg Clayton7f995132011-10-04 22:41:51 +00007279 }
7280
Greg Clayton5cf58b92011-10-05 22:22:08 +00007281 if (symbol_context_scope)
7282 {
Greg Clayton81c22f62011-10-19 18:09:39 +00007283 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
7284 name,
7285 mangled,
Greg Claytond1767f02011-12-08 02:13:16 +00007286 SymbolFileTypeSP (new SymbolFileType(*this, type_uid)),
Greg Clayton81c22f62011-10-19 18:09:39 +00007287 scope,
7288 symbol_context_scope,
7289 &decl,
7290 location,
7291 is_external,
7292 is_artificial));
Greg Clayton5cf58b92011-10-05 22:22:08 +00007293
7294 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
7295 }
7296 else
7297 {
7298 // Not ready to parse this variable yet. It might be a global
7299 // or static variable that is in a function scope and the function
7300 // in the symbol context wasn't filled in yet
7301 return var_sp;
7302 }
Greg Clayton7f995132011-10-04 22:41:51 +00007303 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007304 }
Greg Clayton7f995132011-10-04 22:41:51 +00007305 // Cache var_sp even if NULL (the variable was just a specification or
7306 // was missing vital information to be able to be displayed in the debugger
7307 // (missing location due to optimization, etc)) so we don't re-parse
7308 // this DIE over and over later...
7309 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007310 }
7311 return var_sp;
7312}
7313
Greg Claytonc662ec82011-06-17 22:10:16 +00007314
7315const DWARFDebugInfoEntry *
7316SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
7317 dw_offset_t spec_block_die_offset,
7318 DWARFCompileUnit **result_die_cu_handle)
7319{
7320 // Give the concrete function die specified by "func_die_offset", find the
7321 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7322 // to "spec_block_die_offset"
7323 DWARFDebugInfo* info = DebugInfo();
7324
7325 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
7326 if (die)
7327 {
7328 assert (*result_die_cu_handle);
7329 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
7330 }
7331 return NULL;
7332}
7333
7334
7335const DWARFDebugInfoEntry *
7336SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
7337 const DWARFDebugInfoEntry *die,
7338 dw_offset_t spec_block_die_offset,
7339 DWARFCompileUnit **result_die_cu_handle)
7340{
7341 if (die)
7342 {
7343 switch (die->Tag())
7344 {
7345 case DW_TAG_subprogram:
7346 case DW_TAG_inlined_subroutine:
7347 case DW_TAG_lexical_block:
7348 {
7349 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
7350 {
7351 *result_die_cu_handle = dwarf_cu;
7352 return die;
7353 }
7354
7355 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
7356 {
7357 *result_die_cu_handle = dwarf_cu;
7358 return die;
7359 }
7360 }
7361 break;
7362 }
7363
7364 // Give the concrete function die specified by "func_die_offset", find the
7365 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7366 // to "spec_block_die_offset"
7367 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
7368 {
7369 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
7370 child_die,
7371 spec_block_die_offset,
7372 result_die_cu_handle);
7373 if (result_die)
7374 return result_die;
7375 }
7376 }
7377
7378 *result_die_cu_handle = NULL;
7379 return NULL;
7380}
7381
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007382size_t
7383SymbolFileDWARF::ParseVariables
7384(
7385 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007386 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007387 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007388 const DWARFDebugInfoEntry *orig_die,
7389 bool parse_siblings,
7390 bool parse_children,
7391 VariableList* cc_variable_list
7392)
7393{
7394 if (orig_die == NULL)
7395 return 0;
7396
Greg Claytonc662ec82011-06-17 22:10:16 +00007397 VariableListSP variable_list_sp;
7398
7399 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007400 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00007401 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007402 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007403 dw_tag_t tag = die->Tag();
7404
7405 // Check to see if we have already parsed this variable or constant?
7406 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007407 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007408 if (cc_variable_list)
7409 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007410 }
7411 else
7412 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007413 // We haven't already parsed it, lets do that now.
7414 if ((tag == DW_TAG_variable) ||
7415 (tag == DW_TAG_constant) ||
7416 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007417 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007418 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00007419 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007420 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
7421 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7422 switch (parent_tag)
7423 {
7424 case DW_TAG_compile_unit:
7425 if (sc.comp_unit != NULL)
7426 {
7427 variable_list_sp = sc.comp_unit->GetVariableList(false);
7428 if (variable_list_sp.get() == NULL)
7429 {
7430 variable_list_sp.reset(new VariableList());
7431 sc.comp_unit->SetVariableList(variable_list_sp);
7432 }
7433 }
7434 else
7435 {
Daniel Malead01b2952012-11-29 21:49:15 +00007436 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 +00007437 MakeUserID(sc_parent_die->GetOffset()),
7438 DW_TAG_value_to_name (parent_tag),
7439 MakeUserID(orig_die->GetOffset()),
7440 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007441 }
7442 break;
7443
7444 case DW_TAG_subprogram:
7445 case DW_TAG_inlined_subroutine:
7446 case DW_TAG_lexical_block:
7447 if (sc.function != NULL)
7448 {
7449 // Check to see if we already have parsed the variables for the given scope
7450
Greg Clayton81c22f62011-10-19 18:09:39 +00007451 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007452 if (block == NULL)
7453 {
7454 // This must be a specification or abstract origin with
7455 // a concrete block couterpart in the current function. We need
7456 // to find the concrete block so we can correctly add the
7457 // variable to it
7458 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
7459 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
7460 sc_parent_die->GetOffset(),
7461 &concrete_block_die_cu);
7462 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00007463 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007464 }
7465
7466 if (block != NULL)
7467 {
7468 const bool can_create = false;
7469 variable_list_sp = block->GetBlockVariableList (can_create);
7470 if (variable_list_sp.get() == NULL)
7471 {
7472 variable_list_sp.reset(new VariableList());
7473 block->SetVariableList(variable_list_sp);
7474 }
7475 }
7476 }
7477 break;
7478
7479 default:
Daniel Malead01b2952012-11-29 21:49:15 +00007480 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 +00007481 MakeUserID(orig_die->GetOffset()),
7482 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007483 break;
7484 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00007485 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007486
7487 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007488 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00007489 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
7490 if (var_sp)
7491 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007492 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00007493 if (cc_variable_list)
7494 cc_variable_list->AddVariableIfUnique (var_sp);
7495 ++vars_added;
7496 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007497 }
7498 }
7499 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007500
7501 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
7502
7503 if (!skip_children && parse_children && die->HasChildren())
7504 {
7505 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
7506 }
7507
7508 if (parse_siblings)
7509 die = die->GetSibling();
7510 else
7511 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007512 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007513 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007514}
7515
7516//------------------------------------------------------------------
7517// PluginInterface protocol
7518//------------------------------------------------------------------
7519const char *
7520SymbolFileDWARF::GetPluginName()
7521{
7522 return "SymbolFileDWARF";
7523}
7524
7525const char *
7526SymbolFileDWARF::GetShortPluginName()
7527{
7528 return GetPluginNameStatic();
7529}
7530
7531uint32_t
7532SymbolFileDWARF::GetPluginVersion()
7533{
7534 return 1;
7535}
7536
7537void
Greg Clayton6beaaa62011-01-17 03:46:26 +00007538SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
7539{
7540 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7541 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
7542 if (clang_type)
7543 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7544}
7545
7546void
7547SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
7548{
7549 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7550 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
7551 if (clang_type)
7552 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7553}
7554
Greg Claytona2721472011-06-25 00:44:06 +00007555void
Sean Callanancc427fa2011-07-30 02:42:06 +00007556SymbolFileDWARF::DumpIndexes ()
7557{
7558 StreamFile s(stdout, false);
7559
7560 s.Printf ("DWARF index for (%s) '%s/%s':",
7561 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
7562 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
7563 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
7564 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
7565 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
7566 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
7567 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
7568 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
7569 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
7570 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
7571 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
7572}
7573
7574void
7575SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
7576 const char *name,
7577 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00007578{
Sean Callanancc427fa2011-07-30 02:42:06 +00007579 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00007580
7581 if (iter == m_decl_ctx_to_die.end())
7582 return;
7583
Greg Claytoncb5860a2011-10-13 23:49:28 +00007584 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00007585 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007586 const DWARFDebugInfoEntry *context_die = *pos;
7587
7588 if (!results)
7589 return;
7590
7591 DWARFDebugInfo* info = DebugInfo();
7592
7593 DIEArray die_offsets;
7594
7595 DWARFCompileUnit* dwarf_cu = NULL;
7596 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton220a0072011-12-09 08:48:30 +00007597
7598 if (m_using_apple_tables)
7599 {
7600 if (m_apple_types_ap.get())
7601 m_apple_types_ap->FindByName (name, die_offsets);
7602 }
7603 else
7604 {
7605 if (!m_indexed)
7606 Index ();
7607
7608 m_type_index.Find (ConstString(name), die_offsets);
7609 }
7610
Greg Clayton220a0072011-12-09 08:48:30 +00007611 const size_t num_matches = die_offsets.size();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007612
7613 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00007614 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007615 for (size_t i = 0; i < num_matches; ++i)
7616 {
7617 const dw_offset_t die_offset = die_offsets[i];
7618 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00007619
Greg Claytoncb5860a2011-10-13 23:49:28 +00007620 if (die->GetParent() != context_die)
7621 continue;
7622
7623 Type *matching_type = ResolveType (dwarf_cu, die);
7624
Greg Clayton42ce2f32011-12-12 21:50:19 +00007625 lldb::clang_type_t type = matching_type->GetClangForwardType();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007626 clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type);
7627
7628 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
7629 {
7630 clang::TagDecl *tag_decl = tag_type->getDecl();
7631 results->push_back(tag_decl);
7632 }
7633 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
7634 {
7635 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
7636 results->push_back(typedef_decl);
7637 }
Greg Claytona2721472011-06-25 00:44:06 +00007638 }
7639 }
7640 }
7641}
7642
7643void
7644SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00007645 const clang::DeclContext *decl_context,
7646 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00007647 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
7648{
Greg Clayton85ae2e12011-10-18 23:36:41 +00007649
7650 switch (decl_context->getDeclKind())
7651 {
7652 case clang::Decl::Namespace:
7653 case clang::Decl::TranslationUnit:
7654 {
7655 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7656 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
7657 }
7658 break;
7659 default:
7660 break;
7661 }
Greg Claytona2721472011-06-25 00:44:06 +00007662}
Greg Claytoncaab74e2012-01-28 00:48:57 +00007663
7664bool
7665SymbolFileDWARF::LayoutRecordType (void *baton,
7666 const clang::RecordDecl *record_decl,
7667 uint64_t &size,
7668 uint64_t &alignment,
7669 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7670 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7671 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7672{
7673 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7674 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
7675}
7676
7677
7678bool
7679SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl,
7680 uint64_t &bit_size,
7681 uint64_t &alignment,
7682 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7683 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7684 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7685{
Greg Clayton5160ce52013-03-27 23:08:40 +00007686 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Claytoncaab74e2012-01-28 00:48:57 +00007687 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
7688 bool success = false;
7689 base_offsets.clear();
7690 vbase_offsets.clear();
7691 if (pos != m_record_decl_to_layout_map.end())
7692 {
7693 bit_size = pos->second.bit_size;
7694 alignment = pos->second.alignment;
7695 field_offsets.swap(pos->second.field_offsets);
Greg Clayton2508b9b2012-11-01 23:20:02 +00007696 base_offsets.swap (pos->second.base_offsets);
7697 vbase_offsets.swap (pos->second.vbase_offsets);
Greg Claytoncaab74e2012-01-28 00:48:57 +00007698 m_record_decl_to_layout_map.erase(pos);
7699 success = true;
7700 }
7701 else
7702 {
7703 bit_size = 0;
7704 alignment = 0;
7705 field_offsets.clear();
7706 }
7707
7708 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00007709 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00007710 "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 +00007711 record_decl,
7712 bit_size,
7713 alignment,
7714 (uint32_t)field_offsets.size(),
7715 (uint32_t)base_offsets.size(),
7716 (uint32_t)vbase_offsets.size(),
7717 success);
7718 return success;
7719}
7720
7721
Greg Clayton1f746072012-08-29 21:13:06 +00007722SymbolFileDWARFDebugMap *
7723SymbolFileDWARF::GetDebugMapSymfile ()
7724{
7725 if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired())
7726 {
7727 lldb::ModuleSP module_sp (m_debug_map_module_wp.lock());
7728 if (module_sp)
7729 {
7730 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
7731 if (sym_vendor)
7732 m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile();
7733 }
7734 }
7735 return m_debug_map_symfile;
7736}
7737
Greg Claytoncaab74e2012-01-28 00:48:57 +00007738