blob: 9b247c378189fc6b67aea65c4ef13f8f6b7ca616 [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 Clayton3bffb082011-12-10 02:15:28 +000082static inline bool
Sean Callanan5b26f272012-02-04 08:49:35 +000083child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag)
Greg Clayton3bffb082011-12-10 02:15:28 +000084{
Sean Callanan5b26f272012-02-04 08:49:35 +000085 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;
Greg Clayton3bffb082011-12-10 02:15:28 +000097}
Chris Lattner30fdc8d2010-06-08 16:52:24 +000098
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 {
442 debug_info_file_size = section->GetByteSize();
443
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)
446 debug_abbrev_file_size = section->GetByteSize();
447 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)
452 debug_aranges_file_size = section->GetByteSize();
453 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)
458 debug_frame_file_size = section->GetByteSize();
459 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)
464 debug_line_file_size = section->GetByteSize();
465 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)
470 debug_loc_file_size = section->GetByteSize();
471 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)
476 debug_macinfo_file_size = section->GetByteSize();
477 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)
482 debug_pubnames_file_size = section->GetByteSize();
483 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)
488 debug_pubtypes_file_size = section->GetByteSize();
489 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)
494 debug_ranges_file_size = section->GetByteSize();
495 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)
500 debug_str_file_size = section->GetByteSize();
501 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 Claytone72dfb32012-02-24 01:59:29 +0000544 data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetByteSize());
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
709bool
Greg Clayton96d7d742010-11-10 23:42:09 +0000710SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* curr_cu, CompUnitSP& compile_unit_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000711{
Greg Clayton96d7d742010-11-10 23:42:09 +0000712 if (curr_cu != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000713 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000714 const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000715 if (cu_die)
716 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000717 const char * cu_die_name = cu_die->GetName(this, curr_cu);
718 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL);
Jim Ingham0f35ac22011-08-24 23:34:20 +0000719 LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_language, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000720 if (cu_die_name)
721 {
Jim Ingham0909e5f2010-09-16 00:57:33 +0000722 FileSpec cu_file_spec;
723
Greg Clayton7bd65b92011-02-09 23:39:34 +0000724 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0')
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000725 {
Jim Ingham0909e5f2010-09-16 00:57:33 +0000726 // If we have a full path to the compile unit, we don't need to resolve
727 // the file. This can be expensive e.g. when the source files are NFS mounted.
728 cu_file_spec.SetFile (cu_die_name, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000729 }
730 else
731 {
732 std::string fullpath(cu_comp_dir);
733 if (*fullpath.rbegin() != '/')
734 fullpath += '/';
735 fullpath += cu_die_name;
Jim Ingham0909e5f2010-09-16 00:57:33 +0000736 cu_file_spec.SetFile (fullpath.c_str(), false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000737 }
738
Greg Clayton81c22f62011-10-19 18:09:39 +0000739 compile_unit_sp.reset(new CompileUnit (m_obj_file->GetModule(),
740 curr_cu,
741 cu_file_spec,
742 MakeUserID(curr_cu->GetOffset()),
743 cu_language));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000744 if (compile_unit_sp.get())
745 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000746 curr_cu->SetUserData(compile_unit_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000747 return true;
748 }
749 }
750 }
751 }
752 return false;
753}
754
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000755uint32_t
756SymbolFileDWARF::GetNumCompileUnits()
757{
758 DWARFDebugInfo* info = DebugInfo();
759 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000760 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000761 return 0;
762}
763
764CompUnitSP
765SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
766{
767 CompUnitSP comp_unit;
768 DWARFDebugInfo* info = DebugInfo();
769 if (info)
770 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000771 DWARFCompileUnit* curr_cu = info->GetCompileUnitAtIndex(cu_idx);
772 if (curr_cu != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000773 {
774 // Our symbol vendor shouldn't be asking us to add a compile unit that
775 // has already been added to it, which this DWARF plug-in knows as it
776 // stores the lldb compile unit (CompileUnit) pointer in each
777 // DWARFCompileUnit object when it gets added.
Greg Clayton96d7d742010-11-10 23:42:09 +0000778 assert(curr_cu->GetUserData() == NULL);
779 ParseCompileUnit(curr_cu, comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000780 }
781 }
782 return comp_unit;
783}
784
785static void
Greg Claytonea3e7d52011-10-08 00:49:15 +0000786AddRangesToBlock (Block& block,
787 DWARFDebugRanges::RangeList& ranges,
788 addr_t block_base_addr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000789{
Greg Claytonea3e7d52011-10-08 00:49:15 +0000790 const size_t num_ranges = ranges.GetSize();
791 for (size_t i = 0; i<num_ranges; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000792 {
Greg Claytonea3e7d52011-10-08 00:49:15 +0000793 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i);
794 const addr_t range_base = range.GetRangeBase();
795 assert (range_base >= block_base_addr);
796 block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000797 }
Greg Claytonea3e7d52011-10-08 00:49:15 +0000798 block.FinalizeRanges ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000799}
800
801
802Function *
Greg Clayton0fffff52010-09-24 05:15:53 +0000803SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000804{
805 DWARFDebugRanges::RangeList func_ranges;
806 const char *name = NULL;
807 const char *mangled = NULL;
808 int decl_file = 0;
809 int decl_line = 0;
810 int decl_column = 0;
811 int call_file = 0;
812 int call_line = 0;
813 int call_column = 0;
814 DWARFExpression frame_base;
815
Greg Claytonc93237c2010-10-01 20:48:32 +0000816 assert (die->Tag() == DW_TAG_subprogram);
817
818 if (die->Tag() != DW_TAG_subprogram)
819 return NULL;
820
Greg Clayton3c2e3ae2012-02-06 06:42:51 +0000821 if (die->GetDIENamesAndRanges (this,
822 dwarf_cu,
823 name,
824 mangled,
825 func_ranges,
826 decl_file,
827 decl_line,
828 decl_column,
829 call_file,
830 call_line,
831 call_column,
832 &frame_base))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000833 {
834 // Union of all ranges in the function DIE (if the function is discontiguous)
835 AddressRange func_range;
Greg Claytonea3e7d52011-10-08 00:49:15 +0000836 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0);
837 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000838 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
839 {
840 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList());
841 if (func_range.GetBaseAddress().IsValid())
842 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
843 }
844
845 if (func_range.GetBaseAddress().IsValid())
846 {
847 Mangled func_name;
848 if (mangled)
849 func_name.SetValue(mangled, true);
850 else if (name)
851 func_name.SetValue(name, false);
852
853 FunctionSP func_sp;
854 std::auto_ptr<Declaration> decl_ap;
855 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +0000856 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
857 decl_line,
858 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000859
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000860 // Supply the type _only_ if it has already been parsed
Greg Clayton594e5ed2010-09-27 21:07:38 +0000861 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000862
863 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
864
865 func_range.GetBaseAddress().ResolveLinkedAddress();
866
Greg Clayton81c22f62011-10-19 18:09:39 +0000867 const user_id_t func_user_id = MakeUserID(die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000868 func_sp.reset(new Function (sc.comp_unit,
Greg Clayton81c22f62011-10-19 18:09:39 +0000869 func_user_id, // UserID is the DIE offset
870 func_user_id,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000871 func_name,
872 func_type,
873 func_range)); // first address range
874
875 if (func_sp.get() != NULL)
876 {
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000877 if (frame_base.IsValid())
878 func_sp->GetFrameBaseExpression() = frame_base;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000879 sc.comp_unit->AddFunction(func_sp);
880 return func_sp.get();
881 }
882 }
883 }
884 return NULL;
885}
886
887size_t
888SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
889{
890 assert (sc.comp_unit);
891 size_t functions_added = 0;
Greg Clayton0fffff52010-09-24 05:15:53 +0000892 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000893 if (dwarf_cu)
894 {
895 DWARFDIECollection function_dies;
896 const size_t num_funtions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
897 size_t func_idx;
898 for (func_idx = 0; func_idx < num_funtions; ++func_idx)
899 {
900 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
Greg Clayton81c22f62011-10-19 18:09:39 +0000901 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000902 {
903 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
904 ++functions_added;
905 }
906 }
907 //FixupTypes();
908 }
909 return functions_added;
910}
911
912bool
913SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
914{
915 assert (sc.comp_unit);
Greg Clayton96d7d742010-11-10 23:42:09 +0000916 DWARFCompileUnit* curr_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
917 assert (curr_cu);
918 const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000919
920 if (cu_die)
921 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000922 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL);
923 dw_offset_t stmt_list = cu_die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000924
925 // All file indexes in DWARF are one based and a file of index zero is
926 // supposed to be the compile unit itself.
927 support_files.Append (*sc.comp_unit);
928
929 return DWARFDebugLine::ParseSupportFiles(get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
930 }
931 return false;
932}
933
934struct ParseDWARFLineTableCallbackInfo
935{
936 LineTable* line_table;
937 const SectionList *section_list;
938 lldb::addr_t prev_sect_file_base_addr;
939 lldb::addr_t curr_sect_file_base_addr;
940 bool is_oso_for_debug_map;
941 bool prev_in_final_executable;
942 DWARFDebugLine::Row prev_row;
943 SectionSP prev_section_sp;
944 SectionSP curr_section_sp;
945};
946
947//----------------------------------------------------------------------
948// ParseStatementTableCallback
949//----------------------------------------------------------------------
950static void
951ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
952{
953 LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table;
954 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
955 {
956 // Just started parsing the line table
957 }
958 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
959 {
960 // Done parsing line table, nothing to do for the cleanup
961 }
962 else
963 {
964 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
965 // We have a new row, lets append it
966
967 if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false)
968 {
969 info->prev_section_sp = info->curr_section_sp;
970 info->prev_sect_file_base_addr = info->curr_sect_file_base_addr;
971 // If this is an end sequence entry, then we subtract one from the
972 // address to make sure we get an address that is not the end of
973 // a section.
974 if (state.end_sequence && state.address != 0)
975 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1);
976 else
977 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address);
978
979 if (info->curr_section_sp.get())
980 info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress ();
981 else
982 info->curr_sect_file_base_addr = 0;
983 }
984 if (info->curr_section_sp.get())
985 {
986 lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr;
987 // Check for the fancy section magic to determine if we
988
989 if (info->is_oso_for_debug_map)
990 {
991 // When this is a debug map object file that contains DWARF
992 // (referenced from an N_OSO debug map nlist entry) we will have
993 // a file address in the file range for our section from the
994 // original .o file, and a load address in the executable that
995 // contains the debug map.
996 //
997 // If the sections for the file range and load range are
998 // different, we have a remapped section for the function and
999 // this address is resolved. If they are the same, then the
1000 // function for this address didn't make it into the final
1001 // executable.
1002 bool curr_in_final_executable = info->curr_section_sp->GetLinkedSection () != NULL;
1003
1004 // If we are doing DWARF with debug map, then we need to carefully
1005 // add each line table entry as there may be gaps as functions
1006 // get moved around or removed.
1007 if (!info->prev_row.end_sequence && info->prev_section_sp.get())
1008 {
1009 if (info->prev_in_final_executable)
1010 {
1011 bool terminate_previous_entry = false;
1012 if (!curr_in_final_executable)
1013 {
1014 // Check for the case where the previous line entry
1015 // in a function made it into the final executable,
1016 // yet the current line entry falls in a function
1017 // that didn't. The line table used to be contiguous
1018 // through this address range but now it isn't. We
1019 // need to terminate the previous line entry so
1020 // that we can reconstruct the line range correctly
1021 // for it and to keep the line table correct.
1022 terminate_previous_entry = true;
1023 }
1024 else if (info->curr_section_sp.get() != info->prev_section_sp.get())
1025 {
1026 // Check for cases where the line entries used to be
1027 // contiguous address ranges, but now they aren't.
1028 // This can happen when order files specify the
1029 // ordering of the functions.
1030 lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr;
1031 Section *curr_sect = info->curr_section_sp.get();
1032 Section *prev_sect = info->prev_section_sp.get();
1033 assert (curr_sect->GetLinkedSection());
1034 assert (prev_sect->GetLinkedSection());
1035 lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address;
1036 lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset;
1037 lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset;
1038 lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr;
1039 if (object_file_addr_delta != linked_file_addr_delta)
1040 terminate_previous_entry = true;
1041 }
1042
1043 if (terminate_previous_entry)
1044 {
1045 line_table->InsertLineEntry (info->prev_section_sp,
1046 state.address - info->prev_sect_file_base_addr,
1047 info->prev_row.line,
1048 info->prev_row.column,
1049 info->prev_row.file,
1050 false, // is_stmt
1051 false, // basic_block
1052 false, // state.prologue_end
1053 false, // state.epilogue_begin
1054 true); // end_sequence);
1055 }
1056 }
1057 }
1058
1059 if (curr_in_final_executable)
1060 {
1061 line_table->InsertLineEntry (info->curr_section_sp,
1062 curr_line_section_offset,
1063 state.line,
1064 state.column,
1065 state.file,
1066 state.is_stmt,
1067 state.basic_block,
1068 state.prologue_end,
1069 state.epilogue_begin,
1070 state.end_sequence);
1071 info->prev_section_sp = info->curr_section_sp;
1072 }
1073 else
1074 {
1075 // If the current address didn't make it into the final
1076 // executable, the current section will be the __text
1077 // segment in the .o file, so we need to clear this so
1078 // we can catch the next function that did make it into
1079 // the final executable.
1080 info->prev_section_sp.reset();
1081 info->curr_section_sp.reset();
1082 }
1083
1084 info->prev_in_final_executable = curr_in_final_executable;
1085 }
1086 else
1087 {
1088 // We are not in an object file that contains DWARF for an
1089 // N_OSO, this is just a normal DWARF file. The DWARF spec
1090 // guarantees that the addresses will be in increasing order
1091 // so, since we store line tables in file address order, we
1092 // can always just append the line entry without needing to
1093 // search for the correct insertion point (we don't need to
1094 // use LineEntry::InsertLineEntry()).
1095 line_table->AppendLineEntry (info->curr_section_sp,
1096 curr_line_section_offset,
1097 state.line,
1098 state.column,
1099 state.file,
1100 state.is_stmt,
1101 state.basic_block,
1102 state.prologue_end,
1103 state.epilogue_begin,
1104 state.end_sequence);
1105 }
1106 }
1107
1108 info->prev_row = state;
1109 }
1110}
1111
1112bool
1113SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1114{
1115 assert (sc.comp_unit);
1116 if (sc.comp_unit->GetLineTable() != NULL)
1117 return true;
1118
1119 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
1120 if (dwarf_cu)
1121 {
1122 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Greg Clayton129d12c2011-11-28 03:29:03 +00001123 if (dwarf_cu_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001124 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001125 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1126 if (cu_line_offset != DW_INVALID_OFFSET)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001127 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001128 std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
1129 if (line_table_ap.get())
1130 {
1131 ParseDWARFLineTableCallbackInfo info = {
1132 line_table_ap.get(),
1133 m_obj_file->GetSectionList(),
1134 0,
1135 0,
1136 m_debug_map_symfile != NULL,
1137 false,
1138 DWARFDebugLine::Row(),
1139 SectionSP(),
1140 SectionSP()
1141 };
1142 uint32_t offset = cu_line_offset;
1143 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
1144 sc.comp_unit->SetLineTable(line_table_ap.release());
1145 return true;
1146 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001147 }
1148 }
1149 }
1150 return false;
1151}
1152
1153size_t
1154SymbolFileDWARF::ParseFunctionBlocks
1155(
1156 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001157 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001158 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001159 const DWARFDebugInfoEntry *die,
1160 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001161 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001162)
1163{
1164 size_t blocks_added = 0;
1165 while (die != NULL)
1166 {
1167 dw_tag_t tag = die->Tag();
1168
1169 switch (tag)
1170 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001171 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001172 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001173 case DW_TAG_lexical_block:
1174 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001175 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001176 if (tag == DW_TAG_subprogram)
1177 {
1178 // Skip any DW_TAG_subprogram DIEs that are inside
1179 // of a normal or inlined functions. These will be
1180 // parsed on their own as separate entities.
1181
1182 if (depth > 0)
1183 break;
1184
1185 block = parent_block;
1186 }
1187 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001188 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001189 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001190 parent_block->AddChild(block_sp);
1191 block = block_sp.get();
1192 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001193 DWARFDebugRanges::RangeList ranges;
1194 const char *name = NULL;
1195 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001196
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001197 int decl_file = 0;
1198 int decl_line = 0;
1199 int decl_column = 0;
1200 int call_file = 0;
1201 int call_line = 0;
1202 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001203 if (die->GetDIENamesAndRanges (this,
1204 dwarf_cu,
1205 name,
1206 mangled_name,
1207 ranges,
1208 decl_file, decl_line, decl_column,
1209 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001210 {
1211 if (tag == DW_TAG_subprogram)
1212 {
1213 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001214 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001215 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001216 else if (tag == DW_TAG_inlined_subroutine)
1217 {
1218 // We get called here for inlined subroutines in two ways.
1219 // The first time is when we are making the Function object
1220 // for this inlined concrete instance. Since we're creating a top level block at
1221 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1222 // adjust the containing address.
1223 // The second time is when we are parsing the blocks inside the function that contains
1224 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1225 // function the offset will be for that function.
1226 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1227 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001228 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001229 }
1230 }
1231
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001232 AddRangesToBlock (*block, ranges, subprogram_low_pc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001233
1234 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1235 {
1236 std::auto_ptr<Declaration> decl_ap;
1237 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001238 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1239 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001240
1241 std::auto_ptr<Declaration> call_ap;
1242 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001243 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1244 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001245
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001246 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001247 }
1248
1249 ++blocks_added;
1250
Greg Claytondd7feaf2011-08-12 17:54:33 +00001251 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001252 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001253 blocks_added += ParseFunctionBlocks (sc,
1254 block,
1255 dwarf_cu,
1256 die->GetFirstChild(),
1257 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001258 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001259 }
1260 }
1261 }
1262 break;
1263 default:
1264 break;
1265 }
1266
Greg Claytondd7feaf2011-08-12 17:54:33 +00001267 // Only parse siblings of the block if we are not at depth zero. A depth
1268 // of zero indicates we are currently parsing the top level
1269 // DW_TAG_subprogram DIE
1270
1271 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001272 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001273 else
1274 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001275 }
1276 return blocks_added;
1277}
1278
Greg Claytonf0705c82011-10-22 03:33:13 +00001279bool
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001280SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu,
1281 const DWARFDebugInfoEntry *die,
1282 ClangASTContext::TemplateParameterInfos &template_param_infos)
1283{
1284 const dw_tag_t tag = die->Tag();
1285
1286 switch (tag)
1287 {
1288 case DW_TAG_template_type_parameter:
1289 case DW_TAG_template_value_parameter:
1290 {
1291 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
1292
1293 DWARFDebugInfoEntry::Attributes attributes;
1294 const size_t num_attributes = die->GetAttributes (this,
1295 dwarf_cu,
1296 fixed_form_sizes,
1297 attributes);
1298 const char *name = NULL;
1299 Type *lldb_type = NULL;
1300 clang_type_t clang_type = NULL;
1301 uint64_t uval64 = 0;
1302 bool uval64_valid = false;
1303 if (num_attributes > 0)
1304 {
1305 DWARFFormValue form_value;
1306 for (size_t i=0; i<num_attributes; ++i)
1307 {
1308 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1309
1310 switch (attr)
1311 {
1312 case DW_AT_name:
1313 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1314 name = form_value.AsCString(&get_debug_str_data());
1315 break;
1316
1317 case DW_AT_type:
1318 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1319 {
1320 const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu);
1321 lldb_type = ResolveTypeUID(type_die_offset);
1322 if (lldb_type)
1323 clang_type = lldb_type->GetClangForwardType();
1324 }
1325 break;
1326
1327 case DW_AT_const_value:
1328 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1329 {
1330 uval64_valid = true;
1331 uval64 = form_value.Unsigned();
1332 }
1333 break;
1334 default:
1335 break;
1336 }
1337 }
1338
1339 if (name && lldb_type && clang_type)
1340 {
1341 bool is_signed = false;
1342 template_param_infos.names.push_back(name);
1343 clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type));
1344 if (tag == DW_TAG_template_value_parameter && ClangASTContext::IsIntegerType (clang_type, is_signed) && uval64_valid)
1345 {
1346 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
1347 template_param_infos.args.push_back (clang::TemplateArgument (llvm::APSInt(apint), clang_qual_type));
1348 }
1349 else
1350 {
1351 template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type));
1352 }
1353 }
1354 else
1355 {
1356 return false;
1357 }
1358
1359 }
1360 }
1361 return true;
1362
1363 default:
1364 break;
1365 }
1366 return false;
1367}
1368
1369bool
Greg Claytonf0705c82011-10-22 03:33:13 +00001370SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1371 const DWARFDebugInfoEntry *parent_die,
1372 ClangASTContext::TemplateParameterInfos &template_param_infos)
1373{
1374
1375 if (parent_die == NULL)
1376 return NULL;
1377
Greg Claytonf0705c82011-10-22 03:33:13 +00001378 Args template_parameter_names;
1379 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1380 die != NULL;
1381 die = die->GetSibling())
1382 {
1383 const dw_tag_t tag = die->Tag();
1384
1385 switch (tag)
1386 {
1387 case DW_TAG_template_type_parameter:
1388 case DW_TAG_template_value_parameter:
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001389 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Claytonf0705c82011-10-22 03:33:13 +00001390 break;
1391
1392 default:
1393 break;
1394 }
1395 }
1396 if (template_param_infos.args.empty())
1397 return false;
1398 return template_param_infos.args.size() == template_param_infos.names.size();
1399}
1400
1401clang::ClassTemplateDecl *
1402SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001403 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001404 const char *parent_name,
1405 int tag_decl_kind,
1406 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1407{
1408 if (template_param_infos.IsValid())
1409 {
1410 std::string template_basename(parent_name);
1411 template_basename.erase (template_basename.find('<'));
1412 ClangASTContext &ast = GetClangASTContext();
1413
1414 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001415 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001416 template_basename.c_str(),
1417 tag_decl_kind,
1418 template_param_infos);
1419 }
1420 return NULL;
1421}
1422
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001423size_t
1424SymbolFileDWARF::ParseChildMembers
1425(
1426 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001427 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001428 const DWARFDebugInfoEntry *parent_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00001429 clang_type_t class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001430 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001431 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1432 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001433 DWARFDIECollection& member_function_dies,
Sean Callananc7fbf732010-08-06 00:32:49 +00001434 AccessType& default_accessibility,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001435 bool &is_a_class,
1436 LayoutInfo &layout_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001437)
1438{
1439 if (parent_die == NULL)
1440 return 0;
1441
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001442 size_t count = 0;
1443 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001444 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001445 uint32_t member_idx = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00001446
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001447 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1448 {
1449 dw_tag_t tag = die->Tag();
1450
1451 switch (tag)
1452 {
1453 case DW_TAG_member:
1454 {
1455 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001456 const size_t num_attributes = die->GetAttributes (this,
1457 dwarf_cu,
1458 fixed_form_sizes,
1459 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001460 if (num_attributes > 0)
1461 {
1462 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001463 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001464 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001465 const char *prop_name = NULL;
1466 const char *prop_getter_name = NULL;
1467 const char *prop_setter_name = NULL;
1468 uint32_t prop_attributes = 0;
1469
1470
Greg Clayton24739922010-10-13 03:15:28 +00001471 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001472 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001473 AccessType accessibility = eAccessNone;
Greg Claytoncaab74e2012-01-28 00:48:57 +00001474 uint32_t member_byte_offset = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001475 size_t byte_size = 0;
1476 size_t bit_offset = 0;
1477 size_t bit_size = 0;
1478 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001479 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001480 {
1481 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1482 DWARFFormValue form_value;
1483 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1484 {
1485 switch (attr)
1486 {
1487 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1488 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1489 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1490 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1491 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1492 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1493 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1494 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1495 case DW_AT_data_member_location:
Greg Claytoncaab74e2012-01-28 00:48:57 +00001496 if (form_value.BlockData())
1497 {
1498 Value initialValue(0);
1499 Value memberOffset(0);
1500 const DataExtractor& debug_info_data = get_debug_info_data();
1501 uint32_t block_length = form_value.Unsigned();
1502 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1503 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
1504 NULL, // clang::ASTContext *
1505 NULL, // ClangExpressionVariableList *
1506 NULL, // ClangExpressionDeclMap *
1507 NULL, // RegisterContext *
1508 debug_info_data,
1509 block_offset,
1510 block_length,
1511 eRegisterKindDWARF,
1512 &initialValue,
1513 memberOffset,
1514 NULL))
1515 {
1516 member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1517 }
1518 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001519 break;
1520
Greg Clayton8cf05932010-07-22 18:30:50 +00001521 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton24739922010-10-13 03:15:28 +00001522 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001523 case DW_AT_declaration:
1524 case DW_AT_description:
1525 case DW_AT_mutable:
1526 case DW_AT_visibility:
Jim Inghame3ae82a2011-11-12 01:36:43 +00001527
1528 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1529 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1530 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1531 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
1532
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001533 default:
1534 case DW_AT_sibling:
1535 break;
1536 }
1537 }
1538 }
Sean Callanan5a477cf2010-10-30 01:56:10 +00001539
Greg Clayton44953932011-10-25 01:25:35 +00001540 // Clang has a DWARF generation bug where sometimes it
1541 // represents fields that are references with bad byte size
1542 // and bit size/offset information such as:
1543 //
1544 // DW_AT_byte_size( 0x00 )
1545 // DW_AT_bit_size( 0x40 )
1546 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1547 //
1548 // So check the bit offset to make sure it is sane, and if
1549 // the values are not sane, remove them. If we don't do this
1550 // then we will end up with a crash if we try to use this
1551 // type in an expression when clang becomes unhappy with its
1552 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001553
Greg Clayton44953932011-10-25 01:25:35 +00001554 if (bit_offset > 128)
1555 {
1556 bit_size = 0;
1557 bit_offset = 0;
1558 }
1559
1560 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00001561 if (class_language == eLanguageTypeObjC ||
1562 class_language == eLanguageTypeObjC_plus_plus)
1563 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001564
1565 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1566 {
1567 // Not all compilers will mark the vtable pointer
1568 // member as artificial (llvm-gcc). We can't have
1569 // the virtual members in our classes otherwise it
1570 // throws off all child offsets since we end up
1571 // having and extra pointer sized member in our
1572 // class layouts.
1573 is_artificial = true;
1574 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001575
Greg Clayton24739922010-10-13 03:15:28 +00001576 if (is_artificial == false)
1577 {
1578 Type *member_type = ResolveTypeUID(encoding_uid);
Jim Inghame3ae82a2011-11-12 01:36:43 +00001579 clang::FieldDecl *field_decl = NULL;
Greg Claytond16e1e52011-07-12 17:06:17 +00001580 if (member_type)
1581 {
1582 if (accessibility == eAccessNone)
1583 accessibility = default_accessibility;
1584 member_accessibilities.push_back(accessibility);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001585
Jim Inghame3ae82a2011-11-12 01:36:43 +00001586 field_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
Greg Clayton42ce2f32011-12-12 21:50:19 +00001587 name,
1588 member_type->GetClangLayoutType(),
1589 accessibility,
1590 bit_size);
Greg Claytond16e1e52011-07-12 17:06:17 +00001591 }
1592 else
1593 {
1594 if (name)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001595 GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member '%s' refers to type 0x%8.8llx which was unable to be parsed",
1596 MakeUserID(die->GetOffset()),
1597 name,
1598 encoding_uid);
Greg Claytond16e1e52011-07-12 17:06:17 +00001599 else
Greg Claytone38a5ed2012-01-05 03:57:59 +00001600 GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member refers to type 0x%8.8llx which was unable to be parsed",
1601 MakeUserID(die->GetOffset()),
1602 encoding_uid);
Greg Claytond16e1e52011-07-12 17:06:17 +00001603 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00001604
Sean Callanan5b26f272012-02-04 08:49:35 +00001605 if (member_byte_offset != UINT32_MAX || bit_size != 0)
Greg Claytoncaab74e2012-01-28 00:48:57 +00001606 {
Sean Callanan5b26f272012-02-04 08:49:35 +00001607 /////////////////////////////////////////////////////////////
1608 // How to locate a field given the DWARF debug information
1609 //
1610 // AT_byte_size indicates the size of the word in which the
1611 // bit offset must be interpreted.
1612 //
1613 // AT_data_member_location indicates the byte offset of the
1614 // word from the base address of the structure.
1615 //
1616 // AT_bit_offset indicates how many bits into the word
1617 // (according to the host endianness) the low-order bit of
1618 // the field starts. AT_bit_offset can be negative.
1619 //
1620 // AT_bit_size indicates the size of the field in bits.
1621 /////////////////////////////////////////////////////////////
1622
1623 ByteOrder object_endian = GetObjectFile()->GetModule()->GetArchitecture().GetDefaultEndian();
1624
1625 uint64_t total_bit_offset = 0;
1626
1627 total_bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
1628
1629 if (object_endian == eByteOrderLittle)
1630 {
1631 total_bit_offset += byte_size * 8;
1632 total_bit_offset -= (bit_offset + bit_size);
1633 }
1634 else
1635 {
1636 total_bit_offset += bit_offset;
1637 }
1638
1639 layout_info.field_offsets.insert(std::make_pair(field_decl, total_bit_offset));
Greg Claytoncaab74e2012-01-28 00:48:57 +00001640 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00001641 if (prop_name != NULL)
1642 {
1643
1644 clang::ObjCIvarDecl *ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
1645 assert (ivar_decl != NULL);
1646
1647
1648 GetClangASTContext().AddObjCClassProperty (class_clang_type,
1649 prop_name,
1650 0,
1651 ivar_decl,
1652 prop_setter_name,
1653 prop_getter_name,
1654 prop_attributes);
1655 }
Greg Clayton24739922010-10-13 03:15:28 +00001656 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001657 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00001658 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001659 }
1660 break;
1661
1662 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00001663 // Let the type parsing code handle this one for us.
1664 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001665 break;
1666
1667 case DW_TAG_inheritance:
1668 {
1669 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00001670 if (default_accessibility == eAccessNone)
1671 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001672 // TODO: implement DW_TAG_inheritance type parsing
1673 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001674 const size_t num_attributes = die->GetAttributes (this,
1675 dwarf_cu,
1676 fixed_form_sizes,
1677 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001678 if (num_attributes > 0)
1679 {
1680 Declaration decl;
1681 DWARFExpression location;
1682 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001683 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001684 bool is_virtual = false;
1685 bool is_base_of_class = true;
1686 off_t member_offset = 0;
1687 uint32_t i;
1688 for (i=0; i<num_attributes; ++i)
1689 {
1690 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1691 DWARFFormValue form_value;
1692 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1693 {
1694 switch (attr)
1695 {
1696 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1697 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1698 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1699 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1700 case DW_AT_data_member_location:
1701 if (form_value.BlockData())
1702 {
1703 Value initialValue(0);
1704 Value memberOffset(0);
1705 const DataExtractor& debug_info_data = get_debug_info_data();
1706 uint32_t block_length = form_value.Unsigned();
1707 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
Greg Claytonba2d22d2010-11-13 22:57:37 +00001708 if (DWARFExpression::Evaluate (NULL,
1709 NULL,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001710 NULL,
1711 NULL,
Jason Molenda2d107dd2010-11-20 01:28:30 +00001712 NULL,
Greg Clayton1a65ae12011-01-25 23:55:37 +00001713 debug_info_data,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001714 block_offset,
1715 block_length,
1716 eRegisterKindDWARF,
1717 &initialValue,
1718 memberOffset,
1719 NULL))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001720 {
1721 member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1722 }
1723 }
1724 break;
1725
1726 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00001727 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001728 break;
1729
1730 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
1731 default:
1732 case DW_AT_sibling:
1733 break;
1734 }
1735 }
1736 }
1737
Greg Clayton526e5af2010-11-13 03:52:47 +00001738 Type *base_class_type = ResolveTypeUID(encoding_uid);
1739 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001740
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001741 clang_type_t base_class_clang_type = base_class_type->GetClangFullType();
1742 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001743 if (class_language == eLanguageTypeObjC)
1744 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001745 GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001746 }
1747 else
1748 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001749 base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001750 accessibility,
1751 is_virtual,
1752 is_base_of_class));
Greg Clayton9e409562010-07-28 02:04:09 +00001753 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001754 }
1755 }
1756 break;
1757
1758 default:
1759 break;
1760 }
1761 }
1762 return count;
1763}
1764
1765
1766clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00001767SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001768{
1769 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00001770 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001771 {
1772 DWARFCompileUnitSP cu_sp;
1773 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1774 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00001775 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00001776 }
1777 return NULL;
1778}
1779
1780clang::DeclContext*
1781SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
1782{
Greg Clayton81c22f62011-10-19 18:09:39 +00001783 if (UserIDMatches(type_uid))
1784 return GetClangDeclContextForDIEOffset (sc, type_uid);
1785 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001786}
1787
1788Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00001789SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001790{
Greg Clayton81c22f62011-10-19 18:09:39 +00001791 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001792 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001793 DWARFDebugInfo* debug_info = DebugInfo();
1794 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00001795 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001796 DWARFCompileUnitSP cu_sp;
1797 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00001798 const bool assert_not_being_parsed = true;
1799 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00001800 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001801 }
1802 return NULL;
1803}
1804
Greg Claytoncab36a32011-12-08 05:16:30 +00001805Type*
1806SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00001807{
Greg Claytoncab36a32011-12-08 05:16:30 +00001808 if (die != NULL)
1809 {
Greg Clayton3bffb082011-12-10 02:15:28 +00001810 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
1811 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001812 GetObjectFile()->GetModule()->LogMessage (log.get(),
1813 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
1814 die->GetOffset(),
1815 DW_TAG_value_to_name(die->Tag()),
1816 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00001817
Greg Claytoncab36a32011-12-08 05:16:30 +00001818 // We might be coming in in the middle of a type tree (a class
1819 // withing a class, an enum within a class), so parse any needed
1820 // parent DIEs before we get to this one...
1821 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
1822 switch (decl_ctx_die->Tag())
1823 {
1824 case DW_TAG_structure_type:
1825 case DW_TAG_union_type:
1826 case DW_TAG_class_type:
1827 {
1828 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00001829 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001830 GetObjectFile()->GetModule()->LogMessage (log.get(),
1831 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
1832 die->GetOffset(),
1833 DW_TAG_value_to_name(die->Tag()),
1834 die->GetName(this, cu),
1835 decl_ctx_die->GetOffset());
Greg Clayton3bffb082011-12-10 02:15:28 +00001836
Greg Claytoncab36a32011-12-08 05:16:30 +00001837 Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
Sean Callanan5b26f272012-02-04 08:49:35 +00001838 if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
Greg Clayton3bffb082011-12-10 02:15:28 +00001839 {
1840 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001841 GetObjectFile()->GetModule()->LogMessage (log.get(),
1842 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
1843 die->GetOffset(),
1844 DW_TAG_value_to_name(die->Tag()),
1845 die->GetName(this, cu),
1846 decl_ctx_die->GetOffset());
Greg Clayton3bffb082011-12-10 02:15:28 +00001847 // Ask the type to complete itself if it already hasn't since if we
1848 // want a function (method or static) from a class, the class must
1849 // create itself and add it's own methods and class functions.
1850 if (parent_type)
1851 parent_type->GetClangFullType();
1852 }
Greg Claytoncab36a32011-12-08 05:16:30 +00001853 }
1854 break;
1855
1856 default:
1857 break;
1858 }
1859 return ResolveType (cu, die);
1860 }
1861 return NULL;
1862}
1863
Greg Clayton6beaaa62011-01-17 03:46:26 +00001864// This function is used when SymbolFileDWARFDebugMap owns a bunch of
1865// SymbolFileDWARF objects to detect if this DWARF file is the one that
1866// can resolve a clang_type.
1867bool
1868SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type)
1869{
1870 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1871 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
1872 return die != NULL;
1873}
1874
1875
Greg Clayton1be10fc2010-09-29 01:12:09 +00001876lldb::clang_type_t
1877SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
1878{
1879 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001880 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1881 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001882 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00001883 {
1884 // We have already resolved this type...
1885 return clang_type;
1886 }
1887 // Once we start resolving this type, remove it from the forward declaration
1888 // map in case anyone child members or other types require this type to get resolved.
1889 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
1890 // are done.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001891 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers);
Greg Clayton73b472d2010-10-27 03:32:59 +00001892
Greg Clayton1be10fc2010-09-29 01:12:09 +00001893
Greg Clayton85ae2e12011-10-18 23:36:41 +00001894 // Disable external storage for this type so we don't get anymore
1895 // clang::ExternalASTSource queries for this type.
1896 ClangASTContext::SetHasExternalStorage (clang_type, false);
1897
Greg Clayton450e3f32010-10-12 02:24:53 +00001898 DWARFDebugInfo* debug_info = DebugInfo();
1899
Greg Clayton96d7d742010-11-10 23:42:09 +00001900 DWARFCompileUnit *curr_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001901 Type *type = m_die_to_type.lookup (die);
1902
1903 const dw_tag_t tag = die->Tag();
1904
Greg Clayton3bffb082011-12-10 02:15:28 +00001905 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
1906 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001907 GetObjectFile()->GetModule()->LogMessage (log.get(),
1908 "0x%8.8llx: %s '%s' resolving forward declaration...\n",
1909 MakeUserID(die->GetOffset()),
1910 DW_TAG_value_to_name(tag),
1911 type->GetName().AsCString());
Greg Clayton1be10fc2010-09-29 01:12:09 +00001912 assert (clang_type);
1913 DWARFDebugInfoEntry::Attributes attributes;
1914
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001915 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001916
1917 switch (tag)
1918 {
1919 case DW_TAG_structure_type:
1920 case DW_TAG_union_type:
1921 case DW_TAG_class_type:
Greg Claytonc93237c2010-10-01 20:48:32 +00001922 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00001923 LayoutInfo layout_info;
Sean Callanan77a1fd32012-02-27 20:07:01 +00001924
1925 ast.StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001926 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00001927 if (die->HasChildren())
Greg Claytonc93237c2010-10-01 20:48:32 +00001928 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00001929
Sean Callanan77a1fd32012-02-27 20:07:01 +00001930 LanguageType class_language = eLanguageTypeUnknown;
1931 bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
1932 if (is_objc_class)
1933 class_language = eLanguageTypeObjC;
1934
1935 int tag_decl_kind = -1;
1936 AccessType default_accessibility = eAccessNone;
1937 if (tag == DW_TAG_structure_type)
1938 {
1939 tag_decl_kind = clang::TTK_Struct;
1940 default_accessibility = eAccessPublic;
1941 }
1942 else if (tag == DW_TAG_union_type)
1943 {
1944 tag_decl_kind = clang::TTK_Union;
1945 default_accessibility = eAccessPublic;
1946 }
1947 else if (tag == DW_TAG_class_type)
1948 {
1949 tag_decl_kind = clang::TTK_Class;
1950 default_accessibility = eAccessPrivate;
1951 }
1952
1953 SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu));
1954 std::vector<clang::CXXBaseSpecifier *> base_classes;
1955 std::vector<int> member_accessibilities;
1956 bool is_a_class = false;
1957 // Parse members and base classes first
1958 DWARFDIECollection member_function_dies;
1959
1960 ParseChildMembers (sc,
1961 curr_cu,
1962 die,
1963 clang_type,
1964 class_language,
1965 base_classes,
1966 member_accessibilities,
1967 member_function_dies,
1968 default_accessibility,
1969 is_a_class,
1970 layout_info);
1971
1972 // Now parse any methods if there were any...
1973 size_t num_functions = member_function_dies.Size();
1974 if (num_functions > 0)
1975 {
1976 for (size_t i=0; i<num_functions; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00001977 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00001978 ResolveType(curr_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytoncaab74e2012-01-28 00:48:57 +00001979 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00001980 }
1981
1982 if (class_language == eLanguageTypeObjC)
1983 {
1984 std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(clang_type));
1985 if (!class_str.empty())
Greg Claytoncaab74e2012-01-28 00:48:57 +00001986 {
Greg Clayton450e3f32010-10-12 02:24:53 +00001987
Sean Callanan77a1fd32012-02-27 20:07:01 +00001988 DIEArray method_die_offsets;
1989 if (m_using_apple_tables)
Greg Clayton95d87902011-11-11 03:16:25 +00001990 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00001991 if (m_apple_objc_ap.get())
1992 m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets);
1993 }
1994 else
1995 {
1996 if (!m_indexed)
1997 Index ();
Greg Claytoncaab74e2012-01-28 00:48:57 +00001998
Sean Callanan77a1fd32012-02-27 20:07:01 +00001999 ConstString class_name (class_str.c_str());
2000 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
2001 }
2002
2003 if (!method_die_offsets.empty())
2004 {
2005 DWARFDebugInfo* debug_info = DebugInfo();
2006
2007 DWARFCompileUnit* method_cu = NULL;
2008 const size_t num_matches = method_die_offsets.size();
2009 for (size_t i=0; i<num_matches; ++i)
Greg Clayton95d87902011-11-11 03:16:25 +00002010 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002011 const dw_offset_t die_offset = method_die_offsets[i];
2012 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
2013
2014 if (method_die)
2015 ResolveType (method_cu, method_die);
2016 else
Greg Claytoncaab74e2012-01-28 00:48:57 +00002017 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002018 if (m_using_apple_tables)
2019 {
2020 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n",
2021 die_offset, class_str.c_str());
2022 }
2023 }
2024 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002025 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002026 }
2027 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002028
2029 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2030 // need to tell the clang type it is actually a class.
2031 if (class_language != eLanguageTypeObjC)
2032 {
2033 if (is_a_class && tag_decl_kind != clang::TTK_Class)
2034 ast.SetTagTypeKind (clang_type, clang::TTK_Class);
2035 }
2036
2037 // Since DW_TAG_structure_type gets used for both classes
2038 // and structures, we may need to set any DW_TAG_member
2039 // fields to have a "private" access if none was specified.
2040 // When we parsed the child members we tracked that actual
2041 // accessibility value for each DW_TAG_member in the
2042 // "member_accessibilities" array. If the value for the
2043 // member is zero, then it was set to the "default_accessibility"
2044 // which for structs was "public". Below we correct this
2045 // by setting any fields to "private" that weren't correctly
2046 // set.
2047 if (is_a_class && !member_accessibilities.empty())
2048 {
2049 // This is a class and all members that didn't have
2050 // their access specified are private.
2051 ast.SetDefaultAccessForRecordFields (clang_type,
2052 eAccessPrivate,
2053 &member_accessibilities.front(),
2054 member_accessibilities.size());
2055 }
2056
2057 if (!base_classes.empty())
2058 {
2059 ast.SetBaseClassesForClassType (clang_type,
2060 &base_classes.front(),
2061 base_classes.size());
2062
2063 // Clang will copy each CXXBaseSpecifier in "base_classes"
2064 // so we have to free them all.
2065 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
2066 base_classes.size());
2067 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002068 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002069 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002070 ast.CompleteTagDeclarationDefinition (clang_type);
Sean Callanan5b26f272012-02-04 08:49:35 +00002071
Greg Claytoncaab74e2012-01-28 00:48:57 +00002072 if (!layout_info.field_offsets.empty())
2073 {
2074 if (type)
2075 layout_info.bit_size = type->GetByteSize() * 8;
2076 if (layout_info.bit_size == 0)
2077 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_byte_size, 0) * 8;
2078 clang::QualType qual_type(clang::QualType::getFromOpaquePtr(clang_type));
2079 const clang::RecordType *record_type = clang::dyn_cast<clang::RecordType>(qual_type.getTypePtr());
2080 if (record_type)
2081 {
2082 const clang::RecordDecl *record_decl = record_type->getDecl();
2083
2084 if (log)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002085 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002086 GetObjectFile()->GetModule()->LogMessage (log.get(),
Greg Clayton821ac6d2012-01-28 02:22:27 +00002087 "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 +00002088 clang_type,
2089 record_decl,
2090 layout_info.bit_size,
2091 layout_info.alignment,
2092 (uint32_t)layout_info.field_offsets.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002093
Greg Clayton821ac6d2012-01-28 02:22:27 +00002094 llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end();
2095 for (pos = layout_info.field_offsets.begin(); pos != end; ++pos)
2096 {
2097 GetObjectFile()->GetModule()->LogMessage (log.get(),
2098 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field = { bit_offset=%u, name='%s' }",
2099 clang_type,
2100 (uint32_t)pos->second,
2101 pos->first->getNameAsString().c_str());
2102 }
2103 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002104 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2105 }
2106 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002107 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002108
Greg Claytonc93237c2010-10-01 20:48:32 +00002109 return clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002110
2111 case DW_TAG_enumeration_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002112 ast.StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002113 if (die->HasChildren())
2114 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002115 SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu));
2116 ParseChildEnumerators(sc, clang_type, type->GetByteSize(), curr_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002117 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002118 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002119 return clang_type;
2120
2121 default:
2122 assert(false && "not a forward clang type decl!");
2123 break;
2124 }
2125 return NULL;
2126}
2127
Greg Claytonc685f8e2010-09-15 04:15:46 +00002128Type*
Greg Clayton96d7d742010-11-10 23:42:09 +00002129SymbolFileDWARF::ResolveType (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002130{
2131 if (type_die != NULL)
2132 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002133 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00002134
Greg Claytonc685f8e2010-09-15 04:15:46 +00002135 if (type == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00002136 type = GetTypeForDIE (curr_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00002137
Greg Clayton24739922010-10-13 03:15:28 +00002138 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00002139 {
2140 if (type != DIE_IS_BEING_PARSED)
2141 return type;
2142
2143 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
2144 type_die->GetOffset(),
2145 DW_TAG_value_to_name(type_die->Tag()),
2146 type_die->GetName(this, curr_cu));
2147
2148 }
2149 else
2150 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002151 }
2152 return NULL;
2153}
2154
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002155CompileUnit*
Greg Clayton96d7d742010-11-10 23:42:09 +00002156SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* curr_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002157{
2158 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton96d7d742010-11-10 23:42:09 +00002159 if (curr_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002160 {
2161 // The symbol vendor doesn't know about this compile unit, we
2162 // need to parse and add it to the symbol vendor object.
2163 CompUnitSP dc_cu;
Greg Clayton96d7d742010-11-10 23:42:09 +00002164 ParseCompileUnit(curr_cu, dc_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002165 if (dc_cu.get())
2166 {
2167 // Figure out the compile unit index if we weren't given one
Greg Clayton016a95e2010-09-14 02:20:48 +00002168 if (cu_idx == UINT32_MAX)
Greg Clayton96d7d742010-11-10 23:42:09 +00002169 DebugInfo()->GetCompileUnit(curr_cu->GetOffset(), &cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002170
2171 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(dc_cu, cu_idx);
Greg Clayton450e3f32010-10-12 02:24:53 +00002172
2173 if (m_debug_map_symfile)
2174 m_debug_map_symfile->SetCompileUnit(this, dc_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002175 }
2176 }
Greg Clayton96d7d742010-11-10 23:42:09 +00002177 return (CompileUnit*)curr_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002178}
2179
2180bool
Greg Clayton96d7d742010-11-10 23:42:09 +00002181SymbolFileDWARF::GetFunction (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002182{
2183 sc.Clear();
2184 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton96d7d742010-11-10 23:42:09 +00002185 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002186
Greg Clayton81c22f62011-10-19 18:09:39 +00002187 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002188 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00002189 sc.function = ParseCompileUnitFunction(sc, curr_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002190
2191 if (sc.function)
2192 {
Greg Claytone72dfb32012-02-24 01:59:29 +00002193 sc.module_sp = sc.function->CalculateSymbolContextModule();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002194 return true;
2195 }
2196
2197 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002198}
2199
2200uint32_t
2201SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2202{
2203 Timer scoped_timer(__PRETTY_FUNCTION__,
2204 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)",
Greg Claytone72dfb32012-02-24 01:59:29 +00002205 so_addr.GetSection().get(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002206 so_addr.GetOffset(),
2207 resolve_scope);
2208 uint32_t resolved = 0;
2209 if (resolve_scope & ( eSymbolContextCompUnit |
2210 eSymbolContextFunction |
2211 eSymbolContextBlock |
2212 eSymbolContextLineEntry))
2213 {
2214 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2215
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002216 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00002217 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002218 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002219 dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002220 if (cu_offset != DW_INVALID_OFFSET)
2221 {
2222 uint32_t cu_idx;
Greg Clayton96d7d742010-11-10 23:42:09 +00002223 DWARFCompileUnit* curr_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
2224 if (curr_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002225 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002226 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002227 assert(sc.comp_unit != NULL);
2228 resolved |= eSymbolContextCompUnit;
2229
2230 if (resolve_scope & eSymbolContextLineEntry)
2231 {
2232 LineTable *line_table = sc.comp_unit->GetLineTable();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002233 if (line_table != NULL)
2234 {
2235 if (so_addr.IsLinkedAddress())
2236 {
2237 Address linked_addr (so_addr);
2238 linked_addr.ResolveLinkedAddress();
2239 if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry))
2240 {
2241 resolved |= eSymbolContextLineEntry;
2242 }
2243 }
2244 else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry))
2245 {
2246 resolved |= eSymbolContextLineEntry;
2247 }
2248 }
2249 }
2250
2251 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2252 {
2253 DWARFDebugInfoEntry *function_die = NULL;
2254 DWARFDebugInfoEntry *block_die = NULL;
2255 if (resolve_scope & eSymbolContextBlock)
2256 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002257 curr_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002258 }
2259 else
2260 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002261 curr_cu->LookupAddress(file_vm_addr, &function_die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002262 }
2263
2264 if (function_die != NULL)
2265 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002266 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002267 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00002268 sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002269 }
2270
2271 if (sc.function != NULL)
2272 {
2273 resolved |= eSymbolContextFunction;
2274
2275 if (resolve_scope & eSymbolContextBlock)
2276 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00002277 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002278
2279 if (block_die != NULL)
Greg Clayton81c22f62011-10-19 18:09:39 +00002280 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002281 else
Greg Clayton81c22f62011-10-19 18:09:39 +00002282 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002283 if (sc.block)
2284 resolved |= eSymbolContextBlock;
2285 }
2286 }
2287 }
2288 }
2289 }
2290 }
2291 }
2292 return resolved;
2293}
2294
2295
2296
2297uint32_t
2298SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
2299{
2300 const uint32_t prev_size = sc_list.GetSize();
2301 if (resolve_scope & eSymbolContextCompUnit)
2302 {
2303 DWARFDebugInfo* debug_info = DebugInfo();
2304 if (debug_info)
2305 {
2306 uint32_t cu_idx;
Greg Clayton96d7d742010-11-10 23:42:09 +00002307 DWARFCompileUnit* curr_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002308
Greg Clayton96d7d742010-11-10 23:42:09 +00002309 for (cu_idx = 0; (curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002310 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002311 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002312 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Compare(file_spec, *dc_cu, false) == 0;
2313 if (check_inlines || file_spec_matches_cu_file_spec)
2314 {
2315 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton96d7d742010-11-10 23:42:09 +00002316 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002317 assert(sc.comp_unit != NULL);
2318
2319 uint32_t file_idx = UINT32_MAX;
2320
2321 // If we are looking for inline functions only and we don't
2322 // find it in the support files, we are done.
2323 if (check_inlines)
2324 {
Jim Ingham87df91b2011-09-23 00:54:11 +00002325 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002326 if (file_idx == UINT32_MAX)
2327 continue;
2328 }
2329
2330 if (line != 0)
2331 {
2332 LineTable *line_table = sc.comp_unit->GetLineTable();
2333
2334 if (line_table != NULL && line != 0)
2335 {
2336 // We will have already looked up the file index if
2337 // we are searching for inline entries.
2338 if (!check_inlines)
Jim Ingham87df91b2011-09-23 00:54:11 +00002339 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002340
2341 if (file_idx != UINT32_MAX)
2342 {
2343 uint32_t found_line;
2344 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
2345 found_line = sc.line_entry.line;
2346
Greg Clayton016a95e2010-09-14 02:20:48 +00002347 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002348 {
2349 sc.function = NULL;
2350 sc.block = NULL;
2351 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2352 {
2353 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
2354 if (file_vm_addr != LLDB_INVALID_ADDRESS)
2355 {
2356 DWARFDebugInfoEntry *function_die = NULL;
2357 DWARFDebugInfoEntry *block_die = NULL;
Greg Clayton96d7d742010-11-10 23:42:09 +00002358 curr_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002359
2360 if (function_die != NULL)
2361 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002362 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002363 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00002364 sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002365 }
2366
2367 if (sc.function != NULL)
2368 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00002369 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002370
2371 if (block_die != NULL)
Greg Clayton81c22f62011-10-19 18:09:39 +00002372 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002373 else
Greg Clayton81c22f62011-10-19 18:09:39 +00002374 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002375 }
2376 }
2377 }
2378
2379 sc_list.Append(sc);
2380 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2381 }
2382 }
2383 }
2384 else if (file_spec_matches_cu_file_spec && !check_inlines)
2385 {
2386 // only append the context if we aren't looking for inline call sites
2387 // by file and line and if the file spec matches that of the compile unit
2388 sc_list.Append(sc);
2389 }
2390 }
2391 else if (file_spec_matches_cu_file_spec && !check_inlines)
2392 {
2393 // only append the context if we aren't looking for inline call sites
2394 // by file and line and if the file spec matches that of the compile unit
2395 sc_list.Append(sc);
2396 }
2397
2398 if (!check_inlines)
2399 break;
2400 }
2401 }
2402 }
2403 }
2404 return sc_list.GetSize() - prev_size;
2405}
2406
2407void
2408SymbolFileDWARF::Index ()
2409{
2410 if (m_indexed)
2411 return;
2412 m_indexed = true;
2413 Timer scoped_timer (__PRETTY_FUNCTION__,
2414 "SymbolFileDWARF::Index (%s)",
2415 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
2416
2417 DWARFDebugInfo* debug_info = DebugInfo();
2418 if (debug_info)
2419 {
2420 uint32_t cu_idx = 0;
2421 const uint32_t num_compile_units = GetNumCompileUnits();
2422 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2423 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002424 DWARFCompileUnit* curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002425
Greg Clayton96d7d742010-11-10 23:42:09 +00002426 bool clear_dies = curr_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002427
Greg Clayton96d7d742010-11-10 23:42:09 +00002428 curr_cu->Index (cu_idx,
Greg Clayton83c5cd92010-11-14 22:13:40 +00002429 m_function_basename_index,
2430 m_function_fullname_index,
2431 m_function_method_index,
2432 m_function_selector_index,
2433 m_objc_class_selectors_index,
2434 m_global_index,
2435 m_type_index,
Greg Claytond4a2b372011-09-12 23:21:58 +00002436 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002437
2438 // Keep memory down by clearing DIEs if this generate function
2439 // caused them to be parsed
2440 if (clear_dies)
Greg Clayton96d7d742010-11-10 23:42:09 +00002441 curr_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002442 }
2443
Greg Claytond4a2b372011-09-12 23:21:58 +00002444 m_function_basename_index.Finalize();
2445 m_function_fullname_index.Finalize();
2446 m_function_method_index.Finalize();
2447 m_function_selector_index.Finalize();
2448 m_objc_class_selectors_index.Finalize();
2449 m_global_index.Finalize();
2450 m_type_index.Finalize();
2451 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002452
Greg Clayton24739922010-10-13 03:15:28 +00002453#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00002454 StreamFile s(stdout, false);
Greg Claytonf9eec202011-09-01 23:16:13 +00002455 s.Printf ("DWARF index for '%s/%s':",
Greg Clayton24739922010-10-13 03:15:28 +00002456 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
2457 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
Greg Claytonba2d22d2010-11-13 22:57:37 +00002458 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
2459 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
2460 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
2461 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
2462 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
2463 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00002464 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00002465 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002466#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002467 }
2468}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002469
2470bool
2471SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
2472{
2473 if (namespace_decl == NULL)
2474 {
2475 // Invalid namespace decl which means we aren't matching only things
2476 // in this symbol file, so return true to indicate it matches this
2477 // symbol file.
2478 return true;
2479 }
2480
2481 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
2482
2483 if (namespace_ast == NULL)
2484 return true; // No AST in the "namespace_decl", return true since it
2485 // could then match any symbol file, including this one
2486
2487 if (namespace_ast == GetClangASTContext().getASTContext())
2488 return true; // The ASTs match, return true
2489
2490 // The namespace AST was valid, and it does not match...
Sean Callananc41e68b2011-10-13 21:08:11 +00002491 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2492
2493 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002494 GetObjectFile()->GetModule()->LogMessage(log.get(), "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00002495
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002496 return false;
2497}
2498
Greg Clayton2506a7a2011-10-12 23:34:26 +00002499bool
2500SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
2501 DWARFCompileUnit* cu,
2502 const DWARFDebugInfoEntry* die)
2503{
2504 // No namespace specified, so the answesr i
2505 if (namespace_decl == NULL)
2506 return true;
Sean Callananebe60672011-10-13 21:50:33 +00002507
2508 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002509
Greg Clayton2506a7a2011-10-12 23:34:26 +00002510 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2511 if (decl_ctx_die)
2512 {
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002513
Greg Clayton2506a7a2011-10-12 23:34:26 +00002514 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
2515 if (clang_namespace_decl)
2516 {
2517 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00002518 {
2519 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002520 GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00002521 return false;
Sean Callananebe60672011-10-13 21:50:33 +00002522 }
2523
Greg Clayton2506a7a2011-10-12 23:34:26 +00002524 DeclContextToDIEMap::iterator pos = m_decl_ctx_to_die.find(clang_namespace_decl);
2525
2526 if (pos == m_decl_ctx_to_die.end())
Sean Callananebe60672011-10-13 21:50:33 +00002527 {
2528 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002529 GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match in a namespace, but its parent is not the requested namespace");
Sean Callananebe60672011-10-13 21:50:33 +00002530
Greg Clayton2506a7a2011-10-12 23:34:26 +00002531 return false;
Sean Callananebe60672011-10-13 21:50:33 +00002532 }
Greg Clayton2506a7a2011-10-12 23:34:26 +00002533
Greg Claytoncb5860a2011-10-13 23:49:28 +00002534 return pos->second.count (decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00002535 }
2536 else
2537 {
2538 // We have a namespace_decl that was not NULL but it contained
2539 // a NULL "clang::NamespaceDecl", so this means the global namespace
2540 // So as long the the contained decl context DIE isn't a namespace
2541 // we should be ok.
2542 if (decl_ctx_die->Tag() != DW_TAG_namespace)
2543 return true;
2544 }
2545 }
Sean Callananebe60672011-10-13 21:50:33 +00002546
2547 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002548 GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00002549
Greg Clayton2506a7a2011-10-12 23:34:26 +00002550 return false;
2551}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002552uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00002553SymbolFileDWARF::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 +00002554{
Greg Clayton21f2a492011-10-06 00:09:08 +00002555 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2556
2557 if (log)
2558 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002559 GetObjectFile()->GetModule()->LogMessage (log.get(),
2560 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
2561 name.GetCString(),
2562 namespace_decl,
2563 append,
2564 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002565 }
Sean Callanan213fdb82011-10-13 01:49:10 +00002566
2567 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2568 return 0;
2569
Greg Claytonc685f8e2010-09-15 04:15:46 +00002570 DWARFDebugInfo* info = DebugInfo();
2571 if (info == NULL)
2572 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002573
2574 // If we aren't appending the results to this list, then clear the list
2575 if (!append)
2576 variables.Clear();
2577
2578 // Remember how many variables are in the list before we search in case
2579 // we are appending the results to a variable list.
2580 const uint32_t original_size = variables.GetSize();
2581
Greg Claytond4a2b372011-09-12 23:21:58 +00002582 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002583
Greg Clayton97fbc342011-10-20 22:30:33 +00002584 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002585 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002586 if (m_apple_names_ap.get())
2587 {
2588 const char *name_cstr = name.GetCString();
2589 const char *base_name_start;
2590 const char *base_name_end = NULL;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002591
Greg Clayton97fbc342011-10-20 22:30:33 +00002592 if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end))
2593 base_name_start = name_cstr;
2594
2595 m_apple_names_ap->FindByName (base_name_start, die_offsets);
2596 }
Greg Clayton7f995132011-10-04 22:41:51 +00002597 }
2598 else
2599 {
2600 // Index the DWARF if we haven't already
2601 if (!m_indexed)
2602 Index ();
2603
2604 m_global_index.Find (name, die_offsets);
2605 }
2606
2607 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002608 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002609 {
Greg Clayton7f995132011-10-04 22:41:51 +00002610 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00002611 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00002612 assert (sc.module_sp);
2613
Greg Claytond4a2b372011-09-12 23:21:58 +00002614 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00002615 DWARFCompileUnit* dwarf_cu = NULL;
2616 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002617 for (size_t i=0; i<num_matches; ++i)
2618 {
2619 const dw_offset_t die_offset = die_offsets[i];
2620 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002621
Greg Clayton95d87902011-11-11 03:16:25 +00002622 if (die)
2623 {
2624 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
2625 assert(sc.comp_unit != NULL);
2626
2627 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2628 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002629
Greg Clayton95d87902011-11-11 03:16:25 +00002630 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002631
Greg Clayton95d87902011-11-11 03:16:25 +00002632 if (variables.GetSize() - original_size >= max_matches)
2633 break;
2634 }
2635 else
2636 {
2637 if (m_using_apple_tables)
2638 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002639 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
2640 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00002641 }
2642 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002643 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002644 }
2645
2646 // Return the number of variable that were appended to the list
2647 return variables.GetSize() - original_size;
2648}
2649
2650uint32_t
2651SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
2652{
Greg Clayton21f2a492011-10-06 00:09:08 +00002653 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2654
2655 if (log)
2656 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002657 GetObjectFile()->GetModule()->LogMessage (log.get(),
2658 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
2659 regex.GetText(),
2660 append,
2661 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002662 }
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 Clayton7f995132011-10-04 22:41:51 +00002676 DIEArray die_offsets;
2677
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())
Greg Claytond1767f02011-12-08 02:13:16 +00002681 {
2682 DWARFMappedHash::DIEInfoArray hash_data_array;
2683 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
2684 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
2685 }
Greg Clayton7f995132011-10-04 22:41:51 +00002686 }
2687 else
2688 {
2689 // Index the DWARF if we haven't already
2690 if (!m_indexed)
2691 Index ();
2692
2693 m_global_index.Find (regex, die_offsets);
2694 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002695
Greg Claytonc685f8e2010-09-15 04:15:46 +00002696 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00002697 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002698 assert (sc.module_sp);
2699
Greg Claytond4a2b372011-09-12 23:21:58 +00002700 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002701 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00002702 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002703 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002704 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002705 DWARFDebugInfo* debug_info = DebugInfo();
2706 for (size_t i=0; i<num_matches; ++i)
2707 {
2708 const dw_offset_t die_offset = die_offsets[i];
2709 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00002710
2711 if (die)
2712 {
2713 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002714
Greg Clayton95d87902011-11-11 03:16:25 +00002715 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002716
Greg Clayton95d87902011-11-11 03:16:25 +00002717 if (variables.GetSize() - original_size >= max_matches)
2718 break;
2719 }
2720 else
2721 {
2722 if (m_using_apple_tables)
2723 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002724 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
2725 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00002726 }
2727 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002728 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002729 }
2730
2731 // Return the number of variable that were appended to the list
2732 return variables.GetSize() - original_size;
2733}
2734
Greg Claytonaa044962011-10-13 00:59:38 +00002735
Jim Ingham4cda6e02011-10-07 22:23:45 +00002736bool
2737SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
2738 DWARFCompileUnit *&dwarf_cu,
2739 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00002740{
Greg Claytonaa044962011-10-13 00:59:38 +00002741 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2742 return ResolveFunction (dwarf_cu, die, sc_list);
2743}
2744
2745
2746bool
2747SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
2748 const DWARFDebugInfoEntry *die,
2749 SymbolContextList& sc_list)
2750{
Greg Clayton9e315582011-09-02 04:03:59 +00002751 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00002752
2753 if (die == NULL)
2754 return false;
2755
Jim Ingham4cda6e02011-10-07 22:23:45 +00002756 // If we were passed a die that is not a function, just return false...
2757 if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine)
2758 return false;
2759
2760 const DWARFDebugInfoEntry* inlined_die = NULL;
2761 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00002762 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002763 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00002764
Jim Ingham4cda6e02011-10-07 22:23:45 +00002765 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00002766 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002767 if (die->Tag() == DW_TAG_subprogram)
2768 break;
Greg Clayton9e315582011-09-02 04:03:59 +00002769 }
2770 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002771 assert (die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00002772 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00002773 {
2774 Address addr;
2775 // Parse all blocks if needed
2776 if (inlined_die)
2777 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002778 sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset()));
Jim Ingham4cda6e02011-10-07 22:23:45 +00002779 assert (sc.block != NULL);
2780 if (sc.block->GetStartAddress (addr) == false)
2781 addr.Clear();
2782 }
2783 else
2784 {
2785 sc.block = NULL;
2786 addr = sc.function->GetAddressRange().GetBaseAddress();
2787 }
2788
2789 if (addr.IsValid())
2790 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002791 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00002792 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002793 }
2794 }
2795
Greg Claytonaa044962011-10-13 00:59:38 +00002796 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00002797}
2798
Greg Clayton7f995132011-10-04 22:41:51 +00002799void
2800SymbolFileDWARF::FindFunctions (const ConstString &name,
2801 const NameToDIE &name_to_die,
2802 SymbolContextList& sc_list)
2803{
Greg Claytond4a2b372011-09-12 23:21:58 +00002804 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002805 if (name_to_die.Find (name, die_offsets))
2806 {
2807 ParseFunctions (die_offsets, sc_list);
2808 }
2809}
2810
2811
2812void
2813SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2814 const NameToDIE &name_to_die,
2815 SymbolContextList& sc_list)
2816{
2817 DIEArray die_offsets;
2818 if (name_to_die.Find (regex, die_offsets))
2819 {
2820 ParseFunctions (die_offsets, sc_list);
2821 }
2822}
2823
2824
2825void
2826SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2827 const DWARFMappedHash::MemoryTable &memory_table,
2828 SymbolContextList& sc_list)
2829{
2830 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00002831 DWARFMappedHash::DIEInfoArray hash_data_array;
2832 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00002833 {
Greg Claytond1767f02011-12-08 02:13:16 +00002834 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Greg Clayton7f995132011-10-04 22:41:51 +00002835 ParseFunctions (die_offsets, sc_list);
2836 }
2837}
2838
2839void
2840SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
2841 SymbolContextList& sc_list)
2842{
2843 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002844 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002845 {
Greg Clayton7f995132011-10-04 22:41:51 +00002846 SymbolContext sc;
Greg Clayton7f995132011-10-04 22:41:51 +00002847
2848 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002849 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00002850 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002851 const dw_offset_t die_offset = die_offsets[i];
Jim Ingham4cda6e02011-10-07 22:23:45 +00002852 ResolveFunction (die_offset, dwarf_cu, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002853 }
2854 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002855}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002856
Jim Ingham4cda6e02011-10-07 22:23:45 +00002857bool
2858SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
2859 const DWARFCompileUnit *dwarf_cu,
2860 uint32_t name_type_mask,
2861 const char *partial_name,
2862 const char *base_name_start,
2863 const char *base_name_end)
2864{
2865 // If we are looking only for methods, throw away all the ones that aren't in C++ classes:
2866 if (name_type_mask == eFunctionNameTypeMethod
2867 || name_type_mask == eFunctionNameTypeBase)
2868 {
Greg Claytonf0705c82011-10-22 03:33:13 +00002869 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
2870 if (!containing_decl_ctx)
2871 return false;
2872
2873 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
2874
2875 if (!is_cxx_method && name_type_mask == eFunctionNameTypeMethod)
2876 return false;
2877 if (is_cxx_method && name_type_mask == eFunctionNameTypeBase)
2878 return false;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002879 }
2880
2881 // Now we need to check whether the name we got back for this type matches the extra specifications
2882 // that were in the name we're looking up:
2883 if (base_name_start != partial_name || *base_name_end != '\0')
2884 {
2885 // First see if the stuff to the left matches the full name. To do that let's see if
2886 // we can pull out the mips linkage name attribute:
2887
2888 Mangled best_name;
2889
2890 DWARFDebugInfoEntry::Attributes attributes;
2891 die->GetAttributes(this, dwarf_cu, NULL, attributes);
2892 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
2893 if (idx != UINT32_MAX)
2894 {
2895 DWARFFormValue form_value;
2896 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
2897 {
2898 const char *name = form_value.AsCString(&get_debug_str_data());
2899 best_name.SetValue (name, true);
2900 }
2901 }
2902 if (best_name)
2903 {
2904 const char *demangled = best_name.GetDemangledName().GetCString();
2905 if (demangled)
2906 {
2907 std::string name_no_parens(partial_name, base_name_end - partial_name);
2908 if (strstr (demangled, name_no_parens.c_str()) == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00002909 return false;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002910 }
2911 }
2912 }
2913
2914 return true;
2915}
Greg Claytonc685f8e2010-09-15 04:15:46 +00002916
Greg Clayton0c5cd902010-06-28 21:30:43 +00002917uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00002918SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00002919 const lldb_private::ClangNamespaceDecl *namespace_decl,
Sean Callanan9df05fb2012-02-10 22:52:19 +00002920 uint32_t name_type_mask,
2921 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00002922 bool append,
2923 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00002924{
2925 Timer scoped_timer (__PRETTY_FUNCTION__,
2926 "SymbolFileDWARF::FindFunctions (name = '%s')",
2927 name.AsCString());
2928
Greg Clayton21f2a492011-10-06 00:09:08 +00002929 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2930
2931 if (log)
2932 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002933 GetObjectFile()->GetModule()->LogMessage (log.get(),
2934 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
2935 name.GetCString(),
2936 name_type_mask,
2937 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00002938 }
2939
Greg Clayton0c5cd902010-06-28 21:30:43 +00002940 // If we aren't appending the results to this list, then clear the list
2941 if (!append)
2942 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00002943
2944 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2945 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002946
2947 // If name is empty then we won't find anything.
2948 if (name.IsEmpty())
2949 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00002950
2951 // Remember how many sc_list are in the list before we search in case
2952 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00002953
Greg Clayton9e315582011-09-02 04:03:59 +00002954 const uint32_t original_size = sc_list.GetSize();
Greg Clayton0c5cd902010-06-28 21:30:43 +00002955
Jim Ingham4cda6e02011-10-07 22:23:45 +00002956 const char *name_cstr = name.GetCString();
2957 uint32_t effective_name_type_mask = eFunctionNameTypeNone;
2958 const char *base_name_start = name_cstr;
2959 const char *base_name_end = name_cstr + strlen(name_cstr);
2960
2961 if (name_type_mask & eFunctionNameTypeAuto)
2962 {
2963 if (CPPLanguageRuntime::IsCPPMangledName (name_cstr))
2964 effective_name_type_mask = eFunctionNameTypeFull;
2965 else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr))
2966 effective_name_type_mask = eFunctionNameTypeFull;
2967 else
2968 {
2969 if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
2970 effective_name_type_mask |= eFunctionNameTypeSelector;
2971
2972 if (CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
2973 effective_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
2974 }
2975 }
2976 else
2977 {
2978 effective_name_type_mask = name_type_mask;
2979 if (effective_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase)
2980 {
2981 // If they've asked for a CPP method or function name and it can't be that, we don't
2982 // even need to search for CPP methods or names.
2983 if (!CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
2984 {
2985 effective_name_type_mask &= ~(eFunctionNameTypeMethod | eFunctionNameTypeBase);
2986 if (effective_name_type_mask == eFunctionNameTypeNone)
2987 return 0;
2988 }
2989 }
2990
2991 if (effective_name_type_mask & eFunctionNameTypeSelector)
2992 {
2993 if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
2994 {
2995 effective_name_type_mask &= ~(eFunctionNameTypeSelector);
2996 if (effective_name_type_mask == eFunctionNameTypeNone)
2997 return 0;
2998 }
2999 }
3000 }
3001
3002 DWARFDebugInfo* info = DebugInfo();
3003 if (info == NULL)
3004 return 0;
3005
Greg Claytonaa044962011-10-13 00:59:38 +00003006 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton97fbc342011-10-20 22:30:33 +00003007 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00003008 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003009 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003010 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003011
3012 DIEArray die_offsets;
3013
3014 uint32_t num_matches = 0;
3015
3016 if (effective_name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00003017 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003018 // If they asked for the full name, match what they typed. At some point we may
3019 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
3020 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00003021 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003022 for (uint32_t i = 0; i < num_matches; i++)
3023 {
Greg Clayton95d87902011-11-11 03:16:25 +00003024 const dw_offset_t die_offset = die_offsets[i];
3025 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00003026 if (die)
3027 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003028 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3029 continue;
3030
Sean Callanan9df05fb2012-02-10 22:52:19 +00003031 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3032 continue;
3033
Greg Claytonaa044962011-10-13 00:59:38 +00003034 ResolveFunction (dwarf_cu, die, sc_list);
3035 }
Greg Clayton95d87902011-11-11 03:16:25 +00003036 else
3037 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003038 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3039 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003040 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003041 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003042 }
3043 else
3044 {
3045 if (effective_name_type_mask & eFunctionNameTypeSelector)
3046 {
3047 if (namespace_decl && *namespace_decl)
3048 return 0; // no selectors in namespaces
3049
3050 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3051 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
3052 // and if it is an ObjC method name, we're good.
3053
3054 for (uint32_t i = 0; i < num_matches; i++)
3055 {
Greg Clayton95d87902011-11-11 03:16:25 +00003056 const dw_offset_t die_offset = die_offsets[i];
3057 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton97fbc342011-10-20 22:30:33 +00003058 if (die)
3059 {
3060 const char *die_name = die->GetName(this, dwarf_cu);
3061 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
Sean Callanan9df05fb2012-02-10 22:52:19 +00003062 {
3063 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3064 continue;
3065
Greg Clayton97fbc342011-10-20 22:30:33 +00003066 ResolveFunction (dwarf_cu, die, sc_list);
Sean Callanan9df05fb2012-02-10 22:52:19 +00003067 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003068 }
Greg Clayton95d87902011-11-11 03:16:25 +00003069 else
3070 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003071 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3072 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003073 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003074 }
3075 die_offsets.clear();
3076 }
3077
3078 if (effective_name_type_mask & eFunctionNameTypeMethod
3079 || effective_name_type_mask & eFunctionNameTypeBase)
3080 {
3081 if ((effective_name_type_mask & eFunctionNameTypeMethod) &&
3082 (namespace_decl && *namespace_decl))
3083 return 0; // no methods in namespaces
3084
3085 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
3086 // extract the base name, look that up, and if there is any other information in the name we were
3087 // passed in we have to post-filter based on that.
3088
3089 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
3090 std::string base_name(base_name_start, base_name_end - base_name_start);
3091 num_matches = m_apple_names_ap->FindByName (base_name.c_str(), die_offsets);
3092
3093 for (uint32_t i = 0; i < num_matches; i++)
3094 {
Greg Clayton95d87902011-11-11 03:16:25 +00003095 const dw_offset_t die_offset = die_offsets[i];
3096 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton97fbc342011-10-20 22:30:33 +00003097 if (die)
3098 {
3099 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3100 continue;
3101
3102 if (!FunctionDieMatchesPartialName(die,
3103 dwarf_cu,
3104 effective_name_type_mask,
3105 name_cstr,
3106 base_name_start,
3107 base_name_end))
3108 continue;
Sean Callanan9df05fb2012-02-10 22:52:19 +00003109
3110 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3111 continue;
Greg Clayton97fbc342011-10-20 22:30:33 +00003112
3113 // If we get to here, the die is good, and we should add it:
3114 ResolveFunction (dwarf_cu, die, sc_list);
3115 }
Greg Clayton95d87902011-11-11 03:16:25 +00003116 else
3117 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003118 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3119 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003120 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003121 }
3122 die_offsets.clear();
3123 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003124 }
3125 }
Greg Clayton7f995132011-10-04 22:41:51 +00003126 }
3127 else
3128 {
3129
3130 // Index the DWARF if we haven't already
3131 if (!m_indexed)
3132 Index ();
3133
Greg Clayton7f995132011-10-04 22:41:51 +00003134 if (name_type_mask & eFunctionNameTypeFull)
3135 FindFunctions (name, m_function_fullname_index, sc_list);
3136
Jim Ingham4cda6e02011-10-07 22:23:45 +00003137 std::string base_name(base_name_start, base_name_end - base_name_start);
3138 ConstString base_name_const(base_name.c_str());
3139 DIEArray die_offsets;
3140 DWARFCompileUnit *dwarf_cu = NULL;
3141
3142 if (effective_name_type_mask & eFunctionNameTypeBase)
3143 {
3144 uint32_t num_base = m_function_basename_index.Find(base_name_const, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00003145 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003146 {
Greg Claytonaa044962011-10-13 00:59:38 +00003147 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3148 if (die)
3149 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003150 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3151 continue;
3152
Greg Claytonaa044962011-10-13 00:59:38 +00003153 if (!FunctionDieMatchesPartialName(die,
3154 dwarf_cu,
3155 effective_name_type_mask,
3156 name_cstr,
3157 base_name_start,
3158 base_name_end))
3159 continue;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003160
Sean Callanan9df05fb2012-02-10 22:52:19 +00003161 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3162 continue;
3163
Greg Claytonaa044962011-10-13 00:59:38 +00003164 // If we get to here, the die is good, and we should add it:
3165 ResolveFunction (dwarf_cu, die, sc_list);
3166 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003167 }
3168 die_offsets.clear();
3169 }
3170
Jim Inghamea8005a2011-10-11 01:18:11 +00003171 if (effective_name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003172 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003173 if (namespace_decl && *namespace_decl)
3174 return 0; // no methods in namespaces
3175
Jim Ingham4cda6e02011-10-07 22:23:45 +00003176 uint32_t num_base = m_function_method_index.Find(base_name_const, die_offsets);
3177 {
Greg Claytonaa044962011-10-13 00:59:38 +00003178 for (uint32_t i = 0; i < num_base; i++)
3179 {
3180 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3181 if (die)
3182 {
3183 if (!FunctionDieMatchesPartialName(die,
3184 dwarf_cu,
3185 effective_name_type_mask,
3186 name_cstr,
3187 base_name_start,
3188 base_name_end))
3189 continue;
3190
Sean Callanan9df05fb2012-02-10 22:52:19 +00003191 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3192 continue;
3193
Greg Claytonaa044962011-10-13 00:59:38 +00003194 // If we get to here, the die is good, and we should add it:
3195 ResolveFunction (dwarf_cu, die, sc_list);
3196 }
3197 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003198 }
3199 die_offsets.clear();
3200 }
Greg Clayton7f995132011-10-04 22:41:51 +00003201
Sean Callanan213fdb82011-10-13 01:49:10 +00003202 if ((effective_name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003203 {
Greg Clayton7f995132011-10-04 22:41:51 +00003204 FindFunctions (name, m_function_selector_index, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003205 }
3206
Greg Clayton4d01ace2011-09-29 16:58:15 +00003207 }
3208
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003209 // Return the number of variable that were appended to the list
3210 return sc_list.GetSize() - original_size;
3211}
3212
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003213uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00003214SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003215{
3216 Timer scoped_timer (__PRETTY_FUNCTION__,
3217 "SymbolFileDWARF::FindFunctions (regex = '%s')",
3218 regex.GetText());
3219
Greg Clayton21f2a492011-10-06 00:09:08 +00003220 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3221
3222 if (log)
3223 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003224 GetObjectFile()->GetModule()->LogMessage (log.get(),
3225 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
3226 regex.GetText(),
3227 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003228 }
3229
3230
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003231 // If we aren't appending the results to this list, then clear the list
3232 if (!append)
3233 sc_list.Clear();
3234
3235 // Remember how many sc_list are in the list before we search in case
3236 // we are appending the results to a variable list.
3237 uint32_t original_size = sc_list.GetSize();
3238
Greg Clayton97fbc342011-10-20 22:30:33 +00003239 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003240 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003241 if (m_apple_names_ap.get())
3242 FindFunctions (regex, *m_apple_names_ap, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003243 }
3244 else
3245 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003246 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00003247 if (!m_indexed)
3248 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003249
Greg Clayton7f995132011-10-04 22:41:51 +00003250 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003251
Greg Clayton7f995132011-10-04 22:41:51 +00003252 FindFunctions (regex, m_function_fullname_index, sc_list);
3253 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003254
3255 // Return the number of variable that were appended to the list
3256 return sc_list.GetSize() - original_size;
3257}
Jim Ingham318c9f22011-08-26 19:44:13 +00003258
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003259uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00003260SymbolFileDWARF::FindTypes (const SymbolContext& sc,
3261 const ConstString &name,
3262 const lldb_private::ClangNamespaceDecl *namespace_decl,
3263 bool append,
3264 uint32_t max_matches,
3265 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003266{
Greg Claytonc685f8e2010-09-15 04:15:46 +00003267 DWARFDebugInfo* info = DebugInfo();
3268 if (info == NULL)
3269 return 0;
3270
Greg Clayton21f2a492011-10-06 00:09:08 +00003271 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3272
3273 if (log)
3274 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003275 GetObjectFile()->GetModule()->LogMessage (log.get(),
3276 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", append=%u, max_matches=%u, type_list)",
3277 name.GetCString(),
3278 append,
3279 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003280 }
3281
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003282 // If we aren't appending the results to this list, then clear the list
3283 if (!append)
3284 types.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003285
3286 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3287 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003288
Greg Claytond4a2b372011-09-12 23:21:58 +00003289 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003290
Greg Clayton97fbc342011-10-20 22:30:33 +00003291 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003292 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003293 if (m_apple_types_ap.get())
3294 {
3295 const char *name_cstr = name.GetCString();
3296 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3297 }
Greg Clayton7f995132011-10-04 22:41:51 +00003298 }
3299 else
3300 {
3301 if (!m_indexed)
3302 Index ();
3303
3304 m_type_index.Find (name, die_offsets);
3305 }
3306
Greg Clayton7f995132011-10-04 22:41:51 +00003307 const size_t num_matches = die_offsets.size();
3308
Greg Claytond4a2b372011-09-12 23:21:58 +00003309 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003310 {
Greg Clayton7f995132011-10-04 22:41:51 +00003311 const uint32_t initial_types_size = types.GetSize();
3312 DWARFCompileUnit* dwarf_cu = NULL;
3313 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003314 DWARFDebugInfo* debug_info = DebugInfo();
3315 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003316 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003317 const dw_offset_t die_offset = die_offsets[i];
3318 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3319
Greg Clayton95d87902011-11-11 03:16:25 +00003320 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00003321 {
Greg Clayton95d87902011-11-11 03:16:25 +00003322 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3323 continue;
3324
3325 Type *matching_type = ResolveType (dwarf_cu, die);
3326 if (matching_type)
3327 {
3328 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003329 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00003330 if (types.GetSize() >= max_matches)
3331 break;
3332 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00003333 }
Greg Clayton95d87902011-11-11 03:16:25 +00003334 else
3335 {
3336 if (m_using_apple_tables)
3337 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003338 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
3339 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003340 }
3341 }
3342
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003343 }
Greg Clayton7f995132011-10-04 22:41:51 +00003344 return types.GetSize() - initial_types_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003345 }
Greg Clayton7f995132011-10-04 22:41:51 +00003346 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003347}
3348
3349
Greg Clayton526e5af2010-11-13 03:52:47 +00003350ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00003351SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00003352 const ConstString &name,
3353 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00003354{
Greg Clayton21f2a492011-10-06 00:09:08 +00003355 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3356
3357 if (log)
3358 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003359 GetObjectFile()->GetModule()->LogMessage (log.get(),
3360 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
3361 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00003362 }
Sean Callanan213fdb82011-10-13 01:49:10 +00003363
3364 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
3365 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00003366
Greg Clayton526e5af2010-11-13 03:52:47 +00003367 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003368 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00003369 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00003370 {
Greg Clayton7f995132011-10-04 22:41:51 +00003371 DIEArray die_offsets;
3372
Greg Clayton526e5af2010-11-13 03:52:47 +00003373 // Index if we already haven't to make sure the compile units
3374 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00003375 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003376 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003377 if (m_apple_namespaces_ap.get())
3378 {
3379 const char *name_cstr = name.GetCString();
3380 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
3381 }
Greg Clayton7f995132011-10-04 22:41:51 +00003382 }
3383 else
3384 {
3385 if (!m_indexed)
3386 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00003387
Greg Clayton7f995132011-10-04 22:41:51 +00003388 m_namespace_index.Find (name, die_offsets);
3389 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003390
3391 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00003392 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003393 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003394 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00003395 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003396 DWARFDebugInfo* debug_info = DebugInfo();
3397 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00003398 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003399 const dw_offset_t die_offset = die_offsets[i];
3400 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00003401
Greg Clayton95d87902011-11-11 03:16:25 +00003402 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00003403 {
Greg Clayton95d87902011-11-11 03:16:25 +00003404 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
3405 continue;
3406
3407 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
3408 if (clang_namespace_decl)
3409 {
3410 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
3411 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
Greg Claytond1767f02011-12-08 02:13:16 +00003412 break;
Greg Clayton95d87902011-11-11 03:16:25 +00003413 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003414 }
Greg Clayton95d87902011-11-11 03:16:25 +00003415 else
3416 {
3417 if (m_using_apple_tables)
3418 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003419 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
3420 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003421 }
3422 }
3423
Greg Clayton526e5af2010-11-13 03:52:47 +00003424 }
3425 }
Greg Clayton96d7d742010-11-10 23:42:09 +00003426 }
Greg Clayton526e5af2010-11-13 03:52:47 +00003427 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003428}
3429
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003430uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003431SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003432{
3433 // Remember how many sc_list are in the list before we search in case
3434 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003435 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003436
3437 const uint32_t num_die_offsets = die_offsets.size();
3438 // Parse all of the types we found from the pubtypes matches
3439 uint32_t i;
3440 uint32_t num_matches = 0;
3441 for (i = 0; i < num_die_offsets; ++i)
3442 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003443 Type *matching_type = ResolveTypeUID (die_offsets[i]);
3444 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003445 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003446 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003447 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003448 ++num_matches;
3449 if (num_matches >= max_matches)
3450 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003451 }
3452 }
3453
3454 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003455 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003456}
3457
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003458
3459size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00003460SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
3461 clang::DeclContext *containing_decl_ctx,
Greg Clayton5113dc82011-08-12 06:47:54 +00003462 DWARFCompileUnit* dwarf_cu,
3463 const DWARFDebugInfoEntry *parent_die,
3464 bool skip_artificial,
3465 bool &is_static,
3466 TypeList* type_list,
3467 std::vector<clang_type_t>& function_param_types,
3468 std::vector<clang::ParmVarDecl*>& function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00003469 unsigned &type_quals,
3470 ClangASTContext::TemplateParameterInfos &template_param_infos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003471{
3472 if (parent_die == NULL)
3473 return 0;
3474
Greg Claytond88d7592010-09-15 08:33:30 +00003475 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3476
Greg Clayton7fedea22010-11-16 02:10:54 +00003477 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003478 const DWARFDebugInfoEntry *die;
3479 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3480 {
3481 dw_tag_t tag = die->Tag();
3482 switch (tag)
3483 {
3484 case DW_TAG_formal_parameter:
3485 {
3486 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003487 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003488 if (num_attributes > 0)
3489 {
3490 const char *name = NULL;
3491 Declaration decl;
3492 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003493 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003494 // one of None, Auto, Register, Extern, Static, PrivateExtern
3495
Sean Callanane2ef6e32010-09-23 03:01:22 +00003496 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003497 uint32_t i;
3498 for (i=0; i<num_attributes; ++i)
3499 {
3500 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3501 DWARFFormValue form_value;
3502 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3503 {
3504 switch (attr)
3505 {
3506 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3507 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3508 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3509 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
3510 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003511 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003512 case DW_AT_location:
3513 // if (form_value.BlockData())
3514 // {
3515 // const DataExtractor& debug_info_data = debug_info();
3516 // uint32_t block_length = form_value.Unsigned();
3517 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
3518 // }
3519 // else
3520 // {
3521 // }
3522 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003523 case DW_AT_const_value:
3524 case DW_AT_default_value:
3525 case DW_AT_description:
3526 case DW_AT_endianity:
3527 case DW_AT_is_optional:
3528 case DW_AT_segment:
3529 case DW_AT_variable_parameter:
3530 default:
3531 case DW_AT_abstract_origin:
3532 case DW_AT_sibling:
3533 break;
3534 }
3535 }
3536 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00003537
Greg Clayton0fffff52010-09-24 05:15:53 +00003538 bool skip = false;
3539 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003540 {
Greg Clayton0fffff52010-09-24 05:15:53 +00003541 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00003542 {
3543 // In order to determine if a C++ member function is
3544 // "const" we have to look at the const-ness of "this"...
3545 // Ugly, but that
3546 if (arg_idx == 0)
3547 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003548 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00003549 {
Greg Clayton5113dc82011-08-12 06:47:54 +00003550 // Often times compilers omit the "this" name for the
3551 // specification DIEs, so we can't rely upon the name
3552 // being in the formal parameter DIE...
3553 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00003554 {
Greg Clayton5113dc82011-08-12 06:47:54 +00003555 Type *this_type = ResolveTypeUID (param_type_die_offset);
3556 if (this_type)
3557 {
3558 uint32_t encoding_mask = this_type->GetEncodingMask();
3559 if (encoding_mask & Type::eEncodingIsPointerUID)
3560 {
3561 is_static = false;
3562
3563 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
3564 type_quals |= clang::Qualifiers::Const;
3565 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
3566 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00003567 }
3568 }
3569 }
3570 }
3571 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003572 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00003573 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003574 else
3575 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003576
Greg Clayton0fffff52010-09-24 05:15:53 +00003577 // HACK: Objective C formal parameters "self" and "_cmd"
3578 // are not marked as artificial in the DWARF...
Greg Clayton96d7d742010-11-10 23:42:09 +00003579 CompileUnit *curr_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
3580 if (curr_cu && (curr_cu->GetLanguage() == eLanguageTypeObjC || curr_cu->GetLanguage() == eLanguageTypeObjC_plus_plus))
Greg Clayton0fffff52010-09-24 05:15:53 +00003581 {
3582 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
3583 skip = true;
3584 }
3585 }
3586 }
3587
3588 if (!skip)
3589 {
3590 Type *type = ResolveTypeUID(param_type_die_offset);
3591 if (type)
3592 {
Greg Claytonc93237c2010-10-01 20:48:32 +00003593 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00003594
Greg Clayton42ce2f32011-12-12 21:50:19 +00003595 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
3596 type->GetClangForwardType(),
3597 storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00003598 assert(param_var_decl);
3599 function_param_decls.push_back(param_var_decl);
3600 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003601 }
3602 }
Greg Clayton7fedea22010-11-16 02:10:54 +00003603 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003604 }
3605 break;
3606
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00003607 case DW_TAG_template_type_parameter:
3608 case DW_TAG_template_value_parameter:
3609 ParseTemplateDIE (dwarf_cu, die,template_param_infos);
3610 break;
3611
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003612 default:
3613 break;
3614 }
3615 }
Greg Clayton7fedea22010-11-16 02:10:54 +00003616 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003617}
3618
3619size_t
3620SymbolFileDWARF::ParseChildEnumerators
3621(
3622 const SymbolContext& sc,
Greg Clayton1be10fc2010-09-29 01:12:09 +00003623 clang_type_t enumerator_clang_type,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003624 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00003625 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003626 const DWARFDebugInfoEntry *parent_die
3627)
3628{
3629 if (parent_die == NULL)
3630 return 0;
3631
3632 size_t enumerators_added = 0;
3633 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00003634 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3635
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003636 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3637 {
3638 const dw_tag_t tag = die->Tag();
3639 if (tag == DW_TAG_enumerator)
3640 {
3641 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003642 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003643 if (num_child_attributes > 0)
3644 {
3645 const char *name = NULL;
3646 bool got_value = false;
3647 int64_t enum_value = 0;
3648 Declaration decl;
3649
3650 uint32_t i;
3651 for (i=0; i<num_child_attributes; ++i)
3652 {
3653 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3654 DWARFFormValue form_value;
3655 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3656 {
3657 switch (attr)
3658 {
3659 case DW_AT_const_value:
3660 got_value = true;
3661 enum_value = form_value.Unsigned();
3662 break;
3663
3664 case DW_AT_name:
3665 name = form_value.AsCString(&get_debug_str_data());
3666 break;
3667
3668 case DW_AT_description:
3669 default:
3670 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3671 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3672 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3673 case DW_AT_sibling:
3674 break;
3675 }
3676 }
3677 }
3678
3679 if (name && name[0] && got_value)
3680 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003681 GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
3682 enumerator_clang_type,
3683 decl,
3684 name,
3685 enum_value,
3686 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003687 ++enumerators_added;
3688 }
3689 }
3690 }
3691 }
3692 return enumerators_added;
3693}
3694
3695void
3696SymbolFileDWARF::ParseChildArrayInfo
3697(
3698 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00003699 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003700 const DWARFDebugInfoEntry *parent_die,
3701 int64_t& first_index,
3702 std::vector<uint64_t>& element_orders,
3703 uint32_t& byte_stride,
3704 uint32_t& bit_stride
3705)
3706{
3707 if (parent_die == NULL)
3708 return;
3709
3710 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00003711 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003712 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3713 {
3714 const dw_tag_t tag = die->Tag();
3715 switch (tag)
3716 {
3717 case DW_TAG_enumerator:
3718 {
3719 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003720 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003721 if (num_child_attributes > 0)
3722 {
3723 const char *name = NULL;
3724 bool got_value = false;
3725 int64_t enum_value = 0;
3726
3727 uint32_t i;
3728 for (i=0; i<num_child_attributes; ++i)
3729 {
3730 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3731 DWARFFormValue form_value;
3732 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3733 {
3734 switch (attr)
3735 {
3736 case DW_AT_const_value:
3737 got_value = true;
3738 enum_value = form_value.Unsigned();
3739 break;
3740
3741 case DW_AT_name:
3742 name = form_value.AsCString(&get_debug_str_data());
3743 break;
3744
3745 case DW_AT_description:
3746 default:
3747 case DW_AT_decl_file:
3748 case DW_AT_decl_line:
3749 case DW_AT_decl_column:
3750 case DW_AT_sibling:
3751 break;
3752 }
3753 }
3754 }
3755 }
3756 }
3757 break;
3758
3759 case DW_TAG_subrange_type:
3760 {
3761 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003762 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003763 if (num_child_attributes > 0)
3764 {
3765 const char *name = NULL;
3766 bool got_value = false;
3767 uint64_t byte_size = 0;
3768 int64_t enum_value = 0;
3769 uint64_t num_elements = 0;
3770 uint64_t lower_bound = 0;
3771 uint64_t upper_bound = 0;
3772 uint32_t i;
3773 for (i=0; i<num_child_attributes; ++i)
3774 {
3775 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3776 DWARFFormValue form_value;
3777 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3778 {
3779 switch (attr)
3780 {
3781 case DW_AT_const_value:
3782 got_value = true;
3783 enum_value = form_value.Unsigned();
3784 break;
3785
3786 case DW_AT_name:
3787 name = form_value.AsCString(&get_debug_str_data());
3788 break;
3789
3790 case DW_AT_count:
3791 num_elements = form_value.Unsigned();
3792 break;
3793
3794 case DW_AT_bit_stride:
3795 bit_stride = form_value.Unsigned();
3796 break;
3797
3798 case DW_AT_byte_stride:
3799 byte_stride = form_value.Unsigned();
3800 break;
3801
3802 case DW_AT_byte_size:
3803 byte_size = form_value.Unsigned();
3804 break;
3805
3806 case DW_AT_lower_bound:
3807 lower_bound = form_value.Unsigned();
3808 break;
3809
3810 case DW_AT_upper_bound:
3811 upper_bound = form_value.Unsigned();
3812 break;
3813
3814 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003815 case DW_AT_abstract_origin:
3816 case DW_AT_accessibility:
3817 case DW_AT_allocated:
3818 case DW_AT_associated:
3819 case DW_AT_data_location:
3820 case DW_AT_declaration:
3821 case DW_AT_description:
3822 case DW_AT_sibling:
3823 case DW_AT_threads_scaled:
3824 case DW_AT_type:
3825 case DW_AT_visibility:
3826 break;
3827 }
3828 }
3829 }
3830
3831 if (upper_bound > lower_bound)
3832 num_elements = upper_bound - lower_bound + 1;
3833
3834 if (num_elements > 0)
3835 element_orders.push_back (num_elements);
3836 }
3837 }
3838 break;
3839 }
3840 }
3841}
3842
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003843TypeSP
Greg Clayton96d7d742010-11-10 23:42:09 +00003844SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003845{
3846 TypeSP type_sp;
3847 if (die != NULL)
3848 {
Greg Clayton96d7d742010-11-10 23:42:09 +00003849 assert(curr_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00003850 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003851 if (type_ptr == NULL)
3852 {
Greg Claytonca512b32011-01-14 04:54:56 +00003853 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(curr_cu);
3854 assert (lldb_cu);
3855 SymbolContext sc(lldb_cu);
Greg Clayton96d7d742010-11-10 23:42:09 +00003856 type_sp = ParseType(sc, curr_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003857 }
3858 else if (type_ptr != DIE_IS_BEING_PARSED)
3859 {
3860 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00003861 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003862 }
3863
3864 }
3865 return type_sp;
3866}
3867
3868clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00003869SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003870{
3871 if (die_offset != DW_INVALID_OFFSET)
3872 {
3873 DWARFCompileUnitSP cu_sp;
3874 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00003875 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003876 }
3877 return NULL;
3878}
3879
Sean Callanan72e49402011-08-05 23:43:37 +00003880clang::DeclContext *
3881SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
3882{
3883 if (die_offset != DW_INVALID_OFFSET)
3884 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00003885 DWARFDebugInfo* debug_info = DebugInfo();
3886 if (debug_info)
3887 {
3888 DWARFCompileUnitSP cu_sp;
3889 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
3890 if (die)
3891 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
3892 }
Sean Callanan72e49402011-08-05 23:43:37 +00003893 }
3894 return NULL;
3895}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003896
Greg Clayton96d7d742010-11-10 23:42:09 +00003897clang::NamespaceDecl *
3898SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die)
3899{
Greg Clayton030a2042011-10-14 21:34:45 +00003900 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00003901 {
Greg Clayton030a2042011-10-14 21:34:45 +00003902 // See if we already parsed this namespace DIE and associated it with a
3903 // uniqued namespace declaration
3904 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
3905 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00003906 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00003907 else
3908 {
3909 const char *namespace_name = die->GetAttributeValueAsString(this, curr_cu, DW_AT_name, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00003910 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (curr_cu, die, NULL);
3911 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
3912 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
3913 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00003914 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00003915 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00003916 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003917 GetObjectFile()->GetModule()->LogMessage (log.get(),
3918 "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)",
3919 GetClangASTContext().getASTContext(),
3920 MakeUserID(die->GetOffset()),
3921 namespace_name,
3922 namespace_decl,
3923 namespace_decl->getOriginalNamespace());
Greg Clayton030a2042011-10-14 21:34:45 +00003924 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00003925 else
3926 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003927 GetObjectFile()->GetModule()->LogMessage (log.get(),
3928 "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
3929 GetClangASTContext().getASTContext(),
3930 MakeUserID(die->GetOffset()),
3931 namespace_decl,
3932 namespace_decl->getOriginalNamespace());
Greg Clayton9d3d6882011-10-31 23:51:19 +00003933 }
Greg Clayton030a2042011-10-14 21:34:45 +00003934 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00003935
3936 if (namespace_decl)
3937 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
3938 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003939 }
3940 }
3941 return NULL;
3942}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003943
3944clang::DeclContext *
Greg Claytoncab36a32011-12-08 05:16:30 +00003945SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Sean Callanan72e49402011-08-05 23:43:37 +00003946{
Greg Clayton5cf58b92011-10-05 22:22:08 +00003947 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
3948 if (clang_decl_ctx)
3949 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00003950 // If this DIE has a specification, or an abstract origin, then trace to those.
3951
Greg Claytoncab36a32011-12-08 05:16:30 +00003952 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00003953 if (die_offset != DW_INVALID_OFFSET)
3954 return GetClangDeclContextForDIEOffset (sc, die_offset);
3955
Greg Claytoncab36a32011-12-08 05:16:30 +00003956 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00003957 if (die_offset != DW_INVALID_OFFSET)
3958 return GetClangDeclContextForDIEOffset (sc, die_offset);
3959
Greg Clayton3bffb082011-12-10 02:15:28 +00003960 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
3961 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00003962 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 +00003963 // This is the DIE we want. Parse it, then query our map.
Greg Claytoncab36a32011-12-08 05:16:30 +00003964 bool assert_not_being_parsed = true;
3965 ResolveTypeUID (cu, die, assert_not_being_parsed);
3966
Greg Clayton5cf58b92011-10-05 22:22:08 +00003967 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
3968
3969 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00003970}
3971
3972clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00003973SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003974{
Greg Claytonca512b32011-01-14 04:54:56 +00003975 if (m_clang_tu_decl == NULL)
3976 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003977
Greg Clayton2bc22f82011-09-30 03:20:47 +00003978 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00003979
3980 if (decl_ctx_die_copy)
3981 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00003982
3983 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003984 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00003985
Greg Clayton2bc22f82011-09-30 03:20:47 +00003986 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
3987 if (pos != m_die_to_decl_ctx.end())
3988 return pos->second;
3989
3990 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003991 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00003992 case DW_TAG_compile_unit:
3993 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003994
Greg Clayton2bc22f82011-09-30 03:20:47 +00003995 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00003996 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00003997 break;
3998
3999 case DW_TAG_structure_type:
4000 case DW_TAG_union_type:
4001 case DW_TAG_class_type:
4002 {
4003 Type* type = ResolveType (cu, decl_ctx_die);
4004 if (type)
4005 {
4006 clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ());
4007 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00004008 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004009 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
4010 if (decl_ctx)
4011 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00004012 }
4013 }
Greg Claytonca512b32011-01-14 04:54:56 +00004014 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00004015 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004016
Greg Clayton2bc22f82011-09-30 03:20:47 +00004017 default:
4018 break;
Greg Claytonca512b32011-01-14 04:54:56 +00004019 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004020 }
Greg Clayton7a345282010-11-09 23:46:37 +00004021 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004022}
4023
Greg Clayton2bc22f82011-09-30 03:20:47 +00004024
4025const DWARFDebugInfoEntry *
4026SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4027{
4028 if (cu && die)
4029 {
4030 const DWARFDebugInfoEntry * const decl_die = die;
4031
4032 while (die != NULL)
4033 {
4034 // If this is the original DIE that we are searching for a declaration
4035 // for, then don't look in the cache as we don't want our own decl
4036 // context to be our decl context...
4037 if (decl_die != die)
4038 {
4039 switch (die->Tag())
4040 {
4041 case DW_TAG_compile_unit:
4042 case DW_TAG_namespace:
4043 case DW_TAG_structure_type:
4044 case DW_TAG_union_type:
4045 case DW_TAG_class_type:
4046 return die;
4047
4048 default:
4049 break;
4050 }
4051 }
4052
4053 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4054 if (die_offset != DW_INVALID_OFFSET)
4055 {
4056 DWARFCompileUnit *spec_cu = cu;
4057 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
4058 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
4059 if (spec_die_decl_ctx_die)
4060 return spec_die_decl_ctx_die;
4061 }
4062
4063 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
4064 if (die_offset != DW_INVALID_OFFSET)
4065 {
4066 DWARFCompileUnit *abs_cu = cu;
4067 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
4068 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
4069 if (abs_die_decl_ctx_die)
4070 return abs_die_decl_ctx_die;
4071 }
4072
4073 die = die->GetParent();
4074 }
4075 }
4076 return NULL;
4077}
4078
4079
Greg Clayton901c5ca2011-12-03 04:40:03 +00004080Symbol *
4081SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
4082{
4083 Symbol *objc_class_symbol = NULL;
4084 if (m_obj_file)
4085 {
4086 Symtab *symtab = m_obj_file->GetSymtab();
4087 if (symtab)
4088 {
4089 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
4090 eSymbolTypeObjCClass,
4091 Symtab::eDebugNo,
4092 Symtab::eVisibilityAny);
4093 }
4094 }
4095 return objc_class_symbol;
4096}
4097
Greg Claytonc7f03b62012-01-12 04:33:28 +00004098// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
4099// then we can end up looking through all class types for a complete type and never find
4100// the full definition. We need to know if this attribute is supported, so we determine
4101// this here and cache th result. We also need to worry about the debug map DWARF file
4102// if we are doing darwin DWARF in .o file debugging.
4103bool
4104SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
4105{
4106 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
4107 {
4108 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
4109 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
4110 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4111 else
4112 {
4113 DWARFDebugInfo* debug_info = DebugInfo();
4114 const uint32_t num_compile_units = GetNumCompileUnits();
4115 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
4116 {
4117 DWARFCompileUnit* curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
4118 if (curr_cu != cu && curr_cu->Supports_DW_AT_APPLE_objc_complete_type())
4119 {
4120 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4121 break;
4122 }
4123 }
4124 }
4125 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && m_debug_map_symfile)
4126 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
4127 }
4128 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
4129}
Greg Clayton901c5ca2011-12-03 04:40:03 +00004130
4131// This function can be used when a DIE is found that is a forward declaration
4132// DIE and we want to try and find a type that has the complete definition.
4133TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00004134SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
4135 const ConstString &type_name,
4136 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00004137{
4138
4139 TypeSP type_sp;
4140
Greg Claytonc7f03b62012-01-12 04:33:28 +00004141 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00004142 return type_sp;
4143
4144 DIEArray die_offsets;
4145
4146 if (m_using_apple_tables)
4147 {
4148 if (m_apple_types_ap.get())
4149 {
4150 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00004151 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004152 }
4153 }
4154 else
4155 {
4156 if (!m_indexed)
4157 Index ();
4158
4159 m_type_index.Find (type_name, die_offsets);
4160 }
4161
Greg Clayton901c5ca2011-12-03 04:40:03 +00004162 const size_t num_matches = die_offsets.size();
4163
Greg Clayton901c5ca2011-12-03 04:40:03 +00004164 DWARFCompileUnit* type_cu = NULL;
4165 const DWARFDebugInfoEntry* type_die = NULL;
4166 if (num_matches)
4167 {
4168 DWARFDebugInfo* debug_info = DebugInfo();
4169 for (size_t i=0; i<num_matches; ++i)
4170 {
4171 const dw_offset_t die_offset = die_offsets[i];
4172 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4173
4174 if (type_die)
4175 {
4176 bool try_resolving_type = false;
4177
4178 // Don't try and resolve the DIE we are looking for with the DIE itself!
4179 if (type_die != die)
4180 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004181 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00004182 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004183 case DW_TAG_class_type:
4184 case DW_TAG_structure_type:
4185 try_resolving_type = true;
4186 break;
4187 default:
4188 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00004189 }
4190 }
4191
4192 if (try_resolving_type)
4193 {
Sean Callanana9bc0652012-01-19 02:17:40 +00004194 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004195 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004196
4197 if (try_resolving_type)
4198 {
4199 Type *resolved_type = ResolveType (type_cu, type_die, false);
4200 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4201 {
4202 DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n",
4203 MakeUserID(die->GetOffset()),
4204 MakeUserID(curr_cu->GetOffset()),
4205 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4206 MakeUserID(type_die->GetOffset()),
4207 MakeUserID(type_cu->GetOffset()));
4208
Greg Claytonc7f03b62012-01-12 04:33:28 +00004209 if (die)
4210 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00004211 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00004212 break;
4213 }
4214 }
4215 }
4216 }
4217 else
4218 {
4219 if (m_using_apple_tables)
4220 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004221 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4222 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00004223 }
4224 }
4225
4226 }
4227 }
4228 return type_sp;
4229}
4230
Greg Clayton80c26302012-02-05 06:12:47 +00004231//----------------------------------------------------------------------
4232// This function helps to ensure that the declaration contexts match for
4233// two different DIEs. Often times debug information will refer to a
4234// forward declaration of a type (the equivalent of "struct my_struct;".
4235// There will often be a declaration of that type elsewhere that has the
4236// full definition. When we go looking for the full type "my_struct", we
4237// will find one or more matches in the accelerator tables and we will
4238// then need to make sure the type was in the same declaration context
4239// as the original DIE. This function can efficiently compare two DIEs
4240// and will return true when the declaration context matches, and false
4241// when they don't.
4242//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00004243bool
4244SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
4245 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
4246{
4247 assert (die1 != die2);
4248 DWARFDIECollection decl_ctx_1;
4249 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00004250 //The declaration DIE stack is a stack of the declaration context
4251 // DIEs all the way back to the compile unit. If a type "T" is
4252 // declared inside a class "B", and class "B" is declared inside
4253 // a class "A" and class "A" is in a namespace "lldb", and the
4254 // namespace is in a compile unit, there will be a stack of DIEs:
4255 //
4256 // [0] DW_TAG_class_type for "B"
4257 // [1] DW_TAG_class_type for "A"
4258 // [2] DW_TAG_namespace for "lldb"
4259 // [3] DW_TAG_compile_unit for the source file.
4260 //
4261 // We grab both contexts and make sure that everything matches
4262 // all the way back to the compiler unit.
4263
4264 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00004265 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004266 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00004267 // Make sure the context arrays have the same size, otherwise
4268 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00004269 const size_t count1 = decl_ctx_1.Size();
4270 const size_t count2 = decl_ctx_2.Size();
4271 if (count1 != count2)
4272 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00004273
4274 // Make sure the DW_TAG values match all the way back up the the
4275 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00004276 const DWARFDebugInfoEntry *decl_ctx_die1;
4277 const DWARFDebugInfoEntry *decl_ctx_die2;
4278 size_t i;
4279 for (i=0; i<count1; i++)
4280 {
4281 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4282 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4283 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
4284 return false;
4285 }
Greg Clayton890ff562012-02-02 05:48:16 +00004286#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00004287
4288 // Make sure the top item in the decl context die array is always
4289 // DW_TAG_compile_unit. If it isn't then something went wrong in
4290 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00004291 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00004292
Greg Clayton890ff562012-02-02 05:48:16 +00004293#endif
4294 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00004295 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00004296 for (i=0; i<count1 - 1; i++)
4297 {
4298 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4299 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4300 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004301 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00004302 // If the string was from a DW_FORM_strp, then the pointer will often
4303 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00004304 if (name1 == name2)
4305 continue;
4306
4307 // Name pointers are not equal, so only compare the strings
4308 // if both are not NULL.
4309 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00004310 {
Greg Clayton5569e642012-02-06 01:44:54 +00004311 // If the strings don't compare, we are done...
4312 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00004313 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00004314 }
4315 else
4316 {
4317 // One name was NULL while the other wasn't
4318 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00004319 }
4320 }
Greg Clayton80c26302012-02-05 06:12:47 +00004321 // We made it through all of the checks and the declaration contexts
4322 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00004323 return true;
4324}
Greg Clayton220a0072011-12-09 08:48:30 +00004325
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004326// This function can be used when a DIE is found that is a forward declaration
4327// DIE and we want to try and find a type that has the complete definition.
4328TypeSP
Greg Clayton7f995132011-10-04 22:41:51 +00004329SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
4330 const DWARFDebugInfoEntry *die,
4331 const ConstString &type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004332{
4333 TypeSP type_sp;
4334
Greg Clayton1a65ae12011-01-25 23:55:37 +00004335 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004336 return type_sp;
4337
Greg Clayton7f995132011-10-04 22:41:51 +00004338 DIEArray die_offsets;
4339
Greg Clayton97fbc342011-10-20 22:30:33 +00004340 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004341 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004342 if (m_apple_types_ap.get())
4343 {
Greg Claytond1767f02011-12-08 02:13:16 +00004344 if (m_apple_types_ap->GetHeader().header_data.atoms.size() > 1)
4345 {
Greg Claytonae920b62012-01-06 00:17:16 +00004346 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets);
Greg Claytond1767f02011-12-08 02:13:16 +00004347 }
4348 else
4349 {
4350 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
4351 }
Greg Clayton97fbc342011-10-20 22:30:33 +00004352 }
Greg Clayton7f995132011-10-04 22:41:51 +00004353 }
4354 else
4355 {
4356 if (!m_indexed)
4357 Index ();
4358
4359 m_type_index.Find (type_name, die_offsets);
4360 }
Greg Clayton7f995132011-10-04 22:41:51 +00004361
4362 const size_t num_matches = die_offsets.size();
Greg Clayton69974892010-12-03 21:42:06 +00004363
Greg Clayton934cb052011-12-03 00:27:05 +00004364 const dw_tag_t die_tag = die->Tag();
Greg Claytond4a2b372011-09-12 23:21:58 +00004365
4366 DWARFCompileUnit* type_cu = NULL;
4367 const DWARFDebugInfoEntry* type_die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00004368 if (num_matches)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004369 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004370 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004371 for (size_t i=0; i<num_matches; ++i)
4372 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004373 const dw_offset_t die_offset = die_offsets[i];
4374 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004375
Greg Clayton95d87902011-11-11 03:16:25 +00004376 if (type_die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004377 {
Greg Clayton934cb052011-12-03 00:27:05 +00004378 bool try_resolving_type = false;
4379
4380 // Don't try and resolve the DIE we are looking for with the DIE itself!
4381 if (type_die != die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004382 {
Greg Clayton934cb052011-12-03 00:27:05 +00004383 const dw_tag_t type_die_tag = type_die->Tag();
4384 // Make sure the tags match
4385 if (type_die_tag == die_tag)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004386 {
Greg Clayton934cb052011-12-03 00:27:05 +00004387 // The tags match, lets try resolving this type
4388 try_resolving_type = true;
4389 }
4390 else
4391 {
4392 // The tags don't match, but we need to watch our for a
4393 // forward declaration for a struct and ("struct foo")
4394 // ends up being a class ("class foo { ... };") or
4395 // vice versa.
4396 switch (type_die_tag)
Greg Clayton95d87902011-11-11 03:16:25 +00004397 {
Greg Clayton934cb052011-12-03 00:27:05 +00004398 case DW_TAG_class_type:
4399 // We had a "class foo", see if we ended up with a "struct foo { ... };"
4400 try_resolving_type = (die_tag == DW_TAG_structure_type);
4401 break;
4402 case DW_TAG_structure_type:
4403 // We had a "struct foo", see if we ended up with a "class foo { ... };"
4404 try_resolving_type = (die_tag == DW_TAG_class_type);
4405 break;
4406 default:
4407 // Tags don't match, don't event try to resolve
4408 // using this type whose name matches....
Greg Clayton95d87902011-11-11 03:16:25 +00004409 break;
4410 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004411 }
4412 }
Greg Clayton934cb052011-12-03 00:27:05 +00004413
4414 if (try_resolving_type)
4415 {
Greg Clayton890ff562012-02-02 05:48:16 +00004416 // Make sure the decl contexts match all the way up
4417 if (DIEDeclContextsMatch(cu, die, type_cu, type_die))
Greg Clayton934cb052011-12-03 00:27:05 +00004418 {
Greg Clayton890ff562012-02-02 05:48:16 +00004419 Type *resolved_type = ResolveType (type_cu, type_die, false);
4420 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4421 {
4422 DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n",
4423 MakeUserID(die->GetOffset()),
4424 MakeUserID(curr_cu->GetOffset()),
4425 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4426 MakeUserID(type_die->GetOffset()),
4427 MakeUserID(type_cu->GetOffset()));
4428
4429 m_die_to_type[die] = resolved_type;
Greg Claytonff7692a2012-02-02 18:16:59 +00004430 type_sp = resolved_type->shared_from_this();
Greg Clayton890ff562012-02-02 05:48:16 +00004431 break;
4432 }
Greg Clayton934cb052011-12-03 00:27:05 +00004433 }
4434 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004435 }
Greg Clayton95d87902011-11-11 03:16:25 +00004436 else
4437 {
4438 if (m_using_apple_tables)
4439 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004440 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4441 die_offset, type_name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004442 }
4443 }
4444
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004445 }
4446 }
4447 return type_sp;
4448}
4449
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004450TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00004451SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004452{
4453 TypeSP type_sp;
4454
Greg Clayton1be10fc2010-09-29 01:12:09 +00004455 if (type_is_new_ptr)
4456 *type_is_new_ptr = false;
Greg Clayton1fba87112012-02-09 20:03:49 +00004457
4458#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
4459 static DIEStack g_die_stack;
4460 DIEStack::ScopedPopper scoped_die_logger(g_die_stack);
4461#endif
Greg Clayton1be10fc2010-09-29 01:12:09 +00004462
Sean Callananc7fbf732010-08-06 00:32:49 +00004463 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004464 if (die != NULL)
4465 {
Greg Clayton21f2a492011-10-06 00:09:08 +00004466 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00004467 if (log)
Sean Callanan5b26f272012-02-04 08:49:35 +00004468 {
4469 const DWARFDebugInfoEntry *context_die;
4470 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
4471
Greg Clayton1fba87112012-02-09 20:03:49 +00004472 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 +00004473 die->GetOffset(),
4474 context,
4475 context_die->GetOffset(),
Greg Clayton3bffb082011-12-10 02:15:28 +00004476 DW_TAG_value_to_name(die->Tag()),
Greg Clayton1fba87112012-02-09 20:03:49 +00004477 die->GetName(this, dwarf_cu));
4478
4479#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
4480 scoped_die_logger.Push (dwarf_cu, die);
4481 g_die_stack.LogDIEs(log.get(), this);
4482#endif
Sean Callanan5b26f272012-02-04 08:49:35 +00004483 }
Greg Clayton3bffb082011-12-10 02:15:28 +00004484//
4485// LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4486// if (log && dwarf_cu)
4487// {
4488// StreamString s;
4489// die->DumpLocation (this, dwarf_cu, s);
Greg Claytone38a5ed2012-01-05 03:57:59 +00004490// GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Greg Clayton3bffb082011-12-10 02:15:28 +00004491//
4492// }
Jim Ingham16746d12011-08-25 23:21:43 +00004493
Greg Clayton594e5ed2010-09-27 21:07:38 +00004494 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004495 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00004496 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004497 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004498 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00004499 if (type_is_new_ptr)
4500 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004501
Greg Clayton594e5ed2010-09-27 21:07:38 +00004502 const dw_tag_t tag = die->Tag();
4503
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004504 bool is_forward_declaration = false;
4505 DWARFDebugInfoEntry::Attributes attributes;
4506 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00004507 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00004508 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
4509 size_t byte_size = 0;
Greg Clayton36909642011-03-15 04:38:20 +00004510 bool byte_size_valid = false;
Greg Clayton526e5af2010-11-13 03:52:47 +00004511 Declaration decl;
4512
Greg Clayton4957bf62010-09-30 21:49:03 +00004513 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton1be10fc2010-09-29 01:12:09 +00004514 clang_type_t clang_type = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004515
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004516 dw_attr_t attr;
4517
4518 switch (tag)
4519 {
4520 case DW_TAG_base_type:
4521 case DW_TAG_pointer_type:
4522 case DW_TAG_reference_type:
4523 case DW_TAG_typedef:
4524 case DW_TAG_const_type:
4525 case DW_TAG_restrict_type:
4526 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00004527 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004528 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004529 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00004530 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004531
Greg Claytond88d7592010-09-15 08:33:30 +00004532 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004533 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004534 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
4535
4536 if (num_attributes > 0)
4537 {
4538 uint32_t i;
4539 for (i=0; i<num_attributes; ++i)
4540 {
4541 attr = attributes.AttributeAtIndex(i);
4542 DWARFFormValue form_value;
4543 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4544 {
4545 switch (attr)
4546 {
4547 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4548 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4549 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4550 case DW_AT_name:
Jim Ingham337030f2011-04-15 23:41:23 +00004551
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004552 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00004553 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
4554 // include the "&"...
4555 if (tag == DW_TAG_reference_type)
4556 {
4557 if (strchr (type_name_cstr, '&') == NULL)
4558 type_name_cstr = NULL;
4559 }
4560 if (type_name_cstr)
4561 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004562 break;
Greg Clayton36909642011-03-15 04:38:20 +00004563 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004564 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
4565 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
4566 default:
4567 case DW_AT_sibling:
4568 break;
4569 }
4570 }
4571 }
4572 }
4573
Greg Clayton81c22f62011-10-19 18:09:39 +00004574 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 +00004575
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004576 switch (tag)
4577 {
4578 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00004579 break;
4580
Greg Claytond4436412011-10-28 21:00:00 +00004581 case DW_TAG_unspecified_type:
4582 if (strcmp(type_name_cstr, "nullptr_t") == 0)
4583 {
4584 resolve_state = Type::eResolveStateFull;
4585 clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr();
4586 break;
4587 }
4588 // Fall through to base type below in case we can handle the type there...
4589
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004590 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00004591 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004592 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
4593 encoding,
4594 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004595 break;
4596
Greg Clayton526e5af2010-11-13 03:52:47 +00004597 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
4598 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
4599 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
4600 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
4601 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
4602 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004603 }
4604
Greg Claytonc7f03b62012-01-12 04:33:28 +00004605 if (clang_type == NULL && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID))
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004606 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004607 if (type_name_cstr != NULL && sc.comp_unit != NULL &&
4608 (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus))
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004609 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004610 static ConstString g_objc_type_name_id("id");
4611 static ConstString g_objc_type_name_Class("Class");
4612 static ConstString g_objc_type_name_selector("SEL");
4613
4614 if (type_name_const_str == g_objc_type_name_id)
4615 {
4616 if (log)
4617 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'id' built-in type.",
4618 die->GetOffset(),
4619 DW_TAG_value_to_name(die->Tag()),
4620 die->GetName(this, dwarf_cu));
4621 clang_type = ast.GetBuiltInType_objc_id();
4622 encoding_data_type = Type::eEncodingIsUID;
4623 encoding_uid = LLDB_INVALID_UID;
4624 resolve_state = Type::eResolveStateFull;
Greg Clayton526e5af2010-11-13 03:52:47 +00004625
Greg Claytonc7f03b62012-01-12 04:33:28 +00004626 }
4627 else if (type_name_const_str == g_objc_type_name_Class)
4628 {
4629 if (log)
4630 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'Class' built-in type.",
4631 die->GetOffset(),
4632 DW_TAG_value_to_name(die->Tag()),
4633 die->GetName(this, dwarf_cu));
4634 clang_type = ast.GetBuiltInType_objc_Class();
4635 encoding_data_type = Type::eEncodingIsUID;
4636 encoding_uid = LLDB_INVALID_UID;
4637 resolve_state = Type::eResolveStateFull;
4638 }
4639 else if (type_name_const_str == g_objc_type_name_selector)
4640 {
4641 if (log)
4642 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.",
4643 die->GetOffset(),
4644 DW_TAG_value_to_name(die->Tag()),
4645 die->GetName(this, dwarf_cu));
4646 clang_type = ast.GetBuiltInType_objc_selector();
4647 encoding_data_type = Type::eEncodingIsUID;
4648 encoding_uid = LLDB_INVALID_UID;
4649 resolve_state = Type::eResolveStateFull;
4650 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004651 }
4652 }
4653
Greg Clayton81c22f62011-10-19 18:09:39 +00004654 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004655 this,
4656 type_name_const_str,
4657 byte_size,
4658 NULL,
4659 encoding_uid,
4660 encoding_data_type,
4661 &decl,
4662 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00004663 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004664
Greg Clayton594e5ed2010-09-27 21:07:38 +00004665 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004666
4667// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
4668// if (encoding_type != NULL)
4669// {
4670// if (encoding_type != DIE_IS_BEING_PARSED)
4671// type_sp->SetEncodingType(encoding_type);
4672// else
4673// m_indirect_fixups.push_back(type_sp.get());
4674// }
4675 }
4676 break;
4677
4678 case DW_TAG_structure_type:
4679 case DW_TAG_union_type:
4680 case DW_TAG_class_type:
4681 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004682 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00004683 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004684
Greg Clayton9e409562010-07-28 02:04:09 +00004685 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00004686 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004687 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00004688 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004689 if (num_attributes > 0)
4690 {
4691 uint32_t i;
4692 for (i=0; i<num_attributes; ++i)
4693 {
4694 attr = attributes.AttributeAtIndex(i);
4695 DWARFFormValue form_value;
4696 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4697 {
4698 switch (attr)
4699 {
Greg Clayton9e409562010-07-28 02:04:09 +00004700 case DW_AT_decl_file:
Greg Claytonc7f03b62012-01-12 04:33:28 +00004701 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
4702 {
4703 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
4704 // point to the compile unit file, so we clear this invalid value
4705 // so that we can still unique types efficiently.
4706 decl.SetFile(FileSpec ("<invalid>", false));
4707 }
4708 else
4709 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
Greg Clayton9e409562010-07-28 02:04:09 +00004710 break;
4711
4712 case DW_AT_decl_line:
4713 decl.SetLine(form_value.Unsigned());
4714 break;
4715
4716 case DW_AT_decl_column:
4717 decl.SetColumn(form_value.Unsigned());
4718 break;
4719
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004720 case DW_AT_name:
4721 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00004722 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004723 break;
Greg Clayton9e409562010-07-28 02:04:09 +00004724
4725 case DW_AT_byte_size:
4726 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00004727 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00004728 break;
4729
4730 case DW_AT_accessibility:
4731 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
4732 break;
4733
4734 case DW_AT_declaration:
Greg Clayton7a345282010-11-09 23:46:37 +00004735 is_forward_declaration = form_value.Unsigned() != 0;
Greg Clayton9e409562010-07-28 02:04:09 +00004736 break;
4737
4738 case DW_AT_APPLE_runtime_class:
4739 class_language = (LanguageType)form_value.Signed();
4740 break;
4741
Greg Clayton18774842011-11-29 23:40:34 +00004742 case DW_AT_APPLE_objc_complete_type:
4743 is_complete_objc_class = form_value.Signed();
4744 break;
4745
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004746 case DW_AT_allocated:
4747 case DW_AT_associated:
4748 case DW_AT_data_location:
4749 case DW_AT_description:
4750 case DW_AT_start_scope:
4751 case DW_AT_visibility:
4752 default:
4753 case DW_AT_sibling:
4754 break;
4755 }
4756 }
4757 }
4758 }
4759
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004760 UniqueDWARFASTType unique_ast_entry;
Sean Callanan8e8072d2012-02-07 21:13:38 +00004761
4762 if (GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
4763 this,
4764 dwarf_cu,
4765 die,
4766 decl,
4767 byte_size_valid ? byte_size : -1,
4768 unique_ast_entry))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004769 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00004770 // We have already parsed this type or from another
4771 // compile unit. GCC loves to use the "one definition
4772 // rule" which can result in multiple definitions
4773 // of the same class over and over in each compile
4774 // unit.
4775 type_sp = unique_ast_entry.m_type_sp;
4776 if (type_sp)
Greg Claytonc615ce42010-11-09 04:42:43 +00004777 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00004778 m_die_to_type[die] = type_sp.get();
4779 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00004780 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004781 }
4782
Greg Clayton81c22f62011-10-19 18:09:39 +00004783 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 +00004784
4785 int tag_decl_kind = -1;
4786 AccessType default_accessibility = eAccessNone;
4787 if (tag == DW_TAG_structure_type)
4788 {
4789 tag_decl_kind = clang::TTK_Struct;
4790 default_accessibility = eAccessPublic;
4791 }
4792 else if (tag == DW_TAG_union_type)
4793 {
4794 tag_decl_kind = clang::TTK_Union;
4795 default_accessibility = eAccessPublic;
4796 }
4797 else if (tag == DW_TAG_class_type)
4798 {
4799 tag_decl_kind = clang::TTK_Class;
4800 default_accessibility = eAccessPrivate;
4801 }
Greg Clayton3a5f29a2011-11-30 02:48:28 +00004802
4803 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
4804 die->HasChildren() == false &&
4805 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
4806 {
4807 // Work around an issue with clang at the moment where
4808 // forward declarations for objective C classes are emitted
4809 // as:
4810 // DW_TAG_structure_type [2]
4811 // DW_AT_name( "ForwardObjcClass" )
4812 // DW_AT_byte_size( 0x00 )
4813 // DW_AT_decl_file( "..." )
4814 // DW_AT_decl_line( 1 )
4815 //
4816 // Note that there is no DW_AT_declaration and there are
4817 // no children, and the byte size is zero.
4818 is_forward_declaration = true;
4819 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004820
Greg Clayton18774842011-11-29 23:40:34 +00004821 if (class_language == eLanguageTypeObjC)
4822 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004823 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
Greg Clayton901c5ca2011-12-03 04:40:03 +00004824 {
4825 // We have a valid eSymbolTypeObjCClass class symbol whose
4826 // name matches the current objective C class that we
4827 // are trying to find and this DIE isn't the complete
4828 // definition (we checked is_complete_objc_class above and
4829 // know it is false), so the real definition is in here somewhere
Greg Claytonc7f03b62012-01-12 04:33:28 +00004830 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004831
Greg Clayton901c5ca2011-12-03 04:40:03 +00004832 if (!type_sp && m_debug_map_symfile)
4833 {
4834 // We weren't able to find a full declaration in
4835 // this DWARF, see if we have a declaration anywhere
4836 // else...
Greg Claytonc7f03b62012-01-12 04:33:28 +00004837 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004838 }
4839
4840 if (type_sp)
4841 {
4842 if (log)
4843 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004844 GetObjectFile()->GetModule()->LogMessage (log.get(),
4845 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8llx",
4846 this,
4847 die->GetOffset(),
4848 DW_TAG_value_to_name(tag),
4849 type_name_cstr,
4850 type_sp->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00004851 }
4852
4853 // We found a real definition for this type elsewhere
4854 // so lets use it and cache the fact that we found
4855 // a complete type for this die
4856 m_die_to_type[die] = type_sp.get();
4857 return type_sp;
4858 }
4859 }
4860 }
4861
4862
4863 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004864 {
4865 // We have a forward declaration to a type and we need
4866 // to try and find a full declaration. We look in the
4867 // current type index just in case we have a forward
4868 // declaration followed by an actual declarations in the
4869 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00004870 if (log)
4871 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004872 GetObjectFile()->GetModule()->LogMessage (log.get(),
4873 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
4874 this,
4875 die->GetOffset(),
4876 DW_TAG_value_to_name(tag),
4877 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00004878 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004879
4880 type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
4881
4882 if (!type_sp && m_debug_map_symfile)
Greg Clayton4272cc72011-02-02 02:24:04 +00004883 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004884 // We weren't able to find a full declaration in
4885 // this DWARF, see if we have a declaration anywhere
4886 // else...
4887 type_sp = m_debug_map_symfile->FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
Greg Clayton4272cc72011-02-02 02:24:04 +00004888 }
4889
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004890 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00004891 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00004892 if (log)
4893 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004894 GetObjectFile()->GetModule()->LogMessage (log.get(),
4895 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8llx",
4896 this,
4897 die->GetOffset(),
4898 DW_TAG_value_to_name(tag),
4899 type_name_cstr,
4900 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00004901 }
4902
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004903 // We found a real definition for this type elsewhere
4904 // so lets use it and cache the fact that we found
4905 // a complete type for this die
4906 m_die_to_type[die] = type_sp.get();
4907 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00004908 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004909 }
4910 assert (tag_decl_kind != -1);
4911 bool clang_type_was_created = false;
4912 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
4913 if (clang_type == NULL)
4914 {
Sean Callanan4d04c6a2012-02-09 22:54:11 +00004915 const DWARFDebugInfoEntry *decl_ctx_die;
4916
4917 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton55561e92011-10-26 03:31:36 +00004918 if (accessibility == eAccessNone && decl_ctx)
4919 {
4920 // Check the decl context that contains this class/struct/union.
4921 // If it is a class we must give it an accessability.
4922 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
4923 if (DeclKindIsCXXClass (containing_decl_kind))
4924 accessibility = default_accessibility;
4925 }
4926
Greg Claytonf0705c82011-10-22 03:33:13 +00004927 if (type_name_cstr && strchr (type_name_cstr, '<'))
4928 {
4929 ClangASTContext::TemplateParameterInfos template_param_infos;
4930 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
4931 {
4932 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00004933 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00004934 type_name_cstr,
4935 tag_decl_kind,
4936 template_param_infos);
4937
4938 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
4939 class_template_decl,
4940 tag_decl_kind,
4941 template_param_infos);
4942 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
4943 clang_type_was_created = true;
4944 }
4945 }
4946
4947 if (!clang_type_was_created)
4948 {
4949 clang_type_was_created = true;
Greg Clayton55561e92011-10-26 03:31:36 +00004950 clang_type = ast.CreateRecordType (decl_ctx,
4951 accessibility,
4952 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00004953 tag_decl_kind,
Greg Claytonf0705c82011-10-22 03:33:13 +00004954 class_language);
4955 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004956 }
4957
4958 // Store a forward declaration to this class type in case any
4959 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00004960 // types for function prototypes.
4961 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00004962 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004963 this,
4964 type_name_const_str,
4965 byte_size,
4966 NULL,
4967 LLDB_INVALID_UID,
4968 Type::eEncodingIsUID,
4969 &decl,
4970 clang_type,
4971 Type::eResolveStateForward));
Sean Callanan72772842012-02-22 23:57:45 +00004972
4973 type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004974
4975
4976 // Add our type to the unique type map so we don't
4977 // end up creating many copies of the same type over
4978 // and over in the ASTContext for our module
4979 unique_ast_entry.m_type_sp = type_sp;
Greg Clayton36909642011-03-15 04:38:20 +00004980 unique_ast_entry.m_symfile = this;
4981 unique_ast_entry.m_cu = dwarf_cu;
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004982 unique_ast_entry.m_die = die;
4983 unique_ast_entry.m_declaration = decl;
Sean Callanan59700592012-02-13 22:30:16 +00004984 unique_ast_entry.m_byte_size = byte_size;
Greg Claytone576ab22011-02-15 00:19:15 +00004985 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
4986 unique_ast_entry);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004987
Sean Callanan12014a02011-12-08 23:45:45 +00004988 if (!is_forward_declaration)
4989 {
4990 if (die->HasChildren() == false)
4991 {
4992 // No children for this struct/union/class, lets finish it
4993 ast.StartTagDeclarationDefinition (clang_type);
4994 ast.CompleteTagDeclarationDefinition (clang_type);
4995 }
4996 else if (clang_type_was_created)
4997 {
4998 // Leave this as a forward declaration until we need
4999 // to know the details of the type. lldb_private::Type
5000 // will automatically call the SymbolFile virtual function
5001 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
5002 // When the definition needs to be defined.
5003 m_forward_decl_die_to_clang_type[die] = clang_type;
5004 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
5005 ClangASTContext::SetHasExternalStorage (clang_type, true);
5006 }
Greg Claytonc615ce42010-11-09 04:42:43 +00005007 }
Greg Claytoncab36a32011-12-08 05:16:30 +00005008
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005009 }
5010 break;
5011
5012 case DW_TAG_enumeration_type:
5013 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005014 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005015 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005016
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005017 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005018
Greg Claytond88d7592010-09-15 08:33:30 +00005019 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005020 if (num_attributes > 0)
5021 {
5022 uint32_t i;
5023
5024 for (i=0; i<num_attributes; ++i)
5025 {
5026 attr = attributes.AttributeAtIndex(i);
5027 DWARFFormValue form_value;
5028 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5029 {
5030 switch (attr)
5031 {
Greg Clayton7a345282010-11-09 23:46:37 +00005032 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5033 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5034 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005035 case DW_AT_name:
5036 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005037 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005038 break;
Greg Clayton7a345282010-11-09 23:46:37 +00005039 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00005040 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Greg Clayton7a345282010-11-09 23:46:37 +00005041 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
5042 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005043 case DW_AT_allocated:
5044 case DW_AT_associated:
5045 case DW_AT_bit_stride:
5046 case DW_AT_byte_stride:
5047 case DW_AT_data_location:
5048 case DW_AT_description:
5049 case DW_AT_start_scope:
5050 case DW_AT_visibility:
5051 case DW_AT_specification:
5052 case DW_AT_abstract_origin:
5053 case DW_AT_sibling:
5054 break;
5055 }
5056 }
5057 }
5058
Greg Clayton81c22f62011-10-19 18:09:39 +00005059 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 +00005060
Greg Clayton1be10fc2010-09-29 01:12:09 +00005061 clang_type_t enumerator_clang_type = NULL;
5062 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
5063 if (clang_type == NULL)
5064 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005065 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
5066 DW_ATE_signed,
5067 byte_size * 8);
Greg Claytonca512b32011-01-14 04:54:56 +00005068 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00005069 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00005070 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005071 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00005072 }
5073 else
5074 {
5075 enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
5076 assert (enumerator_clang_type != NULL);
5077 }
5078
Greg Claytona2721472011-06-25 00:44:06 +00005079 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
5080
Greg Clayton81c22f62011-10-19 18:09:39 +00005081 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005082 this,
5083 type_name_const_str,
5084 byte_size,
5085 NULL,
5086 encoding_uid,
5087 Type::eEncodingIsUID,
5088 &decl,
5089 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005090 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005091
Greg Clayton6beaaa62011-01-17 03:46:26 +00005092 ast.StartTagDeclarationDefinition (clang_type);
5093 if (die->HasChildren())
5094 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00005095 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
5096 ParseChildEnumerators(cu_sc, clang_type, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00005097 }
5098 ast.CompleteTagDeclarationDefinition (clang_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005099 }
5100 }
5101 break;
5102
Jim Inghamb0be4422010-08-12 01:20:14 +00005103 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005104 case DW_TAG_subprogram:
5105 case DW_TAG_subroutine_type:
5106 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005107 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005108 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005109
5110 const char *mangled = NULL;
5111 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00005112 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005113 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00005114 bool is_static = false;
5115 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00005116 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00005117 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00005118 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
5119 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00005120
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005121 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00005122 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005123
5124
Greg Claytond88d7592010-09-15 08:33:30 +00005125 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005126 if (num_attributes > 0)
5127 {
5128 uint32_t i;
5129 for (i=0; i<num_attributes; ++i)
5130 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00005131 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005132 DWARFFormValue form_value;
5133 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5134 {
5135 switch (attr)
5136 {
5137 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5138 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5139 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5140 case DW_AT_name:
5141 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005142 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005143 break;
5144
5145 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
5146 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00005147 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00005148 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Greg Clayton0fffff52010-09-24 05:15:53 +00005149 case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break;
5150 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
Greg Claytonf51de672010-10-01 02:31:07 +00005151 case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break;
Sean Callanandbb58392011-11-02 01:38:59 +00005152 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
5153
Greg Claytonf51de672010-10-01 02:31:07 +00005154
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005155 case DW_AT_external:
5156 if (form_value.Unsigned())
5157 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00005158 if (storage == clang::SC_None)
5159 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005160 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00005161 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005162 }
5163 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005164
Greg Clayton72da3972011-08-16 18:40:23 +00005165 case DW_AT_specification:
5166 specification_die_offset = form_value.Reference(dwarf_cu);
5167 break;
5168
5169 case DW_AT_abstract_origin:
5170 abstract_origin_die_offset = form_value.Reference(dwarf_cu);
5171 break;
5172
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005173 case DW_AT_allocated:
5174 case DW_AT_associated:
5175 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005176 case DW_AT_calling_convention:
5177 case DW_AT_data_location:
5178 case DW_AT_elemental:
5179 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005180 case DW_AT_frame_base:
5181 case DW_AT_high_pc:
5182 case DW_AT_low_pc:
5183 case DW_AT_object_pointer:
5184 case DW_AT_prototyped:
5185 case DW_AT_pure:
5186 case DW_AT_ranges:
5187 case DW_AT_recursive:
5188 case DW_AT_return_addr:
5189 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005190 case DW_AT_start_scope:
5191 case DW_AT_static_link:
5192 case DW_AT_trampoline:
5193 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005194 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005195 case DW_AT_description:
5196 case DW_AT_sibling:
5197 break;
5198 }
5199 }
5200 }
Greg Clayton24739922010-10-13 03:15:28 +00005201 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005202
Greg Clayton81c22f62011-10-19 18:09:39 +00005203 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 +00005204
Greg Clayton24739922010-10-13 03:15:28 +00005205 clang_type_t return_clang_type = NULL;
5206 Type *func_type = NULL;
5207
5208 if (type_die_offset != DW_INVALID_OFFSET)
5209 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00005210
Greg Clayton24739922010-10-13 03:15:28 +00005211 if (func_type)
Greg Clayton42ce2f32011-12-12 21:50:19 +00005212 return_clang_type = func_type->GetClangForwardType();
Greg Clayton24739922010-10-13 03:15:28 +00005213 else
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005214 return_clang_type = ast.GetBuiltInType_void();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005215
Greg Claytonf51de672010-10-01 02:31:07 +00005216
Greg Clayton24739922010-10-13 03:15:28 +00005217 std::vector<clang_type_t> function_param_types;
5218 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005219
Greg Clayton24739922010-10-13 03:15:28 +00005220 // Parse the function children for the parameters
Sean Callanan763d72a2011-08-02 22:21:50 +00005221
Greg Claytoncb5860a2011-10-13 23:49:28 +00005222 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
5223 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00005224 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
5225
Greg Claytonf0705c82011-10-22 03:33:13 +00005226 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00005227 // Start off static. This will be set to false in ParseChildParameters(...)
5228 // if we find a "this" paramters as the first parameter
5229 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00005230 is_static = true;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00005231 ClangASTContext::TemplateParameterInfos template_param_infos;
5232
Greg Clayton24739922010-10-13 03:15:28 +00005233 if (die->HasChildren())
5234 {
Greg Clayton0fffff52010-09-24 05:15:53 +00005235 bool skip_artificial = true;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005236 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00005237 containing_decl_ctx,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005238 dwarf_cu,
5239 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00005240 skip_artificial,
5241 is_static,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005242 type_list,
5243 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00005244 function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00005245 type_quals,
5246 template_param_infos);
Greg Clayton24739922010-10-13 03:15:28 +00005247 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005248
Greg Clayton24739922010-10-13 03:15:28 +00005249 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005250 clang_type = ast.CreateFunctionType (return_clang_type,
5251 &function_param_types[0],
5252 function_param_types.size(),
5253 is_variadic,
5254 type_quals);
5255
Greg Clayton24739922010-10-13 03:15:28 +00005256 if (type_name_cstr)
5257 {
5258 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00005259 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005260 {
Greg Clayton7c810422012-01-18 23:40:49 +00005261 ConstString class_name;
Greg Claytone42ae842012-01-19 03:24:53 +00005262 ConstString class_name_no_category;
5263 if (ObjCLanguageRuntime::ParseMethodName (type_name_cstr, &class_name, NULL, NULL, &class_name_no_category))
Greg Clayton0fffff52010-09-24 05:15:53 +00005264 {
Greg Claytone42ae842012-01-19 03:24:53 +00005265 // Use the class name with no category if there is one
5266 if (class_name_no_category)
5267 class_name = class_name_no_category;
5268
Greg Clayton24739922010-10-13 03:15:28 +00005269 SymbolContext empty_sc;
5270 clang_type_t class_opaque_type = NULL;
Greg Clayton7c810422012-01-18 23:40:49 +00005271 if (class_name)
Greg Clayton0fffff52010-09-24 05:15:53 +00005272 {
Greg Clayton24739922010-10-13 03:15:28 +00005273 TypeList types;
Greg Clayton278a16b2012-01-19 00:52:59 +00005274 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
Greg Claytonc7f03b62012-01-12 04:33:28 +00005275
5276 if (complete_objc_class_type_sp)
Greg Clayton0fffff52010-09-24 05:15:53 +00005277 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005278 clang_type_t type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
5279 if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
5280 class_opaque_type = type_clang_forward_type;
Greg Clayton0fffff52010-09-24 05:15:53 +00005281 }
Greg Clayton24739922010-10-13 03:15:28 +00005282 }
Greg Clayton0fffff52010-09-24 05:15:53 +00005283
Greg Clayton24739922010-10-13 03:15:28 +00005284 if (class_opaque_type)
5285 {
5286 // If accessibility isn't set to anything valid, assume public for
5287 // now...
5288 if (accessibility == eAccessNone)
5289 accessibility = eAccessPublic;
5290
5291 clang::ObjCMethodDecl *objc_method_decl;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005292 objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
5293 type_name_cstr,
5294 clang_type,
5295 accessibility);
Greg Clayton2c5f0e92011-08-04 21:02:57 +00005296 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Clayton24739922010-10-13 03:15:28 +00005297 type_handled = objc_method_decl != NULL;
5298 }
5299 }
Greg Clayton5113dc82011-08-12 06:47:54 +00005300 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00005301 {
5302 // Look at the parent of this DIE and see if is is
5303 // a class or struct and see if this is actually a
5304 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00005305 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00005306 if (class_type)
5307 {
Greg Clayton72da3972011-08-16 18:40:23 +00005308 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00005309 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00005310 // We have a specification which we are going to base our function
5311 // prototype off of, so we need this type to be completed so that the
5312 // m_die_to_decl_ctx for the method in the specification has a valid
5313 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00005314 class_type->GetClangForwardType();
Greg Clayton72da3972011-08-16 18:40:23 +00005315 // If we have a specification, then the function type should have been
5316 // made with the specification and not with this die.
5317 DWARFCompileUnitSP spec_cu_sp;
5318 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Greg Clayton5cf58b92011-10-05 22:22:08 +00005319 clang::DeclContext *spec_clang_decl_ctx = GetCachedClangDeclContextForDIE (spec_die);
5320 if (spec_clang_decl_ctx)
5321 {
5322 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
5323 }
5324 else
Jim Inghamc1663042011-09-29 22:12:35 +00005325 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005326 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_specification(0x%8.8x) has no decl\n",
5327 MakeUserID(die->GetOffset()),
5328 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00005329 }
Greg Clayton72da3972011-08-16 18:40:23 +00005330 type_handled = true;
5331 }
5332 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
5333 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00005334 // We have a specification which we are going to base our function
5335 // prototype off of, so we need this type to be completed so that the
5336 // m_die_to_decl_ctx for the method in the abstract origin has a valid
5337 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00005338 class_type->GetClangForwardType();
Greg Clayton5cf58b92011-10-05 22:22:08 +00005339
Greg Clayton72da3972011-08-16 18:40:23 +00005340 DWARFCompileUnitSP abs_cu_sp;
5341 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Greg Clayton5cf58b92011-10-05 22:22:08 +00005342 clang::DeclContext *abs_clang_decl_ctx = GetCachedClangDeclContextForDIE (abs_die);
5343 if (abs_clang_decl_ctx)
5344 {
5345 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
5346 }
5347 else
Jim Inghamc1663042011-09-29 22:12:35 +00005348 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005349 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_abstract_origin(0x%8.8x) has no decl\n",
5350 MakeUserID(die->GetOffset()),
5351 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00005352 }
Greg Clayton72da3972011-08-16 18:40:23 +00005353 type_handled = true;
5354 }
5355 else
5356 {
5357 clang_type_t class_opaque_type = class_type->GetClangForwardType();
5358 if (ClangASTContext::IsCXXClassType (class_opaque_type))
Greg Clayton931180e2011-01-27 06:44:37 +00005359 {
Greg Clayton20568dd2011-10-13 23:13:20 +00005360 if (ClangASTContext::IsBeingDefined (class_opaque_type))
Greg Clayton72da3972011-08-16 18:40:23 +00005361 {
Greg Clayton20568dd2011-10-13 23:13:20 +00005362 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
5363 // in the DWARF for C++ methods... Default to public for now...
5364 if (accessibility == eAccessNone)
5365 accessibility = eAccessPublic;
5366
5367 if (!is_static && !die->HasChildren())
5368 {
5369 // We have a C++ member function with no children (this pointer!)
5370 // and clang will get mad if we try and make a function that isn't
5371 // well formed in the DWARF, so we will just skip it...
5372 type_handled = true;
5373 }
5374 else
5375 {
5376 clang::CXXMethodDecl *cxx_method_decl;
5377 // REMOVE THE CRASH DESCRIPTION BELOW
Greg Clayton81c22f62011-10-19 18:09:39 +00005378 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 +00005379 type_name_cstr,
5380 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00005381 MakeUserID(die->GetOffset()),
Greg Clayton20568dd2011-10-13 23:13:20 +00005382 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
5383 m_obj_file->GetFileSpec().GetFilename().GetCString());
5384
Sean Callananc1b732d2011-11-01 18:07:13 +00005385 const bool is_attr_used = false;
5386
Greg Clayton20568dd2011-10-13 23:13:20 +00005387 cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type,
5388 type_name_cstr,
5389 clang_type,
5390 accessibility,
5391 is_virtual,
5392 is_static,
5393 is_inline,
Sean Callananc1b732d2011-11-01 18:07:13 +00005394 is_explicit,
Sean Callanandbb58392011-11-02 01:38:59 +00005395 is_attr_used,
5396 is_artificial);
Greg Clayton20568dd2011-10-13 23:13:20 +00005397 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
5398
Greg Claytonf49e65a2011-11-10 18:31:53 +00005399 Host::SetCrashDescription (NULL);
5400
Greg Clayton20568dd2011-10-13 23:13:20 +00005401 type_handled = cxx_method_decl != NULL;
5402 }
Greg Clayton72da3972011-08-16 18:40:23 +00005403 }
5404 else
5405 {
Greg Clayton20568dd2011-10-13 23:13:20 +00005406 // We were asked to parse the type for a method in a class, yet the
5407 // class hasn't been asked to complete itself through the
5408 // clang::ExternalASTSource protocol, so we need to just have the
5409 // class complete itself and do things the right way, then our
5410 // DIE should then have an entry in the m_die_to_type map. First
5411 // we need to modify the m_die_to_type so it doesn't think we are
5412 // trying to parse this DIE anymore...
5413 m_die_to_type[die] = NULL;
5414
5415 // Now we get the full type to force our class type to complete itself
5416 // using the clang::ExternalASTSource protocol which will parse all
5417 // base classes and all methods (including the method for this DIE).
5418 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00005419
Greg Clayton20568dd2011-10-13 23:13:20 +00005420 // The type for this DIE should have been filled in the function call above
5421 type_ptr = m_die_to_type[die];
5422 if (type_ptr)
5423 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00005424 type_sp = type_ptr->shared_from_this();
Greg Clayton20568dd2011-10-13 23:13:20 +00005425 break;
5426 }
Greg Clayton72da3972011-08-16 18:40:23 +00005427 }
Greg Clayton931180e2011-01-27 06:44:37 +00005428 }
Greg Clayton0fffff52010-09-24 05:15:53 +00005429 }
5430 }
Greg Clayton0fffff52010-09-24 05:15:53 +00005431 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005432 }
Greg Clayton24739922010-10-13 03:15:28 +00005433
5434 if (!type_handled)
5435 {
5436 // We just have a function that isn't part of a class
Greg Clayton147e1fa2011-10-14 22:47:18 +00005437 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (containing_decl_ctx,
5438 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005439 clang_type,
5440 storage,
5441 is_inline);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00005442
5443// if (template_param_infos.GetSize() > 0)
5444// {
5445// clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
5446// function_decl,
5447// type_name_cstr,
5448// template_param_infos);
5449//
5450// ast.CreateFunctionTemplateSpecializationInfo (function_decl,
5451// func_template_decl,
5452// template_param_infos);
5453// }
Greg Clayton24739922010-10-13 03:15:28 +00005454 // Add the decl to our DIE to decl context map
5455 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00005456 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00005457 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005458 ast.SetFunctionParameters (function_decl,
5459 &function_param_decls.front(),
5460 function_param_decls.size());
Greg Clayton24739922010-10-13 03:15:28 +00005461 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005462 }
Greg Clayton81c22f62011-10-19 18:09:39 +00005463 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005464 this,
5465 type_name_const_str,
5466 0,
5467 NULL,
5468 LLDB_INVALID_UID,
5469 Type::eEncodingIsUID,
5470 &decl,
5471 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005472 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00005473 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005474 }
5475 break;
5476
5477 case DW_TAG_array_type:
5478 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005479 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005480 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005481
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005482 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005483 int64_t first_index = 0;
5484 uint32_t byte_stride = 0;
5485 uint32_t bit_stride = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00005486 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005487
5488 if (num_attributes > 0)
5489 {
5490 uint32_t i;
5491 for (i=0; i<num_attributes; ++i)
5492 {
5493 attr = attributes.AttributeAtIndex(i);
5494 DWARFFormValue form_value;
5495 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5496 {
5497 switch (attr)
5498 {
5499 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5500 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5501 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5502 case DW_AT_name:
5503 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005504 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005505 break;
5506
5507 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00005508 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005509 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
5510 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00005511 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00005512 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005513 case DW_AT_allocated:
5514 case DW_AT_associated:
5515 case DW_AT_data_location:
5516 case DW_AT_description:
5517 case DW_AT_ordering:
5518 case DW_AT_start_scope:
5519 case DW_AT_visibility:
5520 case DW_AT_specification:
5521 case DW_AT_abstract_origin:
5522 case DW_AT_sibling:
5523 break;
5524 }
5525 }
5526 }
5527
Greg Clayton81c22f62011-10-19 18:09:39 +00005528 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 +00005529
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005530 Type *element_type = ResolveTypeUID(type_die_offset);
5531
5532 if (element_type)
5533 {
5534 std::vector<uint64_t> element_orders;
5535 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
Greg Claytona134cc12010-09-13 02:37:44 +00005536 // We have an array that claims to have no members, lets give it at least one member...
5537 if (element_orders.empty())
5538 element_orders.push_back (1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005539 if (byte_stride == 0 && bit_stride == 0)
5540 byte_stride = element_type->GetByteSize();
Greg Clayton42ce2f32011-12-12 21:50:19 +00005541 clang_type_t array_element_type = element_type->GetClangForwardType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005542 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
5543 uint64_t num_elements = 0;
5544 std::vector<uint64_t>::const_reverse_iterator pos;
5545 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
5546 for (pos = element_orders.rbegin(); pos != end; ++pos)
5547 {
5548 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005549 clang_type = ast.CreateArrayType (array_element_type,
5550 num_elements,
5551 num_elements * array_element_bit_stride);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005552 array_element_type = clang_type;
5553 array_element_bit_stride = array_element_bit_stride * num_elements;
5554 }
5555 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00005556 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005557 this,
5558 empty_name,
5559 array_element_bit_stride / 8,
5560 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00005561 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005562 Type::eEncodingIsUID,
5563 &decl,
5564 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005565 Type::eResolveStateFull));
5566 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005567 }
5568 }
5569 }
5570 break;
5571
Greg Clayton9b81a312010-06-12 01:20:30 +00005572 case DW_TAG_ptr_to_member_type:
5573 {
5574 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
5575 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
5576
Greg Claytond88d7592010-09-15 08:33:30 +00005577 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00005578
5579 if (num_attributes > 0) {
5580 uint32_t i;
5581 for (i=0; i<num_attributes; ++i)
5582 {
5583 attr = attributes.AttributeAtIndex(i);
5584 DWARFFormValue form_value;
5585 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5586 {
5587 switch (attr)
5588 {
5589 case DW_AT_type:
5590 type_die_offset = form_value.Reference(dwarf_cu); break;
5591 case DW_AT_containing_type:
5592 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
5593 }
5594 }
5595 }
5596
5597 Type *pointee_type = ResolveTypeUID(type_die_offset);
5598 Type *class_type = ResolveTypeUID(containing_type_die_offset);
5599
Greg Clayton526e5af2010-11-13 03:52:47 +00005600 clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
5601 clang_type_t class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00005602
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005603 clang_type = ast.CreateMemberPointerType(pointee_clang_type,
5604 class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00005605
Greg Clayton526e5af2010-11-13 03:52:47 +00005606 byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(),
5607 clang_type) / 8;
Greg Clayton9b81a312010-06-12 01:20:30 +00005608
Greg Clayton81c22f62011-10-19 18:09:39 +00005609 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005610 this,
5611 type_name_const_str,
5612 byte_size,
5613 NULL,
5614 LLDB_INVALID_UID,
5615 Type::eEncodingIsUID,
5616 NULL,
5617 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005618 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00005619 }
5620
5621 break;
5622 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005623 default:
Greg Clayton9b81a312010-06-12 01:20:30 +00005624 assert(false && "Unhandled type tag!");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005625 break;
5626 }
5627
5628 if (type_sp.get())
5629 {
5630 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
5631 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
5632
5633 SymbolContextScope * symbol_context_scope = NULL;
5634 if (sc_parent_tag == DW_TAG_compile_unit)
5635 {
5636 symbol_context_scope = sc.comp_unit;
5637 }
5638 else if (sc.function != NULL)
5639 {
Greg Clayton81c22f62011-10-19 18:09:39 +00005640 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005641 if (symbol_context_scope == NULL)
5642 symbol_context_scope = sc.function;
5643 }
5644
5645 if (symbol_context_scope != NULL)
5646 {
5647 type_sp->SetSymbolContextScope(symbol_context_scope);
5648 }
5649
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005650 // We are ready to put this type into the uniqued list up at the module level
5651 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00005652
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005653 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005654 }
5655 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00005656 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005657 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00005658 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005659 }
5660 }
5661 return type_sp;
5662}
5663
5664size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00005665SymbolFileDWARF::ParseTypes
5666(
5667 const SymbolContext& sc,
5668 DWARFCompileUnit* dwarf_cu,
5669 const DWARFDebugInfoEntry *die,
5670 bool parse_siblings,
5671 bool parse_children
5672)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005673{
5674 size_t types_added = 0;
5675 while (die != NULL)
5676 {
5677 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00005678 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005679 {
5680 if (type_is_new)
5681 ++types_added;
5682 }
5683
5684 if (parse_children && die->HasChildren())
5685 {
5686 if (die->Tag() == DW_TAG_subprogram)
5687 {
5688 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00005689 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005690 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
5691 }
5692 else
5693 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
5694 }
5695
5696 if (parse_siblings)
5697 die = die->GetSibling();
5698 else
5699 die = NULL;
5700 }
5701 return types_added;
5702}
5703
5704
5705size_t
5706SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
5707{
5708 assert(sc.comp_unit && sc.function);
5709 size_t functions_added = 0;
5710 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
5711 if (dwarf_cu)
5712 {
5713 dw_offset_t function_die_offset = sc.function->GetID();
5714 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
5715 if (function_die)
5716 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00005717 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005718 }
5719 }
5720
5721 return functions_added;
5722}
5723
5724
5725size_t
5726SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
5727{
5728 // At least a compile unit must be valid
5729 assert(sc.comp_unit);
5730 size_t types_added = 0;
5731 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
5732 if (dwarf_cu)
5733 {
5734 if (sc.function)
5735 {
5736 dw_offset_t function_die_offset = sc.function->GetID();
5737 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
5738 if (func_die && func_die->HasChildren())
5739 {
5740 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
5741 }
5742 }
5743 else
5744 {
5745 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
5746 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
5747 {
5748 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
5749 }
5750 }
5751 }
5752
5753 return types_added;
5754}
5755
5756size_t
5757SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
5758{
5759 if (sc.comp_unit != NULL)
5760 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00005761 DWARFDebugInfo* info = DebugInfo();
5762 if (info == NULL)
5763 return 0;
5764
5765 uint32_t cu_idx = UINT32_MAX;
5766 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005767
5768 if (dwarf_cu == NULL)
5769 return 0;
5770
5771 if (sc.function)
5772 {
5773 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00005774
5775 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 +00005776 if (func_lo_pc != DW_INVALID_ADDRESS)
5777 {
5778 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00005779
Greg Claytone38a5ed2012-01-05 03:57:59 +00005780 // Let all blocks know they have parse all their variables
5781 sc.function->GetBlock (false).SetDidParseVariables (true, true);
5782 return num_variables;
5783 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005784 }
5785 else if (sc.comp_unit)
5786 {
5787 uint32_t vars_added = 0;
5788 VariableListSP variables (sc.comp_unit->GetVariableList(false));
5789
5790 if (variables.get() == NULL)
5791 {
5792 variables.reset(new VariableList());
5793 sc.comp_unit->SetVariableList(variables);
5794
Greg Claytond4a2b372011-09-12 23:21:58 +00005795 DWARFCompileUnit* match_dwarf_cu = NULL;
5796 const DWARFDebugInfoEntry* die = NULL;
5797 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00005798 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00005799 {
Greg Clayton97fbc342011-10-20 22:30:33 +00005800 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00005801 {
5802 DWARFMappedHash::DIEInfoArray hash_data_array;
5803 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
5804 dwarf_cu->GetNextCompileUnitOffset(),
5805 hash_data_array))
5806 {
5807 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
5808 }
5809 }
Greg Clayton7f995132011-10-04 22:41:51 +00005810 }
5811 else
5812 {
5813 // Index if we already haven't to make sure the compile units
5814 // get indexed and make their global DIE index list
5815 if (!m_indexed)
5816 Index ();
5817
5818 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
5819 dwarf_cu->GetNextCompileUnitOffset(),
5820 die_offsets);
5821 }
5822
5823 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00005824 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005825 {
Greg Claytond4a2b372011-09-12 23:21:58 +00005826 DWARFDebugInfo* debug_info = DebugInfo();
5827 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005828 {
Greg Claytond4a2b372011-09-12 23:21:58 +00005829 const dw_offset_t die_offset = die_offsets[i];
5830 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00005831 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00005832 {
Greg Clayton95d87902011-11-11 03:16:25 +00005833 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
5834 if (var_sp)
5835 {
5836 variables->AddVariableIfUnique (var_sp);
5837 ++vars_added;
5838 }
Greg Claytond4a2b372011-09-12 23:21:58 +00005839 }
Greg Clayton95d87902011-11-11 03:16:25 +00005840 else
5841 {
5842 if (m_using_apple_tables)
5843 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005844 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 +00005845 }
5846 }
5847
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005848 }
5849 }
5850 }
5851 return vars_added;
5852 }
5853 }
5854 return 0;
5855}
5856
5857
5858VariableSP
5859SymbolFileDWARF::ParseVariableDIE
5860(
5861 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00005862 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00005863 const DWARFDebugInfoEntry *die,
5864 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005865)
5866{
5867
Greg Clayton83c5cd92010-11-14 22:13:40 +00005868 VariableSP var_sp (m_die_to_variable_sp[die]);
5869 if (var_sp)
5870 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005871
5872 const dw_tag_t tag = die->Tag();
Greg Clayton7f995132011-10-04 22:41:51 +00005873
5874 if ((tag == DW_TAG_variable) ||
5875 (tag == DW_TAG_constant) ||
5876 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005877 {
Greg Clayton7f995132011-10-04 22:41:51 +00005878 DWARFDebugInfoEntry::Attributes attributes;
5879 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
5880 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005881 {
Greg Clayton7f995132011-10-04 22:41:51 +00005882 const char *name = NULL;
5883 const char *mangled = NULL;
5884 Declaration decl;
5885 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00005886 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00005887 DWARFExpression location;
5888 bool is_external = false;
5889 bool is_artificial = false;
5890 bool location_is_const_value_data = false;
5891 AccessType accessibility = eAccessNone;
5892
5893 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005894 {
Greg Clayton7f995132011-10-04 22:41:51 +00005895 dw_attr_t attr = attributes.AttributeAtIndex(i);
5896 DWARFFormValue form_value;
5897 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005898 {
Greg Clayton7f995132011-10-04 22:41:51 +00005899 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005900 {
Greg Clayton7f995132011-10-04 22:41:51 +00005901 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5902 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5903 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5904 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
5905 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Claytond1767f02011-12-08 02:13:16 +00005906 case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton7f995132011-10-04 22:41:51 +00005907 case DW_AT_external: is_external = form_value.Unsigned() != 0; break;
5908 case DW_AT_const_value:
5909 location_is_const_value_data = true;
5910 // Fall through...
5911 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005912 {
Greg Clayton7f995132011-10-04 22:41:51 +00005913 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005914 {
Greg Clayton7f995132011-10-04 22:41:51 +00005915 const DataExtractor& debug_info_data = get_debug_info_data();
5916
5917 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
5918 uint32_t block_length = form_value.Unsigned();
5919 location.SetOpcodeData(get_debug_info_data(), block_offset, block_length);
5920 }
5921 else
5922 {
5923 const DataExtractor& debug_loc_data = get_debug_loc_data();
5924 const dw_offset_t debug_loc_offset = form_value.Unsigned();
5925
5926 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
5927 if (loc_list_length > 0)
5928 {
5929 location.SetOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
5930 assert (func_low_pc != LLDB_INVALID_ADDRESS);
5931 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
5932 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005933 }
5934 }
Greg Clayton7f995132011-10-04 22:41:51 +00005935 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005936
Greg Clayton7f995132011-10-04 22:41:51 +00005937 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
5938 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
5939 case DW_AT_declaration:
5940 case DW_AT_description:
5941 case DW_AT_endianity:
5942 case DW_AT_segment:
5943 case DW_AT_start_scope:
5944 case DW_AT_visibility:
5945 default:
5946 case DW_AT_abstract_origin:
5947 case DW_AT_sibling:
5948 case DW_AT_specification:
5949 break;
5950 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005951 }
5952 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005953
Greg Clayton7f995132011-10-04 22:41:51 +00005954 if (location.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005955 {
Greg Clayton7f995132011-10-04 22:41:51 +00005956 ValueType scope = eValueTypeInvalid;
5957
5958 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
5959 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005960 SymbolContextScope * symbol_context_scope = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00005961
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005962 // DWARF doesn't specify if a DW_TAG_variable is a local, global
5963 // or static variable, so we have to do a little digging by
5964 // looking at the location of a varaible to see if it contains
5965 // a DW_OP_addr opcode _somewhere_ in the definition. I say
5966 // somewhere because clang likes to combine small global variables
5967 // into the same symbol and have locations like:
5968 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
5969 // So if we don't have a DW_TAG_formal_parameter, we can look at
5970 // the location to see if it contains a DW_OP_addr opcode, and
5971 // then we can correctly classify our variables.
Greg Clayton7f995132011-10-04 22:41:51 +00005972 if (tag == DW_TAG_formal_parameter)
5973 scope = eValueTypeVariableArgument;
Greg Claytond1767f02011-12-08 02:13:16 +00005974 else
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005975 {
Greg Clayton96c09682012-01-04 22:56:43 +00005976 bool op_error = false;
Greg Claytond1767f02011-12-08 02:13:16 +00005977 // Check if the location has a DW_OP_addr with any address value...
5978 addr_t location_has_op_addr = false;
5979 if (!location_is_const_value_data)
Greg Clayton96c09682012-01-04 22:56:43 +00005980 {
5981 location_has_op_addr = location.LocationContains_DW_OP_addr (LLDB_INVALID_ADDRESS, op_error);
5982 if (op_error)
5983 {
5984 StreamString strm;
5985 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
Greg Claytone38a5ed2012-01-05 03:57:59 +00005986 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 +00005987 }
5988 }
Greg Claytond1767f02011-12-08 02:13:16 +00005989
5990 if (location_has_op_addr)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005991 {
Greg Claytond1767f02011-12-08 02:13:16 +00005992 if (is_external)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005993 {
Greg Claytond1767f02011-12-08 02:13:16 +00005994 scope = eValueTypeVariableGlobal;
5995
5996 if (m_debug_map_symfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005997 {
Greg Claytond1767f02011-12-08 02:13:16 +00005998 // When leaving the DWARF in the .o files on darwin,
5999 // when we have a global variable that wasn't initialized,
6000 // the .o file might not have allocated a virtual
6001 // address for the global variable. In this case it will
6002 // have created a symbol for the global variable
6003 // that is undefined and external and the value will
6004 // be the byte size of the variable. When we do the
6005 // address map in SymbolFileDWARFDebugMap we rely on
6006 // having an address, we need to do some magic here
6007 // so we can get the correct address for our global
6008 // variable. The address for all of these entries
6009 // will be zero, and there will be an undefined symbol
6010 // in this object file, and the executable will have
6011 // a matching symbol with a good address. So here we
6012 // dig up the correct address and replace it in the
6013 // location for the variable, and set the variable's
6014 // symbol context scope to be that of the main executable
6015 // so the file address will resolve correctly.
Greg Clayton96c09682012-01-04 22:56:43 +00006016 if (location.LocationContains_DW_OP_addr (0, op_error))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006017 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006018
Greg Claytond1767f02011-12-08 02:13:16 +00006019 // we have a possible uninitialized extern global
6020 Symtab *symtab = m_obj_file->GetSymtab();
6021 if (symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006022 {
Greg Claytond1767f02011-12-08 02:13:16 +00006023 ConstString const_name(name);
6024 Symbol *undefined_symbol = symtab->FindFirstSymbolWithNameAndType (const_name,
6025 eSymbolTypeUndefined,
6026 Symtab::eDebugNo,
6027 Symtab::eVisibilityExtern);
6028
6029 if (undefined_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006030 {
Greg Claytond1767f02011-12-08 02:13:16 +00006031 ObjectFile *debug_map_objfile = m_debug_map_symfile->GetObjectFile();
6032 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006033 {
Greg Claytond1767f02011-12-08 02:13:16 +00006034 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
6035 Symbol *defined_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
6036 eSymbolTypeData,
6037 Symtab::eDebugYes,
6038 Symtab::eVisibilityExtern);
6039 if (defined_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006040 {
Greg Claytond1767f02011-12-08 02:13:16 +00006041 const AddressRange *defined_range = defined_symbol->GetAddressRangePtr();
6042 if (defined_range)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006043 {
Greg Claytond1767f02011-12-08 02:13:16 +00006044 const addr_t defined_addr = defined_range->GetBaseAddress().GetFileAddress();
6045 if (defined_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006046 {
Greg Claytond1767f02011-12-08 02:13:16 +00006047 if (location.Update_DW_OP_addr (defined_addr))
6048 {
6049 symbol_context_scope = defined_symbol;
6050 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006051 }
6052 }
6053 }
6054 }
6055 }
6056 }
6057 }
6058 }
6059 }
Greg Claytond1767f02011-12-08 02:13:16 +00006060 else
6061 {
6062 scope = eValueTypeVariableStatic;
6063 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006064 }
6065 else
Greg Claytond1767f02011-12-08 02:13:16 +00006066 {
6067 scope = eValueTypeVariableLocal;
6068 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006069 }
Greg Clayton7f995132011-10-04 22:41:51 +00006070
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006071 if (symbol_context_scope == NULL)
Greg Clayton7f995132011-10-04 22:41:51 +00006072 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006073 switch (parent_tag)
Greg Clayton5cf58b92011-10-05 22:22:08 +00006074 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006075 case DW_TAG_subprogram:
6076 case DW_TAG_inlined_subroutine:
6077 case DW_TAG_lexical_block:
6078 if (sc.function)
6079 {
6080 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
6081 if (symbol_context_scope == NULL)
6082 symbol_context_scope = sc.function;
6083 }
6084 break;
6085
6086 default:
6087 symbol_context_scope = sc.comp_unit;
6088 break;
Greg Clayton5cf58b92011-10-05 22:22:08 +00006089 }
Greg Clayton7f995132011-10-04 22:41:51 +00006090 }
6091
Greg Clayton5cf58b92011-10-05 22:22:08 +00006092 if (symbol_context_scope)
6093 {
Greg Clayton81c22f62011-10-19 18:09:39 +00006094 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
6095 name,
6096 mangled,
Greg Claytond1767f02011-12-08 02:13:16 +00006097 SymbolFileTypeSP (new SymbolFileType(*this, type_uid)),
Greg Clayton81c22f62011-10-19 18:09:39 +00006098 scope,
6099 symbol_context_scope,
6100 &decl,
6101 location,
6102 is_external,
6103 is_artificial));
Greg Clayton5cf58b92011-10-05 22:22:08 +00006104
6105 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
6106 }
6107 else
6108 {
6109 // Not ready to parse this variable yet. It might be a global
6110 // or static variable that is in a function scope and the function
6111 // in the symbol context wasn't filled in yet
6112 return var_sp;
6113 }
Greg Clayton7f995132011-10-04 22:41:51 +00006114 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006115 }
Greg Clayton7f995132011-10-04 22:41:51 +00006116 // Cache var_sp even if NULL (the variable was just a specification or
6117 // was missing vital information to be able to be displayed in the debugger
6118 // (missing location due to optimization, etc)) so we don't re-parse
6119 // this DIE over and over later...
6120 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006121 }
6122 return var_sp;
6123}
6124
Greg Claytonc662ec82011-06-17 22:10:16 +00006125
6126const DWARFDebugInfoEntry *
6127SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
6128 dw_offset_t spec_block_die_offset,
6129 DWARFCompileUnit **result_die_cu_handle)
6130{
6131 // Give the concrete function die specified by "func_die_offset", find the
6132 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
6133 // to "spec_block_die_offset"
6134 DWARFDebugInfo* info = DebugInfo();
6135
6136 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
6137 if (die)
6138 {
6139 assert (*result_die_cu_handle);
6140 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
6141 }
6142 return NULL;
6143}
6144
6145
6146const DWARFDebugInfoEntry *
6147SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
6148 const DWARFDebugInfoEntry *die,
6149 dw_offset_t spec_block_die_offset,
6150 DWARFCompileUnit **result_die_cu_handle)
6151{
6152 if (die)
6153 {
6154 switch (die->Tag())
6155 {
6156 case DW_TAG_subprogram:
6157 case DW_TAG_inlined_subroutine:
6158 case DW_TAG_lexical_block:
6159 {
6160 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
6161 {
6162 *result_die_cu_handle = dwarf_cu;
6163 return die;
6164 }
6165
6166 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
6167 {
6168 *result_die_cu_handle = dwarf_cu;
6169 return die;
6170 }
6171 }
6172 break;
6173 }
6174
6175 // Give the concrete function die specified by "func_die_offset", find the
6176 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
6177 // to "spec_block_die_offset"
6178 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
6179 {
6180 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
6181 child_die,
6182 spec_block_die_offset,
6183 result_die_cu_handle);
6184 if (result_die)
6185 return result_die;
6186 }
6187 }
6188
6189 *result_die_cu_handle = NULL;
6190 return NULL;
6191}
6192
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006193size_t
6194SymbolFileDWARF::ParseVariables
6195(
6196 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00006197 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00006198 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006199 const DWARFDebugInfoEntry *orig_die,
6200 bool parse_siblings,
6201 bool parse_children,
6202 VariableList* cc_variable_list
6203)
6204{
6205 if (orig_die == NULL)
6206 return 0;
6207
Greg Claytonc662ec82011-06-17 22:10:16 +00006208 VariableListSP variable_list_sp;
6209
6210 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006211 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00006212 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006213 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006214 dw_tag_t tag = die->Tag();
6215
6216 // Check to see if we have already parsed this variable or constant?
6217 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006218 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006219 if (cc_variable_list)
6220 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006221 }
6222 else
6223 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006224 // We haven't already parsed it, lets do that now.
6225 if ((tag == DW_TAG_variable) ||
6226 (tag == DW_TAG_constant) ||
6227 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006228 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006229 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00006230 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006231 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
6232 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
6233 switch (parent_tag)
6234 {
6235 case DW_TAG_compile_unit:
6236 if (sc.comp_unit != NULL)
6237 {
6238 variable_list_sp = sc.comp_unit->GetVariableList(false);
6239 if (variable_list_sp.get() == NULL)
6240 {
6241 variable_list_sp.reset(new VariableList());
6242 sc.comp_unit->SetVariableList(variable_list_sp);
6243 }
6244 }
6245 else
6246 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00006247 GetObjectFile()->GetModule()->ReportError ("parent 0x%8.8llx %s with no valid compile unit in symbol context for 0x%8.8llx %s.\n",
6248 MakeUserID(sc_parent_die->GetOffset()),
6249 DW_TAG_value_to_name (parent_tag),
6250 MakeUserID(orig_die->GetOffset()),
6251 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006252 }
6253 break;
6254
6255 case DW_TAG_subprogram:
6256 case DW_TAG_inlined_subroutine:
6257 case DW_TAG_lexical_block:
6258 if (sc.function != NULL)
6259 {
6260 // Check to see if we already have parsed the variables for the given scope
6261
Greg Clayton81c22f62011-10-19 18:09:39 +00006262 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006263 if (block == NULL)
6264 {
6265 // This must be a specification or abstract origin with
6266 // a concrete block couterpart in the current function. We need
6267 // to find the concrete block so we can correctly add the
6268 // variable to it
6269 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
6270 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
6271 sc_parent_die->GetOffset(),
6272 &concrete_block_die_cu);
6273 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00006274 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006275 }
6276
6277 if (block != NULL)
6278 {
6279 const bool can_create = false;
6280 variable_list_sp = block->GetBlockVariableList (can_create);
6281 if (variable_list_sp.get() == NULL)
6282 {
6283 variable_list_sp.reset(new VariableList());
6284 block->SetVariableList(variable_list_sp);
6285 }
6286 }
6287 }
6288 break;
6289
6290 default:
Greg Claytone38a5ed2012-01-05 03:57:59 +00006291 GetObjectFile()->GetModule()->ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8llx %s.\n",
6292 MakeUserID(orig_die->GetOffset()),
6293 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006294 break;
6295 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00006296 }
Greg Claytonc662ec82011-06-17 22:10:16 +00006297
6298 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006299 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00006300 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
6301 if (var_sp)
6302 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006303 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00006304 if (cc_variable_list)
6305 cc_variable_list->AddVariableIfUnique (var_sp);
6306 ++vars_added;
6307 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006308 }
6309 }
6310 }
Greg Claytonc662ec82011-06-17 22:10:16 +00006311
6312 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
6313
6314 if (!skip_children && parse_children && die->HasChildren())
6315 {
6316 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
6317 }
6318
6319 if (parse_siblings)
6320 die = die->GetSibling();
6321 else
6322 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006323 }
Greg Claytonc662ec82011-06-17 22:10:16 +00006324 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006325}
6326
6327//------------------------------------------------------------------
6328// PluginInterface protocol
6329//------------------------------------------------------------------
6330const char *
6331SymbolFileDWARF::GetPluginName()
6332{
6333 return "SymbolFileDWARF";
6334}
6335
6336const char *
6337SymbolFileDWARF::GetShortPluginName()
6338{
6339 return GetPluginNameStatic();
6340}
6341
6342uint32_t
6343SymbolFileDWARF::GetPluginVersion()
6344{
6345 return 1;
6346}
6347
6348void
Greg Clayton6beaaa62011-01-17 03:46:26 +00006349SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
6350{
6351 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6352 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
6353 if (clang_type)
6354 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
6355}
6356
6357void
6358SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
6359{
6360 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6361 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
6362 if (clang_type)
6363 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
6364}
6365
Greg Claytona2721472011-06-25 00:44:06 +00006366void
Sean Callanancc427fa2011-07-30 02:42:06 +00006367SymbolFileDWARF::DumpIndexes ()
6368{
6369 StreamFile s(stdout, false);
6370
6371 s.Printf ("DWARF index for (%s) '%s/%s':",
6372 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
6373 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
6374 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
6375 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
6376 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
6377 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
6378 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
6379 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
6380 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
6381 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
6382 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
6383}
6384
6385void
6386SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
6387 const char *name,
6388 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00006389{
Sean Callanancc427fa2011-07-30 02:42:06 +00006390 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00006391
6392 if (iter == m_decl_ctx_to_die.end())
6393 return;
6394
Greg Claytoncb5860a2011-10-13 23:49:28 +00006395 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00006396 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00006397 const DWARFDebugInfoEntry *context_die = *pos;
6398
6399 if (!results)
6400 return;
6401
6402 DWARFDebugInfo* info = DebugInfo();
6403
6404 DIEArray die_offsets;
6405
6406 DWARFCompileUnit* dwarf_cu = NULL;
6407 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton220a0072011-12-09 08:48:30 +00006408
6409 if (m_using_apple_tables)
6410 {
6411 if (m_apple_types_ap.get())
6412 m_apple_types_ap->FindByName (name, die_offsets);
6413 }
6414 else
6415 {
6416 if (!m_indexed)
6417 Index ();
6418
6419 m_type_index.Find (ConstString(name), die_offsets);
6420 }
6421
Greg Clayton220a0072011-12-09 08:48:30 +00006422 const size_t num_matches = die_offsets.size();
Greg Claytoncb5860a2011-10-13 23:49:28 +00006423
6424 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00006425 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00006426 for (size_t i = 0; i < num_matches; ++i)
6427 {
6428 const dw_offset_t die_offset = die_offsets[i];
6429 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00006430
Greg Claytoncb5860a2011-10-13 23:49:28 +00006431 if (die->GetParent() != context_die)
6432 continue;
6433
6434 Type *matching_type = ResolveType (dwarf_cu, die);
6435
Greg Clayton42ce2f32011-12-12 21:50:19 +00006436 lldb::clang_type_t type = matching_type->GetClangForwardType();
Greg Claytoncb5860a2011-10-13 23:49:28 +00006437 clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type);
6438
6439 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
6440 {
6441 clang::TagDecl *tag_decl = tag_type->getDecl();
6442 results->push_back(tag_decl);
6443 }
6444 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
6445 {
6446 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
6447 results->push_back(typedef_decl);
6448 }
Greg Claytona2721472011-06-25 00:44:06 +00006449 }
6450 }
6451 }
6452}
6453
6454void
6455SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00006456 const clang::DeclContext *decl_context,
6457 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00006458 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
6459{
Greg Clayton85ae2e12011-10-18 23:36:41 +00006460
6461 switch (decl_context->getDeclKind())
6462 {
6463 case clang::Decl::Namespace:
6464 case clang::Decl::TranslationUnit:
6465 {
6466 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6467 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
6468 }
6469 break;
6470 default:
6471 break;
6472 }
Greg Claytona2721472011-06-25 00:44:06 +00006473}
Greg Claytoncaab74e2012-01-28 00:48:57 +00006474
6475bool
6476SymbolFileDWARF::LayoutRecordType (void *baton,
6477 const clang::RecordDecl *record_decl,
6478 uint64_t &size,
6479 uint64_t &alignment,
6480 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
6481 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
6482 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
6483{
6484 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6485 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
6486}
6487
6488
6489bool
6490SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl,
6491 uint64_t &bit_size,
6492 uint64_t &alignment,
6493 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
6494 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
6495 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
6496{
6497 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
6498 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
6499 bool success = false;
6500 base_offsets.clear();
6501 vbase_offsets.clear();
6502 if (pos != m_record_decl_to_layout_map.end())
6503 {
6504 bit_size = pos->second.bit_size;
6505 alignment = pos->second.alignment;
6506 field_offsets.swap(pos->second.field_offsets);
6507 m_record_decl_to_layout_map.erase(pos);
6508 success = true;
6509 }
6510 else
6511 {
6512 bit_size = 0;
6513 alignment = 0;
6514 field_offsets.clear();
6515 }
6516
6517 if (log)
6518 GetObjectFile()->GetModule()->LogMessage (log.get(),
6519 "SymbolFileDWARF::LayoutRecordType (record_decl = %p, bit_size = %llu, alignment = %llu, field_offsets[%u],base_offsets[%u], vbase_offsets[%u]) success = %i",
6520 record_decl,
6521 bit_size,
6522 alignment,
6523 (uint32_t)field_offsets.size(),
6524 (uint32_t)base_offsets.size(),
6525 (uint32_t)vbase_offsets.size(),
6526 success);
6527 return success;
6528}
6529
6530
6531