blob: f7388d2b4a92e3069cfb80ce30ef0dd03d8499f8 [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"
60#include "DWARFDIECollection.h"
61#include "DWARFFormValue.h"
62#include "DWARFLocationList.h"
63#include "LogChannelDWARF.h"
Greg Clayton450e3f32010-10-12 02:24:53 +000064#include "SymbolFileDWARFDebugMap.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065
66#include <map>
67
Greg Clayton62742b12010-11-11 01:09:45 +000068//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
Greg Claytonc93237c2010-10-01 20:48:32 +000069
70#ifdef ENABLE_DEBUG_PRINTF
71#include <stdio.h>
72#define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
73#else
74#define DEBUG_PRINTF(fmt, ...)
75#endif
76
Greg Clayton594e5ed2010-09-27 21:07:38 +000077#define DIE_IS_BEING_PARSED ((lldb_private::Type*)1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000078
79using namespace lldb;
80using namespace lldb_private;
81
Greg Clayton219cf312012-03-30 00:51:13 +000082//static inline bool
83//child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag)
84//{
85// switch (tag)
86// {
87// default:
88// break;
89// case DW_TAG_subprogram:
90// case DW_TAG_inlined_subroutine:
91// case DW_TAG_class_type:
92// case DW_TAG_structure_type:
93// case DW_TAG_union_type:
94// return true;
95// }
96// return false;
97//}
98//
Sean Callananc7fbf732010-08-06 00:32:49 +000099static AccessType
Greg Clayton8cf05932010-07-22 18:30:50 +0000100DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000101{
102 switch (dwarf_accessibility)
103 {
Sean Callananc7fbf732010-08-06 00:32:49 +0000104 case DW_ACCESS_public: return eAccessPublic;
105 case DW_ACCESS_private: return eAccessPrivate;
106 case DW_ACCESS_protected: return eAccessProtected;
Greg Clayton8cf05932010-07-22 18:30:50 +0000107 default: break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000108 }
Sean Callananc7fbf732010-08-06 00:32:49 +0000109 return eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000110}
111
Greg Clayton1fba87112012-02-09 20:03:49 +0000112#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
113
114class DIEStack
115{
116public:
117
118 void Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
119 {
120 m_dies.push_back (DIEInfo(cu, die));
121 }
122
123
124 void LogDIEs (Log *log, SymbolFileDWARF *dwarf)
125 {
126 StreamString log_strm;
127 const size_t n = m_dies.size();
128 log_strm.Printf("DIEStack[%zu]:\n", n);
129 for (size_t i=0; i<n; i++)
130 {
131 DWARFCompileUnit *cu = m_dies[i].cu;
132 const DWARFDebugInfoEntry *die = m_dies[i].die;
133 std::string qualified_name;
134 die->GetQualifiedName(dwarf, cu, qualified_name);
135 log_strm.Printf ("[%zu] 0x%8.8x: %s name='%s'\n",
136 i,
137 die->GetOffset(),
138 DW_TAG_value_to_name(die->Tag()),
139 qualified_name.c_str());
140 }
141 log->PutCString(log_strm.GetData());
142 }
143 void Pop ()
144 {
145 m_dies.pop_back();
146 }
147
148 class ScopedPopper
149 {
150 public:
151 ScopedPopper (DIEStack &die_stack) :
152 m_die_stack (die_stack),
153 m_valid (false)
154 {
155 }
156
157 void
158 Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
159 {
160 m_valid = true;
161 m_die_stack.Push (cu, die);
162 }
163
164 ~ScopedPopper ()
165 {
166 if (m_valid)
167 m_die_stack.Pop();
168 }
169
170
171
172 protected:
173 DIEStack &m_die_stack;
174 bool m_valid;
175 };
176
177protected:
178 struct DIEInfo {
179 DIEInfo (DWARFCompileUnit *c, const DWARFDebugInfoEntry *d) :
180 cu(c),
181 die(d)
182 {
183 }
184 DWARFCompileUnit *cu;
185 const DWARFDebugInfoEntry *die;
186 };
187 typedef std::vector<DIEInfo> Stack;
188 Stack m_dies;
189};
190#endif
191
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000192void
193SymbolFileDWARF::Initialize()
194{
195 LogChannelDWARF::Initialize();
196 PluginManager::RegisterPlugin (GetPluginNameStatic(),
197 GetPluginDescriptionStatic(),
198 CreateInstance);
199}
200
201void
202SymbolFileDWARF::Terminate()
203{
204 PluginManager::UnregisterPlugin (CreateInstance);
205 LogChannelDWARF::Initialize();
206}
207
208
209const char *
210SymbolFileDWARF::GetPluginNameStatic()
211{
Greg Claytond4a2b372011-09-12 23:21:58 +0000212 return "dwarf";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000213}
214
215const char *
216SymbolFileDWARF::GetPluginDescriptionStatic()
217{
218 return "DWARF and DWARF3 debug symbol file reader.";
219}
220
221
222SymbolFile*
223SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
224{
225 return new SymbolFileDWARF(obj_file);
226}
227
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000228TypeList *
229SymbolFileDWARF::GetTypeList ()
230{
231 if (m_debug_map_symfile)
232 return m_debug_map_symfile->GetTypeList();
233 return m_obj_file->GetModule()->GetTypeList();
234
235}
236
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000237//----------------------------------------------------------------------
238// Gets the first parent that is a lexical block, function or inlined
239// subroutine, or compile unit.
240//----------------------------------------------------------------------
241static const DWARFDebugInfoEntry *
242GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
243{
244 const DWARFDebugInfoEntry *die;
245 for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
246 {
247 dw_tag_t tag = die->Tag();
248
249 switch (tag)
250 {
251 case DW_TAG_compile_unit:
252 case DW_TAG_subprogram:
253 case DW_TAG_inlined_subroutine:
254 case DW_TAG_lexical_block:
255 return die;
256 }
257 }
258 return NULL;
259}
260
261
Greg Clayton450e3f32010-10-12 02:24:53 +0000262SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
263 SymbolFile (objfile),
Greg Clayton81c22f62011-10-19 18:09:39 +0000264 UserID (0), // Used by SymbolFileDWARFDebugMap to when this class parses .o files to contain the .o file index/ID
Greg Clayton450e3f32010-10-12 02:24:53 +0000265 m_debug_map_symfile (NULL),
Greg Clayton7a345282010-11-09 23:46:37 +0000266 m_clang_tu_decl (NULL),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000267 m_flags(),
Greg Claytond4a2b372011-09-12 23:21:58 +0000268 m_data_debug_abbrev (),
269 m_data_debug_aranges (),
270 m_data_debug_frame (),
271 m_data_debug_info (),
272 m_data_debug_line (),
273 m_data_debug_loc (),
274 m_data_debug_ranges (),
275 m_data_debug_str (),
Greg Clayton17674402011-09-28 17:06:40 +0000276 m_data_apple_names (),
277 m_data_apple_types (),
Greg Clayton7f995132011-10-04 22:41:51 +0000278 m_data_apple_namespaces (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000279 m_abbr(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000280 m_info(),
281 m_line(),
Greg Clayton7f995132011-10-04 22:41:51 +0000282 m_apple_names_ap (),
283 m_apple_types_ap (),
284 m_apple_namespaces_ap (),
Greg Clayton5009f9d2011-10-27 17:55:14 +0000285 m_apple_objc_ap (),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000286 m_function_basename_index(),
287 m_function_fullname_index(),
288 m_function_method_index(),
289 m_function_selector_index(),
Greg Clayton450e3f32010-10-12 02:24:53 +0000290 m_objc_class_selectors_index(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000291 m_global_index(),
Greg Clayton69b04882010-10-15 02:03:22 +0000292 m_type_index(),
293 m_namespace_index(),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000294 m_indexed (false),
295 m_is_external_ast_source (false),
Greg Clayton97fbc342011-10-20 22:30:33 +0000296 m_using_apple_tables (false),
Greg Claytonc7f03b62012-01-12 04:33:28 +0000297 m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +0000298 m_ranges(),
299 m_unique_ast_type_map ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000300{
301}
302
303SymbolFileDWARF::~SymbolFileDWARF()
304{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000305 if (m_is_external_ast_source)
Greg Claytone72dfb32012-02-24 01:59:29 +0000306 {
307 ModuleSP module_sp (m_obj_file->GetModule());
308 if (module_sp)
309 module_sp->GetClangASTContext().RemoveExternalSource ();
310 }
Greg Clayton6beaaa62011-01-17 03:46:26 +0000311}
312
313static const ConstString &
314GetDWARFMachOSegmentName ()
315{
316 static ConstString g_dwarf_section_name ("__DWARF");
317 return g_dwarf_section_name;
318}
319
Greg Claytone576ab22011-02-15 00:19:15 +0000320UniqueDWARFASTTypeMap &
321SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
322{
323 if (m_debug_map_symfile)
324 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
325 return m_unique_ast_type_map;
326}
327
Greg Clayton6beaaa62011-01-17 03:46:26 +0000328ClangASTContext &
329SymbolFileDWARF::GetClangASTContext ()
330{
331 if (m_debug_map_symfile)
332 return m_debug_map_symfile->GetClangASTContext ();
333
334 ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext();
335 if (!m_is_external_ast_source)
336 {
337 m_is_external_ast_source = true;
338 llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap (
339 new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl,
340 SymbolFileDWARF::CompleteObjCInterfaceDecl,
Greg Claytona2721472011-06-25 00:44:06 +0000341 SymbolFileDWARF::FindExternalVisibleDeclsByName,
Greg Claytoncaab74e2012-01-28 00:48:57 +0000342 SymbolFileDWARF::LayoutRecordType,
Greg Clayton6beaaa62011-01-17 03:46:26 +0000343 this));
Greg Clayton6beaaa62011-01-17 03:46:26 +0000344 ast.SetExternalSource (ast_source_ap);
345 }
346 return ast;
347}
348
349void
350SymbolFileDWARF::InitializeObject()
351{
352 // Install our external AST source callbacks so we can complete Clang types.
Greg Claytone72dfb32012-02-24 01:59:29 +0000353 ModuleSP module_sp (m_obj_file->GetModule());
354 if (module_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +0000355 {
356 const SectionList *section_list = m_obj_file->GetSectionList();
357
358 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
359
360 // Memory map the DWARF mach-o segment so we have everything mmap'ed
361 // to keep our heap memory usage down.
362 if (section)
Greg Claytonc9660542012-02-05 02:38:54 +0000363 m_obj_file->MemoryMapSectionData(section, m_dwarf_data);
Greg Clayton6beaaa62011-01-17 03:46:26 +0000364 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000365 get_apple_names_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000366 if (m_data_apple_names.GetByteSize() > 0)
367 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000368 m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names"));
369 if (m_apple_names_ap->IsValid())
370 m_using_apple_tables = true;
371 else
Greg Clayton7f995132011-10-04 22:41:51 +0000372 m_apple_names_ap.reset();
373 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000374 get_apple_types_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000375 if (m_data_apple_types.GetByteSize() > 0)
376 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000377 m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types"));
378 if (m_apple_types_ap->IsValid())
379 m_using_apple_tables = true;
380 else
Greg Clayton7f995132011-10-04 22:41:51 +0000381 m_apple_types_ap.reset();
382 }
383
384 get_apple_namespaces_data();
385 if (m_data_apple_namespaces.GetByteSize() > 0)
386 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000387 m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces"));
388 if (m_apple_namespaces_ap->IsValid())
389 m_using_apple_tables = true;
390 else
Greg Clayton7f995132011-10-04 22:41:51 +0000391 m_apple_namespaces_ap.reset();
392 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000393
Greg Clayton5009f9d2011-10-27 17:55:14 +0000394 get_apple_objc_data();
395 if (m_data_apple_objc.GetByteSize() > 0)
396 {
397 m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc"));
398 if (m_apple_objc_ap->IsValid())
399 m_using_apple_tables = true;
400 else
401 m_apple_objc_ap.reset();
402 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000403}
404
405bool
406SymbolFileDWARF::SupportedVersion(uint16_t version)
407{
408 return version == 2 || version == 3;
409}
410
411uint32_t
Sean Callananbfaf54d2011-12-03 04:38:43 +0000412SymbolFileDWARF::CalculateAbilities ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000413{
414 uint32_t abilities = 0;
415 if (m_obj_file != NULL)
416 {
417 const Section* section = NULL;
418 const SectionList *section_list = m_obj_file->GetSectionList();
419 if (section_list == NULL)
420 return 0;
421
422 uint64_t debug_abbrev_file_size = 0;
423 uint64_t debug_aranges_file_size = 0;
424 uint64_t debug_frame_file_size = 0;
425 uint64_t debug_info_file_size = 0;
426 uint64_t debug_line_file_size = 0;
427 uint64_t debug_loc_file_size = 0;
428 uint64_t debug_macinfo_file_size = 0;
429 uint64_t debug_pubnames_file_size = 0;
430 uint64_t debug_pubtypes_file_size = 0;
431 uint64_t debug_ranges_file_size = 0;
432 uint64_t debug_str_file_size = 0;
433
Greg Clayton6beaaa62011-01-17 03:46:26 +0000434 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000435
436 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000437 section_list = &section->GetChildren ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000438
Greg Clayton4ceb9982010-07-21 22:54:26 +0000439 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000440 if (section != NULL)
441 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000442 debug_info_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000443
Greg Clayton4ceb9982010-07-21 22:54:26 +0000444 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000445 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000446 debug_abbrev_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000447 else
448 m_flags.Set (flagsGotDebugAbbrevData);
449
Greg Clayton4ceb9982010-07-21 22:54:26 +0000450 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000451 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000452 debug_aranges_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000453 else
454 m_flags.Set (flagsGotDebugArangesData);
455
Greg Clayton4ceb9982010-07-21 22:54:26 +0000456 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000457 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000458 debug_frame_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000459 else
460 m_flags.Set (flagsGotDebugFrameData);
461
Greg Clayton4ceb9982010-07-21 22:54:26 +0000462 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000463 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000464 debug_line_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000465 else
466 m_flags.Set (flagsGotDebugLineData);
467
Greg Clayton4ceb9982010-07-21 22:54:26 +0000468 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000469 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000470 debug_loc_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000471 else
472 m_flags.Set (flagsGotDebugLocData);
473
Greg Clayton4ceb9982010-07-21 22:54:26 +0000474 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000475 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000476 debug_macinfo_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000477 else
478 m_flags.Set (flagsGotDebugMacInfoData);
479
Greg Clayton4ceb9982010-07-21 22:54:26 +0000480 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000481 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000482 debug_pubnames_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000483 else
484 m_flags.Set (flagsGotDebugPubNamesData);
485
Greg Clayton4ceb9982010-07-21 22:54:26 +0000486 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000487 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000488 debug_pubtypes_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000489 else
490 m_flags.Set (flagsGotDebugPubTypesData);
491
Greg Clayton4ceb9982010-07-21 22:54:26 +0000492 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000493 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000494 debug_ranges_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000495 else
496 m_flags.Set (flagsGotDebugRangesData);
497
Greg Clayton4ceb9982010-07-21 22:54:26 +0000498 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000499 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000500 debug_str_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000501 else
502 m_flags.Set (flagsGotDebugStrData);
503 }
504
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;
510
511 if (debug_aranges_file_size > 0)
512 abilities |= AddressAcceleratorTable;
513
514 if (debug_pubnames_file_size > 0)
515 abilities |= FunctionAcceleratorTable;
516
517 if (debug_pubtypes_file_size > 0)
518 abilities |= TypeAcceleratorTable;
519
520 if (debug_macinfo_file_size > 0)
521 abilities |= MacroInformation;
522
523 if (debug_frame_file_size > 0)
524 abilities |= CallFrameInformation;
525 }
526 return abilities;
527}
528
529const DataExtractor&
Greg Clayton4ceb9982010-07-21 22:54:26 +0000530SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000531{
532 if (m_flags.IsClear (got_flag))
533 {
534 m_flags.Set (got_flag);
535 const SectionList *section_list = m_obj_file->GetSectionList();
536 if (section_list)
537 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000538 SectionSP section_sp (section_list->FindSectionByType(sect_type, true));
539 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000540 {
541 // See if we memory mapped the DWARF segment?
542 if (m_dwarf_data.GetByteSize())
543 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000544 data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000545 }
546 else
547 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000548 if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000549 data.Clear();
550 }
551 }
552 }
553 }
554 return data;
555}
556
557const DataExtractor&
558SymbolFileDWARF::get_debug_abbrev_data()
559{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000560 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000561}
562
563const DataExtractor&
Greg Claytond4a2b372011-09-12 23:21:58 +0000564SymbolFileDWARF::get_debug_aranges_data()
565{
566 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
567}
568
569const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000570SymbolFileDWARF::get_debug_frame_data()
571{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000572 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000573}
574
575const DataExtractor&
576SymbolFileDWARF::get_debug_info_data()
577{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000578 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000579}
580
581const DataExtractor&
582SymbolFileDWARF::get_debug_line_data()
583{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000584 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000585}
586
587const DataExtractor&
588SymbolFileDWARF::get_debug_loc_data()
589{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000590 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000591}
592
593const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000594SymbolFileDWARF::get_debug_ranges_data()
595{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000596 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000597}
598
599const DataExtractor&
600SymbolFileDWARF::get_debug_str_data()
601{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000602 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000603}
604
Greg Claytonf9eec202011-09-01 23:16:13 +0000605const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000606SymbolFileDWARF::get_apple_names_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000607{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000608 return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names);
Greg Claytonf9eec202011-09-01 23:16:13 +0000609}
610
611const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000612SymbolFileDWARF::get_apple_types_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000613{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000614 return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types);
Greg Claytonf9eec202011-09-01 23:16:13 +0000615}
616
Greg Clayton7f995132011-10-04 22:41:51 +0000617const DataExtractor&
618SymbolFileDWARF::get_apple_namespaces_data()
619{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000620 return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
621}
622
623const DataExtractor&
624SymbolFileDWARF::get_apple_objc_data()
625{
626 return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc);
Greg Clayton7f995132011-10-04 22:41:51 +0000627}
628
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000629
630DWARFDebugAbbrev*
631SymbolFileDWARF::DebugAbbrev()
632{
633 if (m_abbr.get() == NULL)
634 {
635 const DataExtractor &debug_abbrev_data = get_debug_abbrev_data();
636 if (debug_abbrev_data.GetByteSize() > 0)
637 {
638 m_abbr.reset(new DWARFDebugAbbrev());
639 if (m_abbr.get())
640 m_abbr->Parse(debug_abbrev_data);
641 }
642 }
643 return m_abbr.get();
644}
645
646const DWARFDebugAbbrev*
647SymbolFileDWARF::DebugAbbrev() const
648{
649 return m_abbr.get();
650}
651
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000652
653DWARFDebugInfo*
654SymbolFileDWARF::DebugInfo()
655{
656 if (m_info.get() == NULL)
657 {
658 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
659 if (get_debug_info_data().GetByteSize() > 0)
660 {
661 m_info.reset(new DWARFDebugInfo());
662 if (m_info.get())
663 {
664 m_info->SetDwarfData(this);
665 }
666 }
667 }
668 return m_info.get();
669}
670
671const DWARFDebugInfo*
672SymbolFileDWARF::DebugInfo() const
673{
674 return m_info.get();
675}
676
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000677DWARFCompileUnit*
678SymbolFileDWARF::GetDWARFCompileUnitForUID(lldb::user_id_t cu_uid)
679{
680 DWARFDebugInfo* info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +0000681 if (info && UserIDMatches(cu_uid))
682 return info->GetCompileUnit((dw_offset_t)cu_uid).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000683 return NULL;
684}
685
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000686
687DWARFDebugRanges*
688SymbolFileDWARF::DebugRanges()
689{
690 if (m_ranges.get() == NULL)
691 {
692 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
693 if (get_debug_ranges_data().GetByteSize() > 0)
694 {
695 m_ranges.reset(new DWARFDebugRanges());
696 if (m_ranges.get())
697 m_ranges->Extract(this);
698 }
699 }
700 return m_ranges.get();
701}
702
703const DWARFDebugRanges*
704SymbolFileDWARF::DebugRanges() const
705{
706 return m_ranges.get();
707}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000708
Greg Clayton53eb1c22012-04-02 22:59:12 +0000709lldb::CompUnitSP
710SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000711{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000712 CompUnitSP cu_sp;
713 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000714 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000715 CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData();
716 if (comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000717 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000718 // We already parsed this compile unit, had out a shared pointer to it
719 cu_sp = comp_unit->shared_from_this();
720 }
721 else
722 {
723 ModuleSP module_sp (m_obj_file->GetModule());
724 if (module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000725 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000726 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly ();
727 if (cu_die)
728 {
729 const char * cu_die_name = cu_die->GetName(this, dwarf_cu);
730 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
731 LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
732 if (cu_die_name)
733 {
734 std::string ramapped_file;
735 FileSpec cu_file_spec;
Jim Ingham0909e5f2010-09-16 00:57:33 +0000736
Greg Clayton53eb1c22012-04-02 22:59:12 +0000737 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0')
738 {
739 // If we have a full path to the compile unit, we don't need to resolve
740 // the file. This can be expensive e.g. when the source files are NFS mounted.
741 if (module_sp->RemapSourceFile(cu_die_name, ramapped_file))
742 cu_file_spec.SetFile (ramapped_file.c_str(), false);
743 else
744 cu_file_spec.SetFile (cu_die_name, false);
745 }
746 else
747 {
748 std::string fullpath(cu_comp_dir);
749 if (*fullpath.rbegin() != '/')
750 fullpath += '/';
751 fullpath += cu_die_name;
752 if (module_sp->RemapSourceFile (fullpath.c_str(), ramapped_file))
753 cu_file_spec.SetFile (ramapped_file.c_str(), false);
754 else
755 cu_file_spec.SetFile (fullpath.c_str(), false);
756 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000757
Greg Clayton53eb1c22012-04-02 22:59:12 +0000758 cu_sp.reset(new CompileUnit (module_sp,
759 dwarf_cu,
760 cu_file_spec,
761 MakeUserID(dwarf_cu->GetOffset()),
762 cu_language));
763 if (cu_sp)
764 {
765 dwarf_cu->SetUserData(cu_sp.get());
766
767 if (m_debug_map_symfile)
768 {
769 // Let the symbol file register the compile unit with
770 // the symbol vendor using its compile unit index
771 // when we are doing DWARF in .o files + debug map
772 m_debug_map_symfile->SetCompileUnit(this, cu_sp);
773 }
774 else
775 {
776 // 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)
878 func_name.SetValue(mangled, true);
879 else if (name)
880 func_name.SetValue(name, false);
881
882 FunctionSP func_sp;
883 std::auto_ptr<Declaration> decl_ap;
884 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
894 func_range.GetBaseAddress().ResolveLinkedAddress();
895
Greg Clayton81c22f62011-10-19 18:09:39 +0000896 const user_id_t func_user_id = MakeUserID(die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000897 func_sp.reset(new Function (sc.comp_unit,
Greg Clayton81c22f62011-10-19 18:09:39 +0000898 func_user_id, // UserID is the DIE offset
899 func_user_id,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000900 func_name,
901 func_type,
902 func_range)); // first address range
903
904 if (func_sp.get() != NULL)
905 {
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000906 if (frame_base.IsValid())
907 func_sp->GetFrameBaseExpression() = frame_base;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000908 sc.comp_unit->AddFunction(func_sp);
909 return func_sp.get();
910 }
911 }
912 }
913 return NULL;
914}
915
916size_t
917SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
918{
919 assert (sc.comp_unit);
920 size_t functions_added = 0;
Greg Clayton0fffff52010-09-24 05:15:53 +0000921 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000922 if (dwarf_cu)
923 {
924 DWARFDIECollection function_dies;
925 const size_t num_funtions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
926 size_t func_idx;
927 for (func_idx = 0; func_idx < num_funtions; ++func_idx)
928 {
929 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
Greg Clayton81c22f62011-10-19 18:09:39 +0000930 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000931 {
932 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
933 ++functions_added;
934 }
935 }
936 //FixupTypes();
937 }
938 return functions_added;
939}
940
941bool
942SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
943{
944 assert (sc.comp_unit);
Greg Clayton53eb1c22012-04-02 22:59:12 +0000945 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
946 assert (dwarf_cu);
947 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000948
949 if (cu_die)
950 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000951 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
952 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 +0000953
954 // All file indexes in DWARF are one based and a file of index zero is
955 // supposed to be the compile unit itself.
956 support_files.Append (*sc.comp_unit);
957
Greg Claytond804d282012-03-15 21:01:31 +0000958 return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000959 }
960 return false;
961}
962
963struct ParseDWARFLineTableCallbackInfo
964{
965 LineTable* line_table;
966 const SectionList *section_list;
967 lldb::addr_t prev_sect_file_base_addr;
968 lldb::addr_t curr_sect_file_base_addr;
969 bool is_oso_for_debug_map;
970 bool prev_in_final_executable;
971 DWARFDebugLine::Row prev_row;
972 SectionSP prev_section_sp;
973 SectionSP curr_section_sp;
974};
975
976//----------------------------------------------------------------------
977// ParseStatementTableCallback
978//----------------------------------------------------------------------
979static void
980ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
981{
982 LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table;
983 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
984 {
985 // Just started parsing the line table
986 }
987 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
988 {
989 // Done parsing line table, nothing to do for the cleanup
990 }
991 else
992 {
993 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
994 // We have a new row, lets append it
995
996 if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false)
997 {
998 info->prev_section_sp = info->curr_section_sp;
999 info->prev_sect_file_base_addr = info->curr_sect_file_base_addr;
1000 // If this is an end sequence entry, then we subtract one from the
1001 // address to make sure we get an address that is not the end of
1002 // a section.
1003 if (state.end_sequence && state.address != 0)
1004 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1);
1005 else
1006 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address);
1007
1008 if (info->curr_section_sp.get())
1009 info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress ();
1010 else
1011 info->curr_sect_file_base_addr = 0;
1012 }
1013 if (info->curr_section_sp.get())
1014 {
1015 lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr;
1016 // Check for the fancy section magic to determine if we
1017
1018 if (info->is_oso_for_debug_map)
1019 {
1020 // When this is a debug map object file that contains DWARF
1021 // (referenced from an N_OSO debug map nlist entry) we will have
1022 // a file address in the file range for our section from the
1023 // original .o file, and a load address in the executable that
1024 // contains the debug map.
1025 //
1026 // If the sections for the file range and load range are
1027 // different, we have a remapped section for the function and
1028 // this address is resolved. If they are the same, then the
1029 // function for this address didn't make it into the final
1030 // executable.
1031 bool curr_in_final_executable = info->curr_section_sp->GetLinkedSection () != NULL;
1032
1033 // If we are doing DWARF with debug map, then we need to carefully
1034 // add each line table entry as there may be gaps as functions
1035 // get moved around or removed.
1036 if (!info->prev_row.end_sequence && info->prev_section_sp.get())
1037 {
1038 if (info->prev_in_final_executable)
1039 {
1040 bool terminate_previous_entry = false;
1041 if (!curr_in_final_executable)
1042 {
1043 // Check for the case where the previous line entry
1044 // in a function made it into the final executable,
1045 // yet the current line entry falls in a function
1046 // that didn't. The line table used to be contiguous
1047 // through this address range but now it isn't. We
1048 // need to terminate the previous line entry so
1049 // that we can reconstruct the line range correctly
1050 // for it and to keep the line table correct.
1051 terminate_previous_entry = true;
1052 }
1053 else if (info->curr_section_sp.get() != info->prev_section_sp.get())
1054 {
1055 // Check for cases where the line entries used to be
1056 // contiguous address ranges, but now they aren't.
1057 // This can happen when order files specify the
1058 // ordering of the functions.
1059 lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr;
1060 Section *curr_sect = info->curr_section_sp.get();
1061 Section *prev_sect = info->prev_section_sp.get();
1062 assert (curr_sect->GetLinkedSection());
1063 assert (prev_sect->GetLinkedSection());
1064 lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address;
1065 lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset;
1066 lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset;
1067 lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr;
1068 if (object_file_addr_delta != linked_file_addr_delta)
1069 terminate_previous_entry = true;
1070 }
1071
1072 if (terminate_previous_entry)
1073 {
1074 line_table->InsertLineEntry (info->prev_section_sp,
1075 state.address - info->prev_sect_file_base_addr,
1076 info->prev_row.line,
1077 info->prev_row.column,
1078 info->prev_row.file,
1079 false, // is_stmt
1080 false, // basic_block
1081 false, // state.prologue_end
1082 false, // state.epilogue_begin
1083 true); // end_sequence);
1084 }
1085 }
1086 }
1087
1088 if (curr_in_final_executable)
1089 {
1090 line_table->InsertLineEntry (info->curr_section_sp,
1091 curr_line_section_offset,
1092 state.line,
1093 state.column,
1094 state.file,
1095 state.is_stmt,
1096 state.basic_block,
1097 state.prologue_end,
1098 state.epilogue_begin,
1099 state.end_sequence);
1100 info->prev_section_sp = info->curr_section_sp;
1101 }
1102 else
1103 {
1104 // If the current address didn't make it into the final
1105 // executable, the current section will be the __text
1106 // segment in the .o file, so we need to clear this so
1107 // we can catch the next function that did make it into
1108 // the final executable.
1109 info->prev_section_sp.reset();
1110 info->curr_section_sp.reset();
1111 }
1112
1113 info->prev_in_final_executable = curr_in_final_executable;
1114 }
1115 else
1116 {
1117 // We are not in an object file that contains DWARF for an
1118 // N_OSO, this is just a normal DWARF file. The DWARF spec
1119 // guarantees that the addresses will be in increasing order
1120 // so, since we store line tables in file address order, we
1121 // can always just append the line entry without needing to
1122 // search for the correct insertion point (we don't need to
1123 // use LineEntry::InsertLineEntry()).
1124 line_table->AppendLineEntry (info->curr_section_sp,
1125 curr_line_section_offset,
1126 state.line,
1127 state.column,
1128 state.file,
1129 state.is_stmt,
1130 state.basic_block,
1131 state.prologue_end,
1132 state.epilogue_begin,
1133 state.end_sequence);
1134 }
1135 }
1136
1137 info->prev_row = state;
1138 }
1139}
1140
1141bool
1142SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1143{
1144 assert (sc.comp_unit);
1145 if (sc.comp_unit->GetLineTable() != NULL)
1146 return true;
1147
1148 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
1149 if (dwarf_cu)
1150 {
1151 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Greg Clayton129d12c2011-11-28 03:29:03 +00001152 if (dwarf_cu_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001153 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001154 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1155 if (cu_line_offset != DW_INVALID_OFFSET)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001156 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001157 std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
1158 if (line_table_ap.get())
1159 {
1160 ParseDWARFLineTableCallbackInfo info = {
1161 line_table_ap.get(),
1162 m_obj_file->GetSectionList(),
1163 0,
1164 0,
1165 m_debug_map_symfile != NULL,
1166 false,
1167 DWARFDebugLine::Row(),
1168 SectionSP(),
1169 SectionSP()
1170 };
1171 uint32_t offset = cu_line_offset;
1172 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
1173 sc.comp_unit->SetLineTable(line_table_ap.release());
1174 return true;
1175 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001176 }
1177 }
1178 }
1179 return false;
1180}
1181
1182size_t
1183SymbolFileDWARF::ParseFunctionBlocks
1184(
1185 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001186 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001187 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001188 const DWARFDebugInfoEntry *die,
1189 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001190 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001191)
1192{
1193 size_t blocks_added = 0;
1194 while (die != NULL)
1195 {
1196 dw_tag_t tag = die->Tag();
1197
1198 switch (tag)
1199 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001200 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001201 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001202 case DW_TAG_lexical_block:
1203 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001204 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001205 if (tag == DW_TAG_subprogram)
1206 {
1207 // Skip any DW_TAG_subprogram DIEs that are inside
1208 // of a normal or inlined functions. These will be
1209 // parsed on their own as separate entities.
1210
1211 if (depth > 0)
1212 break;
1213
1214 block = parent_block;
1215 }
1216 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001217 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001218 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001219 parent_block->AddChild(block_sp);
1220 block = block_sp.get();
1221 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001222 DWARFDebugRanges::RangeList ranges;
1223 const char *name = NULL;
1224 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001225
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001226 int decl_file = 0;
1227 int decl_line = 0;
1228 int decl_column = 0;
1229 int call_file = 0;
1230 int call_line = 0;
1231 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001232 if (die->GetDIENamesAndRanges (this,
1233 dwarf_cu,
1234 name,
1235 mangled_name,
1236 ranges,
1237 decl_file, decl_line, decl_column,
1238 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001239 {
1240 if (tag == DW_TAG_subprogram)
1241 {
1242 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001243 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001244 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001245 else if (tag == DW_TAG_inlined_subroutine)
1246 {
1247 // We get called here for inlined subroutines in two ways.
1248 // The first time is when we are making the Function object
1249 // for this inlined concrete instance. Since we're creating a top level block at
1250 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1251 // adjust the containing address.
1252 // The second time is when we are parsing the blocks inside the function that contains
1253 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1254 // function the offset will be for that function.
1255 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1256 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001257 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001258 }
1259 }
1260
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001261 AddRangesToBlock (*block, ranges, subprogram_low_pc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001262
1263 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1264 {
1265 std::auto_ptr<Declaration> decl_ap;
1266 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001267 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1268 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001269
1270 std::auto_ptr<Declaration> call_ap;
1271 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001272 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1273 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001274
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001275 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001276 }
1277
1278 ++blocks_added;
1279
Greg Claytondd7feaf2011-08-12 17:54:33 +00001280 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001281 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001282 blocks_added += ParseFunctionBlocks (sc,
1283 block,
1284 dwarf_cu,
1285 die->GetFirstChild(),
1286 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001287 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001288 }
1289 }
1290 }
1291 break;
1292 default:
1293 break;
1294 }
1295
Greg Claytondd7feaf2011-08-12 17:54:33 +00001296 // Only parse siblings of the block if we are not at depth zero. A depth
1297 // of zero indicates we are currently parsing the top level
1298 // DW_TAG_subprogram DIE
1299
1300 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001301 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001302 else
1303 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001304 }
1305 return blocks_added;
1306}
1307
Greg Claytonf0705c82011-10-22 03:33:13 +00001308bool
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001309SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu,
1310 const DWARFDebugInfoEntry *die,
1311 ClangASTContext::TemplateParameterInfos &template_param_infos)
1312{
1313 const dw_tag_t tag = die->Tag();
1314
1315 switch (tag)
1316 {
1317 case DW_TAG_template_type_parameter:
1318 case DW_TAG_template_value_parameter:
1319 {
1320 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
1321
1322 DWARFDebugInfoEntry::Attributes attributes;
1323 const size_t num_attributes = die->GetAttributes (this,
1324 dwarf_cu,
1325 fixed_form_sizes,
1326 attributes);
1327 const char *name = NULL;
1328 Type *lldb_type = NULL;
1329 clang_type_t clang_type = NULL;
1330 uint64_t uval64 = 0;
1331 bool uval64_valid = false;
1332 if (num_attributes > 0)
1333 {
1334 DWARFFormValue form_value;
1335 for (size_t i=0; i<num_attributes; ++i)
1336 {
1337 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1338
1339 switch (attr)
1340 {
1341 case DW_AT_name:
1342 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1343 name = form_value.AsCString(&get_debug_str_data());
1344 break;
1345
1346 case DW_AT_type:
1347 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1348 {
1349 const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu);
1350 lldb_type = ResolveTypeUID(type_die_offset);
1351 if (lldb_type)
1352 clang_type = lldb_type->GetClangForwardType();
1353 }
1354 break;
1355
1356 case DW_AT_const_value:
1357 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1358 {
1359 uval64_valid = true;
1360 uval64 = form_value.Unsigned();
1361 }
1362 break;
1363 default:
1364 break;
1365 }
1366 }
1367
1368 if (name && lldb_type && clang_type)
1369 {
1370 bool is_signed = false;
1371 template_param_infos.names.push_back(name);
1372 clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type));
1373 if (tag == DW_TAG_template_value_parameter && ClangASTContext::IsIntegerType (clang_type, is_signed) && uval64_valid)
1374 {
1375 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
1376 template_param_infos.args.push_back (clang::TemplateArgument (llvm::APSInt(apint), clang_qual_type));
1377 }
1378 else
1379 {
1380 template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type));
1381 }
1382 }
1383 else
1384 {
1385 return false;
1386 }
1387
1388 }
1389 }
1390 return true;
1391
1392 default:
1393 break;
1394 }
1395 return false;
1396}
1397
1398bool
Greg Claytonf0705c82011-10-22 03:33:13 +00001399SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1400 const DWARFDebugInfoEntry *parent_die,
1401 ClangASTContext::TemplateParameterInfos &template_param_infos)
1402{
1403
1404 if (parent_die == NULL)
1405 return NULL;
1406
Greg Claytonf0705c82011-10-22 03:33:13 +00001407 Args template_parameter_names;
1408 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1409 die != NULL;
1410 die = die->GetSibling())
1411 {
1412 const dw_tag_t tag = die->Tag();
1413
1414 switch (tag)
1415 {
1416 case DW_TAG_template_type_parameter:
1417 case DW_TAG_template_value_parameter:
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001418 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Claytonf0705c82011-10-22 03:33:13 +00001419 break;
1420
1421 default:
1422 break;
1423 }
1424 }
1425 if (template_param_infos.args.empty())
1426 return false;
1427 return template_param_infos.args.size() == template_param_infos.names.size();
1428}
1429
1430clang::ClassTemplateDecl *
1431SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001432 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001433 const char *parent_name,
1434 int tag_decl_kind,
1435 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1436{
1437 if (template_param_infos.IsValid())
1438 {
1439 std::string template_basename(parent_name);
1440 template_basename.erase (template_basename.find('<'));
1441 ClangASTContext &ast = GetClangASTContext();
1442
1443 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001444 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001445 template_basename.c_str(),
1446 tag_decl_kind,
1447 template_param_infos);
1448 }
1449 return NULL;
1450}
1451
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001452size_t
1453SymbolFileDWARF::ParseChildMembers
1454(
1455 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001456 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001457 const DWARFDebugInfoEntry *parent_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00001458 clang_type_t class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001459 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001460 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1461 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001462 DWARFDIECollection& member_function_dies,
Sean Callananc7fbf732010-08-06 00:32:49 +00001463 AccessType& default_accessibility,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001464 bool &is_a_class,
1465 LayoutInfo &layout_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001466)
1467{
1468 if (parent_die == NULL)
1469 return 0;
1470
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001471 size_t count = 0;
1472 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001473 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001474 uint32_t member_idx = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00001475
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001476 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1477 {
1478 dw_tag_t tag = die->Tag();
1479
1480 switch (tag)
1481 {
1482 case DW_TAG_member:
Bill Wendling9e5bf872012-04-03 08:45:33 +00001483 case DW_TAG_APPLE_Property:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001484 {
1485 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001486 const size_t num_attributes = die->GetAttributes (this,
1487 dwarf_cu,
1488 fixed_form_sizes,
1489 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001490 if (num_attributes > 0)
1491 {
1492 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001493 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001494 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001495 const char *prop_name = NULL;
1496 const char *prop_getter_name = NULL;
1497 const char *prop_setter_name = NULL;
1498 uint32_t prop_attributes = 0;
1499
1500
Greg Clayton24739922010-10-13 03:15:28 +00001501 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001502 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001503 AccessType accessibility = eAccessNone;
Greg Claytoncaab74e2012-01-28 00:48:57 +00001504 uint32_t member_byte_offset = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001505 size_t byte_size = 0;
1506 size_t bit_offset = 0;
1507 size_t bit_size = 0;
1508 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001509 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001510 {
1511 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1512 DWARFFormValue form_value;
1513 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1514 {
1515 switch (attr)
1516 {
1517 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1518 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1519 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1520 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1521 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1522 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1523 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1524 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1525 case DW_AT_data_member_location:
Greg Claytoncaab74e2012-01-28 00:48:57 +00001526 if (form_value.BlockData())
1527 {
1528 Value initialValue(0);
1529 Value memberOffset(0);
1530 const DataExtractor& debug_info_data = get_debug_info_data();
1531 uint32_t block_length = form_value.Unsigned();
1532 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1533 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
1534 NULL, // clang::ASTContext *
1535 NULL, // ClangExpressionVariableList *
1536 NULL, // ClangExpressionDeclMap *
1537 NULL, // RegisterContext *
1538 debug_info_data,
1539 block_offset,
1540 block_length,
1541 eRegisterKindDWARF,
1542 &initialValue,
1543 memberOffset,
1544 NULL))
1545 {
1546 member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1547 }
1548 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001549 break;
1550
Greg Clayton8cf05932010-07-22 18:30:50 +00001551 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton1b02c172012-03-14 21:00:47 +00001552 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001553 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1554 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1555 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1556 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
1557
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001558 default:
Greg Clayton1b02c172012-03-14 21:00:47 +00001559 case DW_AT_declaration:
1560 case DW_AT_description:
1561 case DW_AT_mutable:
1562 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001563 case DW_AT_sibling:
1564 break;
1565 }
1566 }
1567 }
Sean Callanana6582262012-04-05 00:12:52 +00001568
1569 if (prop_name)
Sean Callanan751aac62012-03-29 19:07:06 +00001570 {
Sean Callanana6582262012-04-05 00:12:52 +00001571 ConstString fixed_getter;
1572 ConstString fixed_setter;
1573
1574 // Check if the property getter/setter were provided as full
1575 // names. We want basenames, so we extract them.
1576
1577 if (prop_getter_name && prop_getter_name[0] == '-')
1578 {
1579 ObjCLanguageRuntime::ParseMethodName (prop_getter_name,
1580 NULL,
1581 &fixed_getter,
1582 NULL,
1583 NULL);
1584 prop_getter_name = fixed_getter.GetCString();
1585 }
1586
1587 if (prop_setter_name && prop_setter_name[0] == '-')
1588 {
1589 ObjCLanguageRuntime::ParseMethodName (prop_setter_name,
1590 NULL,
1591 &fixed_setter,
1592 NULL,
1593 NULL);
1594 prop_setter_name = fixed_setter.GetCString();
1595 }
1596
1597 // If the names haven't been provided, they need to be
1598 // filled in.
1599
1600 if (!prop_getter_name)
1601 {
1602 prop_getter_name = prop_name;
1603 }
1604 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly))
1605 {
1606 StreamString ss;
1607
1608 ss.Printf("set%c%s:",
1609 toupper(prop_name[0]),
1610 &prop_name[1]);
1611
1612 fixed_setter.SetCString(ss.GetData());
1613 prop_setter_name = fixed_setter.GetCString();
1614 }
Sean Callanan751aac62012-03-29 19:07:06 +00001615 }
1616
1617 // Clang has a DWARF generation bug where sometimes it
Greg Clayton44953932011-10-25 01:25:35 +00001618 // represents fields that are references with bad byte size
1619 // and bit size/offset information such as:
1620 //
1621 // DW_AT_byte_size( 0x00 )
1622 // DW_AT_bit_size( 0x40 )
1623 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1624 //
1625 // So check the bit offset to make sure it is sane, and if
1626 // the values are not sane, remove them. If we don't do this
1627 // then we will end up with a crash if we try to use this
1628 // type in an expression when clang becomes unhappy with its
1629 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001630
Greg Clayton44953932011-10-25 01:25:35 +00001631 if (bit_offset > 128)
1632 {
1633 bit_size = 0;
1634 bit_offset = 0;
1635 }
1636
1637 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00001638 if (class_language == eLanguageTypeObjC ||
1639 class_language == eLanguageTypeObjC_plus_plus)
1640 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001641
1642 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1643 {
1644 // Not all compilers will mark the vtable pointer
1645 // member as artificial (llvm-gcc). We can't have
1646 // the virtual members in our classes otherwise it
1647 // throws off all child offsets since we end up
1648 // having and extra pointer sized member in our
1649 // class layouts.
1650 is_artificial = true;
1651 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001652
Greg Clayton24739922010-10-13 03:15:28 +00001653 if (is_artificial == false)
1654 {
1655 Type *member_type = ResolveTypeUID(encoding_uid);
Jim Inghame3ae82a2011-11-12 01:36:43 +00001656 clang::FieldDecl *field_decl = NULL;
Sean Callanan751aac62012-03-29 19:07:06 +00001657 if (tag == DW_TAG_member)
Greg Claytond16e1e52011-07-12 17:06:17 +00001658 {
Sean Callanan751aac62012-03-29 19:07:06 +00001659 if (member_type)
1660 {
1661 if (accessibility == eAccessNone)
1662 accessibility = default_accessibility;
1663 member_accessibilities.push_back(accessibility);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001664
Sean Callanan751aac62012-03-29 19:07:06 +00001665 field_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
1666 name,
1667 member_type->GetClangLayoutType(),
1668 accessibility,
1669 bit_size);
Sean Callanan5b26f272012-02-04 08:49:35 +00001670 }
1671 else
1672 {
Sean Callanan751aac62012-03-29 19:07:06 +00001673 if (name)
1674 GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member '%s' refers to type 0x%8.8llx which was unable to be parsed",
1675 MakeUserID(die->GetOffset()),
1676 name,
1677 encoding_uid);
1678 else
1679 GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member refers to type 0x%8.8llx which was unable to be parsed",
1680 MakeUserID(die->GetOffset()),
1681 encoding_uid);
Sean Callanan5b26f272012-02-04 08:49:35 +00001682 }
Sean Callanan751aac62012-03-29 19:07:06 +00001683
1684 if (member_byte_offset != UINT32_MAX || bit_size != 0)
1685 {
1686 /////////////////////////////////////////////////////////////
1687 // How to locate a field given the DWARF debug information
1688 //
1689 // AT_byte_size indicates the size of the word in which the
1690 // bit offset must be interpreted.
1691 //
1692 // AT_data_member_location indicates the byte offset of the
1693 // word from the base address of the structure.
1694 //
1695 // AT_bit_offset indicates how many bits into the word
1696 // (according to the host endianness) the low-order bit of
1697 // the field starts. AT_bit_offset can be negative.
1698 //
1699 // AT_bit_size indicates the size of the field in bits.
1700 /////////////////////////////////////////////////////////////
Sean Callanan5b26f272012-02-04 08:49:35 +00001701
Sean Callanan751aac62012-03-29 19:07:06 +00001702 ByteOrder object_endian = GetObjectFile()->GetModule()->GetArchitecture().GetDefaultEndian();
1703
1704 uint64_t total_bit_offset = 0;
1705
1706 total_bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
1707
1708 if (object_endian == eByteOrderLittle)
1709 {
1710 total_bit_offset += byte_size * 8;
1711 total_bit_offset -= (bit_offset + bit_size);
1712 }
1713 else
1714 {
1715 total_bit_offset += bit_offset;
1716 }
1717
1718 layout_info.field_offsets.insert(std::make_pair(field_decl, total_bit_offset));
1719 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00001720 }
Sean Callanan751aac62012-03-29 19:07:06 +00001721
Jim Inghame3ae82a2011-11-12 01:36:43 +00001722 if (prop_name != NULL)
1723 {
Sean Callanan751aac62012-03-29 19:07:06 +00001724 clang::ObjCIvarDecl *ivar_decl = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001725
Sean Callanan751aac62012-03-29 19:07:06 +00001726 if (field_decl)
1727 {
1728 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
1729 assert (ivar_decl != NULL);
1730 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00001731
Jim Inghame3ae82a2011-11-12 01:36:43 +00001732 GetClangASTContext().AddObjCClassProperty (class_clang_type,
1733 prop_name,
Sean Callanan751aac62012-03-29 19:07:06 +00001734 member_type->GetClangLayoutType(),
Jim Inghame3ae82a2011-11-12 01:36:43 +00001735 ivar_decl,
1736 prop_setter_name,
1737 prop_getter_name,
1738 prop_attributes);
1739 }
Greg Clayton24739922010-10-13 03:15:28 +00001740 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001741 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00001742 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001743 }
1744 break;
1745
1746 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00001747 // Let the type parsing code handle this one for us.
1748 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001749 break;
1750
1751 case DW_TAG_inheritance:
1752 {
1753 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00001754 if (default_accessibility == eAccessNone)
1755 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001756 // TODO: implement DW_TAG_inheritance type parsing
1757 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001758 const size_t num_attributes = die->GetAttributes (this,
1759 dwarf_cu,
1760 fixed_form_sizes,
1761 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001762 if (num_attributes > 0)
1763 {
1764 Declaration decl;
1765 DWARFExpression location;
1766 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001767 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001768 bool is_virtual = false;
1769 bool is_base_of_class = true;
1770 off_t member_offset = 0;
1771 uint32_t i;
1772 for (i=0; i<num_attributes; ++i)
1773 {
1774 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1775 DWARFFormValue form_value;
1776 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1777 {
1778 switch (attr)
1779 {
1780 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1781 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1782 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1783 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1784 case DW_AT_data_member_location:
1785 if (form_value.BlockData())
1786 {
1787 Value initialValue(0);
1788 Value memberOffset(0);
1789 const DataExtractor& debug_info_data = get_debug_info_data();
1790 uint32_t block_length = form_value.Unsigned();
1791 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
Greg Claytonba2d22d2010-11-13 22:57:37 +00001792 if (DWARFExpression::Evaluate (NULL,
1793 NULL,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001794 NULL,
1795 NULL,
Jason Molenda2d107dd2010-11-20 01:28:30 +00001796 NULL,
Greg Clayton1a65ae12011-01-25 23:55:37 +00001797 debug_info_data,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001798 block_offset,
1799 block_length,
1800 eRegisterKindDWARF,
1801 &initialValue,
1802 memberOffset,
1803 NULL))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001804 {
1805 member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1806 }
1807 }
1808 break;
1809
1810 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00001811 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001812 break;
1813
1814 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
1815 default:
1816 case DW_AT_sibling:
1817 break;
1818 }
1819 }
1820 }
1821
Greg Clayton526e5af2010-11-13 03:52:47 +00001822 Type *base_class_type = ResolveTypeUID(encoding_uid);
1823 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001824
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001825 clang_type_t base_class_clang_type = base_class_type->GetClangFullType();
1826 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001827 if (class_language == eLanguageTypeObjC)
1828 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001829 GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001830 }
1831 else
1832 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001833 base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001834 accessibility,
1835 is_virtual,
1836 is_base_of_class));
Greg Clayton9e409562010-07-28 02:04:09 +00001837 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001838 }
1839 }
1840 break;
1841
1842 default:
1843 break;
1844 }
1845 }
1846 return count;
1847}
1848
1849
1850clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00001851SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001852{
1853 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00001854 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001855 {
1856 DWARFCompileUnitSP cu_sp;
1857 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1858 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00001859 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00001860 }
1861 return NULL;
1862}
1863
1864clang::DeclContext*
1865SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
1866{
Greg Clayton81c22f62011-10-19 18:09:39 +00001867 if (UserIDMatches(type_uid))
1868 return GetClangDeclContextForDIEOffset (sc, type_uid);
1869 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001870}
1871
1872Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00001873SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001874{
Greg Clayton81c22f62011-10-19 18:09:39 +00001875 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001876 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001877 DWARFDebugInfo* debug_info = DebugInfo();
1878 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00001879 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001880 DWARFCompileUnitSP cu_sp;
1881 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00001882 const bool assert_not_being_parsed = true;
1883 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00001884 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001885 }
1886 return NULL;
1887}
1888
Greg Claytoncab36a32011-12-08 05:16:30 +00001889Type*
1890SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00001891{
Greg Claytoncab36a32011-12-08 05:16:30 +00001892 if (die != NULL)
1893 {
Greg Clayton3bffb082011-12-10 02:15:28 +00001894 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
1895 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001896 GetObjectFile()->GetModule()->LogMessage (log.get(),
1897 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
1898 die->GetOffset(),
1899 DW_TAG_value_to_name(die->Tag()),
1900 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00001901
Greg Claytoncab36a32011-12-08 05:16:30 +00001902 // We might be coming in in the middle of a type tree (a class
1903 // withing a class, an enum within a class), so parse any needed
1904 // parent DIEs before we get to this one...
1905 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
1906 switch (decl_ctx_die->Tag())
1907 {
1908 case DW_TAG_structure_type:
1909 case DW_TAG_union_type:
1910 case DW_TAG_class_type:
1911 {
1912 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00001913 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001914 GetObjectFile()->GetModule()->LogMessage (log.get(),
1915 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
1916 die->GetOffset(),
1917 DW_TAG_value_to_name(die->Tag()),
1918 die->GetName(this, cu),
1919 decl_ctx_die->GetOffset());
Greg Clayton219cf312012-03-30 00:51:13 +00001920//
1921// Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
1922// if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
1923// {
1924// if (log)
1925// GetObjectFile()->GetModule()->LogMessage (log.get(),
1926// "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
1927// die->GetOffset(),
1928// DW_TAG_value_to_name(die->Tag()),
1929// die->GetName(this, cu),
1930// decl_ctx_die->GetOffset());
1931// // Ask the type to complete itself if it already hasn't since if we
1932// // want a function (method or static) from a class, the class must
1933// // create itself and add it's own methods and class functions.
1934// if (parent_type)
1935// parent_type->GetClangFullType();
1936// }
Greg Claytoncab36a32011-12-08 05:16:30 +00001937 }
1938 break;
1939
1940 default:
1941 break;
1942 }
1943 return ResolveType (cu, die);
1944 }
1945 return NULL;
1946}
1947
Greg Clayton6beaaa62011-01-17 03:46:26 +00001948// This function is used when SymbolFileDWARFDebugMap owns a bunch of
1949// SymbolFileDWARF objects to detect if this DWARF file is the one that
1950// can resolve a clang_type.
1951bool
1952SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type)
1953{
1954 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1955 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
1956 return die != NULL;
1957}
1958
1959
Greg Clayton1be10fc2010-09-29 01:12:09 +00001960lldb::clang_type_t
1961SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
1962{
1963 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001964 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1965 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001966 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00001967 {
1968 // We have already resolved this type...
1969 return clang_type;
1970 }
1971 // Once we start resolving this type, remove it from the forward declaration
1972 // map in case anyone child members or other types require this type to get resolved.
1973 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
1974 // are done.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001975 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers);
Greg Clayton73b472d2010-10-27 03:32:59 +00001976
Greg Clayton1be10fc2010-09-29 01:12:09 +00001977
Greg Clayton85ae2e12011-10-18 23:36:41 +00001978 // Disable external storage for this type so we don't get anymore
1979 // clang::ExternalASTSource queries for this type.
1980 ClangASTContext::SetHasExternalStorage (clang_type, false);
1981
Greg Clayton450e3f32010-10-12 02:24:53 +00001982 DWARFDebugInfo* debug_info = DebugInfo();
1983
Greg Clayton53eb1c22012-04-02 22:59:12 +00001984 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001985 Type *type = m_die_to_type.lookup (die);
1986
1987 const dw_tag_t tag = die->Tag();
1988
Greg Claytonbaf95da2012-03-30 23:50:54 +00001989 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
Greg Clayton3bffb082011-12-10 02:15:28 +00001990 if (log)
Greg Claytonbaf95da2012-03-30 23:50:54 +00001991 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00001992 GetObjectFile()->GetModule()->LogMessage (log.get(),
Greg Claytonbaf95da2012-03-30 23:50:54 +00001993 "0x%8.8llx: %s '%s' resolving forward declaration...",
Greg Claytone38a5ed2012-01-05 03:57:59 +00001994 MakeUserID(die->GetOffset()),
1995 DW_TAG_value_to_name(tag),
1996 type->GetName().AsCString());
Greg Claytonbaf95da2012-03-30 23:50:54 +00001997
1998 if (log->GetVerbose())
1999 {
2000 StreamString strm;
2001 Host::Backtrace (strm, 1024);
2002 if (strm.GetData())
2003 log->PutCString(strm.GetData());
2004 }
2005 }
Greg Clayton1be10fc2010-09-29 01:12:09 +00002006 assert (clang_type);
2007 DWARFDebugInfoEntry::Attributes attributes;
2008
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002009 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002010
2011 switch (tag)
2012 {
2013 case DW_TAG_structure_type:
2014 case DW_TAG_union_type:
2015 case DW_TAG_class_type:
Greg Claytonc93237c2010-10-01 20:48:32 +00002016 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002017 LayoutInfo layout_info;
Sean Callanan77a1fd32012-02-27 20:07:01 +00002018
Greg Clayton1be10fc2010-09-29 01:12:09 +00002019 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002020 if (die->HasChildren())
Greg Claytonc93237c2010-10-01 20:48:32 +00002021 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002022
Sean Callanan77a1fd32012-02-27 20:07:01 +00002023 LanguageType class_language = eLanguageTypeUnknown;
2024 bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
2025 if (is_objc_class)
Greg Clayton219cf312012-03-30 00:51:13 +00002026 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002027 class_language = eLanguageTypeObjC;
Greg Clayton219cf312012-03-30 00:51:13 +00002028 // For objective C we don't start the definition when
2029 // the class is created.
2030 ast.StartTagDeclarationDefinition (clang_type);
2031 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002032
2033 int tag_decl_kind = -1;
2034 AccessType default_accessibility = eAccessNone;
2035 if (tag == DW_TAG_structure_type)
2036 {
2037 tag_decl_kind = clang::TTK_Struct;
2038 default_accessibility = eAccessPublic;
2039 }
2040 else if (tag == DW_TAG_union_type)
2041 {
2042 tag_decl_kind = clang::TTK_Union;
2043 default_accessibility = eAccessPublic;
2044 }
2045 else if (tag == DW_TAG_class_type)
2046 {
2047 tag_decl_kind = clang::TTK_Class;
2048 default_accessibility = eAccessPrivate;
2049 }
2050
Greg Clayton53eb1c22012-04-02 22:59:12 +00002051 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002052 std::vector<clang::CXXBaseSpecifier *> base_classes;
2053 std::vector<int> member_accessibilities;
2054 bool is_a_class = false;
2055 // Parse members and base classes first
2056 DWARFDIECollection member_function_dies;
2057
2058 ParseChildMembers (sc,
Greg Clayton53eb1c22012-04-02 22:59:12 +00002059 dwarf_cu,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002060 die,
2061 clang_type,
2062 class_language,
2063 base_classes,
2064 member_accessibilities,
2065 member_function_dies,
2066 default_accessibility,
2067 is_a_class,
2068 layout_info);
2069
2070 // Now parse any methods if there were any...
2071 size_t num_functions = member_function_dies.Size();
2072 if (num_functions > 0)
2073 {
2074 for (size_t i=0; i<num_functions; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002075 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002076 ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytoncaab74e2012-01-28 00:48:57 +00002077 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002078 }
2079
2080 if (class_language == eLanguageTypeObjC)
2081 {
Greg Clayton84db9102012-03-26 23:03:23 +00002082 std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(ast.getASTContext(), clang_type));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002083 if (!class_str.empty())
Greg Claytoncaab74e2012-01-28 00:48:57 +00002084 {
Greg Clayton450e3f32010-10-12 02:24:53 +00002085
Sean Callanan77a1fd32012-02-27 20:07:01 +00002086 DIEArray method_die_offsets;
2087 if (m_using_apple_tables)
Greg Clayton95d87902011-11-11 03:16:25 +00002088 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002089 if (m_apple_objc_ap.get())
2090 m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets);
2091 }
2092 else
2093 {
2094 if (!m_indexed)
2095 Index ();
Greg Claytoncaab74e2012-01-28 00:48:57 +00002096
Sean Callanan77a1fd32012-02-27 20:07:01 +00002097 ConstString class_name (class_str.c_str());
2098 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
2099 }
2100
2101 if (!method_die_offsets.empty())
2102 {
2103 DWARFDebugInfo* debug_info = DebugInfo();
2104
2105 DWARFCompileUnit* method_cu = NULL;
2106 const size_t num_matches = method_die_offsets.size();
2107 for (size_t i=0; i<num_matches; ++i)
Greg Clayton95d87902011-11-11 03:16:25 +00002108 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002109 const dw_offset_t die_offset = method_die_offsets[i];
2110 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
2111
2112 if (method_die)
2113 ResolveType (method_cu, method_die);
2114 else
Greg Claytoncaab74e2012-01-28 00:48:57 +00002115 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002116 if (m_using_apple_tables)
2117 {
2118 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n",
2119 die_offset, class_str.c_str());
2120 }
2121 }
2122 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002123 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002124 }
2125 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002126
2127 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2128 // need to tell the clang type it is actually a class.
2129 if (class_language != eLanguageTypeObjC)
2130 {
2131 if (is_a_class && tag_decl_kind != clang::TTK_Class)
2132 ast.SetTagTypeKind (clang_type, clang::TTK_Class);
2133 }
2134
2135 // Since DW_TAG_structure_type gets used for both classes
2136 // and structures, we may need to set any DW_TAG_member
2137 // fields to have a "private" access if none was specified.
2138 // When we parsed the child members we tracked that actual
2139 // accessibility value for each DW_TAG_member in the
2140 // "member_accessibilities" array. If the value for the
2141 // member is zero, then it was set to the "default_accessibility"
2142 // which for structs was "public". Below we correct this
2143 // by setting any fields to "private" that weren't correctly
2144 // set.
2145 if (is_a_class && !member_accessibilities.empty())
2146 {
2147 // This is a class and all members that didn't have
2148 // their access specified are private.
2149 ast.SetDefaultAccessForRecordFields (clang_type,
2150 eAccessPrivate,
2151 &member_accessibilities.front(),
2152 member_accessibilities.size());
2153 }
2154
2155 if (!base_classes.empty())
2156 {
2157 ast.SetBaseClassesForClassType (clang_type,
2158 &base_classes.front(),
2159 base_classes.size());
2160
2161 // Clang will copy each CXXBaseSpecifier in "base_classes"
2162 // so we have to free them all.
2163 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
2164 base_classes.size());
2165 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002166 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002167 }
Sean Callanane8c0cfb2012-03-02 01:03:45 +00002168
2169 ast.BuildIndirectFields (clang_type);
2170
Sean Callanan77a1fd32012-02-27 20:07:01 +00002171 ast.CompleteTagDeclarationDefinition (clang_type);
Sean Callanan5b26f272012-02-04 08:49:35 +00002172
Greg Claytoncaab74e2012-01-28 00:48:57 +00002173 if (!layout_info.field_offsets.empty())
2174 {
2175 if (type)
2176 layout_info.bit_size = type->GetByteSize() * 8;
2177 if (layout_info.bit_size == 0)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002178 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8;
Greg Claytoncaab74e2012-01-28 00:48:57 +00002179 clang::QualType qual_type(clang::QualType::getFromOpaquePtr(clang_type));
2180 const clang::RecordType *record_type = clang::dyn_cast<clang::RecordType>(qual_type.getTypePtr());
2181 if (record_type)
2182 {
2183 const clang::RecordDecl *record_decl = record_type->getDecl();
2184
2185 if (log)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002186 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002187 GetObjectFile()->GetModule()->LogMessage (log.get(),
Greg Clayton821ac6d2012-01-28 02:22:27 +00002188 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) caching layout info for record_decl = %p, bit_size = %llu, alignment = %llu, field_offsets[%u], base_offsets[0], vbase_offsets[0])",
Greg Claytoncaab74e2012-01-28 00:48:57 +00002189 clang_type,
2190 record_decl,
2191 layout_info.bit_size,
2192 layout_info.alignment,
2193 (uint32_t)layout_info.field_offsets.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002194
Greg Clayton821ac6d2012-01-28 02:22:27 +00002195 llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end();
2196 for (pos = layout_info.field_offsets.begin(); pos != end; ++pos)
2197 {
2198 GetObjectFile()->GetModule()->LogMessage (log.get(),
2199 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field = { bit_offset=%u, name='%s' }",
2200 clang_type,
2201 (uint32_t)pos->second,
2202 pos->first->getNameAsString().c_str());
2203 }
2204 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002205 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2206 }
2207 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002208 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002209
Greg Claytonc93237c2010-10-01 20:48:32 +00002210 return clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002211
2212 case DW_TAG_enumeration_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002213 ast.StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002214 if (die->HasChildren())
2215 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002216 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
2217 ParseChildEnumerators(sc, clang_type, type->GetByteSize(), dwarf_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002218 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002219 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002220 return clang_type;
2221
2222 default:
2223 assert(false && "not a forward clang type decl!");
2224 break;
2225 }
2226 return NULL;
2227}
2228
Greg Claytonc685f8e2010-09-15 04:15:46 +00002229Type*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002230SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002231{
2232 if (type_die != NULL)
2233 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002234 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00002235
Greg Claytonc685f8e2010-09-15 04:15:46 +00002236 if (type == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002237 type = GetTypeForDIE (dwarf_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00002238
Greg Clayton24739922010-10-13 03:15:28 +00002239 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00002240 {
2241 if (type != DIE_IS_BEING_PARSED)
2242 return type;
2243
2244 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
Greg Clayton53eb1c22012-04-02 22:59:12 +00002245 type_die->GetOffset(),
2246 DW_TAG_value_to_name(type_die->Tag()),
2247 type_die->GetName(this, dwarf_cu));
Jim Inghamc3549282012-01-11 02:21:12 +00002248
2249 }
2250 else
2251 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002252 }
2253 return NULL;
2254}
2255
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002256CompileUnit*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002257SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002258{
2259 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002260 if (dwarf_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002261 {
2262 // The symbol vendor doesn't know about this compile unit, we
2263 // need to parse and add it to the symbol vendor object.
Greg Clayton53eb1c22012-04-02 22:59:12 +00002264 return ParseCompileUnit(dwarf_cu, cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002265 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00002266 return (CompileUnit*)dwarf_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002267}
2268
2269bool
Greg Clayton53eb1c22012-04-02 22:59:12 +00002270SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002271{
2272 sc.Clear();
2273 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002274 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002275
Greg Clayton81c22f62011-10-19 18:09:39 +00002276 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002277 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002278 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002279
2280 if (sc.function)
2281 {
Greg Claytone72dfb32012-02-24 01:59:29 +00002282 sc.module_sp = sc.function->CalculateSymbolContextModule();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002283 return true;
2284 }
2285
2286 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002287}
2288
2289uint32_t
2290SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2291{
2292 Timer scoped_timer(__PRETTY_FUNCTION__,
2293 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)",
Greg Claytone72dfb32012-02-24 01:59:29 +00002294 so_addr.GetSection().get(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002295 so_addr.GetOffset(),
2296 resolve_scope);
2297 uint32_t resolved = 0;
2298 if (resolve_scope & ( eSymbolContextCompUnit |
2299 eSymbolContextFunction |
2300 eSymbolContextBlock |
2301 eSymbolContextLineEntry))
2302 {
2303 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2304
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002305 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00002306 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002307 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002308 dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002309 if (cu_offset != DW_INVALID_OFFSET)
2310 {
2311 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002312 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
2313 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002314 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002315 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002316 assert(sc.comp_unit != NULL);
2317 resolved |= eSymbolContextCompUnit;
2318
2319 if (resolve_scope & eSymbolContextLineEntry)
2320 {
2321 LineTable *line_table = sc.comp_unit->GetLineTable();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002322 if (line_table != NULL)
2323 {
2324 if (so_addr.IsLinkedAddress())
2325 {
2326 Address linked_addr (so_addr);
2327 linked_addr.ResolveLinkedAddress();
2328 if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry))
2329 {
2330 resolved |= eSymbolContextLineEntry;
2331 }
2332 }
2333 else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry))
2334 {
2335 resolved |= eSymbolContextLineEntry;
2336 }
2337 }
2338 }
2339
2340 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2341 {
2342 DWARFDebugInfoEntry *function_die = NULL;
2343 DWARFDebugInfoEntry *block_die = NULL;
2344 if (resolve_scope & eSymbolContextBlock)
2345 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002346 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002347 }
2348 else
2349 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002350 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002351 }
2352
2353 if (function_die != NULL)
2354 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002355 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002356 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002357 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002358 }
Greg Clayton12b834d2012-03-29 21:43:25 +00002359 else
2360 {
2361 // We might have had a compile unit that had discontiguous
2362 // address ranges where the gaps are symbols that don't have
2363 // any debug info. Discontiguous compile unit address ranges
2364 // should only happen when there aren't other functions from
2365 // other compile units in these gaps. This helps keep the size
2366 // of the aranges down.
2367 sc.comp_unit = NULL;
2368 resolved &= ~eSymbolContextCompUnit;
2369 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002370
2371 if (sc.function != NULL)
2372 {
2373 resolved |= eSymbolContextFunction;
2374
2375 if (resolve_scope & eSymbolContextBlock)
2376 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00002377 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002378
2379 if (block_die != NULL)
Greg Clayton81c22f62011-10-19 18:09:39 +00002380 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002381 else
Greg Clayton81c22f62011-10-19 18:09:39 +00002382 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002383 if (sc.block)
2384 resolved |= eSymbolContextBlock;
2385 }
2386 }
2387 }
2388 }
2389 }
2390 }
2391 }
2392 return resolved;
2393}
2394
2395
2396
2397uint32_t
2398SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
2399{
2400 const uint32_t prev_size = sc_list.GetSize();
2401 if (resolve_scope & eSymbolContextCompUnit)
2402 {
2403 DWARFDebugInfo* debug_info = DebugInfo();
2404 if (debug_info)
2405 {
2406 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002407 DWARFCompileUnit* dwarf_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002408
Greg Clayton53eb1c22012-04-02 22:59:12 +00002409 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002410 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002411 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002412 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Compare(file_spec, *dc_cu, false) == 0;
2413 if (check_inlines || file_spec_matches_cu_file_spec)
2414 {
2415 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton53eb1c22012-04-02 22:59:12 +00002416 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002417 assert(sc.comp_unit != NULL);
2418
2419 uint32_t file_idx = UINT32_MAX;
2420
2421 // If we are looking for inline functions only and we don't
2422 // find it in the support files, we are done.
2423 if (check_inlines)
2424 {
Jim Ingham87df91b2011-09-23 00:54:11 +00002425 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002426 if (file_idx == UINT32_MAX)
2427 continue;
2428 }
2429
2430 if (line != 0)
2431 {
2432 LineTable *line_table = sc.comp_unit->GetLineTable();
2433
2434 if (line_table != NULL && line != 0)
2435 {
2436 // We will have already looked up the file index if
2437 // we are searching for inline entries.
2438 if (!check_inlines)
Jim Ingham87df91b2011-09-23 00:54:11 +00002439 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002440
2441 if (file_idx != UINT32_MAX)
2442 {
2443 uint32_t found_line;
2444 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
2445 found_line = sc.line_entry.line;
2446
Greg Clayton016a95e2010-09-14 02:20:48 +00002447 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002448 {
2449 sc.function = NULL;
2450 sc.block = NULL;
2451 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2452 {
2453 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
2454 if (file_vm_addr != LLDB_INVALID_ADDRESS)
2455 {
2456 DWARFDebugInfoEntry *function_die = NULL;
2457 DWARFDebugInfoEntry *block_die = NULL;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002458 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002459
2460 if (function_die != NULL)
2461 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002462 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002463 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002464 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002465 }
2466
2467 if (sc.function != NULL)
2468 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00002469 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002470
2471 if (block_die != NULL)
Greg Clayton81c22f62011-10-19 18:09:39 +00002472 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002473 else
Greg Clayton81c22f62011-10-19 18:09:39 +00002474 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002475 }
2476 }
2477 }
2478
2479 sc_list.Append(sc);
2480 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2481 }
2482 }
2483 }
2484 else if (file_spec_matches_cu_file_spec && !check_inlines)
2485 {
2486 // only append the context if we aren't looking for inline call sites
2487 // by file and line and if the file spec matches that of the compile unit
2488 sc_list.Append(sc);
2489 }
2490 }
2491 else if (file_spec_matches_cu_file_spec && !check_inlines)
2492 {
2493 // only append the context if we aren't looking for inline call sites
2494 // by file and line and if the file spec matches that of the compile unit
2495 sc_list.Append(sc);
2496 }
2497
2498 if (!check_inlines)
2499 break;
2500 }
2501 }
2502 }
2503 }
2504 return sc_list.GetSize() - prev_size;
2505}
2506
2507void
2508SymbolFileDWARF::Index ()
2509{
2510 if (m_indexed)
2511 return;
2512 m_indexed = true;
2513 Timer scoped_timer (__PRETTY_FUNCTION__,
2514 "SymbolFileDWARF::Index (%s)",
2515 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
2516
2517 DWARFDebugInfo* debug_info = DebugInfo();
2518 if (debug_info)
2519 {
2520 uint32_t cu_idx = 0;
2521 const uint32_t num_compile_units = GetNumCompileUnits();
2522 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2523 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002524 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002525
Greg Clayton53eb1c22012-04-02 22:59:12 +00002526 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002527
Greg Clayton53eb1c22012-04-02 22:59:12 +00002528 dwarf_cu->Index (cu_idx,
2529 m_function_basename_index,
2530 m_function_fullname_index,
2531 m_function_method_index,
2532 m_function_selector_index,
2533 m_objc_class_selectors_index,
2534 m_global_index,
2535 m_type_index,
2536 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002537
2538 // Keep memory down by clearing DIEs if this generate function
2539 // caused them to be parsed
2540 if (clear_dies)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002541 dwarf_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002542 }
2543
Greg Claytond4a2b372011-09-12 23:21:58 +00002544 m_function_basename_index.Finalize();
2545 m_function_fullname_index.Finalize();
2546 m_function_method_index.Finalize();
2547 m_function_selector_index.Finalize();
2548 m_objc_class_selectors_index.Finalize();
2549 m_global_index.Finalize();
2550 m_type_index.Finalize();
2551 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002552
Greg Clayton24739922010-10-13 03:15:28 +00002553#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00002554 StreamFile s(stdout, false);
Greg Claytonf9eec202011-09-01 23:16:13 +00002555 s.Printf ("DWARF index for '%s/%s':",
Greg Clayton24739922010-10-13 03:15:28 +00002556 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
2557 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
Greg Claytonba2d22d2010-11-13 22:57:37 +00002558 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
2559 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
2560 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
2561 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
2562 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
2563 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00002564 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00002565 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002566#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002567 }
2568}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002569
2570bool
2571SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
2572{
2573 if (namespace_decl == NULL)
2574 {
2575 // Invalid namespace decl which means we aren't matching only things
2576 // in this symbol file, so return true to indicate it matches this
2577 // symbol file.
2578 return true;
2579 }
2580
2581 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
2582
2583 if (namespace_ast == NULL)
2584 return true; // No AST in the "namespace_decl", return true since it
2585 // could then match any symbol file, including this one
2586
2587 if (namespace_ast == GetClangASTContext().getASTContext())
2588 return true; // The ASTs match, return true
2589
2590 // The namespace AST was valid, and it does not match...
Sean Callananc41e68b2011-10-13 21:08:11 +00002591 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2592
2593 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002594 GetObjectFile()->GetModule()->LogMessage(log.get(), "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00002595
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002596 return false;
2597}
2598
Greg Clayton2506a7a2011-10-12 23:34:26 +00002599bool
2600SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
2601 DWARFCompileUnit* cu,
2602 const DWARFDebugInfoEntry* die)
2603{
2604 // No namespace specified, so the answesr i
2605 if (namespace_decl == NULL)
2606 return true;
Sean Callananebe60672011-10-13 21:50:33 +00002607
2608 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002609
Greg Clayton437a1352012-04-09 22:43:43 +00002610 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
2611 clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00002612 if (decl_ctx_die)
Greg Clayton437a1352012-04-09 22:43:43 +00002613 {
Greg Clayton2506a7a2011-10-12 23:34:26 +00002614 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
Greg Clayton437a1352012-04-09 22:43:43 +00002615
Greg Clayton2506a7a2011-10-12 23:34:26 +00002616 if (clang_namespace_decl)
2617 {
2618 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00002619 {
2620 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002621 GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00002622 return false;
Sean Callananebe60672011-10-13 21:50:33 +00002623 }
2624
Greg Clayton437a1352012-04-09 22:43:43 +00002625 if (clang_namespace_decl == die_clang_decl_ctx)
2626 return true;
2627 else
Greg Clayton2506a7a2011-10-12 23:34:26 +00002628 return false;
Greg Clayton2506a7a2011-10-12 23:34:26 +00002629 }
2630 else
2631 {
2632 // We have a namespace_decl that was not NULL but it contained
2633 // a NULL "clang::NamespaceDecl", so this means the global namespace
2634 // So as long the the contained decl context DIE isn't a namespace
2635 // we should be ok.
2636 if (decl_ctx_die->Tag() != DW_TAG_namespace)
2637 return true;
2638 }
2639 }
Sean Callananebe60672011-10-13 21:50:33 +00002640
2641 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002642 GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00002643
Greg Clayton2506a7a2011-10-12 23:34:26 +00002644 return false;
2645}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002646uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00002647SymbolFileDWARF::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 +00002648{
Greg Clayton21f2a492011-10-06 00:09:08 +00002649 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2650
2651 if (log)
2652 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002653 GetObjectFile()->GetModule()->LogMessage (log.get(),
2654 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
2655 name.GetCString(),
2656 namespace_decl,
2657 append,
2658 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002659 }
Sean Callanan213fdb82011-10-13 01:49:10 +00002660
2661 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2662 return 0;
2663
Greg Claytonc685f8e2010-09-15 04:15:46 +00002664 DWARFDebugInfo* info = DebugInfo();
2665 if (info == NULL)
2666 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002667
2668 // If we aren't appending the results to this list, then clear the list
2669 if (!append)
2670 variables.Clear();
2671
2672 // Remember how many variables are in the list before we search in case
2673 // we are appending the results to a variable list.
2674 const uint32_t original_size = variables.GetSize();
2675
Greg Claytond4a2b372011-09-12 23:21:58 +00002676 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002677
Greg Clayton97fbc342011-10-20 22:30:33 +00002678 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002679 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002680 if (m_apple_names_ap.get())
2681 {
2682 const char *name_cstr = name.GetCString();
2683 const char *base_name_start;
2684 const char *base_name_end = NULL;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002685
Greg Clayton97fbc342011-10-20 22:30:33 +00002686 if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end))
2687 base_name_start = name_cstr;
2688
2689 m_apple_names_ap->FindByName (base_name_start, die_offsets);
2690 }
Greg Clayton7f995132011-10-04 22:41:51 +00002691 }
2692 else
2693 {
2694 // Index the DWARF if we haven't already
2695 if (!m_indexed)
2696 Index ();
2697
2698 m_global_index.Find (name, die_offsets);
2699 }
2700
Greg Clayton437a1352012-04-09 22:43:43 +00002701 const size_t num_die_matches = die_offsets.size();
2702 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002703 {
Greg Clayton7f995132011-10-04 22:41:51 +00002704 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00002705 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00002706 assert (sc.module_sp);
2707
Greg Claytond4a2b372011-09-12 23:21:58 +00002708 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00002709 DWARFCompileUnit* dwarf_cu = NULL;
2710 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton437a1352012-04-09 22:43:43 +00002711 bool done = false;
2712 for (size_t i=0; i<num_die_matches && !done; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002713 {
2714 const dw_offset_t die_offset = die_offsets[i];
2715 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002716
Greg Clayton95d87902011-11-11 03:16:25 +00002717 if (die)
2718 {
Greg Clayton437a1352012-04-09 22:43:43 +00002719 switch (die->Tag())
2720 {
2721 default:
2722 case DW_TAG_subprogram:
2723 case DW_TAG_inlined_subroutine:
2724 case DW_TAG_try_block:
2725 case DW_TAG_catch_block:
2726 break;
2727
2728 case DW_TAG_variable:
2729 {
2730 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
2731 assert(sc.comp_unit != NULL);
2732
2733 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2734 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002735
Greg Clayton437a1352012-04-09 22:43:43 +00002736 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002737
Greg Clayton437a1352012-04-09 22:43:43 +00002738 if (variables.GetSize() - original_size >= max_matches)
2739 done = true;
2740 }
2741 break;
2742 }
Greg Clayton95d87902011-11-11 03:16:25 +00002743 }
2744 else
2745 {
2746 if (m_using_apple_tables)
2747 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002748 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
2749 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00002750 }
2751 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002752 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002753 }
2754
2755 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00002756 const uint32_t num_matches = variables.GetSize() - original_size;
2757 if (log && num_matches > 0)
2758 {
2759 GetObjectFile()->GetModule()->LogMessage (log.get(),
2760 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u",
2761 name.GetCString(),
2762 namespace_decl,
2763 append,
2764 max_matches,
2765 num_matches);
2766 }
2767 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002768}
2769
2770uint32_t
2771SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
2772{
Greg Clayton21f2a492011-10-06 00:09:08 +00002773 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2774
2775 if (log)
2776 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002777 GetObjectFile()->GetModule()->LogMessage (log.get(),
2778 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
2779 regex.GetText(),
2780 append,
2781 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002782 }
2783
Greg Claytonc685f8e2010-09-15 04:15:46 +00002784 DWARFDebugInfo* info = DebugInfo();
2785 if (info == NULL)
2786 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002787
2788 // If we aren't appending the results to this list, then clear the list
2789 if (!append)
2790 variables.Clear();
2791
2792 // Remember how many variables are in the list before we search in case
2793 // we are appending the results to a variable list.
2794 const uint32_t original_size = variables.GetSize();
2795
Greg Clayton7f995132011-10-04 22:41:51 +00002796 DIEArray die_offsets;
2797
Greg Clayton97fbc342011-10-20 22:30:33 +00002798 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002799 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002800 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00002801 {
2802 DWARFMappedHash::DIEInfoArray hash_data_array;
2803 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
2804 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
2805 }
Greg Clayton7f995132011-10-04 22:41:51 +00002806 }
2807 else
2808 {
2809 // Index the DWARF if we haven't already
2810 if (!m_indexed)
2811 Index ();
2812
2813 m_global_index.Find (regex, die_offsets);
2814 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002815
Greg Claytonc685f8e2010-09-15 04:15:46 +00002816 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00002817 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002818 assert (sc.module_sp);
2819
Greg Claytond4a2b372011-09-12 23:21:58 +00002820 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002821 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00002822 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002823 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002824 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002825 DWARFDebugInfo* debug_info = DebugInfo();
2826 for (size_t i=0; i<num_matches; ++i)
2827 {
2828 const dw_offset_t die_offset = die_offsets[i];
2829 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00002830
2831 if (die)
2832 {
2833 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002834
Greg Clayton95d87902011-11-11 03:16:25 +00002835 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002836
Greg Clayton95d87902011-11-11 03:16:25 +00002837 if (variables.GetSize() - original_size >= max_matches)
2838 break;
2839 }
2840 else
2841 {
2842 if (m_using_apple_tables)
2843 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002844 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
2845 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00002846 }
2847 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002848 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002849 }
2850
2851 // Return the number of variable that were appended to the list
2852 return variables.GetSize() - original_size;
2853}
2854
Greg Claytonaa044962011-10-13 00:59:38 +00002855
Jim Ingham4cda6e02011-10-07 22:23:45 +00002856bool
2857SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
2858 DWARFCompileUnit *&dwarf_cu,
2859 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00002860{
Greg Claytonaa044962011-10-13 00:59:38 +00002861 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2862 return ResolveFunction (dwarf_cu, die, sc_list);
2863}
2864
2865
2866bool
2867SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
2868 const DWARFDebugInfoEntry *die,
2869 SymbolContextList& sc_list)
2870{
Greg Clayton9e315582011-09-02 04:03:59 +00002871 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00002872
2873 if (die == NULL)
2874 return false;
2875
Jim Ingham4cda6e02011-10-07 22:23:45 +00002876 // If we were passed a die that is not a function, just return false...
2877 if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine)
2878 return false;
2879
2880 const DWARFDebugInfoEntry* inlined_die = NULL;
2881 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00002882 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002883 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00002884
Jim Ingham4cda6e02011-10-07 22:23:45 +00002885 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00002886 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002887 if (die->Tag() == DW_TAG_subprogram)
2888 break;
Greg Clayton9e315582011-09-02 04:03:59 +00002889 }
2890 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002891 assert (die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00002892 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00002893 {
2894 Address addr;
2895 // Parse all blocks if needed
2896 if (inlined_die)
2897 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002898 sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset()));
Jim Ingham4cda6e02011-10-07 22:23:45 +00002899 assert (sc.block != NULL);
2900 if (sc.block->GetStartAddress (addr) == false)
2901 addr.Clear();
2902 }
2903 else
2904 {
2905 sc.block = NULL;
2906 addr = sc.function->GetAddressRange().GetBaseAddress();
2907 }
2908
2909 if (addr.IsValid())
2910 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002911 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00002912 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002913 }
2914 }
2915
Greg Claytonaa044962011-10-13 00:59:38 +00002916 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00002917}
2918
Greg Clayton7f995132011-10-04 22:41:51 +00002919void
2920SymbolFileDWARF::FindFunctions (const ConstString &name,
2921 const NameToDIE &name_to_die,
2922 SymbolContextList& sc_list)
2923{
Greg Claytond4a2b372011-09-12 23:21:58 +00002924 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002925 if (name_to_die.Find (name, die_offsets))
2926 {
2927 ParseFunctions (die_offsets, sc_list);
2928 }
2929}
2930
2931
2932void
2933SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2934 const NameToDIE &name_to_die,
2935 SymbolContextList& sc_list)
2936{
2937 DIEArray die_offsets;
2938 if (name_to_die.Find (regex, die_offsets))
2939 {
2940 ParseFunctions (die_offsets, sc_list);
2941 }
2942}
2943
2944
2945void
2946SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2947 const DWARFMappedHash::MemoryTable &memory_table,
2948 SymbolContextList& sc_list)
2949{
2950 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00002951 DWARFMappedHash::DIEInfoArray hash_data_array;
2952 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00002953 {
Greg Claytond1767f02011-12-08 02:13:16 +00002954 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Greg Clayton7f995132011-10-04 22:41:51 +00002955 ParseFunctions (die_offsets, sc_list);
2956 }
2957}
2958
2959void
2960SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
2961 SymbolContextList& sc_list)
2962{
2963 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002964 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002965 {
Greg Clayton7f995132011-10-04 22:41:51 +00002966 SymbolContext sc;
Greg Clayton7f995132011-10-04 22:41:51 +00002967
2968 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002969 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00002970 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002971 const dw_offset_t die_offset = die_offsets[i];
Jim Ingham4cda6e02011-10-07 22:23:45 +00002972 ResolveFunction (die_offset, dwarf_cu, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002973 }
2974 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002975}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002976
Jim Ingham4cda6e02011-10-07 22:23:45 +00002977bool
2978SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
2979 const DWARFCompileUnit *dwarf_cu,
2980 uint32_t name_type_mask,
2981 const char *partial_name,
2982 const char *base_name_start,
2983 const char *base_name_end)
2984{
2985 // If we are looking only for methods, throw away all the ones that aren't in C++ classes:
2986 if (name_type_mask == eFunctionNameTypeMethod
2987 || name_type_mask == eFunctionNameTypeBase)
2988 {
Greg Claytonf0705c82011-10-22 03:33:13 +00002989 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
2990 if (!containing_decl_ctx)
2991 return false;
2992
2993 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
2994
2995 if (!is_cxx_method && name_type_mask == eFunctionNameTypeMethod)
2996 return false;
2997 if (is_cxx_method && name_type_mask == eFunctionNameTypeBase)
2998 return false;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002999 }
3000
3001 // Now we need to check whether the name we got back for this type matches the extra specifications
3002 // that were in the name we're looking up:
3003 if (base_name_start != partial_name || *base_name_end != '\0')
3004 {
3005 // First see if the stuff to the left matches the full name. To do that let's see if
3006 // we can pull out the mips linkage name attribute:
3007
3008 Mangled best_name;
3009
3010 DWARFDebugInfoEntry::Attributes attributes;
3011 die->GetAttributes(this, dwarf_cu, NULL, attributes);
3012 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
3013 if (idx != UINT32_MAX)
3014 {
3015 DWARFFormValue form_value;
3016 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
3017 {
3018 const char *name = form_value.AsCString(&get_debug_str_data());
3019 best_name.SetValue (name, true);
3020 }
3021 }
3022 if (best_name)
3023 {
3024 const char *demangled = best_name.GetDemangledName().GetCString();
3025 if (demangled)
3026 {
3027 std::string name_no_parens(partial_name, base_name_end - partial_name);
Jim Ingham85c13d72012-03-02 02:24:42 +00003028 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str());
3029 if (partial_in_demangled == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003030 return false;
Jim Ingham85c13d72012-03-02 02:24:42 +00003031 else
3032 {
3033 // Sort out the case where our name is something like "Process::Destroy" and the match is
3034 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on
3035 // namespace boundaries...
3036
3037 if (partial_name[0] == ':' && partial_name[1] == ':')
3038 {
3039 // The partial name was already on a namespace boundary so all matches are good.
3040 return true;
3041 }
3042 else if (partial_in_demangled == demangled)
3043 {
3044 // They both start the same, so this is an good match.
3045 return true;
3046 }
3047 else
3048 {
3049 if (partial_in_demangled - demangled == 1)
3050 {
3051 // Only one character difference, can't be a namespace boundary...
3052 return false;
3053 }
3054 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':')
3055 {
3056 // We are on a namespace boundary, so this is also good.
3057 return true;
3058 }
3059 else
3060 return false;
3061 }
3062 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003063 }
3064 }
3065 }
3066
3067 return true;
3068}
Greg Claytonc685f8e2010-09-15 04:15:46 +00003069
Greg Clayton0c5cd902010-06-28 21:30:43 +00003070uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00003071SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00003072 const lldb_private::ClangNamespaceDecl *namespace_decl,
Sean Callanan9df05fb2012-02-10 22:52:19 +00003073 uint32_t name_type_mask,
3074 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00003075 bool append,
3076 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00003077{
3078 Timer scoped_timer (__PRETTY_FUNCTION__,
3079 "SymbolFileDWARF::FindFunctions (name = '%s')",
3080 name.AsCString());
3081
Greg Clayton21f2a492011-10-06 00:09:08 +00003082 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3083
3084 if (log)
3085 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003086 GetObjectFile()->GetModule()->LogMessage (log.get(),
3087 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
3088 name.GetCString(),
3089 name_type_mask,
3090 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003091 }
3092
Greg Clayton0c5cd902010-06-28 21:30:43 +00003093 // If we aren't appending the results to this list, then clear the list
3094 if (!append)
3095 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003096
3097 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3098 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003099
3100 // If name is empty then we won't find anything.
3101 if (name.IsEmpty())
3102 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00003103
3104 // Remember how many sc_list are in the list before we search in case
3105 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00003106
Greg Clayton9e315582011-09-02 04:03:59 +00003107 const uint32_t original_size = sc_list.GetSize();
Greg Clayton0c5cd902010-06-28 21:30:43 +00003108
Jim Ingham4cda6e02011-10-07 22:23:45 +00003109 const char *name_cstr = name.GetCString();
3110 uint32_t effective_name_type_mask = eFunctionNameTypeNone;
3111 const char *base_name_start = name_cstr;
3112 const char *base_name_end = name_cstr + strlen(name_cstr);
3113
3114 if (name_type_mask & eFunctionNameTypeAuto)
3115 {
3116 if (CPPLanguageRuntime::IsCPPMangledName (name_cstr))
3117 effective_name_type_mask = eFunctionNameTypeFull;
3118 else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr))
3119 effective_name_type_mask = eFunctionNameTypeFull;
3120 else
3121 {
3122 if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
3123 effective_name_type_mask |= eFunctionNameTypeSelector;
3124
3125 if (CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
3126 effective_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
3127 }
3128 }
3129 else
3130 {
3131 effective_name_type_mask = name_type_mask;
3132 if (effective_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase)
3133 {
3134 // If they've asked for a CPP method or function name and it can't be that, we don't
3135 // even need to search for CPP methods or names.
3136 if (!CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
3137 {
3138 effective_name_type_mask &= ~(eFunctionNameTypeMethod | eFunctionNameTypeBase);
3139 if (effective_name_type_mask == eFunctionNameTypeNone)
3140 return 0;
3141 }
3142 }
3143
3144 if (effective_name_type_mask & eFunctionNameTypeSelector)
3145 {
3146 if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
3147 {
3148 effective_name_type_mask &= ~(eFunctionNameTypeSelector);
3149 if (effective_name_type_mask == eFunctionNameTypeNone)
3150 return 0;
3151 }
3152 }
3153 }
3154
3155 DWARFDebugInfo* info = DebugInfo();
3156 if (info == NULL)
3157 return 0;
3158
Greg Claytonaa044962011-10-13 00:59:38 +00003159 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton97fbc342011-10-20 22:30:33 +00003160 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00003161 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003162 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003163 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003164
3165 DIEArray die_offsets;
3166
3167 uint32_t num_matches = 0;
3168
3169 if (effective_name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00003170 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003171 // If they asked for the full name, match what they typed. At some point we may
3172 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
3173 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00003174 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003175 for (uint32_t i = 0; i < num_matches; i++)
3176 {
Greg Clayton95d87902011-11-11 03:16:25 +00003177 const dw_offset_t die_offset = die_offsets[i];
3178 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00003179 if (die)
3180 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003181 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3182 continue;
3183
Sean Callanan9df05fb2012-02-10 22:52:19 +00003184 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3185 continue;
3186
Greg Claytonaa044962011-10-13 00:59:38 +00003187 ResolveFunction (dwarf_cu, die, sc_list);
3188 }
Greg Clayton95d87902011-11-11 03:16:25 +00003189 else
3190 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003191 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3192 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003193 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003194 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003195 }
3196 else
3197 {
3198 if (effective_name_type_mask & eFunctionNameTypeSelector)
3199 {
3200 if (namespace_decl && *namespace_decl)
3201 return 0; // no selectors in namespaces
3202
3203 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3204 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
3205 // and if it is an ObjC method name, we're good.
3206
3207 for (uint32_t i = 0; i < num_matches; i++)
3208 {
Greg Clayton95d87902011-11-11 03:16:25 +00003209 const dw_offset_t die_offset = die_offsets[i];
3210 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton97fbc342011-10-20 22:30:33 +00003211 if (die)
3212 {
3213 const char *die_name = die->GetName(this, dwarf_cu);
3214 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
Sean Callanan9df05fb2012-02-10 22:52:19 +00003215 {
3216 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3217 continue;
3218
Greg Clayton97fbc342011-10-20 22:30:33 +00003219 ResolveFunction (dwarf_cu, die, sc_list);
Sean Callanan9df05fb2012-02-10 22:52:19 +00003220 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003221 }
Greg Clayton95d87902011-11-11 03:16:25 +00003222 else
3223 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003224 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3225 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003226 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003227 }
3228 die_offsets.clear();
3229 }
3230
3231 if (effective_name_type_mask & eFunctionNameTypeMethod
3232 || effective_name_type_mask & eFunctionNameTypeBase)
3233 {
3234 if ((effective_name_type_mask & eFunctionNameTypeMethod) &&
3235 (namespace_decl && *namespace_decl))
3236 return 0; // no methods in namespaces
3237
3238 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
3239 // extract the base name, look that up, and if there is any other information in the name we were
3240 // passed in we have to post-filter based on that.
3241
3242 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
3243 std::string base_name(base_name_start, base_name_end - base_name_start);
3244 num_matches = m_apple_names_ap->FindByName (base_name.c_str(), die_offsets);
3245
3246 for (uint32_t i = 0; i < num_matches; i++)
3247 {
Greg Clayton95d87902011-11-11 03:16:25 +00003248 const dw_offset_t die_offset = die_offsets[i];
3249 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton97fbc342011-10-20 22:30:33 +00003250 if (die)
3251 {
3252 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3253 continue;
3254
3255 if (!FunctionDieMatchesPartialName(die,
3256 dwarf_cu,
3257 effective_name_type_mask,
3258 name_cstr,
3259 base_name_start,
3260 base_name_end))
3261 continue;
Sean Callanan9df05fb2012-02-10 22:52:19 +00003262
3263 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3264 continue;
Greg Clayton97fbc342011-10-20 22:30:33 +00003265
3266 // If we get to here, the die is good, and we should add it:
3267 ResolveFunction (dwarf_cu, die, sc_list);
3268 }
Greg Clayton95d87902011-11-11 03:16:25 +00003269 else
3270 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003271 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3272 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003273 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003274 }
3275 die_offsets.clear();
3276 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003277 }
3278 }
Greg Clayton7f995132011-10-04 22:41:51 +00003279 }
3280 else
3281 {
3282
3283 // Index the DWARF if we haven't already
3284 if (!m_indexed)
3285 Index ();
3286
Greg Clayton7f995132011-10-04 22:41:51 +00003287 if (name_type_mask & eFunctionNameTypeFull)
3288 FindFunctions (name, m_function_fullname_index, sc_list);
3289
Jim Ingham4cda6e02011-10-07 22:23:45 +00003290 std::string base_name(base_name_start, base_name_end - base_name_start);
3291 ConstString base_name_const(base_name.c_str());
3292 DIEArray die_offsets;
3293 DWARFCompileUnit *dwarf_cu = NULL;
3294
3295 if (effective_name_type_mask & eFunctionNameTypeBase)
3296 {
3297 uint32_t num_base = m_function_basename_index.Find(base_name_const, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00003298 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003299 {
Greg Claytonaa044962011-10-13 00:59:38 +00003300 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3301 if (die)
3302 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003303 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3304 continue;
3305
Greg Claytonaa044962011-10-13 00:59:38 +00003306 if (!FunctionDieMatchesPartialName(die,
3307 dwarf_cu,
3308 effective_name_type_mask,
3309 name_cstr,
3310 base_name_start,
3311 base_name_end))
3312 continue;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003313
Sean Callanan9df05fb2012-02-10 22:52:19 +00003314 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3315 continue;
3316
Greg Claytonaa044962011-10-13 00:59:38 +00003317 // If we get to here, the die is good, and we should add it:
3318 ResolveFunction (dwarf_cu, die, sc_list);
3319 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003320 }
3321 die_offsets.clear();
3322 }
3323
Jim Inghamea8005a2011-10-11 01:18:11 +00003324 if (effective_name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003325 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003326 if (namespace_decl && *namespace_decl)
3327 return 0; // no methods in namespaces
3328
Jim Ingham4cda6e02011-10-07 22:23:45 +00003329 uint32_t num_base = m_function_method_index.Find(base_name_const, die_offsets);
3330 {
Greg Claytonaa044962011-10-13 00:59:38 +00003331 for (uint32_t i = 0; i < num_base; i++)
3332 {
3333 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3334 if (die)
3335 {
3336 if (!FunctionDieMatchesPartialName(die,
3337 dwarf_cu,
3338 effective_name_type_mask,
3339 name_cstr,
3340 base_name_start,
3341 base_name_end))
3342 continue;
3343
Sean Callanan9df05fb2012-02-10 22:52:19 +00003344 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3345 continue;
3346
Greg Claytonaa044962011-10-13 00:59:38 +00003347 // If we get to here, the die is good, and we should add it:
3348 ResolveFunction (dwarf_cu, die, sc_list);
3349 }
3350 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003351 }
3352 die_offsets.clear();
3353 }
Greg Clayton7f995132011-10-04 22:41:51 +00003354
Sean Callanan213fdb82011-10-13 01:49:10 +00003355 if ((effective_name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003356 {
Greg Clayton7f995132011-10-04 22:41:51 +00003357 FindFunctions (name, m_function_selector_index, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003358 }
3359
Greg Clayton4d01ace2011-09-29 16:58:15 +00003360 }
3361
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003362 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003363 const uint32_t num_matches = sc_list.GetSize() - original_size;
3364
3365 if (log && num_matches > 0)
3366 {
3367 GetObjectFile()->GetModule()->LogMessage (log.get(),
3368 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list) => %u",
3369 name.GetCString(),
3370 name_type_mask,
3371 append,
3372 num_matches);
3373 }
3374 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003375}
3376
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003377uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00003378SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003379{
3380 Timer scoped_timer (__PRETTY_FUNCTION__,
3381 "SymbolFileDWARF::FindFunctions (regex = '%s')",
3382 regex.GetText());
3383
Greg Clayton21f2a492011-10-06 00:09:08 +00003384 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3385
3386 if (log)
3387 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003388 GetObjectFile()->GetModule()->LogMessage (log.get(),
3389 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
3390 regex.GetText(),
3391 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003392 }
3393
3394
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003395 // If we aren't appending the results to this list, then clear the list
3396 if (!append)
3397 sc_list.Clear();
3398
3399 // Remember how many sc_list are in the list before we search in case
3400 // we are appending the results to a variable list.
3401 uint32_t original_size = sc_list.GetSize();
3402
Greg Clayton97fbc342011-10-20 22:30:33 +00003403 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003404 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003405 if (m_apple_names_ap.get())
3406 FindFunctions (regex, *m_apple_names_ap, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003407 }
3408 else
3409 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003410 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00003411 if (!m_indexed)
3412 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003413
Greg Clayton7f995132011-10-04 22:41:51 +00003414 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003415
Greg Clayton7f995132011-10-04 22:41:51 +00003416 FindFunctions (regex, m_function_fullname_index, sc_list);
3417 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003418
3419 // Return the number of variable that were appended to the list
3420 return sc_list.GetSize() - original_size;
3421}
Jim Ingham318c9f22011-08-26 19:44:13 +00003422
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003423uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00003424SymbolFileDWARF::FindTypes (const SymbolContext& sc,
3425 const ConstString &name,
3426 const lldb_private::ClangNamespaceDecl *namespace_decl,
3427 bool append,
3428 uint32_t max_matches,
3429 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003430{
Greg Claytonc685f8e2010-09-15 04:15:46 +00003431 DWARFDebugInfo* info = DebugInfo();
3432 if (info == NULL)
3433 return 0;
3434
Greg Clayton21f2a492011-10-06 00:09:08 +00003435 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3436
3437 if (log)
3438 {
Greg Clayton437a1352012-04-09 22:43:43 +00003439 if (namespace_decl)
3440 {
3441 GetObjectFile()->GetModule()->LogMessage (log.get(),
3442 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)",
3443 name.GetCString(),
3444 namespace_decl->GetNamespaceDecl(),
3445 namespace_decl->GetQualifiedName().c_str(),
3446 append,
3447 max_matches);
3448 }
3449 else
3450 {
3451 GetObjectFile()->GetModule()->LogMessage (log.get(),
3452 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)",
3453 name.GetCString(),
3454 append,
3455 max_matches);
3456 }
Greg Clayton21f2a492011-10-06 00:09:08 +00003457 }
3458
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003459 // If we aren't appending the results to this list, then clear the list
3460 if (!append)
3461 types.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003462
3463 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3464 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003465
Greg Claytond4a2b372011-09-12 23:21:58 +00003466 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003467
Greg Clayton97fbc342011-10-20 22:30:33 +00003468 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003469 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003470 if (m_apple_types_ap.get())
3471 {
3472 const char *name_cstr = name.GetCString();
3473 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3474 }
Greg Clayton7f995132011-10-04 22:41:51 +00003475 }
3476 else
3477 {
3478 if (!m_indexed)
3479 Index ();
3480
3481 m_type_index.Find (name, die_offsets);
3482 }
3483
Greg Clayton437a1352012-04-09 22:43:43 +00003484 const size_t num_die_matches = die_offsets.size();
Greg Clayton7f995132011-10-04 22:41:51 +00003485
Greg Clayton437a1352012-04-09 22:43:43 +00003486 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003487 {
Greg Clayton7f995132011-10-04 22:41:51 +00003488 const uint32_t initial_types_size = types.GetSize();
3489 DWARFCompileUnit* dwarf_cu = NULL;
3490 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003491 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00003492 for (size_t i=0; i<num_die_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003493 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003494 const dw_offset_t die_offset = die_offsets[i];
3495 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3496
Greg Clayton95d87902011-11-11 03:16:25 +00003497 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00003498 {
Greg Clayton95d87902011-11-11 03:16:25 +00003499 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3500 continue;
3501
3502 Type *matching_type = ResolveType (dwarf_cu, die);
3503 if (matching_type)
3504 {
3505 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003506 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00003507 if (types.GetSize() >= max_matches)
3508 break;
3509 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00003510 }
Greg Clayton95d87902011-11-11 03:16:25 +00003511 else
3512 {
3513 if (m_using_apple_tables)
3514 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003515 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
3516 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003517 }
3518 }
3519
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003520 }
Greg Clayton437a1352012-04-09 22:43:43 +00003521 const uint32_t num_matches = types.GetSize() - initial_types_size;
3522 if (log && num_matches)
3523 {
3524 if (namespace_decl)
3525 {
3526 GetObjectFile()->GetModule()->LogMessage (log.get(),
3527 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u",
3528 name.GetCString(),
3529 namespace_decl->GetNamespaceDecl(),
3530 namespace_decl->GetQualifiedName().c_str(),
3531 append,
3532 max_matches,
3533 num_matches);
3534 }
3535 else
3536 {
3537 GetObjectFile()->GetModule()->LogMessage (log.get(),
3538 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u",
3539 name.GetCString(),
3540 append,
3541 max_matches,
3542 num_matches);
3543 }
3544 }
3545 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003546 }
Greg Clayton7f995132011-10-04 22:41:51 +00003547 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003548}
3549
3550
Greg Clayton526e5af2010-11-13 03:52:47 +00003551ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00003552SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00003553 const ConstString &name,
3554 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00003555{
Greg Clayton21f2a492011-10-06 00:09:08 +00003556 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3557
3558 if (log)
3559 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003560 GetObjectFile()->GetModule()->LogMessage (log.get(),
3561 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
3562 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00003563 }
Sean Callanan213fdb82011-10-13 01:49:10 +00003564
3565 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
3566 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00003567
Greg Clayton526e5af2010-11-13 03:52:47 +00003568 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003569 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00003570 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00003571 {
Greg Clayton7f995132011-10-04 22:41:51 +00003572 DIEArray die_offsets;
3573
Greg Clayton526e5af2010-11-13 03:52:47 +00003574 // Index if we already haven't to make sure the compile units
3575 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00003576 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003577 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003578 if (m_apple_namespaces_ap.get())
3579 {
3580 const char *name_cstr = name.GetCString();
3581 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
3582 }
Greg Clayton7f995132011-10-04 22:41:51 +00003583 }
3584 else
3585 {
3586 if (!m_indexed)
3587 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00003588
Greg Clayton7f995132011-10-04 22:41:51 +00003589 m_namespace_index.Find (name, die_offsets);
3590 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003591
3592 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00003593 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003594 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003595 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00003596 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003597 DWARFDebugInfo* debug_info = DebugInfo();
3598 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00003599 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003600 const dw_offset_t die_offset = die_offsets[i];
3601 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00003602
Greg Clayton95d87902011-11-11 03:16:25 +00003603 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00003604 {
Greg Clayton95d87902011-11-11 03:16:25 +00003605 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
3606 continue;
3607
3608 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
3609 if (clang_namespace_decl)
3610 {
3611 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
3612 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
Greg Claytond1767f02011-12-08 02:13:16 +00003613 break;
Greg Clayton95d87902011-11-11 03:16:25 +00003614 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003615 }
Greg Clayton95d87902011-11-11 03:16:25 +00003616 else
3617 {
3618 if (m_using_apple_tables)
3619 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003620 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
3621 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003622 }
3623 }
3624
Greg Clayton526e5af2010-11-13 03:52:47 +00003625 }
3626 }
Greg Clayton96d7d742010-11-10 23:42:09 +00003627 }
Greg Clayton437a1352012-04-09 22:43:43 +00003628 if (log && namespace_decl.GetNamespaceDecl())
3629 {
3630 GetObjectFile()->GetModule()->LogMessage (log.get(),
3631 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"",
3632 name.GetCString(),
3633 namespace_decl.GetNamespaceDecl(),
3634 namespace_decl.GetQualifiedName().c_str());
3635 }
3636
Greg Clayton526e5af2010-11-13 03:52:47 +00003637 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003638}
3639
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003640uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003641SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003642{
3643 // Remember how many sc_list are in the list before we search in case
3644 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003645 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003646
3647 const uint32_t num_die_offsets = die_offsets.size();
3648 // Parse all of the types we found from the pubtypes matches
3649 uint32_t i;
3650 uint32_t num_matches = 0;
3651 for (i = 0; i < num_die_offsets; ++i)
3652 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003653 Type *matching_type = ResolveTypeUID (die_offsets[i]);
3654 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003655 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003656 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003657 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003658 ++num_matches;
3659 if (num_matches >= max_matches)
3660 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003661 }
3662 }
3663
3664 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003665 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003666}
3667
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003668
3669size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00003670SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
3671 clang::DeclContext *containing_decl_ctx,
Greg Clayton5113dc82011-08-12 06:47:54 +00003672 DWARFCompileUnit* dwarf_cu,
3673 const DWARFDebugInfoEntry *parent_die,
3674 bool skip_artificial,
3675 bool &is_static,
3676 TypeList* type_list,
3677 std::vector<clang_type_t>& function_param_types,
3678 std::vector<clang::ParmVarDecl*>& function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00003679 unsigned &type_quals,
3680 ClangASTContext::TemplateParameterInfos &template_param_infos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003681{
3682 if (parent_die == NULL)
3683 return 0;
3684
Greg Claytond88d7592010-09-15 08:33:30 +00003685 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3686
Greg Clayton7fedea22010-11-16 02:10:54 +00003687 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003688 const DWARFDebugInfoEntry *die;
3689 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3690 {
3691 dw_tag_t tag = die->Tag();
3692 switch (tag)
3693 {
3694 case DW_TAG_formal_parameter:
3695 {
3696 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003697 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003698 if (num_attributes > 0)
3699 {
3700 const char *name = NULL;
3701 Declaration decl;
3702 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003703 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003704 // one of None, Auto, Register, Extern, Static, PrivateExtern
3705
Sean Callanane2ef6e32010-09-23 03:01:22 +00003706 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003707 uint32_t i;
3708 for (i=0; i<num_attributes; ++i)
3709 {
3710 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3711 DWARFFormValue form_value;
3712 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3713 {
3714 switch (attr)
3715 {
3716 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3717 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3718 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3719 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
3720 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003721 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003722 case DW_AT_location:
3723 // if (form_value.BlockData())
3724 // {
3725 // const DataExtractor& debug_info_data = debug_info();
3726 // uint32_t block_length = form_value.Unsigned();
3727 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
3728 // }
3729 // else
3730 // {
3731 // }
3732 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003733 case DW_AT_const_value:
3734 case DW_AT_default_value:
3735 case DW_AT_description:
3736 case DW_AT_endianity:
3737 case DW_AT_is_optional:
3738 case DW_AT_segment:
3739 case DW_AT_variable_parameter:
3740 default:
3741 case DW_AT_abstract_origin:
3742 case DW_AT_sibling:
3743 break;
3744 }
3745 }
3746 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00003747
Greg Clayton0fffff52010-09-24 05:15:53 +00003748 bool skip = false;
3749 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003750 {
Greg Clayton0fffff52010-09-24 05:15:53 +00003751 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00003752 {
3753 // In order to determine if a C++ member function is
3754 // "const" we have to look at the const-ness of "this"...
3755 // Ugly, but that
3756 if (arg_idx == 0)
3757 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003758 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00003759 {
Greg Clayton5113dc82011-08-12 06:47:54 +00003760 // Often times compilers omit the "this" name for the
3761 // specification DIEs, so we can't rely upon the name
3762 // being in the formal parameter DIE...
3763 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00003764 {
Greg Clayton5113dc82011-08-12 06:47:54 +00003765 Type *this_type = ResolveTypeUID (param_type_die_offset);
3766 if (this_type)
3767 {
3768 uint32_t encoding_mask = this_type->GetEncodingMask();
3769 if (encoding_mask & Type::eEncodingIsPointerUID)
3770 {
3771 is_static = false;
3772
3773 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
3774 type_quals |= clang::Qualifiers::Const;
3775 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
3776 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00003777 }
3778 }
3779 }
3780 }
3781 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003782 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00003783 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003784 else
3785 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003786
Greg Clayton0fffff52010-09-24 05:15:53 +00003787 // HACK: Objective C formal parameters "self" and "_cmd"
3788 // are not marked as artificial in the DWARF...
Greg Clayton53eb1c22012-04-02 22:59:12 +00003789 CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
3790 if (comp_unit)
Greg Clayton0fffff52010-09-24 05:15:53 +00003791 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003792 switch (comp_unit->GetLanguage())
3793 {
3794 case eLanguageTypeObjC:
3795 case eLanguageTypeObjC_plus_plus:
3796 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
3797 skip = true;
3798 break;
3799 default:
3800 break;
3801 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003802 }
3803 }
3804 }
3805
3806 if (!skip)
3807 {
3808 Type *type = ResolveTypeUID(param_type_die_offset);
3809 if (type)
3810 {
Greg Claytonc93237c2010-10-01 20:48:32 +00003811 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00003812
Greg Clayton42ce2f32011-12-12 21:50:19 +00003813 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
3814 type->GetClangForwardType(),
3815 storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00003816 assert(param_var_decl);
3817 function_param_decls.push_back(param_var_decl);
3818 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003819 }
3820 }
Greg Clayton7fedea22010-11-16 02:10:54 +00003821 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003822 }
3823 break;
3824
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00003825 case DW_TAG_template_type_parameter:
3826 case DW_TAG_template_value_parameter:
3827 ParseTemplateDIE (dwarf_cu, die,template_param_infos);
3828 break;
3829
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003830 default:
3831 break;
3832 }
3833 }
Greg Clayton7fedea22010-11-16 02:10:54 +00003834 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003835}
3836
3837size_t
3838SymbolFileDWARF::ParseChildEnumerators
3839(
3840 const SymbolContext& sc,
Greg Clayton1be10fc2010-09-29 01:12:09 +00003841 clang_type_t enumerator_clang_type,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003842 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00003843 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003844 const DWARFDebugInfoEntry *parent_die
3845)
3846{
3847 if (parent_die == NULL)
3848 return 0;
3849
3850 size_t enumerators_added = 0;
3851 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00003852 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3853
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003854 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3855 {
3856 const dw_tag_t tag = die->Tag();
3857 if (tag == DW_TAG_enumerator)
3858 {
3859 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003860 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003861 if (num_child_attributes > 0)
3862 {
3863 const char *name = NULL;
3864 bool got_value = false;
3865 int64_t enum_value = 0;
3866 Declaration decl;
3867
3868 uint32_t i;
3869 for (i=0; i<num_child_attributes; ++i)
3870 {
3871 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3872 DWARFFormValue form_value;
3873 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3874 {
3875 switch (attr)
3876 {
3877 case DW_AT_const_value:
3878 got_value = true;
3879 enum_value = form_value.Unsigned();
3880 break;
3881
3882 case DW_AT_name:
3883 name = form_value.AsCString(&get_debug_str_data());
3884 break;
3885
3886 case DW_AT_description:
3887 default:
3888 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3889 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3890 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3891 case DW_AT_sibling:
3892 break;
3893 }
3894 }
3895 }
3896
3897 if (name && name[0] && got_value)
3898 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003899 GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
3900 enumerator_clang_type,
3901 decl,
3902 name,
3903 enum_value,
3904 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003905 ++enumerators_added;
3906 }
3907 }
3908 }
3909 }
3910 return enumerators_added;
3911}
3912
3913void
3914SymbolFileDWARF::ParseChildArrayInfo
3915(
3916 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00003917 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003918 const DWARFDebugInfoEntry *parent_die,
3919 int64_t& first_index,
3920 std::vector<uint64_t>& element_orders,
3921 uint32_t& byte_stride,
3922 uint32_t& bit_stride
3923)
3924{
3925 if (parent_die == NULL)
3926 return;
3927
3928 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00003929 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003930 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3931 {
3932 const dw_tag_t tag = die->Tag();
3933 switch (tag)
3934 {
3935 case DW_TAG_enumerator:
3936 {
3937 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003938 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003939 if (num_child_attributes > 0)
3940 {
3941 const char *name = NULL;
3942 bool got_value = false;
3943 int64_t enum_value = 0;
3944
3945 uint32_t i;
3946 for (i=0; i<num_child_attributes; ++i)
3947 {
3948 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3949 DWARFFormValue form_value;
3950 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3951 {
3952 switch (attr)
3953 {
3954 case DW_AT_const_value:
3955 got_value = true;
3956 enum_value = form_value.Unsigned();
3957 break;
3958
3959 case DW_AT_name:
3960 name = form_value.AsCString(&get_debug_str_data());
3961 break;
3962
3963 case DW_AT_description:
3964 default:
3965 case DW_AT_decl_file:
3966 case DW_AT_decl_line:
3967 case DW_AT_decl_column:
3968 case DW_AT_sibling:
3969 break;
3970 }
3971 }
3972 }
3973 }
3974 }
3975 break;
3976
3977 case DW_TAG_subrange_type:
3978 {
3979 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003980 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003981 if (num_child_attributes > 0)
3982 {
3983 const char *name = NULL;
3984 bool got_value = false;
3985 uint64_t byte_size = 0;
3986 int64_t enum_value = 0;
3987 uint64_t num_elements = 0;
3988 uint64_t lower_bound = 0;
3989 uint64_t upper_bound = 0;
3990 uint32_t i;
3991 for (i=0; i<num_child_attributes; ++i)
3992 {
3993 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3994 DWARFFormValue form_value;
3995 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3996 {
3997 switch (attr)
3998 {
3999 case DW_AT_const_value:
4000 got_value = true;
4001 enum_value = form_value.Unsigned();
4002 break;
4003
4004 case DW_AT_name:
4005 name = form_value.AsCString(&get_debug_str_data());
4006 break;
4007
4008 case DW_AT_count:
4009 num_elements = form_value.Unsigned();
4010 break;
4011
4012 case DW_AT_bit_stride:
4013 bit_stride = form_value.Unsigned();
4014 break;
4015
4016 case DW_AT_byte_stride:
4017 byte_stride = form_value.Unsigned();
4018 break;
4019
4020 case DW_AT_byte_size:
4021 byte_size = form_value.Unsigned();
4022 break;
4023
4024 case DW_AT_lower_bound:
4025 lower_bound = form_value.Unsigned();
4026 break;
4027
4028 case DW_AT_upper_bound:
4029 upper_bound = form_value.Unsigned();
4030 break;
4031
4032 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004033 case DW_AT_abstract_origin:
4034 case DW_AT_accessibility:
4035 case DW_AT_allocated:
4036 case DW_AT_associated:
4037 case DW_AT_data_location:
4038 case DW_AT_declaration:
4039 case DW_AT_description:
4040 case DW_AT_sibling:
4041 case DW_AT_threads_scaled:
4042 case DW_AT_type:
4043 case DW_AT_visibility:
4044 break;
4045 }
4046 }
4047 }
4048
4049 if (upper_bound > lower_bound)
4050 num_elements = upper_bound - lower_bound + 1;
4051
4052 if (num_elements > 0)
4053 element_orders.push_back (num_elements);
4054 }
4055 }
4056 break;
4057 }
4058 }
4059}
4060
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004061TypeSP
Greg Clayton53eb1c22012-04-02 22:59:12 +00004062SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004063{
4064 TypeSP type_sp;
4065 if (die != NULL)
4066 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004067 assert(dwarf_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00004068 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004069 if (type_ptr == NULL)
4070 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004071 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu);
Greg Claytonca512b32011-01-14 04:54:56 +00004072 assert (lldb_cu);
4073 SymbolContext sc(lldb_cu);
Greg Clayton53eb1c22012-04-02 22:59:12 +00004074 type_sp = ParseType(sc, dwarf_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004075 }
4076 else if (type_ptr != DIE_IS_BEING_PARSED)
4077 {
4078 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00004079 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004080 }
4081
4082 }
4083 return type_sp;
4084}
4085
4086clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00004087SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004088{
4089 if (die_offset != DW_INVALID_OFFSET)
4090 {
4091 DWARFCompileUnitSP cu_sp;
4092 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004093 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004094 }
4095 return NULL;
4096}
4097
Sean Callanan72e49402011-08-05 23:43:37 +00004098clang::DeclContext *
4099SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
4100{
4101 if (die_offset != DW_INVALID_OFFSET)
4102 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004103 DWARFDebugInfo* debug_info = DebugInfo();
4104 if (debug_info)
4105 {
4106 DWARFCompileUnitSP cu_sp;
4107 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
4108 if (die)
4109 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
4110 }
Sean Callanan72e49402011-08-05 23:43:37 +00004111 }
4112 return NULL;
4113}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004114
Greg Clayton96d7d742010-11-10 23:42:09 +00004115clang::NamespaceDecl *
Greg Clayton53eb1c22012-04-02 22:59:12 +00004116SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die)
Greg Clayton96d7d742010-11-10 23:42:09 +00004117{
Greg Clayton030a2042011-10-14 21:34:45 +00004118 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00004119 {
Greg Clayton030a2042011-10-14 21:34:45 +00004120 // See if we already parsed this namespace DIE and associated it with a
4121 // uniqued namespace declaration
4122 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
4123 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004124 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00004125 else
4126 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004127 const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL);
4128 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00004129 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
4130 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4131 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00004132 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00004133 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00004134 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004135 GetObjectFile()->GetModule()->LogMessage (log.get(),
4136 "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)",
4137 GetClangASTContext().getASTContext(),
4138 MakeUserID(die->GetOffset()),
4139 namespace_name,
4140 namespace_decl,
4141 namespace_decl->getOriginalNamespace());
Greg Clayton030a2042011-10-14 21:34:45 +00004142 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004143 else
4144 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004145 GetObjectFile()->GetModule()->LogMessage (log.get(),
4146 "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
4147 GetClangASTContext().getASTContext(),
4148 MakeUserID(die->GetOffset()),
4149 namespace_decl,
4150 namespace_decl->getOriginalNamespace());
Greg Clayton9d3d6882011-10-31 23:51:19 +00004151 }
Greg Clayton030a2042011-10-14 21:34:45 +00004152 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004153
4154 if (namespace_decl)
4155 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
4156 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004157 }
4158 }
4159 return NULL;
4160}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004161
4162clang::DeclContext *
Greg Claytoncab36a32011-12-08 05:16:30 +00004163SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Sean Callanan72e49402011-08-05 23:43:37 +00004164{
Greg Clayton5cf58b92011-10-05 22:22:08 +00004165 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4166 if (clang_decl_ctx)
4167 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004168 // If this DIE has a specification, or an abstract origin, then trace to those.
4169
Greg Claytoncab36a32011-12-08 05:16:30 +00004170 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004171 if (die_offset != DW_INVALID_OFFSET)
4172 return GetClangDeclContextForDIEOffset (sc, die_offset);
4173
Greg Claytoncab36a32011-12-08 05:16:30 +00004174 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004175 if (die_offset != DW_INVALID_OFFSET)
4176 return GetClangDeclContextForDIEOffset (sc, die_offset);
4177
Greg Clayton3bffb082011-12-10 02:15:28 +00004178 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4179 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00004180 GetObjectFile()->GetModule()->LogMessage(log.get(), "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 +00004181 // This is the DIE we want. Parse it, then query our map.
Greg Claytoncab36a32011-12-08 05:16:30 +00004182 bool assert_not_being_parsed = true;
4183 ResolveTypeUID (cu, die, assert_not_being_parsed);
4184
Greg Clayton5cf58b92011-10-05 22:22:08 +00004185 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4186
4187 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004188}
4189
4190clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00004191SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004192{
Greg Claytonca512b32011-01-14 04:54:56 +00004193 if (m_clang_tu_decl == NULL)
4194 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004195
Greg Clayton2bc22f82011-09-30 03:20:47 +00004196 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004197
4198 if (decl_ctx_die_copy)
4199 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00004200
4201 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004202 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00004203
Greg Clayton2bc22f82011-09-30 03:20:47 +00004204 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
4205 if (pos != m_die_to_decl_ctx.end())
4206 return pos->second;
4207
4208 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004209 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004210 case DW_TAG_compile_unit:
4211 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004212
Greg Clayton2bc22f82011-09-30 03:20:47 +00004213 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00004214 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00004215 break;
4216
4217 case DW_TAG_structure_type:
4218 case DW_TAG_union_type:
4219 case DW_TAG_class_type:
4220 {
4221 Type* type = ResolveType (cu, decl_ctx_die);
4222 if (type)
4223 {
4224 clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ());
4225 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00004226 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004227 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
4228 if (decl_ctx)
4229 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00004230 }
4231 }
Greg Claytonca512b32011-01-14 04:54:56 +00004232 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00004233 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004234
Greg Clayton2bc22f82011-09-30 03:20:47 +00004235 default:
4236 break;
Greg Claytonca512b32011-01-14 04:54:56 +00004237 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004238 }
Greg Clayton7a345282010-11-09 23:46:37 +00004239 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004240}
4241
Greg Clayton2bc22f82011-09-30 03:20:47 +00004242
4243const DWARFDebugInfoEntry *
4244SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4245{
4246 if (cu && die)
4247 {
4248 const DWARFDebugInfoEntry * const decl_die = die;
4249
4250 while (die != NULL)
4251 {
4252 // If this is the original DIE that we are searching for a declaration
4253 // for, then don't look in the cache as we don't want our own decl
4254 // context to be our decl context...
4255 if (decl_die != die)
4256 {
4257 switch (die->Tag())
4258 {
4259 case DW_TAG_compile_unit:
4260 case DW_TAG_namespace:
4261 case DW_TAG_structure_type:
4262 case DW_TAG_union_type:
4263 case DW_TAG_class_type:
4264 return die;
4265
4266 default:
4267 break;
4268 }
4269 }
4270
4271 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4272 if (die_offset != DW_INVALID_OFFSET)
4273 {
4274 DWARFCompileUnit *spec_cu = cu;
4275 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
4276 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
4277 if (spec_die_decl_ctx_die)
4278 return spec_die_decl_ctx_die;
4279 }
4280
4281 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
4282 if (die_offset != DW_INVALID_OFFSET)
4283 {
4284 DWARFCompileUnit *abs_cu = cu;
4285 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
4286 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
4287 if (abs_die_decl_ctx_die)
4288 return abs_die_decl_ctx_die;
4289 }
4290
4291 die = die->GetParent();
4292 }
4293 }
4294 return NULL;
4295}
4296
4297
Greg Clayton901c5ca2011-12-03 04:40:03 +00004298Symbol *
4299SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
4300{
4301 Symbol *objc_class_symbol = NULL;
4302 if (m_obj_file)
4303 {
4304 Symtab *symtab = m_obj_file->GetSymtab();
4305 if (symtab)
4306 {
4307 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
4308 eSymbolTypeObjCClass,
4309 Symtab::eDebugNo,
4310 Symtab::eVisibilityAny);
4311 }
4312 }
4313 return objc_class_symbol;
4314}
4315
Greg Claytonc7f03b62012-01-12 04:33:28 +00004316// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
4317// then we can end up looking through all class types for a complete type and never find
4318// the full definition. We need to know if this attribute is supported, so we determine
4319// this here and cache th result. We also need to worry about the debug map DWARF file
4320// if we are doing darwin DWARF in .o file debugging.
4321bool
4322SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
4323{
4324 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
4325 {
4326 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
4327 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
4328 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4329 else
4330 {
4331 DWARFDebugInfo* debug_info = DebugInfo();
4332 const uint32_t num_compile_units = GetNumCompileUnits();
4333 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
4334 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004335 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
4336 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004337 {
4338 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4339 break;
4340 }
4341 }
4342 }
4343 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && m_debug_map_symfile)
4344 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
4345 }
4346 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
4347}
Greg Clayton901c5ca2011-12-03 04:40:03 +00004348
4349// This function can be used when a DIE is found that is a forward declaration
4350// DIE and we want to try and find a type that has the complete definition.
4351TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00004352SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
4353 const ConstString &type_name,
4354 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00004355{
4356
4357 TypeSP type_sp;
4358
Greg Claytonc7f03b62012-01-12 04:33:28 +00004359 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00004360 return type_sp;
4361
4362 DIEArray die_offsets;
4363
4364 if (m_using_apple_tables)
4365 {
4366 if (m_apple_types_ap.get())
4367 {
4368 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00004369 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004370 }
4371 }
4372 else
4373 {
4374 if (!m_indexed)
4375 Index ();
4376
4377 m_type_index.Find (type_name, die_offsets);
4378 }
4379
Greg Clayton901c5ca2011-12-03 04:40:03 +00004380 const size_t num_matches = die_offsets.size();
4381
Greg Clayton901c5ca2011-12-03 04:40:03 +00004382 DWARFCompileUnit* type_cu = NULL;
4383 const DWARFDebugInfoEntry* type_die = NULL;
4384 if (num_matches)
4385 {
4386 DWARFDebugInfo* debug_info = DebugInfo();
4387 for (size_t i=0; i<num_matches; ++i)
4388 {
4389 const dw_offset_t die_offset = die_offsets[i];
4390 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4391
4392 if (type_die)
4393 {
4394 bool try_resolving_type = false;
4395
4396 // Don't try and resolve the DIE we are looking for with the DIE itself!
4397 if (type_die != die)
4398 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004399 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00004400 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004401 case DW_TAG_class_type:
4402 case DW_TAG_structure_type:
4403 try_resolving_type = true;
4404 break;
4405 default:
4406 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00004407 }
4408 }
4409
4410 if (try_resolving_type)
4411 {
Sean Callanana9bc0652012-01-19 02:17:40 +00004412 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004413 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004414
4415 if (try_resolving_type)
4416 {
4417 Type *resolved_type = ResolveType (type_cu, type_die, false);
4418 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4419 {
4420 DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n",
4421 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00004422 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton901c5ca2011-12-03 04:40:03 +00004423 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4424 MakeUserID(type_die->GetOffset()),
4425 MakeUserID(type_cu->GetOffset()));
4426
Greg Claytonc7f03b62012-01-12 04:33:28 +00004427 if (die)
4428 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00004429 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00004430 break;
4431 }
4432 }
4433 }
4434 }
4435 else
4436 {
4437 if (m_using_apple_tables)
4438 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004439 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4440 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00004441 }
4442 }
4443
4444 }
4445 }
4446 return type_sp;
4447}
4448
Greg Clayton80c26302012-02-05 06:12:47 +00004449//----------------------------------------------------------------------
4450// This function helps to ensure that the declaration contexts match for
4451// two different DIEs. Often times debug information will refer to a
4452// forward declaration of a type (the equivalent of "struct my_struct;".
4453// There will often be a declaration of that type elsewhere that has the
4454// full definition. When we go looking for the full type "my_struct", we
4455// will find one or more matches in the accelerator tables and we will
4456// then need to make sure the type was in the same declaration context
4457// as the original DIE. This function can efficiently compare two DIEs
4458// and will return true when the declaration context matches, and false
4459// when they don't.
4460//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00004461bool
4462SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
4463 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
4464{
4465 assert (die1 != die2);
4466 DWARFDIECollection decl_ctx_1;
4467 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00004468 //The declaration DIE stack is a stack of the declaration context
4469 // DIEs all the way back to the compile unit. If a type "T" is
4470 // declared inside a class "B", and class "B" is declared inside
4471 // a class "A" and class "A" is in a namespace "lldb", and the
4472 // namespace is in a compile unit, there will be a stack of DIEs:
4473 //
4474 // [0] DW_TAG_class_type for "B"
4475 // [1] DW_TAG_class_type for "A"
4476 // [2] DW_TAG_namespace for "lldb"
4477 // [3] DW_TAG_compile_unit for the source file.
4478 //
4479 // We grab both contexts and make sure that everything matches
4480 // all the way back to the compiler unit.
4481
4482 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00004483 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004484 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00004485 // Make sure the context arrays have the same size, otherwise
4486 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00004487 const size_t count1 = decl_ctx_1.Size();
4488 const size_t count2 = decl_ctx_2.Size();
4489 if (count1 != count2)
4490 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00004491
4492 // Make sure the DW_TAG values match all the way back up the the
4493 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00004494 const DWARFDebugInfoEntry *decl_ctx_die1;
4495 const DWARFDebugInfoEntry *decl_ctx_die2;
4496 size_t i;
4497 for (i=0; i<count1; i++)
4498 {
4499 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4500 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4501 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
4502 return false;
4503 }
Greg Clayton890ff562012-02-02 05:48:16 +00004504#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00004505
4506 // Make sure the top item in the decl context die array is always
4507 // DW_TAG_compile_unit. If it isn't then something went wrong in
4508 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00004509 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00004510
Greg Clayton890ff562012-02-02 05:48:16 +00004511#endif
4512 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00004513 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00004514 for (i=0; i<count1 - 1; i++)
4515 {
4516 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4517 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4518 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004519 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00004520 // If the string was from a DW_FORM_strp, then the pointer will often
4521 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00004522 if (name1 == name2)
4523 continue;
4524
4525 // Name pointers are not equal, so only compare the strings
4526 // if both are not NULL.
4527 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00004528 {
Greg Clayton5569e642012-02-06 01:44:54 +00004529 // If the strings don't compare, we are done...
4530 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00004531 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00004532 }
4533 else
4534 {
4535 // One name was NULL while the other wasn't
4536 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00004537 }
4538 }
Greg Clayton80c26302012-02-05 06:12:47 +00004539 // We made it through all of the checks and the declaration contexts
4540 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00004541 return true;
4542}
Greg Clayton220a0072011-12-09 08:48:30 +00004543
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004544// This function can be used when a DIE is found that is a forward declaration
4545// DIE and we want to try and find a type that has the complete definition.
4546TypeSP
Greg Clayton7f995132011-10-04 22:41:51 +00004547SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
4548 const DWARFDebugInfoEntry *die,
4549 const ConstString &type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004550{
4551 TypeSP type_sp;
4552
Greg Clayton1a65ae12011-01-25 23:55:37 +00004553 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004554 return type_sp;
4555
Greg Clayton7f995132011-10-04 22:41:51 +00004556 DIEArray die_offsets;
4557
Greg Clayton97fbc342011-10-20 22:30:33 +00004558 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004559 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004560 if (m_apple_types_ap.get())
4561 {
Greg Claytond1767f02011-12-08 02:13:16 +00004562 if (m_apple_types_ap->GetHeader().header_data.atoms.size() > 1)
4563 {
Greg Claytonae920b62012-01-06 00:17:16 +00004564 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets);
Greg Claytond1767f02011-12-08 02:13:16 +00004565 }
4566 else
4567 {
4568 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
4569 }
Greg Clayton97fbc342011-10-20 22:30:33 +00004570 }
Greg Clayton7f995132011-10-04 22:41:51 +00004571 }
4572 else
4573 {
4574 if (!m_indexed)
4575 Index ();
4576
4577 m_type_index.Find (type_name, die_offsets);
4578 }
Greg Clayton7f995132011-10-04 22:41:51 +00004579
4580 const size_t num_matches = die_offsets.size();
Greg Clayton69974892010-12-03 21:42:06 +00004581
Greg Clayton934cb052011-12-03 00:27:05 +00004582 const dw_tag_t die_tag = die->Tag();
Greg Claytond4a2b372011-09-12 23:21:58 +00004583
4584 DWARFCompileUnit* type_cu = NULL;
4585 const DWARFDebugInfoEntry* type_die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00004586 if (num_matches)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004587 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004588 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004589 for (size_t i=0; i<num_matches; ++i)
4590 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004591 const dw_offset_t die_offset = die_offsets[i];
4592 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004593
Greg Clayton95d87902011-11-11 03:16:25 +00004594 if (type_die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004595 {
Greg Clayton934cb052011-12-03 00:27:05 +00004596 bool try_resolving_type = false;
4597
4598 // Don't try and resolve the DIE we are looking for with the DIE itself!
4599 if (type_die != die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004600 {
Greg Clayton934cb052011-12-03 00:27:05 +00004601 const dw_tag_t type_die_tag = type_die->Tag();
4602 // Make sure the tags match
4603 if (type_die_tag == die_tag)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004604 {
Greg Clayton934cb052011-12-03 00:27:05 +00004605 // The tags match, lets try resolving this type
4606 try_resolving_type = true;
4607 }
4608 else
4609 {
4610 // The tags don't match, but we need to watch our for a
4611 // forward declaration for a struct and ("struct foo")
4612 // ends up being a class ("class foo { ... };") or
4613 // vice versa.
4614 switch (type_die_tag)
Greg Clayton95d87902011-11-11 03:16:25 +00004615 {
Greg Clayton934cb052011-12-03 00:27:05 +00004616 case DW_TAG_class_type:
4617 // We had a "class foo", see if we ended up with a "struct foo { ... };"
4618 try_resolving_type = (die_tag == DW_TAG_structure_type);
4619 break;
4620 case DW_TAG_structure_type:
4621 // We had a "struct foo", see if we ended up with a "class foo { ... };"
4622 try_resolving_type = (die_tag == DW_TAG_class_type);
4623 break;
4624 default:
4625 // Tags don't match, don't event try to resolve
4626 // using this type whose name matches....
Greg Clayton95d87902011-11-11 03:16:25 +00004627 break;
4628 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004629 }
4630 }
Greg Clayton934cb052011-12-03 00:27:05 +00004631
4632 if (try_resolving_type)
4633 {
Greg Clayton890ff562012-02-02 05:48:16 +00004634 // Make sure the decl contexts match all the way up
4635 if (DIEDeclContextsMatch(cu, die, type_cu, type_die))
Greg Clayton934cb052011-12-03 00:27:05 +00004636 {
Greg Clayton890ff562012-02-02 05:48:16 +00004637 Type *resolved_type = ResolveType (type_cu, type_die, false);
4638 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4639 {
4640 DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n",
4641 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00004642 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton890ff562012-02-02 05:48:16 +00004643 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4644 MakeUserID(type_die->GetOffset()),
4645 MakeUserID(type_cu->GetOffset()));
4646
4647 m_die_to_type[die] = resolved_type;
Greg Claytonff7692a2012-02-02 18:16:59 +00004648 type_sp = resolved_type->shared_from_this();
Greg Clayton890ff562012-02-02 05:48:16 +00004649 break;
4650 }
Greg Clayton934cb052011-12-03 00:27:05 +00004651 }
4652 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004653 }
Greg Clayton95d87902011-11-11 03:16:25 +00004654 else
4655 {
4656 if (m_using_apple_tables)
4657 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004658 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4659 die_offset, type_name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004660 }
4661 }
4662
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004663 }
4664 }
4665 return type_sp;
4666}
4667
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004668TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00004669SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004670{
4671 TypeSP type_sp;
4672
Greg Clayton1be10fc2010-09-29 01:12:09 +00004673 if (type_is_new_ptr)
4674 *type_is_new_ptr = false;
Greg Clayton1fba87112012-02-09 20:03:49 +00004675
4676#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
4677 static DIEStack g_die_stack;
4678 DIEStack::ScopedPopper scoped_die_logger(g_die_stack);
4679#endif
Greg Clayton1be10fc2010-09-29 01:12:09 +00004680
Sean Callananc7fbf732010-08-06 00:32:49 +00004681 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004682 if (die != NULL)
4683 {
Greg Clayton21f2a492011-10-06 00:09:08 +00004684 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00004685 if (log)
Sean Callanan5b26f272012-02-04 08:49:35 +00004686 {
4687 const DWARFDebugInfoEntry *context_die;
4688 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
4689
Greg Clayton1fba87112012-02-09 20:03:49 +00004690 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x, decl_ctx = %p (die 0x%8.8x)) %s name = '%s')",
Sean Callanan5b26f272012-02-04 08:49:35 +00004691 die->GetOffset(),
4692 context,
4693 context_die->GetOffset(),
Greg Clayton3bffb082011-12-10 02:15:28 +00004694 DW_TAG_value_to_name(die->Tag()),
Greg Clayton1fba87112012-02-09 20:03:49 +00004695 die->GetName(this, dwarf_cu));
4696
4697#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
4698 scoped_die_logger.Push (dwarf_cu, die);
4699 g_die_stack.LogDIEs(log.get(), this);
4700#endif
Sean Callanan5b26f272012-02-04 08:49:35 +00004701 }
Greg Clayton3bffb082011-12-10 02:15:28 +00004702//
4703// LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4704// if (log && dwarf_cu)
4705// {
4706// StreamString s;
4707// die->DumpLocation (this, dwarf_cu, s);
Greg Claytone38a5ed2012-01-05 03:57:59 +00004708// GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Greg Clayton3bffb082011-12-10 02:15:28 +00004709//
4710// }
Jim Ingham16746d12011-08-25 23:21:43 +00004711
Greg Clayton594e5ed2010-09-27 21:07:38 +00004712 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004713 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00004714 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004715 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004716 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00004717 if (type_is_new_ptr)
4718 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004719
Greg Clayton594e5ed2010-09-27 21:07:38 +00004720 const dw_tag_t tag = die->Tag();
4721
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004722 bool is_forward_declaration = false;
4723 DWARFDebugInfoEntry::Attributes attributes;
4724 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00004725 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00004726 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
4727 size_t byte_size = 0;
Greg Clayton36909642011-03-15 04:38:20 +00004728 bool byte_size_valid = false;
Greg Clayton526e5af2010-11-13 03:52:47 +00004729 Declaration decl;
4730
Greg Clayton4957bf62010-09-30 21:49:03 +00004731 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton1be10fc2010-09-29 01:12:09 +00004732 clang_type_t clang_type = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004733
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004734 dw_attr_t attr;
4735
4736 switch (tag)
4737 {
4738 case DW_TAG_base_type:
4739 case DW_TAG_pointer_type:
4740 case DW_TAG_reference_type:
4741 case DW_TAG_typedef:
4742 case DW_TAG_const_type:
4743 case DW_TAG_restrict_type:
4744 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00004745 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004746 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004747 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00004748 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004749
Greg Claytond88d7592010-09-15 08:33:30 +00004750 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004751 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004752 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
4753
4754 if (num_attributes > 0)
4755 {
4756 uint32_t i;
4757 for (i=0; i<num_attributes; ++i)
4758 {
4759 attr = attributes.AttributeAtIndex(i);
4760 DWARFFormValue form_value;
4761 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4762 {
4763 switch (attr)
4764 {
4765 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4766 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4767 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4768 case DW_AT_name:
Jim Ingham337030f2011-04-15 23:41:23 +00004769
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004770 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00004771 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
4772 // include the "&"...
4773 if (tag == DW_TAG_reference_type)
4774 {
4775 if (strchr (type_name_cstr, '&') == NULL)
4776 type_name_cstr = NULL;
4777 }
4778 if (type_name_cstr)
4779 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004780 break;
Greg Clayton36909642011-03-15 04:38:20 +00004781 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004782 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
4783 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
4784 default:
4785 case DW_AT_sibling:
4786 break;
4787 }
4788 }
4789 }
4790 }
4791
Greg Clayton81c22f62011-10-19 18:09:39 +00004792 DEBUG_PRINTF ("0x%8.8llx: %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 +00004793
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004794 switch (tag)
4795 {
4796 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00004797 break;
4798
Greg Claytond4436412011-10-28 21:00:00 +00004799 case DW_TAG_unspecified_type:
4800 if (strcmp(type_name_cstr, "nullptr_t") == 0)
4801 {
4802 resolve_state = Type::eResolveStateFull;
4803 clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr();
4804 break;
4805 }
4806 // Fall through to base type below in case we can handle the type there...
4807
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004808 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00004809 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004810 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
4811 encoding,
4812 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004813 break;
4814
Greg Clayton526e5af2010-11-13 03:52:47 +00004815 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
4816 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
4817 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
4818 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
4819 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
4820 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004821 }
4822
Greg Claytonc7f03b62012-01-12 04:33:28 +00004823 if (clang_type == NULL && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID))
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004824 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004825 if (type_name_cstr != NULL && sc.comp_unit != NULL &&
4826 (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus))
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004827 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004828 static ConstString g_objc_type_name_id("id");
4829 static ConstString g_objc_type_name_Class("Class");
4830 static ConstString g_objc_type_name_selector("SEL");
4831
4832 if (type_name_const_str == g_objc_type_name_id)
4833 {
4834 if (log)
4835 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'id' built-in type.",
4836 die->GetOffset(),
4837 DW_TAG_value_to_name(die->Tag()),
4838 die->GetName(this, dwarf_cu));
4839 clang_type = ast.GetBuiltInType_objc_id();
4840 encoding_data_type = Type::eEncodingIsUID;
4841 encoding_uid = LLDB_INVALID_UID;
4842 resolve_state = Type::eResolveStateFull;
Greg Clayton526e5af2010-11-13 03:52:47 +00004843
Greg Claytonc7f03b62012-01-12 04:33:28 +00004844 }
4845 else if (type_name_const_str == g_objc_type_name_Class)
4846 {
4847 if (log)
4848 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'Class' built-in type.",
4849 die->GetOffset(),
4850 DW_TAG_value_to_name(die->Tag()),
4851 die->GetName(this, dwarf_cu));
4852 clang_type = ast.GetBuiltInType_objc_Class();
4853 encoding_data_type = Type::eEncodingIsUID;
4854 encoding_uid = LLDB_INVALID_UID;
4855 resolve_state = Type::eResolveStateFull;
4856 }
4857 else if (type_name_const_str == g_objc_type_name_selector)
4858 {
4859 if (log)
4860 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.",
4861 die->GetOffset(),
4862 DW_TAG_value_to_name(die->Tag()),
4863 die->GetName(this, dwarf_cu));
4864 clang_type = ast.GetBuiltInType_objc_selector();
4865 encoding_data_type = Type::eEncodingIsUID;
4866 encoding_uid = LLDB_INVALID_UID;
4867 resolve_state = Type::eResolveStateFull;
4868 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004869 }
4870 }
4871
Greg Clayton81c22f62011-10-19 18:09:39 +00004872 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004873 this,
4874 type_name_const_str,
4875 byte_size,
4876 NULL,
4877 encoding_uid,
4878 encoding_data_type,
4879 &decl,
4880 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00004881 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004882
Greg Clayton594e5ed2010-09-27 21:07:38 +00004883 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004884
4885// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
4886// if (encoding_type != NULL)
4887// {
4888// if (encoding_type != DIE_IS_BEING_PARSED)
4889// type_sp->SetEncodingType(encoding_type);
4890// else
4891// m_indirect_fixups.push_back(type_sp.get());
4892// }
4893 }
4894 break;
4895
4896 case DW_TAG_structure_type:
4897 case DW_TAG_union_type:
4898 case DW_TAG_class_type:
4899 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004900 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00004901 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004902
Greg Clayton9e409562010-07-28 02:04:09 +00004903 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00004904 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004905 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00004906 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004907 if (num_attributes > 0)
4908 {
4909 uint32_t i;
4910 for (i=0; i<num_attributes; ++i)
4911 {
4912 attr = attributes.AttributeAtIndex(i);
4913 DWARFFormValue form_value;
4914 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4915 {
4916 switch (attr)
4917 {
Greg Clayton9e409562010-07-28 02:04:09 +00004918 case DW_AT_decl_file:
Greg Claytonc7f03b62012-01-12 04:33:28 +00004919 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
4920 {
4921 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
4922 // point to the compile unit file, so we clear this invalid value
4923 // so that we can still unique types efficiently.
4924 decl.SetFile(FileSpec ("<invalid>", false));
4925 }
4926 else
4927 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
Greg Clayton9e409562010-07-28 02:04:09 +00004928 break;
4929
4930 case DW_AT_decl_line:
4931 decl.SetLine(form_value.Unsigned());
4932 break;
4933
4934 case DW_AT_decl_column:
4935 decl.SetColumn(form_value.Unsigned());
4936 break;
4937
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004938 case DW_AT_name:
4939 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00004940 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004941 break;
Greg Clayton9e409562010-07-28 02:04:09 +00004942
4943 case DW_AT_byte_size:
4944 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00004945 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00004946 break;
4947
4948 case DW_AT_accessibility:
4949 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
4950 break;
4951
4952 case DW_AT_declaration:
Greg Clayton7a345282010-11-09 23:46:37 +00004953 is_forward_declaration = form_value.Unsigned() != 0;
Greg Clayton9e409562010-07-28 02:04:09 +00004954 break;
4955
4956 case DW_AT_APPLE_runtime_class:
4957 class_language = (LanguageType)form_value.Signed();
4958 break;
4959
Greg Clayton18774842011-11-29 23:40:34 +00004960 case DW_AT_APPLE_objc_complete_type:
4961 is_complete_objc_class = form_value.Signed();
4962 break;
4963
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004964 case DW_AT_allocated:
4965 case DW_AT_associated:
4966 case DW_AT_data_location:
4967 case DW_AT_description:
4968 case DW_AT_start_scope:
4969 case DW_AT_visibility:
4970 default:
4971 case DW_AT_sibling:
4972 break;
4973 }
4974 }
4975 }
4976 }
4977
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004978 UniqueDWARFASTType unique_ast_entry;
Sean Callanan8e8072d2012-02-07 21:13:38 +00004979
Greg Clayton123edca2012-03-02 00:07:15 +00004980 // Only try and unique the type if it has a name.
4981 if (type_name_const_str &&
4982 GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Sean Callanan8e8072d2012-02-07 21:13:38 +00004983 this,
4984 dwarf_cu,
4985 die,
4986 decl,
4987 byte_size_valid ? byte_size : -1,
4988 unique_ast_entry))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004989 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00004990 // We have already parsed this type or from another
4991 // compile unit. GCC loves to use the "one definition
4992 // rule" which can result in multiple definitions
4993 // of the same class over and over in each compile
4994 // unit.
4995 type_sp = unique_ast_entry.m_type_sp;
4996 if (type_sp)
Greg Claytonc615ce42010-11-09 04:42:43 +00004997 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00004998 m_die_to_type[die] = type_sp.get();
4999 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005000 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005001 }
5002
Greg Clayton81c22f62011-10-19 18:09:39 +00005003 DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005004
5005 int tag_decl_kind = -1;
5006 AccessType default_accessibility = eAccessNone;
5007 if (tag == DW_TAG_structure_type)
5008 {
5009 tag_decl_kind = clang::TTK_Struct;
5010 default_accessibility = eAccessPublic;
5011 }
5012 else if (tag == DW_TAG_union_type)
5013 {
5014 tag_decl_kind = clang::TTK_Union;
5015 default_accessibility = eAccessPublic;
5016 }
5017 else if (tag == DW_TAG_class_type)
5018 {
5019 tag_decl_kind = clang::TTK_Class;
5020 default_accessibility = eAccessPrivate;
5021 }
Greg Clayton3a5f29a2011-11-30 02:48:28 +00005022
5023 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
5024 die->HasChildren() == false &&
5025 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
5026 {
5027 // Work around an issue with clang at the moment where
5028 // forward declarations for objective C classes are emitted
5029 // as:
5030 // DW_TAG_structure_type [2]
5031 // DW_AT_name( "ForwardObjcClass" )
5032 // DW_AT_byte_size( 0x00 )
5033 // DW_AT_decl_file( "..." )
5034 // DW_AT_decl_line( 1 )
5035 //
5036 // Note that there is no DW_AT_declaration and there are
5037 // no children, and the byte size is zero.
5038 is_forward_declaration = true;
5039 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005040
Greg Clayton18774842011-11-29 23:40:34 +00005041 if (class_language == eLanguageTypeObjC)
5042 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005043 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
Greg Clayton901c5ca2011-12-03 04:40:03 +00005044 {
5045 // We have a valid eSymbolTypeObjCClass class symbol whose
5046 // name matches the current objective C class that we
5047 // are trying to find and this DIE isn't the complete
5048 // definition (we checked is_complete_objc_class above and
5049 // know it is false), so the real definition is in here somewhere
Greg Claytonc7f03b62012-01-12 04:33:28 +00005050 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005051
Greg Clayton901c5ca2011-12-03 04:40:03 +00005052 if (!type_sp && m_debug_map_symfile)
5053 {
5054 // We weren't able to find a full declaration in
5055 // this DWARF, see if we have a declaration anywhere
5056 // else...
Greg Claytonc7f03b62012-01-12 04:33:28 +00005057 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00005058 }
5059
5060 if (type_sp)
5061 {
5062 if (log)
5063 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005064 GetObjectFile()->GetModule()->LogMessage (log.get(),
5065 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8llx",
5066 this,
5067 die->GetOffset(),
5068 DW_TAG_value_to_name(tag),
5069 type_name_cstr,
5070 type_sp->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00005071 }
5072
5073 // We found a real definition for this type elsewhere
5074 // so lets use it and cache the fact that we found
5075 // a complete type for this die
5076 m_die_to_type[die] = type_sp.get();
5077 return type_sp;
5078 }
5079 }
5080 }
5081
5082
5083 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005084 {
5085 // We have a forward declaration to a type and we need
5086 // to try and find a full declaration. We look in the
5087 // current type index just in case we have a forward
5088 // declaration followed by an actual declarations in the
5089 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00005090 if (log)
5091 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005092 GetObjectFile()->GetModule()->LogMessage (log.get(),
5093 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
5094 this,
5095 die->GetOffset(),
5096 DW_TAG_value_to_name(tag),
5097 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00005098 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005099
5100 type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
5101
5102 if (!type_sp && m_debug_map_symfile)
Greg Clayton4272cc72011-02-02 02:24:04 +00005103 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005104 // We weren't able to find a full declaration in
5105 // this DWARF, see if we have a declaration anywhere
5106 // else...
5107 type_sp = m_debug_map_symfile->FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
Greg Clayton4272cc72011-02-02 02:24:04 +00005108 }
5109
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005110 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00005111 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00005112 if (log)
5113 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005114 GetObjectFile()->GetModule()->LogMessage (log.get(),
5115 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8llx",
5116 this,
5117 die->GetOffset(),
5118 DW_TAG_value_to_name(tag),
5119 type_name_cstr,
5120 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00005121 }
5122
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005123 // We found a real definition for this type elsewhere
5124 // so lets use it and cache the fact that we found
5125 // a complete type for this die
5126 m_die_to_type[die] = type_sp.get();
5127 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005128 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005129 }
5130 assert (tag_decl_kind != -1);
5131 bool clang_type_was_created = false;
5132 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
5133 if (clang_type == NULL)
5134 {
Sean Callanan4d04c6a2012-02-09 22:54:11 +00005135 const DWARFDebugInfoEntry *decl_ctx_die;
5136
5137 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton55561e92011-10-26 03:31:36 +00005138 if (accessibility == eAccessNone && decl_ctx)
5139 {
5140 // Check the decl context that contains this class/struct/union.
5141 // If it is a class we must give it an accessability.
5142 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
5143 if (DeclKindIsCXXClass (containing_decl_kind))
5144 accessibility = default_accessibility;
5145 }
5146
Greg Claytonf0705c82011-10-22 03:33:13 +00005147 if (type_name_cstr && strchr (type_name_cstr, '<'))
5148 {
5149 ClangASTContext::TemplateParameterInfos template_param_infos;
5150 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
5151 {
5152 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00005153 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00005154 type_name_cstr,
5155 tag_decl_kind,
5156 template_param_infos);
5157
5158 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
5159 class_template_decl,
5160 tag_decl_kind,
5161 template_param_infos);
5162 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
5163 clang_type_was_created = true;
5164 }
5165 }
5166
5167 if (!clang_type_was_created)
5168 {
5169 clang_type_was_created = true;
Greg Clayton55561e92011-10-26 03:31:36 +00005170 clang_type = ast.CreateRecordType (decl_ctx,
5171 accessibility,
5172 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00005173 tag_decl_kind,
Greg Claytonf0705c82011-10-22 03:33:13 +00005174 class_language);
5175 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005176 }
5177
5178 // Store a forward declaration to this class type in case any
5179 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00005180 // types for function prototypes.
5181 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00005182 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005183 this,
5184 type_name_const_str,
5185 byte_size,
5186 NULL,
5187 LLDB_INVALID_UID,
5188 Type::eEncodingIsUID,
5189 &decl,
5190 clang_type,
5191 Type::eResolveStateForward));
Sean Callanan72772842012-02-22 23:57:45 +00005192
5193 type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005194
5195
5196 // Add our type to the unique type map so we don't
5197 // end up creating many copies of the same type over
5198 // and over in the ASTContext for our module
5199 unique_ast_entry.m_type_sp = type_sp;
Greg Clayton36909642011-03-15 04:38:20 +00005200 unique_ast_entry.m_symfile = this;
5201 unique_ast_entry.m_cu = dwarf_cu;
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005202 unique_ast_entry.m_die = die;
5203 unique_ast_entry.m_declaration = decl;
Sean Callanan59700592012-02-13 22:30:16 +00005204 unique_ast_entry.m_byte_size = byte_size;
Greg Claytone576ab22011-02-15 00:19:15 +00005205 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
5206 unique_ast_entry);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005207
Sean Callanan12014a02011-12-08 23:45:45 +00005208 if (!is_forward_declaration)
Greg Clayton219cf312012-03-30 00:51:13 +00005209 {
5210 // Always start the definition for a class type so that
5211 // if the class has child classes or types that require
5212 // the class to be created for use as their decl contexts
5213 // the class will be ready to accept these child definitions.
Sean Callanan12014a02011-12-08 23:45:45 +00005214 if (die->HasChildren() == false)
5215 {
5216 // No children for this struct/union/class, lets finish it
5217 ast.StartTagDeclarationDefinition (clang_type);
5218 ast.CompleteTagDeclarationDefinition (clang_type);
5219 }
5220 else if (clang_type_was_created)
5221 {
Greg Clayton219cf312012-03-30 00:51:13 +00005222 // Start the definition if the class is not objective C since
5223 // the underlying decls respond to isCompleteDefinition(). Objective
5224 // C decls dont' respond to isCompleteDefinition() so we can't
5225 // start the declaration definition right away. For C++ classs/union/structs
5226 // we want to start the definition in case the class is needed as the
5227 // declaration context for a contained class or type without the need
5228 // to complete that type..
5229
5230 if (class_language != eLanguageTypeObjC)
5231 ast.StartTagDeclarationDefinition (clang_type);
5232
Sean Callanan12014a02011-12-08 23:45:45 +00005233 // Leave this as a forward declaration until we need
5234 // to know the details of the type. lldb_private::Type
5235 // will automatically call the SymbolFile virtual function
5236 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
5237 // When the definition needs to be defined.
5238 m_forward_decl_die_to_clang_type[die] = clang_type;
5239 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
5240 ClangASTContext::SetHasExternalStorage (clang_type, true);
5241 }
Greg Claytonc615ce42010-11-09 04:42:43 +00005242 }
Greg Claytoncab36a32011-12-08 05:16:30 +00005243
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005244 }
5245 break;
5246
5247 case DW_TAG_enumeration_type:
5248 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005249 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005250 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005251
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005252 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005253
Greg Claytond88d7592010-09-15 08:33:30 +00005254 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005255 if (num_attributes > 0)
5256 {
5257 uint32_t i;
5258
5259 for (i=0; i<num_attributes; ++i)
5260 {
5261 attr = attributes.AttributeAtIndex(i);
5262 DWARFFormValue form_value;
5263 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5264 {
5265 switch (attr)
5266 {
Greg Clayton7a345282010-11-09 23:46:37 +00005267 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5268 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5269 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005270 case DW_AT_name:
5271 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005272 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005273 break;
Greg Clayton7a345282010-11-09 23:46:37 +00005274 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00005275 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Greg Clayton7a345282010-11-09 23:46:37 +00005276 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
5277 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005278 case DW_AT_allocated:
5279 case DW_AT_associated:
5280 case DW_AT_bit_stride:
5281 case DW_AT_byte_stride:
5282 case DW_AT_data_location:
5283 case DW_AT_description:
5284 case DW_AT_start_scope:
5285 case DW_AT_visibility:
5286 case DW_AT_specification:
5287 case DW_AT_abstract_origin:
5288 case DW_AT_sibling:
5289 break;
5290 }
5291 }
5292 }
5293
Greg Clayton81c22f62011-10-19 18:09:39 +00005294 DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
Greg Claytonc93237c2010-10-01 20:48:32 +00005295
Greg Clayton1be10fc2010-09-29 01:12:09 +00005296 clang_type_t enumerator_clang_type = NULL;
5297 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
5298 if (clang_type == NULL)
5299 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005300 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
5301 DW_ATE_signed,
5302 byte_size * 8);
Greg Claytonca512b32011-01-14 04:54:56 +00005303 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00005304 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00005305 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005306 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00005307 }
5308 else
5309 {
5310 enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
5311 assert (enumerator_clang_type != NULL);
5312 }
5313
Greg Claytona2721472011-06-25 00:44:06 +00005314 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
5315
Greg Clayton81c22f62011-10-19 18:09:39 +00005316 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005317 this,
5318 type_name_const_str,
5319 byte_size,
5320 NULL,
5321 encoding_uid,
5322 Type::eEncodingIsUID,
5323 &decl,
5324 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005325 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005326
Greg Clayton6beaaa62011-01-17 03:46:26 +00005327 ast.StartTagDeclarationDefinition (clang_type);
5328 if (die->HasChildren())
5329 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00005330 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
5331 ParseChildEnumerators(cu_sc, clang_type, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00005332 }
5333 ast.CompleteTagDeclarationDefinition (clang_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005334 }
5335 }
5336 break;
5337
Jim Inghamb0be4422010-08-12 01:20:14 +00005338 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005339 case DW_TAG_subprogram:
5340 case DW_TAG_subroutine_type:
5341 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005342 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005343 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005344
5345 const char *mangled = NULL;
5346 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00005347 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005348 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00005349 bool is_static = false;
5350 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00005351 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00005352 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00005353 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
5354 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00005355
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005356 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00005357 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005358
5359
Greg Claytond88d7592010-09-15 08:33:30 +00005360 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005361 if (num_attributes > 0)
5362 {
5363 uint32_t i;
5364 for (i=0; i<num_attributes; ++i)
5365 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00005366 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005367 DWARFFormValue form_value;
5368 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5369 {
5370 switch (attr)
5371 {
5372 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5373 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5374 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5375 case DW_AT_name:
5376 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005377 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005378 break;
5379
5380 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
5381 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00005382 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00005383 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Greg Clayton0fffff52010-09-24 05:15:53 +00005384 case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break;
5385 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
Greg Claytonf51de672010-10-01 02:31:07 +00005386 case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break;
Sean Callanandbb58392011-11-02 01:38:59 +00005387 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
5388
Greg Claytonf51de672010-10-01 02:31:07 +00005389
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005390 case DW_AT_external:
5391 if (form_value.Unsigned())
5392 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00005393 if (storage == clang::SC_None)
5394 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005395 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00005396 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005397 }
5398 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005399
Greg Clayton72da3972011-08-16 18:40:23 +00005400 case DW_AT_specification:
5401 specification_die_offset = form_value.Reference(dwarf_cu);
5402 break;
5403
5404 case DW_AT_abstract_origin:
5405 abstract_origin_die_offset = form_value.Reference(dwarf_cu);
5406 break;
5407
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005408 case DW_AT_allocated:
5409 case DW_AT_associated:
5410 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005411 case DW_AT_calling_convention:
5412 case DW_AT_data_location:
5413 case DW_AT_elemental:
5414 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005415 case DW_AT_frame_base:
5416 case DW_AT_high_pc:
5417 case DW_AT_low_pc:
5418 case DW_AT_object_pointer:
5419 case DW_AT_prototyped:
5420 case DW_AT_pure:
5421 case DW_AT_ranges:
5422 case DW_AT_recursive:
5423 case DW_AT_return_addr:
5424 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005425 case DW_AT_start_scope:
5426 case DW_AT_static_link:
5427 case DW_AT_trampoline:
5428 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005429 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005430 case DW_AT_description:
5431 case DW_AT_sibling:
5432 break;
5433 }
5434 }
5435 }
Greg Clayton24739922010-10-13 03:15:28 +00005436 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005437
Greg Clayton81c22f62011-10-19 18:09:39 +00005438 DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
Greg Claytonc93237c2010-10-01 20:48:32 +00005439
Greg Clayton24739922010-10-13 03:15:28 +00005440 clang_type_t return_clang_type = NULL;
5441 Type *func_type = NULL;
5442
5443 if (type_die_offset != DW_INVALID_OFFSET)
5444 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00005445
Greg Clayton24739922010-10-13 03:15:28 +00005446 if (func_type)
Greg Clayton42ce2f32011-12-12 21:50:19 +00005447 return_clang_type = func_type->GetClangForwardType();
Greg Clayton24739922010-10-13 03:15:28 +00005448 else
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005449 return_clang_type = ast.GetBuiltInType_void();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005450
Greg Claytonf51de672010-10-01 02:31:07 +00005451
Greg Clayton24739922010-10-13 03:15:28 +00005452 std::vector<clang_type_t> function_param_types;
5453 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005454
Greg Clayton24739922010-10-13 03:15:28 +00005455 // Parse the function children for the parameters
Sean Callanan763d72a2011-08-02 22:21:50 +00005456
Greg Claytoncb5860a2011-10-13 23:49:28 +00005457 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
5458 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00005459 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
5460
Greg Claytonf0705c82011-10-22 03:33:13 +00005461 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00005462 // Start off static. This will be set to false in ParseChildParameters(...)
5463 // if we find a "this" paramters as the first parameter
5464 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00005465 is_static = true;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00005466 ClangASTContext::TemplateParameterInfos template_param_infos;
5467
Greg Clayton24739922010-10-13 03:15:28 +00005468 if (die->HasChildren())
5469 {
Greg Clayton0fffff52010-09-24 05:15:53 +00005470 bool skip_artificial = true;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005471 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00005472 containing_decl_ctx,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005473 dwarf_cu,
5474 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00005475 skip_artificial,
5476 is_static,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005477 type_list,
5478 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00005479 function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00005480 type_quals,
5481 template_param_infos);
Greg Clayton24739922010-10-13 03:15:28 +00005482 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005483
Greg Clayton24739922010-10-13 03:15:28 +00005484 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005485 clang_type = ast.CreateFunctionType (return_clang_type,
5486 &function_param_types[0],
5487 function_param_types.size(),
5488 is_variadic,
5489 type_quals);
5490
Greg Clayton24739922010-10-13 03:15:28 +00005491 if (type_name_cstr)
5492 {
5493 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00005494 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005495 {
Greg Clayton7c810422012-01-18 23:40:49 +00005496 ConstString class_name;
Greg Claytone42ae842012-01-19 03:24:53 +00005497 ConstString class_name_no_category;
5498 if (ObjCLanguageRuntime::ParseMethodName (type_name_cstr, &class_name, NULL, NULL, &class_name_no_category))
Greg Clayton0fffff52010-09-24 05:15:53 +00005499 {
Greg Claytone42ae842012-01-19 03:24:53 +00005500 // Use the class name with no category if there is one
5501 if (class_name_no_category)
5502 class_name = class_name_no_category;
5503
Greg Clayton24739922010-10-13 03:15:28 +00005504 SymbolContext empty_sc;
5505 clang_type_t class_opaque_type = NULL;
Greg Clayton7c810422012-01-18 23:40:49 +00005506 if (class_name)
Greg Clayton0fffff52010-09-24 05:15:53 +00005507 {
Greg Clayton24739922010-10-13 03:15:28 +00005508 TypeList types;
Greg Clayton278a16b2012-01-19 00:52:59 +00005509 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
Greg Claytonc7f03b62012-01-12 04:33:28 +00005510
5511 if (complete_objc_class_type_sp)
Greg Clayton0fffff52010-09-24 05:15:53 +00005512 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005513 clang_type_t type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
5514 if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
5515 class_opaque_type = type_clang_forward_type;
Greg Clayton0fffff52010-09-24 05:15:53 +00005516 }
Greg Clayton24739922010-10-13 03:15:28 +00005517 }
Greg Clayton0fffff52010-09-24 05:15:53 +00005518
Greg Clayton24739922010-10-13 03:15:28 +00005519 if (class_opaque_type)
5520 {
5521 // If accessibility isn't set to anything valid, assume public for
5522 // now...
5523 if (accessibility == eAccessNone)
5524 accessibility = eAccessPublic;
5525
5526 clang::ObjCMethodDecl *objc_method_decl;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005527 objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
5528 type_name_cstr,
5529 clang_type,
5530 accessibility);
Greg Clayton2c5f0e92011-08-04 21:02:57 +00005531 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Clayton24739922010-10-13 03:15:28 +00005532 type_handled = objc_method_decl != NULL;
5533 }
5534 }
Greg Clayton5113dc82011-08-12 06:47:54 +00005535 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00005536 {
5537 // Look at the parent of this DIE and see if is is
5538 // a class or struct and see if this is actually a
5539 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00005540 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00005541 if (class_type)
5542 {
Greg Clayton72da3972011-08-16 18:40:23 +00005543 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00005544 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00005545 // We have a specification which we are going to base our function
5546 // prototype off of, so we need this type to be completed so that the
5547 // m_die_to_decl_ctx for the method in the specification has a valid
5548 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00005549 class_type->GetClangForwardType();
Greg Clayton72da3972011-08-16 18:40:23 +00005550 // If we have a specification, then the function type should have been
5551 // made with the specification and not with this die.
5552 DWARFCompileUnitSP spec_cu_sp;
5553 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00005554 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00005555 if (spec_clang_decl_ctx)
5556 {
5557 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
5558 }
5559 else
Jim Inghamc1663042011-09-29 22:12:35 +00005560 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005561 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_specification(0x%8.8x) has no decl\n",
5562 MakeUserID(die->GetOffset()),
5563 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00005564 }
Greg Clayton72da3972011-08-16 18:40:23 +00005565 type_handled = true;
5566 }
5567 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
5568 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00005569 // We have a specification which we are going to base our function
5570 // prototype off of, so we need this type to be completed so that the
5571 // m_die_to_decl_ctx for the method in the abstract origin has a valid
5572 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00005573 class_type->GetClangForwardType();
Greg Clayton5cf58b92011-10-05 22:22:08 +00005574
Greg Clayton72da3972011-08-16 18:40:23 +00005575 DWARFCompileUnitSP abs_cu_sp;
5576 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00005577 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00005578 if (abs_clang_decl_ctx)
5579 {
5580 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
5581 }
5582 else
Jim Inghamc1663042011-09-29 22:12:35 +00005583 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005584 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_abstract_origin(0x%8.8x) has no decl\n",
5585 MakeUserID(die->GetOffset()),
5586 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00005587 }
Greg Clayton72da3972011-08-16 18:40:23 +00005588 type_handled = true;
5589 }
5590 else
5591 {
5592 clang_type_t class_opaque_type = class_type->GetClangForwardType();
5593 if (ClangASTContext::IsCXXClassType (class_opaque_type))
Greg Clayton931180e2011-01-27 06:44:37 +00005594 {
Greg Clayton20568dd2011-10-13 23:13:20 +00005595 if (ClangASTContext::IsBeingDefined (class_opaque_type))
Greg Clayton72da3972011-08-16 18:40:23 +00005596 {
Greg Clayton20568dd2011-10-13 23:13:20 +00005597 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
5598 // in the DWARF for C++ methods... Default to public for now...
5599 if (accessibility == eAccessNone)
5600 accessibility = eAccessPublic;
5601
5602 if (!is_static && !die->HasChildren())
5603 {
5604 // We have a C++ member function with no children (this pointer!)
5605 // and clang will get mad if we try and make a function that isn't
5606 // well formed in the DWARF, so we will just skip it...
5607 type_handled = true;
5608 }
5609 else
5610 {
5611 clang::CXXMethodDecl *cxx_method_decl;
5612 // REMOVE THE CRASH DESCRIPTION BELOW
Greg Clayton81c22f62011-10-19 18:09:39 +00005613 Host::SetCrashDescriptionWithFormat ("SymbolFileDWARF::ParseType() is adding a method %s to class %s in DIE 0x%8.8llx from %s/%s",
Greg Clayton20568dd2011-10-13 23:13:20 +00005614 type_name_cstr,
5615 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00005616 MakeUserID(die->GetOffset()),
Greg Clayton20568dd2011-10-13 23:13:20 +00005617 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
5618 m_obj_file->GetFileSpec().GetFilename().GetCString());
5619
Sean Callananc1b732d2011-11-01 18:07:13 +00005620 const bool is_attr_used = false;
5621
Greg Clayton20568dd2011-10-13 23:13:20 +00005622 cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type,
5623 type_name_cstr,
5624 clang_type,
5625 accessibility,
5626 is_virtual,
5627 is_static,
5628 is_inline,
Sean Callananc1b732d2011-11-01 18:07:13 +00005629 is_explicit,
Sean Callanandbb58392011-11-02 01:38:59 +00005630 is_attr_used,
5631 is_artificial);
Greg Clayton20568dd2011-10-13 23:13:20 +00005632 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
5633
Greg Claytonf49e65a2011-11-10 18:31:53 +00005634 Host::SetCrashDescription (NULL);
5635
Greg Clayton20568dd2011-10-13 23:13:20 +00005636 type_handled = cxx_method_decl != NULL;
5637 }
Greg Clayton72da3972011-08-16 18:40:23 +00005638 }
5639 else
5640 {
Greg Clayton20568dd2011-10-13 23:13:20 +00005641 // We were asked to parse the type for a method in a class, yet the
5642 // class hasn't been asked to complete itself through the
5643 // clang::ExternalASTSource protocol, so we need to just have the
5644 // class complete itself and do things the right way, then our
5645 // DIE should then have an entry in the m_die_to_type map. First
5646 // we need to modify the m_die_to_type so it doesn't think we are
5647 // trying to parse this DIE anymore...
5648 m_die_to_type[die] = NULL;
5649
5650 // Now we get the full type to force our class type to complete itself
5651 // using the clang::ExternalASTSource protocol which will parse all
5652 // base classes and all methods (including the method for this DIE).
5653 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00005654
Greg Clayton20568dd2011-10-13 23:13:20 +00005655 // The type for this DIE should have been filled in the function call above
5656 type_ptr = m_die_to_type[die];
5657 if (type_ptr)
5658 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00005659 type_sp = type_ptr->shared_from_this();
Greg Clayton20568dd2011-10-13 23:13:20 +00005660 break;
5661 }
Greg Clayton72da3972011-08-16 18:40:23 +00005662 }
Greg Clayton931180e2011-01-27 06:44:37 +00005663 }
Greg Clayton0fffff52010-09-24 05:15:53 +00005664 }
5665 }
Greg Clayton0fffff52010-09-24 05:15:53 +00005666 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005667 }
Greg Clayton24739922010-10-13 03:15:28 +00005668
5669 if (!type_handled)
5670 {
5671 // We just have a function that isn't part of a class
Greg Clayton147e1fa2011-10-14 22:47:18 +00005672 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (containing_decl_ctx,
5673 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005674 clang_type,
5675 storage,
5676 is_inline);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00005677
5678// if (template_param_infos.GetSize() > 0)
5679// {
5680// clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
5681// function_decl,
5682// type_name_cstr,
5683// template_param_infos);
5684//
5685// ast.CreateFunctionTemplateSpecializationInfo (function_decl,
5686// func_template_decl,
5687// template_param_infos);
5688// }
Greg Clayton24739922010-10-13 03:15:28 +00005689 // Add the decl to our DIE to decl context map
5690 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00005691 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00005692 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005693 ast.SetFunctionParameters (function_decl,
5694 &function_param_decls.front(),
5695 function_param_decls.size());
Greg Clayton24739922010-10-13 03:15:28 +00005696 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005697 }
Greg Clayton81c22f62011-10-19 18:09:39 +00005698 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005699 this,
5700 type_name_const_str,
5701 0,
5702 NULL,
5703 LLDB_INVALID_UID,
5704 Type::eEncodingIsUID,
5705 &decl,
5706 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005707 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00005708 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005709 }
5710 break;
5711
5712 case DW_TAG_array_type:
5713 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005714 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005715 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005716
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005717 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005718 int64_t first_index = 0;
5719 uint32_t byte_stride = 0;
5720 uint32_t bit_stride = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00005721 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005722
5723 if (num_attributes > 0)
5724 {
5725 uint32_t i;
5726 for (i=0; i<num_attributes; ++i)
5727 {
5728 attr = attributes.AttributeAtIndex(i);
5729 DWARFFormValue form_value;
5730 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5731 {
5732 switch (attr)
5733 {
5734 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5735 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5736 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5737 case DW_AT_name:
5738 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005739 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005740 break;
5741
5742 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00005743 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005744 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
5745 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00005746 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00005747 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005748 case DW_AT_allocated:
5749 case DW_AT_associated:
5750 case DW_AT_data_location:
5751 case DW_AT_description:
5752 case DW_AT_ordering:
5753 case DW_AT_start_scope:
5754 case DW_AT_visibility:
5755 case DW_AT_specification:
5756 case DW_AT_abstract_origin:
5757 case DW_AT_sibling:
5758 break;
5759 }
5760 }
5761 }
5762
Greg Clayton81c22f62011-10-19 18:09:39 +00005763 DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
Greg Claytonc93237c2010-10-01 20:48:32 +00005764
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005765 Type *element_type = ResolveTypeUID(type_die_offset);
5766
5767 if (element_type)
5768 {
5769 std::vector<uint64_t> element_orders;
5770 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
Greg Claytona134cc12010-09-13 02:37:44 +00005771 // We have an array that claims to have no members, lets give it at least one member...
5772 if (element_orders.empty())
5773 element_orders.push_back (1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005774 if (byte_stride == 0 && bit_stride == 0)
5775 byte_stride = element_type->GetByteSize();
Greg Clayton42ce2f32011-12-12 21:50:19 +00005776 clang_type_t array_element_type = element_type->GetClangForwardType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005777 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
5778 uint64_t num_elements = 0;
5779 std::vector<uint64_t>::const_reverse_iterator pos;
5780 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
5781 for (pos = element_orders.rbegin(); pos != end; ++pos)
5782 {
5783 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005784 clang_type = ast.CreateArrayType (array_element_type,
5785 num_elements,
5786 num_elements * array_element_bit_stride);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005787 array_element_type = clang_type;
5788 array_element_bit_stride = array_element_bit_stride * num_elements;
5789 }
5790 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00005791 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005792 this,
5793 empty_name,
5794 array_element_bit_stride / 8,
5795 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00005796 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005797 Type::eEncodingIsUID,
5798 &decl,
5799 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005800 Type::eResolveStateFull));
5801 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005802 }
5803 }
5804 }
5805 break;
5806
Greg Clayton9b81a312010-06-12 01:20:30 +00005807 case DW_TAG_ptr_to_member_type:
5808 {
5809 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
5810 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
5811
Greg Claytond88d7592010-09-15 08:33:30 +00005812 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00005813
5814 if (num_attributes > 0) {
5815 uint32_t i;
5816 for (i=0; i<num_attributes; ++i)
5817 {
5818 attr = attributes.AttributeAtIndex(i);
5819 DWARFFormValue form_value;
5820 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5821 {
5822 switch (attr)
5823 {
5824 case DW_AT_type:
5825 type_die_offset = form_value.Reference(dwarf_cu); break;
5826 case DW_AT_containing_type:
5827 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
5828 }
5829 }
5830 }
5831
5832 Type *pointee_type = ResolveTypeUID(type_die_offset);
5833 Type *class_type = ResolveTypeUID(containing_type_die_offset);
5834
Greg Clayton526e5af2010-11-13 03:52:47 +00005835 clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
5836 clang_type_t class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00005837
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005838 clang_type = ast.CreateMemberPointerType(pointee_clang_type,
5839 class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00005840
Greg Clayton526e5af2010-11-13 03:52:47 +00005841 byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(),
5842 clang_type) / 8;
Greg Clayton9b81a312010-06-12 01:20:30 +00005843
Greg Clayton81c22f62011-10-19 18:09:39 +00005844 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005845 this,
5846 type_name_const_str,
5847 byte_size,
5848 NULL,
5849 LLDB_INVALID_UID,
5850 Type::eEncodingIsUID,
5851 NULL,
5852 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005853 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00005854 }
5855
5856 break;
5857 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005858 default:
Greg Clayton9b81a312010-06-12 01:20:30 +00005859 assert(false && "Unhandled type tag!");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005860 break;
5861 }
5862
5863 if (type_sp.get())
5864 {
5865 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
5866 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
5867
5868 SymbolContextScope * symbol_context_scope = NULL;
5869 if (sc_parent_tag == DW_TAG_compile_unit)
5870 {
5871 symbol_context_scope = sc.comp_unit;
5872 }
5873 else if (sc.function != NULL)
5874 {
Greg Clayton81c22f62011-10-19 18:09:39 +00005875 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005876 if (symbol_context_scope == NULL)
5877 symbol_context_scope = sc.function;
5878 }
5879
5880 if (symbol_context_scope != NULL)
5881 {
5882 type_sp->SetSymbolContextScope(symbol_context_scope);
5883 }
5884
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005885 // We are ready to put this type into the uniqued list up at the module level
5886 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00005887
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005888 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005889 }
5890 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00005891 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005892 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00005893 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005894 }
5895 }
5896 return type_sp;
5897}
5898
5899size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00005900SymbolFileDWARF::ParseTypes
5901(
5902 const SymbolContext& sc,
5903 DWARFCompileUnit* dwarf_cu,
5904 const DWARFDebugInfoEntry *die,
5905 bool parse_siblings,
5906 bool parse_children
5907)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005908{
5909 size_t types_added = 0;
5910 while (die != NULL)
5911 {
5912 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00005913 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005914 {
5915 if (type_is_new)
5916 ++types_added;
5917 }
5918
5919 if (parse_children && die->HasChildren())
5920 {
5921 if (die->Tag() == DW_TAG_subprogram)
5922 {
5923 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00005924 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005925 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
5926 }
5927 else
5928 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
5929 }
5930
5931 if (parse_siblings)
5932 die = die->GetSibling();
5933 else
5934 die = NULL;
5935 }
5936 return types_added;
5937}
5938
5939
5940size_t
5941SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
5942{
5943 assert(sc.comp_unit && sc.function);
5944 size_t functions_added = 0;
5945 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
5946 if (dwarf_cu)
5947 {
5948 dw_offset_t function_die_offset = sc.function->GetID();
5949 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
5950 if (function_die)
5951 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00005952 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005953 }
5954 }
5955
5956 return functions_added;
5957}
5958
5959
5960size_t
5961SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
5962{
5963 // At least a compile unit must be valid
5964 assert(sc.comp_unit);
5965 size_t types_added = 0;
5966 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
5967 if (dwarf_cu)
5968 {
5969 if (sc.function)
5970 {
5971 dw_offset_t function_die_offset = sc.function->GetID();
5972 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
5973 if (func_die && func_die->HasChildren())
5974 {
5975 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
5976 }
5977 }
5978 else
5979 {
5980 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
5981 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
5982 {
5983 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
5984 }
5985 }
5986 }
5987
5988 return types_added;
5989}
5990
5991size_t
5992SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
5993{
5994 if (sc.comp_unit != NULL)
5995 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00005996 DWARFDebugInfo* info = DebugInfo();
5997 if (info == NULL)
5998 return 0;
5999
6000 uint32_t cu_idx = UINT32_MAX;
6001 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006002
6003 if (dwarf_cu == NULL)
6004 return 0;
6005
6006 if (sc.function)
6007 {
6008 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00006009
6010 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, DW_INVALID_ADDRESS);
Greg Claytone38a5ed2012-01-05 03:57:59 +00006011 if (func_lo_pc != DW_INVALID_ADDRESS)
6012 {
6013 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00006014
Greg Claytone38a5ed2012-01-05 03:57:59 +00006015 // Let all blocks know they have parse all their variables
6016 sc.function->GetBlock (false).SetDidParseVariables (true, true);
6017 return num_variables;
6018 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006019 }
6020 else if (sc.comp_unit)
6021 {
6022 uint32_t vars_added = 0;
6023 VariableListSP variables (sc.comp_unit->GetVariableList(false));
6024
6025 if (variables.get() == NULL)
6026 {
6027 variables.reset(new VariableList());
6028 sc.comp_unit->SetVariableList(variables);
6029
Greg Claytond4a2b372011-09-12 23:21:58 +00006030 DWARFCompileUnit* match_dwarf_cu = NULL;
6031 const DWARFDebugInfoEntry* die = NULL;
6032 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00006033 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00006034 {
Greg Clayton97fbc342011-10-20 22:30:33 +00006035 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00006036 {
6037 DWARFMappedHash::DIEInfoArray hash_data_array;
6038 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
6039 dwarf_cu->GetNextCompileUnitOffset(),
6040 hash_data_array))
6041 {
6042 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
6043 }
6044 }
Greg Clayton7f995132011-10-04 22:41:51 +00006045 }
6046 else
6047 {
6048 // Index if we already haven't to make sure the compile units
6049 // get indexed and make their global DIE index list
6050 if (!m_indexed)
6051 Index ();
6052
6053 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
6054 dwarf_cu->GetNextCompileUnitOffset(),
6055 die_offsets);
6056 }
6057
6058 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00006059 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006060 {
Greg Claytond4a2b372011-09-12 23:21:58 +00006061 DWARFDebugInfo* debug_info = DebugInfo();
6062 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006063 {
Greg Claytond4a2b372011-09-12 23:21:58 +00006064 const dw_offset_t die_offset = die_offsets[i];
6065 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00006066 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00006067 {
Greg Clayton95d87902011-11-11 03:16:25 +00006068 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
6069 if (var_sp)
6070 {
6071 variables->AddVariableIfUnique (var_sp);
6072 ++vars_added;
6073 }
Greg Claytond4a2b372011-09-12 23:21:58 +00006074 }
Greg Clayton95d87902011-11-11 03:16:25 +00006075 else
6076 {
6077 if (m_using_apple_tables)
6078 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00006079 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 +00006080 }
6081 }
6082
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006083 }
6084 }
6085 }
6086 return vars_added;
6087 }
6088 }
6089 return 0;
6090}
6091
6092
6093VariableSP
6094SymbolFileDWARF::ParseVariableDIE
6095(
6096 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00006097 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00006098 const DWARFDebugInfoEntry *die,
6099 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006100)
6101{
6102
Greg Clayton83c5cd92010-11-14 22:13:40 +00006103 VariableSP var_sp (m_die_to_variable_sp[die]);
6104 if (var_sp)
6105 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006106
6107 const dw_tag_t tag = die->Tag();
Greg Clayton7f995132011-10-04 22:41:51 +00006108
6109 if ((tag == DW_TAG_variable) ||
6110 (tag == DW_TAG_constant) ||
6111 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006112 {
Greg Clayton7f995132011-10-04 22:41:51 +00006113 DWARFDebugInfoEntry::Attributes attributes;
6114 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
6115 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006116 {
Greg Clayton7f995132011-10-04 22:41:51 +00006117 const char *name = NULL;
6118 const char *mangled = NULL;
6119 Declaration decl;
6120 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00006121 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00006122 DWARFExpression location;
6123 bool is_external = false;
6124 bool is_artificial = false;
6125 bool location_is_const_value_data = false;
6126 AccessType accessibility = eAccessNone;
6127
6128 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006129 {
Greg Clayton7f995132011-10-04 22:41:51 +00006130 dw_attr_t attr = attributes.AttributeAtIndex(i);
6131 DWARFFormValue form_value;
6132 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006133 {
Greg Clayton7f995132011-10-04 22:41:51 +00006134 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006135 {
Greg Clayton7f995132011-10-04 22:41:51 +00006136 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6137 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6138 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6139 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
6140 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Claytond1767f02011-12-08 02:13:16 +00006141 case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton7f995132011-10-04 22:41:51 +00006142 case DW_AT_external: is_external = form_value.Unsigned() != 0; break;
6143 case DW_AT_const_value:
6144 location_is_const_value_data = true;
6145 // Fall through...
6146 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006147 {
Greg Clayton7f995132011-10-04 22:41:51 +00006148 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006149 {
Greg Clayton7f995132011-10-04 22:41:51 +00006150 const DataExtractor& debug_info_data = get_debug_info_data();
6151
6152 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
6153 uint32_t block_length = form_value.Unsigned();
6154 location.SetOpcodeData(get_debug_info_data(), block_offset, block_length);
6155 }
6156 else
6157 {
6158 const DataExtractor& debug_loc_data = get_debug_loc_data();
6159 const dw_offset_t debug_loc_offset = form_value.Unsigned();
6160
6161 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
6162 if (loc_list_length > 0)
6163 {
6164 location.SetOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
6165 assert (func_low_pc != LLDB_INVALID_ADDRESS);
6166 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
6167 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006168 }
6169 }
Greg Clayton7f995132011-10-04 22:41:51 +00006170 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006171
Greg Clayton7f995132011-10-04 22:41:51 +00006172 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
6173 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
6174 case DW_AT_declaration:
6175 case DW_AT_description:
6176 case DW_AT_endianity:
6177 case DW_AT_segment:
6178 case DW_AT_start_scope:
6179 case DW_AT_visibility:
6180 default:
6181 case DW_AT_abstract_origin:
6182 case DW_AT_sibling:
6183 case DW_AT_specification:
6184 break;
6185 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006186 }
6187 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006188
Greg Clayton7f995132011-10-04 22:41:51 +00006189 if (location.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006190 {
Greg Clayton7f995132011-10-04 22:41:51 +00006191 ValueType scope = eValueTypeInvalid;
6192
6193 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
6194 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006195 SymbolContextScope * symbol_context_scope = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00006196
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006197 // DWARF doesn't specify if a DW_TAG_variable is a local, global
6198 // or static variable, so we have to do a little digging by
6199 // looking at the location of a varaible to see if it contains
6200 // a DW_OP_addr opcode _somewhere_ in the definition. I say
6201 // somewhere because clang likes to combine small global variables
6202 // into the same symbol and have locations like:
6203 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
6204 // So if we don't have a DW_TAG_formal_parameter, we can look at
6205 // the location to see if it contains a DW_OP_addr opcode, and
6206 // then we can correctly classify our variables.
Greg Clayton7f995132011-10-04 22:41:51 +00006207 if (tag == DW_TAG_formal_parameter)
6208 scope = eValueTypeVariableArgument;
Greg Claytond1767f02011-12-08 02:13:16 +00006209 else
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006210 {
Greg Clayton96c09682012-01-04 22:56:43 +00006211 bool op_error = false;
Greg Claytond1767f02011-12-08 02:13:16 +00006212 // Check if the location has a DW_OP_addr with any address value...
6213 addr_t location_has_op_addr = false;
6214 if (!location_is_const_value_data)
Greg Clayton96c09682012-01-04 22:56:43 +00006215 {
6216 location_has_op_addr = location.LocationContains_DW_OP_addr (LLDB_INVALID_ADDRESS, op_error);
6217 if (op_error)
6218 {
6219 StreamString strm;
6220 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
Greg Claytone38a5ed2012-01-05 03:57:59 +00006221 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 +00006222 }
6223 }
Greg Claytond1767f02011-12-08 02:13:16 +00006224
6225 if (location_has_op_addr)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006226 {
Greg Claytond1767f02011-12-08 02:13:16 +00006227 if (is_external)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006228 {
Greg Claytond1767f02011-12-08 02:13:16 +00006229 scope = eValueTypeVariableGlobal;
6230
6231 if (m_debug_map_symfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006232 {
Greg Claytond1767f02011-12-08 02:13:16 +00006233 // When leaving the DWARF in the .o files on darwin,
6234 // when we have a global variable that wasn't initialized,
6235 // the .o file might not have allocated a virtual
6236 // address for the global variable. In this case it will
6237 // have created a symbol for the global variable
6238 // that is undefined and external and the value will
6239 // be the byte size of the variable. When we do the
6240 // address map in SymbolFileDWARFDebugMap we rely on
6241 // having an address, we need to do some magic here
6242 // so we can get the correct address for our global
6243 // variable. The address for all of these entries
6244 // will be zero, and there will be an undefined symbol
6245 // in this object file, and the executable will have
6246 // a matching symbol with a good address. So here we
6247 // dig up the correct address and replace it in the
6248 // location for the variable, and set the variable's
6249 // symbol context scope to be that of the main executable
6250 // so the file address will resolve correctly.
Greg Clayton96c09682012-01-04 22:56:43 +00006251 if (location.LocationContains_DW_OP_addr (0, op_error))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006252 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006253
Greg Claytond1767f02011-12-08 02:13:16 +00006254 // we have a possible uninitialized extern global
6255 Symtab *symtab = m_obj_file->GetSymtab();
6256 if (symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006257 {
Greg Claytond1767f02011-12-08 02:13:16 +00006258 ConstString const_name(name);
6259 Symbol *undefined_symbol = symtab->FindFirstSymbolWithNameAndType (const_name,
6260 eSymbolTypeUndefined,
6261 Symtab::eDebugNo,
6262 Symtab::eVisibilityExtern);
6263
6264 if (undefined_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006265 {
Greg Claytond1767f02011-12-08 02:13:16 +00006266 ObjectFile *debug_map_objfile = m_debug_map_symfile->GetObjectFile();
6267 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006268 {
Greg Claytond1767f02011-12-08 02:13:16 +00006269 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
6270 Symbol *defined_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
6271 eSymbolTypeData,
6272 Symtab::eDebugYes,
6273 Symtab::eVisibilityExtern);
6274 if (defined_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006275 {
Greg Claytone7612132012-03-07 21:03:09 +00006276 if (defined_symbol->ValueIsAddress())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006277 {
Greg Claytone7612132012-03-07 21:03:09 +00006278 const addr_t defined_addr = defined_symbol->GetAddress().GetFileAddress();
Greg Claytond1767f02011-12-08 02:13:16 +00006279 if (defined_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006280 {
Greg Claytond1767f02011-12-08 02:13:16 +00006281 if (location.Update_DW_OP_addr (defined_addr))
6282 {
6283 symbol_context_scope = defined_symbol;
6284 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006285 }
6286 }
6287 }
6288 }
6289 }
6290 }
6291 }
6292 }
6293 }
Greg Claytond1767f02011-12-08 02:13:16 +00006294 else
6295 {
6296 scope = eValueTypeVariableStatic;
6297 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006298 }
6299 else
Greg Claytond1767f02011-12-08 02:13:16 +00006300 {
6301 scope = eValueTypeVariableLocal;
6302 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006303 }
Greg Clayton7f995132011-10-04 22:41:51 +00006304
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006305 if (symbol_context_scope == NULL)
Greg Clayton7f995132011-10-04 22:41:51 +00006306 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006307 switch (parent_tag)
Greg Clayton5cf58b92011-10-05 22:22:08 +00006308 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006309 case DW_TAG_subprogram:
6310 case DW_TAG_inlined_subroutine:
6311 case DW_TAG_lexical_block:
6312 if (sc.function)
6313 {
6314 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
6315 if (symbol_context_scope == NULL)
6316 symbol_context_scope = sc.function;
6317 }
6318 break;
6319
6320 default:
6321 symbol_context_scope = sc.comp_unit;
6322 break;
Greg Clayton5cf58b92011-10-05 22:22:08 +00006323 }
Greg Clayton7f995132011-10-04 22:41:51 +00006324 }
6325
Greg Clayton5cf58b92011-10-05 22:22:08 +00006326 if (symbol_context_scope)
6327 {
Greg Clayton81c22f62011-10-19 18:09:39 +00006328 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
6329 name,
6330 mangled,
Greg Claytond1767f02011-12-08 02:13:16 +00006331 SymbolFileTypeSP (new SymbolFileType(*this, type_uid)),
Greg Clayton81c22f62011-10-19 18:09:39 +00006332 scope,
6333 symbol_context_scope,
6334 &decl,
6335 location,
6336 is_external,
6337 is_artificial));
Greg Clayton5cf58b92011-10-05 22:22:08 +00006338
6339 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
6340 }
6341 else
6342 {
6343 // Not ready to parse this variable yet. It might be a global
6344 // or static variable that is in a function scope and the function
6345 // in the symbol context wasn't filled in yet
6346 return var_sp;
6347 }
Greg Clayton7f995132011-10-04 22:41:51 +00006348 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006349 }
Greg Clayton7f995132011-10-04 22:41:51 +00006350 // Cache var_sp even if NULL (the variable was just a specification or
6351 // was missing vital information to be able to be displayed in the debugger
6352 // (missing location due to optimization, etc)) so we don't re-parse
6353 // this DIE over and over later...
6354 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006355 }
6356 return var_sp;
6357}
6358
Greg Claytonc662ec82011-06-17 22:10:16 +00006359
6360const DWARFDebugInfoEntry *
6361SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
6362 dw_offset_t spec_block_die_offset,
6363 DWARFCompileUnit **result_die_cu_handle)
6364{
6365 // Give the concrete function die specified by "func_die_offset", find the
6366 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
6367 // to "spec_block_die_offset"
6368 DWARFDebugInfo* info = DebugInfo();
6369
6370 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
6371 if (die)
6372 {
6373 assert (*result_die_cu_handle);
6374 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
6375 }
6376 return NULL;
6377}
6378
6379
6380const DWARFDebugInfoEntry *
6381SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
6382 const DWARFDebugInfoEntry *die,
6383 dw_offset_t spec_block_die_offset,
6384 DWARFCompileUnit **result_die_cu_handle)
6385{
6386 if (die)
6387 {
6388 switch (die->Tag())
6389 {
6390 case DW_TAG_subprogram:
6391 case DW_TAG_inlined_subroutine:
6392 case DW_TAG_lexical_block:
6393 {
6394 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
6395 {
6396 *result_die_cu_handle = dwarf_cu;
6397 return die;
6398 }
6399
6400 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
6401 {
6402 *result_die_cu_handle = dwarf_cu;
6403 return die;
6404 }
6405 }
6406 break;
6407 }
6408
6409 // Give the concrete function die specified by "func_die_offset", find the
6410 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
6411 // to "spec_block_die_offset"
6412 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
6413 {
6414 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
6415 child_die,
6416 spec_block_die_offset,
6417 result_die_cu_handle);
6418 if (result_die)
6419 return result_die;
6420 }
6421 }
6422
6423 *result_die_cu_handle = NULL;
6424 return NULL;
6425}
6426
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006427size_t
6428SymbolFileDWARF::ParseVariables
6429(
6430 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00006431 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00006432 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006433 const DWARFDebugInfoEntry *orig_die,
6434 bool parse_siblings,
6435 bool parse_children,
6436 VariableList* cc_variable_list
6437)
6438{
6439 if (orig_die == NULL)
6440 return 0;
6441
Greg Claytonc662ec82011-06-17 22:10:16 +00006442 VariableListSP variable_list_sp;
6443
6444 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006445 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00006446 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006447 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006448 dw_tag_t tag = die->Tag();
6449
6450 // Check to see if we have already parsed this variable or constant?
6451 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006452 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006453 if (cc_variable_list)
6454 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006455 }
6456 else
6457 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006458 // We haven't already parsed it, lets do that now.
6459 if ((tag == DW_TAG_variable) ||
6460 (tag == DW_TAG_constant) ||
6461 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006462 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006463 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00006464 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006465 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
6466 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
6467 switch (parent_tag)
6468 {
6469 case DW_TAG_compile_unit:
6470 if (sc.comp_unit != NULL)
6471 {
6472 variable_list_sp = sc.comp_unit->GetVariableList(false);
6473 if (variable_list_sp.get() == NULL)
6474 {
6475 variable_list_sp.reset(new VariableList());
6476 sc.comp_unit->SetVariableList(variable_list_sp);
6477 }
6478 }
6479 else
6480 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00006481 GetObjectFile()->GetModule()->ReportError ("parent 0x%8.8llx %s with no valid compile unit in symbol context for 0x%8.8llx %s.\n",
6482 MakeUserID(sc_parent_die->GetOffset()),
6483 DW_TAG_value_to_name (parent_tag),
6484 MakeUserID(orig_die->GetOffset()),
6485 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006486 }
6487 break;
6488
6489 case DW_TAG_subprogram:
6490 case DW_TAG_inlined_subroutine:
6491 case DW_TAG_lexical_block:
6492 if (sc.function != NULL)
6493 {
6494 // Check to see if we already have parsed the variables for the given scope
6495
Greg Clayton81c22f62011-10-19 18:09:39 +00006496 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006497 if (block == NULL)
6498 {
6499 // This must be a specification or abstract origin with
6500 // a concrete block couterpart in the current function. We need
6501 // to find the concrete block so we can correctly add the
6502 // variable to it
6503 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
6504 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
6505 sc_parent_die->GetOffset(),
6506 &concrete_block_die_cu);
6507 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00006508 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006509 }
6510
6511 if (block != NULL)
6512 {
6513 const bool can_create = false;
6514 variable_list_sp = block->GetBlockVariableList (can_create);
6515 if (variable_list_sp.get() == NULL)
6516 {
6517 variable_list_sp.reset(new VariableList());
6518 block->SetVariableList(variable_list_sp);
6519 }
6520 }
6521 }
6522 break;
6523
6524 default:
Greg Claytone38a5ed2012-01-05 03:57:59 +00006525 GetObjectFile()->GetModule()->ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8llx %s.\n",
6526 MakeUserID(orig_die->GetOffset()),
6527 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006528 break;
6529 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00006530 }
Greg Claytonc662ec82011-06-17 22:10:16 +00006531
6532 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006533 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00006534 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
6535 if (var_sp)
6536 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006537 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00006538 if (cc_variable_list)
6539 cc_variable_list->AddVariableIfUnique (var_sp);
6540 ++vars_added;
6541 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006542 }
6543 }
6544 }
Greg Claytonc662ec82011-06-17 22:10:16 +00006545
6546 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
6547
6548 if (!skip_children && parse_children && die->HasChildren())
6549 {
6550 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
6551 }
6552
6553 if (parse_siblings)
6554 die = die->GetSibling();
6555 else
6556 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006557 }
Greg Claytonc662ec82011-06-17 22:10:16 +00006558 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006559}
6560
6561//------------------------------------------------------------------
6562// PluginInterface protocol
6563//------------------------------------------------------------------
6564const char *
6565SymbolFileDWARF::GetPluginName()
6566{
6567 return "SymbolFileDWARF";
6568}
6569
6570const char *
6571SymbolFileDWARF::GetShortPluginName()
6572{
6573 return GetPluginNameStatic();
6574}
6575
6576uint32_t
6577SymbolFileDWARF::GetPluginVersion()
6578{
6579 return 1;
6580}
6581
6582void
Greg Clayton6beaaa62011-01-17 03:46:26 +00006583SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
6584{
6585 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6586 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
6587 if (clang_type)
6588 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
6589}
6590
6591void
6592SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
6593{
6594 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6595 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
6596 if (clang_type)
6597 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
6598}
6599
Greg Claytona2721472011-06-25 00:44:06 +00006600void
Sean Callanancc427fa2011-07-30 02:42:06 +00006601SymbolFileDWARF::DumpIndexes ()
6602{
6603 StreamFile s(stdout, false);
6604
6605 s.Printf ("DWARF index for (%s) '%s/%s':",
6606 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
6607 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
6608 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
6609 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
6610 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
6611 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
6612 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
6613 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
6614 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
6615 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
6616 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
6617}
6618
6619void
6620SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
6621 const char *name,
6622 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00006623{
Sean Callanancc427fa2011-07-30 02:42:06 +00006624 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00006625
6626 if (iter == m_decl_ctx_to_die.end())
6627 return;
6628
Greg Claytoncb5860a2011-10-13 23:49:28 +00006629 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00006630 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00006631 const DWARFDebugInfoEntry *context_die = *pos;
6632
6633 if (!results)
6634 return;
6635
6636 DWARFDebugInfo* info = DebugInfo();
6637
6638 DIEArray die_offsets;
6639
6640 DWARFCompileUnit* dwarf_cu = NULL;
6641 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton220a0072011-12-09 08:48:30 +00006642
6643 if (m_using_apple_tables)
6644 {
6645 if (m_apple_types_ap.get())
6646 m_apple_types_ap->FindByName (name, die_offsets);
6647 }
6648 else
6649 {
6650 if (!m_indexed)
6651 Index ();
6652
6653 m_type_index.Find (ConstString(name), die_offsets);
6654 }
6655
Greg Clayton220a0072011-12-09 08:48:30 +00006656 const size_t num_matches = die_offsets.size();
Greg Claytoncb5860a2011-10-13 23:49:28 +00006657
6658 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00006659 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00006660 for (size_t i = 0; i < num_matches; ++i)
6661 {
6662 const dw_offset_t die_offset = die_offsets[i];
6663 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00006664
Greg Claytoncb5860a2011-10-13 23:49:28 +00006665 if (die->GetParent() != context_die)
6666 continue;
6667
6668 Type *matching_type = ResolveType (dwarf_cu, die);
6669
Greg Clayton42ce2f32011-12-12 21:50:19 +00006670 lldb::clang_type_t type = matching_type->GetClangForwardType();
Greg Claytoncb5860a2011-10-13 23:49:28 +00006671 clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type);
6672
6673 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
6674 {
6675 clang::TagDecl *tag_decl = tag_type->getDecl();
6676 results->push_back(tag_decl);
6677 }
6678 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
6679 {
6680 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
6681 results->push_back(typedef_decl);
6682 }
Greg Claytona2721472011-06-25 00:44:06 +00006683 }
6684 }
6685 }
6686}
6687
6688void
6689SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00006690 const clang::DeclContext *decl_context,
6691 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00006692 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
6693{
Greg Clayton85ae2e12011-10-18 23:36:41 +00006694
6695 switch (decl_context->getDeclKind())
6696 {
6697 case clang::Decl::Namespace:
6698 case clang::Decl::TranslationUnit:
6699 {
6700 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6701 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
6702 }
6703 break;
6704 default:
6705 break;
6706 }
Greg Claytona2721472011-06-25 00:44:06 +00006707}
Greg Claytoncaab74e2012-01-28 00:48:57 +00006708
6709bool
6710SymbolFileDWARF::LayoutRecordType (void *baton,
6711 const clang::RecordDecl *record_decl,
6712 uint64_t &size,
6713 uint64_t &alignment,
6714 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
6715 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
6716 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
6717{
6718 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6719 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
6720}
6721
6722
6723bool
6724SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl,
6725 uint64_t &bit_size,
6726 uint64_t &alignment,
6727 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
6728 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
6729 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
6730{
6731 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
6732 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
6733 bool success = false;
6734 base_offsets.clear();
6735 vbase_offsets.clear();
6736 if (pos != m_record_decl_to_layout_map.end())
6737 {
6738 bit_size = pos->second.bit_size;
6739 alignment = pos->second.alignment;
6740 field_offsets.swap(pos->second.field_offsets);
6741 m_record_decl_to_layout_map.erase(pos);
6742 success = true;
6743 }
6744 else
6745 {
6746 bit_size = 0;
6747 alignment = 0;
6748 field_offsets.clear();
6749 }
6750
6751 if (log)
6752 GetObjectFile()->GetModule()->LogMessage (log.get(),
6753 "SymbolFileDWARF::LayoutRecordType (record_decl = %p, bit_size = %llu, alignment = %llu, field_offsets[%u],base_offsets[%u], vbase_offsets[%u]) success = %i",
6754 record_decl,
6755 bit_size,
6756 alignment,
6757 (uint32_t)field_offsets.size(),
6758 (uint32_t)base_offsets.size(),
6759 (uint32_t)vbase_offsets.size(),
6760 success);
6761 return success;
6762}
6763
6764
6765